shithub: lwext4

Download patch

ref: 80db1e5d2d318f79f13a2b7b51e485b571995961
parent: fb054e5ea7603fc0f7965f6bdfdfaacf8f3d8f96
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Thu Oct 29 01:55:02 EDT 2015

METADATA_CSUM: HTree directory checksum verification added

--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -278,7 +278,7 @@
  * BIG FAT NOTES:
  *       Currently we do not verify the checksum of HTree node.
  */
-__unused static bool
+static bool
 ext4_dir_dx_checksum_verify(struct ext4_inode_ref *inode_ref,
 				struct ext4_directory_entry_ll *dirent)
 {
@@ -630,6 +630,16 @@
 			return EXT4_ERR_BAD_DX_DIR;
 		}
 
+		if (!ext4_dir_dx_checksum_verify(inode_ref,
+					(struct ext4_directory_entry_ll *)tmp_block->data)) {
+			ext4_dbg(DEBUG_DIR_IDX,
+					DBG_WARN "HTree checksum failed."
+					"Inode: %" PRIu32", "
+					"Block: %" PRIu32"\n",
+					inode_ref->index,
+					next_block);
+		}
+
 		++tmp_dx_block;
 	}
 
@@ -691,6 +701,16 @@
 		if (rc != EOK)
 			return rc;
 
+		if (!ext4_dir_dx_checksum_verify(inode_ref,
+					(struct ext4_directory_entry_ll *)block.data)) {
+			ext4_dbg(DEBUG_DIR_IDX,
+					DBG_WARN "HTree checksum failed."
+					"Inode: %" PRIu32", "
+					"Block: %" PRIu32"\n",
+					inode_ref->index,
+					block_idx);
+		}
+
 		p++;
 
 		/* Don't forget to put old block (prevent memory leak) */
@@ -727,6 +747,16 @@
 	if (rc != EOK)
 		return rc;
 
+	if (!ext4_dir_dx_checksum_verify(inode_ref,
+				(struct ext4_directory_entry_ll *)root_block.data)) {
+		ext4_dbg(DEBUG_DIR_IDX,
+			 DBG_WARN "HTree root checksum failed."
+			 "Inode: %" PRIu32", "
+			 "Block: %" PRIu32"\n",
+			 inode_ref->index,
+			 0);
+	}
+
 	/* Initialize hash info (compute hash value) */
 	struct ext4_hash_info hinfo;
 	rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb, name_len, name);
@@ -767,6 +797,16 @@
 		if (rc != EOK)
 			goto cleanup;
 
+		if (!ext4_dir_checksum_verify(inode_ref,
+				(struct ext4_directory_entry_ll *)leaf_block.data)) {
+			ext4_dbg(DEBUG_DIR_IDX,
+				 DBG_WARN "HTree leaf block checksum failed."
+				 "Inode: %" PRIu32", "
+				 "Block: %" PRIu32"\n",
+				 inode_ref->index,
+				 leaf_block_idx);
+		}
+
 		/* Linear search inside block */
 		struct ext4_directory_entry_ll *res_dentry;
 		rc = ext4_dir_find_in_block(&leaf_block, &fs->sb, name_len,
@@ -1335,6 +1375,16 @@
 	if (rc != EOK)
 		return rc;
 
+	if (!ext4_dir_dx_checksum_verify(parent,
+			(struct ext4_directory_entry_ll *)root_block.data)) {
+		ext4_dbg(DEBUG_DIR_IDX,
+			 DBG_WARN "HTree root checksum failed."
+			 "Inode: %" PRIu32", "
+			 "Block: %" PRIu32"\n",
+			 parent->index,
+			 0);
+	}
+
 	/* Initialize hinfo structure (mainly compute hash) */
 	uint32_t name_len = strlen(name);
 	struct ext4_hash_info hinfo;
@@ -1382,6 +1432,16 @@
 	if (rc != EOK)
 		goto release_index;
 
+	if (!ext4_dir_checksum_verify(parent,
+			(struct ext4_directory_entry_ll *)target_block.data)) {
+		ext4_dbg(DEBUG_DIR_IDX,
+				DBG_WARN "HTree leaf block checksum failed."
+				"Inode: %" PRIu32", "
+				"Block: %" PRIu32"\n",
+				parent->index,
+				leaf_block_idx);
+	}
+
 	/* Check if insert operation passed */
 	rc = ext4_dir_try_insert_entry(&fs->sb, parent, &target_block, child, name,
 				       name_len);
@@ -1451,6 +1511,16 @@
 	rc = ext4_block_get(dir->fs->bdev, &block, fblock);
 	if (rc != EOK)
 		return rc;
+
+	if (!ext4_dir_dx_checksum_verify(dir,
+			(struct ext4_directory_entry_ll *)block.data)) {
+		ext4_dbg(DEBUG_DIR_IDX,
+			 DBG_WARN "HTree root checksum failed."
+			 "Inode: %" PRIu32", "
+			 "Block: %" PRIu32"\n",
+			 dir->index,
+			 0);
+	}
 
 	/* Initialize pointers to data structures */
 	struct ext4_directory_dx_root *root = (void *)block.data;