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