Add scan of the btrfs log tree to btrfs-debug-tree
[platform/upstream/btrfs-progs.git] / ctree.h
1 /*
2  * Copyright (C) 2007 Oracle.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License v2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public
14  * License along with this program; if not, write to the
15  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16  * Boston, MA 021110-1307, USA.
17  */
18
19 #ifndef __BTRFS__
20 #define __BTRFS__
21
22 #include "list.h"
23 #include "kerncompat.h"
24 #include "radix-tree.h"
25 #include "extent-cache.h"
26 #include "extent_io.h"
27
28 struct btrfs_root;
29 struct btrfs_trans_handle;
30 #define BTRFS_MAGIC "_BHRfS_M"
31
32 #define BTRFS_MAX_LEVEL 8
33
34 /* holds pointers to all of the tree roots */
35 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
36
37 /* stores information about which extents are in use, and reference counts */
38 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
39
40 /*
41  * chunk tree stores translations from logical -> physical block numbering
42  * the super block points to the chunk tree
43  */
44 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
45
46 /*
47  * stores information about which areas of a given device are in use.
48  * one per device.  The tree of tree roots points to the device tree
49  */
50 #define BTRFS_DEV_TREE_OBJECTID 4ULL
51
52 /* one per subvolume, storing files and directories */
53 #define BTRFS_FS_TREE_OBJECTID 5ULL
54
55 /* directory objectid inside the root tree */
56 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
57 /* holds checksums of all the data extents */
58 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
59
60
61 /* oprhan objectid for tracking unlinked/truncated files */
62 #define BTRFS_ORPHAN_OBJECTID -5ULL
63
64 /* does write ahead logging to speed up fsyncs */
65 #define BTRFS_TREE_LOG_OBJECTID -6ULL
66 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
67
68 /* space balancing */
69 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
70 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
71
72 /*
73  * extent checksums all have this objectid
74  * this allows them to share the logging tree
75  * for fsyncs
76  */
77 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
78
79 /* dummy objectid represents multiple objectids */
80 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
81
82 /*
83  * All files have objectids in this range.
84  */
85 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
86 #define BTRFS_LAST_FREE_OBJECTID -256ULL
87 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
88
89
90
91 /*
92  * the device items go into the chunk tree.  The key is in the form
93  * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
94  */
95 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
96
97 /*
98  * we can actually store much bigger names, but lets not confuse the rest
99  * of linux
100  */
101 #define BTRFS_NAME_LEN 255
102
103 /* 32 bytes in various csum fields */
104 #define BTRFS_CSUM_SIZE 32
105
106 /* csum types */
107 #define BTRFS_CSUM_TYPE_CRC32   0
108
109
110 /* csum types */
111 #define BTRFS_CSUM_TYPE_CRC32   0
112
113 static int btrfs_csum_sizes[] = { 4, 0 };
114
115 /* four bytes for CRC32 */
116 #define BTRFS_CRC32_SIZE 4
117 #define BTRFS_EMPTY_DIR_SIZE 0
118
119 #define BTRFS_FT_UNKNOWN        0
120 #define BTRFS_FT_REG_FILE       1
121 #define BTRFS_FT_DIR            2
122 #define BTRFS_FT_CHRDEV         3
123 #define BTRFS_FT_BLKDEV         4
124 #define BTRFS_FT_FIFO           5
125 #define BTRFS_FT_SOCK           6
126 #define BTRFS_FT_SYMLINK        7
127 #define BTRFS_FT_XATTR          8
128 #define BTRFS_FT_MAX            9
129
130 /*
131  * the key defines the order in the tree, and so it also defines (optimal)
132  * block layout.  objectid corresonds to the inode number.  The flags
133  * tells us things about the object, and is a kind of stream selector.
134  * so for a given inode, keys with flags of 1 might refer to the inode
135  * data, flags of 2 may point to file data in the btree and flags == 3
136  * may point to extents.
137  *
138  * offset is the starting byte offset for this key in the stream.
139  *
140  * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
141  * in cpu native order.  Otherwise they are identical and their sizes
142  * should be the same (ie both packed)
143  */
144 struct btrfs_disk_key {
145         __le64 objectid;
146         u8 type;
147         __le64 offset;
148 } __attribute__ ((__packed__));
149
150 struct btrfs_key {
151         u64 objectid;
152         u8 type;
153         u64 offset;
154 } __attribute__ ((__packed__));
155
156 struct btrfs_mapping_tree {
157         struct cache_tree cache_tree;
158 };
159
160 #define BTRFS_UUID_SIZE 16
161 struct btrfs_dev_item {
162         /* the internal btrfs device id */
163         __le64 devid;
164
165         /* size of the device */
166         __le64 total_bytes;
167
168         /* bytes used */
169         __le64 bytes_used;
170
171         /* optimal io alignment for this device */
172         __le32 io_align;
173
174         /* optimal io width for this device */
175         __le32 io_width;
176
177         /* minimal io size for this device */
178         __le32 sector_size;
179
180         /* type and info about this device */
181         __le64 type;
182
183         /* expected generation for this device */
184         __le64 generation;
185
186         /*
187          * starting byte of this partition on the device,
188          * to allowr for stripe alignment in the future
189          */
190         __le64 start_offset;
191
192         /* grouping information for allocation decisions */
193         __le32 dev_group;
194
195         /* seek speed 0-100 where 100 is fastest */
196         u8 seek_speed;
197
198         /* bandwidth 0-100 where 100 is fastest */
199         u8 bandwidth;
200
201         /* btrfs generated uuid for this device */
202         u8 uuid[BTRFS_UUID_SIZE];
203
204         /* uuid of FS who owns this device */
205         u8 fsid[BTRFS_UUID_SIZE];
206 } __attribute__ ((__packed__));
207
208 struct btrfs_stripe {
209         __le64 devid;
210         __le64 offset;
211         u8 dev_uuid[BTRFS_UUID_SIZE];
212 } __attribute__ ((__packed__));
213
214 struct btrfs_chunk {
215         /* size of this chunk in bytes */
216         __le64 length;
217
218         /* objectid of the root referencing this chunk */
219         __le64 owner;
220
221         __le64 stripe_len;
222         __le64 type;
223
224         /* optimal io alignment for this chunk */
225         __le32 io_align;
226
227         /* optimal io width for this chunk */
228         __le32 io_width;
229
230         /* minimal io size for this chunk */
231         __le32 sector_size;
232
233         /* 2^16 stripes is quite a lot, a second limit is the size of a single
234          * item in the btree
235          */
236         __le16 num_stripes;
237
238         /* sub stripes only matter for raid10 */
239         __le16 sub_stripes;
240         struct btrfs_stripe stripe;
241         /* additional stripes go here */
242 } __attribute__ ((__packed__));
243
244 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
245 {
246         BUG_ON(num_stripes == 0);
247         return sizeof(struct btrfs_chunk) +
248                 sizeof(struct btrfs_stripe) * (num_stripes - 1);
249 }
250
251 #define BTRFS_FSID_SIZE 16
252 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
253
254 /*
255  * every tree block (leaf or node) starts with this header.
256  */
257 struct btrfs_header {
258         /* these first four must match the super block */
259         u8 csum[BTRFS_CSUM_SIZE];
260         u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
261         __le64 bytenr; /* which block this node is supposed to live in */
262         __le64 flags;
263
264         /* allowed to be different from the super from here on down */
265         u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
266         __le64 generation;
267         __le64 owner;
268         __le32 nritems;
269         u8 level;
270 } __attribute__ ((__packed__));
271
272 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
273                                 sizeof(struct btrfs_header)) / \
274                                 sizeof(struct btrfs_key_ptr))
275 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
276 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
277 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
278                                         sizeof(struct btrfs_item) - \
279                                         sizeof(struct btrfs_file_extent_item))
280
281 #define BTRFS_SUPER_FLAG_SEEDING        (1ULL << 32)
282 #define BTRFS_SUPER_FLAG_METADUMP       (1ULL << 33)
283
284 /*
285  * this is a very generous portion of the super block, giving us
286  * room to translate 14 chunks with 3 stripes each.
287  */
288 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
289 #define BTRFS_LABEL_SIZE 256
290
291 /*
292  * the super block basically lists the main trees of the FS
293  * it currently lacks any block count etc etc
294  */
295 struct btrfs_super_block {
296         u8 csum[BTRFS_CSUM_SIZE];
297         /* the first 3 fields must match struct btrfs_header */
298         u8 fsid[BTRFS_FSID_SIZE];    /* FS specific uuid */
299         __le64 bytenr; /* this block number */
300         __le64 flags;
301
302         /* allowed to be different from the btrfs_header from here own down */
303         __le64 magic;
304         __le64 generation;
305         __le64 root;
306         __le64 chunk_root;
307         __le64 log_root;
308
309         /* this will help find the new super based on the log root */
310         __le64 log_root_transid;
311         __le64 total_bytes;
312         __le64 bytes_used;
313         __le64 root_dir_objectid;
314         __le64 num_devices;
315         __le32 sectorsize;
316         __le32 nodesize;
317         __le32 leafsize;
318         __le32 stripesize;
319         __le32 sys_chunk_array_size;
320         __le64 chunk_root_generation;
321         __le64 compat_flags;
322         __le64 compat_ro_flags;
323         __le64 incompat_flags;
324         __le16 csum_type;
325         u8 root_level;
326         u8 chunk_root_level;
327         u8 log_root_level;
328         struct btrfs_dev_item dev_item;
329
330         char label[BTRFS_LABEL_SIZE];
331
332         /* future expansion */
333         __le64 reserved[32];
334         u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
335 } __attribute__ ((__packed__));
336
337 /*
338  * Compat flags that we support.  If any incompat flags are set other than the
339  * ones specified below then we will fail to mount
340  */
341 #define BTRFS_FEATURE_COMPAT_SUPP       0x0
342 #define BTRFS_FEATURE_COMPAT_RO_SUPP    0x0
343 #define BTRFS_FEATURE_INCOMPAT_SUPP     0x0
344
345 /*
346  * A leaf is full of items. offset and size tell us where to find
347  * the item in the leaf (relative to the start of the data area)
348  */
349 struct btrfs_item {
350         struct btrfs_disk_key key;
351         __le32 offset;
352         __le32 size;
353 } __attribute__ ((__packed__));
354
355 /*
356  * leaves have an item area and a data area:
357  * [item0, item1....itemN] [free space] [dataN...data1, data0]
358  *
359  * The data is separate from the items to get the keys closer together
360  * during searches.
361  */
362 struct btrfs_leaf {
363         struct btrfs_header header;
364         struct btrfs_item items[];
365 } __attribute__ ((__packed__));
366
367 /*
368  * all non-leaf blocks are nodes, they hold only keys and pointers to
369  * other blocks
370  */
371 struct btrfs_key_ptr {
372         struct btrfs_disk_key key;
373         __le64 blockptr;
374         __le64 generation;
375 } __attribute__ ((__packed__));
376
377 struct btrfs_node {
378         struct btrfs_header header;
379         struct btrfs_key_ptr ptrs[];
380 } __attribute__ ((__packed__));
381
382 /*
383  * btrfs_paths remember the path taken from the root down to the leaf.
384  * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
385  * to any other levels that are present.
386  *
387  * The slots array records the index of the item or block pointer
388  * used while walking the tree.
389  */
390 struct btrfs_path {
391         struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
392         int slots[BTRFS_MAX_LEVEL];
393         int reada;
394         int lowest_level;
395
396         /*
397          * set by btrfs_split_item, tells search_slot to keep all locks
398          * and to force calls to keep space in the nodes
399          */
400         int search_for_split;
401 };
402
403 /*
404  * items in the extent btree are used to record the objectid of the
405  * owner of the block and the number of references
406  */
407 struct btrfs_extent_item {
408         __le32 refs;
409 } __attribute__ ((__packed__));
410
411 struct btrfs_extent_ref {
412         __le64 root;
413         __le64 generation;
414         __le64 objectid;
415         __le32 num_refs;
416 } __attribute__ ((__packed__));
417
418 /* dev extents record free space on individual devices.  The owner
419  * field points back to the chunk allocation mapping tree that allocated
420  * the extent.  The chunk tree uuid field is a way to double check the owner
421  */
422 struct btrfs_dev_extent {
423         __le64 chunk_tree;
424         __le64 chunk_objectid;
425         __le64 chunk_offset;
426         __le64 length;
427         u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
428 } __attribute__ ((__packed__));
429
430 struct btrfs_inode_ref {
431         __le64 index;
432         __le16 name_len;
433         /* name goes here */
434 } __attribute__ ((__packed__));
435
436 struct btrfs_timespec {
437         __le64 sec;
438         __le32 nsec;
439 } __attribute__ ((__packed__));
440
441 typedef enum {
442         BTRFS_COMPRESS_NONE = 0,
443         BTRFS_COMPRESS_ZLIB = 1,
444         BTRFS_COMPRESS_LAST = 2,
445 } btrfs_compression_type;
446
447 /* we don't understand any encryption methods right now */
448 typedef enum {
449         BTRFS_ENCRYPTION_NONE = 0,
450         BTRFS_ENCRYPTION_LAST = 1,
451 } btrfs_encryption_type;
452
453 struct btrfs_inode_item {
454         /* nfs style generation number */
455         __le64 generation;
456         /* transid that last touched this inode */
457         __le64 transid;
458         __le64 size;
459         __le64 nbytes;
460         __le64 block_group;
461         __le32 nlink;
462         __le32 uid;
463         __le32 gid;
464         __le32 mode;
465         __le64 rdev;
466         __le64 flags;
467
468         /* modification sequence number for NFS */
469         __le64 sequence;
470
471         /*
472          * a little future expansion, for more than this we can
473          * just grow the inode item and version it
474          */
475         __le64 reserved[4];
476         struct btrfs_timespec atime;
477         struct btrfs_timespec ctime;
478         struct btrfs_timespec mtime;
479         struct btrfs_timespec otime;
480 } __attribute__ ((__packed__));
481
482 struct btrfs_dir_log_item {
483         __le64 end;
484 } __attribute__ ((__packed__));
485
486 struct btrfs_dir_item {
487         struct btrfs_disk_key location;
488         __le64 transid;
489         __le16 data_len;
490         __le16 name_len;
491         u8 type;
492 } __attribute__ ((__packed__));
493
494 struct btrfs_root_item {
495         struct btrfs_inode_item inode;
496         __le64 generation;
497         __le64 root_dirid;
498         __le64 bytenr;
499         __le64 byte_limit;
500         __le64 bytes_used;
501         __le64 last_snapshot;
502         __le64 flags;
503         __le32 refs;
504         struct btrfs_disk_key drop_progress;
505         u8 drop_level;
506         u8 level;
507 } __attribute__ ((__packed__));
508
509 /*
510  * this is used for both forward and backward root refs
511  */
512 struct btrfs_root_ref {
513         __le64 dirid;
514         __le64 sequence;
515         __le16 name_len;
516 } __attribute__ ((__packed__));
517
518 #define BTRFS_FILE_EXTENT_INLINE 0
519 #define BTRFS_FILE_EXTENT_REG 1
520 #define BTRFS_FILE_EXTENT_PREALLOC 2
521
522 struct btrfs_file_extent_item {
523         /*
524          * transaction id that created this extent
525          */
526         __le64 generation;
527         /*
528          * max number of bytes to hold this extent in ram
529          * when we split a compressed extent we can't know how big
530          * each of the resulting pieces will be.  So, this is
531          * an upper limit on the size of the extent in ram instead of
532          * an exact limit.
533          */
534         __le64 ram_bytes;
535
536         /*
537          * 32 bits for the various ways we might encode the data,
538          * including compression and encryption.  If any of these
539          * are set to something a given disk format doesn't understand
540          * it is treated like an incompat flag for reading and writing,
541          * but not for stat.
542          */
543         u8 compression;
544         u8 encryption;
545         __le16 other_encoding; /* spare for later use */
546
547         /* are we inline data or a real extent? */
548         u8 type;
549
550         /*
551          * disk space consumed by the extent, checksum blocks are included
552          * in these numbers
553          */
554         __le64 disk_bytenr;
555         __le64 disk_num_bytes;
556         /*
557          * the logical offset in file blocks (no csums)
558          * this extent record is for.  This allows a file extent to point
559          * into the middle of an existing extent on disk, sharing it
560          * between two snapshots (useful if some bytes in the middle of the
561          * extent have changed
562          */
563         __le64 offset;
564         /*
565          * the logical number of file blocks (no csums included)
566          */
567         __le64 num_bytes;
568
569 } __attribute__ ((__packed__));
570
571 struct btrfs_csum_item {
572         u8 csum;
573 } __attribute__ ((__packed__));
574
575 /* tag for the radix tree of block groups in ram */
576 #define BTRFS_BLOCK_GROUP_DATA     (1 << 0)
577 #define BTRFS_BLOCK_GROUP_SYSTEM   (1 << 1)
578 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
579 #define BTRFS_BLOCK_GROUP_RAID0    (1 << 3)
580 #define BTRFS_BLOCK_GROUP_RAID1    (1 << 4)
581 #define BTRFS_BLOCK_GROUP_DUP      (1 << 5)
582 #define BTRFS_BLOCK_GROUP_RAID10   (1 << 6)
583
584 struct btrfs_block_group_item {
585         __le64 used;
586         __le64 chunk_objectid;
587         __le64 flags;
588 } __attribute__ ((__packed__));
589
590 struct btrfs_space_info {
591         u64 flags;
592         u64 total_bytes;
593         u64 bytes_used;
594         u64 bytes_pinned;
595         int full;
596         struct list_head list;
597 };
598
599 struct btrfs_block_group_cache {
600         struct cache_extent cache;
601         struct btrfs_key key;
602         struct btrfs_block_group_item item;
603         struct btrfs_space_info *space_info;
604         u64 pinned;
605         u64 flags;
606         int cached;
607         int ro;
608 };
609
610 struct btrfs_extent_ops {
611        int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
612                            u64 hint_byte, struct btrfs_key *ins);
613        int (*free_extent)(struct btrfs_root *root, u64 bytenr,
614                           u64 num_bytes);
615 };
616
617 struct btrfs_device;
618 struct btrfs_fs_devices;
619 struct btrfs_fs_info {
620         u8 fsid[BTRFS_FSID_SIZE];
621         u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
622         struct btrfs_root *fs_root;
623         struct btrfs_root *extent_root;
624         struct btrfs_root *tree_root;
625         struct btrfs_root *chunk_root;
626         struct btrfs_root *dev_root;
627         struct btrfs_root *csum_root;
628
629         /* the log root tree is a directory of all the other log roots */
630         struct btrfs_root *log_root_tree;
631
632         struct extent_io_tree extent_cache;
633         struct extent_io_tree free_space_cache;
634         struct extent_io_tree block_group_cache;
635         struct extent_io_tree pinned_extents;
636         struct extent_io_tree pending_del;
637         struct extent_io_tree extent_ins;
638
639         /* logical->physical extent mapping */
640         struct btrfs_mapping_tree mapping_tree;
641
642         u64 generation;
643         u64 last_trans_committed;
644
645         u64 avail_data_alloc_bits;
646         u64 avail_metadata_alloc_bits;
647         u64 avail_system_alloc_bits;
648         u64 data_alloc_profile;
649         u64 metadata_alloc_profile;
650         u64 system_alloc_profile;
651         u64 alloc_start;
652
653         struct btrfs_trans_handle *running_transaction;
654         struct btrfs_super_block super_copy;
655         struct mutex fs_mutex;
656
657         u64 super_bytenr;
658         u64 total_pinned;
659
660         struct btrfs_extent_ops *extent_ops;
661         struct list_head dirty_cowonly_roots;
662
663         struct btrfs_fs_devices *fs_devices;
664         struct list_head space_info;
665         int system_allocs;
666         int readonly;
667 };
668
669 /*
670  * in ram representation of the tree.  extent_root is used for all allocations
671  * and for the extent tree extent_root root.
672  */
673 struct btrfs_root {
674         struct extent_buffer *node;
675         struct extent_buffer *commit_root;
676         struct btrfs_root_item root_item;
677         struct btrfs_key root_key;
678         struct btrfs_fs_info *fs_info;
679         u64 objectid;
680         u64 last_trans;
681
682         /* data allocations are done in sectorsize units */
683         u32 sectorsize;
684
685         /* node allocations are done in nodesize units */
686         u32 nodesize;
687
688         /* leaf allocations are done in leafsize units */
689         u32 leafsize;
690
691         /* leaf allocations are done in leafsize units */
692         u32 stripesize;
693
694         int ref_cows;
695         int track_dirty;
696
697
698         u32 type;
699         u64 highest_inode;
700         u64 last_inode_alloc;
701
702         /* the dirty list is only used by non-reference counted roots */
703         struct list_head dirty_list;
704 };
705
706 /*
707  * inode items have the data typically returned from stat and store other
708  * info about object characteristics.  There is one for every file and dir in
709  * the FS
710  */
711 #define BTRFS_INODE_ITEM_KEY            1
712 #define BTRFS_INODE_REF_KEY             12
713 #define BTRFS_XATTR_ITEM_KEY            24
714 #define BTRFS_ORPHAN_ITEM_KEY           48
715
716 #define BTRFS_DIR_LOG_ITEM_KEY  60
717 #define BTRFS_DIR_LOG_INDEX_KEY 72
718 /*
719  * dir items are the name -> inode pointers in a directory.  There is one
720  * for every name in a directory.
721  */
722 #define BTRFS_DIR_ITEM_KEY      84
723 #define BTRFS_DIR_INDEX_KEY     96
724
725 /*
726  * extent data is for file data
727  */
728 #define BTRFS_EXTENT_DATA_KEY   108
729
730 /*
731  * csum items have the checksums for data in the extents
732  */
733 #define BTRFS_CSUM_ITEM_KEY     120
734 /*
735  * extent csums are stored in a separate tree and hold csums for
736  * an entire extent on disk.
737  */
738 #define BTRFS_EXTENT_CSUM_KEY   128
739
740 /*
741  * root items point to tree roots.  There are typically in the root
742  * tree used by the super block to find all the other trees
743  */
744 #define BTRFS_ROOT_ITEM_KEY     132
745
746 /*
747  * root backrefs tie subvols and snapshots to the directory entries that
748  * reference them
749  */
750 #define BTRFS_ROOT_BACKREF_KEY  144
751
752 /*
753  * root refs make a fast index for listing all of the snapshots and
754  * subvolumes referenced by a given root.  They point directly to the
755  * directory item in the root that references the subvol
756  */
757 #define BTRFS_ROOT_REF_KEY      156
758
759 /*
760  * extent items are in the extent map tree.  These record which blocks
761  * are used, and how many references there are to each block
762  */
763 #define BTRFS_EXTENT_ITEM_KEY   168
764 #define BTRFS_EXTENT_REF_KEY    180
765
766 /*
767  * block groups give us hints into the extent allocation trees.  Which
768  * blocks are free etc etc
769  */
770 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
771
772 #define BTRFS_DEV_EXTENT_KEY    204
773 #define BTRFS_DEV_ITEM_KEY      216
774 #define BTRFS_CHUNK_ITEM_KEY    228
775
776 /*
777  * string items are for debugging.  They just store a short string of
778  * data in the FS
779  */
780 #define BTRFS_STRING_ITEM_KEY   253
781 /*
782  * Inode flags
783  */
784 #define BTRFS_INODE_NODATASUM           (1 << 0)
785 #define BTRFS_INODE_NODATACOW           (1 << 1)
786 #define BTRFS_INODE_READONLY            (1 << 2)
787
788 #define read_eb_member(eb, ptr, type, member, result) (                 \
789         read_extent_buffer(eb, (char *)(result),                        \
790                            ((unsigned long)(ptr)) +                     \
791                             offsetof(type, member),                     \
792                            sizeof(((type *)0)->member)))
793
794 #define write_eb_member(eb, ptr, type, member, result) (                \
795         write_extent_buffer(eb, (char *)(result),                       \
796                            ((unsigned long)(ptr)) +                     \
797                             offsetof(type, member),                     \
798                            sizeof(((type *)0)->member)))
799
800 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits)             \
801 static inline u##bits btrfs_##name(struct extent_buffer *eb)            \
802 {                                                                       \
803         struct btrfs_header *h = (struct btrfs_header *)eb->data;       \
804         return le##bits##_to_cpu(h->member);                            \
805 }                                                                       \
806 static inline void btrfs_set_##name(struct extent_buffer *eb,           \
807                                     u##bits val)                        \
808 {                                                                       \
809         struct btrfs_header *h = (struct btrfs_header *)eb->data;       \
810         h->member = cpu_to_le##bits(val);                               \
811 }
812
813 #define BTRFS_SETGET_FUNCS(name, type, member, bits)                    \
814 static inline u##bits btrfs_##name(struct extent_buffer *eb,            \
815                                    type *s)                             \
816 {                                                                       \
817         unsigned long offset = (unsigned long)s;                        \
818         type *p = (type *) (eb->data + offset);                         \
819         return le##bits##_to_cpu(p->member);                            \
820 }                                                                       \
821 static inline void btrfs_set_##name(struct extent_buffer *eb,           \
822                                     type *s, u##bits val)               \
823 {                                                                       \
824         unsigned long offset = (unsigned long)s;                        \
825         type *p = (type *) (eb->data + offset);                         \
826         p->member = cpu_to_le##bits(val);                               \
827 }
828
829 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits)              \
830 static inline u##bits btrfs_##name(type *s)                             \
831 {                                                                       \
832         return le##bits##_to_cpu(s->member);                            \
833 }                                                                       \
834 static inline void btrfs_set_##name(type *s, u##bits val)               \
835 {                                                                       \
836         s->member = cpu_to_le##bits(val);                               \
837 }
838
839 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
840 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
841 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
842 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
843 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
844 BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
845                    start_offset, 64);
846 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
847 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
848 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
849 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
850 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
851 BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
852
853 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
854 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
855                          total_bytes, 64);
856 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
857                          bytes_used, 64);
858 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
859                          io_align, 32);
860 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
861                          io_width, 32);
862 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
863                          sector_size, 32);
864 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
865 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
866                          dev_group, 32);
867 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
868                          seek_speed, 8);
869 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
870                          bandwidth, 8);
871 BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
872                          generation, 64);
873
874 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
875 {
876         return (char *)d + offsetof(struct btrfs_dev_item, uuid);
877 }
878
879 static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
880 {
881         return (char *)d + offsetof(struct btrfs_dev_item, fsid);
882 }
883
884 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
885 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
886 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
887 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
888 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
889 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
890 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
891 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
892 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
893 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
894 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
895
896 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
897 {
898         return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
899 }
900
901 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
902 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
903 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
904                          stripe_len, 64);
905 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
906                          io_align, 32);
907 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
908                          io_width, 32);
909 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
910                          sector_size, 32);
911 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
912 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
913                          num_stripes, 16);
914 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
915                          sub_stripes, 16);
916 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
917 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
918
919 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
920                                                    int nr)
921 {
922         unsigned long offset = (unsigned long)c;
923         offset += offsetof(struct btrfs_chunk, stripe);
924         offset += nr * sizeof(struct btrfs_stripe);
925         return (struct btrfs_stripe *)offset;
926 }
927
928 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
929 {
930         return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
931 }
932
933 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
934                                          struct btrfs_chunk *c, int nr)
935 {
936         return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
937 }
938
939 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
940                                              struct btrfs_chunk *c, int nr,
941                                              u64 val)
942 {
943         btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
944 }
945
946 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
947                                          struct btrfs_chunk *c, int nr)
948 {
949         return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
950 }
951
952 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
953                                              struct btrfs_chunk *c, int nr,
954                                              u64 val)
955 {
956         btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
957 }
958
959 /* struct btrfs_block_group_item */
960 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
961                          used, 64);
962 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
963                          used, 64);
964 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
965                         struct btrfs_block_group_item, chunk_objectid, 64);
966
967 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
968                    struct btrfs_block_group_item, chunk_objectid, 64);
969 BTRFS_SETGET_FUNCS(disk_block_group_flags,
970                    struct btrfs_block_group_item, flags, 64);
971 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
972                         struct btrfs_block_group_item, flags, 64);
973
974 /* struct btrfs_inode_ref */
975 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
976 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
977
978 /* struct btrfs_inode_item */
979 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
980 BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
981 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
982 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
983 BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
984 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
985 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
986 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
987 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
988 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
989 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
990 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
991
992 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
993                          struct btrfs_inode_item, generation, 64);
994 BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence,
995                          struct btrfs_inode_item, generation, 64);
996 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
997                          struct btrfs_inode_item, size, 64);
998 BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes,
999                          struct btrfs_inode_item, nbytes, 64);
1000 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
1001                          struct btrfs_inode_item, block_group, 64);
1002 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
1003                          struct btrfs_inode_item, nlink, 32);
1004 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
1005                          struct btrfs_inode_item, uid, 32);
1006 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
1007                          struct btrfs_inode_item, gid, 32);
1008 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
1009                          struct btrfs_inode_item, mode, 32);
1010 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
1011                          struct btrfs_inode_item, rdev, 64);
1012 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
1013                          struct btrfs_inode_item, flags, 64);
1014
1015 static inline struct btrfs_timespec *
1016 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
1017 {
1018         unsigned long ptr = (unsigned long)inode_item;
1019         ptr += offsetof(struct btrfs_inode_item, atime);
1020         return (struct btrfs_timespec *)ptr;
1021 }
1022
1023 static inline struct btrfs_timespec *
1024 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
1025 {
1026         unsigned long ptr = (unsigned long)inode_item;
1027         ptr += offsetof(struct btrfs_inode_item, mtime);
1028         return (struct btrfs_timespec *)ptr;
1029 }
1030
1031 static inline struct btrfs_timespec *
1032 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
1033 {
1034         unsigned long ptr = (unsigned long)inode_item;
1035         ptr += offsetof(struct btrfs_inode_item, ctime);
1036         return (struct btrfs_timespec *)ptr;
1037 }
1038
1039 static inline struct btrfs_timespec *
1040 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
1041 {
1042         unsigned long ptr = (unsigned long)inode_item;
1043         ptr += offsetof(struct btrfs_inode_item, otime);
1044         return (struct btrfs_timespec *)ptr;
1045 }
1046
1047 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
1048 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
1049 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
1050                          sec, 64);
1051 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
1052                          nsec, 32);
1053
1054 /* struct btrfs_dev_extent */
1055 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
1056                    chunk_tree, 64);
1057 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
1058                    chunk_objectid, 64);
1059 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
1060                    chunk_offset, 64);
1061 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
1062
1063 static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
1064 {
1065         unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
1066         return (u8 *)((unsigned long)dev + ptr);
1067 }
1068
1069 /* struct btrfs_extent_ref */
1070 BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
1071 BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
1072 BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
1073 BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
1074
1075 BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
1076 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
1077                          generation, 64);
1078 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
1079                          objectid, 64);
1080 BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
1081                          num_refs, 32);
1082
1083 /* struct btrfs_extent_item */
1084 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
1085 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
1086                          refs, 32);
1087
1088 /* struct btrfs_node */
1089 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
1090 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
1091
1092 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
1093 {
1094         unsigned long ptr;
1095         ptr = offsetof(struct btrfs_node, ptrs) +
1096                 sizeof(struct btrfs_key_ptr) * nr;
1097         return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
1098 }
1099
1100 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
1101                                            int nr, u64 val)
1102 {
1103         unsigned long ptr;
1104         ptr = offsetof(struct btrfs_node, ptrs) +
1105                 sizeof(struct btrfs_key_ptr) * nr;
1106         btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
1107 }
1108
1109 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
1110 {
1111         unsigned long ptr;
1112         ptr = offsetof(struct btrfs_node, ptrs) +
1113                 sizeof(struct btrfs_key_ptr) * nr;
1114         return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
1115 }
1116
1117 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
1118                                                  int nr, u64 val)
1119 {
1120         unsigned long ptr;
1121         ptr = offsetof(struct btrfs_node, ptrs) +
1122                 sizeof(struct btrfs_key_ptr) * nr;
1123         btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
1124 }
1125
1126 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
1127 {
1128         return offsetof(struct btrfs_node, ptrs) +
1129                 sizeof(struct btrfs_key_ptr) * nr;
1130 }
1131
1132 static inline void btrfs_node_key(struct extent_buffer *eb,
1133                                   struct btrfs_disk_key *disk_key, int nr)
1134 {
1135         unsigned long ptr;
1136         ptr = btrfs_node_key_ptr_offset(nr);
1137         read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1138                        struct btrfs_key_ptr, key, disk_key);
1139 }
1140
1141 static inline void btrfs_set_node_key(struct extent_buffer *eb,
1142                                       struct btrfs_disk_key *disk_key, int nr)
1143 {
1144         unsigned long ptr;
1145         ptr = btrfs_node_key_ptr_offset(nr);
1146         write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1147                        struct btrfs_key_ptr, key, disk_key);
1148 }
1149
1150 /* struct btrfs_item */
1151 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
1152 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
1153
1154 static inline unsigned long btrfs_item_nr_offset(int nr)
1155 {
1156         return offsetof(struct btrfs_leaf, items) +
1157                 sizeof(struct btrfs_item) * nr;
1158 }
1159
1160 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
1161                                                int nr)
1162 {
1163         return (struct btrfs_item *)btrfs_item_nr_offset(nr);
1164 }
1165
1166 static inline u32 btrfs_item_end(struct extent_buffer *eb,
1167                                  struct btrfs_item *item)
1168 {
1169         return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
1170 }
1171
1172 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
1173 {
1174         return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
1175 }
1176
1177 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
1178 {
1179         return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
1180 }
1181
1182 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
1183 {
1184         return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
1185 }
1186
1187 static inline void btrfs_item_key(struct extent_buffer *eb,
1188                            struct btrfs_disk_key *disk_key, int nr)
1189 {
1190         struct btrfs_item *item = btrfs_item_nr(eb, nr);
1191         read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1192 }
1193
1194 static inline void btrfs_set_item_key(struct extent_buffer *eb,
1195                                struct btrfs_disk_key *disk_key, int nr)
1196 {
1197         struct btrfs_item *item = btrfs_item_nr(eb, nr);
1198         write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1199 }
1200
1201 BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
1202
1203 /*
1204  * struct btrfs_root_ref
1205  */
1206 BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
1207 BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
1208 BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
1209
1210 /* struct btrfs_dir_item */
1211 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1212 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1213 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1214 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1215
1216 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1217                                       struct btrfs_dir_item *item,
1218                                       struct btrfs_disk_key *key)
1219 {
1220         read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1221 }
1222
1223 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1224                                           struct btrfs_dir_item *item,
1225                                           struct btrfs_disk_key *key)
1226 {
1227         write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1228 }
1229
1230 /* struct btrfs_disk_key */
1231 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1232                          objectid, 64);
1233 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1234 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1235
1236 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1237                                          struct btrfs_disk_key *disk)
1238 {
1239         cpu->offset = le64_to_cpu(disk->offset);
1240         cpu->type = disk->type;
1241         cpu->objectid = le64_to_cpu(disk->objectid);
1242 }
1243
1244 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
1245                                          struct btrfs_key *cpu)
1246 {
1247         disk->offset = cpu_to_le64(cpu->offset);
1248         disk->type = cpu->type;
1249         disk->objectid = cpu_to_le64(cpu->objectid);
1250 }
1251
1252 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1253                                   struct btrfs_key *key, int nr)
1254 {
1255         struct btrfs_disk_key disk_key;
1256         btrfs_node_key(eb, &disk_key, nr);
1257         btrfs_disk_key_to_cpu(key, &disk_key);
1258 }
1259
1260 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1261                                   struct btrfs_key *key, int nr)
1262 {
1263         struct btrfs_disk_key disk_key;
1264         btrfs_item_key(eb, &disk_key, nr);
1265         btrfs_disk_key_to_cpu(key, &disk_key);
1266 }
1267
1268 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1269                                       struct btrfs_dir_item *item,
1270                                       struct btrfs_key *key)
1271 {
1272         struct btrfs_disk_key disk_key;
1273         btrfs_dir_item_key(eb, item, &disk_key);
1274         btrfs_disk_key_to_cpu(key, &disk_key);
1275 }
1276
1277
1278 static inline u8 btrfs_key_type(struct btrfs_key *key)
1279 {
1280         return key->type;
1281 }
1282
1283 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1284 {
1285         key->type = val;
1286 }
1287
1288 /* struct btrfs_header */
1289 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1290 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1291                           generation, 64);
1292 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1293 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1294 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1295 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1296
1297 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1298 {
1299         return (btrfs_header_flags(eb) & flag) == flag;
1300 }
1301
1302 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1303 {
1304         u64 flags = btrfs_header_flags(eb);
1305         btrfs_set_header_flags(eb, flags | flag);
1306         return (flags & flag) == flag;
1307 }
1308
1309 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1310 {
1311         u64 flags = btrfs_header_flags(eb);
1312         btrfs_set_header_flags(eb, flags & ~flag);
1313         return (flags & flag) == flag;
1314 }
1315
1316 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1317 {
1318         unsigned long ptr = offsetof(struct btrfs_header, fsid);
1319         return (u8 *)ptr;
1320 }
1321
1322 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1323 {
1324         unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1325         return (u8 *)ptr;
1326 }
1327
1328 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1329 {
1330         unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1331         return (u8 *)ptr;
1332 }
1333
1334 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1335 {
1336         unsigned long ptr = offsetof(struct btrfs_header, csum);
1337         return (u8 *)ptr;
1338 }
1339
1340 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1341 {
1342         return NULL;
1343 }
1344
1345 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1346 {
1347         return NULL;
1348 }
1349
1350 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1351 {
1352         return NULL;
1353 }
1354
1355 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1356 {
1357         return (btrfs_header_level(eb) == 0);
1358 }
1359
1360 /* struct btrfs_root_item */
1361 BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
1362                    generation, 64);
1363 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1364 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1365 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1366
1367 BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
1368                          generation, 64);
1369 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1370 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1371 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1372 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1373 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
1374 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1375 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1376 BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
1377                          last_snapshot, 64);
1378
1379
1380 /* struct btrfs_super_block */
1381
1382 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1383 BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
1384 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1385                          generation, 64);
1386 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1387 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1388                          struct btrfs_super_block, sys_chunk_array_size, 32);
1389 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
1390                          struct btrfs_super_block, chunk_root_generation, 64);
1391 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1392                          root_level, 8);
1393 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1394                          chunk_root, 64);
1395 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1396                          chunk_root_level, 8);
1397 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
1398                          log_root, 64);
1399 BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
1400                          log_root_transid, 64);
1401 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
1402                          log_root_level, 8);
1403 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1404                          total_bytes, 64);
1405 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1406                          bytes_used, 64);
1407 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1408                          sectorsize, 32);
1409 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1410                          nodesize, 32);
1411 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1412                          leafsize, 32);
1413 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1414                          stripesize, 32);
1415 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1416                          root_dir_objectid, 64);
1417 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1418                          num_devices, 64);
1419 BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
1420                          compat_flags, 64);
1421 BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
1422                          compat_flags, 64);
1423 BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
1424                          incompat_flags, 64);
1425 BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
1426                          csum_type, 16);
1427
1428 static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
1429 {
1430         int t = btrfs_super_csum_type(s);
1431         BUG_ON(t >= ARRAY_SIZE(btrfs_csum_sizes));
1432         return btrfs_csum_sizes[t];
1433 }
1434
1435 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1436 {
1437         return offsetof(struct btrfs_leaf, items);
1438 }
1439
1440 /* struct btrfs_file_extent_item */
1441 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1442
1443 static inline unsigned long btrfs_file_extent_inline_start(struct
1444                                                    btrfs_file_extent_item *e)
1445 {
1446         unsigned long offset = (unsigned long)e;
1447         offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1448         return offset;
1449 }
1450
1451 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1452 {
1453         return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1454 }
1455
1456 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1457                    disk_bytenr, 64);
1458 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1459                    generation, 64);
1460 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1461                    disk_num_bytes, 64);
1462 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1463                   offset, 64);
1464 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1465                    num_bytes, 64);
1466 BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
1467                    ram_bytes, 64);
1468 BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
1469                    compression, 8);
1470 BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
1471                    encryption, 8);
1472 BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
1473                    other_encoding, 16);
1474
1475 /* this returns the number of file bytes represented by the inline item.
1476  * If an item is compressed, this is the uncompressed size
1477  */
1478 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1479                                         struct btrfs_file_extent_item *e)
1480 {
1481        return btrfs_file_extent_ram_bytes(eb, e);
1482 }
1483
1484 /*
1485  * this returns the number of bytes used by the item on disk, minus the
1486  * size of any extent headers.  If a file is compressed on disk, this is
1487  * the compressed size
1488  */
1489 static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
1490                                                     struct btrfs_item *e)
1491 {
1492        unsigned long offset;
1493        offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
1494        return btrfs_item_size(eb, e) - offset;
1495 }
1496
1497 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1498         if (level == 0)
1499                 return root->leafsize;
1500         return root->nodesize;
1501 }
1502
1503 /* helper function to cast into the data area of the leaf. */
1504 #define btrfs_item_ptr(leaf, slot, type) \
1505         ((type *)(btrfs_leaf_data(leaf) + \
1506         btrfs_item_offset_nr(leaf, slot)))
1507
1508 #define btrfs_item_ptr_offset(leaf, slot) \
1509         ((unsigned long)(btrfs_leaf_data(leaf) + \
1510         btrfs_item_offset_nr(leaf, slot)))
1511
1512 /* extent-tree.c */
1513 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1514                          struct btrfs_root *root);
1515 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
1516 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1517                                                          btrfs_fs_info *info,
1518                                                          u64 bytenr);
1519 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1520                                                  struct btrfs_block_group_cache
1521                                                  *hint, u64 search_start,
1522                                                  int data, int owner);
1523 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1524                                              struct btrfs_root *root,
1525                                              u32 blocksize, u64 parent,
1526                                              u64 root_objectid,
1527                                              u64 ref_generation,
1528                                              int level,
1529                                              u64 hint,
1530                                              u64 empty_size);
1531 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1532                        struct btrfs_root *root,
1533                        u64 num_bytes, u64 parent,
1534                        u64 root_objectid, u64 ref_generation,
1535                        u64 owner, u64 empty_size, u64 hint_byte,
1536                        u64 search_end, struct btrfs_key *ins, int data);
1537 int btrfs_lookup_extent_ref(struct btrfs_trans_handle *trans,
1538                             struct btrfs_root *root, u64 bytenr,
1539                             u64 num_bytes, u32 *refs);
1540 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1541                   struct extent_buffer *orig_buf, struct extent_buffer *buf,
1542                   u32 *nr_extents);
1543 int btrfs_update_ref(struct btrfs_trans_handle *trans,
1544                      struct btrfs_root *root, struct extent_buffer *orig_buf,
1545                      struct extent_buffer *buf, int start_slot, int nr);
1546 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1547                       *root, u64 bytenr, u64 num_bytes, u64 parent,
1548                       u64 root_objectid, u64 ref_generation,
1549                       u64 owner_objectid, int pin);
1550 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1551                                struct btrfs_root *root,
1552                                struct extent_io_tree *unpin);
1553 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1554                                 struct btrfs_root *root,
1555                                 u64 bytenr, u64 num_bytes, u64 parent,
1556                                 u64 root_objectid, u64 ref_generation,
1557                                 u64 owner_objectid);
1558 int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
1559                             struct btrfs_root *root, u64 bytenr,
1560                             u64 orig_parent, u64 parent,
1561                             u64 root_objectid, u64 ref_generation,
1562                             u64 owner_objectid);
1563 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1564                                     struct btrfs_root *root);
1565 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1566 int btrfs_read_block_groups(struct btrfs_root *root);
1567 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1568                            struct btrfs_root *root, u64 bytes_used,
1569                            u64 type, u64 chunk_objectid, u64 chunk_offset,
1570                            u64 size);
1571 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
1572                             struct btrfs_root *root);
1573 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
1574                              struct btrfs_root *root, u64 bytenr, u64 num,
1575                              int alloc, int mark_free);
1576 /* ctree.c */
1577 int btrfs_previous_item(struct btrfs_root *root,
1578                         struct btrfs_path *path, u64 min_objectid,
1579                         int type);
1580 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1581 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1582                     struct btrfs_root *root, struct extent_buffer *buf,
1583                     struct extent_buffer *parent, int parent_slot,
1584                     struct extent_buffer **cow_ret);
1585 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
1586                              struct btrfs_root *root,
1587                              struct extent_buffer *buf,
1588                              struct extent_buffer *parent, int parent_slot,
1589                              struct extent_buffer **cow_ret,
1590                              u64 search_start, u64 empty_size);
1591 int btrfs_copy_root(struct btrfs_trans_handle *trans,
1592                       struct btrfs_root *root,
1593                       struct extent_buffer *buf,
1594                       struct extent_buffer **cow_ret, u64 new_root_objectid);
1595 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1596                       *root, struct btrfs_path *path, u32 data_size);
1597 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1598                         struct btrfs_root *root,
1599                         struct btrfs_path *path,
1600                         u32 new_size, int from_end);
1601 int btrfs_split_item(struct btrfs_trans_handle *trans,
1602                      struct btrfs_root *root,
1603                      struct btrfs_path *path,
1604                      struct btrfs_key *new_key,
1605                      unsigned long split_offset);
1606 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1607                       *root, struct btrfs_key *key, struct btrfs_path *p, int
1608                       ins_len, int cow);
1609 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1610                        struct btrfs_root *root, struct extent_buffer *parent,
1611                        int start_slot, int cache_only, u64 *last_ret,
1612                        struct btrfs_key *progress);
1613 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1614 struct btrfs_path *btrfs_alloc_path(void);
1615 void btrfs_free_path(struct btrfs_path *p);
1616 void btrfs_init_path(struct btrfs_path *p);
1617 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1618                    struct btrfs_path *path, int slot, int nr);
1619
1620 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1621                                  struct btrfs_root *root,
1622                                  struct btrfs_path *path)
1623 {
1624         return btrfs_del_items(trans, root, path, path->slots[0], 1);
1625 }
1626
1627 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1628                       *root, struct btrfs_key *key, void *data, u32 data_size);
1629 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1630                              struct btrfs_root *root,
1631                              struct btrfs_path *path,
1632                              struct btrfs_key *cpu_key, u32 *data_size, int nr);
1633
1634 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1635                                           struct btrfs_root *root,
1636                                           struct btrfs_path *path,
1637                                           struct btrfs_key *key,
1638                                           u32 data_size)
1639 {
1640         return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1641 }
1642
1643 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1644 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
1645 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1646 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1647                         *root);
1648 int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
1649                             struct btrfs_root *root, struct btrfs_path *path,
1650                             struct btrfs_key *new_key);
1651
1652 /* root-item.c */
1653 int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
1654                        struct btrfs_root *tree_root,
1655                        u64 root_id, u8 type, u64 ref_id,
1656                        u64 dirid, u64 sequence,
1657                        const char *name, int name_len);
1658 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1659                    struct btrfs_key *key);
1660 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1661                       *root, struct btrfs_key *key, struct btrfs_root_item
1662                       *item);
1663 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1664                       *root, struct btrfs_key *key, struct btrfs_root_item
1665                       *item);
1666 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1667                          btrfs_root_item *item, struct btrfs_key *key);
1668 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1669                           struct btrfs_root *latest_root);
1670 /* dir-item.c */
1671 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1672                           *root, const char *name, int name_len, u64 dir,
1673                           struct btrfs_key *location, u8 type, u64 index);
1674 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1675                                              struct btrfs_root *root,
1676                                              struct btrfs_path *path, u64 dir,
1677                                              const char *name, int name_len,
1678                                              int mod);
1679 struct btrfs_dir_item *
1680 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1681                             struct btrfs_root *root,
1682                             struct btrfs_path *path, u64 dir,
1683                             u64 objectid, const char *name, int name_len,
1684                             int mod);
1685 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1686                               struct btrfs_path *path,
1687                               const char *name, int name_len);
1688 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1689                               struct btrfs_root *root,
1690                               struct btrfs_path *path,
1691                               struct btrfs_dir_item *di);
1692 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1693                             struct btrfs_root *root, const char *name,
1694                             u16 name_len, const void *data, u16 data_len,
1695                             u64 dir);
1696 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1697                                           struct btrfs_root *root,
1698                                           struct btrfs_path *path, u64 dir,
1699                                           const char *name, u16 name_len,
1700                                           int mod);
1701 /* inode-map.c */
1702 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1703                              struct btrfs_root *fs_root,
1704                              u64 dirid, u64 *objectid);
1705 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1706
1707 /* inode-item.c */
1708 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1709                            struct btrfs_root *root,
1710                            const char *name, int name_len,
1711                            u64 inode_objectid, u64 ref_objectid, u64 index);
1712 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1713                            struct btrfs_root *root,
1714                            const char *name, int name_len,
1715                            u64 inode_objectid, u64 ref_objectid);
1716 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1717                              struct btrfs_root *root,
1718                              struct btrfs_path *path, u64 objectid);
1719 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1720                        *root, u64 objectid, struct btrfs_inode_item
1721                        *inode_item);
1722 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1723                        *root, struct btrfs_path *path,
1724                        struct btrfs_key *location, int mod);
1725
1726 /* file-item.c */
1727 int btrfs_del_csums(struct btrfs_trans_handle *trans,
1728                     struct btrfs_root *root, u64 bytenr, u64 len);
1729 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1730                              struct btrfs_root *root,
1731                              u64 objectid, u64 pos, u64 offset,
1732                              u64 disk_num_bytes,
1733                              u64 num_bytes);
1734 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
1735                                 struct btrfs_root *root, u64 objectid,
1736                                 u64 offset, char *buffer, size_t size);
1737 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1738                              struct btrfs_root *root,
1739                              struct btrfs_path *path, u64 objectid,
1740                              u64 bytenr, int mod);
1741 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1742                           struct btrfs_root *root, u64 alloc_end,
1743                           u64 bytenr, char *data, size_t len);
1744 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1745                                           struct btrfs_root *root,
1746                                           struct btrfs_path *path,
1747                                           u64 bytenr, int cow);
1748 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1749                         struct btrfs_root *root, struct btrfs_path *path,
1750                         u64 isize);
1751 #endif