1/* 2 * Unsquash a squashfs filesystem. This is a highly compressed read only 3 * filesystem. 4 * 5 * Copyright (c) 2010 6 * Phillip Lougher <phillip@lougher.demon.co.uk> 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2, 11 * or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 * 22 * unsquashfs_xattr.c 23 */ 24 25#include "unsquashfs.h" 26#include "xattr.h" 27 28#include <sys/xattr.h> 29 30extern int root_process; 31 32void write_xattr(char *pathname, unsigned int xattr) 33{ 34 unsigned int count; 35 struct xattr_list *xattr_list; 36 int i; 37 38 if(xattr == SQUASHFS_INVALID_XATTR || 39 sBlk.s.xattr_id_table_start == SQUASHFS_INVALID_BLK) 40 return; 41 42 xattr_list = get_xattr(xattr, &count); 43 if(xattr_list == NULL) { 44 ERROR("Failed to read xattrs for file %s\n", pathname); 45 return; 46 } 47 48 for(i = 0; i < count; i++) { 49 int prefix = xattr_list[i].type & SQUASHFS_XATTR_PREFIX_MASK; 50 51 if(root_process || prefix == SQUASHFS_XATTR_USER) { 52 int res = lsetxattr(pathname, xattr_list[i].full_name, 53 xattr_list[i].value, xattr_list[i].vsize, 0); 54 55 if(res == -1) 56 ERROR("write_xattr: failed to write xattr %s" 57 " for file %s because %s\n", 58 xattr_list[i].full_name, pathname, 59 errno == ENOSPC || errno == EDQUOT ? 60 "no extended attribute space remaining " 61 "on destination filesystem" : 62 errno == ENOTSUP ? 63 "extended attributes are not supported " 64 "by the destination filesystem" : 65 "a weird error occurred"); 66 } else 67 ERROR("write_xattr: could not write xattr %s " 68 "for file %s because you're not " 69 "superuser!\n", 70 xattr_list[i].full_name, pathname); 71 } 72} 73