2 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
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.
23 #include "kerncompat.h"
24 #include "radix-tree.h"
25 #include "extent-cache.h"
26 #include "extent_io.h"
30 struct btrfs_trans_handle;
31 #define BTRFS_MAGIC "_BHRfS_M"
33 #define BTRFS_MAX_LEVEL 8
35 #define BTRFS_COMPAT_EXTENT_TREE_V0
37 /* holds pointers to all of the tree roots */
38 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
40 /* stores information about which extents are in use, and reference counts */
41 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
44 * chunk tree stores translations from logical -> physical block numbering
45 * the super block points to the chunk tree
47 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
50 * stores information about which areas of a given device are in use.
51 * one per device. The tree of tree roots points to the device tree
53 #define BTRFS_DEV_TREE_OBJECTID 4ULL
55 /* one per subvolume, storing files and directories */
56 #define BTRFS_FS_TREE_OBJECTID 5ULL
58 /* directory objectid inside the root tree */
59 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
60 /* holds checksums of all the data extents */
61 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
62 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
65 /* for storing balance parameters in the root tree */
66 #define BTRFS_BALANCE_OBJECTID -4ULL
68 /* oprhan objectid for tracking unlinked/truncated files */
69 #define BTRFS_ORPHAN_OBJECTID -5ULL
71 /* does write ahead logging to speed up fsyncs */
72 #define BTRFS_TREE_LOG_OBJECTID -6ULL
73 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
76 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
77 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
80 * extent checksums all have this objectid
81 * this allows them to share the logging tree
84 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
86 /* For storing free space cache */
87 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
90 * The inode number assigned to the special inode for sotring
93 #define BTRFS_FREE_INO_OBJECTID -12ULL
95 /* dummy objectid represents multiple objectids */
96 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
99 * All files have objectids in this range.
101 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
102 #define BTRFS_LAST_FREE_OBJECTID -256ULL
103 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
108 * the device items go into the chunk tree. The key is in the form
109 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
111 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
114 * the max metadata block size. This limit is somewhat artificial,
115 * but the memmove costs go through the roof for larger blocks.
117 #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
120 * we can actually store much bigger names, but lets not confuse the rest
123 #define BTRFS_NAME_LEN 255
126 * Theoretical limit is larger, but we keep this down to a sane
127 * value. That should limit greatly the possibility of collisions on
130 #define BTRFS_LINK_MAX 65535U
132 /* 32 bytes in various csum fields */
133 #define BTRFS_CSUM_SIZE 32
136 #define BTRFS_CSUM_TYPE_CRC32 0
138 static int btrfs_csum_sizes[] = { 4, 0 };
140 /* four bytes for CRC32 */
141 #define BTRFS_CRC32_SIZE 4
142 #define BTRFS_EMPTY_DIR_SIZE 0
144 #define BTRFS_FT_UNKNOWN 0
145 #define BTRFS_FT_REG_FILE 1
146 #define BTRFS_FT_DIR 2
147 #define BTRFS_FT_CHRDEV 3
148 #define BTRFS_FT_BLKDEV 4
149 #define BTRFS_FT_FIFO 5
150 #define BTRFS_FT_SOCK 6
151 #define BTRFS_FT_SYMLINK 7
152 #define BTRFS_FT_XATTR 8
153 #define BTRFS_FT_MAX 9
155 #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
158 * the key defines the order in the tree, and so it also defines (optimal)
159 * block layout. objectid corresonds to the inode number. The flags
160 * tells us things about the object, and is a kind of stream selector.
161 * so for a given inode, keys with flags of 1 might refer to the inode
162 * data, flags of 2 may point to file data in the btree and flags == 3
163 * may point to extents.
165 * offset is the starting byte offset for this key in the stream.
167 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
168 * in cpu native order. Otherwise they are identical and their sizes
169 * should be the same (ie both packed)
171 struct btrfs_disk_key {
175 } __attribute__ ((__packed__));
181 } __attribute__ ((__packed__));
183 struct btrfs_mapping_tree {
184 struct cache_tree cache_tree;
187 #define BTRFS_UUID_SIZE 16
188 struct btrfs_dev_item {
189 /* the internal btrfs device id */
192 /* size of the device */
198 /* optimal io alignment for this device */
201 /* optimal io width for this device */
204 /* minimal io size for this device */
207 /* type and info about this device */
210 /* expected generation for this device */
214 * starting byte of this partition on the device,
215 * to allowr for stripe alignment in the future
219 /* grouping information for allocation decisions */
222 /* seek speed 0-100 where 100 is fastest */
225 /* bandwidth 0-100 where 100 is fastest */
228 /* btrfs generated uuid for this device */
229 u8 uuid[BTRFS_UUID_SIZE];
231 /* uuid of FS who owns this device */
232 u8 fsid[BTRFS_UUID_SIZE];
233 } __attribute__ ((__packed__));
235 struct btrfs_stripe {
238 u8 dev_uuid[BTRFS_UUID_SIZE];
239 } __attribute__ ((__packed__));
242 /* size of this chunk in bytes */
245 /* objectid of the root referencing this chunk */
251 /* optimal io alignment for this chunk */
254 /* optimal io width for this chunk */
257 /* minimal io size for this chunk */
260 /* 2^16 stripes is quite a lot, a second limit is the size of a single
265 /* sub stripes only matter for raid10 */
267 struct btrfs_stripe stripe;
268 /* additional stripes go here */
269 } __attribute__ ((__packed__));
271 struct btrfs_free_space_header {
272 struct btrfs_disk_key location;
276 } __attribute__ ((__packed__));
278 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
280 BUG_ON(num_stripes == 0);
281 return sizeof(struct btrfs_chunk) +
282 sizeof(struct btrfs_stripe) * (num_stripes - 1);
285 #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
286 #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
287 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
288 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
290 #define BTRFS_BACKREF_REV_MAX 256
291 #define BTRFS_BACKREF_REV_SHIFT 56
292 #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
293 BTRFS_BACKREF_REV_SHIFT)
295 #define BTRFS_OLD_BACKREF_REV 0
296 #define BTRFS_MIXED_BACKREF_REV 1
299 * every tree block (leaf or node) starts with this header.
301 struct btrfs_header {
302 /* these first four must match the super block */
303 u8 csum[BTRFS_CSUM_SIZE];
304 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
305 __le64 bytenr; /* which block this node is supposed to live in */
308 /* allowed to be different from the super from here on down */
309 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
314 } __attribute__ ((__packed__));
316 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
317 sizeof(struct btrfs_header)) / \
318 sizeof(struct btrfs_key_ptr))
319 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
320 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
321 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
322 sizeof(struct btrfs_item) - \
323 sizeof(struct btrfs_file_extent_item))
324 #define BTRFS_MAX_XATTR_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
325 sizeof(struct btrfs_item) -\
326 sizeof(struct btrfs_dir_item))
330 * this is a very generous portion of the super block, giving us
331 * room to translate 14 chunks with 3 stripes each.
333 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
334 #define BTRFS_LABEL_SIZE 256
337 * just in case we somehow lose the roots and are not able to mount,
338 * we store an array of the roots from previous transactions
341 #define BTRFS_NUM_BACKUP_ROOTS 4
342 struct btrfs_root_backup {
344 __le64 tree_root_gen;
347 __le64 chunk_root_gen;
350 __le64 extent_root_gen;
359 __le64 csum_root_gen;
369 u8 extent_root_level;
373 /* future and to align */
375 } __attribute__ ((__packed__));
378 * the super block basically lists the main trees of the FS
379 * it currently lacks any block count etc etc
381 struct btrfs_super_block {
382 u8 csum[BTRFS_CSUM_SIZE];
383 /* the first 3 fields must match struct btrfs_header */
384 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
385 __le64 bytenr; /* this block number */
388 /* allowed to be different from the btrfs_header from here own down */
395 /* this will help find the new super based on the log root */
396 __le64 log_root_transid;
399 __le64 root_dir_objectid;
405 __le32 sys_chunk_array_size;
406 __le64 chunk_root_generation;
408 __le64 compat_ro_flags;
409 __le64 incompat_flags;
414 struct btrfs_dev_item dev_item;
416 char label[BTRFS_LABEL_SIZE];
418 __le64 cache_generation;
420 /* future expansion */
422 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
423 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
424 } __attribute__ ((__packed__));
427 * Compat flags that we support. If any incompat flags are set other than the
428 * ones specified below then we will fail to mount
430 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
431 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
432 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
433 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
436 * some patches floated around with a second compression method
437 * lets save that incompat here for when they do get in
438 * Note we don't actually support it, we're just reserving the
441 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2 (1ULL << 4)
444 * older kernels tried to do bigger metadata blocks, but the
445 * code was pretty buggy. Lets not let them try anymore.
447 #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
448 #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
450 #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
452 #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
453 #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
454 #define BTRFS_FEATURE_INCOMPAT_SUPP \
455 (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
456 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
457 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
458 BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
459 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
460 BTRFS_FEATURE_INCOMPAT_RAID56 | \
461 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
464 * A leaf is full of items. offset and size tell us where to find
465 * the item in the leaf (relative to the start of the data area)
468 struct btrfs_disk_key key;
471 } __attribute__ ((__packed__));
474 * leaves have an item area and a data area:
475 * [item0, item1....itemN] [free space] [dataN...data1, data0]
477 * The data is separate from the items to get the keys closer together
481 struct btrfs_header header;
482 struct btrfs_item items[];
483 } __attribute__ ((__packed__));
486 * all non-leaf blocks are nodes, they hold only keys and pointers to
489 struct btrfs_key_ptr {
490 struct btrfs_disk_key key;
493 } __attribute__ ((__packed__));
496 struct btrfs_header header;
497 struct btrfs_key_ptr ptrs[];
498 } __attribute__ ((__packed__));
501 * btrfs_paths remember the path taken from the root down to the leaf.
502 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
503 * to any other levels that are present.
505 * The slots array records the index of the item or block pointer
506 * used while walking the tree.
510 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
511 int slots[BTRFS_MAX_LEVEL];
512 /* if there is real range locking, this locks field will change */
513 int locks[BTRFS_MAX_LEVEL];
515 /* keep some upper locks as we walk down */
519 * set by btrfs_split_item, tells search_slot to keep all locks
520 * and to force calls to keep space in the nodes
522 unsigned int search_for_split:1;
523 unsigned int keep_locks:1;
524 unsigned int skip_locking:1;
525 unsigned int leave_spinning:1;
529 * items in the extent btree are used to record the objectid of the
530 * owner of the block and the number of references
533 struct btrfs_extent_item {
537 } __attribute__ ((__packed__));
539 struct btrfs_extent_item_v0 {
541 } __attribute__ ((__packed__));
543 #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \
544 sizeof(struct btrfs_item))
546 #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
547 #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
549 /* following flags only apply to tree blocks */
551 /* use full backrefs for extent pointers in the block*/
552 #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
554 struct btrfs_tree_block_info {
555 struct btrfs_disk_key key;
557 } __attribute__ ((__packed__));
559 struct btrfs_extent_data_ref {
564 } __attribute__ ((__packed__));
566 struct btrfs_shared_data_ref {
568 } __attribute__ ((__packed__));
570 struct btrfs_extent_inline_ref {
573 } __attribute__ ((__packed__));
575 struct btrfs_extent_ref_v0 {
580 } __attribute__ ((__packed__));
582 /* dev extents record free space on individual devices. The owner
583 * field points back to the chunk allocation mapping tree that allocated
584 * the extent. The chunk tree uuid field is a way to double check the owner
586 struct btrfs_dev_extent {
588 __le64 chunk_objectid;
591 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
592 } __attribute__ ((__packed__));
594 struct btrfs_inode_ref {
598 } __attribute__ ((__packed__));
600 struct btrfs_inode_extref {
601 __le64 parent_objectid;
604 __u8 name[0]; /* name goes here */
605 } __attribute__ ((__packed__));
607 struct btrfs_timespec {
610 } __attribute__ ((__packed__));
613 BTRFS_COMPRESS_NONE = 0,
614 BTRFS_COMPRESS_ZLIB = 1,
615 BTRFS_COMPRESS_LZO = 2,
616 BTRFS_COMPRESS_TYPES = 2,
617 BTRFS_COMPRESS_LAST = 3,
618 } btrfs_compression_type;
620 /* we don't understand any encryption methods right now */
622 BTRFS_ENCRYPTION_NONE = 0,
623 BTRFS_ENCRYPTION_LAST = 1,
624 } btrfs_encryption_type;
626 struct btrfs_inode_item {
627 /* nfs style generation number */
629 /* transid that last touched this inode */
641 /* modification sequence number for NFS */
645 * a little future expansion, for more than this we can
646 * just grow the inode item and version it
649 struct btrfs_timespec atime;
650 struct btrfs_timespec ctime;
651 struct btrfs_timespec mtime;
652 struct btrfs_timespec otime;
653 } __attribute__ ((__packed__));
655 struct btrfs_dir_log_item {
657 } __attribute__ ((__packed__));
659 struct btrfs_dir_item {
660 struct btrfs_disk_key location;
665 } __attribute__ ((__packed__));
667 struct btrfs_root_item_v0 {
668 struct btrfs_inode_item inode;
674 __le64 last_snapshot;
677 struct btrfs_disk_key drop_progress;
680 } __attribute__ ((__packed__));
682 struct btrfs_root_item {
683 struct btrfs_inode_item inode;
689 __le64 last_snapshot;
692 struct btrfs_disk_key drop_progress;
697 * The following fields appear after subvol_uuids+subvol_times
702 * This generation number is used to test if the new fields are valid
703 * and up to date while reading the root item. Everytime the root item
704 * is written out, the "generation" field is copied into this field. If
705 * anyone ever mounted the fs with an older kernel, we will have
706 * mismatching generation values here and thus must invalidate the
707 * new fields. See btrfs_update_root and btrfs_find_last_root for
709 * the offset of generation_v2 is also used as the start for the memset
710 * when invalidating the fields.
712 __le64 generation_v2;
713 u8 uuid[BTRFS_UUID_SIZE];
714 u8 parent_uuid[BTRFS_UUID_SIZE];
715 u8 received_uuid[BTRFS_UUID_SIZE];
716 __le64 ctransid; /* updated when an inode changes */
717 __le64 otransid; /* trans when created */
718 __le64 stransid; /* trans when sent. non-zero for received subvol */
719 __le64 rtransid; /* trans when received. non-zero for received subvol */
720 struct btrfs_timespec ctime;
721 struct btrfs_timespec otime;
722 struct btrfs_timespec stime;
723 struct btrfs_timespec rtime;
724 __le64 reserved[8]; /* for future */
725 } __attribute__ ((__packed__));
728 * this is used for both forward and backward root refs
730 struct btrfs_root_ref {
734 } __attribute__ ((__packed__));
736 #define BTRFS_FILE_EXTENT_INLINE 0
737 #define BTRFS_FILE_EXTENT_REG 1
738 #define BTRFS_FILE_EXTENT_PREALLOC 2
740 struct btrfs_file_extent_item {
742 * transaction id that created this extent
746 * max number of bytes to hold this extent in ram
747 * when we split a compressed extent we can't know how big
748 * each of the resulting pieces will be. So, this is
749 * an upper limit on the size of the extent in ram instead of
755 * 32 bits for the various ways we might encode the data,
756 * including compression and encryption. If any of these
757 * are set to something a given disk format doesn't understand
758 * it is treated like an incompat flag for reading and writing,
763 __le16 other_encoding; /* spare for later use */
765 /* are we inline data or a real extent? */
769 * disk space consumed by the extent, checksum blocks are included
773 __le64 disk_num_bytes;
775 * the logical offset in file blocks (no csums)
776 * this extent record is for. This allows a file extent to point
777 * into the middle of an existing extent on disk, sharing it
778 * between two snapshots (useful if some bytes in the middle of the
779 * extent have changed
783 * the logical number of file blocks (no csums included)
787 } __attribute__ ((__packed__));
789 struct btrfs_csum_item {
791 } __attribute__ ((__packed__));
793 /* tag for the radix tree of block groups in ram */
794 #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
795 #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
796 #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
797 #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
798 #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
799 #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
800 #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
801 #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
802 #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
803 #define BTRFS_BLOCK_GROUP_RESERVED BTRFS_AVAIL_ALLOC_BIT_SINGLE
805 /* used in struct btrfs_balance_args fields */
806 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
808 #define BTRFS_QGROUP_STATUS_OFF 0
809 #define BTRFS_QGROUP_STATUS_ON 1
810 #define BTRFS_QGROUP_STATUS_SCANNING 2
812 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1 << 0)
814 struct btrfs_qgroup_status_item {
818 __le64 scan; /* progress during scanning */
819 } __attribute__ ((__packed__));
821 struct btrfs_block_group_item {
823 __le64 chunk_objectid;
825 } __attribute__ ((__packed__));
827 struct btrfs_qgroup_info_item {
830 __le64 referenced_compressed;
832 __le64 exclusive_compressed;
833 } __attribute__ ((__packed__));
835 /* flags definition for qgroup limits */
836 #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
837 #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
838 #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
839 #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
840 #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
841 #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
843 struct btrfs_qgroup_limit_item {
845 __le64 max_referenced;
846 __le64 max_exclusive;
847 __le64 rsv_referenced;
848 __le64 rsv_exclusive;
849 } __attribute__ ((__packed__));
851 struct btrfs_space_info {
857 struct list_head list;
860 struct btrfs_block_group_cache {
861 struct cache_extent cache;
862 struct btrfs_key key;
863 struct btrfs_block_group_item item;
864 struct btrfs_space_info *space_info;
871 struct btrfs_extent_ops {
872 int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
873 u64 hint_byte, struct btrfs_key *ins);
874 int (*free_extent)(struct btrfs_root *root, u64 bytenr,
879 struct btrfs_fs_devices;
880 struct btrfs_fs_info {
881 u8 fsid[BTRFS_FSID_SIZE];
882 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
883 struct btrfs_root *fs_root;
884 struct btrfs_root *extent_root;
885 struct btrfs_root *tree_root;
886 struct btrfs_root *chunk_root;
887 struct btrfs_root *dev_root;
888 struct btrfs_root *csum_root;
890 struct cache_tree fs_root_cache;
892 /* the log root tree is a directory of all the other log roots */
893 struct btrfs_root *log_root_tree;
895 struct extent_io_tree extent_cache;
896 struct extent_io_tree free_space_cache;
897 struct extent_io_tree block_group_cache;
898 struct extent_io_tree pinned_extents;
899 struct extent_io_tree pending_del;
900 struct extent_io_tree extent_ins;
902 /* logical->physical extent mapping */
903 struct btrfs_mapping_tree mapping_tree;
906 u64 last_trans_committed;
908 u64 avail_data_alloc_bits;
909 u64 avail_metadata_alloc_bits;
910 u64 avail_system_alloc_bits;
911 u64 data_alloc_profile;
912 u64 metadata_alloc_profile;
913 u64 system_alloc_profile;
916 struct btrfs_trans_handle *running_transaction;
917 struct btrfs_super_block super_copy;
918 struct mutex fs_mutex;
923 struct btrfs_extent_ops *extent_ops;
924 struct list_head dirty_cowonly_roots;
926 struct btrfs_fs_devices *fs_devices;
927 struct list_head space_info;
930 int (*free_extent_hook)(struct btrfs_trans_handle *trans,
931 struct btrfs_root *root,
932 u64 bytenr, u64 num_bytes, u64 parent,
933 u64 root_objectid, u64 owner, u64 offset,
935 struct cache_tree *fsck_extent_cache;
936 struct cache_tree *corrupt_blocks;
940 * in ram representation of the tree. extent_root is used for all allocations
941 * and for the extent tree extent_root root.
944 struct extent_buffer *node;
945 struct extent_buffer *commit_root;
946 struct btrfs_root_item root_item;
947 struct btrfs_key root_key;
948 struct btrfs_fs_info *fs_info;
952 /* data allocations are done in sectorsize units */
955 /* node allocations are done in nodesize units */
958 /* leaf allocations are done in leafsize units */
961 /* leaf allocations are done in leafsize units */
970 u64 last_inode_alloc;
972 /* the dirty list is only used by non-reference counted roots */
973 struct list_head dirty_list;
974 struct cache_extent cache;
978 * inode items have the data typically returned from stat and store other
979 * info about object characteristics. There is one for every file and dir in
982 #define BTRFS_INODE_ITEM_KEY 1
983 #define BTRFS_INODE_REF_KEY 12
984 #define BTRFS_INODE_EXTREF_KEY 13
985 #define BTRFS_XATTR_ITEM_KEY 24
986 #define BTRFS_ORPHAN_ITEM_KEY 48
988 #define BTRFS_DIR_LOG_ITEM_KEY 60
989 #define BTRFS_DIR_LOG_INDEX_KEY 72
991 * dir items are the name -> inode pointers in a directory. There is one
992 * for every name in a directory.
994 #define BTRFS_DIR_ITEM_KEY 84
995 #define BTRFS_DIR_INDEX_KEY 96
998 * extent data is for file data
1000 #define BTRFS_EXTENT_DATA_KEY 108
1003 * csum items have the checksums for data in the extents
1005 #define BTRFS_CSUM_ITEM_KEY 120
1007 * extent csums are stored in a separate tree and hold csums for
1008 * an entire extent on disk.
1010 #define BTRFS_EXTENT_CSUM_KEY 128
1013 * root items point to tree roots. There are typically in the root
1014 * tree used by the super block to find all the other trees
1016 #define BTRFS_ROOT_ITEM_KEY 132
1019 * root backrefs tie subvols and snapshots to the directory entries that
1022 #define BTRFS_ROOT_BACKREF_KEY 144
1025 * root refs make a fast index for listing all of the snapshots and
1026 * subvolumes referenced by a given root. They point directly to the
1027 * directory item in the root that references the subvol
1029 #define BTRFS_ROOT_REF_KEY 156
1032 * extent items are in the extent map tree. These record which blocks
1033 * are used, and how many references there are to each block
1035 #define BTRFS_EXTENT_ITEM_KEY 168
1037 #define BTRFS_TREE_BLOCK_REF_KEY 176
1039 #define BTRFS_EXTENT_DATA_REF_KEY 178
1041 /* old style extent backrefs */
1042 #define BTRFS_EXTENT_REF_V0_KEY 180
1044 #define BTRFS_SHARED_BLOCK_REF_KEY 182
1046 #define BTRFS_SHARED_DATA_REF_KEY 184
1050 * block groups give us hints into the extent allocation trees. Which
1051 * blocks are free etc etc
1053 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
1055 #define BTRFS_DEV_EXTENT_KEY 204
1056 #define BTRFS_DEV_ITEM_KEY 216
1057 #define BTRFS_CHUNK_ITEM_KEY 228
1059 #define BTRFS_BALANCE_ITEM_KEY 248
1064 #define BTRFS_QGROUP_STATUS_KEY 240
1065 #define BTRFS_QGROUP_INFO_KEY 242
1066 #define BTRFS_QGROUP_LIMIT_KEY 244
1067 #define BTRFS_QGROUP_RELATION_KEY 246
1070 * Persistently stores the io stats in the device tree.
1071 * One key for all stats, (0, BTRFS_DEV_STATS_KEY, devid).
1073 #define BTRFS_DEV_STATS_KEY 249
1076 * Persistently stores the device replace state in the device tree.
1077 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
1079 #define BTRFS_DEV_REPLACE_KEY 250
1082 * string items are for debugging. They just store a short string of
1085 #define BTRFS_STRING_ITEM_KEY 253
1089 #define BTRFS_INODE_NODATASUM (1 << 0)
1090 #define BTRFS_INODE_NODATACOW (1 << 1)
1091 #define BTRFS_INODE_READONLY (1 << 2)
1093 #define read_eb_member(eb, ptr, type, member, result) ( \
1094 read_extent_buffer(eb, (char *)(result), \
1095 ((unsigned long)(ptr)) + \
1096 offsetof(type, member), \
1097 sizeof(((type *)0)->member)))
1099 #define write_eb_member(eb, ptr, type, member, result) ( \
1100 write_extent_buffer(eb, (char *)(result), \
1101 ((unsigned long)(ptr)) + \
1102 offsetof(type, member), \
1103 sizeof(((type *)0)->member)))
1105 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
1106 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
1108 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
1109 return le##bits##_to_cpu(h->member); \
1111 static inline void btrfs_set_##name(struct extent_buffer *eb, \
1114 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
1115 h->member = cpu_to_le##bits(val); \
1118 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
1119 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
1122 unsigned long offset = (unsigned long)s; \
1123 type *p = (type *) (eb->data + offset); \
1124 return get_unaligned_le##bits(&p->member); \
1126 static inline void btrfs_set_##name(struct extent_buffer *eb, \
1127 type *s, u##bits val) \
1129 unsigned long offset = (unsigned long)s; \
1130 type *p = (type *) (eb->data + offset); \
1131 put_unaligned_le##bits(val, &p->member); \
1134 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
1135 static inline u##bits btrfs_##name(type *s) \
1137 return le##bits##_to_cpu(s->member); \
1139 static inline void btrfs_set_##name(type *s, u##bits val) \
1141 s->member = cpu_to_le##bits(val); \
1144 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
1145 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
1146 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
1147 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
1148 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
1149 BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
1151 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
1152 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
1153 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
1154 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
1155 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
1156 BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
1158 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
1159 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
1161 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
1163 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
1165 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
1167 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
1169 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
1170 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
1172 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
1174 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
1176 BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
1179 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
1181 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
1184 static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
1186 return (char *)d + offsetof(struct btrfs_dev_item, fsid);
1189 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
1190 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
1191 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
1192 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
1193 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
1194 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
1195 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
1196 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
1197 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
1198 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
1199 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
1201 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
1203 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
1206 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
1207 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
1208 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
1210 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
1212 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
1214 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
1216 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
1217 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
1219 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
1221 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
1222 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
1224 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
1227 unsigned long offset = (unsigned long)c;
1228 offset += offsetof(struct btrfs_chunk, stripe);
1229 offset += nr * sizeof(struct btrfs_stripe);
1230 return (struct btrfs_stripe *)offset;
1233 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
1235 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
1238 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
1239 struct btrfs_chunk *c, int nr)
1241 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
1244 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
1245 struct btrfs_chunk *c, int nr,
1248 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
1251 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
1252 struct btrfs_chunk *c, int nr)
1254 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
1257 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
1258 struct btrfs_chunk *c, int nr,
1261 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
1264 /* struct btrfs_block_group_item */
1265 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
1267 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
1269 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
1270 struct btrfs_block_group_item, chunk_objectid, 64);
1272 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
1273 struct btrfs_block_group_item, chunk_objectid, 64);
1274 BTRFS_SETGET_FUNCS(disk_block_group_flags,
1275 struct btrfs_block_group_item, flags, 64);
1276 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
1277 struct btrfs_block_group_item, flags, 64);
1279 /* struct btrfs_inode_ref */
1280 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
1281 BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
1282 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
1284 /* struct btrfs_inode_extref */
1285 BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref,
1286 parent_objectid, 64);
1287 BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref,
1289 BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64);
1291 /* struct btrfs_inode_item */
1292 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
1293 BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
1294 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
1295 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
1296 BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
1297 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
1298 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1299 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1300 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1301 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1302 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1303 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1305 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
1306 struct btrfs_inode_item, generation, 64);
1307 BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence,
1308 struct btrfs_inode_item, generation, 64);
1309 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
1310 struct btrfs_inode_item, size, 64);
1311 BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes,
1312 struct btrfs_inode_item, nbytes, 64);
1313 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
1314 struct btrfs_inode_item, block_group, 64);
1315 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
1316 struct btrfs_inode_item, nlink, 32);
1317 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
1318 struct btrfs_inode_item, uid, 32);
1319 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
1320 struct btrfs_inode_item, gid, 32);
1321 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
1322 struct btrfs_inode_item, mode, 32);
1323 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
1324 struct btrfs_inode_item, rdev, 64);
1325 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
1326 struct btrfs_inode_item, flags, 64);
1328 static inline struct btrfs_timespec *
1329 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
1331 unsigned long ptr = (unsigned long)inode_item;
1332 ptr += offsetof(struct btrfs_inode_item, atime);
1333 return (struct btrfs_timespec *)ptr;
1336 static inline struct btrfs_timespec *
1337 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
1339 unsigned long ptr = (unsigned long)inode_item;
1340 ptr += offsetof(struct btrfs_inode_item, mtime);
1341 return (struct btrfs_timespec *)ptr;
1344 static inline struct btrfs_timespec *
1345 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
1347 unsigned long ptr = (unsigned long)inode_item;
1348 ptr += offsetof(struct btrfs_inode_item, ctime);
1349 return (struct btrfs_timespec *)ptr;
1352 static inline struct btrfs_timespec *
1353 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
1355 unsigned long ptr = (unsigned long)inode_item;
1356 ptr += offsetof(struct btrfs_inode_item, otime);
1357 return (struct btrfs_timespec *)ptr;
1360 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
1361 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
1362 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
1364 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
1367 /* struct btrfs_dev_extent */
1368 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
1370 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
1371 chunk_objectid, 64);
1372 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
1374 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
1376 static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
1378 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
1379 return (u8 *)((unsigned long)dev + ptr);
1383 /* struct btrfs_extent_item */
1384 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
1385 BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item,
1387 BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
1389 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1391 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1393 static inline void btrfs_tree_block_key(struct extent_buffer *eb,
1394 struct btrfs_tree_block_info *item,
1395 struct btrfs_disk_key *key)
1397 read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
1400 static inline void btrfs_set_tree_block_key(struct extent_buffer *eb,
1401 struct btrfs_tree_block_info *item,
1402 struct btrfs_disk_key *key)
1404 write_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
1407 BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref,
1409 BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref,
1411 BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref,
1413 BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref,
1416 BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref,
1419 BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref,
1421 BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref,
1424 static inline u32 btrfs_extent_inline_ref_size(int type)
1426 if (type == BTRFS_TREE_BLOCK_REF_KEY ||
1427 type == BTRFS_SHARED_BLOCK_REF_KEY)
1428 return sizeof(struct btrfs_extent_inline_ref);
1429 if (type == BTRFS_SHARED_DATA_REF_KEY)
1430 return sizeof(struct btrfs_shared_data_ref) +
1431 sizeof(struct btrfs_extent_inline_ref);
1432 if (type == BTRFS_EXTENT_DATA_REF_KEY)
1433 return sizeof(struct btrfs_extent_data_ref) +
1434 offsetof(struct btrfs_extent_inline_ref, offset);
1439 BTRFS_SETGET_FUNCS(ref_root_v0, struct btrfs_extent_ref_v0, root, 64);
1440 BTRFS_SETGET_FUNCS(ref_generation_v0, struct btrfs_extent_ref_v0,
1442 BTRFS_SETGET_FUNCS(ref_objectid_v0, struct btrfs_extent_ref_v0, objectid, 64);
1443 BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32);
1445 /* struct btrfs_node */
1446 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
1447 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
1449 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
1452 ptr = offsetof(struct btrfs_node, ptrs) +
1453 sizeof(struct btrfs_key_ptr) * nr;
1454 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
1457 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
1461 ptr = offsetof(struct btrfs_node, ptrs) +
1462 sizeof(struct btrfs_key_ptr) * nr;
1463 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
1466 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
1469 ptr = offsetof(struct btrfs_node, ptrs) +
1470 sizeof(struct btrfs_key_ptr) * nr;
1471 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
1474 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
1478 ptr = offsetof(struct btrfs_node, ptrs) +
1479 sizeof(struct btrfs_key_ptr) * nr;
1480 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
1483 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
1485 return offsetof(struct btrfs_node, ptrs) +
1486 sizeof(struct btrfs_key_ptr) * nr;
1489 static inline void btrfs_node_key(struct extent_buffer *eb,
1490 struct btrfs_disk_key *disk_key, int nr)
1493 ptr = btrfs_node_key_ptr_offset(nr);
1494 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1495 struct btrfs_key_ptr, key, disk_key);
1498 static inline void btrfs_set_node_key(struct extent_buffer *eb,
1499 struct btrfs_disk_key *disk_key, int nr)
1502 ptr = btrfs_node_key_ptr_offset(nr);
1503 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1504 struct btrfs_key_ptr, key, disk_key);
1507 /* struct btrfs_item */
1508 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
1509 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
1511 static inline unsigned long btrfs_item_nr_offset(int nr)
1513 return offsetof(struct btrfs_leaf, items) +
1514 sizeof(struct btrfs_item) * nr;
1517 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
1520 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
1523 static inline u32 btrfs_item_end(struct extent_buffer *eb,
1524 struct btrfs_item *item)
1526 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
1529 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
1531 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
1534 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
1536 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
1539 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
1541 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
1544 static inline void btrfs_item_key(struct extent_buffer *eb,
1545 struct btrfs_disk_key *disk_key, int nr)
1547 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1548 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1551 static inline void btrfs_set_item_key(struct extent_buffer *eb,
1552 struct btrfs_disk_key *disk_key, int nr)
1554 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1555 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1558 BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
1561 * struct btrfs_root_ref
1563 BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
1564 BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
1565 BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
1567 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid, struct btrfs_root_ref, dirid, 64);
1568 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequence, 64);
1569 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16);
1571 /* struct btrfs_dir_item */
1572 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1573 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1574 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1575 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1577 BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16);
1579 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1580 struct btrfs_dir_item *item,
1581 struct btrfs_disk_key *key)
1583 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1586 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1587 struct btrfs_dir_item *item,
1588 struct btrfs_disk_key *key)
1590 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1593 /* struct btrfs_free_space_header */
1594 BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header,
1596 BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header,
1598 BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header,
1601 static inline void btrfs_free_space_key(struct extent_buffer *eb,
1602 struct btrfs_free_space_header *h,
1603 struct btrfs_disk_key *key)
1605 read_eb_member(eb, h, struct btrfs_free_space_header, location, key);
1608 static inline void btrfs_set_free_space_key(struct extent_buffer *eb,
1609 struct btrfs_free_space_header *h,
1610 struct btrfs_disk_key *key)
1612 write_eb_member(eb, h, struct btrfs_free_space_header, location, key);
1615 /* struct btrfs_disk_key */
1616 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1618 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1619 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1621 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1622 struct btrfs_disk_key *disk)
1624 cpu->offset = le64_to_cpu(disk->offset);
1625 cpu->type = disk->type;
1626 cpu->objectid = le64_to_cpu(disk->objectid);
1629 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
1630 struct btrfs_key *cpu)
1632 disk->offset = cpu_to_le64(cpu->offset);
1633 disk->type = cpu->type;
1634 disk->objectid = cpu_to_le64(cpu->objectid);
1637 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1638 struct btrfs_key *key, int nr)
1640 struct btrfs_disk_key disk_key;
1641 btrfs_node_key(eb, &disk_key, nr);
1642 btrfs_disk_key_to_cpu(key, &disk_key);
1645 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1646 struct btrfs_key *key, int nr)
1648 struct btrfs_disk_key disk_key;
1649 btrfs_item_key(eb, &disk_key, nr);
1650 btrfs_disk_key_to_cpu(key, &disk_key);
1653 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1654 struct btrfs_dir_item *item,
1655 struct btrfs_key *key)
1657 struct btrfs_disk_key disk_key;
1658 btrfs_dir_item_key(eb, item, &disk_key);
1659 btrfs_disk_key_to_cpu(key, &disk_key);
1663 static inline u8 btrfs_key_type(struct btrfs_key *key)
1668 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1673 /* struct btrfs_header */
1674 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1675 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1677 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1678 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1679 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1680 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1682 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1684 return (btrfs_header_flags(eb) & flag) == flag;
1687 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1689 u64 flags = btrfs_header_flags(eb);
1690 btrfs_set_header_flags(eb, flags | flag);
1691 return (flags & flag) == flag;
1694 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1696 u64 flags = btrfs_header_flags(eb);
1697 btrfs_set_header_flags(eb, flags & ~flag);
1698 return (flags & flag) == flag;
1701 static inline int btrfs_header_backref_rev(struct extent_buffer *eb)
1703 u64 flags = btrfs_header_flags(eb);
1704 return flags >> BTRFS_BACKREF_REV_SHIFT;
1707 static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
1710 u64 flags = btrfs_header_flags(eb);
1711 flags &= ~BTRFS_BACKREF_REV_MASK;
1712 flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
1713 btrfs_set_header_flags(eb, flags);
1716 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1718 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1722 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1724 unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1728 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1730 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1734 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1736 unsigned long ptr = offsetof(struct btrfs_header, csum);
1740 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1745 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1750 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1755 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1757 return (btrfs_header_level(eb) == 0);
1760 /* struct btrfs_root_item */
1761 BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
1763 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1764 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1765 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1767 BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
1769 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1770 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1771 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1772 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1773 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
1774 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1775 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1776 BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
1778 BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item,
1780 BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item,
1782 BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item,
1784 BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item,
1786 BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item,
1789 /* struct btrfs_root_backup */
1790 BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
1792 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup,
1794 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup,
1795 tree_root_level, 8);
1797 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup,
1799 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup,
1800 chunk_root_gen, 64);
1801 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup,
1802 chunk_root_level, 8);
1804 BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup,
1806 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup,
1807 extent_root_gen, 64);
1808 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup,
1809 extent_root_level, 8);
1811 BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup,
1813 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup,
1815 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup,
1818 BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup,
1820 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup,
1822 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup,
1825 BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup,
1827 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup,
1829 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup,
1830 csum_root_level, 8);
1831 BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup,
1833 BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
1835 BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
1838 /* struct btrfs_super_block */
1840 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1841 BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
1842 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1844 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1845 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1846 struct btrfs_super_block, sys_chunk_array_size, 32);
1847 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
1848 struct btrfs_super_block, chunk_root_generation, 64);
1849 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1851 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1853 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1854 chunk_root_level, 8);
1855 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
1857 BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
1858 log_root_transid, 64);
1859 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
1861 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1863 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1865 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1867 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1869 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1871 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1873 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1874 root_dir_objectid, 64);
1875 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1877 BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
1879 BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
1881 BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
1882 incompat_flags, 64);
1883 BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
1885 BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
1886 cache_generation, 64);
1888 static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
1890 int t = btrfs_super_csum_type(s);
1891 BUG_ON(t >= ARRAY_SIZE(btrfs_csum_sizes));
1892 return btrfs_csum_sizes[t];
1895 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1897 return offsetof(struct btrfs_leaf, items);
1900 /* struct btrfs_file_extent_item */
1901 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1902 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, type, 8);
1904 static inline unsigned long btrfs_file_extent_inline_start(struct
1905 btrfs_file_extent_item *e)
1907 unsigned long offset = (unsigned long)e;
1908 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1912 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1914 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1917 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1919 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, struct btrfs_file_extent_item,
1921 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1923 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, struct btrfs_file_extent_item,
1925 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1926 disk_num_bytes, 64);
1927 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1929 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, struct btrfs_file_extent_item,
1931 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1933 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, struct btrfs_file_extent_item,
1935 BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
1937 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes, struct btrfs_file_extent_item,
1939 BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
1941 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, struct btrfs_file_extent_item,
1943 BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
1945 BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
1946 other_encoding, 16);
1948 /* btrfs_qgroup_status_item */
1949 BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item,
1951 BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item,
1953 BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item,
1955 BTRFS_SETGET_FUNCS(qgroup_status_scan, struct btrfs_qgroup_status_item,
1958 /* btrfs_qgroup_info_item */
1959 BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item,
1961 BTRFS_SETGET_FUNCS(qgroup_info_referenced, struct btrfs_qgroup_info_item,
1963 BTRFS_SETGET_FUNCS(qgroup_info_referenced_compressed,
1964 struct btrfs_qgroup_info_item, referenced_compressed, 64);
1965 BTRFS_SETGET_FUNCS(qgroup_info_exclusive, struct btrfs_qgroup_info_item,
1967 BTRFS_SETGET_FUNCS(qgroup_info_exclusive_compressed,
1968 struct btrfs_qgroup_info_item, exclusive_compressed, 64);
1970 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation,
1971 struct btrfs_qgroup_info_item, generation, 64);
1972 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_referenced,
1973 struct btrfs_qgroup_info_item, referenced, 64);
1974 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_referenced_compressed,
1975 struct btrfs_qgroup_info_item, referenced_compressed, 64);
1976 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_exclusive,
1977 struct btrfs_qgroup_info_item, exclusive, 64);
1978 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_exclusive_compressed,
1979 struct btrfs_qgroup_info_item, exclusive_compressed, 64);
1981 /* btrfs_qgroup_limit_item */
1982 BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item,
1984 BTRFS_SETGET_FUNCS(qgroup_limit_max_referenced, struct btrfs_qgroup_limit_item,
1985 max_referenced, 64);
1986 BTRFS_SETGET_FUNCS(qgroup_limit_max_exclusive, struct btrfs_qgroup_limit_item,
1988 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_referenced, struct btrfs_qgroup_limit_item,
1989 rsv_referenced, 64);
1990 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_exclusive, struct btrfs_qgroup_limit_item,
1993 /* this returns the number of file bytes represented by the inline item.
1994 * If an item is compressed, this is the uncompressed size
1996 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1997 struct btrfs_file_extent_item *e)
1999 return btrfs_file_extent_ram_bytes(eb, e);
2003 * this returns the number of bytes used by the item on disk, minus the
2004 * size of any extent headers. If a file is compressed on disk, this is
2005 * the compressed size
2007 static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
2008 struct btrfs_item *e)
2010 unsigned long offset;
2011 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
2012 return btrfs_item_size(eb, e) - offset;
2015 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
2017 return root->leafsize;
2018 return root->nodesize;
2021 /* helper function to cast into the data area of the leaf. */
2022 #define btrfs_item_ptr(leaf, slot, type) \
2023 ((type *)(btrfs_leaf_data(leaf) + \
2024 btrfs_item_offset_nr(leaf, slot)))
2026 #define btrfs_item_ptr_offset(leaf, slot) \
2027 ((unsigned long)(btrfs_leaf_data(leaf) + \
2028 btrfs_item_offset_nr(leaf, slot)))
2031 int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans,
2032 struct btrfs_root *root);
2033 int btrfs_check_block_accounting(struct btrfs_root *root);
2034 void btrfs_pin_extent(struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes);
2035 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
2036 struct btrfs_root *root);
2037 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
2038 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
2039 btrfs_fs_info *info,
2041 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
2042 struct btrfs_block_group_cache
2043 *hint, u64 search_start,
2044 int data, int owner);
2045 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
2046 struct btrfs_root *root,
2047 u32 blocksize, u64 root_objectid,
2048 struct btrfs_disk_key *key, int level,
2049 u64 hint, u64 empty_size);
2050 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
2051 struct btrfs_root *root,
2052 u64 num_bytes, u64 parent,
2053 u64 root_objectid, u64 ref_generation,
2054 u64 owner, u64 empty_size, u64 hint_byte,
2055 u64 search_end, struct btrfs_key *ins, int data);
2056 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
2057 struct btrfs_root *root, u64 bytenr,
2058 u64 num_bytes, u64 *refs, u64 *flags);
2059 int btrfs_set_block_flags(struct btrfs_trans_handle *trans,
2060 struct btrfs_root *root,
2061 u64 bytenr, u64 num_bytes, u64 flags);
2062 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2063 struct extent_buffer *buf, int record_parent);
2064 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2065 struct extent_buffer *buf, int record_parent);
2066 int btrfs_free_extent(struct btrfs_trans_handle *trans,
2067 struct btrfs_root *root,
2068 u64 bytenr, u64 num_bytes, u64 parent,
2069 u64 root_objectid, u64 owner, u64 offset);
2070 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
2071 struct btrfs_root *root,
2072 struct extent_io_tree *unpin);
2073 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
2074 struct btrfs_root *root,
2075 u64 bytenr, u64 num_bytes, u64 parent,
2076 u64 root_objectid, u64 ref_generation,
2077 u64 owner_objectid);
2078 int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
2079 struct btrfs_root *root, u64 bytenr,
2080 u64 orig_parent, u64 parent,
2081 u64 root_objectid, u64 ref_generation,
2082 u64 owner_objectid);
2083 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
2084 struct btrfs_root *root);
2085 int btrfs_free_block_groups(struct btrfs_fs_info *info);
2086 int btrfs_read_block_groups(struct btrfs_root *root);
2087 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
2088 struct btrfs_root *root, u64 bytes_used,
2089 u64 type, u64 chunk_objectid, u64 chunk_offset,
2091 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
2092 struct btrfs_root *root);
2093 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
2094 struct btrfs_root *root, u64 bytenr, u64 num,
2095 int alloc, int mark_free);
2097 int btrfs_del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2098 struct btrfs_path *path, int level, int slot);
2099 int btrfs_check_node(struct btrfs_root *root,
2100 struct btrfs_disk_key *parent_key,
2101 struct extent_buffer *buf);
2102 int btrfs_check_leaf(struct btrfs_root *root,
2103 struct btrfs_disk_key *parent_key,
2104 struct extent_buffer *buf);
2105 int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
2106 struct btrfs_root *root);
2107 void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
2108 int level, int slot, u64 objectid);
2109 struct extent_buffer *read_node_slot(struct btrfs_root *root,
2110 struct extent_buffer *parent, int slot);
2111 int btrfs_previous_item(struct btrfs_root *root,
2112 struct btrfs_path *path, u64 min_objectid,
2114 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
2115 int btrfs_cow_block(struct btrfs_trans_handle *trans,
2116 struct btrfs_root *root, struct extent_buffer *buf,
2117 struct extent_buffer *parent, int parent_slot,
2118 struct extent_buffer **cow_ret);
2119 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
2120 struct btrfs_root *root,
2121 struct extent_buffer *buf,
2122 struct extent_buffer *parent, int parent_slot,
2123 struct extent_buffer **cow_ret,
2124 u64 search_start, u64 empty_size);
2125 int btrfs_copy_root(struct btrfs_trans_handle *trans,
2126 struct btrfs_root *root,
2127 struct extent_buffer *buf,
2128 struct extent_buffer **cow_ret, u64 new_root_objectid);
2129 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
2130 *root, struct btrfs_path *path, u32 data_size);
2131 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
2132 struct btrfs_root *root,
2133 struct btrfs_path *path,
2134 u32 new_size, int from_end);
2135 int btrfs_split_item(struct btrfs_trans_handle *trans,
2136 struct btrfs_root *root,
2137 struct btrfs_path *path,
2138 struct btrfs_key *new_key,
2139 unsigned long split_offset);
2140 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
2141 *root, struct btrfs_key *key, struct btrfs_path *p, int
2143 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
2144 struct btrfs_root *root, struct extent_buffer *parent,
2145 int start_slot, int cache_only, u64 *last_ret,
2146 struct btrfs_key *progress);
2147 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
2148 struct btrfs_path *btrfs_alloc_path(void);
2149 void btrfs_free_path(struct btrfs_path *p);
2150 void btrfs_init_path(struct btrfs_path *p);
2151 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2152 struct btrfs_path *path, int slot, int nr);
2154 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
2155 struct btrfs_root *root,
2156 struct btrfs_path *path)
2158 return btrfs_del_items(trans, root, path, path->slots[0], 1);
2161 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
2162 *root, struct btrfs_key *key, void *data, u32 data_size);
2163 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
2164 struct btrfs_root *root,
2165 struct btrfs_path *path,
2166 struct btrfs_key *cpu_key, u32 *data_size, int nr);
2168 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
2169 struct btrfs_root *root,
2170 struct btrfs_path *path,
2171 struct btrfs_key *key,
2174 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
2177 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
2178 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
2179 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
2180 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
2182 int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
2183 struct btrfs_root *root, struct btrfs_path *path,
2184 struct btrfs_key *new_key);
2187 int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
2188 struct btrfs_root *tree_root,
2189 u64 root_id, u8 type, u64 ref_id,
2190 u64 dirid, u64 sequence,
2191 const char *name, int name_len);
2192 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
2193 struct btrfs_key *key);
2194 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
2195 *root, struct btrfs_key *key, struct btrfs_root_item
2197 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
2198 *root, struct btrfs_key *key, struct btrfs_root_item
2200 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
2201 btrfs_root_item *item, struct btrfs_key *key);
2202 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
2203 struct btrfs_root *latest_root);
2205 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
2206 *root, const char *name, int name_len, u64 dir,
2207 struct btrfs_key *location, u8 type, u64 index);
2208 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
2209 struct btrfs_root *root,
2210 struct btrfs_path *path, u64 dir,
2211 const char *name, int name_len,
2213 struct btrfs_dir_item *
2214 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
2215 struct btrfs_root *root,
2216 struct btrfs_path *path, u64 dir,
2217 u64 objectid, const char *name, int name_len,
2219 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
2220 struct btrfs_path *path,
2221 const char *name, int name_len);
2222 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
2223 struct btrfs_root *root,
2224 struct btrfs_path *path,
2225 struct btrfs_dir_item *di);
2226 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
2227 struct btrfs_root *root, const char *name,
2228 u16 name_len, const void *data, u16 data_len,
2230 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
2231 struct btrfs_root *root,
2232 struct btrfs_path *path, u64 dir,
2233 const char *name, u16 name_len,
2236 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
2237 struct btrfs_root *fs_root,
2238 u64 dirid, u64 *objectid);
2239 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
2242 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
2243 struct btrfs_root *root,
2244 const char *name, int name_len,
2245 u64 inode_objectid, u64 ref_objectid, u64 index);
2246 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
2247 struct btrfs_root *root,
2248 const char *name, int name_len,
2249 u64 inode_objectid, u64 ref_objectid);
2250 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
2251 struct btrfs_root *root,
2252 struct btrfs_path *path, u64 objectid);
2253 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
2254 *root, u64 objectid, struct btrfs_inode_item
2256 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
2257 *root, struct btrfs_path *path,
2258 struct btrfs_key *location, int mod);
2261 int btrfs_del_csums(struct btrfs_trans_handle *trans,
2262 struct btrfs_root *root, u64 bytenr, u64 len);
2263 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
2264 struct btrfs_root *root,
2265 u64 objectid, u64 pos, u64 offset,
2268 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
2269 struct btrfs_root *root, u64 objectid,
2270 u64 offset, char *buffer, size_t size);
2271 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
2272 struct btrfs_root *root,
2273 struct btrfs_path *path, u64 objectid,
2274 u64 bytenr, int mod);
2275 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
2276 struct btrfs_root *root, u64 alloc_end,
2277 u64 bytenr, char *data, size_t len);
2278 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
2279 struct btrfs_root *root,
2280 struct btrfs_path *path,
2281 u64 bytenr, int cow);
2282 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
2283 struct btrfs_root *root, struct btrfs_path *path,