diff options
-rw-r--r-- | e2fsprogs/chattr.c | 26 | ||||
-rw-r--r-- | e2fsprogs/e2fs_lib.c | 30 | ||||
-rw-r--r-- | e2fsprogs/e2fs_lib.h | 8 | ||||
-rw-r--r-- | e2fsprogs/lsattr.c | 7 |
4 files changed, 20 insertions, 51 deletions
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index c1e90d13f..e35b9d223 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c | |||
@@ -190,8 +190,8 @@ static int FAST_FUNC chattr_dir_proc(const char *dir_name, struct dirent *de, vo | |||
190 | 190 | ||
191 | static void change_attributes(const char *name, struct globals *gp) | 191 | static void change_attributes(const char *name, struct globals *gp) |
192 | { | 192 | { |
193 | unsigned fsflags; | ||
194 | #if !ENABLE_PLATFORM_MINGW32 | 193 | #if !ENABLE_PLATFORM_MINGW32 |
194 | unsigned fsflags; | ||
195 | int fd; | 195 | int fd; |
196 | #endif | 196 | #endif |
197 | struct stat st; | 197 | struct stat st; |
@@ -261,22 +261,14 @@ static void change_attributes(const char *name, struct globals *gp) | |||
261 | close(fd); | 261 | close(fd); |
262 | } | 262 | } |
263 | #else /* ENABLE_PLATFORM_MINGW32 */ | 263 | #else /* ENABLE_PLATFORM_MINGW32 */ |
264 | if (gp->flags & OPT_SET) { | 264 | /*if (gp->flags & OPT_REM) - not needed, rf is zero otherwise */ |
265 | fsflags = gp->af; | 265 | st.st_attr &= ~gp->rf; |
266 | } else { | 266 | /*if (gp->flags & OPT_ADD) - not needed, af is zero otherwise */ |
267 | if (fgetflags(name, &fsflags) != 0) { | 267 | st.st_attr |= gp->af; |
268 | bb_perror_msg("reading flags on %s", name); | 268 | if (!SetFileAttributes(name, st.st_attr & CHATTR_MASK)) { |
269 | goto skip_setflags; | 269 | errno = err_win_to_posix(); |
270 | } | ||
271 | /*if (gp->flags & OPT_REM) - not needed, rf is zero otherwise */ | ||
272 | fsflags &= ~gp->rf; | ||
273 | /*if (gp->flags & OPT_ADD) - not needed, af is zero otherwise */ | ||
274 | fsflags |= gp->af; | ||
275 | } | ||
276 | if (fsetflags(name, fsflags) != 0) | ||
277 | bb_perror_msg("setting flags on %s", name); | 270 | bb_perror_msg("setting flags on %s", name); |
278 | 271 | } | |
279 | skip_setflags: | ||
280 | #endif | 272 | #endif |
281 | 273 | ||
282 | if (gp->recursive && S_ISDIR(st.st_mode)) | 274 | if (gp->recursive && S_ISDIR(st.st_mode)) |
@@ -307,8 +299,10 @@ int chattr_main(int argc UNUSED_PARAM, char **argv) | |||
307 | /* note: on loop exit, remaining argv[] is never empty */ | 299 | /* note: on loop exit, remaining argv[] is never empty */ |
308 | 300 | ||
309 | /* run sanity checks on all the arguments given us */ | 301 | /* run sanity checks on all the arguments given us */ |
302 | #if !ENABLE_PLATFORM_MINGW32 | ||
310 | if ((g.flags & OPT_SET) && (g.flags & (OPT_ADD|OPT_REM))) | 303 | if ((g.flags & OPT_SET) && (g.flags & (OPT_ADD|OPT_REM))) |
311 | bb_simple_error_msg_and_die("= is incompatible with - and +"); | 304 | bb_simple_error_msg_and_die("= is incompatible with - and +"); |
305 | #endif | ||
312 | if (g.rf & g.af) | 306 | if (g.rf & g.af) |
313 | bb_simple_error_msg_and_die("can't set and unset a flag"); | 307 | bb_simple_error_msg_and_die("can't set and unset a flag"); |
314 | if (!g.flags) | 308 | if (!g.flags) |
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index 48c3b68b5..e40702e78 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c | |||
@@ -8,36 +8,6 @@ | |||
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 | ||
12 | /* Only certain attributes can be set using SetFileAttributes() */ | ||
13 | #define CHATTR_MASK (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \ | ||
14 | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE | \ | ||
15 | FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | \ | ||
16 | FILE_ATTRIBUTE_OFFLINE) | ||
17 | |||
18 | /* Get/set file attributes on a Windows file system */ | ||
19 | int fgetsetflags(const char *name, unsigned *get_flags, unsigned set_flags) | ||
20 | { | ||
21 | struct stat buf; | ||
22 | |||
23 | if (stat(name, &buf) == 0 /* stat is ok */ | ||
24 | && !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) | ||
25 | ) { | ||
26 | errno = EOPNOTSUPP; | ||
27 | return -1; | ||
28 | } | ||
29 | |||
30 | if (get_flags) { | ||
31 | *get_flags = (unsigned long)buf.st_attr; | ||
32 | } | ||
33 | else if (!SetFileAttributes(name, set_flags & CHATTR_MASK)) { | ||
34 | errno = err_win_to_posix(); | ||
35 | return -1; | ||
36 | } | ||
37 | return 0; | ||
38 | } | ||
39 | #endif | ||
40 | |||
41 | #if !ENABLE_PLATFORM_MINGW32 | 11 | #if !ENABLE_PLATFORM_MINGW32 |
42 | /* Print file attributes on an ext2 file system */ | 12 | /* Print file attributes on an ext2 file system */ |
43 | const uint32_t e2attr_flags_value[] ALIGN4 = { | 13 | const uint32_t e2attr_flags_value[] ALIGN4 = { |
diff --git a/e2fsprogs/e2fs_lib.h b/e2fsprogs/e2fs_lib.h index aa92e63af..fd6948fc7 100644 --- a/e2fsprogs/e2fs_lib.h +++ b/e2fsprogs/e2fs_lib.h | |||
@@ -12,10 +12,10 @@ | |||
12 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | 12 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
13 | 13 | ||
14 | #if ENABLE_PLATFORM_MINGW32 | 14 | #if ENABLE_PLATFORM_MINGW32 |
15 | /* Get/set a file flags */ | 15 | /* Only certain attributes can be set using SetFileAttributes() */ |
16 | int fgetsetflags(const char *name, unsigned *get_flags, unsigned set_flags); | 16 | #define CHATTR_MASK (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \ |
17 | #define fgetflags(name, flags) fgetsetflags(name, flags, 0) | 17 | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE | \ |
18 | #define fsetflags(name, flags) fgetsetflags(name, NULL, flags) | 18 | FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) |
19 | #endif | 19 | #endif |
20 | 20 | ||
21 | /* Print file attributes on an ext2 file system */ | 21 | /* Print file attributes on an ext2 file system */ |
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index d82861e14..461ce39e6 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c | |||
@@ -89,8 +89,13 @@ static void list_attributes(const char *name) | |||
89 | 89 | ||
90 | close(fd); | 90 | close(fd); |
91 | #else /* ENABLE_PLATFORM_MINGW32 */ | 91 | #else /* ENABLE_PLATFORM_MINGW32 */ |
92 | if (fgetflags(name, &fsflags) != 0) | 92 | struct stat st; |
93 | |||
94 | if (lstat(name, &st) == 0 && !(S_ISREG(st.st_mode) || | ||
95 | S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))) | ||
93 | goto read_err; | 96 | goto read_err; |
97 | |||
98 | fsflags = st.st_attr; | ||
94 | #endif | 99 | #endif |
95 | 100 | ||
96 | if (option_mask32 & OPT_PF_LONG) { | 101 | if (option_mask32 & OPT_PF_LONG) { |