From 8ef9f10b20e313db5edd0b9c11ecdd8690812b8d Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 9 Sep 2019 11:45:26 +0200 Subject: Remove ad-hoc image size accounting Much simpler to just set the correct size in the end, before writing the super block. Signed-off-by: David Oberhollenzer --- lib/sqfs/id_table.c | 2 +- lib/sqfs/write_table.c | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'lib/sqfs') diff --git a/lib/sqfs/id_table.c b/lib/sqfs/id_table.c index 34db8f7..92a0039 100644 --- a/lib/sqfs/id_table.c +++ b/lib/sqfs/id_table.c @@ -132,7 +132,7 @@ int sqfs_id_table_write(sqfs_id_table_t *tbl, sqfs_file_t *file, super->id_count = tbl->num_ids; - ret = sqfs_write_table(file, super, cmp, tbl->ids, + ret = sqfs_write_table(file, cmp, tbl->ids, sizeof(tbl->ids[0]) * tbl->num_ids, &start); super->id_table_start = start; diff --git a/lib/sqfs/write_table.c b/lib/sqfs/write_table.c index 70c7d19..8d20a74 100644 --- a/lib/sqfs/write_table.c +++ b/lib/sqfs/write_table.c @@ -18,14 +18,12 @@ #include #include -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) +int sqfs_write_table(sqfs_file_t *file, 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 off, block, *locations; + uint64_t off, *locations; sqfs_meta_writer_t *m; - uint32_t offset; int ret; block_count = table_size / SQFS_META_BLOCK_SIZE; @@ -45,8 +43,7 @@ int sqfs_write_table(sqfs_file_t *file, sqfs_super_t *super, } while (table_size > 0) { - sqfs_meta_writer_get_position(m, &block, &offset); - locations[blkidx++] = htole64(super->bytes_used + block); + locations[blkidx++] = htole64(file->get_size(file)); diff = SQFS_META_BLOCK_SIZE; if (diff > table_size) @@ -64,11 +61,8 @@ int sqfs_write_table(sqfs_file_t *file, sqfs_super_t *super, if (ret) goto out; - sqfs_meta_writer_get_position(m, &block, &offset); - super->bytes_used += block; - /* write location list */ - *start = super->bytes_used; + *start = file->get_size(file); list_size = sizeof(uint64_t) * block_count; @@ -78,8 +72,6 @@ int sqfs_write_table(sqfs_file_t *file, sqfs_super_t *super, if (ret) goto out; - super->bytes_used += list_size; - /* cleanup */ ret = 0; out: -- cgit v1.2.3