From e6c323d4d3405130e6bc2392dc28bcfd41feb83a Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 29 Sep 2019 00:25:25 +0200 Subject: Fix data writer: remember where we stored the padding If we don't store the padding location in the deduplication list, the block deduplication might try to deduplicate across two files with padding in between, which can't be done. Signed-off-by: David Oberhollenzer --- lib/sqfs/data_writer/block.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/sqfs') diff --git a/lib/sqfs/data_writer/block.c b/lib/sqfs/data_writer/block.c index 5dce26c..7c52bb4 100644 --- a/lib/sqfs/data_writer/block.c +++ b/lib/sqfs/data_writer/block.c @@ -52,11 +52,32 @@ static size_t deduplicate_blocks(sqfs_data_writer_t *proc, size_t count) static int allign_file(sqfs_data_writer_t *proc, sqfs_block_t *blk) { + sqfs_u32 chksum; + void *padding; + sqfs_u64 size; + size_t diff; + int ret; + if (!(blk->flags & SQFS_BLK_ALLIGN)) return 0; - return padd_sqfs(proc->file, proc->file->get_size(proc->file), - proc->devblksz); + size = proc->file->get_size(proc->file); + diff = size % proc->devblksz; + if (diff == 0) + return 0; + + padding = calloc(1, diff); + if (padding == 0) + return SQFS_ERROR_ALLOC; + + chksum = crc32(0, padding, diff); + + ret = proc->file->write_at(proc->file, size, padding, diff); + free(padding); + if (ret) + return ret; + + return store_block_location(proc, size, diff | (1 << 24), chksum); } int process_completed_block(sqfs_data_writer_t *proc, sqfs_block_t *blk) -- cgit v1.2.3