aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-05-16 09:46:29 -0400
committerDavid Sterba <dsterba@suse.com>2016-05-16 09:46:29 -0400
commit680834ca0ad4e9827048d4bda1e38db69c3dd1e4 (patch)
tree595935ba3afc91dce9be83ca65932f3cf1379436
parent36fac9e9ff20f71fe7ba21978f5949a38d390a4b (diff)
parent14b05c5106312744badb463e7fb9a78811e44fc0 (diff)
Merge branch 'foreign/jeffm/uapi' into for-chris-4.7-20160516
# Conflicts: # include/uapi/linux/btrfs.h
-rw-r--r--fs/btrfs/ctree.h1014
-rw-r--r--fs/btrfs/volumes.h46
-rw-r--r--include/uapi/linux/btrfs.h173
-rw-r--r--include/uapi/linux/btrfs_tree.h966
4 files changed, 1135 insertions, 1064 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 95bc8c888ba9..e613e48d7122 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -33,6 +33,7 @@
33#include <asm/kmap_types.h> 33#include <asm/kmap_types.h>
34#include <linux/pagemap.h> 34#include <linux/pagemap.h>
35#include <linux/btrfs.h> 35#include <linux/btrfs.h>
36#include <linux/btrfs_tree.h>
36#include <linux/workqueue.h> 37#include <linux/workqueue.h>
37#include <linux/security.h> 38#include <linux/security.h>
38#include <linux/sizes.h> 39#include <linux/sizes.h>
@@ -64,98 +65,6 @@ struct btrfs_ordered_sum;
64 65
65#define BTRFS_COMPAT_EXTENT_TREE_V0 66#define BTRFS_COMPAT_EXTENT_TREE_V0
66 67
67/* holds pointers to all of the tree roots */
68#define BTRFS_ROOT_TREE_OBJECTID 1ULL
69
70/* stores information about which extents are in use, and reference counts */
71#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
72
73/*
74 * chunk tree stores translations from logical -> physical block numbering
75 * the super block points to the chunk tree
76 */
77#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
78
79/*
80 * stores information about which areas of a given device are in use.
81 * one per device. The tree of tree roots points to the device tree
82 */
83#define BTRFS_DEV_TREE_OBJECTID 4ULL
84
85/* one per subvolume, storing files and directories */
86#define BTRFS_FS_TREE_OBJECTID 5ULL
87
88/* directory objectid inside the root tree */
89#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
90
91/* holds checksums of all the data extents */
92#define BTRFS_CSUM_TREE_OBJECTID 7ULL
93
94/* holds quota configuration and tracking */
95#define BTRFS_QUOTA_TREE_OBJECTID 8ULL
96
97/* for storing items that use the BTRFS_UUID_KEY* types */
98#define BTRFS_UUID_TREE_OBJECTID 9ULL
99
100/* tracks free space in block groups. */
101#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
102
103/* device stats in the device tree */
104#define BTRFS_DEV_STATS_OBJECTID 0ULL
105
106/* for storing balance parameters in the root tree */
107#define BTRFS_BALANCE_OBJECTID -4ULL
108
109/* orhpan objectid for tracking unlinked/truncated files */
110#define BTRFS_ORPHAN_OBJECTID -5ULL
111
112/* does write ahead logging to speed up fsyncs */
113#define BTRFS_TREE_LOG_OBJECTID -6ULL
114#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
115
116/* for space balancing */
117#define BTRFS_TREE_RELOC_OBJECTID -8ULL
118#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
119
120/*
121 * extent checksums all have this objectid
122 * this allows them to share the logging tree
123 * for fsyncs
124 */
125#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
126
127/* For storing free space cache */
128#define BTRFS_FREE_SPACE_OBJECTID -11ULL
129
130/*
131 * The inode number assigned to the special inode for storing
132 * free ino cache
133 */
134#define BTRFS_FREE_INO_OBJECTID -12ULL
135
136/* dummy objectid represents multiple objectids */
137#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
138
139/*
140 * All files have objectids in this range.
141 */
142#define BTRFS_FIRST_FREE_OBJECTID 256ULL
143#define BTRFS_LAST_FREE_OBJECTID -256ULL
144#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
145
146
147/*
148 * the device items go into the chunk tree. The key is in the form
149 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
150 */
151#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
152
153#define BTRFS_BTREE_INODE_OBJECTID 1
154
155#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
156
157#define BTRFS_DEV_REPLACE_DEVID 0ULL
158
159/* 68/*
160 * the max metadata block size. This limit is somewhat artificial, 69 * the max metadata block size. This limit is somewhat artificial,
161 * but the memmove costs go through the roof for larger blocks. 70 * but the memmove costs go through the roof for larger blocks.
@@ -175,12 +84,6 @@ struct btrfs_ordered_sum;
175 */ 84 */
176#define BTRFS_LINK_MAX 65535U 85#define BTRFS_LINK_MAX 65535U
177 86
178/* 32 bytes in various csum fields */
179#define BTRFS_CSUM_SIZE 32
180
181/* csum types */
182#define BTRFS_CSUM_TYPE_CRC32 0
183
184static const int btrfs_csum_sizes[] = { 4 }; 87static const int btrfs_csum_sizes[] = { 4 };
185 88
186/* four bytes for CRC32 */ 89/* four bytes for CRC32 */
@@ -189,17 +92,6 @@ static const int btrfs_csum_sizes[] = { 4 };
189/* spefic to btrfs_map_block(), therefore not in include/linux/blk_types.h */ 92/* spefic to btrfs_map_block(), therefore not in include/linux/blk_types.h */
190#define REQ_GET_READ_MIRRORS (1 << 30) 93#define REQ_GET_READ_MIRRORS (1 << 30)
191 94
192#define BTRFS_FT_UNKNOWN 0
193#define BTRFS_FT_REG_FILE 1
194#define BTRFS_FT_DIR 2
195#define BTRFS_FT_CHRDEV 3
196#define BTRFS_FT_BLKDEV 4
197#define BTRFS_FT_FIFO 5
198#define BTRFS_FT_SOCK 6
199#define BTRFS_FT_SYMLINK 7
200#define BTRFS_FT_XATTR 8
201#define BTRFS_FT_MAX 9
202
203/* ioprio of readahead is set to idle */ 95/* ioprio of readahead is set to idle */
204#define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) 96#define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0))
205 97
@@ -207,138 +99,10 @@ static const int btrfs_csum_sizes[] = { 4 };
207 99
208#define BTRFS_MAX_EXTENT_SIZE SZ_128M 100#define BTRFS_MAX_EXTENT_SIZE SZ_128M
209 101
210/*
211 * The key defines the order in the tree, and so it also defines (optimal)
212 * block layout.
213 *
214 * objectid corresponds to the inode number.
215 *
216 * type tells us things about the object, and is a kind of stream selector.
217 * so for a given inode, keys with type of 1 might refer to the inode data,
218 * type of 2 may point to file data in the btree and type == 3 may point to
219 * extents.
220 *
221 * offset is the starting byte offset for this key in the stream.
222 *
223 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
224 * in cpu native order. Otherwise they are identical and their sizes
225 * should be the same (ie both packed)
226 */
227struct btrfs_disk_key {
228 __le64 objectid;
229 u8 type;
230 __le64 offset;
231} __attribute__ ((__packed__));
232
233struct btrfs_key {
234 u64 objectid;
235 u8 type;
236 u64 offset;
237} __attribute__ ((__packed__));
238
239struct btrfs_mapping_tree { 102struct btrfs_mapping_tree {
240 struct extent_map_tree map_tree; 103 struct extent_map_tree map_tree;
241}; 104};
242 105
243struct btrfs_dev_item {
244 /* the internal btrfs device id */
245 __le64 devid;
246
247 /* size of the device */
248 __le64 total_bytes;
249
250 /* bytes used */
251 __le64 bytes_used;
252
253 /* optimal io alignment for this device */
254 __le32 io_align;
255
256 /* optimal io width for this device */
257 __le32 io_width;
258
259 /* minimal io size for this device */
260 __le32 sector_size;
261
262 /* type and info about this device */
263 __le64 type;
264
265 /* expected generation for this device */
266 __le64 generation;
267
268 /*
269 * starting byte of this partition on the device,
270 * to allow for stripe alignment in the future
271 */
272 __le64 start_offset;
273
274 /* grouping information for allocation decisions */
275 __le32 dev_group;
276
277 /* seek speed 0-100 where 100 is fastest */
278 u8 seek_speed;
279
280 /* bandwidth 0-100 where 100 is fastest */
281 u8 bandwidth;
282
283 /* btrfs generated uuid for this device */
284 u8 uuid[BTRFS_UUID_SIZE];
285
286 /* uuid of FS who owns this device */
287 u8 fsid[BTRFS_UUID_SIZE];
288} __attribute__ ((__packed__));
289
290struct btrfs_stripe {
291 __le64 devid;
292 __le64 offset;
293 u8 dev_uuid[BTRFS_UUID_SIZE];
294} __attribute__ ((__packed__));
295
296struct btrfs_chunk {
297 /* size of this chunk in bytes */
298 __le64 length;
299
300 /* objectid of the root referencing this chunk */
301 __le64 owner;
302
303 __le64 stripe_len;
304 __le64 type;
305
306 /* optimal io alignment for this chunk */
307 __le32 io_align;
308
309 /* optimal io width for this chunk */
310 __le32 io_width;
311
312 /* minimal io size for this chunk */
313 __le32 sector_size;
314
315 /* 2^16 stripes is quite a lot, a second limit is the size of a single
316 * item in the btree
317 */
318 __le16 num_stripes;
319
320 /* sub stripes only matter for raid10 */
321 __le16 sub_stripes;
322 struct btrfs_stripe stripe;
323 /* additional stripes go here */
324} __attribute__ ((__packed__));
325
326#define BTRFS_FREE_SPACE_EXTENT 1
327#define BTRFS_FREE_SPACE_BITMAP 2
328
329struct btrfs_free_space_entry {
330 __le64 offset;
331 __le64 bytes;
332 u8 type;
333} __attribute__ ((__packed__));
334
335struct btrfs_free_space_header {
336 struct btrfs_disk_key location;
337 __le64 generation;
338 __le64 num_entries;
339 __le64 num_bitmaps;
340} __attribute__ ((__packed__));
341
342static inline unsigned long btrfs_chunk_item_size(int num_stripes) 106static inline unsigned long btrfs_chunk_item_size(int num_stripes)
343{ 107{
344 BUG_ON(num_stripes == 0); 108 BUG_ON(num_stripes == 0);
@@ -346,9 +110,6 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
346 sizeof(struct btrfs_stripe) * (num_stripes - 1); 110 sizeof(struct btrfs_stripe) * (num_stripes - 1);
347} 111}
348 112
349#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
350#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
351
352/* 113/*
353 * File system states 114 * File system states
354 */ 115 */
@@ -357,13 +118,6 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
357#define BTRFS_FS_STATE_TRANS_ABORTED 2 118#define BTRFS_FS_STATE_TRANS_ABORTED 2
358#define BTRFS_FS_STATE_DEV_REPLACING 3 119#define BTRFS_FS_STATE_DEV_REPLACING 3
359 120
360/* Super block flags */
361/* Errors detected */
362#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
363
364#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
365#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
366
367#define BTRFS_BACKREF_REV_MAX 256 121#define BTRFS_BACKREF_REV_MAX 256
368#define BTRFS_BACKREF_REV_SHIFT 56 122#define BTRFS_BACKREF_REV_SHIFT 56
369#define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \ 123#define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
@@ -410,7 +164,6 @@ struct btrfs_header {
410 * room to translate 14 chunks with 3 stripes each. 164 * room to translate 14 chunks with 3 stripes each.
411 */ 165 */
412#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 166#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
413#define BTRFS_LABEL_SIZE 256
414 167
415/* 168/*
416 * just in case we somehow lose the roots and are not able to mount, 169 * just in case we somehow lose the roots and are not able to mount,
@@ -507,31 +260,6 @@ struct btrfs_super_block {
507 * Compat flags that we support. If any incompat flags are set other than the 260 * Compat flags that we support. If any incompat flags are set other than the
508 * ones specified below then we will fail to mount 261 * ones specified below then we will fail to mount
509 */ 262 */
510#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
511
512#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
513#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
514#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
515#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
516/*
517 * some patches floated around with a second compression method
518 * lets save that incompat here for when they do get in
519 * Note we don't actually support it, we're just reserving the
520 * number
521 */
522#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2 (1ULL << 4)
523
524/*
525 * older kernels tried to do bigger metadata blocks, but the
526 * code was pretty buggy. Lets not let them try anymore.
527 */
528#define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
529
530#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
531#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
532#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
533#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
534
535#define BTRFS_FEATURE_COMPAT_SUPP 0ULL 263#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
536#define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL 264#define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL
537#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL 265#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL
@@ -624,357 +352,8 @@ struct btrfs_path {
624 unsigned int need_commit_sem:1; 352 unsigned int need_commit_sem:1;
625 unsigned int skip_release_on_error:1; 353 unsigned int skip_release_on_error:1;
626}; 354};
627
628/*
629 * items in the extent btree are used to record the objectid of the
630 * owner of the block and the number of references
631 */
632
633struct btrfs_extent_item {
634 __le64 refs;
635 __le64 generation;
636 __le64 flags;
637} __attribute__ ((__packed__));
638
639struct btrfs_extent_item_v0 {
640 __le32 refs;
641} __attribute__ ((__packed__));
642
643#define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \ 355#define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \
644 sizeof(struct btrfs_item)) 356 sizeof(struct btrfs_item))
645
646#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
647#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
648
649/* following flags only apply to tree blocks */
650
651/* use full backrefs for extent pointers in the block */
652#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
653
654/*
655 * this flag is only used internally by scrub and may be changed at any time
656 * it is only declared here to avoid collisions
657 */
658#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
659
660struct btrfs_tree_block_info {
661 struct btrfs_disk_key key;
662 u8 level;
663} __attribute__ ((__packed__));
664
665struct btrfs_extent_data_ref {
666 __le64 root;
667 __le64 objectid;
668 __le64 offset;
669 __le32 count;
670} __attribute__ ((__packed__));
671
672struct btrfs_shared_data_ref {
673 __le32 count;
674} __attribute__ ((__packed__));
675
676struct btrfs_extent_inline_ref {
677 u8 type;
678 __le64 offset;
679} __attribute__ ((__packed__));
680
681/* old style backrefs item */
682struct btrfs_extent_ref_v0 {
683 __le64 root;
684 __le64 generation;
685 __le64 objectid;
686 __le32 count;
687} __attribute__ ((__packed__));
688
689
690/* dev extents record free space on individual devices. The owner
691 * field points back to the chunk allocation mapping tree that allocated
692 * the extent. The chunk tree uuid field is a way to double check the owner
693 */
694struct btrfs_dev_extent {
695 __le64 chunk_tree;
696 __le64 chunk_objectid;
697 __le64 chunk_offset;
698 __le64 length;
699 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
700} __attribute__ ((__packed__));
701
702struct btrfs_inode_ref {
703 __le64 index;
704 __le16 name_len;
705 /* name goes here */
706} __attribute__ ((__packed__));
707
708struct btrfs_inode_extref {
709 __le64 parent_objectid;
710 __le64 index;
711 __le16 name_len;
712 __u8 name[0];
713 /* name goes here */
714} __attribute__ ((__packed__));
715
716struct btrfs_timespec {
717 __le64 sec;
718 __le32 nsec;
719} __attribute__ ((__packed__));
720
721struct btrfs_inode_item {
722 /* nfs style generation number */
723 __le64 generation;
724 /* transid that last touched this inode */
725 __le64 transid;
726 __le64 size;
727 __le64 nbytes;
728 __le64 block_group;
729 __le32 nlink;
730 __le32 uid;
731 __le32 gid;
732 __le32 mode;
733 __le64 rdev;
734 __le64 flags;
735
736 /* modification sequence number for NFS */
737 __le64 sequence;
738
739 /*
740 * a little future expansion, for more than this we can
741 * just grow the inode item and version it
742 */
743 __le64 reserved[4];
744 struct btrfs_timespec atime;
745 struct btrfs_timespec ctime;
746 struct btrfs_timespec mtime;
747 struct btrfs_timespec otime;
748} __attribute__ ((__packed__));
749
750struct btrfs_dir_log_item {
751 __le64 end;
752} __attribute__ ((__packed__));
753
754struct btrfs_dir_item {
755 struct btrfs_disk_key location;
756 __le64 transid;
757 __le16 data_len;
758 __le16 name_len;
759 u8 type;
760} __attribute__ ((__packed__));
761
762#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
763
764/*
765 * Internal in-memory flag that a subvolume has been marked for deletion but
766 * still visible as a directory
767 */
768#define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
769
770struct btrfs_root_item {
771 struct btrfs_inode_item inode;
772 __le64 generation;
773 __le64 root_dirid;
774 __le64 bytenr;
775 __le64 byte_limit;
776 __le64 bytes_used;
777 __le64 last_snapshot;
778 __le64 flags;
779 __le32 refs;
780 struct btrfs_disk_key drop_progress;
781 u8 drop_level;
782 u8 level;
783
784 /*
785 * The following fields appear after subvol_uuids+subvol_times
786 * were introduced.
787 */
788
789 /*
790 * This generation number is used to test if the new fields are valid
791 * and up to date while reading the root item. Every time the root item
792 * is written out, the "generation" field is copied into this field. If
793 * anyone ever mounted the fs with an older kernel, we will have
794 * mismatching generation values here and thus must invalidate the
795 * new fields. See btrfs_update_root and btrfs_find_last_root for
796 * details.
797 * the offset of generation_v2 is also used as the start for the memset
798 * when invalidating the fields.
799 */
800 __le64 generation_v2;
801 u8 uuid[BTRFS_UUID_SIZE];
802 u8 parent_uuid[BTRFS_UUID_SIZE];
803 u8 received_uuid[BTRFS_UUID_SIZE];
804 __le64 ctransid; /* updated when an inode changes */
805 __le64 otransid; /* trans when created */
806 __le64 stransid; /* trans when sent. non-zero for received subvol */
807 __le64 rtransid; /* trans when received. non-zero for received subvol */
808 struct btrfs_timespec ctime;
809 struct btrfs_timespec otime;
810 struct btrfs_timespec stime;
811 struct btrfs_timespec rtime;
812 __le64 reserved[8]; /* for future */
813} __attribute__ ((__packed__));
814
815/*
816 * this is used for both forward and backward root refs
817 */
818struct btrfs_root_ref {
819 __le64 dirid;
820 __le64 sequence;
821 __le16 name_len;
822} __attribute__ ((__packed__));
823
824struct btrfs_disk_balance_args {
825 /*
826 * profiles to operate on, single is denoted by
827 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
828 */
829 __le64 profiles;
830
831 /*
832 * usage filter
833 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
834 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
835 */
836 union {
837 __le64 usage;
838 struct {
839 __le32 usage_min;
840 __le32 usage_max;
841 };
842 };
843
844 /* devid filter */
845 __le64 devid;
846
847 /* devid subset filter [pstart..pend) */
848 __le64 pstart;
849 __le64 pend;
850
851 /* btrfs virtual address space subset filter [vstart..vend) */
852 __le64 vstart;
853 __le64 vend;
854
855 /*
856 * profile to convert to, single is denoted by
857 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
858 */
859 __le64 target;
860
861 /* BTRFS_BALANCE_ARGS_* */
862 __le64 flags;
863
864 /*
865 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
866 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
867 * and maximum
868 */
869 union {
870 __le64 limit;
871 struct {
872 __le32 limit_min;
873 __le32 limit_max;
874 };
875 };
876
877 /*
878 * Process chunks that cross stripes_min..stripes_max devices,
879 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
880 */
881 __le32 stripes_min;
882 __le32 stripes_max;
883
884 __le64 unused[6];
885} __attribute__ ((__packed__));
886
887/*
888 * store balance parameters to disk so that balance can be properly
889 * resumed after crash or unmount
890 */
891struct btrfs_balance_item {
892 /* BTRFS_BALANCE_* */
893 __le64 flags;
894
895 struct btrfs_disk_balance_args data;
896 struct btrfs_disk_balance_args meta;
897 struct btrfs_disk_balance_args sys;
898
899 __le64 unused[4];
900} __attribute__ ((__packed__));
901
902#define BTRFS_FILE_EXTENT_INLINE 0
903#define BTRFS_FILE_EXTENT_REG 1
904#define BTRFS_FILE_EXTENT_PREALLOC 2
905
906struct btrfs_file_extent_item {
907 /*
908 * transaction id that created this extent
909 */
910 __le64 generation;
911 /*
912 * max number of bytes to hold this extent in ram
913 * when we split a compressed extent we can't know how big
914 * each of the resulting pieces will be. So, this is
915 * an upper limit on the size of the extent in ram instead of
916 * an exact limit.
917 */
918 __le64 ram_bytes;
919
920 /*
921 * 32 bits for the various ways we might encode the data,
922 * including compression and encryption. If any of these
923 * are set to something a given disk format doesn't understand
924 * it is treated like an incompat flag for reading and writing,
925 * but not for stat.
926 */
927 u8 compression;
928 u8 encryption;
929 __le16 other_encoding; /* spare for later use */
930
931 /* are we inline data or a real extent? */
932 u8 type;
933
934 /*
935 * disk space consumed by the extent, checksum blocks are included
936 * in these numbers
937 *
938 * At this offset in the structure, the inline extent data start.
939 */
940 __le64 disk_bytenr;
941 __le64 disk_num_bytes;
942 /*
943 * the logical offset in file blocks (no csums)
944 * this extent record is for. This allows a file extent to point
945 * into the middle of an existing extent on disk, sharing it
946 * between two snapshots (useful if some bytes in the middle of the
947 * extent have changed
948 */
949 __le64 offset;
950 /*
951 * the logical number of file blocks (no csums included). This
952 * always reflects the size uncompressed and without encoding.
953 */
954 __le64 num_bytes;
955
956} __attribute__ ((__packed__));
957
958struct btrfs_csum_item {
959 u8 csum;
960} __attribute__ ((__packed__));
961
962struct btrfs_dev_stats_item {
963 /*
964 * grow this item struct at the end for future enhancements and keep
965 * the existing values unchanged
966 */
967 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
968} __attribute__ ((__packed__));
969
970#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
971#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
972#define BTRFS_DEV_REPLACE_ITEM_STATE_NEVER_STARTED 0
973#define BTRFS_DEV_REPLACE_ITEM_STATE_STARTED 1
974#define BTRFS_DEV_REPLACE_ITEM_STATE_SUSPENDED 2
975#define BTRFS_DEV_REPLACE_ITEM_STATE_FINISHED 3
976#define BTRFS_DEV_REPLACE_ITEM_STATE_CANCELED 4
977
978struct btrfs_dev_replace { 357struct btrfs_dev_replace {
979 u64 replace_state; /* see #define above */ 358 u64 replace_state; /* see #define above */
980 u64 time_started; /* seconds since 1-Jan-1970 */ 359 u64 time_started; /* seconds since 1-Jan-1970 */
@@ -1005,175 +384,6 @@ struct btrfs_dev_replace {
1005 struct btrfs_scrub_progress scrub_progress; 384 struct btrfs_scrub_progress scrub_progress;
1006}; 385};
1007 386
1008struct btrfs_dev_replace_item {
1009 /*
1010 * grow this item struct at the end for future enhancements and keep
1011 * the existing values unchanged
1012 */
1013 __le64 src_devid;
1014 __le64 cursor_left;
1015 __le64 cursor_right;
1016 __le64 cont_reading_from_srcdev_mode;
1017
1018 __le64 replace_state;
1019 __le64 time_started;
1020 __le64 time_stopped;
1021 __le64 num_write_errors;
1022 __le64 num_uncorrectable_read_errors;
1023} __attribute__ ((__packed__));
1024
1025/* different types of block groups (and chunks) */
1026#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
1027#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
1028#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
1029#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
1030#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
1031#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
1032#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
1033#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
1034#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
1035#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
1036 BTRFS_SPACE_INFO_GLOBAL_RSV)
1037
1038enum btrfs_raid_types {
1039 BTRFS_RAID_RAID10,
1040 BTRFS_RAID_RAID1,
1041 BTRFS_RAID_DUP,
1042 BTRFS_RAID_RAID0,
1043 BTRFS_RAID_SINGLE,
1044 BTRFS_RAID_RAID5,
1045 BTRFS_RAID_RAID6,
1046 BTRFS_NR_RAID_TYPES
1047};
1048
1049#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
1050 BTRFS_BLOCK_GROUP_SYSTEM | \
1051 BTRFS_BLOCK_GROUP_METADATA)
1052
1053#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
1054 BTRFS_BLOCK_GROUP_RAID1 | \
1055 BTRFS_BLOCK_GROUP_RAID5 | \
1056 BTRFS_BLOCK_GROUP_RAID6 | \
1057 BTRFS_BLOCK_GROUP_DUP | \
1058 BTRFS_BLOCK_GROUP_RAID10)
1059#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
1060 BTRFS_BLOCK_GROUP_RAID6)
1061
1062/*
1063 * We need a bit for restriper to be able to tell when chunks of type
1064 * SINGLE are available. This "extended" profile format is used in
1065 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
1066 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
1067 * to avoid remappings between two formats in future.
1068 */
1069#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
1070
1071/*
1072 * A fake block group type that is used to communicate global block reserve
1073 * size to userspace via the SPACE_INFO ioctl.
1074 */
1075#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
1076
1077#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
1078 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
1079
1080static inline u64 chunk_to_extended(u64 flags)
1081{
1082 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1083 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1084
1085 return flags;
1086}
1087static inline u64 extended_to_chunk(u64 flags)
1088{
1089 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1090}
1091
1092struct btrfs_block_group_item {
1093 __le64 used;
1094 __le64 chunk_objectid;
1095 __le64 flags;
1096} __attribute__ ((__packed__));
1097
1098struct btrfs_free_space_info {
1099 __le32 extent_count;
1100 __le32 flags;
1101} __attribute__ ((__packed__));
1102
1103#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1104
1105#define BTRFS_QGROUP_LEVEL_SHIFT 48
1106static inline u64 btrfs_qgroup_level(u64 qgroupid)
1107{
1108 return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
1109}
1110
1111/*
1112 * is subvolume quota turned on?
1113 */
1114#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1115/*
1116 * RESCAN is set during the initialization phase
1117 */
1118#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1119/*
1120 * Some qgroup entries are known to be out of date,
1121 * either because the configuration has changed in a way that
1122 * makes a rescan necessary, or because the fs has been mounted
1123 * with a non-qgroup-aware version.
1124 * Turning qouta off and on again makes it inconsistent, too.
1125 */
1126#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1127
1128#define BTRFS_QGROUP_STATUS_VERSION 1
1129
1130struct btrfs_qgroup_status_item {
1131 __le64 version;
1132 /*
1133 * the generation is updated during every commit. As older
1134 * versions of btrfs are not aware of qgroups, it will be
1135 * possible to detect inconsistencies by checking the
1136 * generation on mount time
1137 */
1138 __le64 generation;
1139
1140 /* flag definitions see above */
1141 __le64 flags;
1142
1143 /*
1144 * only used during scanning to record the progress
1145 * of the scan. It contains a logical address
1146 */
1147 __le64 rescan;
1148} __attribute__ ((__packed__));
1149
1150struct btrfs_qgroup_info_item {
1151 __le64 generation;
1152 __le64 rfer;
1153 __le64 rfer_cmpr;
1154 __le64 excl;
1155 __le64 excl_cmpr;
1156} __attribute__ ((__packed__));
1157
1158/* flags definition for qgroup limits */
1159#define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
1160#define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
1161#define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
1162#define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
1163#define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
1164#define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
1165
1166struct btrfs_qgroup_limit_item {
1167 /*
1168 * only updated when any of the other values change
1169 */
1170 __le64 flags;
1171 __le64 max_rfer;
1172 __le64 max_excl;
1173 __le64 rsv_rfer;
1174 __le64 rsv_excl;
1175} __attribute__ ((__packed__));
1176
1177/* For raid type sysfs entries */ 387/* For raid type sysfs entries */
1178struct raid_kobject { 388struct raid_kobject {
1179 int raid_type; 389 int raid_type;
@@ -2026,228 +1236,6 @@ struct btrfs_root {
2026 atomic_t qgroup_meta_rsv; 1236 atomic_t qgroup_meta_rsv;
2027}; 1237};
2028 1238
2029struct btrfs_ioctl_defrag_range_args {
2030 /* start of the defrag operation */
2031 __u64 start;
2032
2033 /* number of bytes to defrag, use (u64)-1 to say all */
2034 __u64 len;
2035
2036 /*
2037 * flags for the operation, which can include turning
2038 * on compression for this one defrag
2039 */
2040 __u64 flags;
2041
2042 /*
2043 * any extent bigger than this will be considered
2044 * already defragged. Use 0 to take the kernel default
2045 * Use 1 to say every single extent must be rewritten
2046 */
2047 __u32 extent_thresh;
2048
2049 /*
2050 * which compression method to use if turning on compression
2051 * for this defrag operation. If unspecified, zlib will
2052 * be used
2053 */
2054 __u32 compress_type;
2055
2056 /* spare for later */
2057 __u32 unused[4];
2058};
2059
2060
2061/*
2062 * inode items have the data typically returned from stat and store other
2063 * info about object characteristics. There is one for every file and dir in
2064 * the FS
2065 */
2066#define BTRFS_INODE_ITEM_KEY 1
2067#define BTRFS_INODE_REF_KEY 12
2068#define BTRFS_INODE_EXTREF_KEY 13
2069#define BTRFS_XATTR_ITEM_KEY 24
2070#define BTRFS_ORPHAN_ITEM_KEY 48
2071/* reserve 2-15 close to the inode for later flexibility */
2072
2073/*
2074 * dir items are the name -> inode pointers in a directory. There is one
2075 * for every name in a directory.
2076 */
2077#define BTRFS_DIR_LOG_ITEM_KEY 60
2078#define BTRFS_DIR_LOG_INDEX_KEY 72
2079#define BTRFS_DIR_ITEM_KEY 84
2080#define BTRFS_DIR_INDEX_KEY 96
2081/*
2082 * extent data is for file data
2083 */
2084#define BTRFS_EXTENT_DATA_KEY 108
2085
2086/*
2087 * extent csums are stored in a separate tree and hold csums for
2088 * an entire extent on disk.
2089 */
2090#define BTRFS_EXTENT_CSUM_KEY 128
2091
2092/*
2093 * root items point to tree roots. They are typically in the root
2094 * tree used by the super block to find all the other trees
2095 */
2096#define BTRFS_ROOT_ITEM_KEY 132
2097
2098/*
2099 * root backrefs tie subvols and snapshots to the directory entries that
2100 * reference them
2101 */
2102#define BTRFS_ROOT_BACKREF_KEY 144
2103
2104/*
2105 * root refs make a fast index for listing all of the snapshots and
2106 * subvolumes referenced by a given root. They point directly to the
2107 * directory item in the root that references the subvol
2108 */
2109#define BTRFS_ROOT_REF_KEY 156
2110
2111/*
2112 * extent items are in the extent map tree. These record which blocks
2113 * are used, and how many references there are to each block
2114 */
2115#define BTRFS_EXTENT_ITEM_KEY 168
2116
2117/*
2118 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
2119 * the length, so we save the level in key->offset instead of the length.
2120 */
2121#define BTRFS_METADATA_ITEM_KEY 169
2122
2123#define BTRFS_TREE_BLOCK_REF_KEY 176
2124
2125#define BTRFS_EXTENT_DATA_REF_KEY 178
2126
2127#define BTRFS_EXTENT_REF_V0_KEY 180
2128
2129#define BTRFS_SHARED_BLOCK_REF_KEY 182
2130
2131#define BTRFS_SHARED_DATA_REF_KEY 184
2132
2133/*
2134 * block groups give us hints into the extent allocation trees. Which
2135 * blocks are free etc etc
2136 */
2137#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
2138
2139/*
2140 * Every block group is represented in the free space tree by a free space info
2141 * item, which stores some accounting information. It is keyed on
2142 * (block_group_start, FREE_SPACE_INFO, block_group_length).
2143 */
2144#define BTRFS_FREE_SPACE_INFO_KEY 198
2145
2146/*
2147 * A free space extent tracks an extent of space that is free in a block group.
2148 * It is keyed on (start, FREE_SPACE_EXTENT, length).
2149 */
2150#define BTRFS_FREE_SPACE_EXTENT_KEY 199
2151
2152/*
2153 * When a block group becomes very fragmented, we convert it to use bitmaps
2154 * instead of extents. A free space bitmap is keyed on
2155 * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
2156 * (length / sectorsize) bits.
2157 */
2158#define BTRFS_FREE_SPACE_BITMAP_KEY 200
2159
2160#define BTRFS_DEV_EXTENT_KEY 204
2161#define BTRFS_DEV_ITEM_KEY 216
2162#define BTRFS_CHUNK_ITEM_KEY 228
2163
2164/*
2165 * Records the overall state of the qgroups.
2166 * There's only one instance of this key present,
2167 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
2168 */
2169#define BTRFS_QGROUP_STATUS_KEY 240
2170/*
2171 * Records the currently used space of the qgroup.
2172 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
2173 */
2174#define BTRFS_QGROUP_INFO_KEY 242
2175/*
2176 * Contains the user configured limits for the qgroup.
2177 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
2178 */
2179#define BTRFS_QGROUP_LIMIT_KEY 244
2180/*
2181 * Records the child-parent relationship of qgroups. For
2182 * each relation, 2 keys are present:
2183 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
2184 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
2185 */
2186#define BTRFS_QGROUP_RELATION_KEY 246
2187
2188/*
2189 * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
2190 */
2191#define BTRFS_BALANCE_ITEM_KEY 248
2192
2193/*
2194 * The key type for tree items that are stored persistently, but do not need to
2195 * exist for extended period of time. The items can exist in any tree.
2196 *
2197 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
2198 *
2199 * Existing items:
2200 *
2201 * - balance status item
2202 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
2203 */
2204#define BTRFS_TEMPORARY_ITEM_KEY 248
2205
2206/*
2207 * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
2208 */
2209#define BTRFS_DEV_STATS_KEY 249
2210
2211/*
2212 * The key type for tree items that are stored persistently and usually exist
2213 * for a long period, eg. filesystem lifetime. The item kinds can be status
2214 * information, stats or preference values. The item can exist in any tree.
2215 *
2216 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
2217 *
2218 * Existing items:
2219 *
2220 * - device statistics, store IO stats in the device tree, one key for all
2221 * stats
2222 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
2223 */
2224#define BTRFS_PERSISTENT_ITEM_KEY 249
2225
2226/*
2227 * Persistantly stores the device replace state in the device tree.
2228 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
2229 */
2230#define BTRFS_DEV_REPLACE_KEY 250
2231
2232/*
2233 * Stores items that allow to quickly map UUIDs to something else.
2234 * These items are part of the filesystem UUID tree.
2235 * The key is built like this:
2236 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
2237 */
2238#if BTRFS_UUID_SIZE != 16
2239#error "UUID items require BTRFS_UUID_SIZE == 16!"
2240#endif
2241#define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
2242#define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
2243 * received subvols */
2244
2245/*
2246 * string items are for debugging. They just store a short string of
2247 * data in the FS
2248 */
2249#define BTRFS_STRING_ITEM_KEY 253
2250
2251/* 1239/*
2252 * Flags for mount options. 1240 * Flags for mount options.
2253 * 1241 *
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 19f6bb861640..0ac90f8d85bd 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -357,52 +357,6 @@ struct map_lookup {
357#define map_lookup_size(n) (sizeof(struct map_lookup) + \ 357#define map_lookup_size(n) (sizeof(struct map_lookup) + \
358 (sizeof(struct btrfs_bio_stripe) * (n))) 358 (sizeof(struct btrfs_bio_stripe) * (n)))
359 359
360/*
361 * Restriper's general type filter
362 */
363#define BTRFS_BALANCE_DATA (1ULL << 0)
364#define BTRFS_BALANCE_SYSTEM (1ULL << 1)
365#define BTRFS_BALANCE_METADATA (1ULL << 2)
366
367#define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \
368 BTRFS_BALANCE_SYSTEM | \
369 BTRFS_BALANCE_METADATA)
370
371#define BTRFS_BALANCE_FORCE (1ULL << 3)
372#define BTRFS_BALANCE_RESUME (1ULL << 4)
373
374/*
375 * Balance filters
376 */
377#define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0)
378#define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1)
379#define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2)
380#define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3)
381#define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4)
382#define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5)
383#define BTRFS_BALANCE_ARGS_LIMIT_RANGE (1ULL << 6)
384#define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
385#define BTRFS_BALANCE_ARGS_USAGE_RANGE (1ULL << 10)
386
387#define BTRFS_BALANCE_ARGS_MASK \
388 (BTRFS_BALANCE_ARGS_PROFILES | \
389 BTRFS_BALANCE_ARGS_USAGE | \
390 BTRFS_BALANCE_ARGS_DEVID | \
391 BTRFS_BALANCE_ARGS_DRANGE | \
392 BTRFS_BALANCE_ARGS_VRANGE | \
393 BTRFS_BALANCE_ARGS_LIMIT | \
394 BTRFS_BALANCE_ARGS_LIMIT_RANGE | \
395 BTRFS_BALANCE_ARGS_STRIPES_RANGE | \
396 BTRFS_BALANCE_ARGS_USAGE_RANGE)
397
398/*
399 * Profile changing flags. When SOFT is set we won't relocate chunk if
400 * it already has the target profile (even though it may be
401 * half-filled).
402 */
403#define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8)
404#define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9)
405
406struct btrfs_balance_args; 360struct btrfs_balance_args;
407struct btrfs_balance_progress; 361struct btrfs_balance_progress;
408struct btrfs_balance_control { 362struct btrfs_balance_control {
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 3975e683af72..23c6960e94a4 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -23,6 +23,7 @@
23 23
24#define BTRFS_IOCTL_MAGIC 0x94 24#define BTRFS_IOCTL_MAGIC 0x94
25#define BTRFS_VOL_NAME_MAX 255 25#define BTRFS_VOL_NAME_MAX 255
26#define BTRFS_LABEL_SIZE 256
26 27
27/* this should be 4k */ 28/* this should be 4k */
28#define BTRFS_PATH_NAME_MAX 4087 29#define BTRFS_PATH_NAME_MAX 4087
@@ -33,9 +34,6 @@ struct btrfs_ioctl_vol_args {
33 34
34#define BTRFS_DEVICE_PATH_NAME_MAX 1024 35#define BTRFS_DEVICE_PATH_NAME_MAX 1024
35 36
36#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
37#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
38#define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
39#define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3) 37#define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
40 38
41#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \ 39#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
@@ -48,7 +46,19 @@ struct btrfs_ioctl_vol_args {
48#define BTRFS_UUID_SIZE 16 46#define BTRFS_UUID_SIZE 16
49#define BTRFS_UUID_UNPARSED_SIZE 37 47#define BTRFS_UUID_UNPARSED_SIZE 37
50 48
51#define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0) 49/*
50 * flags definition for qgroup limits
51 *
52 * Used by:
53 * struct btrfs_qgroup_limit.flags
54 * struct btrfs_qgroup_limit_item.flags
55 */
56#define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
57#define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
58#define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
59#define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
60#define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
61#define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
52 62
53struct btrfs_qgroup_limit { 63struct btrfs_qgroup_limit {
54 __u64 flags; 64 __u64 flags;
@@ -58,6 +68,14 @@ struct btrfs_qgroup_limit {
58 __u64 rsv_excl; 68 __u64 rsv_excl;
59}; 69};
60 70
71/*
72 * flags definition for qgroup inheritance
73 *
74 * Used by:
75 * struct btrfs_qgroup_inherit.flags
76 */
77#define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
78
61struct btrfs_qgroup_inherit { 79struct btrfs_qgroup_inherit {
62 __u64 flags; 80 __u64 flags;
63 __u64 num_qgroups; 81 __u64 num_qgroups;
@@ -72,6 +90,20 @@ struct btrfs_ioctl_qgroup_limit_args {
72 struct btrfs_qgroup_limit lim; 90 struct btrfs_qgroup_limit lim;
73}; 91};
74 92
93/*
94 * flags for subvolumes
95 *
96 * Used by:
97 * struct btrfs_ioctl_vol_args_v2.flags
98 *
99 * BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls:
100 * - BTRFS_IOC_SUBVOL_GETFLAGS
101 * - BTRFS_IOC_SUBVOL_SETFLAGS
102 */
103#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
104#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
105#define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
106
75#define BTRFS_SUBVOL_NAME_MAX 4039 107#define BTRFS_SUBVOL_NAME_MAX 4039
76struct btrfs_ioctl_vol_args_v2 { 108struct btrfs_ioctl_vol_args_v2 {
77 __s64 fd; 109 __s64 fd;
@@ -201,6 +233,37 @@ struct btrfs_ioctl_fs_info_args {
201 __u64 reserved[122]; /* pad to 1k */ 233 __u64 reserved[122]; /* pad to 1k */
202}; 234};
203 235
236/*
237 * feature flags
238 *
239 * Used by:
240 * struct btrfs_ioctl_feature_flags
241 */
242#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
243
244#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
245#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
246#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
247#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
248/*
249 * some patches floated around with a second compression method
250 * lets save that incompat here for when they do get in
251 * Note we don't actually support it, we're just reserving the
252 * number
253 */
254#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2 (1ULL << 4)
255
256/*
257 * older kernels tried to do bigger metadata blocks, but the
258 * code was pretty buggy. Lets not let them try anymore.
259 */
260#define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
261
262#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
263#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
264#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
265#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
266
204struct btrfs_ioctl_feature_flags { 267struct btrfs_ioctl_feature_flags {
205 __u64 compat_flags; 268 __u64 compat_flags;
206 __u64 compat_ro_flags; 269 __u64 compat_ro_flags;
@@ -265,6 +328,70 @@ struct btrfs_balance_progress {
265 __u64 completed; /* # of chunks relocated so far */ 328 __u64 completed; /* # of chunks relocated so far */
266}; 329};
267 330
331/*
332 * flags definition for balance
333 *
334 * Restriper's general type filter
335 *
336 * Used by:
337 * btrfs_ioctl_balance_args.flags
338 * btrfs_balance_control.flags (internal)
339 */
340#define BTRFS_BALANCE_DATA (1ULL << 0)
341#define BTRFS_BALANCE_SYSTEM (1ULL << 1)
342#define BTRFS_BALANCE_METADATA (1ULL << 2)
343
344#define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \
345 BTRFS_BALANCE_SYSTEM | \
346 BTRFS_BALANCE_METADATA)
347
348#define BTRFS_BALANCE_FORCE (1ULL << 3)
349#define BTRFS_BALANCE_RESUME (1ULL << 4)
350
351/*
352 * flags definitions for per-type balance args
353 *
354 * Balance filters
355 *
356 * Used by:
357 * struct btrfs_balance_args
358 */
359#define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0)
360#define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1)
361#define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2)
362#define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3)
363#define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4)
364#define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5)
365#define BTRFS_BALANCE_ARGS_LIMIT_RANGE (1ULL << 6)
366#define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
367#define BTRFS_BALANCE_ARGS_USAGE_RANGE (1ULL << 10)
368
369#define BTRFS_BALANCE_ARGS_MASK \
370 (BTRFS_BALANCE_ARGS_PROFILES | \
371 BTRFS_BALANCE_ARGS_USAGE | \
372 BTRFS_BALANCE_ARGS_DEVID | \
373 BTRFS_BALANCE_ARGS_DRANGE | \
374 BTRFS_BALANCE_ARGS_VRANGE | \
375 BTRFS_BALANCE_ARGS_LIMIT | \
376 BTRFS_BALANCE_ARGS_LIMIT_RANGE | \
377 BTRFS_BALANCE_ARGS_STRIPES_RANGE | \
378 BTRFS_BALANCE_ARGS_USAGE_RANGE)
379
380/*
381 * Profile changing flags. When SOFT is set we won't relocate chunk if
382 * it already has the target profile (even though it may be
383 * half-filled).
384 */
385#define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8)
386#define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9)
387
388
389/*
390 * flags definition for balance state
391 *
392 * Used by:
393 * struct btrfs_ioctl_balance_args.state
394 */
268#define BTRFS_BALANCE_STATE_RUNNING (1ULL << 0) 395#define BTRFS_BALANCE_STATE_RUNNING (1ULL << 0)
269#define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1) 396#define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1)
270#define BTRFS_BALANCE_STATE_CANCEL_REQ (1ULL << 2) 397#define BTRFS_BALANCE_STATE_CANCEL_REQ (1ULL << 2)
@@ -358,9 +485,45 @@ struct btrfs_ioctl_clone_range_args {
358 __u64 dest_offset; 485 __u64 dest_offset;
359}; 486};
360 487
361/* flags for the defrag range ioctl */ 488/*
489 * flags definition for the defrag range ioctl
490 *
491 * Used by:
492 * struct btrfs_ioctl_defrag_range_args.flags
493 */
362#define BTRFS_DEFRAG_RANGE_COMPRESS 1 494#define BTRFS_DEFRAG_RANGE_COMPRESS 1
363#define BTRFS_DEFRAG_RANGE_START_IO 2 495#define BTRFS_DEFRAG_RANGE_START_IO 2
496struct btrfs_ioctl_defrag_range_args {
497 /* start of the defrag operation */
498 __u64 start;
499
500 /* number of bytes to defrag, use (u64)-1 to say all */
501 __u64 len;
502
503 /*
504 * flags for the operation, which can include turning
505 * on compression for this one defrag
506 */
507 __u64 flags;
508
509 /*
510 * any extent bigger than this will be considered
511 * already defragged. Use 0 to take the kernel default
512 * Use 1 to say every single extent must be rewritten
513 */
514 __u32 extent_thresh;
515
516 /*
517 * which compression method to use if turning on compression
518 * for this defrag operation. If unspecified, zlib will
519 * be used
520 */
521 __u32 compress_type;
522
523 /* spare for later */
524 __u32 unused[4];
525};
526
364 527
365#define BTRFS_SAME_DATA_DIFFERS 1 528#define BTRFS_SAME_DATA_DIFFERS 1
366/* For extent-same ioctl */ 529/* For extent-same ioctl */
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
new file mode 100644
index 000000000000..d5ad15a106a7
--- /dev/null
+++ b/include/uapi/linux/btrfs_tree.h
@@ -0,0 +1,966 @@
1#ifndef _BTRFS_CTREE_H_
2#define _BTRFS_CTREE_H_
3
4/*
5 * This header contains the structure definitions and constants used
6 * by file system objects that can be retrieved using
7 * the BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that
8 * is needed to describe a leaf node's key or item contents.
9 */
10
11/* holds pointers to all of the tree roots */
12#define BTRFS_ROOT_TREE_OBJECTID 1ULL
13
14/* stores information about which extents are in use, and reference counts */
15#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
16
17/*
18 * chunk tree stores translations from logical -> physical block numbering
19 * the super block points to the chunk tree
20 */
21#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
22
23/*
24 * stores information about which areas of a given device are in use.
25 * one per device. The tree of tree roots points to the device tree
26 */
27#define BTRFS_DEV_TREE_OBJECTID 4ULL
28
29/* one per subvolume, storing files and directories */
30#define BTRFS_FS_TREE_OBJECTID 5ULL
31
32/* directory objectid inside the root tree */
33#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
34
35/* holds checksums of all the data extents */
36#define BTRFS_CSUM_TREE_OBJECTID 7ULL
37
38/* holds quota configuration and tracking */
39#define BTRFS_QUOTA_TREE_OBJECTID 8ULL
40
41/* for storing items that use the BTRFS_UUID_KEY* types */
42#define BTRFS_UUID_TREE_OBJECTID 9ULL
43
44/* tracks free space in block groups. */
45#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
46
47/* device stats in the device tree */
48#define BTRFS_DEV_STATS_OBJECTID 0ULL
49
50/* for storing balance parameters in the root tree */
51#define BTRFS_BALANCE_OBJECTID -4ULL
52
53/* orhpan objectid for tracking unlinked/truncated files */
54#define BTRFS_ORPHAN_OBJECTID -5ULL
55
56/* does write ahead logging to speed up fsyncs */
57#define BTRFS_TREE_LOG_OBJECTID -6ULL
58#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
59
60/* for space balancing */
61#define BTRFS_TREE_RELOC_OBJECTID -8ULL
62#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
63
64/*
65 * extent checksums all have this objectid
66 * this allows them to share the logging tree
67 * for fsyncs
68 */
69#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
70
71/* For storing free space cache */
72#define BTRFS_FREE_SPACE_OBJECTID -11ULL
73
74/*
75 * The inode number assigned to the special inode for storing
76 * free ino cache
77 */
78#define BTRFS_FREE_INO_OBJECTID -12ULL
79
80/* dummy objectid represents multiple objectids */
81#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
82
83/*
84 * All files have objectids in this range.
85 */
86#define BTRFS_FIRST_FREE_OBJECTID 256ULL
87#define BTRFS_LAST_FREE_OBJECTID -256ULL
88#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
89
90
91/*
92 * the device items go into the chunk tree. The key is in the form
93 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
94 */
95#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
96
97#define BTRFS_BTREE_INODE_OBJECTID 1
98
99#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
100
101#define BTRFS_DEV_REPLACE_DEVID 0ULL
102
103/*
104 * inode items have the data typically returned from stat and store other
105 * info about object characteristics. There is one for every file and dir in
106 * the FS
107 */
108#define BTRFS_INODE_ITEM_KEY 1
109#define BTRFS_INODE_REF_KEY 12
110#define BTRFS_INODE_EXTREF_KEY 13
111#define BTRFS_XATTR_ITEM_KEY 24
112#define BTRFS_ORPHAN_ITEM_KEY 48
113/* reserve 2-15 close to the inode for later flexibility */
114
115/*
116 * dir items are the name -> inode pointers in a directory. There is one
117 * for every name in a directory.
118 */
119#define BTRFS_DIR_LOG_ITEM_KEY 60
120#define BTRFS_DIR_LOG_INDEX_KEY 72
121#define BTRFS_DIR_ITEM_KEY 84
122#define BTRFS_DIR_INDEX_KEY 96
123/*
124 * extent data is for file data
125 */
126#define BTRFS_EXTENT_DATA_KEY 108
127
128/*
129 * extent csums are stored in a separate tree and hold csums for
130 * an entire extent on disk.
131 */
132#define BTRFS_EXTENT_CSUM_KEY 128
133
134/*
135 * root items point to tree roots. They are typically in the root
136 * tree used by the super block to find all the other trees
137 */
138#define BTRFS_ROOT_ITEM_KEY 132
139
140/*
141 * root backrefs tie subvols and snapshots to the directory entries that
142 * reference them
143 */
144#define BTRFS_ROOT_BACKREF_KEY 144
145
146/*
147 * root refs make a fast index for listing all of the snapshots and
148 * subvolumes referenced by a given root. They point directly to the
149 * directory item in the root that references the subvol
150 */
151#define BTRFS_ROOT_REF_KEY 156
152
153/*
154 * extent items are in the extent map tree. These record which blocks
155 * are used, and how many references there are to each block
156 */
157#define BTRFS_EXTENT_ITEM_KEY 168
158
159/*
160 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
161 * the length, so we save the level in key->offset instead of the length.
162 */
163#define BTRFS_METADATA_ITEM_KEY 169
164
165#define BTRFS_TREE_BLOCK_REF_KEY 176
166
167#define BTRFS_EXTENT_DATA_REF_KEY 178
168
169#define BTRFS_EXTENT_REF_V0_KEY 180
170
171#define BTRFS_SHARED_BLOCK_REF_KEY 182
172
173#define BTRFS_SHARED_DATA_REF_KEY 184
174
175/*
176 * block groups give us hints into the extent allocation trees. Which
177 * blocks are free etc etc
178 */
179#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
180
181/*
182 * Every block group is represented in the free space tree by a free space info
183 * item, which stores some accounting information. It is keyed on
184 * (block_group_start, FREE_SPACE_INFO, block_group_length).
185 */
186#define BTRFS_FREE_SPACE_INFO_KEY 198
187
188/*
189 * A free space extent tracks an extent of space that is free in a block group.
190 * It is keyed on (start, FREE_SPACE_EXTENT, length).
191 */
192#define BTRFS_FREE_SPACE_EXTENT_KEY 199
193
194/*
195 * When a block group becomes very fragmented, we convert it to use bitmaps
196 * instead of extents. A free space bitmap is keyed on
197 * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
198 * (length / sectorsize) bits.
199 */
200#define BTRFS_FREE_SPACE_BITMAP_KEY 200
201
202#define BTRFS_DEV_EXTENT_KEY 204
203#define BTRFS_DEV_ITEM_KEY 216
204#define BTRFS_CHUNK_ITEM_KEY 228
205
206/*
207 * Records the overall state of the qgroups.
208 * There's only one instance of this key present,
209 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
210 */
211#define BTRFS_QGROUP_STATUS_KEY 240
212/*
213 * Records the currently used space of the qgroup.
214 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
215 */
216#define BTRFS_QGROUP_INFO_KEY 242
217/*
218 * Contains the user configured limits for the qgroup.
219 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
220 */
221#define BTRFS_QGROUP_LIMIT_KEY 244
222/*
223 * Records the child-parent relationship of qgroups. For
224 * each relation, 2 keys are present:
225 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
226 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
227 */
228#define BTRFS_QGROUP_RELATION_KEY 246
229
230/*
231 * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
232 */
233#define BTRFS_BALANCE_ITEM_KEY 248
234
235/*
236 * The key type for tree items that are stored persistently, but do not need to
237 * exist for extended period of time. The items can exist in any tree.
238 *
239 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
240 *
241 * Existing items:
242 *
243 * - balance status item
244 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
245 */
246#define BTRFS_TEMPORARY_ITEM_KEY 248
247
248/*
249 * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
250 */
251#define BTRFS_DEV_STATS_KEY 249
252
253/*
254 * The key type for tree items that are stored persistently and usually exist
255 * for a long period, eg. filesystem lifetime. The item kinds can be status
256 * information, stats or preference values. The item can exist in any tree.
257 *
258 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
259 *
260 * Existing items:
261 *
262 * - device statistics, store IO stats in the device tree, one key for all
263 * stats
264 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
265 */
266#define BTRFS_PERSISTENT_ITEM_KEY 249
267
268/*
269 * Persistantly stores the device replace state in the device tree.
270 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
271 */
272#define BTRFS_DEV_REPLACE_KEY 250
273
274/*
275 * Stores items that allow to quickly map UUIDs to something else.
276 * These items are part of the filesystem UUID tree.
277 * The key is built like this:
278 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
279 */
280#if BTRFS_UUID_SIZE != 16
281#error "UUID items require BTRFS_UUID_SIZE == 16!"
282#endif
283#define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
284#define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
285 * received subvols */
286
287/*
288 * string items are for debugging. They just store a short string of
289 * data in the FS
290 */
291#define BTRFS_STRING_ITEM_KEY 253
292
293
294
295/* 32 bytes in various csum fields */
296#define BTRFS_CSUM_SIZE 32
297
298/* csum types */
299#define BTRFS_CSUM_TYPE_CRC32 0
300
301/*
302 * flags definitions for directory entry item type
303 *
304 * Used by:
305 * struct btrfs_dir_item.type
306 */
307#define BTRFS_FT_UNKNOWN 0
308#define BTRFS_FT_REG_FILE 1
309#define BTRFS_FT_DIR 2
310#define BTRFS_FT_CHRDEV 3
311#define BTRFS_FT_BLKDEV 4
312#define BTRFS_FT_FIFO 5
313#define BTRFS_FT_SOCK 6
314#define BTRFS_FT_SYMLINK 7
315#define BTRFS_FT_XATTR 8
316#define BTRFS_FT_MAX 9
317
318/*
319 * The key defines the order in the tree, and so it also defines (optimal)
320 * block layout.
321 *
322 * objectid corresponds to the inode number.
323 *
324 * type tells us things about the object, and is a kind of stream selector.
325 * so for a given inode, keys with type of 1 might refer to the inode data,
326 * type of 2 may point to file data in the btree and type == 3 may point to
327 * extents.
328 *
329 * offset is the starting byte offset for this key in the stream.
330 *
331 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
332 * in cpu native order. Otherwise they are identical and their sizes
333 * should be the same (ie both packed)
334 */
335struct btrfs_disk_key {
336 __le64 objectid;
337 __u8 type;
338 __le64 offset;
339} __attribute__ ((__packed__));
340
341struct btrfs_key {
342 __u64 objectid;
343 __u8 type;
344 __u64 offset;
345} __attribute__ ((__packed__));
346
347struct btrfs_dev_item {
348 /* the internal btrfs device id */
349 __le64 devid;
350
351 /* size of the device */
352 __le64 total_bytes;
353
354 /* bytes used */
355 __le64 bytes_used;
356
357 /* optimal io alignment for this device */
358 __le32 io_align;
359
360 /* optimal io width for this device */
361 __le32 io_width;
362
363 /* minimal io size for this device */
364 __le32 sector_size;
365
366 /* type and info about this device */
367 __le64 type;
368
369 /* expected generation for this device */
370 __le64 generation;
371
372 /*
373 * starting byte of this partition on the device,
374 * to allow for stripe alignment in the future
375 */
376 __le64 start_offset;
377
378 /* grouping information for allocation decisions */
379 __le32 dev_group;
380
381 /* seek speed 0-100 where 100 is fastest */
382 __u8 seek_speed;
383
384 /* bandwidth 0-100 where 100 is fastest */
385 __u8 bandwidth;
386
387 /* btrfs generated uuid for this device */
388 __u8 uuid[BTRFS_UUID_SIZE];
389
390 /* uuid of FS who owns this device */
391 __u8 fsid[BTRFS_UUID_SIZE];
392} __attribute__ ((__packed__));
393
394struct btrfs_stripe {
395 __le64 devid;
396 __le64 offset;
397 __u8 dev_uuid[BTRFS_UUID_SIZE];
398} __attribute__ ((__packed__));
399
400struct btrfs_chunk {
401 /* size of this chunk in bytes */
402 __le64 length;
403
404 /* objectid of the root referencing this chunk */
405 __le64 owner;
406
407 __le64 stripe_len;
408 __le64 type;
409
410 /* optimal io alignment for this chunk */
411 __le32 io_align;
412
413 /* optimal io width for this chunk */
414 __le32 io_width;
415
416 /* minimal io size for this chunk */
417 __le32 sector_size;
418
419 /* 2^16 stripes is quite a lot, a second limit is the size of a single
420 * item in the btree
421 */
422 __le16 num_stripes;
423
424 /* sub stripes only matter for raid10 */
425 __le16 sub_stripes;
426 struct btrfs_stripe stripe;
427 /* additional stripes go here */
428} __attribute__ ((__packed__));
429
430#define BTRFS_FREE_SPACE_EXTENT 1
431#define BTRFS_FREE_SPACE_BITMAP 2
432
433struct btrfs_free_space_entry {
434 __le64 offset;
435 __le64 bytes;
436 __u8 type;
437} __attribute__ ((__packed__));
438
439struct btrfs_free_space_header {
440 struct btrfs_disk_key location;
441 __le64 generation;
442 __le64 num_entries;
443 __le64 num_bitmaps;
444} __attribute__ ((__packed__));
445
446#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
447#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
448
449/* Super block flags */
450/* Errors detected */
451#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
452
453#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
454#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
455
456
457/*
458 * items in the extent btree are used to record the objectid of the
459 * owner of the block and the number of references
460 */
461
462struct btrfs_extent_item {
463 __le64 refs;
464 __le64 generation;
465 __le64 flags;
466} __attribute__ ((__packed__));
467
468struct btrfs_extent_item_v0 {
469 __le32 refs;
470} __attribute__ ((__packed__));
471
472
473#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
474#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
475
476/* following flags only apply to tree blocks */
477
478/* use full backrefs for extent pointers in the block */
479#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
480
481/*
482 * this flag is only used internally by scrub and may be changed at any time
483 * it is only declared here to avoid collisions
484 */
485#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
486
487struct btrfs_tree_block_info {
488 struct btrfs_disk_key key;
489 __u8 level;
490} __attribute__ ((__packed__));
491
492struct btrfs_extent_data_ref {
493 __le64 root;
494 __le64 objectid;
495 __le64 offset;
496 __le32 count;
497} __attribute__ ((__packed__));
498
499struct btrfs_shared_data_ref {
500 __le32 count;
501} __attribute__ ((__packed__));
502
503struct btrfs_extent_inline_ref {
504 __u8 type;
505 __le64 offset;
506} __attribute__ ((__packed__));
507
508/* old style backrefs item */
509struct btrfs_extent_ref_v0 {
510 __le64 root;
511 __le64 generation;
512 __le64 objectid;
513 __le32 count;
514} __attribute__ ((__packed__));
515
516
517/* dev extents record free space on individual devices. The owner
518 * field points back to the chunk allocation mapping tree that allocated
519 * the extent. The chunk tree uuid field is a way to double check the owner
520 */
521struct btrfs_dev_extent {
522 __le64 chunk_tree;
523 __le64 chunk_objectid;
524 __le64 chunk_offset;
525 __le64 length;
526 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
527} __attribute__ ((__packed__));
528
529struct btrfs_inode_ref {
530 __le64 index;
531 __le16 name_len;
532 /* name goes here */
533} __attribute__ ((__packed__));
534
535struct btrfs_inode_extref {
536 __le64 parent_objectid;
537 __le64 index;
538 __le16 name_len;
539 __u8 name[0];
540 /* name goes here */
541} __attribute__ ((__packed__));
542
543struct btrfs_timespec {
544 __le64 sec;
545 __le32 nsec;
546} __attribute__ ((__packed__));
547
548struct btrfs_inode_item {
549 /* nfs style generation number */
550 __le64 generation;
551 /* transid that last touched this inode */
552 __le64 transid;
553 __le64 size;
554 __le64 nbytes;
555 __le64 block_group;
556 __le32 nlink;
557 __le32 uid;
558 __le32 gid;
559 __le32 mode;
560 __le64 rdev;
561 __le64 flags;
562
563 /* modification sequence number for NFS */
564 __le64 sequence;
565
566 /*
567 * a little future expansion, for more than this we can
568 * just grow the inode item and version it
569 */
570 __le64 reserved[4];
571 struct btrfs_timespec atime;
572 struct btrfs_timespec ctime;
573 struct btrfs_timespec mtime;
574 struct btrfs_timespec otime;
575} __attribute__ ((__packed__));
576
577struct btrfs_dir_log_item {
578 __le64 end;
579} __attribute__ ((__packed__));
580
581struct btrfs_dir_item {
582 struct btrfs_disk_key location;
583 __le64 transid;
584 __le16 data_len;
585 __le16 name_len;
586 __u8 type;
587} __attribute__ ((__packed__));
588
589#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
590
591/*
592 * Internal in-memory flag that a subvolume has been marked for deletion but
593 * still visible as a directory
594 */
595#define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
596
597struct btrfs_root_item {
598 struct btrfs_inode_item inode;
599 __le64 generation;
600 __le64 root_dirid;
601 __le64 bytenr;
602 __le64 byte_limit;
603 __le64 bytes_used;
604 __le64 last_snapshot;
605 __le64 flags;
606 __le32 refs;
607 struct btrfs_disk_key drop_progress;
608 __u8 drop_level;
609 __u8 level;
610
611 /*
612 * The following fields appear after subvol_uuids+subvol_times
613 * were introduced.
614 */
615
616 /*
617 * This generation number is used to test if the new fields are valid
618 * and up to date while reading the root item. Every time the root item
619 * is written out, the "generation" field is copied into this field. If
620 * anyone ever mounted the fs with an older kernel, we will have
621 * mismatching generation values here and thus must invalidate the
622 * new fields. See btrfs_update_root and btrfs_find_last_root for
623 * details.
624 * the offset of generation_v2 is also used as the start for the memset
625 * when invalidating the fields.
626 */
627 __le64 generation_v2;
628 __u8 uuid[BTRFS_UUID_SIZE];
629 __u8 parent_uuid[BTRFS_UUID_SIZE];
630 __u8 received_uuid[BTRFS_UUID_SIZE];
631 __le64 ctransid; /* updated when an inode changes */
632 __le64 otransid; /* trans when created */
633 __le64 stransid; /* trans when sent. non-zero for received subvol */
634 __le64 rtransid; /* trans when received. non-zero for received subvol */
635 struct btrfs_timespec ctime;
636 struct btrfs_timespec otime;
637 struct btrfs_timespec stime;
638 struct btrfs_timespec rtime;
639 __le64 reserved[8]; /* for future */
640} __attribute__ ((__packed__));
641
642/*
643 * this is used for both forward and backward root refs
644 */
645struct btrfs_root_ref {
646 __le64 dirid;
647 __le64 sequence;
648 __le16 name_len;
649} __attribute__ ((__packed__));
650
651struct btrfs_disk_balance_args {
652 /*
653 * profiles to operate on, single is denoted by
654 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
655 */
656 __le64 profiles;
657
658 /*
659 * usage filter
660 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
661 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
662 */
663 union {
664 __le64 usage;
665 struct {
666 __le32 usage_min;
667 __le32 usage_max;
668 };
669 };
670
671 /* devid filter */
672 __le64 devid;
673
674 /* devid subset filter [pstart..pend) */
675 __le64 pstart;
676 __le64 pend;
677
678 /* btrfs virtual address space subset filter [vstart..vend) */
679 __le64 vstart;
680 __le64 vend;
681
682 /*
683 * profile to convert to, single is denoted by
684 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
685 */
686 __le64 target;
687
688 /* BTRFS_BALANCE_ARGS_* */
689 __le64 flags;
690
691 /*
692 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
693 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
694 * and maximum
695 */
696 union {
697 __le64 limit;
698 struct {
699 __le32 limit_min;
700 __le32 limit_max;
701 };
702 };
703
704 /*
705 * Process chunks that cross stripes_min..stripes_max devices,
706 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
707 */
708 __le32 stripes_min;
709 __le32 stripes_max;
710
711 __le64 unused[6];
712} __attribute__ ((__packed__));
713
714/*
715 * store balance parameters to disk so that balance can be properly
716 * resumed after crash or unmount
717 */
718struct btrfs_balance_item {
719 /* BTRFS_BALANCE_* */
720 __le64 flags;
721
722 struct btrfs_disk_balance_args data;
723 struct btrfs_disk_balance_args meta;
724 struct btrfs_disk_balance_args sys;
725
726 __le64 unused[4];
727} __attribute__ ((__packed__));
728
729#define BTRFS_FILE_EXTENT_INLINE 0
730#define BTRFS_FILE_EXTENT_REG 1
731#define BTRFS_FILE_EXTENT_PREALLOC 2
732
733struct btrfs_file_extent_item {
734 /*
735 * transaction id that created this extent
736 */
737 __le64 generation;
738 /*
739 * max number of bytes to hold this extent in ram
740 * when we split a compressed extent we can't know how big
741 * each of the resulting pieces will be. So, this is
742 * an upper limit on the size of the extent in ram instead of
743 * an exact limit.
744 */
745 __le64 ram_bytes;
746
747 /*
748 * 32 bits for the various ways we might encode the data,
749 * including compression and encryption. If any of these
750 * are set to something a given disk format doesn't understand
751 * it is treated like an incompat flag for reading and writing,
752 * but not for stat.
753 */
754 __u8 compression;
755 __u8 encryption;
756 __le16 other_encoding; /* spare for later use */
757
758 /* are we inline data or a real extent? */
759 __u8 type;
760
761 /*
762 * disk space consumed by the extent, checksum blocks are included
763 * in these numbers
764 *
765 * At this offset in the structure, the inline extent data start.
766 */
767 __le64 disk_bytenr;
768 __le64 disk_num_bytes;
769 /*
770 * the logical offset in file blocks (no csums)
771 * this extent record is for. This allows a file extent to point
772 * into the middle of an existing extent on disk, sharing it
773 * between two snapshots (useful if some bytes in the middle of the
774 * extent have changed
775 */
776 __le64 offset;
777 /*
778 * the logical number of file blocks (no csums included). This
779 * always reflects the size uncompressed and without encoding.
780 */
781 __le64 num_bytes;
782
783} __attribute__ ((__packed__));
784
785struct btrfs_csum_item {
786 __u8 csum;
787} __attribute__ ((__packed__));
788
789struct btrfs_dev_stats_item {
790 /*
791 * grow this item struct at the end for future enhancements and keep
792 * the existing values unchanged
793 */
794 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
795} __attribute__ ((__packed__));
796
797#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
798#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
799#define BTRFS_DEV_REPLACE_ITEM_STATE_NEVER_STARTED 0
800#define BTRFS_DEV_REPLACE_ITEM_STATE_STARTED 1
801#define BTRFS_DEV_REPLACE_ITEM_STATE_SUSPENDED 2
802#define BTRFS_DEV_REPLACE_ITEM_STATE_FINISHED 3
803#define BTRFS_DEV_REPLACE_ITEM_STATE_CANCELED 4
804
805struct btrfs_dev_replace_item {
806 /*
807 * grow this item struct at the end for future enhancements and keep
808 * the existing values unchanged
809 */
810 __le64 src_devid;
811 __le64 cursor_left;
812 __le64 cursor_right;
813 __le64 cont_reading_from_srcdev_mode;
814
815 __le64 replace_state;
816 __le64 time_started;
817 __le64 time_stopped;
818 __le64 num_write_errors;
819 __le64 num_uncorrectable_read_errors;
820} __attribute__ ((__packed__));
821
822/* different types of block groups (and chunks) */
823#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
824#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
825#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
826#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
827#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
828#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
829#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
830#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
831#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
832#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
833 BTRFS_SPACE_INFO_GLOBAL_RSV)
834
835enum btrfs_raid_types {
836 BTRFS_RAID_RAID10,
837 BTRFS_RAID_RAID1,
838 BTRFS_RAID_DUP,
839 BTRFS_RAID_RAID0,
840 BTRFS_RAID_SINGLE,
841 BTRFS_RAID_RAID5,
842 BTRFS_RAID_RAID6,
843 BTRFS_NR_RAID_TYPES
844};
845
846#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
847 BTRFS_BLOCK_GROUP_SYSTEM | \
848 BTRFS_BLOCK_GROUP_METADATA)
849
850#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
851 BTRFS_BLOCK_GROUP_RAID1 | \
852 BTRFS_BLOCK_GROUP_RAID5 | \
853 BTRFS_BLOCK_GROUP_RAID6 | \
854 BTRFS_BLOCK_GROUP_DUP | \
855 BTRFS_BLOCK_GROUP_RAID10)
856#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
857 BTRFS_BLOCK_GROUP_RAID6)
858
859/*
860 * We need a bit for restriper to be able to tell when chunks of type
861 * SINGLE are available. This "extended" profile format is used in
862 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
863 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
864 * to avoid remappings between two formats in future.
865 */
866#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
867
868/*
869 * A fake block group type that is used to communicate global block reserve
870 * size to userspace via the SPACE_INFO ioctl.
871 */
872#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
873
874#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
875 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
876
877static inline __u64 chunk_to_extended(__u64 flags)
878{
879 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
880 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
881
882 return flags;
883}
884static inline __u64 extended_to_chunk(__u64 flags)
885{
886 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
887}
888
889struct btrfs_block_group_item {
890 __le64 used;
891 __le64 chunk_objectid;
892 __le64 flags;
893} __attribute__ ((__packed__));
894
895struct btrfs_free_space_info {
896 __le32 extent_count;
897 __le32 flags;
898} __attribute__ ((__packed__));
899
900#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
901
902#define BTRFS_QGROUP_LEVEL_SHIFT 48
903static inline __u64 btrfs_qgroup_level(__u64 qgroupid)
904{
905 return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
906}
907
908/*
909 * is subvolume quota turned on?
910 */
911#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
912/*
913 * RESCAN is set during the initialization phase
914 */
915#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
916/*
917 * Some qgroup entries are known to be out of date,
918 * either because the configuration has changed in a way that
919 * makes a rescan necessary, or because the fs has been mounted
920 * with a non-qgroup-aware version.
921 * Turning qouta off and on again makes it inconsistent, too.
922 */
923#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
924
925#define BTRFS_QGROUP_STATUS_VERSION 1
926
927struct btrfs_qgroup_status_item {
928 __le64 version;
929 /*
930 * the generation is updated during every commit. As older
931 * versions of btrfs are not aware of qgroups, it will be
932 * possible to detect inconsistencies by checking the
933 * generation on mount time
934 */
935 __le64 generation;
936
937 /* flag definitions see above */
938 __le64 flags;
939
940 /*
941 * only used during scanning to record the progress
942 * of the scan. It contains a logical address
943 */
944 __le64 rescan;
945} __attribute__ ((__packed__));
946
947struct btrfs_qgroup_info_item {
948 __le64 generation;
949 __le64 rfer;
950 __le64 rfer_cmpr;
951 __le64 excl;
952 __le64 excl_cmpr;
953} __attribute__ ((__packed__));
954
955struct btrfs_qgroup_limit_item {
956 /*
957 * only updated when any of the other values change
958 */
959 __le64 flags;
960 __le64 max_rfer;
961 __le64 max_excl;
962 __le64 rsv_rfer;
963 __le64 rsv_excl;
964} __attribute__ ((__packed__));
965
966#endif /* _BTRFS_CTREE_H_ */