use binrw::BinRead;
use crate::const_assert_size;
const FSINFO_LEAD_SIG: u32 = 0x41615252;
const FSINFO_STRUC_SIG: u32 = 0x61417272;
const FSINFO_TRAIL_SIG: u32 = 0xAA550000;
const FSINFO_UNKNOWN: u32 = 0xFFFFFFFF;
#[derive(Debug, Copy, Clone, BinRead)]
#[repr(C, packed)]
pub(crate) struct FSInfoSector {
lead_sig: u32,
_reserved1: [u8; 480],
struc_sig: u32,
pub free_count: u32,
pub nxt_free: u32,
_reserved2: [u8; 12],
trail_sig: u32,
}
const_assert_size!(FSInfoSector, 512);
impl FSInfoSector {
pub fn is_valid(&self) -> bool {
self.lead_sig == FSINFO_LEAD_SIG
&& self.struc_sig == FSINFO_STRUC_SIG
&& self.trail_sig == FSINFO_TRAIL_SIG
}
pub fn next_free_hint(&self) -> Option<u32> {
if self.nxt_free == FSINFO_UNKNOWN || self.nxt_free < 2 {
None
} else {
Some(self.nxt_free)
}
}
}