1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _BTRFS_CTREE_H_
3 #define _BTRFS_CTREE_H_
5 #include <linux/btrfs.h>
6 #include <linux/types.h>
8 #include <linux/stddef.h>
13 /* ASCII for _BHRfS_M, no terminating nul */
14 #define BTRFS_MAGIC 0x4D5F53665248425FULL
16 #define BTRFS_MAX_LEVEL 8
19 * We can actually store much bigger names, but lets not confuse the rest of
22 #define BTRFS_NAME_LEN 255
25 * Theoretical limit is larger, but we keep this down to a sane value. That
26 * should limit greatly the possibility of collisions on inode ref items.
28 #define BTRFS_LINK_MAX 65535U
31 * This header contains the structure definitions and constants used
32 * by file system objects that can be retrieved using
33 * the BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that
34 * is needed to describe a leaf node's key or item contents.
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
61 /* holds checksums of all the data extents */
62 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
64 /* holds quota configuration and tracking */
65 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
67 /* for storing items that use the BTRFS_UUID_KEY* types */
68 #define BTRFS_UUID_TREE_OBJECTID 9ULL
70 /* tracks free space in block groups. */
71 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
73 /* Holds the block group items for extent tree v2. */
74 #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
76 /* device stats in the device tree */
77 #define BTRFS_DEV_STATS_OBJECTID 0ULL
79 /* for storing balance parameters in the root tree */
80 #define BTRFS_BALANCE_OBJECTID -4ULL
82 /* orphan objectid for tracking unlinked/truncated files */
83 #define BTRFS_ORPHAN_OBJECTID -5ULL
85 /* does write ahead logging to speed up fsyncs */
86 #define BTRFS_TREE_LOG_OBJECTID -6ULL
87 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
89 /* for space balancing */
90 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
91 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
94 * extent checksums all have this objectid
95 * this allows them to share the logging tree
98 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
100 /* For storing free space cache */
101 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
104 * The inode number assigned to the special inode for storing
107 #define BTRFS_FREE_INO_OBJECTID -12ULL
109 /* dummy objectid represents multiple objectids */
110 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
113 * All files have objectids in this range.
115 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
116 #define BTRFS_LAST_FREE_OBJECTID -256ULL
117 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
121 * the device items go into the chunk tree. The key is in the form
122 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
124 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
126 #define BTRFS_BTREE_INODE_OBJECTID 1
128 #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
130 #define BTRFS_DEV_REPLACE_DEVID 0ULL
133 * inode items have the data typically returned from stat and store other
134 * info about object characteristics. There is one for every file and dir in
137 #define BTRFS_INODE_ITEM_KEY 1
138 #define BTRFS_INODE_REF_KEY 12
139 #define BTRFS_INODE_EXTREF_KEY 13
140 #define BTRFS_XATTR_ITEM_KEY 24
143 * fs verity items are stored under two different key types on disk.
144 * The descriptor items:
145 * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
147 * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
148 * of the descriptor item and some extra data for encryption.
149 * Starting at offset 1, these hold the generic fs verity descriptor. The
150 * latter are opaque to btrfs, we just read and write them as a blob for the
151 * higher level verity code. The most common descriptor size is 256 bytes.
153 * The merkle tree items:
154 * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
156 * These also start at offset 0, and correspond to the merkle tree bytes. When
157 * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
158 * offset 0 for this key type. These are also opaque to btrfs, we're blindly
159 * storing whatever fsverity sends down.
161 #define BTRFS_VERITY_DESC_ITEM_KEY 36
162 #define BTRFS_VERITY_MERKLE_ITEM_KEY 37
164 #define BTRFS_ORPHAN_ITEM_KEY 48
165 /* reserve 2-15 close to the inode for later flexibility */
168 * dir items are the name -> inode pointers in a directory. There is one
169 * for every name in a directory. BTRFS_DIR_LOG_ITEM_KEY is no longer used
170 * but it's still defined here for documentation purposes and to help avoid
171 * having its numerical value reused in the future.
173 #define BTRFS_DIR_LOG_ITEM_KEY 60
174 #define BTRFS_DIR_LOG_INDEX_KEY 72
175 #define BTRFS_DIR_ITEM_KEY 84
176 #define BTRFS_DIR_INDEX_KEY 96
178 * extent data is for file data
180 #define BTRFS_EXTENT_DATA_KEY 108
183 * extent csums are stored in a separate tree and hold csums for
184 * an entire extent on disk.
186 #define BTRFS_EXTENT_CSUM_KEY 128
189 * root items point to tree roots. They are typically in the root
190 * tree used by the super block to find all the other trees
192 #define BTRFS_ROOT_ITEM_KEY 132
195 * root backrefs tie subvols and snapshots to the directory entries that
198 #define BTRFS_ROOT_BACKREF_KEY 144
201 * root refs make a fast index for listing all of the snapshots and
202 * subvolumes referenced by a given root. They point directly to the
203 * directory item in the root that references the subvol
205 #define BTRFS_ROOT_REF_KEY 156
208 * extent items are in the extent map tree. These record which blocks
209 * are used, and how many references there are to each block
211 #define BTRFS_EXTENT_ITEM_KEY 168
214 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
215 * the length, so we save the level in key->offset instead of the length.
217 #define BTRFS_METADATA_ITEM_KEY 169
219 #define BTRFS_TREE_BLOCK_REF_KEY 176
221 #define BTRFS_EXTENT_DATA_REF_KEY 178
223 #define BTRFS_EXTENT_REF_V0_KEY 180
225 #define BTRFS_SHARED_BLOCK_REF_KEY 182
227 #define BTRFS_SHARED_DATA_REF_KEY 184
230 * block groups give us hints into the extent allocation trees. Which
231 * blocks are free etc etc
233 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
236 * Every block group is represented in the free space tree by a free space info
237 * item, which stores some accounting information. It is keyed on
238 * (block_group_start, FREE_SPACE_INFO, block_group_length).
240 #define BTRFS_FREE_SPACE_INFO_KEY 198
243 * A free space extent tracks an extent of space that is free in a block group.
244 * It is keyed on (start, FREE_SPACE_EXTENT, length).
246 #define BTRFS_FREE_SPACE_EXTENT_KEY 199
249 * When a block group becomes very fragmented, we convert it to use bitmaps
250 * instead of extents. A free space bitmap is keyed on
251 * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
252 * (length / sectorsize) bits.
254 #define BTRFS_FREE_SPACE_BITMAP_KEY 200
256 #define BTRFS_DEV_EXTENT_KEY 204
257 #define BTRFS_DEV_ITEM_KEY 216
258 #define BTRFS_CHUNK_ITEM_KEY 228
261 * Records the overall state of the qgroups.
262 * There's only one instance of this key present,
263 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
265 #define BTRFS_QGROUP_STATUS_KEY 240
267 * Records the currently used space of the qgroup.
268 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
270 #define BTRFS_QGROUP_INFO_KEY 242
272 * Contains the user configured limits for the qgroup.
273 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
275 #define BTRFS_QGROUP_LIMIT_KEY 244
277 * Records the child-parent relationship of qgroups. For
278 * each relation, 2 keys are present:
279 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
280 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
282 #define BTRFS_QGROUP_RELATION_KEY 246
285 * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
287 #define BTRFS_BALANCE_ITEM_KEY 248
290 * The key type for tree items that are stored persistently, but do not need to
291 * exist for extended period of time. The items can exist in any tree.
293 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
297 * - balance status item
298 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
300 #define BTRFS_TEMPORARY_ITEM_KEY 248
303 * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
305 #define BTRFS_DEV_STATS_KEY 249
308 * The key type for tree items that are stored persistently and usually exist
309 * for a long period, eg. filesystem lifetime. The item kinds can be status
310 * information, stats or preference values. The item can exist in any tree.
312 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
316 * - device statistics, store IO stats in the device tree, one key for all
318 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
320 #define BTRFS_PERSISTENT_ITEM_KEY 249
323 * Persistently stores the device replace state in the device tree.
324 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
326 #define BTRFS_DEV_REPLACE_KEY 250
329 * Stores items that allow to quickly map UUIDs to something else.
330 * These items are part of the filesystem UUID tree.
331 * The key is built like this:
332 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
334 #if BTRFS_UUID_SIZE != 16
335 #error "UUID items require BTRFS_UUID_SIZE == 16!"
337 #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
338 #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
339 * received subvols */
342 * string items are for debugging. They just store a short string of
345 #define BTRFS_STRING_ITEM_KEY 253
347 /* Maximum metadata block size (nodesize) */
348 #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
350 /* 32 bytes in various csum fields */
351 #define BTRFS_CSUM_SIZE 32
354 enum btrfs_csum_type {
355 BTRFS_CSUM_TYPE_CRC32 = 0,
356 BTRFS_CSUM_TYPE_XXHASH = 1,
357 BTRFS_CSUM_TYPE_SHA256 = 2,
358 BTRFS_CSUM_TYPE_BLAKE2 = 3,
362 * flags definitions for directory entry item type
365 * struct btrfs_dir_item.type
367 * Values 0..7 must match common file type values in fs_types.h.
369 #define BTRFS_FT_UNKNOWN 0
370 #define BTRFS_FT_REG_FILE 1
371 #define BTRFS_FT_DIR 2
372 #define BTRFS_FT_CHRDEV 3
373 #define BTRFS_FT_BLKDEV 4
374 #define BTRFS_FT_FIFO 5
375 #define BTRFS_FT_SOCK 6
376 #define BTRFS_FT_SYMLINK 7
377 #define BTRFS_FT_XATTR 8
378 #define BTRFS_FT_MAX 9
379 /* Directory contains encrypted data */
380 #define BTRFS_FT_ENCRYPTED 0x80
382 static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags)
384 return flags & ~BTRFS_FT_ENCRYPTED;
390 #define BTRFS_INODE_NODATASUM (1U << 0)
391 #define BTRFS_INODE_NODATACOW (1U << 1)
392 #define BTRFS_INODE_READONLY (1U << 2)
393 #define BTRFS_INODE_NOCOMPRESS (1U << 3)
394 #define BTRFS_INODE_PREALLOC (1U << 4)
395 #define BTRFS_INODE_SYNC (1U << 5)
396 #define BTRFS_INODE_IMMUTABLE (1U << 6)
397 #define BTRFS_INODE_APPEND (1U << 7)
398 #define BTRFS_INODE_NODUMP (1U << 8)
399 #define BTRFS_INODE_NOATIME (1U << 9)
400 #define BTRFS_INODE_DIRSYNC (1U << 10)
401 #define BTRFS_INODE_COMPRESS (1U << 11)
403 #define BTRFS_INODE_ROOT_ITEM_INIT (1U << 31)
405 #define BTRFS_INODE_FLAG_MASK \
406 (BTRFS_INODE_NODATASUM | \
407 BTRFS_INODE_NODATACOW | \
408 BTRFS_INODE_READONLY | \
409 BTRFS_INODE_NOCOMPRESS | \
410 BTRFS_INODE_PREALLOC | \
412 BTRFS_INODE_IMMUTABLE | \
413 BTRFS_INODE_APPEND | \
414 BTRFS_INODE_NODUMP | \
415 BTRFS_INODE_NOATIME | \
416 BTRFS_INODE_DIRSYNC | \
417 BTRFS_INODE_COMPRESS | \
418 BTRFS_INODE_ROOT_ITEM_INIT)
420 #define BTRFS_INODE_RO_VERITY (1U << 0)
422 #define BTRFS_INODE_RO_FLAG_MASK (BTRFS_INODE_RO_VERITY)
425 * The key defines the order in the tree, and so it also defines (optimal)
428 * objectid corresponds to the inode number.
430 * type tells us things about the object, and is a kind of stream selector.
431 * so for a given inode, keys with type of 1 might refer to the inode data,
432 * type of 2 may point to file data in the btree and type == 3 may point to
435 * offset is the starting byte offset for this key in the stream.
437 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
438 * in cpu native order. Otherwise they are identical and their sizes
439 * should be the same (ie both packed)
441 struct btrfs_disk_key {
445 } __attribute__ ((__packed__));
451 } __attribute__ ((__packed__));
454 * Every tree block (leaf or node) starts with this header.
456 struct btrfs_header {
457 /* These first four must match the super block */
458 __u8 csum[BTRFS_CSUM_SIZE];
459 /* FS specific uuid */
460 __u8 fsid[BTRFS_FSID_SIZE];
461 /* Which block this node is supposed to live in */
465 /* Allowed to be different from the super from here on down */
466 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
471 } __attribute__ ((__packed__));
474 * This is a very generous portion of the super block, giving us room to
475 * translate 14 chunks with 3 stripes each.
477 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
480 * Just in case we somehow lose the roots and are not able to mount, we store
481 * an array of the roots from previous transactions in the super.
483 #define BTRFS_NUM_BACKUP_ROOTS 4
484 struct btrfs_root_backup {
486 __le64 tree_root_gen;
489 __le64 chunk_root_gen;
492 __le64 extent_root_gen;
501 __le64 csum_root_gen;
509 __u8 tree_root_level;
510 __u8 chunk_root_level;
511 __u8 extent_root_level;
514 __u8 csum_root_level;
515 /* future and to align */
517 } __attribute__ ((__packed__));
520 * A leaf is full of items. offset and size tell us where to find the item in
521 * the leaf (relative to the start of the data area)
524 struct btrfs_disk_key key;
527 } __attribute__ ((__packed__));
530 * Leaves have an item area and a data area:
531 * [item0, item1....itemN] [free space] [dataN...data1, data0]
533 * The data is separate from the items to get the keys closer together during
537 struct btrfs_header header;
538 struct btrfs_item items[];
539 } __attribute__ ((__packed__));
542 * All non-leaf blocks are nodes, they hold only keys and pointers to other
545 struct btrfs_key_ptr {
546 struct btrfs_disk_key key;
549 } __attribute__ ((__packed__));
552 struct btrfs_header header;
553 struct btrfs_key_ptr ptrs[];
554 } __attribute__ ((__packed__));
556 struct btrfs_dev_item {
557 /* the internal btrfs device id */
560 /* size of the device */
566 /* optimal io alignment for this device */
569 /* optimal io width for this device */
572 /* minimal io size for this device */
575 /* type and info about this device */
578 /* expected generation for this device */
582 * starting byte of this partition on the device,
583 * to allow for stripe alignment in the future
587 /* grouping information for allocation decisions */
590 /* seek speed 0-100 where 100 is fastest */
593 /* bandwidth 0-100 where 100 is fastest */
596 /* btrfs generated uuid for this device */
597 __u8 uuid[BTRFS_UUID_SIZE];
599 /* uuid of FS who owns this device */
600 __u8 fsid[BTRFS_UUID_SIZE];
601 } __attribute__ ((__packed__));
603 struct btrfs_stripe {
606 __u8 dev_uuid[BTRFS_UUID_SIZE];
607 } __attribute__ ((__packed__));
610 /* size of this chunk in bytes */
613 /* objectid of the root referencing this chunk */
619 /* optimal io alignment for this chunk */
622 /* optimal io width for this chunk */
625 /* minimal io size for this chunk */
628 /* 2^16 stripes is quite a lot, a second limit is the size of a single
633 /* sub stripes only matter for raid10 */
635 struct btrfs_stripe stripe;
636 /* additional stripes go here */
637 } __attribute__ ((__packed__));
640 * The super block basically lists the main trees of the FS.
642 struct btrfs_super_block {
643 /* The first 4 fields must match struct btrfs_header */
644 __u8 csum[BTRFS_CSUM_SIZE];
645 /* FS specific UUID, visible to user */
646 __u8 fsid[BTRFS_FSID_SIZE];
647 /* This block number */
651 /* Allowed to be different from the btrfs_header from here own down */
659 * This member has never been utilized since the very beginning, thus
660 * it's always 0 regardless of kernel version. We always use
661 * generation + 1 to read log tree root. So here we mark it deprecated.
663 __le64 __unused_log_root_transid;
666 __le64 root_dir_objectid;
670 __le32 __unused_leafsize;
672 __le32 sys_chunk_array_size;
673 __le64 chunk_root_generation;
675 __le64 compat_ro_flags;
676 __le64 incompat_flags;
679 __u8 chunk_root_level;
681 struct btrfs_dev_item dev_item;
683 char label[BTRFS_LABEL_SIZE];
685 __le64 cache_generation;
686 __le64 uuid_tree_generation;
688 /* The UUID written into btree blocks */
689 __u8 metadata_uuid[BTRFS_FSID_SIZE];
691 __u64 nr_global_roots;
693 /* Future expansion */
695 __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
696 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
698 /* Padded to 4096 bytes */
700 } __attribute__ ((__packed__));
702 #define BTRFS_FREE_SPACE_EXTENT 1
703 #define BTRFS_FREE_SPACE_BITMAP 2
705 struct btrfs_free_space_entry {
709 } __attribute__ ((__packed__));
711 struct btrfs_free_space_header {
712 struct btrfs_disk_key location;
716 } __attribute__ ((__packed__));
718 #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
719 #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
721 /* Super block flags */
722 /* Errors detected */
723 #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
725 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
726 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
727 #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
728 #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
729 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
733 * items in the extent btree are used to record the objectid of the
734 * owner of the block and the number of references
737 struct btrfs_extent_item {
741 } __attribute__ ((__packed__));
743 struct btrfs_extent_item_v0 {
745 } __attribute__ ((__packed__));
748 #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
749 #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
751 /* following flags only apply to tree blocks */
753 /* use full backrefs for extent pointers in the block */
754 #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
756 #define BTRFS_BACKREF_REV_MAX 256
757 #define BTRFS_BACKREF_REV_SHIFT 56
758 #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
759 BTRFS_BACKREF_REV_SHIFT)
761 #define BTRFS_OLD_BACKREF_REV 0
762 #define BTRFS_MIXED_BACKREF_REV 1
765 * this flag is only used internally by scrub and may be changed at any time
766 * it is only declared here to avoid collisions
768 #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
770 struct btrfs_tree_block_info {
771 struct btrfs_disk_key key;
773 } __attribute__ ((__packed__));
775 struct btrfs_extent_data_ref {
780 } __attribute__ ((__packed__));
782 struct btrfs_shared_data_ref {
784 } __attribute__ ((__packed__));
786 struct btrfs_extent_inline_ref {
789 } __attribute__ ((__packed__));
791 /* dev extents record free space on individual devices. The owner
792 * field points back to the chunk allocation mapping tree that allocated
793 * the extent. The chunk tree uuid field is a way to double check the owner
795 struct btrfs_dev_extent {
797 __le64 chunk_objectid;
800 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
801 } __attribute__ ((__packed__));
803 struct btrfs_inode_ref {
807 } __attribute__ ((__packed__));
809 struct btrfs_inode_extref {
810 __le64 parent_objectid;
815 } __attribute__ ((__packed__));
817 struct btrfs_timespec {
820 } __attribute__ ((__packed__));
822 struct btrfs_inode_item {
823 /* nfs style generation number */
825 /* transid that last touched this inode */
837 /* modification sequence number for NFS */
841 * a little future expansion, for more than this we can
842 * just grow the inode item and version it
845 struct btrfs_timespec atime;
846 struct btrfs_timespec ctime;
847 struct btrfs_timespec mtime;
848 struct btrfs_timespec otime;
849 } __attribute__ ((__packed__));
851 struct btrfs_dir_log_item {
853 } __attribute__ ((__packed__));
855 struct btrfs_dir_item {
856 struct btrfs_disk_key location;
861 } __attribute__ ((__packed__));
863 #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
866 * Internal in-memory flag that a subvolume has been marked for deletion but
867 * still visible as a directory
869 #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
871 struct btrfs_root_item {
872 struct btrfs_inode_item inode;
878 __le64 last_snapshot;
881 struct btrfs_disk_key drop_progress;
886 * The following fields appear after subvol_uuids+subvol_times
891 * This generation number is used to test if the new fields are valid
892 * and up to date while reading the root item. Every time the root item
893 * is written out, the "generation" field is copied into this field. If
894 * anyone ever mounted the fs with an older kernel, we will have
895 * mismatching generation values here and thus must invalidate the
896 * new fields. See btrfs_update_root and btrfs_find_last_root for
898 * the offset of generation_v2 is also used as the start for the memset
899 * when invalidating the fields.
901 __le64 generation_v2;
902 __u8 uuid[BTRFS_UUID_SIZE];
903 __u8 parent_uuid[BTRFS_UUID_SIZE];
904 __u8 received_uuid[BTRFS_UUID_SIZE];
905 __le64 ctransid; /* updated when an inode changes */
906 __le64 otransid; /* trans when created */
907 __le64 stransid; /* trans when sent. non-zero for received subvol */
908 __le64 rtransid; /* trans when received. non-zero for received subvol */
909 struct btrfs_timespec ctime;
910 struct btrfs_timespec otime;
911 struct btrfs_timespec stime;
912 struct btrfs_timespec rtime;
913 __le64 reserved[8]; /* for future */
914 } __attribute__ ((__packed__));
917 * Btrfs root item used to be smaller than current size. The old format ends
918 * at where member generation_v2 is.
920 static inline __u32 btrfs_legacy_root_item_size(void)
922 return offsetof(struct btrfs_root_item, generation_v2);
926 * this is used for both forward and backward root refs
928 struct btrfs_root_ref {
932 } __attribute__ ((__packed__));
934 struct btrfs_disk_balance_args {
936 * profiles to operate on, single is denoted by
937 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
943 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
944 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
957 /* devid subset filter [pstart..pend) */
961 /* btrfs virtual address space subset filter [vstart..vend) */
966 * profile to convert to, single is denoted by
967 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
971 /* BTRFS_BALANCE_ARGS_* */
975 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
976 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
988 * Process chunks that cross stripes_min..stripes_max devices,
989 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
995 } __attribute__ ((__packed__));
998 * store balance parameters to disk so that balance can be properly
999 * resumed after crash or unmount
1001 struct btrfs_balance_item {
1002 /* BTRFS_BALANCE_* */
1005 struct btrfs_disk_balance_args data;
1006 struct btrfs_disk_balance_args meta;
1007 struct btrfs_disk_balance_args sys;
1010 } __attribute__ ((__packed__));
1013 BTRFS_FILE_EXTENT_INLINE = 0,
1014 BTRFS_FILE_EXTENT_REG = 1,
1015 BTRFS_FILE_EXTENT_PREALLOC = 2,
1016 BTRFS_NR_FILE_EXTENT_TYPES = 3,
1019 struct btrfs_file_extent_item {
1021 * transaction id that created this extent
1025 * max number of bytes to hold this extent in ram
1026 * when we split a compressed extent we can't know how big
1027 * each of the resulting pieces will be. So, this is
1028 * an upper limit on the size of the extent in ram instead of
1034 * 32 bits for the various ways we might encode the data,
1035 * including compression and encryption. If any of these
1036 * are set to something a given disk format doesn't understand
1037 * it is treated like an incompat flag for reading and writing,
1042 __le16 other_encoding; /* spare for later use */
1044 /* are we inline data or a real extent? */
1048 * disk space consumed by the extent, checksum blocks are included
1051 * At this offset in the structure, the inline extent data start.
1054 __le64 disk_num_bytes;
1056 * the logical offset in file blocks (no csums)
1057 * this extent record is for. This allows a file extent to point
1058 * into the middle of an existing extent on disk, sharing it
1059 * between two snapshots (useful if some bytes in the middle of the
1060 * extent have changed
1064 * the logical number of file blocks (no csums included). This
1065 * always reflects the size uncompressed and without encoding.
1069 } __attribute__ ((__packed__));
1071 struct btrfs_csum_item {
1073 } __attribute__ ((__packed__));
1075 struct btrfs_dev_stats_item {
1077 * grow this item struct at the end for future enhancements and keep
1078 * the existing values unchanged
1080 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
1081 } __attribute__ ((__packed__));
1083 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
1084 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
1086 struct btrfs_dev_replace_item {
1088 * grow this item struct at the end for future enhancements and keep
1089 * the existing values unchanged
1093 __le64 cursor_right;
1094 __le64 cont_reading_from_srcdev_mode;
1096 __le64 replace_state;
1097 __le64 time_started;
1098 __le64 time_stopped;
1099 __le64 num_write_errors;
1100 __le64 num_uncorrectable_read_errors;
1101 } __attribute__ ((__packed__));
1103 /* different types of block groups (and chunks) */
1104 #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
1105 #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
1106 #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
1107 #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
1108 #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
1109 #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
1110 #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
1111 #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
1112 #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
1113 #define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
1114 #define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
1115 #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
1116 BTRFS_SPACE_INFO_GLOBAL_RSV)
1118 #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
1119 BTRFS_BLOCK_GROUP_SYSTEM | \
1120 BTRFS_BLOCK_GROUP_METADATA)
1122 #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
1123 BTRFS_BLOCK_GROUP_RAID1 | \
1124 BTRFS_BLOCK_GROUP_RAID1C3 | \
1125 BTRFS_BLOCK_GROUP_RAID1C4 | \
1126 BTRFS_BLOCK_GROUP_RAID5 | \
1127 BTRFS_BLOCK_GROUP_RAID6 | \
1128 BTRFS_BLOCK_GROUP_DUP | \
1129 BTRFS_BLOCK_GROUP_RAID10)
1130 #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
1131 BTRFS_BLOCK_GROUP_RAID6)
1133 #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
1134 BTRFS_BLOCK_GROUP_RAID1C3 | \
1135 BTRFS_BLOCK_GROUP_RAID1C4)
1138 * We need a bit for restriper to be able to tell when chunks of type
1139 * SINGLE are available. This "extended" profile format is used in
1140 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
1141 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
1142 * to avoid remappings between two formats in future.
1144 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
1147 * A fake block group type that is used to communicate global block reserve
1148 * size to userspace via the SPACE_INFO ioctl.
1150 #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
1152 #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
1153 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
1155 static inline __u64 chunk_to_extended(__u64 flags)
1157 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1158 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1162 static inline __u64 extended_to_chunk(__u64 flags)
1164 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1167 struct btrfs_block_group_item {
1169 __le64 chunk_objectid;
1171 } __attribute__ ((__packed__));
1173 struct btrfs_free_space_info {
1174 __le32 extent_count;
1176 } __attribute__ ((__packed__));
1178 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1180 #define BTRFS_QGROUP_LEVEL_SHIFT 48
1181 static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
1183 return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
1187 * is subvolume quota turned on?
1189 #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1191 * RESCAN is set during the initialization phase
1193 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1195 * Some qgroup entries are known to be out of date,
1196 * either because the configuration has changed in a way that
1197 * makes a rescan necessary, or because the fs has been mounted
1198 * with a non-qgroup-aware version.
1199 * Turning qouta off and on again makes it inconsistent, too.
1201 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1203 #define BTRFS_QGROUP_STATUS_FLAGS_MASK (BTRFS_QGROUP_STATUS_FLAG_ON | \
1204 BTRFS_QGROUP_STATUS_FLAG_RESCAN | \
1205 BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
1207 #define BTRFS_QGROUP_STATUS_VERSION 1
1209 struct btrfs_qgroup_status_item {
1212 * the generation is updated during every commit. As older
1213 * versions of btrfs are not aware of qgroups, it will be
1214 * possible to detect inconsistencies by checking the
1215 * generation on mount time
1219 /* flag definitions see above */
1223 * only used during scanning to record the progress
1224 * of the scan. It contains a logical address
1227 } __attribute__ ((__packed__));
1229 struct btrfs_qgroup_info_item {
1235 } __attribute__ ((__packed__));
1237 struct btrfs_qgroup_limit_item {
1239 * only updated when any of the other values change
1246 } __attribute__ ((__packed__));
1248 struct btrfs_verity_descriptor_item {
1249 /* Size of the verity descriptor in bytes */
1252 * When we implement support for fscrypt, we will need to encrypt the
1253 * Merkle tree for encrypted verity files. These 128 bits are for the
1254 * eventual storage of an fscrypt initialization vector.
1258 } __attribute__ ((__packed__));
1260 #endif /* _BTRFS_CTREE_H_ */