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