start of support for subvolumes
[btrfs-progs-unstable.git] / ctree.h
blob19e792703b08b380185e608a85831e7306555088
1 #ifndef __BTRFS__
2 #define __BTRFS__
4 #include "list.h"
5 #include "kerncompat.h"
7 struct btrfs_trans_handle;
9 #define BTRFS_MAGIC "_BtRfS_M"
11 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
12 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
13 #define BTRFS_INODE_MAP_OBJECTID 3ULL
14 #define BTRFS_FS_TREE_OBJECTID 4ULL
15 #define BTRFS_FIRST_FREE_OBJECTID 5ULL
18 * we can actually store much bigger names, but lets not confuse the rest
19 * of linux
21 #define BTRFS_NAME_LEN 255
23 /* 32 bytes in various csum fields */
24 #define BTRFS_CSUM_SIZE 32
27 * the key defines the order in the tree, and so it also defines (optimal)
28 * block layout. objectid corresonds to the inode number. The flags
29 * tells us things about the object, and is a kind of stream selector.
30 * so for a given inode, keys with flags of 1 might refer to the inode
31 * data, flags of 2 may point to file data in the btree and flags == 3
32 * may point to extents.
34 * offset is the starting byte offset for this key in the stream.
36 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
37 * in cpu native order. Otherwise they are identical and their sizes
38 * should be the same (ie both packed)
40 struct btrfs_disk_key {
41 __le64 objectid;
42 __le64 offset;
43 __le32 flags;
44 } __attribute__ ((__packed__));
46 struct btrfs_key {
47 u64 objectid;
48 u64 offset;
49 u32 flags;
50 } __attribute__ ((__packed__));
53 * every tree block (leaf or node) starts with this header.
55 struct btrfs_header {
56 u8 csum[BTRFS_CSUM_SIZE];
57 u8 fsid[16]; /* FS specific uuid */
58 __le64 blocknr; /* which block this node is supposed to live in */
59 __le64 generation;
60 __le64 parentid; /* objectid of the tree root */
61 __le32 ham;
62 __le16 nritems;
63 __le16 flags;
64 u8 level;
65 } __attribute__ ((__packed__));
67 #define BTRFS_MAX_LEVEL 8
68 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
69 sizeof(struct btrfs_header)) / \
70 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
71 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
72 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
74 struct btrfs_buffer;
76 * the super block basically lists the main trees of the FS
77 * it currently lacks any block count etc etc
79 struct btrfs_super_block {
80 u8 csum[BTRFS_CSUM_SIZE];
81 /* the first 3 fields must match struct btrfs_header */
82 u8 fsid[16]; /* FS specific uuid */
83 __le64 blocknr; /* this block number */
84 __le64 magic;
85 __le32 blocksize;
86 __le64 generation;
87 __le64 root;
88 __le64 total_blocks;
89 __le64 blocks_used;
90 __le64 root_dir_objectid;
91 } __attribute__ ((__packed__));
94 * A leaf is full of items. offset and size tell us where to find
95 * the item in the leaf (relative to the start of the data area)
97 struct btrfs_item {
98 struct btrfs_disk_key key;
99 __le32 offset;
100 __le16 size;
101 } __attribute__ ((__packed__));
104 * leaves have an item area and a data area:
105 * [item0, item1....itemN] [free space] [dataN...data1, data0]
107 * The data is separate from the items to get the keys closer together
108 * during searches.
110 struct btrfs_leaf {
111 struct btrfs_header header;
112 struct btrfs_item items[];
113 } __attribute__ ((__packed__));
116 * all non-leaf blocks are nodes, they hold only keys and pointers to
117 * other blocks
119 struct btrfs_key_ptr {
120 struct btrfs_disk_key key;
121 __le64 blockptr;
122 } __attribute__ ((__packed__));
124 struct btrfs_node {
125 struct btrfs_header header;
126 struct btrfs_key_ptr ptrs[];
127 } __attribute__ ((__packed__));
130 * btrfs_paths remember the path taken from the root down to the leaf.
131 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
132 * to any other levels that are present.
134 * The slots array records the index of the item or block pointer
135 * used while walking the tree.
137 struct btrfs_path {
138 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
139 int slots[BTRFS_MAX_LEVEL];
143 * items in the extent btree are used to record the objectid of the
144 * owner of the block and the number of references
146 struct btrfs_extent_item {
147 __le32 refs;
148 __le64 owner;
149 } __attribute__ ((__packed__));
151 struct btrfs_inode_timespec {
152 __le64 sec;
153 __le32 nsec;
154 } __attribute__ ((__packed__));
157 * there is no padding here on purpose. If you want to extent the inode,
158 * make a new item type
160 struct btrfs_inode_item {
161 __le64 generation;
162 __le64 size;
163 __le64 nblocks;
164 __le32 nlink;
165 __le32 uid;
166 __le32 gid;
167 __le32 mode;
168 __le32 rdev;
169 __le16 flags;
170 __le16 compat_flags;
171 struct btrfs_inode_timespec atime;
172 struct btrfs_inode_timespec ctime;
173 struct btrfs_inode_timespec mtime;
174 struct btrfs_inode_timespec otime;
175 } __attribute__ ((__packed__));
177 /* inline data is just a blob of bytes */
178 struct btrfs_inline_data_item {
179 u8 data;
180 } __attribute__ ((__packed__));
182 struct btrfs_dir_item {
183 struct btrfs_disk_key location;
184 __le16 flags;
185 __le16 name_len;
186 u8 type;
187 } __attribute__ ((__packed__));
189 struct btrfs_root_item {
190 struct btrfs_inode_item inode;
191 __le64 root_dirid;
192 __le64 blocknr;
193 __le32 flags;
194 __le64 block_limit;
195 __le64 blocks_used;
196 __le32 refs;
197 } __attribute__ ((__packed__));
199 struct btrfs_file_extent_item {
200 __le64 generation;
202 * disk space consumed by the extent, checksum blocks are included
203 * in these numbers
205 __le64 disk_blocknr;
206 __le64 disk_num_blocks;
208 * the logical offset in file blocks (no csums)
209 * this extent record is for. This allows a file extent to point
210 * into the middle of an existing extent on disk, sharing it
211 * between two snapshots (useful if some bytes in the middle of the
212 * extent have changed
214 __le64 offset;
216 * the logical number of file blocks (no csums included)
218 __le64 num_blocks;
219 } __attribute__ ((__packed__));
221 struct btrfs_csum_item {
222 u8 csum[BTRFS_CSUM_SIZE];
223 } __attribute__ ((__packed__));
225 struct btrfs_inode_map_item {
226 struct btrfs_disk_key key;
227 } __attribute__ ((__packed__));
230 struct btrfs_fs_info {
231 struct btrfs_root *fs_root;
232 struct btrfs_root *extent_root;
233 struct btrfs_root *tree_root;
234 struct btrfs_root *inode_root;
235 struct btrfs_key current_insert;
236 struct btrfs_key last_insert;
237 struct radix_tree_root cache_radix;
238 struct radix_tree_root pinned_radix;
239 struct list_head trans;
240 struct list_head cache;
241 u64 last_inode_alloc;
242 u64 last_inode_alloc_dirid;
243 u64 generation;
244 int cache_size;
245 int fp;
246 struct btrfs_trans_handle *running_transaction;
247 struct btrfs_super_block *disk_super;
251 * in ram representation of the tree. extent_root is used for all allocations
252 * and for the extent tree extent_root root. current_insert is used
253 * only for the extent tree.
255 struct btrfs_root {
256 struct btrfs_buffer *node;
257 struct btrfs_buffer *commit_root;
258 struct btrfs_root_item root_item;
259 struct btrfs_key root_key;
260 struct btrfs_fs_info *fs_info;
261 u32 blocksize;
262 int ref_cows;
263 u32 type;
266 /* the lower bits in the key flags defines the item type */
267 #define BTRFS_KEY_TYPE_MAX 256
268 #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1)
270 #define BTRFS_KEY_OVERFLOW_MAX 128
271 #define BTRFS_KEY_OVERFLOW_SHIFT 8
272 #define BTRFS_KEY_OVERFLOW_MASK (0x7FULL << BTRFS_KEY_OVERFLOW_SHIFT)
275 * inode items have the data typically returned from stat and store other
276 * info about object characteristics. There is one for every file and dir in
277 * the FS
279 #define BTRFS_INODE_ITEM_KEY 1
282 * dir items are the name -> inode pointers in a directory. There is one
283 * for every name in a directory.
285 #define BTRFS_DIR_ITEM_KEY 2
286 #define BTRFS_DIR_INDEX_KEY 3
288 * inline data is file data that fits in the btree.
290 #define BTRFS_INLINE_DATA_KEY 4
292 * extent data is for data that can't fit in the btree. It points to
293 * a (hopefully) huge chunk of disk
295 #define BTRFS_EXTENT_DATA_KEY 5
297 * csum items have the checksums for data in the extents
299 #define BTRFS_CSUM_ITEM_KEY 6
302 * root items point to tree roots. There are typically in the root
303 * tree used by the super block to find all the other trees
305 #define BTRFS_ROOT_ITEM_KEY 7
307 * extent items are in the extent map tree. These record which blocks
308 * are used, and how many references there are to each block
310 #define BTRFS_EXTENT_ITEM_KEY 8
313 * the inode map records which inode numbers are in use and where
314 * they actually live on disk
316 #define BTRFS_INODE_MAP_ITEM_KEY 9
318 * string items are for debugging. They just store a short string of
319 * data in the FS
321 #define BTRFS_STRING_ITEM_KEY 10
323 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
325 return le64_to_cpu(i->generation);
328 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
329 u64 val)
331 i->generation = cpu_to_le64(val);
334 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
336 return le64_to_cpu(i->size);
339 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
341 i->size = cpu_to_le64(val);
344 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
346 return le64_to_cpu(i->nblocks);
349 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
351 i->nblocks = cpu_to_le64(val);
354 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
356 return le32_to_cpu(i->nlink);
359 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
361 i->nlink = cpu_to_le32(val);
364 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
366 return le32_to_cpu(i->uid);
369 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
371 i->uid = cpu_to_le32(val);
374 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
376 return le32_to_cpu(i->gid);
379 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
381 i->gid = cpu_to_le32(val);
384 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
386 return le32_to_cpu(i->mode);
389 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
391 i->mode = cpu_to_le32(val);
394 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
396 return le32_to_cpu(i->rdev);
399 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
401 i->rdev = cpu_to_le32(val);
404 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
406 return le16_to_cpu(i->flags);
409 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
411 i->flags = cpu_to_le16(val);
414 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
416 return le16_to_cpu(i->compat_flags);
419 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
420 u16 val)
422 i->compat_flags = cpu_to_le16(val);
425 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
427 return le64_to_cpu(ts->sec);
430 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
431 u64 val)
433 ts->sec = cpu_to_le64(val);
436 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
438 return le32_to_cpu(ts->nsec);
441 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
442 u32 val)
444 ts->nsec = cpu_to_le32(val);
447 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
449 return le64_to_cpu(ei->owner);
452 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
454 ei->owner = cpu_to_le64(val);
457 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
459 return le32_to_cpu(ei->refs);
462 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
464 ei->refs = cpu_to_le32(val);
467 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
469 return le64_to_cpu(n->ptrs[nr].blockptr);
472 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
473 u64 val)
475 n->ptrs[nr].blockptr = cpu_to_le64(val);
478 static inline u32 btrfs_item_offset(struct btrfs_item *item)
480 return le32_to_cpu(item->offset);
483 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
485 item->offset = cpu_to_le32(val);
488 static inline u32 btrfs_item_end(struct btrfs_item *item)
490 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
493 static inline u16 btrfs_item_size(struct btrfs_item *item)
495 return le16_to_cpu(item->size);
498 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
500 item->size = cpu_to_le16(val);
503 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
505 return le16_to_cpu(d->flags);
508 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
510 d->flags = cpu_to_le16(val);
513 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
515 return d->type;
518 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
520 d->type = val;
523 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
525 return le16_to_cpu(d->name_len);
528 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
530 d->name_len = cpu_to_le16(val);
533 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
534 struct btrfs_disk_key *disk)
536 cpu->offset = le64_to_cpu(disk->offset);
537 cpu->flags = le32_to_cpu(disk->flags);
538 cpu->objectid = le64_to_cpu(disk->objectid);
541 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
542 struct btrfs_key *cpu)
544 disk->offset = cpu_to_le64(cpu->offset);
545 disk->flags = cpu_to_le32(cpu->flags);
546 disk->objectid = cpu_to_le64(cpu->objectid);
549 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
551 return le64_to_cpu(disk->objectid);
554 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
555 u64 val)
557 disk->objectid = cpu_to_le64(val);
560 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
562 return le64_to_cpu(disk->offset);
565 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
566 u64 val)
568 disk->offset = cpu_to_le64(val);
571 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
573 return le32_to_cpu(disk->flags);
576 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
577 u32 val)
579 disk->flags = cpu_to_le32(val);
582 static inline u32 btrfs_key_overflow(struct btrfs_key *key)
584 u32 over = key->flags & BTRFS_KEY_OVERFLOW_MASK;
585 return over >> BTRFS_KEY_OVERFLOW_SHIFT;
588 static inline void btrfs_set_key_overflow(struct btrfs_key *key, u32 over)
590 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
591 over = over << BTRFS_KEY_OVERFLOW_SHIFT;
592 key->flags = (key->flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
595 static inline u32 btrfs_key_type(struct btrfs_key *key)
597 return key->flags & BTRFS_KEY_TYPE_MASK;
600 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
602 return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK;
605 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type)
607 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
608 key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
611 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
613 u32 flags = btrfs_disk_key_flags(key);
614 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
615 flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
616 btrfs_set_disk_key_flags(key, flags);
619 static inline u32 btrfs_disk_key_overflow(struct btrfs_disk_key *key)
621 u32 over = le32_to_cpu(key->flags) & BTRFS_KEY_OVERFLOW_MASK;
622 return over >> BTRFS_KEY_OVERFLOW_SHIFT;
625 static inline void btrfs_set_disK_key_overflow(struct btrfs_disk_key *key,
626 u32 over)
628 u32 flags = btrfs_disk_key_flags(key);
629 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
630 over = over << BTRFS_KEY_OVERFLOW_SHIFT;
631 flags = (flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
632 btrfs_set_disk_key_flags(key, flags);
635 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
637 return le64_to_cpu(h->blocknr);
640 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
642 h->blocknr = cpu_to_le64(blocknr);
645 static inline u64 btrfs_header_generation(struct btrfs_header *h)
647 return le64_to_cpu(h->generation);
650 static inline void btrfs_set_header_generation(struct btrfs_header *h,
651 u64 val)
653 h->generation = cpu_to_le64(val);
656 static inline u64 btrfs_header_parentid(struct btrfs_header *h)
658 return le64_to_cpu(h->parentid);
661 static inline void btrfs_set_header_parentid(struct btrfs_header *h,
662 u64 parentid)
664 h->parentid = cpu_to_le64(parentid);
667 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
669 return le16_to_cpu(h->nritems);
672 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
674 h->nritems = cpu_to_le16(val);
677 static inline u16 btrfs_header_flags(struct btrfs_header *h)
679 return le16_to_cpu(h->flags);
682 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
684 h->flags = cpu_to_le16(val);
687 static inline int btrfs_header_level(struct btrfs_header *h)
689 return h->level;
692 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
694 BUG_ON(level > BTRFS_MAX_LEVEL);
695 h->level = level;
698 static inline int btrfs_is_leaf(struct btrfs_node *n)
700 return (btrfs_header_level(&n->header) == 0);
703 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
705 return le64_to_cpu(item->blocknr);
708 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
710 item->blocknr = cpu_to_le64(val);
713 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
715 return le64_to_cpu(item->root_dirid);
718 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
720 item->root_dirid = cpu_to_le64(val);
723 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
725 return le32_to_cpu(item->refs);
728 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
730 item->refs = cpu_to_le32(val);
733 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
735 return le64_to_cpu(s->blocknr);
738 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
740 s->blocknr = cpu_to_le64(val);
743 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
745 return le64_to_cpu(s->root);
748 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
750 s->root = cpu_to_le64(val);
753 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
755 return le64_to_cpu(s->total_blocks);
758 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
759 u64 val)
761 s->total_blocks = cpu_to_le64(val);
764 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
766 return le64_to_cpu(s->blocks_used);
769 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
770 u64 val)
772 s->blocks_used = cpu_to_le64(val);
775 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
777 return le32_to_cpu(s->blocksize);
780 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
781 u32 val)
783 s->blocksize = cpu_to_le32(val);
786 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
788 return le64_to_cpu(s->root_dir_objectid);
791 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
792 val)
794 s->root_dir_objectid = cpu_to_le64(val);
797 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
799 return (u8 *)l->items;
802 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
805 return le64_to_cpu(e->disk_blocknr);
808 static inline void btrfs_set_file_extent_disk_blocknr(struct
809 btrfs_file_extent_item
810 *e, u64 val)
812 e->disk_blocknr = cpu_to_le64(val);
815 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
817 return le64_to_cpu(e->generation);
820 static inline void btrfs_set_file_extent_generation(struct
821 btrfs_file_extent_item *e,
822 u64 val)
824 e->generation = cpu_to_le64(val);
827 static inline u64 btrfs_file_extent_disk_num_blocks(struct
828 btrfs_file_extent_item *e)
830 return le64_to_cpu(e->disk_num_blocks);
833 static inline void btrfs_set_file_extent_disk_num_blocks(struct
834 btrfs_file_extent_item
835 *e, u64 val)
837 e->disk_num_blocks = cpu_to_le64(val);
840 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
842 return le64_to_cpu(e->offset);
845 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
846 *e, u64 val)
848 e->offset = cpu_to_le64(val);
851 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
854 return le64_to_cpu(e->num_blocks);
857 static inline void btrfs_set_file_extent_num_blocks(struct
858 btrfs_file_extent_item *e,
859 u64 val)
861 e->num_blocks = cpu_to_le64(val);
864 /* helper function to cast into the data area of the leaf. */
865 #define btrfs_item_ptr(leaf, slot, type) \
866 ((type *)(btrfs_leaf_data(leaf) + \
867 btrfs_item_offset((leaf)->items + (slot))))
869 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
870 struct btrfs_root *root);
871 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
872 struct btrfs_buffer *buf);
873 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
874 *root, u64 blocknr, u64 num_blocks, int pin);
875 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
876 *root, struct btrfs_key *key, struct btrfs_path *p, int
877 ins_len, int cow);
878 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
879 void btrfs_init_path(struct btrfs_path *p);
880 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
881 struct btrfs_path *path);
882 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
883 *root, struct btrfs_key *key, void *data, u32 data_size);
884 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
885 *root, struct btrfs_path *path, struct btrfs_key
886 *cpu_key, u32 data_size);
887 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
888 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
889 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
890 *root, struct btrfs_buffer *snap);
891 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
892 btrfs_root *root);
893 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
894 struct btrfs_key *key);
895 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
896 *root, struct btrfs_key *key, struct btrfs_root_item
897 *item);
898 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
899 *root, struct btrfs_key *key, struct btrfs_root_item
900 *item);
901 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
902 btrfs_root_item *item, struct btrfs_key *key);
903 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
904 *root, char *name, int name_len, u64 dir,
905 struct btrfs_key *location, u8 type);
906 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
907 *root, struct btrfs_path *path, u64 dir, char *name,
908 int name_len, int mod);
909 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
910 char *name, int name_len);
911 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
912 struct btrfs_root *fs_root,
913 u64 dirid, u64 *objectid);
914 int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
915 struct btrfs_root *root,
916 u64 objectid, struct btrfs_key *location);
917 int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
918 struct btrfs_root *root, struct btrfs_path *path,
919 u64 objectid, int mod);
920 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
921 *root, u64 objectid, struct btrfs_inode_item
922 *inode_item);
923 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
924 *root, struct btrfs_path *path, u64 objectid, int mod);
925 #endif