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