btrfs_diskformat/core/
node.rs1use crate::{Key, UuidBytes, constants::CSUM_SIZE};
2use num_enum::{IntoPrimitive, TryFromPrimitive};
3use static_assertions::const_assert_eq;
4use strum::EnumIter;
5use zerocopy::little_endian::{U32 as U32LE, U64 as U64LE};
6use zerocopy_derive::*;
7
8#[derive(Clone, Debug, IntoBytes, TryFromBytes, Unaligned, KnownLayout)]
10#[repr(C, packed)]
11pub struct Header {
12 pub csum: [u8; CSUM_SIZE],
15
16 pub fs_uuid: UuidBytes,
18
19 pub logical_address: U64LE,
21
22 pub flags: [u8; 7],
24
25 pub backref_rev: BackrefRevision,
27
28 pub chunk_tree_uuid: UuidBytes,
30
31 pub generation: U64LE,
33
34 pub tree_id: U64LE,
36
37 pub num_items: U32LE,
39
40 pub level: u8,
42}
43const_assert_eq!(core::mem::size_of::<Header>(), 101);
44
45#[derive(Copy, Clone, Debug, IntoBytes, FromBytes, Unaligned, KnownLayout)]
50#[repr(C, packed)]
51pub struct KeyPointer {
52 pub key: Key,
53 pub block_pointer: U64LE,
54 pub generation: U64LE,
55}
56const_assert_eq!(core::mem::size_of::<KeyPointer>(), 33);
57
58#[derive(Copy, Clone, Debug, IntoBytes, FromBytes, Unaligned, KnownLayout)]
68#[repr(C, packed)]
69pub struct Item {
70 pub key: Key,
72
73 pub offset: U32LE,
75
76 pub size: U32LE,
78}
79const_assert_eq!(core::mem::size_of::<Item>(), 25);
80
81#[derive(
82 Copy,
83 Clone,
84 Debug,
85 Hash,
86 PartialEq,
87 EnumIter,
88 IntoPrimitive,
89 TryFromPrimitive,
90 IntoBytes,
91 TryFromBytes,
92 Unaligned,
93 KnownLayout,
94)]
95#[repr(u8)]
96pub enum BackrefRevision {
97 Old = 0,
99
100 Mixed = 1,
102}
103const_assert_eq!(core::mem::size_of::<BackrefRevision>(), 1);