aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/e2fs_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsprogs/e2fs_lib.c')
-rw-r--r--e2fsprogs/e2fs_lib.c67
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 */
50int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version) 53int 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 */
86int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags) 88int 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 */
137int 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 */
130const uint32_t e2attr_flags_value[] = { 162const 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 */
214const 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
228const char e2attr_flags_sname[] ALIGN1 =
229 "roecSrhsatn";
230
231static 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
181void print_e2flags(FILE *f, unsigned long flags, unsigned options) 246void print_e2flags(FILE *f, unsigned long flags, unsigned options)
182{ 247{