moved low-level code into fat-bits subcrate

This commit is contained in:
Moritz Gmeiner 2025-07-27 13:17:04 +02:00
commit f3d411f821
17 changed files with 187 additions and 46 deletions

43
fat-bits/src/fs_info.rs Normal file
View file

@ -0,0 +1,43 @@
use crate::utils::load_u32_le;
#[allow(dead_code)]
pub struct FsInfo {
free_count: u32,
next_free: u32,
}
impl FsInfo {
pub fn load(bytes: &[u8]) -> anyhow::Result<FsInfo> {
let lead_sig = load_u32_le(&bytes[..4]);
anyhow::ensure!(
lead_sig == 0x41615252,
"invalid lead signature: 0x{:#08X} instead of 0x41615252",
lead_sig
);
let struct_sig = load_u32_le(&bytes[484..][..4]);
anyhow::ensure!(
struct_sig == 0x61417272,
"invalid structural signature: 0x{:#08X} instead of 0x61417272",
struct_sig
);
let trail_sig = load_u32_le(&bytes[508..][..4]);
anyhow::ensure!(
trail_sig == 0xAA550000,
"invalid trailing signature: 0x{:#08X} instead of 0xAA550000",
trail_sig
);
let free_count = load_u32_le(&bytes[488..][..4]);
let next_free = load_u32_le(&bytes[492..][..4]);
Ok(FsInfo {
free_count,
next_free,
})
}
}