rpm: prepare rpm_gettags for reuse in rpm2cpio
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
3fa9262dcd
commit
e5650a40d4
@ -117,14 +117,15 @@ static void extract_cpio(int fd, const char *source_rpm)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rpm_index *rpm_gettags(int fd)
|
static int rpm_gettags(const char *filename)
|
||||||
{
|
{
|
||||||
rpm_index *tags;
|
rpm_index *tags;
|
||||||
|
int fd;
|
||||||
unsigned pass, idx;
|
unsigned pass, idx;
|
||||||
unsigned storepos;
|
unsigned storepos;
|
||||||
|
|
||||||
|
fd = xopen(filename, O_RDONLY);
|
||||||
storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||||
|
|
||||||
G.tagcount = 0;
|
G.tagcount = 0;
|
||||||
tags = NULL;
|
tags = NULL;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
@ -135,13 +136,13 @@ static rpm_index *rpm_gettags(int fd)
|
|||||||
|
|
||||||
xread(fd, &header, sizeof(header));
|
xread(fd, &header, sizeof(header));
|
||||||
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))
|
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))
|
||||||
return NULL; /* Invalid magic, or not version 1 */
|
bb_error_msg_and_die("invalid RPM header magic in '%s'", filename);
|
||||||
header.size = ntohl(header.size);
|
header.size = ntohl(header.size);
|
||||||
cnt = ntohl(header.entries);
|
cnt = ntohl(header.entries);
|
||||||
storepos += sizeof(header) + cnt * 16;
|
storepos += sizeof(header) + cnt * 16;
|
||||||
|
|
||||||
G.tagcount += cnt;
|
G.tagcount += cnt;
|
||||||
tags = xrealloc(tags, G.tagcount * sizeof(tags[0]));
|
tags = xrealloc(tags, sizeof(tags[0]) * G.tagcount);
|
||||||
xread(fd, &tags[idx], sizeof(tags[0]) * cnt);
|
xread(fd, &tags[idx], sizeof(tags[0]) * cnt);
|
||||||
while (cnt--) {
|
while (cnt--) {
|
||||||
rpm_index *tag = &tags[idx];
|
rpm_index *tag = &tags[idx];
|
||||||
@ -160,6 +161,7 @@ static rpm_index *rpm_gettags(int fd)
|
|||||||
/* Seek past store */
|
/* Seek past store */
|
||||||
storepos = xlseek(fd, header.size, SEEK_CUR);
|
storepos = xlseek(fd, header.size, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
G.mytags = tags;
|
||||||
|
|
||||||
/* Map the store */
|
/* Map the store */
|
||||||
storepos = (storepos + G.pagesize) & -(int)G.pagesize;
|
storepos = (storepos + G.pagesize) & -(int)G.pagesize;
|
||||||
@ -168,9 +170,9 @@ static rpm_index *rpm_gettags(int fd)
|
|||||||
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
|
/* some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
|
||||||
G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0);
|
G.map = mmap(0, storepos, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if (G.map == MAP_FAILED)
|
if (G.map == MAP_FAILED)
|
||||||
return NULL; /* error */
|
bb_perror_msg_and_die("mmap '%s'", filename);
|
||||||
|
|
||||||
return tags;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bsearch_rpmtag(const void *key, const void *item)
|
static int bsearch_rpmtag(const void *key, const void *item)
|
||||||
@ -383,11 +385,7 @@ int rpm_main(int argc, char **argv)
|
|||||||
int rpm_fd;
|
int rpm_fd;
|
||||||
const char *source_rpm;
|
const char *source_rpm;
|
||||||
|
|
||||||
rpm_fd = xopen(*argv, O_RDONLY);
|
rpm_fd = rpm_gettags(*argv);
|
||||||
G.mytags = rpm_gettags(rpm_fd);
|
|
||||||
if (!G.mytags)
|
|
||||||
bb_error_msg_and_die("error reading rpm header from '%s'", *argv);
|
|
||||||
|
|
||||||
print_all_tags();
|
print_all_tags();
|
||||||
|
|
||||||
source_rpm = rpm_getstr0(TAG_SOURCERPM);
|
source_rpm = rpm_getstr0(TAG_SOURCERPM);
|
||||||
|
Loading…
Reference in New Issue
Block a user