diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-26 01:30:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-26 01:30:59 +0000 |
commit | c4f623ef2a7980a63de7c9f1d539a656b83f10e7 (patch) | |
tree | a294e28b0112052cb9d58b403554b3390e76f50c /e2fsprogs/old_e2fsprogs/e2p | |
parent | 64c54025842f205ad722675105b88044a5b6845a (diff) | |
download | busybox-w32-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.tar.gz busybox-w32-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.tar.bz2 busybox-w32-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.zip |
put small subset of e2fsprogs back in the tree:
lsattr, chattr, fsck. Old e2fsprogs tree is in
e2fsprogs/old_e2fsprogs/*.
Diffstat (limited to 'e2fsprogs/old_e2fsprogs/e2p')
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/Kbuild | 15 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/e2p.h | 64 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/feature.c | 187 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/fgetsetflags.c | 70 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/fgetsetversion.c | 70 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/hashstr.c | 70 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/iod.c | 52 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/ls.c | 273 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/mntopts.c | 134 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/ostype.c | 74 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/parse_num.c | 65 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/pe.c | 32 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/pf.c | 74 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/ps.c | 27 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/uuid.c | 78 |
15 files changed, 1285 insertions, 0 deletions
diff --git a/e2fsprogs/old_e2fsprogs/e2p/Kbuild b/e2fsprogs/old_e2fsprogs/e2p/Kbuild new file mode 100644 index 000000000..c0ff824e3 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/Kbuild | |||
@@ -0,0 +1,15 @@ | |||
1 | # Makefile for busybox | ||
2 | # | ||
3 | # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> | ||
4 | # | ||
5 | # Licensed under the GPL v2, see the file LICENSE in this tarball. | ||
6 | |||
7 | NEEDED-$(CONFIG_CHATTR) = y | ||
8 | NEEDED-$(CONFIG_LSATTR) = y | ||
9 | NEEDED-$(CONFIG_MKE2FS) = y | ||
10 | NEEDED-$(CONFIG_TUNE2FS) = y | ||
11 | |||
12 | lib-y:= | ||
13 | lib-$(NEEDED-y) += fgetsetflags.o fgetsetversion.o pf.o iod.o mntopts.o \ | ||
14 | feature.o ls.o uuid.o pe.o ostype.o ps.o hashstr.o \ | ||
15 | parse_num.o | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/e2p.h b/e2fsprogs/old_e2fsprogs/e2p/e2p.h new file mode 100644 index 000000000..2a2367b9f --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/e2p.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | #include "busybox.h" | ||
3 | #include <sys/types.h> /* Needed by dirent.h on netbsd */ | ||
4 | #include <stdio.h> | ||
5 | #include <dirent.h> | ||
6 | |||
7 | #include "../ext2fs/ext2_fs.h" | ||
8 | |||
9 | #define E2P_FEATURE_COMPAT 0 | ||
10 | #define E2P_FEATURE_INCOMPAT 1 | ||
11 | #define E2P_FEATURE_RO_INCOMPAT 2 | ||
12 | #ifndef EXT3_FEATURE_INCOMPAT_EXTENTS | ||
13 | #define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 | ||
14 | #endif | ||
15 | |||
16 | /* `options' for print_flags() */ | ||
17 | |||
18 | #define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */ | ||
19 | |||
20 | /*int fgetversion (const char * name, unsigned long * version);*/ | ||
21 | /*int fsetversion (const char * name, unsigned long version);*/ | ||
22 | int fgetsetversion(const char * name, unsigned long * get_version, unsigned long set_version); | ||
23 | #define fgetversion(name, version) fgetsetversion(name, version, 0) | ||
24 | #define fsetversion(name, version) fgetsetversion(name, NULL, version) | ||
25 | |||
26 | /*int fgetflags (const char * name, unsigned long * flags);*/ | ||
27 | /*int fsetflags (const char * name, unsigned long flags);*/ | ||
28 | int fgetsetflags(const char * name, unsigned long * get_flags, unsigned long set_flags); | ||
29 | #define fgetflags(name, flags) fgetsetflags(name, flags, 0) | ||
30 | #define fsetflags(name, flags) fgetsetflags(name, NULL, flags) | ||
31 | |||
32 | int getflags (int fd, unsigned long * flags); | ||
33 | int getversion (int fd, unsigned long * version); | ||
34 | int iterate_on_dir (const char * dir_name, | ||
35 | int (*func) (const char *, struct dirent *, void *), | ||
36 | void * private); | ||
37 | /*void list_super(struct ext2_super_block * s);*/ | ||
38 | void list_super2(struct ext2_super_block * s, FILE *f); | ||
39 | #define list_super(s) list_super2(s, stdout) | ||
40 | void print_fs_errors (FILE * f, unsigned short errors); | ||
41 | void print_flags (FILE * f, unsigned long flags, unsigned options); | ||
42 | void print_fs_state (FILE * f, unsigned short state); | ||
43 | int setflags (int fd, unsigned long flags); | ||
44 | int setversion (int fd, unsigned long version); | ||
45 | |||
46 | const char *e2p_feature2string(int compat, unsigned int mask); | ||
47 | int e2p_string2feature(char *string, int *compat, unsigned int *mask); | ||
48 | int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array); | ||
49 | |||
50 | int e2p_is_null_uuid(void *uu); | ||
51 | void e2p_uuid_to_str(void *uu, char *out); | ||
52 | const char *e2p_uuid2str(void *uu); | ||
53 | |||
54 | const char *e2p_hash2string(int num); | ||
55 | int e2p_string2hash(char *string); | ||
56 | |||
57 | const char *e2p_mntopt2string(unsigned int mask); | ||
58 | int e2p_string2mntopt(char *string, unsigned int *mask); | ||
59 | int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok); | ||
60 | |||
61 | unsigned long parse_num_blocks(const char *arg, int log_block_size); | ||
62 | |||
63 | char *e2p_os2string(int os_type); | ||
64 | int e2p_string2os(char *str); | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/feature.c b/e2fsprogs/old_e2fsprogs/e2p/feature.c new file mode 100644 index 000000000..b45754f97 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/feature.c | |||
@@ -0,0 +1,187 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * feature.c --- convert between features and strings | ||
4 | * | ||
5 | * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu> | ||
6 | * | ||
7 | * This file can be redistributed under the terms of the GNU Library General | ||
8 | * Public License | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <stdio.h> | ||
13 | #include <stdlib.h> | ||
14 | #include <string.h> | ||
15 | #include <ctype.h> | ||
16 | #include <errno.h> | ||
17 | |||
18 | #include "e2p.h" | ||
19 | |||
20 | struct feature { | ||
21 | int compat; | ||
22 | unsigned int mask; | ||
23 | const char *string; | ||
24 | }; | ||
25 | |||
26 | static const struct feature feature_list[] = { | ||
27 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_PREALLOC, | ||
28 | "dir_prealloc" }, | ||
29 | { E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL, | ||
30 | "has_journal" }, | ||
31 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_IMAGIC_INODES, | ||
32 | "imagic_inodes" }, | ||
33 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_EXT_ATTR, | ||
34 | "ext_attr" }, | ||
35 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX, | ||
36 | "dir_index" }, | ||
37 | { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INODE, | ||
38 | "resize_inode" }, | ||
39 | { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER, | ||
40 | "sparse_super" }, | ||
41 | { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE, | ||
42 | "large_file" }, | ||
43 | { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION, | ||
44 | "compression" }, | ||
45 | { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE, | ||
46 | "filetype" }, | ||
47 | { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER, | ||
48 | "needs_recovery" }, | ||
49 | { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_JOURNAL_DEV, | ||
50 | "journal_dev" }, | ||
51 | { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS, | ||
52 | "extents" }, | ||
53 | { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_META_BG, | ||
54 | "meta_bg" }, | ||
55 | { 0, 0, 0 }, | ||
56 | }; | ||
57 | |||
58 | const char *e2p_feature2string(int compat, unsigned int mask) | ||
59 | { | ||
60 | const struct feature *f; | ||
61 | static char buf[20]; | ||
62 | char fchar; | ||
63 | int fnum; | ||
64 | |||
65 | for (f = feature_list; f->string; f++) { | ||
66 | if ((compat == f->compat) && | ||
67 | (mask == f->mask)) | ||
68 | return f->string; | ||
69 | } | ||
70 | switch (compat) { | ||
71 | case E2P_FEATURE_COMPAT: | ||
72 | fchar = 'C'; | ||
73 | break; | ||
74 | case E2P_FEATURE_INCOMPAT: | ||
75 | fchar = 'I'; | ||
76 | break; | ||
77 | case E2P_FEATURE_RO_INCOMPAT: | ||
78 | fchar = 'R'; | ||
79 | break; | ||
80 | default: | ||
81 | fchar = '?'; | ||
82 | break; | ||
83 | } | ||
84 | for (fnum = 0; mask >>= 1; fnum++); | ||
85 | sprintf(buf, "FEATURE_%c%d", fchar, fnum); | ||
86 | return buf; | ||
87 | } | ||
88 | |||
89 | int e2p_string2feature(char *string, int *compat_type, unsigned int *mask) | ||
90 | { | ||
91 | const struct feature *f; | ||
92 | char *eptr; | ||
93 | int num; | ||
94 | |||
95 | for (f = feature_list; f->string; f++) { | ||
96 | if (!strcasecmp(string, f->string)) { | ||
97 | *compat_type = f->compat; | ||
98 | *mask = f->mask; | ||
99 | return 0; | ||
100 | } | ||
101 | } | ||
102 | if (strncasecmp(string, "FEATURE_", 8)) | ||
103 | return 1; | ||
104 | |||
105 | switch (string[8]) { | ||
106 | case 'c': | ||
107 | case 'C': | ||
108 | *compat_type = E2P_FEATURE_COMPAT; | ||
109 | break; | ||
110 | case 'i': | ||
111 | case 'I': | ||
112 | *compat_type = E2P_FEATURE_INCOMPAT; | ||
113 | break; | ||
114 | case 'r': | ||
115 | case 'R': | ||
116 | *compat_type = E2P_FEATURE_RO_INCOMPAT; | ||
117 | break; | ||
118 | default: | ||
119 | return 1; | ||
120 | } | ||
121 | if (string[9] == 0) | ||
122 | return 1; | ||
123 | num = strtol(string+9, &eptr, 10); | ||
124 | if (num > 32 || num < 0) | ||
125 | return 1; | ||
126 | if (*eptr) | ||
127 | return 1; | ||
128 | *mask = 1 << num; | ||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | static inline char *skip_over_blanks(char *cp) | ||
133 | { | ||
134 | while (*cp && isspace(*cp)) | ||
135 | cp++; | ||
136 | return cp; | ||
137 | } | ||
138 | |||
139 | static inline char *skip_over_word(char *cp) | ||
140 | { | ||
141 | while (*cp && !isspace(*cp) && *cp != ',') | ||
142 | cp++; | ||
143 | return cp; | ||
144 | } | ||
145 | |||
146 | /* | ||
147 | * Edit a feature set array as requested by the user. The ok_array, | ||
148 | * if set, allows the application to limit what features the user is | ||
149 | * allowed to set or clear using this function. | ||
150 | */ | ||
151 | int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array) | ||
152 | { | ||
153 | char *cp, *buf, *next; | ||
154 | int neg; | ||
155 | unsigned int mask; | ||
156 | int compat_type; | ||
157 | |||
158 | buf = xstrdup(str); | ||
159 | cp = buf; | ||
160 | while (cp && *cp) { | ||
161 | neg = 0; | ||
162 | cp = skip_over_blanks(cp); | ||
163 | next = skip_over_word(cp); | ||
164 | if (*next == 0) | ||
165 | next = 0; | ||
166 | else | ||
167 | *next = 0; | ||
168 | switch (*cp) { | ||
169 | case '-': | ||
170 | case '^': | ||
171 | neg++; | ||
172 | case '+': | ||
173 | cp++; | ||
174 | break; | ||
175 | } | ||
176 | if (e2p_string2feature(cp, &compat_type, &mask)) | ||
177 | return 1; | ||
178 | if (ok_array && !(ok_array[compat_type] & mask)) | ||
179 | return 1; | ||
180 | if (neg) | ||
181 | compat_array[compat_type] &= ~mask; | ||
182 | else | ||
183 | compat_array[compat_type] |= mask; | ||
184 | cp = next ? next+1 : 0; | ||
185 | } | ||
186 | return 0; | ||
187 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/fgetsetflags.c b/e2fsprogs/old_e2fsprogs/e2p/fgetsetflags.c new file mode 100644 index 000000000..008b79850 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/fgetsetflags.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * fgetflags.c - Get a file flags on an ext2 file system | ||
4 | * fsetflags.c - Set a file flags on an ext2 file system | ||
5 | * | ||
6 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
7 | * Laboratoire MASI, Institut Blaise Pascal | ||
8 | * Universite Pierre et Marie Curie (Paris VI) | ||
9 | * | ||
10 | * This file can be redistributed under the terms of the GNU Library General | ||
11 | * Public License | ||
12 | */ | ||
13 | |||
14 | /* | ||
15 | * History: | ||
16 | * 93/10/30 - Creation | ||
17 | */ | ||
18 | |||
19 | #ifdef HAVE_ERRNO_H | ||
20 | #include <errno.h> | ||
21 | #endif | ||
22 | #ifdef HAVE_UNISTD_H | ||
23 | #include <unistd.h> | ||
24 | #endif | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/stat.h> | ||
27 | #ifdef HAVE_EXT2_IOCTLS | ||
28 | #include <fcntl.h> | ||
29 | #include <sys/ioctl.h> | ||
30 | #endif | ||
31 | |||
32 | #include "e2p.h" | ||
33 | |||
34 | #ifdef O_LARGEFILE | ||
35 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) | ||
36 | #else | ||
37 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) | ||
38 | #endif | ||
39 | |||
40 | int fgetsetflags (const char * name, unsigned long * get_flags, unsigned long set_flags) | ||
41 | { | ||
42 | #ifdef HAVE_EXT2_IOCTLS | ||
43 | struct stat buf; | ||
44 | int fd, r, f, save_errno = 0; | ||
45 | |||
46 | if (!stat(name, &buf) && | ||
47 | !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { | ||
48 | goto notsupp; | ||
49 | } | ||
50 | fd = open (name, OPEN_FLAGS); | ||
51 | if (fd == -1) | ||
52 | return -1; | ||
53 | if (!get_flags) { | ||
54 | f = (int) set_flags; | ||
55 | r = ioctl (fd, EXT2_IOC_SETFLAGS, &f); | ||
56 | } else { | ||
57 | r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); | ||
58 | *get_flags = f; | ||
59 | } | ||
60 | if (r == -1) | ||
61 | save_errno = errno; | ||
62 | close (fd); | ||
63 | if (save_errno) | ||
64 | errno = save_errno; | ||
65 | return r; | ||
66 | notsupp: | ||
67 | #endif /* HAVE_EXT2_IOCTLS */ | ||
68 | errno = EOPNOTSUPP; | ||
69 | return -1; | ||
70 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/fgetsetversion.c b/e2fsprogs/old_e2fsprogs/e2p/fgetsetversion.c new file mode 100644 index 000000000..8d79054d6 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/fgetsetversion.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * fgetversion.c - Get a file version on an ext2 file system | ||
4 | * fsetversion.c - Set a file version on an ext2 file system | ||
5 | * | ||
6 | * | ||
7 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
8 | * Laboratoire MASI, Institut Blaise Pascal | ||
9 | * Universite Pierre et Marie Curie (Paris VI) | ||
10 | * | ||
11 | * This file can be redistributed under the terms of the GNU Library General | ||
12 | * Public License | ||
13 | */ | ||
14 | |||
15 | /* | ||
16 | * History: | ||
17 | * 93/10/30 - Creation | ||
18 | */ | ||
19 | |||
20 | #ifdef HAVE_ERRNO_H | ||
21 | #include <errno.h> | ||
22 | #endif | ||
23 | #ifdef HAVE_UNISTD_H | ||
24 | #include <unistd.h> | ||
25 | #endif | ||
26 | #include <fcntl.h> | ||
27 | #include <sys/ioctl.h> | ||
28 | |||
29 | #include "e2p.h" | ||
30 | |||
31 | #ifdef O_LARGEFILE | ||
32 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) | ||
33 | #else | ||
34 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) | ||
35 | #endif | ||
36 | |||
37 | /* | ||
38 | To do fsetversion: unsigned long *ptr_version must be set to NULL. | ||
39 | and unsigned long version must be set to a value | ||
40 | To do fgetversion: unsigned long *ptr_version must NOT be set to NULL | ||
41 | and unsigned long version is ignored. | ||
42 | TITO. | ||
43 | */ | ||
44 | |||
45 | int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version) | ||
46 | { | ||
47 | #ifdef HAVE_EXT2_IOCTLS | ||
48 | int fd, r, ver, save_errno = 0; | ||
49 | |||
50 | fd = open (name, OPEN_FLAGS); | ||
51 | if (fd == -1) | ||
52 | return -1; | ||
53 | if (!get_version) { | ||
54 | ver = (int) set_version; | ||
55 | r = ioctl (fd, EXT2_IOC_SETVERSION, &ver); | ||
56 | } else { | ||
57 | r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); | ||
58 | *get_version = ver; | ||
59 | } | ||
60 | if (r == -1) | ||
61 | save_errno = errno; | ||
62 | close (fd); | ||
63 | if (save_errno) | ||
64 | errno = save_errno; | ||
65 | return r; | ||
66 | #else /* ! HAVE_EXT2_IOCTLS */ | ||
67 | errno = EOPNOTSUPP; | ||
68 | return -1; | ||
69 | #endif /* ! HAVE_EXT2_IOCTLS */ | ||
70 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/hashstr.c b/e2fsprogs/old_e2fsprogs/e2p/hashstr.c new file mode 100644 index 000000000..697ffadc3 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/hashstr.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * feature.c --- convert between features and strings | ||
4 | * | ||
5 | * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu> | ||
6 | * | ||
7 | * This file can be redistributed under the terms of the GNU Library General | ||
8 | * Public License | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <stdio.h> | ||
13 | #include <stdlib.h> | ||
14 | #include <string.h> | ||
15 | #include <ctype.h> | ||
16 | #include <errno.h> | ||
17 | |||
18 | #include "e2p.h" | ||
19 | |||
20 | struct hash { | ||
21 | int num; | ||
22 | const char *string; | ||
23 | }; | ||
24 | |||
25 | static const struct hash hash_list[] = { | ||
26 | { EXT2_HASH_LEGACY, "legacy" }, | ||
27 | { EXT2_HASH_HALF_MD4, "half_md4" }, | ||
28 | { EXT2_HASH_TEA, "tea" }, | ||
29 | { 0, 0 }, | ||
30 | }; | ||
31 | |||
32 | const char *e2p_hash2string(int num) | ||
33 | { | ||
34 | const struct hash *p; | ||
35 | static char buf[20]; | ||
36 | |||
37 | for (p = hash_list; p->string; p++) { | ||
38 | if (num == p->num) | ||
39 | return p->string; | ||
40 | } | ||
41 | sprintf(buf, "HASHALG_%d", num); | ||
42 | return buf; | ||
43 | } | ||
44 | |||
45 | /* | ||
46 | * Returns the hash algorithm, or -1 on error | ||
47 | */ | ||
48 | int e2p_string2hash(char *string) | ||
49 | { | ||
50 | const struct hash *p; | ||
51 | char *eptr; | ||
52 | int num; | ||
53 | |||
54 | for (p = hash_list; p->string; p++) { | ||
55 | if (!strcasecmp(string, p->string)) { | ||
56 | return p->num; | ||
57 | } | ||
58 | } | ||
59 | if (strncasecmp(string, "HASHALG_", 8)) | ||
60 | return -1; | ||
61 | |||
62 | if (string[8] == 0) | ||
63 | return -1; | ||
64 | num = strtol(string+8, &eptr, 10); | ||
65 | if (num > 255 || num < 0) | ||
66 | return -1; | ||
67 | if (*eptr) | ||
68 | return -1; | ||
69 | return num; | ||
70 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/iod.c b/e2fsprogs/old_e2fsprogs/e2p/iod.c new file mode 100644 index 000000000..23ab8d5b5 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/iod.c | |||
@@ -0,0 +1,52 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * iod.c - Iterate a function on each entry of a directory | ||
4 | * | ||
5 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
6 | * Laboratoire MASI, Institut Blaise Pascal | ||
7 | * Universite Pierre et Marie Curie (Paris VI) | ||
8 | * | ||
9 | * This file can be redistributed under the terms of the GNU Library General | ||
10 | * Public License | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * History: | ||
15 | * 93/10/30 - Creation | ||
16 | */ | ||
17 | |||
18 | #include "e2p.h" | ||
19 | #include <unistd.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | |||
23 | int iterate_on_dir (const char * dir_name, | ||
24 | int (*func) (const char *, struct dirent *, void *), | ||
25 | void * private) | ||
26 | { | ||
27 | DIR * dir; | ||
28 | struct dirent *de, *dep; | ||
29 | int max_len, len; | ||
30 | |||
31 | max_len = PATH_MAX + sizeof(struct dirent); | ||
32 | de = xmalloc(max_len+1); | ||
33 | memset(de, 0, max_len+1); | ||
34 | |||
35 | dir = opendir (dir_name); | ||
36 | if (dir == NULL) { | ||
37 | free(de); | ||
38 | return -1; | ||
39 | } | ||
40 | while ((dep = readdir (dir))) { | ||
41 | len = sizeof(struct dirent); | ||
42 | if (len < dep->d_reclen) | ||
43 | len = dep->d_reclen; | ||
44 | if (len > max_len) | ||
45 | len = max_len; | ||
46 | memcpy(de, dep, len); | ||
47 | (*func) (dir_name, de, private); | ||
48 | } | ||
49 | free(de); | ||
50 | closedir(dir); | ||
51 | return 0; | ||
52 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/ls.c b/e2fsprogs/old_e2fsprogs/e2p/ls.c new file mode 100644 index 000000000..9d29db6af --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/ls.c | |||
@@ -0,0 +1,273 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * ls.c - List the contents of an ext2fs superblock | ||
4 | * | ||
5 | * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
6 | * Laboratoire MASI, Institut Blaise Pascal | ||
7 | * Universite Pierre et Marie Curie (Paris VI) | ||
8 | * | ||
9 | * Copyright (C) 1995, 1996, 1997 Theodore Ts'o <tytso@mit.edu> | ||
10 | * | ||
11 | * This file can be redistributed under the terms of the GNU Library General | ||
12 | * Public License | ||
13 | */ | ||
14 | |||
15 | #include <stdio.h> | ||
16 | #include <stdlib.h> | ||
17 | #include <sys/types.h> | ||
18 | #include <string.h> | ||
19 | #include <grp.h> | ||
20 | #include <pwd.h> | ||
21 | #include <time.h> | ||
22 | |||
23 | #include "e2p.h" | ||
24 | |||
25 | static void print_user(unsigned short uid, FILE *f) | ||
26 | { | ||
27 | struct passwd *pw = getpwuid(uid); | ||
28 | fprintf(f, "%u (user %s)\n", uid, | ||
29 | (pw == NULL ? "unknown" : pw->pw_name)); | ||
30 | } | ||
31 | |||
32 | static void print_group(unsigned short gid, FILE *f) | ||
33 | { | ||
34 | struct group *gr = getgrgid(gid); | ||
35 | fprintf(f, "%u (group %s)\n", gid, | ||
36 | (gr == NULL ? "unknown" : gr->gr_name)); | ||
37 | } | ||
38 | |||
39 | #define MONTH_INT (86400 * 30) | ||
40 | #define WEEK_INT (86400 * 7) | ||
41 | #define DAY_INT (86400) | ||
42 | #define HOUR_INT (60 * 60) | ||
43 | #define MINUTE_INT (60) | ||
44 | |||
45 | static const char *interval_string(unsigned int secs) | ||
46 | { | ||
47 | static char buf[256], tmp[80]; | ||
48 | int hr, min, num; | ||
49 | |||
50 | buf[0] = 0; | ||
51 | |||
52 | if (secs == 0) | ||
53 | return "<none>"; | ||
54 | |||
55 | if (secs >= MONTH_INT) { | ||
56 | num = secs / MONTH_INT; | ||
57 | secs -= num*MONTH_INT; | ||
58 | sprintf(buf, "%d month%s", num, (num>1) ? "s" : ""); | ||
59 | } | ||
60 | if (secs >= WEEK_INT) { | ||
61 | num = secs / WEEK_INT; | ||
62 | secs -= num*WEEK_INT; | ||
63 | sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "", | ||
64 | num, (num>1) ? "s" : ""); | ||
65 | strcat(buf, tmp); | ||
66 | } | ||
67 | if (secs >= DAY_INT) { | ||
68 | num = secs / DAY_INT; | ||
69 | secs -= num*DAY_INT; | ||
70 | sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "", | ||
71 | num, (num>1) ? "s" : ""); | ||
72 | strcat(buf, tmp); | ||
73 | } | ||
74 | if (secs > 0) { | ||
75 | hr = secs / HOUR_INT; | ||
76 | secs -= hr*HOUR_INT; | ||
77 | min = secs / MINUTE_INT; | ||
78 | secs -= min*MINUTE_INT; | ||
79 | sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "", | ||
80 | hr, min, secs); | ||
81 | strcat(buf, tmp); | ||
82 | } | ||
83 | return buf; | ||
84 | } | ||
85 | |||
86 | static void print_features(struct ext2_super_block * s, FILE *f) | ||
87 | { | ||
88 | #ifdef EXT2_DYNAMIC_REV | ||
89 | int i, j, printed=0; | ||
90 | __u32 *mask = &s->s_feature_compat, m; | ||
91 | |||
92 | fprintf(f, "Filesystem features: "); | ||
93 | for (i=0; i <3; i++,mask++) { | ||
94 | for (j=0,m=1; j < 32; j++, m<<=1) { | ||
95 | if (*mask & m) { | ||
96 | fprintf(f, " %s", e2p_feature2string(i, m)); | ||
97 | printed++; | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | if (printed == 0) | ||
102 | fprintf(f, " (none)"); | ||
103 | fprintf(f, "\n"); | ||
104 | #endif | ||
105 | } | ||
106 | |||
107 | static void print_mntopts(struct ext2_super_block * s, FILE *f) | ||
108 | { | ||
109 | #ifdef EXT2_DYNAMIC_REV | ||
110 | int i, printed=0; | ||
111 | __u32 mask = s->s_default_mount_opts, m; | ||
112 | |||
113 | fprintf(f, "Default mount options: "); | ||
114 | if (mask & EXT3_DEFM_JMODE) { | ||
115 | fprintf(f, " %s", e2p_mntopt2string(mask & EXT3_DEFM_JMODE)); | ||
116 | printed++; | ||
117 | } | ||
118 | for (i=0,m=1; i < 32; i++, m<<=1) { | ||
119 | if (m & EXT3_DEFM_JMODE) | ||
120 | continue; | ||
121 | if (mask & m) { | ||
122 | fprintf(f, " %s", e2p_mntopt2string(m)); | ||
123 | printed++; | ||
124 | } | ||
125 | } | ||
126 | if (printed == 0) | ||
127 | fprintf(f, " (none)"); | ||
128 | fprintf(f, "\n"); | ||
129 | #endif | ||
130 | } | ||
131 | |||
132 | |||
133 | #ifndef EXT2_INODE_SIZE | ||
134 | #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode) | ||
135 | #endif | ||
136 | |||
137 | #ifndef EXT2_GOOD_OLD_REV | ||
138 | #define EXT2_GOOD_OLD_REV 0 | ||
139 | #endif | ||
140 | |||
141 | void list_super2(struct ext2_super_block * sb, FILE *f) | ||
142 | { | ||
143 | int inode_blocks_per_group; | ||
144 | char buf[80], *str; | ||
145 | time_t tm; | ||
146 | |||
147 | inode_blocks_per_group = (((sb->s_inodes_per_group * | ||
148 | EXT2_INODE_SIZE(sb)) + | ||
149 | EXT2_BLOCK_SIZE(sb) - 1) / | ||
150 | EXT2_BLOCK_SIZE(sb)); | ||
151 | if (sb->s_volume_name[0]) { | ||
152 | memset(buf, 0, sizeof(buf)); | ||
153 | strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name)); | ||
154 | } else | ||
155 | strcpy(buf, "<none>"); | ||
156 | fprintf(f, "Filesystem volume name: %s\n", buf); | ||
157 | if (sb->s_last_mounted[0]) { | ||
158 | memset(buf, 0, sizeof(buf)); | ||
159 | strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted)); | ||
160 | } else | ||
161 | strcpy(buf, "<not available>"); | ||
162 | fprintf(f, | ||
163 | "Last mounted on: %s\n" | ||
164 | "Filesystem UUID: %s\n" | ||
165 | "Filesystem magic number: 0x%04X\n" | ||
166 | "Filesystem revision #: %d", | ||
167 | buf, e2p_uuid2str(sb->s_uuid), sb->s_magic, sb->s_rev_level); | ||
168 | if (sb->s_rev_level == EXT2_GOOD_OLD_REV) { | ||
169 | fprintf(f, " (original)\n"); | ||
170 | #ifdef EXT2_DYNAMIC_REV | ||
171 | } else if (sb->s_rev_level == EXT2_DYNAMIC_REV) { | ||
172 | fprintf(f, " (dynamic)\n"); | ||
173 | #endif | ||
174 | } else | ||
175 | fprintf(f, " (unknown)\n"); | ||
176 | print_features(sb, f); | ||
177 | print_mntopts(sb, f); | ||
178 | fprintf(f, "Filesystem state: "); | ||
179 | print_fs_state (f, sb->s_state); | ||
180 | fprintf(f, "\nErrors behavior: "); | ||
181 | print_fs_errors(f, sb->s_errors); | ||
182 | str = e2p_os2string(sb->s_creator_os); | ||
183 | fprintf(f, | ||
184 | "\n" | ||
185 | "Filesystem OS type: %s\n" | ||
186 | "Inode count: %u\n" | ||
187 | "Block count: %u\n" | ||
188 | "Reserved block count: %u\n" | ||
189 | "Free blocks: %u\n" | ||
190 | "Free inodes: %u\n" | ||
191 | "First block: %u\n" | ||
192 | "Block size: %u\n" | ||
193 | "Fragment size: %u\n", | ||
194 | str, sb->s_inodes_count, sb->s_blocks_count, sb->s_r_blocks_count, | ||
195 | sb->s_free_blocks_count, sb->s_free_inodes_count, | ||
196 | sb->s_first_data_block, EXT2_BLOCK_SIZE(sb), EXT2_FRAG_SIZE(sb)); | ||
197 | free(str); | ||
198 | if (sb->s_reserved_gdt_blocks) | ||
199 | fprintf(f, "Reserved GDT blocks: %u\n", | ||
200 | sb->s_reserved_gdt_blocks); | ||
201 | fprintf(f, | ||
202 | "Blocks per group: %u\n" | ||
203 | "Fragments per group: %u\n" | ||
204 | "Inodes per group: %u\n" | ||
205 | "Inode blocks per group: %u\n", | ||
206 | sb->s_blocks_per_group, sb->s_frags_per_group, | ||
207 | sb->s_inodes_per_group, 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, | ||
220 | "Last write time: %s" | ||
221 | "Mount count: %u\n" | ||
222 | "Maximum mount count: %d\n", | ||
223 | ctime(&tm), sb->s_mnt_count, sb->s_max_mnt_count); | ||
224 | tm = sb->s_lastcheck; | ||
225 | fprintf(f, | ||
226 | "Last checked: %s" | ||
227 | "Check interval: %u (%s)\n", | ||
228 | ctime(&tm), | ||
229 | sb->s_checkinterval, interval_string(sb->s_checkinterval)); | ||
230 | if (sb->s_checkinterval) | ||
231 | { | ||
232 | time_t next; | ||
233 | |||
234 | next = sb->s_lastcheck + sb->s_checkinterval; | ||
235 | fprintf(f, "Next check after: %s", ctime(&next)); | ||
236 | } | ||
237 | fprintf(f, "Reserved blocks uid: "); | ||
238 | print_user(sb->s_def_resuid, f); | ||
239 | fprintf(f, "Reserved blocks gid: "); | ||
240 | print_group(sb->s_def_resgid, f); | ||
241 | if (sb->s_rev_level >= EXT2_DYNAMIC_REV) { | ||
242 | fprintf(f, | ||
243 | "First inode: %d\n" | ||
244 | "Inode size: %d\n", | ||
245 | sb->s_first_ino, sb->s_inode_size); | ||
246 | } | ||
247 | if (!e2p_is_null_uuid(sb->s_journal_uuid)) | ||
248 | fprintf(f, "Journal UUID: %s\n", | ||
249 | e2p_uuid2str(sb->s_journal_uuid)); | ||
250 | if (sb->s_journal_inum) | ||
251 | fprintf(f, "Journal inode: %u\n", | ||
252 | sb->s_journal_inum); | ||
253 | if (sb->s_journal_dev) | ||
254 | fprintf(f, "Journal device: 0x%04x\n", | ||
255 | sb->s_journal_dev); | ||
256 | if (sb->s_last_orphan) | ||
257 | fprintf(f, "First orphan inode: %u\n", | ||
258 | sb->s_last_orphan); | ||
259 | if ((sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) || | ||
260 | sb->s_def_hash_version) | ||
261 | fprintf(f, "Default directory hash: %s\n", | ||
262 | e2p_hash2string(sb->s_def_hash_version)); | ||
263 | if (!e2p_is_null_uuid(sb->s_hash_seed)) | ||
264 | fprintf(f, "Directory Hash Seed: %s\n", | ||
265 | e2p_uuid2str(sb->s_hash_seed)); | ||
266 | if (sb->s_jnl_backup_type) { | ||
267 | fprintf(f, "Journal backup: "); | ||
268 | if (sb->s_jnl_backup_type == 1) | ||
269 | fprintf(f, "inode blocks\n"); | ||
270 | else | ||
271 | fprintf(f, "type %u\n", sb->s_jnl_backup_type); | ||
272 | } | ||
273 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/mntopts.c b/e2fsprogs/old_e2fsprogs/e2p/mntopts.c new file mode 100644 index 000000000..17c26c480 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/mntopts.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * mountopts.c --- convert between default mount options and strings | ||
4 | * | ||
5 | * Copyright (C) 2002 Theodore Ts'o <tytso@mit.edu> | ||
6 | * | ||
7 | * This file can be redistributed under the terms of the GNU Library General | ||
8 | * Public License | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <stdio.h> | ||
13 | #include <stdlib.h> | ||
14 | #include <string.h> | ||
15 | #include <ctype.h> | ||
16 | #include <errno.h> | ||
17 | |||
18 | #include "e2p.h" | ||
19 | |||
20 | struct mntopt { | ||
21 | unsigned int mask; | ||
22 | const char *string; | ||
23 | }; | ||
24 | |||
25 | static const struct mntopt mntopt_list[] = { | ||
26 | { EXT2_DEFM_DEBUG, "debug" }, | ||
27 | { EXT2_DEFM_BSDGROUPS, "bsdgroups" }, | ||
28 | { EXT2_DEFM_XATTR_USER, "user_xattr" }, | ||
29 | { EXT2_DEFM_ACL, "acl" }, | ||
30 | { EXT2_DEFM_UID16, "uid16" }, | ||
31 | { EXT3_DEFM_JMODE_DATA, "journal_data" }, | ||
32 | { EXT3_DEFM_JMODE_ORDERED, "journal_data_ordered" }, | ||
33 | { EXT3_DEFM_JMODE_WBACK, "journal_data_writeback" }, | ||
34 | { 0, 0 }, | ||
35 | }; | ||
36 | |||
37 | const char *e2p_mntopt2string(unsigned int mask) | ||
38 | { | ||
39 | const struct mntopt *f; | ||
40 | static char buf[20]; | ||
41 | int fnum; | ||
42 | |||
43 | for (f = mntopt_list; f->string; f++) { | ||
44 | if (mask == f->mask) | ||
45 | return f->string; | ||
46 | } | ||
47 | for (fnum = 0; mask >>= 1; fnum++); | ||
48 | sprintf(buf, "MNTOPT_%d", fnum); | ||
49 | return buf; | ||
50 | } | ||
51 | |||
52 | int e2p_string2mntopt(char *string, unsigned int *mask) | ||
53 | { | ||
54 | const struct mntopt *f; | ||
55 | char *eptr; | ||
56 | int num; | ||
57 | |||
58 | for (f = mntopt_list; f->string; f++) { | ||
59 | if (!strcasecmp(string, f->string)) { | ||
60 | *mask = f->mask; | ||
61 | return 0; | ||
62 | } | ||
63 | } | ||
64 | if (strncasecmp(string, "MNTOPT_", 8)) | ||
65 | return 1; | ||
66 | |||
67 | if (string[8] == 0) | ||
68 | return 1; | ||
69 | num = strtol(string+8, &eptr, 10); | ||
70 | if (num > 32 || num < 0) | ||
71 | return 1; | ||
72 | if (*eptr) | ||
73 | return 1; | ||
74 | *mask = 1 << num; | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static char *skip_over_blanks(char *cp) | ||
79 | { | ||
80 | while (*cp && isspace(*cp)) | ||
81 | cp++; | ||
82 | return cp; | ||
83 | } | ||
84 | |||
85 | static char *skip_over_word(char *cp) | ||
86 | { | ||
87 | while (*cp && !isspace(*cp) && *cp != ',') | ||
88 | cp++; | ||
89 | return cp; | ||
90 | } | ||
91 | |||
92 | /* | ||
93 | * Edit a mntopt set array as requested by the user. The ok | ||
94 | * parameter, if non-zero, allows the application to limit what | ||
95 | * mntopts the user is allowed to set or clear using this function. | ||
96 | */ | ||
97 | int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok) | ||
98 | { | ||
99 | char *cp, *buf, *next; | ||
100 | int neg; | ||
101 | unsigned int mask; | ||
102 | |||
103 | buf = xstrdup(str); | ||
104 | cp = buf; | ||
105 | while (cp && *cp) { | ||
106 | neg = 0; | ||
107 | cp = skip_over_blanks(cp); | ||
108 | next = skip_over_word(cp); | ||
109 | if (*next == 0) | ||
110 | next = 0; | ||
111 | else | ||
112 | *next = 0; | ||
113 | switch (*cp) { | ||
114 | case '-': | ||
115 | case '^': | ||
116 | neg++; | ||
117 | case '+': | ||
118 | cp++; | ||
119 | break; | ||
120 | } | ||
121 | if (e2p_string2mntopt(cp, &mask)) | ||
122 | return 1; | ||
123 | if (ok && !(ok & mask)) | ||
124 | return 1; | ||
125 | if (mask & EXT3_DEFM_JMODE) | ||
126 | *mntopts &= ~EXT3_DEFM_JMODE; | ||
127 | if (neg) | ||
128 | *mntopts &= ~mask; | ||
129 | else | ||
130 | *mntopts |= mask; | ||
131 | cp = next ? next+1 : 0; | ||
132 | } | ||
133 | return 0; | ||
134 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/ostype.c b/e2fsprogs/old_e2fsprogs/e2p/ostype.c new file mode 100644 index 000000000..0e111d408 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/ostype.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * getostype.c - Get the Filesystem OS type | ||
4 | * | ||
5 | * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu> | ||
6 | * | ||
7 | * This file can be redistributed under the terms of the GNU Library General | ||
8 | * Public License | ||
9 | */ | ||
10 | |||
11 | #include "e2p.h" | ||
12 | #include <string.h> | ||
13 | #include <stdlib.h> | ||
14 | |||
15 | static const char * const os_tab[] = | ||
16 | { "Linux", | ||
17 | "Hurd", | ||
18 | "Masix", | ||
19 | "FreeBSD", | ||
20 | "Lites", | ||
21 | 0 }; | ||
22 | |||
23 | /* | ||
24 | * Convert an os_type to a string | ||
25 | */ | ||
26 | char *e2p_os2string(int os_type) | ||
27 | { | ||
28 | const char *os; | ||
29 | char *ret; | ||
30 | |||
31 | if (os_type <= EXT2_OS_LITES) | ||
32 | os = os_tab[os_type]; | ||
33 | else | ||
34 | os = "(unknown os)"; | ||
35 | |||
36 | ret = xstrdup(os); | ||
37 | return ret; | ||
38 | } | ||
39 | |||
40 | /* | ||
41 | * Convert an os_type to a string | ||
42 | */ | ||
43 | int e2p_string2os(char *str) | ||
44 | { | ||
45 | const char * const *cpp; | ||
46 | int i = 0; | ||
47 | |||
48 | for (cpp = os_tab; *cpp; cpp++, i++) { | ||
49 | if (!strcasecmp(str, *cpp)) | ||
50 | return i; | ||
51 | } | ||
52 | return -1; | ||
53 | } | ||
54 | |||
55 | #ifdef TEST_PROGRAM | ||
56 | int main(int argc, char **argv) | ||
57 | { | ||
58 | char *s; | ||
59 | int i, os; | ||
60 | |||
61 | for (i=0; i <= EXT2_OS_LITES; i++) { | ||
62 | s = e2p_os2string(i); | ||
63 | os = e2p_string2os(s); | ||
64 | printf("%d: %s (%d)\n", i, s, os); | ||
65 | if (i != os) { | ||
66 | fprintf(stderr, "Failure!\n"); | ||
67 | exit(1); | ||
68 | } | ||
69 | } | ||
70 | exit(0); | ||
71 | } | ||
72 | #endif | ||
73 | |||
74 | |||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/parse_num.c b/e2fsprogs/old_e2fsprogs/e2p/parse_num.c new file mode 100644 index 000000000..6db076f9c --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/parse_num.c | |||
@@ -0,0 +1,65 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * parse_num.c - Parse the number of blocks | ||
4 | * | ||
5 | * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu> | ||
6 | * | ||
7 | * This file can be redistributed under the terms of the GNU Library General | ||
8 | * Public License | ||
9 | */ | ||
10 | |||
11 | #include "e2p.h" | ||
12 | |||
13 | #include <stdlib.h> | ||
14 | |||
15 | unsigned long parse_num_blocks(const char *arg, int log_block_size) | ||
16 | { | ||
17 | char *p; | ||
18 | unsigned long long num; | ||
19 | |||
20 | num = strtoull(arg, &p, 0); | ||
21 | |||
22 | if (p[0] && p[1]) | ||
23 | return 0; | ||
24 | |||
25 | switch (*p) { /* Using fall-through logic */ | ||
26 | case 'T': case 't': | ||
27 | num <<= 10; | ||
28 | case 'G': case 'g': | ||
29 | num <<= 10; | ||
30 | case 'M': case 'm': | ||
31 | num <<= 10; | ||
32 | case 'K': case 'k': | ||
33 | num >>= log_block_size; | ||
34 | break; | ||
35 | case 's': | ||
36 | num >>= 1; | ||
37 | break; | ||
38 | case '\0': | ||
39 | break; | ||
40 | default: | ||
41 | return 0; | ||
42 | } | ||
43 | return num; | ||
44 | } | ||
45 | |||
46 | #ifdef DEBUG | ||
47 | #include <unistd.h> | ||
48 | #include <stdio.h> | ||
49 | |||
50 | main(int argc, char **argv) | ||
51 | { | ||
52 | unsigned long num; | ||
53 | int log_block_size = 0; | ||
54 | |||
55 | if (argc != 2) { | ||
56 | fprintf(stderr, "Usage: %s arg\n", argv[0]); | ||
57 | exit(1); | ||
58 | } | ||
59 | |||
60 | num = parse_num_blocks(argv[1], log_block_size); | ||
61 | |||
62 | printf("Parsed number: %lu\n", num); | ||
63 | exit(0); | ||
64 | } | ||
65 | #endif | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/pe.c b/e2fsprogs/old_e2fsprogs/e2p/pe.c new file mode 100644 index 000000000..835274b54 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/pe.c | |||
@@ -0,0 +1,32 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * pe.c - Print a second extended filesystem errors behavior | ||
4 | * | ||
5 | * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
6 | * Laboratoire MASI, Institut Blaise Pascal | ||
7 | * Universite Pierre et Marie Curie (Paris VI) | ||
8 | * | ||
9 | * This file can be redistributed under the terms of the GNU Library General | ||
10 | * Public License | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * History: | ||
15 | * 94/01/09 - Creation | ||
16 | */ | ||
17 | |||
18 | #include <stdio.h> | ||
19 | |||
20 | #include "e2p.h" | ||
21 | |||
22 | void print_fs_errors(FILE *f, unsigned short errors) | ||
23 | { | ||
24 | char *disp = NULL; | ||
25 | switch (errors) { | ||
26 | case EXT2_ERRORS_CONTINUE: disp = "Continue"; break; | ||
27 | case EXT2_ERRORS_RO: disp = "Remount read-only"; break; | ||
28 | case EXT2_ERRORS_PANIC: disp = "Panic"; break; | ||
29 | default: disp = "Unknown (continue)"; | ||
30 | } | ||
31 | fprintf(f, disp); | ||
32 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/pf.c b/e2fsprogs/old_e2fsprogs/e2p/pf.c new file mode 100644 index 000000000..55d4bc487 --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/pf.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * pf.c - Print file attributes on an ext2 file system | ||
4 | * | ||
5 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
6 | * Laboratoire MASI, Institut Blaise Pascal | ||
7 | * Universite Pierre et Marie Curie (Paris VI) | ||
8 | * | ||
9 | * This file can be redistributed under the terms of the GNU Library General | ||
10 | * Public License | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * History: | ||
15 | * 93/10/30 - Creation | ||
16 | */ | ||
17 | |||
18 | #include <stdio.h> | ||
19 | |||
20 | #include "e2p.h" | ||
21 | |||
22 | struct flags_name { | ||
23 | unsigned long flag; | ||
24 | const char *short_name; | ||
25 | const char *long_name; | ||
26 | }; | ||
27 | |||
28 | static const struct flags_name flags_array[] = { | ||
29 | { EXT2_SECRM_FL, "s", "Secure_Deletion" }, | ||
30 | { EXT2_UNRM_FL, "u" , "Undelete" }, | ||
31 | { EXT2_SYNC_FL, "S", "Synchronous_Updates" }, | ||
32 | { EXT2_DIRSYNC_FL, "D", "Synchronous_Directory_Updates" }, | ||
33 | { EXT2_IMMUTABLE_FL, "i", "Immutable" }, | ||
34 | { EXT2_APPEND_FL, "a", "Append_Only" }, | ||
35 | { EXT2_NODUMP_FL, "d", "No_Dump" }, | ||
36 | { EXT2_NOATIME_FL, "A", "No_Atime" }, | ||
37 | { EXT2_COMPR_FL, "c", "Compression_Requested" }, | ||
38 | #ifdef ENABLE_COMPRESSION | ||
39 | { EXT2_COMPRBLK_FL, "B", "Compressed_File" }, | ||
40 | { EXT2_DIRTY_FL, "Z", "Compressed_Dirty_File" }, | ||
41 | { EXT2_NOCOMPR_FL, "X", "Compression_Raw_Access" }, | ||
42 | { EXT2_ECOMPR_FL, "E", "Compression_Error" }, | ||
43 | #endif | ||
44 | { EXT3_JOURNAL_DATA_FL, "j", "Journaled_Data" }, | ||
45 | { EXT2_INDEX_FL, "I", "Indexed_direcctory" }, | ||
46 | { EXT2_NOTAIL_FL, "t", "No_Tailmerging" }, | ||
47 | { EXT2_TOPDIR_FL, "T", "Top_of_Directory_Hierarchies" }, | ||
48 | { 0, NULL, NULL } | ||
49 | }; | ||
50 | |||
51 | void print_flags (FILE * f, unsigned long flags, unsigned options) | ||
52 | { | ||
53 | int long_opt = (options & PFOPT_LONG); | ||
54 | const struct flags_name *fp; | ||
55 | int first = 1; | ||
56 | |||
57 | for (fp = flags_array; fp->flag != 0; fp++) { | ||
58 | if (flags & fp->flag) { | ||
59 | if (long_opt) { | ||
60 | if (first) | ||
61 | first = 0; | ||
62 | else | ||
63 | fputs(", ", f); | ||
64 | fputs(fp->long_name, f); | ||
65 | } else | ||
66 | fputs(fp->short_name, f); | ||
67 | } else { | ||
68 | if (!long_opt) | ||
69 | fputs("-", f); | ||
70 | } | ||
71 | } | ||
72 | if (long_opt && first) | ||
73 | fputs("---", f); | ||
74 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/ps.c b/e2fsprogs/old_e2fsprogs/e2p/ps.c new file mode 100644 index 000000000..a6b4099db --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/ps.c | |||
@@ -0,0 +1,27 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * ps.c - Print filesystem state | ||
4 | * | ||
5 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> | ||
6 | * Laboratoire MASI, Institut Blaise Pascal | ||
7 | * Universite Pierre et Marie Curie (Paris VI) | ||
8 | * | ||
9 | * This file can be redistributed under the terms of the GNU Library General | ||
10 | * Public License | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * History: | ||
15 | * 93/12/22 - Creation | ||
16 | */ | ||
17 | |||
18 | #include <stdio.h> | ||
19 | |||
20 | #include "e2p.h" | ||
21 | |||
22 | void print_fs_state(FILE *f, unsigned short state) | ||
23 | { | ||
24 | fprintf(f, (state & EXT2_VALID_FS ? " clean" : " not clean")); | ||
25 | if (state & EXT2_ERROR_FS) | ||
26 | fprintf(f, " with errors"); | ||
27 | } | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/uuid.c b/e2fsprogs/old_e2fsprogs/e2p/uuid.c new file mode 100644 index 000000000..474d64a5a --- /dev/null +++ b/e2fsprogs/old_e2fsprogs/e2p/uuid.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * uuid.c -- utility routines for manipulating UUID's. | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <string.h> | ||
8 | #include "../ext2fs/ext2_types.h" | ||
9 | |||
10 | #include "e2p.h" | ||
11 | |||
12 | struct uuid { | ||
13 | __u32 time_low; | ||
14 | __u16 time_mid; | ||
15 | __u16 time_hi_and_version; | ||
16 | __u16 clock_seq; | ||
17 | __u8 node[6]; | ||
18 | }; | ||
19 | |||
20 | /* Returns 1 if the uuid is the NULL uuid */ | ||
21 | int e2p_is_null_uuid(void *uu) | ||
22 | { | ||
23 | __u8 *cp; | ||
24 | int i; | ||
25 | |||
26 | for (i=0, cp = uu; i < 16; i++) | ||
27 | if (*cp) | ||
28 | return 0; | ||
29 | return 1; | ||
30 | } | ||
31 | |||
32 | static void e2p_unpack_uuid(void *in, struct uuid *uu) | ||
33 | { | ||
34 | __u8 *ptr = in; | ||
35 | __u32 tmp; | ||
36 | |||
37 | tmp = *ptr++; | ||
38 | tmp = (tmp << 8) | *ptr++; | ||
39 | tmp = (tmp << 8) | *ptr++; | ||
40 | tmp = (tmp << 8) | *ptr++; | ||
41 | uu->time_low = tmp; | ||
42 | |||
43 | tmp = *ptr++; | ||
44 | tmp = (tmp << 8) | *ptr++; | ||
45 | uu->time_mid = tmp; | ||
46 | |||
47 | tmp = *ptr++; | ||
48 | tmp = (tmp << 8) | *ptr++; | ||
49 | uu->time_hi_and_version = tmp; | ||
50 | |||
51 | tmp = *ptr++; | ||
52 | tmp = (tmp << 8) | *ptr++; | ||
53 | uu->clock_seq = tmp; | ||
54 | |||
55 | memcpy(uu->node, ptr, 6); | ||
56 | } | ||
57 | |||
58 | void e2p_uuid_to_str(void *uu, char *out) | ||
59 | { | ||
60 | struct uuid uuid; | ||
61 | |||
62 | e2p_unpack_uuid(uu, &uuid); | ||
63 | sprintf(out, | ||
64 | "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", | ||
65 | uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, | ||
66 | uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, | ||
67 | uuid.node[0], uuid.node[1], uuid.node[2], | ||
68 | uuid.node[3], uuid.node[4], uuid.node[5]); | ||
69 | } | ||
70 | |||
71 | const char *e2p_uuid2str(void *uu) | ||
72 | { | ||
73 | static char buf[80]; | ||
74 | if (e2p_is_null_uuid(uu)) | ||
75 | return "<none>"; | ||
76 | e2p_uuid_to_str(uu, buf); | ||
77 | return buf; | ||
78 | } | ||