From 89fa0a791ece0ea3cef57b0fa3a24c473dd7b056 Mon Sep 17 00:00:00 2001 From: Matthew Jackson <1085847+MattJackson@users.noreply.github.com> Date: Tue, 23 Jun 2026 04:11:46 -0700 Subject: [PATCH] disc: warn when READ CAPACITY fails instead of silently using 0 sectors read_udf treated a READ CAPACITY SCSI failure as a 0-sector disc via unwrap_or(0) with no diagnostic. capacity=0 then skews the layer heuristic (always reports 1 layer, even for dual-layer discs) and the canonical title-ordering sort, with nothing in /api/state or info to indicate the command actually failed. Emit a tracing::warn carrying the original error at the fallback site so a transient capacity failure is visible. Recovery behavior is unchanged: 0 is still used as the fallback. --- src/disc/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/disc/mod.rs b/src/disc/mod.rs index 9dfe5f3..98d66c9 100644 --- a/src/disc/mod.rs +++ b/src/disc/mod.rs @@ -1229,7 +1229,18 @@ impl Disc { /// Read UDF filesystem and set up buffered reader with metadata prefetched. /// Shared setup for both identify() and scan(). fn read_udf(session: &mut Drive) -> Result<(u32, udf::BufferedSectorReader<'_>, udf::UdfFs)> { - let capacity = Self::read_capacity(session).unwrap_or(0); + let capacity = Self::read_capacity(session).unwrap_or_else(|e| { + // A READ CAPACITY failure (transient drive spin-up, SCSI error) + // must not be silently treated as a 0-sector disc: capacity=0 + // skews the layer heuristic (always 1 layer) and title ordering. + // Recovery is unchanged (we still proceed with 0), but surface it. + tracing::warn!( + target: "freemkv::scan", + error = %e, + "READ CAPACITY failed; treating disc capacity as 0 sectors (layer count and title ordering may be wrong)" + ); + 0 + }); let batch = detect_max_batch_sectors(session.device_path()); let mut buffered = udf::BufferedSectorReader::new(session, batch); let udf_fs = udf::read_filesystem(&mut buffered)?;