btrfs-progs: recieve: add missing short option E to getopt
[platform/upstream/btrfs-progs.git] / cmds-check.c
index 339297d..f6320b2 100644 (file)
@@ -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,
@@ -4672,6 +4680,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);
 
@@ -6626,7 +6643,7 @@ static int process_chunk_item(struct cache_tree *chunk_cache,
         * wrong onwer(3) out of chunk tree, to pass both chunk tree check
         * and owner<->key_type check.
         */
-       ret = btrfs_check_chunk_valid(global_info->tree_root, eb, chunk, slot,
+       ret = btrfs_check_chunk_valid(global_info, eb, chunk, slot,
                                      key->offset);
        if (ret < 0) {
                error("chunk(%llu, %llu) is not valid, ignore it",
@@ -10927,7 +10944,7 @@ static int check_dev_extent_item(struct btrfs_fs_info *fs_info,
 
        l = path.nodes[0];
        chunk = btrfs_item_ptr(l, path.slots[0], struct btrfs_chunk);
-       ret = btrfs_check_chunk_valid(chunk_root, l, chunk, path.slots[0],
+       ret = btrfs_check_chunk_valid(fs_info, l, chunk, path.slots[0],
                                      chunk_key.offset);
        if (ret < 0)
                goto out;
@@ -11185,7 +11202,7 @@ static int check_chunk_item(struct btrfs_fs_info *fs_info,
        chunk = btrfs_item_ptr(eb, slot, struct btrfs_chunk);
        length = btrfs_chunk_length(eb, chunk);
        chunk_end = chunk_key.offset + length;
-       ret = btrfs_check_chunk_valid(extent_root, eb, chunk, slot,
+       ret = btrfs_check_chunk_valid(fs_info, eb, chunk, slot,
                                      chunk_key.offset);
        if (ret < 0) {
                error("chunk[%llu %llu) is invalid", chunk_key.offset,
@@ -12745,7 +12762,7 @@ int cmd_check(int argc, char **argv)
                        { NULL, 0, NULL, 0}
                };
 
-               c = getopt_long(argc, argv, "as:br:p", long_options, NULL);
+               c = getopt_long(argc, argv, "as:br:pEQ", long_options, NULL);
                if (c < 0)
                        break;
                switch(c) {