Clean API: read_sectors_recover(recovery: bool) replaces read_sectors_fast

This commit is contained in:
Matt Jackson
2026-04-20 01:12:59 +00:00
parent 8a256cc620
commit c78e83e916
3 changed files with 16 additions and 8 deletions
+5 -1
View File
@@ -670,9 +670,13 @@ impl SectorReader for Drive {
self.read(lba, count, buf) self.read(lba, count, buf)
} }
fn read_sectors_fast(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result<usize> { fn read_sectors_recover(&mut self, lba: u32, count: u16, buf: &mut [u8], recovery: bool) -> Result<usize> {
if recovery {
self.read(lba, count, buf)
} else {
self.read_fast(lba, count, buf) self.read_fast(lba, count, buf)
} }
}
} }
/// Find all optical drives connected to this system. /// Find all optical drives connected to this system.
+7 -3
View File
@@ -10,11 +10,15 @@ use crate::error::Result;
pub trait SectorReader: Send { pub trait SectorReader: Send {
/// Read `count` sectors starting at `lba` into `buf`. /// Read `count` sectors starting at `lba` into `buf`.
/// `buf` must be at least `count * 2048` bytes. /// `buf` must be at least `count * 2048` bytes.
/// Full recovery enabled (retry + reset on failure).
fn read_sectors(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result<usize>; fn read_sectors(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result<usize>;
/// Fast single-attempt read — no recovery, short timeout. /// Read with explicit recovery flag.
/// Default implementation calls read_sectors (ISO files don't need fast mode). /// true = full retry/reset loop (for ripping). false = single attempt, fast fail (for verify).
fn read_sectors_fast(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result<usize> { /// Default: delegates to read_sectors (recovery=true behavior).
fn read_sectors_recover(&mut self, lba: u32, count: u16, buf: &mut [u8], recovery: bool) -> Result<usize> {
// Default ignores flag — file-backed readers don't have recovery
let _ = recovery;
self.read_sectors(lba, count, buf) self.read_sectors(lba, count, buf)
} }
+3 -3
View File
@@ -105,7 +105,7 @@ pub fn verify_title(
let batch_start = Instant::now(); let batch_start = Instant::now();
let batch_ok = reader let batch_ok = reader
.read_sectors_fast(lba, count, &mut buf[..bytes]) .read_sectors_recover(lba, count, &mut buf[..bytes], false)
.is_ok(); .is_ok();
let batch_ms = batch_start.elapsed().as_millis(); let batch_ms = batch_start.elapsed().as_millis();
@@ -144,7 +144,7 @@ pub fn verify_title(
let s1 = Instant::now(); let s1 = Instant::now();
let first_ok = reader let first_ok = reader
.read_sectors_fast(sector_lba, 1, &mut buf[sector_offset..sector_offset + 2048]) .read_sectors_recover(sector_lba, 1, &mut buf[sector_offset..sector_offset + 2048], false)
.is_ok(); .is_ok();
let s1_ms = s1.elapsed().as_millis(); let s1_ms = s1.elapsed().as_millis();
@@ -158,7 +158,7 @@ pub fn verify_title(
// Retry once more after brief pause // Retry once more after brief pause
std::thread::sleep(std::time::Duration::from_secs(2)); std::thread::sleep(std::time::Duration::from_secs(2));
if reader if reader
.read_sectors_fast(sector_lba, 1, &mut buf[sector_offset..sector_offset + 2048]) .read_sectors_recover(sector_lba, 1, &mut buf[sector_offset..sector_offset + 2048], false)
.is_ok() .is_ok()
{ {
recovered += 1; recovered += 1;