2 * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
3 * Distributed under the terms of the MIT License.
9 #include "system_dependencies.h"
12 typedef uint64 fileblock_t
; // file block number
13 typedef uint64 fsblock_t
; // filesystem block number
15 #define BTRFS_SUPER_BLOCK_OFFSET 0x10000
16 #define BTRFS_NUM_ROOT_BACKUPS 4
19 struct btrfs_backup_roots
{
21 uint64 root_generation
;
23 uint64 chunk_root_generation
;
25 uint64 extent_root_generation
;
27 uint64 fs_root_generation
;
29 uint64 device_root_generation
;
31 uint64 csum_root_generation
;
37 uint8 chunk_root_level
;
38 uint8 extent_root_level
;
40 uint8 device_root_level
;
41 uint8 csum_root_level
;
44 uint64
Root() const { return B_LENDIAN_TO_HOST_INT64(root
); }
45 uint64
RootGen() const
46 { return B_LENDIAN_TO_HOST_INT64(root_generation
); }
47 uint64
ChunkRoot() const { return B_LENDIAN_TO_HOST_INT64(chunk_root
); }
48 uint64
ChunkRootGen() const
49 { return B_LENDIAN_TO_HOST_INT64(chunk_root_generation
); }
50 uint64
ExtentRoot() const { return B_LENDIAN_TO_HOST_INT64(extent_root
); }
51 uint64
ExtentRootGen() const
52 { return B_LENDIAN_TO_HOST_INT64(extent_root_generation
); }
53 uint64
FSRoot() const { return B_LENDIAN_TO_HOST_INT64(fs_root
); }
54 uint64
FSRootGen() const
55 { return B_LENDIAN_TO_HOST_INT64(fs_root_generation
); }
56 uint64
DeviceRoot() const { return B_LENDIAN_TO_HOST_INT64(device_root
); }
57 uint64
DeviceRootGen() const
58 { return B_LENDIAN_TO_HOST_INT64(device_root_generation
); }
59 uint64
CSumRoot() const { return B_LENDIAN_TO_HOST_INT64(csum_root
); }
60 uint64
CSumRootGen() const
61 { return B_LENDIAN_TO_HOST_INT64(csum_root_generation
); }
62 uint8
RootLevel() const { return root_level
; }
63 uint8
ChunkRootLevel() const { return chunk_root_level
; }
64 uint8
ExtentRootLevel() const { return extent_root_level
; }
65 uint8
FSRootLevel() const { return fs_root_level
; }
66 uint8
DeviceRootLevel() const { return device_root_level
; }
67 uint8
CSumRootLevel() const { return csum_root_level
; }
76 uint64
ObjectID() const { return B_LENDIAN_TO_HOST_INT64(object_id
); }
77 uint8
Type() const { return type
; }
78 uint64
Offset() const { return B_LENDIAN_TO_HOST_INT64(offset
); }
79 void SetObjectID(uint64 id
) { object_id
= B_HOST_TO_LENDIAN_INT64(id
); }
80 void SetType(uint8 key_type
) { type
= key_type
; }
81 void SetOffset(uint64 off
) { offset
= B_HOST_TO_LENDIAN_INT64(off
); }
82 int32
Compare(const btrfs_key
& key
) const;
83 //implemented in BTree.cpp
87 struct btrfs_timespec
{
96 uint64 logical_address
;
98 uint8 chunk_tree_uuid
[16];
103 uint64
LogicalAddress() const
104 { return B_LENDIAN_TO_HOST_INT64(logical_address
); }
105 uint64
Flags() const { return B_LENDIAN_TO_HOST_INT64(flags
); }
106 uint64
Generation() const
107 { return B_LENDIAN_TO_HOST_INT64(generation
); }
109 { return B_LENDIAN_TO_HOST_INT64(owner
); }
110 uint32
ItemCount() const
111 { return B_LENDIAN_TO_HOST_INT32(item_count
); }
112 uint8
Level() const { return level
; }
118 uint64 logical_address
;
120 uint64
LogicalAddress() const
121 { return B_LENDIAN_TO_HOST_INT64(logical_address
); }
122 uint64
Generation() const
123 { return B_LENDIAN_TO_HOST_INT64(generation
); }
131 uint32
Offset() const
132 { return B_LENDIAN_TO_HOST_INT32(offset
); }
134 { return B_LENDIAN_TO_HOST_INT32(size
); }
138 struct btrfs_stream
{
141 btrfs_entry entries
[0];
142 btrfs_index index
[0];
147 struct btrfs_stripe
{
150 uint8 device_uuid
[16];
151 uint64
DeviceID() const { return B_LENDIAN_TO_HOST_INT64(device_id
); }
152 uint64
Offset() const { return B_LENDIAN_TO_HOST_INT64(offset
); }
159 uint64 stripe_length
;
166 btrfs_stripe stripes
[0];
167 uint64
Length() const { return B_LENDIAN_TO_HOST_INT64(length
); }
168 uint64
Owner() const { return B_LENDIAN_TO_HOST_INT64(owner
); }
169 uint64
StripeLength() const
170 { return B_LENDIAN_TO_HOST_INT64(stripe_length
); }
171 uint64
Type() const { return B_LENDIAN_TO_HOST_INT64(type
); }
172 uint32
IOAlign() const { return B_LENDIAN_TO_HOST_INT32(io_align
); }
173 uint32
IOWidth() const { return B_LENDIAN_TO_HOST_INT32(io_width
); }
174 uint32
SectorSize() const
175 { return B_LENDIAN_TO_HOST_INT32(sector_size
); }
176 uint16
StripeCount() const
177 { return B_LENDIAN_TO_HOST_INT16(stripe_count
); }
178 uint16
SubStripes() const
179 { return B_LENDIAN_TO_HOST_INT16(sub_stripes
); }
183 struct btrfs_device
{
201 struct btrfs_super_block
{
211 uint64 log_root_transaction_id
;
214 uint64 root_dir_object_id
;
220 uint32 system_chunk_array_size
;
221 uint64 chunk_root_generation
;
223 uint64 readonly_flags
;
224 uint64 incompat_flags
;
225 uint16 checksum_type
;
227 uint8 chunk_root_level
;
228 uint8 log_root_level
;
232 uint8 system_chunk_array
[2048];
233 btrfs_backup_roots backup_roots
[BTRFS_NUM_ROOT_BACKUPS
];
236 // implemented in Volume.cpp
237 uint64
TotalSize() const { return B_LENDIAN_TO_HOST_INT64(total_size
); }
238 uint32
BlockSize() const { return B_LENDIAN_TO_HOST_INT32(node_size
); }
239 uint32
SectorSize() const { return B_LENDIAN_TO_HOST_INT32(sector_size
); }
240 uint64
RootDirObjectID() const
241 { return B_LENDIAN_TO_HOST_INT64(root_dir_object_id
); }
242 uint64
Generation() const
243 { return B_LENDIAN_TO_HOST_INT64(generation
); }
245 { return B_LENDIAN_TO_HOST_INT64(root
); }
246 uint64
ChunkRoot() const
247 { return B_LENDIAN_TO_HOST_INT64(chunk_root
); }
248 uint64
LogRoot() const
249 { return B_LENDIAN_TO_HOST_INT64(log_root
); }
250 uint8
ChunkRootLevel() const { return chunk_root_level
; }
256 uint64 transaction_id
;
268 btrfs_timespec access_time
;
269 btrfs_timespec change_time
;
270 btrfs_timespec modification_time
;
271 btrfs_timespec creation_time
;
272 uint64
Generation() const { return B_LENDIAN_TO_HOST_INT64(generation
); }
273 uint64
Size() const { return B_LENDIAN_TO_HOST_INT64(size
); }
274 uint32
UserID() const { return B_LENDIAN_TO_HOST_INT32(uid
); }
275 uint32
GroupID() const { return B_LENDIAN_TO_HOST_INT32(gid
); }
276 uint32
Mode() const { return B_LENDIAN_TO_HOST_INT32(mode
); }
277 uint64
Flags() const { return B_LENDIAN_TO_HOST_INT64(flags
); }
278 uint64
Sequence() const { return B_LENDIAN_TO_HOST_INT64(sequence
); }
279 static void _DecodeTime(struct timespec
& timespec
,
280 const btrfs_timespec
& time
)
282 timespec
.tv_sec
= B_LENDIAN_TO_HOST_INT64(time
.seconds
);
283 timespec
.tv_nsec
= B_LENDIAN_TO_HOST_INT32(time
.nanoseconds
);
285 void GetAccessTime(struct timespec
& timespec
) const
286 { _DecodeTime(timespec
, access_time
); }
287 void GetChangeTime(struct timespec
& timespec
) const
288 { _DecodeTime(timespec
, change_time
); }
289 void GetModificationTime(struct timespec
& timespec
) const
290 { _DecodeTime(timespec
, modification_time
); }
291 void GetCreationTime(struct timespec
& timespec
) const
292 { _DecodeTime(timespec
, creation_time
); }
296 struct btrfs_inode_ref
{
301 uint8
Index() const { return index
; }
302 uint16
NameLength() const { return B_LENDIAN_TO_HOST_INT16(name_length
); }
310 uint64 logical_address
;
313 uint64 last_snapshot
;
316 btrfs_key drop_progress
;
319 uint64
Generation() const
320 { return B_LENDIAN_TO_HOST_INT64(generation
); }
321 uint64
LogicalAddress() const
322 { return B_LENDIAN_TO_HOST_INT64(logical_address
); }
326 struct btrfs_dir_entry
{
328 uint64 transaction_id
;
332 uint16
DataLength() const { return B_LENDIAN_TO_HOST_INT16(data_length
); }
333 uint16
NameLength() const { return B_LENDIAN_TO_HOST_INT16(name_length
); }
334 ino_t
InodeID() const { return location
.ObjectID(); }
335 uint16
Length() const
336 { return sizeof(*this) + NameLength() + DataLength(); }
340 struct btrfs_extent_data
{
351 uint64 extent_offset
;
354 uint8 inline_data
[0];
356 uint64
Generation() const
357 { return B_LENDIAN_TO_HOST_INT64(generation
); }
358 uint64
MemoryBytes() const
359 { return B_LENDIAN_TO_HOST_INT64(memory_size
); }
360 uint8
Compression() const { return compression
; }
361 uint8
Type() const { return type
; }
362 uint64
DiskOffset() const
363 { return B_LENDIAN_TO_HOST_INT64(disk_offset
); }
364 uint64
DiskSize() const
365 { return B_LENDIAN_TO_HOST_INT64(disk_size
); }
366 uint64
ExtentOffset() const
367 { return B_LENDIAN_TO_HOST_INT64(extent_offset
); }
369 { return B_LENDIAN_TO_HOST_INT64(size
); }
373 struct btrfs_block_group
{
375 uint64 chunk_object_id
;
378 uint64
UsedSpace() const { return B_LENDIAN_TO_HOST_INT64(used_space
); }
379 uint64
ChunkObjectID() const
380 { return B_HOST_TO_LENDIAN_INT64(chunk_object_id
); }
381 uint64
Flags() const { return B_LENDIAN_TO_HOST_INT64(flags
); }
385 struct btrfs_extent
{
390 uint64
RefCount() const { return B_LENDIAN_TO_HOST_INT64(refs
); }
391 uint64
Generation() const { return B_LENDIAN_TO_HOST_INT64(generation
); }
392 uint64
Flags() const { return B_LENDIAN_TO_HOST_INT64(flags
); }
396 struct btrfs_extent_inline_ref
{
400 uint8
Type() const { return type
; }
401 uint64
Offset() const { return B_LENDIAN_TO_HOST_INT64(offset
); }
405 struct btrfs_extent_data_ref
{
411 uint64
RootID() const { return B_LENDIAN_TO_HOST_INT64(root_id
); }
412 uint64
InodeID() const { return B_LENDIAN_TO_HOST_INT64(inode_id
); }
413 uint64
Offset() const { return B_LENDIAN_TO_HOST_INT64(offset
);}
414 uint32
RefCount() const { return B_LENDIAN_TO_HOST_INT32(ref_count
); }
418 #define BTRFS_SUPER_BLOCK_MAGIC "_BHRfS_M"
419 #define BTRFS_FIRST_SUBVOLUME 256
421 #define BTRFS_OBJECT_ID_ROOT_TREE 1
422 #define BTRFS_OBJECT_ID_EXTENT_TREE 2
423 #define BTRFS_OBJECT_ID_CHUNK_TREE 3
424 #define BTRFS_OBJECT_ID_DEV_TREE 4
425 #define BTRFS_OBJECT_ID_FS_TREE 5
426 #define BTRFS_OBJECT_ID_ROOT_TREE_DIR 6
427 #define BTRFS_OBJECT_ID_CHECKSUM_TREE 7
428 #define BTRFS_OBJECT_ID_FIRST_CHUNK_TREE 256
430 #define BTRFS_KEY_TYPE_ANY 0
431 #define BTRFS_KEY_TYPE_INODE_ITEM 1
432 #define BTRFS_KEY_TYPE_INODE_REF 12
433 #define BTRFS_KEY_TYPE_XATTR_ITEM 24
434 #define BTRFS_KEY_TYPE_DIR_ITEM 84
435 #define BTRFS_KEY_TYPE_DIR_INDEX 96
436 #define BTRFS_KEY_TYPE_EXTENT_DATA 108
437 #define BTRFS_KEY_TYPE_ROOT_ITEM 132
438 #define BTRFS_KEY_TYPE_EXTENT_ITEM 168
439 #define BTRFS_KEY_TYPE_METADATA_ITEM 169
440 #define BTRFS_KEY_TYPE_EXTENT_DATA_REF 178
441 #define BTRFS_KEY_TYPE_BLOCKGROUP_ITEM 192
442 #define BTRFS_KEY_TYPE_CHUNK_ITEM 228
444 #define BTRFS_EXTENT_COMPRESS_NONE 0
445 #define BTRFS_EXTENT_COMPRESS_ZLIB 1
446 #define BTRFS_EXTENT_COMPRESS_LZO 2
447 #define BTRFS_EXTENT_DATA_INLINE 0
448 #define BTRFS_EXTENT_DATA_REGULAR 1
449 #define BTRFS_EXTENT_DATA_PRE 2
450 #define BTRFS_EXTENT_FLAG_DATA 1
451 #define BTRFS_EXTENT_FLAG_TREE_BLOCK 2
453 #define BTRFS_BLOCKGROUP_FLAG_DATA 1
454 #define BTRFS_BLOCKGROUP_FLAG_SYSTEM 2
455 #define BTRFS_BLOCKGROUP_FLAG_METADA 4
456 #define BTRFS_BLOCKGROUP_FLAG_RAID0 8
457 #define BTRFS_BLOCKGROUP_FLAG_RAID1 16
458 #define BTRFS_BLOCKGROUP_FLAG_DUP 32
459 #define BTRFS_BLOCKGROUP_FLAG_RAID10 64
460 #define BTRFS_BLOCKGROUP_FLAG_RAID5 128
461 #define BTRFS_BLOCKGROUP_FLAG_RAID6 256
462 #define BTRFS_BLOCKGROUP_FLAG_MASK 511
466 bigtime_t last_notification
;
472 #define BTRFS_OPEN_MODE_USER_MASK 0x7fffffff
474 extern fs_volume_ops gBtrfsVolumeOps
;
475 extern fs_vnode_ops gBtrfsVnodeOps
;