diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-04-23 01:45:08 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-04-23 01:45:08 +0000 |
commit | 3b59821cbdc63ad3acb920095cae1b866e28bcb7 (patch) | |
tree | 3f352a7a58e597b36b7a9154b6a32b098d6ccbb6 | |
parent | 0ea3a6f660d890368d22fc7d3543487f825b2f1b (diff) | |
download | busybox-w32-3b59821cbdc63ad3acb920095cae1b866e28bcb7.tar.gz busybox-w32-3b59821cbdc63ad3acb920095cae1b866e28bcb7.tar.bz2 busybox-w32-3b59821cbdc63ad3acb920095cae1b866e28bcb7.zip |
remove lsattr/chattr to prepare for a top level e2fsprogs dir with more stuff in it
-rw-r--r-- | util-linux/Config.in | 12 | ||||
-rw-r--r-- | util-linux/Makefile.in | 11 | ||||
-rw-r--r-- | util-linux/chattr.c | 307 | ||||
-rw-r--r-- | util-linux/e2p/README | 24 | ||||
-rw-r--r-- | util-linux/e2p/e2p.h | 52 | ||||
-rw-r--r-- | util-linux/e2p/feature.c | 190 | ||||
-rw-r--r-- | util-linux/e2p/fgetflags.c | 92 | ||||
-rw-r--r-- | util-linux/e2p/fgetversion.c | 62 | ||||
-rw-r--r-- | util-linux/e2p/fsetflags.c | 96 | ||||
-rw-r--r-- | util-linux/e2p/fsetversion.c | 60 | ||||
-rw-r--r-- | util-linux/e2p/getflags.c | 66 | ||||
-rw-r--r-- | util-linux/e2p/getversion.c | 37 | ||||
-rw-r--r-- | util-linux/e2p/hashstr.c | 70 | ||||
-rw-r--r-- | util-linux/e2p/iod.c | 72 | ||||
-rw-r--r-- | util-linux/e2p/ls.c | 276 | ||||
-rw-r--r-- | util-linux/e2p/mntopts.c | 136 | ||||
-rw-r--r-- | util-linux/e2p/ostype.c | 73 | ||||
-rw-r--r-- | util-linux/e2p/parse_num.c | 64 | ||||
-rw-r--r-- | util-linux/e2p/pe.c | 37 | ||||
-rw-r--r-- | util-linux/e2p/pf.c | 74 | ||||
-rw-r--r-- | util-linux/e2p/ps.c | 29 | ||||
-rw-r--r-- | util-linux/e2p/setflags.c | 72 | ||||
-rw-r--r-- | util-linux/e2p/setversion.c | 36 | ||||
-rw-r--r-- | util-linux/e2p/uuid.c | 79 | ||||
-rw-r--r-- | util-linux/ext2_fs.h | 644 | ||||
-rw-r--r-- | util-linux/lsattr.c | 195 |
26 files changed, 0 insertions, 2866 deletions
diff --git a/util-linux/Config.in b/util-linux/Config.in index 65ac62ed8..c47a42d5b 100644 --- a/util-linux/Config.in +++ b/util-linux/Config.in | |||
@@ -5,18 +5,6 @@ | |||
5 | 5 | ||
6 | menu "Linux System Utilities" | 6 | menu "Linux System Utilities" |
7 | 7 | ||
8 | config CONFIG_CHATTR | ||
9 | bool "chattr" | ||
10 | default n | ||
11 | help | ||
12 | chattr changes the file attributes on a second extended file system. | ||
13 | |||
14 | config CONFIG_LSATTR | ||
15 | bool "lsattr" | ||
16 | default n | ||
17 | help | ||
18 | lsattr lists the file attributes on a second extended file system. | ||
19 | |||
20 | config CONFIG_DMESG | 8 | config CONFIG_DMESG |
21 | bool "dmesg" | 9 | bool "dmesg" |
22 | default n | 10 | default n |
diff --git a/util-linux/Makefile.in b/util-linux/Makefile.in index 034794a8d..2747b4f21 100644 --- a/util-linux/Makefile.in +++ b/util-linux/Makefile.in | |||
@@ -24,7 +24,6 @@ endif | |||
24 | srcdir=$(top_srcdir)/util-linux | 24 | srcdir=$(top_srcdir)/util-linux |
25 | 25 | ||
26 | UTILLINUX-:= | 26 | UTILLINUX-:= |
27 | UTILLINUX-$(CONFIG_CHATTR) +=chattr.o e2p.o | ||
28 | UTILLINUX-$(CONFIG_DMESG) +=dmesg.o | 27 | UTILLINUX-$(CONFIG_DMESG) +=dmesg.o |
29 | UTILLINUX-$(CONFIG_FBSET) +=fbset.o | 28 | UTILLINUX-$(CONFIG_FBSET) +=fbset.o |
30 | UTILLINUX-$(CONFIG_FDFLUSH) +=fdflush.o | 29 | UTILLINUX-$(CONFIG_FDFLUSH) +=fdflush.o |
@@ -36,7 +35,6 @@ UTILLINUX-$(CONFIG_GETOPT) +=getopt.o | |||
36 | UTILLINUX-$(CONFIG_HEXDUMP) +=hexdump.o | 35 | UTILLINUX-$(CONFIG_HEXDUMP) +=hexdump.o |
37 | UTILLINUX-$(CONFIG_HWCLOCK) +=hwclock.o | 36 | UTILLINUX-$(CONFIG_HWCLOCK) +=hwclock.o |
38 | UTILLINUX-$(CONFIG_LOSETUP) +=losetup.o | 37 | UTILLINUX-$(CONFIG_LOSETUP) +=losetup.o |
39 | UTILLINUX-$(CONFIG_LSATTR) +=lsattr.o e2p.o | ||
40 | UTILLINUX-$(CONFIG_MKFS_MINIX) +=mkfs_minix.o | 38 | UTILLINUX-$(CONFIG_MKFS_MINIX) +=mkfs_minix.o |
41 | UTILLINUX-$(CONFIG_MKSWAP) +=mkswap.o | 39 | UTILLINUX-$(CONFIG_MKSWAP) +=mkswap.o |
42 | UTILLINUX-$(CONFIG_MORE) +=more.o | 40 | UTILLINUX-$(CONFIG_MORE) +=more.o |
@@ -55,15 +53,6 @@ $(UTILLINUX_DIR)$(UTILLINUX_AR): $(patsubst %,$(UTILLINUX_DIR)%, $(UTILLINUX-y)) | |||
55 | $(UTILLINUX_DIR)%.o: $(srcdir)/%.c | 53 | $(UTILLINUX_DIR)%.o: $(srcdir)/%.c |
56 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< | 54 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< |
57 | 55 | ||
58 | E2P_SRC_LIST := \ | ||
59 | fgetflags.c fsetflags.c \ | ||
60 | fgetversion.c fsetversion.c \ | ||
61 | pf.c iod.c | ||
62 | E2P_SRC := $(patsubst %, $(UTILLINUX_DIR)/e2p/%, $(E2P_SRC_LIST)) | ||
63 | $(UTILLINUX_DIR)e2p.o: $(E2P_SRC) | ||
64 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $(E2P_SRC) \ | ||
65 | -DHAVE_ERRNO_H=1 -DHAVE_UNISTD_H=1 -DHAVE_EXT2_IOCTLS=1 -DHAVE_EXT2_IOCTLS=1 | ||
66 | |||
67 | ifneq ($(strip $(CONFIG_LFS)),y) | 56 | ifneq ($(strip $(CONFIG_LFS)),y) |
68 | ifeq ($(strip $(FDISK_SUPPORT_LARGE_DISKS)),y) | 57 | ifeq ($(strip $(FDISK_SUPPORT_LARGE_DISKS)),y) |
69 | 58 | ||
diff --git a/util-linux/chattr.c b/util-linux/chattr.c deleted file mode 100644 index 74209d586..000000000 --- a/util-linux/chattr.c +++ /dev/null | |||
@@ -1,307 +0,0 @@ | |||
1 | /* | ||
2 | * chattr.c - Change file attributes on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | * 93/11/13 - Replace stat() calls by lstat() to avoid loops | ||
16 | * 94/02/27 - Integrated in Ted's distribution | ||
17 | * 98/12/29 - Ignore symlinks when working recursively (G M Sipe) | ||
18 | * 98/12/29 - Display version info only when -V specified (G M Sipe) | ||
19 | */ | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | #include <dirent.h> | ||
23 | #include <fcntl.h> | ||
24 | #include <stdio.h> | ||
25 | #include <stdlib.h> | ||
26 | #include <unistd.h> | ||
27 | #include <string.h> | ||
28 | #include <errno.h> | ||
29 | #include <sys/param.h> | ||
30 | #include <sys/stat.h> | ||
31 | #include "ext2_fs.h" | ||
32 | |||
33 | #ifdef __GNUC__ | ||
34 | #define EXT2FS_ATTR(x) __attribute__(x) | ||
35 | #else | ||
36 | #define EXT2FS_ATTR(x) | ||
37 | #endif | ||
38 | |||
39 | #ifndef S_ISLNK /* So we can compile even with gcc-warn */ | ||
40 | # ifdef __S_IFLNK | ||
41 | # define S_ISLNK(mode) __S_ISTYPE((mode), __S_IFLNK) | ||
42 | # else | ||
43 | # define S_ISLNK(mode) 0 | ||
44 | # endif | ||
45 | #endif | ||
46 | |||
47 | #include "e2fsbb.h" | ||
48 | #include "e2p/e2p.h" | ||
49 | |||
50 | #define main chattr_main | ||
51 | |||
52 | static int add; | ||
53 | static int rem; | ||
54 | static int set; | ||
55 | static int set_version; | ||
56 | |||
57 | static unsigned long version; | ||
58 | |||
59 | static int recursive; | ||
60 | static int verbose; | ||
61 | |||
62 | static unsigned long af; | ||
63 | static unsigned long rf; | ||
64 | static unsigned long sf; | ||
65 | |||
66 | #ifdef _LFS64_LARGEFILE | ||
67 | #define LSTAT lstat64 | ||
68 | #define STRUCT_STAT struct stat64 | ||
69 | #else | ||
70 | #define LSTAT lstat | ||
71 | #define STRUCT_STAT struct stat | ||
72 | #endif | ||
73 | |||
74 | #if 0 | ||
75 | static void fatal_error(const char * fmt_string, int errcode) | ||
76 | { | ||
77 | fprintf (stderr, fmt_string, program_name); | ||
78 | exit (errcode); | ||
79 | } | ||
80 | |||
81 | #define usage() fatal_error(_("usage: %s [-RV] [-+=AacDdijsSu] [-v version] files...\n"), \ | ||
82 | 1) | ||
83 | #endif | ||
84 | |||
85 | struct flags_char { | ||
86 | unsigned long flag; | ||
87 | char optchar; | ||
88 | }; | ||
89 | |||
90 | static const struct flags_char flags_array[] = { | ||
91 | { EXT2_NOATIME_FL, 'A' }, | ||
92 | { EXT2_SYNC_FL, 'S' }, | ||
93 | { EXT2_DIRSYNC_FL, 'D' }, | ||
94 | { EXT2_APPEND_FL, 'a' }, | ||
95 | { EXT2_COMPR_FL, 'c' }, | ||
96 | { EXT2_NODUMP_FL, 'd' }, | ||
97 | { EXT2_IMMUTABLE_FL, 'i' }, | ||
98 | { EXT3_JOURNAL_DATA_FL, 'j' }, | ||
99 | { EXT2_SECRM_FL, 's' }, | ||
100 | { EXT2_UNRM_FL, 'u' }, | ||
101 | { EXT2_NOTAIL_FL, 't' }, | ||
102 | { EXT2_TOPDIR_FL, 'T' }, | ||
103 | { 0, 0 } | ||
104 | }; | ||
105 | |||
106 | static unsigned long get_flag(char c) | ||
107 | { | ||
108 | const struct flags_char *fp; | ||
109 | |||
110 | for (fp = flags_array; fp->flag != 0; fp++) { | ||
111 | if (fp->optchar == c) | ||
112 | return fp->flag; | ||
113 | } | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | |||
118 | static int decode_arg (int * i, int argc, char ** argv) | ||
119 | { | ||
120 | char * p; | ||
121 | char * tmp; | ||
122 | unsigned long fl; | ||
123 | |||
124 | switch (argv[*i][0]) | ||
125 | { | ||
126 | case '-': | ||
127 | for (p = &argv[*i][1]; *p; p++) { | ||
128 | if (*p == 'R') { | ||
129 | recursive = 1; | ||
130 | continue; | ||
131 | } | ||
132 | if (*p == 'V') { | ||
133 | verbose = 1; | ||
134 | continue; | ||
135 | } | ||
136 | if (*p == 'v') { | ||
137 | (*i)++; | ||
138 | if (*i >= argc) | ||
139 | usage (); | ||
140 | version = strtol (argv[*i], &tmp, 0); | ||
141 | if (*tmp) { | ||
142 | com_err (program_name, 0, | ||
143 | _("bad version - %s\n"), | ||
144 | argv[*i]); | ||
145 | usage (); | ||
146 | } | ||
147 | set_version = 1; | ||
148 | continue; | ||
149 | } | ||
150 | if ((fl = get_flag(*p)) == 0) | ||
151 | usage(); | ||
152 | rf |= fl; | ||
153 | rem = 1; | ||
154 | } | ||
155 | break; | ||
156 | case '+': | ||
157 | add = 1; | ||
158 | for (p = &argv[*i][1]; *p; p++) { | ||
159 | if ((fl = get_flag(*p)) == 0) | ||
160 | usage(); | ||
161 | af |= fl; | ||
162 | } | ||
163 | break; | ||
164 | case '=': | ||
165 | set = 1; | ||
166 | for (p = &argv[*i][1]; *p; p++) { | ||
167 | if ((fl = get_flag(*p)) == 0) | ||
168 | usage(); | ||
169 | sf |= fl; | ||
170 | } | ||
171 | break; | ||
172 | default: | ||
173 | return EOF; | ||
174 | break; | ||
175 | } | ||
176 | return 1; | ||
177 | } | ||
178 | |||
179 | static int chattr_dir_proc (const char *, struct dirent *, void *); | ||
180 | |||
181 | static void change_attributes (const char * name) | ||
182 | { | ||
183 | unsigned long flags; | ||
184 | STRUCT_STAT st; | ||
185 | |||
186 | if (LSTAT (name, &st) == -1) { | ||
187 | com_err (program_name, errno, _("while trying to stat %s"), | ||
188 | name); | ||
189 | return; | ||
190 | } | ||
191 | if (S_ISLNK(st.st_mode) && recursive) | ||
192 | return; | ||
193 | |||
194 | /* Don't try to open device files, fifos etc. We probably | ||
195 | ought to display an error if the file was explicitly given | ||
196 | on the command line (whether or not recursive was | ||
197 | requested). */ | ||
198 | if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && | ||
199 | !S_ISDIR(st.st_mode)) | ||
200 | return; | ||
201 | |||
202 | if (set) { | ||
203 | if (verbose) { | ||
204 | printf (_("Flags of %s set as "), name); | ||
205 | print_flags (stdout, sf, 0); | ||
206 | printf ("\n"); | ||
207 | } | ||
208 | if (fsetflags (name, sf) == -1) | ||
209 | perror (name); | ||
210 | } else { | ||
211 | if (fgetflags (name, &flags) == -1) | ||
212 | com_err (program_name, errno, | ||
213 | _("while reading flags on %s"), name); | ||
214 | else { | ||
215 | if (rem) | ||
216 | flags &= ~rf; | ||
217 | if (add) | ||
218 | flags |= af; | ||
219 | if (verbose) { | ||
220 | printf (_("Flags of %s set as "), name); | ||
221 | print_flags (stdout, flags, 0); | ||
222 | printf ("\n"); | ||
223 | } | ||
224 | if (!S_ISDIR(st.st_mode)) | ||
225 | flags &= ~EXT2_DIRSYNC_FL; | ||
226 | if (fsetflags (name, flags) == -1) | ||
227 | com_err (program_name, errno, | ||
228 | _("while setting flags on %s"), name); | ||
229 | } | ||
230 | } | ||
231 | if (set_version) { | ||
232 | if (verbose) | ||
233 | printf (_("Version of %s set as %lu\n"), name, version); | ||
234 | if (fsetversion (name, version) == -1) | ||
235 | com_err (program_name, errno, | ||
236 | _("while setting version on %s"), name); | ||
237 | } | ||
238 | if (S_ISDIR(st.st_mode) && recursive) | ||
239 | iterate_on_dir (name, chattr_dir_proc, NULL); | ||
240 | } | ||
241 | |||
242 | static int chattr_dir_proc (const char * dir_name, struct dirent * de, | ||
243 | void * private EXT2FS_ATTR((unused))) | ||
244 | { | ||
245 | if (strcmp (de->d_name, ".") && strcmp (de->d_name, "..")) { | ||
246 | char *path; | ||
247 | |||
248 | path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1); | ||
249 | if (!path) | ||
250 | fatal_error(_("Couldn't allocate path variable " | ||
251 | "in chattr_dir_proc"), 1); | ||
252 | sprintf (path, "%s/%s", dir_name, de->d_name); | ||
253 | change_attributes (path); | ||
254 | free(path); | ||
255 | } | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | int main (int argc, char ** argv) | ||
260 | { | ||
261 | int i, j; | ||
262 | int end_arg = 0; | ||
263 | |||
264 | #ifdef ENABLE_NLS | ||
265 | setlocale(LC_MESSAGES, ""); | ||
266 | setlocale(LC_CTYPE, ""); | ||
267 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); | ||
268 | textdomain(NLS_CAT_NAME); | ||
269 | #endif | ||
270 | #if 0 | ||
271 | if (argc && *argv) | ||
272 | program_name = *argv; | ||
273 | #endif | ||
274 | i = 1; | ||
275 | while (i < argc && !end_arg) { | ||
276 | /* '--' arg should end option processing */ | ||
277 | if (strcmp(argv[i], "--") == 0) { | ||
278 | i++; | ||
279 | end_arg = 1; | ||
280 | } else if (decode_arg (&i, argc, argv) == EOF) | ||
281 | end_arg = 1; | ||
282 | else | ||
283 | i++; | ||
284 | } | ||
285 | if (i >= argc) | ||
286 | usage (); | ||
287 | if (set && (add || rem)) { | ||
288 | fputs(_("= is incompatible with - and +\n"), stderr); | ||
289 | exit (1); | ||
290 | } | ||
291 | if ((rf & af) != 0) { | ||
292 | fputs("Can't both set and unset same flag.\n", stderr); | ||
293 | exit (1); | ||
294 | } | ||
295 | if (!(add || rem || set || set_version)) { | ||
296 | fputs(_("Must use '-v', =, - or +\n"), stderr); | ||
297 | exit (1); | ||
298 | } | ||
299 | #if 0 | ||
300 | if (verbose) | ||
301 | fprintf (stderr, "chattr %s (%s)\n", | ||
302 | E2FSPROGS_VERSION, E2FSPROGS_DATE); | ||
303 | #endif | ||
304 | for (j = i; j < argc; j++) | ||
305 | change_attributes (argv[j]); | ||
306 | exit(0); | ||
307 | } | ||
diff --git a/util-linux/e2p/README b/util-linux/e2p/README deleted file mode 100644 index 5a3318420..000000000 --- a/util-linux/e2p/README +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | ------ | ||
2 | ABOUT: | ||
3 | ------ | ||
4 | |||
5 | This is a straight rip from the e2fsprogs pkg. | ||
6 | |||
7 | These files are used to support other misc progs ripped out of e2fsprogs | ||
8 | and included in busybox. | ||
9 | |||
10 | ------- | ||
11 | UPDATE: | ||
12 | ------- | ||
13 | |||
14 | Simply copy the 'e2p' dir from e2fsprogs/lib/ and then delete the extra | ||
15 | files we don't need (Makefile.in, e2p.pc.in, etc...). Update the e2p.h | ||
16 | file to look for "../ext2_fs.h" instead of <ext2fs/ext2_fs.h>. Finally, | ||
17 | remove the _LARGEFILE* define's from the few source files that use it | ||
18 | since we'll be appending it ourselves to CFLAGS when we compile. | ||
19 | |||
20 | ------ | ||
21 | STAMP: | ||
22 | ------ | ||
23 | |||
24 | Last ripped from the e2fsprogs-1.37 release. | ||
diff --git a/util-linux/e2p/e2p.h b/util-linux/e2p/e2p.h deleted file mode 100644 index 40c9fa25a..000000000 --- a/util-linux/e2p/e2p.h +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | #include <sys/types.h> /* Needed by dirent.h on netbsd */ | ||
2 | #include <stdio.h> | ||
3 | #include <dirent.h> | ||
4 | |||
5 | #include "../ext2_fs.h" | ||
6 | |||
7 | #define E2P_FEATURE_COMPAT 0 | ||
8 | #define E2P_FEATURE_INCOMPAT 1 | ||
9 | #define E2P_FEATURE_RO_INCOMPAT 2 | ||
10 | |||
11 | |||
12 | /* `options' for print_flags() */ | ||
13 | |||
14 | #define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */ | ||
15 | |||
16 | |||
17 | int fgetflags (const char * name, unsigned long * flags); | ||
18 | int fgetversion (const char * name, unsigned long * version); | ||
19 | int fsetflags (const char * name, unsigned long flags); | ||
20 | int fsetversion (const char * name, unsigned long version); | ||
21 | int getflags (int fd, unsigned long * flags); | ||
22 | int getversion (int fd, unsigned long * version); | ||
23 | int iterate_on_dir (const char * dir_name, | ||
24 | int (*func) (const char *, struct dirent *, void *), | ||
25 | void * private); | ||
26 | void list_super(struct ext2_super_block * s); | ||
27 | void list_super2(struct ext2_super_block * s, FILE *f); | ||
28 | void print_fs_errors (FILE * f, unsigned short errors); | ||
29 | void print_flags (FILE * f, unsigned long flags, unsigned options); | ||
30 | void print_fs_state (FILE * f, unsigned short state); | ||
31 | int setflags (int fd, unsigned long flags); | ||
32 | int setversion (int fd, unsigned long version); | ||
33 | |||
34 | const char *e2p_feature2string(int compat, unsigned int mask); | ||
35 | int e2p_string2feature(char *string, int *compat, unsigned int *mask); | ||
36 | int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array); | ||
37 | |||
38 | int e2p_is_null_uuid(void *uu); | ||
39 | void e2p_uuid_to_str(void *uu, char *out); | ||
40 | const char *e2p_uuid2str(void *uu); | ||
41 | |||
42 | const char *e2p_hash2string(int num); | ||
43 | int e2p_string2hash(char *string); | ||
44 | |||
45 | const char *e2p_mntopt2string(unsigned int mask); | ||
46 | int e2p_string2mntopt(char *string, unsigned int *mask); | ||
47 | int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok); | ||
48 | |||
49 | unsigned long parse_num_blocks(const char *arg, int log_block_size); | ||
50 | |||
51 | char *e2p_os2string(int os_type); | ||
52 | int e2p_string2os(char *str); | ||
diff --git a/util-linux/e2p/feature.c b/util-linux/e2p/feature.c deleted file mode 100644 index ef11d93b7..000000000 --- a/util-linux/e2p/feature.c +++ /dev/null | |||
@@ -1,190 +0,0 @@ | |||
1 | /* | ||
2 | * feature.c --- convert between features and strings | ||
3 | * | ||
4 | * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu> | ||
5 | * | ||
6 | * This file can be redistributed under the terms of the GNU Library General | ||
7 | * Public License | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #include <stdio.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <string.h> | ||
14 | #include <ctype.h> | ||
15 | #include <errno.h> | ||
16 | |||
17 | #include "e2p.h" | ||
18 | |||
19 | struct feature { | ||
20 | int compat; | ||
21 | unsigned int mask; | ||
22 | const char *string; | ||
23 | }; | ||
24 | |||
25 | static struct feature feature_list[] = { | ||
26 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_PREALLOC, | ||
27 | "dir_prealloc" }, | ||
28 | { E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL, | ||
29 | "has_journal" }, | ||
30 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_IMAGIC_INODES, | ||
31 | "imagic_inodes" }, | ||
32 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_EXT_ATTR, | ||
33 | "ext_attr" }, | ||
34 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX, | ||
35 | "dir_index" }, | ||
36 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INODE, | ||
37 | "resize_inode" }, | ||
38 | { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER, | ||
39 | "sparse_super" }, | ||
40 | { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE, | ||
41 | "large_file" }, | ||
42 | { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION, | ||
43 | "compression" }, | ||
44 | { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE, | ||
45 | "filetype" }, | ||
46 | { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER, | ||
47 | "needs_recovery" }, | ||
48 | { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_JOURNAL_DEV, | ||
49 | "journal_dev" }, | ||
50 | { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS, | ||
51 | "extents" }, | ||
52 | { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_META_BG, | ||
53 | "meta_bg" }, | ||
54 | { 0, 0, 0 }, | ||
55 | }; | ||
56 | |||
57 | const char *e2p_feature2string(int compat, unsigned int mask) | ||
58 | { | ||
59 | struct feature *f; | ||
60 | static char buf[20]; | ||
61 | char fchar; | ||
62 | int fnum; | ||
63 | |||
64 | for (f = feature_list; f->string; f++) { | ||
65 | if ((compat == f->compat) && | ||
66 | (mask == f->mask)) | ||
67 | return f->string; | ||
68 | } | ||
69 | switch (compat) { | ||
70 | case E2P_FEATURE_COMPAT: | ||
71 | fchar = 'C'; | ||
72 | break; | ||
73 | case E2P_FEATURE_INCOMPAT: | ||
74 | fchar = 'I'; | ||
75 | break; | ||
76 | case E2P_FEATURE_RO_INCOMPAT: | ||
77 | fchar = 'R'; | ||
78 | break; | ||
79 | default: | ||
80 | fchar = '?'; | ||
81 | break; | ||
82 | } | ||
83 | for (fnum = 0; mask >>= 1; fnum++); | ||
84 | sprintf(buf, "FEATURE_%c%d", fchar, fnum); | ||
85 | return buf; | ||
86 | } | ||
87 | |||
88 | int e2p_string2feature(char *string, int *compat_type, unsigned int *mask) | ||
89 | { | ||
90 | struct feature *f; | ||
91 | char *eptr; | ||
92 | int num; | ||
93 | |||
94 | for (f = feature_list; f->string; f++) { | ||
95 | if (!strcasecmp(string, f->string)) { | ||
96 | *compat_type = f->compat; | ||
97 | *mask = f->mask; | ||
98 | return 0; | ||
99 | } | ||
100 | } | ||
101 | if (strncasecmp(string, "FEATURE_", 8)) | ||
102 | return 1; | ||
103 | |||
104 | switch (string[8]) { | ||
105 | case 'c': | ||
106 | case 'C': | ||
107 | *compat_type = E2P_FEATURE_COMPAT; | ||
108 | break; | ||
109 | case 'i': | ||
110 | case 'I': | ||
111 | *compat_type = E2P_FEATURE_INCOMPAT; | ||
112 | break; | ||
113 | case 'r': | ||
114 | case 'R': | ||
115 | *compat_type = E2P_FEATURE_RO_INCOMPAT; | ||
116 | break; | ||
117 | default: | ||
118 | return 1; | ||
119 | } | ||
120 | if (string[9] == 0) | ||
121 | return 1; | ||
122 | num = strtol(string+9, &eptr, 10); | ||
123 | if (num > 32 || num < 0) | ||
124 | return 1; | ||
125 | if (*eptr) | ||
126 | return 1; | ||
127 | *mask = 1 << num; | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | static char *skip_over_blanks(char *cp) | ||
132 | { | ||
133 | while (*cp && isspace(*cp)) | ||
134 | cp++; | ||
135 | return cp; | ||
136 | } | ||
137 | |||
138 | static char *skip_over_word(char *cp) | ||
139 | { | ||
140 | while (*cp && !isspace(*cp) && *cp != ',') | ||
141 | cp++; | ||
142 | return cp; | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * Edit a feature set array as requested by the user. The ok_array, | ||
147 | * if set, allows the application to limit what features the user is | ||
148 | * allowed to set or clear using this function. | ||
149 | */ | ||
150 | int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array) | ||
151 | { | ||
152 | char *cp, *buf, *next; | ||
153 | int neg; | ||
154 | unsigned int mask; | ||
155 | int compat_type; | ||
156 | |||
157 | buf = malloc(strlen(str)+1); | ||
158 | if (!buf) | ||
159 | return 1; | ||
160 | strcpy(buf, str); | ||
161 | cp = buf; | ||
162 | while (cp && *cp) { | ||
163 | neg = 0; | ||
164 | cp = skip_over_blanks(cp); | ||
165 | next = skip_over_word(cp); | ||
166 | if (*next == 0) | ||
167 | next = 0; | ||
168 | else | ||
169 | *next = 0; | ||
170 | switch (*cp) { | ||
171 | case '-': | ||
172 | case '^': | ||
173 | neg++; | ||
174 | case '+': | ||
175 | cp++; | ||
176 | break; | ||
177 | } | ||
178 | if (e2p_string2feature(cp, &compat_type, &mask)) | ||
179 | return 1; | ||
180 | if (ok_array && !(ok_array[compat_type] & mask)) | ||
181 | return 1; | ||
182 | if (neg) | ||
183 | compat_array[compat_type] &= ~mask; | ||
184 | else | ||
185 | compat_array[compat_type] |= mask; | ||
186 | cp = next ? next+1 : 0; | ||
187 | } | ||
188 | return 0; | ||
189 | } | ||
190 | |||
diff --git a/util-linux/e2p/fgetflags.c b/util-linux/e2p/fgetflags.c deleted file mode 100644 index 6db729e08..000000000 --- a/util-linux/e2p/fgetflags.c +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | /* | ||
2 | * fgetflags.c - Get a file flags on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #if HAVE_UNISTD_H | ||
21 | #include <unistd.h> | ||
22 | #endif | ||
23 | #include <sys/types.h> | ||
24 | #include <sys/stat.h> | ||
25 | #if HAVE_EXT2_IOCTLS | ||
26 | #include <fcntl.h> | ||
27 | #include <sys/ioctl.h> | ||
28 | #endif | ||
29 | |||
30 | #include "e2p.h" | ||
31 | |||
32 | #ifdef O_LARGEFILE | ||
33 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) | ||
34 | #else | ||
35 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) | ||
36 | #endif | ||
37 | |||
38 | int fgetflags (const char * name, unsigned long * flags) | ||
39 | { | ||
40 | struct stat buf; | ||
41 | #if HAVE_STAT_FLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS) | ||
42 | |||
43 | if (stat (name, &buf) == -1) | ||
44 | return -1; | ||
45 | |||
46 | *flags = 0; | ||
47 | #ifdef UF_IMMUTABLE | ||
48 | if (buf.st_flags & UF_IMMUTABLE) | ||
49 | *flags |= EXT2_IMMUTABLE_FL; | ||
50 | #endif | ||
51 | #ifdef UF_APPEND | ||
52 | if (buf.st_flags & UF_APPEND) | ||
53 | *flags |= EXT2_APPEND_FL; | ||
54 | #endif | ||
55 | #ifdef UF_NODUMP | ||
56 | if (buf.st_flags & UF_NODUMP) | ||
57 | *flags |= EXT2_NODUMP_FL; | ||
58 | #endif | ||
59 | |||
60 | return 0; | ||
61 | #else | ||
62 | #if HAVE_EXT2_IOCTLS | ||
63 | int fd, r, f, save_errno = 0; | ||
64 | |||
65 | if (!stat(name, &buf) && | ||
66 | !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { | ||
67 | goto notsupp; | ||
68 | } | ||
69 | #if !APPLE_DARWIN | ||
70 | fd = open (name, OPEN_FLAGS); | ||
71 | if (fd == -1) | ||
72 | return -1; | ||
73 | r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); | ||
74 | if (r == -1) | ||
75 | save_errno = errno; | ||
76 | *flags = f; | ||
77 | close (fd); | ||
78 | if (save_errno) | ||
79 | errno = save_errno; | ||
80 | return r; | ||
81 | #else | ||
82 | f = -1; | ||
83 | save_errno = syscall(SYS_fsctl, name, EXT2_IOC_GETFLAGS, &f, 0); | ||
84 | *flags = f; | ||
85 | return (save_errno); | ||
86 | #endif | ||
87 | #endif /* HAVE_EXT2_IOCTLS */ | ||
88 | #endif | ||
89 | notsupp: | ||
90 | errno = EOPNOTSUPP; | ||
91 | return -1; | ||
92 | } | ||
diff --git a/util-linux/e2p/fgetversion.c b/util-linux/e2p/fgetversion.c deleted file mode 100644 index 351a7d5d0..000000000 --- a/util-linux/e2p/fgetversion.c +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | /* | ||
2 | * fgetversion.c - Get a file version on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #if HAVE_UNISTD_H | ||
21 | #include <unistd.h> | ||
22 | #endif | ||
23 | #include <fcntl.h> | ||
24 | #include <sys/ioctl.h> | ||
25 | |||
26 | #include "e2p.h" | ||
27 | |||
28 | #ifdef O_LARGEFILE | ||
29 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) | ||
30 | #else | ||
31 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) | ||
32 | #endif | ||
33 | |||
34 | int fgetversion (const char * name, unsigned long * version) | ||
35 | { | ||
36 | #if HAVE_EXT2_IOCTLS | ||
37 | #if !APPLE_DARWIN | ||
38 | int fd, r, ver, save_errno = 0; | ||
39 | |||
40 | fd = open (name, OPEN_FLAGS); | ||
41 | if (fd == -1) | ||
42 | return -1; | ||
43 | r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); | ||
44 | if (r == -1) | ||
45 | save_errno = errno; | ||
46 | *version = ver; | ||
47 | close (fd); | ||
48 | if (save_errno) | ||
49 | errno = save_errno; | ||
50 | return r; | ||
51 | #else | ||
52 | int ver=-1, err; | ||
53 | err = syscall(SYS_fsctl, name, EXT2_IOC_GETVERSION, &ver, 0); | ||
54 | *version = ver; | ||
55 | return(err); | ||
56 | #endif | ||
57 | #else /* ! HAVE_EXT2_IOCTLS */ | ||
58 | extern int errno; | ||
59 | errno = EOPNOTSUPP; | ||
60 | return -1; | ||
61 | #endif /* ! HAVE_EXT2_IOCTLS */ | ||
62 | } | ||
diff --git a/util-linux/e2p/fsetflags.c b/util-linux/e2p/fsetflags.c deleted file mode 100644 index 40e7292dd..000000000 --- a/util-linux/e2p/fsetflags.c +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | /* | ||
2 | * fsetflags.c - Set a file flags on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #if HAVE_UNISTD_H | ||
21 | #include <unistd.h> | ||
22 | #endif | ||
23 | #include <sys/types.h> | ||
24 | #include <sys/stat.h> | ||
25 | #if HAVE_EXT2_IOCTLS | ||
26 | #include <fcntl.h> | ||
27 | #include <sys/ioctl.h> | ||
28 | #endif | ||
29 | |||
30 | #include "e2p.h" | ||
31 | |||
32 | /* | ||
33 | * Deal with lame glibc's that define this function without actually | ||
34 | * implementing it. Can you say "attractive nuisance", boys and girls? | ||
35 | * I knew you could! | ||
36 | */ | ||
37 | #ifdef __linux__ | ||
38 | #undef HAVE_CHFLAGS | ||
39 | #endif | ||
40 | |||
41 | #ifdef O_LARGEFILE | ||
42 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) | ||
43 | #else | ||
44 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) | ||
45 | #endif | ||
46 | |||
47 | int fsetflags (const char * name, unsigned long flags) | ||
48 | { | ||
49 | struct stat buf; | ||
50 | #if HAVE_CHFLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS) | ||
51 | unsigned long bsd_flags = 0; | ||
52 | |||
53 | #ifdef UF_IMMUTABLE | ||
54 | if (flags & EXT2_IMMUTABLE_FL) | ||
55 | bsd_flags |= UF_IMMUTABLE; | ||
56 | #endif | ||
57 | #ifdef UF_APPEND | ||
58 | if (flags & EXT2_APPEND_FL) | ||
59 | bsd_flags |= UF_APPEND; | ||
60 | #endif | ||
61 | #ifdef UF_NODUMP | ||
62 | if (flags & EXT2_NODUMP_FL) | ||
63 | bsd_flags |= UF_NODUMP; | ||
64 | #endif | ||
65 | |||
66 | return chflags (name, bsd_flags); | ||
67 | #else | ||
68 | #if HAVE_EXT2_IOCTLS | ||
69 | int fd, r, f, save_errno = 0; | ||
70 | |||
71 | if (!stat(name, &buf) && | ||
72 | !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { | ||
73 | goto notsupp; | ||
74 | } | ||
75 | #if !APPLE_DARWIN | ||
76 | fd = open (name, OPEN_FLAGS); | ||
77 | if (fd == -1) | ||
78 | return -1; | ||
79 | f = (int) flags; | ||
80 | r = ioctl (fd, EXT2_IOC_SETFLAGS, &f); | ||
81 | if (r == -1) | ||
82 | save_errno = errno; | ||
83 | close (fd); | ||
84 | if (save_errno) | ||
85 | errno = save_errno; | ||
86 | #else | ||
87 | f = (int) flags; | ||
88 | return syscall(SYS_fsctl, name, EXT2_IOC_SETFLAGS, &f, 0); | ||
89 | #endif | ||
90 | return r; | ||
91 | #endif /* HAVE_EXT2_IOCTLS */ | ||
92 | #endif | ||
93 | notsupp: | ||
94 | errno = EOPNOTSUPP; | ||
95 | return -1; | ||
96 | } | ||
diff --git a/util-linux/e2p/fsetversion.c b/util-linux/e2p/fsetversion.c deleted file mode 100644 index 93243d6e0..000000000 --- a/util-linux/e2p/fsetversion.c +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | /* | ||
2 | * fsetversion.c - Set a file version on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #if HAVE_UNISTD_H | ||
21 | #include <unistd.h> | ||
22 | #endif | ||
23 | #include <fcntl.h> | ||
24 | #include <sys/ioctl.h> | ||
25 | |||
26 | #include "e2p.h" | ||
27 | |||
28 | #ifdef O_LARGEFILE | ||
29 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) | ||
30 | #else | ||
31 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) | ||
32 | #endif | ||
33 | |||
34 | int fsetversion (const char * name, unsigned long version) | ||
35 | { | ||
36 | #if HAVE_EXT2_IOCTLS | ||
37 | #if !APPLE_DARWIN | ||
38 | int fd, r, ver, save_errno = 0; | ||
39 | |||
40 | fd = open (name, OPEN_FLAGS); | ||
41 | if (fd == -1) | ||
42 | return -1; | ||
43 | ver = (int) version; | ||
44 | r = ioctl (fd, EXT2_IOC_SETVERSION, &ver); | ||
45 | if (r == -1) | ||
46 | save_errno = errno; | ||
47 | close (fd); | ||
48 | if (save_errno) | ||
49 | errno = save_errno; | ||
50 | return r; | ||
51 | #else | ||
52 | int ver = (int)version; | ||
53 | return syscall(SYS_fsctl, name, EXT2_IOC_SETVERSION, &ver, 0); | ||
54 | #endif | ||
55 | #else /* ! HAVE_EXT2_IOCTLS */ | ||
56 | extern int errno; | ||
57 | errno = EOPNOTSUPP; | ||
58 | return -1; | ||
59 | #endif /* ! HAVE_EXT2_IOCTLS */ | ||
60 | } | ||
diff --git a/util-linux/e2p/getflags.c b/util-linux/e2p/getflags.c deleted file mode 100644 index acf7a122b..000000000 --- a/util-linux/e2p/getflags.c +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* | ||
2 | * getflags.c - Get a file flags on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #include <sys/types.h> | ||
21 | #include <sys/stat.h> | ||
22 | #if HAVE_EXT2_IOCTLS | ||
23 | #include <sys/ioctl.h> | ||
24 | #endif | ||
25 | |||
26 | #include "e2p.h" | ||
27 | |||
28 | int getflags (int fd, unsigned long * flags) | ||
29 | { | ||
30 | struct stat buf; | ||
31 | #if HAVE_STAT_FLAGS | ||
32 | |||
33 | if (fstat (fd, &buf) == -1) | ||
34 | return -1; | ||
35 | |||
36 | *flags = 0; | ||
37 | #ifdef UF_IMMUTABLE | ||
38 | if (buf.st_flags & UF_IMMUTABLE) | ||
39 | *flags |= EXT2_IMMUTABLE_FL; | ||
40 | #endif | ||
41 | #ifdef UF_APPEND | ||
42 | if (buf.st_flags & UF_APPEND) | ||
43 | *flags |= EXT2_APPEND_FL; | ||
44 | #endif | ||
45 | #ifdef UF_NODUMP | ||
46 | if (buf.st_flags & UF_NODUMP) | ||
47 | *flags |= EXT2_NODUMP_FL; | ||
48 | #endif | ||
49 | |||
50 | return 0; | ||
51 | #else | ||
52 | #if HAVE_EXT2_IOCTLS | ||
53 | int r, f; | ||
54 | |||
55 | if (!fstat(fd, &buf) && | ||
56 | !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) | ||
57 | goto notsupp; | ||
58 | r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); | ||
59 | *flags = f; | ||
60 | return r; | ||
61 | #endif /* HAVE_EXT2_IOCTLS */ | ||
62 | #endif | ||
63 | notsupp: | ||
64 | errno = EOPNOTSUPP; | ||
65 | return -1; | ||
66 | } | ||
diff --git a/util-linux/e2p/getversion.c b/util-linux/e2p/getversion.c deleted file mode 100644 index 38b7d0fb0..000000000 --- a/util-linux/e2p/getversion.c +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | /* | ||
2 | * getversion.c - Get a file version on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #include <sys/ioctl.h> | ||
21 | |||
22 | #include "e2p.h" | ||
23 | |||
24 | int getversion (int fd, unsigned long * version) | ||
25 | { | ||
26 | #if HAVE_EXT2_IOCTLS | ||
27 | int r, ver; | ||
28 | |||
29 | r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); | ||
30 | *version = ver; | ||
31 | return 0; | ||
32 | #else /* ! HAVE_EXT2_IOCTLS */ | ||
33 | extern int errno; | ||
34 | errno = EOPNOTSUPP; | ||
35 | return -1; | ||
36 | #endif /* ! HAVE_EXT2_IOCTLS */ | ||
37 | } | ||
diff --git a/util-linux/e2p/hashstr.c b/util-linux/e2p/hashstr.c deleted file mode 100644 index b257eb26c..000000000 --- a/util-linux/e2p/hashstr.c +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* | ||
2 | * feature.c --- convert between features and strings | ||
3 | * | ||
4 | * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu> | ||
5 | * | ||
6 | * This file can be redistributed under the terms of the GNU Library General | ||
7 | * Public License | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #include <stdio.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <string.h> | ||
14 | #include <ctype.h> | ||
15 | #include <errno.h> | ||
16 | |||
17 | #include "e2p.h" | ||
18 | |||
19 | struct hash { | ||
20 | int num; | ||
21 | const char *string; | ||
22 | }; | ||
23 | |||
24 | static struct hash hash_list[] = { | ||
25 | { EXT2_HASH_LEGACY, "legacy" }, | ||
26 | { EXT2_HASH_HALF_MD4, "half_md4" }, | ||
27 | { EXT2_HASH_TEA, "tea" }, | ||
28 | { 0, 0 }, | ||
29 | }; | ||
30 | |||
31 | const char *e2p_hash2string(int num) | ||
32 | { | ||
33 | struct hash *p; | ||
34 | static char buf[20]; | ||
35 | |||
36 | for (p = hash_list; p->string; p++) { | ||
37 | if (num == p->num) | ||
38 | return p->string; | ||
39 | } | ||
40 | sprintf(buf, "HASHALG_%d", num); | ||
41 | return buf; | ||
42 | } | ||
43 | |||
44 | /* | ||
45 | * Returns the hash algorithm, or -1 on error | ||
46 | */ | ||
47 | int e2p_string2hash(char *string) | ||
48 | { | ||
49 | struct hash *p; | ||
50 | char *eptr; | ||
51 | int num; | ||
52 | |||
53 | for (p = hash_list; p->string; p++) { | ||
54 | if (!strcasecmp(string, p->string)) { | ||
55 | return p->num; | ||
56 | } | ||
57 | } | ||
58 | if (strncasecmp(string, "HASHALG_", 8)) | ||
59 | return -1; | ||
60 | |||
61 | if (string[8] == 0) | ||
62 | return -1; | ||
63 | num = strtol(string+8, &eptr, 10); | ||
64 | if (num > 255 || num < 0) | ||
65 | return -1; | ||
66 | if (*eptr) | ||
67 | return -1; | ||
68 | return num; | ||
69 | } | ||
70 | |||
diff --git a/util-linux/e2p/iod.c b/util-linux/e2p/iod.c deleted file mode 100644 index 808d3a39d..000000000 --- a/util-linux/e2p/iod.c +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | /* | ||
2 | * iod.c - Iterate a function on each entry of a directory | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #include "e2p.h" | ||
18 | #if HAVE_UNISTD_H | ||
19 | #include <unistd.h> | ||
20 | #endif | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | |||
24 | int iterate_on_dir (const char * dir_name, | ||
25 | int (*func) (const char *, struct dirent *, void *), | ||
26 | void * private) | ||
27 | { | ||
28 | DIR * dir; | ||
29 | struct dirent *de, *dep; | ||
30 | int max_len = -1, len; | ||
31 | |||
32 | #if HAVE_PATHCONF && defined(_PC_NAME_MAX) | ||
33 | max_len = pathconf(dir_name, _PC_NAME_MAX); | ||
34 | #endif | ||
35 | if (max_len == -1) { | ||
36 | #ifdef _POSIX_NAME_MAX | ||
37 | max_len = _POSIX_NAME_MAX; | ||
38 | #else | ||
39 | #ifdef NAME_MAX | ||
40 | max_len = NAME_MAX; | ||
41 | #else | ||
42 | max_len = 256; | ||
43 | #endif /* NAME_MAX */ | ||
44 | #endif /* _POSIX_NAME_MAX */ | ||
45 | } | ||
46 | max_len += sizeof(struct dirent); | ||
47 | |||
48 | de = malloc(max_len+1); | ||
49 | if (!de) | ||
50 | return -1; | ||
51 | memset(de, 0, max_len+1); | ||
52 | |||
53 | dir = opendir (dir_name); | ||
54 | if (dir == NULL) { | ||
55 | free(de); | ||
56 | return -1; | ||
57 | } | ||
58 | while ((dep = readdir (dir))) { | ||
59 | len = sizeof(struct dirent); | ||
60 | #ifdef HAVE_RECLEN_DIRENT | ||
61 | if (len < dep->d_reclen) | ||
62 | len = dep->d_reclen; | ||
63 | if (len > max_len) | ||
64 | len = max_len; | ||
65 | #endif | ||
66 | memcpy(de, dep, len); | ||
67 | (*func) (dir_name, de, private); | ||
68 | } | ||
69 | free(de); | ||
70 | closedir(dir); | ||
71 | return 0; | ||
72 | } | ||
diff --git a/util-linux/e2p/ls.c b/util-linux/e2p/ls.c deleted file mode 100644 index e8d9d482d..000000000 --- a/util-linux/e2p/ls.c +++ /dev/null | |||
@@ -1,276 +0,0 @@ | |||
1 | /* | ||
2 | * ls.c - List the contents of an ext2fs superblock | ||
3 | * | ||
4 | * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * Copyright (C) 1995, 1996, 1997 Theodore Ts'o <tytso@mit.edu> | ||
9 | * | ||
10 | * This file can be redistributed under the terms of the GNU Library General | ||
11 | * Public License | ||
12 | */ | ||
13 | |||
14 | #include <stdio.h> | ||
15 | #include <sys/types.h> | ||
16 | #include <string.h> | ||
17 | #include <grp.h> | ||
18 | #include <pwd.h> | ||
19 | #include <time.h> | ||
20 | |||
21 | #include "e2p.h" | ||
22 | |||
23 | static void print_user (unsigned short uid, FILE *f) | ||
24 | { | ||
25 | struct passwd *pw; | ||
26 | |||
27 | fprintf(f, "%u ", uid); | ||
28 | pw = getpwuid (uid); | ||
29 | if (pw == NULL) | ||
30 | fprintf(f, "(user unknown)\n"); | ||
31 | else | ||
32 | fprintf(f, "(user %s)\n", pw->pw_name); | ||
33 | } | ||
34 | |||
35 | static void print_group (unsigned short gid, FILE *f) | ||
36 | { | ||
37 | struct group *gr; | ||
38 | |||
39 | fprintf(f, "%u ", gid); | ||
40 | gr = getgrgid (gid); | ||
41 | if (gr == NULL) | ||
42 | fprintf(f, "(group unknown)\n"); | ||
43 | else | ||
44 | fprintf(f, "(group %s)\n", gr->gr_name); | ||
45 | } | ||
46 | |||
47 | #define MONTH_INT (86400 * 30) | ||
48 | #define WEEK_INT (86400 * 7) | ||
49 | #define DAY_INT (86400) | ||
50 | #define HOUR_INT (60 * 60) | ||
51 | #define MINUTE_INT (60) | ||
52 | |||
53 | static const char *interval_string(unsigned int secs) | ||
54 | { | ||
55 | static char buf[256], tmp[80]; | ||
56 | int hr, min, num; | ||
57 | |||
58 | buf[0] = 0; | ||
59 | |||
60 | if (secs == 0) | ||
61 | return "<none>"; | ||
62 | |||
63 | if (secs >= MONTH_INT) { | ||
64 | num = secs / MONTH_INT; | ||
65 | secs -= num*MONTH_INT; | ||
66 | sprintf(buf, "%d month%s", num, (num>1) ? "s" : ""); | ||
67 | } | ||
68 | if (secs >= WEEK_INT) { | ||
69 | num = secs / WEEK_INT; | ||
70 | secs -= num*WEEK_INT; | ||
71 | sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "", | ||
72 | num, (num>1) ? "s" : ""); | ||
73 | strcat(buf, tmp); | ||
74 | } | ||
75 | if (secs >= DAY_INT) { | ||
76 | num = secs / DAY_INT; | ||
77 | secs -= num*DAY_INT; | ||
78 | sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "", | ||
79 | num, (num>1) ? "s" : ""); | ||
80 | strcat(buf, tmp); | ||
81 | } | ||
82 | if (secs > 0) { | ||
83 | hr = secs / HOUR_INT; | ||
84 | secs -= hr*HOUR_INT; | ||
85 | min = secs / MINUTE_INT; | ||
86 | secs -= min*MINUTE_INT; | ||
87 | sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "", | ||
88 | hr, min, secs); | ||
89 | strcat(buf, tmp); | ||
90 | } | ||
91 | return buf; | ||
92 | } | ||
93 | |||
94 | static void print_features(struct ext2_super_block * s, FILE *f) | ||
95 | { | ||
96 | #ifdef EXT2_DYNAMIC_REV | ||
97 | int i, j, printed=0; | ||
98 | __u32 *mask = &s->s_feature_compat, m; | ||
99 | |||
100 | fprintf(f, "Filesystem features: "); | ||
101 | for (i=0; i <3; i++,mask++) { | ||
102 | for (j=0,m=1; j < 32; j++, m<<=1) { | ||
103 | if (*mask & m) { | ||
104 | fprintf(f, " %s", e2p_feature2string(i, m)); | ||
105 | printed++; | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | if (printed == 0) | ||
110 | fprintf(f, " (none)"); | ||
111 | fprintf(f, "\n"); | ||
112 | #endif | ||
113 | } | ||
114 | |||
115 | static void print_mntopts(struct ext2_super_block * s, FILE *f) | ||
116 | { | ||
117 | #ifdef EXT2_DYNAMIC_REV | ||
118 | int i, printed=0; | ||
119 | __u32 mask = s->s_default_mount_opts, m; | ||
120 | |||
121 | fprintf(f, "Default mount options: "); | ||
122 | if (mask & EXT3_DEFM_JMODE) { | ||
123 | fprintf(f, " %s", e2p_mntopt2string(mask & EXT3_DEFM_JMODE)); | ||
124 | printed++; | ||
125 | } | ||
126 | for (i=0,m=1; i < 32; i++, m<<=1) { | ||
127 | if (m & EXT3_DEFM_JMODE) | ||
128 | continue; | ||
129 | if (mask & m) { | ||
130 | fprintf(f, " %s", e2p_mntopt2string(m)); | ||
131 | printed++; | ||
132 | } | ||
133 | } | ||
134 | if (printed == 0) | ||
135 | fprintf(f, " (none)"); | ||
136 | fprintf(f, "\n"); | ||
137 | #endif | ||
138 | } | ||
139 | |||
140 | |||
141 | #ifndef EXT2_INODE_SIZE | ||
142 | #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode) | ||
143 | #endif | ||
144 | |||
145 | #ifndef EXT2_GOOD_OLD_REV | ||
146 | #define EXT2_GOOD_OLD_REV 0 | ||
147 | #endif | ||
148 | |||
149 | void list_super2(struct ext2_super_block * sb, FILE *f) | ||
150 | { | ||
151 | int inode_blocks_per_group; | ||
152 | char buf[80], *str; | ||
153 | time_t tm; | ||
154 | |||
155 | inode_blocks_per_group = (((sb->s_inodes_per_group * | ||
156 | EXT2_INODE_SIZE(sb)) + | ||
157 | EXT2_BLOCK_SIZE(sb) - 1) / | ||
158 | EXT2_BLOCK_SIZE(sb)); | ||
159 | if (sb->s_volume_name[0]) { | ||
160 | memset(buf, 0, sizeof(buf)); | ||
161 | strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name)); | ||
162 | } else | ||
163 | strcpy(buf, "<none>"); | ||
164 | fprintf(f, "Filesystem volume name: %s\n", buf); | ||
165 | if (sb->s_last_mounted[0]) { | ||
166 | memset(buf, 0, sizeof(buf)); | ||
167 | strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted)); | ||
168 | } else | ||
169 | strcpy(buf, "<not available>"); | ||
170 | fprintf(f, "Last mounted on: %s\n", buf); | ||
171 | fprintf(f, "Filesystem UUID: %s\n", e2p_uuid2str(sb->s_uuid)); | ||
172 | fprintf(f, "Filesystem magic number: 0x%04X\n", sb->s_magic); | ||
173 | fprintf(f, "Filesystem revision #: %d", sb->s_rev_level); | ||
174 | if (sb->s_rev_level == EXT2_GOOD_OLD_REV) { | ||
175 | fprintf(f, " (original)\n"); | ||
176 | #ifdef EXT2_DYNAMIC_REV | ||
177 | } else if (sb->s_rev_level == EXT2_DYNAMIC_REV) { | ||
178 | fprintf(f, " (dynamic)\n"); | ||
179 | #endif | ||
180 | } else | ||
181 | fprintf(f, " (unknown)\n"); | ||
182 | print_features(sb, f); | ||
183 | print_mntopts(sb, f); | ||
184 | fprintf(f, "Filesystem state: "); | ||
185 | print_fs_state (f, sb->s_state); | ||
186 | fprintf(f, "\n"); | ||
187 | fprintf(f, "Errors behavior: "); | ||
188 | print_fs_errors(f, sb->s_errors); | ||
189 | fprintf(f, "\n"); | ||
190 | str = e2p_os2string(sb->s_creator_os); | ||
191 | fprintf(f, "Filesystem OS type: %s\n", str); | ||
192 | free(str); | ||
193 | fprintf(f, "Inode count: %u\n", sb->s_inodes_count); | ||
194 | fprintf(f, "Block count: %u\n", sb->s_blocks_count); | ||
195 | fprintf(f, "Reserved block count: %u\n", sb->s_r_blocks_count); | ||
196 | fprintf(f, "Free blocks: %u\n", sb->s_free_blocks_count); | ||
197 | fprintf(f, "Free inodes: %u\n", sb->s_free_inodes_count); | ||
198 | fprintf(f, "First block: %u\n", sb->s_first_data_block); | ||
199 | fprintf(f, "Block size: %u\n", EXT2_BLOCK_SIZE(sb)); | ||
200 | fprintf(f, "Fragment size: %u\n", EXT2_FRAG_SIZE(sb)); | ||
201 | if (sb->s_reserved_gdt_blocks) | ||
202 | fprintf(f, "Reserved GDT blocks: %u\n", | ||
203 | sb->s_reserved_gdt_blocks); | ||
204 | fprintf(f, "Blocks per group: %u\n", sb->s_blocks_per_group); | ||
205 | fprintf(f, "Fragments per group: %u\n", sb->s_frags_per_group); | ||
206 | fprintf(f, "Inodes per group: %u\n", sb->s_inodes_per_group); | ||
207 | fprintf(f, "Inode blocks per group: %u\n", inode_blocks_per_group); | ||
208 | if (sb->s_first_meta_bg) | ||
209 | fprintf(f, "First meta block group: %u\n", | ||
210 | sb->s_first_meta_bg); | ||
211 | if (sb->s_mkfs_time) { | ||
212 | tm = sb->s_mkfs_time; | ||
213 | fprintf(f, "Filesystem created: %s", ctime(&tm)); | ||
214 | } | ||
215 | tm = sb->s_mtime; | ||
216 | fprintf(f, "Last mount time: %s", | ||
217 | sb->s_mtime ? ctime(&tm) : "n/a\n"); | ||
218 | tm = sb->s_wtime; | ||
219 | fprintf(f, "Last write time: %s", ctime(&tm)); | ||
220 | fprintf(f, "Mount count: %u\n", sb->s_mnt_count); | ||
221 | fprintf(f, "Maximum mount count: %d\n", sb->s_max_mnt_count); | ||
222 | tm = sb->s_lastcheck; | ||
223 | fprintf(f, "Last checked: %s", ctime(&tm)); | ||
224 | fprintf(f, "Check interval: %u (%s)\n", sb->s_checkinterval, | ||
225 | interval_string(sb->s_checkinterval)); | ||
226 | if (sb->s_checkinterval) | ||
227 | { | ||
228 | time_t next; | ||
229 | |||
230 | next = sb->s_lastcheck + sb->s_checkinterval; | ||
231 | fprintf(f, "Next check after: %s", ctime(&next)); | ||
232 | } | ||
233 | fprintf(f, "Reserved blocks uid: "); | ||
234 | print_user(sb->s_def_resuid, f); | ||
235 | fprintf(f, "Reserved blocks gid: "); | ||
236 | print_group(sb->s_def_resgid, f); | ||
237 | if (sb->s_rev_level >= EXT2_DYNAMIC_REV) { | ||
238 | fprintf(f, "First inode: %d\n", sb->s_first_ino); | ||
239 | fprintf(f, "Inode size: %d\n", sb->s_inode_size); | ||
240 | } | ||
241 | if (!e2p_is_null_uuid(sb->s_journal_uuid)) | ||
242 | fprintf(f, "Journal UUID: %s\n", | ||
243 | e2p_uuid2str(sb->s_journal_uuid)); | ||
244 | if (sb->s_journal_inum) | ||
245 | fprintf(f, "Journal inode: %u\n", | ||
246 | sb->s_journal_inum); | ||
247 | if (sb->s_journal_dev) | ||
248 | fprintf(f, "Journal device: 0x%04x\n", | ||
249 | sb->s_journal_dev); | ||
250 | if (sb->s_last_orphan) | ||
251 | fprintf(f, "First orphan inode: %u\n", | ||
252 | sb->s_last_orphan); | ||
253 | if ((sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) || | ||
254 | sb->s_def_hash_version) | ||
255 | fprintf(f, "Default directory hash: %s\n", | ||
256 | e2p_hash2string(sb->s_def_hash_version)); | ||
257 | if (!e2p_is_null_uuid(sb->s_hash_seed)) | ||
258 | fprintf(f, "Directory Hash Seed: %s\n", | ||
259 | e2p_uuid2str(sb->s_hash_seed)); | ||
260 | if (sb->s_jnl_backup_type) { | ||
261 | fprintf(f, "Journal backup: "); | ||
262 | switch (sb->s_jnl_backup_type) { | ||
263 | case 1: | ||
264 | fprintf(f, "inode blocks\n"); | ||
265 | break; | ||
266 | default: | ||
267 | fprintf(f, "type %u\n", sb->s_jnl_backup_type); | ||
268 | } | ||
269 | } | ||
270 | } | ||
271 | |||
272 | void list_super (struct ext2_super_block * s) | ||
273 | { | ||
274 | list_super2(s, stdout); | ||
275 | } | ||
276 | |||
diff --git a/util-linux/e2p/mntopts.c b/util-linux/e2p/mntopts.c deleted file mode 100644 index 6d0eca0ae..000000000 --- a/util-linux/e2p/mntopts.c +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | /* | ||
2 | * mountopts.c --- convert between default mount options and strings | ||
3 | * | ||
4 | * Copyright (C) 2002 Theodore Ts'o <tytso@mit.edu> | ||
5 | * | ||
6 | * This file can be redistributed under the terms of the GNU Library General | ||
7 | * Public License | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #include <stdio.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <string.h> | ||
14 | #include <ctype.h> | ||
15 | #include <errno.h> | ||
16 | |||
17 | #include "e2p.h" | ||
18 | |||
19 | struct mntopt { | ||
20 | unsigned int mask; | ||
21 | const char *string; | ||
22 | }; | ||
23 | |||
24 | static struct mntopt mntopt_list[] = { | ||
25 | { EXT2_DEFM_DEBUG, "debug" }, | ||
26 | { EXT2_DEFM_BSDGROUPS, "bsdgroups" }, | ||
27 | { EXT2_DEFM_XATTR_USER, "user_xattr" }, | ||
28 | { EXT2_DEFM_ACL, "acl" }, | ||
29 | { EXT2_DEFM_UID16, "uid16" }, | ||
30 | { EXT3_DEFM_JMODE_DATA, "journal_data" }, | ||
31 | { EXT3_DEFM_JMODE_ORDERED, "journal_data_ordered" }, | ||
32 | { EXT3_DEFM_JMODE_WBACK, "journal_data_writeback" }, | ||
33 | { 0, 0 }, | ||
34 | }; | ||
35 | |||
36 | const char *e2p_mntopt2string(unsigned int mask) | ||
37 | { | ||
38 | struct mntopt *f; | ||
39 | static char buf[20]; | ||
40 | int fnum; | ||
41 | |||
42 | for (f = mntopt_list; f->string; f++) { | ||
43 | if (mask == f->mask) | ||
44 | return f->string; | ||
45 | } | ||
46 | for (fnum = 0; mask >>= 1; fnum++); | ||
47 | sprintf(buf, "MNTOPT_%d", fnum); | ||
48 | return buf; | ||
49 | } | ||
50 | |||
51 | int e2p_string2mntopt(char *string, unsigned int *mask) | ||
52 | { | ||
53 | struct mntopt *f; | ||
54 | char *eptr; | ||
55 | int num; | ||
56 | |||
57 | for (f = mntopt_list; f->string; f++) { | ||
58 | if (!strcasecmp(string, f->string)) { | ||
59 | *mask = f->mask; | ||
60 | return 0; | ||
61 | } | ||
62 | } | ||
63 | if (strncasecmp(string, "MNTOPT_", 8)) | ||
64 | return 1; | ||
65 | |||
66 | if (string[8] == 0) | ||
67 | return 1; | ||
68 | num = strtol(string+8, &eptr, 10); | ||
69 | if (num > 32 || num < 0) | ||
70 | return 1; | ||
71 | if (*eptr) | ||
72 | return 1; | ||
73 | *mask = 1 << num; | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static char *skip_over_blanks(char *cp) | ||
78 | { | ||
79 | while (*cp && isspace(*cp)) | ||
80 | cp++; | ||
81 | return cp; | ||
82 | } | ||
83 | |||
84 | static char *skip_over_word(char *cp) | ||
85 | { | ||
86 | while (*cp && !isspace(*cp) && *cp != ',') | ||
87 | cp++; | ||
88 | return cp; | ||
89 | } | ||
90 | |||
91 | /* | ||
92 | * Edit a mntopt set array as requested by the user. The ok | ||
93 | * parameter, if non-zero, allows the application to limit what | ||
94 | * mntopts the user is allowed to set or clear using this function. | ||
95 | */ | ||
96 | int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok) | ||
97 | { | ||
98 | char *cp, *buf, *next; | ||
99 | int neg; | ||
100 | unsigned int mask; | ||
101 | |||
102 | buf = malloc(strlen(str)+1); | ||
103 | if (!buf) | ||
104 | return 1; | ||
105 | strcpy(buf, str); | ||
106 | cp = buf; | ||
107 | while (cp && *cp) { | ||
108 | neg = 0; | ||
109 | cp = skip_over_blanks(cp); | ||
110 | next = skip_over_word(cp); | ||
111 | if (*next == 0) | ||
112 | next = 0; | ||
113 | else | ||
114 | *next = 0; | ||
115 | switch (*cp) { | ||
116 | case '-': | ||
117 | case '^': | ||
118 | neg++; | ||
119 | case '+': | ||
120 | cp++; | ||
121 | break; | ||
122 | } | ||
123 | if (e2p_string2mntopt(cp, &mask)) | ||
124 | return 1; | ||
125 | if (ok && !(ok & mask)) | ||
126 | return 1; | ||
127 | if (mask & EXT3_DEFM_JMODE) | ||
128 | *mntopts &= ~EXT3_DEFM_JMODE; | ||
129 | if (neg) | ||
130 | *mntopts &= ~mask; | ||
131 | else | ||
132 | *mntopts |= mask; | ||
133 | cp = next ? next+1 : 0; | ||
134 | } | ||
135 | return 0; | ||
136 | } | ||
diff --git a/util-linux/e2p/ostype.c b/util-linux/e2p/ostype.c deleted file mode 100644 index fe6597dd5..000000000 --- a/util-linux/e2p/ostype.c +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | /* | ||
2 | * getostype.c - Get the Filesystem OS type | ||
3 | * | ||
4 | * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu> | ||
5 | * | ||
6 | * This file can be redistributed under the terms of the GNU Library General | ||
7 | * Public License | ||
8 | */ | ||
9 | |||
10 | #include "e2p.h" | ||
11 | #include <string.h> | ||
12 | |||
13 | const char *os_tab[] = | ||
14 | { "Linux", | ||
15 | "Hurd", | ||
16 | "Masix", | ||
17 | "FreeBSD", | ||
18 | "Lites", | ||
19 | 0 }; | ||
20 | |||
21 | /* | ||
22 | * Convert an os_type to a string | ||
23 | */ | ||
24 | char *e2p_os2string(int os_type) | ||
25 | { | ||
26 | const char *os; | ||
27 | char *ret; | ||
28 | |||
29 | if (os_type <= EXT2_OS_LITES) | ||
30 | os = os_tab[os_type]; | ||
31 | else | ||
32 | os = "(unknown os)"; | ||
33 | |||
34 | ret = malloc(strlen(os)+1); | ||
35 | strcpy(ret, os); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | /* | ||
40 | * Convert an os_type to a string | ||
41 | */ | ||
42 | int e2p_string2os(char *str) | ||
43 | { | ||
44 | const char **cpp; | ||
45 | int i = 0; | ||
46 | |||
47 | for (cpp = os_tab; *cpp; cpp++, i++) { | ||
48 | if (!strcasecmp(str, *cpp)) | ||
49 | return i; | ||
50 | } | ||
51 | return -1; | ||
52 | } | ||
53 | |||
54 | #ifdef TEST_PROGRAM | ||
55 | int main(int argc, char **argv) | ||
56 | { | ||
57 | char *s; | ||
58 | int i, os; | ||
59 | |||
60 | for (i=0; i <= EXT2_OS_LITES; i++) { | ||
61 | s = e2p_os2string(i); | ||
62 | os = e2p_string2os(s); | ||
63 | printf("%d: %s (%d)\n", i, s, os); | ||
64 | if (i != os) { | ||
65 | fprintf(stderr, "Failure!\n"); | ||
66 | exit(1); | ||
67 | } | ||
68 | } | ||
69 | exit(0); | ||
70 | } | ||
71 | #endif | ||
72 | |||
73 | |||
diff --git a/util-linux/e2p/parse_num.c b/util-linux/e2p/parse_num.c deleted file mode 100644 index 3910e70de..000000000 --- a/util-linux/e2p/parse_num.c +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* | ||
2 | * parse_num.c - Parse the number of blocks | ||
3 | * | ||
4 | * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu> | ||
5 | * | ||
6 | * This file can be redistributed under the terms of the GNU Library General | ||
7 | * Public License | ||
8 | */ | ||
9 | |||
10 | #include "e2p.h" | ||
11 | |||
12 | #include <stdlib.h> | ||
13 | |||
14 | unsigned long parse_num_blocks(const char *arg, int log_block_size) | ||
15 | { | ||
16 | char *p; | ||
17 | unsigned long long num; | ||
18 | |||
19 | num = strtoull(arg, &p, 0); | ||
20 | |||
21 | if (p[0] && p[1]) | ||
22 | return 0; | ||
23 | |||
24 | switch (*p) { /* Using fall-through logic */ | ||
25 | case 'T': case 't': | ||
26 | num <<= 10; | ||
27 | case 'G': case 'g': | ||
28 | num <<= 10; | ||
29 | case 'M': case 'm': | ||
30 | num <<= 10; | ||
31 | case 'K': case 'k': | ||
32 | num >>= log_block_size; | ||
33 | break; | ||
34 | case 's': | ||
35 | num >>= 1; | ||
36 | break; | ||
37 | case '\0': | ||
38 | break; | ||
39 | default: | ||
40 | return 0; | ||
41 | } | ||
42 | return num; | ||
43 | } | ||
44 | |||
45 | #ifdef DEBUG | ||
46 | #include <unistd.h> | ||
47 | #include <stdio.h> | ||
48 | |||
49 | main(int argc, char **argv) | ||
50 | { | ||
51 | unsigned long num; | ||
52 | int log_block_size = 0; | ||
53 | |||
54 | if (argc != 2) { | ||
55 | fprintf(stderr, "Usage: %s arg\n", argv[0]); | ||
56 | exit(1); | ||
57 | } | ||
58 | |||
59 | num = parse_num_blocks(argv[1], log_block_size); | ||
60 | |||
61 | printf("Parsed number: %lu\n", num); | ||
62 | exit(0); | ||
63 | } | ||
64 | #endif | ||
diff --git a/util-linux/e2p/pe.c b/util-linux/e2p/pe.c deleted file mode 100644 index 4cce69117..000000000 --- a/util-linux/e2p/pe.c +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | /* | ||
2 | * pe.c - Print a second extended filesystem errors behavior | ||
3 | * | ||
4 | * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 94/01/09 - Creation | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | |||
19 | #include "e2p.h" | ||
20 | |||
21 | void print_fs_errors (FILE * f, unsigned short errors) | ||
22 | { | ||
23 | switch (errors) | ||
24 | { | ||
25 | case EXT2_ERRORS_CONTINUE: | ||
26 | fprintf (f, "Continue"); | ||
27 | break; | ||
28 | case EXT2_ERRORS_RO: | ||
29 | fprintf (f, "Remount read-only"); | ||
30 | break; | ||
31 | case EXT2_ERRORS_PANIC: | ||
32 | fprintf (f, "Panic"); | ||
33 | break; | ||
34 | default: | ||
35 | fprintf (f, "Unknown (continue)"); | ||
36 | } | ||
37 | } | ||
diff --git a/util-linux/e2p/pf.c b/util-linux/e2p/pf.c deleted file mode 100644 index 48d75a9ae..000000000 --- a/util-linux/e2p/pf.c +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | /* | ||
2 | * pf.c - Print file attributes on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | |||
19 | #include "e2p.h" | ||
20 | |||
21 | struct flags_name { | ||
22 | unsigned long flag; | ||
23 | const char *short_name; | ||
24 | const char *long_name; | ||
25 | }; | ||
26 | |||
27 | static struct flags_name flags_array[] = { | ||
28 | { EXT2_SECRM_FL, "s", "Secure_Deletion" }, | ||
29 | { EXT2_UNRM_FL, "u" , "Undelete" }, | ||
30 | { EXT2_SYNC_FL, "S", "Synchronous_Updates" }, | ||
31 | { EXT2_DIRSYNC_FL, "D", "Synchronous_Directory_Updates" }, | ||
32 | { EXT2_IMMUTABLE_FL, "i", "Immutable" }, | ||
33 | { EXT2_APPEND_FL, "a", "Append_Only" }, | ||
34 | { EXT2_NODUMP_FL, "d", "No_Dump" }, | ||
35 | { EXT2_NOATIME_FL, "A", "No_Atime" }, | ||
36 | { EXT2_COMPR_FL, "c", "Compression_Requested" }, | ||
37 | #ifdef ENABLE_COMPRESSION | ||
38 | { EXT2_COMPRBLK_FL, "B", "Compressed_File" }, | ||
39 | { EXT2_DIRTY_FL, "Z", "Compressed_Dirty_File" }, | ||
40 | { EXT2_NOCOMPR_FL, "X", "Compression_Raw_Access" }, | ||
41 | { EXT2_ECOMPR_FL, "E", "Compression_Error" }, | ||
42 | #endif | ||
43 | { EXT3_JOURNAL_DATA_FL, "j", "Journaled_Data" }, | ||
44 | { EXT2_INDEX_FL, "I", "Indexed_direcctory" }, | ||
45 | { EXT2_NOTAIL_FL, "t", "No_Tailmerging" }, | ||
46 | { EXT2_TOPDIR_FL, "T", "Top_of_Directory_Hierarchies" }, | ||
47 | { 0, NULL, NULL } | ||
48 | }; | ||
49 | |||
50 | void print_flags (FILE * f, unsigned long flags, unsigned options) | ||
51 | { | ||
52 | int long_opt = (options & PFOPT_LONG); | ||
53 | struct flags_name *fp; | ||
54 | int first = 1; | ||
55 | |||
56 | for (fp = flags_array; fp->flag != 0; fp++) { | ||
57 | if (flags & fp->flag) { | ||
58 | if (long_opt) { | ||
59 | if (first) | ||
60 | first = 0; | ||
61 | else | ||
62 | fputs(", ", f); | ||
63 | fputs(fp->long_name, f); | ||
64 | } else | ||
65 | fputs(fp->short_name, f); | ||
66 | } else { | ||
67 | if (!long_opt) | ||
68 | fputs("-", f); | ||
69 | } | ||
70 | } | ||
71 | if (long_opt && first) | ||
72 | fputs("---", f); | ||
73 | } | ||
74 | |||
diff --git a/util-linux/e2p/ps.c b/util-linux/e2p/ps.c deleted file mode 100644 index bec8b4195..000000000 --- a/util-linux/e2p/ps.c +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | /* | ||
2 | * ps.c - Print filesystem state | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/12/22 - Creation | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | |||
19 | #include "e2p.h" | ||
20 | |||
21 | void print_fs_state (FILE * f, unsigned short state) | ||
22 | { | ||
23 | if (state & EXT2_VALID_FS) | ||
24 | fprintf (f, " clean"); | ||
25 | else | ||
26 | fprintf (f, " not clean"); | ||
27 | if (state & EXT2_ERROR_FS) | ||
28 | fprintf (f, " with errors"); | ||
29 | } | ||
diff --git a/util-linux/e2p/setflags.c b/util-linux/e2p/setflags.c deleted file mode 100644 index 47c52a7ad..000000000 --- a/util-linux/e2p/setflags.c +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | /* | ||
2 | * setflags.c - Set a file flags on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #include <sys/types.h> | ||
21 | #include <sys/stat.h> | ||
22 | #if HAVE_EXT2_IOCTLS | ||
23 | #include <sys/ioctl.h> | ||
24 | #endif | ||
25 | |||
26 | #include "e2p.h" | ||
27 | |||
28 | /* | ||
29 | * Deal with lame glibc's that define this function without actually | ||
30 | * implementing it. Can you say "attractive nuisance", boys and girls? | ||
31 | * I knew you could! | ||
32 | */ | ||
33 | #ifdef __linux__ | ||
34 | #undef HAVE_CHFLAGS | ||
35 | #endif | ||
36 | |||
37 | int setflags (int fd, unsigned long flags) | ||
38 | { | ||
39 | struct stat buf; | ||
40 | #if HAVE_CHFLAGS | ||
41 | unsigned long bsd_flags = 0; | ||
42 | |||
43 | #ifdef UF_IMMUTABLE | ||
44 | if (flags & EXT2_IMMUTABLE_FL) | ||
45 | bsd_flags |= UF_IMMUTABLE; | ||
46 | #endif | ||
47 | #ifdef UF_APPEND | ||
48 | if (flags & EXT2_APPEND_FL) | ||
49 | bsd_flags |= UF_APPEND; | ||
50 | #endif | ||
51 | #ifdef UF_NODUMP | ||
52 | if (flags & EXT2_NODUMP_FL) | ||
53 | bsd_flags |= UF_NODUMP; | ||
54 | #endif | ||
55 | |||
56 | return fchflags (fd, bsd_flags); | ||
57 | #else | ||
58 | #if HAVE_EXT2_IOCTLS | ||
59 | int f; | ||
60 | |||
61 | if (!fstat(fd, &buf) && | ||
62 | !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { | ||
63 | errno = EOPNOTSUPP; | ||
64 | return -1; | ||
65 | } | ||
66 | f = (int) flags; | ||
67 | return ioctl (fd, EXT2_IOC_SETFLAGS, &f); | ||
68 | #endif /* HAVE_EXT2_IOCTLS */ | ||
69 | #endif | ||
70 | errno = EOPNOTSUPP; | ||
71 | return -1; | ||
72 | } | ||
diff --git a/util-linux/e2p/setversion.c b/util-linux/e2p/setversion.c deleted file mode 100644 index bd00df668..000000000 --- a/util-linux/e2p/setversion.c +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | /* | ||
2 | * setversion.c - Set a file version on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU Library General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | */ | ||
16 | |||
17 | #if HAVE_ERRNO_H | ||
18 | #include <errno.h> | ||
19 | #endif | ||
20 | #include <sys/ioctl.h> | ||
21 | |||
22 | #include "e2p.h" | ||
23 | |||
24 | int setversion (int fd, unsigned long version) | ||
25 | { | ||
26 | #if HAVE_EXT2_IOCTLS | ||
27 | int ver; | ||
28 | |||
29 | ver = (int) version; | ||
30 | return ioctl (fd, EXT2_IOC_SETVERSION, &ver); | ||
31 | #else /* ! HAVE_EXT2_IOCTLS */ | ||
32 | extern int errno; | ||
33 | errno = EOPNOTSUPP; | ||
34 | return -1; | ||
35 | #endif /* ! HAVE_EXT2_IOCTLS */ | ||
36 | } | ||
diff --git a/util-linux/e2p/uuid.c b/util-linux/e2p/uuid.c deleted file mode 100644 index fef3b91e7..000000000 --- a/util-linux/e2p/uuid.c +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | /* | ||
2 | * uuid.c -- utility routines for manipulating UUID's. | ||
3 | */ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <ext2fs/ext2_types.h> | ||
8 | |||
9 | #include "e2p.h" | ||
10 | |||
11 | struct uuid { | ||
12 | __u32 time_low; | ||
13 | __u16 time_mid; | ||
14 | __u16 time_hi_and_version; | ||
15 | __u16 clock_seq; | ||
16 | __u8 node[6]; | ||
17 | }; | ||
18 | |||
19 | /* Returns 1 if the uuid is the NULL uuid */ | ||
20 | int e2p_is_null_uuid(void *uu) | ||
21 | { | ||
22 | __u8 *cp; | ||
23 | int i; | ||
24 | |||
25 | for (i=0, cp = uu; i < 16; i++) | ||
26 | if (*cp) | ||
27 | return 0; | ||
28 | return 1; | ||
29 | } | ||
30 | |||
31 | static void e2p_unpack_uuid(void *in, struct uuid *uu) | ||
32 | { | ||
33 | __u8 *ptr = in; | ||
34 | __u32 tmp; | ||
35 | |||
36 | tmp = *ptr++; | ||
37 | tmp = (tmp << 8) | *ptr++; | ||
38 | tmp = (tmp << 8) | *ptr++; | ||
39 | tmp = (tmp << 8) | *ptr++; | ||
40 | uu->time_low = tmp; | ||
41 | |||
42 | tmp = *ptr++; | ||
43 | tmp = (tmp << 8) | *ptr++; | ||
44 | uu->time_mid = tmp; | ||
45 | |||
46 | tmp = *ptr++; | ||
47 | tmp = (tmp << 8) | *ptr++; | ||
48 | uu->time_hi_and_version = tmp; | ||
49 | |||
50 | tmp = *ptr++; | ||
51 | tmp = (tmp << 8) | *ptr++; | ||
52 | uu->clock_seq = tmp; | ||
53 | |||
54 | memcpy(uu->node, ptr, 6); | ||
55 | } | ||
56 | |||
57 | void e2p_uuid_to_str(void *uu, char *out) | ||
58 | { | ||
59 | struct uuid uuid; | ||
60 | |||
61 | e2p_unpack_uuid(uu, &uuid); | ||
62 | sprintf(out, | ||
63 | "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", | ||
64 | uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, | ||
65 | uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, | ||
66 | uuid.node[0], uuid.node[1], uuid.node[2], | ||
67 | uuid.node[3], uuid.node[4], uuid.node[5]); | ||
68 | } | ||
69 | |||
70 | const char *e2p_uuid2str(void *uu) | ||
71 | { | ||
72 | static char buf[80]; | ||
73 | |||
74 | if (e2p_is_null_uuid(uu)) | ||
75 | return "<none>"; | ||
76 | e2p_uuid_to_str(uu, buf); | ||
77 | return buf; | ||
78 | } | ||
79 | |||
diff --git a/util-linux/ext2_fs.h b/util-linux/ext2_fs.h deleted file mode 100644 index ff615c4bd..000000000 --- a/util-linux/ext2_fs.h +++ /dev/null | |||
@@ -1,644 +0,0 @@ | |||
1 | /* | ||
2 | * linux/include/linux/ext2_fs.h | ||
3 | * | ||
4 | * Copyright (C) 1992, 1993, 1994, 1995 | ||
5 | * Remy Card (card@masi.ibp.fr) | ||
6 | * Laboratoire MASI - Institut Blaise Pascal | ||
7 | * Universite Pierre et Marie Curie (Paris VI) | ||
8 | * | ||
9 | * from | ||
10 | * | ||
11 | * linux/include/linux/minix_fs.h | ||
12 | * | ||
13 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
14 | */ | ||
15 | |||
16 | #ifndef _LINUX_EXT2_FS_H | ||
17 | #define _LINUX_EXT2_FS_H | ||
18 | |||
19 | #include <ext2fs/ext2_types.h> /* Changed from linux/types.h */ | ||
20 | |||
21 | /* | ||
22 | * The second extended filesystem constants/structures | ||
23 | */ | ||
24 | |||
25 | /* | ||
26 | * Define EXT2FS_DEBUG to produce debug messages | ||
27 | */ | ||
28 | #undef EXT2FS_DEBUG | ||
29 | |||
30 | /* | ||
31 | * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files | ||
32 | */ | ||
33 | #define EXT2_PREALLOCATE | ||
34 | #define EXT2_DEFAULT_PREALLOC_BLOCKS 8 | ||
35 | |||
36 | /* | ||
37 | * The second extended file system version | ||
38 | */ | ||
39 | #define EXT2FS_DATE "95/08/09" | ||
40 | #define EXT2FS_VERSION "0.5b" | ||
41 | |||
42 | /* | ||
43 | * Special inode numbers | ||
44 | */ | ||
45 | #define EXT2_BAD_INO 1 /* Bad blocks inode */ | ||
46 | #define EXT2_ROOT_INO 2 /* Root inode */ | ||
47 | #define EXT2_ACL_IDX_INO 3 /* ACL inode */ | ||
48 | #define EXT2_ACL_DATA_INO 4 /* ACL inode */ | ||
49 | #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */ | ||
50 | #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */ | ||
51 | #define EXT2_RESIZE_INO 7 /* Reserved group descriptors inode */ | ||
52 | #define EXT2_JOURNAL_INO 8 /* Journal inode */ | ||
53 | |||
54 | /* First non-reserved inode for old ext2 filesystems */ | ||
55 | #define EXT2_GOOD_OLD_FIRST_INO 11 | ||
56 | |||
57 | /* | ||
58 | * The second extended file system magic number | ||
59 | */ | ||
60 | #define EXT2_SUPER_MAGIC 0xEF53 | ||
61 | |||
62 | #ifdef __KERNEL__ | ||
63 | #define EXT2_SB(sb) (&((sb)->u.ext2_sb)) | ||
64 | #else | ||
65 | /* Assume that user mode programs are passing in an ext2fs superblock, not | ||
66 | * a kernel struct super_block. This will allow us to call the feature-test | ||
67 | * macros from user land. */ | ||
68 | #define EXT2_SB(sb) (sb) | ||
69 | #endif | ||
70 | |||
71 | /* | ||
72 | * Maximal count of links to a file | ||
73 | */ | ||
74 | #define EXT2_LINK_MAX 32000 | ||
75 | |||
76 | /* | ||
77 | * Macro-instructions used to manage several block sizes | ||
78 | */ | ||
79 | #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */ | ||
80 | #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */ | ||
81 | #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE) | ||
82 | #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE) | ||
83 | #ifdef __KERNEL__ | ||
84 | #define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize) | ||
85 | #define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) | ||
86 | #define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->addr_per_block_bits) | ||
87 | #define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size) | ||
88 | #define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino) | ||
89 | #else | ||
90 | #define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size) | ||
91 | #define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) | ||
92 | #define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \ | ||
93 | EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size) | ||
94 | #define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \ | ||
95 | EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino) | ||
96 | #endif | ||
97 | #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(__u32)) | ||
98 | |||
99 | /* | ||
100 | * Macro-instructions used to manage fragments | ||
101 | */ | ||
102 | #define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE | ||
103 | #define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE | ||
104 | #define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE | ||
105 | #ifdef __KERNEL__ | ||
106 | # define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size) | ||
107 | # define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block) | ||
108 | #else | ||
109 | # define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size) | ||
110 | # define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s)) | ||
111 | #endif | ||
112 | |||
113 | /* | ||
114 | * ACL structures | ||
115 | */ | ||
116 | struct ext2_acl_header /* Header of Access Control Lists */ | ||
117 | { | ||
118 | __u32 aclh_size; | ||
119 | __u32 aclh_file_count; | ||
120 | __u32 aclh_acle_count; | ||
121 | __u32 aclh_first_acle; | ||
122 | }; | ||
123 | |||
124 | struct ext2_acl_entry /* Access Control List Entry */ | ||
125 | { | ||
126 | __u32 acle_size; | ||
127 | __u16 acle_perms; /* Access permissions */ | ||
128 | __u16 acle_type; /* Type of entry */ | ||
129 | __u16 acle_tag; /* User or group identity */ | ||
130 | __u16 acle_pad1; | ||
131 | __u32 acle_next; /* Pointer on next entry for the */ | ||
132 | /* same inode or on next free entry */ | ||
133 | }; | ||
134 | |||
135 | /* | ||
136 | * Structure of a blocks group descriptor | ||
137 | */ | ||
138 | struct ext2_group_desc | ||
139 | { | ||
140 | __u32 bg_block_bitmap; /* Blocks bitmap block */ | ||
141 | __u32 bg_inode_bitmap; /* Inodes bitmap block */ | ||
142 | __u32 bg_inode_table; /* Inodes table block */ | ||
143 | __u16 bg_free_blocks_count; /* Free blocks count */ | ||
144 | __u16 bg_free_inodes_count; /* Free inodes count */ | ||
145 | __u16 bg_used_dirs_count; /* Directories count */ | ||
146 | __u16 bg_pad; | ||
147 | __u32 bg_reserved[3]; | ||
148 | }; | ||
149 | |||
150 | /* | ||
151 | * Data structures used by the directory indexing feature | ||
152 | * | ||
153 | * Note: all of the multibyte integer fields are little endian. | ||
154 | */ | ||
155 | |||
156 | /* | ||
157 | * Note: dx_root_info is laid out so that if it should somehow get | ||
158 | * overlaid by a dirent the two low bits of the hash version will be | ||
159 | * zero. Therefore, the hash version mod 4 should never be 0. | ||
160 | * Sincerely, the paranoia department. | ||
161 | */ | ||
162 | struct ext2_dx_root_info { | ||
163 | __u32 reserved_zero; | ||
164 | __u8 hash_version; /* 0 now, 1 at release */ | ||
165 | __u8 info_length; /* 8 */ | ||
166 | __u8 indirect_levels; | ||
167 | __u8 unused_flags; | ||
168 | }; | ||
169 | |||
170 | #define EXT2_HASH_LEGACY 0 | ||
171 | #define EXT2_HASH_HALF_MD4 1 | ||
172 | #define EXT2_HASH_TEA 2 | ||
173 | |||
174 | #define EXT2_HASH_FLAG_INCOMPAT 0x1 | ||
175 | |||
176 | struct ext2_dx_entry { | ||
177 | __u32 hash; | ||
178 | __u32 block; | ||
179 | }; | ||
180 | |||
181 | struct ext2_dx_countlimit { | ||
182 | __u16 limit; | ||
183 | __u16 count; | ||
184 | }; | ||
185 | |||
186 | |||
187 | /* | ||
188 | * Macro-instructions used to manage group descriptors | ||
189 | */ | ||
190 | #define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group) | ||
191 | #define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group) | ||
192 | #define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s)) | ||
193 | /* limits imposed by 16-bit value gd_free_{blocks,inode}_count */ | ||
194 | #define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8) | ||
195 | #define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s)) | ||
196 | #ifdef __KERNEL__ | ||
197 | #define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block) | ||
198 | #define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits) | ||
199 | #else | ||
200 | #define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc)) | ||
201 | #endif | ||
202 | |||
203 | /* | ||
204 | * Constants relative to the data blocks | ||
205 | */ | ||
206 | #define EXT2_NDIR_BLOCKS 12 | ||
207 | #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS | ||
208 | #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1) | ||
209 | #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1) | ||
210 | #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1) | ||
211 | |||
212 | /* | ||
213 | * Inode flags | ||
214 | */ | ||
215 | #define EXT2_SECRM_FL 0x00000001 /* Secure deletion */ | ||
216 | #define EXT2_UNRM_FL 0x00000002 /* Undelete */ | ||
217 | #define EXT2_COMPR_FL 0x00000004 /* Compress file */ | ||
218 | #define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */ | ||
219 | #define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */ | ||
220 | #define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */ | ||
221 | #define EXT2_NODUMP_FL 0x00000040 /* do not dump file */ | ||
222 | #define EXT2_NOATIME_FL 0x00000080 /* do not update atime */ | ||
223 | /* Reserved for compression usage... */ | ||
224 | #define EXT2_DIRTY_FL 0x00000100 | ||
225 | #define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ | ||
226 | #define EXT2_NOCOMPR_FL 0x00000400 /* Access raw compressed data */ | ||
227 | #define EXT2_ECOMPR_FL 0x00000800 /* Compression error */ | ||
228 | /* End compression flags --- maybe not all used */ | ||
229 | #define EXT2_BTREE_FL 0x00001000 /* btree format dir */ | ||
230 | #define EXT2_INDEX_FL 0x00001000 /* hash-indexed directory */ | ||
231 | #define EXT2_IMAGIC_FL 0x00002000 | ||
232 | #define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ | ||
233 | #define EXT2_NOTAIL_FL 0x00008000 /* file tail should not be merged */ | ||
234 | #define EXT2_DIRSYNC_FL 0x00010000 /* Synchronous directory modifications */ | ||
235 | #define EXT2_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ | ||
236 | #define EXT3_EXTENTS_FL 0x00080000 /* Inode uses extents */ | ||
237 | #define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ | ||
238 | |||
239 | #define EXT2_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ | ||
240 | #define EXT2_FL_USER_MODIFIABLE 0x000080FF /* User modifiable flags */ | ||
241 | |||
242 | /* | ||
243 | * ioctl commands | ||
244 | */ | ||
245 | #define EXT2_IOC_GETFLAGS _IOR('f', 1, long) | ||
246 | #define EXT2_IOC_SETFLAGS _IOW('f', 2, long) | ||
247 | #define EXT2_IOC_GETVERSION _IOR('v', 1, long) | ||
248 | #define EXT2_IOC_SETVERSION _IOW('v', 2, long) | ||
249 | |||
250 | /* | ||
251 | * Structure of an inode on the disk | ||
252 | */ | ||
253 | struct ext2_inode { | ||
254 | __u16 i_mode; /* File mode */ | ||
255 | __u16 i_uid; /* Low 16 bits of Owner Uid */ | ||
256 | __u32 i_size; /* Size in bytes */ | ||
257 | __u32 i_atime; /* Access time */ | ||
258 | __u32 i_ctime; /* Creation time */ | ||
259 | __u32 i_mtime; /* Modification time */ | ||
260 | __u32 i_dtime; /* Deletion Time */ | ||
261 | __u16 i_gid; /* Low 16 bits of Group Id */ | ||
262 | __u16 i_links_count; /* Links count */ | ||
263 | __u32 i_blocks; /* Blocks count */ | ||
264 | __u32 i_flags; /* File flags */ | ||
265 | union { | ||
266 | struct { | ||
267 | __u32 l_i_reserved1; | ||
268 | } linux1; | ||
269 | struct { | ||
270 | __u32 h_i_translator; | ||
271 | } hurd1; | ||
272 | struct { | ||
273 | __u32 m_i_reserved1; | ||
274 | } masix1; | ||
275 | } osd1; /* OS dependent 1 */ | ||
276 | __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */ | ||
277 | __u32 i_generation; /* File version (for NFS) */ | ||
278 | __u32 i_file_acl; /* File ACL */ | ||
279 | __u32 i_dir_acl; /* Directory ACL */ | ||
280 | __u32 i_faddr; /* Fragment address */ | ||
281 | union { | ||
282 | struct { | ||
283 | __u8 l_i_frag; /* Fragment number */ | ||
284 | __u8 l_i_fsize; /* Fragment size */ | ||
285 | __u16 i_pad1; | ||
286 | __u16 l_i_uid_high; /* these 2 fields */ | ||
287 | __u16 l_i_gid_high; /* were reserved2[0] */ | ||
288 | __u32 l_i_reserved2; | ||
289 | } linux2; | ||
290 | struct { | ||
291 | __u8 h_i_frag; /* Fragment number */ | ||
292 | __u8 h_i_fsize; /* Fragment size */ | ||
293 | __u16 h_i_mode_high; | ||
294 | __u16 h_i_uid_high; | ||
295 | __u16 h_i_gid_high; | ||
296 | __u32 h_i_author; | ||
297 | } hurd2; | ||
298 | struct { | ||
299 | __u8 m_i_frag; /* Fragment number */ | ||
300 | __u8 m_i_fsize; /* Fragment size */ | ||
301 | __u16 m_pad1; | ||
302 | __u32 m_i_reserved2[2]; | ||
303 | } masix2; | ||
304 | } osd2; /* OS dependent 2 */ | ||
305 | }; | ||
306 | |||
307 | /* | ||
308 | * Permanent part of an large inode on the disk | ||
309 | */ | ||
310 | struct ext2_inode_large { | ||
311 | __u16 i_mode; /* File mode */ | ||
312 | __u16 i_uid; /* Low 16 bits of Owner Uid */ | ||
313 | __u32 i_size; /* Size in bytes */ | ||
314 | __u32 i_atime; /* Access time */ | ||
315 | __u32 i_ctime; /* Creation time */ | ||
316 | __u32 i_mtime; /* Modification time */ | ||
317 | __u32 i_dtime; /* Deletion Time */ | ||
318 | __u16 i_gid; /* Low 16 bits of Group Id */ | ||
319 | __u16 i_links_count; /* Links count */ | ||
320 | __u32 i_blocks; /* Blocks count */ | ||
321 | __u32 i_flags; /* File flags */ | ||
322 | union { | ||
323 | struct { | ||
324 | __u32 l_i_reserved1; | ||
325 | } linux1; | ||
326 | struct { | ||
327 | __u32 h_i_translator; | ||
328 | } hurd1; | ||
329 | struct { | ||
330 | __u32 m_i_reserved1; | ||
331 | } masix1; | ||
332 | } osd1; /* OS dependent 1 */ | ||
333 | __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */ | ||
334 | __u32 i_generation; /* File version (for NFS) */ | ||
335 | __u32 i_file_acl; /* File ACL */ | ||
336 | __u32 i_dir_acl; /* Directory ACL */ | ||
337 | __u32 i_faddr; /* Fragment address */ | ||
338 | union { | ||
339 | struct { | ||
340 | __u8 l_i_frag; /* Fragment number */ | ||
341 | __u8 l_i_fsize; /* Fragment size */ | ||
342 | __u16 i_pad1; | ||
343 | __u16 l_i_uid_high; /* these 2 fields */ | ||
344 | __u16 l_i_gid_high; /* were reserved2[0] */ | ||
345 | __u32 l_i_reserved2; | ||
346 | } linux2; | ||
347 | struct { | ||
348 | __u8 h_i_frag; /* Fragment number */ | ||
349 | __u8 h_i_fsize; /* Fragment size */ | ||
350 | __u16 h_i_mode_high; | ||
351 | __u16 h_i_uid_high; | ||
352 | __u16 h_i_gid_high; | ||
353 | __u32 h_i_author; | ||
354 | } hurd2; | ||
355 | struct { | ||
356 | __u8 m_i_frag; /* Fragment number */ | ||
357 | __u8 m_i_fsize; /* Fragment size */ | ||
358 | __u16 m_pad1; | ||
359 | __u32 m_i_reserved2[2]; | ||
360 | } masix2; | ||
361 | } osd2; /* OS dependent 2 */ | ||
362 | __u16 i_extra_isize; | ||
363 | __u16 i_pad1; | ||
364 | }; | ||
365 | |||
366 | #define i_size_high i_dir_acl | ||
367 | |||
368 | #if defined(__KERNEL__) || defined(__linux__) | ||
369 | #define i_reserved1 osd1.linux1.l_i_reserved1 | ||
370 | #define i_frag osd2.linux2.l_i_frag | ||
371 | #define i_fsize osd2.linux2.l_i_fsize | ||
372 | #define i_uid_low i_uid | ||
373 | #define i_gid_low i_gid | ||
374 | #define i_uid_high osd2.linux2.l_i_uid_high | ||
375 | #define i_gid_high osd2.linux2.l_i_gid_high | ||
376 | #define i_reserved2 osd2.linux2.l_i_reserved2 | ||
377 | |||
378 | #else | ||
379 | #if defined(__GNU__) | ||
380 | |||
381 | #define i_translator osd1.hurd1.h_i_translator | ||
382 | #define i_frag osd2.hurd2.h_i_frag; | ||
383 | #define i_fsize osd2.hurd2.h_i_fsize; | ||
384 | #define i_uid_high osd2.hurd2.h_i_uid_high | ||
385 | #define i_gid_high osd2.hurd2.h_i_gid_high | ||
386 | #define i_author osd2.hurd2.h_i_author | ||
387 | |||
388 | #else | ||
389 | #if defined(__masix__) | ||
390 | |||
391 | #define i_reserved1 osd1.masix1.m_i_reserved1 | ||
392 | #define i_frag osd2.masix2.m_i_frag | ||
393 | #define i_fsize osd2.masix2.m_i_fsize | ||
394 | #define i_reserved2 osd2.masix2.m_i_reserved2 | ||
395 | |||
396 | #endif /* __masix__ */ | ||
397 | #endif /* __GNU__ */ | ||
398 | #endif /* defined(__KERNEL__) || defined(__linux__) */ | ||
399 | |||
400 | /* | ||
401 | * File system states | ||
402 | */ | ||
403 | #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */ | ||
404 | #define EXT2_ERROR_FS 0x0002 /* Errors detected */ | ||
405 | |||
406 | /* | ||
407 | * Mount flags | ||
408 | */ | ||
409 | #define EXT2_MOUNT_CHECK 0x0001 /* Do mount-time checks */ | ||
410 | #define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */ | ||
411 | #define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */ | ||
412 | #define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */ | ||
413 | #define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */ | ||
414 | #define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */ | ||
415 | #define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */ | ||
416 | #define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */ | ||
417 | |||
418 | #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt | ||
419 | #define set_opt(o, opt) o |= EXT2_MOUNT_##opt | ||
420 | #define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \ | ||
421 | EXT2_MOUNT_##opt) | ||
422 | /* | ||
423 | * Maximal mount counts between two filesystem checks | ||
424 | */ | ||
425 | #define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ | ||
426 | #define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */ | ||
427 | |||
428 | /* | ||
429 | * Behaviour when detecting errors | ||
430 | */ | ||
431 | #define EXT2_ERRORS_CONTINUE 1 /* Continue execution */ | ||
432 | #define EXT2_ERRORS_RO 2 /* Remount fs read-only */ | ||
433 | #define EXT2_ERRORS_PANIC 3 /* Panic */ | ||
434 | #define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE | ||
435 | |||
436 | /* | ||
437 | * Structure of the super block | ||
438 | */ | ||
439 | struct ext2_super_block { | ||
440 | __u32 s_inodes_count; /* Inodes count */ | ||
441 | __u32 s_blocks_count; /* Blocks count */ | ||
442 | __u32 s_r_blocks_count; /* Reserved blocks count */ | ||
443 | __u32 s_free_blocks_count; /* Free blocks count */ | ||
444 | __u32 s_free_inodes_count; /* Free inodes count */ | ||
445 | __u32 s_first_data_block; /* First Data Block */ | ||
446 | __u32 s_log_block_size; /* Block size */ | ||
447 | __s32 s_log_frag_size; /* Fragment size */ | ||
448 | __u32 s_blocks_per_group; /* # Blocks per group */ | ||
449 | __u32 s_frags_per_group; /* # Fragments per group */ | ||
450 | __u32 s_inodes_per_group; /* # Inodes per group */ | ||
451 | __u32 s_mtime; /* Mount time */ | ||
452 | __u32 s_wtime; /* Write time */ | ||
453 | __u16 s_mnt_count; /* Mount count */ | ||
454 | __s16 s_max_mnt_count; /* Maximal mount count */ | ||
455 | __u16 s_magic; /* Magic signature */ | ||
456 | __u16 s_state; /* File system state */ | ||
457 | __u16 s_errors; /* Behaviour when detecting errors */ | ||
458 | __u16 s_minor_rev_level; /* minor revision level */ | ||
459 | __u32 s_lastcheck; /* time of last check */ | ||
460 | __u32 s_checkinterval; /* max. time between checks */ | ||
461 | __u32 s_creator_os; /* OS */ | ||
462 | __u32 s_rev_level; /* Revision level */ | ||
463 | __u16 s_def_resuid; /* Default uid for reserved blocks */ | ||
464 | __u16 s_def_resgid; /* Default gid for reserved blocks */ | ||
465 | /* | ||
466 | * These fields are for EXT2_DYNAMIC_REV superblocks only. | ||
467 | * | ||
468 | * Note: the difference between the compatible feature set and | ||
469 | * the incompatible feature set is that if there is a bit set | ||
470 | * in the incompatible feature set that the kernel doesn't | ||
471 | * know about, it should refuse to mount the filesystem. | ||
472 | * | ||
473 | * e2fsck's requirements are more strict; if it doesn't know | ||
474 | * about a feature in either the compatible or incompatible | ||
475 | * feature set, it must abort and not try to meddle with | ||
476 | * things it doesn't understand... | ||
477 | */ | ||
478 | __u32 s_first_ino; /* First non-reserved inode */ | ||
479 | __u16 s_inode_size; /* size of inode structure */ | ||
480 | __u16 s_block_group_nr; /* block group # of this superblock */ | ||
481 | __u32 s_feature_compat; /* compatible feature set */ | ||
482 | __u32 s_feature_incompat; /* incompatible feature set */ | ||
483 | __u32 s_feature_ro_compat; /* readonly-compatible feature set */ | ||
484 | __u8 s_uuid[16]; /* 128-bit uuid for volume */ | ||
485 | char s_volume_name[16]; /* volume name */ | ||
486 | char s_last_mounted[64]; /* directory where last mounted */ | ||
487 | __u32 s_algorithm_usage_bitmap; /* For compression */ | ||
488 | /* | ||
489 | * Performance hints. Directory preallocation should only | ||
490 | * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on. | ||
491 | */ | ||
492 | __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ | ||
493 | __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ | ||
494 | __u16 s_reserved_gdt_blocks; /* Per group table for online growth */ | ||
495 | /* | ||
496 | * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set. | ||
497 | */ | ||
498 | __u8 s_journal_uuid[16]; /* uuid of journal superblock */ | ||
499 | __u32 s_journal_inum; /* inode number of journal file */ | ||
500 | __u32 s_journal_dev; /* device number of journal file */ | ||
501 | __u32 s_last_orphan; /* start of list of inodes to delete */ | ||
502 | __u32 s_hash_seed[4]; /* HTREE hash seed */ | ||
503 | __u8 s_def_hash_version; /* Default hash version to use */ | ||
504 | __u8 s_jnl_backup_type; /* Default type of journal backup */ | ||
505 | __u16 s_reserved_word_pad; | ||
506 | __u32 s_default_mount_opts; | ||
507 | __u32 s_first_meta_bg; /* First metablock group */ | ||
508 | __u32 s_mkfs_time; /* When the filesystem was created */ | ||
509 | __u32 s_jnl_blocks[17]; /* Backup of the journal inode */ | ||
510 | __u32 s_reserved[172]; /* Padding to the end of the block */ | ||
511 | }; | ||
512 | |||
513 | /* | ||
514 | * Codes for operating systems | ||
515 | */ | ||
516 | #define EXT2_OS_LINUX 0 | ||
517 | #define EXT2_OS_HURD 1 | ||
518 | #define EXT2_OS_MASIX 2 | ||
519 | #define EXT2_OS_FREEBSD 3 | ||
520 | #define EXT2_OS_LITES 4 | ||
521 | |||
522 | /* | ||
523 | * Revision levels | ||
524 | */ | ||
525 | #define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */ | ||
526 | #define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ | ||
527 | |||
528 | #define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV | ||
529 | #define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV | ||
530 | |||
531 | #define EXT2_GOOD_OLD_INODE_SIZE 128 | ||
532 | |||
533 | /* | ||
534 | * Journal inode backup types | ||
535 | */ | ||
536 | #define EXT3_JNL_BACKUP_BLOCKS 1 | ||
537 | |||
538 | /* | ||
539 | * Feature set definitions | ||
540 | */ | ||
541 | |||
542 | #define EXT2_HAS_COMPAT_FEATURE(sb,mask) \ | ||
543 | ( EXT2_SB(sb)->s_feature_compat & (mask) ) | ||
544 | #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \ | ||
545 | ( EXT2_SB(sb)->s_feature_ro_compat & (mask) ) | ||
546 | #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \ | ||
547 | ( EXT2_SB(sb)->s_feature_incompat & (mask) ) | ||
548 | |||
549 | #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001 | ||
550 | #define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002 | ||
551 | #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 | ||
552 | #define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008 | ||
553 | #define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010 | ||
554 | #define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 | ||
555 | |||
556 | #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 | ||
557 | #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 | ||
558 | /* #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 not used */ | ||
559 | |||
560 | #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 | ||
561 | #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 | ||
562 | #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ | ||
563 | #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ | ||
564 | #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 | ||
565 | #define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 | ||
566 | |||
567 | |||
568 | #define EXT2_FEATURE_COMPAT_SUPP 0 | ||
569 | #define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE) | ||
570 | #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ | ||
571 | EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ | ||
572 | EXT2_FEATURE_RO_COMPAT_BTREE_DIR) | ||
573 | |||
574 | /* | ||
575 | * Default values for user and/or group using reserved blocks | ||
576 | */ | ||
577 | #define EXT2_DEF_RESUID 0 | ||
578 | #define EXT2_DEF_RESGID 0 | ||
579 | |||
580 | /* | ||
581 | * Default mount options | ||
582 | */ | ||
583 | #define EXT2_DEFM_DEBUG 0x0001 | ||
584 | #define EXT2_DEFM_BSDGROUPS 0x0002 | ||
585 | #define EXT2_DEFM_XATTR_USER 0x0004 | ||
586 | #define EXT2_DEFM_ACL 0x0008 | ||
587 | #define EXT2_DEFM_UID16 0x0010 | ||
588 | #define EXT3_DEFM_JMODE 0x0060 | ||
589 | #define EXT3_DEFM_JMODE_DATA 0x0020 | ||
590 | #define EXT3_DEFM_JMODE_ORDERED 0x0040 | ||
591 | #define EXT3_DEFM_JMODE_WBACK 0x0060 | ||
592 | |||
593 | /* | ||
594 | * Structure of a directory entry | ||
595 | */ | ||
596 | #define EXT2_NAME_LEN 255 | ||
597 | |||
598 | struct ext2_dir_entry { | ||
599 | __u32 inode; /* Inode number */ | ||
600 | __u16 rec_len; /* Directory entry length */ | ||
601 | __u16 name_len; /* Name length */ | ||
602 | char name[EXT2_NAME_LEN]; /* File name */ | ||
603 | }; | ||
604 | |||
605 | /* | ||
606 | * The new version of the directory entry. Since EXT2 structures are | ||
607 | * stored in intel byte order, and the name_len field could never be | ||
608 | * bigger than 255 chars, it's safe to reclaim the extra byte for the | ||
609 | * file_type field. | ||
610 | */ | ||
611 | struct ext2_dir_entry_2 { | ||
612 | __u32 inode; /* Inode number */ | ||
613 | __u16 rec_len; /* Directory entry length */ | ||
614 | __u8 name_len; /* Name length */ | ||
615 | __u8 file_type; | ||
616 | char name[EXT2_NAME_LEN]; /* File name */ | ||
617 | }; | ||
618 | |||
619 | /* | ||
620 | * Ext2 directory file types. Only the low 3 bits are used. The | ||
621 | * other bits are reserved for now. | ||
622 | */ | ||
623 | #define EXT2_FT_UNKNOWN 0 | ||
624 | #define EXT2_FT_REG_FILE 1 | ||
625 | #define EXT2_FT_DIR 2 | ||
626 | #define EXT2_FT_CHRDEV 3 | ||
627 | #define EXT2_FT_BLKDEV 4 | ||
628 | #define EXT2_FT_FIFO 5 | ||
629 | #define EXT2_FT_SOCK 6 | ||
630 | #define EXT2_FT_SYMLINK 7 | ||
631 | |||
632 | #define EXT2_FT_MAX 8 | ||
633 | |||
634 | /* | ||
635 | * EXT2_DIR_PAD defines the directory entries boundaries | ||
636 | * | ||
637 | * NOTE: It must be a multiple of 4 | ||
638 | */ | ||
639 | #define EXT2_DIR_PAD 4 | ||
640 | #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1) | ||
641 | #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \ | ||
642 | ~EXT2_DIR_ROUND) | ||
643 | |||
644 | #endif /* _LINUX_EXT2_FS_H */ | ||
diff --git a/util-linux/lsattr.c b/util-linux/lsattr.c deleted file mode 100644 index ca523c821..000000000 --- a/util-linux/lsattr.c +++ /dev/null | |||
@@ -1,195 +0,0 @@ | |||
1 | /* | ||
2 | * lsattr.c - List file attributes on an ext2 file system | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
5 | * Laboratoire MASI, Institut Blaise Pascal | ||
6 | * Universite Pierre et Marie Curie (Paris VI) | ||
7 | * | ||
8 | * This file can be redistributed under the terms of the GNU General | ||
9 | * Public License | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * History: | ||
14 | * 93/10/30 - Creation | ||
15 | * 93/11/13 - Replace stat() calls by lstat() to avoid loops | ||
16 | * 94/02/27 - Integrated in Ted's distribution | ||
17 | * 98/12/29 - Display version info only when -V specified (G M Sipe) | ||
18 | */ | ||
19 | |||
20 | #include <sys/types.h> | ||
21 | #include <dirent.h> | ||
22 | #include <errno.h> | ||
23 | #include <fcntl.h> | ||
24 | #include <getopt.h> | ||
25 | #include <stdio.h> | ||
26 | #include <unistd.h> | ||
27 | #include <stdlib.h> | ||
28 | #include <string.h> | ||
29 | #include <sys/param.h> | ||
30 | #include <sys/stat.h> | ||
31 | |||
32 | #include "ext2_fs.h" | ||
33 | #include "e2fsbb.h" | ||
34 | #include "e2p/e2p.h" | ||
35 | |||
36 | #define main lsattr_main | ||
37 | |||
38 | #ifdef __GNUC__ | ||
39 | #define EXT2FS_ATTR(x) __attribute__(x) | ||
40 | #else | ||
41 | #define EXT2FS_ATTR(x) | ||
42 | #endif | ||
43 | |||
44 | static int all; | ||
45 | static int dirs_opt; | ||
46 | static unsigned pf_options; | ||
47 | static int recursive; | ||
48 | static int verbose; | ||
49 | static int generation_opt; | ||
50 | |||
51 | #ifdef _LFS64_LARGEFILE | ||
52 | #define LSTAT lstat64 | ||
53 | #define STRUCT_STAT struct stat64 | ||
54 | #else | ||
55 | #define LSTAT lstat | ||
56 | #define STRUCT_STAT struct stat | ||
57 | #endif | ||
58 | |||
59 | #if 0 | ||
60 | static void usage(void) | ||
61 | { | ||
62 | fprintf(stderr, _("Usage: %s [-RVadlv] [files...]\n"), program_name); | ||
63 | exit(1); | ||
64 | } | ||
65 | #endif | ||
66 | |||
67 | static void list_attributes (const char * name) | ||
68 | { | ||
69 | unsigned long flags; | ||
70 | unsigned long generation; | ||
71 | |||
72 | if (fgetflags (name, &flags) == -1) { | ||
73 | com_err (program_name, errno, _("While reading flags on %s"), | ||
74 | name); | ||
75 | return; | ||
76 | } | ||
77 | if (generation_opt) { | ||
78 | if (fgetversion (name, &generation) == -1) { | ||
79 | com_err (program_name, errno, | ||
80 | _("While reading version on %s"), | ||
81 | name); | ||
82 | return; | ||
83 | } | ||
84 | printf ("%5lu ", generation); | ||
85 | } | ||
86 | if (pf_options & PFOPT_LONG) { | ||
87 | printf("%-28s ", name); | ||
88 | print_flags(stdout, flags, pf_options); | ||
89 | fputc('\n', stdout); | ||
90 | } else { | ||
91 | print_flags(stdout, flags, pf_options); | ||
92 | printf(" %s\n", name); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | static int lsattr_dir_proc (const char *, struct dirent *, void *); | ||
97 | |||
98 | static void lsattr_args (const char * name) | ||
99 | { | ||
100 | STRUCT_STAT st; | ||
101 | |||
102 | if (LSTAT (name, &st) == -1) | ||
103 | com_err (program_name, errno, _("while trying to stat %s"), | ||
104 | name); | ||
105 | else { | ||
106 | if (S_ISDIR(st.st_mode) && !dirs_opt) | ||
107 | iterate_on_dir (name, lsattr_dir_proc, NULL); | ||
108 | else | ||
109 | list_attributes (name); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | static int lsattr_dir_proc (const char * dir_name, struct dirent * de, | ||
114 | void * private EXT2FS_ATTR((unused))) | ||
115 | { | ||
116 | STRUCT_STAT st; | ||
117 | char *path; | ||
118 | int dir_len = strlen(dir_name); | ||
119 | |||
120 | path = malloc(dir_len + strlen (de->d_name) + 2); | ||
121 | |||
122 | if (dir_len && dir_name[dir_len-1] == '/') | ||
123 | sprintf (path, "%s%s", dir_name, de->d_name); | ||
124 | else | ||
125 | sprintf (path, "%s/%s", dir_name, de->d_name); | ||
126 | if (LSTAT (path, &st) == -1) | ||
127 | perror (path); | ||
128 | else { | ||
129 | if (de->d_name[0] != '.' || all) { | ||
130 | list_attributes (path); | ||
131 | if (S_ISDIR(st.st_mode) && recursive && | ||
132 | strcmp(de->d_name, ".") && | ||
133 | strcmp(de->d_name, "..")) { | ||
134 | printf ("\n%s:\n", path); | ||
135 | iterate_on_dir (path, lsattr_dir_proc, NULL); | ||
136 | printf ("\n"); | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | free(path); | ||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | int main (int argc, char ** argv) | ||
145 | { | ||
146 | int c; | ||
147 | int i; | ||
148 | |||
149 | #ifdef ENABLE_NLS | ||
150 | setlocale(LC_MESSAGES, ""); | ||
151 | setlocale(LC_CTYPE, ""); | ||
152 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); | ||
153 | textdomain(NLS_CAT_NAME); | ||
154 | #endif | ||
155 | #if 0 | ||
156 | if (argc && *argv) | ||
157 | program_name = *argv; | ||
158 | #endif | ||
159 | while ((c = getopt (argc, argv, "Radlv")) != EOF) | ||
160 | switch (c) | ||
161 | { | ||
162 | case 'R': | ||
163 | recursive = 1; | ||
164 | break; | ||
165 | case 'V': | ||
166 | verbose = 1; | ||
167 | break; | ||
168 | case 'a': | ||
169 | all = 1; | ||
170 | break; | ||
171 | case 'd': | ||
172 | dirs_opt = 1; | ||
173 | break; | ||
174 | case 'l': | ||
175 | pf_options = PFOPT_LONG; | ||
176 | break; | ||
177 | case 'v': | ||
178 | generation_opt = 1; | ||
179 | break; | ||
180 | default: | ||
181 | usage(); | ||
182 | } | ||
183 | |||
184 | #if 0 | ||
185 | if (verbose) | ||
186 | fprintf (stderr, "lsattr %s (%s)\n", | ||
187 | E2FSPROGS_VERSION, E2FSPROGS_DATE); | ||
188 | #endif | ||
189 | if (optind > argc - 1) | ||
190 | lsattr_args ("."); | ||
191 | else | ||
192 | for (i = optind; i < argc; i++) | ||
193 | lsattr_args (argv[i]); | ||
194 | exit(0); | ||
195 | } | ||