Commit | Line | Data |
---|---|---|
9888c340 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
557ea5dd QW |
2 | /* |
3 | * Copyright (C) Qu Wenruo 2017. All rights reserved. | |
557ea5dd QW |
4 | */ |
5 | ||
9888c340 DS |
6 | #ifndef BTRFS_TREE_CHECKER_H |
7 | #define BTRFS_TREE_CHECKER_H | |
557ea5dd | 8 | |
602035d7 | 9 | #include <linux/types.h> |
27137fac CH |
10 | #include <uapi/linux/btrfs_tree.h> |
11 | ||
12 | struct extent_buffer; | |
2a9bb78c | 13 | struct btrfs_fs_info; |
27137fac | 14 | struct btrfs_chunk; |
602035d7 | 15 | struct btrfs_key; |
27137fac CH |
16 | |
17 | /* All the extra info needed to verify the parentness of a tree block. */ | |
18 | struct btrfs_tree_parent_check { | |
19 | /* | |
20 | * The owner check against the tree block. | |
21 | * | |
22 | * Can be 0 to skip the owner check. | |
23 | */ | |
24 | u64 owner_root; | |
25 | ||
26 | /* | |
27 | * Expected transid, can be 0 to skip the check, but such skip | |
eefaf0a1 | 28 | * should only be utilized for backref walk related code. |
27137fac CH |
29 | */ |
30 | u64 transid; | |
31 | ||
32 | /* | |
33 | * The expected first key. | |
34 | * | |
35 | * This check can be skipped if @has_first_key is false, such skip | |
36 | * can happen for case where we don't have the parent node key, | |
37 | * e.g. reading the tree root, doing backref walk. | |
38 | */ | |
39 | struct btrfs_key first_key; | |
40 | bool has_first_key; | |
41 | ||
42 | /* The expected level. Should always be set. */ | |
43 | u8 level; | |
44 | }; | |
557ea5dd | 45 | |
a7b4e6c7 JB |
46 | enum btrfs_tree_block_status { |
47 | BTRFS_TREE_BLOCK_CLEAN, | |
48 | BTRFS_TREE_BLOCK_INVALID_NRITEMS, | |
49 | BTRFS_TREE_BLOCK_INVALID_PARENT_KEY, | |
50 | BTRFS_TREE_BLOCK_BAD_KEY_ORDER, | |
51 | BTRFS_TREE_BLOCK_INVALID_LEVEL, | |
52 | BTRFS_TREE_BLOCK_INVALID_FREE_SPACE, | |
53 | BTRFS_TREE_BLOCK_INVALID_OFFSETS, | |
54 | BTRFS_TREE_BLOCK_INVALID_BLOCKPTR, | |
55 | BTRFS_TREE_BLOCK_INVALID_ITEM, | |
56 | BTRFS_TREE_BLOCK_INVALID_OWNER, | |
e03418ab | 57 | BTRFS_TREE_BLOCK_WRITTEN_NOT_SET, |
a7b4e6c7 JB |
58 | }; |
59 | ||
924452c8 JB |
60 | /* |
61 | * Exported simply for btrfs-progs which wants to have the | |
62 | * btrfs_tree_block_status return codes. | |
63 | */ | |
64 | enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf); | |
c26fa931 | 65 | enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node); |
924452c8 | 66 | |
85d8a826 | 67 | int btrfs_check_leaf(struct extent_buffer *leaf); |
813fd1dc | 68 | int btrfs_check_node(struct extent_buffer *node); |
557ea5dd | 69 | |
2a9bb78c QW |
70 | int btrfs_check_chunk_valid(const struct btrfs_fs_info *fs_info, |
71 | const struct extent_buffer *leaf, | |
72 | const struct btrfs_chunk *chunk, u64 logical, | |
73 | u32 sectorsize); | |
88c602ab | 74 | int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner); |
c88ebf1d FM |
75 | int btrfs_verify_level_key(struct extent_buffer *eb, |
76 | const struct btrfs_tree_parent_check *check); | |
82fc28fb | 77 | |
557ea5dd | 78 | #endif |