GNU Linux-libre 6.0.15-gnu
[releases.git] / include / uapi / linux / btrfs_tree.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _BTRFS_CTREE_H_
3 #define _BTRFS_CTREE_H_
4
5 #include <linux/btrfs.h>
6 #include <linux/types.h>
7 #ifdef __KERNEL__
8 #include <linux/stddef.h>
9 #else
10 #include <stddef.h>
11 #endif
12
13 /*
14  * This header contains the structure definitions and constants used
15  * by file system objects that can be retrieved using
16  * the BTRFS_IOC_SEARCH_TREE ioctl.  That means basically anything that
17  * is needed to describe a leaf node's key or item contents.
18  */
19
20 /* holds pointers to all of the tree roots */
21 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
22
23 /* stores information about which extents are in use, and reference counts */
24 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
25
26 /*
27  * chunk tree stores translations from logical -> physical block numbering
28  * the super block points to the chunk tree
29  */
30 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
31
32 /*
33  * stores information about which areas of a given device are in use.
34  * one per device.  The tree of tree roots points to the device tree
35  */
36 #define BTRFS_DEV_TREE_OBJECTID 4ULL
37
38 /* one per subvolume, storing files and directories */
39 #define BTRFS_FS_TREE_OBJECTID 5ULL
40
41 /* directory objectid inside the root tree */
42 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
43
44 /* holds checksums of all the data extents */
45 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
46
47 /* holds quota configuration and tracking */
48 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
49
50 /* for storing items that use the BTRFS_UUID_KEY* types */
51 #define BTRFS_UUID_TREE_OBJECTID 9ULL
52
53 /* tracks free space in block groups. */
54 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
55
56 /* Holds the block group items for extent tree v2. */
57 #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
58
59 /* device stats in the device tree */
60 #define BTRFS_DEV_STATS_OBJECTID 0ULL
61
62 /* for storing balance parameters in the root tree */
63 #define BTRFS_BALANCE_OBJECTID -4ULL
64
65 /* orphan objectid for tracking unlinked/truncated files */
66 #define BTRFS_ORPHAN_OBJECTID -5ULL
67
68 /* does write ahead logging to speed up fsyncs */
69 #define BTRFS_TREE_LOG_OBJECTID -6ULL
70 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
71
72 /* for space balancing */
73 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
74 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
75
76 /*
77  * extent checksums all have this objectid
78  * this allows them to share the logging tree
79  * for fsyncs
80  */
81 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
82
83 /* For storing free space cache */
84 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
85
86 /*
87  * The inode number assigned to the special inode for storing
88  * free ino cache
89  */
90 #define BTRFS_FREE_INO_OBJECTID -12ULL
91
92 /* dummy objectid represents multiple objectids */
93 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
94
95 /*
96  * All files have objectids in this range.
97  */
98 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
99 #define BTRFS_LAST_FREE_OBJECTID -256ULL
100 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
101
102
103 /*
104  * the device items go into the chunk tree.  The key is in the form
105  * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
106  */
107 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
108
109 #define BTRFS_BTREE_INODE_OBJECTID 1
110
111 #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
112
113 #define BTRFS_DEV_REPLACE_DEVID 0ULL
114
115 /*
116  * inode items have the data typically returned from stat and store other
117  * info about object characteristics.  There is one for every file and dir in
118  * the FS
119  */
120 #define BTRFS_INODE_ITEM_KEY            1
121 #define BTRFS_INODE_REF_KEY             12
122 #define BTRFS_INODE_EXTREF_KEY          13
123 #define BTRFS_XATTR_ITEM_KEY            24
124
125 /*
126  * fs verity items are stored under two different key types on disk.
127  * The descriptor items:
128  * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
129  *
130  * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
131  * of the descriptor item and some extra data for encryption.
132  * Starting at offset 1, these hold the generic fs verity descriptor.  The
133  * latter are opaque to btrfs, we just read and write them as a blob for the
134  * higher level verity code.  The most common descriptor size is 256 bytes.
135  *
136  * The merkle tree items:
137  * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
138  *
139  * These also start at offset 0, and correspond to the merkle tree bytes.  When
140  * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
141  * offset 0 for this key type.  These are also opaque to btrfs, we're blindly
142  * storing whatever fsverity sends down.
143  */
144 #define BTRFS_VERITY_DESC_ITEM_KEY      36
145 #define BTRFS_VERITY_MERKLE_ITEM_KEY    37
146
147 #define BTRFS_ORPHAN_ITEM_KEY           48
148 /* reserve 2-15 close to the inode for later flexibility */
149
150 /*
151  * dir items are the name -> inode pointers in a directory.  There is one
152  * for every name in a directory.  BTRFS_DIR_LOG_ITEM_KEY is no longer used
153  * but it's still defined here for documentation purposes and to help avoid
154  * having its numerical value reused in the future.
155  */
156 #define BTRFS_DIR_LOG_ITEM_KEY  60
157 #define BTRFS_DIR_LOG_INDEX_KEY 72
158 #define BTRFS_DIR_ITEM_KEY      84
159 #define BTRFS_DIR_INDEX_KEY     96
160 /*
161  * extent data is for file data
162  */
163 #define BTRFS_EXTENT_DATA_KEY   108
164
165 /*
166  * extent csums are stored in a separate tree and hold csums for
167  * an entire extent on disk.
168  */
169 #define BTRFS_EXTENT_CSUM_KEY   128
170
171 /*
172  * root items point to tree roots.  They are typically in the root
173  * tree used by the super block to find all the other trees
174  */
175 #define BTRFS_ROOT_ITEM_KEY     132
176
177 /*
178  * root backrefs tie subvols and snapshots to the directory entries that
179  * reference them
180  */
181 #define BTRFS_ROOT_BACKREF_KEY  144
182
183 /*
184  * root refs make a fast index for listing all of the snapshots and
185  * subvolumes referenced by a given root.  They point directly to the
186  * directory item in the root that references the subvol
187  */
188 #define BTRFS_ROOT_REF_KEY      156
189
190 /*
191  * extent items are in the extent map tree.  These record which blocks
192  * are used, and how many references there are to each block
193  */
194 #define BTRFS_EXTENT_ITEM_KEY   168
195
196 /*
197  * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
198  * the length, so we save the level in key->offset instead of the length.
199  */
200 #define BTRFS_METADATA_ITEM_KEY 169
201
202 #define BTRFS_TREE_BLOCK_REF_KEY        176
203
204 #define BTRFS_EXTENT_DATA_REF_KEY       178
205
206 #define BTRFS_EXTENT_REF_V0_KEY         180
207
208 #define BTRFS_SHARED_BLOCK_REF_KEY      182
209
210 #define BTRFS_SHARED_DATA_REF_KEY       184
211
212 /*
213  * block groups give us hints into the extent allocation trees.  Which
214  * blocks are free etc etc
215  */
216 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
217
218 /*
219  * Every block group is represented in the free space tree by a free space info
220  * item, which stores some accounting information. It is keyed on
221  * (block_group_start, FREE_SPACE_INFO, block_group_length).
222  */
223 #define BTRFS_FREE_SPACE_INFO_KEY 198
224
225 /*
226  * A free space extent tracks an extent of space that is free in a block group.
227  * It is keyed on (start, FREE_SPACE_EXTENT, length).
228  */
229 #define BTRFS_FREE_SPACE_EXTENT_KEY 199
230
231 /*
232  * When a block group becomes very fragmented, we convert it to use bitmaps
233  * instead of extents. A free space bitmap is keyed on
234  * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
235  * (length / sectorsize) bits.
236  */
237 #define BTRFS_FREE_SPACE_BITMAP_KEY 200
238
239 #define BTRFS_DEV_EXTENT_KEY    204
240 #define BTRFS_DEV_ITEM_KEY      216
241 #define BTRFS_CHUNK_ITEM_KEY    228
242
243 /*
244  * Records the overall state of the qgroups.
245  * There's only one instance of this key present,
246  * (0, BTRFS_QGROUP_STATUS_KEY, 0)
247  */
248 #define BTRFS_QGROUP_STATUS_KEY         240
249 /*
250  * Records the currently used space of the qgroup.
251  * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
252  */
253 #define BTRFS_QGROUP_INFO_KEY           242
254 /*
255  * Contains the user configured limits for the qgroup.
256  * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
257  */
258 #define BTRFS_QGROUP_LIMIT_KEY          244
259 /*
260  * Records the child-parent relationship of qgroups. For
261  * each relation, 2 keys are present:
262  * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
263  * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
264  */
265 #define BTRFS_QGROUP_RELATION_KEY       246
266
267 /*
268  * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
269  */
270 #define BTRFS_BALANCE_ITEM_KEY  248
271
272 /*
273  * The key type for tree items that are stored persistently, but do not need to
274  * exist for extended period of time. The items can exist in any tree.
275  *
276  * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
277  *
278  * Existing items:
279  *
280  * - balance status item
281  *   (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
282  */
283 #define BTRFS_TEMPORARY_ITEM_KEY        248
284
285 /*
286  * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
287  */
288 #define BTRFS_DEV_STATS_KEY             249
289
290 /*
291  * The key type for tree items that are stored persistently and usually exist
292  * for a long period, eg. filesystem lifetime. The item kinds can be status
293  * information, stats or preference values. The item can exist in any tree.
294  *
295  * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
296  *
297  * Existing items:
298  *
299  * - device statistics, store IO stats in the device tree, one key for all
300  *   stats
301  *   (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
302  */
303 #define BTRFS_PERSISTENT_ITEM_KEY       249
304
305 /*
306  * Persistently stores the device replace state in the device tree.
307  * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
308  */
309 #define BTRFS_DEV_REPLACE_KEY   250
310
311 /*
312  * Stores items that allow to quickly map UUIDs to something else.
313  * These items are part of the filesystem UUID tree.
314  * The key is built like this:
315  * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
316  */
317 #if BTRFS_UUID_SIZE != 16
318 #error "UUID items require BTRFS_UUID_SIZE == 16!"
319 #endif
320 #define BTRFS_UUID_KEY_SUBVOL   251     /* for UUIDs assigned to subvols */
321 #define BTRFS_UUID_KEY_RECEIVED_SUBVOL  252     /* for UUIDs assigned to
322                                                  * received subvols */
323
324 /*
325  * string items are for debugging.  They just store a short string of
326  * data in the FS
327  */
328 #define BTRFS_STRING_ITEM_KEY   253
329
330 /* Maximum metadata block size (nodesize) */
331 #define BTRFS_MAX_METADATA_BLOCKSIZE                    65536
332
333 /* 32 bytes in various csum fields */
334 #define BTRFS_CSUM_SIZE 32
335
336 /* csum types */
337 enum btrfs_csum_type {
338         BTRFS_CSUM_TYPE_CRC32   = 0,
339         BTRFS_CSUM_TYPE_XXHASH  = 1,
340         BTRFS_CSUM_TYPE_SHA256  = 2,
341         BTRFS_CSUM_TYPE_BLAKE2  = 3,
342 };
343
344 /*
345  * flags definitions for directory entry item type
346  *
347  * Used by:
348  * struct btrfs_dir_item.type
349  *
350  * Values 0..7 must match common file type values in fs_types.h.
351  */
352 #define BTRFS_FT_UNKNOWN        0
353 #define BTRFS_FT_REG_FILE       1
354 #define BTRFS_FT_DIR            2
355 #define BTRFS_FT_CHRDEV         3
356 #define BTRFS_FT_BLKDEV         4
357 #define BTRFS_FT_FIFO           5
358 #define BTRFS_FT_SOCK           6
359 #define BTRFS_FT_SYMLINK        7
360 #define BTRFS_FT_XATTR          8
361 #define BTRFS_FT_MAX            9
362
363 /*
364  * The key defines the order in the tree, and so it also defines (optimal)
365  * block layout.
366  *
367  * objectid corresponds to the inode number.
368  *
369  * type tells us things about the object, and is a kind of stream selector.
370  * so for a given inode, keys with type of 1 might refer to the inode data,
371  * type of 2 may point to file data in the btree and type == 3 may point to
372  * extents.
373  *
374  * offset is the starting byte offset for this key in the stream.
375  *
376  * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
377  * in cpu native order.  Otherwise they are identical and their sizes
378  * should be the same (ie both packed)
379  */
380 struct btrfs_disk_key {
381         __le64 objectid;
382         __u8 type;
383         __le64 offset;
384 } __attribute__ ((__packed__));
385
386 struct btrfs_key {
387         __u64 objectid;
388         __u8 type;
389         __u64 offset;
390 } __attribute__ ((__packed__));
391
392 struct btrfs_dev_item {
393         /* the internal btrfs device id */
394         __le64 devid;
395
396         /* size of the device */
397         __le64 total_bytes;
398
399         /* bytes used */
400         __le64 bytes_used;
401
402         /* optimal io alignment for this device */
403         __le32 io_align;
404
405         /* optimal io width for this device */
406         __le32 io_width;
407
408         /* minimal io size for this device */
409         __le32 sector_size;
410
411         /* type and info about this device */
412         __le64 type;
413
414         /* expected generation for this device */
415         __le64 generation;
416
417         /*
418          * starting byte of this partition on the device,
419          * to allow for stripe alignment in the future
420          */
421         __le64 start_offset;
422
423         /* grouping information for allocation decisions */
424         __le32 dev_group;
425
426         /* seek speed 0-100 where 100 is fastest */
427         __u8 seek_speed;
428
429         /* bandwidth 0-100 where 100 is fastest */
430         __u8 bandwidth;
431
432         /* btrfs generated uuid for this device */
433         __u8 uuid[BTRFS_UUID_SIZE];
434
435         /* uuid of FS who owns this device */
436         __u8 fsid[BTRFS_UUID_SIZE];
437 } __attribute__ ((__packed__));
438
439 struct btrfs_stripe {
440         __le64 devid;
441         __le64 offset;
442         __u8 dev_uuid[BTRFS_UUID_SIZE];
443 } __attribute__ ((__packed__));
444
445 struct btrfs_chunk {
446         /* size of this chunk in bytes */
447         __le64 length;
448
449         /* objectid of the root referencing this chunk */
450         __le64 owner;
451
452         __le64 stripe_len;
453         __le64 type;
454
455         /* optimal io alignment for this chunk */
456         __le32 io_align;
457
458         /* optimal io width for this chunk */
459         __le32 io_width;
460
461         /* minimal io size for this chunk */
462         __le32 sector_size;
463
464         /* 2^16 stripes is quite a lot, a second limit is the size of a single
465          * item in the btree
466          */
467         __le16 num_stripes;
468
469         /* sub stripes only matter for raid10 */
470         __le16 sub_stripes;
471         struct btrfs_stripe stripe;
472         /* additional stripes go here */
473 } __attribute__ ((__packed__));
474
475 #define BTRFS_FREE_SPACE_EXTENT 1
476 #define BTRFS_FREE_SPACE_BITMAP 2
477
478 struct btrfs_free_space_entry {
479         __le64 offset;
480         __le64 bytes;
481         __u8 type;
482 } __attribute__ ((__packed__));
483
484 struct btrfs_free_space_header {
485         struct btrfs_disk_key location;
486         __le64 generation;
487         __le64 num_entries;
488         __le64 num_bitmaps;
489 } __attribute__ ((__packed__));
490
491 #define BTRFS_HEADER_FLAG_WRITTEN       (1ULL << 0)
492 #define BTRFS_HEADER_FLAG_RELOC         (1ULL << 1)
493
494 /* Super block flags */
495 /* Errors detected */
496 #define BTRFS_SUPER_FLAG_ERROR          (1ULL << 2)
497
498 #define BTRFS_SUPER_FLAG_SEEDING        (1ULL << 32)
499 #define BTRFS_SUPER_FLAG_METADUMP       (1ULL << 33)
500 #define BTRFS_SUPER_FLAG_METADUMP_V2    (1ULL << 34)
501 #define BTRFS_SUPER_FLAG_CHANGING_FSID  (1ULL << 35)
502 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
503
504
505 /*
506  * items in the extent btree are used to record the objectid of the
507  * owner of the block and the number of references
508  */
509
510 struct btrfs_extent_item {
511         __le64 refs;
512         __le64 generation;
513         __le64 flags;
514 } __attribute__ ((__packed__));
515
516 struct btrfs_extent_item_v0 {
517         __le32 refs;
518 } __attribute__ ((__packed__));
519
520
521 #define BTRFS_EXTENT_FLAG_DATA          (1ULL << 0)
522 #define BTRFS_EXTENT_FLAG_TREE_BLOCK    (1ULL << 1)
523
524 /* following flags only apply to tree blocks */
525
526 /* use full backrefs for extent pointers in the block */
527 #define BTRFS_BLOCK_FLAG_FULL_BACKREF   (1ULL << 8)
528
529 /*
530  * this flag is only used internally by scrub and may be changed at any time
531  * it is only declared here to avoid collisions
532  */
533 #define BTRFS_EXTENT_FLAG_SUPER         (1ULL << 48)
534
535 struct btrfs_tree_block_info {
536         struct btrfs_disk_key key;
537         __u8 level;
538 } __attribute__ ((__packed__));
539
540 struct btrfs_extent_data_ref {
541         __le64 root;
542         __le64 objectid;
543         __le64 offset;
544         __le32 count;
545 } __attribute__ ((__packed__));
546
547 struct btrfs_shared_data_ref {
548         __le32 count;
549 } __attribute__ ((__packed__));
550
551 struct btrfs_extent_inline_ref {
552         __u8 type;
553         __le64 offset;
554 } __attribute__ ((__packed__));
555
556 /* dev extents record free space on individual devices.  The owner
557  * field points back to the chunk allocation mapping tree that allocated
558  * the extent.  The chunk tree uuid field is a way to double check the owner
559  */
560 struct btrfs_dev_extent {
561         __le64 chunk_tree;
562         __le64 chunk_objectid;
563         __le64 chunk_offset;
564         __le64 length;
565         __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
566 } __attribute__ ((__packed__));
567
568 struct btrfs_inode_ref {
569         __le64 index;
570         __le16 name_len;
571         /* name goes here */
572 } __attribute__ ((__packed__));
573
574 struct btrfs_inode_extref {
575         __le64 parent_objectid;
576         __le64 index;
577         __le16 name_len;
578         __u8   name[];
579         /* name goes here */
580 } __attribute__ ((__packed__));
581
582 struct btrfs_timespec {
583         __le64 sec;
584         __le32 nsec;
585 } __attribute__ ((__packed__));
586
587 struct btrfs_inode_item {
588         /* nfs style generation number */
589         __le64 generation;
590         /* transid that last touched this inode */
591         __le64 transid;
592         __le64 size;
593         __le64 nbytes;
594         __le64 block_group;
595         __le32 nlink;
596         __le32 uid;
597         __le32 gid;
598         __le32 mode;
599         __le64 rdev;
600         __le64 flags;
601
602         /* modification sequence number for NFS */
603         __le64 sequence;
604
605         /*
606          * a little future expansion, for more than this we can
607          * just grow the inode item and version it
608          */
609         __le64 reserved[4];
610         struct btrfs_timespec atime;
611         struct btrfs_timespec ctime;
612         struct btrfs_timespec mtime;
613         struct btrfs_timespec otime;
614 } __attribute__ ((__packed__));
615
616 struct btrfs_dir_log_item {
617         __le64 end;
618 } __attribute__ ((__packed__));
619
620 struct btrfs_dir_item {
621         struct btrfs_disk_key location;
622         __le64 transid;
623         __le16 data_len;
624         __le16 name_len;
625         __u8 type;
626 } __attribute__ ((__packed__));
627
628 #define BTRFS_ROOT_SUBVOL_RDONLY        (1ULL << 0)
629
630 /*
631  * Internal in-memory flag that a subvolume has been marked for deletion but
632  * still visible as a directory
633  */
634 #define BTRFS_ROOT_SUBVOL_DEAD          (1ULL << 48)
635
636 struct btrfs_root_item {
637         struct btrfs_inode_item inode;
638         __le64 generation;
639         __le64 root_dirid;
640         __le64 bytenr;
641         __le64 byte_limit;
642         __le64 bytes_used;
643         __le64 last_snapshot;
644         __le64 flags;
645         __le32 refs;
646         struct btrfs_disk_key drop_progress;
647         __u8 drop_level;
648         __u8 level;
649
650         /*
651          * The following fields appear after subvol_uuids+subvol_times
652          * were introduced.
653          */
654
655         /*
656          * This generation number is used to test if the new fields are valid
657          * and up to date while reading the root item. Every time the root item
658          * is written out, the "generation" field is copied into this field. If
659          * anyone ever mounted the fs with an older kernel, we will have
660          * mismatching generation values here and thus must invalidate the
661          * new fields. See btrfs_update_root and btrfs_find_last_root for
662          * details.
663          * the offset of generation_v2 is also used as the start for the memset
664          * when invalidating the fields.
665          */
666         __le64 generation_v2;
667         __u8 uuid[BTRFS_UUID_SIZE];
668         __u8 parent_uuid[BTRFS_UUID_SIZE];
669         __u8 received_uuid[BTRFS_UUID_SIZE];
670         __le64 ctransid; /* updated when an inode changes */
671         __le64 otransid; /* trans when created */
672         __le64 stransid; /* trans when sent. non-zero for received subvol */
673         __le64 rtransid; /* trans when received. non-zero for received subvol */
674         struct btrfs_timespec ctime;
675         struct btrfs_timespec otime;
676         struct btrfs_timespec stime;
677         struct btrfs_timespec rtime;
678         __le64 reserved[8]; /* for future */
679 } __attribute__ ((__packed__));
680
681 /*
682  * Btrfs root item used to be smaller than current size.  The old format ends
683  * at where member generation_v2 is.
684  */
685 static inline __u32 btrfs_legacy_root_item_size(void)
686 {
687         return offsetof(struct btrfs_root_item, generation_v2);
688 }
689
690 /*
691  * this is used for both forward and backward root refs
692  */
693 struct btrfs_root_ref {
694         __le64 dirid;
695         __le64 sequence;
696         __le16 name_len;
697 } __attribute__ ((__packed__));
698
699 struct btrfs_disk_balance_args {
700         /*
701          * profiles to operate on, single is denoted by
702          * BTRFS_AVAIL_ALLOC_BIT_SINGLE
703          */
704         __le64 profiles;
705
706         /*
707          * usage filter
708          * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
709          * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
710          */
711         union {
712                 __le64 usage;
713                 struct {
714                         __le32 usage_min;
715                         __le32 usage_max;
716                 };
717         };
718
719         /* devid filter */
720         __le64 devid;
721
722         /* devid subset filter [pstart..pend) */
723         __le64 pstart;
724         __le64 pend;
725
726         /* btrfs virtual address space subset filter [vstart..vend) */
727         __le64 vstart;
728         __le64 vend;
729
730         /*
731          * profile to convert to, single is denoted by
732          * BTRFS_AVAIL_ALLOC_BIT_SINGLE
733          */
734         __le64 target;
735
736         /* BTRFS_BALANCE_ARGS_* */
737         __le64 flags;
738
739         /*
740          * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
741          * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
742          * and maximum
743          */
744         union {
745                 __le64 limit;
746                 struct {
747                         __le32 limit_min;
748                         __le32 limit_max;
749                 };
750         };
751
752         /*
753          * Process chunks that cross stripes_min..stripes_max devices,
754          * BTRFS_BALANCE_ARGS_STRIPES_RANGE
755          */
756         __le32 stripes_min;
757         __le32 stripes_max;
758
759         __le64 unused[6];
760 } __attribute__ ((__packed__));
761
762 /*
763  * store balance parameters to disk so that balance can be properly
764  * resumed after crash or unmount
765  */
766 struct btrfs_balance_item {
767         /* BTRFS_BALANCE_* */
768         __le64 flags;
769
770         struct btrfs_disk_balance_args data;
771         struct btrfs_disk_balance_args meta;
772         struct btrfs_disk_balance_args sys;
773
774         __le64 unused[4];
775 } __attribute__ ((__packed__));
776
777 enum {
778         BTRFS_FILE_EXTENT_INLINE   = 0,
779         BTRFS_FILE_EXTENT_REG      = 1,
780         BTRFS_FILE_EXTENT_PREALLOC = 2,
781         BTRFS_NR_FILE_EXTENT_TYPES = 3,
782 };
783
784 struct btrfs_file_extent_item {
785         /*
786          * transaction id that created this extent
787          */
788         __le64 generation;
789         /*
790          * max number of bytes to hold this extent in ram
791          * when we split a compressed extent we can't know how big
792          * each of the resulting pieces will be.  So, this is
793          * an upper limit on the size of the extent in ram instead of
794          * an exact limit.
795          */
796         __le64 ram_bytes;
797
798         /*
799          * 32 bits for the various ways we might encode the data,
800          * including compression and encryption.  If any of these
801          * are set to something a given disk format doesn't understand
802          * it is treated like an incompat flag for reading and writing,
803          * but not for stat.
804          */
805         __u8 compression;
806         __u8 encryption;
807         __le16 other_encoding; /* spare for later use */
808
809         /* are we inline data or a real extent? */
810         __u8 type;
811
812         /*
813          * disk space consumed by the extent, checksum blocks are included
814          * in these numbers
815          *
816          * At this offset in the structure, the inline extent data start.
817          */
818         __le64 disk_bytenr;
819         __le64 disk_num_bytes;
820         /*
821          * the logical offset in file blocks (no csums)
822          * this extent record is for.  This allows a file extent to point
823          * into the middle of an existing extent on disk, sharing it
824          * between two snapshots (useful if some bytes in the middle of the
825          * extent have changed
826          */
827         __le64 offset;
828         /*
829          * the logical number of file blocks (no csums included).  This
830          * always reflects the size uncompressed and without encoding.
831          */
832         __le64 num_bytes;
833
834 } __attribute__ ((__packed__));
835
836 struct btrfs_csum_item {
837         __u8 csum;
838 } __attribute__ ((__packed__));
839
840 struct btrfs_dev_stats_item {
841         /*
842          * grow this item struct at the end for future enhancements and keep
843          * the existing values unchanged
844          */
845         __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
846 } __attribute__ ((__packed__));
847
848 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS     0
849 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID      1
850
851 struct btrfs_dev_replace_item {
852         /*
853          * grow this item struct at the end for future enhancements and keep
854          * the existing values unchanged
855          */
856         __le64 src_devid;
857         __le64 cursor_left;
858         __le64 cursor_right;
859         __le64 cont_reading_from_srcdev_mode;
860
861         __le64 replace_state;
862         __le64 time_started;
863         __le64 time_stopped;
864         __le64 num_write_errors;
865         __le64 num_uncorrectable_read_errors;
866 } __attribute__ ((__packed__));
867
868 /* different types of block groups (and chunks) */
869 #define BTRFS_BLOCK_GROUP_DATA          (1ULL << 0)
870 #define BTRFS_BLOCK_GROUP_SYSTEM        (1ULL << 1)
871 #define BTRFS_BLOCK_GROUP_METADATA      (1ULL << 2)
872 #define BTRFS_BLOCK_GROUP_RAID0         (1ULL << 3)
873 #define BTRFS_BLOCK_GROUP_RAID1         (1ULL << 4)
874 #define BTRFS_BLOCK_GROUP_DUP           (1ULL << 5)
875 #define BTRFS_BLOCK_GROUP_RAID10        (1ULL << 6)
876 #define BTRFS_BLOCK_GROUP_RAID5         (1ULL << 7)
877 #define BTRFS_BLOCK_GROUP_RAID6         (1ULL << 8)
878 #define BTRFS_BLOCK_GROUP_RAID1C3       (1ULL << 9)
879 #define BTRFS_BLOCK_GROUP_RAID1C4       (1ULL << 10)
880 #define BTRFS_BLOCK_GROUP_RESERVED      (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
881                                          BTRFS_SPACE_INFO_GLOBAL_RSV)
882
883 #define BTRFS_BLOCK_GROUP_TYPE_MASK     (BTRFS_BLOCK_GROUP_DATA |    \
884                                          BTRFS_BLOCK_GROUP_SYSTEM |  \
885                                          BTRFS_BLOCK_GROUP_METADATA)
886
887 #define BTRFS_BLOCK_GROUP_PROFILE_MASK  (BTRFS_BLOCK_GROUP_RAID0 |   \
888                                          BTRFS_BLOCK_GROUP_RAID1 |   \
889                                          BTRFS_BLOCK_GROUP_RAID1C3 | \
890                                          BTRFS_BLOCK_GROUP_RAID1C4 | \
891                                          BTRFS_BLOCK_GROUP_RAID5 |   \
892                                          BTRFS_BLOCK_GROUP_RAID6 |   \
893                                          BTRFS_BLOCK_GROUP_DUP |     \
894                                          BTRFS_BLOCK_GROUP_RAID10)
895 #define BTRFS_BLOCK_GROUP_RAID56_MASK   (BTRFS_BLOCK_GROUP_RAID5 |   \
896                                          BTRFS_BLOCK_GROUP_RAID6)
897
898 #define BTRFS_BLOCK_GROUP_RAID1_MASK    (BTRFS_BLOCK_GROUP_RAID1 |   \
899                                          BTRFS_BLOCK_GROUP_RAID1C3 | \
900                                          BTRFS_BLOCK_GROUP_RAID1C4)
901
902 /*
903  * We need a bit for restriper to be able to tell when chunks of type
904  * SINGLE are available.  This "extended" profile format is used in
905  * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
906  * (on-disk).  The corresponding on-disk bit in chunk.type is reserved
907  * to avoid remappings between two formats in future.
908  */
909 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE    (1ULL << 48)
910
911 /*
912  * A fake block group type that is used to communicate global block reserve
913  * size to userspace via the SPACE_INFO ioctl.
914  */
915 #define BTRFS_SPACE_INFO_GLOBAL_RSV     (1ULL << 49)
916
917 #define BTRFS_EXTENDED_PROFILE_MASK     (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
918                                          BTRFS_AVAIL_ALLOC_BIT_SINGLE)
919
920 static inline __u64 chunk_to_extended(__u64 flags)
921 {
922         if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
923                 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
924
925         return flags;
926 }
927 static inline __u64 extended_to_chunk(__u64 flags)
928 {
929         return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
930 }
931
932 struct btrfs_block_group_item {
933         __le64 used;
934         __le64 chunk_objectid;
935         __le64 flags;
936 } __attribute__ ((__packed__));
937
938 struct btrfs_free_space_info {
939         __le32 extent_count;
940         __le32 flags;
941 } __attribute__ ((__packed__));
942
943 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
944
945 #define BTRFS_QGROUP_LEVEL_SHIFT                48
946 static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
947 {
948         return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
949 }
950
951 /*
952  * is subvolume quota turned on?
953  */
954 #define BTRFS_QGROUP_STATUS_FLAG_ON             (1ULL << 0)
955 /*
956  * RESCAN is set during the initialization phase
957  */
958 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN         (1ULL << 1)
959 /*
960  * Some qgroup entries are known to be out of date,
961  * either because the configuration has changed in a way that
962  * makes a rescan necessary, or because the fs has been mounted
963  * with a non-qgroup-aware version.
964  * Turning qouta off and on again makes it inconsistent, too.
965  */
966 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT   (1ULL << 2)
967
968 #define BTRFS_QGROUP_STATUS_VERSION        1
969
970 struct btrfs_qgroup_status_item {
971         __le64 version;
972         /*
973          * the generation is updated during every commit. As older
974          * versions of btrfs are not aware of qgroups, it will be
975          * possible to detect inconsistencies by checking the
976          * generation on mount time
977          */
978         __le64 generation;
979
980         /* flag definitions see above */
981         __le64 flags;
982
983         /*
984          * only used during scanning to record the progress
985          * of the scan. It contains a logical address
986          */
987         __le64 rescan;
988 } __attribute__ ((__packed__));
989
990 struct btrfs_qgroup_info_item {
991         __le64 generation;
992         __le64 rfer;
993         __le64 rfer_cmpr;
994         __le64 excl;
995         __le64 excl_cmpr;
996 } __attribute__ ((__packed__));
997
998 struct btrfs_qgroup_limit_item {
999         /*
1000          * only updated when any of the other values change
1001          */
1002         __le64 flags;
1003         __le64 max_rfer;
1004         __le64 max_excl;
1005         __le64 rsv_rfer;
1006         __le64 rsv_excl;
1007 } __attribute__ ((__packed__));
1008
1009 struct btrfs_verity_descriptor_item {
1010         /* Size of the verity descriptor in bytes */
1011         __le64 size;
1012         /*
1013          * When we implement support for fscrypt, we will need to encrypt the
1014          * Merkle tree for encrypted verity files. These 128 bits are for the
1015          * eventual storage of an fscrypt initialization vector.
1016          */
1017         __le64 reserved[2];
1018         __u8 encryption;
1019 } __attribute__ ((__packed__));
1020
1021 #endif /* _BTRFS_CTREE_H_ */