19888c340SDavid Sterba /* SPDX-License-Identifier: GPL-2.0 */ 2557ea5ddSQu Wenruo /* 3557ea5ddSQu Wenruo * Copyright (C) Qu Wenruo 2017. All rights reserved. 4557ea5ddSQu Wenruo */ 5557ea5ddSQu Wenruo 69888c340SDavid Sterba #ifndef BTRFS_TREE_CHECKER_H 79888c340SDavid Sterba #define BTRFS_TREE_CHECKER_H 8557ea5ddSQu Wenruo 927137facSChristoph Hellwig #include <uapi/linux/btrfs_tree.h> 1027137facSChristoph Hellwig 1127137facSChristoph Hellwig struct extent_buffer; 1227137facSChristoph Hellwig struct btrfs_chunk; 1327137facSChristoph Hellwig 1427137facSChristoph Hellwig /* All the extra info needed to verify the parentness of a tree block. */ 1527137facSChristoph Hellwig struct btrfs_tree_parent_check { 1627137facSChristoph Hellwig /* 1727137facSChristoph Hellwig * The owner check against the tree block. 1827137facSChristoph Hellwig * 1927137facSChristoph Hellwig * Can be 0 to skip the owner check. 2027137facSChristoph Hellwig */ 2127137facSChristoph Hellwig u64 owner_root; 2227137facSChristoph Hellwig 2327137facSChristoph Hellwig /* 2427137facSChristoph Hellwig * Expected transid, can be 0 to skip the check, but such skip 2527137facSChristoph Hellwig * should only be utlized for backref walk related code. 2627137facSChristoph Hellwig */ 2727137facSChristoph Hellwig u64 transid; 2827137facSChristoph Hellwig 2927137facSChristoph Hellwig /* 3027137facSChristoph Hellwig * The expected first key. 3127137facSChristoph Hellwig * 3227137facSChristoph Hellwig * This check can be skipped if @has_first_key is false, such skip 3327137facSChristoph Hellwig * can happen for case where we don't have the parent node key, 3427137facSChristoph Hellwig * e.g. reading the tree root, doing backref walk. 3527137facSChristoph Hellwig */ 3627137facSChristoph Hellwig struct btrfs_key first_key; 3727137facSChristoph Hellwig bool has_first_key; 3827137facSChristoph Hellwig 3927137facSChristoph Hellwig /* The expected level. Should always be set. */ 4027137facSChristoph Hellwig u8 level; 4127137facSChristoph Hellwig }; 42557ea5ddSQu Wenruo 43a7b4e6c7SJosef Bacik enum btrfs_tree_block_status { 44a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_CLEAN, 45a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_NRITEMS, 46a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_PARENT_KEY, 47a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_BAD_KEY_ORDER, 48a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_LEVEL, 49a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_FREE_SPACE, 50a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_OFFSETS, 51a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_BLOCKPTR, 52a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_ITEM, 53a7b4e6c7SJosef Bacik BTRFS_TREE_BLOCK_INVALID_OWNER, 54a7b4e6c7SJosef Bacik }; 55a7b4e6c7SJosef Bacik 56924452c8SJosef Bacik /* 57924452c8SJosef Bacik * Exported simply for btrfs-progs which wants to have the 58924452c8SJosef Bacik * btrfs_tree_block_status return codes. 59924452c8SJosef Bacik */ 60924452c8SJosef Bacik enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf); 61c26fa931SJosef Bacik enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node); 62924452c8SJosef Bacik 6385d8a826SJosef Bacik int btrfs_check_leaf(struct extent_buffer *leaf); 64813fd1dcSDavid Sterba int btrfs_check_node(struct extent_buffer *node); 65557ea5ddSQu Wenruo 66ddaf1d5aSDavid Sterba int btrfs_check_chunk_valid(struct extent_buffer *leaf, 6782fc28fbSQu Wenruo struct btrfs_chunk *chunk, u64 logical); 6888c602abSQu Wenruo int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner); 69*2cac5af1SJosef Bacik int btrfs_verify_level_key(struct extent_buffer *eb, int level, 70*2cac5af1SJosef Bacik struct btrfs_key *first_key, u64 parent_transid); 7182fc28fbSQu Wenruo 72557ea5ddSQu Wenruo #endif 73