diff options
author | Su Yue <suy.fnst@cn.fujitsu.com> | 2017-07-14 15:47:44 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2017-08-24 19:07:46 +0200 |
commit | d4833d709b338df0edf7a721a155e9e00723911a (patch) | |
tree | 891cd5555c2ac797c0a1114115b0d3839834168b | |
parent | 0cd4485178dcf97f2ed58a59f5d3ade56aa11eb3 (diff) |
btrfs-progs: check: verify name in dir_item for original mode
In original mode, we don't check if the name in dir_item matches the
hash in key.offset.
In the following case, original mode will report nothing wrong while
lowmem mode will detect the name and hash mismatch.
------
item 72 key (79177 DIR_ITEM 54846528) itemoff 12380 itemsize 88
location key (4222342 INODE_ITEM 0) type FILE
transid 170929 data_len 0 name_len 14
name: deprecated.sxt
location key (13590433 INODE_ITEM 0) type FILE
transid 796448 data_len 0 name_len 14
name: deprecated.txt
------
In above case, hash of "deprecated.txt" matches with 54846528,
while hash of "deprecated.sxt" should be 2008317993.
Reported-by: Filippe LeMarchand <gasinvein@gmail.com>
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | cmds-check.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/cmds-check.c b/cmds-check.c index c5faa2b3..48e9a070 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -1528,6 +1528,14 @@ static int process_dir_item(struct extent_buffer *eb, read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len); + if (key->type == BTRFS_DIR_ITEM_KEY && + key->offset != btrfs_name_hash(namebuf, len)) { + rec->errors |= I_ERR_ODD_DIR_ITEM; + error("DIR_ITEM[%llu %llu] name %s namelen %u filetype %u mismatch with its hash, wanted %llu have %llu", + key->objectid, key->offset, namebuf, len, filetype, + key->offset, btrfs_name_hash(namebuf, len)); + } + if (location.type == BTRFS_INODE_ITEM_KEY) { add_inode_backref(inode_cache, location.objectid, key->objectid, key->offset, namebuf, |