Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/archival
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 3 added
- 2 deleted
- 41 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/archival/Config.src
r3232 r3621 5 5 6 6 menu "Archival Utilities" 7 8 INSERT9 7 10 8 config FEATURE_SEAMLESS_XZ … … 34 32 config FEATURE_SEAMLESS_Z 35 33 bool "tar, rpm, modprobe etc understand .Z data" 36 default n 34 default n # it is ancient 37 35 help 38 36 Make tar, rpm, modprobe etc understand .Z data. 39 37 40 config AR 41 bool "ar" 42 default n # needs to be improved to be able to replace binutils ar 43 help 44 ar is an archival utility program used to create, modify, and 45 extract contents from archives. An archive is a single file holding 46 a collection of other files in a structure that makes it possible to 47 retrieve the original individual files (called archive members). 48 The original files' contents, mode (permissions), timestamp, owner, 49 and group are preserved in the archive, and can be restored on 50 extraction. 51 52 The stored filename is limited to 15 characters. (for more information 53 see long filename support). 54 ar has 60 bytes of overheads for every stored file. 55 56 This implementation of ar can extract archives, it cannot create or 57 modify them. 58 On an x86 system, the ar applet adds about 1K. 59 60 Unless you have a specific application which requires ar, you should 61 probably say N here. 62 63 config FEATURE_AR_LONG_FILENAMES 64 bool "Support for long filenames (not needed for debs)" 65 default y 66 depends on AR 67 help 68 By default the ar format can only store the first 15 characters 69 of the filename, this option removes that limitation. 70 It supports the GNU ar long filename method which moves multiple long 71 filenames into a the data section of a new ar entry. 72 73 config FEATURE_AR_CREATE 74 bool "Support archive creation" 75 default y 76 depends on AR 77 help 78 This enables archive creation (-c and -r) with busybox ar. 79 80 config BUNZIP2 81 bool "bunzip2" 82 default y 83 help 84 bunzip2 is a compression utility using the Burrows-Wheeler block 85 sorting text compression algorithm, and Huffman coding. Compression 86 is generally considerably better than that achieved by more 87 conventional LZ77/LZ78-based compressors, and approaches the 88 performance of the PPM family of statistical compressors. 89 90 Unless you have a specific application which requires bunzip2, you 91 should probably say N here. 92 93 config BZIP2 94 bool "bzip2" 95 default y 96 help 97 bzip2 is a compression utility using the Burrows-Wheeler block 98 sorting text compression algorithm, and Huffman coding. Compression 99 is generally considerably better than that achieved by more 100 conventional LZ77/LZ78-based compressors, and approaches the 101 performance of the PPM family of statistical compressors. 102 103 Unless you have a specific application which requires bzip2, you 104 should probably say N here. 105 106 config CPIO 107 bool "cpio" 108 default y 109 help 110 cpio is an archival utility program used to create, modify, and 111 extract contents from archives. 112 cpio has 110 bytes of overheads for every stored file. 113 114 This implementation of cpio can extract cpio archives created in the 115 "newc" or "crc" format, it cannot create or modify them. 116 117 Unless you have a specific application which requires cpio, you 118 should probably say N here. 119 120 config FEATURE_CPIO_O 121 bool "Support for archive creation" 122 default y 123 depends on CPIO 124 help 125 This implementation of cpio can create cpio archives in the "newc" 126 format only. 127 128 config FEATURE_CPIO_P 129 bool "Support for passthrough mode" 130 default y 131 depends on FEATURE_CPIO_O 132 help 133 Passthrough mode. Rarely used. 134 135 config DPKG 136 bool "dpkg" 137 default n 138 select FEATURE_SEAMLESS_GZ 139 help 140 dpkg is a medium-level tool to install, build, remove and manage 141 Debian packages. 142 143 This implementation of dpkg has a number of limitations, 144 you should use the official dpkg if possible. 145 146 config DPKG_DEB 147 bool "dpkg_deb" 148 default n 149 select FEATURE_SEAMLESS_GZ 150 help 151 dpkg-deb unpacks and provides information about Debian archives. 152 153 This implementation of dpkg-deb cannot pack archives. 154 155 Unless you have a specific application which requires dpkg-deb, 156 say N here. 157 158 config FEATURE_DPKG_DEB_EXTRACT_ONLY 159 bool "Extract only (-x)" 160 default n 161 depends on DPKG_DEB 162 help 163 This reduces dpkg-deb to the equivalent of 164 "ar -p <deb> data.tar.gz | tar -zx". However it saves space as none 165 of the extra dpkg-deb, ar or tar options are needed, they are linked 166 to internally. 167 168 config GUNZIP 169 bool "gunzip" 170 default y 171 help 172 gunzip is used to decompress archives created by gzip. 173 You can use the `-t' option to test the integrity of 174 an archive, without decompressing it. 175 176 config GZIP 177 bool "gzip" 178 default y 179 help 180 gzip is used to compress files. 181 It's probably the most widely used UNIX compression program. 182 183 config FEATURE_GZIP_LONG_OPTIONS 184 bool "Enable long options" 185 default y 186 depends on GZIP && LONG_OPTS 187 help 188 Enable use of long options, increases size by about 106 Bytes 189 190 config GZIP_FAST 191 int "Trade memory for gzip speed (0:small,slow - 2:fast,big)" 192 default 0 193 range 0 2 194 depends on GZIP 195 help 196 Enable big memory options for gzip. 197 0: small buffers, small hash-tables 198 1: larger buffers, larger hash-tables 199 2: larger buffers, largest hash-tables 200 Larger models may give slightly better compression 201 202 config LZOP 203 bool "lzop" 204 default y 205 help 206 Lzop compression/decompresion. 207 208 config LZOP_COMPR_HIGH 209 bool "lzop compression levels 7,8,9 (not very useful)" 210 default n 211 depends on LZOP 212 help 213 High levels (7,8,9) of lzop compression. These levels 214 are actually slower than gzip at equivalent compression ratios 215 and take up 3.2K of code. 216 217 config RPM2CPIO 218 bool "rpm2cpio" 219 default y 220 help 221 Converts a RPM file into a CPIO archive. 222 223 config RPM 224 bool "rpm" 225 default y 226 help 227 Mini RPM applet - queries and extracts RPM packages. 228 229 config TAR 230 bool "tar" 231 default y 232 help 233 tar is an archiving program. It's commonly used with gzip to 234 create compressed archives. It's probably the most widely used 235 UNIX archive program. 236 237 config FEATURE_TAR_CREATE 238 bool "Enable archive creation" 239 default y 240 depends on TAR 241 help 242 If you enable this option you'll be able to create 243 tar archives using the `-c' option. 244 245 config FEATURE_TAR_AUTODETECT 246 bool "Autodetect compressed tarballs" 247 default y 248 depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ) 249 help 250 With this option tar can automatically detect compressed 251 tarballs. Currently it works only on files (not pipes etc). 252 253 config FEATURE_TAR_FROM 254 bool "Enable -X (exclude from) and -T (include from) options)" 255 default y 256 depends on TAR 257 help 258 If you enable this option you'll be able to specify 259 a list of files to include or exclude from an archive. 260 261 config FEATURE_TAR_OLDGNU_COMPATIBILITY 262 bool "Support for old tar header format" 263 default y 264 depends on TAR || DPKG 265 help 266 This option is required to unpack archives created in 267 the old GNU format; help to kill this old format by 268 repacking your ancient archives with the new format. 269 270 config FEATURE_TAR_OLDSUN_COMPATIBILITY 271 bool "Enable untarring of tarballs with checksums produced by buggy Sun tar" 272 default y 273 depends on TAR || DPKG 274 help 275 This option is required to unpack archives created by some old 276 version of Sun's tar (it was calculating checksum using signed 277 arithmetic). It is said to be fixed in newer Sun tar, but "old" 278 tarballs still exist. 279 280 config FEATURE_TAR_GNU_EXTENSIONS 281 bool "Support for GNU tar extensions (long filenames)" 282 default y 283 depends on TAR || DPKG 284 help 285 With this option busybox supports GNU long filenames and 286 linknames. 287 288 config FEATURE_TAR_LONG_OPTIONS 289 bool "Enable long options" 290 default y 291 depends on TAR && LONG_OPTS 292 help 293 Enable use of long options, increases size by about 400 Bytes 294 295 config FEATURE_TAR_TO_COMMAND 296 bool "Support for writing to an external program" 297 default y 298 depends on TAR && FEATURE_TAR_LONG_OPTIONS 299 help 300 If you enable this option you'll be able to instruct tar to send 301 the contents of each extracted file to the standard input of an 302 external program. 303 304 config FEATURE_TAR_UNAME_GNAME 305 bool "Enable use of user and group names" 306 default y 307 depends on TAR 308 help 309 Enables use of user and group names in tar. This affects contents 310 listings (-t) and preserving permissions when unpacking (-p). 311 +200 bytes. 312 313 config FEATURE_TAR_NOPRESERVE_TIME 314 bool "Enable -m (do not preserve time) option" 315 default y 316 depends on TAR 317 help 318 With this option busybox supports GNU tar -m 319 (do not preserve time) option. 320 321 config FEATURE_TAR_SELINUX 322 bool "Support for extracting SELinux labels" 323 default n 324 depends on TAR && SELINUX 325 help 326 With this option busybox supports restoring SELinux labels 327 when extracting files from tar archives. 328 329 config UNCOMPRESS 330 bool "uncompress" 331 default n 332 help 333 uncompress is used to decompress archives created by compress. 334 Not much used anymore, replaced by gzip/gunzip. 335 336 config UNLZMA 337 bool "unlzma" 338 default y 339 help 340 unlzma is a compression utility using the Lempel-Ziv-Markov chain 341 compression algorithm, and range coding. Compression 342 is generally considerably better than that achieved by the bzip2 343 compressors. 344 345 The BusyBox unlzma applet is limited to decompression only. 346 On an x86 system, this applet adds about 4K. 347 348 config FEATURE_LZMA_FAST 349 bool "Optimize unlzma for speed" 350 default n 351 depends on UNLZMA 352 help 353 This option reduces decompression time by about 25% at the cost of 354 a 1K bigger binary. 355 356 config LZMA 357 bool "Provide lzma alias which supports only unpacking" 358 default y 359 depends on UNLZMA 360 help 361 Enable this option if you want commands like "lzma -d" to work. 362 IOW: you'll get lzma applet, but it will always require -d option. 363 364 config UNXZ 365 bool "unxz" 366 default y 367 help 368 unxz is a unlzma successor. 369 370 config XZ 371 bool "Provide xz alias which supports only unpacking" 372 default y 373 depends on UNXZ 374 help 375 Enable this option if you want commands like "xz -d" to work. 376 IOW: you'll get xz applet, but it will always require -d option. 377 378 config UNZIP 379 bool "unzip" 380 default y 381 help 382 unzip will list or extract files from a ZIP archive, 383 commonly found on DOS/WIN systems. The default behavior 384 (with no options) is to extract the archive into the 385 current directory. Use the `-d' option to extract to a 386 directory of your choice. 38 INSERT 387 39 388 40 endmenu -
branches/3.3/mindi-busybox/archival/Kbuild.src
r2725 r3621 5 5 # Licensed under GPLv2, see file LICENSE in this source tree. 6 6 7 libs-y 7 libs-y += libarchive/ 8 8 9 9 lib-y:= 10 10 11 11 INSERT 12 13 lib-$(CONFIG_AR) += ar.o14 lib-$(CONFIG_CPIO) += cpio.o15 lib-$(CONFIG_DPKG) += dpkg.o16 lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o17 lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o18 lib-$(CONFIG_RPM) += rpm.o19 lib-$(CONFIG_TAR) += tar.o20 lib-$(CONFIG_UNZIP) += unzip.o21 22 lib-$(CONFIG_LZOP) += lzop.o bbunzip.o23 lib-$(CONFIG_GZIP) += gzip.o bbunzip.o24 lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o25 26 lib-$(CONFIG_UNXZ) += bbunzip.o27 lib-$(CONFIG_UNLZMA) += bbunzip.o28 lib-$(CONFIG_BUNZIP2) += bbunzip.o29 lib-$(CONFIG_GUNZIP) += bbunzip.o30 lib-$(CONFIG_UNCOMPRESS) += bbunzip.o -
branches/3.3/mindi-busybox/archival/ar.c
r3232 r3621 17 17 * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html 18 18 */ 19 20 //config:config AR 21 //config: bool "ar" 22 //config: default n # needs to be improved to be able to replace binutils ar 23 //config: help 24 //config: ar is an archival utility program used to create, modify, and 25 //config: extract contents from archives. In practice, it is used exclusively 26 //config: for object module archives used by compilers. 27 //config: 28 //config: On an x86 system, the ar applet adds about 1K. 29 //config: 30 //config: Unless you have a specific application which requires ar, you should 31 //config: probably say N here: most compilers come with their own ar utility. 32 //config: 33 //config:config FEATURE_AR_LONG_FILENAMES 34 //config: bool "Support for long filenames (not needed for debs)" 35 //config: default y 36 //config: depends on AR 37 //config: help 38 //config: By default the ar format can only store the first 15 characters 39 //config: of the filename, this option removes that limitation. 40 //config: It supports the GNU ar long filename method which moves multiple long 41 //config: filenames into a the data section of a new ar entry. 42 //config: 43 //config:config FEATURE_AR_CREATE 44 //config: bool "Support archive creation" 45 //config: default y 46 //config: depends on AR 47 //config: help 48 //config: This enables archive creation (-c and -r) with busybox ar. 49 50 //applet:IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP)) 51 //kbuild:lib-$(CONFIG_AR) += ar.o 19 52 20 53 //usage:#define ar_trivial_usage -
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 -
branches/3.3/mindi-busybox/archival/bzip2.c
r3232 r3621 7 7 * about bzip2 library code. 8 8 */ 9 10 //config:config BZIP2 11 //config: bool "bzip2" 12 //config: default y 13 //config: help 14 //config: bzip2 is a compression utility using the Burrows-Wheeler block 15 //config: sorting text compression algorithm, and Huffman coding. Compression 16 //config: is generally considerably better than that achieved by more 17 //config: conventional LZ77/LZ78-based compressors, and approaches the 18 //config: performance of the PPM family of statistical compressors. 19 //config: 20 //config: Unless you have a specific application which requires bzip2, you 21 //config: should probably say N here. 22 23 //applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) 24 //kbuild:lib-$(CONFIG_BZIP2) += bzip2.o 9 25 10 26 //usage:#define bzip2_trivial_usage … … 112 128 113 129 static 114 IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_ aux_data_t *auxUNUSED_PARAM)130 IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM) 115 131 { 116 132 IF_DESKTOP(long long) int total; -
branches/3.3/mindi-busybox/archival/cpio.c
r3232 r3621 10 10 * Doesn't check CRC's 11 11 * Only supports new ASCII and CRC formats 12 *13 12 */ 14 13 #include "libbb.h" 14 #include "common_bufsiz.h" 15 15 #include "bb_archive.h" 16 16 17 //config:config CPIO 18 //config: bool "cpio" 19 //config: default y 20 //config: help 21 //config: cpio is an archival utility program used to create, modify, and 22 //config: extract contents from archives. 23 //config: cpio has 110 bytes of overheads for every stored file. 24 //config: 25 //config: This implementation of cpio can extract cpio archives created in the 26 //config: "newc" or "crc" format, it cannot create or modify them. 27 //config: 28 //config: Unless you have a specific application which requires cpio, you 29 //config: should probably say N here. 30 //config: 31 //config:config FEATURE_CPIO_O 32 //config: bool "Support for archive creation" 33 //config: default y 34 //config: depends on CPIO 35 //config: help 36 //config: This implementation of cpio can create cpio archives in the "newc" 37 //config: format only. 38 //config: 39 //config:config FEATURE_CPIO_P 40 //config: bool "Support for passthrough mode" 41 //config: default y 42 //config: depends on FEATURE_CPIO_O 43 //config: help 44 //config: Passthrough mode. Rarely used. 45 46 //applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) 47 //kbuild:lib-$(CONFIG_CPIO) += cpio.o 48 17 49 //usage:#define cpio_trivial_usage 18 //usage: "[-dmvu] [-F FILE] " IF_FEATURE_CPIO_O(" [-H newc]")50 //usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]") 19 51 //usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]") 20 52 //usage: " [EXTR_FILE]..." … … 35 67 //usage: "\n -p DIR Copy files to DIR" 36 68 //usage: ) 69 //usage: "\nOptions:" 37 70 //usage: "\n -d Make leading directories" 38 71 //usage: "\n -m Preserve mtime" … … 40 73 //usage: "\n -u Overwrite" 41 74 //usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file" 75 //usage: "\n -R USER[:GRP] Set owner of created files" 42 76 //usage: IF_FEATURE_CPIO_O( 43 77 //usage: "\n -H newc Archive format" … … 99 133 -L, --dereference Dereference symbolic links (copy the files 100 134 that they point to instead of copying the links) 101 -R, --owner=[USER][:.][GR OUP] Set owner of created files135 -R, --owner=[USER][:.][GRP] Set owner of created files 102 136 103 137 Options valid in --extract and --pass-through modes: … … 119 153 OPT_DEREF = (1 << 7), 120 154 OPT_FILE = (1 << 8), 121 OPTBIT_FILE = 8, 155 OPT_OWNER = (1 << 9), 156 OPTBIT_OWNER = 9, 122 157 IF_FEATURE_CPIO_O(OPTBIT_CREATE ,) 123 158 IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,) … … 132 167 }; 133 168 134 #define OPTION_STR "it0uvdmLF:" 169 #define OPTION_STR "it0uvdmLF:R:" 170 171 struct globals { 172 struct bb_uidgid_t owner_ugid; 173 } FIX_ALIASING; 174 #define G (*(struct globals*)bb_common_bufsiz1) 175 void BUG_cpio_globals_too_big(void); 176 #define INIT_G() do { \ 177 setup_common_bufsiz(); \ 178 G.owner_ugid.uid = -1L; \ 179 G.owner_ugid.gid = -1L; \ 180 } while (0) 135 181 136 182 #if ENABLE_FEATURE_CPIO_O … … 150 196 static NOINLINE int cpio_o(void) 151 197 { 152 static const char trailer[] ALIGN1 = "TRAILER!!!";153 198 struct name_s { 154 199 struct name_s *next; … … 191 236 bb_simple_perror_msg_and_die(name); 192 237 } 238 239 if (G.owner_ugid.uid != (uid_t)-1L) 240 st.st_uid = G.owner_ugid.uid; 241 if (G.owner_ugid.gid != (gid_t)-1L) 242 st.st_gid = G.owner_ugid.gid; 193 243 194 244 if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode))) … … 226 276 continue; 227 277 } 228 229 278 } else { /* line == NULL: EOF */ 230 279 next_link: … … 245 294 /* If no (more) hardlinks to output, 246 295 * output "trailer" entry */ 247 name = trailer;296 name = cpio_TRAILER; 248 297 /* st.st_size == 0 is a must, but for uniformity 249 298 * in the output, we zero out everything */ … … 293 342 294 343 if (!line) { 295 if (name != trailer)344 if (name != cpio_TRAILER) 296 345 goto next_link; 297 346 /* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */ … … 309 358 archive_handle_t *archive_handle; 310 359 char *cpio_filename; 360 char *cpio_owner; 311 361 IF_FEATURE_CPIO_O(const char *cpio_fmt = "";) 312 362 unsigned opt; … … 323 373 #endif 324 374 #endif 375 "owner\0" Required_argument "R" 325 376 "verbose\0" No_argument "v" 326 377 "quiet\0" No_argument "\xff" … … 329 380 #endif 330 381 382 INIT_G(); 331 383 archive_handle = init_handle(); 332 384 /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */ … … 339 391 340 392 #if !ENABLE_FEATURE_CPIO_O 341 opt = getopt32(argv, OPTION_STR, &cpio_filename); 393 opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner); 394 #else 395 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), 396 &cpio_filename, &cpio_owner, &cpio_fmt); 397 #endif 342 398 argv += optind; 399 if (opt & OPT_OWNER) { /* -R */ 400 parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner); 401 archive_handle->cpio__owner = G.owner_ugid; 402 } 403 #if !ENABLE_FEATURE_CPIO_O 343 404 if (opt & OPT_FILE) { /* -F */ 344 405 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO); 345 406 } 346 407 #else 347 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);348 argv += optind;349 408 if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */ 350 409 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO); -
branches/3.3/mindi-busybox/archival/dpkg.c
r3232 r3621 15 15 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 16 16 */ 17 18 17 /* 19 18 * known difference between busybox dpkg and the official dpkg that i don't … … 26 25 * bugs that need to be fixed 27 26 * - (unknown, please let me know when you find any) 28 *29 27 */ 28 29 //config:config DPKG 30 //config: bool "dpkg" 31 //config: default n 32 //config: select FEATURE_SEAMLESS_GZ 33 //config: help 34 //config: dpkg is a medium-level tool to install, build, remove and manage 35 //config: Debian packages. 36 //config: 37 //config: This implementation of dpkg has a number of limitations, 38 //config: you should use the official dpkg if possible. 39 40 //applet:IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP)) 41 //kbuild:lib-$(CONFIG_DPKG) += dpkg.o 30 42 31 43 //usage:#define dpkg_trivial_usage … … 1140 1152 if (root_of_alternatives) 1141 1153 bb_error_msg_and_die( 1142 "package %s %sdepends on %s, " 1143 "which cannot be satisfied", 1154 "package %s %sdepends on %s, which %s", 1144 1155 name_hashtable[package_node->name], 1145 1156 package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", 1146 name_hashtable[root_of_alternatives->name]); 1157 name_hashtable[root_of_alternatives->name], 1158 "cannot be satisfied"); 1147 1159 bb_error_msg_and_die( 1148 "package %s %sdepends on %s, which %s \n",1160 "package %s %sdepends on %s, which %s", 1149 1161 name_hashtable[package_node->name], 1150 1162 package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "", … … 1461 1473 1462 1474 /* We don't care about data.tar.* or debian-binary, just control.tar.* */ 1475 llist_add_to(&(ar_handle->accept), (char*)"control.tar"); 1463 1476 #if ENABLE_FEATURE_SEAMLESS_GZ 1464 1477 llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz"); … … 1467 1480 llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2"); 1468 1481 #endif 1482 #if ENABLE_FEATURE_SEAMLESS_XZ 1483 llist_add_to(&(ar_handle->accept), (char*)"control.tar.xz"); 1484 #endif 1469 1485 1470 1486 /* Assign the tar handle as a subarchive of the ar handle */ … … 1481 1497 1482 1498 /* We don't care about control.tar.* or debian-binary, just data.tar.* */ 1499 llist_add_to(&(ar_handle->accept), (char*)"data.tar"); 1483 1500 #if ENABLE_FEATURE_SEAMLESS_GZ 1484 1501 llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz"); … … 1486 1503 #if ENABLE_FEATURE_SEAMLESS_BZ2 1487 1504 llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2"); 1505 #endif 1506 #if ENABLE_FEATURE_SEAMLESS_LZMA 1507 llist_add_to(&(ar_handle->accept), (char*)"data.tar.lzma"); 1508 #endif 1509 #if ENABLE_FEATURE_SEAMLESS_XZ 1510 llist_add_to(&(ar_handle->accept), (char*)"data.tar.xz"); 1488 1511 #endif 1489 1512 -
branches/3.3/mindi-busybox/archival/dpkg_deb.c
r3232 r3621 6 6 */ 7 7 8 //config:config DPKG_DEB 9 //config: bool "dpkg_deb" 10 //config: default n 11 //config: select FEATURE_SEAMLESS_GZ 12 //config: help 13 //config: dpkg-deb unpacks and provides information about Debian archives. 14 //config: 15 //config: This implementation of dpkg-deb cannot pack archives. 16 //config: 17 //config: Unless you have a specific application which requires dpkg-deb, 18 //config: say N here. 19 //config: 20 //config:config FEATURE_DPKG_DEB_EXTRACT_ONLY 21 //config: bool "Extract only (-x)" 22 //config: default n 23 //config: depends on DPKG_DEB 24 //config: help 25 //config: This reduces dpkg-deb to the equivalent of 26 //config: "ar -p <deb> data.tar.gz | tar -zx". However it saves space as none 27 //config: of the extra dpkg-deb, ar or tar options are needed, they are linked 28 //config: to internally. 29 30 //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) 31 //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o 32 8 33 //usage:#define dpkg_deb_trivial_usage 9 //usage: "[-cefxX] FILE [argument "34 //usage: "[-cefxX] FILE [argument]" 10 35 //usage:#define dpkg_deb_full_usage "\n\n" 11 36 //usage: "Perform actions on Debian packages (.debs)\n" … … 46 71 ar_archive->filter = filter_accept_list_reassign; 47 72 73 llist_add_to(&ar_archive->accept, (char*)"data.tar"); 74 llist_add_to(&control_tar_llist, (char*)"control.tar"); 48 75 #if ENABLE_FEATURE_SEAMLESS_GZ 49 76 llist_add_to(&ar_archive->accept, (char*)"data.tar.gz"); … … 57 84 llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma"); 58 85 llist_add_to(&control_tar_llist, (char*)"control.tar.lzma"); 86 #endif 87 #if ENABLE_FEATURE_SEAMLESS_XZ 88 llist_add_to(&ar_archive->accept, (char*)"data.tar.xz"); 89 llist_add_to(&control_tar_llist, (char*)"control.tar.xz"); 59 90 #endif 60 91 -
branches/3.3/mindi-busybox/archival/gzip.c
r3232 r3621 16 16 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 17 17 */ 18 19 18 /* big objects in bss: 20 19 * 00000020 b bl_count … … 32 31 * 000008f4 b dyn_ltree 33 32 */ 34 35 33 /* TODO: full support for -v for DESKTOP 36 34 * "/usr/bin/gzip -v a bogus aa" should say: … … 40 38 */ 41 39 40 //config:config GZIP 41 //config: bool "gzip" 42 //config: default y 43 //config: help 44 //config: gzip is used to compress files. 45 //config: It's probably the most widely used UNIX compression program. 46 //config: 47 //config:config FEATURE_GZIP_LONG_OPTIONS 48 //config: bool "Enable long options" 49 //config: default y 50 //config: depends on GZIP && LONG_OPTS 51 //config: help 52 //config: Enable use of long options, increases size by about 106 Bytes 53 //config: 54 //config:config GZIP_FAST 55 //config: int "Trade memory for gzip speed (0:small,slow - 2:fast,big)" 56 //config: default 0 57 //config: range 0 2 58 //config: depends on GZIP 59 //config: help 60 //config: Enable big memory options for gzip. 61 //config: 0: small buffers, small hash-tables 62 //config: 1: larger buffers, larger hash-tables 63 //config: 2: larger buffers, largest hash-tables 64 //config: Larger models may give slightly better compression 65 //config: 66 //config:config FEATURE_GZIP_LEVELS 67 //config: bool "Enable compression levels" 68 //config: default n 69 //config: depends on GZIP 70 //config: help 71 //config: Enable support for compression levels 4-9. The default level 72 //config: is 6. If levels 1-3 are specified, 4 is used. 73 //config: If this option is not selected, -N options are ignored and -9 74 //config: is used. 75 76 //applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) 77 //kbuild:lib-$(CONFIG_GZIP) += gzip.o 78 42 79 //usage:#define gzip_trivial_usage 43 //usage: "[-cf d] [FILE]..."80 //usage: "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..." 44 81 //usage:#define gzip_full_usage "\n\n" 45 82 //usage: "Compress FILEs (or stdin)\n" 83 //usage: IF_FEATURE_GZIP_LEVELS( 84 //usage: "\n -1..9 Compression level" 85 //usage: ) 86 //usage: IF_GUNZIP( 46 87 //usage: "\n -d Decompress" 88 //usage: ) 47 89 //usage: "\n -c Write to stdout" 48 90 //usage: "\n -f Force" … … 226 268 */ 227 269 270 #ifndef ENABLE_FEATURE_GZIP_LEVELS 271 228 272 max_chain_length = 4096, 229 273 /* To speed up deflation, hash chains are never searched beyond this length. … … 257 301 * meaning. 258 302 */ 303 #endif /* ENABLE_FEATURE_GZIP_LEVELS */ 259 304 }; 260 305 261 306 262 307 struct globals { 308 309 #ifdef ENABLE_FEATURE_GZIP_LEVELS 310 unsigned max_chain_length; 311 unsigned max_lazy_match; 312 unsigned good_match; 313 unsigned nice_match; 314 #define max_chain_length (G1.max_chain_length) 315 #define max_lazy_match (G1.max_lazy_match) 316 #define good_match (G1.good_match) 317 #define nice_match (G1.nice_match) 318 #endif 263 319 264 320 lng block_start; … … 391 447 do { \ 392 448 G1.outbuf[G1.outcnt++] = (c); \ 393 if (G1.outcnt == OUTBUFSIZ) flush_outbuf(); \ 449 if (G1.outcnt == OUTBUFSIZ) \ 450 flush_outbuf(); \ 394 451 } while (0) 395 452 … … 397 454 static void put_16bit(ush w) 398 455 { 399 if (G1.outcnt < OUTBUFSIZ - 2) { 400 G1.outbuf[G1.outcnt++] = w; 401 G1.outbuf[G1.outcnt++] = w >> 8; 402 } else { 403 put_8bit(w); 404 put_8bit(w >> 8); 405 } 456 /* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt 457 * (probably because of fear of aliasing with G1.outbuf[] 458 * stores), do it explicitly: 459 */ 460 unsigned outcnt = G1.outcnt; 461 uch *dst = &G1.outbuf[outcnt]; 462 463 #if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN 464 if (outcnt < OUTBUFSIZ-2) { 465 /* Common case */ 466 ush *dst16 = (void*) dst; 467 *dst16 = w; /* unalinged LSB 16-bit store */ 468 G1.outcnt = outcnt + 2; 469 return; 470 } 471 *dst = (uch)w; 472 w >>= 8; 473 #else 474 *dst = (uch)w; 475 w >>= 8; 476 if (outcnt < OUTBUFSIZ-2) { 477 /* Common case */ 478 dst[1] = w; 479 G1.outcnt = outcnt + 2; 480 return; 481 } 482 #endif 483 484 /* Slowpath: we will need to do flush_outbuf() */ 485 G1.outcnt = ++outcnt; 486 if (outcnt == OUTBUFSIZ) 487 flush_outbuf(); 488 put_8bit(w); 406 489 } 407 490 … … 1292 1375 G2.heap[SMALLEST] = node++; 1293 1376 pqdownheap(tree, SMALLEST); 1294 1295 1377 } while (G2.heap_len >= 2); 1296 1378 … … 1640 1722 copy_block(buf, (unsigned) stored_len, 0); /* without header */ 1641 1723 G2.compressed_len = stored_len << 3; 1642 1643 1724 } else if (stored_len + 4 <= opt_lenb && buf != NULL) { 1644 1725 /* 4: two words for the lengths */ … … 1654 1735 1655 1736 copy_block(buf, (unsigned) stored_len, 1); /* with header */ 1656 1657 1737 } else if (static_lenb == opt_lenb) { 1658 1738 send_bits((STATIC_TREES << 1) + eof, 3); … … 1981 2061 */ 1982 2062 1983 static void zip( ulg time_stamp)2063 static void zip(void) 1984 2064 { 1985 2065 ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ … … 1992 2072 /* general flags: 0 */ 1993 2073 put_32bit(0x00088b1f); 1994 put_32bit( time_stamp);2074 put_32bit(0); /* Unix timestamp */ 1995 2075 1996 2076 /* Write deflated file to zip file */ … … 2016 2096 /* ======================================================================== */ 2017 2097 static 2018 IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM) 2019 { 2020 struct stat s; 2021 2098 IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM) 2099 { 2022 2100 /* Clear input and output buffers */ 2023 2101 G1.outcnt = 0; … … 2051 2129 //G2.bl_desc.max_code = 0; 2052 2130 2131 #if 0 2132 /* Saving of timestamp is disabled. Why? 2133 * - it is not Y2038-safe. 2134 * - some people want deterministic results 2135 * (normally they'd use -n, but our -n is a nop). 2136 * - it's bloat. 2137 * Per RFC 1952, gzfile.time=0 is "no timestamp". 2138 * If users will demand this to be reinstated, 2139 * implement -n "don't save timestamp". 2140 */ 2141 struct stat s; 2053 2142 s.st_ctime = 0; 2054 2143 fstat(STDIN_FILENO, &s); 2055 2144 zip(s.st_ctime); 2145 #else 2146 zip(); 2147 #endif 2056 2148 return 0; 2057 2149 } … … 2071 2163 "fast\0" No_argument "1" 2072 2164 "best\0" No_argument "9" 2165 "no-name\0" No_argument "n" 2073 2166 ; 2074 2167 #endif … … 2096 2189 { 2097 2190 unsigned opt; 2191 #ifdef ENABLE_FEATURE_GZIP_LEVELS 2192 static const struct { 2193 uint8_t good; 2194 uint8_t chain_shift; 2195 uint8_t lazy2; 2196 uint8_t nice2; 2197 } gzip_level_config[6] = { 2198 {4, 4, 4/2, 16/2}, /* Level 4 */ 2199 {8, 5, 16/2, 32/2}, /* Level 5 */ 2200 {8, 7, 16/2, 128/2}, /* Level 6 */ 2201 {8, 8, 32/2, 128/2}, /* Level 7 */ 2202 {32, 10, 128/2, 258/2}, /* Level 8 */ 2203 {32, 12, 258/2, 258/2}, /* Level 9 */ 2204 }; 2205 #endif 2206 2207 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) 2208 + sizeof(struct globals)); 2098 2209 2099 2210 #if ENABLE_FEATURE_GZIP_LONG_OPTIONS … … 2101 2212 #endif 2102 2213 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2103 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q 123456789n");2214 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789"); 2104 2215 #if ENABLE_GUNZIP /* gunzip_main may not be visible... */ 2105 2216 if (opt & 0x18) // -d and/or -t 2106 2217 return gunzip_main(argc, argv); 2107 2218 #endif 2108 option_mask32 &= 0x7; /* ignore -q, -0..9 */ 2109 //if (opt & 0x1) // -c 2110 //if (opt & 0x2) // -f 2111 //if (opt & 0x4) // -v 2112 argv += optind; 2113 2114 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) 2115 + sizeof(struct globals)); 2219 #ifdef ENABLE_FEATURE_GZIP_LEVELS 2220 opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */ 2221 if (opt == 0) 2222 opt = 1 << 6; /* default: 6 */ 2223 opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */ 2224 max_chain_length = 1 << gzip_level_config[opt].chain_shift; 2225 good_match = gzip_level_config[opt].good; 2226 max_lazy_match = gzip_level_config[opt].lazy2 * 2; 2227 nice_match = gzip_level_config[opt].nice2 * 2; 2228 #endif 2229 option_mask32 &= 0x7; /* retain only -cfv */ 2116 2230 2117 2231 /* Allocate all global buffers (for DYN_ALLOC option) */ … … 2125 2239 global_crc32_table = crc32_filltable(NULL, 0); 2126 2240 2241 argv += optind; 2127 2242 return bbunpack(argv, pack_gzip, append_ext, "gz"); 2128 2243 } -
branches/3.3/mindi-busybox/archival/libarchive/Kbuild.src
r3232 r3621 5 5 # Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 6 7 lib-y:= 7 lib-y:= common.o 8 8 9 9 COMMON_FILES:= \ … … 31 31 unpack_ar_archive.o \ 32 32 filter_accept_list_reassign.o \ 33 unsafe_prefix.o \ 33 34 get_header_ar.o \ 34 35 get_header_tar.o \ … … 36 37 get_header_tar_bz2.o \ 37 38 get_header_tar_lzma.o \ 39 get_header_tar_xz.o \ 38 40 39 41 INSERT 40 42 41 lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o42 lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o43 lib-$(CONFIG_UNLZMA) += decompress_unlzma.o44 lib-$(CONFIG_UNXZ) += decompress_unxz.o45 lib-$(CONFIG_CPIO) += get_header_cpio.o46 43 lib-$(CONFIG_DPKG) += $(DPKG_FILES) 47 44 lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) 48 lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o 49 lib-$(CONFIG_RPM2CPIO) += decompress_gunzip.o get_header_cpio.o 50 lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o 51 lib-$(CONFIG_TAR) += get_header_tar.o 52 lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o 53 lib-$(CONFIG_UNZIP) += decompress_gunzip.o 45 46 lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o 47 lib-$(CONFIG_CPIO) += get_header_cpio.o 48 lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o 49 lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o 54 50 lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o 55 51 lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o 52 lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o 53 lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o 54 lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o 55 lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o 56 lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o 57 lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o 58 lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o 59 lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o 60 61 lib-$(CONFIG_GZIP) += open_transformer.o 62 lib-$(CONFIG_BZIP2) += open_transformer.o 63 lib-$(CONFIG_LZOP) += open_transformer.o 64 lib-$(CONFIG_MAN) += open_transformer.o 65 lib-$(CONFIG_SETFONT) += open_transformer.o 66 lib-$(CONFIG_FEATURE_2_4_MODULES) += open_transformer.o 56 67 lib-$(CONFIG_MODINFO) += open_transformer.o 57 68 lib-$(CONFIG_INSMOD) += open_transformer.o 69 lib-$(CONFIG_DEPMOD) += open_transformer.o 70 lib-$(CONFIG_RMMOD) += open_transformer.o 71 lib-$(CONFIG_LSMOD) += open_transformer.o 72 lib-$(CONFIG_MODPROBE) += open_transformer.o 73 lib-$(CONFIG_MODPROBE_SMALL) += open_transformer.o 74 58 75 lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o 59 76 lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_gunzip.o … … 62 79 lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o 63 80 lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o 64 lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += decompress_bunzip2.o 65 lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o 81 lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o 66 82 67 83 ifneq ($(lib-y),) -
branches/3.3/mindi-busybox/archival/libarchive/bz/compress.c
r3232 r3621 250 250 void sendMTFValues(EState* s) 251 251 { 252 int32_t v, t, i, j, gs, ge, totc,bt, bc, iter;252 int32_t v, t, i, j, gs, ge, bt, bc, iter; 253 253 int32_t nSelectors, alphaSize, minLen, maxLen, selCtr; 254 254 int32_t nGroups; … … 346 346 #endif 347 347 nSelectors = 0; 348 totc = 0;349 348 gs = 0; 350 349 while (1) { … … 387 386 cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16; 388 387 cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16; 389 390 388 } else 391 389 #endif … … 412 410 } 413 411 } 414 totc += bc;415 412 fave[bt]++; 416 413 s->selector[nSelectors] = bt; … … 502 499 if (sizeof(long) <= 4) { 503 500 inUse16 = inUse16*2 + 504 ((*( uint32_t*)&(s->inUse[i * 16 + 0])505 | *( uint32_t*)&(s->inUse[i * 16 + 4])506 | *( uint32_t*)&(s->inUse[i * 16 + 8])507 | *( uint32_t*)&(s->inUse[i * 16 + 12])) != 0);501 ((*(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 0]) 502 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 4]) 503 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 8]) 504 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 12])) != 0); 508 505 } else { /* Our CPU can do better */ 509 506 inUse16 = inUse16*2 + 510 ((*( uint64_t*)&(s->inUse[i * 16 + 0])511 | *( uint64_t*)&(s->inUse[i * 16 + 8])) != 0);507 ((*(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 0]) 508 | *(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 8])) != 0); 512 509 } 513 510 } -
branches/3.3/mindi-busybox/archival/libarchive/data_extract_all.c
r3232 r3621 12 12 int dst_fd; 13 13 int res; 14 char *hard_link; 15 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 16 char *dst_name; 17 #else 18 # define dst_name (file_header->name) 19 #endif 14 20 15 21 #if ENABLE_FEATURE_TAR_SELINUX … … 24 30 #endif 25 31 32 /* Hard links are encoded as regular files of size 0 33 * with a nonempty link field */ 34 hard_link = NULL; 35 if (S_ISREG(file_header->mode) && file_header->size == 0) 36 hard_link = file_header->link_target; 37 38 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 39 dst_name = file_header->name; 40 if (archive_handle->tar__strip_components) { 41 unsigned n = archive_handle->tar__strip_components; 42 do { 43 dst_name = strchr(dst_name, '/'); 44 if (!dst_name || dst_name[1] == '\0') { 45 data_skip(archive_handle); 46 goto ret; 47 } 48 dst_name++; 49 /* 50 * Link target is shortened only for hardlinks: 51 * softlinks restored unchanged. 52 */ 53 if (hard_link) { 54 // GNU tar 1.26 does not check that we reached end of link name: 55 // if "dir/hardlink" is hardlinked to "file", 56 // tar xvf a.tar --strip-components=1 says: 57 // tar: hardlink: Cannot hard link to '': No such file or directory 58 // and continues processing. We silently skip such entries. 59 hard_link = strchr(hard_link, '/'); 60 if (!hard_link || hard_link[1] == '\0') { 61 data_skip(archive_handle); 62 goto ret; 63 } 64 hard_link++; 65 } 66 } while (--n != 0); 67 } 68 #endif 69 26 70 if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) { 27 char *slash = strrchr( file_header->name, '/');71 char *slash = strrchr(dst_name, '/'); 28 72 if (slash) { 29 73 *slash = '\0'; 30 bb_make_directory( file_header->name, -1, FILEUTILS_RECUR);74 bb_make_directory(dst_name, -1, FILEUTILS_RECUR); 31 75 *slash = '/'; 32 76 } … … 36 80 /* Remove the entry if it exists */ 37 81 if (!S_ISDIR(file_header->mode)) { 38 /* Is it hardlink? 39 * We encode hard links as regular files of size 0 with a symlink */ 40 if (S_ISREG(file_header->mode) 41 && file_header->link_target 42 && file_header->size == 0 43 ) { 82 if (hard_link) { 44 83 /* Ugly special case: 45 84 * tar cf t.tar hardlink1 hardlink2 hardlink1 … … 49 88 * hardlink1 -> hardlink1 <== !!! 50 89 */ 51 if (strcmp( file_header->link_target, file_header->name) == 0)90 if (strcmp(hard_link, dst_name) == 0) 52 91 goto ret; 53 92 } 54 93 /* Proceed with deleting */ 55 if (unlink( file_header->name) == -194 if (unlink(dst_name) == -1 56 95 && errno != ENOENT 57 96 ) { 58 97 bb_perror_msg_and_die("can't remove old file %s", 59 file_header->name);98 dst_name); 60 99 } 61 100 } … … 64 103 /* Remove the existing entry if its older than the extracted entry */ 65 104 struct stat existing_sb; 66 if (lstat( file_header->name, &existing_sb) == -1) {105 if (lstat(dst_name, &existing_sb) == -1) { 67 106 if (errno != ENOENT) { 68 107 bb_perror_msg_and_die("can't stat old file"); … … 74 113 ) { 75 114 bb_error_msg("%s not created: newer or " 76 "same age file exists", file_header->name);115 "same age file exists", dst_name); 77 116 } 78 117 data_skip(archive_handle); 79 118 goto ret; 80 119 } 81 else if ((unlink( file_header->name) == -1) && (errno != EISDIR)) {120 else if ((unlink(dst_name) == -1) && (errno != EISDIR)) { 82 121 bb_perror_msg_and_die("can't remove old file %s", 83 file_header->name); 84 } 85 } 86 87 /* Handle hard links separately 88 * We encode hard links as regular files of size 0 with a symlink */ 89 if (S_ISREG(file_header->mode) 90 && file_header->link_target 91 && file_header->size == 0 92 ) { 93 /* hard link */ 94 res = link(file_header->link_target, file_header->name); 95 if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) { 122 dst_name); 123 } 124 } 125 126 /* Handle hard links separately */ 127 if (hard_link) { 128 res = link(hard_link, dst_name); 129 if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) { 96 130 bb_perror_msg("can't create %slink " 97 131 "from %s to %s", "hard", 98 file_header->name,99 file_header->link_target);132 dst_name, 133 hard_link); 100 134 } 101 135 /* Hardlinks have no separate mode/ownership, skip chown/chmod */ … … 107 141 case S_IFREG: { 108 142 /* Regular file */ 143 char *dst_nameN; 109 144 int flags = O_WRONLY | O_CREAT | O_EXCL; 110 145 if (archive_handle->ah_flags & ARCHIVE_O_TRUNC) 111 146 flags = O_WRONLY | O_CREAT | O_TRUNC; 112 dst_fd = xopen3(file_header->name, 147 dst_nameN = dst_name; 148 #ifdef ARCHIVE_REPLACE_VIA_RENAME 149 if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) 150 /* rpm-style temp file name */ 151 dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid()); 152 #endif 153 dst_fd = xopen3(dst_nameN, 113 154 flags, 114 155 file_header->mode … … 116 157 bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size); 117 158 close(dst_fd); 159 #ifdef ARCHIVE_REPLACE_VIA_RENAME 160 if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) { 161 xrename(dst_nameN, dst_name); 162 free(dst_nameN); 163 } 164 #endif 118 165 break; 119 166 } 120 167 case S_IFDIR: 121 res = mkdir( file_header->name, file_header->mode);168 res = mkdir(dst_name, file_header->mode); 122 169 if ((res == -1) 123 170 && (errno != EISDIR) /* btw, Linux doesn't return this */ … … 125 172 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) 126 173 ) { 127 bb_perror_msg("can't make dir %s", file_header->name);174 bb_perror_msg("can't make dir %s", dst_name); 128 175 } 129 176 break; … … 131 178 /* Symlink */ 132 179 //TODO: what if file_header->link_target == NULL (say, corrupted tarball?) 133 res = symlink(file_header->link_target, file_header->name);134 if ( (res == -1)180 res = symlink(file_header->link_target, dst_name); 181 if (res != 0 135 182 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) 136 183 ) { 137 184 bb_perror_msg("can't create %slink " 138 185 "from %s to %s", "sym", 139 file_header->name,186 dst_name, 140 187 file_header->link_target); 141 188 } … … 145 192 case S_IFCHR: 146 193 case S_IFIFO: 147 res = mknod( file_header->name, file_header->mode, file_header->device);194 res = mknod(dst_name, file_header->mode, file_header->device); 148 195 if ((res == -1) 149 196 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) 150 197 ) { 151 bb_perror_msg("can't create node %s", file_header->name);198 bb_perror_msg("can't create node %s", dst_name); 152 199 } 153 200 break; … … 174 221 #endif 175 222 /* GNU tar 1.15.1 uses chown, not lchown */ 176 chown( file_header->name, uid, gid);223 chown(dst_name, uid, gid); 177 224 } 178 225 /* uclibc has no lchmod, glibc is even stranger - … … 180 227 * so we use chmod... */ 181 228 if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) { 182 chmod( file_header->name, file_header->mode);229 chmod(dst_name, file_header->mode); 183 230 } 184 231 if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) { … … 187 234 t[1].tv_sec = t[0].tv_sec = file_header->mtime; 188 235 t[1].tv_usec = t[0].tv_usec = 0; 189 utimes( file_header->name, t);236 utimes(dst_name, t); 190 237 } 191 238 } -
branches/3.3/mindi-busybox/archival/libarchive/data_extract_to_command.c
r3232 r3621 104 104 "-c", 105 105 archive_handle->tar__to_command, 106 NULL);106 (char *)0); 107 107 bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell); 108 108 } … … 113 113 close(p[1]); 114 114 115 if (safe_waitpid(pid, &status, 0) == -1) 116 bb_perror_msg_and_die("waitpid"); 115 status = wait_for_exitstatus(pid); 117 116 if (WIFEXITED(status) && WEXITSTATUS(status)) 118 117 bb_error_msg_and_die("'%s' returned status %d", 119 118 archive_handle->tar__to_command, WEXITSTATUS(status)); 120 119 if (WIFSIGNALED(status)) 121 bb_error_msg_and_die("'%s' terminated onsignal %d",120 bb_error_msg_and_die("'%s' terminated by signal %d", 122 121 archive_handle->tar__to_command, WTERMSIG(status)); 123 122 -
branches/3.3/mindi-busybox/archival/libarchive/decompress_bunzip2.c
r3232 r3621 43 43 #include "bb_archive.h" 44 44 45 #if 0 46 # define dbg(...) bb_error_msg(__VA_ARGS__) 47 #else 48 # define dbg(...) ((void)0) 49 #endif 50 45 51 /* Constants for Huffman coding */ 46 52 #define MAX_GROUPS 6 … … 53 59 /* Status return values */ 54 60 #define RETVAL_OK 0 55 #define RETVAL_LAST_BLOCK ( -1)56 #define RETVAL_NOT_BZIP_DATA ( -2)57 #define RETVAL_UNEXPECTED_INPUT_EOF ( -3)58 #define RETVAL_SHORT_WRITE ( -4)59 #define RETVAL_DATA_ERROR ( -5)60 #define RETVAL_OUT_OF_MEMORY ( -6)61 #define RETVAL_OBSOLETE_INPUT ( -7)61 #define RETVAL_LAST_BLOCK (dbg("%d", __LINE__), -1) 62 #define RETVAL_NOT_BZIP_DATA (dbg("%d", __LINE__), -2) 63 #define RETVAL_UNEXPECTED_INPUT_EOF (dbg("%d", __LINE__), -3) 64 #define RETVAL_SHORT_WRITE (dbg("%d", __LINE__), -4) 65 #define RETVAL_DATA_ERROR (dbg("%d", __LINE__), -5) 66 #define RETVAL_OUT_OF_MEMORY (dbg("%d", __LINE__), -6) 67 #define RETVAL_OBSOLETE_INPUT (dbg("%d", __LINE__), -7) 62 68 63 69 /* Other housekeeping constants */ … … 441 447 if (runPos != 0) { 442 448 uint8_t tmp_byte; 443 if (dbufCount + runCnt >= dbufSize) return RETVAL_DATA_ERROR; 449 if (dbufCount + runCnt > dbufSize) { 450 dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR", 451 dbufCount, runCnt, dbufCount + runCnt, dbufSize); 452 return RETVAL_DATA_ERROR; 453 } 444 454 tmp_byte = symToByte[mtfSymbol[0]]; 445 455 byteCount[tmp_byte] += runCnt; … … 722 732 /* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */ 723 733 IF_DESKTOP(long long) int FAST_FUNC 724 unpack_bz2_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)734 unpack_bz2_stream(transformer_state_t *xstate) 725 735 { 726 736 IF_DESKTOP(long long total_written = 0;) … … 730 740 unsigned len; 731 741 732 if (check_signature16( aux, src_fd, BZIP2_MAGIC))742 if (check_signature16(xstate, BZIP2_MAGIC)) 733 743 return -1; 734 744 … … 737 747 while (1) { /* "Process one BZ... stream" loop */ 738 748 739 i = start_bunzip(&bd, src_fd, outbuf + 2, len);749 i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len); 740 750 741 751 if (i == 0) { … … 747 757 if (i == 0) /* EOF? */ 748 758 break; 749 if (i != full_write(dst_fd, outbuf, i)) { 750 bb_error_msg("short write"); 759 if (i != transformer_write(xstate, outbuf, i)) { 751 760 i = RETVAL_SHORT_WRITE; 752 761 goto release_mem; … … 781 790 memcpy(outbuf, &bd->inbuf[bd->inbufPos], len); 782 791 if (len < 2) { 783 if (safe_read( src_fd, outbuf + len, 2 - len) != 2 - len)792 if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len) 784 793 break; 785 794 len = 2; … … 809 818 int main(int argc, char **argv) 810 819 { 811 int i;812 820 char c; 813 821 -
branches/3.3/mindi-busybox/archival/libarchive/decompress_gunzip.c
r3233 r3621 306 306 unsigned j; /* counter */ 307 307 int k; /* number of bits in current code */ 308 unsigned *p;/* pointer into c[], b[], or v[] */308 const unsigned *p; /* pointer into c[], b[], or v[] */ 309 309 huft_t *q; /* points to current table */ 310 310 huft_t r; /* table entry for structure assignment */ 311 311 huft_t *u[BMAX]; /* table stack */ 312 unsigned v[N_MAX ]; /* values in order of bit length*/312 unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */ 313 313 int ws[BMAX + 1]; /* bits decoded stack */ 314 314 int w; /* bits decoded */ … … 325 325 /* Generate counts for each bit length */ 326 326 memset(c, 0, sizeof(c)); 327 p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */327 p = b; 328 328 i = n; 329 329 do { … … 337 337 338 338 /* Find minimum and maximum length, bound *m by those */ 339 for (j = 1; ( c[j] == 0) && (j <= BMAX); j++)339 for (j = 1; (j <= BMAX) && (c[j] == 0); j++) 340 340 continue; 341 341 k = j; /* minimum code length */ … … 365 365 } 366 366 367 /* Make a table of values in order of bit lengths */ 368 p = (unsigned *) b; 367 /* Make a table of values in order of bit lengths. 368 * To detect bad input, unused v[i]'s are set to invalid value UINT_MAX. 369 * In particular, last v[i] is never filled and must not be accessed. 370 */ 371 memset(v, 0xff, sizeof(v)); 372 p = b; 369 373 i = 0; 370 374 do { … … 433 437 /* set up table entry in r */ 434 438 r.b = (unsigned char) (k - w); 435 if (p >= v + n) { 439 if (/*p >= v + n || -- redundant, caught by the second check: */ 440 *p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/ 441 ) { 436 442 r.e = 99; /* out of values--invalid code */ 437 443 } else if (*p < s) { … … 518 524 if (e > 16) 519 525 do { 520 if (e == 99) 521 abort_unzip(PASS_STATE_ONLY);; 526 if (e == 99) { 527 abort_unzip(PASS_STATE_ONLY); 528 } 522 529 bb >>= t->b; 523 530 k -= t->b; … … 555 562 if (e > 16) 556 563 do { 557 if (e == 99) 564 if (e == 99) { 558 565 abort_unzip(PASS_STATE_ONLY); 566 } 559 567 bb >>= t->b; 560 568 k -= t->b; … … 822 830 b_dynamic >>= 4; 823 831 k_dynamic -= 4; 824 if (nl > 286 || nd > 30) 832 if (nl > 286 || nd > 30) { 825 833 abort_unzip(PASS_STATE_ONLY); /* bad lengths */ 834 } 826 835 827 836 /* read in bit-length-code lengths */ … … 904 913 905 914 i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl); 906 if (i != 0) 915 if (i != 0) { 907 916 abort_unzip(PASS_STATE_ONLY); 917 } 908 918 bd = dbits; 909 919 i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd); 910 if (i != 0) 920 if (i != 0) { 911 921 abort_unzip(PASS_STATE_ONLY); 922 } 912 923 913 924 /* set up data for inflate_codes() */ … … 972 983 /* Called from unpack_gz_stream() and inflate_unzip() */ 973 984 static IF_DESKTOP(long long) int 974 inflate_unzip_internal(STATE_PARAM int in, int out)985 inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate) 975 986 { 976 987 IF_DESKTOP(long long) int n = 0; … … 981 992 gunzip_outbuf_count = 0; 982 993 gunzip_bytes_out = 0; 983 gunzip_src_fd = in;994 gunzip_src_fd = xstate->src_fd; 984 995 985 996 /* (re) initialize state */ … … 997 1008 if (setjmp(error_jmp)) { 998 1009 /* Error from deep inside zip machinery */ 1010 bb_error_msg(error_msg); 999 1011 n = -1; 1000 1012 goto ret; … … 1003 1015 while (1) { 1004 1016 int r = inflate_get_next_window(PASS_STATE_ONLY); 1005 nwrote = full_write(out, gunzip_window, gunzip_outbuf_count); 1006 if (nwrote != (ssize_t)gunzip_outbuf_count) { 1007 bb_perror_msg("write"); 1017 nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count); 1018 if (nwrote == (ssize_t)-1) { 1008 1019 n = -1; 1009 1020 goto ret; … … 1035 1046 1036 1047 IF_DESKTOP(long long) int FAST_FUNC 1037 inflate_unzip(transformer_ aux_data_t *aux, int in, int out)1048 inflate_unzip(transformer_state_t *xstate) 1038 1049 { 1039 1050 IF_DESKTOP(long long) int n; … … 1042 1053 ALLOC_STATE; 1043 1054 1044 to_read = aux->bytes_in;1055 to_read = xstate->bytes_in; 1045 1056 // bytebuffer_max = 0x8000; 1046 1057 bytebuffer_offset = 4; 1047 1058 bytebuffer = xmalloc(bytebuffer_max); 1048 n = inflate_unzip_internal(PASS_STATE in, out);1059 n = inflate_unzip_internal(PASS_STATE xstate); 1049 1060 free(bytebuffer); 1050 1061 1051 aux->crc32 = gunzip_crc;1052 aux->bytes_out = gunzip_bytes_out;1062 xstate->crc32 = gunzip_crc; 1063 xstate->bytes_out = gunzip_bytes_out; 1053 1064 DEALLOC_STATE; 1054 1065 return n; … … 1108 1119 } 1109 1120 1110 static int check_header_gzip(STATE_PARAM transformer_ aux_data_t *aux)1121 static int check_header_gzip(STATE_PARAM transformer_state_t *xstate) 1111 1122 { 1112 1123 union { … … 1120 1131 } PACKED formatted; 1121 1132 } header; 1122 struct BUG_header { 1123 char BUG_header[sizeof(header) == 8 ? 1 : -1]; 1124 }; 1133 1134 BUILD_BUG_ON(sizeof(header) != 8); 1125 1135 1126 1136 /* … … 1170 1180 } 1171 1181 1172 if (aux) 1173 aux->mtime = SWAP_LE32(header.formatted.mtime); 1182 xstate->mtime = SWAP_LE32(header.formatted.mtime); 1174 1183 1175 1184 /* Read the header checksum */ … … 1183 1192 1184 1193 IF_DESKTOP(long long) int FAST_FUNC 1185 unpack_gz_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)1194 unpack_gz_stream(transformer_state_t *xstate) 1186 1195 { 1187 1196 uint32_t v32; … … 1190 1199 1191 1200 #if !ENABLE_FEATURE_SEAMLESS_Z 1192 if (check_signature16( aux, src_fd, GZIP_MAGIC))1201 if (check_signature16(xstate, GZIP_MAGIC)) 1193 1202 return -1; 1194 1203 #else 1195 if ( aux && aux->check_signature) {1204 if (!xstate->signature_skipped) { 1196 1205 uint16_t magic2; 1197 1206 1198 if (full_read( src_fd, &magic2, 2) != 2) {1207 if (full_read(xstate->src_fd, &magic2, 2) != 2) { 1199 1208 bad_magic: 1200 1209 bb_error_msg("invalid magic"); … … 1202 1211 } 1203 1212 if (magic2 == COMPRESS_MAGIC) { 1204 aux->check_signature = 0;1205 return unpack_Z_stream( aux, src_fd, dst_fd);1213 xstate->signature_skipped = 2; 1214 return unpack_Z_stream(xstate); 1206 1215 } 1207 1216 if (magic2 != GZIP_MAGIC) … … 1216 1225 // bytebuffer_max = 0x8000; 1217 1226 bytebuffer = xmalloc(bytebuffer_max); 1218 gunzip_src_fd = src_fd;1227 gunzip_src_fd = xstate->src_fd; 1219 1228 1220 1229 again: 1221 if (!check_header_gzip(PASS_STATE aux)) {1230 if (!check_header_gzip(PASS_STATE xstate)) { 1222 1231 bb_error_msg("corrupted data"); 1223 1232 total = -1; … … 1225 1234 } 1226 1235 1227 n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);1236 n = inflate_unzip_internal(PASS_STATE xstate); 1228 1237 if (n < 0) { 1229 1238 total = -1; -
branches/3.3/mindi-busybox/archival/libarchive/decompress_uncompress.c
r3232 r3621 74 74 75 75 IF_DESKTOP(long long) int FAST_FUNC 76 unpack_Z_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)76 unpack_Z_stream(transformer_state_t *xstate) 77 77 { 78 78 IF_DESKTOP(long long total_written = 0;) … … 103 103 int block_mode; /* = BLOCK_MODE; */ 104 104 105 if (check_signature16( aux, src_fd, COMPRESS_MAGIC))105 if (check_signature16(xstate, COMPRESS_MAGIC)) 106 106 return -1; 107 107 … … 115 115 /* xread isn't good here, we have to return - caller may want 116 116 * to do some cleanup (e.g. delete incomplete unpacked file etc) */ 117 if (full_read( src_fd, inbuf, 1) != 1) {117 if (full_read(xstate->src_fd, inbuf, 1) != 1) { 118 118 bb_error_msg("short read"); 119 119 goto err; … … 167 167 168 168 if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) { 169 rsize = safe_read( src_fd, inbuf + insize, IBUFSIZ);169 rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ); 170 170 if (rsize < 0) 171 171 bb_error_msg_and_die(bb_msg_read_error); … … 275 275 276 276 if (outpos >= OBUFSIZ) { 277 x write(dst_fd, outbuf, outpos);277 xtransformer_write(xstate, outbuf, outpos); 278 278 IF_DESKTOP(total_written += outpos;) 279 279 outpos = 0; … … 298 298 oldcode = incode; 299 299 } 300 301 300 } while (rsize > 0); 302 301 303 302 if (outpos > 0) { 304 x write(dst_fd, outbuf, outpos);303 xtransformer_write(xstate, outbuf, outpos); 305 304 IF_DESKTOP(total_written += outpos;) 306 305 } -
branches/3.3/mindi-busybox/archival/libarchive/decompress_unlzma.c
r3232 r3621 46 46 47 47 48 /* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */49 static size_inlinevoid rc_read(rc_t *rc)48 /* Called once in rc_do_normalize() */ 49 static void rc_read(rc_t *rc) 50 50 { 51 51 int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE); … … 54 54 if (buffer_size <= 0) 55 55 bb_error_msg_and_die("unexpected EOF"); 56 rc->buffer_end = RC_BUFFER + buffer_size; 56 57 rc->ptr = RC_BUFFER; 57 rc->buffer_end = RC_BUFFER + buffer_size;58 58 } 59 59 … … 66 66 rc->code = (rc->code << 8) | *rc->ptr++; 67 67 } 68 static ALWAYS_INLINE void rc_normalize(rc_t *rc) 69 { 70 if (rc->range < (1 << RC_TOP_BITS)) { 71 rc_do_normalize(rc); 72 } 73 } 68 74 69 75 /* Called once */ … … 79 85 80 86 for (i = 0; i < 5; i++) { 81 #if ENABLE_FEATURE_LZMA_FAST82 if (rc->ptr >= rc->buffer_end)83 rc_read(rc);84 rc->code = (rc->code << 8) | *rc->ptr++;85 #else86 87 rc_do_normalize(rc); 87 #endif 88 } 89 rc->range = 0xFFFFFFFF; 88 } 89 rc->range = 0xffffffff; 90 90 return rc; 91 91 } … … 95 95 { 96 96 free(rc); 97 }98 99 static ALWAYS_INLINE void rc_normalize(rc_t *rc)100 {101 if (rc->range < (1 << RC_TOP_BITS)) {102 rc_do_normalize(rc);103 }104 97 } 105 98 … … 121 114 122 115 /* Called 4 times in unlzma loop */ 123 static speed_inlineint rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)116 static ALWAYS_INLINE int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol) 124 117 { 125 118 int ret = rc_is_bit_1(rc, p); … … 214 207 215 208 IF_DESKTOP(long long) int FAST_FUNC 216 unpack_lzma_stream(transformer_ aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)209 unpack_lzma_stream(transformer_state_t *xstate) 217 210 { 218 211 IF_DESKTOP(long long total_written = 0;) … … 222 215 uint32_t literal_pos_mask; 223 216 uint16_t *p; 224 int num_bits;225 int num_probs;226 217 rc_t *rc; 227 218 int i; … … 233 224 uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; 234 225 235 if (full_read( src_fd, &header, sizeof(header)) != sizeof(header)226 if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header) 236 227 || header.pos >= (9 * 5 * 5) 237 228 ) { … … 247 238 literal_pos_mask = (1 << lp) - 1; 248 239 240 /* Example values from linux-3.3.4.tar.lzma: 241 * dict_size: 64M, dst_size: 2^64-1 242 */ 249 243 header.dict_size = SWAP_LE32(header.dict_size); 250 244 header.dst_size = SWAP_LE64(header.dst_size); … … 255 249 buffer = xmalloc(MIN(header.dst_size, header.dict_size)); 256 250 257 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 258 p = xmalloc(num_probs * sizeof(*p)); 259 num_probs += LZMA_LITERAL - LZMA_BASE_SIZE; 260 for (i = 0; i < num_probs; i++) 261 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; 262 263 rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */ 251 { 252 int num_probs; 253 254 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 255 p = xmalloc(num_probs * sizeof(*p)); 256 num_probs += LZMA_LITERAL - LZMA_BASE_SIZE; 257 for (i = 0; i < num_probs; i++) 258 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; 259 } 260 261 rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */ 264 262 265 263 while (global_pos + buffer_pos < header.dst_size) { … … 309 307 buffer_pos = 0; 310 308 global_pos += header.dict_size; 311 if ( full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)309 if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size) 312 310 goto bad; 313 311 IF_DESKTOP(total_written += header.dict_size;) … … 318 316 #endif 319 317 } else { 318 int num_bits; 320 319 int offset; 321 320 uint16_t *prob2; … … 442 441 buffer_pos = 0; 443 442 global_pos += header.dict_size; 444 if ( full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)443 if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size) 445 444 goto bad; 446 445 IF_DESKTOP(total_written += header.dict_size;) … … 448 447 len--; 449 448 } while (len != 0 && buffer_pos < header.dst_size); 449 /* FIXME: ...........^^^^^ 450 * shouldn't it be "global_pos + buffer_pos < header.dst_size"? 451 */ 450 452 } 451 453 } … … 454 456 IF_NOT_DESKTOP(int total_written = 0; /* success */) 455 457 IF_DESKTOP(total_written += buffer_pos;) 456 if ( full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {458 if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) { 457 459 bad: 458 460 total_written = -1; /* failure */ -
branches/3.3/mindi-busybox/archival/libarchive/decompress_unxz.c
r3232 r3621 39 39 40 40 IF_DESKTOP(long long) int FAST_FUNC 41 unpack_xz_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)41 unpack_xz_stream(transformer_state_t *xstate) 42 42 { 43 43 enum xz_ret xz_result; … … 56 56 iobuf.out_size = BUFSIZ; 57 57 58 if (! aux || aux->check_signature == 0) {58 if (!xstate || xstate->signature_skipped) { 59 59 /* Preload XZ file signature */ 60 60 strcpy((char*)membuf, HEADER_MAGIC); … … 68 68 while (1) { 69 69 if (iobuf.in_pos == iobuf.in_size) { 70 int rd = safe_read( src_fd, membuf, BUFSIZ);70 int rd = safe_read(xstate->src_fd, membuf, BUFSIZ); 71 71 if (rd < 0) { 72 72 bb_error_msg(bb_msg_read_error); … … 105 105 // iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result); 106 106 if (iobuf.out_pos) { 107 x write(dst_fd, iobuf.out, iobuf.out_pos);107 xtransformer_write(xstate, iobuf.out, iobuf.out_pos); 108 108 IF_DESKTOP(total += iobuf.out_pos;) 109 109 iobuf.out_pos = 0; -
branches/3.3/mindi-busybox/archival/libarchive/filter_accept_list_reassign.c
r3232 r3621 29 29 30 30 /* Modify the subarchive handler based on the extension */ 31 if (strcmp(name_ptr, "tar") == 0) { 32 archive_handle->dpkg__action_data_subarchive = get_header_tar; 33 return EXIT_SUCCESS; 34 } 31 35 if (ENABLE_FEATURE_SEAMLESS_GZ 32 36 && strcmp(name_ptr, "gz") == 0 … … 47 51 return EXIT_SUCCESS; 48 52 } 53 if (ENABLE_FEATURE_SEAMLESS_XZ 54 && strcmp(name_ptr, "xz") == 0 55 ) { 56 archive_handle->dpkg__action_data_subarchive = get_header_tar_xz; 57 return EXIT_SUCCESS; 58 } 49 59 } 50 60 return EXIT_FAILURE; -
branches/3.3/mindi-busybox/archival/libarchive/get_header_ar.c
r3232 r3621 9 9 #include "ar.h" 10 10 11 static unsigned read_num(const char *str, int base) 11 /* WARNING: Clobbers str[len], so fields must be read in reverse order! */ 12 static unsigned read_num(char *str, int base, int len) 12 13 { 14 int err; 15 16 /* ar fields are fixed length text strings (padded with spaces). 17 * Ensure bb_strtou doesn't read past the field in case the full 18 * width is used. */ 19 str[len] = 0; 20 13 21 /* This code works because 14 22 * on misformatted numbers bb_strtou returns all-ones */ 15 interr = bb_strtou(str, NULL, base);23 err = bb_strtou(str, NULL, base); 16 24 if (err == -1) 17 25 bb_error_msg_and_die("invalid ar header"); … … 52 60 bb_error_msg_and_die("invalid ar header"); 53 61 54 /* FIXME: more thorough routine would be in order here 55 * (we have something like that in tar) 56 * but for now we are lax. */ 57 ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */ 58 typed->size = size = read_num(ar.formatted.size, 10); 62 /* 63 * Note that the fields MUST be read in reverse order as 64 * read_num() clobbers the next byte after the field! 65 * Order is: name, date, uid, gid, mode, size, magic. 66 */ 67 typed->size = size = read_num(ar.formatted.size, 10, 68 sizeof(ar.formatted.size)); 59 69 60 70 /* special filenames have '/' as the first character */ … … 88 98 * after dealing with long filename pseudo file. 89 99 */ 90 typed->mode = read_num(ar.formatted.mode, 8 );91 typed-> mtime = read_num(ar.formatted.date, 10);92 typed->uid = read_num(ar.formatted.uid, 10 );93 typed-> gid = read_num(ar.formatted.gid, 10);100 typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)); 101 typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid)); 102 typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid)); 103 typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date)); 94 104 95 105 #if ENABLE_FEATURE_AR_LONG_FILENAMES … … 99 109 /* The number after the '/' indicates the offset in the ar data section 100 110 * (saved in ar_long_names) that conatains the real filename */ 101 long_offset = read_num(&ar.formatted.name[1], 10); 111 long_offset = read_num(&ar.formatted.name[1], 10, 112 sizeof(ar.formatted.name) - 1); 102 113 if (long_offset >= ar_long_name_size) { 103 114 bb_error_msg_and_die("can't resolve long filename"); -
branches/3.3/mindi-busybox/archival/libarchive/get_header_cpio.c
r3232 r3621 38 38 archive_handle->offset += 110; 39 39 40 if ( strncmp(&cpio_header[0], "07070", 5) != 040 if (!is_prefixed_with(&cpio_header[0], "07070") 41 41 || (cpio_header[5] != '1' && cpio_header[5] != '2') 42 42 ) { … … 53 53 bb_error_msg_and_die("damaged cpio file"); 54 54 file_header->mode = mode; 55 /* "cpio -R USER:GRP" support: */ 56 if (archive_handle->cpio__owner.uid != (uid_t)-1L) 57 uid = archive_handle->cpio__owner.uid; 58 if (archive_handle->cpio__owner.gid != (gid_t)-1L) 59 gid = archive_handle->cpio__owner.gid; 55 60 file_header->uid = uid; 56 61 file_header->gid = gid; … … 76 81 data_align(archive_handle, 4); 77 82 78 if (strcmp(file_header->name, "TRAILER!!!") == 0) {83 if (strcmp(file_header->name, cpio_TRAILER) == 0) { 79 84 /* Always round up. ">> 9" divides by 512 */ 80 85 archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9; -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar.c
r3232 r3621 17 17 typedef uint32_t aliased_uint32_t FIX_ALIASING; 18 18 typedef off_t aliased_off_t FIX_ALIASING; 19 20 21 const char* FAST_FUNC strip_unsafe_prefix(const char *str)22 {23 const char *cp = str;24 while (1) {25 char *cp2;26 if (*cp == '/') {27 cp++;28 continue;29 }30 if (strncmp(cp, "/../"+1, 3) == 0) {31 cp += 3;32 continue;33 }34 cp2 = strstr(cp, "/../");35 if (!cp2)36 break;37 cp = cp2 + 4;38 }39 if (cp != str) {40 static smallint warned = 0;41 if (!warned) {42 warned = 1;43 bb_error_msg("removing leading '%.*s' from member names",44 (int)(cp - str), str);45 }46 }47 return cp;48 }49 19 50 20 /* NB: _DESTROYS_ str[len] character! */ … … 91 61 #define GET_OCTAL(a) getOctal((a), sizeof(a)) 92 62 63 #define TAR_EXTD (ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX) 64 #if !TAR_EXTD 65 #define process_pax_hdr(archive_handle, sz, global) \ 66 process_pax_hdr(archive_handle, sz) 67 #endif 93 68 /* "global" is 0 or 1 */ 94 69 static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global) 95 70 { 71 #if !TAR_EXTD 72 unsigned blk_sz = (sz + 511) & (~511); 73 seek_by_read(archive_handle->src_fd, blk_sz); 74 #else 75 unsigned blk_sz = (sz + 511) & (~511); 96 76 char *buf, *p; 97 unsigned blk_sz; 98 99 blk_sz = (sz + 511) & (~511); 77 100 78 p = buf = xmalloc(blk_sz + 1); 101 79 xread(archive_handle->src_fd, buf, blk_sz); … … 116 94 p += len; 117 95 sz -= len; 118 if ((int)sz < 0 96 if ( 97 /** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */ 98 (int)(sz|len) < 0 /* this works */ 119 99 || len == 0 120 100 || errno != EINVAL … … 133 113 value = end + 1; 134 114 135 # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS136 if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {115 # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 116 if (!global && is_prefixed_with(value, "path=")) { 137 117 value += sizeof("path=") - 1; 138 118 free(archive_handle->tar__longname); … … 140 120 continue; 141 121 } 142 # endif143 144 # if ENABLE_FEATURE_TAR_SELINUX122 # endif 123 124 # if ENABLE_FEATURE_TAR_SELINUX 145 125 /* Scan for SELinux contexts, via "RHT.security.selinux" keyword. 146 126 * This is what Red Hat's patched version of tar uses. 147 127 */ 148 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"149 if ( strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {128 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux" 129 if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) { 150 130 value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1; 151 131 free(archive_handle->tar__sctx[global]); … … 153 133 continue; 154 134 } 155 # endif135 # endif 156 136 } 157 137 158 138 free(buf); 139 #endif 159 140 } 160 141 … … 199 180 * saw zero block directly before this. */ 200 181 if (i == 0) { 201 xfunc_error_retval = 0;202 short_read: 203 bb_error_msg_and_die("short read");182 bb_error_msg("short read"); 183 /* this merely signals end of archive, not exit(1): */ 184 return EXIT_FAILURE; 204 185 } 205 186 if (i != 512) { 206 187 IF_FEATURE_TAR_AUTODETECT(goto autodetect;) 207 goto short_read;188 bb_error_msg_and_die("short read"); 208 189 } 209 190 … … 222 203 while (full_read(archive_handle->src_fd, &tar, 512) == 512) 223 204 continue; 224 return EXIT_FAILURE; 205 return EXIT_FAILURE; /* "end of archive" */ 225 206 } 226 207 archive_handle->tar__end = 1; 227 return EXIT_SUCCESS; 208 return EXIT_SUCCESS; /* "decoded one header" */ 228 209 } 229 210 archive_handle->tar__end = 0; … … 231 212 /* Check header has valid magic, "ustar" is for the proper tar, 232 213 * five NULs are for the old tar format */ 233 if ( strncmp(tar.magic, "ustar", 5) != 0214 if (!is_prefixed_with(tar.magic, "ustar") 234 215 && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY 235 216 || memcmp(tar.magic, "\0\0\0\0", 5) != 0) … … 242 223 if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0) 243 224 goto err; 244 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_ detected:*/ 0) != 0)225 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0) 245 226 err: 246 227 bb_error_msg_and_die("invalid tar magic"); … … 379 360 file_header->mode |= S_IFIFO; 380 361 goto size0; 362 case 'g': /* pax global header */ 363 case 'x': { /* pax extended header */ 364 if ((uoff_t)file_header->size > 0xfffff) /* paranoia */ 365 goto skip_ext_hdr; 366 process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g')); 367 goto again_after_align; 381 368 #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 369 /* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */ 382 370 case 'L': 383 371 /* free: paranoia: tar with several consecutive longnames */ … … 399 387 /* return get_header_tar(archive_handle); */ 400 388 goto again; 401 case 'D': /* GNU dump dir */ 402 case 'M': /* Continuation of multi volume archive */ 403 case 'N': /* Old GNU for names > 100 characters */ 404 case 'S': /* Sparse file */ 405 case 'V': /* Volume header */ 406 #endif 407 case 'g': /* pax global header */ 408 case 'x': { /* pax extended header */ 409 if ((uoff_t)file_header->size > 0xfffff) /* paranoia */ 410 goto skip_ext_hdr; 411 process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g')); 412 goto again_after_align; 389 /* 390 * case 'S': // Sparse file 391 * Was seen in the wild. Not supported (yet?). 392 * See https://www.gnu.org/software/tar/manual/html_section/tar_92.html 393 * for the format. (An "Old GNU Format" was seen, not PAX formats). 394 */ 395 // case 'D': /* GNU dump dir */ 396 // case 'M': /* Continuation of multi volume archive */ 397 // case 'N': /* Old GNU for names > 100 characters */ 398 // case 'V': /* Volume header */ 399 #endif 413 400 } 414 401 skip_ext_hdr: … … 441 428 /* Everything up to and including last ".." component is stripped */ 442 429 overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name)); 430 //TODO: do the same for file_header->link_target? 443 431 444 432 /* Strip trailing '/' in directories */ … … 472 460 free(file_header->tar__gname); 473 461 #endif 474 return EXIT_SUCCESS; 462 return EXIT_SUCCESS; /* "decoded one header" */ 475 463 } -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_bz2.c
r3232 r3621 12 12 archive_handle->seek = seek_by_read; 13 13 14 open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");14 fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2"); 15 15 archive_handle->offset = 0; 16 16 while (get_header_tar(archive_handle) == EXIT_SUCCESS) -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_gz.c
r3232 r3621 12 12 archive_handle->seek = seek_by_read; 13 13 14 open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");14 fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip"); 15 15 archive_handle->offset = 0; 16 16 while (get_header_tar(archive_handle) == EXIT_SUCCESS) -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_lzma.c
r3232 r3621 15 15 archive_handle->seek = seek_by_read; 16 16 17 open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");17 fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma"); 18 18 archive_handle->offset = 0; 19 19 while (get_header_tar(archive_handle) == EXIT_SUCCESS) -
branches/3.3/mindi-busybox/archival/libarchive/liblzo.h
r2725 r3621 77 77 # define NEED_IP(x) \ 78 78 if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun 79 # define TEST_IV(x) if ((x) > (unsigned)0 - (511)) goto input_overrun 79 80 80 81 # undef TEST_OP /* don't need both of the tests here */ … … 82 83 # define NEED_OP(x) \ 83 84 if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun 85 # define TEST_OV(x) if ((x) > (unsigned)0 - (511)) goto output_overrun 84 86 85 87 #define HAVE_ANY_OP 1 -
branches/3.3/mindi-busybox/archival/libarchive/lzo1x_9x.c
r3232 r3621 72 72 73 73 unsigned r1_lit; 74 75 74 } lzo1x_999_t; 76 75 … … 95 94 96 95 #if defined(LZO_UNALIGNED_OK_2) 97 # define HEAD2(b,p) (* ( uint16_t *) &(b[p]))96 # define HEAD2(b,p) (* (bb__aliased_uint16_t *) &(b[p])) 98 97 #else 99 98 # define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8)) … … 466 465 } 467 466 468 s->m_len = 1;469 467 s->m_len = 1; 470 468 #ifdef SWD_BEST_OFF -
branches/3.3/mindi-busybox/archival/libarchive/lzo1x_d.c
r3232 r3621 93 93 NEED_IP(1); 94 94 } 95 TEST_IV(t); 95 96 t += 15 + *ip++; 96 97 } … … 225 226 NEED_IP(1); 226 227 } 228 TEST_IV(t); 227 229 t += 31 + *ip++; 228 230 } … … 266 268 NEED_IP(1); 267 269 } 270 TEST_IV(t); 268 271 t += 7 + *ip++; 269 272 } -
branches/3.3/mindi-busybox/archival/libarchive/open_transformer.c
r3232 r3621 7 7 #include "bb_archive.h" 8 8 9 void FAST_FUNC init_transformer_ aux_data(transformer_aux_data_t *aux)10 { 11 memset( aux, 0, sizeof(*aux));12 } 13 14 int FAST_FUNC check_signature16(transformer_ aux_data_t *aux, int src_fd, unsigned magic16)15 { 16 if ( aux && aux->check_signature) {9 void FAST_FUNC init_transformer_state(transformer_state_t *xstate) 10 { 11 memset(xstate, 0, sizeof(*xstate)); 12 } 13 14 int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16) 15 { 16 if (!xstate->signature_skipped) { 17 17 uint16_t magic2; 18 if (full_read( src_fd, &magic2, 2) != 2 || magic2 != magic16) {18 if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) { 19 19 bb_error_msg("invalid magic"); 20 #if 0 /* possible future extension */21 if (aux->check_signature > 1)22 xfunc_die();23 #endif24 20 return -1; 25 21 } 22 xstate->signature_skipped = 2; 26 23 } 27 24 return 0; 25 } 26 27 ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) 28 { 29 ssize_t nwrote; 30 31 if (xstate->mem_output_size_max != 0) { 32 size_t pos = xstate->mem_output_size; 33 size_t size; 34 35 size = (xstate->mem_output_size += bufsize); 36 if (size > xstate->mem_output_size_max) { 37 free(xstate->mem_output_buf); 38 xstate->mem_output_buf = NULL; 39 bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max); 40 nwrote = -1; 41 goto ret; 42 } 43 xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1); 44 memcpy(xstate->mem_output_buf + pos, buf, bufsize); 45 xstate->mem_output_buf[size] = '\0'; 46 nwrote = bufsize; 47 } else { 48 nwrote = full_write(xstate->dst_fd, buf, bufsize); 49 if (nwrote != (ssize_t)bufsize) { 50 bb_perror_msg("write"); 51 nwrote = -1; 52 goto ret; 53 } 54 } 55 ret: 56 return nwrote; 57 } 58 59 ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) 60 { 61 ssize_t nwrote = transformer_write(xstate, buf, bufsize); 62 if (nwrote != (ssize_t)bufsize) { 63 xfunc_die(); 64 } 65 return nwrote; 28 66 } 29 67 … … 35 73 /* block waiting for any child */ 36 74 if (wait(&status) < 0) 75 //FIXME: check EINTR? 37 76 return; /* probably there are no children */ 38 77 goto check_status; … … 42 81 for (;;) { 43 82 if (wait_any_nohang(&status) < 0) 83 //FIXME: check EINTR? 44 84 /* wait failed?! I'm confused... */ 45 85 return; 46 86 check_status: 47 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) 87 /*if (WIFEXITED(status) && WEXITSTATUS(status) == 0)*/ 88 /* On Linux, the above can be checked simply as: */ 89 if (status == 0) 48 90 /* this child exited with 0 */ 49 91 continue; 50 /* Cannot happen? 51 if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */ 92 /* Cannot happen: 93 if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; 94 */ 52 95 bb_got_signal = 1; 53 96 } … … 56 99 /* transformer(), more than meets the eye */ 57 100 #if BB_MMU 58 void FAST_FUNC open_transformer(int fd,59 int check_signature,60 IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_ aux_data_t *aux, int src_fd, int dst_fd)101 void FAST_FUNC fork_transformer(int fd, 102 int signature_skipped, 103 IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate) 61 104 ) 62 105 #else 63 void FAST_FUNC open_transformer(int fd, const char *transform_prog)106 void FAST_FUNC fork_transformer(int fd, const char *transform_prog) 64 107 #endif 65 108 { … … 75 118 #if BB_MMU 76 119 { 77 transformer_aux_data_t aux; 78 init_transformer_aux_data(&aux); 79 aux.check_signature = check_signature; 80 transformer(&aux, fd, fd_pipe.wr); 120 IF_DESKTOP(long long) int r; 121 transformer_state_t xstate; 122 init_transformer_state(&xstate); 123 xstate.signature_skipped = signature_skipped; 124 xstate.src_fd = fd; 125 xstate.dst_fd = fd_pipe.wr; 126 r = transformer(&xstate); 81 127 if (ENABLE_FEATURE_CLEAN_UP) { 82 128 close(fd_pipe.wr); /* send EOF */ … … 84 130 } 85 131 /* must be _exit! bug was actually seen here */ 86 _exit( EXIT_SUCCESS);132 _exit(/*error if:*/ r < 0); 87 133 } 88 134 #else … … 113 159 * thus we can't guess the format from filename's extension. 114 160 */ 115 int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)161 static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed) 116 162 { 117 163 union { … … 120 166 uint32_t b32[1]; 121 167 } magic; 122 int offset = -2; 123 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);) 124 USE_FOR_NOMMU(const char *xformer_prog;) 168 transformer_state_t *xstate; 169 170 xstate = xzalloc(sizeof(*xstate)); 171 xstate->src_fd = fd; 172 xstate->signature_skipped = 2; 125 173 126 174 /* .gz and .bz2 both have 2-byte signature, and their … … 130 178 && magic.b16[0] == GZIP_MAGIC 131 179 ) { 132 USE_FOR_MMU(xformer = unpack_gz_stream;) 133 USE_FOR_NOMMU(xformer_prog = "gunzip";) 180 xstate->xformer = unpack_gz_stream; 181 USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";) 182 goto found_magic; 183 } 184 if (ENABLE_FEATURE_SEAMLESS_Z 185 && magic.b16[0] == COMPRESS_MAGIC 186 ) { 187 xstate->xformer = unpack_Z_stream; 188 USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";) 134 189 goto found_magic; 135 190 } … … 137 192 && magic.b16[0] == BZIP2_MAGIC 138 193 ) { 139 USE_FOR_MMU(xformer = unpack_bz2_stream;)140 USE_FOR_NOMMU(x former_prog = "bunzip2";)194 xstate->xformer = unpack_bz2_stream; 195 USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";) 141 196 goto found_magic; 142 197 } … … 144 199 && magic.b16[0] == XZ_MAGIC1 145 200 ) { 146 offset = -6;201 xstate->signature_skipped = 6; 147 202 xread(fd, magic.b32, sizeof(magic.b32[0])); 148 203 if (magic.b32[0] == XZ_MAGIC2) { 149 USE_FOR_MMU(xformer = unpack_xz_stream;)150 USE_FOR_NOMMU(x former_prog = "unxz";)204 xstate->xformer = unpack_xz_stream; 205 USE_FOR_NOMMU(xstate->xformer_prog = "unxz";) 151 206 goto found_magic; 152 207 } … … 154 209 155 210 /* No known magic seen */ 156 if (fail_if_not_ detected)211 if (fail_if_not_compressed) 157 212 bb_error_msg_and_die("no gzip" 158 213 IF_FEATURE_SEAMLESS_BZ2("/bzip2") 159 214 IF_FEATURE_SEAMLESS_XZ("/xz") 160 215 " magic"); 161 xlseek(fd, offset, SEEK_CUR); 162 return 1; 216 217 /* Some callers expect this function to "consume" fd 218 * even if data is not compressed. In this case, 219 * we return a state with trivial transformer. 220 */ 221 // USE_FOR_MMU(xstate->xformer = copy_stream;) 222 // USE_FOR_NOMMU(xstate->xformer_prog = "cat";) 163 223 164 224 found_magic: 225 return xstate; 226 } 227 228 /* Used by e.g. rpm which gives us a fd without filename, 229 * thus we can't guess the format from filename's extension. 230 */ 231 int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed) 232 { 233 transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed); 234 235 if (!xstate || !xstate->xformer) { 236 free(xstate); 237 return 1; 238 } 239 165 240 # if BB_MMU 166 open_transformer_with_no_sig(fd,xformer);241 fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer); 167 242 # else 168 /* NOMMU version of open_transformer execs243 /* NOMMU version of fork_transformer execs 169 244 * an external unzipper that wants 170 * file position at the start of the file */ 171 xlseek(fd, offset, SEEK_CUR); 172 open_transformer_with_sig(fd, xformer, xformer_prog); 245 * file position at the start of the file. 246 */ 247 xlseek(fd, - xstate->signature_skipped, SEEK_CUR); 248 xstate->signature_skipped = 0; 249 fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog); 173 250 # endif 251 free(xstate); 174 252 return 0; 175 253 } 176 254 177 int FAST_FUNC open_zipped(const char *fname)178 { 179 char *sfx;255 static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed) 256 { 257 transformer_state_t *xstate; 180 258 int fd; 181 259 182 260 fd = open(fname, O_RDONLY); 183 261 if (fd < 0) 184 return fd; 185 186 sfx = strrchr(fname, '.'); 187 if (sfx) { 188 sfx++; 189 if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0) 190 /* .lzma has no header/signature, just trust it */ 191 open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma"); 192 else 193 if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0) 194 || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0) 195 || (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0) 196 ) { 197 setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1); 198 } 199 } 200 262 return NULL; 263 264 if (ENABLE_FEATURE_SEAMLESS_LZMA) { 265 /* .lzma has no header/signature, can only detect it by extension */ 266 char *sfx = strrchr(fname, '.'); 267 if (sfx && strcmp(sfx+1, "lzma") == 0) { 268 xstate = xzalloc(sizeof(*xstate)); 269 xstate->src_fd = fd; 270 xstate->xformer = unpack_lzma_stream; 271 USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";) 272 return xstate; 273 } 274 } 275 276 xstate = setup_transformer_on_fd(fd, fail_if_not_compressed); 277 278 return xstate; 279 } 280 281 int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed) 282 { 283 int fd; 284 transformer_state_t *xstate; 285 286 xstate = open_transformer(fname, fail_if_not_compressed); 287 if (!xstate) 288 return -1; 289 290 fd = xstate->src_fd; 291 # if BB_MMU 292 if (xstate->xformer) { 293 fork_transformer_with_no_sig(fd, xstate->xformer); 294 } else { 295 /* the file is not compressed */ 296 xlseek(fd, - xstate->signature_skipped, SEEK_CUR); 297 xstate->signature_skipped = 0; 298 } 299 # else 300 /* NOMMU can't avoid the seek :( */ 301 xlseek(fd, - xstate->signature_skipped, SEEK_CUR); 302 xstate->signature_skipped = 0; 303 if (xstate->xformer) { 304 fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog); 305 } /* else: the file is not compressed */ 306 # endif 307 308 free(xstate); 201 309 return fd; 202 310 } 203 311 204 #endif /* SEAMLESS_COMPRESSION */205 206 312 void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) 207 313 { 314 # if 1 315 transformer_state_t *xstate; 316 char *image; 317 318 xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0); 319 if (!xstate) /* file open error */ 320 return NULL; 321 322 image = NULL; 323 if (xstate->xformer) { 324 /* In-memory decompression */ 325 xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095); 326 xstate->xformer(xstate); 327 if (xstate->mem_output_buf) { 328 image = xstate->mem_output_buf; 329 if (maxsz_p) 330 *maxsz_p = xstate->mem_output_size; 331 } 332 } else { 333 /* File is not compressed */ 334 //FIXME: avoid seek 335 xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR); 336 xstate->signature_skipped = 0; 337 image = xmalloc_read(xstate->src_fd, maxsz_p); 338 } 339 340 if (!image) 341 bb_perror_msg("read error from '%s'", fname); 342 close(xstate->src_fd); 343 free(xstate); 344 return image; 345 # else 346 /* This version forks a subprocess - much more expensive */ 208 347 int fd; 209 348 char *image; 210 349 211 fd = open_zipped(fname );350 fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0); 212 351 if (fd < 0) 213 352 return NULL; … … 217 356 bb_perror_msg("read error from '%s'", fname); 218 357 close(fd); 219 220 358 return image; 221 } 359 # endif 360 } 361 362 #endif /* SEAMLESS_COMPRESSION */ -
branches/3.3/mindi-busybox/archival/libarchive/unpack_ar_archive.c
r3232 r3621 13 13 14 14 xread(ar_archive->src_fd, magic, AR_MAGIC_LEN); 15 if ( strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) {15 if (!is_prefixed_with(magic, AR_MAGIC)) { 16 16 bb_error_msg_and_die("invalid ar magic"); 17 17 } -
branches/3.3/mindi-busybox/archival/libarchive/unxz/README
r2725 r3621 8 8 XZ Embedded was written for use in the Linux kernel, but the code can 9 9 be easily used in other environments too, including regular userspace 10 applications. 10 applications. See userspace/xzminidec.c for an example program. 11 11 12 12 This README contains information that is useful only when the copy … … 56 56 care than just using 32-bit integer instead of 64-bit). 57 57 58 If you use GCC, try to use a recent version. For example, on x86 ,58 If you use GCC, try to use a recent version. For example, on x86-32, 59 59 xz_dec_lzma2.c compiled with GCC 3.3.6 is 15-25 % slower than when 60 60 compiled with GCC 4.3.3. … … 94 94 95 95 #define Instruction set BCJ filter endianness 96 XZ_DEC_X86 x86 or x86-64Little endian only96 XZ_DEC_X86 x86-32 or x86-64 Little endian only 97 97 XZ_DEC_POWERPC PowerPC Big endian only 98 98 XZ_DEC_IA64 Itanium (IA-64) Big or little endian -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz.h
r2725 r3621 18 18 # include <stddef.h> 19 19 # include <stdint.h> 20 #endif 21 22 #ifdef __cplusplus 23 extern "C" { 20 24 #endif 21 25 … … 71 75 * is still possible in multi-call mode by simply 72 76 * calling xz_dec_run() again. 73 * N OTE: This return value is used only if77 * Note that this return value is used only if 74 78 * XZ_DEC_ANY_CHECK was defined at build time, 75 79 * which is not used in the kernel. Unsupported … … 106 110 * 107 111 * In single-call mode, XZ_BUF_ERROR is returned only when the output buffer 108 * is too small ,or the compressed input is corrupt in a way that makes the112 * is too small or the compressed input is corrupt in a way that makes the 109 113 * decoder produce more output than the caller expected. When it is 110 114 * (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR … … 208 212 * See enum xz_ret for details. 209 213 * 210 * N OTE: If an error occurs in single-call mode (return value is not211 * XZ_STREAM_END), b->in_pos and b->out_pos are not modified ,and the214 * Note that if an error occurs in single-call mode (return value is not 215 * XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the 212 216 * contents of the output buffer from b->out[b->out_pos] onward are 213 217 * undefined. This is true even after XZ_BUF_ERROR, because with some filter … … 269 273 const uint8_t *buf, size_t size, uint32_t crc); 270 274 #endif 271 #endif 275 276 #ifdef __cplusplus 277 } 278 #endif 279 280 #endif -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_bcj.c
r2725 r3621 78 78 #ifdef XZ_DEC_X86 79 79 /* 80 * This is macroused to test the most significant byte of a memory address80 * This is used to test the most significant byte of a memory address 81 81 * in an x86 instruction. 82 82 */ 83 #define bcj_x86_test_msbyte(b) ((b) == 0x00 || (b) == 0xFF) 83 static inline int bcj_x86_test_msbyte(uint8_t b) 84 { 85 return b == 0x00 || b == 0xFF; 86 } 84 87 85 88 static noinline_for_stack size_t XZ_FUNC bcj_x86( … … 444 447 * in the output buffer. If everything cannot be filtered, copy it 445 448 * to temp and rewind the output buffer position accordingly. 449 * 450 * This needs to be always run when temp.size == 0 to handle a special 451 * case where the output buffer is full and the next filter has no 452 * more output coming but hasn't returned XZ_STREAM_END yet. 446 453 */ 447 if (s->temp.size < b->out_size - b->out_pos ) {454 if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) { 448 455 out_start = b->out_pos; 449 456 memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size); … … 468 475 b->out_pos -= s->temp.size; 469 476 memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size); 477 478 /* 479 * If there wasn't enough input to the next filter to fill 480 * the output buffer with unfiltered data, there's no point 481 * to try decoding more data to temp. 482 */ 483 if (b->out_pos + s->temp.size < b->out_size) 484 return XZ_OK; 470 485 } 471 486 472 487 /* 473 * If we have unfiltered data in temp, try to fill by decoding more 474 * data from the next filter. Apply the BCJ filter on temp. Then we 475 * hopefully can fill the actual output buffer by copying filtered 476 * data from temp. A mix of filtered and unfiltered data may be left 477 * in temp; it will be taken care on the next call to this function. 488 * We have unfiltered data in temp. If the output buffer isn't full 489 * yet, try to fill the temp buffer by decoding more data from the 490 * next filter. Apply the BCJ filter on temp. Then we hopefully can 491 * fill the actual output buffer by copying filtered data from temp. 492 * A mix of filtered and unfiltered data may be left in temp; it will 493 * be taken care on the next call to this function. 478 494 */ 479 if ( s->temp.size > 0) {495 if (b->out_pos < b->out_size) { 480 496 /* Make b->out{,_pos,_size} temporarily point to s->temp. */ 481 497 s->out = b->out; -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_lzma2.c
r2725 r3621 408 408 b->out_pos += copy_size; 409 409 b->in_pos += copy_size; 410 411 410 } 412 411 } … … 973 972 tmp = b->in[b->in_pos++]; 974 973 974 if (tmp == 0x00) 975 return XZ_STREAM_END; 976 975 977 if (tmp >= 0xE0 || tmp == 0x01) { 976 978 s->lzma2.need_props = true; … … 994 996 s->lzma2.next_sequence 995 997 = SEQ_PROPERTIES; 996 997 998 } else if (s->lzma2.need_props) { 998 999 return XZ_DATA_ERROR; 999 1000 1000 } else { 1001 1001 s->lzma2.next_sequence … … 1005 1005 } 1006 1006 } else { 1007 if (tmp == 0x00)1008 return XZ_STREAM_END;1009 1010 1007 if (tmp > 0x02) 1011 1008 return XZ_DATA_ERROR; … … 1082 1079 rc_reset(&s->rc); 1083 1080 s->lzma2.sequence = SEQ_CONTROL; 1084 1085 1081 } else if (b->out_pos == b->out_size 1086 1082 || (b->in_pos == b->in_size -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_stream.c
r2725 r3621 354 354 355 355 s->pos += 8; 356 357 356 } while (s->pos < 32); 358 357 … … 754 753 b->out_pos = out_start; 755 754 } 756 757 755 } else if (ret == XZ_OK && in_start == b->in_pos 758 756 && out_start == b->out_pos) { -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_stream.h
r2725 r3621 26 26 #define STREAM_HEADER_SIZE 12 27 27 28 #define HEADER_MAGIC "\3757zXZ \0"28 #define HEADER_MAGIC "\3757zXZ" 29 29 #define HEADER_MAGIC_SIZE 6 30 30 … … 33 33 34 34 /* 35 * Variable-length integer can hold a 63-bit unsigned integer, or a special 36 * value to indicate that the value is unknown. 35 * Variable-length integer can hold a 63-bit unsigned integer or a special 36 * value indicating that the value is unknown. 37 * 38 * Experimental: vli_type can be defined to uint32_t to save a few bytes 39 * in code size (no effect on speed). Doing so limits the uncompressed and 40 * compressed size of the file to less than 256 MiB and may also weaken 41 * error detection slightly. 37 42 */ 38 43 typedef uint64_t vli_type; -
branches/3.3/mindi-busybox/archival/lzop.c
r3232 r3621 25 25 "Minimalized" for busybox by Alain Knaff 26 26 */ 27 28 //config:config LZOP 29 //config: bool "lzop" 30 //config: default y 31 //config: help 32 //config: Lzop compression/decompresion. 33 //config: 34 //config:config LZOP_COMPR_HIGH 35 //config: bool "lzop compression levels 7,8,9 (not very useful)" 36 //config: default n 37 //config: depends on LZOP 38 //config: help 39 //config: High levels (7,8,9) of lzop compression. These levels 40 //config: are actually slower than gzip at equivalent compression ratios 41 //config: and take up 3.2K of code. 42 43 //applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP)) 44 //applet:IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat)) 45 //applet:IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop)) 46 //kbuild:lib-$(CONFIG_LZOP) += lzop.o 27 47 28 48 //usage:#define lzop_trivial_usage … … 52 72 53 73 #include "libbb.h" 74 #include "common_bufsiz.h" 54 75 #include "bb_archive.h" 55 76 #include "liblzo_interface.h" … … 424 445 chksum_t chksum_out; 425 446 } FIX_ALIASING; 426 #define G (*(struct globals*) &bb_common_bufsiz1)427 #define INIT_G() do { } while (0)447 #define G (*(struct globals*)bb_common_bufsiz1) 448 #define INIT_G() do { setup_common_bufsiz(); } while (0) 428 449 //#define G (*ptr_to_globals) 429 450 //#define INIT_G() do { … … 437 458 //#define LZOP_VERSION_DATE "Apr 27th 2003" 438 459 439 #define OPTION_STRING "cfvdt123456789CF" 440 460 #define OPTION_STRING "cfvqdt123456789CF" 461 462 /* Note: must be kept in sync with archival/bbunzip.c */ 441 463 enum { 442 464 OPT_STDOUT = (1 << 0), 443 465 OPT_FORCE = (1 << 1), 444 466 OPT_VERBOSE = (1 << 2), 445 OPT_DECOMPRESS = (1 << 3), 446 OPT_TEST = (1 << 4), 447 OPT_1 = (1 << 5), 448 OPT_2 = (1 << 6), 449 OPT_3 = (1 << 7), 450 OPT_4 = (1 << 8), 451 OPT_5 = (1 << 9), 452 OPT_6 = (1 << 10), 453 OPT_789 = (7 << 11), 454 OPT_7 = (1 << 11), 455 OPT_8 = (1 << 12), 456 OPT_C = (1 << 14), 457 OPT_F = (1 << 15), 467 OPT_QUIET = (1 << 3), 468 OPT_DECOMPRESS = (1 << 4), 469 OPT_TEST = (1 << 5), 470 OPT_1 = (1 << 6), 471 OPT_2 = (1 << 7), 472 OPT_3 = (1 << 8), 473 OPT_4 = (1 << 9), 474 OPT_5 = (1 << 10), 475 OPT_6 = (1 << 11), 476 OPT_789 = (7 << 12), 477 OPT_7 = (1 << 13), 478 OPT_8 = (1 << 14), 479 OPT_C = (1 << 15), 480 OPT_F = (1 << 16), 458 481 }; 459 482 … … 619 642 // compress a file 620 643 /**********************************************************************/ 621 static NOINLINE smallint lzo_compress(const header_t *h)644 static NOINLINE int lzo_compress(const header_t *h) 622 645 { 623 646 unsigned block_size = LZO_BLOCK_SIZE; … … 629 652 uint32_t d_crc32 = CRC32_INIT_VALUE; 630 653 int l; 631 smallint ok = 1;632 654 uint8_t *wrk_mem = NULL; 633 655 … … 711 733 free(b1); 712 734 free(b2); 713 return ok;735 return 1; 714 736 } 715 737 … … 732 754 // decompress a file 733 755 /**********************************************************************/ 734 static NOINLINE smallint lzo_decompress(const header_t *h)756 static NOINLINE int lzo_decompress(const header_t *h) 735 757 { 736 758 unsigned block_size = LZO_BLOCK_SIZE; … … 740 762 uint32_t d_adler32 = ADLER32_INIT_VALUE; 741 763 uint32_t c_crc32 = CRC32_INIT_VALUE, d_crc32 = CRC32_INIT_VALUE; 742 smallint ok = 1;743 764 uint8_t *b1; 744 765 uint32_t mcs_block_size = MAX_COMPRESSED_SIZE(block_size); … … 844 865 845 866 free(b2); 846 return ok;867 return 1; 847 868 } 848 869 … … 876 897 * The rest is identical. 877 898 */ 878 static const unsigned char lzop_magic[9] = {899 static const unsigned char lzop_magic[9] ALIGN1 = { 879 900 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a 880 901 }; … … 1029 1050 } 1030 1051 1031 static smallint do_lzo_compress(void)1052 static int do_lzo_compress(void) 1032 1053 { 1033 1054 header_t header; … … 1057 1078 // decompress 1058 1079 /**********************************************************************/ 1059 static smallint do_lzo_decompress(void)1080 static int do_lzo_decompress(void) 1060 1081 { 1061 1082 header_t header; … … 1078 1099 } 1079 1100 1080 static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_ aux_data_t *auxUNUSED_PARAM)1101 static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate UNUSED_PARAM) 1081 1102 { 1082 1103 if (option_mask32 & OPT_DECOMPRESS) … … 1094 1115 option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS); 1095 1116 /* unlzop? */ 1096 if (applet_name[ 0] == 'u')1117 if (applet_name[4] == 'o') 1097 1118 option_mask32 |= OPT_DECOMPRESS; 1098 1119 -
branches/3.3/mindi-busybox/archival/rpm.c
r3232 r3621 8 8 */ 9 9 10 //config:config RPM 11 //config: bool "rpm" 12 //config: default y 13 //config: help 14 //config: Mini RPM applet - queries and extracts RPM packages. 15 16 //applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP)) 17 //kbuild:lib-$(CONFIG_RPM) += rpm.o 18 10 19 //usage:#define rpm_trivial_usage 11 20 //usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm" … … 15 24 //usage: "\n -i Install package" 16 25 //usage: "\n -qp Query package" 17 //usage: "\n - i Show information"18 //usage: "\n - l List contents"19 //usage: "\n - d List documents"20 //usage: "\n - c List config files"26 //usage: "\n -qpi Show information" 27 //usage: "\n -qpl List contents" 28 //usage: "\n -qpd List documents" 29 //usage: "\n -qpc List config files" 21 30 22 31 #include "libbb.h" 32 #include "common_bufsiz.h" 23 33 #include "bb_archive.h" 24 34 #include "rpm.h" … … 80 90 } rpm_index; 81 91 82 static void *map; 83 static rpm_index **mytags; 84 static int tagcount; 85 86 static void extract_cpio(int fd, const char *source_rpm); 87 static rpm_index **rpm_gettags(int fd, int *num_tags); 88 static int bsearch_rpmtag(const void *key, const void *item); 89 static char *rpm_getstr(int tag, int itemindex); 90 static int rpm_getint(int tag, int itemindex); 91 static int rpm_getcount(int tag); 92 static void fileaction_dobackup(char *filename, int fileref); 93 static void fileaction_setowngrp(char *filename, int fileref); 94 static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)); 92 struct globals { 93 void *map; 94 rpm_index **mytags; 95 int tagcount; 96 } FIX_ALIASING; 97 #define G (*(struct globals*)bb_common_bufsiz1) 98 #define INIT_G() do { setup_common_bufsiz(); } while (0) 99 100 static void extract_cpio(int fd, const char *source_rpm) 101 { 102 archive_handle_t *archive_handle; 103 104 if (source_rpm != NULL) { 105 /* Binary rpm (it was built from some SRPM), install to root */ 106 xchdir("/"); 107 } /* else: SRPM, install to current dir */ 108 109 /* Initialize */ 110 archive_handle = init_handle(); 111 archive_handle->seek = seek_by_read; 112 archive_handle->action_data = data_extract_all; 113 #if 0 /* For testing (rpm -i only lists the files in internal cpio): */ 114 archive_handle->action_header = header_list; 115 archive_handle->action_data = data_skip; 116 #endif 117 archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS 118 /* compat: overwrite existing files. 119 * try "rpm -i foo.src.rpm" few times in a row - 120 * standard rpm will not complain. 121 */ 122 | ARCHIVE_REPLACE_VIA_RENAME; 123 archive_handle->src_fd = fd; 124 /*archive_handle->offset = 0; - init_handle() did it */ 125 126 setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1); 127 while (get_header_cpio(archive_handle) == EXIT_SUCCESS) 128 continue; 129 } 130 131 static rpm_index **rpm_gettags(int fd, int *num_tags) 132 { 133 /* We should never need more than 200 (shrink via realloc later) */ 134 rpm_index **tags = xzalloc(200 * sizeof(tags[0])); 135 int pass, tagindex = 0; 136 137 xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ 138 139 /* 1st pass is the signature headers, 2nd is the main stuff */ 140 for (pass = 0; pass < 2; pass++) { 141 struct rpm_header header; 142 rpm_index *tmpindex; 143 int storepos; 144 145 xread(fd, &header, sizeof(header)); 146 if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) 147 return NULL; /* Invalid magic, or not version 1 */ 148 header.size = ntohl(header.size); 149 header.entries = ntohl(header.entries); 150 storepos = xlseek(fd, 0, SEEK_CUR) + header.entries * 16; 151 152 while (header.entries--) { 153 tmpindex = tags[tagindex++] = xmalloc(sizeof(*tmpindex)); 154 xread(fd, tmpindex, sizeof(*tmpindex)); 155 tmpindex->tag = ntohl(tmpindex->tag); 156 tmpindex->type = ntohl(tmpindex->type); 157 tmpindex->count = ntohl(tmpindex->count); 158 tmpindex->offset = storepos + ntohl(tmpindex->offset); 159 if (pass == 0) 160 tmpindex->tag -= 743; 161 } 162 storepos = xlseek(fd, header.size, SEEK_CUR); /* Seek past store */ 163 /* Skip padding to 8 byte boundary after reading signature headers */ 164 if (pass == 0) 165 xlseek(fd, (-storepos) & 0x7, SEEK_CUR); 166 } 167 /* realloc tags to save space */ 168 tags = xrealloc(tags, tagindex * sizeof(tags[0])); 169 *num_tags = tagindex; 170 /* All done, leave the file at the start of the gzipped cpio archive */ 171 return tags; 172 } 173 174 static int bsearch_rpmtag(const void *key, const void *item) 175 { 176 int *tag = (int *)key; 177 rpm_index **tmp = (rpm_index **) item; 178 return (*tag - tmp[0]->tag); 179 } 180 181 static int rpm_getcount(int tag) 182 { 183 rpm_index **found; 184 found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); 185 if (!found) 186 return 0; 187 return found[0]->count; 188 } 189 190 static char *rpm_getstr(int tag, int itemindex) 191 { 192 rpm_index **found; 193 found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); 194 if (!found || itemindex >= found[0]->count) 195 return NULL; 196 if (found[0]->type == RPM_STRING_TYPE 197 || found[0]->type == RPM_I18NSTRING_TYPE 198 || found[0]->type == RPM_STRING_ARRAY_TYPE 199 ) { 200 int n; 201 char *tmpstr = (char *) G.map + found[0]->offset; 202 for (n = 0; n < itemindex; n++) 203 tmpstr = tmpstr + strlen(tmpstr) + 1; 204 return tmpstr; 205 } 206 return NULL; 207 } 208 209 static int rpm_getint(int tag, int itemindex) 210 { 211 rpm_index **found; 212 char *tmpint; 213 214 /* gcc throws warnings here when sizeof(void*)!=sizeof(int) ... 215 * it's ok to ignore it because tag won't be used as a pointer */ 216 found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); 217 if (!found || itemindex >= found[0]->count) 218 return -1; 219 220 tmpint = (char *) G.map + found[0]->offset; 221 if (found[0]->type == RPM_INT32_TYPE) { 222 tmpint += itemindex*4; 223 return ntohl(*(int32_t*)tmpint); 224 } 225 if (found[0]->type == RPM_INT16_TYPE) { 226 tmpint += itemindex*2; 227 return ntohs(*(int16_t*)tmpint); 228 } 229 if (found[0]->type == RPM_INT8_TYPE) { 230 tmpint += itemindex; 231 return *(int8_t*)tmpint; 232 } 233 return -1; 234 } 235 236 static void fileaction_dobackup(char *filename, int fileref) 237 { 238 struct stat oldfile; 239 int stat_res; 240 char *newname; 241 if (rpm_getint(TAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { 242 /* Only need to backup config files */ 243 stat_res = lstat(filename, &oldfile); 244 if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { 245 /* File already exists - really should check MD5's etc to see if different */ 246 newname = xasprintf("%s.rpmorig", filename); 247 copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS); 248 remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE); 249 free(newname); 250 } 251 } 252 } 253 254 static void fileaction_setowngrp(char *filename, int fileref) 255 { 256 /* real rpm warns: "user foo does not exist - using <you>" */ 257 struct passwd *pw = getpwnam(rpm_getstr(TAG_FILEUSERNAME, fileref)); 258 int uid = pw ? pw->pw_uid : getuid(); /* or euid? */ 259 struct group *gr = getgrnam(rpm_getstr(TAG_FILEGROUPNAME, fileref)); 260 int gid = gr ? gr->gr_gid : getgid(); 261 chown(filename, uid, gid); 262 } 263 264 static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)) 265 { 266 int count = 0; 267 while (rpm_getstr(filetag, count)) { 268 char* filename = xasprintf("%s%s", 269 rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, count)), 270 rpm_getstr(TAG_BASENAMES, count)); 271 fileaction(filename, count++); 272 free(filename); 273 } 274 } 95 275 96 276 int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 97 277 int rpm_main(int argc, char **argv) 98 278 { 99 int opt = 0, func = 0, rpm_fd, offset;100 const intpagesize = getpagesize();279 int opt, func = 0; 280 const unsigned pagesize = getpagesize(); 101 281 102 282 while ((opt = getopt(argc, argv, "iqpldc")) != -1) { … … 135 315 136 316 while (*argv) { 317 int rpm_fd; 318 unsigned mapsize; 137 319 const char *source_rpm; 138 320 139 321 rpm_fd = xopen(*argv++, O_RDONLY); 140 mytags = rpm_gettags(rpm_fd, &tagcount);141 if (! mytags)322 G.mytags = rpm_gettags(rpm_fd, &G.tagcount); 323 if (!G.mytags) 142 324 bb_error_msg_and_die("error reading rpm header"); 143 offset = xlseek(rpm_fd, 0, SEEK_CUR); 144 /* Mimimum is one page */ 145 map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0); 325 mapsize = xlseek(rpm_fd, 0, SEEK_CUR); 326 mapsize = (mapsize + pagesize) & -(int)pagesize; 327 /* Some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */ 328 G.map = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, rpm_fd, 0); 329 //FIXME: error check? 146 330 147 331 source_rpm = rpm_getstr(TAG_SOURCERPM, 0); … … 167 351 const char *p; 168 352 169 p = rpm_getstr(TAG_PREFIXS, 0); 170 if (!p) p = "(not relocateable)"; 171 printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), p); 172 p = rpm_getstr(TAG_VENDOR, 0); 173 if (!p) p = "(none)"; 174 printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), p); 353 printf("%-12s: %s\n", "Name" , rpm_getstr(TAG_NAME, 0)); 354 /* TODO compat: add "Epoch" here */ 355 printf("%-12s: %s\n", "Version" , rpm_getstr(TAG_VERSION, 0)); 356 printf("%-12s: %s\n", "Release" , rpm_getstr(TAG_RELEASE, 0)); 357 /* add "Architecture" */ 358 printf("%-12s: %s\n", "Install Date", "(not installed)"); 359 printf("%-12s: %s\n", "Group" , rpm_getstr(TAG_GROUP, 0)); 360 printf("%-12s: %d\n", "Size" , rpm_getint(TAG_SIZE, 0)); 361 printf("%-12s: %s\n", "License" , rpm_getstr(TAG_LICENSE, 0)); 362 /* add "Signature" */ 363 printf("%-12s: %s\n", "Source RPM" , source_rpm ? source_rpm : "(none)"); 175 364 bdate_time = rpm_getint(TAG_BUILDTIME, 0); 176 365 bdate_ptm = localtime(&bdate_time); 177 366 strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm); 178 printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring); 179 printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0)); 180 printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), source_rpm); 181 printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0)); 182 printf("URL : %s\n", rpm_getstr(TAG_URL, 0)); 183 printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0)); 367 printf("%-12s: %s\n", "Build Date" , bdatestring); 368 printf("%-12s: %s\n", "Build Host" , rpm_getstr(TAG_BUILDHOST, 0)); 369 p = rpm_getstr(TAG_PREFIXS, 0); 370 printf("%-12s: %s\n", "Relocations" , p ? p : "(not relocatable)"); 371 /* add "Packager" */ 372 p = rpm_getstr(TAG_VENDOR, 0); 373 printf("%-12s: %s\n", "Vendor" , p ? p : "(none)"); 374 printf("%-12s: %s\n", "URL" , rpm_getstr(TAG_URL, 0)); 375 printf("%-12s: %s\n", "Summary" , rpm_getstr(TAG_SUMMARY, 0)); 184 376 printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0)); 185 377 } … … 206 398 } 207 399 } 208 free(mytags); 400 munmap(G.map, mapsize); 401 free(G.mytags); 402 close(rpm_fd); 209 403 } 210 404 return 0; 211 405 } 212 213 static void extract_cpio(int fd, const char *source_rpm)214 {215 archive_handle_t *archive_handle;216 217 if (source_rpm != NULL) {218 /* Binary rpm (it was built from some SRPM), install to root */219 xchdir("/");220 } /* else: SRPM, install to current dir */221 222 /* Initialize */223 archive_handle = init_handle();224 archive_handle->seek = seek_by_read;225 archive_handle->action_data = data_extract_all;226 #if 0 /* For testing (rpm -i only lists the files in internal cpio): */227 archive_handle->action_header = header_list;228 archive_handle->action_data = data_skip;229 #endif230 archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS231 /* compat: overwrite existing files.232 * try "rpm -i foo.src.rpm" few times in a row -233 * standard rpm will not complain.234 * (TODO? real rpm creates "file;1234" and then renames it) */235 | ARCHIVE_UNLINK_OLD;236 archive_handle->src_fd = fd;237 /*archive_handle->offset = 0; - init_handle() did it */238 239 setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);240 while (get_header_cpio(archive_handle) == EXIT_SUCCESS)241 continue;242 }243 244 static rpm_index **rpm_gettags(int fd, int *num_tags)245 {246 /* We should never need more than 200 (shrink via realloc later) */247 rpm_index **tags = xzalloc(200 * sizeof(tags[0]));248 int pass, tagindex = 0;249 250 xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */251 252 /* 1st pass is the signature headers, 2nd is the main stuff */253 for (pass = 0; pass < 2; pass++) {254 struct rpm_header header;255 rpm_index *tmpindex;256 int storepos;257 258 xread(fd, &header, sizeof(header));259 if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))260 return NULL; /* Invalid magic, or not version 1 */261 header.size = ntohl(header.size);262 header.entries = ntohl(header.entries);263 storepos = xlseek(fd, 0, SEEK_CUR) + header.entries * 16;264 265 while (header.entries--) {266 tmpindex = tags[tagindex++] = xmalloc(sizeof(*tmpindex));267 xread(fd, tmpindex, sizeof(*tmpindex));268 tmpindex->tag = ntohl(tmpindex->tag);269 tmpindex->type = ntohl(tmpindex->type);270 tmpindex->count = ntohl(tmpindex->count);271 tmpindex->offset = storepos + ntohl(tmpindex->offset);272 if (pass == 0)273 tmpindex->tag -= 743;274 }275 storepos = xlseek(fd, header.size, SEEK_CUR); /* Seek past store */276 /* Skip padding to 8 byte boundary after reading signature headers */277 if (pass == 0)278 xlseek(fd, (-storepos) & 0x7, SEEK_CUR);279 }280 /* realloc tags to save space */281 tags = xrealloc(tags, tagindex * sizeof(tags[0]));282 *num_tags = tagindex;283 /* All done, leave the file at the start of the gzipped cpio archive */284 return tags;285 }286 287 static int bsearch_rpmtag(const void *key, const void *item)288 {289 int *tag = (int *)key;290 rpm_index **tmp = (rpm_index **) item;291 return (*tag - tmp[0]->tag);292 }293 294 static int rpm_getcount(int tag)295 {296 rpm_index **found;297 found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);298 if (!found)299 return 0;300 return found[0]->count;301 }302 303 static char *rpm_getstr(int tag, int itemindex)304 {305 rpm_index **found;306 found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);307 if (!found || itemindex >= found[0]->count)308 return NULL;309 if (found[0]->type == RPM_STRING_TYPE310 || found[0]->type == RPM_I18NSTRING_TYPE311 || found[0]->type == RPM_STRING_ARRAY_TYPE312 ) {313 int n;314 char *tmpstr = (char *) map + found[0]->offset;315 for (n = 0; n < itemindex; n++)316 tmpstr = tmpstr + strlen(tmpstr) + 1;317 return tmpstr;318 }319 return NULL;320 }321 322 static int rpm_getint(int tag, int itemindex)323 {324 rpm_index **found;325 int *tmpint; /* NB: using int8_t* would be easier to code */326 327 /* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...328 * it's ok to ignore it because tag won't be used as a pointer */329 found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);330 if (!found || itemindex >= found[0]->count)331 return -1;332 333 tmpint = (int *) ((char *) map + found[0]->offset);334 335 if (found[0]->type == RPM_INT32_TYPE) {336 tmpint = (int *) ((char *) tmpint + itemindex*4);337 /*return ntohl(*tmpint);*/338 /* int can be != int32_t */339 return ntohl(*(int32_t*)tmpint);340 }341 if (found[0]->type == RPM_INT16_TYPE) {342 tmpint = (int *) ((char *) tmpint + itemindex*2);343 /* ??? read int, and THEN ntohs() it?? */344 /*return ntohs(*tmpint);*/345 return ntohs(*(int16_t*)tmpint);346 }347 if (found[0]->type == RPM_INT8_TYPE) {348 tmpint = (int *) ((char *) tmpint + itemindex);349 /* ??? why we don't read byte here??? */350 /*return ntohs(*tmpint);*/351 return *(int8_t*)tmpint;352 }353 return -1;354 }355 356 static void fileaction_dobackup(char *filename, int fileref)357 {358 struct stat oldfile;359 int stat_res;360 char *newname;361 if (rpm_getint(TAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) {362 /* Only need to backup config files */363 stat_res = lstat(filename, &oldfile);364 if (stat_res == 0 && S_ISREG(oldfile.st_mode)) {365 /* File already exists - really should check MD5's etc to see if different */366 newname = xasprintf("%s.rpmorig", filename);367 copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);368 remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);369 free(newname);370 }371 }372 }373 374 static void fileaction_setowngrp(char *filename, int fileref)375 {376 /* real rpm warns: "user foo does not exist - using <you>" */377 struct passwd *pw = getpwnam(rpm_getstr(TAG_FILEUSERNAME, fileref));378 int uid = pw ? pw->pw_uid : getuid(); /* or euid? */379 struct group *gr = getgrnam(rpm_getstr(TAG_FILEGROUPNAME, fileref));380 int gid = gr ? gr->gr_gid : getgid();381 chown(filename, uid, gid);382 }383 384 static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))385 {386 int count = 0;387 while (rpm_getstr(filetag, count)) {388 char* filename = xasprintf("%s%s",389 rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, count)),390 rpm_getstr(TAG_BASENAMES, count));391 fileaction(filename, count++);392 free(filename);393 }394 } -
branches/3.3/mindi-busybox/archival/rpm2cpio.c
r3232 r3621 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 //config:config RPM2CPIO 11 //config: bool "rpm2cpio" 12 //config: default y 13 //config: help 14 //config: Converts a RPM file into a CPIO archive. 15 16 //applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP)) 17 //kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o 9 18 10 19 //usage:#define rpm2cpio_trivial_usage … … 72 81 73 82 /* This works, but doesn't report uncompress errors (they happen in child) */ 74 setup_unzip_on_fd(rpm_fd, /*fail_if_not_ detected:*/ 1);83 setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1); 75 84 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) 76 85 bb_error_msg_and_die("error unpacking"); -
branches/3.3/mindi-busybox/archival/tar.c
r3232 r3621 23 23 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 24 24 */ 25 26 25 /* TODO: security with -C DESTDIR option can be enhanced. 27 26 * Consider tar file created via: … … 43 42 */ 44 43 44 //config:config TAR 45 //config: bool "tar" 46 //config: default y 47 //config: help 48 //config: tar is an archiving program. It's commonly used with gzip to 49 //config: create compressed archives. It's probably the most widely used 50 //config: UNIX archive program. 51 //config: 52 //config:config FEATURE_TAR_CREATE 53 //config: bool "Enable archive creation" 54 //config: default y 55 //config: depends on TAR 56 //config: help 57 //config: If you enable this option you'll be able to create 58 //config: tar archives using the `-c' option. 59 //config: 60 //config:config FEATURE_TAR_AUTODETECT 61 //config: bool "Autodetect compressed tarballs" 62 //config: default y 63 //config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ) 64 //config: help 65 //config: With this option tar can automatically detect compressed 66 //config: tarballs. Currently it works only on files (not pipes etc). 67 //config: 68 //config:config FEATURE_TAR_FROM 69 //config: bool "Enable -X (exclude from) and -T (include from) options)" 70 //config: default y 71 //config: depends on TAR 72 //config: help 73 //config: If you enable this option you'll be able to specify 74 //config: a list of files to include or exclude from an archive. 75 //config: 76 //config:config FEATURE_TAR_OLDGNU_COMPATIBILITY 77 //config: bool "Support for old tar header format" 78 //config: default y 79 //config: depends on TAR || DPKG 80 //config: help 81 //config: This option is required to unpack archives created in 82 //config: the old GNU format; help to kill this old format by 83 //config: repacking your ancient archives with the new format. 84 //config: 85 //config:config FEATURE_TAR_OLDSUN_COMPATIBILITY 86 //config: bool "Enable untarring of tarballs with checksums produced by buggy Sun tar" 87 //config: default y 88 //config: depends on TAR || DPKG 89 //config: help 90 //config: This option is required to unpack archives created by some old 91 //config: version of Sun's tar (it was calculating checksum using signed 92 //config: arithmetic). It is said to be fixed in newer Sun tar, but "old" 93 //config: tarballs still exist. 94 //config: 95 //config:config FEATURE_TAR_GNU_EXTENSIONS 96 //config: bool "Support for GNU tar extensions (long filenames)" 97 //config: default y 98 //config: depends on TAR || DPKG 99 //config: help 100 //config: With this option busybox supports GNU long filenames and 101 //config: linknames. 102 //config: 103 //config:config FEATURE_TAR_LONG_OPTIONS 104 //config: bool "Enable long options" 105 //config: default y 106 //config: depends on TAR && LONG_OPTS 107 //config: help 108 //config: Enable use of long options, increases size by about 400 Bytes 109 //config: 110 //config:config FEATURE_TAR_TO_COMMAND 111 //config: bool "Support for writing to an external program" 112 //config: default y 113 //config: depends on TAR && FEATURE_TAR_LONG_OPTIONS 114 //config: help 115 //config: If you enable this option you'll be able to instruct tar to send 116 //config: the contents of each extracted file to the standard input of an 117 //config: external program. 118 //config: 119 //config:config FEATURE_TAR_UNAME_GNAME 120 //config: bool "Enable use of user and group names" 121 //config: default y 122 //config: depends on TAR 123 //config: help 124 //config: Enables use of user and group names in tar. This affects contents 125 //config: listings (-t) and preserving permissions when unpacking (-p). 126 //config: +200 bytes. 127 //config: 128 //config:config FEATURE_TAR_NOPRESERVE_TIME 129 //config: bool "Enable -m (do not preserve time) option" 130 //config: default y 131 //config: depends on TAR 132 //config: help 133 //config: With this option busybox supports GNU tar -m 134 //config: (do not preserve time) option. 135 //config: 136 //config:config FEATURE_TAR_SELINUX 137 //config: bool "Support for extracting SELinux labels" 138 //config: default n 139 //config: depends on TAR && SELINUX 140 //config: help 141 //config: With this option busybox supports restoring SELinux labels 142 //config: when extracting files from tar archives. 143 144 //applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP)) 145 //kbuild:lib-$(CONFIG_TAR) += tar.o 146 45 147 #include <fnmatch.h> 46 148 #include "libbb.h" 149 #include "common_bufsiz.h" 47 150 #include "bb_archive.h" 48 151 /* FIXME: Stop using this non-standard feature */ … … 51 154 #endif 52 155 53 54 //#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__) 55 #define DBG(...) ((void)0) 156 #if 0 157 # define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__) 158 #else 159 # define DBG(...) ((void)0) 160 #endif 161 #define DBG_OPTION_PARSING 0 56 162 57 163 58 164 #define block_buf bb_common_bufsiz1 59 60 61 #if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2 62 /* Do not pass gzip flag to writeTarFile() */ 63 #define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \ 64 writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude) 65 #endif 165 #define INIT_G() do { setup_common_bufsiz(); } while (0) 66 166 67 167 … … 520 620 } 521 621 522 #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 523 # if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2) 524 # define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd) 525 # endif 622 #if SEAMLESS_COMPRESSION 526 623 /* Don't inline: vfork scares gcc and pessimizes code */ 527 static void NOINLINE vfork_compressor(int tar_fd, intgzip)624 static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) 528 625 { 529 626 pid_t gzipPid; 530 # if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2 531 const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; 532 # elif ENABLE_FEATURE_SEAMLESS_GZ 533 const char *zip_exec = "gzip"; 534 # else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */ 535 const char *zip_exec = "bzip2"; 536 # endif 627 537 628 // On Linux, vfork never unpauses parent early, although standard 538 629 // allows for that. Do we want to waste bytes checking for it? … … 547 638 548 639 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ 549 550 # if defined(__GNUC__) && __GNUC__551 /* Avoid vfork clobbering */552 (void) &zip_exec;553 # endif554 640 555 641 gzipPid = xvfork(); … … 568 654 xmove_fd(tar_fd, 1); 569 655 /* exec gzip/bzip2 program/applet */ 570 BB_EXECLP( zip_exec, zip_exec, "-f", NULL);656 BB_EXECLP(gzip, gzip, "-f", (char *)0); 571 657 vfork_exec_errno = errno; 572 658 _exit(EXIT_FAILURE); … … 591 677 if (vfork_exec_errno) { 592 678 errno = vfork_exec_errno; 593 bb_perror_msg_and_die("can't execute '%s'", zip_exec);679 bb_perror_msg_and_die("can't execute '%s'", gzip); 594 680 } 595 681 } 596 #endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */ 597 598 682 #endif /* SEAMLESS_COMPRESSION */ 683 684 685 #if !SEAMLESS_COMPRESSION 686 /* Do not pass gzip flag to writeTarFile() */ 687 #define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \ 688 writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude) 689 #endif 599 690 /* gcc 4.2.1 inlines it, making code bigger */ 600 691 static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, 601 692 int recurseFlags, const llist_t *include, 602 const llist_t *exclude, intgzip)693 const llist_t *exclude, const char *gzip) 603 694 { 604 695 int errorFlag = FALSE; … … 613 704 xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file"); 614 705 615 #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2706 #if SEAMLESS_COMPRESSION 616 707 if (gzip) 617 708 vfork_compressor(tbInfo.tarFd, gzip); … … 648 739 bb_error_msg("error exit delayed from previous errors"); 649 740 650 #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2741 #if SEAMLESS_COMPRESSION 651 742 if (gzip) { 652 743 int status; … … 660 751 return errorFlag; 661 752 } 662 #else 663 int writeTarFile(int tar_fd, int verboseFlag, 664 int recurseFlags, const llist_t *include, 665 const llist_t *exclude, int gzip); 666 #endif /* FEATURE_TAR_CREATE */ 753 #else /* !FEATURE_TAR_CREATE */ 754 # define writeTarFile(...) 0 755 #endif 667 756 668 757 #if ENABLE_FEATURE_TAR_FROM … … 680 769 if (cp > line) 681 770 *cp = '\0'; 682 llist_add_to (&newlist, line);771 llist_add_to_end(&newlist, line); 683 772 } 684 773 fclose(src_stream); … … 686 775 return newlist; 687 776 } 688 #else689 # define append_file_list_to_list(x) 0690 777 #endif 691 778 … … 774 861 IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,) 775 862 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 863 OPTBIT_STRIP_COMPONENTS, 776 864 OPTBIT_NORECURSION, 777 865 IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,) … … 798 886 OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J 799 887 OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z 800 OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m 801 OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion 802 OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command 803 OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner 804 OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions 805 OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite 888 OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m 889 OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components 890 OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion 891 OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command 892 OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner 893 OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions 894 OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite 806 895 807 896 OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS), … … 847 936 "touch\0" No_argument "m" 848 937 # endif 938 "strip-components\0" Required_argument "\xf9" 849 939 "no-recursion\0" No_argument "\xfa" 850 940 # if ENABLE_FEATURE_TAR_TO_COMMAND … … 876 966 llist_t *excludes = NULL; 877 967 #endif 968 INIT_G(); 878 969 879 970 /* Initialise default values */ … … 892 983 IF_FEATURE_TAR_FROM("X::T::") // cumulative lists 893 984 #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM 894 "\xff::" // cumulative lists for --exclude985 "\xff::" // --exclude=PATTERN is a list 895 986 #endif 896 987 IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd 897 988 IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive 898 IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive 989 IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive 990 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 991 ":\xf9+" // --strip-components=NUM 992 #endif 993 ; 899 994 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 900 995 applet_long_options = tar_longopts; 901 996 #endif 902 997 #if ENABLE_DESKTOP 998 /* Lie to buildroot when it starts asking stupid questions. */ 999 if (argv[1] && strcmp(argv[1], "--version") == 0) { 1000 // Output of 'tar --version' examples: 1001 // tar (GNU tar) 1.15.1 1002 // tar (GNU tar) 1.25 1003 // bsdtar 2.8.3 - libarchive 2.8.3 1004 puts("tar (busybox) " BB_VER); 1005 return 0; 1006 } 903 1007 if (argv[1] && argv[1][0] != '-') { 904 1008 /* Compat: … … 937 1041 IF_FEATURE_SEAMLESS_Z( "Z" ) 938 1042 IF_FEATURE_TAR_NOPRESERVE_TIME("m") 1043 IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components 939 1044 , &base_dir // -C dir 940 1045 , &tar_filename // -f filename 941 1046 IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T 942 1047 IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X 1048 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 1049 , &tar_handle->tar__strip_components // --strip-components 1050 #endif 943 1051 IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command 944 1052 #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM … … 948 1056 , &verboseFlag // combined count for -t and -v 949 1057 ); 950 //bb_error_msg("opt:%08x", opt); 1058 #if DBG_OPTION_PARSING 1059 bb_error_msg("opt: 0x%08x", opt); 1060 # define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o); 1061 showopt(OPT_TEST ); 1062 showopt(OPT_EXTRACT ); 1063 showopt(OPT_BASEDIR ); 1064 showopt(OPT_TARNAME ); 1065 showopt(OPT_2STDOUT ); 1066 showopt(OPT_NOPRESERVE_OWNER); 1067 showopt(OPT_P ); 1068 showopt(OPT_VERBOSE ); 1069 showopt(OPT_KEEP_OLD ); 1070 showopt(OPT_CREATE ); 1071 showopt(OPT_DEREFERENCE ); 1072 showopt(OPT_BZIP2 ); 1073 showopt(OPT_LZMA ); 1074 showopt(OPT_INCLUDE_FROM ); 1075 showopt(OPT_EXCLUDE_FROM ); 1076 showopt(OPT_GZIP ); 1077 showopt(OPT_XZ ); 1078 showopt(OPT_COMPRESS ); 1079 showopt(OPT_NOPRESERVE_TIME ); 1080 showopt(OPT_STRIP_COMPONENTS); 1081 showopt(OPT_NORECURSION ); 1082 showopt(OPT_2COMMAND ); 1083 showopt(OPT_NUMERIC_OWNER ); 1084 showopt(OPT_NOPRESERVE_PERM ); 1085 showopt(OPT_OVERWRITE ); 1086 showopt(OPT_ANY_COMPRESS ); 1087 bb_error_msg("base_dir:'%s'", base_dir); 1088 bb_error_msg("tar_filename:'%s'", tar_filename); 1089 bb_error_msg("verboseFlag:%d", verboseFlag); 1090 bb_error_msg("tar_handle->tar__to_command:'%s'", tar_handle->tar__to_command); 1091 bb_error_msg("tar_handle->tar__strip_components:%u", tar_handle->tar__strip_components); 1092 return 0; 1093 # undef showopt 1094 #endif 951 1095 argv += optind; 952 1096 953 if (verboseFlag) tar_handle->action_header = header_verbose_list; 954 if (verboseFlag == 1) tar_handle->action_header = header_list; 1097 if (verboseFlag) 1098 tar_handle->action_header = header_verbose_list; 1099 if (verboseFlag == 1) 1100 tar_handle->action_header = header_list; 955 1101 956 1102 if (opt & OPT_EXTRACT) … … 1038 1184 && !(opt & OPT_ANY_COMPRESS) 1039 1185 ) { 1040 tar_handle->src_fd = open_zipped(tar_filename );1186 tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0); 1041 1187 if (tar_handle->src_fd < 0) 1042 1188 bb_perror_msg_and_die("can't open '%s'", tar_filename); … … 1050 1196 xchdir(base_dir); 1051 1197 1052 //if (SEAMLESS_COMPRESSION || OPT_COMPRESS)1198 //if (SEAMLESS_COMPRESSION) 1053 1199 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ 1054 1200 // signal(SIGCHLD, check_errors_in_children); 1055 1201 1202 #if ENABLE_FEATURE_TAR_CREATE 1056 1203 /* Create an archive */ 1057 1204 if (opt & OPT_CREATE) { 1058 #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 1059 int zipMode = 0; 1060 if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP)) 1061 zipMode = 1; 1062 if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2)) 1063 zipMode = 2; 1064 #endif 1205 # if SEAMLESS_COMPRESSION 1206 const char *zipMode = NULL; 1207 if (opt & OPT_COMPRESS) 1208 zipMode = "compress"; 1209 if (opt & OPT_GZIP) 1210 zipMode = "gzip"; 1211 if (opt & OPT_BZIP2) 1212 zipMode = "bzip2"; 1213 if (opt & OPT_LZMA) 1214 zipMode = "lzma"; 1215 if (opt & OPT_XZ) 1216 zipMode = "xz"; 1217 # endif 1065 1218 /* NB: writeTarFile() closes tar_handle->src_fd */ 1066 1219 return writeTarFile(tar_handle->src_fd, verboseFlag, … … 1070 1223 tar_handle->reject, zipMode); 1071 1224 } 1225 #endif 1072 1226 1073 1227 if (opt & OPT_ANY_COMPRESS) { 1074 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_ aux_data_t *aux, int src_fd, int dst_fd);)1228 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);) 1075 1229 USE_FOR_NOMMU(const char *xformer_prog;) 1076 1230 … … 1091 1245 USE_FOR_NOMMU(xformer_prog = "unxz";) 1092 1246 1093 open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);1247 fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog); 1094 1248 /* Can't lseek over pipes */ 1095 1249 tar_handle->seek = seek_by_read; … … 1097 1251 } 1098 1252 1253 /* Zero processed headers (== empty file) is not a valid tarball. 1254 * We (ab)use bb_got_signal as exitcode here, 1255 * because check_errors_in_children() uses _it_ as error indicator. 1256 */ 1257 bb_got_signal = EXIT_FAILURE; 1258 1099 1259 while (get_header_tar(tar_handle) == EXIT_SUCCESS) 1100 continue;1260 bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */ 1101 1261 1102 1262 /* Check that every file that should have been extracted was */ … … 1114 1274 1115 1275 if (SEAMLESS_COMPRESSION || OPT_COMPRESS) { 1276 /* Set bb_got_signal to 1 if a child died with !0 exitcode */ 1116 1277 check_errors_in_children(0); 1117 return bb_got_signal;1118 } 1119 return EXIT_SUCCESS;1278 } 1279 1280 return bb_got_signal; 1120 1281 } -
branches/3.3/mindi-busybox/archival/unzip.c
r3232 r3621 10 10 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 11 11 */ 12 13 12 /* For reference see 14 13 * http://www.pkware.com/company/standards/appnote/ 15 14 * http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip 16 */ 17 18 /* TODO 15 * 16 * TODO 19 17 * Zip64 + other methods 20 18 */ 19 20 //config:config UNZIP 21 //config: bool "unzip" 22 //config: default y 23 //config: help 24 //config: unzip will list or extract files from a ZIP archive, 25 //config: commonly found on DOS/WIN systems. The default behavior 26 //config: (with no options) is to extract the archive into the 27 //config: current directory. Use the `-d' option to extract to a 28 //config: directory of your choice. 29 30 //applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP)) 31 //kbuild:lib-$(CONFIG_UNZIP) += unzip.o 21 32 22 33 //usage:#define unzip_trivial_usage … … 34 45 #include "libbb.h" 35 46 #include "bb_archive.h" 47 48 #if 0 49 # define dbg(...) bb_error_msg(__VA_ARGS__) 50 #else 51 # define dbg(...) ((void)0) 52 #endif 36 53 37 54 enum { … … 164 181 #if ENABLE_DESKTOP 165 182 166 #define PEEK_FROM_END 16384 183 /* Seen in the wild: 184 * Self-extracting PRO2K3XP_32.exe contains 19078464 byte zip archive, 185 * where CDE was nearly 48 kbytes before EOF. 186 * (Surprisingly, it also apparently has *another* CDE structure 187 * closer to the end, with bogus cdf_offset). 188 * To make extraction work, bumped PEEK_FROM_END from 16k to 64k. 189 */ 190 #define PEEK_FROM_END (64*1024) 191 192 /* This value means that we failed to find CDF */ 193 #define BAD_CDF_OFFSET ((uint32_t)0xffffffff) 167 194 168 195 /* NB: does not preserve file position! */ … … 173 200 off_t end; 174 201 unsigned char *buf = xzalloc(PEEK_FROM_END); 202 uint32_t found; 175 203 176 204 end = xlseek(zip_fd, 0, SEEK_END); … … 178 206 if (end < 0) 179 207 end = 0; 180 xlseek(zip_fd, end, SEEK_SET); 208 dbg("Looking for cdf_offset starting from 0x%"OFF_FMT"x", end); 209 xlseek(zip_fd, end, SEEK_SET); 181 210 full_read(zip_fd, buf, PEEK_FROM_END); 182 211 212 found = BAD_CDF_OFFSET; 183 213 p = buf; 184 214 while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) { … … 196 226 memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN); 197 227 FIX_ENDIANNESS_CDE(cde_header); 198 free(buf); 199 return cde_header.formatted.cdf_offset; 200 } 201 //free(buf); 202 bb_error_msg_and_die("can't find file table"); 228 /* 229 * I've seen .ZIP files with seemingly valid CDEs 230 * where cdf_offset points past EOF - ?? 231 * This check ignores such CDEs: 232 */ 233 if (cde_header.formatted.cdf_offset < end + (p - buf)) { 234 found = cde_header.formatted.cdf_offset; 235 dbg("Possible cdf_offset:0x%x at 0x%"OFF_FMT"x", 236 (unsigned)found, end + (p-3 - buf)); 237 dbg(" cdf_offset+cdf_size:0x%x", 238 (unsigned)(found + SWAP_LE32(cde_header.formatted.cdf_size))); 239 /* 240 * We do not "break" here because only the last CDE is valid. 241 * I've seen a .zip archive which contained a .zip file, 242 * uncompressed, and taking the first CDE was using 243 * the CDE inside that file! 244 */ 245 } 246 } 247 free(buf); 248 dbg("Found cdf_offset:0x%x", (unsigned)found); 249 return found; 203 250 }; 204 251 … … 212 259 cdf_offset = find_cdf_offset(); 213 260 214 xlseek(zip_fd, cdf_offset + 4, SEEK_SET); 215 xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN); 216 FIX_ENDIANNESS_CDF(*cdf_ptr); 217 cdf_offset += 4 + CDF_HEADER_LEN 218 + cdf_ptr->formatted.file_name_length 219 + cdf_ptr->formatted.extra_field_length 220 + cdf_ptr->formatted.file_comment_length; 221 261 if (cdf_offset != BAD_CDF_OFFSET) { 262 dbg("Reading CDF at 0x%x", (unsigned)cdf_offset); 263 xlseek(zip_fd, cdf_offset + 4, SEEK_SET); 264 xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN); 265 FIX_ENDIANNESS_CDF(*cdf_ptr); 266 dbg(" file_name_length:%u extra_field_length:%u file_comment_length:%u", 267 (unsigned)cdf_ptr->formatted.file_name_length, 268 (unsigned)cdf_ptr->formatted.extra_field_length, 269 (unsigned)cdf_ptr->formatted.file_comment_length 270 ); 271 cdf_offset += 4 + CDF_HEADER_LEN 272 + cdf_ptr->formatted.file_name_length 273 + cdf_ptr->formatted.extra_field_length 274 + cdf_ptr->formatted.file_comment_length; 275 } 276 277 dbg("Returning file position to 0x%"OFF_FMT"x", org); 222 278 xlseek(zip_fd, org, SEEK_SET); 223 279 return cdf_offset; … … 227 283 static void unzip_skip(off_t skip) 228 284 { 229 if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1) 230 bb_copyfd_exact_size(zip_fd, -1, skip); 285 if (skip != 0) 286 if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1) 287 bb_copyfd_exact_size(zip_fd, -1, skip); 231 288 } 232 289 … … 250 307 } else { 251 308 /* Method 8 - inflate */ 252 transformer_aux_data_t aux; 253 init_transformer_aux_data(&aux); 254 aux.bytes_in = zip_header->formatted.cmpsize; 255 if (inflate_unzip(&aux, zip_fd, dst_fd) < 0) 309 transformer_state_t xstate; 310 init_transformer_state(&xstate); 311 xstate.bytes_in = zip_header->formatted.cmpsize; 312 xstate.src_fd = zip_fd; 313 xstate.dst_fd = dst_fd; 314 if (inflate_unzip(&xstate) < 0) 256 315 bb_error_msg_and_die("inflate error"); 257 316 /* Validate decompression - crc */ 258 if (zip_header->formatted.crc32 != ( aux.crc32 ^ 0xffffffffL)) {317 if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) { 259 318 bb_error_msg_and_die("crc error"); 260 319 } 261 320 /* Validate decompression - size */ 262 if (zip_header->formatted.ucmpsize != aux.bytes_out) {321 if (zip_header->formatted.ucmpsize != xstate.bytes_out) { 263 322 /* Don't die. Who knows, maybe len calculation 264 323 * was botched somewhere. After all, crc matched! */ 265 324 bb_error_msg("bad length"); 266 325 } 326 } 327 } 328 329 static void my_fgets80(char *buf80) 330 { 331 fflush_all(); 332 if (!fgets(buf80, 80, stdin)) { 333 bb_perror_msg_and_die("can't read standard input"); 267 334 } 268 335 } … … 292 359 char *base_dir = NULL; 293 360 int i, opt; 294 char key_buf[80]; 361 char key_buf[80]; /* must match size used by my_fgets80 */ 295 362 struct stat stat_buf; 296 363 … … 421 488 overwrite = O_NEVER; 422 489 } else { 423 static const char extn[][5] = { ".zip", ".ZIP" };490 static const char extn[][5] ALIGN1 = { ".zip", ".ZIP" }; 424 491 char *ext = src_fn + strlen(src_fn); 425 492 int src_fd; … … 448 515 if (listing) { 449 516 puts(verbose ? 450 " Length Method Size Ratio Date Time CRC-32Name\n"451 "-------- ------ ------- ---- - ---- ---- ----------"517 " Length Method Size Cmpr Date Time CRC-32 Name\n" 518 "-------- ------ ------- ---- ---------- ----- -------- ----" 452 519 : 453 " Length DateTime Name\n"454 " -------- ---- --------"520 " Length Date Time Name\n" 521 "--------- ---------- ----- ----" 455 522 ); 456 523 } … … 492 559 xread(zip_fd, &magic, 4); 493 560 /* Central directory? It's at the end, so exit */ 494 if (magic == ZIP_CDF_MAGIC) 495 break; 561 if (magic == ZIP_CDF_MAGIC) { 562 dbg("got ZIP_CDF_MAGIC"); 563 break; 564 } 496 565 #if ENABLE_DESKTOP 497 566 /* Data descriptor? It was a streaming file, go on */ 498 567 if (magic == ZIP_DD_MAGIC) { 568 dbg("got ZIP_DD_MAGIC"); 499 569 /* skip over duplicate crc32, cmpsize and ucmpsize */ 500 570 unzip_skip(3 * 4); … … 504 574 if (magic != ZIP_FILEHEADER_MAGIC) 505 575 bb_error_msg_and_die("invalid zip magic %08X", (int)magic); 576 dbg("got ZIP_FILEHEADER_MAGIC"); 506 577 507 578 /* Read the file header */ … … 521 592 } 522 593 523 {594 if (cdf_offset != BAD_CDF_OFFSET) { 524 595 cdf_header_t cdf_header; 525 596 cdf_offset = read_next_cdf(cdf_offset, &cdf_header); 597 /* 598 * Note: cdf_offset can become BAD_CDF_OFFSET after the above call. 599 */ 526 600 if (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) { 527 601 /* 0x0008 - streaming. [u]cmpsize can be reliably gotten 528 * only from Central Directory. See unzip_doc.txt */ 602 * only from Central Directory. See unzip_doc.txt 603 */ 529 604 zip_header.formatted.crc32 = cdf_header.formatted.crc32; 530 605 zip_header.formatted.cmpsize = cdf_header.formatted.cmpsize; … … 532 607 } 533 608 if ((cdf_header.formatted.version_made_by >> 8) == 3) { 534 /* this archive is created on Unix */609 /* This archive is created on Unix */ 535 610 dir_mode = file_mode = (cdf_header.formatted.external_file_attributes >> 16); 536 611 } 537 612 } 538 #endif 613 if (cdf_offset == BAD_CDF_OFFSET 614 && (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) 615 ) { 616 /* If it's a streaming zip, we _require_ CDF */ 617 bb_error_msg_and_die("can't find file table"); 618 } 619 #endif 620 dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x", 621 (unsigned)zip_header.formatted.cmpsize, 622 (unsigned)zip_header.formatted.extra_len, 623 (unsigned)zip_header.formatted.ucmpsize 624 ); 539 625 540 626 /* Read filename */ … … 545 631 /* Skip extra header bytes */ 546 632 unzip_skip(zip_header.formatted.extra_len); 633 634 /* Guard against "/abspath", "/../" and similar attacks */ 635 overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn)); 547 636 548 637 /* Filter zip entries */ … … 551 640 ) { /* Skip entry */ 552 641 i = 'n'; 553 554 } else { /* Extract entry */ 555 if (listing) { /* List entry */ 556 unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); 642 } else { 643 if (listing) { 644 /* List entry */ 645 char dtbuf[sizeof("mm-dd-yyyy hh:mm")]; 646 sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u", 647 (zip_header.formatted.moddate >> 5) & 0xf, // mm: 0x01e0 648 (zip_header.formatted.moddate) & 0x1f, // dd: 0x001f 649 (zip_header.formatted.moddate >> 9) + 1980, // yy: 0xfe00 650 (zip_header.formatted.modtime >> 11), // hh: 0xf800 651 (zip_header.formatted.modtime >> 5) & 0x3f // mm: 0x07e0 652 // seconds/2 are not shown, encoded in ----------- 0x001f 653 ); 557 654 if (!verbose) { 558 // " Length DateTime Name\n"559 // " -------- ---- --------"560 printf( "%9u %02u-%02u-%02u %02u:%02u%s\n",655 // " Length Date Time Name\n" 656 // "--------- ---------- ----- ----" 657 printf( "%9u " "%s " "%s\n", 561 658 (unsigned)zip_header.formatted.ucmpsize, 562 (dostime & 0x01e00000) >> 21, 563 (dostime & 0x001f0000) >> 16, 564 (((dostime & 0xfe000000) >> 25) + 1980) % 100, 565 (dostime & 0x0000f800) >> 11, 566 (dostime & 0x000007e0) >> 5, 659 dtbuf, 567 660 dst_fn); 568 total_usize += zip_header.formatted.ucmpsize;569 661 } else { 570 662 unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; 663 if ((int32_t)percents < 0) 664 percents = 0; /* happens if ucmpsize < cmpsize */ 571 665 percents = percents * 100; 572 666 if (zip_header.formatted.ucmpsize) 573 667 percents /= zip_header.formatted.ucmpsize; 574 // " Length Method Size Ratio Date Time CRC-32Name\n"575 // "-------- ------ ------- ---- - ---- ---- ----------"576 printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x%s\n",668 // " Length Method Size Cmpr Date Time CRC-32 Name\n" 669 // "-------- ------ ------- ---- ---------- ----- -------- ----" 670 printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n", 577 671 (unsigned)zip_header.formatted.ucmpsize, 672 zip_header.formatted.method == 0 ? "Stored" : "Defl:N", /* Defl is method 8 */ 673 /* TODO: show other methods? 674 * 1 - Shrunk 675 * 2 - Reduced with compression factor 1 676 * 3 - Reduced with compression factor 2 677 * 4 - Reduced with compression factor 3 678 * 5 - Reduced with compression factor 4 679 * 6 - Imploded 680 * 7 - Reserved for Tokenizing compression algorithm 681 * 9 - Deflate64 682 * 10 - PKWARE Data Compression Library Imploding 683 * 11 - Reserved by PKWARE 684 * 12 - BZIP2 685 */ 578 686 (unsigned)zip_header.formatted.cmpsize, 579 687 (unsigned)percents, 580 (dostime & 0x01e00000) >> 21, 581 (dostime & 0x001f0000) >> 16, 582 (((dostime & 0xfe000000) >> 25) + 1980) % 100, 583 (dostime & 0x0000f800) >> 11, 584 (dostime & 0x000007e0) >> 5, 688 dtbuf, 585 689 zip_header.formatted.crc32, 586 690 dst_fn); 587 total_usize += zip_header.formatted.ucmpsize;588 691 total_size += zip_header.formatted.cmpsize; 589 692 } 693 total_usize += zip_header.formatted.ucmpsize; 590 694 i = 'n'; 591 } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ 695 } else if (dst_fd == STDOUT_FILENO) { 696 /* Extracting to STDOUT */ 592 697 i = -1; 593 } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ 698 } else if (last_char_is(dst_fn, '/')) { 699 /* Extract directory */ 594 700 if (stat(dst_fn, &stat_buf) == -1) { 595 701 if (errno != ENOENT) { … … 605 711 } else { 606 712 if (!S_ISDIR(stat_buf.st_mode)) { 607 bb_error_msg_and_die("'%s' exists but is not directory", dst_fn); 713 bb_error_msg_and_die("'%s' exists but is not a %s", 714 dst_fn, "directory"); 608 715 } 609 716 } 610 717 i = 'n'; 611 612 } else {/* Extract file */718 } else { 719 /* Extract file */ 613 720 check_file: 614 if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */ 721 if (stat(dst_fn, &stat_buf) == -1) { 722 /* File does not exist */ 615 723 if (errno != ENOENT) { 616 724 bb_perror_msg_and_die("can't stat '%s'", dst_fn); 617 725 } 618 726 i = 'y'; 619 } else { /* File already exists */ 727 } else { 728 /* File already exists */ 620 729 if (overwrite == O_NEVER) { 621 730 i = 'n'; 622 } else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */ 731 } else if (S_ISREG(stat_buf.st_mode)) { 732 /* File is regular file */ 623 733 if (overwrite == O_ALWAYS) { 624 734 i = 'y'; 625 735 } else { 626 736 printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn); 627 fflush_all(); 628 if (!fgets(key_buf, sizeof(key_buf), stdin)) { 629 bb_perror_msg_and_die("can't read input"); 630 } 737 my_fgets80(key_buf); 631 738 i = key_buf[0]; 632 739 } 633 } else { /* File is not regular file */ 634 bb_error_msg_and_die("'%s' exists but is not regular file", dst_fn); 740 } else { 741 /* File is not regular file */ 742 bb_error_msg_and_die("'%s' exists but is not a %s", 743 dst_fn, "regular file"); 635 744 } 636 745 } … … 669 778 /* Prompt for new name */ 670 779 printf("new name: "); 671 if (!fgets(key_buf, sizeof(key_buf), stdin)) { 672 bb_perror_msg_and_die("can't read input"); 673 } 780 my_fgets80(key_buf); 674 781 free(dst_fn); 675 782 dst_fn = xstrdup(key_buf); … … 687 794 if (listing && quiet <= 1) { 688 795 if (!verbose) { 689 // " Length Date Time Name\n" 690 // " -------- ---- ---- ----" 691 printf( " -------- -------\n" 692 "%9lu" " %u files\n", 693 total_usize, total_entries); 796 // " Length Date Time Name\n" 797 // "--------- ---------- ----- ----" 798 printf( " --------%21s" "-------\n" 799 "%9lu%21s" "%u files\n", 800 "", 801 total_usize, "", total_entries); 694 802 } else { 695 803 unsigned long percents = total_usize - total_size; 804 if ((long)percents < 0) 805 percents = 0; /* happens if usize < size */ 696 806 percents = percents * 100; 697 807 if (total_usize) 698 808 percents /= total_usize; 699 // " Length Method Size Ratio Date Time CRC-32 Name\n" 700 // "-------- ------ ------- ----- ---- ---- ------ ----" 701 printf( "-------- ------- --- -------\n" 702 "%8lu" "%17lu%4u%% %u files\n", 703 total_usize, total_size, (unsigned)percents, 809 // " Length Method Size Cmpr Date Time CRC-32 Name\n" 810 // "-------- ------ ------- ---- ---------- ----- -------- ----" 811 printf( "-------- ------- ----%28s" "----\n" 812 "%8lu" "%17lu%4u%%%28s" "%u files\n", 813 "", 814 total_usize, total_size, (unsigned)percents, "", 704 815 total_entries); 705 816 }
Note:
See TracChangeset
for help on using the changeset viewer.