From e8a313ac4c684d2a500d3500e58892d7f810c6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Tue, 4 Dec 2018 00:24:19 +0100 Subject: [PATCH] Change total FAT entries calculation Old way of doing it was wrong because 512 (standard sector size) is not dividable by 12. Also fix the build... --- src/fs.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 1fad792..aa693a6 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -48,9 +48,9 @@ impl FatType { pub(crate) fn bits_per_fat_entry(&self) -> u32 { match self { - FatType::Fat12 => 12, - FatType::Fat16 => 16, - FatType::Fat32 => 32, + &FatType::Fat12 => 12, + &FatType::Fat16 => 16, + &FatType::Fat32 => 32, } } } @@ -331,8 +331,8 @@ impl BiosParameterBlock { )); } - let fat_entries_per_sector = self.fat_entries_per_sector(fat_type); - let total_fat_entries = self.sectors_per_fat() * fat_entries_per_sector as u32; + let bits_per_fat_entry = fat_type.bits_per_fat_entry(); + let total_fat_entries = self.sectors_per_fat() * self.bytes_per_sector as u32 * 8 / bits_per_fat_entry as u32; if total_fat_entries - RESERVED_FAT_ENTRIES < total_clusters { warn!("FAT is too small to compared to total number of clusters"); } @@ -401,14 +401,6 @@ impl BiosParameterBlock { let data_sectors = total_sectors - first_data_sector; data_sectors / self.sectors_per_cluster as u32 } - - fn fat_entries_per_sector(&self, fat_type: FatType) -> u16 { - match fat_type { - FatType::Fat12 => self.bytes_per_sector * 8 / 12, - FatType::Fat16 => self.bytes_per_sector * 8 / 16, - FatType::Fat32 => self.bytes_per_sector * 8 / 32, - } - } } #[allow(dead_code)]