From 854119c62621e017c13be5192a9494c0eea2fe2f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 6 Dec 2020 00:35:01 +0100 Subject: libsqfs: implement exact matching in the default block writer. Instead of comparing (compresed, disk-size, checksum) tuples to find block matches, do an exact, byte-for-byte comparison of the data stored on disk to avoid the possibility of a spurious colision. Since this is the desired behaviour, make it the default, optionally overrideable through a flag. Signed-off-by: David Oberhollenzer --- include/sqfs/block_writer.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'include/sqfs') diff --git a/include/sqfs/block_writer.h b/include/sqfs/block_writer.h index 6352f4d..6376d2e 100644 --- a/include/sqfs/block_writer.h +++ b/include/sqfs/block_writer.h @@ -90,6 +90,32 @@ struct sqfs_block_writer_t { sqfs_u64 (*get_block_count)(const sqfs_block_writer_t *wr); }; +/** + * @enum SQFS_BLOCK_WRITER_FLAGS + * + * @brief Flags that can be passed to @ref sqfs_block_writer_create + */ +typedef enum { + /** + * @brief If set, only compare checksums when deduplicating blocks. + * + * Since squashfs-tools-ng version 1.1, the default for the block + * writer is to compare checksum & size for blocks during deduplication + * and then read the potential match back from disk and do a byte for + * byte comparison to make absolutely sure they match. + * + * If this flag is set, the hash & size check is treated as being + * sufficient for block deduplication, which does increase performance, + * but risks data loss or corruption if a hash collision occours. + */ + SQFS_BLOCK_WRITER_HASH_COMPARE_ONLY = 0x01, + + /** + * @brief A combination of all valid flags. + */ + SQFS_BLOCK_WRITER_ALL_FLAGS = 0x01 +} SQFS_BLOCK_WRITER_FLAGS; + #ifdef __cplusplus extern "C" { #endif @@ -102,7 +128,8 @@ extern "C" { * @param file A pointer to a file object that data should be appended to. * @param devblksz The underlying device block size if output data * should be aligned. - * @param flags Currently must be set to 0 or creation will fail. + * @param flags A combination of @ref SQFS_BLOCK_WRITER_FLAGS values. If an + * unknown flag is set, creation will fail. * * @return A pointer to a new block writer on success, NULL on failure. */ -- cgit v1.2.3