aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/data_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/data_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/data_reader.c')
-rw-r--r--lib/sqfs/data_reader.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c
index 4fbd97a..e03a436 100644
--- a/lib/sqfs/data_reader.c
+++ b/lib/sqfs/data_reader.c
@@ -65,6 +65,7 @@ int data_reader_dump_file(data_reader_t *data, file_info_t *fi, int outfd,
bool allow_sparse)
{
size_t i, count, fragsz, unpackedsz;
+ off_t sqfs_location;
uint64_t filesz = 0;
bool compressed;
uint32_t bs;
@@ -81,8 +82,7 @@ int data_reader_dump_file(data_reader_t *data, file_info_t *fi, int outfd,
}
if (count > 0) {
- if (lseek(data->sqfsfd, fi->startblock, SEEK_SET) == (off_t)-1)
- goto fail_seek;
+ sqfs_location = fi->startblock;
for (i = 0; i < count; ++i) {
bs = fi->blocksizes[i];
@@ -112,9 +112,13 @@ int data_reader_dump_file(data_reader_t *data, file_info_t *fi, int outfd,
if (bs == 0) {
memset(data->buffer, 0, unpackedsz);
compressed = false;
- } else if (read_data("reading data block",
- data->sqfsfd, data->buffer, bs)) {
- return -1;
+ } else {
+ if (read_data_at("reading data block",
+ sqfs_location, data->sqfsfd,
+ data->buffer, bs)) {
+ return -1;
+ }
+ sqfs_location += bs;
}
if (compressed) {
@@ -157,9 +161,6 @@ int data_reader_dump_file(data_reader_t *data, file_info_t *fi, int outfd,
fail_sparse:
perror("creating sparse output file");
return -1;
-fail_seek:
- perror("seek on squashfs");
- return -1;
fail_bs:
fputs("found compressed block larger than block size\n", stderr);
return -1;