1 /* vi: set sw=4 ts=4: */
3 * See README for additional information
5 * Licensed under GPLv2, see file LICENSE in this tarball for details.
11 #define HAVE_EXT2_IOCTLS 1
13 #if INT_MAX == LONG_MAX
14 #define IF_LONG_IS_SAME(...) __VA_ARGS__
15 #define IF_LONG_IS_WIDER(...)
17 #define IF_LONG_IS_SAME(...)
18 #define IF_LONG_IS_WIDER(...) __VA_ARGS__
21 static void close_silently(int fd)
29 /* Iterate a function on each entry of a directory */
30 int iterate_on_dir(const char *dir_name,
31 int (*func)(const char *, struct dirent *, void *),
35 struct dirent *de, *dep;
38 max_len = PATH_MAX + sizeof(struct dirent);
39 de = xmalloc(max_len+1);
40 memset(de, 0, max_len+1);
42 dir = opendir(dir_name);
47 while ((dep = readdir(dir))) {
48 len = sizeof(struct dirent);
49 if (len < dep->d_reclen)
54 func(dir_name, de, private);
62 /* Get/set a file version on an ext2 file system */
63 int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version)
67 IF_LONG_IS_WIDER(int ver;)
69 fd = open(name, O_NONBLOCK);
74 ver = (int) set_version;
75 r = ioctl(fd, EXT2_IOC_SETVERSION, &ver);
78 r = ioctl(fd, EXT2_IOC_SETVERSION, (void*)&set_version);
82 r = ioctl(fd, EXT2_IOC_GETVERSION, &ver);
86 r = ioctl(fd, EXT2_IOC_GETVERSION, (void*)get_version);
91 #else /* ! HAVE_EXT2_IOCTLS */
94 #endif /* ! HAVE_EXT2_IOCTLS */
98 /* Get/set a file flags on an ext2 file system */
99 int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags)
104 IF_LONG_IS_WIDER(int f;)
106 if (stat(name, &buf) == 0 /* stat is ok */
107 && !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)
111 fd = open(name, O_NONBLOCK); /* neither read nor write asked for */
118 r = ioctl(fd, EXT2_IOC_SETFLAGS, &f);
121 r = ioctl(fd, EXT2_IOC_SETFLAGS, (void*)&set_flags);
125 r = ioctl(fd, EXT2_IOC_GETFLAGS, &f);
129 r = ioctl(fd, EXT2_IOC_GETFLAGS, (void*)get_flags);
136 #endif /* HAVE_EXT2_IOCTLS */
142 /* Print file attributes on an ext2 file system */
143 const uint32_t e2attr_flags_value[] = {
144 #ifdef ENABLE_COMPRESSION
160 EXT3_JOURNAL_DATA_FL,
165 const char e2attr_flags_sname[] =
166 #ifdef ENABLE_COMPRESSION
172 static const char e2attr_flags_lname[] =
173 #ifdef ENABLE_COMPRESSION
174 "Compressed_File" "\0"
175 "Compressed_Dirty_File" "\0"
176 "Compression_Raw_Access" "\0"
177 "Compression_Error" "\0"
179 "Indexed_directory" "\0"
180 "Secure_Deletion" "\0"
182 "Synchronous_Updates" "\0"
183 "Synchronous_Directory_Updates" "\0"
188 "Compression_Requested" "\0"
189 "Journaled_Data" "\0"
190 "No_Tailmerging" "\0"
191 "Top_of_Directory_Hierarchies" "\0"
192 /* Another trailing NUL is added by compiler */;
194 void print_e2flags(FILE *f, unsigned long flags, unsigned options)
199 fv = e2attr_flags_value;
200 if (options & PFOPT_LONG) {
202 fn = e2attr_flags_lname;
211 fn += strlen(fn) + 1;
216 fn = e2attr_flags_sname;