summaryrefslogtreecommitdiff
path: root/lib/sqfs/frag_reader.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-25 14:16:10 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-25 14:20:48 +0200
commitf8346498604f417415c131e3c6dbf66e6643254e (patch)
tree8f9de79c9d4d59bfa9481a632064afde5afa2d39 /lib/sqfs/frag_reader.c
parentdb9187c8d21e9f08b20899e3e14c1938db7b79fb (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/frag_reader.c')
-rw-r--r--lib/sqfs/frag_reader.c19
1 files changed, 5 insertions, 14 deletions
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;