aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-10 09:41:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-10 09:41:57 +0200
commite5650a40d4602c9a4ac7f3007d221bfb97dbf25a (patch)
tree2ea24246ebed009615c75df9b617252243db8fa1
parent3fa9262dcd4186a9a5cabb5a7586597187a62565 (diff)
downloadbusybox-w32-e5650a40d4602c9a4ac7f3007d221bfb97dbf25a.tar.gz
busybox-w32-e5650a40d4602c9a4ac7f3007d221bfb97dbf25a.tar.bz2
busybox-w32-e5650a40d4602c9a4ac7f3007d221bfb97dbf25a.zip
rpm: prepare rpm_gettags for reuse in rpm2cpio
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/rpm.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/archival/rpm.c b/archival/rpm.c
index bb6cc4520..461e1707f 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -117,14 +117,15 @@ static void extract_cpio(int fd, const char *source_rpm)
117 continue; 117 continue;
118} 118}
119 119
120static rpm_index *rpm_gettags(int fd) 120static int rpm_gettags(const char *filename)
121{ 121{
122 rpm_index *tags; 122 rpm_index *tags;
123 int fd;
123 unsigned pass, idx; 124 unsigned pass, idx;
124 unsigned storepos; 125 unsigned storepos;
125 126
127 fd = xopen(filename, O_RDONLY);
126 storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ 128 storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
127
128 G.tagcount = 0; 129 G.tagcount = 0;
129 tags = NULL; 130 tags = NULL;
130 idx = 0; 131 idx = 0;
@@ -135,13 +136,13 @@ static rpm_index *rpm_gettags(int fd)
135 136
136 xread(fd, &header, sizeof(header)); 137 xread(fd, &header, sizeof(header));
137 if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) 138 if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))
138 return NULL; /* Invalid magic, or not version 1 */ 139 bb_error_msg_and_die("invalid RPM header magic in '%s'", filename);
139 header.size = ntohl(header.size); 140 header.size = ntohl(header.size);
140 cnt = ntohl(header.entries); 141 cnt = ntohl(header.entries);
141 storepos += sizeof(header) + cnt * 16; 142 storepos += sizeof(header) + cnt * 16;
142 143
143 G.tagcount += cnt; 144 G.tagcount += cnt;
144 tags = xrealloc(tags, G.tagcount * sizeof(tags[0])); 145 tags = xrealloc(tags, sizeof(tags[0]) * G.tagcount);
145 xread(fd, &tags[idx], sizeof(tags[0]) * cnt); 146 xread(fd, &tags[idx], sizeof(tags[0]) * cnt);
146 while (cnt--) { 147 while (cnt--) {
147 rpm_index *tag = &tags[idx]; 148 rpm_index *tag = &tags[idx];
@@ -160,6 +161,7 @@ static rpm_index *rpm_gettags(int fd)
160 /* Seek past store */ 161 /* Seek past store */
161 storepos = xlseek(fd, header.size, SEEK_CUR); 162 storepos = xlseek(fd, header.size, SEEK_CUR);
162 } 163 }
164 G.mytags = tags;
163 165
164 /* Map the store */ 166 /* Map the store */
165 storepos = (storepos + G.pagesize) & -(int)G.pagesize; 167 storepos = (storepos + G.pagesize) & -(int)G.pagesize;
@@ -168,9 +170,9 @@ static rpm_index *rpm_gettags(int fd)
168 /* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */ 170 /* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
169 G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0); 171 G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0);
170 if (G.map == MAP_FAILED) 172 if (G.map == MAP_FAILED)
171 return NULL; /* error */ 173 bb_perror_msg_and_die("mmap '%s'", filename);
172 174
173 return tags; 175 return fd;
174} 176}
175 177
176static int bsearch_rpmtag(const void *key, const void *item) 178static int bsearch_rpmtag(const void *key, const void *item)
@@ -383,11 +385,7 @@ int rpm_main(int argc, char **argv)
383 int rpm_fd; 385 int rpm_fd;
384 const char *source_rpm; 386 const char *source_rpm;
385 387
386 rpm_fd = xopen(*argv, O_RDONLY); 388 rpm_fd = rpm_gettags(*argv);
387 G.mytags = rpm_gettags(rpm_fd);
388 if (!G.mytags)
389 bb_error_msg_and_die("error reading rpm header from '%s'", *argv);
390
391 print_all_tags(); 389 print_all_tags();
392 390
393 source_rpm = rpm_getstr0(TAG_SOURCERPM); 391 source_rpm = rpm_getstr0(TAG_SOURCERPM);