diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-07-25 14:16:10 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-07-25 14:20:48 +0200 |
commit | f8346498604f417415c131e3c6dbf66e6643254e (patch) | |
tree | 8f9de79c9d4d59bfa9481a632064afde5afa2d39 /lib/sqfs/meta_reader.c | |
parent | db9187c8d21e9f08b20899e3e14c1938db7b79fb (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/meta_reader.c')
-rw-r--r-- | lib/sqfs/meta_reader.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/sqfs/meta_reader.c b/lib/sqfs/meta_reader.c index 96b59fd..2c6ec97 100644 --- a/lib/sqfs/meta_reader.c +++ b/lib/sqfs/meta_reader.c @@ -68,14 +68,11 @@ int meta_reader_seek(meta_reader_t *m, uint64_t block_start, size_t offset) return 0; } - if (lseek(m->fd, block_start, SEEK_SET) == (off_t)-1) { - perror("seek on image file"); + if (read_data_at("reading meta data header", block_start, + m->fd, &header, 2)) { return -1; } - if (read_data("reading meta data header", m->fd, &header, 2)) - return -1; - header = le16toh(header); compressed = (header & 0x8000) == 0; size = header & 0x7FFF; @@ -92,8 +89,10 @@ int meta_reader_seek(meta_reader_t *m, uint64_t block_start, size_t offset) memset(m->data, 0, sizeof(m->data)); - if (read_data("reading meta data block", m->fd, m->data, size)) + if (read_data_at("reading meta data block", block_start + 2, + m->fd, m->data, size)) { return -1; + } if (compressed) { ret = m->cmp->do_block(m->cmp, m->data, size, |