diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-11-20 17:04:14 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-11-20 17:04:14 -0500 |
commit | f769be3c2d9d6a743b304886c16ff0c94db32a1a (patch) | |
tree | 6a9570189731731df5f42942617d0b109d4fd9c9 /cpio.c | |
parent | 1b1b9d0177e051400b5722cfc9a5c42cb27a7b9e (diff) |
Diffstat (limited to 'cpio.c')
-rw-r--r-- | cpio.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -97,20 +97,27 @@ static struct cpio_entry cpio_deserialize(struct cpio_header *dh) e.st.st_rdev = pax_atoi(sizeof(dh->rdev), dh->rdev, 8); e.st.st_mtim.tv_sec = pax_atoi(sizeof(dh->mtime), dh->mtime, 8); e.st.st_size = pax_atoi(sizeof(dh->filesize), dh->filesize, 8); + e.st.st_blocks = e.st.st_size / 512; e.namesize = pax_atoi(sizeof(dh->namesize), dh->namesize, 8); return e; } -int cpio_list(FILE *input, size_t firstlen, void *firstblock) +int cpio_list(FILE *input, size_t nblocks, void *block) { - struct cpio_header *dh = firstblock; + struct cpio_header *dh = block; - //for (;;) { + for (;;) { struct cpio_entry e = cpio_deserialize(dh); - pax_list_file(&e.st, (char*)firstblock + sizeof(*dh)); - //} + pax_list_file(&e.st, (char*)block + sizeof(*dh)); + for (blkcnt_t i = 0; i < e.st.st_blocks + 1; i++) { + if (fread(dh, 1, 512, input) != 512) { + fprintf(stderr, "pax: interrupted\n"); + return 1; + } + } + } return 0; } |