diff options
author | Ron Yorston <rmy@pobox.com> | 2020-07-09 08:58:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-07-09 09:07:55 +0100 |
commit | 0e3456e0c4a8623fe2d8bc28c51f16c8274b8098 (patch) | |
tree | e8fc4feb3f700a1101c082d8f815d426d515ce95 /e2fsprogs/e2fs_lib.c | |
parent | 86eb680bbfd096ab1a2664e36f80f4bea55e18cf (diff) | |
download | busybox-w32-0e3456e0c4a8623fe2d8bc28c51f16c8274b8098.tar.gz busybox-w32-0e3456e0c4a8623fe2d8bc28c51f16c8274b8098.tar.bz2 busybox-w32-0e3456e0c4a8623fe2d8bc28c51f16c8274b8098.zip |
chattr, lsattr: enable in the default configuration
The chattr and lsattr utilities allow file attributes to be changed
and displayed. Modify them to support Windows file attributes using
the same names as Cygwin.
Only allow a limited subset of attributes to be changed: just most of
those supported by SetFileAttributes(). Since it isn't possible to set
all attributes the '=' operator isn't allowed.
Diffstat (limited to 'e2fsprogs/e2fs_lib.c')
-rw-r--r-- | e2fsprogs/e2fs_lib.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index 6ce655be3..3b776bc97 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "libbb.h" | 8 | #include "libbb.h" |
9 | #include "e2fs_lib.h" | 9 | #include "e2fs_lib.h" |
10 | 10 | ||
11 | #if !ENABLE_PLATFORM_MINGW32 | ||
11 | #define HAVE_EXT2_IOCTLS 1 | 12 | #define HAVE_EXT2_IOCTLS 1 |
12 | 13 | ||
13 | #if INT_MAX == LONG_MAX | 14 | #if INT_MAX == LONG_MAX |
@@ -24,6 +25,7 @@ static void close_silently(int fd) | |||
24 | close(fd); | 25 | close(fd); |
25 | errno = e; | 26 | errno = e; |
26 | } | 27 | } |
28 | #endif | ||
27 | 29 | ||
28 | 30 | ||
29 | /* Iterate a function on each entry of a directory */ | 31 | /* Iterate a function on each entry of a directory */ |
@@ -46,6 +48,7 @@ int iterate_on_dir(const char *dir_name, | |||
46 | } | 48 | } |
47 | 49 | ||
48 | 50 | ||
51 | #if !ENABLE_PLATFORM_MINGW32 | ||
49 | /* Get/set a file version on an ext2 file system */ | 52 | /* Get/set a file version on an ext2 file system */ |
50 | int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version) | 53 | int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version) |
51 | { | 54 | { |
@@ -81,7 +84,6 @@ int fgetsetversion(const char *name, unsigned long *get_version, unsigned long s | |||
81 | #endif /* ! HAVE_EXT2_IOCTLS */ | 84 | #endif /* ! HAVE_EXT2_IOCTLS */ |
82 | } | 85 | } |
83 | 86 | ||
84 | |||
85 | /* Get/set a file flags on an ext2 file system */ | 87 | /* Get/set a file flags on an ext2 file system */ |
86 | int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags) | 88 | int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags) |
87 | { | 89 | { |
@@ -124,8 +126,38 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f | |||
124 | errno = EOPNOTSUPP; | 126 | errno = EOPNOTSUPP; |
125 | return -1; | 127 | return -1; |
126 | } | 128 | } |
129 | #else /* ENABLE_PLATFORM_MINGW32 */ | ||
130 | /* Only certain attributes can be set using SetFileAttributes() */ | ||
131 | #define CHATTR_MASK (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \ | ||
132 | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE | \ | ||
133 | FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | \ | ||
134 | FILE_ATTRIBUTE_OFFLINE) | ||
127 | 135 | ||
136 | /* Get/set file attributes on a Windows file system */ | ||
137 | int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags) | ||
138 | { | ||
139 | struct stat buf; | ||
140 | |||
141 | if (stat(name, &buf) == 0 /* stat is ok */ | ||
142 | && !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) | ||
143 | ) { | ||
144 | errno = EOPNOTSUPP; | ||
145 | return -1; | ||
146 | } | ||
128 | 147 | ||
148 | if (get_flags) { | ||
149 | *get_flags = (unsigned long)buf.st_attr; | ||
150 | } | ||
151 | else if (!SetFileAttributes(name, set_flags & CHATTR_MASK)) { | ||
152 | errno = err_win_to_posix(); | ||
153 | return -1; | ||
154 | } | ||
155 | return 0; | ||
156 | } | ||
157 | #endif | ||
158 | |||
159 | |||
160 | #if !ENABLE_PLATFORM_MINGW32 | ||
129 | /* Print file attributes on an ext2 file system */ | 161 | /* Print file attributes on an ext2 file system */ |
130 | const uint32_t e2attr_flags_value[] = { | 162 | const uint32_t e2attr_flags_value[] = { |
131 | #ifdef ENABLE_COMPRESSION | 163 | #ifdef ENABLE_COMPRESSION |
@@ -177,6 +209,39 @@ static const char e2attr_flags_lname[] ALIGN1 = | |||
177 | "No_Tailmerging" "\0" | 209 | "No_Tailmerging" "\0" |
178 | "Top_of_Directory_Hierarchies" "\0" | 210 | "Top_of_Directory_Hierarchies" "\0" |
179 | /* Another trailing NUL is added by compiler */; | 211 | /* Another trailing NUL is added by compiler */; |
212 | #else /* ENABLE_PLATFORM_MINGW32 */ | ||
213 | /* Print file attributes on a Windows file system */ | ||
214 | const uint32_t e2attr_flags_value[] = { | ||
215 | FILE_ATTRIBUTE_REPARSE_POINT, | ||
216 | FILE_ATTRIBUTE_OFFLINE, | ||
217 | FILE_ATTRIBUTE_ENCRYPTED, | ||
218 | FILE_ATTRIBUTE_COMPRESSED, | ||
219 | FILE_ATTRIBUTE_SPARSE_FILE, | ||
220 | FILE_ATTRIBUTE_READONLY, | ||
221 | FILE_ATTRIBUTE_HIDDEN, | ||
222 | FILE_ATTRIBUTE_SYSTEM, | ||
223 | FILE_ATTRIBUTE_ARCHIVE, | ||
224 | FILE_ATTRIBUTE_TEMPORARY, | ||
225 | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, | ||
226 | }; | ||
227 | |||
228 | const char e2attr_flags_sname[] ALIGN1 = | ||
229 | "roecSrhsatn"; | ||
230 | |||
231 | static const char e2attr_flags_lname[] ALIGN1 = | ||
232 | "Reparse" "\0" | ||
233 | "Offline" "\0" | ||
234 | "Encrypted" "\0" | ||
235 | "Compressed" "\0" | ||
236 | "Sparse" "\0" | ||
237 | "Readonly" "\0" | ||
238 | "Hidden" "\0" | ||
239 | "System" "\0" | ||
240 | "Archive" "\0" | ||
241 | "Temporary" "\0" | ||
242 | "Notindexed" "\0" | ||
243 | /* Another trailing NUL is added by compiler */; | ||
244 | #endif | ||
180 | 245 | ||
181 | void print_e2flags(FILE *f, unsigned long flags, unsigned options) | 246 | void print_e2flags(FILE *f, unsigned long flags, unsigned options) |
182 | { | 247 | { |