diff options
author | Tim Kientzle <kientzle@gmail.com> | 2008-10-29 18:07:37 -0400 |
---|---|---|
committer | Tim Kientzle <kientzle@gmail.com> | 2008-10-29 18:07:37 -0400 |
commit | 9aeac49740d27af02c35231a5a89b397878cbc2c (patch) | |
tree | c201500d89e085f80d2965e8eaa051ba1dc89468 /libarchive/archive_read_support_format_cpio.c | |
parent | fc95189e4e486de8422c006d7b4f25320702aec0 (diff) | |
download | libarchive-9aeac49740d27af02c35231a5a89b397878cbc2c.tar.gz |
First step in transitioning the current decompression code to
a more generic system of stackable stream transforms.
In particular, I believe I've edited every place that called the
decompressor directly to go through new __archive_read_ahead(),
__archive_read_consume() and __archive_read_skip() functions, so
the rest of the work here will not require any changes to the
format handlers.
I've also laid out the new types that will be needed for this.
Next step is to rewrite the decompressors to the new interface,
and overhaul the decompression auction to juggle generic "sources."
Then I'll be able to consolidate reblocking into a single place;
the transforms can emit arbitrary-sized blocks and the current
decompress_none logic will be used to reblock as needed by the
consumer format.
The initial impetus for this was to simplify the decompressors by
consolidating the reblocking logic. I recently came up with
some other transforms I'd like to implement (including new
decompressors, an encryption filter for secure backup, and
uudecode handling to simplify test harnesses) that would also
benefit from this. Eventually, I think I might be able to
standardize the interface for new transforms enough to allow
libarchive clients to register their own transforms complete
with bidding logic (the old interface was too wired into libarchive
internals for the API to be exported). In the very long term,
this might divorce the transformation logic from the rest of
libarchive enough to allow it to be packaged as an independent
library.
SVN-Revision: 234
Diffstat (limited to 'libarchive/archive_read_support_format_cpio.c')
-rw-r--r-- | libarchive/archive_read_support_format_cpio.c | 79 |
1 files changed, 31 insertions, 48 deletions
diff --git a/libarchive/archive_read_support_format_cpio.c b/libarchive/archive_read_support_format_cpio.c index 3734b386..9c3f2944 100644 --- a/libarchive/archive_read_support_format_cpio.c +++ b/libarchive/archive_read_support_format_cpio.c @@ -165,7 +165,6 @@ archive_read_support_format_cpio(struct archive *_a) static int archive_read_format_cpio_bid(struct archive_read *a) { - int bytes_read; const void *h; const unsigned char *p; struct cpio *cpio; @@ -173,11 +172,7 @@ archive_read_format_cpio_bid(struct archive_read *a) cpio = (struct cpio *)(a->format->data); - bytes_read = (a->decompressor->read_ahead)(a, &h, 6); - /* Convert error code into error return. */ - if (bytes_read < 0) - return ((int)bytes_read); - if (bytes_read < 6) + if ((h = __archive_read_ahead(a, 6, NULL)) == NULL) return (-1); p = (const unsigned char *)h; @@ -228,7 +223,6 @@ archive_read_format_cpio_read_header(struct archive_read *a, struct archive_entry *entry) { struct cpio *cpio; - size_t bytes; const void *h; size_t namelength; size_t name_pad; @@ -241,21 +235,20 @@ archive_read_format_cpio_read_header(struct archive_read *a, return (r); /* Read name from buffer. */ - bytes = (a->decompressor->read_ahead)(a, &h, namelength + name_pad); - if (bytes < namelength + name_pad) + h = __archive_read_ahead(a, namelength + name_pad, NULL); + if (h == NULL) return (ARCHIVE_FATAL); - (a->decompressor->consume)(a, namelength + name_pad); + __archive_read_consume(a, namelength + name_pad); archive_strncpy(&cpio->entry_name, (const char *)h, namelength); archive_entry_set_pathname(entry, cpio->entry_name.s); cpio->entry_offset = 0; /* If this is a symlink, read the link contents. */ if (archive_entry_filetype(entry) == AE_IFLNK) { - bytes = (a->decompressor->read_ahead)(a, &h, - cpio->entry_bytes_remaining); - if ((off_t)bytes < cpio->entry_bytes_remaining) + h = __archive_read_ahead(a, cpio->entry_bytes_remaining, NULL); + if (h == NULL) return (ARCHIVE_FATAL); - (a->decompressor->consume)(a, cpio->entry_bytes_remaining); + __archive_read_consume(a, cpio->entry_bytes_remaining); archive_strncpy(&cpio->entry_linkname, (const char *)h, cpio->entry_bytes_remaining); archive_entry_set_symlink(entry, cpio->entry_linkname.s); @@ -284,7 +277,7 @@ archive_read_format_cpio_read_data(struct archive_read *a, cpio = (struct cpio *)(a->format->data); if (cpio->entry_bytes_remaining > 0) { - bytes_read = (a->decompressor->read_ahead)(a, buff, 1); + *buff = __archive_read_ahead(a, 1, &bytes_read); if (bytes_read <= 0) return (ARCHIVE_FATAL); if (bytes_read > cpio->entry_bytes_remaining) @@ -293,16 +286,16 @@ archive_read_format_cpio_read_data(struct archive_read *a, *offset = cpio->entry_offset; cpio->entry_offset += bytes_read; cpio->entry_bytes_remaining -= bytes_read; - (a->decompressor->consume)(a, bytes_read); + __archive_read_consume(a, bytes_read); return (ARCHIVE_OK); } else { while (cpio->entry_padding > 0) { - bytes_read = (a->decompressor->read_ahead)(a, buff, 1); + *buff = __archive_read_ahead(a, 1, &bytes_read); if (bytes_read <= 0) return (ARCHIVE_FATAL); if (bytes_read > cpio->entry_padding) bytes_read = cpio->entry_padding; - (a->decompressor->consume)(a, bytes_read); + __archive_read_consume(a, bytes_read); cpio->entry_padding -= bytes_read; } *buff = NULL; @@ -339,9 +332,8 @@ find_newc_header(struct archive_read *a) size_t skip, bytes, skipped = 0; for (;;) { - bytes = (a->decompressor->read_ahead)(a, &h, - sizeof(struct cpio_newc_header)); - if (bytes < sizeof(struct cpio_newc_header)) + h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), &bytes); + if (h == NULL) return (ARCHIVE_FATAL); p = h; q = p + bytes; @@ -363,7 +355,7 @@ find_newc_header(struct archive_read *a) if (memcmp("07070", p, 5) == 0 && is_hex(p, sizeof(struct cpio_newc_header))) { skip = p - (const char *)h; - (a->decompressor->consume)(a, skip); + __archive_read_consume(a, skip); skipped += skip; if (skipped > 0) { archive_set_error(&a->archive, @@ -386,7 +378,7 @@ find_newc_header(struct archive_read *a) } } skip = p - (const char *)h; - (a->decompressor->consume)(a, skip); + __archive_read_consume(a, skip); skipped += skip; } } @@ -397,7 +389,6 @@ header_newc(struct archive_read *a, struct cpio *cpio, { const void *h; const struct cpio_newc_header *header; - size_t bytes; int r; r = find_newc_header(a); @@ -405,11 +396,10 @@ header_newc(struct archive_read *a, struct cpio *cpio, return (r); /* Read fixed-size portion of header. */ - bytes = (a->decompressor->read_ahead)(a, &h, - sizeof(struct cpio_newc_header)); - if (bytes < sizeof(struct cpio_newc_header)) + h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), NULL); + if (h == NULL) return (ARCHIVE_FATAL); - (a->decompressor->consume)(a, sizeof(struct cpio_newc_header)); + __archive_read_consume(a, sizeof(struct cpio_newc_header)); /* Parse out hex fields. */ header = (const struct cpio_newc_header *)h; @@ -476,9 +466,8 @@ find_odc_header(struct archive_read *a) size_t skip, bytes, skipped = 0; for (;;) { - bytes = (a->decompressor->read_ahead)(a, &h, - sizeof(struct cpio_odc_header)); - if (bytes < sizeof(struct cpio_odc_header)) + h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), &bytes); + if (h == NULL) return (ARCHIVE_FATAL); p = h; q = p + bytes; @@ -498,7 +487,7 @@ find_odc_header(struct archive_read *a) if (memcmp("070707", p, 6) == 0 && is_octal(p, sizeof(struct cpio_odc_header))) { skip = p - (const char *)h; - (a->decompressor->consume)(a, skip); + __archive_read_consume(a, skip); skipped += skip; if (skipped > 0) { archive_set_error(&a->archive, @@ -521,7 +510,7 @@ find_odc_header(struct archive_read *a) } } skip = p - (const char *)h; - (a->decompressor->consume)(a, skip); + __archive_read_consume(a, skip); skipped += skip; } } @@ -533,7 +522,6 @@ header_odc(struct archive_read *a, struct cpio *cpio, const void *h; int r; const struct cpio_odc_header *header; - size_t bytes; a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; a->archive.archive_format_name = "POSIX octet-oriented cpio"; @@ -544,11 +532,10 @@ header_odc(struct archive_read *a, struct cpio *cpio, return (r); /* Read fixed-size portion of header. */ - bytes = (a->decompressor->read_ahead)(a, &h, - sizeof(struct cpio_odc_header)); - if (bytes < sizeof(struct cpio_odc_header)) + h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), NULL); + if (h == NULL) return (ARCHIVE_FATAL); - (a->decompressor->consume)(a, sizeof(struct cpio_odc_header)); + __archive_read_consume(a, sizeof(struct cpio_odc_header)); /* Parse out octal fields. */ header = (const struct cpio_odc_header *)h; @@ -582,17 +569,15 @@ header_bin_le(struct archive_read *a, struct cpio *cpio, { const void *h; const struct cpio_bin_header *header; - size_t bytes; a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_LE; a->archive.archive_format_name = "cpio (little-endian binary)"; /* Read fixed-size portion of header. */ - bytes = (a->decompressor->read_ahead)(a, &h, - sizeof(struct cpio_bin_header)); - if (bytes < sizeof(struct cpio_bin_header)) + h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); + if (h == NULL) return (ARCHIVE_FATAL); - (a->decompressor->consume)(a, sizeof(struct cpio_bin_header)); + __archive_read_consume(a, sizeof(struct cpio_bin_header)); /* Parse out binary fields. */ header = (const struct cpio_bin_header *)h; @@ -620,17 +605,15 @@ header_bin_be(struct archive_read *a, struct cpio *cpio, { const void *h; const struct cpio_bin_header *header; - size_t bytes; a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_BE; a->archive.archive_format_name = "cpio (big-endian binary)"; /* Read fixed-size portion of header. */ - bytes = (a->decompressor->read_ahead)(a, &h, - sizeof(struct cpio_bin_header)); - if (bytes < sizeof(struct cpio_bin_header)) + h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); + if (h == NULL) return (ARCHIVE_FATAL); - (a->decompressor->consume)(a, sizeof(struct cpio_bin_header)); + __archive_read_consume(a, sizeof(struct cpio_bin_header)); /* Parse out binary fields. */ header = (const struct cpio_bin_header *)h; |