From 3a851dfe87c88ac1d4dddc2a26cc48b037f852f9 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 8 Sep 2019 14:53:30 +0200 Subject: 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 --- lib/sqfs/write_table.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/sqfs/write_table.c') diff --git a/lib/sqfs/write_table.c b/lib/sqfs/write_table.c index c264ebd..70c7d19 100644 --- a/lib/sqfs/write_table.c +++ b/lib/sqfs/write_table.c @@ -12,16 +12,18 @@ #include "sqfs/super.h" #include "sqfs/table.h" #include "sqfs/data.h" +#include "sqfs/io.h" #include "util.h" #include #include -int sqfs_write_table(int outfd, sqfs_super_t *super, sqfs_compressor_t *cmp, - const void *data, size_t table_size, uint64_t *start) +int sqfs_write_table(sqfs_file_t *file, sqfs_super_t *super, + sqfs_compressor_t *cmp, const void *data, + size_t table_size, uint64_t *start) { size_t block_count, list_size, diff, blkidx = 0; - uint64_t block, *locations; + uint64_t off, block, *locations; sqfs_meta_writer_t *m; uint32_t offset; int ret; @@ -36,7 +38,7 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, sqfs_compressor_t *cmp, return SQFS_ERROR_ALLOC; /* Write actual data */ - m = sqfs_meta_writer_create(outfd, cmp, false); + m = sqfs_meta_writer_create(file, cmp, false); if (m == NULL) { ret = SQFS_ERROR_ALLOC; goto out_idx; @@ -69,11 +71,12 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, sqfs_compressor_t *cmp, *start = super->bytes_used; list_size = sizeof(uint64_t) * block_count; - if (write_data("writing table locations", outfd, - locations, list_size)) { - ret = SQFS_ERROR_IO; + + off = file->get_size(file); + + ret = file->write_at(file, off, locations, list_size); + if (ret) goto out; - } super->bytes_used += list_size; -- cgit v1.2.3