From: Michihiro NAKAJIMA Date: Tue, 8 Jun 2010 21:18:32 +0000 (-0400) Subject: Make archive_read_next_header2 and archive_read_data_block virtualization. X-Git-Tag: v3.0.0a~974 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=262d48e052259fbd561560c54198272397b65ee3;p=thirdparty%2Flibarchive.git Make archive_read_next_header2 and archive_read_data_block virtualization. This is a initial step of supporting directory traversals in archive_read_disk. SVN-Revision: 2453 --- diff --git a/libarchive/archive_private.h b/libarchive/archive_private.h index 862eb032f..8b96937b7 100644 --- a/libarchive/archive_private.h +++ b/libarchive/archive_private.h @@ -66,6 +66,11 @@ struct archive_vtable { ssize_t (*archive_write_data_block)(struct archive *, const void *, size_t, int64_t); + int (*archive_read_next_header2)(struct archive *, + struct archive_entry *); + int (*archive_read_data_block)(struct archive *, + const void **, size_t *, int64_t *); + int (*archive_filter_count)(struct archive *); int64_t (*archive_filter_bytes)(struct archive *, int); int (*archive_filter_code)(struct archive *, int); diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index 450f9dbf2..319590c50 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -65,12 +65,12 @@ static int _archive_filter_code(struct archive *, int); static const char *_archive_filter_name(struct archive *, int); static int _archive_filter_count(struct archive *); static int _archive_read_close(struct archive *); +static int _archive_read_data_block(struct archive *, + const void **, size_t *, int64_t *); static int _archive_read_free(struct archive *); +static int _archive_read_next_header2(struct archive *, + struct archive_entry *); static int64_t advance_file_pointer(struct archive_read_filter *, int64_t); -#if ARCHIVE_VERSION_NUMBER < 3000000 -static int archive_read_data_block64(struct archive *, - const void **, size_t *, int64_t *); -#endif static struct archive_vtable * archive_read_vtable(void) @@ -83,6 +83,8 @@ archive_read_vtable(void) av.archive_filter_code = _archive_filter_code; av.archive_filter_name = _archive_filter_name; av.archive_filter_count = _archive_filter_count; + av.archive_read_data_block = _archive_read_data_block; + av.archive_read_next_header2 = _archive_read_next_header2; av.archive_free = _archive_read_free; av.archive_close = _archive_read_close; } @@ -424,8 +426,8 @@ build_stream(struct archive_read *a) /* * Read header of next entry. */ -int -archive_read_next_header2(struct archive *_a, struct archive_entry *entry) +static int +_archive_read_next_header2(struct archive *_a, struct archive_entry *entry) { struct archive_read *a = (struct archive_read *)_a; int slot, ret; @@ -503,7 +505,7 @@ archive_read_next_header(struct archive *_a, struct archive_entry **entryp) int ret; struct archive_read *a = (struct archive_read *)_a; *entryp = NULL; - ret = archive_read_next_header2(_a, a->entry); + ret = _archive_read_next_header2(_a, a->entry); *entryp = a->entry; return ret; } @@ -600,13 +602,8 @@ archive_read_data(struct archive *_a, void *buff, size_t s) while (s > 0) { if (a->read_data_remaining == 0) { read_buf = a->read_data_block; -#if ARCHIVE_VERSION_NUMBER < 3000000 - r = archive_read_data_block64(&a->archive, &read_buf, - &a->read_data_remaining, &a->read_data_offset); -#else - r = archive_read_data_block(&a->archive, &read_buf, + r = _archive_read_data_block(&a->archive, &read_buf, &a->read_data_remaining, &a->read_data_offset); -#endif a->read_data_block = read_buf; if (r == ARCHIVE_EOF) return (bytes_read); @@ -720,27 +717,9 @@ archive_read_data_skip(struct archive *_a) * Returns ARCHIVE_OK if the operation is successful, ARCHIVE_EOF if * the end of entry is encountered. */ -#if ARCHIVE_VERSION_NUMBER < 3000000 -int -archive_read_data_block(struct archive *_a, - const void **buff, size_t *size, off_t *offset) -{ - int r; - int64_t offset64; - r = archive_read_data_block64(_a, buff, size, &offset64); - *offset = (off_t)offset64; - return (r); -} - - static int -archive_read_data_block64(struct archive *_a, +_archive_read_data_block(struct archive *_a, const void **buff, size_t *size, int64_t *offset) -#else -int -archive_read_data_block(struct archive *_a, - const void **buff, size_t *size, int64_t *offset) -#endif { struct archive_read *a = (struct archive_read *)_a; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, diff --git a/libarchive/archive_read_disk.c b/libarchive/archive_read_disk.c index ba03a38fd..ffd378949 100644 --- a/libarchive/archive_read_disk.c +++ b/libarchive/archive_read_disk.c @@ -35,6 +35,10 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk.c 189429 2009-03-06 04 static int _archive_read_free(struct archive *); static int _archive_read_close(struct archive *); +static int _archive_read_data_block(struct archive *, + const void **, size_t *, int64_t *); +static int _archive_read_next_header2(struct archive *, + struct archive_entry *); #if ARCHIVE_VERSION_NUMBER < 3000000 static const char *trivial_lookup_gname(void *, gid_t gid); static const char *trivial_lookup_uname(void *, uid_t uid); @@ -51,6 +55,8 @@ archive_read_disk_vtable(void) if (!inited) { av.archive_free = _archive_read_free; av.archive_close = _archive_read_close; + av.archive_read_data_block = _archive_read_data_block; + av.archive_read_next_header2 = _archive_read_next_header2; } return (&av); } @@ -255,3 +261,29 @@ trivial_lookup_uname(void *private_data, int64_t uid) (void)uid; /* UNUSED */ return (NULL); } + +static int +_archive_read_data_block(struct archive *_a, const void **buff, + size_t *size, int64_t *offset) +{ + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_data_block"); + + (void)buff; /* UNUSED */ + (void)size; /* UNUSED */ + (void)offset; /* UNUSED */ + /* Not implemented yet. */ + return (ARCHIVE_FAILED); +} + +static int +_archive_read_next_header2(struct archive *_a, struct archive_entry *entry) +{ + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_read_next_header2"); + + (void)entry; /* UNUSED */ + /* Not implemented yet. */ + return (ARCHIVE_FAILED); +} diff --git a/libarchive/archive_virtual.c b/libarchive/archive_virtual.c index fd5ce5533..943d9257a 100644 --- a/libarchive/archive_virtual.c +++ b/libarchive/archive_virtual.c @@ -125,3 +125,30 @@ archive_write_data_block(struct archive *a, const void *buff, size_t s, int64_t { return ((a->vtable->archive_write_data_block)(a, buff, s, o)); } + +int +archive_read_next_header2(struct archive *a, struct archive_entry *entry) +{ + return ((a->vtable->archive_read_next_header2)(a, entry)); +} + +#if ARCHIVE_VERSION_NUMBER < 3000000 +int +archive_read_data_block(struct archive *a, + const void **buff, size_t *s, off_t *o) +{ + int r; + int64_t o64; + + r = ((a->vtable->archive_read_data_block)(a, buff, s, &o64)); + *o = (off_t)o64; + return (r); +} +#else +int +archive_read_data_block(struct archive *_a, + const void **buff, size_t *s, int64_t *o) +{ + return ((a->vtable->archive_read_data_block)(a, buff, s, o)); +} +#endif