1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * Copied from kernel/include/uapi/linux/btrfs_btree.h.
5 * Only modified the header.
7 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
8 #ifndef __BTRFS_TREE_H__
9 #define __BTRFS_TREE_H__
11 #include <linux/types.h>
13 #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
16 * The max metadata block size (node size).
18 * This limit is somewhat artificial. The memmove and tree block locking cost
19 * go up with larger node size.
21 #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
24 * We can actually store much bigger names, but lets not confuse the rest
27 * btrfs_dir_item::name_len follows this limitation.
29 #define BTRFS_NAME_LEN 255
32 * Objectids start from here.
34 * Check btrfs_disk_key for the meaning of objectids.
38 * Root tree holds pointers to all of the tree roots.
39 * Without special mention, the root tree contains the root bytenr of all other
40 * trees, except the chunk tree and the log tree.
42 * The super block contains the root bytenr of this tree.
44 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
47 * Extent tree stores information about which extents are in use, and backrefs
50 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
53 * Chunk tree stores btrfs logical address -> physical address mapping.
55 * The super block contains part of chunk tree for bootstrap, and contains
56 * the root bytenr of this tree.
58 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
61 * Device tree stores info about which areas of a given device are in use,
62 * and physical address -> btrfs logical address mapping.
64 #define BTRFS_DEV_TREE_OBJECTID 4ULL
66 /* The fs tree is the first subvolume tree, storing files and directories. */
67 #define BTRFS_FS_TREE_OBJECTID 5ULL
69 /* Shows the directory objectid inside the root tree. */
70 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
72 /* Csum tree holds checksums of all the data extents. */
73 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
75 /* Quota tree holds quota configuration and tracking. */
76 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
78 /* UUID tree stores items that use the BTRFS_UUID_KEY* types. */
79 #define BTRFS_UUID_TREE_OBJECTID 9ULL
81 /* Free space cache tree (v2 space cache) tracks free space in block groups. */
82 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
84 /* Indicates device stats in the device tree. */
85 #define BTRFS_DEV_STATS_OBJECTID 0ULL
87 /* For storing balance parameters in the root tree. */
88 #define BTRFS_BALANCE_OBJECTID -4ULL
90 /* Orhpan objectid for tracking unlinked/truncated files. */
91 #define BTRFS_ORPHAN_OBJECTID -5ULL
93 /* Does write ahead logging to speed up fsyncs. */
94 #define BTRFS_TREE_LOG_OBJECTID -6ULL
95 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
97 /* For space balancing. */
98 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
99 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
101 /* Extent checksums, shared between the csum tree and log trees. */
102 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
104 /* For storing free space cache (v1 space cache). */
105 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
107 /* The inode number assigned to the special inode for storing free ino cache. */
108 #define BTRFS_FREE_INO_OBJECTID -12ULL
110 /* Dummy objectid represents multiple objectids. */
111 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
113 /* All files have objectids in this range. */
114 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
115 #define BTRFS_LAST_FREE_OBJECTID -256ULL
116 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
120 * The device items go into the chunk tree.
122 * The key is in the form
123 * (BTRFS_DEV_ITEMS_OBJECTID, BTRFS_DEV_ITEM_KEY, <device_id>)
125 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
127 #define BTRFS_BTREE_INODE_OBJECTID 1
129 #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
131 #define BTRFS_DEV_REPLACE_DEVID 0ULL
134 * Types start from here.
136 * Check btrfs_disk_key for details about types.
140 * Inode items have the data typically returned from stat and store other
141 * info about object characteristics.
143 * There is one for every file and dir in the FS.
145 #define BTRFS_INODE_ITEM_KEY 1
146 /* reserve 2-11 close to the inode for later flexibility */
147 #define BTRFS_INODE_REF_KEY 12
148 #define BTRFS_INODE_EXTREF_KEY 13
149 #define BTRFS_XATTR_ITEM_KEY 24
150 #define BTRFS_ORPHAN_ITEM_KEY 48
153 * Dir items are the name -> inode pointers in a directory.
155 * There is one for every name in a directory.
157 #define BTRFS_DIR_LOG_ITEM_KEY 60
158 #define BTRFS_DIR_LOG_INDEX_KEY 72
159 #define BTRFS_DIR_ITEM_KEY 84
160 #define BTRFS_DIR_INDEX_KEY 96
162 /* Stores info (position, size ...) about a data extent of a file */
163 #define BTRFS_EXTENT_DATA_KEY 108
166 * Extent csums are stored in a separate tree and hold csums for
167 * an entire extent on disk.
169 #define BTRFS_EXTENT_CSUM_KEY 128
172 * Root items point to tree roots.
174 * They are typically in the root tree used by the super block to find all the
177 #define BTRFS_ROOT_ITEM_KEY 132
180 * Root backrefs tie subvols and snapshots to the directory entries that
183 #define BTRFS_ROOT_BACKREF_KEY 144
186 * Root refs make a fast index for listing all of the snapshots and
187 * subvolumes referenced by a given root. They point directly to the
188 * directory item in the root that references the subvol.
190 #define BTRFS_ROOT_REF_KEY 156
193 * Extent items are in the extent tree.
195 * These record which blocks are used, and how many references there are.
197 #define BTRFS_EXTENT_ITEM_KEY 168
200 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
201 * the length, so we save the level in key->offset instead of the length.
203 #define BTRFS_METADATA_ITEM_KEY 169
205 #define BTRFS_TREE_BLOCK_REF_KEY 176
207 #define BTRFS_EXTENT_DATA_REF_KEY 178
209 #define BTRFS_EXTENT_REF_V0_KEY 180
211 #define BTRFS_SHARED_BLOCK_REF_KEY 182
213 #define BTRFS_SHARED_DATA_REF_KEY 184
216 * Block groups give us hints into the extent allocation trees.
218 * Stores how many free space there is in a block group.
220 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
223 * Every block group is represented in the free space tree by a free space info
224 * item, which stores some accounting information. It is keyed on
225 * (block_group_start, FREE_SPACE_INFO, block_group_length).
227 #define BTRFS_FREE_SPACE_INFO_KEY 198
230 * A free space extent tracks an extent of space that is free in a block group.
231 * It is keyed on (start, FREE_SPACE_EXTENT, length).
233 #define BTRFS_FREE_SPACE_EXTENT_KEY 199
236 * When a block group becomes very fragmented, we convert it to use bitmaps
237 * instead of extents.
239 * A free space bitmap is keyed on (start, FREE_SPACE_BITMAP, length).
240 * The corresponding item is a bitmap with (length / sectorsize) bits.
242 #define BTRFS_FREE_SPACE_BITMAP_KEY 200
244 #define BTRFS_DEV_EXTENT_KEY 204
245 #define BTRFS_DEV_ITEM_KEY 216
246 #define BTRFS_CHUNK_ITEM_KEY 228
249 * Records the overall state of the qgroups.
251 * There's only one instance of this key present,
252 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
254 #define BTRFS_QGROUP_STATUS_KEY 240
256 * Records the currently used space of the qgroup.
258 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
260 #define BTRFS_QGROUP_INFO_KEY 242
263 * Contains the user configured limits for the qgroup.
265 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
267 #define BTRFS_QGROUP_LIMIT_KEY 244
270 * Records the child-parent relationship of qgroups. For
271 * each relation, 2 keys are present:
272 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
273 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
275 #define BTRFS_QGROUP_RELATION_KEY 246
277 /* Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. */
278 #define BTRFS_BALANCE_ITEM_KEY 248
281 * The key type for tree items that are stored persistently, but do not need to
282 * exist for extended period of time. The items can exist in any tree.
284 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
288 * - balance status item
289 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
291 #define BTRFS_TEMPORARY_ITEM_KEY 248
293 /* Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY */
294 #define BTRFS_DEV_STATS_KEY 249
297 * The key type for tree items that are stored persistently and usually exist
298 * for a long period, eg. filesystem lifetime. The item kinds can be status
299 * information, stats or preference values. The item can exist in any tree.
301 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
305 * - device statistics, store IO stats in the device tree, one key for all
307 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
309 #define BTRFS_PERSISTENT_ITEM_KEY 249
312 * Persistently stores the device replace state in the device tree.
314 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
316 #define BTRFS_DEV_REPLACE_KEY 250
319 * Stores items that allow to quickly map UUIDs to something else.
321 * These items are part of the filesystem UUID tree.
322 * The key is built like this:
323 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
325 #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
326 #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
327 * received subvols */
330 * String items are for debugging.
332 * They just store a short string of data in the FS.
334 #define BTRFS_STRING_ITEM_KEY 253
338 /* 32 bytes in various csum fields */
339 #define BTRFS_CSUM_SIZE 32
342 enum btrfs_csum_type {
343 BTRFS_CSUM_TYPE_CRC32 = 0,
344 BTRFS_CSUM_TYPE_XXHASH = 1,
345 BTRFS_CSUM_TYPE_SHA256 = 2,
346 BTRFS_CSUM_TYPE_BLAKE2 = 3,
350 * Flags definitions for directory entry item type.
353 * struct btrfs_dir_item.type
355 * Values 0..7 must match common file type values in fs_types.h.
357 #define BTRFS_FT_UNKNOWN 0
358 #define BTRFS_FT_REG_FILE 1
359 #define BTRFS_FT_DIR 2
360 #define BTRFS_FT_CHRDEV 3
361 #define BTRFS_FT_BLKDEV 4
362 #define BTRFS_FT_FIFO 5
363 #define BTRFS_FT_SOCK 6
364 #define BTRFS_FT_SYMLINK 7
365 #define BTRFS_FT_XATTR 8
366 #define BTRFS_FT_MAX 9
368 #define BTRFS_FSID_SIZE 16
369 #define BTRFS_UUID_SIZE 16
372 * The key defines the order in the tree, and so it also defines (optimal)
375 * Objectid and offset are interpreted based on type.
376 * While normally for objectid, it either represents a root number, or an
379 * Type tells us things about the object, and is a kind of stream selector.
380 * Check the following URL for full references about btrfs_disk_key/btrfs_key:
381 * https://btrfs.wiki.kernel.org/index.php/Btree_Items
383 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
384 * in cpu native order. Otherwise they are identical and their sizes
385 * should be the same (ie both packed)
387 struct btrfs_disk_key {
391 } __attribute__ ((__packed__));
397 } __attribute__ ((__packed__));
399 struct btrfs_dev_item {
400 /* The internal btrfs device id */
403 /* Size of the device */
409 /* Optimal io alignment for this device */
412 /* Optimal io width for this device */
415 /* Minimal io size for this device */
418 /* Type and info about this device */
421 /* Expected generation for this device */
425 * Starting byte of this partition on the device,
426 * to allow for stripe alignment in the future.
430 /* Grouping information for allocation decisions */
433 /* Optimal seek speed 0-100 where 100 is fastest */
436 /* Optimal bandwidth 0-100 where 100 is fastest */
439 /* Btrfs generated uuid for this device */
440 __u8 uuid[BTRFS_UUID_SIZE];
442 /* UUID of FS who owns this device */
443 __u8 fsid[BTRFS_UUID_SIZE];
444 } __attribute__ ((__packed__));
446 struct btrfs_stripe {
449 __u8 dev_uuid[BTRFS_UUID_SIZE];
450 } __attribute__ ((__packed__));
453 /* Size of this chunk in bytes */
456 /* Objectid of the root referencing this chunk */
462 /* Optimal io alignment for this chunk */
465 /* Optimal io width for this chunk */
468 /* Minimal io size for this chunk */
472 * 2^16 stripes is quite a lot, a second limit is the size of a single
477 /* Sub stripes only matter for raid10 */
479 struct btrfs_stripe stripe;
480 /* additional stripes go here */
481 } __attribute__ ((__packed__));
483 #define BTRFS_FREE_SPACE_EXTENT 1
484 #define BTRFS_FREE_SPACE_BITMAP 2
486 struct btrfs_free_space_entry {
490 } __attribute__ ((__packed__));
492 struct btrfs_free_space_header {
493 struct btrfs_disk_key location;
497 } __attribute__ ((__packed__));
499 #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
500 #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
502 /* Super block flags */
503 /* Errors detected */
504 #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
506 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
507 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
508 #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
509 #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
510 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
514 * Items in the extent tree are used to record the objectid of the
515 * owner of the block and the number of references.
517 struct btrfs_extent_item {
521 } __attribute__ ((__packed__));
523 struct btrfs_extent_item_v0 {
525 } __attribute__ ((__packed__));
528 #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
529 #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
531 /* Use full backrefs for extent pointers in the block */
532 #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
535 * This flag is only used internally by scrub and may be changed at any time
536 * it is only declared here to avoid collisions.
538 #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
540 struct btrfs_tree_block_info {
541 struct btrfs_disk_key key;
543 } __attribute__ ((__packed__));
545 struct btrfs_extent_data_ref {
550 } __attribute__ ((__packed__));
552 struct btrfs_shared_data_ref {
554 } __attribute__ ((__packed__));
556 struct btrfs_extent_inline_ref {
559 } __attribute__ ((__packed__));
561 /* Old style backrefs item */
562 struct btrfs_extent_ref_v0 {
567 } __attribute__ ((__packed__));
570 /* Dev extents record used space on individual devices.
572 * The owner field points back to the chunk allocation mapping tree that
573 * allocated the extent.
574 * The chunk tree uuid field is a way to double check the owner.
576 struct btrfs_dev_extent {
578 __le64 chunk_objectid;
581 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
582 } __attribute__ ((__packed__));
584 struct btrfs_inode_ref {
588 } __attribute__ ((__packed__));
590 struct btrfs_inode_extref {
591 __le64 parent_objectid;
596 } __attribute__ ((__packed__));
598 struct btrfs_timespec {
601 } __attribute__ ((__packed__));
604 #define BTRFS_INODE_NODATASUM (1 << 0)
605 #define BTRFS_INODE_NODATACOW (1 << 1)
606 #define BTRFS_INODE_READONLY (1 << 2)
607 #define BTRFS_INODE_NOCOMPRESS (1 << 3)
608 #define BTRFS_INODE_PREALLOC (1 << 4)
609 #define BTRFS_INODE_SYNC (1 << 5)
610 #define BTRFS_INODE_IMMUTABLE (1 << 6)
611 #define BTRFS_INODE_APPEND (1 << 7)
612 #define BTRFS_INODE_NODUMP (1 << 8)
613 #define BTRFS_INODE_NOATIME (1 << 9)
614 #define BTRFS_INODE_DIRSYNC (1 << 10)
615 #define BTRFS_INODE_COMPRESS (1 << 11)
617 #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
619 #define BTRFS_INODE_FLAG_MASK \
620 (BTRFS_INODE_NODATASUM | \
621 BTRFS_INODE_NODATACOW | \
622 BTRFS_INODE_READONLY | \
623 BTRFS_INODE_NOCOMPRESS | \
624 BTRFS_INODE_PREALLOC | \
626 BTRFS_INODE_IMMUTABLE | \
627 BTRFS_INODE_APPEND | \
628 BTRFS_INODE_NODUMP | \
629 BTRFS_INODE_NOATIME | \
630 BTRFS_INODE_DIRSYNC | \
631 BTRFS_INODE_COMPRESS | \
632 BTRFS_INODE_ROOT_ITEM_INIT)
634 struct btrfs_inode_item {
635 /* Nfs style generation number */
637 /* Transid that last touched this inode */
649 /* Modification sequence number for NFS */
653 * A little future expansion, for more than this we can just grow the
654 * inode item and version it
657 struct btrfs_timespec atime;
658 struct btrfs_timespec ctime;
659 struct btrfs_timespec mtime;
660 struct btrfs_timespec otime;
661 } __attribute__ ((__packed__));
663 struct btrfs_dir_log_item {
665 } __attribute__ ((__packed__));
667 struct btrfs_dir_item {
668 struct btrfs_disk_key location;
673 } __attribute__ ((__packed__));
675 #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
678 * Internal in-memory flag that a subvolume has been marked for deletion but
679 * still visible as a directory
681 #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
683 struct btrfs_root_item {
684 struct btrfs_inode_item inode;
690 __le64 last_snapshot;
693 struct btrfs_disk_key drop_progress;
698 * The following fields appear after subvol_uuids+subvol_times
703 * This generation number is used to test if the new fields are valid
704 * and up to date while reading the root item. Every time the root item
705 * is written out, the "generation" field is copied into this field. If
706 * anyone ever mounted the fs with an older kernel, we will have
707 * mismatching generation values here and thus must invalidate the
708 * new fields. See btrfs_update_root and btrfs_find_last_root for
710 * The offset of generation_v2 is also used as the start for the memset
711 * when invalidating the fields.
713 __le64 generation_v2;
714 __u8 uuid[BTRFS_UUID_SIZE];
715 __u8 parent_uuid[BTRFS_UUID_SIZE];
716 __u8 received_uuid[BTRFS_UUID_SIZE];
717 __le64 ctransid; /* Updated when an inode changes */
718 __le64 otransid; /* Trans when created */
719 __le64 stransid; /* Trans when sent. Non-zero for received subvol. */
720 __le64 rtransid; /* Trans when received. Non-zero for received subvol.*/
721 struct btrfs_timespec ctime;
722 struct btrfs_timespec otime;
723 struct btrfs_timespec stime;
724 struct btrfs_timespec rtime;
725 __le64 reserved[8]; /* For future */
726 } __attribute__ ((__packed__));
728 /* This is used for both forward and backward root refs */
729 struct btrfs_root_ref {
733 } __attribute__ ((__packed__));
735 struct btrfs_disk_balance_args {
737 * Profiles to operate on.
739 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
745 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
746 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
759 /* Devid subset filter [pstart..pend) */
763 /* Btrfs virtual address space subset filter [vstart..vend) */
768 * Profile to convert to.
770 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
774 /* BTRFS_BALANCE_ARGS_* */
778 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'.
779 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
791 * Process chunks that cross stripes_min..stripes_max devices,
792 * BTRFS_BALANCE_ARGS_STRIPES_RANGE.
798 } __attribute__ ((__packed__));
801 * Stores balance parameters to disk so that balance can be properly
802 * resumed after crash or unmount.
804 struct btrfs_balance_item {
805 /* BTRFS_BALANCE_* */
808 struct btrfs_disk_balance_args data;
809 struct btrfs_disk_balance_args meta;
810 struct btrfs_disk_balance_args sys;
813 } __attribute__ ((__packed__));
816 BTRFS_FILE_EXTENT_INLINE = 0,
817 BTRFS_FILE_EXTENT_REG = 1,
818 BTRFS_FILE_EXTENT_PREALLOC = 2,
819 BTRFS_NR_FILE_EXTENT_TYPES = 3,
822 enum btrfs_compression_type {
823 BTRFS_COMPRESS_NONE = 0,
824 BTRFS_COMPRESS_ZLIB = 1,
825 BTRFS_COMPRESS_LZO = 2,
826 BTRFS_COMPRESS_ZSTD = 3,
827 BTRFS_NR_COMPRESS_TYPES = 4,
830 struct btrfs_file_extent_item {
831 /* Transaction id that created this extent */
834 * Max number of bytes to hold this extent in ram.
836 * When we split a compressed extent we can't know how big each of the
837 * resulting pieces will be. So, this is an upper limit on the size of
838 * the extent in ram instead of an exact limit.
843 * 32 bits for the various ways we might encode the data,
844 * including compression and encryption. If any of these
845 * are set to something a given disk format doesn't understand
846 * it is treated like an incompat flag for reading and writing,
851 __le16 other_encoding; /* Spare for later use */
853 /* Are we inline data or a real extent? */
857 * Disk space consumed by the extent, checksum blocks are not included
860 * At this offset in the structure, the inline extent data start.
863 __le64 disk_num_bytes;
866 * The logical offset inside the file extent.
868 * This allows a file extent to point into the middle of an existing
869 * extent on disk, sharing it between two snapshots (useful if some
870 * bytes in the middle of the extent have changed).
875 * The logical number of bytes this file extent is referencing (no
878 * This always reflects the size uncompressed and without encoding.
882 } __attribute__ ((__packed__));
884 struct btrfs_csum_item {
886 } __attribute__ ((__packed__));
888 enum btrfs_dev_stat_values {
889 /* Disk I/O failure stats */
890 BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
891 BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
892 BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
894 /* Stats for indirect indications for I/O failures */
895 BTRFS_DEV_STAT_CORRUPTION_ERRS, /* Checksum error, bytenr error or
896 * contents is illegal: this is an
897 * indication that the block was damaged
898 * during read or write, or written to
899 * wrong location or read from wrong
901 BTRFS_DEV_STAT_GENERATION_ERRS, /* An indication that blocks have not
904 BTRFS_DEV_STAT_VALUES_MAX
907 struct btrfs_dev_stats_item {
909 * Grow this item struct at the end for future enhancements and keep
910 * the existing values unchanged.
912 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
913 } __attribute__ ((__packed__));
915 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
916 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
918 struct btrfs_dev_replace_item {
920 * Grow this item struct at the end for future enhancements and keep
921 * the existing values unchanged.
926 __le64 cont_reading_from_srcdev_mode;
928 __le64 replace_state;
931 __le64 num_write_errors;
932 __le64 num_uncorrectable_read_errors;
933 } __attribute__ ((__packed__));
935 /* Different types of block groups (and chunks) */
936 #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
937 #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
938 #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
939 #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
940 #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
941 #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
942 #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
943 #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
944 #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
945 #define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
946 #define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
947 #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
948 BTRFS_SPACE_INFO_GLOBAL_RSV)
950 enum btrfs_raid_types {
963 #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
964 BTRFS_BLOCK_GROUP_SYSTEM | \
965 BTRFS_BLOCK_GROUP_METADATA)
967 #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
968 BTRFS_BLOCK_GROUP_RAID1 | \
969 BTRFS_BLOCK_GROUP_RAID1C3 | \
970 BTRFS_BLOCK_GROUP_RAID1C4 | \
971 BTRFS_BLOCK_GROUP_RAID5 | \
972 BTRFS_BLOCK_GROUP_RAID6 | \
973 BTRFS_BLOCK_GROUP_DUP | \
974 BTRFS_BLOCK_GROUP_RAID10)
975 #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
976 BTRFS_BLOCK_GROUP_RAID6)
978 #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
979 BTRFS_BLOCK_GROUP_RAID1C3 | \
980 BTRFS_BLOCK_GROUP_RAID1C4)
983 * We need a bit for restriper to be able to tell when chunks of type
984 * SINGLE are available. This "extended" profile format is used in
985 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
986 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
987 * to avoid remappings between two formats in future.
989 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
992 * A fake block group type that is used to communicate global block reserve
993 * size to userspace via the SPACE_INFO ioctl.
995 #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
997 #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
998 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
1000 static inline __u64 chunk_to_extended(__u64 flags)
1002 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1003 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1007 static inline __u64 extended_to_chunk(__u64 flags)
1009 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1012 struct btrfs_block_group_item {
1014 __le64 chunk_objectid;
1016 } __attribute__ ((__packed__));
1018 struct btrfs_free_space_info {
1019 __le32 extent_count;
1021 } __attribute__ ((__packed__));
1023 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1025 #define BTRFS_QGROUP_LEVEL_SHIFT 48
1026 static inline __u64 btrfs_qgroup_level(__u64 qgroupid)
1028 return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
1031 /* Is subvolume quota turned on? */
1032 #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1034 /* Is qgroup rescan running? */
1035 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1038 * Some qgroup entries are known to be out of date, either because the
1039 * configuration has changed in a way that makes a rescan necessary, or
1040 * because the fs has been mounted with a non-qgroup-aware version.
1042 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1044 #define BTRFS_QGROUP_STATUS_VERSION 1
1046 struct btrfs_qgroup_status_item {
1049 * The generation is updated during every commit. As older
1050 * versions of btrfs are not aware of qgroups, it will be
1051 * possible to detect inconsistencies by checking the
1052 * generation on mount time.
1056 /* Flag definitions see above */
1060 * Only used during scanning to record the progress of the scan.
1061 * It contains a logical address.
1064 } __attribute__ ((__packed__));
1066 struct btrfs_qgroup_info_item {
1072 } __attribute__ ((__packed__));
1075 * Flags definition for qgroup limits
1078 * struct btrfs_qgroup_limit.flags
1079 * struct btrfs_qgroup_limit_item.flags
1081 #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
1082 #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
1083 #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
1084 #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
1085 #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
1086 #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
1088 struct btrfs_qgroup_limit_item {
1089 /* Only updated when any of the other values change. */
1095 } __attribute__ ((__packed__));
1098 * Just in case we somehow lose the roots and are not able to mount,
1099 * we store an array of the roots from previous transactions in the super.
1101 #define BTRFS_NUM_BACKUP_ROOTS 4
1102 struct btrfs_root_backup {
1104 __le64 tree_root_gen;
1107 __le64 chunk_root_gen;
1110 __le64 extent_root_gen;
1116 __le64 dev_root_gen;
1119 __le64 csum_root_gen;
1125 __le64 unused_64[4];
1128 u8 chunk_root_level;
1129 u8 extent_root_level;
1133 /* future and to align */
1135 } __attribute__ ((__packed__));
1138 * This is a very generous portion of the super block, giving us room to
1139 * translate 14 chunks with 3 stripes each.
1141 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
1143 #define BTRFS_LABEL_SIZE 256
1145 /* The super block basically lists the main trees of the FS. */
1146 struct btrfs_super_block {
1147 /* The first 4 fields must match struct btrfs_header */
1148 u8 csum[BTRFS_CSUM_SIZE];
1149 /* FS specific UUID, visible to user */
1150 u8 fsid[BTRFS_FSID_SIZE];
1151 __le64 bytenr; /* this block number */
1154 /* Allowed to be different from the btrfs_header from here own down. */
1161 /* This will help find the new super based on the log root. */
1162 __le64 log_root_transid;
1165 __le64 root_dir_objectid;
1169 __le32 __unused_leafsize;
1171 __le32 sys_chunk_array_size;
1172 __le64 chunk_root_generation;
1173 __le64 compat_flags;
1174 __le64 compat_ro_flags;
1175 __le64 incompat_flags;
1178 u8 chunk_root_level;
1180 struct btrfs_dev_item dev_item;
1182 char label[BTRFS_LABEL_SIZE];
1184 __le64 cache_generation;
1185 __le64 uuid_tree_generation;
1187 /* The UUID written into btree blocks */
1188 u8 metadata_uuid[BTRFS_FSID_SIZE];
1190 /* Future expansion */
1191 __le64 reserved[28];
1192 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
1193 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
1194 } __attribute__ ((__packed__));
1200 * struct btrfs_super_block::(compat|compat_ro|incompat)_flags
1201 * struct btrfs_ioctl_feature_flags
1203 #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
1206 * Older kernels (< 4.9) on big-endian systems produced broken free space tree
1207 * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
1208 * < 4.7.3). If this bit is clear, then the free space tree cannot be trusted.
1209 * btrfs-progs can also intentionally clear this bit to ask the kernel to
1210 * rebuild the free space tree, however this might not work on older kernels
1211 * that do not know about this bit. If not sure, clear the cache manually on
1212 * first mount when booting older kernel versions.
1214 #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1)
1216 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
1217 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
1218 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
1219 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
1220 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4)
1223 * Older kernels tried to do bigger metadata blocks, but the
1224 * code was pretty buggy. Lets not let them try anymore.
1226 #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
1228 #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
1229 #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
1230 #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
1231 #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
1232 #define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10)
1233 #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11)
1236 * Compat flags that we support.
1238 * If any incompat flags are set other than the ones specified below then we
1239 * will fail to mount.
1241 #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
1242 #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL
1243 #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL
1245 #define BTRFS_FEATURE_COMPAT_RO_SUPP \
1246 (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE | \
1247 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
1249 #define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL
1250 #define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
1252 #define BTRFS_FEATURE_INCOMPAT_SUPP \
1253 (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
1254 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
1255 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
1256 BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
1257 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
1258 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD | \
1259 BTRFS_FEATURE_INCOMPAT_RAID56 | \
1260 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
1261 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
1262 BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
1263 BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
1264 BTRFS_FEATURE_INCOMPAT_RAID1C34)
1266 #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
1267 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
1268 #define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL
1270 #define BTRFS_BACKREF_REV_MAX 256
1271 #define BTRFS_BACKREF_REV_SHIFT 56
1272 #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
1273 BTRFS_BACKREF_REV_SHIFT)
1275 #define BTRFS_OLD_BACKREF_REV 0
1276 #define BTRFS_MIXED_BACKREF_REV 1
1278 #define BTRFS_MAX_LEVEL 8
1280 /* Every tree block (leaf or node) starts with this header. */
1281 struct btrfs_header {
1282 /* These first four must match the super block */
1283 u8 csum[BTRFS_CSUM_SIZE];
1284 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
1285 __le64 bytenr; /* Which block this node is supposed to live in */
1288 /* Allowed to be different from the super from here on down. */
1289 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
1294 } __attribute__ ((__packed__));
1297 * A leaf is full of items. Offset and size tell us where to find
1298 * the item in the leaf (relative to the start of the data area).
1301 struct btrfs_disk_key key;
1304 } __attribute__ ((__packed__));
1307 * leaves have an item area and a data area:
1308 * [item0, item1....itemN] [free space] [dataN...data1, data0]
1310 * The data is separate from the items to get the keys closer together
1314 struct btrfs_header header;
1315 struct btrfs_item items[];
1316 } __attribute__ ((__packed__));
1319 * All non-leaf blocks are nodes, they hold only keys and pointers to children
1322 struct btrfs_key_ptr {
1323 struct btrfs_disk_key key;
1326 } __attribute__ ((__packed__));
1329 struct btrfs_header header;
1330 struct btrfs_key_ptr ptrs[];
1331 } __attribute__ ((__packed__));
1333 #endif /* __BTRFS_TREE_H__ */