Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/archival/bbunzip.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/archival/bbunzip.c
r3232 r3621 8 8 #include "bb_archive.h" 9 9 10 /* lzop_main() uses bbunpack(), need this: */ 11 //kbuild:lib-$(CONFIG_LZOP) += bbunzip.o 12 13 /* Note: must be kept in sync with archival/lzop.c */ 10 14 enum { 11 15 OPT_STDOUT = 1 << 0, … … 13 17 /* only some decompressors: */ 14 18 OPT_VERBOSE = 1 << 2, 15 OPT_DECOMPRESS = 1 << 3, 16 OPT_TEST = 1 << 4, 19 OPT_QUIET = 1 << 3, 20 OPT_DECOMPRESS = 1 << 4, 21 OPT_TEST = 1 << 5, 22 SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION, 17 23 }; 18 24 … … 34 40 35 41 int FAST_FUNC bbunpack(char **argv, 36 IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_ aux_data_t *aux),42 IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate), 37 43 char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), 38 44 const char *expected_ext … … 40 46 { 41 47 struct stat stat_buf; 42 IF_DESKTOP(long long) int status ;48 IF_DESKTOP(long long) int status = 0; 43 49 char *filename, *new_name; 44 50 smallint exitcode = 0; 45 transformer_ aux_data_t aux;51 transformer_state_t xstate; 46 52 47 53 do { … … 55 61 /* Open src */ 56 62 if (filename) { 57 if (stat(filename, &stat_buf) != 0) { 58 bb_simple_perror_msg(filename); 63 if (!(option_mask32 & SEAMLESS_MAGIC)) { 64 if (stat(filename, &stat_buf) != 0) { 65 err_name: 66 bb_simple_perror_msg(filename); 59 67 err: 60 exitcode = 1; 61 goto free_name; 68 exitcode = 1; 69 goto free_name; 70 } 71 if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0)) 72 goto err; 73 } else { 74 /* "clever zcat" with FILE */ 75 /* fail_if_not_compressed because zcat refuses uncompressed input */ 76 int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1); 77 if (fd < 0) 78 goto err_name; 79 xmove_fd(fd, STDIN_FILENO); 62 80 } 63 if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0)) 81 } else 82 if (option_mask32 & SEAMLESS_MAGIC) { 83 /* "clever zcat" on stdin */ 84 if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1)) 64 85 goto err; 65 86 } … … 69 90 if (option_mask32 & OPT_TEST) 70 91 if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0)) 71 goto err;92 xfunc_die(); 72 93 filename = NULL; 73 94 } … … 94 115 95 116 /* Check that the input is sane */ 96 if ( isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {117 if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) { 97 118 bb_error_msg_and_die("compressed data not read from terminal, " 98 119 "use -f to force it"); 99 120 } 100 121 101 init_transformer_aux_data(&aux); 102 aux.check_signature = 1; 103 status = unpacker(&aux); 104 if (status < 0) 105 exitcode = 1; 122 if (!(option_mask32 & SEAMLESS_MAGIC)) { 123 init_transformer_state(&xstate); 124 xstate.signature_skipped = 0; 125 /*xstate.src_fd = STDIN_FILENO; - already is */ 126 xstate.dst_fd = STDOUT_FILENO; 127 status = unpacker(&xstate); 128 if (status < 0) 129 exitcode = 1; 130 } else { 131 if (bb_copyfd_eof(STDIN_FILENO, STDOUT_FILENO) < 0) 132 /* Disk full, tty closed, etc. No point in continuing */ 133 xfunc_die(); 134 } 106 135 107 136 if (!(option_mask32 & OPT_STDOUT)) … … 110 139 if (filename) { 111 140 char *del = new_name; 141 112 142 if (status >= 0) { 143 unsigned new_name_len; 144 113 145 /* TODO: restore other things? */ 114 if ( aux.mtime != 0) {146 if (xstate.mtime != 0) { 115 147 struct timeval times[2]; 116 148 117 times[1].tv_sec = times[0].tv_sec = aux.mtime;149 times[1].tv_sec = times[0].tv_sec = xstate.mtime; 118 150 times[1].tv_usec = times[0].tv_usec = 0; 119 151 /* Note: we closed it first. … … 124 156 } 125 157 126 /* Delete _compressed_ file */ 158 if (ENABLE_DESKTOP) 159 new_name_len = strlen(new_name); 160 /* Restore source filename (unless tgz -> tar case) */ 161 if (new_name == filename) { 162 new_name_len = strlen(filename); 163 filename[new_name_len] = '.'; 164 } 165 /* Extreme bloat for gunzip compat */ 166 /* Some users do want this info... */ 167 if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) { 168 unsigned percent = status 169 ? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status) 170 : 0; 171 fprintf(stderr, "%s: %u%% - replaced with %.*s\n", 172 filename, 173 100u - percent, 174 new_name_len, new_name 175 ); 176 } 177 /* Delete _source_ file */ 127 178 del = filename; 128 /* restore extension (unless tgz -> tar case) */129 if (new_name == filename)130 filename[strlen(filename)] = '.';131 179 } 132 180 xunlink(del); 133 134 #if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */135 /* Extreme bloat for gunzip compat */136 if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {137 fprintf(stderr, "%s: %u%% - replaced with %s\n",138 filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);139 }140 #endif141 142 181 free_name: 143 182 if (new_name != filename) … … 173 212 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 174 213 */ 175 176 214 //usage:#define uncompress_trivial_usage 177 215 //usage: "[-cf] [FILE]..." … … 181 219 //usage: "\n -f Overwrite" 182 220 221 //config:config UNCOMPRESS 222 //config: bool "uncompress" 223 //config: default n # ancient 224 //config: help 225 //config: uncompress is used to decompress archives created by compress. 226 //config: Not much used anymore, replaced by gzip/gunzip. 227 228 //applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP)) 229 //kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o 183 230 #if ENABLE_UNCOMPRESS 184 static185 IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)186 {187 return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);188 }189 231 int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 190 232 int uncompress_main(int argc UNUSED_PARAM, char **argv) … … 193 235 argv += optind; 194 236 195 return bbunpack(argv, unpack_ uncompress, make_new_name_generic, "Z");237 return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z"); 196 238 } 197 239 #endif … … 221 263 * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, 222 264 * Ken Turkowski, Dave Mack and Peter Jannesen. 223 *224 * See the license_msg below and the file COPYING for the software license.225 * See the file algorithm.doc for the compression algorithms and file formats.226 265 */ 227 228 266 //usage:#define gunzip_trivial_usage 229 267 //usage: "[-cft] [FILE]..." … … 242 280 //usage: 243 281 //usage:#define zcat_trivial_usage 244 //usage: " FILE"282 //usage: "[FILE]..." 245 283 //usage:#define zcat_full_usage "\n\n" 246 284 //usage: "Decompress to stdout" 247 285 286 //config:config GUNZIP 287 //config: bool "gunzip" 288 //config: default y 289 //config: help 290 //config: gunzip is used to decompress archives created by gzip. 291 //config: You can use the `-t' option to test the integrity of 292 //config: an archive, without decompressing it. 293 //config: 294 //config:config FEATURE_GUNZIP_LONG_OPTIONS 295 //config: bool "Enable long options" 296 //config: default y 297 //config: depends on GUNZIP && LONG_OPTS 298 //config: help 299 //config: Enable use of long options. 300 301 //applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP)) 302 //applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat)) 303 //kbuild:lib-$(CONFIG_GZIP) += bbunzip.o 304 //kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o 248 305 #if ENABLE_GUNZIP 249 306 static … … 272 329 return filename; 273 330 } 274 static 275 IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux) 276 { 277 return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO); 278 } 331 332 #if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS 333 static const char gunzip_longopts[] ALIGN1 = 334 "stdout\0" No_argument "c" 335 "to-stdout\0" No_argument "c" 336 "force\0" No_argument "f" 337 "test\0" No_argument "t" 338 "no-name\0" No_argument "n" 339 ; 340 #endif 341 279 342 /* 280 343 * Linux kernel build uses gzip -d -n. We accept and ignore it. … … 293 356 int gunzip_main(int argc UNUSED_PARAM, char **argv) 294 357 { 295 getopt32(argv, "cfvdtn"); 358 #if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS 359 applet_long_options = gunzip_longopts; 360 #endif 361 getopt32(argv, "cfvqdtn"); 296 362 argv += optind; 297 /* if called as zcat */ 363 364 /* If called as zcat... 365 * Normally, "zcat" is just "gunzip -c". 366 * But if seamless magic is enabled, then we are much more clever. 367 */ 298 368 if (applet_name[1] == 'c') 299 option_mask32 |= OPT_STDOUT ;300 301 return bbunpack(argv, unpack_g unzip, make_new_name_gunzip, /*unused:*/ NULL);369 option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC; 370 371 return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL); 302 372 } 303 373 #endif … … 317 387 //usage: "\n -f Force" 318 388 //usage:#define bzcat_trivial_usage 319 //usage: " FILE"389 //usage: "[FILE]..." 320 390 //usage:#define bzcat_full_usage "\n\n" 321 391 //usage: "Decompress to stdout" 392 393 //config:config BUNZIP2 394 //config: bool "bunzip2" 395 //config: default y 396 //config: help 397 //config: bunzip2 is a compression utility using the Burrows-Wheeler block 398 //config: sorting text compression algorithm, and Huffman coding. Compression 399 //config: is generally considerably better than that achieved by more 400 //config: conventional LZ77/LZ78-based compressors, and approaches the 401 //config: performance of the PPM family of statistical compressors. 402 //config: 403 //config: Unless you have a specific application which requires bunzip2, you 404 //config: should probably say N here. 405 322 406 //applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) 323 407 //applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) 408 //kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o 409 //kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o 324 410 #if ENABLE_BUNZIP2 325 static326 IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)327 {328 return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);329 }330 411 int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 331 412 int bunzip2_main(int argc UNUSED_PARAM, char **argv) 332 413 { 333 getopt32(argv, "cfv dt");414 getopt32(argv, "cfvqdt"); 334 415 argv += optind; 335 416 if (applet_name[2] == 'c') /* bzcat */ 336 417 option_mask32 |= OPT_STDOUT; 337 418 338 return bbunpack(argv, unpack_b unzip2, make_new_name_generic, "bz2");419 return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2"); 339 420 } 340 421 #endif … … 349 430 * Licensed under GPLv2, see file LICENSE in this source tree. 350 431 */ 351 352 432 //usage:#define unlzma_trivial_usage 353 433 //usage: "[-cf] [FILE]..." … … 366 446 //usage: 367 447 //usage:#define lzcat_trivial_usage 368 //usage: " FILE"448 //usage: "[FILE]..." 369 449 //usage:#define lzcat_full_usage "\n\n" 370 450 //usage: "Decompress to stdout" … … 386 466 //usage: 387 467 //usage:#define xzcat_trivial_usage 388 //usage: " FILE"468 //usage: "[FILE]..." 389 469 //usage:#define xzcat_full_usage "\n\n" 390 470 //usage: "Decompress to stdout" 391 471 472 //config:config UNLZMA 473 //config: bool "unlzma" 474 //config: default y 475 //config: help 476 //config: unlzma is a compression utility using the Lempel-Ziv-Markov chain 477 //config: compression algorithm, and range coding. Compression 478 //config: is generally considerably better than that achieved by the bzip2 479 //config: compressors. 480 //config: 481 //config: The BusyBox unlzma applet is limited to decompression only. 482 //config: On an x86 system, this applet adds about 4K. 483 //config: 484 //config:config FEATURE_LZMA_FAST 485 //config: bool "Optimize unlzma for speed" 486 //config: default n 487 //config: depends on UNLZMA 488 //config: help 489 //config: This option reduces decompression time by about 25% at the cost of 490 //config: a 1K bigger binary. 491 //config: 492 //config:config LZMA 493 //config: bool "Provide lzma alias which supports only unpacking" 494 //config: default y 495 //config: depends on UNLZMA 496 //config: help 497 //config: Enable this option if you want commands like "lzma -d" to work. 498 //config: IOW: you'll get lzma applet, but it will always require -d option. 499 500 //applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP)) 501 //applet:IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat)) 502 //applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma)) 503 //kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o 392 504 #if ENABLE_UNLZMA 393 static394 IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)395 {396 return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);397 }398 505 int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 399 506 int unlzma_main(int argc UNUSED_PARAM, char **argv) 400 507 { 401 IF_LZMA(int opts =) getopt32(argv, "cfv dt");508 IF_LZMA(int opts =) getopt32(argv, "cfvqdt"); 402 509 # if ENABLE_LZMA 403 510 /* lzma without -d or -t? */ … … 410 517 411 518 argv += optind; 412 return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma"); 413 } 414 #endif 415 416 519 return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma"); 520 } 521 #endif 522 523 524 //config:config UNXZ 525 //config: bool "unxz" 526 //config: default y 527 //config: help 528 //config: unxz is a unlzma successor. 529 //config: 530 //config:config XZ 531 //config: bool "Provide xz alias which supports only unpacking" 532 //config: default y 533 //config: depends on UNXZ 534 //config: help 535 //config: Enable this option if you want commands like "xz -d" to work. 536 //config: IOW: you'll get xz applet, but it will always require -d option. 537 538 //applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP)) 539 //applet:IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat)) 540 //applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz)) 541 //kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o 417 542 #if ENABLE_UNXZ 418 static419 IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)420 {421 return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);422 }423 543 int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 424 544 int unxz_main(int argc UNUSED_PARAM, char **argv) 425 545 { 426 IF_XZ(int opts =) getopt32(argv, "cfv dt");546 IF_XZ(int opts =) getopt32(argv, "cfvqdt"); 427 547 # if ENABLE_XZ 428 548 /* xz without -d or -t? */ … … 435 555 436 556 argv += optind; 437 return bbunpack(argv, unpack_ unxz, make_new_name_generic, "xz");438 } 439 #endif 557 return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz"); 558 } 559 #endif
Note:
See TracChangeset
for help on using the changeset viewer.