btrfs_no_std/chunk/chunk.rs
1use {
2 crate::Stripe,
3 byteorder::LE,
4 static_assertions::const_assert_eq,
5 zerocopy::{AsBytes, FromBytes, Unaligned, U16, U32, U64},
6};
7
8/// This structure contains the mapping from a virtualized usable byte range within the backing
9/// storage to a set of one or more stripes on individual backing devices. In addition to the
10/// mapping, hints on optimal I/O parameters for this chunk. It is associated with `CHUNK_ITEM`.
11///
12/// Although the structure definition only contains one stripe member, `CHUNK_ITEM` contain as
13/// many struct [`Stripe`] structures as specified in the [`num_stripes`] and [`sub_stripes`]
14/// fields.
15///
16/// [`Stripe`]: crate::Stripe
17/// [`num_stripes`]: Chunk::num_stripes
18/// [`sub_stripes`]: Chunk::sub_stripes
19#[derive(Copy, Clone, Debug, AsBytes, FromBytes, Unaligned)]
20#[repr(C, packed)]
21pub struct Chunk {
22 /// The size of this chunk, in bytes.
23 pub length: U64<LE>,
24
25 /// The object ID of the root referencing this chunk. This is always the ID of an extent root.
26 pub owner: U64<LE>,
27
28 /// The replication stripe length.
29 pub stripe_len: U64<LE>,
30
31 /// Flags indicating allocation type and replication policy.
32 pub r#type: U64<LE>,
33
34 /// The optimal I/O alignment for this chunk.
35 pub io_align: U32<LE>,
36
37 /// The optimal I/O width for this chunk.
38 pub io_width: U32<LE>,
39
40 /// The minimal I/O size for this chunk.
41 pub sector_size: U32<LE>,
42
43 /// The number of replication stripes.
44 pub num_stripes: U16<LE>,
45
46 /// The number of sub-stripes. This is only used for RAID-10.
47 pub sub_stripes: U16<LE>,
48
49 /// The first of one or more stripes that map to device extents.
50 pub stripe: Stripe,
51}
52const_assert_eq!(core::mem::size_of::<Chunk>(), 80);