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