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