From: Thomas Weißschuh Date: Thu, 27 Feb 2025 17:16:01 +0000 (+0100) Subject: libc/crc32: make fill value of excluded area configurable X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=977dd748c53a24c01ed23d3be65f6489130795fc;p=thirdparty%2Futil-linux.git libc/crc32: make fill value of excluded area configurable A new user of crc32_exclude_offset() is going to be added which requires a different fill value than the currently hardcoded "0". Add a parameter where each caller can specify their own value. Signed-off-by: Thomas Weißschuh --- diff --git a/include/crc32.h b/include/crc32.h index 0d34da0d2..c78d291b0 100644 --- a/include/crc32.h +++ b/include/crc32.h @@ -10,7 +10,8 @@ extern uint32_t ul_crc32(uint32_t seed, const unsigned char *buf, size_t len); extern uint32_t ul_crc32_exclude_offset(uint32_t seed, const unsigned char *buf, size_t len, - size_t exclude_off, size_t exclude_len); + size_t exclude_off, size_t exclude_len, + uint8_t exclude_fill); #endif diff --git a/lib/crc32.c b/lib/crc32.c index 824693d01..b62b9f638 100644 --- a/lib/crc32.c +++ b/lib/crc32.c @@ -122,7 +122,7 @@ uint32_t ul_crc32(uint32_t seed, const unsigned char *buf, size_t len) } uint32_t ul_crc32_exclude_offset(uint32_t seed, const unsigned char *buf, size_t len, - size_t exclude_off, size_t exclude_len) + size_t exclude_off, size_t exclude_len, uint8_t exclude_fill) { uint32_t crc = seed; const unsigned char *p = buf; @@ -132,7 +132,7 @@ uint32_t ul_crc32_exclude_offset(uint32_t seed, const unsigned char *buf, size_t unsigned char x = *p++; if (i >= exclude_off && i < exclude_off + exclude_len) - x = 0; + x = exclude_fill; crc = crc32_add_char(crc, x); } diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c index a8846be21..dc5bcf3aa 100644 --- a/libblkid/src/partitions/gpt.c +++ b/libblkid/src/partitions/gpt.c @@ -106,7 +106,7 @@ struct gpt_entry { static inline uint32_t count_crc32(const unsigned char *buf, size_t len, size_t exclude_off, size_t exclude_len) { - return (ul_crc32_exclude_offset(~0L, buf, len, exclude_off, exclude_len) ^ ~0L); + return (ul_crc32_exclude_offset(~0L, buf, len, exclude_off, exclude_len, 0) ^ ~0L); } static inline const unsigned char *get_lba_buffer(blkid_probe pr, diff --git a/libblkid/src/superblocks/cramfs.c b/libblkid/src/superblocks/cramfs.c index 6a8731f7b..d9f3ed19d 100644 --- a/libblkid/src/superblocks/cramfs.c +++ b/libblkid/src/superblocks/cramfs.c @@ -64,7 +64,7 @@ static int cramfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag, crc = ~ul_crc32_exclude_offset(~0LL, csummed, csummed_size, offsetof(struct cramfs_super, info.crc), - sizeof_member(struct cramfs_super, info.crc)); + sizeof_member(struct cramfs_super, info.crc), 0); return blkid_probe_verify_csum(pr, crc, expected); } diff --git a/libblkid/src/superblocks/zonefs.c b/libblkid/src/superblocks/zonefs.c index e8fcab34f..8534e2ffe 100644 --- a/libblkid/src/superblocks/zonefs.c +++ b/libblkid/src/superblocks/zonefs.c @@ -54,7 +54,7 @@ static int zonefs_verify_csum(blkid_probe pr, const struct zonefs_super *sb) uint32_t expected = le32_to_cpu(sb->s_crc); uint32_t crc = ul_crc32_exclude_offset( ~0LL, (unsigned char *) sb, sizeof(*sb), - offsetof(__typeof__(*sb), s_crc), sizeof(sb->s_crc)); + offsetof(__typeof__(*sb), s_crc), sizeof(sb->s_crc), 0); return blkid_probe_verify_csum(pr, crc, expected); } diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index 374246ce6..2f850fa8a 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -1043,7 +1043,7 @@ fail: static inline uint32_t count_crc32(const unsigned char *buf, size_t len, size_t ex_off, size_t ex_len) { - return (ul_crc32_exclude_offset(~0L, buf, len, ex_off, ex_len) ^ ~0L); + return (ul_crc32_exclude_offset(~0L, buf, len, ex_off, ex_len, 0) ^ ~0L); } static inline uint32_t gpt_header_count_crc32(struct gpt_header *header)