From a529a8fcb61cb579eb565c3f84454a15ad2387eb Mon Sep 17 00:00:00 2001 From: Matt Jackson <1085847+MattJackson@users.noreply.github.com> Date: Tue, 21 Apr 2026 03:27:17 +0000 Subject: [PATCH] Clean API: merge read() and read_fast() into read(recovery: bool) --- src/drive/mod.rs | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/src/drive/mod.rs b/src/drive/mod.rs index a13b226..0e3593f 100644 --- a/src/drive/mod.rs +++ b/src/drive/mod.rs @@ -496,8 +496,10 @@ impl Drive { /// /// Returns Err only after all attempts exhausted — user should clean /// the disc and resume. - pub fn read(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result { - let timeout_ms = if self.recovery_bytes_remaining > 0 { + pub fn read(&mut self, lba: u32, count: u16, buf: &mut [u8], recovery: bool) -> Result { + let timeout_ms = if !recovery { + 5_000 + } else if self.recovery_bytes_remaining > 0 { 30_000 } else { 10_000 @@ -534,7 +536,12 @@ impl Drive { return Ok(result.bytes_transferred); } - // Read failed — enter recovery + // Read failed + if !recovery { + return Err(Error::DiscRead { sector: lba as u64 }); + } + + // Enter recovery self.emit(EventKind::ReadError { sector: lba as u64, error: Error::DiscRead { sector: lba as u64 }, @@ -605,32 +612,6 @@ impl Drive { Err(Error::DiscRead { sector: lba as u64 }) } - /// Fast single-attempt read for verification — no recovery, short timeout. - /// Returns Ok on success, Err on any failure. Does not retry. - pub fn read_fast(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result { - let cdb = [ - crate::scsi::SCSI_READ_10, - 0x00, - (lba >> 24) as u8, - (lba >> 16) as u8, - (lba >> 8) as u8, - lba as u8, - 0x00, - (count >> 8) as u8, - count as u8, - 0x00, - ]; - match self.scsi.as_mut().execute( - &cdb, - crate::scsi::DataDirection::FromDevice, - buf, - 5_000, // 5 second timeout — enough for healthy reads, fast fail for bad sectors - ) { - Ok(result) => Ok(result.bytes_transferred), - Err(_) => Err(Error::DiscRead { sector: lba as u64 }), - } - } - /// Read the disc capacity in sectors (2048 bytes each). pub fn read_capacity(&mut self) -> Result { let cdb = [ @@ -730,15 +711,11 @@ impl Drop for Drive { impl SectorReader for Drive { fn read_sectors(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result { - self.read(lba, count, buf) + self.read(lba, count, buf, true) } fn read_sectors_recover(&mut self, lba: u32, count: u16, buf: &mut [u8], recovery: bool) -> Result { - if recovery { - self.read(lba, count, buf) - } else { - self.read_fast(lba, count, buf) - } + self.read(lba, count, buf, recovery) } }