1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2021-2026 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0
use core::fmt;
use zerocopy::{FromBytes, Immutable, KnownLayout, LittleEndian, U16, U32, Unaligned};
/// Size of a single GUID on disk (= size of all GUID fields).
pub(crate) const GUID_SIZE: usize = 16;
/// A Globally Unique Identifier (GUID), used for Object IDs in NTFS.
#[derive(Clone, Debug, Eq, FromBytes, Immutable, KnownLayout, PartialEq, Unaligned)]
#[repr(C, packed)]
pub struct NtfsGuid {
data1: U32<LittleEndian>,
data2: U16<LittleEndian>,
data3: U16<LittleEndian>,
data4: [u8; 8],
}
impl NtfsGuid {
/// Returns the `data1` component of the GUID.
pub fn data1(&self) -> u32 {
self.data1.get()
}
/// Returns the `data2` component of the GUID.
pub fn data2(&self) -> u16 {
self.data2.get()
}
/// Returns the `data3` component of the GUID.
pub fn data3(&self) -> u16 {
self.data3.get()
}
/// Returns the `data4` component of the GUID.
pub fn data4(&self) -> [u8; 8] {
self.data4
}
}
impl fmt::Display for NtfsGuid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{:8X}-{:4X}-{:4X}-{:2X}{:2X}-{:2X}{:2X}{:2X}{:2X}{:2X}{:2X}",
self.data1,
self.data2,
self.data3,
self.data4[0],
self.data4[1],
self.data4[2],
self.data4[3],
self.data4[4],
self.data4[5],
self.data4[6],
self.data4[7]
)
}
}