Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 #ifndef _BTRFS_CTREE_H_
0003 #define _BTRFS_CTREE_H_
0004 
0005 #include <linux/btrfs.h>
0006 #include <linux/types.h>
0007 #ifdef __KERNEL__
0008 #include <linux/stddef.h>
0009 #else
0010 #include <stddef.h>
0011 #endif
0012 
0013 /*
0014  * This header contains the structure definitions and constants used
0015  * by file system objects that can be retrieved using
0016  * the BTRFS_IOC_SEARCH_TREE ioctl.  That means basically anything that
0017  * is needed to describe a leaf node's key or item contents.
0018  */
0019 
0020 /* holds pointers to all of the tree roots */
0021 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
0022 
0023 /* stores information about which extents are in use, and reference counts */
0024 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
0025 
0026 /*
0027  * chunk tree stores translations from logical -> physical block numbering
0028  * the super block points to the chunk tree
0029  */
0030 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
0031 
0032 /*
0033  * stores information about which areas of a given device are in use.
0034  * one per device.  The tree of tree roots points to the device tree
0035  */
0036 #define BTRFS_DEV_TREE_OBJECTID 4ULL
0037 
0038 /* one per subvolume, storing files and directories */
0039 #define BTRFS_FS_TREE_OBJECTID 5ULL
0040 
0041 /* directory objectid inside the root tree */
0042 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
0043 
0044 /* holds checksums of all the data extents */
0045 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
0046 
0047 /* holds quota configuration and tracking */
0048 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
0049 
0050 /* for storing items that use the BTRFS_UUID_KEY* types */
0051 #define BTRFS_UUID_TREE_OBJECTID 9ULL
0052 
0053 /* tracks free space in block groups. */
0054 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
0055 
0056 /* Holds the block group items for extent tree v2. */
0057 #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
0058 
0059 /* device stats in the device tree */
0060 #define BTRFS_DEV_STATS_OBJECTID 0ULL
0061 
0062 /* for storing balance parameters in the root tree */
0063 #define BTRFS_BALANCE_OBJECTID -4ULL
0064 
0065 /* orphan objectid for tracking unlinked/truncated files */
0066 #define BTRFS_ORPHAN_OBJECTID -5ULL
0067 
0068 /* does write ahead logging to speed up fsyncs */
0069 #define BTRFS_TREE_LOG_OBJECTID -6ULL
0070 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
0071 
0072 /* for space balancing */
0073 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
0074 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
0075 
0076 /*
0077  * extent checksums all have this objectid
0078  * this allows them to share the logging tree
0079  * for fsyncs
0080  */
0081 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
0082 
0083 /* For storing free space cache */
0084 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
0085 
0086 /*
0087  * The inode number assigned to the special inode for storing
0088  * free ino cache
0089  */
0090 #define BTRFS_FREE_INO_OBJECTID -12ULL
0091 
0092 /* dummy objectid represents multiple objectids */
0093 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
0094 
0095 /*
0096  * All files have objectids in this range.
0097  */
0098 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
0099 #define BTRFS_LAST_FREE_OBJECTID -256ULL
0100 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
0101 
0102 
0103 /*
0104  * the device items go into the chunk tree.  The key is in the form
0105  * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
0106  */
0107 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
0108 
0109 #define BTRFS_BTREE_INODE_OBJECTID 1
0110 
0111 #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
0112 
0113 #define BTRFS_DEV_REPLACE_DEVID 0ULL
0114 
0115 /*
0116  * inode items have the data typically returned from stat and store other
0117  * info about object characteristics.  There is one for every file and dir in
0118  * the FS
0119  */
0120 #define BTRFS_INODE_ITEM_KEY        1
0121 #define BTRFS_INODE_REF_KEY     12
0122 #define BTRFS_INODE_EXTREF_KEY      13
0123 #define BTRFS_XATTR_ITEM_KEY        24
0124 
0125 /*
0126  * fs verity items are stored under two different key types on disk.
0127  * The descriptor items:
0128  * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
0129  *
0130  * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
0131  * of the descriptor item and some extra data for encryption.
0132  * Starting at offset 1, these hold the generic fs verity descriptor.  The
0133  * latter are opaque to btrfs, we just read and write them as a blob for the
0134  * higher level verity code.  The most common descriptor size is 256 bytes.
0135  *
0136  * The merkle tree items:
0137  * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
0138  *
0139  * These also start at offset 0, and correspond to the merkle tree bytes.  When
0140  * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
0141  * offset 0 for this key type.  These are also opaque to btrfs, we're blindly
0142  * storing whatever fsverity sends down.
0143  */
0144 #define BTRFS_VERITY_DESC_ITEM_KEY  36
0145 #define BTRFS_VERITY_MERKLE_ITEM_KEY    37
0146 
0147 #define BTRFS_ORPHAN_ITEM_KEY       48
0148 /* reserve 2-15 close to the inode for later flexibility */
0149 
0150 /*
0151  * dir items are the name -> inode pointers in a directory.  There is one
0152  * for every name in a directory.  BTRFS_DIR_LOG_ITEM_KEY is no longer used
0153  * but it's still defined here for documentation purposes and to help avoid
0154  * having its numerical value reused in the future.
0155  */
0156 #define BTRFS_DIR_LOG_ITEM_KEY  60
0157 #define BTRFS_DIR_LOG_INDEX_KEY 72
0158 #define BTRFS_DIR_ITEM_KEY  84
0159 #define BTRFS_DIR_INDEX_KEY 96
0160 /*
0161  * extent data is for file data
0162  */
0163 #define BTRFS_EXTENT_DATA_KEY   108
0164 
0165 /*
0166  * extent csums are stored in a separate tree and hold csums for
0167  * an entire extent on disk.
0168  */
0169 #define BTRFS_EXTENT_CSUM_KEY   128
0170 
0171 /*
0172  * root items point to tree roots.  They are typically in the root
0173  * tree used by the super block to find all the other trees
0174  */
0175 #define BTRFS_ROOT_ITEM_KEY 132
0176 
0177 /*
0178  * root backrefs tie subvols and snapshots to the directory entries that
0179  * reference them
0180  */
0181 #define BTRFS_ROOT_BACKREF_KEY  144
0182 
0183 /*
0184  * root refs make a fast index for listing all of the snapshots and
0185  * subvolumes referenced by a given root.  They point directly to the
0186  * directory item in the root that references the subvol
0187  */
0188 #define BTRFS_ROOT_REF_KEY  156
0189 
0190 /*
0191  * extent items are in the extent map tree.  These record which blocks
0192  * are used, and how many references there are to each block
0193  */
0194 #define BTRFS_EXTENT_ITEM_KEY   168
0195 
0196 /*
0197  * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
0198  * the length, so we save the level in key->offset instead of the length.
0199  */
0200 #define BTRFS_METADATA_ITEM_KEY 169
0201 
0202 #define BTRFS_TREE_BLOCK_REF_KEY    176
0203 
0204 #define BTRFS_EXTENT_DATA_REF_KEY   178
0205 
0206 #define BTRFS_EXTENT_REF_V0_KEY     180
0207 
0208 #define BTRFS_SHARED_BLOCK_REF_KEY  182
0209 
0210 #define BTRFS_SHARED_DATA_REF_KEY   184
0211 
0212 /*
0213  * block groups give us hints into the extent allocation trees.  Which
0214  * blocks are free etc etc
0215  */
0216 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
0217 
0218 /*
0219  * Every block group is represented in the free space tree by a free space info
0220  * item, which stores some accounting information. It is keyed on
0221  * (block_group_start, FREE_SPACE_INFO, block_group_length).
0222  */
0223 #define BTRFS_FREE_SPACE_INFO_KEY 198
0224 
0225 /*
0226  * A free space extent tracks an extent of space that is free in a block group.
0227  * It is keyed on (start, FREE_SPACE_EXTENT, length).
0228  */
0229 #define BTRFS_FREE_SPACE_EXTENT_KEY 199
0230 
0231 /*
0232  * When a block group becomes very fragmented, we convert it to use bitmaps
0233  * instead of extents. A free space bitmap is keyed on
0234  * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
0235  * (length / sectorsize) bits.
0236  */
0237 #define BTRFS_FREE_SPACE_BITMAP_KEY 200
0238 
0239 #define BTRFS_DEV_EXTENT_KEY    204
0240 #define BTRFS_DEV_ITEM_KEY  216
0241 #define BTRFS_CHUNK_ITEM_KEY    228
0242 
0243 /*
0244  * Records the overall state of the qgroups.
0245  * There's only one instance of this key present,
0246  * (0, BTRFS_QGROUP_STATUS_KEY, 0)
0247  */
0248 #define BTRFS_QGROUP_STATUS_KEY         240
0249 /*
0250  * Records the currently used space of the qgroup.
0251  * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
0252  */
0253 #define BTRFS_QGROUP_INFO_KEY           242
0254 /*
0255  * Contains the user configured limits for the qgroup.
0256  * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
0257  */
0258 #define BTRFS_QGROUP_LIMIT_KEY          244
0259 /*
0260  * Records the child-parent relationship of qgroups. For
0261  * each relation, 2 keys are present:
0262  * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
0263  * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
0264  */
0265 #define BTRFS_QGROUP_RELATION_KEY       246
0266 
0267 /*
0268  * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
0269  */
0270 #define BTRFS_BALANCE_ITEM_KEY  248
0271 
0272 /*
0273  * The key type for tree items that are stored persistently, but do not need to
0274  * exist for extended period of time. The items can exist in any tree.
0275  *
0276  * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
0277  *
0278  * Existing items:
0279  *
0280  * - balance status item
0281  *   (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
0282  */
0283 #define BTRFS_TEMPORARY_ITEM_KEY    248
0284 
0285 /*
0286  * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
0287  */
0288 #define BTRFS_DEV_STATS_KEY     249
0289 
0290 /*
0291  * The key type for tree items that are stored persistently and usually exist
0292  * for a long period, eg. filesystem lifetime. The item kinds can be status
0293  * information, stats or preference values. The item can exist in any tree.
0294  *
0295  * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
0296  *
0297  * Existing items:
0298  *
0299  * - device statistics, store IO stats in the device tree, one key for all
0300  *   stats
0301  *   (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
0302  */
0303 #define BTRFS_PERSISTENT_ITEM_KEY   249
0304 
0305 /*
0306  * Persistently stores the device replace state in the device tree.
0307  * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
0308  */
0309 #define BTRFS_DEV_REPLACE_KEY   250
0310 
0311 /*
0312  * Stores items that allow to quickly map UUIDs to something else.
0313  * These items are part of the filesystem UUID tree.
0314  * The key is built like this:
0315  * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
0316  */
0317 #if BTRFS_UUID_SIZE != 16
0318 #error "UUID items require BTRFS_UUID_SIZE == 16!"
0319 #endif
0320 #define BTRFS_UUID_KEY_SUBVOL   251 /* for UUIDs assigned to subvols */
0321 #define BTRFS_UUID_KEY_RECEIVED_SUBVOL  252 /* for UUIDs assigned to
0322                          * received subvols */
0323 
0324 /*
0325  * string items are for debugging.  They just store a short string of
0326  * data in the FS
0327  */
0328 #define BTRFS_STRING_ITEM_KEY   253
0329 
0330 /* Maximum metadata block size (nodesize) */
0331 #define BTRFS_MAX_METADATA_BLOCKSIZE            65536
0332 
0333 /* 32 bytes in various csum fields */
0334 #define BTRFS_CSUM_SIZE 32
0335 
0336 /* csum types */
0337 enum btrfs_csum_type {
0338     BTRFS_CSUM_TYPE_CRC32   = 0,
0339     BTRFS_CSUM_TYPE_XXHASH  = 1,
0340     BTRFS_CSUM_TYPE_SHA256  = 2,
0341     BTRFS_CSUM_TYPE_BLAKE2  = 3,
0342 };
0343 
0344 /*
0345  * flags definitions for directory entry item type
0346  *
0347  * Used by:
0348  * struct btrfs_dir_item.type
0349  *
0350  * Values 0..7 must match common file type values in fs_types.h.
0351  */
0352 #define BTRFS_FT_UNKNOWN    0
0353 #define BTRFS_FT_REG_FILE   1
0354 #define BTRFS_FT_DIR        2
0355 #define BTRFS_FT_CHRDEV     3
0356 #define BTRFS_FT_BLKDEV     4
0357 #define BTRFS_FT_FIFO       5
0358 #define BTRFS_FT_SOCK       6
0359 #define BTRFS_FT_SYMLINK    7
0360 #define BTRFS_FT_XATTR      8
0361 #define BTRFS_FT_MAX        9
0362 
0363 /*
0364  * The key defines the order in the tree, and so it also defines (optimal)
0365  * block layout.
0366  *
0367  * objectid corresponds to the inode number.
0368  *
0369  * type tells us things about the object, and is a kind of stream selector.
0370  * so for a given inode, keys with type of 1 might refer to the inode data,
0371  * type of 2 may point to file data in the btree and type == 3 may point to
0372  * extents.
0373  *
0374  * offset is the starting byte offset for this key in the stream.
0375  *
0376  * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
0377  * in cpu native order.  Otherwise they are identical and their sizes
0378  * should be the same (ie both packed)
0379  */
0380 struct btrfs_disk_key {
0381     __le64 objectid;
0382     __u8 type;
0383     __le64 offset;
0384 } __attribute__ ((__packed__));
0385 
0386 struct btrfs_key {
0387     __u64 objectid;
0388     __u8 type;
0389     __u64 offset;
0390 } __attribute__ ((__packed__));
0391 
0392 struct btrfs_dev_item {
0393     /* the internal btrfs device id */
0394     __le64 devid;
0395 
0396     /* size of the device */
0397     __le64 total_bytes;
0398 
0399     /* bytes used */
0400     __le64 bytes_used;
0401 
0402     /* optimal io alignment for this device */
0403     __le32 io_align;
0404 
0405     /* optimal io width for this device */
0406     __le32 io_width;
0407 
0408     /* minimal io size for this device */
0409     __le32 sector_size;
0410 
0411     /* type and info about this device */
0412     __le64 type;
0413 
0414     /* expected generation for this device */
0415     __le64 generation;
0416 
0417     /*
0418      * starting byte of this partition on the device,
0419      * to allow for stripe alignment in the future
0420      */
0421     __le64 start_offset;
0422 
0423     /* grouping information for allocation decisions */
0424     __le32 dev_group;
0425 
0426     /* seek speed 0-100 where 100 is fastest */
0427     __u8 seek_speed;
0428 
0429     /* bandwidth 0-100 where 100 is fastest */
0430     __u8 bandwidth;
0431 
0432     /* btrfs generated uuid for this device */
0433     __u8 uuid[BTRFS_UUID_SIZE];
0434 
0435     /* uuid of FS who owns this device */
0436     __u8 fsid[BTRFS_UUID_SIZE];
0437 } __attribute__ ((__packed__));
0438 
0439 struct btrfs_stripe {
0440     __le64 devid;
0441     __le64 offset;
0442     __u8 dev_uuid[BTRFS_UUID_SIZE];
0443 } __attribute__ ((__packed__));
0444 
0445 struct btrfs_chunk {
0446     /* size of this chunk in bytes */
0447     __le64 length;
0448 
0449     /* objectid of the root referencing this chunk */
0450     __le64 owner;
0451 
0452     __le64 stripe_len;
0453     __le64 type;
0454 
0455     /* optimal io alignment for this chunk */
0456     __le32 io_align;
0457 
0458     /* optimal io width for this chunk */
0459     __le32 io_width;
0460 
0461     /* minimal io size for this chunk */
0462     __le32 sector_size;
0463 
0464     /* 2^16 stripes is quite a lot, a second limit is the size of a single
0465      * item in the btree
0466      */
0467     __le16 num_stripes;
0468 
0469     /* sub stripes only matter for raid10 */
0470     __le16 sub_stripes;
0471     struct btrfs_stripe stripe;
0472     /* additional stripes go here */
0473 } __attribute__ ((__packed__));
0474 
0475 #define BTRFS_FREE_SPACE_EXTENT 1
0476 #define BTRFS_FREE_SPACE_BITMAP 2
0477 
0478 struct btrfs_free_space_entry {
0479     __le64 offset;
0480     __le64 bytes;
0481     __u8 type;
0482 } __attribute__ ((__packed__));
0483 
0484 struct btrfs_free_space_header {
0485     struct btrfs_disk_key location;
0486     __le64 generation;
0487     __le64 num_entries;
0488     __le64 num_bitmaps;
0489 } __attribute__ ((__packed__));
0490 
0491 #define BTRFS_HEADER_FLAG_WRITTEN   (1ULL << 0)
0492 #define BTRFS_HEADER_FLAG_RELOC     (1ULL << 1)
0493 
0494 /* Super block flags */
0495 /* Errors detected */
0496 #define BTRFS_SUPER_FLAG_ERROR      (1ULL << 2)
0497 
0498 #define BTRFS_SUPER_FLAG_SEEDING    (1ULL << 32)
0499 #define BTRFS_SUPER_FLAG_METADUMP   (1ULL << 33)
0500 #define BTRFS_SUPER_FLAG_METADUMP_V2    (1ULL << 34)
0501 #define BTRFS_SUPER_FLAG_CHANGING_FSID  (1ULL << 35)
0502 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
0503 
0504 
0505 /*
0506  * items in the extent btree are used to record the objectid of the
0507  * owner of the block and the number of references
0508  */
0509 
0510 struct btrfs_extent_item {
0511     __le64 refs;
0512     __le64 generation;
0513     __le64 flags;
0514 } __attribute__ ((__packed__));
0515 
0516 struct btrfs_extent_item_v0 {
0517     __le32 refs;
0518 } __attribute__ ((__packed__));
0519 
0520 
0521 #define BTRFS_EXTENT_FLAG_DATA      (1ULL << 0)
0522 #define BTRFS_EXTENT_FLAG_TREE_BLOCK    (1ULL << 1)
0523 
0524 /* following flags only apply to tree blocks */
0525 
0526 /* use full backrefs for extent pointers in the block */
0527 #define BTRFS_BLOCK_FLAG_FULL_BACKREF   (1ULL << 8)
0528 
0529 /*
0530  * this flag is only used internally by scrub and may be changed at any time
0531  * it is only declared here to avoid collisions
0532  */
0533 #define BTRFS_EXTENT_FLAG_SUPER     (1ULL << 48)
0534 
0535 struct btrfs_tree_block_info {
0536     struct btrfs_disk_key key;
0537     __u8 level;
0538 } __attribute__ ((__packed__));
0539 
0540 struct btrfs_extent_data_ref {
0541     __le64 root;
0542     __le64 objectid;
0543     __le64 offset;
0544     __le32 count;
0545 } __attribute__ ((__packed__));
0546 
0547 struct btrfs_shared_data_ref {
0548     __le32 count;
0549 } __attribute__ ((__packed__));
0550 
0551 struct btrfs_extent_inline_ref {
0552     __u8 type;
0553     __le64 offset;
0554 } __attribute__ ((__packed__));
0555 
0556 /* dev extents record free space on individual devices.  The owner
0557  * field points back to the chunk allocation mapping tree that allocated
0558  * the extent.  The chunk tree uuid field is a way to double check the owner
0559  */
0560 struct btrfs_dev_extent {
0561     __le64 chunk_tree;
0562     __le64 chunk_objectid;
0563     __le64 chunk_offset;
0564     __le64 length;
0565     __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
0566 } __attribute__ ((__packed__));
0567 
0568 struct btrfs_inode_ref {
0569     __le64 index;
0570     __le16 name_len;
0571     /* name goes here */
0572 } __attribute__ ((__packed__));
0573 
0574 struct btrfs_inode_extref {
0575     __le64 parent_objectid;
0576     __le64 index;
0577     __le16 name_len;
0578     __u8   name[];
0579     /* name goes here */
0580 } __attribute__ ((__packed__));
0581 
0582 struct btrfs_timespec {
0583     __le64 sec;
0584     __le32 nsec;
0585 } __attribute__ ((__packed__));
0586 
0587 struct btrfs_inode_item {
0588     /* nfs style generation number */
0589     __le64 generation;
0590     /* transid that last touched this inode */
0591     __le64 transid;
0592     __le64 size;
0593     __le64 nbytes;
0594     __le64 block_group;
0595     __le32 nlink;
0596     __le32 uid;
0597     __le32 gid;
0598     __le32 mode;
0599     __le64 rdev;
0600     __le64 flags;
0601 
0602     /* modification sequence number for NFS */
0603     __le64 sequence;
0604 
0605     /*
0606      * a little future expansion, for more than this we can
0607      * just grow the inode item and version it
0608      */
0609     __le64 reserved[4];
0610     struct btrfs_timespec atime;
0611     struct btrfs_timespec ctime;
0612     struct btrfs_timespec mtime;
0613     struct btrfs_timespec otime;
0614 } __attribute__ ((__packed__));
0615 
0616 struct btrfs_dir_log_item {
0617     __le64 end;
0618 } __attribute__ ((__packed__));
0619 
0620 struct btrfs_dir_item {
0621     struct btrfs_disk_key location;
0622     __le64 transid;
0623     __le16 data_len;
0624     __le16 name_len;
0625     __u8 type;
0626 } __attribute__ ((__packed__));
0627 
0628 #define BTRFS_ROOT_SUBVOL_RDONLY    (1ULL << 0)
0629 
0630 /*
0631  * Internal in-memory flag that a subvolume has been marked for deletion but
0632  * still visible as a directory
0633  */
0634 #define BTRFS_ROOT_SUBVOL_DEAD      (1ULL << 48)
0635 
0636 struct btrfs_root_item {
0637     struct btrfs_inode_item inode;
0638     __le64 generation;
0639     __le64 root_dirid;
0640     __le64 bytenr;
0641     __le64 byte_limit;
0642     __le64 bytes_used;
0643     __le64 last_snapshot;
0644     __le64 flags;
0645     __le32 refs;
0646     struct btrfs_disk_key drop_progress;
0647     __u8 drop_level;
0648     __u8 level;
0649 
0650     /*
0651      * The following fields appear after subvol_uuids+subvol_times
0652      * were introduced.
0653      */
0654 
0655     /*
0656      * This generation number is used to test if the new fields are valid
0657      * and up to date while reading the root item. Every time the root item
0658      * is written out, the "generation" field is copied into this field. If
0659      * anyone ever mounted the fs with an older kernel, we will have
0660      * mismatching generation values here and thus must invalidate the
0661      * new fields. See btrfs_update_root and btrfs_find_last_root for
0662      * details.
0663      * the offset of generation_v2 is also used as the start for the memset
0664      * when invalidating the fields.
0665      */
0666     __le64 generation_v2;
0667     __u8 uuid[BTRFS_UUID_SIZE];
0668     __u8 parent_uuid[BTRFS_UUID_SIZE];
0669     __u8 received_uuid[BTRFS_UUID_SIZE];
0670     __le64 ctransid; /* updated when an inode changes */
0671     __le64 otransid; /* trans when created */
0672     __le64 stransid; /* trans when sent. non-zero for received subvol */
0673     __le64 rtransid; /* trans when received. non-zero for received subvol */
0674     struct btrfs_timespec ctime;
0675     struct btrfs_timespec otime;
0676     struct btrfs_timespec stime;
0677     struct btrfs_timespec rtime;
0678     __le64 reserved[8]; /* for future */
0679 } __attribute__ ((__packed__));
0680 
0681 /*
0682  * Btrfs root item used to be smaller than current size.  The old format ends
0683  * at where member generation_v2 is.
0684  */
0685 static inline __u32 btrfs_legacy_root_item_size(void)
0686 {
0687     return offsetof(struct btrfs_root_item, generation_v2);
0688 }
0689 
0690 /*
0691  * this is used for both forward and backward root refs
0692  */
0693 struct btrfs_root_ref {
0694     __le64 dirid;
0695     __le64 sequence;
0696     __le16 name_len;
0697 } __attribute__ ((__packed__));
0698 
0699 struct btrfs_disk_balance_args {
0700     /*
0701      * profiles to operate on, single is denoted by
0702      * BTRFS_AVAIL_ALLOC_BIT_SINGLE
0703      */
0704     __le64 profiles;
0705 
0706     /*
0707      * usage filter
0708      * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
0709      * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
0710      */
0711     union {
0712         __le64 usage;
0713         struct {
0714             __le32 usage_min;
0715             __le32 usage_max;
0716         };
0717     };
0718 
0719     /* devid filter */
0720     __le64 devid;
0721 
0722     /* devid subset filter [pstart..pend) */
0723     __le64 pstart;
0724     __le64 pend;
0725 
0726     /* btrfs virtual address space subset filter [vstart..vend) */
0727     __le64 vstart;
0728     __le64 vend;
0729 
0730     /*
0731      * profile to convert to, single is denoted by
0732      * BTRFS_AVAIL_ALLOC_BIT_SINGLE
0733      */
0734     __le64 target;
0735 
0736     /* BTRFS_BALANCE_ARGS_* */
0737     __le64 flags;
0738 
0739     /*
0740      * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
0741      * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
0742      * and maximum
0743      */
0744     union {
0745         __le64 limit;
0746         struct {
0747             __le32 limit_min;
0748             __le32 limit_max;
0749         };
0750     };
0751 
0752     /*
0753      * Process chunks that cross stripes_min..stripes_max devices,
0754      * BTRFS_BALANCE_ARGS_STRIPES_RANGE
0755      */
0756     __le32 stripes_min;
0757     __le32 stripes_max;
0758 
0759     __le64 unused[6];
0760 } __attribute__ ((__packed__));
0761 
0762 /*
0763  * store balance parameters to disk so that balance can be properly
0764  * resumed after crash or unmount
0765  */
0766 struct btrfs_balance_item {
0767     /* BTRFS_BALANCE_* */
0768     __le64 flags;
0769 
0770     struct btrfs_disk_balance_args data;
0771     struct btrfs_disk_balance_args meta;
0772     struct btrfs_disk_balance_args sys;
0773 
0774     __le64 unused[4];
0775 } __attribute__ ((__packed__));
0776 
0777 enum {
0778     BTRFS_FILE_EXTENT_INLINE   = 0,
0779     BTRFS_FILE_EXTENT_REG      = 1,
0780     BTRFS_FILE_EXTENT_PREALLOC = 2,
0781     BTRFS_NR_FILE_EXTENT_TYPES = 3,
0782 };
0783 
0784 struct btrfs_file_extent_item {
0785     /*
0786      * transaction id that created this extent
0787      */
0788     __le64 generation;
0789     /*
0790      * max number of bytes to hold this extent in ram
0791      * when we split a compressed extent we can't know how big
0792      * each of the resulting pieces will be.  So, this is
0793      * an upper limit on the size of the extent in ram instead of
0794      * an exact limit.
0795      */
0796     __le64 ram_bytes;
0797 
0798     /*
0799      * 32 bits for the various ways we might encode the data,
0800      * including compression and encryption.  If any of these
0801      * are set to something a given disk format doesn't understand
0802      * it is treated like an incompat flag for reading and writing,
0803      * but not for stat.
0804      */
0805     __u8 compression;
0806     __u8 encryption;
0807     __le16 other_encoding; /* spare for later use */
0808 
0809     /* are we inline data or a real extent? */
0810     __u8 type;
0811 
0812     /*
0813      * disk space consumed by the extent, checksum blocks are included
0814      * in these numbers
0815      *
0816      * At this offset in the structure, the inline extent data start.
0817      */
0818     __le64 disk_bytenr;
0819     __le64 disk_num_bytes;
0820     /*
0821      * the logical offset in file blocks (no csums)
0822      * this extent record is for.  This allows a file extent to point
0823      * into the middle of an existing extent on disk, sharing it
0824      * between two snapshots (useful if some bytes in the middle of the
0825      * extent have changed
0826      */
0827     __le64 offset;
0828     /*
0829      * the logical number of file blocks (no csums included).  This
0830      * always reflects the size uncompressed and without encoding.
0831      */
0832     __le64 num_bytes;
0833 
0834 } __attribute__ ((__packed__));
0835 
0836 struct btrfs_csum_item {
0837     __u8 csum;
0838 } __attribute__ ((__packed__));
0839 
0840 struct btrfs_dev_stats_item {
0841     /*
0842      * grow this item struct at the end for future enhancements and keep
0843      * the existing values unchanged
0844      */
0845     __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
0846 } __attribute__ ((__packed__));
0847 
0848 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
0849 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID  1
0850 
0851 struct btrfs_dev_replace_item {
0852     /*
0853      * grow this item struct at the end for future enhancements and keep
0854      * the existing values unchanged
0855      */
0856     __le64 src_devid;
0857     __le64 cursor_left;
0858     __le64 cursor_right;
0859     __le64 cont_reading_from_srcdev_mode;
0860 
0861     __le64 replace_state;
0862     __le64 time_started;
0863     __le64 time_stopped;
0864     __le64 num_write_errors;
0865     __le64 num_uncorrectable_read_errors;
0866 } __attribute__ ((__packed__));
0867 
0868 /* different types of block groups (and chunks) */
0869 #define BTRFS_BLOCK_GROUP_DATA      (1ULL << 0)
0870 #define BTRFS_BLOCK_GROUP_SYSTEM    (1ULL << 1)
0871 #define BTRFS_BLOCK_GROUP_METADATA  (1ULL << 2)
0872 #define BTRFS_BLOCK_GROUP_RAID0     (1ULL << 3)
0873 #define BTRFS_BLOCK_GROUP_RAID1     (1ULL << 4)
0874 #define BTRFS_BLOCK_GROUP_DUP       (1ULL << 5)
0875 #define BTRFS_BLOCK_GROUP_RAID10    (1ULL << 6)
0876 #define BTRFS_BLOCK_GROUP_RAID5         (1ULL << 7)
0877 #define BTRFS_BLOCK_GROUP_RAID6         (1ULL << 8)
0878 #define BTRFS_BLOCK_GROUP_RAID1C3       (1ULL << 9)
0879 #define BTRFS_BLOCK_GROUP_RAID1C4       (1ULL << 10)
0880 #define BTRFS_BLOCK_GROUP_RESERVED  (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
0881                      BTRFS_SPACE_INFO_GLOBAL_RSV)
0882 
0883 #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA |    \
0884                      BTRFS_BLOCK_GROUP_SYSTEM |  \
0885                      BTRFS_BLOCK_GROUP_METADATA)
0886 
0887 #define BTRFS_BLOCK_GROUP_PROFILE_MASK  (BTRFS_BLOCK_GROUP_RAID0 |   \
0888                      BTRFS_BLOCK_GROUP_RAID1 |   \
0889                      BTRFS_BLOCK_GROUP_RAID1C3 | \
0890                      BTRFS_BLOCK_GROUP_RAID1C4 | \
0891                      BTRFS_BLOCK_GROUP_RAID5 |   \
0892                      BTRFS_BLOCK_GROUP_RAID6 |   \
0893                      BTRFS_BLOCK_GROUP_DUP |     \
0894                      BTRFS_BLOCK_GROUP_RAID10)
0895 #define BTRFS_BLOCK_GROUP_RAID56_MASK   (BTRFS_BLOCK_GROUP_RAID5 |   \
0896                      BTRFS_BLOCK_GROUP_RAID6)
0897 
0898 #define BTRFS_BLOCK_GROUP_RAID1_MASK    (BTRFS_BLOCK_GROUP_RAID1 |   \
0899                      BTRFS_BLOCK_GROUP_RAID1C3 | \
0900                      BTRFS_BLOCK_GROUP_RAID1C4)
0901 
0902 /*
0903  * We need a bit for restriper to be able to tell when chunks of type
0904  * SINGLE are available.  This "extended" profile format is used in
0905  * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
0906  * (on-disk).  The corresponding on-disk bit in chunk.type is reserved
0907  * to avoid remappings between two formats in future.
0908  */
0909 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE    (1ULL << 48)
0910 
0911 /*
0912  * A fake block group type that is used to communicate global block reserve
0913  * size to userspace via the SPACE_INFO ioctl.
0914  */
0915 #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
0916 
0917 #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
0918                      BTRFS_AVAIL_ALLOC_BIT_SINGLE)
0919 
0920 static inline __u64 chunk_to_extended(__u64 flags)
0921 {
0922     if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
0923         flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
0924 
0925     return flags;
0926 }
0927 static inline __u64 extended_to_chunk(__u64 flags)
0928 {
0929     return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
0930 }
0931 
0932 struct btrfs_block_group_item {
0933     __le64 used;
0934     __le64 chunk_objectid;
0935     __le64 flags;
0936 } __attribute__ ((__packed__));
0937 
0938 struct btrfs_free_space_info {
0939     __le32 extent_count;
0940     __le32 flags;
0941 } __attribute__ ((__packed__));
0942 
0943 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
0944 
0945 #define BTRFS_QGROUP_LEVEL_SHIFT        48
0946 static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
0947 {
0948     return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
0949 }
0950 
0951 /*
0952  * is subvolume quota turned on?
0953  */
0954 #define BTRFS_QGROUP_STATUS_FLAG_ON     (1ULL << 0)
0955 /*
0956  * RESCAN is set during the initialization phase
0957  */
0958 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN     (1ULL << 1)
0959 /*
0960  * Some qgroup entries are known to be out of date,
0961  * either because the configuration has changed in a way that
0962  * makes a rescan necessary, or because the fs has been mounted
0963  * with a non-qgroup-aware version.
0964  * Turning qouta off and on again makes it inconsistent, too.
0965  */
0966 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT   (1ULL << 2)
0967 
0968 #define BTRFS_QGROUP_STATUS_VERSION        1
0969 
0970 struct btrfs_qgroup_status_item {
0971     __le64 version;
0972     /*
0973      * the generation is updated during every commit. As older
0974      * versions of btrfs are not aware of qgroups, it will be
0975      * possible to detect inconsistencies by checking the
0976      * generation on mount time
0977      */
0978     __le64 generation;
0979 
0980     /* flag definitions see above */
0981     __le64 flags;
0982 
0983     /*
0984      * only used during scanning to record the progress
0985      * of the scan. It contains a logical address
0986      */
0987     __le64 rescan;
0988 } __attribute__ ((__packed__));
0989 
0990 struct btrfs_qgroup_info_item {
0991     __le64 generation;
0992     __le64 rfer;
0993     __le64 rfer_cmpr;
0994     __le64 excl;
0995     __le64 excl_cmpr;
0996 } __attribute__ ((__packed__));
0997 
0998 struct btrfs_qgroup_limit_item {
0999     /*
1000      * only updated when any of the other values change
1001      */
1002     __le64 flags;
1003     __le64 max_rfer;
1004     __le64 max_excl;
1005     __le64 rsv_rfer;
1006     __le64 rsv_excl;
1007 } __attribute__ ((__packed__));
1008 
1009 struct btrfs_verity_descriptor_item {
1010     /* Size of the verity descriptor in bytes */
1011     __le64 size;
1012     /*
1013      * When we implement support for fscrypt, we will need to encrypt the
1014      * Merkle tree for encrypted verity files. These 128 bits are for the
1015      * eventual storage of an fscrypt initialization vector.
1016      */
1017     __le64 reserved[2];
1018     __u8 encryption;
1019 } __attribute__ ((__packed__));
1020 
1021 #endif /* _BTRFS_CTREE_H_ */