aboutsummaryrefslogtreecommitdiff
path: root/archival/rpm2cpio.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-05-06 14:19:19 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2010-05-06 14:19:19 +0000
commit27653adc8b7ebe44bd357511de53d0c14eef0894 (patch)
treed1c9b0facbcca408a18d75f93aa507e96927ef31 /archival/rpm2cpio.c
parentb8ba6b66f5d730efcf13dbbb3f9362dd6840d93b (diff)
downloadbusybox-w32-27653adc8b7ebe44bd357511de53d0c14eef0894.tar.gz
busybox-w32-27653adc8b7ebe44bd357511de53d0c14eef0894.tar.bz2
busybox-w32-27653adc8b7ebe44bd357511de53d0c14eef0894.zip
rpm: code shrink. Now uses open_zipped's logic (factored out into setup_unzip_on_fd())
function old new delta setup_unzip_on_fd - 80 +80 open_zipped 176 113 -63 rpm_main 1672 1355 -317 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 80/-380) Total: -300 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/rpm2cpio.c')
-rw-r--r--archival/rpm2cpio.c69
1 files changed, 28 insertions, 41 deletions
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 5403aee02..4ed5b023b 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -8,30 +8,7 @@
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10#include "unarchive.h" 10#include "unarchive.h"
11 11#include "rpm.h"
12#define RPM_MAGIC 0xedabeedb
13#define RPM_MAGIC_STR "\355\253\356\333"
14
15struct rpm_lead {
16 uint32_t magic;
17 uint8_t major, minor;
18 uint16_t type;
19 uint16_t archnum;
20 char name[66];
21 uint16_t osnum;
22 uint16_t signature_type;
23 char reserved[16];
24};
25
26#define RPM_HEADER_MAGICnVER 0x8eade801
27#define RPM_HEADER_MAGIC_STR "\216\255\350"
28
29struct rpm_header {
30 uint32_t magic_and_ver; /* 3 byte magic: 0x8e 0xad 0xe8; 1 byte version */
31 uint32_t reserved; /* 4 bytes reserved */
32 uint32_t entries; /* Number of entries in header (4 bytes) */
33 uint32_t size; /* Size of store (4 bytes) */
34};
35 12
36enum { rpm_fd = STDIN_FILENO }; 13enum { rpm_fd = STDIN_FILENO };
37 14
@@ -65,8 +42,6 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
65{ 42{
66 struct rpm_lead lead; 43 struct rpm_lead lead;
67 unsigned pos; 44 unsigned pos;
68 unsigned char magic[2];
69 IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
70 45
71 if (argv[1]) { 46 if (argv[1]) {
72 xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd); 47 xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
@@ -74,33 +49,45 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
74 xread(rpm_fd, &lead, sizeof(lead)); 49 xread(rpm_fd, &lead, sizeof(lead));
75 50
76 /* Just check the magic, the rest is irrelevant */ 51 /* Just check the magic, the rest is irrelevant */
77 if (lead.magic != htonl(RPM_MAGIC)) { 52 if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
78 bb_error_msg_and_die("invalid RPM magic"); 53 bb_error_msg_and_die("invalid RPM magic");
79 } 54 }
80 55
81 /* Skip the signature header, align to 8 bytes */ 56 /* Skip the signature header, align to 8 bytes */
82 pos = skip_header(); 57 pos = skip_header();
83 seek_by_jump(rpm_fd, (8 - pos) & 7); 58 seek_by_jump(rpm_fd, (-(int)pos) & 7);
84 59
85 /* Skip the main header */ 60 /* Skip the main header */
86 skip_header(); 61 skip_header();
87 62
88 xread(rpm_fd, &magic, 2); 63#if 0
89 unpack = unpack_gz_stream; 64 /* This works, but doesn't report uncompress errors (they happen in child) */
90 if (magic[0] != 0x1f || magic[1] != 0x8b) { 65 setup_unzip_on_fd(rpm_fd /*fail_if_not_detected: 1*/);
91 if (!ENABLE_FEATURE_SEAMLESS_BZ2 66 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
92 || magic[0] != 'B' || magic[1] != 'Z' 67 bb_error_msg_and_die("error unpacking");
93 ) { 68#else
94 bb_error_msg_and_die("invalid gzip" 69 /* BLOAT */
95 IF_FEATURE_SEAMLESS_BZ2("/bzip2") 70 {
96 " magic"); 71 unsigned char magic[2];
72 IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
73
74 xread(rpm_fd, &magic, 2);
75 unpack = unpack_gz_stream;
76 if (magic[0] != 0x1f || magic[1] != 0x8b) {
77 if (!ENABLE_FEATURE_SEAMLESS_BZ2
78 || magic[0] != 'B' || magic[1] != 'Z'
79 ) {
80 bb_error_msg_and_die("invalid gzip"
81 IF_FEATURE_SEAMLESS_BZ2("/bzip2")
82 " magic");
83 }
84 unpack = unpack_bz2_stream;
97 } 85 }
98 unpack = unpack_bz2_stream;
99 }
100 86
101 if (unpack(rpm_fd, STDOUT_FILENO) < 0) { 87 if (unpack(rpm_fd, STDOUT_FILENO) < 0)
102 bb_error_msg_and_die("error unpacking"); 88 bb_error_msg_and_die("error unpacking");
103 } 89 }
90#endif
104 91
105 if (ENABLE_FEATURE_CLEAN_UP) { 92 if (ENABLE_FEATURE_CLEAN_UP) {
106 close(rpm_fd); 93 close(rpm_fd);