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_DEV_TREE_OBJECTID 2ULL
13 #define BTRFS_EXTENT_TREE_OBJECTID 3ULL
14 #define BTRFS_FS_TREE_OBJECTID 4ULL
15 #define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL
16 #define BTRFS_FIRST_FREE_OBJECTID 6ULL
19 * we can actually store much bigger names, but lets not confuse the rest
22 #define BTRFS_NAME_LEN 255
24 /* 32 bytes in various csum fields */
25 #define BTRFS_CSUM_SIZE 32
28 * the key defines the order in the tree, and so it also defines (optimal)
29 * block layout. objectid corresonds to the inode number. The flags
30 * tells us things about the object, and is a kind of stream selector.
31 * so for a given inode, keys with flags of 1 might refer to the inode
32 * data, flags of 2 may point to file data in the btree and flags == 3
33 * may point to extents.
35 * offset is the starting byte offset for this key in the stream.
37 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
38 * in cpu native order. Otherwise they are identical and their sizes
39 * should be the same (ie both packed)
41 struct btrfs_disk_key {
45 } __attribute__ ((__packed__));
51 } __attribute__ ((__packed__));
54 * every tree block (leaf or node) starts with this header.
57 u8 csum[BTRFS_CSUM_SIZE];
58 u8 fsid[16]; /* FS specific uuid */
59 __le64 blocknr; /* which block this node is supposed to live in */
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))
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 */
90 __le64 root_dir_objectid;
91 __le64 last_device_id;
92 /* fields below here vary with the underlying disk */
93 __le64 device_block_start;
94 __le64 device_num_blocks;
97 } __attribute__ ((__packed__));
100 * A leaf is full of items. offset and size tell us where to find
101 * the item in the leaf (relative to the start of the data area)
104 struct btrfs_disk_key key;
107 } __attribute__ ((__packed__));
110 * leaves have an item area and a data area:
111 * [item0, item1....itemN] [free space] [dataN...data1, data0]
113 * The data is separate from the items to get the keys closer together
117 struct btrfs_header header;
118 struct btrfs_item items[];
119 } __attribute__ ((__packed__));
122 * all non-leaf blocks are nodes, they hold only keys and pointers to
125 struct btrfs_key_ptr {
126 struct btrfs_disk_key key;
128 } __attribute__ ((__packed__));
131 struct btrfs_header header;
132 struct btrfs_key_ptr ptrs[];
133 } __attribute__ ((__packed__));
136 * btrfs_paths remember the path taken from the root down to the leaf.
137 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
138 * to any other levels that are present.
140 * The slots array records the index of the item or block pointer
141 * used while walking the tree.
144 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
145 int slots[BTRFS_MAX_LEVEL];
149 * items in the extent btree are used to record the objectid of the
150 * owner of the block and the number of references
152 struct btrfs_extent_item {
155 } __attribute__ ((__packed__));
157 struct btrfs_inode_timespec {
160 } __attribute__ ((__packed__));
163 * there is no padding here on purpose. If you want to extent the inode,
164 * make a new item type
166 struct btrfs_inode_item {
178 struct btrfs_inode_timespec atime;
179 struct btrfs_inode_timespec ctime;
180 struct btrfs_inode_timespec mtime;
181 struct btrfs_inode_timespec otime;
182 } __attribute__ ((__packed__));
184 /* inline data is just a blob of bytes */
185 struct btrfs_inline_data_item {
187 } __attribute__ ((__packed__));
189 struct btrfs_dir_item {
190 struct btrfs_disk_key location;
194 } __attribute__ ((__packed__));
196 struct btrfs_root_item {
197 struct btrfs_inode_item inode;
204 } __attribute__ ((__packed__));
206 #define BTRFS_FILE_EXTENT_REG 0
207 #define BTRFS_FILE_EXTENT_INLINE 1
209 struct btrfs_file_extent_item {
213 * disk space consumed by the extent, checksum blocks are included
217 __le64 disk_num_blocks;
219 * the logical offset in file blocks (no csums)
220 * this extent record is for. This allows a file extent to point
221 * into the middle of an existing extent on disk, sharing it
222 * between two snapshots (useful if some bytes in the middle of the
223 * extent have changed
227 * the logical number of file blocks (no csums included)
230 } __attribute__ ((__packed__));
232 struct btrfs_csum_item {
233 u8 csum[BTRFS_CSUM_SIZE];
234 } __attribute__ ((__packed__));
236 struct btrfs_device_item {
239 } __attribute__ ((__packed__));
241 /* tag for the radix tree of block groups in ram */
242 #define BTRFS_BLOCK_GROUP_DIRTY 0
243 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
246 #define BTRFS_BLOCK_GROUP_DATA 1
247 struct btrfs_block_group_item {
250 } __attribute__ ((__packed__));
252 struct btrfs_block_group_cache {
253 struct btrfs_key key;
254 struct btrfs_block_group_item item;
257 struct btrfs_fs_info {
258 struct btrfs_root *fs_root;
259 struct btrfs_root *extent_root;
260 struct btrfs_root *tree_root;
261 struct btrfs_root *dev_root;
262 struct btrfs_key current_insert;
263 struct btrfs_key last_insert;
264 struct radix_tree_root cache_radix;
265 struct radix_tree_root pinned_radix;
266 struct radix_tree_root dev_radix;
267 struct radix_tree_root block_group_radix;
268 struct list_head trans;
269 struct list_head cache;
270 u64 last_inode_alloc;
271 u64 last_inode_alloc_dirid;
275 struct btrfs_trans_handle *running_transaction;
276 struct btrfs_super_block *disk_super;
280 * in ram representation of the tree. extent_root is used for all allocations
281 * and for the extent tree extent_root root. current_insert is used
282 * only for the extent tree.
285 struct btrfs_buffer *node;
286 struct btrfs_buffer *commit_root;
287 struct btrfs_root_item root_item;
288 struct btrfs_key root_key;
289 struct btrfs_fs_info *fs_info;
295 /* the lower bits in the key flags defines the item type */
296 #define BTRFS_KEY_TYPE_MAX 256
297 #define BTRFS_KEY_TYPE_SHIFT 24
298 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
299 BTRFS_KEY_TYPE_SHIFT)
302 * inode items have the data typically returned from stat and store other
303 * info about object characteristics. There is one for every file and dir in
306 #define BTRFS_INODE_ITEM_KEY 1
308 /* reserve 2-15 close to the inode for later flexibility */
311 * dir items are the name -> inode pointers in a directory. There is one
312 * for every name in a directory.
314 #define BTRFS_DIR_ITEM_KEY 16
315 #define BTRFS_DIR_INDEX_KEY 17
317 * extent data is for file data
319 #define BTRFS_EXTENT_DATA_KEY 18
321 * csum items have the checksums for data in the extents
323 #define BTRFS_CSUM_ITEM_KEY 19
325 /* reserve 20-31 for other file stuff */
328 * root items point to tree roots. There are typically in the root
329 * tree used by the super block to find all the other trees
331 #define BTRFS_ROOT_ITEM_KEY 32
333 * extent items are in the extent map tree. These record which blocks
334 * are used, and how many references there are to each block
336 #define BTRFS_EXTENT_ITEM_KEY 33
339 * block groups give us hints into the extent allocation trees. Which
340 * blocks are free etc etc
342 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
345 * dev items list the devices that make up the FS
347 #define BTRFS_DEV_ITEM_KEY 35
350 * string items are for debugging. They just store a short string of
353 #define BTRFS_STRING_ITEM_KEY 253
356 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
358 return le64_to_cpu(bi->used);
361 static inline void btrfs_set_block_group_used(struct
362 btrfs_block_group_item *bi,
365 bi->used = cpu_to_le64(val);
368 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
370 return le64_to_cpu(i->generation);
373 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
376 i->generation = cpu_to_le64(val);
379 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
381 return le64_to_cpu(i->size);
384 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
386 i->size = cpu_to_le64(val);
389 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
391 return le64_to_cpu(i->nblocks);
394 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
396 i->nblocks = cpu_to_le64(val);
399 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
401 return le64_to_cpu(i->block_group);
404 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
407 i->block_group = cpu_to_le64(val);
410 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
412 return le32_to_cpu(i->nlink);
415 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
417 i->nlink = cpu_to_le32(val);
420 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
422 return le32_to_cpu(i->uid);
425 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
427 i->uid = cpu_to_le32(val);
430 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
432 return le32_to_cpu(i->gid);
435 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
437 i->gid = cpu_to_le32(val);
440 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
442 return le32_to_cpu(i->mode);
445 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
447 i->mode = cpu_to_le32(val);
450 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
452 return le32_to_cpu(i->rdev);
455 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
457 i->rdev = cpu_to_le32(val);
460 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
462 return le16_to_cpu(i->flags);
465 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
467 i->flags = cpu_to_le16(val);
470 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
472 return le16_to_cpu(i->compat_flags);
475 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
478 i->compat_flags = cpu_to_le16(val);
481 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
483 return le64_to_cpu(ts->sec);
486 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
489 ts->sec = cpu_to_le64(val);
492 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
494 return le32_to_cpu(ts->nsec);
497 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
500 ts->nsec = cpu_to_le32(val);
503 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
505 return le32_to_cpu(ei->refs);
508 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
510 ei->refs = cpu_to_le32(val);
513 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
515 return le64_to_cpu(ei->owner);
518 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
520 ei->owner = cpu_to_le64(val);
523 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
525 return le64_to_cpu(n->ptrs[nr].blockptr);
529 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
532 n->ptrs[nr].blockptr = cpu_to_le64(val);
535 static inline u32 btrfs_item_offset(struct btrfs_item *item)
537 return le32_to_cpu(item->offset);
540 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
542 item->offset = cpu_to_le32(val);
545 static inline u32 btrfs_item_end(struct btrfs_item *item)
547 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
550 static inline u16 btrfs_item_size(struct btrfs_item *item)
552 return le16_to_cpu(item->size);
555 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
557 item->size = cpu_to_le16(val);
560 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
562 return le16_to_cpu(d->flags);
565 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
567 d->flags = cpu_to_le16(val);
570 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
575 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
580 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
582 return le16_to_cpu(d->name_len);
585 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
587 d->name_len = cpu_to_le16(val);
590 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
591 struct btrfs_disk_key *disk)
593 cpu->offset = le64_to_cpu(disk->offset);
594 cpu->flags = le32_to_cpu(disk->flags);
595 cpu->objectid = le64_to_cpu(disk->objectid);
598 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
599 struct btrfs_key *cpu)
601 disk->offset = cpu_to_le64(cpu->offset);
602 disk->flags = cpu_to_le32(cpu->flags);
603 disk->objectid = cpu_to_le64(cpu->objectid);
606 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
608 return le64_to_cpu(disk->objectid);
611 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
614 disk->objectid = cpu_to_le64(val);
617 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
619 return le64_to_cpu(disk->offset);
622 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
625 disk->offset = cpu_to_le64(val);
628 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
630 return le32_to_cpu(disk->flags);
633 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
636 disk->flags = cpu_to_le32(val);
639 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
641 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
644 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
647 u32 flags = btrfs_disk_key_flags(key);
648 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
649 val = val << BTRFS_KEY_TYPE_SHIFT;
650 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
651 btrfs_set_disk_key_flags(key, flags);
654 static inline u32 btrfs_key_type(struct btrfs_key *key)
656 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
659 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
661 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
662 val = val << BTRFS_KEY_TYPE_SHIFT;
663 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
666 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
668 return le64_to_cpu(h->blocknr);
671 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
673 h->blocknr = cpu_to_le64(blocknr);
676 static inline u64 btrfs_header_generation(struct btrfs_header *h)
678 return le64_to_cpu(h->generation);
681 static inline void btrfs_set_header_generation(struct btrfs_header *h,
684 h->generation = cpu_to_le64(val);
687 static inline u64 btrfs_header_owner(struct btrfs_header *h)
689 return le64_to_cpu(h->owner);
692 static inline void btrfs_set_header_owner(struct btrfs_header *h,
695 h->owner = cpu_to_le64(val);
698 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
700 return le16_to_cpu(h->nritems);
703 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
705 h->nritems = cpu_to_le16(val);
708 static inline u16 btrfs_header_flags(struct btrfs_header *h)
710 return le16_to_cpu(h->flags);
713 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
715 h->flags = cpu_to_le16(val);
718 static inline int btrfs_header_level(struct btrfs_header *h)
723 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
725 BUG_ON(level > BTRFS_MAX_LEVEL);
729 static inline int btrfs_is_leaf(struct btrfs_node *n)
731 return (btrfs_header_level(&n->header) == 0);
734 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
736 return le64_to_cpu(item->blocknr);
739 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
741 item->blocknr = cpu_to_le64(val);
744 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
746 return le64_to_cpu(item->root_dirid);
749 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
751 item->root_dirid = cpu_to_le64(val);
754 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
756 return le32_to_cpu(item->refs);
759 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
761 item->refs = cpu_to_le32(val);
764 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
766 return le64_to_cpu(s->blocknr);
769 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
771 s->blocknr = cpu_to_le64(val);
774 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
776 return le64_to_cpu(s->generation);
779 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
782 s->generation = cpu_to_le64(val);
785 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
787 return le64_to_cpu(s->root);
790 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
792 s->root = cpu_to_le64(val);
795 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
797 return le64_to_cpu(s->total_blocks);
800 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
803 s->total_blocks = cpu_to_le64(val);
806 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
808 return le64_to_cpu(s->blocks_used);
811 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
814 s->blocks_used = cpu_to_le64(val);
817 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
819 return le32_to_cpu(s->blocksize);
822 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
825 s->blocksize = cpu_to_le32(val);
828 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
830 return le64_to_cpu(s->root_dir_objectid);
833 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
836 s->root_dir_objectid = cpu_to_le64(val);
839 static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
841 return le64_to_cpu(s->last_device_id);
844 static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
847 s->last_device_id = cpu_to_le64(val);
850 static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
852 return le64_to_cpu(s->device_id);
855 static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
858 s->device_id = cpu_to_le64(val);
861 static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
863 return le64_to_cpu(s->device_block_start);
866 static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
869 s->device_block_start = cpu_to_le64(val);
872 static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
874 return le64_to_cpu(s->device_num_blocks);
877 static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
880 s->device_num_blocks = cpu_to_le64(val);
883 static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
885 return le64_to_cpu(s->device_root);
888 static inline void btrfs_set_super_device_root(struct btrfs_super_block
891 s->device_root = cpu_to_le64(val);
894 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
896 return (u8 *)l->items;
899 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
903 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
909 static inline char *btrfs_file_extent_inline_start(struct
910 btrfs_file_extent_item *e)
912 return (char *)(&e->disk_blocknr);
915 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
917 return (unsigned long)(&((struct
918 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
921 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
923 struct btrfs_file_extent_item *fe = NULL;
924 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
927 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
930 return le64_to_cpu(e->disk_blocknr);
933 static inline void btrfs_set_file_extent_disk_blocknr(struct
934 btrfs_file_extent_item
937 e->disk_blocknr = cpu_to_le64(val);
940 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
942 return le64_to_cpu(e->generation);
945 static inline void btrfs_set_file_extent_generation(struct
946 btrfs_file_extent_item *e,
949 e->generation = cpu_to_le64(val);
952 static inline u64 btrfs_file_extent_disk_num_blocks(struct
953 btrfs_file_extent_item *e)
955 return le64_to_cpu(e->disk_num_blocks);
958 static inline void btrfs_set_file_extent_disk_num_blocks(struct
959 btrfs_file_extent_item
962 e->disk_num_blocks = cpu_to_le64(val);
965 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
967 return le64_to_cpu(e->offset);
970 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
973 e->offset = cpu_to_le64(val);
976 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
979 return le64_to_cpu(e->num_blocks);
982 static inline void btrfs_set_file_extent_num_blocks(struct
983 btrfs_file_extent_item *e,
986 e->num_blocks = cpu_to_le64(val);
989 static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
991 return le16_to_cpu(d->pathlen);
994 static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
997 d->pathlen = cpu_to_le16(val);
1000 static inline u64 btrfs_device_id(struct btrfs_device_item *d)
1002 return le64_to_cpu(d->device_id);
1005 static inline void btrfs_set_device_id(struct btrfs_device_item *d,
1008 d->device_id = cpu_to_le64(val);
1011 /* helper function to cast into the data area of the leaf. */
1012 #define btrfs_item_ptr(leaf, slot, type) \
1013 ((type *)(btrfs_leaf_data(leaf) + \
1014 btrfs_item_offset((leaf)->items + (slot))))
1016 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1017 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1018 *root, struct btrfs_path *path, u32 data_size);
1019 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1020 struct btrfs_root *root);
1021 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1022 struct btrfs_buffer *buf);
1023 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1024 *root, u64 blocknr, u64 num_blocks, int pin);
1025 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1026 *root, struct btrfs_key *key, struct btrfs_path *p, int
1028 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1029 void btrfs_init_path(struct btrfs_path *p);
1030 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1031 struct btrfs_path *path);
1032 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1033 *root, struct btrfs_key *key, void *data, u32 data_size);
1034 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1035 *root, struct btrfs_path *path, struct btrfs_key
1036 *cpu_key, u32 data_size);
1037 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1038 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1039 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1040 *root, struct btrfs_buffer *snap);
1041 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1043 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1044 struct btrfs_key *key);
1045 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1046 *root, struct btrfs_key *key, struct btrfs_root_item
1048 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1049 *root, struct btrfs_key *key, struct btrfs_root_item
1051 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1052 btrfs_root_item *item, struct btrfs_key *key);
1053 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1054 *root, char *name, int name_len, u64 dir,
1055 struct btrfs_key *location, u8 type);
1056 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1057 *root, struct btrfs_path *path, u64 dir, char *name,
1058 int name_len, int mod);
1059 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
1060 char *name, int name_len);
1061 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1062 struct btrfs_root *fs_root,
1063 u64 dirid, u64 *objectid);
1064 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1065 *root, u64 objectid, struct btrfs_inode_item
1067 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1068 *root, struct btrfs_path *path, u64 objectid, int mod);
1069 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1070 struct btrfs_root *root);
1071 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1072 int btrfs_read_block_groups(struct btrfs_root *root);
1073 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1074 struct btrfs_root *root,
1075 struct btrfs_key *key,
1076 struct btrfs_block_group_item *bi);