drop owner and parentid
[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_FIRST_FREE_OBJECTID 4ULL
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 /* 32 bytes in various csum fields */
23 #define BTRFS_CSUM_SIZE 32
24
25 /*
26  * the key defines the order in the tree, and so it also defines (optimal)
27  * block layout.  objectid corresonds to the inode number.  The flags
28  * tells us things about the object, and is a kind of stream selector.
29  * so for a given inode, keys with flags of 1 might refer to the inode
30  * data, flags of 2 may point to file data in the btree and flags == 3
31  * may point to extents.
32  *
33  * offset is the starting byte offset for this key in the stream.
34  *
35  * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
36  * in cpu native order.  Otherwise they are identical and their sizes
37  * should be the same (ie both packed)
38  */
39 struct btrfs_disk_key {
40         __le64 objectid;
41         __le64 offset;
42         __le32 flags;
43 } __attribute__ ((__packed__));
44
45 struct btrfs_key {
46         u64 objectid;
47         u64 offset;
48         u32 flags;
49 } __attribute__ ((__packed__));
50
51 /*
52  * every tree block (leaf or node) starts with this header.
53  */
54 struct btrfs_header {
55         u8 csum[BTRFS_CSUM_SIZE];
56         u8 fsid[16]; /* FS specific uuid */
57         __le64 blocknr; /* which block this node is supposed to live in */
58         __le64 generation;
59         __le16 nritems;
60         __le16 flags;
61         u8 level;
62 } __attribute__ ((__packed__));
63
64 #define BTRFS_MAX_LEVEL 8
65 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
66                                 sizeof(struct btrfs_header)) / \
67                                (sizeof(struct btrfs_disk_key) + sizeof(u64)))
68 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
69 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
70
71 struct btrfs_buffer;
72 /*
73  * the super block basically lists the main trees of the FS
74  * it currently lacks any block count etc etc
75  */
76 struct btrfs_super_block {
77         u8 csum[BTRFS_CSUM_SIZE];
78         /* the first 3 fields must match struct btrfs_header */
79         u8 fsid[16];    /* FS specific uuid */
80         __le64 blocknr; /* this block number */
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 btrfs_buffer *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 } __attribute__ ((__packed__));
146
147 struct btrfs_inode_timespec {
148         __le64 sec;
149         __le32 nsec;
150 } __attribute__ ((__packed__));
151
152 /*
153  * there is no padding here on purpose.  If you want to extent the inode,
154  * make a new item type
155  */
156 struct btrfs_inode_item {
157         __le64 generation;
158         __le64 size;
159         __le64 nblocks;
160         __le32 nlink;
161         __le32 uid;
162         __le32 gid;
163         __le32 mode;
164         __le32 rdev;
165         __le16 flags;
166         __le16 compat_flags;
167         struct btrfs_inode_timespec atime;
168         struct btrfs_inode_timespec ctime;
169         struct btrfs_inode_timespec mtime;
170         struct btrfs_inode_timespec otime;
171 } __attribute__ ((__packed__));
172
173 /* inline data is just a blob of bytes */
174 struct btrfs_inline_data_item {
175         u8 data;
176 } __attribute__ ((__packed__));
177
178 struct btrfs_dir_item {
179         struct btrfs_disk_key location;
180         __le16 flags;
181         __le16 name_len;
182         u8 type;
183 } __attribute__ ((__packed__));
184
185 struct btrfs_root_item {
186         struct btrfs_inode_item inode;
187         __le64 root_dirid;
188         __le64 blocknr;
189         __le32 flags;
190         __le64 block_limit;
191         __le64 blocks_used;
192         __le32 refs;
193 } __attribute__ ((__packed__));
194
195 struct btrfs_file_extent_item {
196         __le64 generation;
197         /*
198          * disk space consumed by the extent, checksum blocks are included
199          * in these numbers
200          */
201         __le64 disk_blocknr;
202         __le64 disk_num_blocks;
203         /*
204          * the logical offset in file blocks (no csums)
205          * this extent record is for.  This allows a file extent to point
206          * into the middle of an existing extent on disk, sharing it
207          * between two snapshots (useful if some bytes in the middle of the
208          * extent have changed
209          */
210         __le64 offset;
211         /*
212          * the logical number of file blocks (no csums included)
213          */
214         __le64 num_blocks;
215 } __attribute__ ((__packed__));
216
217 struct btrfs_csum_item {
218         u8 csum[BTRFS_CSUM_SIZE];
219 } __attribute__ ((__packed__));
220
221 struct btrfs_fs_info {
222         struct btrfs_root *fs_root;
223         struct btrfs_root *extent_root;
224         struct btrfs_root *tree_root;
225         struct btrfs_key current_insert;
226         struct btrfs_key last_insert;
227         struct radix_tree_root cache_radix;
228         struct radix_tree_root pinned_radix;
229         struct list_head trans;
230         struct list_head cache;
231         u64 last_inode_alloc;
232         u64 last_inode_alloc_dirid;
233         u64 generation;
234         int cache_size;
235         int fp;
236         struct btrfs_trans_handle *running_transaction;
237         struct btrfs_super_block *disk_super;
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 btrfs_buffer *node;
247         struct btrfs_buffer *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 #define BTRFS_KEY_OVERFLOW_MAX 128
261 #define BTRFS_KEY_OVERFLOW_SHIFT 8
262 #define BTRFS_KEY_OVERFLOW_MASK (0x7FULL << BTRFS_KEY_OVERFLOW_SHIFT)
263
264 /*
265  * inode items have the data typically returned from stat and store other
266  * info about object characteristics.  There is one for every file and dir in
267  * the FS
268  */
269 #define BTRFS_INODE_ITEM_KEY    1
270
271 /*
272  * dir items are the name -> inode pointers in a directory.  There is one
273  * for every name in a directory.
274  */
275 #define BTRFS_DIR_ITEM_KEY      2
276 #define BTRFS_DIR_INDEX_KEY     3
277 /*
278  * inline data is file data that fits in the btree.
279  */
280 #define BTRFS_INLINE_DATA_KEY   4
281 /*
282  * extent data is for data that can't fit in the btree.  It points to
283  * a (hopefully) huge chunk of disk
284  */
285 #define BTRFS_EXTENT_DATA_KEY   5
286 /*
287  * csum items have the checksums for data in the extents
288  */
289 #define BTRFS_CSUM_ITEM_KEY     6
290
291 /*
292  * root items point to tree roots.  There are typically in the root
293  * tree used by the super block to find all the other trees
294  */
295 #define BTRFS_ROOT_ITEM_KEY     7
296 /*
297  * extent items are in the extent map tree.  These record which blocks
298  * are used, and how many references there are to each block
299  */
300 #define BTRFS_EXTENT_ITEM_KEY   8
301
302 /*
303  * string items are for debugging.  They just store a short string of
304  * data in the FS
305  */
306 #define BTRFS_STRING_ITEM_KEY   9
307
308 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
309 {
310         return le64_to_cpu(i->generation);
311 }
312
313 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
314                                               u64 val)
315 {
316         i->generation = cpu_to_le64(val);
317 }
318
319 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
320 {
321         return le64_to_cpu(i->size);
322 }
323
324 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
325 {
326         i->size = cpu_to_le64(val);
327 }
328
329 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
330 {
331         return le64_to_cpu(i->nblocks);
332 }
333
334 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
335 {
336         i->nblocks = cpu_to_le64(val);
337 }
338
339 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
340 {
341         return le32_to_cpu(i->nlink);
342 }
343
344 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
345 {
346         i->nlink = cpu_to_le32(val);
347 }
348
349 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
350 {
351         return le32_to_cpu(i->uid);
352 }
353
354 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
355 {
356         i->uid = cpu_to_le32(val);
357 }
358
359 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
360 {
361         return le32_to_cpu(i->gid);
362 }
363
364 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
365 {
366         i->gid = cpu_to_le32(val);
367 }
368
369 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
370 {
371         return le32_to_cpu(i->mode);
372 }
373
374 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
375 {
376         i->mode = cpu_to_le32(val);
377 }
378
379 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
380 {
381         return le32_to_cpu(i->rdev);
382 }
383
384 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
385 {
386         i->rdev = cpu_to_le32(val);
387 }
388
389 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
390 {
391         return le16_to_cpu(i->flags);
392 }
393
394 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
395 {
396         i->flags = cpu_to_le16(val);
397 }
398
399 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
400 {
401         return le16_to_cpu(i->compat_flags);
402 }
403
404 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
405                                                 u16 val)
406 {
407         i->compat_flags = cpu_to_le16(val);
408 }
409
410 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
411 {
412         return le64_to_cpu(ts->sec);
413 }
414
415 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
416                                           u64 val)
417 {
418         ts->sec = cpu_to_le64(val);
419 }
420
421 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
422 {
423         return le32_to_cpu(ts->nsec);
424 }
425
426 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
427                                           u32 val)
428 {
429         ts->nsec = cpu_to_le32(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 u16 btrfs_dir_flags(struct btrfs_dir_item *d)
479 {
480         return le16_to_cpu(d->flags);
481 }
482
483 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
484 {
485         d->flags = cpu_to_le16(val);
486 }
487
488 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
489 {
490         return d->type;
491 }
492
493 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
494 {
495         d->type = val;
496 }
497
498 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
499 {
500         return le16_to_cpu(d->name_len);
501 }
502
503 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
504 {
505         d->name_len = cpu_to_le16(val);
506 }
507
508 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
509                                          struct btrfs_disk_key *disk)
510 {
511         cpu->offset = le64_to_cpu(disk->offset);
512         cpu->flags = le32_to_cpu(disk->flags);
513         cpu->objectid = le64_to_cpu(disk->objectid);
514 }
515
516 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
517                                          struct btrfs_key *cpu)
518 {
519         disk->offset = cpu_to_le64(cpu->offset);
520         disk->flags = cpu_to_le32(cpu->flags);
521         disk->objectid = cpu_to_le64(cpu->objectid);
522 }
523
524 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
525 {
526         return le64_to_cpu(disk->objectid);
527 }
528
529 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
530                                                u64 val)
531 {
532         disk->objectid = cpu_to_le64(val);
533 }
534
535 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
536 {
537         return le64_to_cpu(disk->offset);
538 }
539
540 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
541                                              u64 val)
542 {
543         disk->offset = cpu_to_le64(val);
544 }
545
546 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
547 {
548         return le32_to_cpu(disk->flags);
549 }
550
551 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
552                                             u32 val)
553 {
554         disk->flags = cpu_to_le32(val);
555 }
556
557 static inline u32 btrfs_key_overflow(struct btrfs_key *key)
558 {
559         u32 over = key->flags & BTRFS_KEY_OVERFLOW_MASK;
560         return over >> BTRFS_KEY_OVERFLOW_SHIFT;
561 }
562
563 static inline void btrfs_set_key_overflow(struct btrfs_key *key, u32 over)
564 {
565         BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
566         over = over << BTRFS_KEY_OVERFLOW_SHIFT;
567         key->flags = (key->flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
568 }
569
570 static inline u32 btrfs_key_type(struct btrfs_key *key)
571 {
572         return key->flags & BTRFS_KEY_TYPE_MASK;
573 }
574
575 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
576 {
577         return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK;
578 }
579
580 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type)
581 {
582         BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
583         key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
584 }
585
586 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
587 {
588         u32 flags = btrfs_disk_key_flags(key);
589         BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
590         flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
591         btrfs_set_disk_key_flags(key, flags);
592 }
593
594 static inline u32 btrfs_disk_key_overflow(struct btrfs_disk_key *key)
595 {
596         u32 over = le32_to_cpu(key->flags) & BTRFS_KEY_OVERFLOW_MASK;
597         return over >> BTRFS_KEY_OVERFLOW_SHIFT;
598 }
599
600 static inline void btrfs_set_disK_key_overflow(struct btrfs_disk_key *key,
601                                                u32 over)
602 {
603         u32 flags = btrfs_disk_key_flags(key);
604         BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
605         over = over << BTRFS_KEY_OVERFLOW_SHIFT;
606         flags = (flags & ~((u64)BTRFS_KEY_OVERFLOW_MASK)) | over;
607         btrfs_set_disk_key_flags(key, flags);
608 }
609
610 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
611 {
612         return le64_to_cpu(h->blocknr);
613 }
614
615 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
616 {
617         h->blocknr = cpu_to_le64(blocknr);
618 }
619
620 static inline u64 btrfs_header_generation(struct btrfs_header *h)
621 {
622         return le64_to_cpu(h->generation);
623 }
624
625 static inline void btrfs_set_header_generation(struct btrfs_header *h,
626                                                u64 val)
627 {
628         h->generation = cpu_to_le64(val);
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 u64 btrfs_root_dirid(struct btrfs_root_item *item)
678 {
679         return le64_to_cpu(item->root_dirid);
680 }
681
682 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
683 {
684         item->root_dirid = cpu_to_le64(val);
685 }
686
687 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
688 {
689         return le32_to_cpu(item->refs);
690 }
691
692 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
693 {
694         item->refs = cpu_to_le32(val);
695 }
696
697 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
698 {
699         return le64_to_cpu(s->blocknr);
700 }
701
702 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
703 {
704         s->blocknr = cpu_to_le64(val);
705 }
706
707 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
708 {
709         return le64_to_cpu(s->generation);
710 }
711
712 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
713                                               u64 val)
714 {
715         s->generation = cpu_to_le64(val);
716 }
717
718 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
719 {
720         return le64_to_cpu(s->root);
721 }
722
723 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
724 {
725         s->root = cpu_to_le64(val);
726 }
727
728 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
729 {
730         return le64_to_cpu(s->total_blocks);
731 }
732
733 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
734                                                 u64 val)
735 {
736         s->total_blocks = cpu_to_le64(val);
737 }
738
739 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
740 {
741         return le64_to_cpu(s->blocks_used);
742 }
743
744 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
745                                                 u64 val)
746 {
747         s->blocks_used = cpu_to_le64(val);
748 }
749
750 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
751 {
752         return le32_to_cpu(s->blocksize);
753 }
754
755 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
756                                                 u32 val)
757 {
758         s->blocksize = cpu_to_le32(val);
759 }
760
761 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
762 {
763         return le64_to_cpu(s->root_dir_objectid);
764 }
765
766 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
767                                             val)
768 {
769         s->root_dir_objectid = cpu_to_le64(val);
770 }
771
772 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
773 {
774         return (u8 *)l->items;
775 }
776
777 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
778                                                  *e)
779 {
780         return le64_to_cpu(e->disk_blocknr);
781 }
782
783 static inline void btrfs_set_file_extent_disk_blocknr(struct
784                                                       btrfs_file_extent_item
785                                                       *e, u64 val)
786 {
787         e->disk_blocknr = cpu_to_le64(val);
788 }
789
790 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
791 {
792         return le64_to_cpu(e->generation);
793 }
794
795 static inline void btrfs_set_file_extent_generation(struct
796                                                     btrfs_file_extent_item *e,
797                                                     u64 val)
798 {
799         e->generation = cpu_to_le64(val);
800 }
801
802 static inline u64 btrfs_file_extent_disk_num_blocks(struct
803                                                     btrfs_file_extent_item *e)
804 {
805         return le64_to_cpu(e->disk_num_blocks);
806 }
807
808 static inline void btrfs_set_file_extent_disk_num_blocks(struct
809                                                          btrfs_file_extent_item
810                                                          *e, u64 val)
811 {
812         e->disk_num_blocks = cpu_to_le64(val);
813 }
814
815 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
816 {
817         return le64_to_cpu(e->offset);
818 }
819
820 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
821                                                 *e, u64 val)
822 {
823         e->offset = cpu_to_le64(val);
824 }
825
826 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
827                                                *e)
828 {
829         return le64_to_cpu(e->num_blocks);
830 }
831
832 static inline void btrfs_set_file_extent_num_blocks(struct
833                                                     btrfs_file_extent_item *e,
834                                                     u64 val)
835 {
836         e->num_blocks = cpu_to_le64(val);
837 }
838
839 /* helper function to cast into the data area of the leaf. */
840 #define btrfs_item_ptr(leaf, slot, type) \
841         ((type *)(btrfs_leaf_data(leaf) + \
842         btrfs_item_offset((leaf)->items + (slot))))
843
844 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
845                                             struct btrfs_root *root);
846 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
847                   struct btrfs_buffer *buf);
848 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
849                       *root, u64 blocknr, u64 num_blocks, int pin);
850 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
851                       *root, struct btrfs_key *key, struct btrfs_path *p, int
852                       ins_len, int cow);
853 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
854 void btrfs_init_path(struct btrfs_path *p);
855 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
856                    struct btrfs_path *path);
857 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
858                       *root, struct btrfs_key *key, void *data, u32 data_size);
859 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
860                             *root, struct btrfs_path *path, struct btrfs_key
861                             *cpu_key, u32 data_size);
862 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
863 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
864 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
865                         *root, struct btrfs_buffer *snap);
866 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
867                                btrfs_root *root);
868 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
869                    struct btrfs_key *key);
870 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
871                       *root, struct btrfs_key *key, struct btrfs_root_item
872                       *item);
873 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
874                       *root, struct btrfs_key *key, struct btrfs_root_item
875                       *item);
876 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
877                          btrfs_root_item *item, struct btrfs_key *key);
878 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
879                           *root, char *name, int name_len, u64 dir,
880                           struct btrfs_key *location, u8 type);
881 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
882                           *root, struct btrfs_path *path, u64 dir, char *name,
883                           int name_len, int mod);
884 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
885                               char *name, int name_len);
886 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
887                              struct btrfs_root *fs_root,
888                              u64 dirid, u64 *objectid);
889 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
890                        *root, u64 objectid, struct btrfs_inode_item
891                        *inode_item);
892 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
893                        *root, struct btrfs_path *path, u64 objectid, int mod);
894 #endif