shithub: lwext4

Download patch

ref: aea94ae650c9ab0c07e057eaaa86346da603c2d5
parent: b0d0fa2f98efa4af0e5ac4af6cd2ccfd473c8b7f
author: ngkaho1234 <[email protected]>
date: Tue Oct 27 03:53:19 EDT 2015

FIX: Inode & block bitmap checksums is not assigned correctly.

--- a/lwext4/ext4_balloc.c
+++ b/lwext4/ext4_balloc.c
@@ -84,11 +84,14 @@
 	uint32_t checksum = 0;
 	if (ext4_sb_has_feature_read_only(sb,
 				EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
+		uint32_t blocks_per_group =
+			ext4_get32(sb, blocks_per_group);
+
 		/* First calculate crc32 checksum against fs uuid */
 		checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
 		/* Then calculate crc32 checksum against block_group_desc */
 		checksum = ext4_crc32c(checksum, bitmap,
-				     ext4_sb_get_block_size(sb));
+				     (blocks_per_group + 7) / 8);
 	}
 	return checksum;
 }
--- a/lwext4/ext4_ialloc.c
+++ b/lwext4/ext4_ialloc.c
@@ -92,11 +92,14 @@
 	uint32_t checksum = 0;
 	if (ext4_sb_has_feature_read_only(sb,
 				EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
+		uint32_t inodes_per_group =
+			ext4_get32(sb, inodes_per_group);
+
 		/* First calculate crc32 checksum against fs uuid */
 		checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
-		/* Then calculate crc32 checksum against block_group_desc */
+		/* Then calculate crc32 checksum against inode bitmap */
 		checksum = ext4_crc32c(checksum, bitmap,
-				     ext4_sb_get_block_size(sb));
+				     (inodes_per_group + 7) / 8);
 	}
 	return checksum;
 }
@@ -116,9 +119,9 @@
 		 hi_checksum = to_le16(checksum >> 16);
 	
 	/* See if we need to assign a 32bit checksum */
-	bg->block_bitmap_csum_lo = lo_checksum;
+	bg->inode_bitmap_csum_lo = lo_checksum;
 	if (desc_size == EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE)
-		bg->block_bitmap_csum_hi = hi_checksum;
+		bg->inode_bitmap_csum_hi = hi_checksum;
 
 }