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