2 * Unsquash a squashfs filesystem. This is a highly compressed read only
5 * Copyright (c) 2010, 2012, 2019
6 * Phillip Lougher <phillip@squashfs.org.uk>
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.
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.
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.
25 #include "unsquashfs.h"
28 #include <sys/xattr.h>
30 #define NOSPACE_MAX 10
32 extern int root_process
;
33 extern int user_xattrs
;
34 extern int ignore_errors
;
35 extern int strict_errors
;
37 int write_xattr(char *pathname
, unsigned int xattr
)
40 struct xattr_list
*xattr_list
;
42 static int nonsuper_error
= FALSE
;
43 static int ignore_xattrs
= FALSE
;
44 static int nospace_error
= 0;
47 if(ignore_xattrs
|| xattr
== SQUASHFS_INVALID_XATTR
||
48 sBlk
.s
.xattr_id_table_start
== SQUASHFS_INVALID_BLK
)
51 xattr_list
= get_xattr(xattr
, &count
, &failed
);
53 EXIT_UNSQUASH_STRICT("write_xattr: Failed to read one or more xattrs for %s\n", pathname
);
55 for(i
= 0; i
< count
; i
++) {
56 int prefix
= xattr_list
[i
].type
& SQUASHFS_XATTR_PREFIX_MASK
;
58 if(ignore_xattrs
|| (user_xattrs
&& prefix
!= SQUASHFS_XATTR_USER
))
61 if(root_process
|| prefix
== SQUASHFS_XATTR_USER
) {
62 int res
= lsetxattr(pathname
, xattr_list
[i
].full_name
,
63 xattr_list
[i
].value
, xattr_list
[i
].vsize
, 0);
66 if(errno
== ENOTSUP
) {
68 * If the destination filesystem cannot
69 * suppport xattrs, print error, and
70 * disable xattr output as this error is
71 * unlikely to go away, and printing
72 * screenfulls of the same error message
75 ERROR("write_xattr: failed to write "
76 "xattr %s for file %s because "
77 "extended attributes are not "
78 "supported by the destination "
80 xattr_list
[i
].full_name
,
82 ERROR("Ignoring xattrs in "
84 EXIT_UNSQUASH_STRICT("To avoid this error message, "
85 "specify -no-xattrs\n");
87 } else if((errno
== ENOSPC
|| errno
== EDQUOT
)
88 && nospace_error
< NOSPACE_MAX
) {
90 * Many filesystems like ext2/3/4 have
91 * limits on the amount of xattr
92 * data that can be stored per file
93 * (typically one block or 4K), so
94 * we shouldn't disable xattr ouput,
95 * as the error may be restriced to one
96 * file only. If we get a lot of these
97 * then suppress the error messsage
99 EXIT_UNSQUASH_IGNORE("write_xattr: failed to write "
100 "xattr %s for file %s because "
101 "no extended attribute space "
102 "remaining (per file or "
103 "filesystem limit)\n",
104 xattr_list
[i
].full_name
,
106 if(++ nospace_error
== NOSPACE_MAX
)
107 ERROR("%d of these errors "
108 "printed, further error "
109 "messages of this type "
113 EXIT_UNSQUASH_IGNORE("write_xattr: failed to write "
114 "xattr %s for file %s because "
115 "%s\n", xattr_list
[i
].full_name
,
116 pathname
, strerror(errno
));
119 } else if(nonsuper_error
== FALSE
) {
121 * if extract user xattrs only then
122 * error message is suppressed, if not
123 * print error, and then suppress further error
124 * messages to avoid possible screenfulls of the
125 * same error message!
127 ERROR("write_xattr: could not write xattr %s "
128 "for file %s because you're not "
130 xattr_list
[i
].full_name
, pathname
);
131 EXIT_UNSQUASH_STRICT("write_xattr: to avoid this error message, either"
132 " specify -user-xattrs, -no-xattrs, or run as "
134 ERROR("Further error messages of this type are "
136 nonsuper_error
= TRUE
;
141 free_xattr(xattr_list
, count
);