32 bit compile fixes
[btrfs-progs-unstable.git] / ctree.h
blob9240fef5a82da2a47cdc8f0e0f783be899253d40
1 #ifndef __BTRFS__
2 #define __BTRFS__
4 #include "list.h"
5 #include "kerncompat.h"
7 struct btrfs_trans_handle;
9 #define BTRFS_MAGIC "_BtRfS_M"
11 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
12 #define BTRFS_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
20 * of linux
22 #define BTRFS_NAME_LEN 255
24 /* 32 bytes in various csum fields */
25 #define BTRFS_CSUM_SIZE 32
27 #define BTRFS_FT_UNKNOWN 0
28 #define BTRFS_FT_REG_FILE 1
29 #define BTRFS_FT_DIR 2
30 #define BTRFS_FT_CHRDEV 3
31 #define BTRFS_FT_BLKDEV 4
32 #define BTRFS_FT_FIFO 5
33 #define BTRFS_FT_SOCK 6
34 #define BTRFS_FT_SYMLINK 7
35 #define BTRFS_FT_MAX 8
38 * the key defines the order in the tree, and so it also defines (optimal)
39 * block layout. objectid corresonds to the inode number. The flags
40 * tells us things about the object, and is a kind of stream selector.
41 * so for a given inode, keys with flags of 1 might refer to the inode
42 * data, flags of 2 may point to file data in the btree and flags == 3
43 * may point to extents.
45 * offset is the starting byte offset for this key in the stream.
47 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
48 * in cpu native order. Otherwise they are identical and their sizes
49 * should be the same (ie both packed)
51 struct btrfs_disk_key {
52 __le64 objectid;
53 __le32 flags;
54 __le64 offset;
55 } __attribute__ ((__packed__));
57 struct btrfs_key {
58 u64 objectid;
59 u32 flags;
60 u64 offset;
61 } __attribute__ ((__packed__));
64 * every tree block (leaf or node) starts with this header.
66 struct btrfs_header {
67 u8 csum[BTRFS_CSUM_SIZE];
68 u8 fsid[16]; /* FS specific uuid */
69 __le64 blocknr; /* which block this node is supposed to live in */
70 __le64 generation;
71 __le64 owner;
72 __le16 nritems;
73 __le16 flags;
74 u8 level;
75 } __attribute__ ((__packed__));
77 #define BTRFS_MAX_LEVEL 8
78 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
79 sizeof(struct btrfs_header)) / \
80 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
81 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
82 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
84 struct btrfs_buffer;
86 * the super block basically lists the main trees of the FS
87 * it currently lacks any block count etc etc
89 struct btrfs_super_block {
90 u8 csum[BTRFS_CSUM_SIZE];
91 /* the first 3 fields must match struct btrfs_header */
92 u8 fsid[16]; /* FS specific uuid */
93 __le64 blocknr; /* this block number */
94 __le64 magic;
95 __le32 blocksize;
96 __le64 generation;
97 __le64 root;
98 __le64 total_blocks;
99 __le64 blocks_used;
100 __le64 root_dir_objectid;
101 __le64 last_device_id;
102 /* fields below here vary with the underlying disk */
103 __le64 device_block_start;
104 __le64 device_num_blocks;
105 __le64 device_root;
106 __le64 device_id;
107 } __attribute__ ((__packed__));
110 * A leaf is full of items. offset and size tell us where to find
111 * the item in the leaf (relative to the start of the data area)
113 struct btrfs_item {
114 struct btrfs_disk_key key;
115 __le32 offset;
116 __le16 size;
117 } __attribute__ ((__packed__));
120 * leaves have an item area and a data area:
121 * [item0, item1....itemN] [free space] [dataN...data1, data0]
123 * The data is separate from the items to get the keys closer together
124 * during searches.
126 struct btrfs_leaf {
127 struct btrfs_header header;
128 struct btrfs_item items[];
129 } __attribute__ ((__packed__));
132 * all non-leaf blocks are nodes, they hold only keys and pointers to
133 * other blocks
135 struct btrfs_key_ptr {
136 struct btrfs_disk_key key;
137 __le64 blockptr;
138 } __attribute__ ((__packed__));
140 struct btrfs_node {
141 struct btrfs_header header;
142 struct btrfs_key_ptr ptrs[];
143 } __attribute__ ((__packed__));
146 * btrfs_paths remember the path taken from the root down to the leaf.
147 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
148 * to any other levels that are present.
150 * The slots array records the index of the item or block pointer
151 * used while walking the tree.
153 struct btrfs_path {
154 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
155 int slots[BTRFS_MAX_LEVEL];
159 * items in the extent btree are used to record the objectid of the
160 * owner of the block and the number of references
162 struct btrfs_extent_item {
163 __le32 refs;
164 __le64 owner;
165 } __attribute__ ((__packed__));
167 struct btrfs_inode_timespec {
168 __le64 sec;
169 __le32 nsec;
170 } __attribute__ ((__packed__));
173 * there is no padding here on purpose. If you want to extent the inode,
174 * make a new item type
176 struct btrfs_inode_item {
177 __le64 generation;
178 __le64 size;
179 __le64 nblocks;
180 __le64 block_group;
181 __le32 nlink;
182 __le32 uid;
183 __le32 gid;
184 __le32 mode;
185 __le32 rdev;
186 __le16 flags;
187 __le16 compat_flags;
188 struct btrfs_inode_timespec atime;
189 struct btrfs_inode_timespec ctime;
190 struct btrfs_inode_timespec mtime;
191 struct btrfs_inode_timespec otime;
192 } __attribute__ ((__packed__));
194 /* inline data is just a blob of bytes */
195 struct btrfs_inline_data_item {
196 u8 data;
197 } __attribute__ ((__packed__));
199 struct btrfs_dir_item {
200 struct btrfs_disk_key location;
201 __le16 flags;
202 __le16 name_len;
203 u8 type;
204 } __attribute__ ((__packed__));
206 struct btrfs_root_item {
207 struct btrfs_inode_item inode;
208 __le64 root_dirid;
209 __le64 blocknr;
210 __le32 flags;
211 __le64 block_limit;
212 __le64 blocks_used;
213 __le32 refs;
214 } __attribute__ ((__packed__));
216 #define BTRFS_FILE_EXTENT_REG 0
217 #define BTRFS_FILE_EXTENT_INLINE 1
219 struct btrfs_file_extent_item {
220 __le64 generation;
221 u8 type;
223 * disk space consumed by the extent, checksum blocks are included
224 * in these numbers
226 __le64 disk_blocknr;
227 __le64 disk_num_blocks;
229 * the logical offset in file blocks (no csums)
230 * this extent record is for. This allows a file extent to point
231 * into the middle of an existing extent on disk, sharing it
232 * between two snapshots (useful if some bytes in the middle of the
233 * extent have changed
235 __le64 offset;
237 * the logical number of file blocks (no csums included)
239 __le64 num_blocks;
240 } __attribute__ ((__packed__));
242 struct btrfs_csum_item {
243 u8 csum[BTRFS_CSUM_SIZE];
244 } __attribute__ ((__packed__));
246 struct btrfs_device_item {
247 __le16 pathlen;
248 __le64 device_id;
249 } __attribute__ ((__packed__));
251 /* tag for the radix tree of block groups in ram */
252 #define BTRFS_BLOCK_GROUP_DIRTY 0
253 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
256 #define BTRFS_BLOCK_GROUP_DATA 1
257 struct btrfs_block_group_item {
258 __le64 used;
259 u8 flags;
260 } __attribute__ ((__packed__));
262 struct btrfs_block_group_cache {
263 struct btrfs_key key;
264 struct btrfs_block_group_item item;
267 struct btrfs_fs_info {
268 struct btrfs_root *fs_root;
269 struct btrfs_root *extent_root;
270 struct btrfs_root *tree_root;
271 struct btrfs_root *dev_root;
272 struct btrfs_key current_insert;
273 struct btrfs_key last_insert;
274 struct radix_tree_root cache_radix;
275 struct radix_tree_root pinned_radix;
276 struct radix_tree_root dev_radix;
277 struct radix_tree_root block_group_radix;
278 struct list_head trans;
279 struct list_head cache;
280 u64 last_inode_alloc;
281 u64 last_inode_alloc_dirid;
282 u64 generation;
283 int cache_size;
284 int fp;
285 struct btrfs_trans_handle *running_transaction;
286 struct btrfs_super_block *disk_super;
290 * in ram representation of the tree. extent_root is used for all allocations
291 * and for the extent tree extent_root root. current_insert is used
292 * only for the extent tree.
294 struct btrfs_root {
295 struct btrfs_buffer *node;
296 struct btrfs_buffer *commit_root;
297 struct btrfs_root_item root_item;
298 struct btrfs_key root_key;
299 struct btrfs_fs_info *fs_info;
300 u32 blocksize;
301 int ref_cows;
302 u32 type;
305 /* the lower bits in the key flags defines the item type */
306 #define BTRFS_KEY_TYPE_MAX 256
307 #define BTRFS_KEY_TYPE_SHIFT 24
308 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
309 BTRFS_KEY_TYPE_SHIFT)
312 * inode items have the data typically returned from stat and store other
313 * info about object characteristics. There is one for every file and dir in
314 * the FS
316 #define BTRFS_INODE_ITEM_KEY 1
318 /* reserve 2-15 close to the inode for later flexibility */
321 * dir items are the name -> inode pointers in a directory. There is one
322 * for every name in a directory.
324 #define BTRFS_DIR_ITEM_KEY 16
325 #define BTRFS_DIR_INDEX_KEY 17
327 * extent data is for file data
329 #define BTRFS_EXTENT_DATA_KEY 18
331 * csum items have the checksums for data in the extents
333 #define BTRFS_CSUM_ITEM_KEY 19
335 /* reserve 20-31 for other file stuff */
338 * root items point to tree roots. There are typically in the root
339 * tree used by the super block to find all the other trees
341 #define BTRFS_ROOT_ITEM_KEY 32
343 * extent items are in the extent map tree. These record which blocks
344 * are used, and how many references there are to each block
346 #define BTRFS_EXTENT_ITEM_KEY 33
349 * block groups give us hints into the extent allocation trees. Which
350 * blocks are free etc etc
352 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
355 * dev items list the devices that make up the FS
357 #define BTRFS_DEV_ITEM_KEY 35
360 * string items are for debugging. They just store a short string of
361 * data in the FS
363 #define BTRFS_STRING_ITEM_KEY 253
366 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
368 return le64_to_cpu(bi->used);
371 static inline void btrfs_set_block_group_used(struct
372 btrfs_block_group_item *bi,
373 u64 val)
375 bi->used = cpu_to_le64(val);
378 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
380 return le64_to_cpu(i->generation);
383 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
384 u64 val)
386 i->generation = cpu_to_le64(val);
389 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
391 return le64_to_cpu(i->size);
394 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
396 i->size = cpu_to_le64(val);
399 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
401 return le64_to_cpu(i->nblocks);
404 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
406 i->nblocks = cpu_to_le64(val);
409 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
411 return le64_to_cpu(i->block_group);
414 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
415 u64 val)
417 i->block_group = cpu_to_le64(val);
420 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
422 return le32_to_cpu(i->nlink);
425 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
427 i->nlink = cpu_to_le32(val);
430 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
432 return le32_to_cpu(i->uid);
435 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
437 i->uid = cpu_to_le32(val);
440 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
442 return le32_to_cpu(i->gid);
445 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
447 i->gid = cpu_to_le32(val);
450 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
452 return le32_to_cpu(i->mode);
455 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
457 i->mode = cpu_to_le32(val);
460 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
462 return le32_to_cpu(i->rdev);
465 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
467 i->rdev = cpu_to_le32(val);
470 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
472 return le16_to_cpu(i->flags);
475 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
477 i->flags = cpu_to_le16(val);
480 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
482 return le16_to_cpu(i->compat_flags);
485 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
486 u16 val)
488 i->compat_flags = cpu_to_le16(val);
491 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
493 return le64_to_cpu(ts->sec);
496 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
497 u64 val)
499 ts->sec = cpu_to_le64(val);
502 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
504 return le32_to_cpu(ts->nsec);
507 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
508 u32 val)
510 ts->nsec = cpu_to_le32(val);
513 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
515 return le32_to_cpu(ei->refs);
518 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
520 ei->refs = cpu_to_le32(val);
523 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
525 return le64_to_cpu(ei->owner);
528 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
530 ei->owner = cpu_to_le64(val);
533 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
535 return le64_to_cpu(n->ptrs[nr].blockptr);
539 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
540 u64 val)
542 n->ptrs[nr].blockptr = cpu_to_le64(val);
545 static inline u32 btrfs_item_offset(struct btrfs_item *item)
547 return le32_to_cpu(item->offset);
550 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
552 item->offset = cpu_to_le32(val);
555 static inline u32 btrfs_item_end(struct btrfs_item *item)
557 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
560 static inline u16 btrfs_item_size(struct btrfs_item *item)
562 return le16_to_cpu(item->size);
565 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
567 item->size = cpu_to_le16(val);
570 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
572 return le16_to_cpu(d->flags);
575 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
577 d->flags = cpu_to_le16(val);
580 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
582 return d->type;
585 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
587 d->type = val;
590 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
592 return le16_to_cpu(d->name_len);
595 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
597 d->name_len = cpu_to_le16(val);
600 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
601 struct btrfs_disk_key *disk)
603 cpu->offset = le64_to_cpu(disk->offset);
604 cpu->flags = le32_to_cpu(disk->flags);
605 cpu->objectid = le64_to_cpu(disk->objectid);
608 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
609 struct btrfs_key *cpu)
611 disk->offset = cpu_to_le64(cpu->offset);
612 disk->flags = cpu_to_le32(cpu->flags);
613 disk->objectid = cpu_to_le64(cpu->objectid);
616 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
618 return le64_to_cpu(disk->objectid);
621 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
622 u64 val)
624 disk->objectid = cpu_to_le64(val);
627 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
629 return le64_to_cpu(disk->offset);
632 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
633 u64 val)
635 disk->offset = cpu_to_le64(val);
638 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
640 return le32_to_cpu(disk->flags);
643 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
644 u32 val)
646 disk->flags = cpu_to_le32(val);
649 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
651 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
654 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
655 u32 val)
657 u32 flags = btrfs_disk_key_flags(key);
658 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
659 val = val << BTRFS_KEY_TYPE_SHIFT;
660 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
661 btrfs_set_disk_key_flags(key, flags);
664 static inline u32 btrfs_key_type(struct btrfs_key *key)
666 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
669 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
671 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
672 val = val << BTRFS_KEY_TYPE_SHIFT;
673 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
676 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
678 return le64_to_cpu(h->blocknr);
681 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
683 h->blocknr = cpu_to_le64(blocknr);
686 static inline u64 btrfs_header_generation(struct btrfs_header *h)
688 return le64_to_cpu(h->generation);
691 static inline void btrfs_set_header_generation(struct btrfs_header *h,
692 u64 val)
694 h->generation = cpu_to_le64(val);
697 static inline u64 btrfs_header_owner(struct btrfs_header *h)
699 return le64_to_cpu(h->owner);
702 static inline void btrfs_set_header_owner(struct btrfs_header *h,
703 u64 val)
705 h->owner = cpu_to_le64(val);
708 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
710 return le16_to_cpu(h->nritems);
713 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
715 h->nritems = cpu_to_le16(val);
718 static inline u16 btrfs_header_flags(struct btrfs_header *h)
720 return le16_to_cpu(h->flags);
723 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
725 h->flags = cpu_to_le16(val);
728 static inline int btrfs_header_level(struct btrfs_header *h)
730 return h->level;
733 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
735 BUG_ON(level > BTRFS_MAX_LEVEL);
736 h->level = level;
739 static inline int btrfs_is_leaf(struct btrfs_node *n)
741 return (btrfs_header_level(&n->header) == 0);
744 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
746 return le64_to_cpu(item->blocknr);
749 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
751 item->blocknr = cpu_to_le64(val);
754 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
756 return le64_to_cpu(item->root_dirid);
759 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
761 item->root_dirid = cpu_to_le64(val);
764 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
766 return le32_to_cpu(item->refs);
769 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
771 item->refs = cpu_to_le32(val);
774 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
776 return le64_to_cpu(s->blocknr);
779 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
781 s->blocknr = cpu_to_le64(val);
784 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
786 return le64_to_cpu(s->generation);
789 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
790 u64 val)
792 s->generation = cpu_to_le64(val);
795 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
797 return le64_to_cpu(s->root);
800 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
802 s->root = cpu_to_le64(val);
805 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
807 return le64_to_cpu(s->total_blocks);
810 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
811 u64 val)
813 s->total_blocks = cpu_to_le64(val);
816 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
818 return le64_to_cpu(s->blocks_used);
821 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
822 u64 val)
824 s->blocks_used = cpu_to_le64(val);
827 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
829 return le32_to_cpu(s->blocksize);
832 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
833 u32 val)
835 s->blocksize = cpu_to_le32(val);
838 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
840 return le64_to_cpu(s->root_dir_objectid);
843 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
844 val)
846 s->root_dir_objectid = cpu_to_le64(val);
849 static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
851 return le64_to_cpu(s->last_device_id);
854 static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
855 u64 val)
857 s->last_device_id = cpu_to_le64(val);
860 static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
862 return le64_to_cpu(s->device_id);
865 static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
866 u64 val)
868 s->device_id = cpu_to_le64(val);
871 static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
873 return le64_to_cpu(s->device_block_start);
876 static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
877 *s, u64 val)
879 s->device_block_start = cpu_to_le64(val);
882 static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
884 return le64_to_cpu(s->device_num_blocks);
887 static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
888 *s, u64 val)
890 s->device_num_blocks = cpu_to_le64(val);
893 static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
895 return le64_to_cpu(s->device_root);
898 static inline void btrfs_set_super_device_root(struct btrfs_super_block
899 *s, u64 val)
901 s->device_root = cpu_to_le64(val);
904 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
906 return (u8 *)l->items;
909 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
911 return e->type;
913 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
914 u8 val)
916 e->type = val;
919 static inline char *btrfs_file_extent_inline_start(struct
920 btrfs_file_extent_item *e)
922 return (char *)(&e->disk_blocknr);
925 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
927 return (unsigned long)(&((struct
928 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
931 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
933 struct btrfs_file_extent_item *fe = NULL;
934 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
937 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
940 return le64_to_cpu(e->disk_blocknr);
943 static inline void btrfs_set_file_extent_disk_blocknr(struct
944 btrfs_file_extent_item
945 *e, u64 val)
947 e->disk_blocknr = cpu_to_le64(val);
950 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
952 return le64_to_cpu(e->generation);
955 static inline void btrfs_set_file_extent_generation(struct
956 btrfs_file_extent_item *e,
957 u64 val)
959 e->generation = cpu_to_le64(val);
962 static inline u64 btrfs_file_extent_disk_num_blocks(struct
963 btrfs_file_extent_item *e)
965 return le64_to_cpu(e->disk_num_blocks);
968 static inline void btrfs_set_file_extent_disk_num_blocks(struct
969 btrfs_file_extent_item
970 *e, u64 val)
972 e->disk_num_blocks = cpu_to_le64(val);
975 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
977 return le64_to_cpu(e->offset);
980 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
981 *e, u64 val)
983 e->offset = cpu_to_le64(val);
986 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
989 return le64_to_cpu(e->num_blocks);
992 static inline void btrfs_set_file_extent_num_blocks(struct
993 btrfs_file_extent_item *e,
994 u64 val)
996 e->num_blocks = cpu_to_le64(val);
999 static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
1001 return le16_to_cpu(d->pathlen);
1004 static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
1005 u16 val)
1007 d->pathlen = cpu_to_le16(val);
1010 static inline u64 btrfs_device_id(struct btrfs_device_item *d)
1012 return le64_to_cpu(d->device_id);
1015 static inline void btrfs_set_device_id(struct btrfs_device_item *d,
1016 u64 val)
1018 d->device_id = cpu_to_le64(val);
1021 /* helper function to cast into the data area of the leaf. */
1022 #define btrfs_item_ptr(leaf, slot, type) \
1023 ((type *)(btrfs_leaf_data(leaf) + \
1024 btrfs_item_offset((leaf)->items + (slot))))
1026 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1027 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1028 *root, struct btrfs_path *path, u32 data_size);
1029 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1030 struct btrfs_root *root);
1031 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1032 struct btrfs_buffer *buf);
1033 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1034 *root, u64 blocknr, u64 num_blocks, int pin);
1035 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1036 *root, struct btrfs_key *key, struct btrfs_path *p, int
1037 ins_len, int cow);
1038 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1039 void btrfs_init_path(struct btrfs_path *p);
1040 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1041 struct btrfs_path *path);
1042 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1043 *root, struct btrfs_key *key, void *data, u32 data_size);
1044 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1045 *root, struct btrfs_path *path, struct btrfs_key
1046 *cpu_key, u32 data_size);
1047 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1048 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1049 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1050 *root, struct btrfs_buffer *snap);
1051 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1052 btrfs_root *root);
1053 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1054 struct btrfs_key *key);
1055 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1056 *root, struct btrfs_key *key, struct btrfs_root_item
1057 *item);
1058 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1059 *root, struct btrfs_key *key, struct btrfs_root_item
1060 *item);
1061 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1062 btrfs_root_item *item, struct btrfs_key *key);
1063 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1064 *root, char *name, int name_len, u64 dir,
1065 struct btrfs_key *location, u8 type);
1066 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1067 *root, struct btrfs_path *path, u64 dir, char *name,
1068 int name_len, int mod);
1069 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
1070 char *name, int name_len);
1071 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1072 struct btrfs_root *fs_root,
1073 u64 dirid, u64 *objectid);
1074 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1075 *root, u64 objectid, struct btrfs_inode_item
1076 *inode_item);
1077 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1078 *root, struct btrfs_path *path, u64 objectid, int mod);
1079 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1080 struct btrfs_root *root);
1081 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1082 int btrfs_read_block_groups(struct btrfs_root *root);
1083 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1084 struct btrfs_root *root,
1085 struct btrfs_key *key,
1086 struct btrfs_block_group_item *bi);
1087 #endif