btrfs_diskformat/extent/block_group_item.rs
1use {
2 bitflags::bitflags,
3 byteorder::LE,
4 static_assertions::const_assert_eq,
5 zerocopy::{AsBytes, FromBytes, Unaligned, U64},
6};
7
8/// Defines the location, properties, and usage of a block group.
9#[derive(Copy, Clone, Debug, AsBytes, FromBytes, Unaligned)]
10#[repr(C, packed)]
11pub struct BlockGroupItem {
12 /// The space used, in bytes, in this block group.
13 pub used: U64<LE>,
14
15 /// The object ID of the chunk backing this block group.
16 pub chunk_objectid: U64<LE>,
17
18 /// Flags indicating allocation type and replication policy.
19 pub flags: U64<LE>,
20}
21const_assert_eq!(core::mem::size_of::<BlockGroupItem>(), 24);
22
23bitflags! {
24 /// The type of storage a block group allows.
25 ///
26 /// [Data] and [metadata] chunks may be mixed within a [block group], as indicated by its
27 /// [flags]. However, [system] chunks cannot be mixed.
28 ///
29 /// [Data]: AllocationType::DATA
30 /// [metadata]: AllocationType::METADATA
31 /// [block group]: BlockGroupItem
32 /// [flags]: BlockGroupItem::flags
33 /// [SYSTEM]: AllocationType::SYSTEM
34 pub struct AllocationType: u64 {
35 const DATA = 0x1;
36 const SYSTEM = 0x2;
37 const METADATA = 0x4;
38 }
39}
40
41bitflags! {
42 /// The replication policy a [block group] implements.
43 ///
44 /// Only one policy may be set for a given group.
45 ///
46 /// [block group]: BlockGroupItem
47 pub struct ReplicationPolicy: u64 {
48 const RAID0 = 0x8;
49 const RAID1 = 0x10;
50 const DUP = 0x20;
51 const RAID10 = 0x40;
52 const RAID5 = 0x80;
53 const RAID6 = 0x100;
54 const RAID1C3 = 0x200;
55 const RAID1C4 = 0x400;
56 }
57}