]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/unsquashfs_xattr.c
1.1.07 release
[Ventoy.git] / SQUASHFS / squashfs-tools-4.4 / squashfs-tools / unsquashfs_xattr.c
1 /*
2 * Unsquash a squashfs filesystem. This is a highly compressed read only
3 * filesystem.
4 *
5 * Copyright (c) 2010, 2012, 2019
6 * Phillip Lougher <phillip@squashfs.org.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
30 #define NOSPACE_MAX 10
31
32 extern int root_process;
33 extern int user_xattrs;
34 extern int ignore_errors;
35 extern int strict_errors;
36
37 int write_xattr(char *pathname, unsigned int xattr)
38 {
39 unsigned int count;
40 struct xattr_list *xattr_list;
41 int i;
42 static int nonsuper_error = FALSE;
43 static int ignore_xattrs = FALSE;
44 static int nospace_error = 0;
45 int failed;
46
47 if(ignore_xattrs || xattr == SQUASHFS_INVALID_XATTR ||
48 sBlk.s.xattr_id_table_start == SQUASHFS_INVALID_BLK)
49 return TRUE;
50
51 xattr_list = get_xattr(xattr, &count, &failed);
52 if(failed)
53 EXIT_UNSQUASH_STRICT("write_xattr: Failed to read one or more xattrs for %s\n", pathname);
54
55 for(i = 0; i < count; i++) {
56 int prefix = xattr_list[i].type & SQUASHFS_XATTR_PREFIX_MASK;
57
58 if(ignore_xattrs || (user_xattrs && prefix != SQUASHFS_XATTR_USER))
59 continue;
60
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);
64
65 if(res == -1) {
66 if(errno == ENOTSUP) {
67 /*
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
73 * is rather annoying
74 */
75 ERROR("write_xattr: failed to write "
76 "xattr %s for file %s because "
77 "extended attributes are not "
78 "supported by the destination "
79 "filesystem\n",
80 xattr_list[i].full_name,
81 pathname);
82 ERROR("Ignoring xattrs in "
83 "filesystem\n");
84 EXIT_UNSQUASH_STRICT("To avoid this error message, "
85 "specify -no-xattrs\n");
86 ignore_xattrs = TRUE;
87 } else if((errno == ENOSPC || errno == EDQUOT)
88 && nospace_error < NOSPACE_MAX) {
89 /*
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
98 */
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,
105 pathname);
106 if(++ nospace_error == NOSPACE_MAX)
107 ERROR("%d of these errors "
108 "printed, further error "
109 "messages of this type "
110 "are suppressed!\n",
111 NOSPACE_MAX);
112 } else
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));
117 failed = TRUE;
118 }
119 } else if(nonsuper_error == FALSE) {
120 /*
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!
126 */
127 ERROR("write_xattr: could not write xattr %s "
128 "for file %s because you're not "
129 "superuser!\n",
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 "
133 "superuser!\n");
134 ERROR("Further error messages of this type are "
135 "suppressed!\n");
136 nonsuper_error = TRUE;
137 failed = TRUE;
138 }
139 }
140
141 free_xattr(xattr_list, count);
142
143 return !failed;
144 }