ctree.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef __CTREE__
  2. #define __CTREE__
  3. #define CTREE_BLOCKSIZE 256
  4. struct key {
  5. u64 objectid;
  6. u32 flags;
  7. u64 offset;
  8. } __attribute__ ((__packed__));
  9. struct header {
  10. u64 fsid[2]; /* FS specific uuid */
  11. u64 blocknr;
  12. u64 parentid;
  13. u32 csum;
  14. u32 ham;
  15. u16 nritems;
  16. u16 flags;
  17. } __attribute__ ((__packed__));
  18. #define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct header)) / \
  19. (sizeof(struct key) + sizeof(u64)))
  20. #define MAX_LEVEL 8
  21. #define node_level(f) ((f) & (MAX_LEVEL-1))
  22. #define is_leaf(f) (node_level(f) == 0)
  23. struct tree_buffer;
  24. struct alloc_extent {
  25. u64 blocknr;
  26. u64 num_blocks;
  27. u64 num_used;
  28. } __attribute__ ((__packed__));
  29. struct ctree_root {
  30. struct tree_buffer *node;
  31. struct ctree_root *extent_root;
  32. struct alloc_extent *alloc_extent;
  33. struct alloc_extent *reserve_extent;
  34. int fp;
  35. struct radix_tree_root cache_radix;
  36. struct alloc_extent ai1;
  37. struct alloc_extent ai2;
  38. };
  39. struct ctree_root_info {
  40. u64 fsid[2]; /* FS specific uuid */
  41. u64 blocknr; /* blocknr of this block */
  42. u64 objectid; /* inode number of this root */
  43. u64 tree_root; /* the tree root */
  44. u32 csum;
  45. u32 ham;
  46. struct alloc_extent alloc_extent;
  47. struct alloc_extent reserve_extent;
  48. u64 snapuuid[2]; /* root specific uuid */
  49. } __attribute__ ((__packed__));
  50. struct item {
  51. struct key key;
  52. u16 offset;
  53. u16 size;
  54. } __attribute__ ((__packed__));
  55. #define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header))
  56. struct leaf {
  57. struct header header;
  58. union {
  59. struct item items[LEAF_DATA_SIZE/sizeof(struct item)];
  60. u8 data[CTREE_BLOCKSIZE-sizeof(struct header)];
  61. };
  62. } __attribute__ ((__packed__));
  63. struct node {
  64. struct header header;
  65. struct key keys[NODEPTRS_PER_BLOCK];
  66. u64 blockptrs[NODEPTRS_PER_BLOCK];
  67. } __attribute__ ((__packed__));
  68. struct extent_item {
  69. u32 refs;
  70. u64 owner;
  71. } __attribute__ ((__packed__));
  72. struct ctree_path {
  73. struct tree_buffer *nodes[MAX_LEVEL];
  74. int slots[MAX_LEVEL];
  75. };
  76. #endif