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