fast_ntfs 1.0.2

Forked a low-level NTFS filesystem library
Documentation
// 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]
        )
    }
}