From 8bb05ac73a5b448b339ce0bc8d396c82c459b47f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 21:33:32 +0200 Subject: Merging upstream version 2.40. Signed-off-by: Daniel Baumann --- libblkid/src/superblocks/cramfs.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'libblkid/src/superblocks/cramfs.c') diff --git a/libblkid/src/superblocks/cramfs.c b/libblkid/src/superblocks/cramfs.c index 2a87acd..6a8731f 100644 --- a/libblkid/src/superblocks/cramfs.c +++ b/libblkid/src/superblocks/cramfs.c @@ -37,12 +37,6 @@ struct cramfs_super #define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */ -static int cramfs_is_little_endian(const struct blkid_idmag *mag) -{ - assert(mag->len == 4); - return memcmp(mag->magic, "\x45\x3d\xcd\x28", 4) == 0; -} - static uint32_t cfs32_to_cpu(int le, uint32_t value) { if (le) @@ -52,10 +46,10 @@ static uint32_t cfs32_to_cpu(int le, uint32_t value) } static int cramfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag, - struct cramfs_super *cs, int le) + const struct cramfs_super *cs, int le) { uint32_t crc, expected, csummed_size; - unsigned char *csummed; + const unsigned char *csummed; expected = cfs32_to_cpu(le, cs->info.crc); csummed_size = cfs32_to_cpu(le, cs->size); @@ -67,22 +61,23 @@ static int cramfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag, csummed = blkid_probe_get_sb_buffer(pr, mag, csummed_size); if (!csummed) return 0; - memset(csummed + offsetof(struct cramfs_super, info.crc), 0, sizeof(uint32_t)); - crc = ~ul_crc32(~0LL, csummed, csummed_size); + crc = ~ul_crc32_exclude_offset(~0LL, csummed, csummed_size, + offsetof(struct cramfs_super, info.crc), + sizeof_member(struct cramfs_super, info.crc)); return blkid_probe_verify_csum(pr, crc, expected); } static int probe_cramfs(blkid_probe pr, const struct blkid_idmag *mag) { - struct cramfs_super *cs; + const struct cramfs_super *cs; cs = blkid_probe_get_sb(pr, mag, struct cramfs_super); if (!cs) return errno ? -errno : 1; - int le = cramfs_is_little_endian(mag); + int le = mag->hint == BLKID_ENDIANNESS_LITTLE; int v2 = cfs32_to_cpu(le, cs->flags) & CRAMFS_FLAG_FSID_VERSION_2; if (v2 && !cramfs_verify_csum(pr, mag, cs, le)) @@ -91,8 +86,7 @@ static int probe_cramfs(blkid_probe pr, const struct blkid_idmag *mag) blkid_probe_set_label(pr, cs->name, sizeof(cs->name)); blkid_probe_set_fssize(pr, cfs32_to_cpu(le, cs->size)); blkid_probe_sprintf_version(pr, "%d", v2 ? 2 : 1); - blkid_probe_set_fsendianness(pr, - le ? BLKID_ENDIANNESS_LITTLE : BLKID_ENDIANNESS_BIG); + blkid_probe_set_fsendianness(pr, mag->hint); return 0; } @@ -103,8 +97,10 @@ const struct blkid_idinfo cramfs_idinfo = .probefunc = probe_cramfs, .magics = { - { .magic = "\x45\x3d\xcd\x28", .len = 4 }, - { .magic = "\x28\xcd\x3d\x45", .len = 4 }, + { .magic = "\x45\x3d\xcd\x28", .len = 4, + .hint = BLKID_ENDIANNESS_LITTLE }, + { .magic = "\x28\xcd\x3d\x45", .len = 4, + .hint = BLKID_ENDIANNESS_BIG }, { NULL } } }; -- cgit v1.2.3