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 u8 csum[BTRFS_CSUM_SIZE];
227 } __attribute__ ((__packed__));
229 struct btrfs_device_item {
232 } __attribute__ ((__packed__));
234 struct btrfs_fs_info {
235 struct btrfs_root *fs_root;
236 struct btrfs_root *extent_root;
237 struct btrfs_root *tree_root;
238 struct btrfs_root *dev_root;
239 struct btrfs_key current_insert;
240 struct btrfs_key last_insert;
241 struct radix_tree_root cache_radix;
242 struct radix_tree_root pinned_radix;
243 struct radix_tree_root dev_radix;
244 struct list_head trans;
245 struct list_head cache;
246 u64 last_inode_alloc;
247 u64 last_inode_alloc_dirid;
251 struct btrfs_trans_handle *running_transaction;
252 struct btrfs_super_block *disk_super;
256 * in ram representation of the tree. extent_root is used for all allocations
257 * and for the extent tree extent_root root. current_insert is used
258 * only for the extent tree.
261 struct btrfs_buffer *node;
262 struct btrfs_buffer *commit_root;
263 struct btrfs_root_item root_item;
264 struct btrfs_key root_key;
265 struct btrfs_fs_info *fs_info;
271 /* the lower bits in the key flags defines the item type */
272 #define BTRFS_KEY_TYPE_MAX 256
273 #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1)
275 #define BTRFS_KEY_OVERFLOW_MAX 128
276 #define BTRFS_KEY_OVERFLOW_SHIFT 8
277 #define BTRFS_KEY_OVERFLOW_MASK (0x7FULL << BTRFS_KEY_OVERFLOW_SHIFT)
280 * inode items have the data typically returned from stat and store other
281 * info about object characteristics. There is one for every file and dir in
284 #define BTRFS_INODE_ITEM_KEY 1
287 * dir items are the name -> inode pointers in a directory. There is one
288 * for every name in a directory.
290 #define BTRFS_DIR_ITEM_KEY 2
291 #define BTRFS_DIR_INDEX_KEY 3
293 * inline data is file data that fits in the btree.
295 #define BTRFS_INLINE_DATA_KEY 4
297 * extent data is for data that can't fit in the btree. It points to
298 * a (hopefully) huge chunk of disk
300 #define BTRFS_EXTENT_DATA_KEY 5
302 * csum items have the checksums for data in the extents
304 #define BTRFS_CSUM_ITEM_KEY 6
307 * root items point to tree roots. There are typically in the root
308 * tree used by the super block to find all the other trees
310 #define BTRFS_ROOT_ITEM_KEY 7
312 * extent items are in the extent map tree. These record which blocks
313 * are used, and how many references there are to each block
315 #define BTRFS_EXTENT_ITEM_KEY 8
318 * dev items list the devices that make up the FS
320 #define BTRFS_DEV_ITEM_KEY 9
323 * string items are for debugging. They just store a short string of
326 #define BTRFS_STRING_ITEM_KEY 10
328 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
330 return le64_to_cpu(i->generation);
333 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
336 i->generation = cpu_to_le64(val);
339 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
341 return le64_to_cpu(i->size);
344 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
346 i->size = cpu_to_le64(val);
349 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
351 return le64_to_cpu(i->nblocks);
354 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
356 i->nblocks = cpu_to_le64(val);
359 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
361 return le32_to_cpu(i->nlink);
364 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
366 i->nlink = cpu_to_le32(val);
369 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
371 return le32_to_cpu(i->uid);
374 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
376 i->uid = cpu_to_le32(val);
379 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
381 return le32_to_cpu(i->gid);
384 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
386 i->gid = cpu_to_le32(val);
389 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
391 return le32_to_cpu(i->mode);
394 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
396 i->mode = cpu_to_le32(val);
399 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
401 return le32_to_cpu(i->rdev);
404 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
406 i->rdev = cpu_to_le32(val);
409 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
411 return le16_to_cpu(i->flags);
414 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
416 i->flags = cpu_to_le16(val);
419 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
421 return le16_to_cpu(i->compat_flags);
424 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
427 i->compat_flags = cpu_to_le16(val);
430 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
432 return le64_to_cpu(ts->sec);
435 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
438 ts->sec = cpu_to_le64(val);
441 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
443 return le32_to_cpu(ts->nsec);
446 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
449 ts->nsec = cpu_to_le32(val);
452 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
454 return le32_to_cpu(ei->refs);
457 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
459 ei->refs = cpu_to_le32(val);
462 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
464 return le64_to_cpu(n->ptrs[nr].blockptr);
467 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
470 n->ptrs[nr].blockptr = cpu_to_le64(val);
473 static inline u32 btrfs_item_offset(struct btrfs_item *item)
475 return le32_to_cpu(item->offset);
478 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
480 item->offset = cpu_to_le32(val);
483 static inline u32 btrfs_item_end(struct btrfs_item *item)
485 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
488 static inline u16 btrfs_item_size(struct btrfs_item *item)
490 return le16_to_cpu(item->size);
493 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
495 item->size = cpu_to_le16(val);
498 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
500 return le16_to_cpu(d->flags);
503 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
505 d->flags = cpu_to_le16(val);
508 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
513 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
518 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
520 return le16_to_cpu(d->name_len);
523 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
525 d->name_len = cpu_to_le16(val);
528 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
529 struct btrfs_disk_key *disk)
531 cpu->offset = le64_to_cpu(disk->offset);
532 cpu->flags = le32_to_cpu(disk->flags);
533 cpu->objectid = le64_to_cpu(disk->objectid);
536 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
537 struct btrfs_key *cpu)
539 disk->offset = cpu_to_le64(cpu->offset);
540 disk->flags = cpu_to_le32(cpu->flags);
541 disk->objectid = cpu_to_le64(cpu->objectid);
544 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
546 return le64_to_cpu(disk->objectid);
549 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
552 disk->objectid = cpu_to_le64(val);
555 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
557 return le64_to_cpu(disk->offset);
560 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
563 disk->offset = cpu_to_le64(val);
566 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
568 return le32_to_cpu(disk->flags);
571 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
574 disk->flags = cpu_to_le32(val);
577 static inline u32 btrfs_key_overflow(struct btrfs_key *key)
579 u32 over = key->flags & BTRFS_KEY_OVERFLOW_MASK;
580 return over >> BTRFS_KEY_OVERFLOW_SHIFT;
583 static inline void btrfs_set_key_overflow(struct btrfs_key *key, u32 over)
585 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
586 over = over << BTRFS_KEY_OVERFLOW_SHIFT;
587 key->flags = (key->flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
590 static inline u32 btrfs_key_type(struct btrfs_key *key)
592 return key->flags & BTRFS_KEY_TYPE_MASK;
595 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
597 return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK;
600 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type)
602 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
603 key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
606 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
608 u32 flags = btrfs_disk_key_flags(key);
609 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
610 flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
611 btrfs_set_disk_key_flags(key, flags);
614 static inline u32 btrfs_disk_key_overflow(struct btrfs_disk_key *key)
616 u32 over = le32_to_cpu(key->flags) & BTRFS_KEY_OVERFLOW_MASK;
617 return over >> BTRFS_KEY_OVERFLOW_SHIFT;
620 static inline void btrfs_set_disK_key_overflow(struct btrfs_disk_key *key,
623 u32 flags = btrfs_disk_key_flags(key);
624 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
625 over = over << BTRFS_KEY_OVERFLOW_SHIFT;
626 flags = (flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
627 btrfs_set_disk_key_flags(key, flags);
630 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
632 return le64_to_cpu(h->blocknr);
635 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
637 h->blocknr = cpu_to_le64(blocknr);
640 static inline u64 btrfs_header_generation(struct btrfs_header *h)
642 return le64_to_cpu(h->generation);
645 static inline void btrfs_set_header_generation(struct btrfs_header *h,
648 h->generation = 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 u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
855 return le64_to_cpu(e->disk_blocknr);
858 static inline void btrfs_set_file_extent_disk_blocknr(struct
859 btrfs_file_extent_item
862 e->disk_blocknr = cpu_to_le64(val);
865 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
867 return le64_to_cpu(e->generation);
870 static inline void btrfs_set_file_extent_generation(struct
871 btrfs_file_extent_item *e,
874 e->generation = cpu_to_le64(val);
877 static inline u64 btrfs_file_extent_disk_num_blocks(struct
878 btrfs_file_extent_item *e)
880 return le64_to_cpu(e->disk_num_blocks);
883 static inline void btrfs_set_file_extent_disk_num_blocks(struct
884 btrfs_file_extent_item
887 e->disk_num_blocks = cpu_to_le64(val);
890 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
892 return le64_to_cpu(e->offset);
895 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
898 e->offset = cpu_to_le64(val);
901 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
904 return le64_to_cpu(e->num_blocks);
907 static inline void btrfs_set_file_extent_num_blocks(struct
908 btrfs_file_extent_item *e,
911 e->num_blocks = cpu_to_le64(val);
914 static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
916 return le16_to_cpu(d->pathlen);
919 static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
922 d->pathlen = cpu_to_le16(val);
925 static inline u64 btrfs_device_id(struct btrfs_device_item *d)
927 return le64_to_cpu(d->device_id);
930 static inline void btrfs_set_device_id(struct btrfs_device_item *d,
933 d->device_id = cpu_to_le64(val);
936 /* helper function to cast into the data area of the leaf. */
937 #define btrfs_item_ptr(leaf, slot, type) \
938 ((type *)(btrfs_leaf_data(leaf) + \
939 btrfs_item_offset((leaf)->items + (slot))))
941 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
942 struct btrfs_root *root);
943 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
944 struct btrfs_buffer *buf);
945 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
946 *root, u64 blocknr, u64 num_blocks, int pin);
947 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
948 *root, struct btrfs_key *key, struct btrfs_path *p, int
950 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
951 void btrfs_init_path(struct btrfs_path *p);
952 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
953 struct btrfs_path *path);
954 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
955 *root, struct btrfs_key *key, void *data, u32 data_size);
956 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
957 *root, struct btrfs_path *path, struct btrfs_key
958 *cpu_key, u32 data_size);
959 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
960 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
961 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
962 *root, struct btrfs_buffer *snap);
963 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
965 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
966 struct btrfs_key *key);
967 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
968 *root, struct btrfs_key *key, struct btrfs_root_item
970 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
971 *root, struct btrfs_key *key, struct btrfs_root_item
973 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
974 btrfs_root_item *item, struct btrfs_key *key);
975 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
976 *root, char *name, int name_len, u64 dir,
977 struct btrfs_key *location, u8 type);
978 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
979 *root, struct btrfs_path *path, u64 dir, char *name,
980 int name_len, int mod);
981 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
982 char *name, int name_len);
983 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
984 struct btrfs_root *fs_root,
985 u64 dirid, u64 *objectid);
986 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
987 *root, u64 objectid, struct btrfs_inode_item
989 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
990 *root, struct btrfs_path *path, u64 objectid, int mod);