diff options
author | kientzle <kientzle@FreeBSD.org> | 2007-06-26 03:06:48 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2007-06-26 03:06:48 +0000 |
commit | 0d5ae862936f390eeabe0d0030d8992f8aef43b0 (patch) | |
tree | a05439b0b80a18ac1fe803e9152fa185536a9373 /lib/libarchive/archive_read_open_filename.c | |
parent | a404044c907d9b5f13dccea6e9e518f93fcfa73f (diff) | |
download | FreeBSD-src-0d5ae862936f390eeabe0d0030d8992f8aef43b0.zip FreeBSD-src-0d5ae862936f390eeabe0d0030d8992f8aef43b0.tar.gz |
Fix 'bsdtar -t' on tape drives. Libarchive uses the
skip() callback to skip over data when reading uncompressed
archives. This gets invoked, for example, during tar -t
or tar -x with a filename argument. The revised code
only calls [lf]seek() on regular files, instead of depending
on the kernel to return an error.
Thanks to: bde for explaining the implementation of lseek()
Thanks to: Daniel O'Connor for testing
Approved by: re (Ken Smith)
MFC after: 5 days
Diffstat (limited to 'lib/libarchive/archive_read_open_filename.c')
-rw-r--r-- | lib/libarchive/archive_read_open_filename.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libarchive/archive_read_open_filename.c b/lib/libarchive/archive_read_open_filename.c index c95e787..fa3563a 100644 --- a/lib/libarchive/archive_read_open_filename.c +++ b/lib/libarchive/archive_read_open_filename.c @@ -96,7 +96,8 @@ archive_read_open_filename(struct archive *a, const char *filename, mine->block_size = block_size; mine->buffer = NULL; mine->fd = -1; - mine->can_skip = 1; + /* lseek() almost never works; disable it by default. See below. */ + mine->can_skip = 0; return (archive_read_open2(a, mine, file_open, file_read, file_skip, file_close)); } @@ -123,8 +124,19 @@ file_open(struct archive *a, void *client_data) if (fstat(mine->fd, &st) == 0) { /* If we're reading a file from disk, ensure that we don't overwrite it with an extracted file. */ - if (S_ISREG(st.st_mode)) + if (S_ISREG(st.st_mode)) { archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); + /* + * Enabling skip here is a performance + * optimization for anything that supports + * lseek(). On FreeBSD, only regular files + * and raw disk devices support lseek() and + * there's no portable way to determine if a + * device is a raw disk device, so we only + * enable this optimization for regular files. + */ + mine->can_skip = 1; + } /* Remember mode so close can decide whether to flush. */ mine->st_mode = st.st_mode; } else { |