diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-05 13:10:34 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-05 13:10:34 +0000 |
commit | e9ad84dfd4c7eb2936374f02989dacf7026a7276 (patch) | |
tree | 37412d21c0a2ccec7c162e0fb42833058f5934e3 /archival/libunarchive | |
parent | 9b44613202a6f2f080ec23746d0680dcef88628d (diff) | |
download | busybox-w32-e9ad84dfd4c7eb2936374f02989dacf7026a7276.tar.gz busybox-w32-e9ad84dfd4c7eb2936374f02989dacf7026a7276.tar.bz2 busybox-w32-e9ad84dfd4c7eb2936374f02989dacf7026a7276.zip |
*: refactor handling of archived files. "tar f file.tar.lzma" now works too.
function old new delta
unpack_Z_stream - 1229 +1229
open_zipped - 176 +176
unpack_bz2_stream_prime - 60 +60
tar_main 642 677 +35
find_main 406 418 +12
sv_main 1222 1233 +11
decode_format_string 829 837 +8
cmp_main 641 649 +8
popstring 134 140 +6
filter_accept_list_reassign 120 125 +5
parse_and_put_prompt 800 804 +4
passwd_main 1053 1049 -4
make_new_name_gunzip 119 114 -5
rpm_main 1688 1670 -18
prepare 302 283 -19
xmalloc_open_zipped_read_close 135 61 -74
uncompress 1229 - -1229
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 8/5 up/down: 1554/-1349) Total: 205 bytes
Diffstat (limited to 'archival/libunarchive')
-rw-r--r-- | archival/libunarchive/Kbuild | 26 | ||||
-rw-r--r-- | archival/libunarchive/decompress_bunzip2.c | 29 | ||||
-rw-r--r-- | archival/libunarchive/decompress_uncompress.c | 8 | ||||
-rw-r--r-- | archival/libunarchive/filter_accept_list_reassign.c | 15 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 4 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar_bz2.c | 2 |
6 files changed, 46 insertions, 38 deletions
diff --git a/archival/libunarchive/Kbuild b/archival/libunarchive/Kbuild index 468a7e82a..364f9174c 100644 --- a/archival/libunarchive/Kbuild +++ b/archival/libunarchive/Kbuild | |||
@@ -32,36 +32,20 @@ DPKG_FILES:= \ | |||
32 | get_header_tar.o \ | 32 | get_header_tar.o \ |
33 | filter_accept_list_reassign.o | 33 | filter_accept_list_reassign.o |
34 | 34 | ||
35 | lib-$(CONFIG_RPM) += open_transformer.o | ||
36 | lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o | ||
37 | lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o | ||
38 | lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o | ||
39 | lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o | ||
40 | lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o | ||
41 | lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o | ||
42 | lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o | ||
43 | |||
44 | lib-$(CONFIG_FEATURE_MODPROBE_SMALL_ZIPPED) += open_transformer.o decompress_unzip.o decompress_bunzip2.o | ||
45 | |||
46 | lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o | 35 | lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o |
47 | lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o | 36 | lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o |
48 | lib-$(CONFIG_UNLZMA) += decompress_unlzma.o | 37 | lib-$(CONFIG_UNLZMA) += decompress_unlzma.o |
49 | lib-$(CONFIG_CPIO) += get_header_cpio.o | 38 | lib-$(CONFIG_CPIO) += get_header_cpio.o |
50 | lib-$(CONFIG_DPKG) += $(DPKG_FILES) | 39 | lib-$(CONFIG_DPKG) += $(DPKG_FILES) |
51 | lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) | 40 | lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) |
52 | lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += decompress_unzip.o get_header_tar_gz.o | ||
53 | lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o | ||
54 | lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o | ||
55 | lib-$(CONFIG_GUNZIP) += decompress_unzip.o | 41 | lib-$(CONFIG_GUNZIP) += decompress_unzip.o |
56 | lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o | ||
57 | lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o | 42 | lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o |
58 | lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o | 43 | lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o |
59 | lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o | ||
60 | lib-$(CONFIG_TAR) += get_header_tar.o | 44 | lib-$(CONFIG_TAR) += get_header_tar.o |
61 | lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o | ||
62 | lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o | ||
63 | lib-$(CONFIG_FEATURE_TAR_GZIP) += decompress_unzip.o get_header_tar_gz.o | ||
64 | lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o | ||
65 | lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o | 45 | lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o |
66 | lib-$(CONFIG_UNZIP) += decompress_unzip.o | 46 | lib-$(CONFIG_UNZIP) += decompress_unzip.o |
47 | lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o | ||
48 | lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_unzip.o get_header_tar_gz.o | ||
49 | lib-$(CONFIG_FEATURE_SEAMLESS_BZ2) += open_transformer.o decompress_bunzip2.o get_header_tar_bz2.o | ||
50 | lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.o get_header_tar_lzma.o | ||
67 | lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o | 51 | lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o |
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c index 654dc28a9..b53720f23 100644 --- a/archival/libunarchive/decompress_bunzip2.c +++ b/archival/libunarchive/decompress_bunzip2.c | |||
@@ -590,7 +590,8 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *in | |||
590 | bunzip_data *bd; | 590 | bunzip_data *bd; |
591 | unsigned i; | 591 | unsigned i; |
592 | enum { | 592 | enum { |
593 | BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0' | 593 | BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0', |
594 | h0 = ('h' << 8) + '0', | ||
594 | }; | 595 | }; |
595 | 596 | ||
596 | /* Figure out how much data to allocate */ | 597 | /* Figure out how much data to allocate */ |
@@ -617,12 +618,18 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *in | |||
617 | if (i) return i; | 618 | if (i) return i; |
618 | 619 | ||
619 | /* Ensure that file starts with "BZh['1'-'9']." */ | 620 | /* Ensure that file starts with "BZh['1'-'9']." */ |
620 | i = get_bits(bd, 32); | 621 | /* Update: now caller verifies 1st two bytes, makes .gz/.bz2 |
621 | if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA; | 622 | * integration easier */ |
623 | /* was: */ | ||
624 | /* i = get_bits(bd, 32); */ | ||
625 | /* if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA; */ | ||
626 | i = get_bits(bd, 16); | ||
627 | if ((unsigned)(i - h0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA; | ||
622 | 628 | ||
623 | /* Fourth byte (ascii '1'-'9') indicates block size in units of 100k of | 629 | /* Fourth byte (ascii '1'-'9') indicates block size in units of 100k of |
624 | uncompressed data. Allocate intermediate buffer for block. */ | 630 | uncompressed data. Allocate intermediate buffer for block. */ |
625 | bd->dbufSize = 100000 * (i - BZh0); | 631 | /* bd->dbufSize = 100000 * (i - BZh0); */ |
632 | bd->dbufSize = 100000 * (i - h0); | ||
626 | 633 | ||
627 | /* Cannot use xmalloc - may leak bd in NOFORK case! */ | 634 | /* Cannot use xmalloc - may leak bd in NOFORK case! */ |
628 | bd->dbuf = malloc_or_warn(bd->dbufSize * sizeof(int)); | 635 | bd->dbuf = malloc_or_warn(bd->dbufSize * sizeof(int)); |
@@ -682,6 +689,17 @@ unpack_bz2_stream(int src_fd, int dst_fd) | |||
682 | return i ? i : USE_DESKTOP(total_written) + 0; | 689 | return i ? i : USE_DESKTOP(total_written) + 0; |
683 | } | 690 | } |
684 | 691 | ||
692 | USE_DESKTOP(long long) int FAST_FUNC | ||
693 | unpack_bz2_stream_prime(int src_fd, int dst_fd) | ||
694 | { | ||
695 | unsigned char magic[2]; | ||
696 | xread(src_fd, magic, 2); | ||
697 | if (magic[0] != 'B' || magic[1] != 'Z') { | ||
698 | bb_error_msg_and_die("invalid magic"); | ||
699 | } | ||
700 | return unpack_bz2_stream(src_fd, dst_fd); | ||
701 | } | ||
702 | |||
685 | #ifdef TESTING | 703 | #ifdef TESTING |
686 | 704 | ||
687 | static char *const bunzip_errors[] = { | 705 | static char *const bunzip_errors[] = { |
@@ -693,9 +711,10 @@ static char *const bunzip_errors[] = { | |||
693 | /* Dumb little test thing, decompress stdin to stdout */ | 711 | /* Dumb little test thing, decompress stdin to stdout */ |
694 | int main(int argc, char **argv) | 712 | int main(int argc, char **argv) |
695 | { | 713 | { |
696 | int i = unpack_bz2_stream(0, 1); | 714 | int i; |
697 | char c; | 715 | char c; |
698 | 716 | ||
717 | int i = unpack_bz2_stream_prime(0, 1); | ||
699 | if (i < 0) | 718 | if (i < 0) |
700 | fprintf(stderr, "%s\n", bunzip_errors[-i]); | 719 | fprintf(stderr, "%s\n", bunzip_errors[-i]); |
701 | else if (read(STDIN_FILENO, &c, 1)) | 720 | else if (read(STDIN_FILENO, &c, 1)) |
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c index 161570040..fe1491e71 100644 --- a/archival/libunarchive/decompress_uncompress.c +++ b/archival/libunarchive/decompress_uncompress.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | #include "libbb.h" | ||
3 | |||
4 | /* uncompress for busybox -- (c) 2002 Robert Griebl | 2 | /* uncompress for busybox -- (c) 2002 Robert Griebl |
5 | * | 3 | * |
6 | * based on the original compress42.c source | 4 | * based on the original compress42.c source |
@@ -26,6 +24,10 @@ | |||
26 | * | 24 | * |
27 | */ | 25 | */ |
28 | 26 | ||
27 | #include "libbb.h" | ||
28 | #include "unarchive.h" | ||
29 | |||
30 | |||
29 | /* Default input buffer size */ | 31 | /* Default input buffer size */ |
30 | #define IBUFSIZ 2048 | 32 | #define IBUFSIZ 2048 |
31 | 33 | ||
@@ -71,7 +73,7 @@ | |||
71 | */ | 73 | */ |
72 | 74 | ||
73 | USE_DESKTOP(long long) int FAST_FUNC | 75 | USE_DESKTOP(long long) int FAST_FUNC |
74 | uncompress(int fd_in, int fd_out) | 76 | unpack_Z_stream(int fd_in, int fd_out) |
75 | { | 77 | { |
76 | USE_DESKTOP(long long total_written = 0;) | 78 | USE_DESKTOP(long long total_written = 0;) |
77 | USE_DESKTOP(long long) int retval = -1; | 79 | USE_DESKTOP(long long) int retval = -1; |
diff --git a/archival/libunarchive/filter_accept_list_reassign.c b/archival/libunarchive/filter_accept_list_reassign.c index 4dbc2d13e..f1de4e803 100644 --- a/archival/libunarchive/filter_accept_list_reassign.c +++ b/archival/libunarchive/filter_accept_list_reassign.c | |||
@@ -23,22 +23,25 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle) | |||
23 | 23 | ||
24 | /* Find extension */ | 24 | /* Find extension */ |
25 | name_ptr = strrchr(archive_handle->file_header->name, '.'); | 25 | name_ptr = strrchr(archive_handle->file_header->name, '.'); |
26 | if (!name_ptr) | ||
27 | return EXIT_FAILURE; | ||
28 | name_ptr++; | ||
26 | 29 | ||
27 | /* Modify the subarchive handler based on the extension */ | 30 | /* Modify the subarchive handler based on the extension */ |
28 | if (ENABLE_FEATURE_DEB_TAR_GZ | 31 | if (ENABLE_FEATURE_SEAMLESS_GZ |
29 | && strcmp(name_ptr, ".gz") == 0 | 32 | && strcmp(name_ptr, "gz") == 0 |
30 | ) { | 33 | ) { |
31 | archive_handle->action_data_subarchive = get_header_tar_gz; | 34 | archive_handle->action_data_subarchive = get_header_tar_gz; |
32 | return EXIT_SUCCESS; | 35 | return EXIT_SUCCESS; |
33 | } | 36 | } |
34 | if (ENABLE_FEATURE_DEB_TAR_BZ2 | 37 | if (ENABLE_FEATURE_SEAMLESS_BZ2 |
35 | && strcmp(name_ptr, ".bz2") == 0 | 38 | && strcmp(name_ptr, "bz2") == 0 |
36 | ) { | 39 | ) { |
37 | archive_handle->action_data_subarchive = get_header_tar_bz2; | 40 | archive_handle->action_data_subarchive = get_header_tar_bz2; |
38 | return EXIT_SUCCESS; | 41 | return EXIT_SUCCESS; |
39 | } | 42 | } |
40 | if (ENABLE_FEATURE_DEB_TAR_LZMA | 43 | if (ENABLE_FEATURE_SEAMLESS_LZMA |
41 | && strcmp(name_ptr, ".lzma") == 0 | 44 | && strcmp(name_ptr, "lzma") == 0 |
42 | ) { | 45 | ) { |
43 | archive_handle->action_data_subarchive = get_header_tar_lzma; | 46 | archive_handle->action_data_subarchive = get_header_tar_lzma; |
44 | return EXIT_SUCCESS; | 47 | return EXIT_SUCCESS; |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 5310f3f7c..bf0f92b25 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -148,12 +148,12 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
148 | * we can switch to get_header_tar_gz/bz2/lzma(). | 148 | * we can switch to get_header_tar_gz/bz2/lzma(). |
149 | * Needs seekable fd. I wish recv(MSG_PEEK) works | 149 | * Needs seekable fd. I wish recv(MSG_PEEK) works |
150 | * on any fd... */ | 150 | * on any fd... */ |
151 | #if ENABLE_FEATURE_TAR_GZIP | 151 | #if ENABLE_FEATURE_SEAMLESS_GZ |
152 | if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ | 152 | if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ |
153 | get_header_ptr = get_header_tar_gz; | 153 | get_header_ptr = get_header_tar_gz; |
154 | } else | 154 | } else |
155 | #endif | 155 | #endif |
156 | #if ENABLE_FEATURE_TAR_BZIP2 | 156 | #if ENABLE_FEATURE_SEAMLESS_BZ2 |
157 | if (tar.name[0] == 'B' && tar.name[1] == 'Z' | 157 | if (tar.name[0] == 'B' && tar.name[1] == 'Z' |
158 | && tar.name[2] == 'h' && isdigit(tar.name[3]) | 158 | && tar.name[2] == 'h' && isdigit(tar.name[3]) |
159 | ) { /* bzip2 */ | 159 | ) { /* bzip2 */ |
diff --git a/archival/libunarchive/get_header_tar_bz2.c b/archival/libunarchive/get_header_tar_bz2.c index 035c10bfb..615bbba4a 100644 --- a/archival/libunarchive/get_header_tar_bz2.c +++ b/archival/libunarchive/get_header_tar_bz2.c | |||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle) | |||
11 | /* Can't lseek over pipes */ | 11 | /* Can't lseek over pipes */ |
12 | archive_handle->seek = seek_by_read; | 12 | archive_handle->seek = seek_by_read; |
13 | 13 | ||
14 | open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2"); | 14 | open_transformer(archive_handle->src_fd, unpack_bz2_stream_prime, "bunzip2"); |
15 | archive_handle->offset = 0; | 15 | archive_handle->offset = 0; |
16 | while (get_header_tar(archive_handle) == EXIT_SUCCESS) | 16 | while (get_header_tar(archive_handle) == EXIT_SUCCESS) |
17 | continue; | 17 | continue; |