ctree.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 ctree_super_block {
  51. struct ctree_root_info root_info;
  52. struct ctree_root_info extent_info;
  53. } __attribute__ ((__packed__));
  54. struct item {
  55. struct key key;
  56. u16 offset;
  57. u16 size;
  58. } __attribute__ ((__packed__));
  59. #define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header))
  60. struct leaf {
  61. struct header header;
  62. union {
  63. struct item items[LEAF_DATA_SIZE/sizeof(struct item)];
  64. u8 data[CTREE_BLOCKSIZE-sizeof(struct header)];
  65. };
  66. } __attribute__ ((__packed__));
  67. struct node {
  68. struct header header;
  69. struct key keys[NODEPTRS_PER_BLOCK];
  70. u64 blockptrs[NODEPTRS_PER_BLOCK];
  71. } __attribute__ ((__packed__));
  72. struct extent_item {
  73. u32 refs;
  74. u64 owner;
  75. } __attribute__ ((__packed__));
  76. struct ctree_path {
  77. struct tree_buffer *nodes[MAX_LEVEL];
  78. int slots[MAX_LEVEL];
  79. };
  80. #endif