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