From 515c5e38a4089135a2a7717ce50d6d2c30137d3f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 26 Jul 2019 22:39:00 +0200 Subject: Compute per-block and per-fragment checksums in data wrtier Signed-off-by: David Oberhollenzer --- lib/sqfs/data_writer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c index aff296e..9e20889 100644 --- a/lib/sqfs/data_writer.c +++ b/lib/sqfs/data_writer.c @@ -128,20 +128,25 @@ int data_writer_flush_fragments(data_writer_t *data) static int flush_data_block(data_writer_t *data, size_t size, file_info_t *fi, int flags) { - uint32_t out; + uint32_t out, chksum; if (is_zero_block(data->block, size)) { - fi->blocks[data->block_idx++].size = 0; + fi->blocks[data->block_idx].size = 0; + fi->blocks[data->block_idx].chksum = 0; fi->sparse += size; + data->block_idx++; return 0; } + chksum = update_crc32(0, data->block, size); + if (size < data->super->block_size && !(flags & DW_DONT_FRAGMENT)) { if (data->frag_offset + size > data->super->block_size) { if (data_writer_flush_fragments(data)) return -1; } + fi->fragment_chksum = chksum; fi->fragment_offset = data->frag_offset; fi->fragment = data->num_fragments; @@ -152,7 +157,9 @@ static int flush_data_block(data_writer_t *data, size_t size, if (write_compressed(data, data->block, size, &out, flags)) return -1; - fi->blocks[data->block_idx++].size = out; + fi->blocks[data->block_idx].chksum = chksum; + fi->blocks[data->block_idx].size = out; + data->block_idx++; } return 0; -- cgit v1.2.3