ReactOS 0.4.16-dev-1946-g52006dd
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_UNKNOWN 0
75#define BTRFS_FT_REG_FILE 1
76#define BTRFS_FT_DIR 2
77#define BTRFS_FT_SYMLINK 7
78#define BTRFS_FT_XATTR 8
79#define BTRFS_FT_MAX 9
80
81#define BTRFS_COMPRESS_NONE 0
82#define BTRFS_COMPRESS_ZLIB 1
83#define BTRFS_COMPRESS_LZO 2
84
85#define ROOT_DIR_WORD 0x002f
86
87#include <pshpack1.h>
88
93};
94
96 /* these first four must match the super block */
98 __u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
99 __u64 bytenr; /* which block this node is supposed to live in */
101
102 /* allowed to be different from the super from here on down */
108};
109
114};
115
119};
120
125};
126
130};
131
133 /* the internal btrfs device id */
135
136 /* size of the device */
138
139 /* bytes used */
141
142 /* optimal io alignment for this device */
144
145 /* optimal io width for this device */
147
148 /* minimal io size for this device */
150
151 /* type and info about this device */
153
154 /* expected generation for this device */
156
157 /*
158 * starting byte of this partition on the device,
159 * to allow for stripe alignment in the future
160 */
162
163 /* grouping information for allocation decisions */
165
166 /* seek speed 0-100 where 100 is fastest */
168
169 /* bandwidth 0-100 where 100 is fastest */
171
172 /* btrfs generated uuid for this device */
174
175 /* uuid of FS who owns this device */
177};
178
183};
184
186 /* size of this chunk in bytes */
188
189 /* objectid of the root referencing this chunk */
191
194
195 /* optimal io alignment for this chunk */
197
198 /* optimal io width for this chunk */
200
201 /* minimal io size for this chunk */
203
204 /* 2^16 stripes is quite a lot, a second limit is the size of a single
205 * item in the btree
206 */
208
209 /* sub stripes only matter for raid10 */
212 /* additional stripes go here */
213};
214
218 /* name goes here */
219};
220
224};
225
227 /* nfs style generation number */
229 /* transid that last touched this inode */
240
241 /* modification sequence number for NFS */
243
244 /*
245 * a little future expansion, for more than this we can
246 * just grow the inode item and version it
247 */
253};
254
255
262};
263
277};
278
283};
284
286 /*
287 * transaction id that created this extent
288 */
290 /*
291 * max number of bytes to hold this extent in ram
292 * when we split a compressed extent we can't know how big
293 * each of the resulting pieces will be. So, this is
294 * an upper limit on the size of the extent in ram instead of
295 * an exact limit.
296 */
298
299 /*
300 * 32 bits for the various ways we might encode the data,
301 * including compression and encryption. If any of these
302 * are set to something a given disk format doesn't understand
303 * it is treated like an incompat flag for reading and writing,
304 * but not for stat.
305 */
308 __u16 other_encoding; /* spare for later use */
309
310 /* are we inline data or a real extent? */
312
313 /*
314 * disk space consumed by the extent, checksum blocks are included
315 * in these numbers
316 *
317 * At this offset in the structure, the inline extent data start.
318 */
321 /*
322 * the logical offset in file blocks (no csums)
323 * this extent record is for. This allows a file extent to point
324 * into the middle of an existing extent on disk, sharing it
325 * between two snapshots (useful if some bytes in the middle of the
326 * extent have changed
327 */
329 /*
330 * the logical number of file blocks (no csums included). This
331 * always reflects the size uncompressed and without encoding.
332 */
334
335};
336
339 /* the first 4 fields must match struct btrfs_header */
340 __u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
341 __u64 bytenr; /* this block number */
343
344 /* allowed to be different from the btrfs_header from here own down */
350
351 /* this will help find the new super based on the log root */
371
373
376
377 /* future expansion */
380};
381
382#include <poppack.h>
383
384union tree_buf {
388};
389
390/* remember how we get to a node/leaf */
395 /* remember whole last leaf */
397};
398
399/* store logical offset to physical offset mapping */
405};
406
411};
412
413typedef struct _BTRFS_INFO *PBTRFS_INFO;
414
415typedef struct {
424
427 _In_ ULONG DeviceId);
428
429const DEVVTBL* BtrFsMount(ULONG DeviceId);
unsigned int ULONG32
Definition: basetsd.h:117
u16 __u16
Definition: btrfs.h:18
ULONGLONG BtrFsGetVolumeSize(_In_ ULONG DeviceId)
Returns the size of the BTRFS volume laid on the storage media device opened via DeviceId.
Definition: btrfs.c:1342
#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:1363
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:413
#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:532
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
unsigned __int64 ULONG64
Definition: imports.h:198
#define _In_
Definition: no_sal2.h:158
unsigned short USHORT
Definition: pedump.c:61
struct btrfs_chunk_map_item * map
Definition: btrfs.h:408
u32 map_length
Definition: btrfs.h:409
u32 cur_length
Definition: btrfs.h:410
__u32 sector_size
Definition: btrfs.h:202
__u64 length
Definition: btrfs.h:187
__u32 io_align
Definition: btrfs.h:196
__u64 stripe_len
Definition: btrfs.h:192
__u32 io_width
Definition: btrfs.h:199
__u64 owner
Definition: btrfs.h:190
__u64 type
Definition: btrfs.h:193
__u16 num_stripes
Definition: btrfs.h:207
__u16 sub_stripes
Definition: btrfs.h:210
__u8 bandwidth
Definition: btrfs.h:170
__u8 fsid[BTRFS_UUID_SIZE]
Definition: btrfs.h:176
__u32 io_align
Definition: btrfs.h:143
__u32 io_width
Definition: btrfs.h:146
__u32 sector_size
Definition: btrfs.h:149
__u64 total_bytes
Definition: btrfs.h:137
__u8 seek_speed
Definition: btrfs.h:167
__u64 devid
Definition: btrfs.h:134
__u64 type
Definition: btrfs.h:152
__u64 start_offset
Definition: btrfs.h:161
__u64 generation
Definition: btrfs.h:155
__u32 dev_group
Definition: btrfs.h:164
__u64 bytes_used
Definition: btrfs.h:140
__u16 data_len
Definition: btrfs.h:259
__u16 name_len
Definition: btrfs.h:260
__u8 type
Definition: btrfs.h:261
__u64 transid
Definition: btrfs.h:258
__u8 type
Definition: btrfs.h:91
__u64 offset
Definition: btrfs.h:92
__u64 objectid
Definition: btrfs.h:90
UCHAR Attributes
Definition: btrfs.h:421
PBTRFS_INFO Volume
Definition: btrfs.h:419
ULONG FileNameLength
Definition: btrfs.h:420
u64 position
Definition: btrfs.h:417
__u64 generation
Definition: btrfs.h:104
__u32 nritems
Definition: btrfs.h:106
__u8 chunk_tree_uuid[BTRFS_UUID_SIZE]
Definition: btrfs.h:103
__u8 fsid[BTRFS_FSID_SIZE]
Definition: btrfs.h:98
__u64 flags
Definition: btrfs.h:100
__u64 owner
Definition: btrfs.h:105
__u64 bytenr
Definition: btrfs.h:99
__u8 level
Definition: btrfs.h:107
__u32 mode
Definition: btrfs.h:237
struct btrfs_timespec atime
Definition: btrfs.h:249
__u64 generation
Definition: btrfs.h:228
__u64 size
Definition: btrfs.h:231
__u64 sequence
Definition: btrfs.h:242
__u64 reserved[4]
Definition: btrfs.h:248
__u64 flags
Definition: btrfs.h:239
__u64 transid
Definition: btrfs.h:230
struct btrfs_timespec ctime
Definition: btrfs.h:250
__u64 rdev
Definition: btrfs.h:238
__u32 nlink
Definition: btrfs.h:234
struct btrfs_timespec otime
Definition: btrfs.h:252
struct btrfs_timespec mtime
Definition: btrfs.h:251
__u64 block_group
Definition: btrfs.h:233
__u64 nbytes
Definition: btrfs.h:232
__u64 index
Definition: btrfs.h:216
__u16 name_len
Definition: btrfs.h:217
__u32 size
Definition: btrfs.h:113
__u32 offset
Definition: btrfs.h:112
__u64 generation
Definition: btrfs.h:124
__u64 blockptr
Definition: btrfs.h:123
struct btrfs_item items[]
Definition: btrfs.h:118
struct btrfs_key_ptr ptrs[]
Definition: btrfs.h:129
u64 offsets[BTRFS_MAX_LEVEL]
Definition: btrfs.h:392
int slots[BTRFS_MAX_LEVEL]
Definition: btrfs.h:394
int itemsnr[BTRFS_MAX_LEVEL]
Definition: btrfs.h:393
union tree_buf * tree_buf
Definition: btrfs.h:396
struct btrfs_disk_key drop_progress
Definition: btrfs.h:274
__u64 last_snapshot
Definition: btrfs.h:271
__u64 bytenr
Definition: btrfs.h:268
__u32 refs
Definition: btrfs.h:273
__u64 flags
Definition: btrfs.h:272
__u64 byte_limit
Definition: btrfs.h:269
__u64 root_dirid
Definition: btrfs.h:267
__u64 generation
Definition: btrfs.h:266
__u64 bytes_used
Definition: btrfs.h:270
__u8 drop_level
Definition: btrfs.h:275
__u8 level
Definition: btrfs.h:276
__u16 name_len
Definition: btrfs.h:282
__u64 sequence
Definition: btrfs.h:281
__u64 dirid
Definition: btrfs.h:280
__u64 offset
Definition: btrfs.h:181
__u8 dev_uuid[BTRFS_UUID_SIZE]
Definition: btrfs.h:182
__u64 devid
Definition: btrfs.h:180
__u64 uuid_tree_generation
Definition: btrfs.h:375
__u32 __unused_leafsize
Definition: btrfs.h:359
struct btrfs_dev_item dev_item
Definition: btrfs.h:370
__u64 incompat_flags
Definition: btrfs.h:365
__u64 generation
Definition: btrfs.h:346
__u32 sys_chunk_array_size
Definition: btrfs.h:361
__u64 reserved[30]
Definition: btrfs.h:378
__u64 log_root_transid
Definition: btrfs.h:352
__u64 cache_generation
Definition: btrfs.h:374
__u64 bytes_used
Definition: btrfs.h:354
__u8 fsid[BTRFS_FSID_SIZE]
Definition: btrfs.h:340
__u64 root_dir_objectid
Definition: btrfs.h:355
__u16 csum_type
Definition: btrfs.h:366
__u8 chunk_root_level
Definition: btrfs.h:368
__u64 compat_flags
Definition: btrfs.h:363
__u32 stripesize
Definition: btrfs.h:360
__u64 total_bytes
Definition: btrfs.h:353
__u8 log_root_level
Definition: btrfs.h:369
__u64 chunk_root
Definition: btrfs.h:348
__u8 root_level
Definition: btrfs.h:367
__u32 sectorsize
Definition: btrfs.h:357
__u64 num_devices
Definition: btrfs.h:356
__u64 log_root
Definition: btrfs.h:349
__u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]
Definition: btrfs.h:379
__u32 nodesize
Definition: btrfs.h:358
__u64 chunk_root_generation
Definition: btrfs.h:362
__u64 compat_ro_flags
Definition: btrfs.h:364
char label[BTRFS_LABEL_SIZE]
Definition: btrfs.h:372
__u64 bytenr
Definition: btrfs.h:341
__u64 sec
Definition: btrfs.h:222
__u32 nsec
Definition: btrfs.h:223
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
uint64_t ULONGLONG
Definition: typedefs.h:67
Definition: dlist.c:348
struct btrfs_leaf leaf
Definition: btrfs.h:387
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175