btrfs_diskformat/core/
root_item.rs

1use crate::{InodeItem, Key, Time, UuidBytes};
2use static_assertions::const_assert_eq;
3use zerocopy::little_endian::{U32 as U32LE, U64 as U64LE};
4use zerocopy_derive::*;
5
6/// Defines the location and parameters of the root of a b-tree.
7#[derive(Copy, Clone, Debug, IntoBytes, FromBytes, Unaligned, KnownLayout)]
8#[repr(C, packed)]
9pub struct RootItem {
10    pub inode: InodeItem,
11
12    pub generation: U64LE,
13
14    pub root_dirid: U64LE,
15
16    pub bytenr: U64LE,
17
18    /// Currently unused. Always 0.
19    pub byte_limit: U64LE,
20
21    /// Currently unused.
22    pub bytes_used: U64LE,
23
24    /// The transaction ID of the last transaction that created a snapshot of this root.
25    pub last_snapshot: U64LE,
26
27    pub flags: U64LE,
28
29    /// Only 0 or 1. Historically contained a reference count.
30    pub refs: U32LE,
31
32    /// Contains the key of the last dropped item during subvolume removal or relocation.
33    ///
34    /// Value will be zeroed out otherwise.
35    pub drop_progress: Key,
36
37    /// The tree level of the node referenced in [drop_progress](RootItem::drop_progress).
38    pub drop_level: u8,
39
40    /// The height of this root's tree.
41    pub level: u8,
42
43    /// Value to help determine whether this root has been modified by an older btrfs
44    /// implementation.
45    ///
46    /// If the value is equal to [generation], the fields below are valid. Otherwise, this indicates
47    /// the fields are invalid but recoverable.
48    ///
49    /// [generation]: RootItem::generation
50    pub generation_v2: U64LE,
51
52    /// The subvolume's UUID.
53    pub uuid: UuidBytes,
54
55    /// The parent's subvolume UUID.
56    ///
57    /// This is used during send/receive.
58    pub parent_uuid: UuidBytes,
59
60    /// The received UUID.
61    ///
62    /// This is used during send/receive.
63    pub received_uuid: UuidBytes,
64
65    /// The transaction ID of the last transaction that modified the tree.
66    ///
67    /// Note: some operations like internal caches or relocation will not update this value.
68    pub ctransid: U64LE,
69
70    /// The transaction ID of the transaction that created the tree.
71    pub otransid: U64LE,
72
73    /// The transaction ID for the transaction that sent this subvolume.
74    ///
75    /// This value is non-zero for a received subvolume.
76    pub stransid: U64LE,
77
78    /// The transaction ID for the transaction that received this subvolume.
79    ///
80    /// This value is non-zero for a received subvolume.
81    pub rtransid: U64LE,
82
83    /// The timestamp of the [`ctransid`](RootItem::ctransid).
84    pub ctime: Time,
85
86    /// The timestamp of the [`otransid`](RootItem::otransid).
87    pub otime: Time,
88
89    /// The timestamp of the [`stransid`](RootItem::stransid).
90    pub stime: Time,
91
92    /// The timestamp of the [`rtransid`](RootItem::rtransid).
93    pub rtime: Time,
94
95    /// Currently unused. Reserved for future use.
96    pub _unused: [u64; 8],
97}
98const_assert_eq!(core::mem::size_of::<RootItem>(), 439);