summaryrefslogtreecommitdiff
path: root/libarchive/archive_read_open_filename.c
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@gmail.com>2010-02-23 11:18:00 -0500
committerTim Kientzle <kientzle@gmail.com>2010-02-23 11:18:00 -0500
commit81b8193dacf21a071e8fdc919c3444f10ca7c490 (patch)
tree7135a2a59f7ae4fd21a35a3edd548ae144fb9a86 /libarchive/archive_read_open_filename.c
parent7cf625f3e1ff2f376d265465f8f97dd5b8953ef2 (diff)
downloadlibarchive-81b8193dacf21a071e8fdc919c3444f10ca7c490.tar.gz
Oops. Forgot to initialize the is_disk_like variable. While I'm
here, make the block size selection for disks be aware of the users request. Users should be able to ask for larger block sizes. SVN-Revision: 1965
Diffstat (limited to 'libarchive/archive_read_open_filename.c')
-rw-r--r--libarchive/archive_read_open_filename.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/libarchive/archive_read_open_filename.c b/libarchive/archive_read_open_filename.c
index a726fed7..9cac80e6 100644
--- a/libarchive/archive_read_open_filename.c
+++ b/libarchive/archive_read_open_filename.c
@@ -94,7 +94,7 @@ archive_read_open_filename(struct archive *a, const char *filename,
struct read_file_data *mine;
void *buffer;
int fd;
- int is_disk_like;
+ int is_disk_like = 0;
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
off_t mediasize = 0;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
@@ -139,8 +139,8 @@ archive_read_open_filename(struct archive *a, const char *filename,
* = "disk-like" devices support arbitrary lseek() and will
* support I/O requests of any size. So we get easy skipping
* and can cheat on block sizes to get better performance.
- * = "tape-like" devices require strict blocking and sometimes
- * support specialized seek ioctls.
+ * = "tape-like" devices require strict blocking and use
+ * specialized ioctls for seeking.
* = "socket-like" devices cannot seek at all but can improve
* performance by using nonblocking I/O to read "whatever is
* available right now".
@@ -190,10 +190,15 @@ archive_read_open_filename(struct archive *a, const char *filename,
mine = (struct read_file_data *)calloc(1,
sizeof(*mine) + strlen(filename));
- /* For regular files and disks, ignore the block size passed
- * in and just use a fixed moderately large power of two. */
- if (is_disk_like)
- block_size = 64 * 1024;
+ /* Disk-like devices prefer power-of-two block sizes. */
+ /* Use provided block_size as a guide so users have some control. */
+ if (is_disk_like) {
+ size_t new_block_size = 64 * 1024;
+ while (new_block_size < block_size
+ && new_block_size < 64 * 1024 * 1024)
+ new_block_size *= 2;
+ block_size = new_block_size;
+ }
buffer = malloc(block_size);
if (mine == NULL || buffer == NULL) {
archive_set_error(a, ENOMEM, "No memory");