From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 5 Sep 2005 07:43:57 +0400 From: Alexey Tourbin To: ALT Devel discussion list Message-ID: <20050905034357.GM3539@solemn.turbinal.org> Mail-Followup-To: ALT Devel discussion list References: <20050902201456.GF7033@solemn.turbinal.org> <20050902210007.GA32163@basalt.office.altlinux.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0lsrIB+s628ok5gC" Content-Disposition: inline In-Reply-To: <20050902210007.GA32163@basalt.office.altlinux.org> Cc: Subject: [devel] Re: librpm payload X-BeenThere: devel@altlinux.ru X-Mailman-Version: 2.1.5 Precedence: list Reply-To: ALT Devel discussion list List-Id: ALT Devel discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Sep 2005 03:44:54 -0000 Archived-At: List-Archive: List-Post: --0lsrIB+s628ok5gC Content-Type: multipart/mixed; boundary="sy9WyBOsCRoUO165" Content-Disposition: inline --sy9WyBOsCRoUO165 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 03, 2005 at 01:00:07AM +0400, Dmitry V. Levin wrote: > librpmio =CD=CF=D6=C5=D4 =D0=D2=C5=C4=CF=D3=D4=C1=D7=C9=D4=D8 cpio-=C1=D2= =C8=C9=D7 =D7 =D7=C9=C4=C5 =CF=C2=D9=DE=CE=CF=C7=CF =D0=CF=D4=CF=CB=C1, =C4= =CC=D1 > =CB=CF=D4=CF=D2=CF=C7=CF, =CB=C1=D6=C5=D4=D3=D1, =D0=D2=C9=CD=C5=CE=C9=CD= =D9 =CF=D0=C5=D2=C1=C3=C9=C9 =D4=C9=D0=C1 fsetpos(3). =EE=CF =D0=CF=D3=CB= =CF=CC=D8=CB=D5 =DC=D4=CF=D4 > cpio-=C1=D2=C8=C9=D7 =CE=C1 =D0=D2=C1=CB=D4=C9=CB=C5 =DA=C1=D0=C1=CB=CF= =D7=C1=CE, =D0=D2=CF=DA=D2=C1=DE=CE=CF=CA =D2=C1=D3=D0=C1=CB=CF=D7=CB=C9 = =D7=D3=A3 =D2=C1=D7=CE=CF =CE=C5 > =CD=C9=CE=CF=D7=C1=D4=D8. =F3=DE=C9=D4=C1=D4=D8 =D0=C5=D2=D7=D9=C5 N =C2= =C1=CA=D4 =CB=C1=D6=C4=CF=C7=CF =C6=C1=CA=CC=C1 =DC=D4=CF=C7=CF cpio-=D0=CF= =D4=CF=CB=C1 librpmio > =D7=D2=D1=C4 =CC=C9 =D0=CF=CD=CF=D6=C5=D4, =CC=D5=DE=DB=C5 =D0=CF=C9=D3= =CB=C1=D4=D8 =C4=D2=D5=C7=C9=C5 =D3=D2=C5=C4=D3=D4=D7=C1. =EB=C1=CB =DE=C9=D4=C1=D4=D8 =D0=CF=D4=CF=CB cpio, =D1 =D2=C1=DA=CF=C2=D2= =C1=CC=D3=D1. =F4=C5=D0=C5=D2=D8 =C4=C1=CC=D8=DB=C5, =CB=C1=CB =D0=C1=D2= =D3=C9=D4=D8 cpio? =F5 =CE=C5=C7=CF =CB=C1=CB=CF=CA-=D4=CF =C8=C9=D4=D2=D9=CA padding (=D3=CD.= TODO). =EB=C1=CB libmagic =D0=CF=C4=CB=CC=C0=DE=C9=D4=D8 -- =D7=D2=CF=C4=C5 =D1=D3=CE=CF, magic_buffer(). =FE=D4=CF-=D4=CF =D4=C1=CB=CF=C5 =C5=D3=D4=D8 =D7 rpm-4_0-4.0.4/lib/{cpio,f= sm}.{c,h}, =CE=CF =C9=CD =D7=CF=D3=D0=CF=CC=D8=DA=CF=D7=C1=D4=D8=D3=D1 =CF=DE=C5=CE=D8 =D0=D2=CF=C2= =CC=C5=CD=CE=CF. --sy9WyBOsCRoUO165 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="rpmfile.c" Content-Transfer-Encoding: quoted-printable // gcc -Wall -I/usr/include/rpm rpmfile.c -lrpm -o rpmfile #include #include #include #include struct cpio_header { char magic[6]; char inode[8]; char mode[8]; char uid[8]; char gid[8]; char nlink[8]; char mtime[8]; char filesize[8]; char dev_major[8]; char dev_minor[8]; char rdev_major[8]; char rdev_minor[8]; char namesize[8]; char checksum[8]; }; int num8(char *s) { char c =3D s[8]; s[8] =3D 0; int n =3D strtoul(s, NULL, 16); s[8] =3D c; return n; } FD_t open_payload(const char *fname) { FD_t fd =3D Fopen(fname, "r.ufdio"); if (Ferror(fd)) error(1, 0, "%s: %s", fname, Fstrerror(fd)); =09 Header h; int isSource; if (rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL)) error(1, 0, "%s: %s", fname, "bad RPM header"); =09 char *method; if (headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL, (void **) &method, N= ULL)) method =3D "gzip"; =09 char *type =3D "r"; if (strcmp(method, "gzip") =3D=3D 0) type =3D "r.gzdio"; if (strcmp(method, "bzip2") =3D=3D 0) type =3D "r.bzdio"; FD_t zfd =3D Fdopen(fd, type); if (Ferror(zfd)) error(1, 0, "%s: %s", fname, Fstrerror(zfd)); if (fd !=3D zfd) Fclose(fd); return zfd; } void rpmfile(const char *fname) { FD_t fd =3D open_payload(fname); =09 while (1) { size_t n; struct cpio_header h; n =3D Fread(&h, sizeof(h), 1, fd); if (n !=3D 1) error(1, 0, "%s: %s", fname, "bad cpio header"); if (strncmp(h.magic, "070701", 6)) error(1, 0, "%s: %s", fname, "bad cpio magic"); char path[PATH_MAX]; int len =3D num8(h.namesize); n =3D Fread(path, len, 1, fd); if (n !=3D 1) error(1, 0, "%s: %s", fname, "bad cpio namesize"); if (strcmp(path, "TRAILER!!!") =3D=3D 0) break; char buf[4096]; int size =3D num8(h.filesize); int toread =3D (size > sizeof(buf)) ? sizeof(buf) : size; int toseek =3D size - toread; n =3D 1; if (toread) n =3D Fread(buf, toread, 1, fd); if (toseek) n +=3D Fseek(fd, toseek, SEEK_CUR); if (n !=3D 1) error(1, 0, "%s: %s", fname, "bad cpio filesize"); =09 int mode =3D num8(h.mode); printf("%s\t%s\t0%o\n", fname, path, mode); =09 /* TODO: zero padded? how do I seek ? */ break; } Fclose(fd); } int main(int argc, char *argv[]) { while (--argc > 0) rpmfile(*++argv); return 0; } --sy9WyBOsCRoUO165-- --0lsrIB+s628ok5gC Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFDG779fBKgtDjnu0YRAnrPAKCmZw4LmRLXyxMikL3+RPiORdZKugCdEfL9 1S3MOk9RhzB7virjqyE/w2s= =m3F4 -----END PGP SIGNATURE----- --0lsrIB+s628ok5gC--