use crate::const_assert_size;
use binrw::BinRead;
#[derive(Debug, Copy, Clone, BinRead)]
#[repr(C, packed)]
pub struct BiosParameterBlock {
_jump_instr: [u8; 3],
oem_identifier: u64,
pub bytes_per_sector: u16,
pub sectors_per_cluster: u8,
pub reserved_sectors: u16,
pub fat_amount: u8,
max_num_directory_entries: u16,
total_logical_sectors: u16,
fat_id: u8,
pub sectors_per_fat: u16,
num_sectors_per_track: u16,
num_heads_on_storage: u16,
num_hidden_sectors: u32,
pub total_logical_sectors_gt_u16: u32,
}
const_assert_size!(BiosParameterBlock, 36);
#[derive(Debug, Copy, Clone, BinRead)]
pub struct ExtendedBiosParameterBlock {
pub sectors_per_fat: u32,
_flags: u16,
_fat_version: u16,
pub root_cluster: u32,
pub(crate) fsinfo_sector: u16,
_backup_boot_sector: u16,
_reserved: [u8; 12],
_drive_number: u8,
_reserved2: u8,
pub signature: u8,
_volumeid_serial_number: u32,
pub volume_label_string: [u8; 11],
_system_identifier_string: [u8; 8],
_boot_code: [u8; 420],
_bootable_partition_signature: u16,
}
const_assert_size!(ExtendedBiosParameterBlock, 476);
#[derive(Debug, Clone, BinRead)]
pub struct FullExtendedBIOSParameterBlock {
pub bpb: BiosParameterBlock,
pub extended: ExtendedBiosParameterBlock,
}
impl FullExtendedBIOSParameterBlock {
pub fn get_fat_size(&self) -> u32 {
self.extended.sectors_per_fat * self.bpb.bytes_per_sector as u32
}
pub fn sectors_occupied_by_all_fats(&self) -> u32 {
self.bpb.fat_amount as u32 * self.bpb.sectors_per_fat as u32
}
}