diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-01 12:54:56 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-01 12:54:56 +0000 |
commit | 1a9e9bdd93b06508b70bd29ef5eeb82f91d86222 (patch) | |
tree | adcf234f48d8a68a5644f1504cc93025d58ce2a2 | |
parent | 5a89763fb7e57d4fc3d393eafa35c58f8285a083 (diff) | |
download | busybox-w32-1a9e9bdd93b06508b70bd29ef5eeb82f91d86222.tar.gz busybox-w32-1a9e9bdd93b06508b70bd29ef5eeb82f91d86222.tar.bz2 busybox-w32-1a9e9bdd93b06508b70bd29ef5eeb82f91d86222.zip |
gunzip: restore mtime. approx +80 bytes of code
rpm: make code more robust
lsmod: small code shrink
-rw-r--r-- | archival/bbunzip.c | 32 | ||||
-rw-r--r-- | archival/bzip2.c | 3 | ||||
-rw-r--r-- | archival/gzip.c | 3 | ||||
-rw-r--r-- | archival/libunarchive/decompress_unzip.c | 26 | ||||
-rw-r--r-- | archival/rpm.c | 15 | ||||
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | include/unarchive.h | 11 | ||||
-rw-r--r-- | modutils/lsmod.c | 2 |
8 files changed, 69 insertions, 28 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c index c7962058e..75489f2a5 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c | |||
@@ -30,13 +30,14 @@ int open_to_or_warn(int to_fd, const char *filename, int flags, int mode) | |||
30 | 30 | ||
31 | int FAST_FUNC bbunpack(char **argv, | 31 | int FAST_FUNC bbunpack(char **argv, |
32 | char* (*make_new_name)(char *filename), | 32 | char* (*make_new_name)(char *filename), |
33 | USE_DESKTOP(long long) int (*unpacker)(void) | 33 | USE_DESKTOP(long long) int (*unpacker)(unpack_info_t *info) |
34 | ) | 34 | ) |
35 | { | 35 | { |
36 | struct stat stat_buf; | 36 | struct stat stat_buf; |
37 | USE_DESKTOP(long long) int status; | 37 | USE_DESKTOP(long long) int status; |
38 | char *filename, *new_name; | 38 | char *filename, *new_name; |
39 | smallint exitcode = 0; | 39 | smallint exitcode = 0; |
40 | unpack_info_t info; | ||
40 | 41 | ||
41 | do { | 42 | do { |
42 | /* NB: new_name is *maybe* malloc'ed! */ | 43 | /* NB: new_name is *maybe* malloc'ed! */ |
@@ -92,14 +93,29 @@ int FAST_FUNC bbunpack(char **argv, | |||
92 | "use -f to force it"); | 93 | "use -f to force it"); |
93 | } | 94 | } |
94 | 95 | ||
95 | status = unpacker(); | 96 | /* memset(&info, 0, sizeof(info)); */ |
97 | info.mtime = 0; /* so far it has one member only */ | ||
98 | status = unpacker(&info); | ||
96 | if (status < 0) | 99 | if (status < 0) |
97 | exitcode = 1; | 100 | exitcode = 1; |
98 | 101 | ||
99 | if (filename) { | 102 | if (filename) { |
100 | char *del = new_name; | 103 | char *del = new_name; |
101 | if (status >= 0) { | 104 | if (status >= 0) { |
102 | /* TODO: restore user/group/times here? */ | 105 | /* TODO: restore other things? */ |
106 | if (info.mtime) { | ||
107 | struct utimbuf times; | ||
108 | |||
109 | times.actime = info.mtime; | ||
110 | times.modtime = info.mtime; | ||
111 | /* Close first. | ||
112 | * On some systems calling utime | ||
113 | * then closing resets the mtime. */ | ||
114 | close(STDOUT_FILENO); | ||
115 | /* Ignoring errors */ | ||
116 | utime(new_name, ×); | ||
117 | } | ||
118 | |||
103 | /* Delete _compressed_ file */ | 119 | /* Delete _compressed_ file */ |
104 | del = filename; | 120 | del = filename; |
105 | /* restore extension (unless tgz -> tar case) */ | 121 | /* restore extension (unless tgz -> tar case) */ |
@@ -159,7 +175,7 @@ char* make_new_name_bunzip2(char *filename) | |||
159 | } | 175 | } |
160 | 176 | ||
161 | static | 177 | static |
162 | USE_DESKTOP(long long) int unpack_bunzip2(void) | 178 | USE_DESKTOP(long long) int unpack_bunzip2(unpack_info_t *info UNUSED_PARAM) |
163 | { | 179 | { |
164 | return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO); | 180 | return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO); |
165 | } | 181 | } |
@@ -235,7 +251,7 @@ char* make_new_name_gunzip(char *filename) | |||
235 | } | 251 | } |
236 | 252 | ||
237 | static | 253 | static |
238 | USE_DESKTOP(long long) int unpack_gunzip(void) | 254 | USE_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info) |
239 | { | 255 | { |
240 | USE_DESKTOP(long long) int status = -1; | 256 | USE_DESKTOP(long long) int status = -1; |
241 | 257 | ||
@@ -247,7 +263,7 @@ USE_DESKTOP(long long) int unpack_gunzip(void) | |||
247 | if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) { | 263 | if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) { |
248 | status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO); | 264 | status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO); |
249 | } else if (magic2 == 0x8b) { | 265 | } else if (magic2 == 0x8b) { |
250 | status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO); | 266 | status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info); |
251 | } else { | 267 | } else { |
252 | goto bad_magic; | 268 | goto bad_magic; |
253 | } | 269 | } |
@@ -309,7 +325,7 @@ char* make_new_name_unlzma(char *filename) | |||
309 | } | 325 | } |
310 | 326 | ||
311 | static | 327 | static |
312 | USE_DESKTOP(long long) int unpack_unlzma(void) | 328 | USE_DESKTOP(long long) int unpack_unlzma(unpack_info_t *info UNUSED_PARAM) |
313 | { | 329 | { |
314 | return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); | 330 | return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); |
315 | } | 331 | } |
@@ -344,7 +360,7 @@ char* make_new_name_uncompress(char *filename) | |||
344 | } | 360 | } |
345 | 361 | ||
346 | static | 362 | static |
347 | USE_DESKTOP(long long) int unpack_uncompress(void) | 363 | USE_DESKTOP(long long) int unpack_uncompress(unpack_info_t *info UNUSED_PARAM) |
348 | { | 364 | { |
349 | USE_DESKTOP(long long) int status = -1; | 365 | USE_DESKTOP(long long) int status = -1; |
350 | 366 | ||
diff --git a/archival/bzip2.c b/archival/bzip2.c index 1149cad2a..8eb5ca9ae 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c | |||
@@ -8,6 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include "unarchive.h" | ||
11 | 12 | ||
12 | #define CONFIG_BZIP2_FEATURE_SPEED 1 | 13 | #define CONFIG_BZIP2_FEATURE_SPEED 1 |
13 | 14 | ||
@@ -101,7 +102,7 @@ USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, v | |||
101 | } | 102 | } |
102 | 103 | ||
103 | static | 104 | static |
104 | USE_DESKTOP(long long) int compressStream(void) | 105 | USE_DESKTOP(long long) int compressStream(unpack_info_t *info UNUSED_PARAM) |
105 | { | 106 | { |
106 | USE_DESKTOP(long long) int total; | 107 | USE_DESKTOP(long long) int total; |
107 | ssize_t count; | 108 | ssize_t count; |
diff --git a/archival/gzip.c b/archival/gzip.c index ee051356e..43804b2e4 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -40,6 +40,7 @@ aa: 85.1% -- replaced with aa.gz | |||
40 | */ | 40 | */ |
41 | 41 | ||
42 | #include "libbb.h" | 42 | #include "libbb.h" |
43 | #include "unarchive.h" | ||
43 | 44 | ||
44 | 45 | ||
45 | /* =========================================================================== | 46 | /* =========================================================================== |
@@ -2014,7 +2015,7 @@ char* make_new_name_gzip(char *filename) | |||
2014 | } | 2015 | } |
2015 | 2016 | ||
2016 | static | 2017 | static |
2017 | USE_DESKTOP(long long) int pack_gzip(void) | 2018 | USE_DESKTOP(long long) int pack_gzip(unpack_info_t *info UNUSED_PARAM) |
2018 | { | 2019 | { |
2019 | struct stat s; | 2020 | struct stat s; |
2020 | 2021 | ||
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index f25808a1a..e83cd4f45 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
@@ -1108,18 +1108,21 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY) | |||
1108 | return res; | 1108 | return res; |
1109 | } | 1109 | } |
1110 | 1110 | ||
1111 | static int check_header_gzip(STATE_PARAM_ONLY) | 1111 | static int check_header_gzip(STATE_PARAM unpack_info_t *info) |
1112 | { | 1112 | { |
1113 | union { | 1113 | union { |
1114 | unsigned char raw[8]; | 1114 | unsigned char raw[8]; |
1115 | struct { | 1115 | struct { |
1116 | uint8_t gz_method; | 1116 | uint8_t gz_method; |
1117 | uint8_t flags; | 1117 | uint8_t flags; |
1118 | //uint32_t mtime; - unused fields | 1118 | uint32_t mtime; |
1119 | //uint8_t xtra_flags; | 1119 | uint8_t xtra_flags_UNUSED; |
1120 | //uint8_t os_flags; | 1120 | uint8_t os_flags_UNUSED; |
1121 | } formatted; /* packed */ | 1121 | } __attribute__((packed)) formatted; |
1122 | } header; | 1122 | } header; |
1123 | struct BUG_header { | ||
1124 | char BUG_header[sizeof(header) == 8 ? 1 : -1]; | ||
1125 | }; | ||
1123 | 1126 | ||
1124 | /* | 1127 | /* |
1125 | * Rewind bytebuffer. We use the beginning because the header has 8 | 1128 | * Rewind bytebuffer. We use the beginning because the header has 8 |
@@ -1167,6 +1170,9 @@ static int check_header_gzip(STATE_PARAM_ONLY) | |||
1167 | } | 1170 | } |
1168 | } | 1171 | } |
1169 | 1172 | ||
1173 | if (info) | ||
1174 | info->mtime = SWAP_LE32(header.formatted.mtime); | ||
1175 | |||
1170 | /* Read the header checksum */ | 1176 | /* Read the header checksum */ |
1171 | if (header.formatted.flags & 0x02) { | 1177 | if (header.formatted.flags & 0x02) { |
1172 | if (!top_up(PASS_STATE 2)) | 1178 | if (!top_up(PASS_STATE 2)) |
@@ -1177,7 +1183,7 @@ static int check_header_gzip(STATE_PARAM_ONLY) | |||
1177 | } | 1183 | } |
1178 | 1184 | ||
1179 | USE_DESKTOP(long long) int FAST_FUNC | 1185 | USE_DESKTOP(long long) int FAST_FUNC |
1180 | unpack_gz_stream(int in, int out) | 1186 | unpack_gz_stream_with_info(int in, int out, unpack_info_t *info) |
1181 | { | 1187 | { |
1182 | uint32_t v32; | 1188 | uint32_t v32; |
1183 | USE_DESKTOP(long long) int n; | 1189 | USE_DESKTOP(long long) int n; |
@@ -1192,7 +1198,7 @@ unpack_gz_stream(int in, int out) | |||
1192 | gunzip_src_fd = in; | 1198 | gunzip_src_fd = in; |
1193 | 1199 | ||
1194 | again: | 1200 | again: |
1195 | if (!check_header_gzip(PASS_STATE_ONLY)) { | 1201 | if (!check_header_gzip(PASS_STATE info)) { |
1196 | bb_error_msg("corrupted data"); | 1202 | bb_error_msg("corrupted data"); |
1197 | n = -1; | 1203 | n = -1; |
1198 | goto ret; | 1204 | goto ret; |
@@ -1239,3 +1245,9 @@ unpack_gz_stream(int in, int out) | |||
1239 | DEALLOC_STATE; | 1245 | DEALLOC_STATE; |
1240 | return n; | 1246 | return n; |
1241 | } | 1247 | } |
1248 | |||
1249 | USE_DESKTOP(long long) int FAST_FUNC | ||
1250 | unpack_gz_stream(int in, int out) | ||
1251 | { | ||
1252 | return unpack_gz_stream_with_info(in, out, NULL); | ||
1253 | } | ||
diff --git a/archival/rpm.c b/archival/rpm.c index 78568687e..4c36067c4 100644 --- a/archival/rpm.c +++ b/archival/rpm.c | |||
@@ -115,8 +115,8 @@ int rpm_main(int argc, char **argv) | |||
115 | } | 115 | } |
116 | } | 116 | } |
117 | argv += optind; | 117 | argv += optind; |
118 | argc -= optind; | 118 | //argc -= optind; |
119 | if (!argc) bb_show_usage(); | 119 | if (!argv[0]) bb_show_usage(); |
120 | 120 | ||
121 | while (*argv) { | 121 | while (*argv) { |
122 | rpm_fd = xopen(*argv++, O_RDONLY); | 122 | rpm_fd = xopen(*argv++, O_RDONLY); |
@@ -251,7 +251,7 @@ static void extract_cpio_gz(int fd) | |||
251 | static rpm_index **rpm_gettags(int fd, int *num_tags) | 251 | static rpm_index **rpm_gettags(int fd, int *num_tags) |
252 | { | 252 | { |
253 | /* We should never need mode than 200, and realloc later */ | 253 | /* We should never need mode than 200, and realloc later */ |
254 | rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); | 254 | rpm_index **tags = xzalloc(200 * sizeof(tags[0])); |
255 | int pass, tagindex = 0; | 255 | int pass, tagindex = 0; |
256 | 256 | ||
257 | xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ | 257 | xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ |
@@ -265,6 +265,9 @@ static rpm_index **rpm_gettags(int fd, int *num_tags) | |||
265 | uint32_t entries; /* Number of entries in header (4 bytes) */ | 265 | uint32_t entries; /* Number of entries in header (4 bytes) */ |
266 | uint32_t size; /* Size of store (4 bytes) */ | 266 | uint32_t size; /* Size of store (4 bytes) */ |
267 | } header; | 267 | } header; |
268 | struct BUG_header { | ||
269 | char BUG_header[sizeof(header) == 16 ? 1 : -1]; | ||
270 | }; | ||
268 | rpm_index *tmpindex; | 271 | rpm_index *tmpindex; |
269 | int storepos; | 272 | int storepos; |
270 | 273 | ||
@@ -278,8 +281,8 @@ static rpm_index **rpm_gettags(int fd, int *num_tags) | |||
278 | storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16; | 281 | storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16; |
279 | 282 | ||
280 | while (header.entries--) { | 283 | while (header.entries--) { |
281 | tmpindex = tags[tagindex++] = xmalloc(sizeof(rpm_index)); | 284 | tmpindex = tags[tagindex++] = xmalloc(sizeof(*tmpindex)); |
282 | xread(fd, tmpindex, sizeof(rpm_index)); | 285 | xread(fd, tmpindex, sizeof(*tmpindex)); |
283 | tmpindex->tag = ntohl(tmpindex->tag); | 286 | tmpindex->tag = ntohl(tmpindex->tag); |
284 | tmpindex->type = ntohl(tmpindex->type); | 287 | tmpindex->type = ntohl(tmpindex->type); |
285 | tmpindex->count = ntohl(tmpindex->count); | 288 | tmpindex->count = ntohl(tmpindex->count); |
@@ -292,7 +295,7 @@ static rpm_index **rpm_gettags(int fd, int *num_tags) | |||
292 | if (pass == 0) | 295 | if (pass == 0) |
293 | xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR); | 296 | xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR); |
294 | } | 297 | } |
295 | tags = xrealloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */ | 298 | tags = xrealloc(tags, tagindex * sizeof(tags[0])); /* realloc tags to save space */ |
296 | *num_tags = tagindex; | 299 | *num_tags = tagindex; |
297 | return tags; /* All done, leave the file at the start of the gzipped cpio archive */ | 300 | return tags; /* All done, leave the file at the start of the gzipped cpio archive */ |
298 | } | 301 | } |
diff --git a/include/libbb.h b/include/libbb.h index 2a8b18336..5b6a2dae1 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -912,10 +912,7 @@ int chown_main(int argc, char **argv) USE_CHOWN(MAIN_EXTERNALLY_VISIBLE); | |||
912 | /* Don't need USE_xxx() guard for these */ | 912 | /* Don't need USE_xxx() guard for these */ |
913 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 913 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
914 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 914 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
915 | int bbunpack(char **argv, | 915 | |
916 | char* (*make_new_name)(char *filename), | ||
917 | USE_DESKTOP(long long) int (*unpacker)(void) | ||
918 | ) FAST_FUNC; | ||
919 | #if ENABLE_ROUTE | 916 | #if ENABLE_ROUTE |
920 | void bb_displayroutes(int noresolve, int netstatfmt) FAST_FUNC; | 917 | void bb_displayroutes(int noresolve, int netstatfmt) FAST_FUNC; |
921 | #endif | 918 | #endif |
diff --git a/include/unarchive.h b/include/unarchive.h index 7ff791be5..9077130a5 100644 --- a/include/unarchive.h +++ b/include/unarchive.h | |||
@@ -77,6 +77,12 @@ typedef struct archive_handle_t { | |||
77 | } archive_handle_t; | 77 | } archive_handle_t; |
78 | 78 | ||
79 | 79 | ||
80 | /* Info struct unpackers can fill out to inform users of thing like | ||
81 | * timestamps of unpacked files */ | ||
82 | typedef struct unpack_info_t { | ||
83 | time_t mtime; | ||
84 | } unpack_info_t; | ||
85 | |||
80 | extern archive_handle_t *init_handle(void) FAST_FUNC; | 86 | extern archive_handle_t *init_handle(void) FAST_FUNC; |
81 | 87 | ||
82 | extern char filter_accept_all(archive_handle_t *archive_handle) FAST_FUNC; | 88 | extern char filter_accept_all(archive_handle_t *archive_handle) FAST_FUNC; |
@@ -126,10 +132,15 @@ USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd) FAST_FUNC; | |||
126 | /* the rest wants 2 first bytes already skipped by the caller */ | 132 | /* the rest wants 2 first bytes already skipped by the caller */ |
127 | USE_DESKTOP(long long) int unpack_bz2_stream(int src_fd, int dst_fd) FAST_FUNC; | 133 | USE_DESKTOP(long long) int unpack_bz2_stream(int src_fd, int dst_fd) FAST_FUNC; |
128 | USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd) FAST_FUNC; | 134 | USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd) FAST_FUNC; |
135 | USE_DESKTOP(long long) int unpack_gz_stream_with_info(int src_fd, int dst_fd, unpack_info_t *info) FAST_FUNC; | ||
129 | USE_DESKTOP(long long) int unpack_Z_stream(int fd_in, int fd_out) FAST_FUNC; | 136 | USE_DESKTOP(long long) int unpack_Z_stream(int fd_in, int fd_out) FAST_FUNC; |
130 | /* wrapper which checks first two bytes to be "BZ" */ | 137 | /* wrapper which checks first two bytes to be "BZ" */ |
131 | USE_DESKTOP(long long) int unpack_bz2_stream_prime(int src_fd, int dst_fd) FAST_FUNC; | 138 | USE_DESKTOP(long long) int unpack_bz2_stream_prime(int src_fd, int dst_fd) FAST_FUNC; |
132 | 139 | ||
140 | int bbunpack(char **argv, | ||
141 | char* (*make_new_name)(char *filename), | ||
142 | USE_DESKTOP(long long) int (*unpacker)(unpack_info_t *info)) FAST_FUNC; | ||
143 | |||
133 | #if BB_MMU | 144 | #if BB_MMU |
134 | void open_transformer(int fd, | 145 | void open_transformer(int fd, |
135 | USE_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd)) FAST_FUNC; | 146 | USE_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd)) FAST_FUNC; |
diff --git a/modutils/lsmod.c b/modutils/lsmod.c index b66563693..87dd1fcba 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c | |||
@@ -46,7 +46,7 @@ int lsmod_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
46 | #if ENABLE_FEATURE_LSMOD_PRETTY_2_6_OUTPUT | 46 | #if ENABLE_FEATURE_LSMOD_PRETTY_2_6_OUTPUT |
47 | char *token[4]; | 47 | char *token[4]; |
48 | parser_t *parser = config_open("/proc/modules"); | 48 | parser_t *parser = config_open("/proc/modules"); |
49 | printf("Module Size Used by"); //vda! | 49 | printf("%-24sSize Used by", "Module"); |
50 | check_tainted(); | 50 | check_tainted(); |
51 | 51 | ||
52 | if (ENABLE_FEATURE_2_4_MODULES | 52 | if (ENABLE_FEATURE_2_4_MODULES |