blob: 78407d32db786a8765f59b3a66ee337da2e156c7 [file] [log] [blame]
Chris Masoneb60cea2007-02-02 09:18:22 -05001#ifndef __CTREE__
2#define __CTREE__
3
Chris Masond97e63b2007-02-20 16:40:44 -05004#define CTREE_BLOCKSIZE 256
Chris Masoneb60cea2007-02-02 09:18:22 -05005
6struct key {
7 u64 objectid;
8 u32 flags;
9 u64 offset;
10} __attribute__ ((__packed__));
11
12struct 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 Masond97e63b2007-02-20 16:40:44 -050025#define MAX_LEVEL 8
Chris Masoneb60cea2007-02-02 09:18:22 -050026#define node_level(f) ((f) & (MAX_LEVEL-1))
27#define is_leaf(f) (node_level(f) == 0)
28
29struct tree_buffer;
Chris Masond97e63b2007-02-20 16:40:44 -050030
31struct alloc_extent {
32 u64 blocknr;
33 u64 num_blocks;
34 u64 num_used;
35} __attribute__ ((__packed__));
36
Chris Masoneb60cea2007-02-02 09:18:22 -050037struct ctree_root {
38 struct tree_buffer *node;
Chris Masond97e63b2007-02-20 16:40:44 -050039 struct ctree_root *extent_root;
40 struct alloc_extent *alloc_extent;
41 struct alloc_extent *reserve_extent;
Chris Masoneb60cea2007-02-02 09:18:22 -050042 int fp;
43 struct radix_tree_root cache_radix;
Chris Masond97e63b2007-02-20 16:40:44 -050044 struct alloc_extent ai1;
45 struct alloc_extent ai2;
Chris Masoneb60cea2007-02-02 09:18:22 -050046};
47
Chris Masond97e63b2007-02-20 16:40:44 -050048struct 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 Masoncfaa7292007-02-21 17:04:57 -050060struct ctree_super_block {
61 struct ctree_root_info root_info;
62 struct ctree_root_info extent_info;
63} __attribute__ ((__packed__));
64
Chris Masoneb60cea2007-02-02 09:18:22 -050065struct item {
66 struct key key;
67 u16 offset;
68 u16 size;
69} __attribute__ ((__packed__));
70
71#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header))
72struct leaf {
73 struct header header;
74 union {
75 struct item items[LEAF_DATA_SIZE/sizeof(struct item)];
76 u8 data[CTREE_BLOCKSIZE-sizeof(struct header)];
77 };
78} __attribute__ ((__packed__));
79
80struct node {
81 struct header header;
82 struct key keys[NODEPTRS_PER_BLOCK];
83 u64 blockptrs[NODEPTRS_PER_BLOCK];
84} __attribute__ ((__packed__));
85
Chris Masond97e63b2007-02-20 16:40:44 -050086struct extent_item {
87 u32 refs;
88 u64 owner;
89} __attribute__ ((__packed__));
90
Chris Masoneb60cea2007-02-02 09:18:22 -050091struct ctree_path {
92 struct tree_buffer *nodes[MAX_LEVEL];
93 int slots[MAX_LEVEL];
94};
95#endif