6 #define CTREE_BLOCKSIZE 1024
9 * the key defines the order in the tree, and so it also defines (optimal)
10 * block layout. objectid corresonds to the inode number. The flags
11 * tells us things about the object, and is a kind of stream selector.
12 * so for a given inode, keys with flags of 1 might refer to the inode
13 * data, flags of 2 may point to file data in the btree and flags == 3
14 * may point to extents.
16 * offset is the starting byte offset for this key in the stream.
22 } __attribute__ ((__packed__
));
25 * every tree block (leaf or node) starts with this header.
28 u64 fsid
[2]; /* FS specific uuid */
29 u64 blocknr
; /* which block this node is supposed to live in */
30 u64 parentid
; /* objectid of the tree root */
35 /* generation flags to be added */
36 } __attribute__ ((__packed__
));
38 #define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct header)) / \
39 (sizeof(struct key) + sizeof(u64)))
42 #define node_level(f) ((f) & (MAX_LEVEL-1))
43 #define is_leaf(f) (node_level(f) == 0)
48 * in ram representation of the tree. extent_root is used for all allocations
49 * and for the extent tree extent_root root. current_insert is used
50 * only for the extent tree.
53 struct tree_buffer
*node
;
54 struct ctree_root
*extent_root
;
55 struct key current_insert
;
57 struct radix_tree_root cache_radix
;
58 struct list_head trans
;
59 struct list_head cache
;
64 * describes a tree on disk
66 struct ctree_root_info
{
67 u64 fsid
[2]; /* FS specific uuid */
68 u64 blocknr
; /* blocknr of this block */
69 u64 objectid
; /* inode number of this root */
70 u64 tree_root
; /* the tree root block */
73 u64 snapuuid
[2]; /* root specific uuid */
74 } __attribute__ ((__packed__
));
77 * the super block basically lists the main trees of the FS
78 * it currently lacks any block count etc etc
80 struct ctree_super_block
{
81 struct ctree_root_info root_info
;
82 struct ctree_root_info extent_info
;
83 } __attribute__ ((__packed__
));
86 * A leaf is full of items. The exact type of item is defined by
87 * the key flags parameter. offset and size tell us where to find
88 * the item in the leaf (relative to the start of the data area)
94 } __attribute__ ((__packed__
));
97 * leaves have an item area and a data area:
98 * [item0, item1....itemN] [free space] [dataN...data1, data0]
100 * The data is separate from the items to get the keys closer together
103 #define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header))
105 struct header header
;
107 struct item items
[LEAF_DATA_SIZE
/sizeof(struct item
)];
108 u8 data
[CTREE_BLOCKSIZE
-sizeof(struct header
)];
110 } __attribute__ ((__packed__
));
113 * all non-leaf blocks are nodes, they hold only keys and pointers to
117 struct header header
;
118 struct key keys
[NODEPTRS_PER_BLOCK
];
119 u64 blockptrs
[NODEPTRS_PER_BLOCK
];
120 } __attribute__ ((__packed__
));
123 * items in the extent btree are used to record the objectid of the
124 * owner of the block and the number of references
129 } __attribute__ ((__packed__
));
132 * ctree_paths remember the path taken from the root down to the leaf.
133 * level 0 is always the leaf, and nodes[1...MAX_LEVEL] will point
134 * to any other levels that are present.
136 * The slots array records the index of the item or block pointer
137 * used while walking the tree.
140 struct tree_buffer
*nodes
[MAX_LEVEL
];
141 int slots
[MAX_LEVEL
];
144 struct tree_buffer
*alloc_free_block(struct ctree_root
*root
);
145 int btrfs_inc_ref(struct ctree_root
*root
, struct tree_buffer
*buf
);
146 int free_extent(struct ctree_root
*root
, u64 blocknr
, u64 num_blocks
);
147 int search_slot(struct ctree_root
*root
, struct key
*key
, struct ctree_path
*p
, int ins_len
, int cow
);
148 void release_path(struct ctree_root
*root
, struct ctree_path
*p
);
149 void init_path(struct ctree_path
*p
);
150 int del_item(struct ctree_root
*root
, struct ctree_path
*path
);
151 int insert_item(struct ctree_root
*root
, struct key
*key
, void *data
, int data_size
);
152 int next_leaf(struct ctree_root
*root
, struct ctree_path
*path
);
153 int leaf_free_space(struct leaf
*leaf
);