]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libc/crc32: make fill value of excluded area configurable
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 27 Feb 2025 17:16:01 +0000 (18:16 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 27 Feb 2025 17:16:01 +0000 (18:16 +0100)
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 <thomas@t-8ch.de>
include/crc32.h
lib/crc32.c
libblkid/src/partitions/gpt.c
libblkid/src/superblocks/cramfs.c
libblkid/src/superblocks/zonefs.c
libfdisk/src/gpt.c

index 0d34da0d24946e2b819b7919a56f001781f12b78..c78d291b016fb1802229ab37f42b83398f66c227 100644 (file)
@@ -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
 
index 824693d017a0f21bee00bd7ff61e53ae4136b7e4..b62b9f63807a5c0e4546746f38ea6727568151dd 100644 (file)
@@ -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);
        }
index a8846be21f27eeead4a0e1b7ea66987c90bf03f1..dc5bcf3aa44bd395a5ea1f60a4864233a29250ed 100644 (file)
@@ -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,
index 6a8731f7bf714ec7d8eccbe5d8fd385ff8fbd8e3..d9f3ed19d8a712fc51a05af840ddb2173e7896cf 100644 (file)
@@ -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);
 }
index e8fcab34fe30cbb4576e5e579292fb2deddfce64..8534e2ffe40fdd26e50e287ff748788fcf66463e 100644 (file)
@@ -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);
 }
 
index 374246ce6be20ccbba6bca7c83cd922a9581e9e8..2f850fa8a1202e0c5af23c4c53e51a2f3284b952 100644 (file)
@@ -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)