remove device tree
[platform/upstream/btrfs-progs.git] / ctree.h
1 #ifndef __BTRFS__
2 #define __BTRFS__
3
4 #include "list.h"
5 #include "kerncompat.h"
6
7 struct btrfs_trans_handle;
8
9 #define BTRFS_MAGIC "_BtRfS_M"
10
11 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
12 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
13 #define BTRFS_FS_TREE_OBJECTID 3ULL
14 #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
15 #define BTRFS_FIRST_FREE_OBJECTID 5ULL
16
17 /*
18  * we can actually store much bigger names, but lets not confuse the rest
19  * of linux
20  */
21 #define BTRFS_NAME_LEN 255
22
23 /* 32 bytes in various csum fields */
24 #define BTRFS_CSUM_SIZE 32
25
26 #define BTRFS_FT_UNKNOWN        0
27 #define BTRFS_FT_REG_FILE       1
28 #define BTRFS_FT_DIR            2
29 #define BTRFS_FT_CHRDEV         3
30 #define BTRFS_FT_BLKDEV         4
31 #define BTRFS_FT_FIFO           5
32 #define BTRFS_FT_SOCK           6
33 #define BTRFS_FT_SYMLINK        7
34 #define BTRFS_FT_MAX            8
35
36 /*
37  * the key defines the order in the tree, and so it also defines (optimal)
38  * block layout.  objectid corresonds to the inode number.  The flags
39  * tells us things about the object, and is a kind of stream selector.
40  * so for a given inode, keys with flags of 1 might refer to the inode
41  * data, flags of 2 may point to file data in the btree and flags == 3
42  * may point to extents.
43  *
44  * offset is the starting byte offset for this key in the stream.
45  *
46  * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
47  * in cpu native order.  Otherwise they are identical and their sizes
48  * should be the same (ie both packed)
49  */
50 struct btrfs_disk_key {
51         __le64 objectid;
52         __le32 flags;
53         __le64 offset;
54 } __attribute__ ((__packed__));
55
56 struct btrfs_key {
57         u64 objectid;
58         u32 flags;
59         u64 offset;
60 } __attribute__ ((__packed__));
61
62 /*
63  * every tree block (leaf or node) starts with this header.
64  */
65 struct btrfs_header {
66         u8 csum[BTRFS_CSUM_SIZE];
67         u8 fsid[16]; /* FS specific uuid */
68         __le64 blocknr; /* which block this node is supposed to live in */
69         __le64 generation;
70         __le64 owner;
71         __le16 nritems;
72         __le16 flags;
73         u8 level;
74 } __attribute__ ((__packed__));
75
76 #define BTRFS_MAX_LEVEL 8
77 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
78                                 sizeof(struct btrfs_header)) / \
79                                (sizeof(struct btrfs_disk_key) + sizeof(u64)))
80 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
81 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
82
83 struct btrfs_buffer;
84 /*
85  * the super block basically lists the main trees of the FS
86  * it currently lacks any block count etc etc
87  */
88 struct btrfs_super_block {
89         u8 csum[BTRFS_CSUM_SIZE];
90         /* the first 3 fields must match struct btrfs_header */
91         u8 fsid[16];    /* FS specific uuid */
92         __le64 blocknr; /* this block number */
93         __le64 magic;
94         __le32 blocksize;
95         __le64 generation;
96         __le64 root;
97         __le64 total_blocks;
98         __le64 blocks_used;
99         __le64 root_dir_objectid;
100 } __attribute__ ((__packed__));
101
102 /*
103  * A leaf is full of items. offset and size tell us where to find
104  * the item in the leaf (relative to the start of the data area)
105  */
106 struct btrfs_item {
107         struct btrfs_disk_key key;
108         __le32 offset;
109         __le16 size;
110 } __attribute__ ((__packed__));
111
112 /*
113  * leaves have an item area and a data area:
114  * [item0, item1....itemN] [free space] [dataN...data1, data0]
115  *
116  * The data is separate from the items to get the keys closer together
117  * during searches.
118  */
119 struct btrfs_leaf {
120         struct btrfs_header header;
121         struct btrfs_item items[];
122 } __attribute__ ((__packed__));
123
124 /*
125  * all non-leaf blocks are nodes, they hold only keys and pointers to
126  * other blocks
127  */
128 struct btrfs_key_ptr {
129         struct btrfs_disk_key key;
130         __le64 blockptr;
131 } __attribute__ ((__packed__));
132
133 struct btrfs_node {
134         struct btrfs_header header;
135         struct btrfs_key_ptr ptrs[];
136 } __attribute__ ((__packed__));
137
138 /*
139  * btrfs_paths remember the path taken from the root down to the leaf.
140  * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
141  * to any other levels that are present.
142  *
143  * The slots array records the index of the item or block pointer
144  * used while walking the tree.
145  */
146 struct btrfs_path {
147         struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
148         int slots[BTRFS_MAX_LEVEL];
149 };
150
151 /*
152  * items in the extent btree are used to record the objectid of the
153  * owner of the block and the number of references
154  */
155 struct btrfs_extent_item {
156         __le32 refs;
157         __le64 owner;
158 } __attribute__ ((__packed__));
159
160 struct btrfs_inode_timespec {
161         __le64 sec;
162         __le32 nsec;
163 } __attribute__ ((__packed__));
164
165 /*
166  * there is no padding here on purpose.  If you want to extent the inode,
167  * make a new item type
168  */
169 struct btrfs_inode_item {
170         __le64 generation;
171         __le64 size;
172         __le64 nblocks;
173         __le64 block_group;
174         __le32 nlink;
175         __le32 uid;
176         __le32 gid;
177         __le32 mode;
178         __le32 rdev;
179         __le16 flags;
180         __le16 compat_flags;
181         struct btrfs_inode_timespec atime;
182         struct btrfs_inode_timespec ctime;
183         struct btrfs_inode_timespec mtime;
184         struct btrfs_inode_timespec otime;
185 } __attribute__ ((__packed__));
186
187 /* inline data is just a blob of bytes */
188 struct btrfs_inline_data_item {
189         u8 data;
190 } __attribute__ ((__packed__));
191
192 struct btrfs_dir_item {
193         struct btrfs_disk_key location;
194         __le16 flags;
195         __le16 name_len;
196         u8 type;
197 } __attribute__ ((__packed__));
198
199 struct btrfs_root_item {
200         struct btrfs_inode_item inode;
201         __le64 root_dirid;
202         __le64 blocknr;
203         __le32 flags;
204         __le64 block_limit;
205         __le64 blocks_used;
206         __le32 refs;
207 } __attribute__ ((__packed__));
208
209 #define BTRFS_FILE_EXTENT_REG 0
210 #define BTRFS_FILE_EXTENT_INLINE 1
211
212 struct btrfs_file_extent_item {
213         __le64 generation;
214         u8 type;
215         /*
216          * disk space consumed by the extent, checksum blocks are included
217          * in these numbers
218          */
219         __le64 disk_blocknr;
220         __le64 disk_num_blocks;
221         /*
222          * the logical offset in file blocks (no csums)
223          * this extent record is for.  This allows a file extent to point
224          * into the middle of an existing extent on disk, sharing it
225          * between two snapshots (useful if some bytes in the middle of the
226          * extent have changed
227          */
228         __le64 offset;
229         /*
230          * the logical number of file blocks (no csums included)
231          */
232         __le64 num_blocks;
233 } __attribute__ ((__packed__));
234
235 struct btrfs_csum_item {
236         u8 csum[BTRFS_CSUM_SIZE];
237 } __attribute__ ((__packed__));
238
239 /* tag for the radix tree of block groups in ram */
240 #define BTRFS_BLOCK_GROUP_DIRTY 0
241 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
242
243
244 #define BTRFS_BLOCK_GROUP_DATA 1
245 struct btrfs_block_group_item {
246         __le64 used;
247         u8 flags;
248 } __attribute__ ((__packed__));
249
250 struct btrfs_block_group_cache {
251         struct btrfs_key key;
252         struct btrfs_block_group_item item;
253 };
254
255 struct btrfs_fs_info {
256         struct btrfs_root *fs_root;
257         struct btrfs_root *extent_root;
258         struct btrfs_root *tree_root;
259         struct btrfs_key current_insert;
260         struct btrfs_key last_insert;
261         struct radix_tree_root cache_radix;
262         struct radix_tree_root pinned_radix;
263         struct radix_tree_root block_group_radix;
264         struct list_head trans;
265         struct list_head cache;
266         u64 last_inode_alloc;
267         u64 last_inode_alloc_dirid;
268         u64 generation;
269         int cache_size;
270         int fp;
271         struct btrfs_trans_handle *running_transaction;
272         struct btrfs_super_block *disk_super;
273 };
274
275 /*
276  * in ram representation of the tree.  extent_root is used for all allocations
277  * and for the extent tree extent_root root.  current_insert is used
278  * only for the extent tree.
279  */
280 struct btrfs_root {
281         struct btrfs_buffer *node;
282         struct btrfs_buffer *commit_root;
283         struct btrfs_root_item root_item;
284         struct btrfs_key root_key;
285         struct btrfs_fs_info *fs_info;
286         u32 blocksize;
287         int ref_cows;
288         u32 type;
289 };
290
291 /* the lower bits in the key flags defines the item type */
292 #define BTRFS_KEY_TYPE_MAX      256
293 #define BTRFS_KEY_TYPE_SHIFT    24
294 #define BTRFS_KEY_TYPE_MASK     (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
295                                   BTRFS_KEY_TYPE_SHIFT)
296
297 /*
298  * inode items have the data typically returned from stat and store other
299  * info about object characteristics.  There is one for every file and dir in
300  * the FS
301  */
302 #define BTRFS_INODE_ITEM_KEY            1
303
304 /* reserve 2-15 close to the inode for later flexibility */
305
306 /*
307  * dir items are the name -> inode pointers in a directory.  There is one
308  * for every name in a directory.
309  */
310 #define BTRFS_DIR_ITEM_KEY      16
311 #define BTRFS_DIR_INDEX_KEY     17
312 /*
313  * extent data is for file data
314  */
315 #define BTRFS_EXTENT_DATA_KEY   18
316 /*
317  * csum items have the checksums for data in the extents
318  */
319 #define BTRFS_CSUM_ITEM_KEY     19
320
321 /* reserve 20-31 for other file stuff */
322
323 /*
324  * root items point to tree roots.  There are typically in the root
325  * tree used by the super block to find all the other trees
326  */
327 #define BTRFS_ROOT_ITEM_KEY     32
328 /*
329  * extent items are in the extent map tree.  These record which blocks
330  * are used, and how many references there are to each block
331  */
332 #define BTRFS_EXTENT_ITEM_KEY   33
333
334 /*
335  * block groups give us hints into the extent allocation trees.  Which
336  * blocks are free etc etc
337  */
338 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
339
340 /*
341  * string items are for debugging.  They just store a short string of
342  * data in the FS
343  */
344 #define BTRFS_STRING_ITEM_KEY   253
345
346
347 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
348 {
349         return le64_to_cpu(bi->used);
350 }
351
352 static inline void btrfs_set_block_group_used(struct
353                                                    btrfs_block_group_item *bi,
354                                                    u64 val)
355 {
356         bi->used = cpu_to_le64(val);
357 }
358
359 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
360 {
361         return le64_to_cpu(i->generation);
362 }
363
364 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
365                                               u64 val)
366 {
367         i->generation = cpu_to_le64(val);
368 }
369
370 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
371 {
372         return le64_to_cpu(i->size);
373 }
374
375 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
376 {
377         i->size = cpu_to_le64(val);
378 }
379
380 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
381 {
382         return le64_to_cpu(i->nblocks);
383 }
384
385 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
386 {
387         i->nblocks = cpu_to_le64(val);
388 }
389
390 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
391 {
392         return le64_to_cpu(i->block_group);
393 }
394
395 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
396                                                 u64 val)
397 {
398         i->block_group = cpu_to_le64(val);
399 }
400
401 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
402 {
403         return le32_to_cpu(i->nlink);
404 }
405
406 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
407 {
408         i->nlink = cpu_to_le32(val);
409 }
410
411 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
412 {
413         return le32_to_cpu(i->uid);
414 }
415
416 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
417 {
418         i->uid = cpu_to_le32(val);
419 }
420
421 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
422 {
423         return le32_to_cpu(i->gid);
424 }
425
426 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
427 {
428         i->gid = cpu_to_le32(val);
429 }
430
431 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
432 {
433         return le32_to_cpu(i->mode);
434 }
435
436 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
437 {
438         i->mode = cpu_to_le32(val);
439 }
440
441 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
442 {
443         return le32_to_cpu(i->rdev);
444 }
445
446 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
447 {
448         i->rdev = cpu_to_le32(val);
449 }
450
451 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
452 {
453         return le16_to_cpu(i->flags);
454 }
455
456 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
457 {
458         i->flags = cpu_to_le16(val);
459 }
460
461 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
462 {
463         return le16_to_cpu(i->compat_flags);
464 }
465
466 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
467                                                 u16 val)
468 {
469         i->compat_flags = cpu_to_le16(val);
470 }
471
472 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
473 {
474         return le64_to_cpu(ts->sec);
475 }
476
477 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
478                                           u64 val)
479 {
480         ts->sec = cpu_to_le64(val);
481 }
482
483 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
484 {
485         return le32_to_cpu(ts->nsec);
486 }
487
488 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
489                                           u32 val)
490 {
491         ts->nsec = cpu_to_le32(val);
492 }
493
494 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
495 {
496         return le32_to_cpu(ei->refs);
497 }
498
499 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
500 {
501         ei->refs = cpu_to_le32(val);
502 }
503
504 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
505 {
506         return le64_to_cpu(ei->owner);
507 }
508
509 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
510 {
511         ei->owner = cpu_to_le64(val);
512 }
513
514 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
515 {
516         return le64_to_cpu(n->ptrs[nr].blockptr);
517 }
518
519
520 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
521                                            u64 val)
522 {
523         n->ptrs[nr].blockptr = cpu_to_le64(val);
524 }
525
526 static inline u32 btrfs_item_offset(struct btrfs_item *item)
527 {
528         return le32_to_cpu(item->offset);
529 }
530
531 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
532 {
533         item->offset = cpu_to_le32(val);
534 }
535
536 static inline u32 btrfs_item_end(struct btrfs_item *item)
537 {
538         return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
539 }
540
541 static inline u16 btrfs_item_size(struct btrfs_item *item)
542 {
543         return le16_to_cpu(item->size);
544 }
545
546 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
547 {
548         item->size = cpu_to_le16(val);
549 }
550
551 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
552 {
553         return le16_to_cpu(d->flags);
554 }
555
556 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
557 {
558         d->flags = cpu_to_le16(val);
559 }
560
561 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
562 {
563         return d->type;
564 }
565
566 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
567 {
568         d->type = val;
569 }
570
571 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
572 {
573         return le16_to_cpu(d->name_len);
574 }
575
576 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
577 {
578         d->name_len = cpu_to_le16(val);
579 }
580
581 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
582                                          struct btrfs_disk_key *disk)
583 {
584         cpu->offset = le64_to_cpu(disk->offset);
585         cpu->flags = le32_to_cpu(disk->flags);
586         cpu->objectid = le64_to_cpu(disk->objectid);
587 }
588
589 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
590                                          struct btrfs_key *cpu)
591 {
592         disk->offset = cpu_to_le64(cpu->offset);
593         disk->flags = cpu_to_le32(cpu->flags);
594         disk->objectid = cpu_to_le64(cpu->objectid);
595 }
596
597 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
598 {
599         return le64_to_cpu(disk->objectid);
600 }
601
602 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
603                                                u64 val)
604 {
605         disk->objectid = cpu_to_le64(val);
606 }
607
608 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
609 {
610         return le64_to_cpu(disk->offset);
611 }
612
613 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
614                                              u64 val)
615 {
616         disk->offset = cpu_to_le64(val);
617 }
618
619 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
620 {
621         return le32_to_cpu(disk->flags);
622 }
623
624 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
625                                             u32 val)
626 {
627         disk->flags = cpu_to_le32(val);
628 }
629
630 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
631 {
632         return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
633 }
634
635 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
636                                                u32 val)
637 {
638         u32 flags = btrfs_disk_key_flags(key);
639         BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
640         val = val << BTRFS_KEY_TYPE_SHIFT;
641         flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
642         btrfs_set_disk_key_flags(key, flags);
643 }
644
645 static inline u32 btrfs_key_type(struct btrfs_key *key)
646 {
647         return key->flags >> BTRFS_KEY_TYPE_SHIFT;
648 }
649
650 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
651 {
652         BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
653         val = val << BTRFS_KEY_TYPE_SHIFT;
654         key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
655 }
656
657 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
658 {
659         return le64_to_cpu(h->blocknr);
660 }
661
662 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
663 {
664         h->blocknr = cpu_to_le64(blocknr);
665 }
666
667 static inline u64 btrfs_header_generation(struct btrfs_header *h)
668 {
669         return le64_to_cpu(h->generation);
670 }
671
672 static inline void btrfs_set_header_generation(struct btrfs_header *h,
673                                                u64 val)
674 {
675         h->generation = cpu_to_le64(val);
676 }
677
678 static inline u64 btrfs_header_owner(struct btrfs_header *h)
679 {
680         return le64_to_cpu(h->owner);
681 }
682
683 static inline void btrfs_set_header_owner(struct btrfs_header *h,
684                                                u64 val)
685 {
686         h->owner = cpu_to_le64(val);
687 }
688
689 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
690 {
691         return le16_to_cpu(h->nritems);
692 }
693
694 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
695 {
696         h->nritems = cpu_to_le16(val);
697 }
698
699 static inline u16 btrfs_header_flags(struct btrfs_header *h)
700 {
701         return le16_to_cpu(h->flags);
702 }
703
704 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
705 {
706         h->flags = cpu_to_le16(val);
707 }
708
709 static inline int btrfs_header_level(struct btrfs_header *h)
710 {
711         return h->level;
712 }
713
714 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
715 {
716         BUG_ON(level > BTRFS_MAX_LEVEL);
717         h->level = level;
718 }
719
720 static inline int btrfs_is_leaf(struct btrfs_node *n)
721 {
722         return (btrfs_header_level(&n->header) == 0);
723 }
724
725 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
726 {
727         return le64_to_cpu(item->blocknr);
728 }
729
730 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
731 {
732         item->blocknr = cpu_to_le64(val);
733 }
734
735 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
736 {
737         return le64_to_cpu(item->root_dirid);
738 }
739
740 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
741 {
742         item->root_dirid = cpu_to_le64(val);
743 }
744
745 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
746 {
747         return le32_to_cpu(item->refs);
748 }
749
750 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
751 {
752         item->refs = cpu_to_le32(val);
753 }
754
755 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
756 {
757         return le64_to_cpu(s->blocknr);
758 }
759
760 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
761 {
762         s->blocknr = cpu_to_le64(val);
763 }
764
765 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
766 {
767         return le64_to_cpu(s->generation);
768 }
769
770 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
771                                               u64 val)
772 {
773         s->generation = cpu_to_le64(val);
774 }
775
776 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
777 {
778         return le64_to_cpu(s->root);
779 }
780
781 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
782 {
783         s->root = cpu_to_le64(val);
784 }
785
786 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
787 {
788         return le64_to_cpu(s->total_blocks);
789 }
790
791 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
792                                                 u64 val)
793 {
794         s->total_blocks = cpu_to_le64(val);
795 }
796
797 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
798 {
799         return le64_to_cpu(s->blocks_used);
800 }
801
802 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
803                                                 u64 val)
804 {
805         s->blocks_used = cpu_to_le64(val);
806 }
807
808 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
809 {
810         return le32_to_cpu(s->blocksize);
811 }
812
813 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
814                                                 u32 val)
815 {
816         s->blocksize = cpu_to_le32(val);
817 }
818
819 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
820 {
821         return le64_to_cpu(s->root_dir_objectid);
822 }
823
824 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
825                                             val)
826 {
827         s->root_dir_objectid = cpu_to_le64(val);
828 }
829
830 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
831 {
832         return (u8 *)l->items;
833 }
834
835 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
836 {
837         return e->type;
838 }
839 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
840                                               u8 val)
841 {
842         e->type = val;
843 }
844
845 static inline char *btrfs_file_extent_inline_start(struct
846                                                    btrfs_file_extent_item *e)
847 {
848         return (char *)(&e->disk_blocknr);
849 }
850
851 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
852 {
853         return (unsigned long)(&((struct
854                   btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
855 }
856
857 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
858 {
859         struct btrfs_file_extent_item *fe = NULL;
860         return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
861 }
862
863 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
864                                                  *e)
865 {
866         return le64_to_cpu(e->disk_blocknr);
867 }
868
869 static inline void btrfs_set_file_extent_disk_blocknr(struct
870                                                       btrfs_file_extent_item
871                                                       *e, u64 val)
872 {
873         e->disk_blocknr = cpu_to_le64(val);
874 }
875
876 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
877 {
878         return le64_to_cpu(e->generation);
879 }
880
881 static inline void btrfs_set_file_extent_generation(struct
882                                                     btrfs_file_extent_item *e,
883                                                     u64 val)
884 {
885         e->generation = cpu_to_le64(val);
886 }
887
888 static inline u64 btrfs_file_extent_disk_num_blocks(struct
889                                                     btrfs_file_extent_item *e)
890 {
891         return le64_to_cpu(e->disk_num_blocks);
892 }
893
894 static inline void btrfs_set_file_extent_disk_num_blocks(struct
895                                                          btrfs_file_extent_item
896                                                          *e, u64 val)
897 {
898         e->disk_num_blocks = cpu_to_le64(val);
899 }
900
901 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
902 {
903         return le64_to_cpu(e->offset);
904 }
905
906 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
907                                                 *e, u64 val)
908 {
909         e->offset = cpu_to_le64(val);
910 }
911
912 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
913                                                *e)
914 {
915         return le64_to_cpu(e->num_blocks);
916 }
917
918 static inline void btrfs_set_file_extent_num_blocks(struct
919                                                     btrfs_file_extent_item *e,
920                                                     u64 val)
921 {
922         e->num_blocks = cpu_to_le64(val);
923 }
924
925 /* helper function to cast into the data area of the leaf. */
926 #define btrfs_item_ptr(leaf, slot, type) \
927         ((type *)(btrfs_leaf_data(leaf) + \
928         btrfs_item_offset((leaf)->items + (slot))))
929
930 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
931 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
932                       *root, struct btrfs_path *path, u32 data_size);
933 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
934                                             struct btrfs_root *root);
935 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
936                   struct btrfs_buffer *buf);
937 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
938                       *root, u64 blocknr, u64 num_blocks, int pin);
939 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
940                       *root, struct btrfs_key *key, struct btrfs_path *p, int
941                       ins_len, int cow);
942 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
943 void btrfs_init_path(struct btrfs_path *p);
944 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
945                    struct btrfs_path *path);
946 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
947                       *root, struct btrfs_key *key, void *data, u32 data_size);
948 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
949                             *root, struct btrfs_path *path, struct btrfs_key
950                             *cpu_key, u32 data_size);
951 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
952 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
953 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
954                         *root, struct btrfs_buffer *snap);
955 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
956                                btrfs_root *root);
957 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
958                    struct btrfs_key *key);
959 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
960                       *root, struct btrfs_key *key, struct btrfs_root_item
961                       *item);
962 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
963                       *root, struct btrfs_key *key, struct btrfs_root_item
964                       *item);
965 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
966                          btrfs_root_item *item, struct btrfs_key *key);
967 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
968                           *root, char *name, int name_len, u64 dir,
969                           struct btrfs_key *location, u8 type);
970 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
971                           *root, struct btrfs_path *path, u64 dir, char *name,
972                           int name_len, int mod);
973 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
974                               char *name, int name_len);
975 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
976                              struct btrfs_root *fs_root,
977                              u64 dirid, u64 *objectid);
978 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
979                        *root, u64 objectid, struct btrfs_inode_item
980                        *inode_item);
981 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
982                        *root, struct btrfs_path *path, u64 objectid, int mod);
983 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
984                                     struct btrfs_root *root);
985 int btrfs_free_block_groups(struct btrfs_fs_info *info);
986 int btrfs_read_block_groups(struct btrfs_root *root);
987 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
988                              struct btrfs_root *root,
989                              struct btrfs_key *key,
990                              struct btrfs_block_group_item *bi);
991 #endif