From: Theodore Ts'o Date: Mon, 14 Apr 2014 20:37:23 +0000 (-0400) Subject: Merge branch 'maint' into next X-Git-Tag: v1.43-WIP-2015-05-18~298 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71715a5a9ad409df162dbb58a4c3b6fd2c5868d5;p=thirdparty%2Fe2fsprogs.git Merge branch 'maint' into next --- 71715a5a9ad409df162dbb58a4c3b6fd2c5868d5 diff --cc lib/ext2fs/csum.c index 9f08c3871,669f8068c..d7dbca833 --- a/lib/ext2fs/csum.c +++ b/lib/ext2fs/csum.c @@@ -723,40 -34,46 +723,39 @@@ __u16 ext2fs_group_desc_csum(ext2_filsy { 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