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