diff options
author | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-04-25 04:10:35 +0000 |
---|---|---|
committer | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-04-25 04:10:35 +0000 |
commit | 613cd64983de4adc82528e98fc255f21a13674b5 (patch) | |
tree | 216a67c4df7767ffa57a1c36cbeb745607c8ffd3 | |
parent | 87e8ae5bd3aab742e7c5d8b09f021ab960ce3021 (diff) | |
download | busybox-w32-613cd64983de4adc82528e98fc255f21a13674b5.tar.gz busybox-w32-613cd64983de4adc82528e98fc255f21a13674b5.tar.bz2 busybox-w32-613cd64983de4adc82528e98fc255f21a13674b5.zip |
bbify to shrink size
git-svn-id: svn://busybox.net/trunk/busybox@10177 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | e2fsprogs/chattr.c | 326 | ||||
-rw-r--r-- | e2fsprogs/lsattr.c | 148 |
2 files changed, 177 insertions, 297 deletions
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index 7abc83176..5aaa14fbb 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c | |||
@@ -36,270 +36,200 @@ | |||
36 | #define EXT2FS_ATTR(x) | 36 | #define EXT2FS_ATTR(x) |
37 | #endif | 37 | #endif |
38 | 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" | 39 | #include "e2fsbb.h" |
48 | #include "e2p/e2p.h" | 40 | #include "e2p/e2p.h" |
49 | 41 | ||
50 | static int add; | 42 | #define OPT_ADD 1 |
51 | static int rem; | 43 | #define OPT_REM 2 |
52 | static int set; | 44 | #define OPT_SET 4 |
53 | static int set_version; | 45 | #define OPT_SET_VER 8 |
46 | static int flags; | ||
47 | static int recursive; | ||
54 | 48 | ||
55 | static unsigned long version; | 49 | static unsigned long version; |
56 | 50 | ||
57 | static int recursive; | ||
58 | static int verbose; | ||
59 | |||
60 | static unsigned long af; | 51 | static unsigned long af; |
61 | static unsigned long rf; | 52 | static unsigned long rf; |
62 | static unsigned long sf; | 53 | static unsigned long sf; |
63 | 54 | ||
64 | #ifdef _LFS64_LARGEFILE | 55 | #ifdef CONFIG_LFS |
65 | #define LSTAT lstat64 | 56 | # define LSTAT lstat64 |
66 | #define STRUCT_STAT struct stat64 | 57 | # define STRUCT_STAT struct stat64 |
67 | #else | 58 | #else |
68 | #define LSTAT lstat | 59 | # define LSTAT lstat |
69 | #define STRUCT_STAT struct stat | 60 | # define STRUCT_STAT struct stat |
70 | #endif | ||
71 | |||
72 | #if 0 | ||
73 | static void fatal_error(const char * fmt_string, int errcode) | ||
74 | { | ||
75 | fprintf (stderr, fmt_string, program_name); | ||
76 | exit (errcode); | ||
77 | } | ||
78 | |||
79 | #define usage() fatal_error(_("usage: %s [-RV] [-+=AacDdijsSu] [-v version] files...\n"), \ | ||
80 | 1) | ||
81 | #endif | 61 | #endif |
82 | 62 | ||
83 | struct flags_char { | 63 | struct flags_char { |
84 | unsigned long flag; | 64 | unsigned long flag; |
85 | char optchar; | 65 | char optchar; |
86 | }; | 66 | }; |
87 | 67 | ||
88 | static const struct flags_char flags_array[] = { | 68 | static const struct flags_char flags_array[] = { |
89 | { EXT2_NOATIME_FL, 'A' }, | 69 | { EXT2_NOATIME_FL, 'A' }, |
90 | { EXT2_SYNC_FL, 'S' }, | 70 | { EXT2_SYNC_FL, 'S' }, |
91 | { EXT2_DIRSYNC_FL, 'D' }, | 71 | { EXT2_DIRSYNC_FL, 'D' }, |
92 | { EXT2_APPEND_FL, 'a' }, | 72 | { EXT2_APPEND_FL, 'a' }, |
93 | { EXT2_COMPR_FL, 'c' }, | 73 | { EXT2_COMPR_FL, 'c' }, |
94 | { EXT2_NODUMP_FL, 'd' }, | 74 | { EXT2_NODUMP_FL, 'd' }, |
95 | { EXT2_IMMUTABLE_FL, 'i' }, | 75 | { EXT2_IMMUTABLE_FL, 'i' }, |
96 | { EXT3_JOURNAL_DATA_FL, 'j' }, | 76 | { EXT3_JOURNAL_DATA_FL, 'j' }, |
97 | { EXT2_SECRM_FL, 's' }, | 77 | { EXT2_SECRM_FL, 's' }, |
98 | { EXT2_UNRM_FL, 'u' }, | 78 | { EXT2_UNRM_FL, 'u' }, |
99 | { EXT2_NOTAIL_FL, 't' }, | 79 | { EXT2_NOTAIL_FL, 't' }, |
100 | { EXT2_TOPDIR_FL, 'T' }, | 80 | { EXT2_TOPDIR_FL, 'T' }, |
101 | { 0, 0 } | 81 | { 0, 0 } |
102 | }; | 82 | }; |
103 | 83 | ||
104 | static unsigned long get_flag(char c) | 84 | static unsigned long get_flag(char c) |
105 | { | 85 | { |
106 | const struct flags_char *fp; | 86 | const struct flags_char *fp; |
107 | 87 | for (fp = flags_array; fp->flag; fp++) | |
108 | for (fp = flags_array; fp->flag != 0; fp++) { | ||
109 | if (fp->optchar == c) | 88 | if (fp->optchar == c) |
110 | return fp->flag; | 89 | return fp->flag; |
111 | } | 90 | bb_show_usage(); |
112 | return 0; | 91 | return 0; |
113 | } | 92 | } |
114 | 93 | ||
115 | 94 | static int decode_arg(char *arg) | |
116 | static int decode_arg (int * i, int argc, char ** argv) | ||
117 | { | 95 | { |
118 | char * p; | 96 | unsigned long *fl; |
119 | char * tmp; | 97 | char opt = *arg++; |
120 | unsigned long fl; | 98 | |
121 | 99 | if (opt == '-') { | |
122 | switch (argv[*i][0]) | 100 | flags |= OPT_REM; |
123 | { | 101 | fl = &rf; |
124 | case '-': | 102 | } else if (opt == '+') { |
125 | for (p = &argv[*i][1]; *p; p++) { | 103 | flags |= OPT_ADD; |
126 | if (*p == 'R') { | 104 | fl = ⁡ |
127 | recursive = 1; | 105 | } else if (opt == '=') { |
128 | continue; | 106 | flags |= OPT_SET; |
129 | } | 107 | fl = &sf; |
130 | if (*p == 'V') { | 108 | } else |
131 | verbose = 1; | ||
132 | continue; | ||
133 | } | ||
134 | if (*p == 'v') { | ||
135 | (*i)++; | ||
136 | if (*i >= argc) | ||
137 | usage (); | ||
138 | version = strtol (argv[*i], &tmp, 0); | ||
139 | if (*tmp) { | ||
140 | com_err (program_name, 0, | ||
141 | _("bad version - %s\n"), | ||
142 | argv[*i]); | ||
143 | usage (); | ||
144 | } | ||
145 | set_version = 1; | ||
146 | continue; | ||
147 | } | ||
148 | if ((fl = get_flag(*p)) == 0) | ||
149 | usage(); | ||
150 | rf |= fl; | ||
151 | rem = 1; | ||
152 | } | ||
153 | break; | ||
154 | case '+': | ||
155 | add = 1; | ||
156 | for (p = &argv[*i][1]; *p; p++) { | ||
157 | if ((fl = get_flag(*p)) == 0) | ||
158 | usage(); | ||
159 | af |= fl; | ||
160 | } | ||
161 | break; | ||
162 | case '=': | ||
163 | set = 1; | ||
164 | for (p = &argv[*i][1]; *p; p++) { | ||
165 | if ((fl = get_flag(*p)) == 0) | ||
166 | usage(); | ||
167 | sf |= fl; | ||
168 | } | ||
169 | break; | ||
170 | default: | ||
171 | return EOF; | 109 | return EOF; |
172 | break; | 110 | |
173 | } | 111 | for (; *arg ; ++arg) |
112 | (*fl) |= get_flag(*arg); | ||
113 | |||
174 | return 1; | 114 | return 1; |
175 | } | 115 | } |
176 | 116 | ||
177 | static int chattr_dir_proc (const char *, struct dirent *, void *); | 117 | static int chattr_dir_proc(const char *, struct dirent *, void *); |
178 | 118 | ||
179 | static void change_attributes (const char * name) | 119 | static void change_attributes(const char * name) |
180 | { | 120 | { |
181 | unsigned long flags; | 121 | unsigned long fsflags; |
182 | STRUCT_STAT st; | 122 | STRUCT_STAT st; |
183 | 123 | ||
184 | if (LSTAT (name, &st) == -1) { | 124 | if (LSTAT(name, &st) == -1) { |
185 | com_err (program_name, errno, _("while trying to stat %s"), | 125 | bb_error_msg("while trying to stat %s", name); |
186 | name); | ||
187 | return; | 126 | return; |
188 | } | 127 | } |
189 | if (S_ISLNK(st.st_mode) && recursive) | 128 | if (S_ISLNK(st.st_mode) && recursive) |
190 | return; | 129 | return; |
191 | 130 | ||
192 | /* Don't try to open device files, fifos etc. We probably | 131 | /* Don't try to open device files, fifos etc. We probably |
193 | ought to display an error if the file was explicitly given | 132 | * ought to display an error if the file was explicitly given |
194 | on the command line (whether or not recursive was | 133 | * on the command line (whether or not recursive was |
195 | requested). */ | 134 | * requested). */ |
196 | if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && | 135 | if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode)) |
197 | !S_ISDIR(st.st_mode)) | ||
198 | return; | 136 | return; |
199 | 137 | ||
200 | if (set) { | 138 | if (flags & OPT_SET_VER) |
201 | if (verbose) { | 139 | if (fsetversion(name, version) == -1) |
202 | printf (_("Flags of %s set as "), name); | 140 | bb_error_msg("while setting version on %s", name); |
203 | print_flags (stdout, sf, 0); | 141 | |
204 | printf ("\n"); | 142 | if (flags & OPT_SET) { |
205 | } | 143 | fsflags = sf; |
206 | if (fsetflags (name, sf) == -1) | ||
207 | perror (name); | ||
208 | } else { | 144 | } else { |
209 | if (fgetflags (name, &flags) == -1) | 145 | if (fgetflags(name, &fsflags) == -1) { |
210 | com_err (program_name, errno, | 146 | bb_error_msg("while reading flags on %s", name); |
211 | _("while reading flags on %s"), name); | 147 | goto skip_setflags; |
212 | else { | ||
213 | if (rem) | ||
214 | flags &= ~rf; | ||
215 | if (add) | ||
216 | flags |= af; | ||
217 | if (verbose) { | ||
218 | printf (_("Flags of %s set as "), name); | ||
219 | print_flags (stdout, flags, 0); | ||
220 | printf ("\n"); | ||
221 | } | ||
222 | if (!S_ISDIR(st.st_mode)) | ||
223 | flags &= ~EXT2_DIRSYNC_FL; | ||
224 | if (fsetflags (name, flags) == -1) | ||
225 | com_err (program_name, errno, | ||
226 | _("while setting flags on %s"), name); | ||
227 | } | 148 | } |
149 | if (flags & OPT_REM) | ||
150 | fsflags &= ~rf; | ||
151 | if (flags & OPT_ADD) | ||
152 | fsflags |= af; | ||
153 | if (!S_ISDIR(st.st_mode)) | ||
154 | fsflags &= ~EXT2_DIRSYNC_FL; | ||
228 | } | 155 | } |
229 | if (set_version) { | 156 | if (fsetflags(name, fsflags) == -1) |
230 | if (verbose) | 157 | bb_error_msg("while setting flags on %s", name); |
231 | printf (_("Version of %s set as %lu\n"), name, version); | 158 | |
232 | if (fsetversion (name, version) == -1) | 159 | skip_setflags: |
233 | com_err (program_name, errno, | ||
234 | _("while setting version on %s"), name); | ||
235 | } | ||
236 | if (S_ISDIR(st.st_mode) && recursive) | 160 | if (S_ISDIR(st.st_mode) && recursive) |
237 | iterate_on_dir (name, chattr_dir_proc, NULL); | 161 | iterate_on_dir(name, chattr_dir_proc, NULL); |
238 | } | 162 | } |
239 | 163 | ||
240 | static int chattr_dir_proc (const char * dir_name, struct dirent * de, | 164 | static int chattr_dir_proc(const char *dir_name, struct dirent *de, |
241 | void * private EXT2FS_ATTR((unused))) | 165 | void *private EXT2FS_ATTR((unused))) |
242 | { | 166 | { |
243 | if (strcmp (de->d_name, ".") && strcmp (de->d_name, "..")) { | 167 | /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ |
244 | char *path; | 168 | if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ |
169 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { | ||
245 | 170 | ||
246 | path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1); | 171 | char *path = malloc(strlen(dir_name) + 1 + strlen(de->d_name) + 1); |
247 | if (!path) | 172 | if (!path) |
248 | fatal_error(_("Couldn't allocate path variable " | 173 | bb_error_msg_and_die("Couldn't allocate path variable in chattr_dir_proc"); |
249 | "in chattr_dir_proc"), 1); | 174 | sprintf(path, "%s/%s", dir_name, de->d_name); |
250 | sprintf (path, "%s/%s", dir_name, de->d_name); | 175 | change_attributes(path); |
251 | change_attributes (path); | ||
252 | free(path); | 176 | free(path); |
253 | } | 177 | } |
254 | return 0; | 178 | return 0; |
255 | } | 179 | } |
256 | 180 | ||
257 | int chattr_main (int argc, char ** argv) | 181 | int chattr_main(int argc, char **argv) |
258 | { | 182 | { |
259 | int i, j; | 183 | int i; |
260 | int end_arg = 0; | 184 | char *arg; |
261 | 185 | ||
262 | #ifdef ENABLE_NLS | 186 | /* parse the args */ |
263 | setlocale(LC_MESSAGES, ""); | 187 | for (i = 1; i < argc; ++i) { |
264 | setlocale(LC_CTYPE, ""); | 188 | arg = argv[i]; |
265 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); | 189 | |
266 | textdomain(NLS_CAT_NAME); | 190 | /* take care of -R and -v <version> */ |
267 | #endif | 191 | if (arg[0] == '-') { |
268 | #if 0 | 192 | if (arg[1] == 'R' && arg[2] == '\0') { |
269 | if (argc && *argv) | 193 | recursive = 1; |
270 | program_name = *argv; | 194 | continue; |
271 | #endif | 195 | } else if (arg[1] == 'v' && arg[2] == '\0') { |
272 | i = 1; | 196 | char *tmp; |
273 | while (i < argc && !end_arg) { | 197 | ++i; |
274 | /* '--' arg should end option processing */ | 198 | if (i >= argc) |
275 | if (strcmp(argv[i], "--") == 0) { | 199 | bb_show_usage(); |
276 | i++; | 200 | version = strtol(argv[i], &tmp, 0); |
277 | end_arg = 1; | 201 | if (*tmp) { |
278 | } else if (decode_arg (&i, argc, argv) == EOF) | 202 | bb_error_msg("bad version - %s", arg); |
279 | end_arg = 1; | 203 | bb_show_usage(); |
280 | else | 204 | } |
281 | i++; | 205 | flags |= OPT_SET_VER; |
206 | continue; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | if (decode_arg(arg) == EOF) | ||
211 | break; | ||
282 | } | 212 | } |
213 | |||
214 | /* run sanity checks on all the arguments given us */ | ||
283 | if (i >= argc) | 215 | if (i >= argc) |
284 | usage (); | 216 | bb_show_usage(); |
285 | if (set && (add || rem)) { | 217 | if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) { |
286 | fputs(_("= is incompatible with - and +\n"), stderr); | 218 | bb_error_msg("= is incompatible with - and +"); |
287 | exit (1); | 219 | return EXIT_FAILURE; |
288 | } | 220 | } |
289 | if ((rf & af) != 0) { | 221 | if ((rf & af) != 0) { |
290 | fputs("Can't both set and unset same flag.\n", stderr); | 222 | bb_error_msg("Can't both set and unset same flag"); |
291 | exit (1); | 223 | return EXIT_FAILURE; |
292 | } | 224 | } |
293 | if (!(add || rem || set || set_version)) { | 225 | if (!flags) { |
294 | fputs(_("Must use '-v', =, - or +\n"), stderr); | 226 | bb_error_msg("Must use '-v', =, - or +"); |
295 | exit (1); | 227 | return EXIT_FAILURE; |
296 | } | 228 | } |
297 | #if 0 | 229 | |
298 | if (verbose) | 230 | /* now run chattr on all the files passed to us */ |
299 | fprintf (stderr, "chattr %s (%s)\n", | 231 | while (i < argc) |
300 | E2FSPROGS_VERSION, E2FSPROGS_DATE); | 232 | change_attributes(argv[i++]); |
301 | #endif | 233 | |
302 | for (j = i; j < argc; j++) | 234 | return EXIT_SUCCESS; |
303 | change_attributes (argv[j]); | ||
304 | exit(0); | ||
305 | } | 235 | } |
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 0f1c6f22c..be5723c43 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c | |||
@@ -39,99 +39,87 @@ | |||
39 | #define EXT2FS_ATTR(x) | 39 | #define EXT2FS_ATTR(x) |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | static int all; | 42 | #define OPT_RECUR 1 |
43 | static int dirs_opt; | 43 | #define OPT_ALL 2 |
44 | static unsigned pf_options; | 44 | #define OPT_DIRS_OPT 4 |
45 | static int recursive; | 45 | #define OPT_PF_LONG 8 |
46 | static int verbose; | 46 | #define OPT_GENERATION 16 |
47 | static int generation_opt; | 47 | static int flags; |
48 | 48 | ||
49 | #ifdef _LFS64_LARGEFILE | 49 | #ifdef CONFIG_LFS |
50 | #define LSTAT lstat64 | 50 | # define LSTAT lstat64 |
51 | #define STRUCT_STAT struct stat64 | 51 | # define STRUCT_STAT struct stat64 |
52 | #else | 52 | #else |
53 | #define LSTAT lstat | 53 | # define LSTAT lstat |
54 | #define STRUCT_STAT struct stat | 54 | # define STRUCT_STAT struct stat |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | #if 0 | 57 | static void list_attributes(const char *name) |
58 | static void usage(void) | ||
59 | { | 58 | { |
60 | fprintf(stderr, _("Usage: %s [-RVadlv] [files...]\n"), program_name); | 59 | unsigned long fsflags; |
61 | exit(1); | ||
62 | } | ||
63 | #endif | ||
64 | |||
65 | static void list_attributes (const char * name) | ||
66 | { | ||
67 | unsigned long flags; | ||
68 | unsigned long generation; | 60 | unsigned long generation; |
69 | 61 | ||
70 | if (fgetflags (name, &flags) == -1) { | 62 | if (fgetflags(name, &fsflags) == -1) { |
71 | com_err (program_name, errno, _("While reading flags on %s"), | 63 | bb_perror_msg("While reading flags on %s", name); |
72 | name); | ||
73 | return; | 64 | return; |
74 | } | 65 | } |
75 | if (generation_opt) { | 66 | if (flags & OPT_GENERATION) { |
76 | if (fgetversion (name, &generation) == -1) { | 67 | if (fgetversion(name, &generation) == -1) { |
77 | com_err (program_name, errno, | 68 | bb_perror_msg("While reading version on %s", name); |
78 | _("While reading version on %s"), | ||
79 | name); | ||
80 | return; | 69 | return; |
81 | } | 70 | } |
82 | printf ("%5lu ", generation); | 71 | printf("%5lu ", generation); |
83 | } | 72 | } |
84 | if (pf_options & PFOPT_LONG) { | 73 | if (flags & OPT_PF_LONG) { |
85 | printf("%-28s ", name); | 74 | printf("%-28s ", name); |
86 | print_flags(stdout, flags, pf_options); | 75 | print_flags(stdout, fsflags, PFOPT_LONG); |
87 | fputc('\n', stdout); | 76 | fputc('\n', stdout); |
88 | } else { | 77 | } else { |
89 | print_flags(stdout, flags, pf_options); | 78 | print_flags(stdout, fsflags, 0); |
90 | printf(" %s\n", name); | 79 | printf(" %s\n", name); |
91 | } | 80 | } |
92 | } | 81 | } |
93 | 82 | ||
94 | static int lsattr_dir_proc (const char *, struct dirent *, void *); | 83 | static int lsattr_dir_proc(const char *, struct dirent *, void *); |
95 | 84 | ||
96 | static void lsattr_args (const char * name) | 85 | static void lsattr_args(const char *name) |
97 | { | 86 | { |
98 | STRUCT_STAT st; | 87 | STRUCT_STAT st; |
99 | 88 | ||
100 | if (LSTAT (name, &st) == -1) | 89 | if (LSTAT(name, &st) == -1) |
101 | com_err (program_name, errno, _("while trying to stat %s"), | 90 | bb_perror_msg("while trying to stat %s", name); |
102 | name); | ||
103 | else { | 91 | else { |
104 | if (S_ISDIR(st.st_mode) && !dirs_opt) | 92 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) |
105 | iterate_on_dir (name, lsattr_dir_proc, NULL); | 93 | iterate_on_dir(name, lsattr_dir_proc, NULL); |
106 | else | 94 | else |
107 | list_attributes (name); | 95 | list_attributes(name); |
108 | } | 96 | } |
109 | } | 97 | } |
110 | 98 | ||
111 | static int lsattr_dir_proc (const char * dir_name, struct dirent * de, | 99 | static int lsattr_dir_proc(const char *dir_name, struct dirent *de, |
112 | void * private EXT2FS_ATTR((unused))) | 100 | void *private EXT2FS_ATTR((unused))) |
113 | { | 101 | { |
114 | STRUCT_STAT st; | 102 | STRUCT_STAT st; |
115 | char *path; | 103 | char *path; |
116 | int dir_len = strlen(dir_name); | 104 | int dir_len = strlen(dir_name); |
117 | 105 | ||
118 | path = malloc(dir_len + strlen (de->d_name) + 2); | 106 | path = malloc(dir_len + strlen(de->d_name) + 2); |
119 | 107 | ||
120 | if (dir_len && dir_name[dir_len-1] == '/') | 108 | if (dir_len && dir_name[dir_len-1] == '/') |
121 | sprintf (path, "%s%s", dir_name, de->d_name); | 109 | sprintf(path, "%s%s", dir_name, de->d_name); |
122 | else | 110 | else |
123 | sprintf (path, "%s/%s", dir_name, de->d_name); | 111 | sprintf(path, "%s/%s", dir_name, de->d_name); |
124 | if (LSTAT (path, &st) == -1) | 112 | if (LSTAT(path, &st) == -1) |
125 | perror (path); | 113 | bb_perror_msg(path); |
126 | else { | 114 | else { |
127 | if (de->d_name[0] != '.' || all) { | 115 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { |
128 | list_attributes (path); | 116 | list_attributes(path); |
129 | if (S_ISDIR(st.st_mode) && recursive && | 117 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && |
130 | strcmp(de->d_name, ".") && | 118 | strcmp(de->d_name, ".") && |
131 | strcmp(de->d_name, "..")) { | 119 | strcmp(de->d_name, "..")) { |
132 | printf ("\n%s:\n", path); | 120 | printf("\n%s:\n", path); |
133 | iterate_on_dir (path, lsattr_dir_proc, NULL); | 121 | iterate_on_dir(path, lsattr_dir_proc, NULL); |
134 | printf ("\n"); | 122 | printf("\n"); |
135 | } | 123 | } |
136 | } | 124 | } |
137 | } | 125 | } |
@@ -139,55 +127,17 @@ static int lsattr_dir_proc (const char * dir_name, struct dirent * de, | |||
139 | return 0; | 127 | return 0; |
140 | } | 128 | } |
141 | 129 | ||
142 | int lsattr_main (int argc, char ** argv) | 130 | int lsattr_main(int argc, char **argv) |
143 | { | 131 | { |
144 | int c; | ||
145 | int i; | 132 | int i; |
146 | 133 | ||
147 | #ifdef ENABLE_NLS | 134 | flags = bb_getopt_ulflags(argc, argv, "Radlv"); |
148 | setlocale(LC_MESSAGES, ""); | ||
149 | setlocale(LC_CTYPE, ""); | ||
150 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); | ||
151 | textdomain(NLS_CAT_NAME); | ||
152 | #endif | ||
153 | #if 0 | ||
154 | if (argc && *argv) | ||
155 | program_name = *argv; | ||
156 | #endif | ||
157 | while ((c = getopt (argc, argv, "Radlv")) != EOF) | ||
158 | switch (c) | ||
159 | { | ||
160 | case 'R': | ||
161 | recursive = 1; | ||
162 | break; | ||
163 | case 'V': | ||
164 | verbose = 1; | ||
165 | break; | ||
166 | case 'a': | ||
167 | all = 1; | ||
168 | break; | ||
169 | case 'd': | ||
170 | dirs_opt = 1; | ||
171 | break; | ||
172 | case 'l': | ||
173 | pf_options = PFOPT_LONG; | ||
174 | break; | ||
175 | case 'v': | ||
176 | generation_opt = 1; | ||
177 | break; | ||
178 | default: | ||
179 | usage(); | ||
180 | } | ||
181 | 135 | ||
182 | #if 0 | ||
183 | if (verbose) | ||
184 | fprintf (stderr, "lsattr %s (%s)\n", | ||
185 | E2FSPROGS_VERSION, E2FSPROGS_DATE); | ||
186 | #endif | ||
187 | if (optind > argc - 1) | 136 | if (optind > argc - 1) |
188 | lsattr_args ("."); | 137 | lsattr_args("."); |
189 | else | 138 | else |
190 | for (i = optind; i < argc; i++) | 139 | for (i = optind; i < argc; i++) |
191 | lsattr_args (argv[i]); | 140 | lsattr_args(argv[i]); |
192 | exit(0); | 141 | |
142 | return EXIT_SUCCESS; | ||
193 | } | 143 | } |