tree-checker.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_fs_info;
  11. struct btrfs_chunk;
  12. struct btrfs_key;
  13. /* All the extra info needed to verify the parentness of a tree block. */
  14. struct btrfs_tree_parent_check {
  15. /*
  16. * The owner check against the tree block.
  17. *
  18. * Can be 0 to skip the owner check.
  19. */
  20. u64 owner_root;
  21. /*
  22. * Expected transid, can be 0 to skip the check, but such skip
  23. * should only be utilized for backref walk related code.
  24. */
  25. u64 transid;
  26. /*
  27. * The expected first key.
  28. *
  29. * This check can be skipped if @has_first_key is false, such skip
  30. * can happen for case where we don't have the parent node key,
  31. * e.g. reading the tree root, doing backref walk.
  32. */
  33. struct btrfs_key first_key;
  34. bool has_first_key;
  35. /* The expected level. Should always be set. */
  36. u8 level;
  37. };
  38. enum btrfs_tree_block_status {
  39. BTRFS_TREE_BLOCK_CLEAN,
  40. BTRFS_TREE_BLOCK_INVALID_NRITEMS,
  41. BTRFS_TREE_BLOCK_INVALID_PARENT_KEY,
  42. BTRFS_TREE_BLOCK_BAD_KEY_ORDER,
  43. BTRFS_TREE_BLOCK_INVALID_LEVEL,
  44. BTRFS_TREE_BLOCK_INVALID_FREE_SPACE,
  45. BTRFS_TREE_BLOCK_INVALID_OFFSETS,
  46. BTRFS_TREE_BLOCK_INVALID_BLOCKPTR,
  47. BTRFS_TREE_BLOCK_INVALID_ITEM,
  48. BTRFS_TREE_BLOCK_INVALID_OWNER,
  49. BTRFS_TREE_BLOCK_WRITTEN_NOT_SET,
  50. };
  51. #define BTRFS_BLOCK_GROUP_VALID (BTRFS_BLOCK_GROUP_TYPE_MASK | \
  52. BTRFS_BLOCK_GROUP_PROFILE_MASK | \
  53. BTRFS_BLOCK_GROUP_REMAPPED)
  54. /*
  55. * Exported simply for btrfs-progs which wants to have the
  56. * btrfs_tree_block_status return codes.
  57. */
  58. enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf);
  59. enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node);
  60. int btrfs_check_leaf(struct extent_buffer *leaf);
  61. int btrfs_check_node(struct extent_buffer *node);
  62. int btrfs_check_chunk_valid(const struct btrfs_fs_info *fs_info,
  63. const struct extent_buffer *leaf,
  64. const struct btrfs_chunk *chunk, u64 logical,
  65. u32 sectorsize);
  66. int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
  67. int btrfs_verify_level_key(struct extent_buffer *eb,
  68. const struct btrfs_tree_parent_check *check);
  69. #endif