aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h129
1 files changed, 115 insertions, 14 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 68f0af39777f..68e3da274f17 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -10,7 +10,8 @@ struct btrfs_trans_handle;
10 10
11#define BTRFS_ROOT_TREE_OBJECTID 1 11#define BTRFS_ROOT_TREE_OBJECTID 1
12#define BTRFS_EXTENT_TREE_OBJECTID 2 12#define BTRFS_EXTENT_TREE_OBJECTID 2
13#define BTRFS_FS_TREE_OBJECTID 3 13#define BTRFS_INODE_MAP_OBJECTID 3
14#define BTRFS_FS_TREE_OBJECTID 4
14 15
15/* 16/*
16 * the key defines the order in the tree, and so it also defines (optimal) 17 * the key defines the order in the tree, and so it also defines (optimal)
@@ -178,31 +179,65 @@ struct btrfs_root_item {
178 __le64 block_limit; 179 __le64 block_limit;
179 __le64 blocks_used; 180 __le64 blocks_used;
180 __le32 refs; 181 __le32 refs;
181}; 182} __attribute__ ((__packed__));
182 183
183/* 184struct btrfs_file_extent_item {
184 * in ram representation of the tree. extent_root is used for all allocations 185 /*
185 * and for the extent tree extent_root root. current_insert is used 186 * disk space consumed by the extent, checksum blocks are included
186 * only for the extent tree. 187 * in these numbers
187 */ 188 */
188struct btrfs_root { 189 __le64 disk_blocknr;
189 struct btrfs_buffer *node; 190 __le64 disk_num_blocks;
190 struct btrfs_buffer *commit_root; 191 /*
192 * the logical offset in file bytes (no csums)
193 * this extent record is for. This allows a file extent to point
194 * into the middle of an existing extent on disk, sharing it
195 * between two snapshots (useful if some bytes in the middle of the
196 * extent have changed
197 */
198 __le64 offset;
199 /*
200 * the logical number of file blocks (no csums included)
201 */
202 __le64 num_blocks;
203} __attribute__ ((__packed__));
204
205struct btrfs_inode_map_item {
206 struct btrfs_disk_key key;
207} __attribute__ ((__packed__));
208
209struct btrfs_fs_info {
210 struct btrfs_root *fs_root;
191 struct btrfs_root *extent_root; 211 struct btrfs_root *extent_root;
192 struct btrfs_root *tree_root; 212 struct btrfs_root *tree_root;
213 struct btrfs_root *inode_root;
193 struct btrfs_key current_insert; 214 struct btrfs_key current_insert;
194 struct btrfs_key last_insert; 215 struct btrfs_key last_insert;
195 int fp;
196 struct radix_tree_root cache_radix; 216 struct radix_tree_root cache_radix;
197 struct radix_tree_root pinned_radix; 217 struct radix_tree_root pinned_radix;
198 struct list_head trans; 218 struct list_head trans;
199 struct list_head cache; 219 struct list_head cache;
220 u64 last_inode_alloc;
221 u64 last_inode_alloc_dirid;
200 int cache_size; 222 int cache_size;
201 int ref_cows; 223 int fp;
224 struct btrfs_trans_handle *running_transaction;
225};
226
227/*
228 * in ram representation of the tree. extent_root is used for all allocations
229 * and for the extent tree extent_root root. current_insert is used
230 * only for the extent tree.
231 */
232struct btrfs_root {
233 struct btrfs_buffer *node;
234 struct btrfs_buffer *commit_root;
202 struct btrfs_root_item root_item; 235 struct btrfs_root_item root_item;
203 struct btrfs_key root_key; 236 struct btrfs_key root_key;
237 struct btrfs_fs_info *fs_info;
204 u32 blocksize; 238 u32 blocksize;
205 struct btrfs_trans_handle *running_transaction; 239 int ref_cows;
240 u32 type;
206}; 241};
207 242
208/* the lower bits in the key flags defines the item type */ 243/* the lower bits in the key flags defines the item type */
@@ -240,11 +275,17 @@ struct btrfs_root {
240 * are used, and how many references there are to each block 275 * are used, and how many references there are to each block
241 */ 276 */
242#define BTRFS_EXTENT_ITEM_KEY 6 277#define BTRFS_EXTENT_ITEM_KEY 6
278
279/*
280 * the inode map records which inode numbers are in use and where
281 * they actually live on disk
282 */
283#define BTRFS_INODE_MAP_ITEM_KEY 7
243/* 284/*
244 * string items are for debugging. They just store a short string of 285 * string items are for debugging. They just store a short string of
245 * data in the FS 286 * data in the FS
246 */ 287 */
247#define BTRFS_STRING_ITEM_KEY 7 288#define BTRFS_STRING_ITEM_KEY 8
248 289
249static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) 290static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
250{ 291{
@@ -654,6 +695,57 @@ static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
654{ 695{
655 return (u8 *)l->items; 696 return (u8 *)l->items;
656} 697}
698
699static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
700 *e)
701{
702 return le64_to_cpu(e->disk_blocknr);
703}
704
705static inline void btrfs_set_file_extent_disk_blocknr(struct
706 btrfs_file_extent_item
707 *e, u64 val)
708{
709 e->disk_blocknr = cpu_to_le64(val);
710}
711
712static inline u64 btrfs_file_extent_disk_num_blocks(struct
713 btrfs_file_extent_item *e)
714{
715 return le64_to_cpu(e->disk_num_blocks);
716}
717
718static inline void btrfs_set_file_extent_disk_num_blocks(struct
719 btrfs_file_extent_item
720 *e, u64 val)
721{
722 e->disk_num_blocks = cpu_to_le64(val);
723}
724
725static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
726{
727 return le64_to_cpu(e->offset);
728}
729
730static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
731 *e, u64 val)
732{
733 e->offset = cpu_to_le64(val);
734}
735
736static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
737 *e)
738{
739 return le64_to_cpu(e->num_blocks);
740}
741
742static inline void btrfs_set_file_extent_num_blocks(struct
743 btrfs_file_extent_item *e,
744 u64 val)
745{
746 e->num_blocks = cpu_to_le64(val);
747}
748
657/* helper function to cast into the data area of the leaf. */ 749/* helper function to cast into the data area of the leaf. */
658#define btrfs_item_ptr(leaf, slot, type) \ 750#define btrfs_item_ptr(leaf, slot, type) \
659 ((type *)(btrfs_leaf_data(leaf) + \ 751 ((type *)(btrfs_leaf_data(leaf) + \
@@ -701,4 +793,13 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
701 int name_len, int mod); 793 int name_len, int mod);
702int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path, 794int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
703 char *name, int name_len); 795 char *name, int name_len);
796int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
797 struct btrfs_root *fs_root,
798 u64 dirid, u64 *objectid);
799int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
800 struct btrfs_root *root,
801 u64 objectid, struct btrfs_key *location);
802int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
803 struct btrfs_root *root, struct btrfs_path *path,
804 u64 objectid, int mod);
704#endif 805#endif