btrfs: tree-checker: fix false alert caused by legacy btrfs root item
[linux-2.6-block.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 6#include <linux/types.h>
1465af12
QW
7#ifdef __KERNEL__
8#include <linux/stddef.h>
9#else
10#include <stddef.h>
11#endif
9078b4ee 12
db671160
JM
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 */
e35b79a1
JT
308enum btrfs_csum_type {
309 BTRFS_CSUM_TYPE_CRC32 = 0,
3951e7f0 310 BTRFS_CSUM_TYPE_XXHASH = 1,
3831bf00 311 BTRFS_CSUM_TYPE_SHA256 = 2,
352ae07b 312 BTRFS_CSUM_TYPE_BLAKE2 = 3,
e35b79a1 313};
db671160
JM
314
315/*
316 * flags definitions for directory entry item type
317 *
318 * Used by:
319 * struct btrfs_dir_item.type
7d157c3d
PP
320 *
321 * Values 0..7 must match common file type values in fs_types.h.
db671160
JM
322 */
323#define BTRFS_FT_UNKNOWN 0
324#define BTRFS_FT_REG_FILE 1
325#define BTRFS_FT_DIR 2
326#define BTRFS_FT_CHRDEV 3
327#define BTRFS_FT_BLKDEV 4
328#define BTRFS_FT_FIFO 5
329#define BTRFS_FT_SOCK 6
330#define BTRFS_FT_SYMLINK 7
331#define BTRFS_FT_XATTR 8
332#define BTRFS_FT_MAX 9
333
334/*
335 * The key defines the order in the tree, and so it also defines (optimal)
336 * block layout.
337 *
338 * objectid corresponds to the inode number.
339 *
340 * type tells us things about the object, and is a kind of stream selector.
341 * so for a given inode, keys with type of 1 might refer to the inode data,
342 * type of 2 may point to file data in the btree and type == 3 may point to
343 * extents.
344 *
345 * offset is the starting byte offset for this key in the stream.
346 *
347 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
348 * in cpu native order. Otherwise they are identical and their sizes
349 * should be the same (ie both packed)
350 */
351struct btrfs_disk_key {
352 __le64 objectid;
14b05c51 353 __u8 type;
db671160
JM
354 __le64 offset;
355} __attribute__ ((__packed__));
356
357struct btrfs_key {
14b05c51
JM
358 __u64 objectid;
359 __u8 type;
360 __u64 offset;
db671160
JM
361} __attribute__ ((__packed__));
362
363struct btrfs_dev_item {
364 /* the internal btrfs device id */
365 __le64 devid;
366
367 /* size of the device */
368 __le64 total_bytes;
369
370 /* bytes used */
371 __le64 bytes_used;
372
373 /* optimal io alignment for this device */
374 __le32 io_align;
375
376 /* optimal io width for this device */
377 __le32 io_width;
378
379 /* minimal io size for this device */
380 __le32 sector_size;
381
382 /* type and info about this device */
383 __le64 type;
384
385 /* expected generation for this device */
386 __le64 generation;
387
388 /*
389 * starting byte of this partition on the device,
390 * to allow for stripe alignment in the future
391 */
392 __le64 start_offset;
393
394 /* grouping information for allocation decisions */
395 __le32 dev_group;
396
397 /* seek speed 0-100 where 100 is fastest */
14b05c51 398 __u8 seek_speed;
db671160
JM
399
400 /* bandwidth 0-100 where 100 is fastest */
14b05c51 401 __u8 bandwidth;
db671160
JM
402
403 /* btrfs generated uuid for this device */
14b05c51 404 __u8 uuid[BTRFS_UUID_SIZE];
db671160
JM
405
406 /* uuid of FS who owns this device */
14b05c51 407 __u8 fsid[BTRFS_UUID_SIZE];
db671160
JM
408} __attribute__ ((__packed__));
409
410struct btrfs_stripe {
411 __le64 devid;
412 __le64 offset;
14b05c51 413 __u8 dev_uuid[BTRFS_UUID_SIZE];
db671160
JM
414} __attribute__ ((__packed__));
415
416struct btrfs_chunk {
417 /* size of this chunk in bytes */
418 __le64 length;
419
420 /* objectid of the root referencing this chunk */
421 __le64 owner;
422
423 __le64 stripe_len;
424 __le64 type;
425
426 /* optimal io alignment for this chunk */
427 __le32 io_align;
428
429 /* optimal io width for this chunk */
430 __le32 io_width;
431
432 /* minimal io size for this chunk */
433 __le32 sector_size;
434
435 /* 2^16 stripes is quite a lot, a second limit is the size of a single
436 * item in the btree
437 */
438 __le16 num_stripes;
439
440 /* sub stripes only matter for raid10 */
441 __le16 sub_stripes;
442 struct btrfs_stripe stripe;
443 /* additional stripes go here */
444} __attribute__ ((__packed__));
445
446#define BTRFS_FREE_SPACE_EXTENT 1
447#define BTRFS_FREE_SPACE_BITMAP 2
448
449struct btrfs_free_space_entry {
450 __le64 offset;
451 __le64 bytes;
14b05c51 452 __u8 type;
db671160
JM
453} __attribute__ ((__packed__));
454
455struct btrfs_free_space_header {
456 struct btrfs_disk_key location;
457 __le64 generation;
458 __le64 num_entries;
459 __le64 num_bitmaps;
460} __attribute__ ((__packed__));
461
462#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
463#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
464
465/* Super block flags */
466/* Errors detected */
467#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
468
469#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
470#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
e2731e55 471#define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
98820a7e 472#define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
7239ff4b 473#define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
db671160
JM
474
475
476/*
477 * items in the extent btree are used to record the objectid of the
478 * owner of the block and the number of references
479 */
480
481struct btrfs_extent_item {
482 __le64 refs;
483 __le64 generation;
484 __le64 flags;
485} __attribute__ ((__packed__));
486
487struct btrfs_extent_item_v0 {
488 __le32 refs;
489} __attribute__ ((__packed__));
490
491
492#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
493#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
494
495/* following flags only apply to tree blocks */
496
497/* use full backrefs for extent pointers in the block */
498#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
499
500/*
501 * this flag is only used internally by scrub and may be changed at any time
502 * it is only declared here to avoid collisions
503 */
504#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
505
506struct btrfs_tree_block_info {
507 struct btrfs_disk_key key;
14b05c51 508 __u8 level;
db671160
JM
509} __attribute__ ((__packed__));
510
511struct btrfs_extent_data_ref {
512 __le64 root;
513 __le64 objectid;
514 __le64 offset;
515 __le32 count;
516} __attribute__ ((__packed__));
517
518struct btrfs_shared_data_ref {
519 __le32 count;
520} __attribute__ ((__packed__));
521
522struct btrfs_extent_inline_ref {
14b05c51 523 __u8 type;
db671160
JM
524 __le64 offset;
525} __attribute__ ((__packed__));
526
db671160
JM
527/* dev extents record free space on individual devices. The owner
528 * field points back to the chunk allocation mapping tree that allocated
529 * the extent. The chunk tree uuid field is a way to double check the owner
530 */
531struct btrfs_dev_extent {
532 __le64 chunk_tree;
533 __le64 chunk_objectid;
534 __le64 chunk_offset;
535 __le64 length;
14b05c51 536 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
db671160
JM
537} __attribute__ ((__packed__));
538
539struct btrfs_inode_ref {
540 __le64 index;
541 __le16 name_len;
542 /* name goes here */
543} __attribute__ ((__packed__));
544
545struct btrfs_inode_extref {
546 __le64 parent_objectid;
547 __le64 index;
548 __le16 name_len;
549 __u8 name[0];
550 /* name goes here */
551} __attribute__ ((__packed__));
552
553struct btrfs_timespec {
554 __le64 sec;
555 __le32 nsec;
556} __attribute__ ((__packed__));
557
558struct btrfs_inode_item {
559 /* nfs style generation number */
560 __le64 generation;
561 /* transid that last touched this inode */
562 __le64 transid;
563 __le64 size;
564 __le64 nbytes;
565 __le64 block_group;
566 __le32 nlink;
567 __le32 uid;
568 __le32 gid;
569 __le32 mode;
570 __le64 rdev;
571 __le64 flags;
572
573 /* modification sequence number for NFS */
574 __le64 sequence;
575
576 /*
577 * a little future expansion, for more than this we can
578 * just grow the inode item and version it
579 */
580 __le64 reserved[4];
581 struct btrfs_timespec atime;
582 struct btrfs_timespec ctime;
583 struct btrfs_timespec mtime;
584 struct btrfs_timespec otime;
585} __attribute__ ((__packed__));
586
587struct btrfs_dir_log_item {
588 __le64 end;
589} __attribute__ ((__packed__));
590
591struct btrfs_dir_item {
592 struct btrfs_disk_key location;
593 __le64 transid;
594 __le16 data_len;
595 __le16 name_len;
14b05c51 596 __u8 type;
db671160
JM
597} __attribute__ ((__packed__));
598
599#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
600
601/*
602 * Internal in-memory flag that a subvolume has been marked for deletion but
603 * still visible as a directory
604 */
605#define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
606
607struct btrfs_root_item {
608 struct btrfs_inode_item inode;
609 __le64 generation;
610 __le64 root_dirid;
611 __le64 bytenr;
612 __le64 byte_limit;
613 __le64 bytes_used;
614 __le64 last_snapshot;
615 __le64 flags;
616 __le32 refs;
617 struct btrfs_disk_key drop_progress;
14b05c51
JM
618 __u8 drop_level;
619 __u8 level;
db671160
JM
620
621 /*
622 * The following fields appear after subvol_uuids+subvol_times
623 * were introduced.
624 */
625
626 /*
627 * This generation number is used to test if the new fields are valid
628 * and up to date while reading the root item. Every time the root item
629 * is written out, the "generation" field is copied into this field. If
630 * anyone ever mounted the fs with an older kernel, we will have
631 * mismatching generation values here and thus must invalidate the
632 * new fields. See btrfs_update_root and btrfs_find_last_root for
633 * details.
634 * the offset of generation_v2 is also used as the start for the memset
635 * when invalidating the fields.
636 */
637 __le64 generation_v2;
14b05c51
JM
638 __u8 uuid[BTRFS_UUID_SIZE];
639 __u8 parent_uuid[BTRFS_UUID_SIZE];
640 __u8 received_uuid[BTRFS_UUID_SIZE];
db671160
JM
641 __le64 ctransid; /* updated when an inode changes */
642 __le64 otransid; /* trans when created */
643 __le64 stransid; /* trans when sent. non-zero for received subvol */
644 __le64 rtransid; /* trans when received. non-zero for received subvol */
645 struct btrfs_timespec ctime;
646 struct btrfs_timespec otime;
647 struct btrfs_timespec stime;
648 struct btrfs_timespec rtime;
649 __le64 reserved[8]; /* for future */
650} __attribute__ ((__packed__));
651
1465af12
QW
652/*
653 * Btrfs root item used to be smaller than current size. The old format ends
654 * at where member generation_v2 is.
655 */
656static inline __u32 btrfs_legacy_root_item_size(void)
657{
658 return offsetof(struct btrfs_root_item, generation_v2);
659}
660
db671160
JM
661/*
662 * this is used for both forward and backward root refs
663 */
664struct btrfs_root_ref {
665 __le64 dirid;
666 __le64 sequence;
667 __le16 name_len;
668} __attribute__ ((__packed__));
669
670struct btrfs_disk_balance_args {
671 /*
672 * profiles to operate on, single is denoted by
673 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
674 */
675 __le64 profiles;
676
677 /*
678 * usage filter
679 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
680 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
681 */
682 union {
683 __le64 usage;
684 struct {
685 __le32 usage_min;
686 __le32 usage_max;
687 };
688 };
689
690 /* devid filter */
691 __le64 devid;
692
693 /* devid subset filter [pstart..pend) */
694 __le64 pstart;
695 __le64 pend;
696
697 /* btrfs virtual address space subset filter [vstart..vend) */
698 __le64 vstart;
699 __le64 vend;
700
701 /*
702 * profile to convert to, single is denoted by
703 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
704 */
705 __le64 target;
706
707 /* BTRFS_BALANCE_ARGS_* */
708 __le64 flags;
709
710 /*
711 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
712 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
713 * and maximum
714 */
715 union {
716 __le64 limit;
717 struct {
718 __le32 limit_min;
719 __le32 limit_max;
720 };
721 };
722
723 /*
724 * Process chunks that cross stripes_min..stripes_max devices,
725 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
726 */
727 __le32 stripes_min;
728 __le32 stripes_max;
729
730 __le64 unused[6];
731} __attribute__ ((__packed__));
732
733/*
734 * store balance parameters to disk so that balance can be properly
735 * resumed after crash or unmount
736 */
737struct btrfs_balance_item {
738 /* BTRFS_BALANCE_* */
739 __le64 flags;
740
741 struct btrfs_disk_balance_args data;
742 struct btrfs_disk_balance_args meta;
743 struct btrfs_disk_balance_args sys;
744
745 __le64 unused[4];
746} __attribute__ ((__packed__));
747
b9b1a53e
CX
748enum {
749 BTRFS_FILE_EXTENT_INLINE = 0,
750 BTRFS_FILE_EXTENT_REG = 1,
751 BTRFS_FILE_EXTENT_PREALLOC = 2,
752 BTRFS_NR_FILE_EXTENT_TYPES = 3,
753};
db671160
JM
754
755struct btrfs_file_extent_item {
756 /*
757 * transaction id that created this extent
758 */
759 __le64 generation;
760 /*
761 * max number of bytes to hold this extent in ram
762 * when we split a compressed extent we can't know how big
763 * each of the resulting pieces will be. So, this is
764 * an upper limit on the size of the extent in ram instead of
765 * an exact limit.
766 */
767 __le64 ram_bytes;
768
769 /*
770 * 32 bits for the various ways we might encode the data,
771 * including compression and encryption. If any of these
772 * are set to something a given disk format doesn't understand
773 * it is treated like an incompat flag for reading and writing,
774 * but not for stat.
775 */
14b05c51
JM
776 __u8 compression;
777 __u8 encryption;
db671160
JM
778 __le16 other_encoding; /* spare for later use */
779
780 /* are we inline data or a real extent? */
14b05c51 781 __u8 type;
db671160
JM
782
783 /*
784 * disk space consumed by the extent, checksum blocks are included
785 * in these numbers
786 *
787 * At this offset in the structure, the inline extent data start.
788 */
789 __le64 disk_bytenr;
790 __le64 disk_num_bytes;
791 /*
792 * the logical offset in file blocks (no csums)
793 * this extent record is for. This allows a file extent to point
794 * into the middle of an existing extent on disk, sharing it
795 * between two snapshots (useful if some bytes in the middle of the
796 * extent have changed
797 */
798 __le64 offset;
799 /*
800 * the logical number of file blocks (no csums included). This
801 * always reflects the size uncompressed and without encoding.
802 */
803 __le64 num_bytes;
804
805} __attribute__ ((__packed__));
806
807struct btrfs_csum_item {
14b05c51 808 __u8 csum;
db671160
JM
809} __attribute__ ((__packed__));
810
811struct btrfs_dev_stats_item {
812 /*
813 * grow this item struct at the end for future enhancements and keep
814 * the existing values unchanged
815 */
816 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
817} __attribute__ ((__packed__));
818
819#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
820#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
db671160
JM
821
822struct btrfs_dev_replace_item {
823 /*
824 * grow this item struct at the end for future enhancements and keep
825 * the existing values unchanged
826 */
827 __le64 src_devid;
828 __le64 cursor_left;
829 __le64 cursor_right;
830 __le64 cont_reading_from_srcdev_mode;
831
832 __le64 replace_state;
833 __le64 time_started;
834 __le64 time_stopped;
835 __le64 num_write_errors;
836 __le64 num_uncorrectable_read_errors;
837} __attribute__ ((__packed__));
838
839/* different types of block groups (and chunks) */
840#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
841#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
842#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
843#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
844#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
845#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
846#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
847#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
848#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
47e6f742 849#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
8d6fac00 850#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
db671160
JM
851#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
852 BTRFS_SPACE_INFO_GLOBAL_RSV)
853
854enum btrfs_raid_types {
855 BTRFS_RAID_RAID10,
856 BTRFS_RAID_RAID1,
857 BTRFS_RAID_DUP,
858 BTRFS_RAID_RAID0,
859 BTRFS_RAID_SINGLE,
860 BTRFS_RAID_RAID5,
861 BTRFS_RAID_RAID6,
47e6f742 862 BTRFS_RAID_RAID1C3,
8d6fac00 863 BTRFS_RAID_RAID1C4,
db671160
JM
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 | \
47e6f742 873 BTRFS_BLOCK_GROUP_RAID1C3 | \
8d6fac00 874 BTRFS_BLOCK_GROUP_RAID1C4 | \
db671160
JM
875 BTRFS_BLOCK_GROUP_RAID5 | \
876 BTRFS_BLOCK_GROUP_RAID6 | \
877 BTRFS_BLOCK_GROUP_DUP | \
878 BTRFS_BLOCK_GROUP_RAID10)
879#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
880 BTRFS_BLOCK_GROUP_RAID6)
881
47e6f742 882#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
8d6fac00
DS
883 BTRFS_BLOCK_GROUP_RAID1C3 | \
884 BTRFS_BLOCK_GROUP_RAID1C4)
c7369b3f 885
db671160
JM
886/*
887 * We need a bit for restriper to be able to tell when chunks of type
888 * SINGLE are available. This "extended" profile format is used in
889 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
890 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
891 * to avoid remappings between two formats in future.
892 */
893#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
894
895/*
896 * A fake block group type that is used to communicate global block reserve
897 * size to userspace via the SPACE_INFO ioctl.
898 */
899#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
900
901#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
902 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
903
14b05c51 904static inline __u64 chunk_to_extended(__u64 flags)
db671160
JM
905{
906 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
907 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
908
909 return flags;
910}
14b05c51 911static inline __u64 extended_to_chunk(__u64 flags)
db671160
JM
912{
913 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
914}
915
916struct btrfs_block_group_item {
917 __le64 used;
918 __le64 chunk_objectid;
919 __le64 flags;
920} __attribute__ ((__packed__));
921
922struct btrfs_free_space_info {
923 __le32 extent_count;
924 __le32 flags;
925} __attribute__ ((__packed__));
926
927#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
928
929#define BTRFS_QGROUP_LEVEL_SHIFT 48
06f67c47 930static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
db671160 931{
06f67c47 932 return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
db671160
JM
933}
934
935/*
936 * is subvolume quota turned on?
937 */
938#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
939/*
940 * RESCAN is set during the initialization phase
941 */
942#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
943/*
944 * Some qgroup entries are known to be out of date,
945 * either because the configuration has changed in a way that
946 * makes a rescan necessary, or because the fs has been mounted
947 * with a non-qgroup-aware version.
948 * Turning qouta off and on again makes it inconsistent, too.
949 */
950#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
951
952#define BTRFS_QGROUP_STATUS_VERSION 1
953
954struct btrfs_qgroup_status_item {
955 __le64 version;
956 /*
957 * the generation is updated during every commit. As older
958 * versions of btrfs are not aware of qgroups, it will be
959 * possible to detect inconsistencies by checking the
960 * generation on mount time
961 */
962 __le64 generation;
963
964 /* flag definitions see above */
965 __le64 flags;
966
967 /*
968 * only used during scanning to record the progress
969 * of the scan. It contains a logical address
970 */
971 __le64 rescan;
972} __attribute__ ((__packed__));
973
974struct btrfs_qgroup_info_item {
975 __le64 generation;
976 __le64 rfer;
977 __le64 rfer_cmpr;
978 __le64 excl;
979 __le64 excl_cmpr;
980} __attribute__ ((__packed__));
981
982struct btrfs_qgroup_limit_item {
983 /*
984 * only updated when any of the other values change
985 */
986 __le64 flags;
987 __le64 max_rfer;
988 __le64 max_excl;
989 __le64 rsv_rfer;
990 __le64 rsv_excl;
991} __attribute__ ((__packed__));
992
993#endif /* _BTRFS_CTREE_H_ */