tree-checker.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) Qu Wenruo 2017. All rights reserved.
  4. */
  5. #ifndef BTRFS_TREE_CHECKER_H
  6. #define BTRFS_TREE_CHECKER_H
  7. #include <linux/types.h>
  8. #include <uapi/linux/btrfs_tree.h>
  9. struct extent_buffer;
  10. struct btrfs_chunk;
  11. struct btrfs_key;
  12. /* All the extra info needed to verify the parentness of a tree block. */
  13. struct btrfs_tree_parent_check {
  14. /*
  15. * The owner check against the tree block.
  16. *
  17. * Can be 0 to skip the owner check.
  18. */
  19. u64 owner_root;
  20. /*
  21. * Expected transid, can be 0 to skip the check, but such skip
  22. * should only be utilized for backref walk related code.
  23. */
  24. u64 transid;
  25. /*
  26. * The expected first key.
  27. *
  28. * This check can be skipped if @has_first_key is false, such skip
  29. * can happen for case where we don't have the parent node key,
  30. * e.g. reading the tree root, doing backref walk.
  31. */
  32. struct btrfs_key first_key;
  33. bool has_first_key;
  34. /* The expected level. Should always be set. */
  35. u8 level;
  36. };
  37. enum btrfs_tree_block_status {
  38. BTRFS_TREE_BLOCK_CLEAN,
  39. BTRFS_TREE_BLOCK_INVALID_NRITEMS,
  40. BTRFS_TREE_BLOCK_INVALID_PARENT_KEY,
  41. BTRFS_TREE_BLOCK_BAD_KEY_ORDER,
  42. BTRFS_TREE_BLOCK_INVALID_LEVEL,
  43. BTRFS_TREE_BLOCK_INVALID_FREE_SPACE,
  44. BTRFS_TREE_BLOCK_INVALID_OFFSETS,
  45. BTRFS_TREE_BLOCK_INVALID_BLOCKPTR,
  46. BTRFS_TREE_BLOCK_INVALID_ITEM,
  47. BTRFS_TREE_BLOCK_INVALID_OWNER,
  48. BTRFS_TREE_BLOCK_WRITTEN_NOT_SET,
  49. };
  50. /*
  51. * Exported simply for btrfs-progs which wants to have the
  52. * btrfs_tree_block_status return codes.
  53. */
  54. enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf);
  55. enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node);
  56. int btrfs_check_leaf(struct extent_buffer *leaf);
  57. int btrfs_check_node(struct extent_buffer *node);
  58. int btrfs_check_chunk_valid(struct extent_buffer *leaf,
  59. struct btrfs_chunk *chunk, u64 logical);
  60. int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
  61. int btrfs_verify_level_key(struct extent_buffer *eb, int level,
  62. struct btrfs_key *first_key, u64 parent_transid);
  63. #endif