diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-08 14:53:30 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-08 14:53:30 +0200 |
commit | 3a851dfe87c88ac1d4dddc2a26cc48b037f852f9 (patch) | |
tree | a8a8f34291aa58b25737088d247a91a7f60b4fec /lib/sqfshelper/data_reader.c | |
parent | 60064dd0412a149fe00cfc4e2f2361c22656db57 (diff) |
Replace direct file I/O with abstraction layer
This should make it easier to use libsquashfs with custom setups that
embedd a squashfs image inside something else. Also, it should make
it easier to port to non unix-like platforms.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfshelper/data_reader.c')
-rw-r--r-- | lib/sqfshelper/data_reader.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/sqfshelper/data_reader.c b/lib/sqfshelper/data_reader.c index fc92e28..d1a9cce 100644 --- a/lib/sqfshelper/data_reader.c +++ b/lib/sqfshelper/data_reader.c @@ -25,7 +25,7 @@ struct data_reader_t { sqfs_compressor_t *cmp; size_t block_size; - int sqfsfd; + sqfs_file_t *file; void *block; void *scratch; @@ -44,8 +44,10 @@ static ssize_t read_block(data_reader_t *data, off_t offset, uint32_t size, if (size > data->block_size) goto fail_bs; - if (read_data_at("reading block", offset, data->sqfsfd, ptr, size)) + if (data->file->read_at(data->file, offset, ptr, size)) { + fputs("error reading data block from input file\n", stderr); return -1; + } if (compressed) { ret = data->cmp->do_block(data->cmp, data->scratch, size, @@ -104,7 +106,7 @@ static int precache_fragment_block(data_reader_t *data, size_t idx) return 0; } -data_reader_t *data_reader_create(int fd, sqfs_super_t *super, +data_reader_t *data_reader_create(sqfs_file_t *file, sqfs_super_t *super, sqfs_compressor_t *cmp) { data_reader_t *data = alloc_flex(sizeof(*data), super->block_size, 3); @@ -123,7 +125,7 @@ data_reader_t *data_reader_create(int fd, sqfs_super_t *super, data->scratch = (char *)data->block + super->block_size; data->frag_block = (char *)data->scratch + super->block_size; data->current_block = -1; - data->sqfsfd = fd; + data->file = file; data->block_size = super->block_size; data->cmp = cmp; @@ -144,7 +146,7 @@ data_reader_t *data_reader_create(int fd, sqfs_super_t *super, return NULL; } - ret = sqfs_read_table(fd, cmp, size, super->fragment_table_start, + ret = sqfs_read_table(file, cmp, size, super->fragment_table_start, super->directory_table_start, super->fragment_table_start, &raw_frag); |