]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/btrfs/ctree.h
Btrfs: add generation field to file extent
[linux-2.6-omap-h63xx.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 mutex trans_mutex;
237         struct mutex fs_mutex;
238 };
239
240 /*
241  * in ram representation of the tree.  extent_root is used for all allocations
242  * and for the extent tree extent_root root.  current_insert is used
243  * only for the extent tree.
244  */
245 struct btrfs_root {
246         struct buffer_head *node;
247         struct buffer_head *commit_root;
248         struct btrfs_root_item root_item;
249         struct btrfs_key root_key;
250         struct btrfs_fs_info *fs_info;
251         u32 blocksize;
252         int ref_cows;
253         u32 type;
254 };
255
256 /* the lower bits in the key flags defines the item type */
257 #define BTRFS_KEY_TYPE_MAX      256
258 #define BTRFS_KEY_TYPE_MASK     (BTRFS_KEY_TYPE_MAX - 1)
259
260 /*
261  * inode items have the data typically returned from stat and store other
262  * info about object characteristics.  There is one for every file and dir in
263  * the FS
264  */
265 #define BTRFS_INODE_ITEM_KEY    1
266
267 /*
268  * dir items are the name -> inode pointers in a directory.  There is one
269  * for every name in a directory.
270  */
271 #define BTRFS_DIR_ITEM_KEY      2
272 /*
273  * inline data is file data that fits in the btree.
274  */
275 #define BTRFS_INLINE_DATA_KEY   3
276 /*
277  * extent data is for data that can't fit in the btree.  It points to
278  * a (hopefully) huge chunk of disk
279  */
280 #define BTRFS_EXTENT_DATA_KEY   4
281 /*
282  * root items point to tree roots.  There are typically in the root
283  * tree used by the super block to find all the other trees
284  */
285 #define BTRFS_ROOT_ITEM_KEY     5
286 /*
287  * extent items are in the extent map tree.  These record which blocks
288  * are used, and how many references there are to each block
289  */
290 #define BTRFS_EXTENT_ITEM_KEY   6
291
292 /*
293  * the inode map records which inode numbers are in use and where
294  * they actually live on disk
295  */
296 #define BTRFS_INODE_MAP_ITEM_KEY 7
297 /*
298  * string items are for debugging.  They just store a short string of
299  * data in the FS
300  */
301 #define BTRFS_STRING_ITEM_KEY   8
302
303 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
304 {
305         return le64_to_cpu(i->generation);
306 }
307
308 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
309                                               u64 val)
310 {
311         i->generation = cpu_to_le64(val);
312 }
313
314 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
315 {
316         return le64_to_cpu(i->size);
317 }
318
319 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
320 {
321         i->size = cpu_to_le64(val);
322 }
323
324 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
325 {
326         return le64_to_cpu(i->nblocks);
327 }
328
329 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
330 {
331         i->nblocks = cpu_to_le64(val);
332 }
333
334 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
335 {
336         return le32_to_cpu(i->nlink);
337 }
338
339 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
340 {
341         i->nlink = cpu_to_le32(val);
342 }
343
344 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
345 {
346         return le32_to_cpu(i->uid);
347 }
348
349 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
350 {
351         i->uid = cpu_to_le32(val);
352 }
353
354 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
355 {
356         return le32_to_cpu(i->gid);
357 }
358
359 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
360 {
361         i->gid = cpu_to_le32(val);
362 }
363
364 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
365 {
366         return le32_to_cpu(i->mode);
367 }
368
369 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
370 {
371         i->mode = cpu_to_le32(val);
372 }
373
374 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
375 {
376         return le32_to_cpu(i->rdev);
377 }
378
379 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
380 {
381         i->rdev = cpu_to_le32(val);
382 }
383
384 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
385 {
386         return le16_to_cpu(i->flags);
387 }
388
389 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
390 {
391         i->flags = cpu_to_le16(val);
392 }
393
394 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
395 {
396         return le16_to_cpu(i->compat_flags);
397 }
398
399 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
400                                                 u16 val)
401 {
402         i->compat_flags = cpu_to_le16(val);
403 }
404
405 static inline u32 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
406 {
407         return le32_to_cpu(ts->sec);
408 }
409
410 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
411                                           u32 val)
412 {
413         ts->sec = cpu_to_le32(val);
414 }
415
416 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
417 {
418         return le32_to_cpu(ts->nsec);
419 }
420
421 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
422                                           u32 val)
423 {
424         ts->nsec = cpu_to_le32(val);
425 }
426
427
428
429 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
430 {
431         return le64_to_cpu(ei->owner);
432 }
433
434 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
435 {
436         ei->owner = cpu_to_le64(val);
437 }
438
439 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
440 {
441         return le32_to_cpu(ei->refs);
442 }
443
444 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
445 {
446         ei->refs = cpu_to_le32(val);
447 }
448
449 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
450 {
451         return le64_to_cpu(n->ptrs[nr].blockptr);
452 }
453
454 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
455                                            u64 val)
456 {
457         n->ptrs[nr].blockptr = cpu_to_le64(val);
458 }
459
460 static inline u32 btrfs_item_offset(struct btrfs_item *item)
461 {
462         return le32_to_cpu(item->offset);
463 }
464
465 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
466 {
467         item->offset = cpu_to_le32(val);
468 }
469
470 static inline u32 btrfs_item_end(struct btrfs_item *item)
471 {
472         return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
473 }
474
475 static inline u16 btrfs_item_size(struct btrfs_item *item)
476 {
477         return le16_to_cpu(item->size);
478 }
479
480 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
481 {
482         item->size = cpu_to_le16(val);
483 }
484
485 static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d)
486 {
487         return le64_to_cpu(d->objectid);
488 }
489
490 static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val)
491 {
492         d->objectid = cpu_to_le64(val);
493 }
494
495 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
496 {
497         return le16_to_cpu(d->flags);
498 }
499
500 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
501 {
502         d->flags = cpu_to_le16(val);
503 }
504
505 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
506 {
507         return d->type;
508 }
509
510 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
511 {
512         d->type = val;
513 }
514
515 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
516 {
517         return le16_to_cpu(d->name_len);
518 }
519
520 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
521 {
522         d->name_len = cpu_to_le16(val);
523 }
524
525 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
526                                          struct btrfs_disk_key *disk)
527 {
528         cpu->offset = le64_to_cpu(disk->offset);
529         cpu->flags = le32_to_cpu(disk->flags);
530         cpu->objectid = le64_to_cpu(disk->objectid);
531 }
532
533 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
534                                          struct btrfs_key *cpu)
535 {
536         disk->offset = cpu_to_le64(cpu->offset);
537         disk->flags = cpu_to_le32(cpu->flags);
538         disk->objectid = cpu_to_le64(cpu->objectid);
539 }
540
541 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
542 {
543         return le64_to_cpu(disk->objectid);
544 }
545
546 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
547                                                u64 val)
548 {
549         disk->objectid = cpu_to_le64(val);
550 }
551
552 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
553 {
554         return le64_to_cpu(disk->offset);
555 }
556
557 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
558                                              u64 val)
559 {
560         disk->offset = cpu_to_le64(val);
561 }
562
563 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
564 {
565         return le32_to_cpu(disk->flags);
566 }
567
568 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
569                                             u32 val)
570 {
571         disk->flags = cpu_to_le32(val);
572 }
573
574 static inline u32 btrfs_key_type(struct btrfs_key *key)
575 {
576         return key->flags & BTRFS_KEY_TYPE_MASK;
577 }
578
579 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
580 {
581         return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK;
582 }
583
584 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type)
585 {
586         BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
587         key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
588 }
589
590 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
591 {
592         u32 flags = btrfs_disk_key_flags(key);
593         BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
594         flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
595         btrfs_set_disk_key_flags(key, flags);
596 }
597
598 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
599 {
600         return le64_to_cpu(h->blocknr);
601 }
602
603 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
604 {
605         h->blocknr = cpu_to_le64(blocknr);
606 }
607
608 static inline u64 btrfs_header_generation(struct btrfs_header *h)
609 {
610         return le64_to_cpu(h->generation);
611 }
612
613 static inline void btrfs_set_header_generation(struct btrfs_header *h,
614                                                u64 val)
615 {
616         h->generation = cpu_to_le64(val);
617 }
618
619 static inline u64 btrfs_header_parentid(struct btrfs_header *h)
620 {
621         return le64_to_cpu(h->parentid);
622 }
623
624 static inline void btrfs_set_header_parentid(struct btrfs_header *h,
625                                              u64 parentid)
626 {
627         h->parentid = cpu_to_le64(parentid);
628 }
629
630 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
631 {
632         return le16_to_cpu(h->nritems);
633 }
634
635 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
636 {
637         h->nritems = cpu_to_le16(val);
638 }
639
640 static inline u16 btrfs_header_flags(struct btrfs_header *h)
641 {
642         return le16_to_cpu(h->flags);
643 }
644
645 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
646 {
647         h->flags = cpu_to_le16(val);
648 }
649
650 static inline int btrfs_header_level(struct btrfs_header *h)
651 {
652         return h->level;
653 }
654
655 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
656 {
657         BUG_ON(level > BTRFS_MAX_LEVEL);
658         h->level = level;
659 }
660
661 static inline int btrfs_is_leaf(struct btrfs_node *n)
662 {
663         return (btrfs_header_level(&n->header) == 0);
664 }
665
666 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
667 {
668         return le64_to_cpu(item->blocknr);
669 }
670
671 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
672 {
673         item->blocknr = cpu_to_le64(val);
674 }
675
676 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
677 {
678         return le32_to_cpu(item->refs);
679 }
680
681 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
682 {
683         item->refs = cpu_to_le32(val);
684 }
685
686 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
687 {
688         return le64_to_cpu(s->blocknr);
689 }
690
691 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
692 {
693         s->blocknr = cpu_to_le64(val);
694 }
695
696 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
697 {
698         return le64_to_cpu(s->root);
699 }
700
701 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
702 {
703         s->root = cpu_to_le64(val);
704 }
705
706 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
707 {
708         return le64_to_cpu(s->total_blocks);
709 }
710
711 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
712                                                 u64 val)
713 {
714         s->total_blocks = cpu_to_le64(val);
715 }
716
717 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
718 {
719         return le64_to_cpu(s->blocks_used);
720 }
721
722 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
723                                                 u64 val)
724 {
725         s->blocks_used = cpu_to_le64(val);
726 }
727
728 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
729 {
730         return le32_to_cpu(s->blocksize);
731 }
732
733 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
734                                                 u32 val)
735 {
736         s->blocksize = cpu_to_le32(val);
737 }
738
739 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
740 {
741         return le64_to_cpu(s->root_dir_objectid);
742 }
743
744 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
745                                             val)
746 {
747         s->root_dir_objectid = cpu_to_le64(val);
748 }
749
750 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
751 {
752         return (u8 *)l->items;
753 }
754
755 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
756                                                  *e)
757 {
758         return le64_to_cpu(e->disk_blocknr);
759 }
760
761 static inline void btrfs_set_file_extent_disk_blocknr(struct
762                                                       btrfs_file_extent_item
763                                                       *e, u64 val)
764 {
765         e->disk_blocknr = cpu_to_le64(val);
766 }
767
768 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
769 {
770         return le64_to_cpu(e->generation);
771 }
772
773 static inline void btrfs_set_file_extent_generation(struct
774                                                     btrfs_file_extent_item *e,
775                                                     u64 val)
776 {
777         e->generation = cpu_to_le64(val);
778 }
779
780 static inline u64 btrfs_file_extent_disk_num_blocks(struct
781                                                     btrfs_file_extent_item *e)
782 {
783         return le64_to_cpu(e->disk_num_blocks);
784 }
785
786 static inline void btrfs_set_file_extent_disk_num_blocks(struct
787                                                          btrfs_file_extent_item
788                                                          *e, u64 val)
789 {
790         e->disk_num_blocks = cpu_to_le64(val);
791 }
792
793 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
794 {
795         return le64_to_cpu(e->offset);
796 }
797
798 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
799                                                 *e, u64 val)
800 {
801         e->offset = cpu_to_le64(val);
802 }
803
804 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
805                                                *e)
806 {
807         return le64_to_cpu(e->num_blocks);
808 }
809
810 static inline void btrfs_set_file_extent_num_blocks(struct
811                                                     btrfs_file_extent_item *e,
812                                                     u64 val)
813 {
814         e->num_blocks = cpu_to_le64(val);
815 }
816
817 static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
818 {
819         return sb->s_fs_info;
820 }
821
822 /* helper function to cast into the data area of the leaf. */
823 #define btrfs_item_ptr(leaf, slot, type) \
824         ((type *)(btrfs_leaf_data(leaf) + \
825         btrfs_item_offset((leaf)->items + (slot))))
826
827 /* extent-item.c */
828 struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
829                                             struct btrfs_root *root);
830 int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root
831                         *root, u64 num_blocks, u64 search_start, u64
832                         search_end, u64 owner, struct btrfs_key *ins);
833 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
834                   struct buffer_head *buf);
835 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
836                       *root, u64 blocknr, u64 num_blocks, int pin);
837 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
838                                btrfs_root *root);
839 /* ctree.c */
840 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
841                       *root, struct btrfs_key *key, struct btrfs_path *p, int
842                       ins_len, int cow);
843 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
844 void btrfs_init_path(struct btrfs_path *p);
845 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
846                    struct btrfs_path *path);
847 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
848                       *root, struct btrfs_key *key, void *data, u32 data_size);
849 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
850                             *root, struct btrfs_path *path, struct btrfs_key
851                             *cpu_key, u32 data_size);
852 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
853 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
854 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
855                         *root, struct buffer_head *snap);
856 /* root-item.c */
857 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
858                    struct btrfs_key *key);
859 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
860                       *root, struct btrfs_key *key, struct btrfs_root_item
861                       *item);
862 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
863                       *root, struct btrfs_key *key, struct btrfs_root_item
864                       *item);
865 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
866                          btrfs_root_item *item, struct btrfs_key *key);
867 /* dir-item.c */
868 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
869                           *root, const char *name, int name_len, u64 dir, u64
870                           objectid, u8 type);
871 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
872                           *root, struct btrfs_path *path, u64 dir,
873                           const char *name, int name_len, int mod);
874 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
875                               const char *name, int name_len);
876 /* inode-map.c */
877 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
878                              struct btrfs_root *fs_root,
879                              u64 dirid, u64 *objectid);
880 int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
881                            struct btrfs_root *root,
882                            u64 objectid, struct btrfs_key *location);
883 int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
884                            struct btrfs_root *root, struct btrfs_path *path,
885                            u64 objectid, int mod);
886 /* inode-item.c */
887 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
888                        *root, u64 objectid, struct btrfs_inode_item
889                        *inode_item);
890 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
891                        *root, struct btrfs_path *path, u64 objectid, int mod);
892
893 /* file-item.c */
894 int btrfs_alloc_file_extent(struct btrfs_trans_handle *trans,
895                                struct btrfs_root *root,
896                                u64 objectid, u64 offset,
897                                u64 num_blocks, u64 hint_block,
898                                u64 *result);
899 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
900                              struct btrfs_root *root,
901                              struct btrfs_path *path, u64 objectid,
902                              u64 blocknr, u64 num_blocks, int mod);
903 #endif