diff --git a/check/main.c b/check/main.c index db055ae19..96c7ef7d8 100644 --- a/check/main.c +++ b/check/main.c @@ -87,6 +87,7 @@ bool is_free_space_tree = false; bool init_extent_tree = false; bool check_data_csum = false; static bool found_free_ino_cache = false; +static bool found_unknown_key = false; struct cache_tree *roots_info_cache = NULL; enum btrfs_check_mode { @@ -1895,6 +1896,10 @@ static int process_one_leaf(struct btrfs_root *root, struct extent_buffer *eb, ret = process_xattr_item(eb, i, &key, active_node); break; default: + error("Unknown key (%llu %u %llu) found in leaf %llu", + key.objectid, key.type, key.offset, + eb->start); + found_unknown_key = true; break; }; } @@ -4027,6 +4032,8 @@ static int check_fs_roots(struct cache_tree *root_cache) free_extent_cache_tree(&wc.shared); if (!cache_tree_empty(&wc.shared)) fprintf(stderr, "warning line %d\n", __LINE__); + if (!err && found_unknown_key) + err = 1; return err; } diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index ea4d40178..8a4c5bc1e 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -2808,8 +2808,9 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path) case BTRFS_XATTR_ITEM_KEY: break; default: - error("ITEM[%llu %u %llu] UNKNOWN TYPE", - key.objectid, key.type, key.offset); + error("ITEM[%llu %u %llu] UNKNOWN TYPE in leaf %llu", + key.objectid, key.type, key.offset, node->start); + err |= UNKNOWN_KEY; } } diff --git a/check/mode-lowmem.h b/check/mode-lowmem.h index cd0355465..ec199b4c8 100644 --- a/check/mode-lowmem.h +++ b/check/mode-lowmem.h @@ -48,6 +48,7 @@ #define INVALID_GENERATION (1U << 26) /* Generation is too new */ #define SUPER_BYTES_USED_ERROR (1U << 27) /* Super bytes_used is invalid */ #define DUP_FILENAME_ERROR (1U << 28) /* DIR_ITEM contains duplicate names */ +#define UNKNOWN_KEY (1U << 29) /* Found unknown key type in fs trees */ /* * Error bit for low memory mode check. diff --git a/tests/fsck-tests/069-unknown-fs-tree-key/test.sh b/tests/fsck-tests/069-unknown-fs-tree-key/test.sh new file mode 100755 index 000000000..ea4f04e28 --- /dev/null +++ b/tests/fsck-tests/069-unknown-fs-tree-key/test.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Verify that check can report unknown key types in subvolume trees + +source "$TEST_TOP/common" || exit + +check_prereq btrfs + +check_image() { + run_mustfail "unknown keys in subvolume trees not reported as error" \ + "$TOP/btrfs" check "$1" +} + +check_all_images diff --git a/tests/fsck-tests/069-unknown-fs-tree-key/unknown_key_empty.img.xz b/tests/fsck-tests/069-unknown-fs-tree-key/unknown_key_empty.img.xz new file mode 100644 index 000000000..300a7cc92 Binary files /dev/null and b/tests/fsck-tests/069-unknown-fs-tree-key/unknown_key_empty.img.xz differ