diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-07 12:44:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-07 12:44:56 +0200 |
commit | 40c221334fca24acca35f372aef18c0c768c86cc (patch) | |
tree | a6e11e6bb521c04875b01486f6d2aabdc4896939 | |
parent | 3de3f57c6d0200b49a5e31e80421e36272035e15 (diff) | |
parent | 0c6914e50c913b54632b7279dbe3544ca7e633d0 (diff) | |
download | busybox-w32-40c221334fca24acca35f372aef18c0c768c86cc.tar.gz busybox-w32-40c221334fca24acca35f372aef18c0c768c86cc.tar.bz2 busybox-w32-40c221334fca24acca35f372aef18c0c768c86cc.zip |
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
-rw-r--r-- | archival/unzip.c | 147 | ||||
-rw-r--r-- | include/usage.h | 17 | ||||
-rw-r--r-- | modutils/modprobe-small.c | 39 |
3 files changed, 155 insertions, 48 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 4201d1dd2..afab3280d 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -253,14 +253,16 @@ int unzip_main(int argc, char **argv) | |||
253 | enum { O_PROMPT, O_NEVER, O_ALWAYS }; | 253 | enum { O_PROMPT, O_NEVER, O_ALWAYS }; |
254 | 254 | ||
255 | zip_header_t zip_header; | 255 | zip_header_t zip_header; |
256 | smallint verbose = 1; | 256 | smallint quiet = 0; |
257 | IF_NOT_DESKTOP(const) smallint verbose = 0; | ||
257 | smallint listing = 0; | 258 | smallint listing = 0; |
258 | smallint overwrite = O_PROMPT; | 259 | smallint overwrite = O_PROMPT; |
259 | #if ENABLE_DESKTOP | 260 | #if ENABLE_DESKTOP |
260 | uint32_t cds_offset; | 261 | uint32_t cds_offset; |
261 | unsigned cds_entries; | 262 | unsigned cds_entries; |
262 | #endif | 263 | #endif |
263 | unsigned total_size; | 264 | unsigned long total_usize; |
265 | unsigned long total_size; | ||
264 | unsigned total_entries; | 266 | unsigned total_entries; |
265 | int dst_fd = -1; | 267 | int dst_fd = -1; |
266 | char *src_fn = NULL; | 268 | char *src_fn = NULL; |
@@ -273,8 +275,49 @@ int unzip_main(int argc, char **argv) | |||
273 | char key_buf[80]; | 275 | char key_buf[80]; |
274 | struct stat stat_buf; | 276 | struct stat stat_buf; |
275 | 277 | ||
278 | /* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP: | ||
279 | * | ||
280 | * # /usr/bin/unzip -qq -v decompress_unlzma.i.zip | ||
281 | * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i | ||
282 | * # /usr/bin/unzip -q -v decompress_unlzma.i.zip | ||
283 | * Length Method Size Ratio Date Time CRC-32 Name | ||
284 | * -------- ------ ------- ----- ---- ---- ------ ---- | ||
285 | * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i | ||
286 | * -------- ------- --- ------- | ||
287 | * 204372 35278 83% 1 file | ||
288 | * # /usr/bin/unzip -v decompress_unlzma.i.zip | ||
289 | * Archive: decompress_unlzma.i.zip | ||
290 | * Length Method Size Ratio Date Time CRC-32 Name | ||
291 | * -------- ------ ------- ----- ---- ---- ------ ---- | ||
292 | * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i | ||
293 | * -------- ------- --- ------- | ||
294 | * 204372 35278 83% 1 file | ||
295 | * # unzip -v decompress_unlzma.i.zip | ||
296 | * Archive: decompress_unlzma.i.zip | ||
297 | * Length Date Time Name | ||
298 | * -------- ---- ---- ---- | ||
299 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
300 | * -------- ------- | ||
301 | * 204372 1 files | ||
302 | * # /usr/bin/unzip -l -qq decompress_unlzma.i.zip | ||
303 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
304 | * # /usr/bin/unzip -l -q decompress_unlzma.i.zip | ||
305 | * Length Date Time Name | ||
306 | * -------- ---- ---- ---- | ||
307 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
308 | * -------- ------- | ||
309 | * 204372 1 file | ||
310 | * # /usr/bin/unzip -l decompress_unlzma.i.zip | ||
311 | * Archive: decompress_unlzma.i.zip | ||
312 | * Length Date Time Name | ||
313 | * -------- ---- ---- ---- | ||
314 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
315 | * -------- ------- | ||
316 | * 204372 1 file | ||
317 | */ | ||
318 | |||
276 | /* '-' makes getopt return 1 for non-options */ | 319 | /* '-' makes getopt return 1 for non-options */ |
277 | while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) { | 320 | while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) { |
278 | switch (opt_range) { | 321 | switch (opt_range) { |
279 | case 0: /* Options */ | 322 | case 0: /* Options */ |
280 | switch (opt) { | 323 | switch (opt) { |
@@ -294,7 +337,12 @@ int unzip_main(int argc, char **argv) | |||
294 | dst_fd = STDOUT_FILENO; | 337 | dst_fd = STDOUT_FILENO; |
295 | 338 | ||
296 | case 'q': /* Be quiet */ | 339 | case 'q': /* Be quiet */ |
297 | verbose = 0; | 340 | quiet++; |
341 | break; | ||
342 | |||
343 | case 'v': /* Verbose list */ | ||
344 | IF_DESKTOP(verbose++;) | ||
345 | listing = 1; | ||
298 | break; | 346 | break; |
299 | 347 | ||
300 | case 1: /* The zip file */ | 348 | case 1: /* The zip file */ |
@@ -373,14 +421,21 @@ int unzip_main(int argc, char **argv) | |||
373 | if (base_dir) | 421 | if (base_dir) |
374 | xchdir(base_dir); | 422 | xchdir(base_dir); |
375 | 423 | ||
376 | if (verbose) { | 424 | if (quiet <= 1) { /* not -qq */ |
377 | printf("Archive: %s\n", src_fn); | 425 | if (quiet == 0) |
378 | if (listing){ | 426 | printf("Archive: %s\n", src_fn); |
379 | puts(" Length Date Time Name\n" | 427 | if (listing) { |
380 | " -------- ---- ---- ----"); | 428 | puts(verbose ? |
429 | " Length Method Size Ratio Date Time CRC-32 Name\n" | ||
430 | "-------- ------ ------- ----- ---- ---- ------ ----" | ||
431 | : | ||
432 | " Length Date Time Name\n" | ||
433 | " -------- ---- ---- ----" | ||
434 | ); | ||
381 | } | 435 | } |
382 | } | 436 | } |
383 | 437 | ||
438 | total_usize = 0; | ||
384 | total_size = 0; | 439 | total_size = 0; |
385 | total_entries = 0; | 440 | total_entries = 0; |
386 | #if ENABLE_DESKTOP | 441 | #if ENABLE_DESKTOP |
@@ -449,20 +504,39 @@ int unzip_main(int argc, char **argv) | |||
449 | 504 | ||
450 | } else { /* Extract entry */ | 505 | } else { /* Extract entry */ |
451 | if (listing) { /* List entry */ | 506 | if (listing) { /* List entry */ |
452 | if (verbose) { | 507 | unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); |
453 | unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); | 508 | if (!verbose) { |
454 | printf("%9u %02u-%02u-%02u %02u:%02u %s\n", | 509 | // " Length Date Time Name\n" |
455 | zip_header.formatted.ucmpsize, | 510 | // " -------- ---- ---- ----" |
456 | (dostime & 0x01e00000) >> 21, | 511 | printf( "%9u %02u-%02u-%02u %02u:%02u %s\n", |
457 | (dostime & 0x001f0000) >> 16, | 512 | (unsigned)zip_header.formatted.ucmpsize, |
458 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, | 513 | (dostime & 0x01e00000) >> 21, |
459 | (dostime & 0x0000f800) >> 11, | 514 | (dostime & 0x001f0000) >> 16, |
460 | (dostime & 0x000007e0) >> 5, | 515 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, |
461 | dst_fn); | 516 | (dostime & 0x0000f800) >> 11, |
462 | total_size += zip_header.formatted.ucmpsize; | 517 | (dostime & 0x000007e0) >> 5, |
518 | dst_fn); | ||
519 | total_usize += zip_header.formatted.ucmpsize; | ||
463 | } else { | 520 | } else { |
464 | /* short listing -- filenames only */ | 521 | unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; |
465 | puts(dst_fn); | 522 | percents = percents * 100; |
523 | if (zip_header.formatted.ucmpsize) | ||
524 | percents /= zip_header.formatted.ucmpsize; | ||
525 | // " Length Method Size Ratio Date Time CRC-32 Name\n" | ||
526 | // "-------- ------ ------- ----- ---- ---- ------ ----" | ||
527 | printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n", | ||
528 | (unsigned)zip_header.formatted.ucmpsize, | ||
529 | (unsigned)zip_header.formatted.cmpsize, | ||
530 | (unsigned)percents, | ||
531 | (dostime & 0x01e00000) >> 21, | ||
532 | (dostime & 0x001f0000) >> 16, | ||
533 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, | ||
534 | (dostime & 0x0000f800) >> 11, | ||
535 | (dostime & 0x000007e0) >> 5, | ||
536 | zip_header.formatted.crc32, | ||
537 | dst_fn); | ||
538 | total_usize += zip_header.formatted.ucmpsize; | ||
539 | total_size += zip_header.formatted.cmpsize; | ||
466 | } | 540 | } |
467 | i = 'n'; | 541 | i = 'n'; |
468 | } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ | 542 | } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ |
@@ -472,7 +546,7 @@ int unzip_main(int argc, char **argv) | |||
472 | if (errno != ENOENT) { | 546 | if (errno != ENOENT) { |
473 | bb_perror_msg_and_die("can't stat '%s'", dst_fn); | 547 | bb_perror_msg_and_die("can't stat '%s'", dst_fn); |
474 | } | 548 | } |
475 | if (verbose) { | 549 | if (!quiet) { |
476 | printf(" creating: %s\n", dst_fn); | 550 | printf(" creating: %s\n", dst_fn); |
477 | } | 551 | } |
478 | unzip_create_leading_dirs(dst_fn); | 552 | unzip_create_leading_dirs(dst_fn); |
@@ -520,7 +594,7 @@ int unzip_main(int argc, char **argv) | |||
520 | unzip_create_leading_dirs(dst_fn); | 594 | unzip_create_leading_dirs(dst_fn); |
521 | dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); | 595 | dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); |
522 | case -1: /* Unzip */ | 596 | case -1: /* Unzip */ |
523 | if (verbose) { | 597 | if (!quiet) { |
524 | printf(" inflating: %s\n", dst_fn); | 598 | printf(" inflating: %s\n", dst_fn); |
525 | } | 599 | } |
526 | unzip_extract(&zip_header, dst_fd); | 600 | unzip_extract(&zip_header, dst_fd); |
@@ -549,17 +623,32 @@ int unzip_main(int argc, char **argv) | |||
549 | goto check_file; | 623 | goto check_file; |
550 | 624 | ||
551 | default: | 625 | default: |
552 | printf("error: invalid response [%c]\n",(char)i); | 626 | printf("error: invalid response [%c]\n", (char)i); |
553 | goto check_file; | 627 | goto check_file; |
554 | } | 628 | } |
555 | 629 | ||
556 | total_entries++; | 630 | total_entries++; |
557 | } | 631 | } |
558 | 632 | ||
559 | if (listing && verbose) { | 633 | if (listing && quiet <= 1) { |
560 | printf(" -------- -------\n" | 634 | if (!verbose) { |
561 | "%9d %d files\n", | 635 | // " Length Date Time Name\n" |
562 | total_size, total_entries); | 636 | // " -------- ---- ---- ----" |
637 | printf( " -------- -------\n" | ||
638 | "%9lu" " %u files\n", | ||
639 | total_usize, total_entries); | ||
640 | } else { | ||
641 | unsigned long percents = total_usize - total_size; | ||
642 | percents = percents * 100; | ||
643 | if (total_usize) | ||
644 | percents /= total_usize; | ||
645 | // " Length Method Size Ratio Date Time CRC-32 Name\n" | ||
646 | // "-------- ------ ------- ----- ---- ---- ------ ----" | ||
647 | printf( "-------- ------- --- -------\n" | ||
648 | "%8lu" "%17lu%4u%% %u files\n", | ||
649 | total_usize, total_size, (unsigned)percents, | ||
650 | total_entries); | ||
651 | } | ||
563 | } | 652 | } |
564 | 653 | ||
565 | return 0; | 654 | return 0; |
diff --git a/include/usage.h b/include/usage.h index e571d2ba3..036cf9db7 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -2824,9 +2824,21 @@ | |||
2824 | "-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n" | 2824 | "-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n" |
2825 | 2825 | ||
2826 | #define modprobe_trivial_usage \ | 2826 | #define modprobe_trivial_usage \ |
2827 | "[-knqrsv] MODULE [symbol=value...]" | 2827 | IF_MODPROBE_SMALL("[-qfwrsv] MODULE [symbol=value...]") \ |
2828 | IF_NOT_MODPROBE_SMALL("[-" \ | ||
2829 | IF_FEATURE_2_4_MODULES("k")"nqrsv" \ | ||
2830 | IF_FEATURE_MODPROBE_BLACKLIST("b")"] MODULE [symbol=value...]") | ||
2828 | #define modprobe_full_usage "\n\n" \ | 2831 | #define modprobe_full_usage "\n\n" \ |
2829 | "Options:" \ | 2832 | "Options:" \ |
2833 | IF_MODPROBE_SMALL( \ | ||
2834 | "\n -q Quiet" \ | ||
2835 | "\n -f Force" \ | ||
2836 | "\n -w Wait for unload" \ | ||
2837 | "\n -r Remove module (stacks) or do autoclean" \ | ||
2838 | "\n -s Report via syslog instead of stderr" \ | ||
2839 | "\n -v Verbose" \ | ||
2840 | ) \ | ||
2841 | IF_NOT_MODPROBE_SMALL( \ | ||
2830 | IF_FEATURE_2_4_MODULES( \ | 2842 | IF_FEATURE_2_4_MODULES( \ |
2831 | "\n -k Make module autoclean-able" \ | 2843 | "\n -k Make module autoclean-able" \ |
2832 | ) \ | 2844 | ) \ |
@@ -2837,7 +2849,8 @@ | |||
2837 | "\n -v Verbose" \ | 2849 | "\n -v Verbose" \ |
2838 | IF_FEATURE_MODPROBE_BLACKLIST( \ | 2850 | IF_FEATURE_MODPROBE_BLACKLIST( \ |
2839 | "\n -b Apply blacklist to module names too" \ | 2851 | "\n -b Apply blacklist to module names too" \ |
2840 | ) | 2852 | ) \ |
2853 | ) | ||
2841 | 2854 | ||
2842 | #define modprobe_notes_usage \ | 2855 | #define modprobe_notes_usage \ |
2843 | "modprobe can (un)load a stack of modules, passing each module options (when\n" \ | 2856 | "modprobe can (un)load a stack of modules, passing each module options (when\n" \ |
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index 02d8fbd40..e2359d042 100644 --- a/modutils/modprobe-small.c +++ b/modutils/modprobe-small.c | |||
@@ -44,11 +44,13 @@ struct globals { | |||
44 | char *module_load_options; | 44 | char *module_load_options; |
45 | smallint dep_bb_seen; | 45 | smallint dep_bb_seen; |
46 | smallint wrote_dep_bb_ok; | 46 | smallint wrote_dep_bb_ok; |
47 | int module_count; | 47 | unsigned module_count; |
48 | int module_found_idx; | 48 | int module_found_idx; |
49 | int stringbuf_idx; | 49 | unsigned stringbuf_idx; |
50 | char stringbuf[32 * 1024]; /* some modules have lots of stuff */ | 50 | unsigned stringbuf_size; |
51 | char *stringbuf; /* some modules have lots of stuff */ | ||
51 | /* for example, drivers/media/video/saa7134/saa7134.ko */ | 52 | /* for example, drivers/media/video/saa7134/saa7134.ko */ |
53 | /* therefore having a fixed biggish buffer is not wise */ | ||
52 | }; | 54 | }; |
53 | #define G (*ptr_to_globals) | 55 | #define G (*ptr_to_globals) |
54 | #define modinfo (G.modinfo ) | 56 | #define modinfo (G.modinfo ) |
@@ -58,16 +60,29 @@ struct globals { | |||
58 | #define module_found_idx (G.module_found_idx ) | 60 | #define module_found_idx (G.module_found_idx ) |
59 | #define module_load_options (G.module_load_options) | 61 | #define module_load_options (G.module_load_options) |
60 | #define stringbuf_idx (G.stringbuf_idx ) | 62 | #define stringbuf_idx (G.stringbuf_idx ) |
63 | #define stringbuf_size (G.stringbuf_size ) | ||
61 | #define stringbuf (G.stringbuf ) | 64 | #define stringbuf (G.stringbuf ) |
62 | #define INIT_G() do { \ | 65 | #define INIT_G() do { \ |
63 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 66 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
64 | } while (0) | 67 | } while (0) |
65 | 68 | ||
69 | static void append(const char *s) | ||
70 | { | ||
71 | unsigned len = strlen(s); | ||
72 | if (stringbuf_idx + len + 15 > stringbuf_size) { | ||
73 | stringbuf_size = stringbuf_idx + len + 127; | ||
74 | dbg2_error_msg("grow stringbuf to %u", stringbuf_size); | ||
75 | stringbuf = xrealloc(stringbuf, stringbuf_size); | ||
76 | } | ||
77 | memcpy(stringbuf + stringbuf_idx, s, len); | ||
78 | stringbuf_idx += len; | ||
79 | } | ||
66 | 80 | ||
67 | static void appendc(char c) | 81 | static void appendc(char c) |
68 | { | 82 | { |
69 | if (stringbuf_idx < sizeof(stringbuf)) | 83 | /* We appendc() only after append(), + 15 trick in append() |
70 | stringbuf[stringbuf_idx++] = c; | 84 | * makes it unnecessary to check for overflow here */ |
85 | stringbuf[stringbuf_idx++] = c; | ||
71 | } | 86 | } |
72 | 87 | ||
73 | static void bksp(void) | 88 | static void bksp(void) |
@@ -76,15 +91,6 @@ static void bksp(void) | |||
76 | stringbuf_idx--; | 91 | stringbuf_idx--; |
77 | } | 92 | } |
78 | 93 | ||
79 | static void append(const char *s) | ||
80 | { | ||
81 | size_t len = strlen(s); | ||
82 | if (stringbuf_idx + len < sizeof(stringbuf)) { | ||
83 | memcpy(stringbuf + stringbuf_idx, s, len); | ||
84 | stringbuf_idx += len; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | static void reset_stringbuf(void) | 94 | static void reset_stringbuf(void) |
89 | { | 95 | { |
90 | stringbuf_idx = 0; | 96 | stringbuf_idx = 0; |
@@ -92,7 +98,7 @@ static void reset_stringbuf(void) | |||
92 | 98 | ||
93 | static char* copy_stringbuf(void) | 99 | static char* copy_stringbuf(void) |
94 | { | 100 | { |
95 | char *copy = xmalloc(stringbuf_idx); | 101 | char *copy = xzalloc(stringbuf_idx + 1); /* terminating NUL */ |
96 | return memcpy(copy, stringbuf, stringbuf_idx); | 102 | return memcpy(copy, stringbuf, stringbuf_idx); |
97 | } | 103 | } |
98 | 104 | ||
@@ -216,8 +222,8 @@ static void parse_module(module_info *info, const char *pathname) | |||
216 | pos = (ptr - module_image); | 222 | pos = (ptr - module_image); |
217 | } | 223 | } |
218 | bksp(); /* remove last ' ' */ | 224 | bksp(); /* remove last ' ' */ |
219 | appendc('\0'); | ||
220 | info->aliases = copy_stringbuf(); | 225 | info->aliases = copy_stringbuf(); |
226 | replace(info->aliases, '-', '_'); | ||
221 | 227 | ||
222 | /* "dependency1 depandency2" */ | 228 | /* "dependency1 depandency2" */ |
223 | reset_stringbuf(); | 229 | reset_stringbuf(); |
@@ -228,7 +234,6 @@ static void parse_module(module_info *info, const char *pathname) | |||
228 | dbg2_error_msg("dep:'%s'", ptr); | 234 | dbg2_error_msg("dep:'%s'", ptr); |
229 | append(ptr); | 235 | append(ptr); |
230 | } | 236 | } |
231 | appendc('\0'); | ||
232 | info->deps = copy_stringbuf(); | 237 | info->deps = copy_stringbuf(); |
233 | 238 | ||
234 | free(module_image); | 239 | free(module_image); |