From f8346498604f417415c131e3c6dbf66e6643254e Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 25 Jul 2019 14:16:10 +0200 Subject: Replace reads in squashfs with positional reads In most cases, we know exactely where the data that we want to read is on disk, so instead of using read() on the squashfs (or lseek + read), the code can in many places be cleaned up to use the pread wrapper read_data_at instead. Signed-off-by: David Oberhollenzer --- lib/sqfs/frag_reader.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'lib/sqfs/frag_reader.c') diff --git a/lib/sqfs/frag_reader.c b/lib/sqfs/frag_reader.c index 87e4c35..721286c 100644 --- a/lib/sqfs/frag_reader.c +++ b/lib/sqfs/frag_reader.c @@ -31,11 +31,6 @@ static int precache_block(frag_reader_t *f, size_t i) if (i == f->current_index) return 0; - if (lseek(f->fd, f->tbl[i].start_offset, SEEK_SET) == (off_t)-1) { - perror("seeking to fragment location"); - return -1; - } - compressed = (f->tbl[i].size & (1 << 24)) == 0; size = f->tbl[i].size & ((1 << 24) - 1); @@ -44,8 +39,10 @@ static int precache_block(frag_reader_t *f, size_t i) return -1; } - if (read_data("reading fragment", f->fd, f->buffer, size)) + if (read_data_at("reading fragment", f->tbl[i].start_offset, + f->fd, f->buffer, size)) { return -1; + } if (compressed) { ret = f->cmp->do_block(f->cmp, f->buffer, size, @@ -95,11 +92,8 @@ frag_reader_t *frag_reader_create(sqfs_super_t *super, int fd, goto fail_rd; /* read the meta block offset table */ - if (lseek(fd, super->fragment_table_start, SEEK_SET) == (off_t)-1) - goto fail_seek; - - if (read_data("reading fragment table", fd, locations, - blockcount * sizeof(locations[0]))) { + if (read_data_at("reading fragment table", super->fragment_table_start, + fd, locations, blockcount * sizeof(locations[0]))) { goto fail; } @@ -139,9 +133,6 @@ frag_reader_t *frag_reader_create(sqfs_super_t *super, int fd, f->block_size = super->block_size; f->current_index = count; return f; -fail_seek: - perror("seek to fragment table"); - goto fail; fail_rd: perror("reading fragment table"); goto fail; -- cgit v1.2.3