diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-05-07 07:17:43 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-05-07 07:17:43 +0000 |
commit | ea338fffb5e7e78ba215c65e50fb294755389bbf (patch) | |
tree | c9beac6e70d04c3ca149a8be37cf6795e0609135 | |
parent | 6adfd349e989346a40dd95672276eb15f4018b4a (diff) | |
download | busybox-w32-ea338fffb5e7e78ba215c65e50fb294755389bbf.tar.gz busybox-w32-ea338fffb5e7e78ba215c65e50fb294755389bbf.tar.bz2 busybox-w32-ea338fffb5e7e78ba215c65e50fb294755389bbf.zip |
patch by Tito which uses a lot more busybox functions to reduce size nicely
-rw-r--r-- | e2fsprogs/chattr.c | 46 | ||||
-rw-r--r-- | e2fsprogs/lsattr.c | 40 |
2 files changed, 37 insertions, 49 deletions
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index 5ba458934..1471c851d 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c | |||
@@ -31,9 +31,9 @@ | |||
31 | #include <ext2fs/ext2_fs.h> | 31 | #include <ext2fs/ext2_fs.h> |
32 | 32 | ||
33 | #ifdef __GNUC__ | 33 | #ifdef __GNUC__ |
34 | #define EXT2FS_ATTR(x) __attribute__(x) | 34 | # define EXT2FS_ATTR(x) __attribute__(x) |
35 | #else | 35 | #else |
36 | #define EXT2FS_ATTR(x) | 36 | # define EXT2FS_ATTR(x) |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #include "e2fsbb.h" | 39 | #include "e2fsbb.h" |
@@ -122,7 +122,7 @@ static void change_attributes(const char * name) | |||
122 | STRUCT_STAT st; | 122 | STRUCT_STAT st; |
123 | 123 | ||
124 | if (LSTAT(name, &st) == -1) { | 124 | if (LSTAT(name, &st) == -1) { |
125 | bb_error_msg("while trying to stat %s", name); | 125 | bb_error_msg("stat %s failed", name); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | if (S_ISLNK(st.st_mode) && recursive) | 128 | if (S_ISLNK(st.st_mode) && recursive) |
@@ -137,13 +137,13 @@ static void change_attributes(const char * name) | |||
137 | 137 | ||
138 | if (flags & OPT_SET_VER) | 138 | if (flags & OPT_SET_VER) |
139 | if (fsetversion(name, version) == -1) | 139 | if (fsetversion(name, version) == -1) |
140 | bb_error_msg("while setting version on %s", name); | 140 | bb_error_msg("setting version on %s", name); |
141 | 141 | ||
142 | if (flags & OPT_SET) { | 142 | if (flags & OPT_SET) { |
143 | fsflags = sf; | 143 | fsflags = sf; |
144 | } else { | 144 | } else { |
145 | if (fgetflags(name, &fsflags) == -1) { | 145 | if (fgetflags(name, &fsflags) == -1) { |
146 | bb_error_msg("while reading flags on %s", name); | 146 | bb_error_msg("reading flags on %s", name); |
147 | goto skip_setflags; | 147 | goto skip_setflags; |
148 | } | 148 | } |
149 | if (flags & OPT_REM) | 149 | if (flags & OPT_REM) |
@@ -154,7 +154,7 @@ static void change_attributes(const char * name) | |||
154 | fsflags &= ~EXT2_DIRSYNC_FL; | 154 | fsflags &= ~EXT2_DIRSYNC_FL; |
155 | } | 155 | } |
156 | if (fsetflags(name, fsflags) == -1) | 156 | if (fsetflags(name, fsflags) == -1) |
157 | bb_error_msg("while setting flags on %s", name); | 157 | bb_error_msg("setting flags on %s", name); |
158 | 158 | ||
159 | skip_setflags: | 159 | skip_setflags: |
160 | if (S_ISDIR(st.st_mode) && recursive) | 160 | if (S_ISDIR(st.st_mode) && recursive) |
@@ -167,11 +167,11 @@ static int chattr_dir_proc(const char *dir_name, struct dirent *de, | |||
167 | /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ | 167 | /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ |
168 | if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ | 168 | if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ |
169 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { | 169 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { |
170 | char *path; | 170 | char *path = concat_subpath_file(dir_name, de->d_name); |
171 | if (asprintf(&path, "%s/%s", dir_name, de->d_name) == -1) | 171 | if (path) { |
172 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 172 | change_attributes(path); |
173 | change_attributes(path); | 173 | free(path); |
174 | free(path); | 174 | } |
175 | } | 175 | } |
176 | return 0; | 176 | return 0; |
177 | } | 177 | } |
@@ -196,10 +196,8 @@ int chattr_main(int argc, char **argv) | |||
196 | if (i >= argc) | 196 | if (i >= argc) |
197 | bb_show_usage(); | 197 | bb_show_usage(); |
198 | version = strtol(argv[i], &tmp, 0); | 198 | version = strtol(argv[i], &tmp, 0); |
199 | if (*tmp) { | 199 | if (*tmp) |
200 | bb_error_msg("bad version - %s", arg); | 200 | bb_error_msg_and_die("bad version '%s'", arg); |
201 | bb_show_usage(); | ||
202 | } | ||
203 | flags |= OPT_SET_VER; | 201 | flags |= OPT_SET_VER; |
204 | continue; | 202 | continue; |
205 | } | 203 | } |
@@ -212,18 +210,12 @@ int chattr_main(int argc, char **argv) | |||
212 | /* run sanity checks on all the arguments given us */ | 210 | /* run sanity checks on all the arguments given us */ |
213 | if (i >= argc) | 211 | if (i >= argc) |
214 | bb_show_usage(); | 212 | bb_show_usage(); |
215 | if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) { | 213 | if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM))) |
216 | bb_error_msg("= is incompatible with - and +"); | 214 | bb_error_msg_and_die("= is incompatible with - and +"); |
217 | return EXIT_FAILURE; | 215 | if ((rf & af) != 0) |
218 | } | 216 | bb_error_msg_and_die("Can't set and unset a flag"); |
219 | if ((rf & af) != 0) { | 217 | if (!flags) |
220 | bb_error_msg("Can't both set and unset same flag"); | 218 | bb_error_msg_and_die("Must use '-v', =, - or +"); |
221 | return EXIT_FAILURE; | ||
222 | } | ||
223 | if (!flags) { | ||
224 | bb_error_msg("Must use '-v', =, - or +"); | ||
225 | return EXIT_FAILURE; | ||
226 | } | ||
227 | 219 | ||
228 | /* now run chattr on all the files passed to us */ | 220 | /* now run chattr on all the files passed to us */ |
229 | while (i < argc) | 221 | while (i < argc) |
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 62b9535c2..475a66f67 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c | |||
@@ -34,9 +34,9 @@ | |||
34 | #include "e2p/e2p.h" | 34 | #include "e2p/e2p.h" |
35 | 35 | ||
36 | #ifdef __GNUC__ | 36 | #ifdef __GNUC__ |
37 | #define EXT2FS_ATTR(x) __attribute__(x) | 37 | # define EXT2FS_ATTR(x) __attribute__(x) |
38 | #else | 38 | #else |
39 | #define EXT2FS_ATTR(x) | 39 | # define EXT2FS_ATTR(x) |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #define OPT_RECUR 1 | 42 | #define OPT_RECUR 1 |
@@ -59,25 +59,26 @@ static void list_attributes(const char *name) | |||
59 | unsigned long fsflags; | 59 | unsigned long fsflags; |
60 | unsigned long generation; | 60 | unsigned long generation; |
61 | 61 | ||
62 | if (fgetflags(name, &fsflags) == -1) { | 62 | if (fgetflags(name, &fsflags) == -1) |
63 | bb_perror_msg("While reading flags on %s", name); | 63 | goto read_err; |
64 | return; | ||
65 | } | ||
66 | if (flags & OPT_GENERATION) { | 64 | if (flags & OPT_GENERATION) { |
67 | if (fgetversion(name, &generation) == -1) { | 65 | if (fgetversion(name, &generation) == -1) |
68 | bb_perror_msg("While reading version on %s", name); | 66 | goto read_err; |
69 | return; | ||
70 | } | ||
71 | printf("%5lu ", generation); | 67 | printf("%5lu ", generation); |
72 | } | 68 | } |
69 | |||
73 | if (flags & OPT_PF_LONG) { | 70 | if (flags & OPT_PF_LONG) { |
74 | printf("%-28s ", name); | 71 | printf("%-28s ", name); |
75 | print_flags(stdout, fsflags, PFOPT_LONG); | 72 | print_flags(stdout, fsflags, PFOPT_LONG); |
76 | fputc('\n', stdout); | 73 | printf("\n"); |
77 | } else { | 74 | } else { |
78 | print_flags(stdout, fsflags, 0); | 75 | print_flags(stdout, fsflags, 0); |
79 | printf(" %s\n", name); | 76 | printf(" %s\n", name); |
80 | } | 77 | } |
78 | |||
79 | return; | ||
80 | read_err: | ||
81 | bb_perror_msg("reading %s", name); | ||
81 | } | 82 | } |
82 | 83 | ||
83 | static int lsattr_dir_proc(const char *, struct dirent *, void *); | 84 | static int lsattr_dir_proc(const char *, struct dirent *, void *); |
@@ -86,9 +87,9 @@ static void lsattr_args(const char *name) | |||
86 | { | 87 | { |
87 | STRUCT_STAT st; | 88 | STRUCT_STAT st; |
88 | 89 | ||
89 | if (LSTAT(name, &st) == -1) | 90 | if (LSTAT(name, &st) == -1) { |
90 | bb_perror_msg("while trying to stat %s", name); | 91 | bb_perror_msg("stating %s", name); |
91 | else { | 92 | } else { |
92 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) | 93 | if (S_ISDIR(st.st_mode) && !(flags & OPT_DIRS_OPT)) |
93 | iterate_on_dir(name, lsattr_dir_proc, NULL); | 94 | iterate_on_dir(name, lsattr_dir_proc, NULL); |
94 | else | 95 | else |
@@ -101,14 +102,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de, | |||
101 | { | 102 | { |
102 | STRUCT_STAT st; | 103 | STRUCT_STAT st; |
103 | char *path; | 104 | char *path; |
104 | int i = strlen(dir_name); | ||
105 | 105 | ||
106 | if (i && dir_name[i-1] == '/') | 106 | path = concat_path_file(dir_name, de->d_name); |
107 | i = asprintf(&path, "%s%s", dir_name, de->d_name); | ||
108 | else | ||
109 | i = asprintf(&path, "%s/%s", dir_name, de->d_name); | ||
110 | if (i == -1) | ||
111 | bb_error_msg_and_die(bb_msg_memory_exhausted); | ||
112 | 107 | ||
113 | if (LSTAT(path, &st) == -1) | 108 | if (LSTAT(path, &st) == -1) |
114 | bb_perror_msg(path); | 109 | bb_perror_msg(path); |
@@ -116,7 +111,8 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de, | |||
116 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { | 111 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { |
117 | list_attributes(path); | 112 | list_attributes(path); |
118 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && | 113 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && |
119 | strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { | 114 | (de->d_name[0] != '.' && (de->d_name[1] != '\0' || |
115 | (de->d_name[1] != '.' && de->d_name[2] != '\0')))) { | ||
120 | printf("\n%s:\n", path); | 116 | printf("\n%s:\n", path); |
121 | iterate_on_dir(path, lsattr_dir_proc, NULL); | 117 | iterate_on_dir(path, lsattr_dir_proc, NULL); |
122 | printf("\n"); | 118 | printf("\n"); |