xref: /linux/include/uapi/linux/btrfs_tree.h (revision 136292522e43da46bee4c0fef80b2602f79525a2)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2db671160SJeff Mahoney #ifndef _BTRFS_CTREE_H_
3db671160SJeff Mahoney #define _BTRFS_CTREE_H_
4db671160SJeff Mahoney 
53a4e7f56SNicolas Dichtel #include <linux/btrfs.h>
69078b4eeSNicolas Dichtel #include <linux/types.h>
71465af12SQu Wenruo #ifdef __KERNEL__
81465af12SQu Wenruo #include <linux/stddef.h>
91465af12SQu Wenruo #else
101465af12SQu Wenruo #include <stddef.h>
111465af12SQu Wenruo #endif
129078b4eeSNicolas Dichtel 
134300c58fSJosef Bacik /* ASCII for _BHRfS_M, no terminating nul */
144300c58fSJosef Bacik #define BTRFS_MAGIC 0x4D5F53665248425FULL
154300c58fSJosef Bacik 
164300c58fSJosef Bacik #define BTRFS_MAX_LEVEL 8
174300c58fSJosef Bacik 
18db671160SJeff Mahoney /*
19ad4b63caSJosef Bacik  * We can actually store much bigger names, but lets not confuse the rest of
20ad4b63caSJosef Bacik  * linux.
21ad4b63caSJosef Bacik  */
22ad4b63caSJosef Bacik #define BTRFS_NAME_LEN 255
23ad4b63caSJosef Bacik 
24ad4b63caSJosef Bacik /*
25ad4b63caSJosef Bacik  * Theoretical limit is larger, but we keep this down to a sane value. That
26ad4b63caSJosef Bacik  * should limit greatly the possibility of collisions on inode ref items.
27ad4b63caSJosef Bacik  */
28ad4b63caSJosef Bacik #define BTRFS_LINK_MAX 65535U
29ad4b63caSJosef Bacik 
30ad4b63caSJosef Bacik /*
31db671160SJeff Mahoney  * This header contains the structure definitions and constants used
32db671160SJeff Mahoney  * by file system objects that can be retrieved using
33db671160SJeff Mahoney  * the BTRFS_IOC_SEARCH_TREE ioctl.  That means basically anything that
34db671160SJeff Mahoney  * is needed to describe a leaf node's key or item contents.
35db671160SJeff Mahoney  */
36db671160SJeff Mahoney 
37db671160SJeff Mahoney /* holds pointers to all of the tree roots */
38db671160SJeff Mahoney #define BTRFS_ROOT_TREE_OBJECTID 1ULL
39db671160SJeff Mahoney 
40db671160SJeff Mahoney /* stores information about which extents are in use, and reference counts */
41db671160SJeff Mahoney #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
42db671160SJeff Mahoney 
43db671160SJeff Mahoney /*
44db671160SJeff Mahoney  * chunk tree stores translations from logical -> physical block numbering
45db671160SJeff Mahoney  * the super block points to the chunk tree
46db671160SJeff Mahoney  */
47db671160SJeff Mahoney #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
48db671160SJeff Mahoney 
49db671160SJeff Mahoney /*
50db671160SJeff Mahoney  * stores information about which areas of a given device are in use.
51db671160SJeff Mahoney  * one per device.  The tree of tree roots points to the device tree
52db671160SJeff Mahoney  */
53db671160SJeff Mahoney #define BTRFS_DEV_TREE_OBJECTID 4ULL
54db671160SJeff Mahoney 
55db671160SJeff Mahoney /* one per subvolume, storing files and directories */
56db671160SJeff Mahoney #define BTRFS_FS_TREE_OBJECTID 5ULL
57db671160SJeff Mahoney 
58db671160SJeff Mahoney /* directory objectid inside the root tree */
59db671160SJeff Mahoney #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
60db671160SJeff Mahoney 
61db671160SJeff Mahoney /* holds checksums of all the data extents */
62db671160SJeff Mahoney #define BTRFS_CSUM_TREE_OBJECTID 7ULL
63db671160SJeff Mahoney 
64db671160SJeff Mahoney /* holds quota configuration and tracking */
65db671160SJeff Mahoney #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
66db671160SJeff Mahoney 
67db671160SJeff Mahoney /* for storing items that use the BTRFS_UUID_KEY* types */
68db671160SJeff Mahoney #define BTRFS_UUID_TREE_OBJECTID 9ULL
69db671160SJeff Mahoney 
70db671160SJeff Mahoney /* tracks free space in block groups. */
71db671160SJeff Mahoney #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
72db671160SJeff Mahoney 
739c54e80dSJosef Bacik /* Holds the block group items for extent tree v2. */
749c54e80dSJosef Bacik #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
759c54e80dSJosef Bacik 
76ee129330SJohannes Thumshirn /* Tracks RAID stripes in block groups. */
77ee129330SJohannes Thumshirn #define BTRFS_RAID_STRIPE_TREE_OBJECTID 12ULL
78ee129330SJohannes Thumshirn 
79db671160SJeff Mahoney /* device stats in the device tree */
80db671160SJeff Mahoney #define BTRFS_DEV_STATS_OBJECTID 0ULL
81db671160SJeff Mahoney 
82db671160SJeff Mahoney /* for storing balance parameters in the root tree */
83db671160SJeff Mahoney #define BTRFS_BALANCE_OBJECTID -4ULL
84db671160SJeff Mahoney 
851a9fd417SDavid Sterba /* orphan objectid for tracking unlinked/truncated files */
86db671160SJeff Mahoney #define BTRFS_ORPHAN_OBJECTID -5ULL
87db671160SJeff Mahoney 
88db671160SJeff Mahoney /* does write ahead logging to speed up fsyncs */
89db671160SJeff Mahoney #define BTRFS_TREE_LOG_OBJECTID -6ULL
90db671160SJeff Mahoney #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
91db671160SJeff Mahoney 
92db671160SJeff Mahoney /* for space balancing */
93db671160SJeff Mahoney #define BTRFS_TREE_RELOC_OBJECTID -8ULL
94db671160SJeff Mahoney #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
95db671160SJeff Mahoney 
96db671160SJeff Mahoney /*
97db671160SJeff Mahoney  * extent checksums all have this objectid
98db671160SJeff Mahoney  * this allows them to share the logging tree
99db671160SJeff Mahoney  * for fsyncs
100db671160SJeff Mahoney  */
101db671160SJeff Mahoney #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
102db671160SJeff Mahoney 
103db671160SJeff Mahoney /* For storing free space cache */
104db671160SJeff Mahoney #define BTRFS_FREE_SPACE_OBJECTID -11ULL
105db671160SJeff Mahoney 
106db671160SJeff Mahoney /*
107db671160SJeff Mahoney  * The inode number assigned to the special inode for storing
108db671160SJeff Mahoney  * free ino cache
109db671160SJeff Mahoney  */
110db671160SJeff Mahoney #define BTRFS_FREE_INO_OBJECTID -12ULL
111db671160SJeff Mahoney 
112db671160SJeff Mahoney /* dummy objectid represents multiple objectids */
113db671160SJeff Mahoney #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
114db671160SJeff Mahoney 
115db671160SJeff Mahoney /*
116db671160SJeff Mahoney  * All files have objectids in this range.
117db671160SJeff Mahoney  */
118db671160SJeff Mahoney #define BTRFS_FIRST_FREE_OBJECTID 256ULL
119db671160SJeff Mahoney #define BTRFS_LAST_FREE_OBJECTID -256ULL
120db671160SJeff Mahoney #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
121db671160SJeff Mahoney 
122db671160SJeff Mahoney 
123db671160SJeff Mahoney /*
124db671160SJeff Mahoney  * the device items go into the chunk tree.  The key is in the form
125db671160SJeff Mahoney  * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
126db671160SJeff Mahoney  */
127db671160SJeff Mahoney #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
128db671160SJeff Mahoney 
129db671160SJeff Mahoney #define BTRFS_BTREE_INODE_OBJECTID 1
130db671160SJeff Mahoney 
131db671160SJeff Mahoney #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
132db671160SJeff Mahoney 
133db671160SJeff Mahoney #define BTRFS_DEV_REPLACE_DEVID 0ULL
134db671160SJeff Mahoney 
135db671160SJeff Mahoney /*
136db671160SJeff Mahoney  * inode items have the data typically returned from stat and store other
137db671160SJeff Mahoney  * info about object characteristics.  There is one for every file and dir in
138db671160SJeff Mahoney  * the FS
139db671160SJeff Mahoney  */
140db671160SJeff Mahoney #define BTRFS_INODE_ITEM_KEY		1
141db671160SJeff Mahoney #define BTRFS_INODE_REF_KEY		12
142db671160SJeff Mahoney #define BTRFS_INODE_EXTREF_KEY		13
143db671160SJeff Mahoney #define BTRFS_XATTR_ITEM_KEY		24
14414605409SBoris Burkov 
14514605409SBoris Burkov /*
14614605409SBoris Burkov  * fs verity items are stored under two different key types on disk.
14714605409SBoris Burkov  * The descriptor items:
14814605409SBoris Burkov  * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
14914605409SBoris Burkov  *
15014605409SBoris Burkov  * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
15114605409SBoris Burkov  * of the descriptor item and some extra data for encryption.
15214605409SBoris Burkov  * Starting at offset 1, these hold the generic fs verity descriptor.  The
15314605409SBoris Burkov  * latter are opaque to btrfs, we just read and write them as a blob for the
15414605409SBoris Burkov  * higher level verity code.  The most common descriptor size is 256 bytes.
15514605409SBoris Burkov  *
15614605409SBoris Burkov  * The merkle tree items:
15714605409SBoris Burkov  * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
15814605409SBoris Burkov  *
15914605409SBoris Burkov  * These also start at offset 0, and correspond to the merkle tree bytes.  When
16014605409SBoris Burkov  * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
16114605409SBoris Burkov  * offset 0 for this key type.  These are also opaque to btrfs, we're blindly
16214605409SBoris Burkov  * storing whatever fsverity sends down.
16314605409SBoris Burkov  */
16414605409SBoris Burkov #define BTRFS_VERITY_DESC_ITEM_KEY	36
16514605409SBoris Burkov #define BTRFS_VERITY_MERKLE_ITEM_KEY	37
16614605409SBoris Burkov 
167db671160SJeff Mahoney #define BTRFS_ORPHAN_ITEM_KEY		48
168db671160SJeff Mahoney /* reserve 2-15 close to the inode for later flexibility */
169db671160SJeff Mahoney 
170db671160SJeff Mahoney /*
171db671160SJeff Mahoney  * dir items are the name -> inode pointers in a directory.  There is one
172ccae4a19SFilipe Manana  * for every name in a directory.  BTRFS_DIR_LOG_ITEM_KEY is no longer used
173ccae4a19SFilipe Manana  * but it's still defined here for documentation purposes and to help avoid
174ccae4a19SFilipe Manana  * having its numerical value reused in the future.
175db671160SJeff Mahoney  */
176db671160SJeff Mahoney #define BTRFS_DIR_LOG_ITEM_KEY  60
177db671160SJeff Mahoney #define BTRFS_DIR_LOG_INDEX_KEY 72
178db671160SJeff Mahoney #define BTRFS_DIR_ITEM_KEY	84
179db671160SJeff Mahoney #define BTRFS_DIR_INDEX_KEY	96
180db671160SJeff Mahoney /*
181db671160SJeff Mahoney  * extent data is for file data
182db671160SJeff Mahoney  */
183db671160SJeff Mahoney #define BTRFS_EXTENT_DATA_KEY	108
184db671160SJeff Mahoney 
185db671160SJeff Mahoney /*
186db671160SJeff Mahoney  * extent csums are stored in a separate tree and hold csums for
187db671160SJeff Mahoney  * an entire extent on disk.
188db671160SJeff Mahoney  */
189db671160SJeff Mahoney #define BTRFS_EXTENT_CSUM_KEY	128
190db671160SJeff Mahoney 
191db671160SJeff Mahoney /*
192db671160SJeff Mahoney  * root items point to tree roots.  They are typically in the root
193db671160SJeff Mahoney  * tree used by the super block to find all the other trees
194db671160SJeff Mahoney  */
195db671160SJeff Mahoney #define BTRFS_ROOT_ITEM_KEY	132
196db671160SJeff Mahoney 
197db671160SJeff Mahoney /*
198db671160SJeff Mahoney  * root backrefs tie subvols and snapshots to the directory entries that
199db671160SJeff Mahoney  * reference them
200db671160SJeff Mahoney  */
201db671160SJeff Mahoney #define BTRFS_ROOT_BACKREF_KEY	144
202db671160SJeff Mahoney 
203db671160SJeff Mahoney /*
204db671160SJeff Mahoney  * root refs make a fast index for listing all of the snapshots and
205db671160SJeff Mahoney  * subvolumes referenced by a given root.  They point directly to the
206db671160SJeff Mahoney  * directory item in the root that references the subvol
207db671160SJeff Mahoney  */
208db671160SJeff Mahoney #define BTRFS_ROOT_REF_KEY	156
209db671160SJeff Mahoney 
210db671160SJeff Mahoney /*
211db671160SJeff Mahoney  * extent items are in the extent map tree.  These record which blocks
212db671160SJeff Mahoney  * are used, and how many references there are to each block
213db671160SJeff Mahoney  */
214db671160SJeff Mahoney #define BTRFS_EXTENT_ITEM_KEY	168
215db671160SJeff Mahoney 
216db671160SJeff Mahoney /*
217db671160SJeff Mahoney  * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
218db671160SJeff Mahoney  * the length, so we save the level in key->offset instead of the length.
219db671160SJeff Mahoney  */
220db671160SJeff Mahoney #define BTRFS_METADATA_ITEM_KEY	169
221db671160SJeff Mahoney 
222*d3933152SBoris Burkov /*
223*d3933152SBoris Burkov  * Special inline ref key which stores the id of the subvolume which originally
224*d3933152SBoris Burkov  * created the extent. This subvolume owns the extent permanently from the
225*d3933152SBoris Burkov  * perspective of simple quotas. Needed to know which subvolume to free quota
226*d3933152SBoris Burkov  * usage from when the extent is deleted.
227*d3933152SBoris Burkov  *
228*d3933152SBoris Burkov  * Stored as an inline ref rather to avoid wasting space on a separate item on
229*d3933152SBoris Burkov  * top of the existing extent item. However, unlike the other inline refs,
230*d3933152SBoris Burkov  * there is one one owner ref per extent rather than one per extent.
231*d3933152SBoris Burkov  *
232*d3933152SBoris Burkov  * Because of this, it goes at the front of the list of inline refs, and thus
233*d3933152SBoris Burkov  * must have a lower type value than any other inline ref type (to satisfy the
234*d3933152SBoris Burkov  * disk format rule that inline refs have non-decreasing type).
235*d3933152SBoris Burkov  */
236*d3933152SBoris Burkov #define BTRFS_EXTENT_OWNER_REF_KEY	172
237*d3933152SBoris Burkov 
238db671160SJeff Mahoney #define BTRFS_TREE_BLOCK_REF_KEY	176
239db671160SJeff Mahoney 
240db671160SJeff Mahoney #define BTRFS_EXTENT_DATA_REF_KEY	178
241db671160SJeff Mahoney 
242182741d2SQu Wenruo /*
243182741d2SQu Wenruo  * Obsolete key. Defintion removed in 6.6, value may be reused in the future.
244182741d2SQu Wenruo  *
245182741d2SQu Wenruo  * #define BTRFS_EXTENT_REF_V0_KEY	180
246182741d2SQu Wenruo  */
247db671160SJeff Mahoney 
248db671160SJeff Mahoney #define BTRFS_SHARED_BLOCK_REF_KEY	182
249db671160SJeff Mahoney 
250db671160SJeff Mahoney #define BTRFS_SHARED_DATA_REF_KEY	184
251db671160SJeff Mahoney 
252db671160SJeff Mahoney /*
253db671160SJeff Mahoney  * block groups give us hints into the extent allocation trees.  Which
254db671160SJeff Mahoney  * blocks are free etc etc
255db671160SJeff Mahoney  */
256db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
257db671160SJeff Mahoney 
258db671160SJeff Mahoney /*
259db671160SJeff Mahoney  * Every block group is represented in the free space tree by a free space info
260db671160SJeff Mahoney  * item, which stores some accounting information. It is keyed on
261db671160SJeff Mahoney  * (block_group_start, FREE_SPACE_INFO, block_group_length).
262db671160SJeff Mahoney  */
263db671160SJeff Mahoney #define BTRFS_FREE_SPACE_INFO_KEY 198
264db671160SJeff Mahoney 
265db671160SJeff Mahoney /*
266db671160SJeff Mahoney  * A free space extent tracks an extent of space that is free in a block group.
267db671160SJeff Mahoney  * It is keyed on (start, FREE_SPACE_EXTENT, length).
268db671160SJeff Mahoney  */
269db671160SJeff Mahoney #define BTRFS_FREE_SPACE_EXTENT_KEY 199
270db671160SJeff Mahoney 
271db671160SJeff Mahoney /*
272db671160SJeff Mahoney  * When a block group becomes very fragmented, we convert it to use bitmaps
273db671160SJeff Mahoney  * instead of extents. A free space bitmap is keyed on
274db671160SJeff Mahoney  * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
275db671160SJeff Mahoney  * (length / sectorsize) bits.
276db671160SJeff Mahoney  */
277db671160SJeff Mahoney #define BTRFS_FREE_SPACE_BITMAP_KEY 200
278db671160SJeff Mahoney 
279db671160SJeff Mahoney #define BTRFS_DEV_EXTENT_KEY	204
280db671160SJeff Mahoney #define BTRFS_DEV_ITEM_KEY	216
281db671160SJeff Mahoney #define BTRFS_CHUNK_ITEM_KEY	228
282db671160SJeff Mahoney 
283ee129330SJohannes Thumshirn #define BTRFS_RAID_STRIPE_KEY	230
284ee129330SJohannes Thumshirn 
285db671160SJeff Mahoney /*
286db671160SJeff Mahoney  * Records the overall state of the qgroups.
287db671160SJeff Mahoney  * There's only one instance of this key present,
288db671160SJeff Mahoney  * (0, BTRFS_QGROUP_STATUS_KEY, 0)
289db671160SJeff Mahoney  */
290db671160SJeff Mahoney #define BTRFS_QGROUP_STATUS_KEY         240
291db671160SJeff Mahoney /*
292db671160SJeff Mahoney  * Records the currently used space of the qgroup.
293db671160SJeff Mahoney  * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
294db671160SJeff Mahoney  */
295db671160SJeff Mahoney #define BTRFS_QGROUP_INFO_KEY           242
296db671160SJeff Mahoney /*
297db671160SJeff Mahoney  * Contains the user configured limits for the qgroup.
298db671160SJeff Mahoney  * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
299db671160SJeff Mahoney  */
300db671160SJeff Mahoney #define BTRFS_QGROUP_LIMIT_KEY          244
301db671160SJeff Mahoney /*
302db671160SJeff Mahoney  * Records the child-parent relationship of qgroups. For
303db671160SJeff Mahoney  * each relation, 2 keys are present:
304db671160SJeff Mahoney  * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
305db671160SJeff Mahoney  * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
306db671160SJeff Mahoney  */
307db671160SJeff Mahoney #define BTRFS_QGROUP_RELATION_KEY       246
308db671160SJeff Mahoney 
309db671160SJeff Mahoney /*
310db671160SJeff Mahoney  * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
311db671160SJeff Mahoney  */
312db671160SJeff Mahoney #define BTRFS_BALANCE_ITEM_KEY	248
313db671160SJeff Mahoney 
314db671160SJeff Mahoney /*
315db671160SJeff Mahoney  * The key type for tree items that are stored persistently, but do not need to
316db671160SJeff Mahoney  * exist for extended period of time. The items can exist in any tree.
317db671160SJeff Mahoney  *
318db671160SJeff Mahoney  * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
319db671160SJeff Mahoney  *
320db671160SJeff Mahoney  * Existing items:
321db671160SJeff Mahoney  *
322db671160SJeff Mahoney  * - balance status item
323db671160SJeff Mahoney  *   (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
324db671160SJeff Mahoney  */
325db671160SJeff Mahoney #define BTRFS_TEMPORARY_ITEM_KEY	248
326db671160SJeff Mahoney 
327db671160SJeff Mahoney /*
328db671160SJeff Mahoney  * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
329db671160SJeff Mahoney  */
330db671160SJeff Mahoney #define BTRFS_DEV_STATS_KEY		249
331db671160SJeff Mahoney 
332db671160SJeff Mahoney /*
333db671160SJeff Mahoney  * The key type for tree items that are stored persistently and usually exist
334db671160SJeff Mahoney  * for a long period, eg. filesystem lifetime. The item kinds can be status
335db671160SJeff Mahoney  * information, stats or preference values. The item can exist in any tree.
336db671160SJeff Mahoney  *
337db671160SJeff Mahoney  * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
338db671160SJeff Mahoney  *
339db671160SJeff Mahoney  * Existing items:
340db671160SJeff Mahoney  *
341db671160SJeff Mahoney  * - device statistics, store IO stats in the device tree, one key for all
342db671160SJeff Mahoney  *   stats
343db671160SJeff Mahoney  *   (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
344db671160SJeff Mahoney  */
345db671160SJeff Mahoney #define BTRFS_PERSISTENT_ITEM_KEY	249
346db671160SJeff Mahoney 
347db671160SJeff Mahoney /*
3481a9fd417SDavid Sterba  * Persistently stores the device replace state in the device tree.
349db671160SJeff Mahoney  * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
350db671160SJeff Mahoney  */
351db671160SJeff Mahoney #define BTRFS_DEV_REPLACE_KEY	250
352db671160SJeff Mahoney 
353db671160SJeff Mahoney /*
354db671160SJeff Mahoney  * Stores items that allow to quickly map UUIDs to something else.
355db671160SJeff Mahoney  * These items are part of the filesystem UUID tree.
356db671160SJeff Mahoney  * The key is built like this:
357db671160SJeff Mahoney  * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
358db671160SJeff Mahoney  */
359db671160SJeff Mahoney #if BTRFS_UUID_SIZE != 16
360db671160SJeff Mahoney #error "UUID items require BTRFS_UUID_SIZE == 16!"
361db671160SJeff Mahoney #endif
362db671160SJeff Mahoney #define BTRFS_UUID_KEY_SUBVOL	251	/* for UUIDs assigned to subvols */
363db671160SJeff Mahoney #define BTRFS_UUID_KEY_RECEIVED_SUBVOL	252	/* for UUIDs assigned to
364db671160SJeff Mahoney 						 * received subvols */
365db671160SJeff Mahoney 
366db671160SJeff Mahoney /*
367db671160SJeff Mahoney  * string items are for debugging.  They just store a short string of
368db671160SJeff Mahoney  * data in the FS
369db671160SJeff Mahoney  */
370db671160SJeff Mahoney #define BTRFS_STRING_ITEM_KEY	253
371db671160SJeff Mahoney 
372deb67895SQu Wenruo /* Maximum metadata block size (nodesize) */
373deb67895SQu Wenruo #define BTRFS_MAX_METADATA_BLOCKSIZE			65536
374db671160SJeff Mahoney 
375db671160SJeff Mahoney /* 32 bytes in various csum fields */
376db671160SJeff Mahoney #define BTRFS_CSUM_SIZE 32
377db671160SJeff Mahoney 
378db671160SJeff Mahoney /* csum types */
379e35b79a1SJohannes Thumshirn enum btrfs_csum_type {
380e35b79a1SJohannes Thumshirn 	BTRFS_CSUM_TYPE_CRC32	= 0,
3813951e7f0SJohannes Thumshirn 	BTRFS_CSUM_TYPE_XXHASH	= 1,
3823831bf00SJohannes Thumshirn 	BTRFS_CSUM_TYPE_SHA256	= 2,
383352ae07bSDavid Sterba 	BTRFS_CSUM_TYPE_BLAKE2	= 3,
384e35b79a1SJohannes Thumshirn };
385db671160SJeff Mahoney 
386db671160SJeff Mahoney /*
387db671160SJeff Mahoney  * flags definitions for directory entry item type
388db671160SJeff Mahoney  *
389db671160SJeff Mahoney  * Used by:
390db671160SJeff Mahoney  * struct btrfs_dir_item.type
3917d157c3dSPhillip Potter  *
3927d157c3dSPhillip Potter  * Values 0..7 must match common file type values in fs_types.h.
393db671160SJeff Mahoney  */
394db671160SJeff Mahoney #define BTRFS_FT_UNKNOWN	0
395db671160SJeff Mahoney #define BTRFS_FT_REG_FILE	1
396db671160SJeff Mahoney #define BTRFS_FT_DIR		2
397db671160SJeff Mahoney #define BTRFS_FT_CHRDEV		3
398db671160SJeff Mahoney #define BTRFS_FT_BLKDEV		4
399db671160SJeff Mahoney #define BTRFS_FT_FIFO		5
400db671160SJeff Mahoney #define BTRFS_FT_SOCK		6
401db671160SJeff Mahoney #define BTRFS_FT_SYMLINK	7
402db671160SJeff Mahoney #define BTRFS_FT_XATTR		8
403db671160SJeff Mahoney #define BTRFS_FT_MAX		9
40494a48aefSOmar Sandoval /* Directory contains encrypted data */
40594a48aefSOmar Sandoval #define BTRFS_FT_ENCRYPTED	0x80
40694a48aefSOmar Sandoval 
btrfs_dir_flags_to_ftype(__u8 flags)40794a48aefSOmar Sandoval static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags)
40894a48aefSOmar Sandoval {
40994a48aefSOmar Sandoval 	return flags & ~BTRFS_FT_ENCRYPTED;
41094a48aefSOmar Sandoval }
411db671160SJeff Mahoney 
412db671160SJeff Mahoney /*
4134300c58fSJosef Bacik  * Inode flags
4144300c58fSJosef Bacik  */
4154300c58fSJosef Bacik #define BTRFS_INODE_NODATASUM		(1U << 0)
4164300c58fSJosef Bacik #define BTRFS_INODE_NODATACOW		(1U << 1)
4174300c58fSJosef Bacik #define BTRFS_INODE_READONLY		(1U << 2)
4184300c58fSJosef Bacik #define BTRFS_INODE_NOCOMPRESS		(1U << 3)
4194300c58fSJosef Bacik #define BTRFS_INODE_PREALLOC		(1U << 4)
4204300c58fSJosef Bacik #define BTRFS_INODE_SYNC		(1U << 5)
4214300c58fSJosef Bacik #define BTRFS_INODE_IMMUTABLE		(1U << 6)
4224300c58fSJosef Bacik #define BTRFS_INODE_APPEND		(1U << 7)
4234300c58fSJosef Bacik #define BTRFS_INODE_NODUMP		(1U << 8)
4244300c58fSJosef Bacik #define BTRFS_INODE_NOATIME		(1U << 9)
4254300c58fSJosef Bacik #define BTRFS_INODE_DIRSYNC		(1U << 10)
4264300c58fSJosef Bacik #define BTRFS_INODE_COMPRESS		(1U << 11)
4274300c58fSJosef Bacik 
4284300c58fSJosef Bacik #define BTRFS_INODE_ROOT_ITEM_INIT	(1U << 31)
4294300c58fSJosef Bacik 
4304300c58fSJosef Bacik #define BTRFS_INODE_FLAG_MASK						\
4314300c58fSJosef Bacik 	(BTRFS_INODE_NODATASUM |					\
4324300c58fSJosef Bacik 	 BTRFS_INODE_NODATACOW |					\
4334300c58fSJosef Bacik 	 BTRFS_INODE_READONLY |						\
4344300c58fSJosef Bacik 	 BTRFS_INODE_NOCOMPRESS |					\
4354300c58fSJosef Bacik 	 BTRFS_INODE_PREALLOC |						\
4364300c58fSJosef Bacik 	 BTRFS_INODE_SYNC |						\
4374300c58fSJosef Bacik 	 BTRFS_INODE_IMMUTABLE |					\
4384300c58fSJosef Bacik 	 BTRFS_INODE_APPEND |						\
4394300c58fSJosef Bacik 	 BTRFS_INODE_NODUMP |						\
4404300c58fSJosef Bacik 	 BTRFS_INODE_NOATIME |						\
4414300c58fSJosef Bacik 	 BTRFS_INODE_DIRSYNC |						\
4424300c58fSJosef Bacik 	 BTRFS_INODE_COMPRESS |						\
4434300c58fSJosef Bacik 	 BTRFS_INODE_ROOT_ITEM_INIT)
4444300c58fSJosef Bacik 
4454300c58fSJosef Bacik #define BTRFS_INODE_RO_VERITY		(1U << 0)
4464300c58fSJosef Bacik 
4474300c58fSJosef Bacik #define BTRFS_INODE_RO_FLAG_MASK	(BTRFS_INODE_RO_VERITY)
4484300c58fSJosef Bacik 
4494300c58fSJosef Bacik /*
450db671160SJeff Mahoney  * The key defines the order in the tree, and so it also defines (optimal)
451db671160SJeff Mahoney  * block layout.
452db671160SJeff Mahoney  *
453db671160SJeff Mahoney  * objectid corresponds to the inode number.
454db671160SJeff Mahoney  *
455db671160SJeff Mahoney  * type tells us things about the object, and is a kind of stream selector.
456db671160SJeff Mahoney  * so for a given inode, keys with type of 1 might refer to the inode data,
457db671160SJeff Mahoney  * type of 2 may point to file data in the btree and type == 3 may point to
458db671160SJeff Mahoney  * extents.
459db671160SJeff Mahoney  *
460db671160SJeff Mahoney  * offset is the starting byte offset for this key in the stream.
461db671160SJeff Mahoney  *
462db671160SJeff Mahoney  * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
463db671160SJeff Mahoney  * in cpu native order.  Otherwise they are identical and their sizes
464db671160SJeff Mahoney  * should be the same (ie both packed)
465db671160SJeff Mahoney  */
466db671160SJeff Mahoney struct btrfs_disk_key {
467db671160SJeff Mahoney 	__le64 objectid;
46814b05c51SJeff Mahoney 	__u8 type;
469db671160SJeff Mahoney 	__le64 offset;
470db671160SJeff Mahoney } __attribute__ ((__packed__));
471db671160SJeff Mahoney 
472db671160SJeff Mahoney struct btrfs_key {
47314b05c51SJeff Mahoney 	__u64 objectid;
47414b05c51SJeff Mahoney 	__u8 type;
47514b05c51SJeff Mahoney 	__u64 offset;
476db671160SJeff Mahoney } __attribute__ ((__packed__));
477db671160SJeff Mahoney 
4784300c58fSJosef Bacik /*
4794300c58fSJosef Bacik  * Every tree block (leaf or node) starts with this header.
4804300c58fSJosef Bacik  */
4814300c58fSJosef Bacik struct btrfs_header {
4824300c58fSJosef Bacik 	/* These first four must match the super block */
4834300c58fSJosef Bacik 	__u8 csum[BTRFS_CSUM_SIZE];
4844300c58fSJosef Bacik 	/* FS specific uuid */
4854300c58fSJosef Bacik 	__u8 fsid[BTRFS_FSID_SIZE];
4864300c58fSJosef Bacik 	/* Which block this node is supposed to live in */
4874300c58fSJosef Bacik 	__le64 bytenr;
4884300c58fSJosef Bacik 	__le64 flags;
4894300c58fSJosef Bacik 
4904300c58fSJosef Bacik 	/* Allowed to be different from the super from here on down */
4914300c58fSJosef Bacik 	__u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
4924300c58fSJosef Bacik 	__le64 generation;
4934300c58fSJosef Bacik 	__le64 owner;
4944300c58fSJosef Bacik 	__le32 nritems;
4954300c58fSJosef Bacik 	__u8 level;
4964300c58fSJosef Bacik } __attribute__ ((__packed__));
4974300c58fSJosef Bacik 
4984300c58fSJosef Bacik /*
4994300c58fSJosef Bacik  * This is a very generous portion of the super block, giving us room to
5004300c58fSJosef Bacik  * translate 14 chunks with 3 stripes each.
5014300c58fSJosef Bacik  */
5024300c58fSJosef Bacik #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
5034300c58fSJosef Bacik 
5044300c58fSJosef Bacik /*
5054300c58fSJosef Bacik  * Just in case we somehow lose the roots and are not able to mount, we store
5064300c58fSJosef Bacik  * an array of the roots from previous transactions in the super.
5074300c58fSJosef Bacik  */
5084300c58fSJosef Bacik #define BTRFS_NUM_BACKUP_ROOTS 4
5094300c58fSJosef Bacik struct btrfs_root_backup {
5104300c58fSJosef Bacik 	__le64 tree_root;
5114300c58fSJosef Bacik 	__le64 tree_root_gen;
5124300c58fSJosef Bacik 
5134300c58fSJosef Bacik 	__le64 chunk_root;
5144300c58fSJosef Bacik 	__le64 chunk_root_gen;
5154300c58fSJosef Bacik 
5164300c58fSJosef Bacik 	__le64 extent_root;
5174300c58fSJosef Bacik 	__le64 extent_root_gen;
5184300c58fSJosef Bacik 
5194300c58fSJosef Bacik 	__le64 fs_root;
5204300c58fSJosef Bacik 	__le64 fs_root_gen;
5214300c58fSJosef Bacik 
5224300c58fSJosef Bacik 	__le64 dev_root;
5234300c58fSJosef Bacik 	__le64 dev_root_gen;
5244300c58fSJosef Bacik 
5254300c58fSJosef Bacik 	__le64 csum_root;
5264300c58fSJosef Bacik 	__le64 csum_root_gen;
5274300c58fSJosef Bacik 
5284300c58fSJosef Bacik 	__le64 total_bytes;
5294300c58fSJosef Bacik 	__le64 bytes_used;
5304300c58fSJosef Bacik 	__le64 num_devices;
5314300c58fSJosef Bacik 	/* future */
5324300c58fSJosef Bacik 	__le64 unused_64[4];
5334300c58fSJosef Bacik 
5344300c58fSJosef Bacik 	__u8 tree_root_level;
5354300c58fSJosef Bacik 	__u8 chunk_root_level;
5364300c58fSJosef Bacik 	__u8 extent_root_level;
5374300c58fSJosef Bacik 	__u8 fs_root_level;
5384300c58fSJosef Bacik 	__u8 dev_root_level;
5394300c58fSJosef Bacik 	__u8 csum_root_level;
5404300c58fSJosef Bacik 	/* future and to align */
5414300c58fSJosef Bacik 	__u8 unused_8[10];
5424300c58fSJosef Bacik } __attribute__ ((__packed__));
5434300c58fSJosef Bacik 
5444300c58fSJosef Bacik /*
5454300c58fSJosef Bacik  * A leaf is full of items. offset and size tell us where to find the item in
5464300c58fSJosef Bacik  * the leaf (relative to the start of the data area)
5474300c58fSJosef Bacik  */
5484300c58fSJosef Bacik struct btrfs_item {
5494300c58fSJosef Bacik 	struct btrfs_disk_key key;
5504300c58fSJosef Bacik 	__le32 offset;
5514300c58fSJosef Bacik 	__le32 size;
5524300c58fSJosef Bacik } __attribute__ ((__packed__));
5534300c58fSJosef Bacik 
5544300c58fSJosef Bacik /*
5554300c58fSJosef Bacik  * Leaves have an item area and a data area:
5564300c58fSJosef Bacik  * [item0, item1....itemN] [free space] [dataN...data1, data0]
5574300c58fSJosef Bacik  *
5584300c58fSJosef Bacik  * The data is separate from the items to get the keys closer together during
5594300c58fSJosef Bacik  * searches.
5604300c58fSJosef Bacik  */
5614300c58fSJosef Bacik struct btrfs_leaf {
5624300c58fSJosef Bacik 	struct btrfs_header header;
5634300c58fSJosef Bacik 	struct btrfs_item items[];
5644300c58fSJosef Bacik } __attribute__ ((__packed__));
5654300c58fSJosef Bacik 
5664300c58fSJosef Bacik /*
5674300c58fSJosef Bacik  * All non-leaf blocks are nodes, they hold only keys and pointers to other
5684300c58fSJosef Bacik  * blocks.
5694300c58fSJosef Bacik  */
5704300c58fSJosef Bacik struct btrfs_key_ptr {
5714300c58fSJosef Bacik 	struct btrfs_disk_key key;
5724300c58fSJosef Bacik 	__le64 blockptr;
5734300c58fSJosef Bacik 	__le64 generation;
5744300c58fSJosef Bacik } __attribute__ ((__packed__));
5754300c58fSJosef Bacik 
5764300c58fSJosef Bacik struct btrfs_node {
5774300c58fSJosef Bacik 	struct btrfs_header header;
5784300c58fSJosef Bacik 	struct btrfs_key_ptr ptrs[];
5794300c58fSJosef Bacik } __attribute__ ((__packed__));
5804300c58fSJosef Bacik 
581db671160SJeff Mahoney struct btrfs_dev_item {
582db671160SJeff Mahoney 	/* the internal btrfs device id */
583db671160SJeff Mahoney 	__le64 devid;
584db671160SJeff Mahoney 
585db671160SJeff Mahoney 	/* size of the device */
586db671160SJeff Mahoney 	__le64 total_bytes;
587db671160SJeff Mahoney 
588db671160SJeff Mahoney 	/* bytes used */
589db671160SJeff Mahoney 	__le64 bytes_used;
590db671160SJeff Mahoney 
591db671160SJeff Mahoney 	/* optimal io alignment for this device */
592db671160SJeff Mahoney 	__le32 io_align;
593db671160SJeff Mahoney 
594db671160SJeff Mahoney 	/* optimal io width for this device */
595db671160SJeff Mahoney 	__le32 io_width;
596db671160SJeff Mahoney 
597db671160SJeff Mahoney 	/* minimal io size for this device */
598db671160SJeff Mahoney 	__le32 sector_size;
599db671160SJeff Mahoney 
600db671160SJeff Mahoney 	/* type and info about this device */
601db671160SJeff Mahoney 	__le64 type;
602db671160SJeff Mahoney 
603db671160SJeff Mahoney 	/* expected generation for this device */
604db671160SJeff Mahoney 	__le64 generation;
605db671160SJeff Mahoney 
606db671160SJeff Mahoney 	/*
607db671160SJeff Mahoney 	 * starting byte of this partition on the device,
608db671160SJeff Mahoney 	 * to allow for stripe alignment in the future
609db671160SJeff Mahoney 	 */
610db671160SJeff Mahoney 	__le64 start_offset;
611db671160SJeff Mahoney 
612db671160SJeff Mahoney 	/* grouping information for allocation decisions */
613db671160SJeff Mahoney 	__le32 dev_group;
614db671160SJeff Mahoney 
615db671160SJeff Mahoney 	/* seek speed 0-100 where 100 is fastest */
61614b05c51SJeff Mahoney 	__u8 seek_speed;
617db671160SJeff Mahoney 
618db671160SJeff Mahoney 	/* bandwidth 0-100 where 100 is fastest */
61914b05c51SJeff Mahoney 	__u8 bandwidth;
620db671160SJeff Mahoney 
621db671160SJeff Mahoney 	/* btrfs generated uuid for this device */
62214b05c51SJeff Mahoney 	__u8 uuid[BTRFS_UUID_SIZE];
623db671160SJeff Mahoney 
624db671160SJeff Mahoney 	/* uuid of FS who owns this device */
62514b05c51SJeff Mahoney 	__u8 fsid[BTRFS_UUID_SIZE];
626db671160SJeff Mahoney } __attribute__ ((__packed__));
627db671160SJeff Mahoney 
628db671160SJeff Mahoney struct btrfs_stripe {
629db671160SJeff Mahoney 	__le64 devid;
630db671160SJeff Mahoney 	__le64 offset;
63114b05c51SJeff Mahoney 	__u8 dev_uuid[BTRFS_UUID_SIZE];
632db671160SJeff Mahoney } __attribute__ ((__packed__));
633db671160SJeff Mahoney 
634db671160SJeff Mahoney struct btrfs_chunk {
635db671160SJeff Mahoney 	/* size of this chunk in bytes */
636db671160SJeff Mahoney 	__le64 length;
637db671160SJeff Mahoney 
638db671160SJeff Mahoney 	/* objectid of the root referencing this chunk */
639db671160SJeff Mahoney 	__le64 owner;
640db671160SJeff Mahoney 
641db671160SJeff Mahoney 	__le64 stripe_len;
642db671160SJeff Mahoney 	__le64 type;
643db671160SJeff Mahoney 
644db671160SJeff Mahoney 	/* optimal io alignment for this chunk */
645db671160SJeff Mahoney 	__le32 io_align;
646db671160SJeff Mahoney 
647db671160SJeff Mahoney 	/* optimal io width for this chunk */
648db671160SJeff Mahoney 	__le32 io_width;
649db671160SJeff Mahoney 
650db671160SJeff Mahoney 	/* minimal io size for this chunk */
651db671160SJeff Mahoney 	__le32 sector_size;
652db671160SJeff Mahoney 
653db671160SJeff Mahoney 	/* 2^16 stripes is quite a lot, a second limit is the size of a single
654db671160SJeff Mahoney 	 * item in the btree
655db671160SJeff Mahoney 	 */
656db671160SJeff Mahoney 	__le16 num_stripes;
657db671160SJeff Mahoney 
658db671160SJeff Mahoney 	/* sub stripes only matter for raid10 */
659db671160SJeff Mahoney 	__le16 sub_stripes;
660db671160SJeff Mahoney 	struct btrfs_stripe stripe;
661db671160SJeff Mahoney 	/* additional stripes go here */
662db671160SJeff Mahoney } __attribute__ ((__packed__));
663db671160SJeff Mahoney 
6644300c58fSJosef Bacik /*
6654300c58fSJosef Bacik  * The super block basically lists the main trees of the FS.
6664300c58fSJosef Bacik  */
6674300c58fSJosef Bacik struct btrfs_super_block {
6684300c58fSJosef Bacik 	/* The first 4 fields must match struct btrfs_header */
6694300c58fSJosef Bacik 	__u8 csum[BTRFS_CSUM_SIZE];
6704300c58fSJosef Bacik 	/* FS specific UUID, visible to user */
6714300c58fSJosef Bacik 	__u8 fsid[BTRFS_FSID_SIZE];
6724300c58fSJosef Bacik 	/* This block number */
6734300c58fSJosef Bacik 	__le64 bytenr;
6744300c58fSJosef Bacik 	__le64 flags;
6754300c58fSJosef Bacik 
6764300c58fSJosef Bacik 	/* Allowed to be different from the btrfs_header from here own down */
6774300c58fSJosef Bacik 	__le64 magic;
6784300c58fSJosef Bacik 	__le64 generation;
6794300c58fSJosef Bacik 	__le64 root;
6804300c58fSJosef Bacik 	__le64 chunk_root;
6814300c58fSJosef Bacik 	__le64 log_root;
6824300c58fSJosef Bacik 
6834300c58fSJosef Bacik 	/*
6844300c58fSJosef Bacik 	 * This member has never been utilized since the very beginning, thus
6854300c58fSJosef Bacik 	 * it's always 0 regardless of kernel version.  We always use
6864300c58fSJosef Bacik 	 * generation + 1 to read log tree root.  So here we mark it deprecated.
6874300c58fSJosef Bacik 	 */
6884300c58fSJosef Bacik 	__le64 __unused_log_root_transid;
6894300c58fSJosef Bacik 	__le64 total_bytes;
6904300c58fSJosef Bacik 	__le64 bytes_used;
6914300c58fSJosef Bacik 	__le64 root_dir_objectid;
6924300c58fSJosef Bacik 	__le64 num_devices;
6934300c58fSJosef Bacik 	__le32 sectorsize;
6944300c58fSJosef Bacik 	__le32 nodesize;
6954300c58fSJosef Bacik 	__le32 __unused_leafsize;
6964300c58fSJosef Bacik 	__le32 stripesize;
6974300c58fSJosef Bacik 	__le32 sys_chunk_array_size;
6984300c58fSJosef Bacik 	__le64 chunk_root_generation;
6994300c58fSJosef Bacik 	__le64 compat_flags;
7004300c58fSJosef Bacik 	__le64 compat_ro_flags;
7014300c58fSJosef Bacik 	__le64 incompat_flags;
7024300c58fSJosef Bacik 	__le16 csum_type;
7034300c58fSJosef Bacik 	__u8 root_level;
7044300c58fSJosef Bacik 	__u8 chunk_root_level;
7054300c58fSJosef Bacik 	__u8 log_root_level;
7064300c58fSJosef Bacik 	struct btrfs_dev_item dev_item;
7074300c58fSJosef Bacik 
7084300c58fSJosef Bacik 	char label[BTRFS_LABEL_SIZE];
7094300c58fSJosef Bacik 
7104300c58fSJosef Bacik 	__le64 cache_generation;
7114300c58fSJosef Bacik 	__le64 uuid_tree_generation;
7124300c58fSJosef Bacik 
7134300c58fSJosef Bacik 	/* The UUID written into btree blocks */
7144300c58fSJosef Bacik 	__u8 metadata_uuid[BTRFS_FSID_SIZE];
7154300c58fSJosef Bacik 
7160c703003SJosef Bacik 	__u64 nr_global_roots;
7170c703003SJosef Bacik 
7184300c58fSJosef Bacik 	/* Future expansion */
7194300c58fSJosef Bacik 	__le64 reserved[27];
7204300c58fSJosef Bacik 	__u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
7214300c58fSJosef Bacik 	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
7224300c58fSJosef Bacik 
7234300c58fSJosef Bacik 	/* Padded to 4096 bytes */
7244300c58fSJosef Bacik 	__u8 padding[565];
7254300c58fSJosef Bacik } __attribute__ ((__packed__));
7264300c58fSJosef Bacik 
727db671160SJeff Mahoney #define BTRFS_FREE_SPACE_EXTENT	1
728db671160SJeff Mahoney #define BTRFS_FREE_SPACE_BITMAP	2
729db671160SJeff Mahoney 
730db671160SJeff Mahoney struct btrfs_free_space_entry {
731db671160SJeff Mahoney 	__le64 offset;
732db671160SJeff Mahoney 	__le64 bytes;
73314b05c51SJeff Mahoney 	__u8 type;
734db671160SJeff Mahoney } __attribute__ ((__packed__));
735db671160SJeff Mahoney 
736db671160SJeff Mahoney struct btrfs_free_space_header {
737db671160SJeff Mahoney 	struct btrfs_disk_key location;
738db671160SJeff Mahoney 	__le64 generation;
739db671160SJeff Mahoney 	__le64 num_entries;
740db671160SJeff Mahoney 	__le64 num_bitmaps;
741db671160SJeff Mahoney } __attribute__ ((__packed__));
742db671160SJeff Mahoney 
743ee129330SJohannes Thumshirn struct btrfs_raid_stride {
744ee129330SJohannes Thumshirn 	/* The id of device this raid extent lives on. */
745ee129330SJohannes Thumshirn 	__le64 devid;
746ee129330SJohannes Thumshirn 	/* The physical location on disk. */
747ee129330SJohannes Thumshirn 	__le64 physical;
748ee129330SJohannes Thumshirn } __attribute__ ((__packed__));
749ee129330SJohannes Thumshirn 
750ee129330SJohannes Thumshirn /* The stripe_extent::encoding, 1:1 mapping of enum btrfs_raid_types. */
751ee129330SJohannes Thumshirn #define BTRFS_STRIPE_RAID0	1
752ee129330SJohannes Thumshirn #define BTRFS_STRIPE_RAID1	2
753ee129330SJohannes Thumshirn #define BTRFS_STRIPE_DUP	3
754ee129330SJohannes Thumshirn #define BTRFS_STRIPE_RAID10	4
755ee129330SJohannes Thumshirn #define BTRFS_STRIPE_RAID5	5
756ee129330SJohannes Thumshirn #define BTRFS_STRIPE_RAID6	6
757ee129330SJohannes Thumshirn #define BTRFS_STRIPE_RAID1C3	7
758ee129330SJohannes Thumshirn #define BTRFS_STRIPE_RAID1C4	8
759ee129330SJohannes Thumshirn 
760ee129330SJohannes Thumshirn struct btrfs_stripe_extent {
761ee129330SJohannes Thumshirn 	__u8 encoding;
762ee129330SJohannes Thumshirn 	__u8 reserved[7];
763ee129330SJohannes Thumshirn 	/* An array of raid strides this stripe is composed of. */
764ee129330SJohannes Thumshirn 	struct btrfs_raid_stride strides[];
765ee129330SJohannes Thumshirn } __attribute__ ((__packed__));
766ee129330SJohannes Thumshirn 
767db671160SJeff Mahoney #define BTRFS_HEADER_FLAG_WRITTEN	(1ULL << 0)
768db671160SJeff Mahoney #define BTRFS_HEADER_FLAG_RELOC		(1ULL << 1)
769db671160SJeff Mahoney 
770db671160SJeff Mahoney /* Super block flags */
771db671160SJeff Mahoney /* Errors detected */
772db671160SJeff Mahoney #define BTRFS_SUPER_FLAG_ERROR		(1ULL << 2)
773db671160SJeff Mahoney 
774db671160SJeff Mahoney #define BTRFS_SUPER_FLAG_SEEDING	(1ULL << 32)
775db671160SJeff Mahoney #define BTRFS_SUPER_FLAG_METADUMP	(1ULL << 33)
776e2731e55SAnand Jain #define BTRFS_SUPER_FLAG_METADUMP_V2	(1ULL << 34)
77798820a7eSAnand Jain #define BTRFS_SUPER_FLAG_CHANGING_FSID	(1ULL << 35)
7787239ff4bSNikolay Borisov #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
779db671160SJeff Mahoney 
780db671160SJeff Mahoney 
781db671160SJeff Mahoney /*
782db671160SJeff Mahoney  * items in the extent btree are used to record the objectid of the
783db671160SJeff Mahoney  * owner of the block and the number of references
784db671160SJeff Mahoney  */
785db671160SJeff Mahoney 
786db671160SJeff Mahoney struct btrfs_extent_item {
787db671160SJeff Mahoney 	__le64 refs;
788db671160SJeff Mahoney 	__le64 generation;
789db671160SJeff Mahoney 	__le64 flags;
790db671160SJeff Mahoney } __attribute__ ((__packed__));
791db671160SJeff Mahoney 
792db671160SJeff Mahoney struct btrfs_extent_item_v0 {
793db671160SJeff Mahoney 	__le32 refs;
794db671160SJeff Mahoney } __attribute__ ((__packed__));
795db671160SJeff Mahoney 
796db671160SJeff Mahoney 
797db671160SJeff Mahoney #define BTRFS_EXTENT_FLAG_DATA		(1ULL << 0)
798db671160SJeff Mahoney #define BTRFS_EXTENT_FLAG_TREE_BLOCK	(1ULL << 1)
799db671160SJeff Mahoney 
800db671160SJeff Mahoney /* following flags only apply to tree blocks */
801db671160SJeff Mahoney 
802db671160SJeff Mahoney /* use full backrefs for extent pointers in the block */
803db671160SJeff Mahoney #define BTRFS_BLOCK_FLAG_FULL_BACKREF	(1ULL << 8)
804db671160SJeff Mahoney 
8054300c58fSJosef Bacik #define BTRFS_BACKREF_REV_MAX		256
8064300c58fSJosef Bacik #define BTRFS_BACKREF_REV_SHIFT		56
8074300c58fSJosef Bacik #define BTRFS_BACKREF_REV_MASK		(((u64)BTRFS_BACKREF_REV_MAX - 1) << \
8084300c58fSJosef Bacik 					 BTRFS_BACKREF_REV_SHIFT)
8094300c58fSJosef Bacik 
8104300c58fSJosef Bacik #define BTRFS_OLD_BACKREF_REV		0
8114300c58fSJosef Bacik #define BTRFS_MIXED_BACKREF_REV		1
8124300c58fSJosef Bacik 
813db671160SJeff Mahoney /*
814db671160SJeff Mahoney  * this flag is only used internally by scrub and may be changed at any time
815db671160SJeff Mahoney  * it is only declared here to avoid collisions
816db671160SJeff Mahoney  */
817db671160SJeff Mahoney #define BTRFS_EXTENT_FLAG_SUPER		(1ULL << 48)
818db671160SJeff Mahoney 
819db671160SJeff Mahoney struct btrfs_tree_block_info {
820db671160SJeff Mahoney 	struct btrfs_disk_key key;
82114b05c51SJeff Mahoney 	__u8 level;
822db671160SJeff Mahoney } __attribute__ ((__packed__));
823db671160SJeff Mahoney 
824db671160SJeff Mahoney struct btrfs_extent_data_ref {
825db671160SJeff Mahoney 	__le64 root;
826db671160SJeff Mahoney 	__le64 objectid;
827db671160SJeff Mahoney 	__le64 offset;
828db671160SJeff Mahoney 	__le32 count;
829db671160SJeff Mahoney } __attribute__ ((__packed__));
830db671160SJeff Mahoney 
831db671160SJeff Mahoney struct btrfs_shared_data_ref {
832db671160SJeff Mahoney 	__le32 count;
833db671160SJeff Mahoney } __attribute__ ((__packed__));
834db671160SJeff Mahoney 
835d9a620f7SBoris Burkov struct btrfs_extent_owner_ref {
836d9a620f7SBoris Burkov 	__le64 root_id;
837d9a620f7SBoris Burkov } __attribute__ ((__packed__));
838d9a620f7SBoris Burkov 
839db671160SJeff Mahoney struct btrfs_extent_inline_ref {
84014b05c51SJeff Mahoney 	__u8 type;
841db671160SJeff Mahoney 	__le64 offset;
842db671160SJeff Mahoney } __attribute__ ((__packed__));
843db671160SJeff Mahoney 
844db671160SJeff Mahoney /* dev extents record free space on individual devices.  The owner
845db671160SJeff Mahoney  * field points back to the chunk allocation mapping tree that allocated
846db671160SJeff Mahoney  * the extent.  The chunk tree uuid field is a way to double check the owner
847db671160SJeff Mahoney  */
848db671160SJeff Mahoney struct btrfs_dev_extent {
849db671160SJeff Mahoney 	__le64 chunk_tree;
850db671160SJeff Mahoney 	__le64 chunk_objectid;
851db671160SJeff Mahoney 	__le64 chunk_offset;
852db671160SJeff Mahoney 	__le64 length;
85314b05c51SJeff Mahoney 	__u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
854db671160SJeff Mahoney } __attribute__ ((__packed__));
855db671160SJeff Mahoney 
856db671160SJeff Mahoney struct btrfs_inode_ref {
857db671160SJeff Mahoney 	__le64 index;
858db671160SJeff Mahoney 	__le16 name_len;
859db671160SJeff Mahoney 	/* name goes here */
860db671160SJeff Mahoney } __attribute__ ((__packed__));
861db671160SJeff Mahoney 
862db671160SJeff Mahoney struct btrfs_inode_extref {
863db671160SJeff Mahoney 	__le64 parent_objectid;
864db671160SJeff Mahoney 	__le64 index;
865db671160SJeff Mahoney 	__le16 name_len;
86694dfc73eSGustavo A. R. Silva 	__u8   name[];
867db671160SJeff Mahoney 	/* name goes here */
868db671160SJeff Mahoney } __attribute__ ((__packed__));
869db671160SJeff Mahoney 
870db671160SJeff Mahoney struct btrfs_timespec {
871db671160SJeff Mahoney 	__le64 sec;
872db671160SJeff Mahoney 	__le32 nsec;
873db671160SJeff Mahoney } __attribute__ ((__packed__));
874db671160SJeff Mahoney 
875db671160SJeff Mahoney struct btrfs_inode_item {
876db671160SJeff Mahoney 	/* nfs style generation number */
877db671160SJeff Mahoney 	__le64 generation;
878db671160SJeff Mahoney 	/* transid that last touched this inode */
879db671160SJeff Mahoney 	__le64 transid;
880db671160SJeff Mahoney 	__le64 size;
881db671160SJeff Mahoney 	__le64 nbytes;
882db671160SJeff Mahoney 	__le64 block_group;
883db671160SJeff Mahoney 	__le32 nlink;
884db671160SJeff Mahoney 	__le32 uid;
885db671160SJeff Mahoney 	__le32 gid;
886db671160SJeff Mahoney 	__le32 mode;
887db671160SJeff Mahoney 	__le64 rdev;
888db671160SJeff Mahoney 	__le64 flags;
889db671160SJeff Mahoney 
890db671160SJeff Mahoney 	/* modification sequence number for NFS */
891db671160SJeff Mahoney 	__le64 sequence;
892db671160SJeff Mahoney 
893db671160SJeff Mahoney 	/*
894db671160SJeff Mahoney 	 * a little future expansion, for more than this we can
895db671160SJeff Mahoney 	 * just grow the inode item and version it
896db671160SJeff Mahoney 	 */
897db671160SJeff Mahoney 	__le64 reserved[4];
898db671160SJeff Mahoney 	struct btrfs_timespec atime;
899db671160SJeff Mahoney 	struct btrfs_timespec ctime;
900db671160SJeff Mahoney 	struct btrfs_timespec mtime;
901db671160SJeff Mahoney 	struct btrfs_timespec otime;
902db671160SJeff Mahoney } __attribute__ ((__packed__));
903db671160SJeff Mahoney 
904db671160SJeff Mahoney struct btrfs_dir_log_item {
905db671160SJeff Mahoney 	__le64 end;
906db671160SJeff Mahoney } __attribute__ ((__packed__));
907db671160SJeff Mahoney 
908db671160SJeff Mahoney struct btrfs_dir_item {
909db671160SJeff Mahoney 	struct btrfs_disk_key location;
910db671160SJeff Mahoney 	__le64 transid;
911db671160SJeff Mahoney 	__le16 data_len;
912db671160SJeff Mahoney 	__le16 name_len;
91314b05c51SJeff Mahoney 	__u8 type;
914db671160SJeff Mahoney } __attribute__ ((__packed__));
915db671160SJeff Mahoney 
916db671160SJeff Mahoney #define BTRFS_ROOT_SUBVOL_RDONLY	(1ULL << 0)
917db671160SJeff Mahoney 
918db671160SJeff Mahoney /*
919db671160SJeff Mahoney  * Internal in-memory flag that a subvolume has been marked for deletion but
920db671160SJeff Mahoney  * still visible as a directory
921db671160SJeff Mahoney  */
922db671160SJeff Mahoney #define BTRFS_ROOT_SUBVOL_DEAD		(1ULL << 48)
923db671160SJeff Mahoney 
924db671160SJeff Mahoney struct btrfs_root_item {
925db671160SJeff Mahoney 	struct btrfs_inode_item inode;
926db671160SJeff Mahoney 	__le64 generation;
927db671160SJeff Mahoney 	__le64 root_dirid;
928db671160SJeff Mahoney 	__le64 bytenr;
929db671160SJeff Mahoney 	__le64 byte_limit;
930db671160SJeff Mahoney 	__le64 bytes_used;
931db671160SJeff Mahoney 	__le64 last_snapshot;
932db671160SJeff Mahoney 	__le64 flags;
933db671160SJeff Mahoney 	__le32 refs;
934db671160SJeff Mahoney 	struct btrfs_disk_key drop_progress;
93514b05c51SJeff Mahoney 	__u8 drop_level;
93614b05c51SJeff Mahoney 	__u8 level;
937db671160SJeff Mahoney 
938db671160SJeff Mahoney 	/*
939db671160SJeff Mahoney 	 * The following fields appear after subvol_uuids+subvol_times
940db671160SJeff Mahoney 	 * were introduced.
941db671160SJeff Mahoney 	 */
942db671160SJeff Mahoney 
943db671160SJeff Mahoney 	/*
944db671160SJeff Mahoney 	 * This generation number is used to test if the new fields are valid
945db671160SJeff Mahoney 	 * and up to date while reading the root item. Every time the root item
946db671160SJeff Mahoney 	 * is written out, the "generation" field is copied into this field. If
947db671160SJeff Mahoney 	 * anyone ever mounted the fs with an older kernel, we will have
948db671160SJeff Mahoney 	 * mismatching generation values here and thus must invalidate the
949db671160SJeff Mahoney 	 * new fields. See btrfs_update_root and btrfs_find_last_root for
950db671160SJeff Mahoney 	 * details.
951db671160SJeff Mahoney 	 * the offset of generation_v2 is also used as the start for the memset
952db671160SJeff Mahoney 	 * when invalidating the fields.
953db671160SJeff Mahoney 	 */
954db671160SJeff Mahoney 	__le64 generation_v2;
95514b05c51SJeff Mahoney 	__u8 uuid[BTRFS_UUID_SIZE];
95614b05c51SJeff Mahoney 	__u8 parent_uuid[BTRFS_UUID_SIZE];
95714b05c51SJeff Mahoney 	__u8 received_uuid[BTRFS_UUID_SIZE];
958db671160SJeff Mahoney 	__le64 ctransid; /* updated when an inode changes */
959db671160SJeff Mahoney 	__le64 otransid; /* trans when created */
960db671160SJeff Mahoney 	__le64 stransid; /* trans when sent. non-zero for received subvol */
961db671160SJeff Mahoney 	__le64 rtransid; /* trans when received. non-zero for received subvol */
962db671160SJeff Mahoney 	struct btrfs_timespec ctime;
963db671160SJeff Mahoney 	struct btrfs_timespec otime;
964db671160SJeff Mahoney 	struct btrfs_timespec stime;
965db671160SJeff Mahoney 	struct btrfs_timespec rtime;
966db671160SJeff Mahoney 	__le64 reserved[8]; /* for future */
967db671160SJeff Mahoney } __attribute__ ((__packed__));
968db671160SJeff Mahoney 
969db671160SJeff Mahoney /*
9701465af12SQu Wenruo  * Btrfs root item used to be smaller than current size.  The old format ends
9711465af12SQu Wenruo  * at where member generation_v2 is.
9721465af12SQu Wenruo  */
btrfs_legacy_root_item_size(void)9731465af12SQu Wenruo static inline __u32 btrfs_legacy_root_item_size(void)
9741465af12SQu Wenruo {
9751465af12SQu Wenruo 	return offsetof(struct btrfs_root_item, generation_v2);
9761465af12SQu Wenruo }
9771465af12SQu Wenruo 
9781465af12SQu Wenruo /*
979db671160SJeff Mahoney  * this is used for both forward and backward root refs
980db671160SJeff Mahoney  */
981db671160SJeff Mahoney struct btrfs_root_ref {
982db671160SJeff Mahoney 	__le64 dirid;
983db671160SJeff Mahoney 	__le64 sequence;
984db671160SJeff Mahoney 	__le16 name_len;
985db671160SJeff Mahoney } __attribute__ ((__packed__));
986db671160SJeff Mahoney 
987db671160SJeff Mahoney struct btrfs_disk_balance_args {
988db671160SJeff Mahoney 	/*
989db671160SJeff Mahoney 	 * profiles to operate on, single is denoted by
990db671160SJeff Mahoney 	 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
991db671160SJeff Mahoney 	 */
992db671160SJeff Mahoney 	__le64 profiles;
993db671160SJeff Mahoney 
994db671160SJeff Mahoney 	/*
995db671160SJeff Mahoney 	 * usage filter
996db671160SJeff Mahoney 	 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
997db671160SJeff Mahoney 	 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
998db671160SJeff Mahoney 	 */
999db671160SJeff Mahoney 	union {
1000db671160SJeff Mahoney 		__le64 usage;
1001db671160SJeff Mahoney 		struct {
1002db671160SJeff Mahoney 			__le32 usage_min;
1003db671160SJeff Mahoney 			__le32 usage_max;
1004db671160SJeff Mahoney 		};
1005db671160SJeff Mahoney 	};
1006db671160SJeff Mahoney 
1007db671160SJeff Mahoney 	/* devid filter */
1008db671160SJeff Mahoney 	__le64 devid;
1009db671160SJeff Mahoney 
1010db671160SJeff Mahoney 	/* devid subset filter [pstart..pend) */
1011db671160SJeff Mahoney 	__le64 pstart;
1012db671160SJeff Mahoney 	__le64 pend;
1013db671160SJeff Mahoney 
1014db671160SJeff Mahoney 	/* btrfs virtual address space subset filter [vstart..vend) */
1015db671160SJeff Mahoney 	__le64 vstart;
1016db671160SJeff Mahoney 	__le64 vend;
1017db671160SJeff Mahoney 
1018db671160SJeff Mahoney 	/*
1019db671160SJeff Mahoney 	 * profile to convert to, single is denoted by
1020db671160SJeff Mahoney 	 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
1021db671160SJeff Mahoney 	 */
1022db671160SJeff Mahoney 	__le64 target;
1023db671160SJeff Mahoney 
1024db671160SJeff Mahoney 	/* BTRFS_BALANCE_ARGS_* */
1025db671160SJeff Mahoney 	__le64 flags;
1026db671160SJeff Mahoney 
1027db671160SJeff Mahoney 	/*
1028db671160SJeff Mahoney 	 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
1029db671160SJeff Mahoney 	 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
1030db671160SJeff Mahoney 	 * and maximum
1031db671160SJeff Mahoney 	 */
1032db671160SJeff Mahoney 	union {
1033db671160SJeff Mahoney 		__le64 limit;
1034db671160SJeff Mahoney 		struct {
1035db671160SJeff Mahoney 			__le32 limit_min;
1036db671160SJeff Mahoney 			__le32 limit_max;
1037db671160SJeff Mahoney 		};
1038db671160SJeff Mahoney 	};
1039db671160SJeff Mahoney 
1040db671160SJeff Mahoney 	/*
1041db671160SJeff Mahoney 	 * Process chunks that cross stripes_min..stripes_max devices,
1042db671160SJeff Mahoney 	 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
1043db671160SJeff Mahoney 	 */
1044db671160SJeff Mahoney 	__le32 stripes_min;
1045db671160SJeff Mahoney 	__le32 stripes_max;
1046db671160SJeff Mahoney 
1047db671160SJeff Mahoney 	__le64 unused[6];
1048db671160SJeff Mahoney } __attribute__ ((__packed__));
1049db671160SJeff Mahoney 
1050db671160SJeff Mahoney /*
1051db671160SJeff Mahoney  * store balance parameters to disk so that balance can be properly
1052db671160SJeff Mahoney  * resumed after crash or unmount
1053db671160SJeff Mahoney  */
1054db671160SJeff Mahoney struct btrfs_balance_item {
1055db671160SJeff Mahoney 	/* BTRFS_BALANCE_* */
1056db671160SJeff Mahoney 	__le64 flags;
1057db671160SJeff Mahoney 
1058db671160SJeff Mahoney 	struct btrfs_disk_balance_args data;
1059db671160SJeff Mahoney 	struct btrfs_disk_balance_args meta;
1060db671160SJeff Mahoney 	struct btrfs_disk_balance_args sys;
1061db671160SJeff Mahoney 
1062db671160SJeff Mahoney 	__le64 unused[4];
1063db671160SJeff Mahoney } __attribute__ ((__packed__));
1064db671160SJeff Mahoney 
1065b9b1a53eSChengguang Xu enum {
1066b9b1a53eSChengguang Xu 	BTRFS_FILE_EXTENT_INLINE   = 0,
1067b9b1a53eSChengguang Xu 	BTRFS_FILE_EXTENT_REG      = 1,
1068b9b1a53eSChengguang Xu 	BTRFS_FILE_EXTENT_PREALLOC = 2,
1069b9b1a53eSChengguang Xu 	BTRFS_NR_FILE_EXTENT_TYPES = 3,
1070b9b1a53eSChengguang Xu };
1071db671160SJeff Mahoney 
1072db671160SJeff Mahoney struct btrfs_file_extent_item {
1073db671160SJeff Mahoney 	/*
1074db671160SJeff Mahoney 	 * transaction id that created this extent
1075db671160SJeff Mahoney 	 */
1076db671160SJeff Mahoney 	__le64 generation;
1077db671160SJeff Mahoney 	/*
1078db671160SJeff Mahoney 	 * max number of bytes to hold this extent in ram
1079db671160SJeff Mahoney 	 * when we split a compressed extent we can't know how big
1080db671160SJeff Mahoney 	 * each of the resulting pieces will be.  So, this is
1081db671160SJeff Mahoney 	 * an upper limit on the size of the extent in ram instead of
1082db671160SJeff Mahoney 	 * an exact limit.
1083db671160SJeff Mahoney 	 */
1084db671160SJeff Mahoney 	__le64 ram_bytes;
1085db671160SJeff Mahoney 
1086db671160SJeff Mahoney 	/*
1087db671160SJeff Mahoney 	 * 32 bits for the various ways we might encode the data,
1088db671160SJeff Mahoney 	 * including compression and encryption.  If any of these
1089db671160SJeff Mahoney 	 * are set to something a given disk format doesn't understand
1090db671160SJeff Mahoney 	 * it is treated like an incompat flag for reading and writing,
1091db671160SJeff Mahoney 	 * but not for stat.
1092db671160SJeff Mahoney 	 */
109314b05c51SJeff Mahoney 	__u8 compression;
109414b05c51SJeff Mahoney 	__u8 encryption;
1095db671160SJeff Mahoney 	__le16 other_encoding; /* spare for later use */
1096db671160SJeff Mahoney 
1097db671160SJeff Mahoney 	/* are we inline data or a real extent? */
109814b05c51SJeff Mahoney 	__u8 type;
1099db671160SJeff Mahoney 
1100db671160SJeff Mahoney 	/*
1101db671160SJeff Mahoney 	 * disk space consumed by the extent, checksum blocks are included
1102db671160SJeff Mahoney 	 * in these numbers
1103db671160SJeff Mahoney 	 *
1104db671160SJeff Mahoney 	 * At this offset in the structure, the inline extent data start.
1105db671160SJeff Mahoney 	 */
1106db671160SJeff Mahoney 	__le64 disk_bytenr;
1107db671160SJeff Mahoney 	__le64 disk_num_bytes;
1108db671160SJeff Mahoney 	/*
1109db671160SJeff Mahoney 	 * the logical offset in file blocks (no csums)
1110db671160SJeff Mahoney 	 * this extent record is for.  This allows a file extent to point
1111db671160SJeff Mahoney 	 * into the middle of an existing extent on disk, sharing it
1112db671160SJeff Mahoney 	 * between two snapshots (useful if some bytes in the middle of the
1113db671160SJeff Mahoney 	 * extent have changed
1114db671160SJeff Mahoney 	 */
1115db671160SJeff Mahoney 	__le64 offset;
1116db671160SJeff Mahoney 	/*
1117db671160SJeff Mahoney 	 * the logical number of file blocks (no csums included).  This
1118db671160SJeff Mahoney 	 * always reflects the size uncompressed and without encoding.
1119db671160SJeff Mahoney 	 */
1120db671160SJeff Mahoney 	__le64 num_bytes;
1121db671160SJeff Mahoney 
1122db671160SJeff Mahoney } __attribute__ ((__packed__));
1123db671160SJeff Mahoney 
1124db671160SJeff Mahoney struct btrfs_csum_item {
112514b05c51SJeff Mahoney 	__u8 csum;
1126db671160SJeff Mahoney } __attribute__ ((__packed__));
1127db671160SJeff Mahoney 
1128db671160SJeff Mahoney struct btrfs_dev_stats_item {
1129db671160SJeff Mahoney 	/*
1130db671160SJeff Mahoney 	 * grow this item struct at the end for future enhancements and keep
1131db671160SJeff Mahoney 	 * the existing values unchanged
1132db671160SJeff Mahoney 	 */
1133db671160SJeff Mahoney 	__le64 values[BTRFS_DEV_STAT_VALUES_MAX];
1134db671160SJeff Mahoney } __attribute__ ((__packed__));
1135db671160SJeff Mahoney 
1136db671160SJeff Mahoney #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS	0
1137db671160SJeff Mahoney #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID	1
1138db671160SJeff Mahoney 
1139db671160SJeff Mahoney struct btrfs_dev_replace_item {
1140db671160SJeff Mahoney 	/*
1141db671160SJeff Mahoney 	 * grow this item struct at the end for future enhancements and keep
1142db671160SJeff Mahoney 	 * the existing values unchanged
1143db671160SJeff Mahoney 	 */
1144db671160SJeff Mahoney 	__le64 src_devid;
1145db671160SJeff Mahoney 	__le64 cursor_left;
1146db671160SJeff Mahoney 	__le64 cursor_right;
1147db671160SJeff Mahoney 	__le64 cont_reading_from_srcdev_mode;
1148db671160SJeff Mahoney 
1149db671160SJeff Mahoney 	__le64 replace_state;
1150db671160SJeff Mahoney 	__le64 time_started;
1151db671160SJeff Mahoney 	__le64 time_stopped;
1152db671160SJeff Mahoney 	__le64 num_write_errors;
1153db671160SJeff Mahoney 	__le64 num_uncorrectable_read_errors;
1154db671160SJeff Mahoney } __attribute__ ((__packed__));
1155db671160SJeff Mahoney 
1156db671160SJeff Mahoney /* different types of block groups (and chunks) */
1157db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_DATA		(1ULL << 0)
1158db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_SYSTEM	(1ULL << 1)
1159db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_METADATA	(1ULL << 2)
1160db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_RAID0		(1ULL << 3)
1161db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_RAID1		(1ULL << 4)
1162db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_DUP		(1ULL << 5)
1163db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_RAID10	(1ULL << 6)
1164db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_RAID5         (1ULL << 7)
1165db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_RAID6         (1ULL << 8)
116647e6f742SDavid Sterba #define BTRFS_BLOCK_GROUP_RAID1C3       (1ULL << 9)
11678d6fac00SDavid Sterba #define BTRFS_BLOCK_GROUP_RAID1C4       (1ULL << 10)
1168db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_RESERVED	(BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
1169db671160SJeff Mahoney 					 BTRFS_SPACE_INFO_GLOBAL_RSV)
1170db671160SJeff Mahoney 
1171db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_TYPE_MASK	(BTRFS_BLOCK_GROUP_DATA |    \
1172db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_SYSTEM |  \
1173db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_METADATA)
1174db671160SJeff Mahoney 
1175db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_PROFILE_MASK	(BTRFS_BLOCK_GROUP_RAID0 |   \
1176db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_RAID1 |   \
117747e6f742SDavid Sterba 					 BTRFS_BLOCK_GROUP_RAID1C3 | \
11788d6fac00SDavid Sterba 					 BTRFS_BLOCK_GROUP_RAID1C4 | \
1179db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_RAID5 |   \
1180db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_RAID6 |   \
1181db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_DUP |     \
1182db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_RAID10)
1183db671160SJeff Mahoney #define BTRFS_BLOCK_GROUP_RAID56_MASK	(BTRFS_BLOCK_GROUP_RAID5 |   \
1184db671160SJeff Mahoney 					 BTRFS_BLOCK_GROUP_RAID6)
1185db671160SJeff Mahoney 
118647e6f742SDavid Sterba #define BTRFS_BLOCK_GROUP_RAID1_MASK	(BTRFS_BLOCK_GROUP_RAID1 |   \
11878d6fac00SDavid Sterba 					 BTRFS_BLOCK_GROUP_RAID1C3 | \
11888d6fac00SDavid Sterba 					 BTRFS_BLOCK_GROUP_RAID1C4)
1189c7369b3fSDavid Sterba 
1190db671160SJeff Mahoney /*
1191db671160SJeff Mahoney  * We need a bit for restriper to be able to tell when chunks of type
1192db671160SJeff Mahoney  * SINGLE are available.  This "extended" profile format is used in
1193db671160SJeff Mahoney  * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
1194db671160SJeff Mahoney  * (on-disk).  The corresponding on-disk bit in chunk.type is reserved
1195db671160SJeff Mahoney  * to avoid remappings between two formats in future.
1196db671160SJeff Mahoney  */
1197db671160SJeff Mahoney #define BTRFS_AVAIL_ALLOC_BIT_SINGLE	(1ULL << 48)
1198db671160SJeff Mahoney 
1199db671160SJeff Mahoney /*
1200db671160SJeff Mahoney  * A fake block group type that is used to communicate global block reserve
1201db671160SJeff Mahoney  * size to userspace via the SPACE_INFO ioctl.
1202db671160SJeff Mahoney  */
1203db671160SJeff Mahoney #define BTRFS_SPACE_INFO_GLOBAL_RSV	(1ULL << 49)
1204db671160SJeff Mahoney 
1205db671160SJeff Mahoney #define BTRFS_EXTENDED_PROFILE_MASK	(BTRFS_BLOCK_GROUP_PROFILE_MASK | \
1206db671160SJeff Mahoney 					 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
1207db671160SJeff Mahoney 
chunk_to_extended(__u64 flags)120814b05c51SJeff Mahoney static inline __u64 chunk_to_extended(__u64 flags)
1209db671160SJeff Mahoney {
1210db671160SJeff Mahoney 	if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1211db671160SJeff Mahoney 		flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1212db671160SJeff Mahoney 
1213db671160SJeff Mahoney 	return flags;
1214db671160SJeff Mahoney }
extended_to_chunk(__u64 flags)121514b05c51SJeff Mahoney static inline __u64 extended_to_chunk(__u64 flags)
1216db671160SJeff Mahoney {
1217db671160SJeff Mahoney 	return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1218db671160SJeff Mahoney }
1219db671160SJeff Mahoney 
1220db671160SJeff Mahoney struct btrfs_block_group_item {
1221db671160SJeff Mahoney 	__le64 used;
1222db671160SJeff Mahoney 	__le64 chunk_objectid;
1223db671160SJeff Mahoney 	__le64 flags;
1224db671160SJeff Mahoney } __attribute__ ((__packed__));
1225db671160SJeff Mahoney 
1226db671160SJeff Mahoney struct btrfs_free_space_info {
1227db671160SJeff Mahoney 	__le32 extent_count;
1228db671160SJeff Mahoney 	__le32 flags;
1229db671160SJeff Mahoney } __attribute__ ((__packed__));
1230db671160SJeff Mahoney 
1231db671160SJeff Mahoney #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1232db671160SJeff Mahoney 
1233db671160SJeff Mahoney #define BTRFS_QGROUP_LEVEL_SHIFT		48
btrfs_qgroup_level(__u64 qgroupid)123406f67c47SQu Wenruo static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
1235db671160SJeff Mahoney {
123606f67c47SQu Wenruo 	return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
1237db671160SJeff Mahoney }
1238db671160SJeff Mahoney 
1239db671160SJeff Mahoney /*
1240db671160SJeff Mahoney  * is subvolume quota turned on?
1241db671160SJeff Mahoney  */
1242db671160SJeff Mahoney #define BTRFS_QGROUP_STATUS_FLAG_ON		(1ULL << 0)
1243db671160SJeff Mahoney /*
1244db671160SJeff Mahoney  * RESCAN is set during the initialization phase
1245db671160SJeff Mahoney  */
1246db671160SJeff Mahoney #define BTRFS_QGROUP_STATUS_FLAG_RESCAN		(1ULL << 1)
1247db671160SJeff Mahoney /*
1248db671160SJeff Mahoney  * Some qgroup entries are known to be out of date,
1249db671160SJeff Mahoney  * either because the configuration has changed in a way that
1250db671160SJeff Mahoney  * makes a rescan necessary, or because the fs has been mounted
1251db671160SJeff Mahoney  * with a non-qgroup-aware version.
1252db671160SJeff Mahoney  * Turning qouta off and on again makes it inconsistent, too.
1253db671160SJeff Mahoney  */
1254db671160SJeff Mahoney #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT	(1ULL << 2)
1255db671160SJeff Mahoney 
1256182940f4SBoris Burkov /*
1257182940f4SBoris Burkov  * Whether or not this filesystem is using simple quotas.  Not exactly the
1258182940f4SBoris Burkov  * incompat bit, because we support using simple quotas, disabling it, then
1259182940f4SBoris Burkov  * going back to full qgroup quotas.
1260182940f4SBoris Burkov  */
1261182940f4SBoris Burkov #define BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE	(1ULL << 3)
1262182940f4SBoris Burkov 
1263e71564c0SQu Wenruo #define BTRFS_QGROUP_STATUS_FLAGS_MASK	(BTRFS_QGROUP_STATUS_FLAG_ON |		\
1264e71564c0SQu Wenruo 					 BTRFS_QGROUP_STATUS_FLAG_RESCAN |	\
1265182940f4SBoris Burkov 					 BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT | \
1266182940f4SBoris Burkov 					 BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE)
1267e71564c0SQu Wenruo 
1268db671160SJeff Mahoney #define BTRFS_QGROUP_STATUS_VERSION        1
1269db671160SJeff Mahoney 
1270db671160SJeff Mahoney struct btrfs_qgroup_status_item {
1271db671160SJeff Mahoney 	__le64 version;
1272db671160SJeff Mahoney 	/*
1273db671160SJeff Mahoney 	 * the generation is updated during every commit. As older
1274db671160SJeff Mahoney 	 * versions of btrfs are not aware of qgroups, it will be
1275db671160SJeff Mahoney 	 * possible to detect inconsistencies by checking the
1276db671160SJeff Mahoney 	 * generation on mount time
1277db671160SJeff Mahoney 	 */
1278db671160SJeff Mahoney 	__le64 generation;
1279db671160SJeff Mahoney 
1280db671160SJeff Mahoney 	/* flag definitions see above */
1281db671160SJeff Mahoney 	__le64 flags;
1282db671160SJeff Mahoney 
1283db671160SJeff Mahoney 	/*
1284db671160SJeff Mahoney 	 * only used during scanning to record the progress
1285db671160SJeff Mahoney 	 * of the scan. It contains a logical address
1286db671160SJeff Mahoney 	 */
1287db671160SJeff Mahoney 	__le64 rescan;
1288bd7c1ea3SBoris Burkov 
1289bd7c1ea3SBoris Burkov 	/*
1290bd7c1ea3SBoris Burkov 	 * The generation when quotas were last enabled. Used by simple quotas to
1291bd7c1ea3SBoris Burkov 	 * avoid decrementing when freeing an extent that was written before
1292bd7c1ea3SBoris Burkov 	 * enable.
1293bd7c1ea3SBoris Burkov 	 *
1294bd7c1ea3SBoris Burkov 	 * Set only if flags contain BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE.
1295bd7c1ea3SBoris Burkov 	 */
1296bd7c1ea3SBoris Burkov 	__le64 enable_gen;
1297db671160SJeff Mahoney } __attribute__ ((__packed__));
1298db671160SJeff Mahoney 
1299db671160SJeff Mahoney struct btrfs_qgroup_info_item {
1300db671160SJeff Mahoney 	__le64 generation;
1301db671160SJeff Mahoney 	__le64 rfer;
1302db671160SJeff Mahoney 	__le64 rfer_cmpr;
1303db671160SJeff Mahoney 	__le64 excl;
1304db671160SJeff Mahoney 	__le64 excl_cmpr;
1305db671160SJeff Mahoney } __attribute__ ((__packed__));
1306db671160SJeff Mahoney 
1307db671160SJeff Mahoney struct btrfs_qgroup_limit_item {
1308db671160SJeff Mahoney 	/*
1309db671160SJeff Mahoney 	 * only updated when any of the other values change
1310db671160SJeff Mahoney 	 */
1311db671160SJeff Mahoney 	__le64 flags;
1312db671160SJeff Mahoney 	__le64 max_rfer;
1313db671160SJeff Mahoney 	__le64 max_excl;
1314db671160SJeff Mahoney 	__le64 rsv_rfer;
1315db671160SJeff Mahoney 	__le64 rsv_excl;
1316db671160SJeff Mahoney } __attribute__ ((__packed__));
1317db671160SJeff Mahoney 
131814605409SBoris Burkov struct btrfs_verity_descriptor_item {
131914605409SBoris Burkov 	/* Size of the verity descriptor in bytes */
132014605409SBoris Burkov 	__le64 size;
132114605409SBoris Burkov 	/*
132214605409SBoris Burkov 	 * When we implement support for fscrypt, we will need to encrypt the
132314605409SBoris Burkov 	 * Merkle tree for encrypted verity files. These 128 bits are for the
132414605409SBoris Burkov 	 * eventual storage of an fscrypt initialization vector.
132514605409SBoris Burkov 	 */
132614605409SBoris Burkov 	__le64 reserved[2];
132714605409SBoris Burkov 	__u8 encryption;
132814605409SBoris Burkov } __attribute__ ((__packed__));
132914605409SBoris Burkov 
1330db671160SJeff Mahoney #endif /* _BTRFS_CTREE_H_ */
1331