summaryrefslogtreecommitdiff
path: root/lib/sqfs/write_table.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-08 14:53:30 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-08 14:53:30 +0200
commit3a851dfe87c88ac1d4dddc2a26cc48b037f852f9 (patch)
treea8a8f34291aa58b25737088d247a91a7f60b4fec /lib/sqfs/write_table.c
parent60064dd0412a149fe00cfc4e2f2361c22656db57 (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/write_table.c')
-rw-r--r--lib/sqfs/write_table.c19
1 files changed, 11 insertions, 8 deletions
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 <endian.h>
#include <stdlib.h>
-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;