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/sqfs/meta_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/sqfs/meta_reader.c')
-rw-r--r-- | lib/sqfs/meta_reader.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/sqfs/meta_reader.c b/lib/sqfs/meta_reader.c index 295d0de..7d56869 100644 --- a/lib/sqfs/meta_reader.c +++ b/lib/sqfs/meta_reader.c @@ -11,6 +11,7 @@ #include "sqfs/compress.h" #include "sqfs/error.h" #include "sqfs/data.h" +#include "sqfs/io.h" #include "util.h" #include <stdlib.h> @@ -32,7 +33,7 @@ struct sqfs_meta_reader_t { size_t offset; /* The underlying file descriptor to read from */ - int fd; + sqfs_file_t *file; /* A pointer to the compressor to use for extracting data */ sqfs_compressor_t *cmp; @@ -44,7 +45,8 @@ struct sqfs_meta_reader_t { uint8_t scratch[SQFS_META_BLOCK_SIZE]; }; -sqfs_meta_reader_t *sqfs_meta_reader_create(int fd, sqfs_compressor_t *cmp, +sqfs_meta_reader_t *sqfs_meta_reader_create(sqfs_file_t *file, + sqfs_compressor_t *cmp, uint64_t start, uint64_t limit) { sqfs_meta_reader_t *m = calloc(1, sizeof(*m)); @@ -54,7 +56,7 @@ sqfs_meta_reader_t *sqfs_meta_reader_create(int fd, sqfs_compressor_t *cmp, m->start = start; m->limit = limit; - m->fd = fd; + m->file = file; m->cmp = cmp; return m; } @@ -71,6 +73,7 @@ int sqfs_meta_reader_seek(sqfs_meta_reader_t *m, uint64_t block_start, uint16_t header; ssize_t ret; size_t size; + int err; if (block_start < m->start || block_start >= m->limit) return SQFS_ERROR_OUT_OF_BOUNDS; @@ -83,10 +86,9 @@ int sqfs_meta_reader_seek(sqfs_meta_reader_t *m, uint64_t block_start, return 0; } - if (read_data_at("reading meta data header", block_start, - m->fd, &header, 2)) { - return SQFS_ERROR_IO; - } + err = m->file->read_at(m->file, block_start, &header, 2); + if (err) + return err; header = le16toh(header); compressed = (header & 0x8000) == 0; @@ -98,10 +100,9 @@ int sqfs_meta_reader_seek(sqfs_meta_reader_t *m, uint64_t block_start, if ((block_start + 2 + size) > m->limit) return SQFS_ERROR_OUT_OF_BOUNDS; - if (read_data_at("reading meta data block", block_start + 2, - m->fd, m->data, size)) { - return SQFS_ERROR_IO; - } + err = m->file->read_at(m->file, block_start + 2, m->data, size); + if (err) + return err; if (compressed) { ret = m->cmp->do_block(m->cmp, m->data, size, |