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/comp/compressor.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/comp/compressor.c')
-rw-r--r-- | lib/sqfs/comp/compressor.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c index 4d073f2..c938fe2 100644 --- a/lib/sqfs/comp/compressor.c +++ b/lib/sqfs/comp/compressor.c @@ -43,29 +43,31 @@ static const char *names[] = { [SQFS_COMP_ZSTD] = "zstd", }; -int sqfs_generic_write_options(int fd, const void *data, size_t size) +int sqfs_generic_write_options(sqfs_file_t *file, const void *data, size_t size) { uint8_t buffer[size + 2]; + int ret; *((uint16_t *)buffer) = htole16(0x8000 | size); memcpy(buffer + 2, data, size); - if (write_data("writing compressor options", - fd, buffer, sizeof(buffer))) { - return SQFS_ERROR_IO; - } + ret = file->write_at(file, sizeof(sqfs_super_t), + buffer, sizeof(buffer)); + if (ret) + return ret; return sizeof(buffer); } -int sqfs_generic_read_options(int fd, void *data, size_t size) +int sqfs_generic_read_options(sqfs_file_t *file, void *data, size_t size) { uint8_t buffer[size + 2]; + int ret; - if (read_data_at("reading compressor options", sizeof(sqfs_super_t), - fd, buffer, sizeof(buffer))) { - return SQFS_ERROR_IO; - } + ret = file->read_at(file, sizeof(sqfs_super_t), + buffer, sizeof(buffer)); + if (ret) + return ret; if (le16toh(*((uint16_t *)buffer)) != (0x8000 | size)) return SQFS_ERROR_CORRUPTED; |