Add the first bits of rpm file parser.
8 #include <rpm/rpmlib.h>
10 #define RPM_LEAD_SIZE 96
13 unsigned char magic[4];
25 unsigned char magic[4];
26 unsigned char reserved[4];
31 struct rpm_header_index {
38 #define ALIGN(value, base) (((value) + (base - 1)) & ~((base) - 1))
40 static void dump_header(struct rpm_header *header)
42 struct rpm_header_index *base, *index;
43 int i, j, nindex, tag, offset, type, count;
46 nindex = ntohl(header->nindex);
47 printf("header index records: %d\n", nindex);
48 printf("header storage size: %d\n", ntohl(header->hsize));
49 base = (struct rpm_header_index *) (header + 1);
50 pool = (void *) (header + 1) + nindex * sizeof *index;
53 for (i = 0; i < nindex; i++) {
55 tag = ntohl(index->tag);
56 offset = ntohl(index->offset);
57 type = ntohl(index->type);
58 count = ntohl(index->count);
59 printf(" 0x%08x 0x%08x 0x%08x 0x%08x\n",
60 tag, type, offset, count);
72 case RPMTAG_REQUIRENAME:
82 printf(" (%s %s)\n", name, pool + offset);
84 case RPM_STRING_ARRAY_TYPE:
86 for (j = 0; j < count; j++) {
87 printf(" %s", pool + offset);
88 offset += strlen(pool + offset) + 1;
97 razor_rpm_dump(const char *filename)
101 int fd, nindex, hsize;
102 struct rpm_header *signature, *header;
103 struct rpm_header_index *index;
105 if (stat(filename, &buf) < 0) {
106 fprintf(stderr, "no such file %s\n", filename);
110 fd = open(filename, O_RDONLY);
111 p = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
114 printf("%s: %ldkB\n", filename, buf.st_size / 1024);
115 signature = p + RPM_LEAD_SIZE;
117 nindex = ntohl(signature->nindex);
118 hsize = ntohl(signature->hsize);
119 header = (void *) (signature + 1) +
120 ALIGN(nindex * sizeof *index + hsize, 8);
122 dump_header(signature);
125 munmap(p, buf.st_size);