use hadris_common::types::{
endian::LittleEndian,
number::{U16, U32},
};
#[repr(C)]
#[derive(Clone, Copy)]
pub struct RawBpb {
pub jump: [u8; 3],
pub oem_name: [u8; 8],
pub bytes_per_sector: U16<LittleEndian>,
pub sectors_per_cluster: u8,
pub reserved_sector_count: U16<LittleEndian>,
pub fat_count: u8,
pub root_entry_count: [u8; 2],
pub total_sectors_16: [u8; 2],
pub media_type: u8,
pub sectors_per_fat_16: [u8; 2],
pub sectors_per_track: [u8; 2],
pub num_heads: [u8; 2],
pub hidden_sector_count: [u8; 4],
pub total_sectors_32: [u8; 4],
}
unsafe impl bytemuck::NoUninit for RawBpb {}
unsafe impl bytemuck::Zeroable for RawBpb {}
unsafe impl bytemuck::AnyBitPattern for RawBpb {}
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub struct RawBpbExt16 {
pub drive_number: u8,
pub reserved1: u8,
pub ext_boot_signature: u8,
pub volume_id: [u8; 4],
pub volume_label: [u8; 11],
pub fs_type: [u8; 8],
pub padding1: [u8; 448],
pub signature_word: [u8; 2],
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct RawBpbExt32 {
pub sectors_per_fat_32: U32<LittleEndian>,
pub ext_flags: [u8; 2],
pub version: [u8; 2],
pub root_cluster: U32<LittleEndian>,
pub fs_info_sector: U16<LittleEndian>,
pub boot_sector: [u8; 2],
pub reserved: [u8; 12],
pub drive_number: u8,
pub reserved1: u8,
pub ext_boot_signature: u8,
pub volume_id: [u8; 4],
pub volume_label: [u8; 11],
pub fs_type: [u8; 8],
pub padding1: [u8; 420],
pub signature_word: U16<LittleEndian>,
}
unsafe impl bytemuck::NoUninit for RawBpbExt32 {}
unsafe impl bytemuck::Zeroable for RawBpbExt32 {}
unsafe impl bytemuck::AnyBitPattern for RawBpbExt32 {}
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BpbExt32Flags(u16);
#[repr(C, packed)]
#[derive(Clone, Copy)]
pub struct RawFileEntry {
pub name: [u8; 11],
pub attributes: u8,
pub reserved: u8,
pub creation_time_tenth: u8,
pub creation_time: [u8; 2],
pub creation_date: [u8; 2],
pub last_access_date: [u8; 2],
pub first_cluster_high: U16<LittleEndian>,
pub last_write_time: [u8; 2],
pub last_write_date: [u8; 2],
pub first_cluster_low: U16<LittleEndian>,
pub size: U32<LittleEndian>,
}
unsafe impl bytemuck::NoUninit for RawFileEntry {}
unsafe impl bytemuck::Zeroable for RawFileEntry {}
unsafe impl bytemuck::AnyBitPattern for RawFileEntry {}
#[repr(C, packed)]
#[derive(Clone, Copy)]
pub struct RawLfnEntry {
pub sequence_number: u8,
pub name1: [u8; 10],
pub attributes: u8,
pub ty: u8,
pub checksum: u8,
pub name2: [u8; 12],
pub first_cluster_low: [u8; 2],
pub name3: [u8; 4],
}
#[repr(C, packed)]
#[derive(Clone, Copy)]
pub union RawDirectoryEntry {
pub file: RawFileEntry,
#[cfg(feature = "lfn")]
pub lfn: RawLfnEntry,
pub bytes: [u8; 32],
}
impl RawDirectoryEntry {
pub fn attributes(&self) -> u8 {
unsafe { self.file }.attributes
}
}
unsafe impl bytemuck::NoUninit for RawDirectoryEntry {}
unsafe impl bytemuck::Zeroable for RawDirectoryEntry {}
unsafe impl bytemuck::AnyBitPattern for RawDirectoryEntry {}
#[repr(C, packed)]
#[derive(Clone, Copy)]
pub struct RawFsInfo {
pub signature: [u8; 4],
pub reserved1: [u8; 480],
pub structure_signature: [u8; 4],
pub free_count: U32<LittleEndian>,
pub next_free: U32<LittleEndian>,
pub reserved2: [u8; 12],
pub trail_signature: U32<LittleEndian>,
}
unsafe impl bytemuck::NoUninit for RawFsInfo {}
unsafe impl bytemuck::Zeroable for RawFsInfo {}
unsafe impl bytemuck::AnyBitPattern for RawFsInfo {}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DirEntryAttrFlags: u8 {
const READ_ONLY = 1 << 0;
const HIDDEN = 1 << 1;
const SYSTEM = 1 << 2;
const VOLUME_ID = 1 << 3;
const DIRECTORY = 1 << 4;
const ARCHIVE = 1 << 5;
}
}
impl DirEntryAttrFlags {
pub const LONG_NAME: Self = Self::from_bits_truncate(
Self::READ_ONLY.bits() | Self::HIDDEN.bits() | Self::SYSTEM.bits() | Self::VOLUME_ID.bits(),
);
}