{
struct ext2_group_desc *desc = ext2fs_group_desc(fs, fs->group_desc,
group);
-- size_t size = EXT2_DESC_SIZE(fs->super);
- size_t offset;
++ size_t offset, size = EXT2_DESC_SIZE(fs->super);
__u16 crc = 0;
-
- if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
- size_t offset = offsetof(struct ext2_group_desc, bg_checksum);
-
#ifdef WORDS_BIGENDIAN
- struct ext4_group_desc swabdesc;
- size_t save_size = size;
- const size_t ext4_bg_size = sizeof(struct ext4_group_desc);
- struct ext2_group_desc *save_desc = desc;
-
- /* Have to swab back to little-endian to do the checksum */
- if (size > ext4_bg_size)
- size = ext4_bg_size;
- memcpy(&swabdesc, desc, size);
- ext2fs_swap_group_desc2(fs,
- (struct ext2_group_desc *) &swabdesc);
- desc = (struct ext2_group_desc *) &swabdesc;
-
- group = ext2fs_swab32(group);
+ struct ext4_group_desc swabdesc;
+ size_t save_size = size;
+ const size_t ext4_bg_size = sizeof(struct ext4_group_desc);
+ struct ext2_group_desc *save_desc = desc;
+
+ /* Have to swab back to little-endian to do the checksum */
+ if (size > ext4_bg_size)
+ size = ext4_bg_size;
+ memcpy(&swabdesc, desc, size);
+ ext2fs_swap_group_desc2(fs, (struct ext2_group_desc *) &swabdesc);
+ desc = (struct ext2_group_desc *) &swabdesc;
+ group = ext2fs_swab32(group);
#endif
- crc = ext2fs_crc16(~0, fs->super->s_uuid,
- sizeof(fs->super->s_uuid));
- crc = ext2fs_crc16(crc, &group, sizeof(group));
- crc = ext2fs_crc16(crc, desc, offset);
- offset += sizeof(desc->bg_checksum); /* skip checksum */
- /* for checksum of struct ext4_group_desc do the rest...*/
- if (offset < size) {
- crc = ext2fs_crc16(crc, (char *)desc + offset,
- size - offset);
- }
+
+ if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
+ /* new metadata csum code */
+ __u16 old_crc;
+ __u32 crc32;
+
+ old_crc = desc->bg_checksum;
+ desc->bg_checksum = 0;
+ crc32 = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)&group,
+ sizeof(group));
+ crc32 = ext2fs_crc32c_le(crc32, (unsigned char *)desc,
+ size);
+ desc->bg_checksum = old_crc;
#ifdef WORDS_BIGENDIAN
- /*
- * If the size of the bg descriptor is greater than 64
- * bytes, which is the size of the traditional ext4 bg
- * descriptor, checksum the rest of the descriptor here
- */
if (save_size > ext4_bg_size)
- crc = ext2fs_crc16(crc,
+ crc32 = ext2fs_crc32c_le(crc32,
(char *)save_desc + ext4_bg_size,
save_size - ext4_bg_size);
#endif