forked from M-Labs/rust-fatfs
Rename some fields in internal bsp struct.
This commit is contained in:
parent
c8ccd7d86e
commit
284d26282c
78
src/fs.rs
78
src/fs.rs
@ -54,31 +54,31 @@ impl <'a> FatSharedState<'a> {
|
||||
pub(crate) struct FatBiosParameterBlock {
|
||||
bytes_per_sector: u16,
|
||||
sectors_per_cluster: u8,
|
||||
reserved_sector_count: u16,
|
||||
table_count: u8,
|
||||
root_entry_count: u16,
|
||||
reserved_sectors: u16,
|
||||
fats: u8,
|
||||
root_entries: u16,
|
||||
total_sectors_16: u16,
|
||||
media_type: u8,
|
||||
table_size_16: u16,
|
||||
media: u8,
|
||||
sectors_per_fat_16: u16,
|
||||
sectors_per_track: u16,
|
||||
head_side_count: u16,
|
||||
hidden_sector_count: u32,
|
||||
heads: u16,
|
||||
hidden_sectors: u32,
|
||||
total_sectors_32: u32,
|
||||
|
||||
// Extended BIOS Parameter Block
|
||||
table_size_32: u32,
|
||||
sectors_per_fat_32: u32,
|
||||
extended_flags: u16,
|
||||
fat_version: u16,
|
||||
root_cluster: u32,
|
||||
fat_info: u16,
|
||||
backup_bs_sector: u16,
|
||||
fs_version: u16,
|
||||
root_dir_first_cluster: u32,
|
||||
fs_info_sector: u16,
|
||||
backup_boot_sector: u16,
|
||||
reserved_0: [u8; 12],
|
||||
drive_num: u8,
|
||||
reserved_1: u8,
|
||||
ext_sig: u8,
|
||||
volume_id: u32,
|
||||
volume_label: [u8; 11],
|
||||
fat_type_label: [u8; 8],
|
||||
fs_type_label: [u8; 8],
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@ -118,17 +118,17 @@ impl <'a> FatFileSystem<'a> {
|
||||
}
|
||||
|
||||
let total_sectors = if boot.bpb.total_sectors_16 == 0 { boot.bpb.total_sectors_32 } else { boot.bpb.total_sectors_16 as u32 };
|
||||
let table_size = if boot.bpb.table_size_16 == 0 { boot.bpb.table_size_32 } else { boot.bpb.table_size_16 as u32 };
|
||||
let root_dir_sectors = (((boot.bpb.root_entry_count * 32) + (boot.bpb.bytes_per_sector - 1)) / boot.bpb.bytes_per_sector) as u32;
|
||||
let first_data_sector = boot.bpb.reserved_sector_count as u32 + (boot.bpb.table_count as u32 * table_size) + root_dir_sectors;
|
||||
let data_sectors = total_sectors - (boot.bpb.reserved_sector_count as u32 + (boot.bpb.table_count as u32 * table_size) + root_dir_sectors as u32);
|
||||
let sectors_per_fat = if boot.bpb.sectors_per_fat_16 == 0 { boot.bpb.sectors_per_fat_32 } else { boot.bpb.sectors_per_fat_16 as u32 };
|
||||
let root_dir_sectors = (((boot.bpb.root_entries * 32) + (boot.bpb.bytes_per_sector - 1)) / boot.bpb.bytes_per_sector) as u32;
|
||||
let first_data_sector = boot.bpb.reserved_sectors as u32 + (boot.bpb.fats as u32 * sectors_per_fat) + root_dir_sectors;
|
||||
let data_sectors = total_sectors - (boot.bpb.reserved_sectors as u32 + (boot.bpb.fats as u32 * sectors_per_fat) + root_dir_sectors as u32);
|
||||
let total_clusters = data_sectors / boot.bpb.sectors_per_cluster as u32;
|
||||
let fat_type = Self::fat_type_from_clusters(total_clusters);
|
||||
|
||||
let fat_offset = boot.bpb.reserved_sector_count * boot.bpb.bytes_per_sector;
|
||||
let fat_offset = boot.bpb.reserved_sectors * boot.bpb.bytes_per_sector;
|
||||
rdr.seek(SeekFrom::Start(fat_offset as u64))?;
|
||||
let table_size_bytes = table_size * boot.bpb.bytes_per_sector as u32;
|
||||
let table = FatTable::from_read(rdr, fat_type, table_size_bytes as usize)?;
|
||||
let fat_size = sectors_per_fat * boot.bpb.bytes_per_sector as u32;
|
||||
let table = FatTable::from_read(rdr, fat_type, fat_size as usize)?;
|
||||
|
||||
let state = FatSharedState {
|
||||
rdr,
|
||||
@ -162,7 +162,7 @@ impl <'a> FatFileSystem<'a> {
|
||||
match state.fat_type {
|
||||
FatType::Fat12 | FatType::Fat16 => FatDirReader::Root(FatSlice::from_sectors(
|
||||
state.first_data_sector - state.root_dir_sectors, state.root_dir_sectors, &self.state)),
|
||||
_ => FatDirReader::File(FatFile::new(state.boot.bpb.root_cluster, None, &self.state)),
|
||||
_ => FatDirReader::File(FatFile::new(state.boot.bpb.root_dir_first_cluster, None, &self.state)),
|
||||
}
|
||||
};
|
||||
FatDir::new(root_rdr, &self.state)
|
||||
@ -172,42 +172,38 @@ impl <'a> FatFileSystem<'a> {
|
||||
let mut bpb: FatBiosParameterBlock = Default::default();
|
||||
bpb.bytes_per_sector = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.sectors_per_cluster = rdr.read_u8()?;
|
||||
bpb.reserved_sector_count = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.table_count = rdr.read_u8()?;
|
||||
bpb.root_entry_count = rdr.read_u16::<LittleEndian>()? ;
|
||||
bpb.reserved_sectors = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.fats = rdr.read_u8()?;
|
||||
bpb.root_entries = rdr.read_u16::<LittleEndian>()? ;
|
||||
bpb.total_sectors_16 = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.media_type = rdr.read_u8()?;
|
||||
bpb.table_size_16 = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.media = rdr.read_u8()?;
|
||||
bpb.sectors_per_fat_16 = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.sectors_per_track = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.head_side_count = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.hidden_sector_count = rdr.read_u32::<LittleEndian>()?; // hidden_sector_count
|
||||
bpb.heads = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.hidden_sectors = rdr.read_u32::<LittleEndian>()?; // hidden_sector_count
|
||||
bpb.total_sectors_32 = rdr.read_u32::<LittleEndian>()?;
|
||||
|
||||
if bpb.table_size_16 == 0 {
|
||||
bpb.table_size_32 = rdr.read_u32::<LittleEndian>()?;
|
||||
if bpb.sectors_per_fat_16 == 0 {
|
||||
bpb.sectors_per_fat_32 = rdr.read_u32::<LittleEndian>()?;
|
||||
bpb.extended_flags = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.fat_version = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.root_cluster = rdr.read_u32::<LittleEndian>()?;
|
||||
bpb.fat_info = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.backup_bs_sector = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.fs_version = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.root_dir_first_cluster = rdr.read_u32::<LittleEndian>()?;
|
||||
bpb.fs_info_sector = rdr.read_u16::<LittleEndian>()?;
|
||||
bpb.backup_boot_sector = rdr.read_u16::<LittleEndian>()?;
|
||||
rdr.read(&mut bpb.reserved_0)?;
|
||||
bpb.drive_num = rdr.read_u8()?;
|
||||
bpb.reserved_1 = rdr.read_u8()?;
|
||||
bpb.ext_sig = rdr.read_u8()?; // 0x29
|
||||
bpb.volume_id = rdr.read_u32::<LittleEndian>()?;
|
||||
rdr.read(&mut bpb.volume_label)?;
|
||||
rdr.read(&mut bpb.fat_type_label)?;
|
||||
//bpb.boot_code = Vec::with_capacity(420);
|
||||
//rdr.read_exact(bpb.boot_code.as_mut_slice())?;
|
||||
rdr.read(&mut bpb.fs_type_label)?;
|
||||
} else {
|
||||
bpb.drive_num = rdr.read_u8()?;
|
||||
bpb.reserved_1 = rdr.read_u8()?;
|
||||
bpb.ext_sig = rdr.read_u8()?; // 0x29
|
||||
bpb.volume_id = rdr.read_u32::<LittleEndian>()?;
|
||||
rdr.read(&mut bpb.volume_label)?;
|
||||
rdr.read(&mut bpb.fat_type_label)?;
|
||||
//bpb.boot_code = Vec::with_capacity(448);
|
||||
//rdr.read_exact(bpb.boot_code.as_mut_slice())?;
|
||||
rdr.read(&mut bpb.fs_type_label)?;
|
||||
}
|
||||
Ok(bpb)
|
||||
}
|
||||
@ -230,7 +226,7 @@ impl <'a> FatFileSystem<'a> {
|
||||
rdr.read(&mut boot.oem_name)?;
|
||||
boot.bpb = Self::read_bpb(rdr)?;
|
||||
|
||||
if boot.bpb.table_size_16 == 0 {
|
||||
if boot.bpb.sectors_per_fat_16 == 0 {
|
||||
rdr.read_exact(&mut boot.boot_code[0..420])?;
|
||||
} else {
|
||||
rdr.read_exact(&mut boot.boot_code[0..448])?;
|
||||
|
Loading…
Reference in New Issue
Block a user