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