Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 1 | #ifndef __CTREE__ |
| 2 | #define __CTREE__ |
| 3 | |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame^] | 4 | #define CTREE_BLOCKSIZE 4096 |
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 | |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 31 | struct ctree_root { |
| 32 | struct tree_buffer *node; |
Chris Mason | d97e63b | 2007-02-20 16:40:44 -0500 | [diff] [blame] | 33 | struct ctree_root *extent_root; |
Chris Mason | 9a8dd15 | 2007-02-23 08:38:36 -0500 | [diff] [blame] | 34 | struct key current_insert; |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 35 | int fp; |
| 36 | struct radix_tree_root cache_radix; |
| 37 | }; |
| 38 | |
Chris Mason | d97e63b | 2007-02-20 16:40:44 -0500 | [diff] [blame] | 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; |
Chris Mason | d97e63b | 2007-02-20 16:40:44 -0500 | [diff] [blame] | 46 | u64 snapuuid[2]; /* root specific uuid */ |
| 47 | } __attribute__ ((__packed__)); |
| 48 | |
Chris Mason | cfaa729 | 2007-02-21 17:04:57 -0500 | [diff] [blame] | 49 | struct ctree_super_block { |
| 50 | struct ctree_root_info root_info; |
| 51 | struct ctree_root_info extent_info; |
| 52 | } __attribute__ ((__packed__)); |
| 53 | |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 54 | struct item { |
| 55 | struct key key; |
| 56 | u16 offset; |
| 57 | u16 size; |
| 58 | } __attribute__ ((__packed__)); |
| 59 | |
| 60 | #define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header)) |
| 61 | struct leaf { |
| 62 | struct header header; |
| 63 | union { |
| 64 | struct item items[LEAF_DATA_SIZE/sizeof(struct item)]; |
| 65 | u8 data[CTREE_BLOCKSIZE-sizeof(struct header)]; |
| 66 | }; |
| 67 | } __attribute__ ((__packed__)); |
| 68 | |
| 69 | struct node { |
| 70 | struct header header; |
| 71 | struct key keys[NODEPTRS_PER_BLOCK]; |
| 72 | u64 blockptrs[NODEPTRS_PER_BLOCK]; |
| 73 | } __attribute__ ((__packed__)); |
| 74 | |
Chris Mason | d97e63b | 2007-02-20 16:40:44 -0500 | [diff] [blame] | 75 | struct extent_item { |
| 76 | u32 refs; |
| 77 | u64 owner; |
| 78 | } __attribute__ ((__packed__)); |
| 79 | |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 80 | struct ctree_path { |
| 81 | struct tree_buffer *nodes[MAX_LEVEL]; |
| 82 | int slots[MAX_LEVEL]; |
| 83 | }; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame^] | 84 | |
| 85 | struct tree_buffer *alloc_free_block(struct ctree_root *root); |
| 86 | int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks); |
| 87 | int search_slot(struct ctree_root *root, struct key *key, struct ctree_path *p, int ins_len); |
| 88 | void release_path(struct ctree_root *root, struct ctree_path *p); |
| 89 | void init_path(struct ctree_path *p); |
| 90 | int del_item(struct ctree_root *root, struct ctree_path *path); |
| 91 | int insert_item(struct ctree_root *root, struct key *key, void *data, int data_size); |
| 92 | int next_leaf(struct ctree_root *root, struct ctree_path *path); |
| 93 | int leaf_free_space(struct leaf *leaf); |
Chris Mason | eb60cea | 2007-02-02 09:18:22 -0500 | [diff] [blame] | 94 | #endif |