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 /* Tracks RAID stripes in block groups. */
77 #define BTRFS_RAID_STRIPE_TREE_OBJECTID 12ULL
79 /* device stats in the device tree */
80 #define BTRFS_DEV_STATS_OBJECTID 0ULL
82 /* for storing balance parameters in the root tree */
83 #define BTRFS_BALANCE_OBJECTID -4ULL
85 /* orphan objectid for tracking unlinked/truncated files */
86 #define BTRFS_ORPHAN_OBJECTID -5ULL
88 /* does write ahead logging to speed up fsyncs */
89 #define BTRFS_TREE_LOG_OBJECTID -6ULL
90 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
92 /* for space balancing */
93 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
94 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
97 * extent checksums all have this objectid
98 * this allows them to share the logging tree
101 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
103 /* For storing free space cache */
104 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
107 * The inode number assigned to the special inode for storing
110 #define BTRFS_FREE_INO_OBJECTID -12ULL
112 /* dummy objectid represents multiple objectids */
113 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
116 * All files have objectids in this range.
118 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
119 #define BTRFS_LAST_FREE_OBJECTID -256ULL
120 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
124 * the device items go into the chunk tree. The key is in the form
125 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
127 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
129 #define BTRFS_BTREE_INODE_OBJECTID 1
131 #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
133 #define BTRFS_DEV_REPLACE_DEVID 0ULL
136 * inode items have the data typically returned from stat and store other
137 * info about object characteristics. There is one for every file and dir in
140 #define BTRFS_INODE_ITEM_KEY 1
141 #define BTRFS_INODE_REF_KEY 12
142 #define BTRFS_INODE_EXTREF_KEY 13
143 #define BTRFS_XATTR_ITEM_KEY 24
146 * fs verity items are stored under two different key types on disk.
147 * The descriptor items:
148 * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
150 * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
151 * of the descriptor item and some extra data for encryption.
152 * Starting at offset 1, these hold the generic fs verity descriptor. The
153 * latter are opaque to btrfs, we just read and write them as a blob for the
154 * higher level verity code. The most common descriptor size is 256 bytes.
156 * The merkle tree items:
157 * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
159 * These also start at offset 0, and correspond to the merkle tree bytes. When
160 * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
161 * offset 0 for this key type. These are also opaque to btrfs, we're blindly
162 * storing whatever fsverity sends down.
164 #define BTRFS_VERITY_DESC_ITEM_KEY 36
165 #define BTRFS_VERITY_MERKLE_ITEM_KEY 37
167 #define BTRFS_ORPHAN_ITEM_KEY 48
168 /* reserve 2-15 close to the inode for later flexibility */
171 * dir items are the name -> inode pointers in a directory. There is one
172 * for every name in a directory. BTRFS_DIR_LOG_ITEM_KEY is no longer used
173 * but it's still defined here for documentation purposes and to help avoid
174 * having its numerical value reused in the future.
176 #define BTRFS_DIR_LOG_ITEM_KEY 60
177 #define BTRFS_DIR_LOG_INDEX_KEY 72
178 #define BTRFS_DIR_ITEM_KEY 84
179 #define BTRFS_DIR_INDEX_KEY 96
181 * extent data is for file data
183 #define BTRFS_EXTENT_DATA_KEY 108
186 * extent csums are stored in a separate tree and hold csums for
187 * an entire extent on disk.
189 #define BTRFS_EXTENT_CSUM_KEY 128
192 * root items point to tree roots. They are typically in the root
193 * tree used by the super block to find all the other trees
195 #define BTRFS_ROOT_ITEM_KEY 132
198 * root backrefs tie subvols and snapshots to the directory entries that
201 #define BTRFS_ROOT_BACKREF_KEY 144
204 * root refs make a fast index for listing all of the snapshots and
205 * subvolumes referenced by a given root. They point directly to the
206 * directory item in the root that references the subvol
208 #define BTRFS_ROOT_REF_KEY 156
211 * extent items are in the extent map tree. These record which blocks
212 * are used, and how many references there are to each block
214 #define BTRFS_EXTENT_ITEM_KEY 168
217 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
218 * the length, so we save the level in key->offset instead of the length.
220 #define BTRFS_METADATA_ITEM_KEY 169
222 #define BTRFS_TREE_BLOCK_REF_KEY 176
224 #define BTRFS_EXTENT_DATA_REF_KEY 178
227 * Obsolete key. Defintion removed in 6.6, value may be reused in the future.
229 * #define BTRFS_EXTENT_REF_V0_KEY 180
232 #define BTRFS_SHARED_BLOCK_REF_KEY 182
234 #define BTRFS_SHARED_DATA_REF_KEY 184
237 * Special inline ref key which stores the id of the subvolume which originally
238 * created the extent. This subvolume owns the extent permanently from the
239 * perspective of simple quotas. Needed to know which subvolume to free quota
240 * usage from when the extent is deleted.
242 #define BTRFS_EXTENT_OWNER_REF_KEY 188
245 * block groups give us hints into the extent allocation trees. Which
246 * blocks are free etc etc
248 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
251 * Every block group is represented in the free space tree by a free space info
252 * item, which stores some accounting information. It is keyed on
253 * (block_group_start, FREE_SPACE_INFO, block_group_length).
255 #define BTRFS_FREE_SPACE_INFO_KEY 198
258 * A free space extent tracks an extent of space that is free in a block group.
259 * It is keyed on (start, FREE_SPACE_EXTENT, length).
261 #define BTRFS_FREE_SPACE_EXTENT_KEY 199
264 * When a block group becomes very fragmented, we convert it to use bitmaps
265 * instead of extents. A free space bitmap is keyed on
266 * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
267 * (length / sectorsize) bits.
269 #define BTRFS_FREE_SPACE_BITMAP_KEY 200
271 #define BTRFS_DEV_EXTENT_KEY 204
272 #define BTRFS_DEV_ITEM_KEY 216
273 #define BTRFS_CHUNK_ITEM_KEY 228
275 #define BTRFS_RAID_STRIPE_KEY 230
278 * Records the overall state of the qgroups.
279 * There's only one instance of this key present,
280 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
282 #define BTRFS_QGROUP_STATUS_KEY 240
284 * Records the currently used space of the qgroup.
285 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
287 #define BTRFS_QGROUP_INFO_KEY 242
289 * Contains the user configured limits for the qgroup.
290 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
292 #define BTRFS_QGROUP_LIMIT_KEY 244
294 * Records the child-parent relationship of qgroups. For
295 * each relation, 2 keys are present:
296 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
297 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
299 #define BTRFS_QGROUP_RELATION_KEY 246
302 * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
304 #define BTRFS_BALANCE_ITEM_KEY 248
307 * The key type for tree items that are stored persistently, but do not need to
308 * exist for extended period of time. The items can exist in any tree.
310 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
314 * - balance status item
315 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
317 #define BTRFS_TEMPORARY_ITEM_KEY 248
320 * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
322 #define BTRFS_DEV_STATS_KEY 249
325 * The key type for tree items that are stored persistently and usually exist
326 * for a long period, eg. filesystem lifetime. The item kinds can be status
327 * information, stats or preference values. The item can exist in any tree.
329 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
333 * - device statistics, store IO stats in the device tree, one key for all
335 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
337 #define BTRFS_PERSISTENT_ITEM_KEY 249
340 * Persistently stores the device replace state in the device tree.
341 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
343 #define BTRFS_DEV_REPLACE_KEY 250
346 * Stores items that allow to quickly map UUIDs to something else.
347 * These items are part of the filesystem UUID tree.
348 * The key is built like this:
349 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
351 #if BTRFS_UUID_SIZE != 16
352 #error "UUID items require BTRFS_UUID_SIZE == 16!"
354 #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
355 #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
356 * received subvols */
359 * string items are for debugging. They just store a short string of
362 #define BTRFS_STRING_ITEM_KEY 253
364 /* Maximum metadata block size (nodesize) */
365 #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
367 /* 32 bytes in various csum fields */
368 #define BTRFS_CSUM_SIZE 32
371 enum btrfs_csum_type {
372 BTRFS_CSUM_TYPE_CRC32 = 0,
373 BTRFS_CSUM_TYPE_XXHASH = 1,
374 BTRFS_CSUM_TYPE_SHA256 = 2,
375 BTRFS_CSUM_TYPE_BLAKE2 = 3,
379 * flags definitions for directory entry item type
382 * struct btrfs_dir_item.type
384 * Values 0..7 must match common file type values in fs_types.h.
386 #define BTRFS_FT_UNKNOWN 0
387 #define BTRFS_FT_REG_FILE 1
388 #define BTRFS_FT_DIR 2
389 #define BTRFS_FT_CHRDEV 3
390 #define BTRFS_FT_BLKDEV 4
391 #define BTRFS_FT_FIFO 5
392 #define BTRFS_FT_SOCK 6
393 #define BTRFS_FT_SYMLINK 7
394 #define BTRFS_FT_XATTR 8
395 #define BTRFS_FT_MAX 9
396 /* Directory contains encrypted data */
397 #define BTRFS_FT_ENCRYPTED 0x80
399 static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags)
401 return flags & ~BTRFS_FT_ENCRYPTED;
407 #define BTRFS_INODE_NODATASUM (1U << 0)
408 #define BTRFS_INODE_NODATACOW (1U << 1)
409 #define BTRFS_INODE_READONLY (1U << 2)
410 #define BTRFS_INODE_NOCOMPRESS (1U << 3)
411 #define BTRFS_INODE_PREALLOC (1U << 4)
412 #define BTRFS_INODE_SYNC (1U << 5)
413 #define BTRFS_INODE_IMMUTABLE (1U << 6)
414 #define BTRFS_INODE_APPEND (1U << 7)
415 #define BTRFS_INODE_NODUMP (1U << 8)
416 #define BTRFS_INODE_NOATIME (1U << 9)
417 #define BTRFS_INODE_DIRSYNC (1U << 10)
418 #define BTRFS_INODE_COMPRESS (1U << 11)
420 #define BTRFS_INODE_ROOT_ITEM_INIT (1U << 31)
422 #define BTRFS_INODE_FLAG_MASK \
423 (BTRFS_INODE_NODATASUM | \
424 BTRFS_INODE_NODATACOW | \
425 BTRFS_INODE_READONLY | \
426 BTRFS_INODE_NOCOMPRESS | \
427 BTRFS_INODE_PREALLOC | \
429 BTRFS_INODE_IMMUTABLE | \
430 BTRFS_INODE_APPEND | \
431 BTRFS_INODE_NODUMP | \
432 BTRFS_INODE_NOATIME | \
433 BTRFS_INODE_DIRSYNC | \
434 BTRFS_INODE_COMPRESS | \
435 BTRFS_INODE_ROOT_ITEM_INIT)
437 #define BTRFS_INODE_RO_VERITY (1U << 0)
439 #define BTRFS_INODE_RO_FLAG_MASK (BTRFS_INODE_RO_VERITY)
442 * The key defines the order in the tree, and so it also defines (optimal)
445 * objectid corresponds to the inode number.
447 * type tells us things about the object, and is a kind of stream selector.
448 * so for a given inode, keys with type of 1 might refer to the inode data,
449 * type of 2 may point to file data in the btree and type == 3 may point to
452 * offset is the starting byte offset for this key in the stream.
454 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
455 * in cpu native order. Otherwise they are identical and their sizes
456 * should be the same (ie both packed)
458 struct btrfs_disk_key {
462 } __attribute__ ((__packed__));
468 } __attribute__ ((__packed__));
471 * Every tree block (leaf or node) starts with this header.
473 struct btrfs_header {
474 /* These first four must match the super block */
475 __u8 csum[BTRFS_CSUM_SIZE];
476 /* FS specific uuid */
477 __u8 fsid[BTRFS_FSID_SIZE];
478 /* Which block this node is supposed to live in */
482 /* Allowed to be different from the super from here on down */
483 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
488 } __attribute__ ((__packed__));
491 * This is a very generous portion of the super block, giving us room to
492 * translate 14 chunks with 3 stripes each.
494 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
497 * Just in case we somehow lose the roots and are not able to mount, we store
498 * an array of the roots from previous transactions in the super.
500 #define BTRFS_NUM_BACKUP_ROOTS 4
501 struct btrfs_root_backup {
503 __le64 tree_root_gen;
506 __le64 chunk_root_gen;
509 __le64 extent_root_gen;
518 __le64 csum_root_gen;
526 __u8 tree_root_level;
527 __u8 chunk_root_level;
528 __u8 extent_root_level;
531 __u8 csum_root_level;
532 /* future and to align */
534 } __attribute__ ((__packed__));
537 * A leaf is full of items. offset and size tell us where to find the item in
538 * the leaf (relative to the start of the data area)
541 struct btrfs_disk_key key;
544 } __attribute__ ((__packed__));
547 * Leaves have an item area and a data area:
548 * [item0, item1....itemN] [free space] [dataN...data1, data0]
550 * The data is separate from the items to get the keys closer together during
554 struct btrfs_header header;
555 struct btrfs_item items[];
556 } __attribute__ ((__packed__));
559 * All non-leaf blocks are nodes, they hold only keys and pointers to other
562 struct btrfs_key_ptr {
563 struct btrfs_disk_key key;
566 } __attribute__ ((__packed__));
569 struct btrfs_header header;
570 struct btrfs_key_ptr ptrs[];
571 } __attribute__ ((__packed__));
573 struct btrfs_dev_item {
574 /* the internal btrfs device id */
577 /* size of the device */
583 /* optimal io alignment for this device */
586 /* optimal io width for this device */
589 /* minimal io size for this device */
592 /* type and info about this device */
595 /* expected generation for this device */
599 * starting byte of this partition on the device,
600 * to allow for stripe alignment in the future
604 /* grouping information for allocation decisions */
607 /* seek speed 0-100 where 100 is fastest */
610 /* bandwidth 0-100 where 100 is fastest */
613 /* btrfs generated uuid for this device */
614 __u8 uuid[BTRFS_UUID_SIZE];
616 /* uuid of FS who owns this device */
617 __u8 fsid[BTRFS_UUID_SIZE];
618 } __attribute__ ((__packed__));
620 struct btrfs_stripe {
623 __u8 dev_uuid[BTRFS_UUID_SIZE];
624 } __attribute__ ((__packed__));
627 /* size of this chunk in bytes */
630 /* objectid of the root referencing this chunk */
636 /* optimal io alignment for this chunk */
639 /* optimal io width for this chunk */
642 /* minimal io size for this chunk */
645 /* 2^16 stripes is quite a lot, a second limit is the size of a single
650 /* sub stripes only matter for raid10 */
652 struct btrfs_stripe stripe;
653 /* additional stripes go here */
654 } __attribute__ ((__packed__));
657 * The super block basically lists the main trees of the FS.
659 struct btrfs_super_block {
660 /* The first 4 fields must match struct btrfs_header */
661 __u8 csum[BTRFS_CSUM_SIZE];
662 /* FS specific UUID, visible to user */
663 __u8 fsid[BTRFS_FSID_SIZE];
664 /* This block number */
668 /* Allowed to be different from the btrfs_header from here own down */
676 * This member has never been utilized since the very beginning, thus
677 * it's always 0 regardless of kernel version. We always use
678 * generation + 1 to read log tree root. So here we mark it deprecated.
680 __le64 __unused_log_root_transid;
683 __le64 root_dir_objectid;
687 __le32 __unused_leafsize;
689 __le32 sys_chunk_array_size;
690 __le64 chunk_root_generation;
692 __le64 compat_ro_flags;
693 __le64 incompat_flags;
696 __u8 chunk_root_level;
698 struct btrfs_dev_item dev_item;
700 char label[BTRFS_LABEL_SIZE];
702 __le64 cache_generation;
703 __le64 uuid_tree_generation;
705 /* The UUID written into btree blocks */
706 __u8 metadata_uuid[BTRFS_FSID_SIZE];
708 __u64 nr_global_roots;
710 /* Future expansion */
712 __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
713 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
715 /* Padded to 4096 bytes */
717 } __attribute__ ((__packed__));
719 #define BTRFS_FREE_SPACE_EXTENT 1
720 #define BTRFS_FREE_SPACE_BITMAP 2
722 struct btrfs_free_space_entry {
726 } __attribute__ ((__packed__));
728 struct btrfs_free_space_header {
729 struct btrfs_disk_key location;
733 } __attribute__ ((__packed__));
735 struct btrfs_raid_stride {
736 /* The id of device this raid extent lives on. */
738 /* The physical location on disk. */
740 } __attribute__ ((__packed__));
742 /* The stripe_extent::encoding, 1:1 mapping of enum btrfs_raid_types. */
743 #define BTRFS_STRIPE_RAID0 1
744 #define BTRFS_STRIPE_RAID1 2
745 #define BTRFS_STRIPE_DUP 3
746 #define BTRFS_STRIPE_RAID10 4
747 #define BTRFS_STRIPE_RAID5 5
748 #define BTRFS_STRIPE_RAID6 6
749 #define BTRFS_STRIPE_RAID1C3 7
750 #define BTRFS_STRIPE_RAID1C4 8
752 struct btrfs_stripe_extent {
755 /* An array of raid strides this stripe is composed of. */
756 struct btrfs_raid_stride strides[];
757 } __attribute__ ((__packed__));
759 #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
760 #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
762 /* Super block flags */
763 /* Errors detected */
764 #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
766 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
767 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
768 #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
769 #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
770 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
774 * items in the extent btree are used to record the objectid of the
775 * owner of the block and the number of references
778 struct btrfs_extent_item {
782 } __attribute__ ((__packed__));
784 struct btrfs_extent_item_v0 {
786 } __attribute__ ((__packed__));
789 #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
790 #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
792 /* following flags only apply to tree blocks */
794 /* use full backrefs for extent pointers in the block */
795 #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
797 #define BTRFS_BACKREF_REV_MAX 256
798 #define BTRFS_BACKREF_REV_SHIFT 56
799 #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
800 BTRFS_BACKREF_REV_SHIFT)
802 #define BTRFS_OLD_BACKREF_REV 0
803 #define BTRFS_MIXED_BACKREF_REV 1
806 * this flag is only used internally by scrub and may be changed at any time
807 * it is only declared here to avoid collisions
809 #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
811 struct btrfs_tree_block_info {
812 struct btrfs_disk_key key;
814 } __attribute__ ((__packed__));
816 struct btrfs_extent_data_ref {
821 } __attribute__ ((__packed__));
823 struct btrfs_shared_data_ref {
825 } __attribute__ ((__packed__));
827 struct btrfs_extent_owner_ref {
829 } __attribute__ ((__packed__));
831 struct btrfs_extent_inline_ref {
834 } __attribute__ ((__packed__));
836 /* dev extents record free space on individual devices. The owner
837 * field points back to the chunk allocation mapping tree that allocated
838 * the extent. The chunk tree uuid field is a way to double check the owner
840 struct btrfs_dev_extent {
842 __le64 chunk_objectid;
845 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
846 } __attribute__ ((__packed__));
848 struct btrfs_inode_ref {
852 } __attribute__ ((__packed__));
854 struct btrfs_inode_extref {
855 __le64 parent_objectid;
860 } __attribute__ ((__packed__));
862 struct btrfs_timespec {
865 } __attribute__ ((__packed__));
867 struct btrfs_inode_item {
868 /* nfs style generation number */
870 /* transid that last touched this inode */
882 /* modification sequence number for NFS */
886 * a little future expansion, for more than this we can
887 * just grow the inode item and version it
890 struct btrfs_timespec atime;
891 struct btrfs_timespec ctime;
892 struct btrfs_timespec mtime;
893 struct btrfs_timespec otime;
894 } __attribute__ ((__packed__));
896 struct btrfs_dir_log_item {
898 } __attribute__ ((__packed__));
900 struct btrfs_dir_item {
901 struct btrfs_disk_key location;
906 } __attribute__ ((__packed__));
908 #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
911 * Internal in-memory flag that a subvolume has been marked for deletion but
912 * still visible as a directory
914 #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
916 struct btrfs_root_item {
917 struct btrfs_inode_item inode;
923 __le64 last_snapshot;
926 struct btrfs_disk_key drop_progress;
931 * The following fields appear after subvol_uuids+subvol_times
936 * This generation number is used to test if the new fields are valid
937 * and up to date while reading the root item. Every time the root item
938 * is written out, the "generation" field is copied into this field. If
939 * anyone ever mounted the fs with an older kernel, we will have
940 * mismatching generation values here and thus must invalidate the
941 * new fields. See btrfs_update_root and btrfs_find_last_root for
943 * the offset of generation_v2 is also used as the start for the memset
944 * when invalidating the fields.
946 __le64 generation_v2;
947 __u8 uuid[BTRFS_UUID_SIZE];
948 __u8 parent_uuid[BTRFS_UUID_SIZE];
949 __u8 received_uuid[BTRFS_UUID_SIZE];
950 __le64 ctransid; /* updated when an inode changes */
951 __le64 otransid; /* trans when created */
952 __le64 stransid; /* trans when sent. non-zero for received subvol */
953 __le64 rtransid; /* trans when received. non-zero for received subvol */
954 struct btrfs_timespec ctime;
955 struct btrfs_timespec otime;
956 struct btrfs_timespec stime;
957 struct btrfs_timespec rtime;
958 __le64 reserved[8]; /* for future */
959 } __attribute__ ((__packed__));
962 * Btrfs root item used to be smaller than current size. The old format ends
963 * at where member generation_v2 is.
965 static inline __u32 btrfs_legacy_root_item_size(void)
967 return offsetof(struct btrfs_root_item, generation_v2);
971 * this is used for both forward and backward root refs
973 struct btrfs_root_ref {
977 } __attribute__ ((__packed__));
979 struct btrfs_disk_balance_args {
981 * profiles to operate on, single is denoted by
982 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
988 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
989 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
1002 /* devid subset filter [pstart..pend) */
1006 /* btrfs virtual address space subset filter [vstart..vend) */
1011 * profile to convert to, single is denoted by
1012 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
1016 /* BTRFS_BALANCE_ARGS_* */
1020 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
1021 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
1033 * Process chunks that cross stripes_min..stripes_max devices,
1034 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
1040 } __attribute__ ((__packed__));
1043 * store balance parameters to disk so that balance can be properly
1044 * resumed after crash or unmount
1046 struct btrfs_balance_item {
1047 /* BTRFS_BALANCE_* */
1050 struct btrfs_disk_balance_args data;
1051 struct btrfs_disk_balance_args meta;
1052 struct btrfs_disk_balance_args sys;
1055 } __attribute__ ((__packed__));
1058 BTRFS_FILE_EXTENT_INLINE = 0,
1059 BTRFS_FILE_EXTENT_REG = 1,
1060 BTRFS_FILE_EXTENT_PREALLOC = 2,
1061 BTRFS_NR_FILE_EXTENT_TYPES = 3,
1064 struct btrfs_file_extent_item {
1066 * transaction id that created this extent
1070 * max number of bytes to hold this extent in ram
1071 * when we split a compressed extent we can't know how big
1072 * each of the resulting pieces will be. So, this is
1073 * an upper limit on the size of the extent in ram instead of
1079 * 32 bits for the various ways we might encode the data,
1080 * including compression and encryption. If any of these
1081 * are set to something a given disk format doesn't understand
1082 * it is treated like an incompat flag for reading and writing,
1087 __le16 other_encoding; /* spare for later use */
1089 /* are we inline data or a real extent? */
1093 * disk space consumed by the extent, checksum blocks are included
1096 * At this offset in the structure, the inline extent data start.
1099 __le64 disk_num_bytes;
1101 * the logical offset in file blocks (no csums)
1102 * this extent record is for. This allows a file extent to point
1103 * into the middle of an existing extent on disk, sharing it
1104 * between two snapshots (useful if some bytes in the middle of the
1105 * extent have changed
1109 * the logical number of file blocks (no csums included). This
1110 * always reflects the size uncompressed and without encoding.
1114 } __attribute__ ((__packed__));
1116 struct btrfs_csum_item {
1118 } __attribute__ ((__packed__));
1120 struct btrfs_dev_stats_item {
1122 * grow this item struct at the end for future enhancements and keep
1123 * the existing values unchanged
1125 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
1126 } __attribute__ ((__packed__));
1128 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
1129 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
1131 struct btrfs_dev_replace_item {
1133 * grow this item struct at the end for future enhancements and keep
1134 * the existing values unchanged
1138 __le64 cursor_right;
1139 __le64 cont_reading_from_srcdev_mode;
1141 __le64 replace_state;
1142 __le64 time_started;
1143 __le64 time_stopped;
1144 __le64 num_write_errors;
1145 __le64 num_uncorrectable_read_errors;
1146 } __attribute__ ((__packed__));
1148 /* different types of block groups (and chunks) */
1149 #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
1150 #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
1151 #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
1152 #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
1153 #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
1154 #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
1155 #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
1156 #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
1157 #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
1158 #define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
1159 #define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
1160 #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
1161 BTRFS_SPACE_INFO_GLOBAL_RSV)
1163 #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
1164 BTRFS_BLOCK_GROUP_SYSTEM | \
1165 BTRFS_BLOCK_GROUP_METADATA)
1167 #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
1168 BTRFS_BLOCK_GROUP_RAID1 | \
1169 BTRFS_BLOCK_GROUP_RAID1C3 | \
1170 BTRFS_BLOCK_GROUP_RAID1C4 | \
1171 BTRFS_BLOCK_GROUP_RAID5 | \
1172 BTRFS_BLOCK_GROUP_RAID6 | \
1173 BTRFS_BLOCK_GROUP_DUP | \
1174 BTRFS_BLOCK_GROUP_RAID10)
1175 #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
1176 BTRFS_BLOCK_GROUP_RAID6)
1178 #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
1179 BTRFS_BLOCK_GROUP_RAID1C3 | \
1180 BTRFS_BLOCK_GROUP_RAID1C4)
1183 * We need a bit for restriper to be able to tell when chunks of type
1184 * SINGLE are available. This "extended" profile format is used in
1185 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
1186 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
1187 * to avoid remappings between two formats in future.
1189 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
1192 * A fake block group type that is used to communicate global block reserve
1193 * size to userspace via the SPACE_INFO ioctl.
1195 #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
1197 #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
1198 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
1200 static inline __u64 chunk_to_extended(__u64 flags)
1202 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1203 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1207 static inline __u64 extended_to_chunk(__u64 flags)
1209 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1212 struct btrfs_block_group_item {
1214 __le64 chunk_objectid;
1216 } __attribute__ ((__packed__));
1218 struct btrfs_free_space_info {
1219 __le32 extent_count;
1221 } __attribute__ ((__packed__));
1223 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1225 #define BTRFS_QGROUP_LEVEL_SHIFT 48
1226 static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
1228 return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
1232 * is subvolume quota turned on?
1234 #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1236 * RESCAN is set during the initialization phase
1238 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1240 * Some qgroup entries are known to be out of date,
1241 * either because the configuration has changed in a way that
1242 * makes a rescan necessary, or because the fs has been mounted
1243 * with a non-qgroup-aware version.
1244 * Turning qouta off and on again makes it inconsistent, too.
1246 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1249 * Whether or not this filesystem is using simple quotas. Not exactly the
1250 * incompat bit, because we support using simple quotas, disabling it, then
1251 * going back to full qgroup quotas.
1253 #define BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE (1ULL << 3)
1255 #define BTRFS_QGROUP_STATUS_FLAGS_MASK (BTRFS_QGROUP_STATUS_FLAG_ON | \
1256 BTRFS_QGROUP_STATUS_FLAG_RESCAN | \
1257 BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | \
1258 BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE)
1260 #define BTRFS_QGROUP_STATUS_VERSION 1
1262 struct btrfs_qgroup_status_item {
1265 * the generation is updated during every commit. As older
1266 * versions of btrfs are not aware of qgroups, it will be
1267 * possible to detect inconsistencies by checking the
1268 * generation on mount time
1272 /* flag definitions see above */
1276 * only used during scanning to record the progress
1277 * of the scan. It contains a logical address
1282 * The generation when quotas were last enabled. Used by simple quotas to
1283 * avoid decrementing when freeing an extent that was written before
1286 * Set only if flags contain BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE.
1289 } __attribute__ ((__packed__));
1291 struct btrfs_qgroup_info_item {
1297 } __attribute__ ((__packed__));
1299 struct btrfs_qgroup_limit_item {
1301 * only updated when any of the other values change
1308 } __attribute__ ((__packed__));
1310 struct btrfs_verity_descriptor_item {
1311 /* Size of the verity descriptor in bytes */
1314 * When we implement support for fscrypt, we will need to encrypt the
1315 * Merkle tree for encrypted verity files. These 128 bits are for the
1316 * eventual storage of an fscrypt initialization vector.
1320 } __attribute__ ((__packed__));
1322 #endif /* _BTRFS_CTREE_H_ */