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 8870efa77b
commit 43ecad2d43
3 changed files with 16 additions and 8 deletions
+5 -1
View File
@@ -670,10 +670,14 @@ impl SectorReader for Drive {
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)
}
}
}
/// Find all optical drives connected to this system.
/// Returns opened Drive objects ready for use.
+7 -3
View File
@@ -10,11 +10,15 @@ use crate::error::Result;
pub trait SectorReader: Send {
/// Read `count` sectors starting at `lba` into `buf`.
/// `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>;
/// Fast single-attempt read — no recovery, short timeout.
/// Default implementation calls read_sectors (ISO files don't need fast mode).
fn read_sectors_fast(&mut self, lba: u32, count: u16, buf: &mut [u8]) -> Result<usize> {
/// Read with explicit recovery flag.
/// true = full retry/reset loop (for ripping). false = single attempt, fast fail (for verify).
/// 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)
}
+3 -3
View File
@@ -105,7 +105,7 @@ pub fn verify_title(
let batch_start = Instant::now();
let batch_ok = reader
.read_sectors_fast(lba, count, &mut buf[..bytes])
.read_sectors_recover(lba, count, &mut buf[..bytes], false)
.is_ok();
let batch_ms = batch_start.elapsed().as_millis();
@@ -144,7 +144,7 @@ pub fn verify_title(
let s1 = Instant::now();
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();
let s1_ms = s1.elapsed().as_millis();
@@ -158,7 +158,7 @@ pub fn verify_title(
// Retry once more after brief pause
std::thread::sleep(std::time::Duration::from_secs(2));
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()
{
recovered += 1;