Although lowmem mode can detect name and hash mismatch in dir_item,
it's done by checking inode_ref to expose such problem.
This patch will enhance dir_item check, by also comparing name and
hash when checking dir_items.
Reported-by: Filippe LeMarchand <gasinvein@xxxxxxxxx>
Signed-off-by: Su Yue <suy.fnst@xxxxxxxxxxxxxx>
---
cmds-check.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/cmds-check.c b/cmds-check.c
index 55afefbc..81578439 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4672,6 +4672,15 @@ static int check_dir_item(struct btrfs_root *root, struct btrfs_key *key,
read_extent_buffer(node, namebuf, (unsigned long)(di + 1), len);
filetype = btrfs_dir_type(node, di);
+ if (key->type == BTRFS_DIR_ITEM_KEY &&
+ key->offset != btrfs_name_hash(namebuf, len)) {
+ err |= -EIO;
+ error("root %llu DIR_ITEM[%llu %llu] name %s namelen %u filetype %u mismatch with its hash, wanted %llu have %llu",
+ root->objectid, key->objectid, key->offset,
+ namebuf, len, filetype, key->offset,
+ btrfs_name_hash(namebuf, len));
+ }
+
btrfs_init_path(&path);
btrfs_dir_item_key_to_cpu(node, di, &location);
--
2.13.2
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html