btrfs_no_std/extent/extent_inline_ref.rs
1use {
2 byteorder::LE,
3 num_enum::{IntoPrimitive, TryFromPrimitive},
4 static_assertions::const_assert_eq,
5 strum::EnumIter,
6 zerocopy::{AsBytes, FromBytes, Unaligned, U64},
7};
8
9/// This acts as a header for different types of inline extent back references inside extent or
10/// metadata items.
11#[derive(Copy, Clone, Debug, AsBytes, FromBytes, Unaligned)]
12#[repr(C, packed)]
13pub struct ExtentInlineRef {
14 /// The type of reference, which corresponds with a value from [`ExtentInlineRefType`].
15 /// This field also determines the semantic importance of [`offset`].
16 ///
17 /// [`ExtentInlineRefType`]: crate::ExtentInlineRefType
18 /// [`offset`]: ExtentInlineRef::offset
19 pub r#type: u8,
20
21 /// This field has different functions depending on the value of [`type`].
22 ///
23 /// [`type`]: ExtentInlineRef::type
24 pub offset: U64<LE>,
25}
26const_assert_eq!(core::mem::size_of::<ExtentInlineRef>(), 9);
27
28/// The type of [`ExtentInlineRef`].
29///
30/// [`ExtentInlineRef`]: crate::ExtentInlineRef
31#[derive(Copy, Clone, Debug, Hash, PartialEq, EnumIter, IntoPrimitive, TryFromPrimitive)]
32#[repr(u8)]
33pub enum ExtentInlineRefType {
34 /// The reference is indirect for a tree block.
35 ///
36 /// [`offset`] contains the object ID of the tree root that allocated the block.
37 ///
38 /// [`offset`]: ExtentInlineRef::offset
39 TreeBlockRef = 176,
40
41 /// The reference is shared for a tree block.
42 ///
43 /// [`offset`] contains the byte offset of the node one level above in the tree where this block
44 /// is located.
45 ///
46 /// [`offset`]: ExtentInlineRef::offset
47 SharedBlockRef = 182,
48
49 /// The reference is indirect for a data extent.
50 ///
51 /// An `ExtentDataRef` is located immediately after the [`type`] field and overlaps the unused
52 /// [`offset`] field.
53 ///
54 /// [`type`]: ExtentInlineRef::type
55 /// [`offset`]: ExtentInlineRef::offset
56 ExtentDataRef = 178,
57
58 /// The reference is shared for a data extent.
59 ///
60 /// [`offset`] contains the byte offset of the metadata that contains the extent data item that
61 /// describes this extent.
62 ///
63 /// Immediately following [`offset`] (and the end of [`ExtentInlineRef`] structure) is a
64 /// [`SharedDataRef`] that contains the reference count.
65 ///
66 /// [`offset`]: ExtentInlineRef::offset
67 /// [`ExtentInlineRef`]: crate::ExtentInlineRef
68 /// [`SharedDataRef`]: crate::SharedDataRef
69 SharedDataRef = 184,
70}