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 */
64 } __attribute__ ((__packed__));
66 #define BTRFS_MAX_LEVEL 8
67 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
68 sizeof(struct btrfs_header)) / \
69 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
70 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
71 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
75 * the super block basically lists the main trees of the FS
76 * it currently lacks any block count etc etc
78 struct btrfs_super_block {
79 u8 csum[BTRFS_CSUM_SIZE];
80 /* the first 3 fields must match struct btrfs_header */
81 u8 fsid[16]; /* FS specific uuid */
82 __le64 blocknr; /* this block number */
89 __le64 root_dir_objectid;
90 __le64 last_device_id;
91 /* fields below here vary with the underlying disk */
92 __le64 device_block_start;
93 __le64 device_num_blocks;
96 } __attribute__ ((__packed__));
99 * A leaf is full of items. offset and size tell us where to find
100 * the item in the leaf (relative to the start of the data area)
103 struct btrfs_disk_key key;
106 } __attribute__ ((__packed__));
109 * leaves have an item area and a data area:
110 * [item0, item1....itemN] [free space] [dataN...data1, data0]
112 * The data is separate from the items to get the keys closer together
116 struct btrfs_header header;
117 struct btrfs_item items[];
118 } __attribute__ ((__packed__));
121 * all non-leaf blocks are nodes, they hold only keys and pointers to
124 struct btrfs_key_ptr {
125 struct btrfs_disk_key key;
127 } __attribute__ ((__packed__));
130 struct btrfs_header header;
131 struct btrfs_key_ptr ptrs[];
132 } __attribute__ ((__packed__));
135 * btrfs_paths remember the path taken from the root down to the leaf.
136 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
137 * to any other levels that are present.
139 * The slots array records the index of the item or block pointer
140 * used while walking the tree.
143 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
144 int slots[BTRFS_MAX_LEVEL];
148 * items in the extent btree are used to record the objectid of the
149 * owner of the block and the number of references
151 struct btrfs_extent_item {
153 } __attribute__ ((__packed__));
155 struct btrfs_inode_timespec {
158 } __attribute__ ((__packed__));
161 * there is no padding here on purpose. If you want to extent the inode,
162 * make a new item type
164 struct btrfs_inode_item {
175 struct btrfs_inode_timespec atime;
176 struct btrfs_inode_timespec ctime;
177 struct btrfs_inode_timespec mtime;
178 struct btrfs_inode_timespec otime;
179 } __attribute__ ((__packed__));
181 /* inline data is just a blob of bytes */
182 struct btrfs_inline_data_item {
184 } __attribute__ ((__packed__));
186 struct btrfs_dir_item {
187 struct btrfs_disk_key location;
191 } __attribute__ ((__packed__));
193 struct btrfs_root_item {
194 struct btrfs_inode_item inode;
201 } __attribute__ ((__packed__));
203 struct btrfs_file_extent_item {
206 * disk space consumed by the extent, checksum blocks are included
210 __le64 disk_num_blocks;
212 * the logical offset in file blocks (no csums)
213 * this extent record is for. This allows a file extent to point
214 * into the middle of an existing extent on disk, sharing it
215 * between two snapshots (useful if some bytes in the middle of the
216 * extent have changed
220 * the logical number of file blocks (no csums included)
223 } __attribute__ ((__packed__));
225 struct btrfs_csum_item {
226 __le64 extent_offset;
227 u8 csum[BTRFS_CSUM_SIZE];
228 } __attribute__ ((__packed__));
230 struct btrfs_device_item {
233 } __attribute__ ((__packed__));
235 struct btrfs_fs_info {
236 struct btrfs_root *fs_root;
237 struct btrfs_root *extent_root;
238 struct btrfs_root *tree_root;
239 struct btrfs_root *dev_root;
240 struct btrfs_key current_insert;
241 struct btrfs_key last_insert;
242 struct radix_tree_root cache_radix;
243 struct radix_tree_root pinned_radix;
244 struct radix_tree_root dev_radix;
245 struct list_head trans;
246 struct list_head cache;
247 u64 last_inode_alloc;
248 u64 last_inode_alloc_dirid;
252 struct btrfs_trans_handle *running_transaction;
253 struct btrfs_super_block *disk_super;
257 * in ram representation of the tree. extent_root is used for all allocations
258 * and for the extent tree extent_root root. current_insert is used
259 * only for the extent tree.
262 struct btrfs_buffer *node;
263 struct btrfs_buffer *commit_root;
264 struct btrfs_root_item root_item;
265 struct btrfs_key root_key;
266 struct btrfs_fs_info *fs_info;
272 /* the lower bits in the key flags defines the item type */
273 #define BTRFS_KEY_TYPE_MAX 256
274 #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1)
276 #define BTRFS_KEY_OVERFLOW_MAX 128
277 #define BTRFS_KEY_OVERFLOW_SHIFT 8
278 #define BTRFS_KEY_OVERFLOW_MASK (0x7FULL << BTRFS_KEY_OVERFLOW_SHIFT)
281 * inode items have the data typically returned from stat and store other
282 * info about object characteristics. There is one for every file and dir in
285 #define BTRFS_INODE_ITEM_KEY 1
288 * dir items are the name -> inode pointers in a directory. There is one
289 * for every name in a directory.
291 #define BTRFS_DIR_ITEM_KEY 2
292 #define BTRFS_DIR_INDEX_KEY 3
294 * inline data is file data that fits in the btree.
296 #define BTRFS_INLINE_DATA_KEY 4
298 * extent data is for data that can't fit in the btree. It points to
299 * a (hopefully) huge chunk of disk
301 #define BTRFS_EXTENT_DATA_KEY 5
303 * csum items have the checksums for data in the extents
305 #define BTRFS_CSUM_ITEM_KEY 6
308 * root items point to tree roots. There are typically in the root
309 * tree used by the super block to find all the other trees
311 #define BTRFS_ROOT_ITEM_KEY 7
313 * extent items are in the extent map tree. These record which blocks
314 * are used, and how many references there are to each block
316 #define BTRFS_EXTENT_ITEM_KEY 8
319 * dev items list the devices that make up the FS
321 #define BTRFS_DEV_ITEM_KEY 9
324 * string items are for debugging. They just store a short string of
327 #define BTRFS_STRING_ITEM_KEY 10
329 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
331 return le64_to_cpu(i->generation);
334 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
337 i->generation = cpu_to_le64(val);
340 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
342 return le64_to_cpu(i->size);
345 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
347 i->size = cpu_to_le64(val);
350 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
352 return le64_to_cpu(i->nblocks);
355 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
357 i->nblocks = cpu_to_le64(val);
360 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
362 return le32_to_cpu(i->nlink);
365 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
367 i->nlink = cpu_to_le32(val);
370 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
372 return le32_to_cpu(i->uid);
375 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
377 i->uid = cpu_to_le32(val);
380 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
382 return le32_to_cpu(i->gid);
385 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
387 i->gid = cpu_to_le32(val);
390 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
392 return le32_to_cpu(i->mode);
395 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
397 i->mode = cpu_to_le32(val);
400 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
402 return le32_to_cpu(i->rdev);
405 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
407 i->rdev = cpu_to_le32(val);
410 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
412 return le16_to_cpu(i->flags);
415 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
417 i->flags = cpu_to_le16(val);
420 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
422 return le16_to_cpu(i->compat_flags);
425 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
428 i->compat_flags = cpu_to_le16(val);
431 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
433 return le64_to_cpu(ts->sec);
436 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
439 ts->sec = cpu_to_le64(val);
442 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
444 return le32_to_cpu(ts->nsec);
447 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
450 ts->nsec = cpu_to_le32(val);
453 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
455 return le32_to_cpu(ei->refs);
458 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
460 ei->refs = cpu_to_le32(val);
463 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
465 return le64_to_cpu(n->ptrs[nr].blockptr);
468 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
471 n->ptrs[nr].blockptr = cpu_to_le64(val);
474 static inline u32 btrfs_item_offset(struct btrfs_item *item)
476 return le32_to_cpu(item->offset);
479 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
481 item->offset = cpu_to_le32(val);
484 static inline u32 btrfs_item_end(struct btrfs_item *item)
486 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
489 static inline u16 btrfs_item_size(struct btrfs_item *item)
491 return le16_to_cpu(item->size);
494 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
496 item->size = cpu_to_le16(val);
499 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
501 return le16_to_cpu(d->flags);
504 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
506 d->flags = cpu_to_le16(val);
509 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
514 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
519 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
521 return le16_to_cpu(d->name_len);
524 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
526 d->name_len = cpu_to_le16(val);
529 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
530 struct btrfs_disk_key *disk)
532 cpu->offset = le64_to_cpu(disk->offset);
533 cpu->flags = le32_to_cpu(disk->flags);
534 cpu->objectid = le64_to_cpu(disk->objectid);
537 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
538 struct btrfs_key *cpu)
540 disk->offset = cpu_to_le64(cpu->offset);
541 disk->flags = cpu_to_le32(cpu->flags);
542 disk->objectid = cpu_to_le64(cpu->objectid);
545 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
547 return le64_to_cpu(disk->objectid);
550 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
553 disk->objectid = cpu_to_le64(val);
556 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
558 return le64_to_cpu(disk->offset);
561 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
564 disk->offset = cpu_to_le64(val);
567 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
569 return le32_to_cpu(disk->flags);
572 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
575 disk->flags = cpu_to_le32(val);
578 static inline u32 btrfs_key_overflow(struct btrfs_key *key)
580 u32 over = key->flags & BTRFS_KEY_OVERFLOW_MASK;
581 return over >> BTRFS_KEY_OVERFLOW_SHIFT;
584 static inline void btrfs_set_key_overflow(struct btrfs_key *key, u32 over)
586 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
587 over = over << BTRFS_KEY_OVERFLOW_SHIFT;
588 key->flags = (key->flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
591 static inline u32 btrfs_key_type(struct btrfs_key *key)
593 return key->flags & BTRFS_KEY_TYPE_MASK;
596 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
598 return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK;
601 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type)
603 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
604 key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
607 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
609 u32 flags = btrfs_disk_key_flags(key);
610 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
611 flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
612 btrfs_set_disk_key_flags(key, flags);
615 static inline u32 btrfs_disk_key_overflow(struct btrfs_disk_key *key)
617 u32 over = le32_to_cpu(key->flags) & BTRFS_KEY_OVERFLOW_MASK;
618 return over >> BTRFS_KEY_OVERFLOW_SHIFT;
621 static inline void btrfs_set_disK_key_overflow(struct btrfs_disk_key *key,
624 u32 flags = btrfs_disk_key_flags(key);
625 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
626 over = over << BTRFS_KEY_OVERFLOW_SHIFT;
627 flags = (flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
628 btrfs_set_disk_key_flags(key, flags);
631 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
633 return le64_to_cpu(h->blocknr);
636 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
638 h->blocknr = cpu_to_le64(blocknr);
641 static inline u64 btrfs_header_generation(struct btrfs_header *h)
643 return le64_to_cpu(h->generation);
646 static inline void btrfs_set_header_generation(struct btrfs_header *h,
649 h->generation = cpu_to_le64(val);
652 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
654 return le16_to_cpu(h->nritems);
657 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
659 h->nritems = cpu_to_le16(val);
662 static inline u16 btrfs_header_flags(struct btrfs_header *h)
664 return le16_to_cpu(h->flags);
667 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
669 h->flags = cpu_to_le16(val);
672 static inline int btrfs_header_level(struct btrfs_header *h)
677 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
679 BUG_ON(level > BTRFS_MAX_LEVEL);
683 static inline int btrfs_is_leaf(struct btrfs_node *n)
685 return (btrfs_header_level(&n->header) == 0);
688 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
690 return le64_to_cpu(item->blocknr);
693 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
695 item->blocknr = cpu_to_le64(val);
698 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
700 return le64_to_cpu(item->root_dirid);
703 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
705 item->root_dirid = cpu_to_le64(val);
708 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
710 return le32_to_cpu(item->refs);
713 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
715 item->refs = cpu_to_le32(val);
718 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
720 return le64_to_cpu(s->blocknr);
723 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
725 s->blocknr = cpu_to_le64(val);
728 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
730 return le64_to_cpu(s->generation);
733 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
736 s->generation = cpu_to_le64(val);
739 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
741 return le64_to_cpu(s->root);
744 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
746 s->root = cpu_to_le64(val);
749 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
751 return le64_to_cpu(s->total_blocks);
754 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
757 s->total_blocks = cpu_to_le64(val);
760 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
762 return le64_to_cpu(s->blocks_used);
765 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
768 s->blocks_used = cpu_to_le64(val);
771 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
773 return le32_to_cpu(s->blocksize);
776 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
779 s->blocksize = cpu_to_le32(val);
782 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
784 return le64_to_cpu(s->root_dir_objectid);
787 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
790 s->root_dir_objectid = cpu_to_le64(val);
793 static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
795 return le64_to_cpu(s->last_device_id);
798 static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
801 s->last_device_id = cpu_to_le64(val);
804 static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
806 return le64_to_cpu(s->device_id);
809 static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
812 s->device_id = cpu_to_le64(val);
815 static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
817 return le64_to_cpu(s->device_block_start);
820 static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
823 s->device_block_start = cpu_to_le64(val);
826 static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
828 return le64_to_cpu(s->device_num_blocks);
831 static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
834 s->device_num_blocks = cpu_to_le64(val);
837 static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
839 return le64_to_cpu(s->device_root);
842 static inline void btrfs_set_super_device_root(struct btrfs_super_block
845 s->device_root = cpu_to_le64(val);
848 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
850 return (u8 *)l->items;
853 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
856 return le64_to_cpu(e->disk_blocknr);
859 static inline void btrfs_set_file_extent_disk_blocknr(struct
860 btrfs_file_extent_item
863 e->disk_blocknr = cpu_to_le64(val);
866 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
868 return le64_to_cpu(e->generation);
871 static inline void btrfs_set_file_extent_generation(struct
872 btrfs_file_extent_item *e,
875 e->generation = cpu_to_le64(val);
878 static inline u64 btrfs_file_extent_disk_num_blocks(struct
879 btrfs_file_extent_item *e)
881 return le64_to_cpu(e->disk_num_blocks);
884 static inline void btrfs_set_file_extent_disk_num_blocks(struct
885 btrfs_file_extent_item
888 e->disk_num_blocks = cpu_to_le64(val);
891 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
893 return le64_to_cpu(e->offset);
896 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
899 e->offset = cpu_to_le64(val);
902 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
905 return le64_to_cpu(e->num_blocks);
908 static inline void btrfs_set_file_extent_num_blocks(struct
909 btrfs_file_extent_item *e,
912 e->num_blocks = cpu_to_le64(val);
915 static inline u64 btrfs_csum_extent_offset(struct btrfs_csum_item *c)
917 return le64_to_cpu(c->extent_offset);
920 static inline void btrfs_set_csum_extent_offset(struct btrfs_csum_item *c,
923 c->extent_offset = cpu_to_le64(val);
926 static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
928 return le16_to_cpu(d->pathlen);
931 static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
934 d->pathlen = cpu_to_le16(val);
937 static inline u64 btrfs_device_id(struct btrfs_device_item *d)
939 return le64_to_cpu(d->device_id);
942 static inline void btrfs_set_device_id(struct btrfs_device_item *d,
945 d->device_id = cpu_to_le64(val);
948 /* helper function to cast into the data area of the leaf. */
949 #define btrfs_item_ptr(leaf, slot, type) \
950 ((type *)(btrfs_leaf_data(leaf) + \
951 btrfs_item_offset((leaf)->items + (slot))))
953 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
954 struct btrfs_root *root);
955 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
956 struct btrfs_buffer *buf);
957 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
958 *root, u64 blocknr, u64 num_blocks, int pin);
959 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
960 *root, struct btrfs_key *key, struct btrfs_path *p, int
962 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
963 void btrfs_init_path(struct btrfs_path *p);
964 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
965 struct btrfs_path *path);
966 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
967 *root, struct btrfs_key *key, void *data, u32 data_size);
968 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
969 *root, struct btrfs_path *path, struct btrfs_key
970 *cpu_key, u32 data_size);
971 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
972 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
973 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
974 *root, struct btrfs_buffer *snap);
975 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
977 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
978 struct btrfs_key *key);
979 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
980 *root, struct btrfs_key *key, struct btrfs_root_item
982 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
983 *root, struct btrfs_key *key, struct btrfs_root_item
985 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
986 btrfs_root_item *item, struct btrfs_key *key);
987 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
988 *root, char *name, int name_len, u64 dir,
989 struct btrfs_key *location, u8 type);
990 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
991 *root, struct btrfs_path *path, u64 dir, char *name,
992 int name_len, int mod);
993 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
994 char *name, int name_len);
995 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
996 struct btrfs_root *fs_root,
997 u64 dirid, u64 *objectid);
998 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
999 *root, u64 objectid, struct btrfs_inode_item
1001 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1002 *root, struct btrfs_path *path, u64 objectid, int mod);