Linux 6.11-rc2
[linux-2.6-block.git] / fs / btrfs / tree-checker.h
CommitLineData
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
12struct extent_buffer;
13struct btrfs_chunk;
602035d7 14struct btrfs_key;
27137fac
CH
15
16/* All the extra info needed to verify the parentness of a tree block. */
17struct btrfs_tree_parent_check {
18 /*
19 * The owner check against the tree block.
20 *
21 * Can be 0 to skip the owner check.
22 */
23 u64 owner_root;
24
25 /*
26 * Expected transid, can be 0 to skip the check, but such skip
eefaf0a1 27 * should only be utilized for backref walk related code.
27137fac
CH
28 */
29 u64 transid;
30
31 /*
32 * The expected first key.
33 *
34 * This check can be skipped if @has_first_key is false, such skip
35 * can happen for case where we don't have the parent node key,
36 * e.g. reading the tree root, doing backref walk.
37 */
38 struct btrfs_key first_key;
39 bool has_first_key;
40
41 /* The expected level. Should always be set. */
42 u8 level;
43};
557ea5dd 44
a7b4e6c7
JB
45enum btrfs_tree_block_status {
46 BTRFS_TREE_BLOCK_CLEAN,
47 BTRFS_TREE_BLOCK_INVALID_NRITEMS,
48 BTRFS_TREE_BLOCK_INVALID_PARENT_KEY,
49 BTRFS_TREE_BLOCK_BAD_KEY_ORDER,
50 BTRFS_TREE_BLOCK_INVALID_LEVEL,
51 BTRFS_TREE_BLOCK_INVALID_FREE_SPACE,
52 BTRFS_TREE_BLOCK_INVALID_OFFSETS,
53 BTRFS_TREE_BLOCK_INVALID_BLOCKPTR,
54 BTRFS_TREE_BLOCK_INVALID_ITEM,
55 BTRFS_TREE_BLOCK_INVALID_OWNER,
e03418ab 56 BTRFS_TREE_BLOCK_WRITTEN_NOT_SET,
a7b4e6c7
JB
57};
58
924452c8
JB
59/*
60 * Exported simply for btrfs-progs which wants to have the
61 * btrfs_tree_block_status return codes.
62 */
63enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf);
c26fa931 64enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node);
924452c8 65
85d8a826 66int btrfs_check_leaf(struct extent_buffer *leaf);
813fd1dc 67int btrfs_check_node(struct extent_buffer *node);
557ea5dd 68
ddaf1d5a 69int btrfs_check_chunk_valid(struct extent_buffer *leaf,
82fc28fb 70 struct btrfs_chunk *chunk, u64 logical);
88c602ab 71int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
2cac5af1
JB
72int btrfs_verify_level_key(struct extent_buffer *eb, int level,
73 struct btrfs_key *first_key, u64 parent_transid);
82fc28fb 74
557ea5dd 75#endif