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