xref: /reactos/drivers/filesystems/btrfs/btrfs.h (revision 6e0cf03d)
1c2c66affSColin Finck /* btrfs.h
2c2c66affSColin Finck  * Generic btrfs header file. Thanks to whoever it was who wrote
3c2c66affSColin Finck  * https://btrfs.wiki.kernel.org/index.php/On-disk_Format - you saved me a lot of time!
4c2c66affSColin Finck  *
5c2c66affSColin Finck  * I release this file, and this file only, into the public domain - do whatever
6c2c66affSColin Finck  * you want with it. You don't have to, but I'd appreciate if you let me know if you
7c2c66affSColin Finck  * use it anything cool - mark@harmstone.com. */
8c2c66affSColin Finck 
9318da0c1SPierre Schweitzer #pragma once
10c2c66affSColin Finck 
11318da0c1SPierre Schweitzer #include <stdint.h>
12*6e0cf03dSVincent Franchomme #ifndef __REACTOS__
13*6e0cf03dSVincent Franchomme #include <assert.h>
14*6e0cf03dSVincent Franchomme #endif // __REACTOS__
15318da0c1SPierre Schweitzer 
16318da0c1SPierre Schweitzer static const uint64_t superblock_addrs[] = { 0x10000, 0x4000000, 0x4000000000, 0x4000000000000, 0 };
17c2c66affSColin Finck 
18c2c66affSColin Finck #define BTRFS_MAGIC         0x4d5f53665248425f
19c2c66affSColin Finck #define MAX_LABEL_SIZE      0x100
20c2c66affSColin Finck #define SUBVOL_ROOT_INODE   0x100
213cfd8ab7SVincent Franchomme #define BTRFS_LAST_FREE_OBJECTID    0xffffffffffffff00
22c2c66affSColin Finck 
23c2c66affSColin Finck #define TYPE_INODE_ITEM        0x01
24c2c66affSColin Finck #define TYPE_INODE_REF         0x0C
25c2c66affSColin Finck #define TYPE_INODE_EXTREF      0x0D
26c2c66affSColin Finck #define TYPE_XATTR_ITEM        0x18
27f381137cSPierre Schweitzer #define TYPE_ORPHAN_INODE      0x30
28c2c66affSColin Finck #define TYPE_DIR_ITEM          0x54
29c2c66affSColin Finck #define TYPE_DIR_INDEX         0x60
30c2c66affSColin Finck #define TYPE_EXTENT_DATA       0x6C
31c2c66affSColin Finck #define TYPE_EXTENT_CSUM       0x80
32c2c66affSColin Finck #define TYPE_ROOT_ITEM         0x84
33c2c66affSColin Finck #define TYPE_ROOT_BACKREF      0x90
34c2c66affSColin Finck #define TYPE_ROOT_REF          0x9C
35c2c66affSColin Finck #define TYPE_EXTENT_ITEM       0xA8
36c2c66affSColin Finck #define TYPE_METADATA_ITEM     0xA9
37c2c66affSColin Finck #define TYPE_TREE_BLOCK_REF    0xB0
38c2c66affSColin Finck #define TYPE_EXTENT_DATA_REF   0xB2
39c2c66affSColin Finck #define TYPE_EXTENT_REF_V0     0xB4
40c2c66affSColin Finck #define TYPE_SHARED_BLOCK_REF  0xB6
41c2c66affSColin Finck #define TYPE_SHARED_DATA_REF   0xB8
42c2c66affSColin Finck #define TYPE_BLOCK_GROUP_ITEM  0xC0
43c2c66affSColin Finck #define TYPE_FREE_SPACE_INFO   0xC6
44c2c66affSColin Finck #define TYPE_FREE_SPACE_EXTENT 0xC7
45c2c66affSColin Finck #define TYPE_FREE_SPACE_BITMAP 0xC8
46c2c66affSColin Finck #define TYPE_DEV_EXTENT        0xCC
47c2c66affSColin Finck #define TYPE_DEV_ITEM          0xD8
48c2c66affSColin Finck #define TYPE_CHUNK_ITEM        0xE4
49c2c66affSColin Finck #define TYPE_TEMP_ITEM         0xF8
50c2c66affSColin Finck #define TYPE_DEV_STATS         0xF9
51c2c66affSColin Finck #define TYPE_SUBVOL_UUID       0xFB
52c2c66affSColin Finck #define TYPE_SUBVOL_REC_UUID   0xFC
53c2c66affSColin Finck 
54c2c66affSColin Finck #define BTRFS_ROOT_ROOT         1
55c2c66affSColin Finck #define BTRFS_ROOT_EXTENT       2
56c2c66affSColin Finck #define BTRFS_ROOT_CHUNK        3
57c2c66affSColin Finck #define BTRFS_ROOT_DEVTREE      4
58c2c66affSColin Finck #define BTRFS_ROOT_FSTREE       5
5962e630deSPierre Schweitzer #define BTRFS_ROOT_TREEDIR      6
60c2c66affSColin Finck #define BTRFS_ROOT_CHECKSUM     7
61c2c66affSColin Finck #define BTRFS_ROOT_UUID         9
62c2c66affSColin Finck #define BTRFS_ROOT_FREE_SPACE   0xa
63c2c66affSColin Finck #define BTRFS_ROOT_DATA_RELOC   0xFFFFFFFFFFFFFFF7
64c2c66affSColin Finck 
65c2c66affSColin Finck #define BTRFS_COMPRESSION_NONE  0
66c2c66affSColin Finck #define BTRFS_COMPRESSION_ZLIB  1
67c2c66affSColin Finck #define BTRFS_COMPRESSION_LZO   2
68eb7fbc25SPierre Schweitzer #define BTRFS_COMPRESSION_ZSTD  3
69c2c66affSColin Finck 
70c2c66affSColin Finck #define BTRFS_ENCRYPTION_NONE   0
71c2c66affSColin Finck 
72c2c66affSColin Finck #define BTRFS_ENCODING_NONE     0
73c2c66affSColin Finck 
74c2c66affSColin Finck #define EXTENT_TYPE_INLINE      0
75c2c66affSColin Finck #define EXTENT_TYPE_REGULAR     1
76c2c66affSColin Finck #define EXTENT_TYPE_PREALLOC    2
77c2c66affSColin Finck 
78c2c66affSColin Finck #define BLOCK_FLAG_DATA         0x001
79c2c66affSColin Finck #define BLOCK_FLAG_SYSTEM       0x002
80c2c66affSColin Finck #define BLOCK_FLAG_METADATA     0x004
81c2c66affSColin Finck #define BLOCK_FLAG_RAID0        0x008
82c2c66affSColin Finck #define BLOCK_FLAG_RAID1        0x010
83c2c66affSColin Finck #define BLOCK_FLAG_DUPLICATE    0x020
84c2c66affSColin Finck #define BLOCK_FLAG_RAID10       0x040
85c2c66affSColin Finck #define BLOCK_FLAG_RAID5        0x080
86c2c66affSColin Finck #define BLOCK_FLAG_RAID6        0x100
87194ea909SVictor Perevertkin #define BLOCK_FLAG_RAID1C3      0x200
88194ea909SVictor Perevertkin #define BLOCK_FLAG_RAID1C4      0x400
89c2c66affSColin Finck 
90c2c66affSColin Finck #define FREE_SPACE_CACHE_ID     0xFFFFFFFFFFFFFFF5
91c2c66affSColin Finck #define EXTENT_CSUM_ID          0xFFFFFFFFFFFFFFF6
92c2c66affSColin Finck #define BALANCE_ITEM_ID         0xFFFFFFFFFFFFFFFC
93c2c66affSColin Finck 
94c2c66affSColin Finck #define BTRFS_INODE_NODATASUM   0x001
95c2c66affSColin Finck #define BTRFS_INODE_NODATACOW   0x002
96c2c66affSColin Finck #define BTRFS_INODE_READONLY    0x004
97c2c66affSColin Finck #define BTRFS_INODE_NOCOMPRESS  0x008
98c2c66affSColin Finck #define BTRFS_INODE_PREALLOC    0x010
99c2c66affSColin Finck #define BTRFS_INODE_SYNC        0x020
100c2c66affSColin Finck #define BTRFS_INODE_IMMUTABLE   0x040
101c2c66affSColin Finck #define BTRFS_INODE_APPEND      0x080
102c2c66affSColin Finck #define BTRFS_INODE_NODUMP      0x100
103c2c66affSColin Finck #define BTRFS_INODE_NOATIME     0x200
104c2c66affSColin Finck #define BTRFS_INODE_DIRSYNC     0x400
105c2c66affSColin Finck #define BTRFS_INODE_COMPRESS    0x800
106c2c66affSColin Finck 
107*6e0cf03dSVincent Franchomme #define BTRFS_INODE_RO_VERITY   0x1
108*6e0cf03dSVincent Franchomme 
109c2c66affSColin Finck #define BTRFS_SUBVOL_READONLY   0x1
110c2c66affSColin Finck 
111c2c66affSColin Finck #define BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE          0x1
112c2c66affSColin Finck #define BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE_VALID    0x2
113*6e0cf03dSVincent Franchomme #define BTRFS_COMPAT_RO_FLAGS_VERITY                    0x4
114c2c66affSColin Finck 
115c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF      0x0001
116c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL     0x0002
117c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS       0x0004
118c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO       0x0008
119eb7fbc25SPierre Schweitzer #define BTRFS_INCOMPAT_FLAGS_COMPRESS_ZSTD      0x0010
120c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_BIG_METADATA       0x0020
121c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF      0x0040
122c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_RAID56             0x0080
123c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA    0x0100
124c2c66affSColin Finck #define BTRFS_INCOMPAT_FLAGS_NO_HOLES           0x0200
125194ea909SVictor Perevertkin #define BTRFS_INCOMPAT_FLAGS_METADATA_UUID      0x0400
126194ea909SVictor Perevertkin #define BTRFS_INCOMPAT_FLAGS_RAID1C34           0x0800
127c2c66affSColin Finck 
128c2c66affSColin Finck #define BTRFS_SUPERBLOCK_FLAGS_SEEDING   0x100000000
129c2c66affSColin Finck 
130f381137cSPierre Schweitzer #define BTRFS_ORPHAN_INODE_OBJID         0xFFFFFFFFFFFFFFFB
131f381137cSPierre Schweitzer 
132194ea909SVictor Perevertkin #define CSUM_TYPE_CRC32C        0
133194ea909SVictor Perevertkin #define CSUM_TYPE_XXHASH        1
134194ea909SVictor Perevertkin #define CSUM_TYPE_SHA256        2
135194ea909SVictor Perevertkin #define CSUM_TYPE_BLAKE2        3
136194ea909SVictor Perevertkin 
137c2c66affSColin Finck #pragma pack(push, 1)
138c2c66affSColin Finck 
139c2c66affSColin Finck typedef struct {
140318da0c1SPierre Schweitzer     uint8_t uuid[16];
141c2c66affSColin Finck } BTRFS_UUID;
142c2c66affSColin Finck 
143c2c66affSColin Finck typedef struct {
144318da0c1SPierre Schweitzer     uint64_t obj_id;
145318da0c1SPierre Schweitzer     uint8_t obj_type;
146318da0c1SPierre Schweitzer     uint64_t offset;
147c2c66affSColin Finck } KEY;
148c2c66affSColin Finck 
149c2c66affSColin Finck #define HEADER_FLAG_WRITTEN         0x000000000000001
150c2c66affSColin Finck #define HEADER_FLAG_SHARED_BACKREF  0x000000000000002
151c2c66affSColin Finck #define HEADER_FLAG_MIXED_BACKREF   0x100000000000000
152c2c66affSColin Finck 
153c2c66affSColin Finck typedef struct {
154318da0c1SPierre Schweitzer     uint8_t csum[32];
155c2c66affSColin Finck     BTRFS_UUID fs_uuid;
156318da0c1SPierre Schweitzer     uint64_t address;
157318da0c1SPierre Schweitzer     uint64_t flags;
158c2c66affSColin Finck     BTRFS_UUID chunk_tree_uuid;
159318da0c1SPierre Schweitzer     uint64_t generation;
160318da0c1SPierre Schweitzer     uint64_t tree_id;
161318da0c1SPierre Schweitzer     uint32_t num_items;
162318da0c1SPierre Schweitzer     uint8_t level;
163c2c66affSColin Finck } tree_header;
164c2c66affSColin Finck 
165c2c66affSColin Finck typedef struct {
166c2c66affSColin Finck     KEY key;
167318da0c1SPierre Schweitzer     uint32_t offset;
168318da0c1SPierre Schweitzer     uint32_t size;
169c2c66affSColin Finck } leaf_node;
170c2c66affSColin Finck 
171c2c66affSColin Finck typedef struct {
172c2c66affSColin Finck     KEY key;
173318da0c1SPierre Schweitzer     uint64_t address;
174318da0c1SPierre Schweitzer     uint64_t generation;
175c2c66affSColin Finck } internal_node;
176c2c66affSColin Finck 
177c2c66affSColin Finck typedef struct {
178318da0c1SPierre Schweitzer     uint64_t dev_id;
179318da0c1SPierre Schweitzer     uint64_t num_bytes;
180318da0c1SPierre Schweitzer     uint64_t bytes_used;
181318da0c1SPierre Schweitzer     uint32_t optimal_io_align;
182318da0c1SPierre Schweitzer     uint32_t optimal_io_width;
183318da0c1SPierre Schweitzer     uint32_t minimal_io_size;
184318da0c1SPierre Schweitzer     uint64_t type;
185318da0c1SPierre Schweitzer     uint64_t generation;
186318da0c1SPierre Schweitzer     uint64_t start_offset;
187318da0c1SPierre Schweitzer     uint32_t dev_group;
188318da0c1SPierre Schweitzer     uint8_t seek_speed;
189318da0c1SPierre Schweitzer     uint8_t bandwidth;
190c2c66affSColin Finck     BTRFS_UUID device_uuid;
191c2c66affSColin Finck     BTRFS_UUID fs_uuid;
192c2c66affSColin Finck } DEV_ITEM;
193c2c66affSColin Finck 
194c2c66affSColin Finck #define SYS_CHUNK_ARRAY_SIZE 0x800
195c2c66affSColin Finck #define BTRFS_NUM_BACKUP_ROOTS 4
196c2c66affSColin Finck 
197c2c66affSColin Finck typedef struct {
198318da0c1SPierre Schweitzer     uint64_t root_tree_addr;
199318da0c1SPierre Schweitzer     uint64_t root_tree_generation;
200318da0c1SPierre Schweitzer     uint64_t chunk_tree_addr;
201318da0c1SPierre Schweitzer     uint64_t chunk_tree_generation;
202318da0c1SPierre Schweitzer     uint64_t extent_tree_addr;
203318da0c1SPierre Schweitzer     uint64_t extent_tree_generation;
204318da0c1SPierre Schweitzer     uint64_t fs_tree_addr;
205318da0c1SPierre Schweitzer     uint64_t fs_tree_generation;
206318da0c1SPierre Schweitzer     uint64_t dev_root_addr;
207318da0c1SPierre Schweitzer     uint64_t dev_root_generation;
208318da0c1SPierre Schweitzer     uint64_t csum_root_addr;
209318da0c1SPierre Schweitzer     uint64_t csum_root_generation;
210318da0c1SPierre Schweitzer     uint64_t total_bytes;
211318da0c1SPierre Schweitzer     uint64_t bytes_used;
212318da0c1SPierre Schweitzer     uint64_t num_devices;
213318da0c1SPierre Schweitzer     uint64_t reserved[4];
214318da0c1SPierre Schweitzer     uint8_t root_level;
215318da0c1SPierre Schweitzer     uint8_t chunk_root_level;
216318da0c1SPierre Schweitzer     uint8_t extent_root_level;
217318da0c1SPierre Schweitzer     uint8_t fs_root_level;
218318da0c1SPierre Schweitzer     uint8_t dev_root_level;
219318da0c1SPierre Schweitzer     uint8_t csum_root_level;
220318da0c1SPierre Schweitzer     uint8_t reserved2[10];
221c2c66affSColin Finck } superblock_backup;
222c2c66affSColin Finck 
223c2c66affSColin Finck typedef struct {
224318da0c1SPierre Schweitzer     uint8_t checksum[32];
225c2c66affSColin Finck     BTRFS_UUID uuid;
226318da0c1SPierre Schweitzer     uint64_t sb_phys_addr;
227318da0c1SPierre Schweitzer     uint64_t flags;
228318da0c1SPierre Schweitzer     uint64_t magic;
229318da0c1SPierre Schweitzer     uint64_t generation;
230318da0c1SPierre Schweitzer     uint64_t root_tree_addr;
231318da0c1SPierre Schweitzer     uint64_t chunk_tree_addr;
232318da0c1SPierre Schweitzer     uint64_t log_tree_addr;
233318da0c1SPierre Schweitzer     uint64_t log_root_transid;
234318da0c1SPierre Schweitzer     uint64_t total_bytes;
235318da0c1SPierre Schweitzer     uint64_t bytes_used;
236318da0c1SPierre Schweitzer     uint64_t root_dir_objectid;
237318da0c1SPierre Schweitzer     uint64_t num_devices;
238318da0c1SPierre Schweitzer     uint32_t sector_size;
239318da0c1SPierre Schweitzer     uint32_t node_size;
240318da0c1SPierre Schweitzer     uint32_t leaf_size;
241318da0c1SPierre Schweitzer     uint32_t stripe_size;
242318da0c1SPierre Schweitzer     uint32_t n;
243318da0c1SPierre Schweitzer     uint64_t chunk_root_generation;
244318da0c1SPierre Schweitzer     uint64_t compat_flags;
245318da0c1SPierre Schweitzer     uint64_t compat_ro_flags;
246318da0c1SPierre Schweitzer     uint64_t incompat_flags;
247318da0c1SPierre Schweitzer     uint16_t csum_type;
248318da0c1SPierre Schweitzer     uint8_t root_level;
249318da0c1SPierre Schweitzer     uint8_t chunk_root_level;
250318da0c1SPierre Schweitzer     uint8_t log_root_level;
251c2c66affSColin Finck     DEV_ITEM dev_item;
252c2c66affSColin Finck     char label[MAX_LABEL_SIZE];
253318da0c1SPierre Schweitzer     uint64_t cache_generation;
254318da0c1SPierre Schweitzer     uint64_t uuid_tree_generation;
255194ea909SVictor Perevertkin     BTRFS_UUID metadata_uuid;
256194ea909SVictor Perevertkin     uint64_t reserved[28];
257318da0c1SPierre Schweitzer     uint8_t sys_chunk_array[SYS_CHUNK_ARRAY_SIZE];
258c2c66affSColin Finck     superblock_backup backup[BTRFS_NUM_BACKUP_ROOTS];
259318da0c1SPierre Schweitzer     uint8_t reserved2[565];
260c2c66affSColin Finck } superblock;
261c2c66affSColin Finck 
262c2c66affSColin Finck #define BTRFS_TYPE_UNKNOWN   0
263c2c66affSColin Finck #define BTRFS_TYPE_FILE      1
264c2c66affSColin Finck #define BTRFS_TYPE_DIRECTORY 2
265c2c66affSColin Finck #define BTRFS_TYPE_CHARDEV   3
266c2c66affSColin Finck #define BTRFS_TYPE_BLOCKDEV  4
267c2c66affSColin Finck #define BTRFS_TYPE_FIFO      5
268c2c66affSColin Finck #define BTRFS_TYPE_SOCKET    6
269c2c66affSColin Finck #define BTRFS_TYPE_SYMLINK   7
270c2c66affSColin Finck #define BTRFS_TYPE_EA        8
271c2c66affSColin Finck 
272c2c66affSColin Finck typedef struct {
273c2c66affSColin Finck     KEY key;
274318da0c1SPierre Schweitzer     uint64_t transid;
275318da0c1SPierre Schweitzer     uint16_t m;
276318da0c1SPierre Schweitzer     uint16_t n;
277318da0c1SPierre Schweitzer     uint8_t type;
278c2c66affSColin Finck     char name[1];
279c2c66affSColin Finck } DIR_ITEM;
280c2c66affSColin Finck 
281c2c66affSColin Finck typedef struct {
282318da0c1SPierre Schweitzer     uint64_t seconds;
283318da0c1SPierre Schweitzer     uint32_t nanoseconds;
284c2c66affSColin Finck } BTRFS_TIME;
285c2c66affSColin Finck 
286c2c66affSColin Finck typedef struct {
287318da0c1SPierre Schweitzer     uint64_t generation;
288318da0c1SPierre Schweitzer     uint64_t transid;
289318da0c1SPierre Schweitzer     uint64_t st_size;
290318da0c1SPierre Schweitzer     uint64_t st_blocks;
291318da0c1SPierre Schweitzer     uint64_t block_group;
292318da0c1SPierre Schweitzer     uint32_t st_nlink;
293318da0c1SPierre Schweitzer     uint32_t st_uid;
294318da0c1SPierre Schweitzer     uint32_t st_gid;
295318da0c1SPierre Schweitzer     uint32_t st_mode;
296318da0c1SPierre Schweitzer     uint64_t st_rdev;
297*6e0cf03dSVincent Franchomme     uint32_t flags;
298*6e0cf03dSVincent Franchomme     uint32_t flags_ro;
299318da0c1SPierre Schweitzer     uint64_t sequence;
300318da0c1SPierre Schweitzer     uint8_t reserved[32];
301c2c66affSColin Finck     BTRFS_TIME st_atime;
302c2c66affSColin Finck     BTRFS_TIME st_ctime;
303c2c66affSColin Finck     BTRFS_TIME st_mtime;
304c2c66affSColin Finck     BTRFS_TIME otime;
305c2c66affSColin Finck } INODE_ITEM;
306c2c66affSColin Finck 
307*6e0cf03dSVincent Franchomme #ifndef __REACTOS__
308*6e0cf03dSVincent Franchomme static_assert(sizeof(INODE_ITEM) == 0xa0, "INODE_ITEM has wrong size");
309*6e0cf03dSVincent Franchomme #endif // __REACTOS__
310*6e0cf03dSVincent Franchomme 
311c2c66affSColin Finck typedef struct {
312c2c66affSColin Finck     INODE_ITEM inode;
313318da0c1SPierre Schweitzer     uint64_t generation;
314318da0c1SPierre Schweitzer     uint64_t objid;
315318da0c1SPierre Schweitzer     uint64_t block_number;
316318da0c1SPierre Schweitzer     uint64_t byte_limit;
317318da0c1SPierre Schweitzer     uint64_t bytes_used;
318318da0c1SPierre Schweitzer     uint64_t last_snapshot_generation;
319318da0c1SPierre Schweitzer     uint64_t flags;
320318da0c1SPierre Schweitzer     uint32_t num_references;
321c2c66affSColin Finck     KEY drop_progress;
322318da0c1SPierre Schweitzer     uint8_t drop_level;
323318da0c1SPierre Schweitzer     uint8_t root_level;
324318da0c1SPierre Schweitzer     uint64_t generation2;
325c2c66affSColin Finck     BTRFS_UUID uuid;
326c2c66affSColin Finck     BTRFS_UUID parent_uuid;
327c2c66affSColin Finck     BTRFS_UUID received_uuid;
328318da0c1SPierre Schweitzer     uint64_t ctransid;
329318da0c1SPierre Schweitzer     uint64_t otransid;
330318da0c1SPierre Schweitzer     uint64_t stransid;
331318da0c1SPierre Schweitzer     uint64_t rtransid;
332c2c66affSColin Finck     BTRFS_TIME ctime;
333c2c66affSColin Finck     BTRFS_TIME otime;
334c2c66affSColin Finck     BTRFS_TIME stime;
335c2c66affSColin Finck     BTRFS_TIME rtime;
336318da0c1SPierre Schweitzer     uint64_t reserved[8];
337c2c66affSColin Finck } ROOT_ITEM;
338c2c66affSColin Finck 
339c2c66affSColin Finck typedef struct {
340318da0c1SPierre Schweitzer     uint64_t size;
341318da0c1SPierre Schweitzer     uint64_t root_id;
342318da0c1SPierre Schweitzer     uint64_t stripe_length;
343318da0c1SPierre Schweitzer     uint64_t type;
344318da0c1SPierre Schweitzer     uint32_t opt_io_alignment;
345318da0c1SPierre Schweitzer     uint32_t opt_io_width;
346318da0c1SPierre Schweitzer     uint32_t sector_size;
347318da0c1SPierre Schweitzer     uint16_t num_stripes;
348318da0c1SPierre Schweitzer     uint16_t sub_stripes;
349c2c66affSColin Finck } CHUNK_ITEM;
350c2c66affSColin Finck 
351c2c66affSColin Finck typedef struct {
352318da0c1SPierre Schweitzer     uint64_t dev_id;
353318da0c1SPierre Schweitzer     uint64_t offset;
354c2c66affSColin Finck     BTRFS_UUID dev_uuid;
355c2c66affSColin Finck } CHUNK_ITEM_STRIPE;
356c2c66affSColin Finck 
357c2c66affSColin Finck typedef struct {
358318da0c1SPierre Schweitzer     uint64_t generation;
359318da0c1SPierre Schweitzer     uint64_t decoded_size;
360318da0c1SPierre Schweitzer     uint8_t compression;
361318da0c1SPierre Schweitzer     uint8_t encryption;
362318da0c1SPierre Schweitzer     uint16_t encoding;
363318da0c1SPierre Schweitzer     uint8_t type;
364318da0c1SPierre Schweitzer     uint8_t data[1];
365c2c66affSColin Finck } EXTENT_DATA;
366c2c66affSColin Finck 
367c2c66affSColin Finck typedef struct {
368318da0c1SPierre Schweitzer     uint64_t address;
369318da0c1SPierre Schweitzer     uint64_t size;
370318da0c1SPierre Schweitzer     uint64_t offset;
371318da0c1SPierre Schweitzer     uint64_t num_bytes;
372c2c66affSColin Finck } EXTENT_DATA2;
373c2c66affSColin Finck 
374c2c66affSColin Finck typedef struct {
375318da0c1SPierre Schweitzer     uint64_t index;
376318da0c1SPierre Schweitzer     uint16_t n;
377c2c66affSColin Finck     char name[1];
378c2c66affSColin Finck } INODE_REF;
379c2c66affSColin Finck 
380c2c66affSColin Finck typedef struct {
381318da0c1SPierre Schweitzer     uint64_t dir;
382318da0c1SPierre Schweitzer     uint64_t index;
383318da0c1SPierre Schweitzer     uint16_t n;
384c2c66affSColin Finck     char name[1];
385c2c66affSColin Finck } INODE_EXTREF;
386c2c66affSColin Finck 
387c2c66affSColin Finck #define EXTENT_ITEM_DATA            0x001
388c2c66affSColin Finck #define EXTENT_ITEM_TREE_BLOCK      0x002
389c2c66affSColin Finck #define EXTENT_ITEM_SHARED_BACKREFS 0x100
390c2c66affSColin Finck 
391c2c66affSColin Finck typedef struct {
392318da0c1SPierre Schweitzer     uint64_t refcount;
393318da0c1SPierre Schweitzer     uint64_t generation;
394318da0c1SPierre Schweitzer     uint64_t flags;
395c2c66affSColin Finck } EXTENT_ITEM;
396c2c66affSColin Finck 
397c2c66affSColin Finck typedef struct {
398c2c66affSColin Finck     KEY firstitem;
399318da0c1SPierre Schweitzer     uint8_t level;
400c2c66affSColin Finck } EXTENT_ITEM2;
401c2c66affSColin Finck 
402c2c66affSColin Finck typedef struct {
403318da0c1SPierre Schweitzer     uint32_t refcount;
404c2c66affSColin Finck } EXTENT_ITEM_V0;
405c2c66affSColin Finck 
406c2c66affSColin Finck typedef struct {
407c2c66affSColin Finck     EXTENT_ITEM extent_item;
408c2c66affSColin Finck     KEY firstitem;
409318da0c1SPierre Schweitzer     uint8_t level;
410c2c66affSColin Finck } EXTENT_ITEM_TREE;
411c2c66affSColin Finck 
412c2c66affSColin Finck typedef struct {
413318da0c1SPierre Schweitzer     uint64_t offset;
414c2c66affSColin Finck } TREE_BLOCK_REF;
415c2c66affSColin Finck 
416c2c66affSColin Finck typedef struct {
417318da0c1SPierre Schweitzer     uint64_t root;
418318da0c1SPierre Schweitzer     uint64_t objid;
419318da0c1SPierre Schweitzer     uint64_t offset;
420318da0c1SPierre Schweitzer     uint32_t count;
421c2c66affSColin Finck } EXTENT_DATA_REF;
422c2c66affSColin Finck 
423c2c66affSColin Finck typedef struct {
424318da0c1SPierre Schweitzer     uint64_t used;
425318da0c1SPierre Schweitzer     uint64_t chunk_tree;
426318da0c1SPierre Schweitzer     uint64_t flags;
427c2c66affSColin Finck } BLOCK_GROUP_ITEM;
428c2c66affSColin Finck 
429c2c66affSColin Finck typedef struct {
430318da0c1SPierre Schweitzer     uint64_t root;
431318da0c1SPierre Schweitzer     uint64_t gen;
432318da0c1SPierre Schweitzer     uint64_t objid;
433318da0c1SPierre Schweitzer     uint32_t count;
434c2c66affSColin Finck } EXTENT_REF_V0;
435c2c66affSColin Finck 
436c2c66affSColin Finck typedef struct {
437318da0c1SPierre Schweitzer     uint64_t offset;
438c2c66affSColin Finck } SHARED_BLOCK_REF;
439c2c66affSColin Finck 
440c2c66affSColin Finck typedef struct {
441318da0c1SPierre Schweitzer     uint64_t offset;
442318da0c1SPierre Schweitzer     uint32_t count;
443c2c66affSColin Finck } SHARED_DATA_REF;
444c2c66affSColin Finck 
445c2c66affSColin Finck #define FREE_SPACE_EXTENT 1
446c2c66affSColin Finck #define FREE_SPACE_BITMAP 2
447c2c66affSColin Finck 
448c2c66affSColin Finck typedef struct {
449318da0c1SPierre Schweitzer     uint64_t offset;
450318da0c1SPierre Schweitzer     uint64_t size;
451318da0c1SPierre Schweitzer     uint8_t type;
452c2c66affSColin Finck } FREE_SPACE_ENTRY;
453c2c66affSColin Finck 
454c2c66affSColin Finck typedef struct {
455c2c66affSColin Finck     KEY key;
456318da0c1SPierre Schweitzer     uint64_t generation;
457318da0c1SPierre Schweitzer     uint64_t num_entries;
458318da0c1SPierre Schweitzer     uint64_t num_bitmaps;
459c2c66affSColin Finck } FREE_SPACE_ITEM;
460c2c66affSColin Finck 
461c2c66affSColin Finck typedef struct {
462318da0c1SPierre Schweitzer     uint64_t dir;
463318da0c1SPierre Schweitzer     uint64_t index;
464318da0c1SPierre Schweitzer     uint16_t n;
465c2c66affSColin Finck     char name[1];
466c2c66affSColin Finck } ROOT_REF;
467c2c66affSColin Finck 
468c2c66affSColin Finck typedef struct {
469318da0c1SPierre Schweitzer     uint64_t chunktree;
470318da0c1SPierre Schweitzer     uint64_t objid;
471318da0c1SPierre Schweitzer     uint64_t address;
472318da0c1SPierre Schweitzer     uint64_t length;
473c2c66affSColin Finck     BTRFS_UUID chunktree_uuid;
474c2c66affSColin Finck } DEV_EXTENT;
475c2c66affSColin Finck 
476c2c66affSColin Finck #define BALANCE_FLAGS_DATA          0x1
477c2c66affSColin Finck #define BALANCE_FLAGS_SYSTEM        0x2
478c2c66affSColin Finck #define BALANCE_FLAGS_METADATA      0x4
479c2c66affSColin Finck 
480c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_PROFILES         0x001
481c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_USAGE            0x002
482c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_DEVID            0x004
483c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_DRANGE           0x008
484c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_VRANGE           0x010
485c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_LIMIT            0x020
486c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_LIMIT_RANGE      0x040
487c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_STRIPES_RANGE    0x080
488c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_CONVERT          0x100
489c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_SOFT             0x200
490c2c66affSColin Finck #define BALANCE_ARGS_FLAGS_USAGE_RANGE      0x400
491c2c66affSColin Finck 
492c2c66affSColin Finck typedef struct {
493318da0c1SPierre Schweitzer     uint64_t profiles;
494c2c66affSColin Finck 
495c2c66affSColin Finck     union {
496318da0c1SPierre Schweitzer             uint64_t usage;
497c2c66affSColin Finck             struct {
498318da0c1SPierre Schweitzer                     uint32_t usage_start;
499318da0c1SPierre Schweitzer                     uint32_t usage_end;
500c2c66affSColin Finck             };
501c2c66affSColin Finck     };
502c2c66affSColin Finck 
503318da0c1SPierre Schweitzer     uint64_t devid;
504318da0c1SPierre Schweitzer     uint64_t drange_start;
505318da0c1SPierre Schweitzer     uint64_t drange_end;
506318da0c1SPierre Schweitzer     uint64_t vrange_start;
507318da0c1SPierre Schweitzer     uint64_t vrange_end;
508318da0c1SPierre Schweitzer     uint64_t convert;
509318da0c1SPierre Schweitzer     uint64_t flags;
510c2c66affSColin Finck 
511c2c66affSColin Finck     union {
512318da0c1SPierre Schweitzer             uint64_t limit;
513c2c66affSColin Finck             struct {
514318da0c1SPierre Schweitzer                     uint32_t limit_start;
515318da0c1SPierre Schweitzer                     uint32_t limit_end;
516c2c66affSColin Finck             };
517c2c66affSColin Finck     };
518c2c66affSColin Finck 
519318da0c1SPierre Schweitzer     uint32_t stripes_start;
520318da0c1SPierre Schweitzer     uint32_t stripes_end;
521318da0c1SPierre Schweitzer     uint8_t reserved[48];
522c2c66affSColin Finck } BALANCE_ARGS;
523c2c66affSColin Finck 
524c2c66affSColin Finck typedef struct {
525318da0c1SPierre Schweitzer     uint64_t flags;
526c2c66affSColin Finck     BALANCE_ARGS data;
527c2c66affSColin Finck     BALANCE_ARGS metadata;
528c2c66affSColin Finck     BALANCE_ARGS system;
529318da0c1SPierre Schweitzer     uint8_t reserved[32];
530c2c66affSColin Finck } BALANCE_ITEM;
531c2c66affSColin Finck 
532c2c66affSColin Finck #define BTRFS_FREE_SPACE_USING_BITMAPS      1
533c2c66affSColin Finck 
534c2c66affSColin Finck typedef struct {
535318da0c1SPierre Schweitzer     uint32_t count;
536318da0c1SPierre Schweitzer     uint32_t flags;
537c2c66affSColin Finck } FREE_SPACE_INFO;
538c2c66affSColin Finck 
539c2c66affSColin Finck #define BTRFS_DEV_STAT_WRITE_ERRORS          0
540c2c66affSColin Finck #define BTRFS_DEV_STAT_READ_ERRORS           1
541c2c66affSColin Finck #define BTRFS_DEV_STAT_FLUSH_ERRORS          2
542c2c66affSColin Finck #define BTRFS_DEV_STAT_CORRUPTION_ERRORS     3
543c2c66affSColin Finck #define BTRFS_DEV_STAT_GENERATION_ERRORS     4
544c2c66affSColin Finck 
545c2c66affSColin Finck #define BTRFS_SEND_CMD_SUBVOL          1
546c2c66affSColin Finck #define BTRFS_SEND_CMD_SNAPSHOT        2
547c2c66affSColin Finck #define BTRFS_SEND_CMD_MKFILE          3
548c2c66affSColin Finck #define BTRFS_SEND_CMD_MKDIR           4
549c2c66affSColin Finck #define BTRFS_SEND_CMD_MKNOD           5
550c2c66affSColin Finck #define BTRFS_SEND_CMD_MKFIFO          6
551c2c66affSColin Finck #define BTRFS_SEND_CMD_MKSOCK          7
552c2c66affSColin Finck #define BTRFS_SEND_CMD_SYMLINK         8
553c2c66affSColin Finck #define BTRFS_SEND_CMD_RENAME          9
554c2c66affSColin Finck #define BTRFS_SEND_CMD_LINK           10
555c2c66affSColin Finck #define BTRFS_SEND_CMD_UNLINK         11
556c2c66affSColin Finck #define BTRFS_SEND_CMD_RMDIR          12
557c2c66affSColin Finck #define BTRFS_SEND_CMD_SET_XATTR      13
558c2c66affSColin Finck #define BTRFS_SEND_CMD_REMOVE_XATTR   14
559c2c66affSColin Finck #define BTRFS_SEND_CMD_WRITE          15
560c2c66affSColin Finck #define BTRFS_SEND_CMD_CLONE          16
561c2c66affSColin Finck #define BTRFS_SEND_CMD_TRUNCATE       17
562c2c66affSColin Finck #define BTRFS_SEND_CMD_CHMOD          18
563c2c66affSColin Finck #define BTRFS_SEND_CMD_CHOWN          19
564c2c66affSColin Finck #define BTRFS_SEND_CMD_UTIMES         20
565c2c66affSColin Finck #define BTRFS_SEND_CMD_END            21
566c2c66affSColin Finck #define BTRFS_SEND_CMD_UPDATE_EXTENT  22
567c2c66affSColin Finck 
568c2c66affSColin Finck #define BTRFS_SEND_TLV_UUID             1
569c2c66affSColin Finck #define BTRFS_SEND_TLV_TRANSID          2
570c2c66affSColin Finck #define BTRFS_SEND_TLV_INODE            3
571c2c66affSColin Finck #define BTRFS_SEND_TLV_SIZE             4
572c2c66affSColin Finck #define BTRFS_SEND_TLV_MODE             5
573c2c66affSColin Finck #define BTRFS_SEND_TLV_UID              6
574c2c66affSColin Finck #define BTRFS_SEND_TLV_GID              7
575c2c66affSColin Finck #define BTRFS_SEND_TLV_RDEV             8
576c2c66affSColin Finck #define BTRFS_SEND_TLV_CTIME            9
577c2c66affSColin Finck #define BTRFS_SEND_TLV_MTIME           10
578c2c66affSColin Finck #define BTRFS_SEND_TLV_ATIME           11
579c2c66affSColin Finck #define BTRFS_SEND_TLV_OTIME           12
580c2c66affSColin Finck #define BTRFS_SEND_TLV_XATTR_NAME      13
581c2c66affSColin Finck #define BTRFS_SEND_TLV_XATTR_DATA      14
582c2c66affSColin Finck #define BTRFS_SEND_TLV_PATH            15
583c2c66affSColin Finck #define BTRFS_SEND_TLV_PATH_TO         16
584c2c66affSColin Finck #define BTRFS_SEND_TLV_PATH_LINK       17
585c2c66affSColin Finck #define BTRFS_SEND_TLV_OFFSET          18
586c2c66affSColin Finck #define BTRFS_SEND_TLV_DATA            19
587c2c66affSColin Finck #define BTRFS_SEND_TLV_CLONE_UUID      20
588c2c66affSColin Finck #define BTRFS_SEND_TLV_CLONE_CTRANSID  21
589c2c66affSColin Finck #define BTRFS_SEND_TLV_CLONE_PATH      22
590c2c66affSColin Finck #define BTRFS_SEND_TLV_CLONE_OFFSET    23
591c2c66affSColin Finck #define BTRFS_SEND_TLV_CLONE_LENGTH    24
592c2c66affSColin Finck 
593c7806a6bSPierre Schweitzer #define BTRFS_SEND_MAGIC "btrfs-stream"
594c2c66affSColin Finck 
595c2c66affSColin Finck typedef struct {
596318da0c1SPierre Schweitzer     uint8_t magic[13];
597318da0c1SPierre Schweitzer     uint32_t version;
598c2c66affSColin Finck } btrfs_send_header;
599c2c66affSColin Finck 
600c2c66affSColin Finck typedef struct {
601318da0c1SPierre Schweitzer     uint32_t length;
602318da0c1SPierre Schweitzer     uint16_t cmd;
603318da0c1SPierre Schweitzer     uint32_t csum;
604c2c66affSColin Finck } btrfs_send_command;
605c2c66affSColin Finck 
606c2c66affSColin Finck typedef struct {
607318da0c1SPierre Schweitzer     uint16_t type;
608318da0c1SPierre Schweitzer     uint16_t length;
609c2c66affSColin Finck } btrfs_send_tlv;
610c2c66affSColin Finck 
611c2c66affSColin Finck #pragma pack(pop)
612