ReactOS 0.4.15-dev-8227-g32d615f
btrfs.h
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: BTRFS support for FreeLoader
5 * COPYRIGHT: Copyright 2018 Victor Perevertkin (victor@perevertkin.ru)
6 */
7
8/* Structures were taken from u-boot, https://github.com/u-boot/u-boot/tree/master/fs/btrfs */
9
10#pragma once
11
12typedef UCHAR u8;
13typedef USHORT u16;
14typedef ULONG32 u32;
15typedef ULONG64 u64;
16/* type that store on disk, but it is same as cpu type for i386 arch */
17typedef u8 __u8;
18typedef u16 __u16;
19typedef u32 __u32;
20typedef u64 __u64;
21
22#include <fs/crc32c.h>
23#define btrfs_crc32c(name, len) crc32c_le((u32)~1, name, len)
24
25#define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
26#define BTRFS_SUPER_INFO_SIZE 4096
27#define BTRFS_MAX_LEAF_SIZE 4096
28#define BTRFS_BLOCK_SHIFT 12
29#define BTRFS_BLOCK_SIZE (1 << BTRFS_BLOCK_SHIFT)
30
31#define BTRFS_SUPER_MIRROR_MAX 3
32#define BTRFS_SUPER_MIRROR_SHIFT 12
33#define BTRFS_CSUM_SIZE 32
34#define BTRFS_FSID_SIZE 16
35#define BTRFS_LABEL_SIZE 256
36#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
37#define BTRFS_UUID_SIZE 16
38
39#define BTRFS_VOL_NAME_MAX 255
40#define BTRFS_NAME_MAX 255
41
42#define BTRFS_MAGIC "_BHRfS_M"
43#define BTRFS_MAGIC_L 8
44#define BTRFS_MAGIC_N 0x4d5f53665248425fULL
45
46#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
47
48#define BTRFS_DEV_ITEM_KEY 216
49#define BTRFS_CHUNK_ITEM_KEY 228
50#define BTRFS_ROOT_REF_KEY 156
51#define BTRFS_ROOT_ITEM_KEY 132
52#define BTRFS_EXTENT_DATA_KEY 108
53#define BTRFS_DIR_ITEM_KEY 84
54#define BTRFS_DIR_INDEX_KEY 96
55#define BTRFS_INODE_ITEM_KEY 1
56#define BTRFS_INODE_REF_KEY 12
57
58#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
59#define BTRFS_FS_TREE_OBJECTID 5ULL
60
61#define BTRFS_FIRST_FREE_OBJECTID 256ULL
62#define BTRFS_LAST_FREE_OBJECTID -256ULL
63#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
64
65#define BTRFS_FILE_EXTENT_INLINE 0
66#define BTRFS_FILE_EXTENT_REG 1
67#define BTRFS_FILE_EXTENT_PREALLOC 2
68
69#define BTRFS_MAX_LEVEL 8
70#define BTRFS_MAX_CHUNK_ENTRIES 256
71
72#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
73
74#define BTRFS_FT_REG_FILE 1
75#define BTRFS_FT_DIR 2
76#define BTRFS_FT_SYMLINK 7
77#define BTRFS_FT_XATTR 8
78#define BTRFS_FT_MAX 9
79
80#define BTRFS_COMPRESS_NONE 0
81#define BTRFS_COMPRESS_ZLIB 1
82#define BTRFS_COMPRESS_LZO 2
83
84#define ROOT_DIR_WORD 0x002f
85
86#include <pshpack1.h>
87
92};
93
95 /* these first four must match the super block */
97 __u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
98 __u64 bytenr; /* which block this node is supposed to live in */
100
101 /* allowed to be different from the super from here on down */
107};
108
113};
114
118};
119
124};
125
129};
130
132 /* the internal btrfs device id */
134
135 /* size of the device */
137
138 /* bytes used */
140
141 /* optimal io alignment for this device */
143
144 /* optimal io width for this device */
146
147 /* minimal io size for this device */
149
150 /* type and info about this device */
152
153 /* expected generation for this device */
155
156 /*
157 * starting byte of this partition on the device,
158 * to allow for stripe alignment in the future
159 */
161
162 /* grouping information for allocation decisions */
164
165 /* seek speed 0-100 where 100 is fastest */
167
168 /* bandwidth 0-100 where 100 is fastest */
170
171 /* btrfs generated uuid for this device */
173
174 /* uuid of FS who owns this device */
176};
177
182};
183
185 /* size of this chunk in bytes */
187
188 /* objectid of the root referencing this chunk */
190
193
194 /* optimal io alignment for this chunk */
196
197 /* optimal io width for this chunk */
199
200 /* minimal io size for this chunk */
202
203 /* 2^16 stripes is quite a lot, a second limit is the size of a single
204 * item in the btree
205 */
207
208 /* sub stripes only matter for raid10 */
211 /* additional stripes go here */
212};
213
217 /* name goes here */
218};
219
223};
224
226 /* nfs style generation number */
228 /* transid that last touched this inode */
239
240 /* modification sequence number for NFS */
242
243 /*
244 * a little future expansion, for more than this we can
245 * just grow the inode item and version it
246 */
252};
253
254
261};
262
276};
277
282};
283
285 /*
286 * transaction id that created this extent
287 */
289 /*
290 * max number of bytes to hold this extent in ram
291 * when we split a compressed extent we can't know how big
292 * each of the resulting pieces will be. So, this is
293 * an upper limit on the size of the extent in ram instead of
294 * an exact limit.
295 */
297
298 /*
299 * 32 bits for the various ways we might encode the data,
300 * including compression and encryption. If any of these
301 * are set to something a given disk format doesn't understand
302 * it is treated like an incompat flag for reading and writing,
303 * but not for stat.
304 */
307 __u16 other_encoding; /* spare for later use */
308
309 /* are we inline data or a real extent? */
311
312 /*
313 * disk space consumed by the extent, checksum blocks are included
314 * in these numbers
315 *
316 * At this offset in the structure, the inline extent data start.
317 */
320 /*
321 * the logical offset in file blocks (no csums)
322 * this extent record is for. This allows a file extent to point
323 * into the middle of an existing extent on disk, sharing it
324 * between two snapshots (useful if some bytes in the middle of the
325 * extent have changed
326 */
328 /*
329 * the logical number of file blocks (no csums included). This
330 * always reflects the size uncompressed and without encoding.
331 */
333
334};
335
338 /* the first 4 fields must match struct btrfs_header */
339 __u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
340 __u64 bytenr; /* this block number */
342
343 /* allowed to be different from the btrfs_header from here own down */
349
350 /* this will help find the new super based on the log root */
370
372
375
376 /* future expansion */
379};
380
381#include <poppack.h>
382
383union tree_buf {
387};
388
389/* remember how we get to a node/leaf */
394 /* remember whole last leaf */
396};
397
398/* store logical offset to physical offset mapping */
404};
405
410};
411
412typedef struct _BTRFS_INFO *PBTRFS_INFO;
413
414typedef struct {
420
421const DEVVTBL* BtrFsMount(ULONG DeviceId);
unsigned int ULONG32
Definition: basetsd.h:123
u16 __u16
Definition: btrfs.h:18
#define BTRFS_LABEL_SIZE
Definition: btrfs.h:35
u8 __u8
Definition: btrfs.h:17
ULONG32 u32
Definition: btrfs.h:14
const DEVVTBL * BtrFsMount(ULONG DeviceId)
Definition: btrfs.c:1297
struct btrfs_file_info * pbtrfs_file_info
ULONG64 u64
Definition: btrfs.h:15
#define BTRFS_UUID_SIZE
Definition: btrfs.h:37
struct _BTRFS_INFO * PBTRFS_INFO
Definition: btrfs.h:412
#define BTRFS_MAX_LEVEL
Definition: btrfs.h:69
UCHAR u8
Definition: btrfs.h:12
#define BTRFS_CSUM_SIZE
Definition: btrfs.h:33
#define BTRFS_FSID_SIZE
Definition: btrfs.h:34
u32 __u32
Definition: btrfs.h:19
#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE
Definition: btrfs.h:36
USHORT u16
Definition: btrfs.h:13
u64 __u64
Definition: btrfs.h:20
Definition: msctf.idl:550
unsigned __int64 ULONG64
Definition: imports.h:198
unsigned short USHORT
Definition: pedump.c:61
struct btrfs_chunk_map_item * map
Definition: btrfs.h:407
u32 map_length
Definition: btrfs.h:408
u32 cur_length
Definition: btrfs.h:409
__u32 sector_size
Definition: btrfs.h:201
__u64 length
Definition: btrfs.h:186
__u32 io_align
Definition: btrfs.h:195
__u64 stripe_len
Definition: btrfs.h:191
__u32 io_width
Definition: btrfs.h:198
__u64 owner
Definition: btrfs.h:189
__u64 type
Definition: btrfs.h:192
__u16 num_stripes
Definition: btrfs.h:206
__u16 sub_stripes
Definition: btrfs.h:209
__u8 bandwidth
Definition: btrfs.h:169
__u8 fsid[BTRFS_UUID_SIZE]
Definition: btrfs.h:175
__u32 io_align
Definition: btrfs.h:142
__u32 io_width
Definition: btrfs.h:145
__u32 sector_size
Definition: btrfs.h:148
__u64 total_bytes
Definition: btrfs.h:136
__u8 seek_speed
Definition: btrfs.h:166
__u64 devid
Definition: btrfs.h:133
__u64 type
Definition: btrfs.h:151
__u64 start_offset
Definition: btrfs.h:160
__u64 generation
Definition: btrfs.h:154
__u32 dev_group
Definition: btrfs.h:163
__u64 bytes_used
Definition: btrfs.h:139
__u16 data_len
Definition: btrfs.h:258
__u16 name_len
Definition: btrfs.h:259
__u8 type
Definition: btrfs.h:260
__u64 transid
Definition: btrfs.h:257
__u8 type
Definition: btrfs.h:90
__u64 offset
Definition: btrfs.h:91
__u64 objectid
Definition: btrfs.h:89
PBTRFS_INFO Volume
Definition: btrfs.h:418
u64 position
Definition: btrfs.h:416
__u64 generation
Definition: btrfs.h:103
__u32 nritems
Definition: btrfs.h:105
__u8 chunk_tree_uuid[BTRFS_UUID_SIZE]
Definition: btrfs.h:102
__u8 fsid[BTRFS_FSID_SIZE]
Definition: btrfs.h:97
__u64 flags
Definition: btrfs.h:99
__u64 owner
Definition: btrfs.h:104
__u64 bytenr
Definition: btrfs.h:98
__u8 level
Definition: btrfs.h:106
__u32 mode
Definition: btrfs.h:236
struct btrfs_timespec atime
Definition: btrfs.h:248
__u64 generation
Definition: btrfs.h:227
__u64 size
Definition: btrfs.h:230
__u64 sequence
Definition: btrfs.h:241
__u64 reserved[4]
Definition: btrfs.h:247
__u64 flags
Definition: btrfs.h:238
__u64 transid
Definition: btrfs.h:229
struct btrfs_timespec ctime
Definition: btrfs.h:249
__u64 rdev
Definition: btrfs.h:237
__u32 nlink
Definition: btrfs.h:233
struct btrfs_timespec otime
Definition: btrfs.h:251
struct btrfs_timespec mtime
Definition: btrfs.h:250
__u64 block_group
Definition: btrfs.h:232
__u64 nbytes
Definition: btrfs.h:231
__u64 index
Definition: btrfs.h:215
__u16 name_len
Definition: btrfs.h:216
__u32 size
Definition: btrfs.h:112
__u32 offset
Definition: btrfs.h:111
__u64 generation
Definition: btrfs.h:123
__u64 blockptr
Definition: btrfs.h:122
struct btrfs_item items[]
Definition: btrfs.h:117
struct btrfs_key_ptr ptrs[]
Definition: btrfs.h:128
u64 offsets[BTRFS_MAX_LEVEL]
Definition: btrfs.h:391
int slots[BTRFS_MAX_LEVEL]
Definition: btrfs.h:393
int itemsnr[BTRFS_MAX_LEVEL]
Definition: btrfs.h:392
union tree_buf * tree_buf
Definition: btrfs.h:395
struct btrfs_disk_key drop_progress
Definition: btrfs.h:273
__u64 last_snapshot
Definition: btrfs.h:270
__u64 bytenr
Definition: btrfs.h:267
__u32 refs
Definition: btrfs.h:272
__u64 flags
Definition: btrfs.h:271
__u64 byte_limit
Definition: btrfs.h:268
__u64 root_dirid
Definition: btrfs.h:266
__u64 generation
Definition: btrfs.h:265
__u64 bytes_used
Definition: btrfs.h:269
__u8 drop_level
Definition: btrfs.h:274
__u8 level
Definition: btrfs.h:275
__u16 name_len
Definition: btrfs.h:281
__u64 sequence
Definition: btrfs.h:280
__u64 dirid
Definition: btrfs.h:279
__u64 offset
Definition: btrfs.h:180
__u8 dev_uuid[BTRFS_UUID_SIZE]
Definition: btrfs.h:181
__u64 devid
Definition: btrfs.h:179
__u64 uuid_tree_generation
Definition: btrfs.h:374
__u32 __unused_leafsize
Definition: btrfs.h:358
struct btrfs_dev_item dev_item
Definition: btrfs.h:369
__u64 incompat_flags
Definition: btrfs.h:364
__u64 generation
Definition: btrfs.h:345
__u32 sys_chunk_array_size
Definition: btrfs.h:360
__u64 reserved[30]
Definition: btrfs.h:377
__u64 log_root_transid
Definition: btrfs.h:351
__u64 cache_generation
Definition: btrfs.h:373
__u64 bytes_used
Definition: btrfs.h:353
__u8 fsid[BTRFS_FSID_SIZE]
Definition: btrfs.h:339
__u64 root_dir_objectid
Definition: btrfs.h:354
__u16 csum_type
Definition: btrfs.h:365
__u8 chunk_root_level
Definition: btrfs.h:367
__u64 compat_flags
Definition: btrfs.h:362
__u32 stripesize
Definition: btrfs.h:359
__u64 total_bytes
Definition: btrfs.h:352
__u8 log_root_level
Definition: btrfs.h:368
__u64 chunk_root
Definition: btrfs.h:347
__u8 root_level
Definition: btrfs.h:366
__u32 sectorsize
Definition: btrfs.h:356
__u64 num_devices
Definition: btrfs.h:355
__u64 log_root
Definition: btrfs.h:348
__u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]
Definition: btrfs.h:378
__u32 nodesize
Definition: btrfs.h:357
__u64 chunk_root_generation
Definition: btrfs.h:361
__u64 compat_ro_flags
Definition: btrfs.h:363
char label[BTRFS_LABEL_SIZE]
Definition: btrfs.h:371
__u64 bytenr
Definition: btrfs.h:340
__u64 sec
Definition: btrfs.h:221
__u32 nsec
Definition: btrfs.h:222
Definition: ffs.h:52
Definition: fs.h:78
Definition: copy.c:22
Definition: write.c:113
Definition: fs.h:25
uint32_t ULONG
Definition: typedefs.h:59
Definition: dlist.c:348
struct btrfs_leaf leaf
Definition: btrfs.h:386
unsigned char UCHAR
Definition: xmlstorage.h:181