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 {
177 struct btrfs_inode_timespec atime;
178 struct btrfs_inode_timespec ctime;
179 struct btrfs_inode_timespec mtime;
180 struct btrfs_inode_timespec otime;
181 } __attribute__ ((__packed__));
183 /* inline data is just a blob of bytes */
184 struct btrfs_inline_data_item {
186 } __attribute__ ((__packed__));
188 struct btrfs_dir_item {
189 struct btrfs_disk_key location;
193 } __attribute__ ((__packed__));
195 struct btrfs_root_item {
196 struct btrfs_inode_item inode;
203 } __attribute__ ((__packed__));
205 #define BTRFS_FILE_EXTENT_REG 0
206 #define BTRFS_FILE_EXTENT_INLINE 1
208 struct btrfs_file_extent_item {
212 * disk space consumed by the extent, checksum blocks are included
216 __le64 disk_num_blocks;
218 * the logical offset in file blocks (no csums)
219 * this extent record is for. This allows a file extent to point
220 * into the middle of an existing extent on disk, sharing it
221 * between two snapshots (useful if some bytes in the middle of the
222 * extent have changed
226 * the logical number of file blocks (no csums included)
229 } __attribute__ ((__packed__));
231 struct btrfs_csum_item {
232 u8 csum[BTRFS_CSUM_SIZE];
233 } __attribute__ ((__packed__));
235 struct btrfs_device_item {
238 } __attribute__ ((__packed__));
240 struct btrfs_fs_info {
241 struct btrfs_root *fs_root;
242 struct btrfs_root *extent_root;
243 struct btrfs_root *tree_root;
244 struct btrfs_root *dev_root;
245 struct btrfs_key current_insert;
246 struct btrfs_key last_insert;
247 struct radix_tree_root cache_radix;
248 struct radix_tree_root pinned_radix;
249 struct radix_tree_root dev_radix;
250 struct list_head trans;
251 struct list_head cache;
252 u64 last_inode_alloc;
253 u64 last_inode_alloc_dirid;
257 struct btrfs_trans_handle *running_transaction;
258 struct btrfs_super_block *disk_super;
262 * in ram representation of the tree. extent_root is used for all allocations
263 * and for the extent tree extent_root root. current_insert is used
264 * only for the extent tree.
267 struct btrfs_buffer *node;
268 struct btrfs_buffer *commit_root;
269 struct btrfs_root_item root_item;
270 struct btrfs_key root_key;
271 struct btrfs_fs_info *fs_info;
277 /* the lower bits in the key flags defines the item type */
278 #define BTRFS_KEY_TYPE_MAX 256
279 #define BTRFS_KEY_TYPE_SHIFT 24
280 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
281 BTRFS_KEY_TYPE_SHIFT)
284 * inode items have the data typically returned from stat and store other
285 * info about object characteristics. There is one for every file and dir in
288 #define BTRFS_INODE_ITEM_KEY 1
291 * dir items are the name -> inode pointers in a directory. There is one
292 * for every name in a directory.
294 #define BTRFS_DIR_ITEM_KEY 2
295 #define BTRFS_DIR_INDEX_KEY 3
297 * inline data is file data that fits in the btree.
299 #define BTRFS_INLINE_DATA_KEY 4
301 * extent data is for data that can't fit in the btree. It points to
302 * a (hopefully) huge chunk of disk
304 #define BTRFS_EXTENT_DATA_KEY 5
306 * csum items have the checksums for data in the extents
308 #define BTRFS_CSUM_ITEM_KEY 6
311 * root items point to tree roots. There are typically in the root
312 * tree used by the super block to find all the other trees
314 #define BTRFS_ROOT_ITEM_KEY 7
316 * extent items are in the extent map tree. These record which blocks
317 * are used, and how many references there are to each block
319 #define BTRFS_EXTENT_ITEM_KEY 8
322 * dev items list the devices that make up the FS
324 #define BTRFS_DEV_ITEM_KEY 9
327 * string items are for debugging. They just store a short string of
330 #define BTRFS_STRING_ITEM_KEY 10
332 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
334 return le64_to_cpu(i->generation);
337 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
340 i->generation = cpu_to_le64(val);
343 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
345 return le64_to_cpu(i->size);
348 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
350 i->size = cpu_to_le64(val);
353 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
355 return le64_to_cpu(i->nblocks);
358 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
360 i->nblocks = cpu_to_le64(val);
363 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
365 return le32_to_cpu(i->nlink);
368 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
370 i->nlink = cpu_to_le32(val);
373 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
375 return le32_to_cpu(i->uid);
378 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
380 i->uid = cpu_to_le32(val);
383 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
385 return le32_to_cpu(i->gid);
388 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
390 i->gid = cpu_to_le32(val);
393 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
395 return le32_to_cpu(i->mode);
398 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
400 i->mode = cpu_to_le32(val);
403 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
405 return le32_to_cpu(i->rdev);
408 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
410 i->rdev = cpu_to_le32(val);
413 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
415 return le16_to_cpu(i->flags);
418 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
420 i->flags = cpu_to_le16(val);
423 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
425 return le16_to_cpu(i->compat_flags);
428 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
431 i->compat_flags = cpu_to_le16(val);
434 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
436 return le64_to_cpu(ts->sec);
439 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
442 ts->sec = cpu_to_le64(val);
445 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
447 return le32_to_cpu(ts->nsec);
450 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
453 ts->nsec = cpu_to_le32(val);
456 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
458 return le32_to_cpu(ei->refs);
461 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
463 ei->refs = cpu_to_le32(val);
466 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
468 return le64_to_cpu(ei->owner);
471 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
473 ei->owner = cpu_to_le64(val);
476 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
478 return le64_to_cpu(n->ptrs[nr].blockptr);
482 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
485 n->ptrs[nr].blockptr = cpu_to_le64(val);
488 static inline u32 btrfs_item_offset(struct btrfs_item *item)
490 return le32_to_cpu(item->offset);
493 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
495 item->offset = cpu_to_le32(val);
498 static inline u32 btrfs_item_end(struct btrfs_item *item)
500 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
503 static inline u16 btrfs_item_size(struct btrfs_item *item)
505 return le16_to_cpu(item->size);
508 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
510 item->size = cpu_to_le16(val);
513 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
515 return le16_to_cpu(d->flags);
518 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
520 d->flags = cpu_to_le16(val);
523 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
528 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
533 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
535 return le16_to_cpu(d->name_len);
538 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
540 d->name_len = cpu_to_le16(val);
543 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
544 struct btrfs_disk_key *disk)
546 cpu->offset = le64_to_cpu(disk->offset);
547 cpu->flags = le32_to_cpu(disk->flags);
548 cpu->objectid = le64_to_cpu(disk->objectid);
551 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
552 struct btrfs_key *cpu)
554 disk->offset = cpu_to_le64(cpu->offset);
555 disk->flags = cpu_to_le32(cpu->flags);
556 disk->objectid = cpu_to_le64(cpu->objectid);
559 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
561 return le64_to_cpu(disk->objectid);
564 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
567 disk->objectid = cpu_to_le64(val);
570 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
572 return le64_to_cpu(disk->offset);
575 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
578 disk->offset = cpu_to_le64(val);
581 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
583 return le32_to_cpu(disk->flags);
586 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
589 disk->flags = cpu_to_le32(val);
592 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
594 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
597 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
600 u32 flags = btrfs_disk_key_flags(key);
601 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
602 val = val << BTRFS_KEY_TYPE_SHIFT;
603 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
604 btrfs_set_disk_key_flags(key, flags);
607 static inline u32 btrfs_key_type(struct btrfs_key *key)
609 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
612 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
614 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
615 val = val << BTRFS_KEY_TYPE_SHIFT;
616 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
619 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
621 return le64_to_cpu(h->blocknr);
624 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
626 h->blocknr = cpu_to_le64(blocknr);
629 static inline u64 btrfs_header_generation(struct btrfs_header *h)
631 return le64_to_cpu(h->generation);
634 static inline void btrfs_set_header_generation(struct btrfs_header *h,
637 h->generation = cpu_to_le64(val);
640 static inline u64 btrfs_header_owner(struct btrfs_header *h)
642 return le64_to_cpu(h->owner);
645 static inline void btrfs_set_header_owner(struct btrfs_header *h,
648 h->owner = cpu_to_le64(val);
651 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
653 return le16_to_cpu(h->nritems);
656 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
658 h->nritems = cpu_to_le16(val);
661 static inline u16 btrfs_header_flags(struct btrfs_header *h)
663 return le16_to_cpu(h->flags);
666 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
668 h->flags = cpu_to_le16(val);
671 static inline int btrfs_header_level(struct btrfs_header *h)
676 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
678 BUG_ON(level > BTRFS_MAX_LEVEL);
682 static inline int btrfs_is_leaf(struct btrfs_node *n)
684 return (btrfs_header_level(&n->header) == 0);
687 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
689 return le64_to_cpu(item->blocknr);
692 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
694 item->blocknr = cpu_to_le64(val);
697 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
699 return le64_to_cpu(item->root_dirid);
702 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
704 item->root_dirid = cpu_to_le64(val);
707 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
709 return le32_to_cpu(item->refs);
712 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
714 item->refs = cpu_to_le32(val);
717 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
719 return le64_to_cpu(s->blocknr);
722 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
724 s->blocknr = cpu_to_le64(val);
727 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
729 return le64_to_cpu(s->generation);
732 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
735 s->generation = cpu_to_le64(val);
738 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
740 return le64_to_cpu(s->root);
743 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
745 s->root = cpu_to_le64(val);
748 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
750 return le64_to_cpu(s->total_blocks);
753 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
756 s->total_blocks = cpu_to_le64(val);
759 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
761 return le64_to_cpu(s->blocks_used);
764 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
767 s->blocks_used = cpu_to_le64(val);
770 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
772 return le32_to_cpu(s->blocksize);
775 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
778 s->blocksize = cpu_to_le32(val);
781 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
783 return le64_to_cpu(s->root_dir_objectid);
786 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
789 s->root_dir_objectid = cpu_to_le64(val);
792 static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
794 return le64_to_cpu(s->last_device_id);
797 static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
800 s->last_device_id = cpu_to_le64(val);
803 static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
805 return le64_to_cpu(s->device_id);
808 static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
811 s->device_id = cpu_to_le64(val);
814 static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
816 return le64_to_cpu(s->device_block_start);
819 static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
822 s->device_block_start = cpu_to_le64(val);
825 static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
827 return le64_to_cpu(s->device_num_blocks);
830 static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
833 s->device_num_blocks = cpu_to_le64(val);
836 static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
838 return le64_to_cpu(s->device_root);
841 static inline void btrfs_set_super_device_root(struct btrfs_super_block
844 s->device_root = cpu_to_le64(val);
847 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
849 return (u8 *)l->items;
852 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
856 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
862 static inline char *btrfs_file_extent_inline_start(struct
863 btrfs_file_extent_item *e)
865 return (char *)(&e->disk_blocknr);
868 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
870 return (unsigned long)(&((struct
871 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
874 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
876 struct btrfs_file_extent_item *fe = NULL;
877 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
880 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
883 return le64_to_cpu(e->disk_blocknr);
886 static inline void btrfs_set_file_extent_disk_blocknr(struct
887 btrfs_file_extent_item
890 e->disk_blocknr = cpu_to_le64(val);
893 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
895 return le64_to_cpu(e->generation);
898 static inline void btrfs_set_file_extent_generation(struct
899 btrfs_file_extent_item *e,
902 e->generation = cpu_to_le64(val);
905 static inline u64 btrfs_file_extent_disk_num_blocks(struct
906 btrfs_file_extent_item *e)
908 return le64_to_cpu(e->disk_num_blocks);
911 static inline void btrfs_set_file_extent_disk_num_blocks(struct
912 btrfs_file_extent_item
915 e->disk_num_blocks = cpu_to_le64(val);
918 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
920 return le64_to_cpu(e->offset);
923 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
926 e->offset = cpu_to_le64(val);
929 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
932 return le64_to_cpu(e->num_blocks);
935 static inline void btrfs_set_file_extent_num_blocks(struct
936 btrfs_file_extent_item *e,
939 e->num_blocks = cpu_to_le64(val);
942 static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
944 return le16_to_cpu(d->pathlen);
947 static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
950 d->pathlen = cpu_to_le16(val);
953 static inline u64 btrfs_device_id(struct btrfs_device_item *d)
955 return le64_to_cpu(d->device_id);
958 static inline void btrfs_set_device_id(struct btrfs_device_item *d,
961 d->device_id = cpu_to_le64(val);
964 /* helper function to cast into the data area of the leaf. */
965 #define btrfs_item_ptr(leaf, slot, type) \
966 ((type *)(btrfs_leaf_data(leaf) + \
967 btrfs_item_offset((leaf)->items + (slot))))
969 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
970 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
971 *root, struct btrfs_path *path, u32 data_size);
972 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
973 struct btrfs_root *root);
974 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
975 struct btrfs_buffer *buf);
976 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
977 *root, u64 blocknr, u64 num_blocks, int pin);
978 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
979 *root, struct btrfs_key *key, struct btrfs_path *p, int
981 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
982 void btrfs_init_path(struct btrfs_path *p);
983 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
984 struct btrfs_path *path);
985 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
986 *root, struct btrfs_key *key, void *data, u32 data_size);
987 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
988 *root, struct btrfs_path *path, struct btrfs_key
989 *cpu_key, u32 data_size);
990 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
991 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
992 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
993 *root, struct btrfs_buffer *snap);
994 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
996 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
997 struct btrfs_key *key);
998 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
999 *root, struct btrfs_key *key, struct btrfs_root_item
1001 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1002 *root, struct btrfs_key *key, struct btrfs_root_item
1004 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1005 btrfs_root_item *item, struct btrfs_key *key);
1006 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1007 *root, char *name, int name_len, u64 dir,
1008 struct btrfs_key *location, u8 type);
1009 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1010 *root, struct btrfs_path *path, u64 dir, char *name,
1011 int name_len, int mod);
1012 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
1013 char *name, int name_len);
1014 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1015 struct btrfs_root *fs_root,
1016 u64 dirid, u64 *objectid);
1017 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1018 *root, u64 objectid, struct btrfs_inode_item
1020 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1021 *root, struct btrfs_path *path, u64 objectid, int mod);