From e45cfb5188678cfb7abda2ccc7dfab9c9c611923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Wed, 5 Dec 2018 01:35:03 +0100 Subject: [PATCH] fix: do not use hard-coded sector size when dealing with FSInfo sector Previous code is not working correctly if sector size is different than 512. Creating test for this issue would require another binary blob in repository so I am leaving it without test for now. --- src/fs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index f28695f..e75266c 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -622,7 +622,7 @@ impl FileSystem { // read FSInfo sector if this is FAT32 let mut fs_info = if fat_type == FatType::Fat32 { - disk.seek(SeekFrom::Start(bpb.fs_info_sector as u64 * 512))?; + disk.seek(SeekFrom::Start(bpb.fs_info_sector as u64 * bpb.bytes_per_sector as u64))?; FsInfoSector::deserialize(&mut disk)? } else { FsInfoSector::default() @@ -847,7 +847,7 @@ impl FileSystem { let mut fs_info = self.fs_info.borrow_mut(); if self.fat_type == FatType::Fat32 && fs_info.dirty { let mut disk = self.disk.borrow_mut(); - disk.seek(SeekFrom::Start(self.bpb.fs_info_sector as u64 * 512))?; + disk.seek(SeekFrom::Start(self.offset_from_sector(self.bpb.fs_info_sector as u32)))?; fs_info.serialize(&mut *disk)?; fs_info.dirty = false; }