aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-29 00:25:25 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-29 00:25:25 +0200
commite6c323d4d3405130e6bc2392dc28bcfd41feb83a (patch)
tree2fe39ef6782218532fc63b669b00c8505a7ac090 /lib
parent59f84d6a0427068e112a945d5c1882f8ee974176 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfs/data_writer/block.c25
1 files changed, 23 insertions, 2 deletions
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)