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