cargo fmt + clippy --fix: 104 format violations fixed, 8 clippy auto-fixes
This commit is contained in:
+8
-2
@@ -8,7 +8,10 @@ use crate::udf;
|
||||
|
||||
impl Disc {
|
||||
/// Scan Blu-ray titles from MPLS playlists.
|
||||
pub(super) fn scan_bluray_titles(reader: &mut dyn SectorReader, udf_fs: &udf::UdfFs) -> Vec<DiscTitle> {
|
||||
pub(super) fn scan_bluray_titles(
|
||||
reader: &mut dyn SectorReader,
|
||||
udf_fs: &udf::UdfFs,
|
||||
) -> Vec<DiscTitle> {
|
||||
let mut titles = Vec::new();
|
||||
if let Some(playlist_dir) = udf_fs.find_dir("/BDMV/PLAYLIST") {
|
||||
for entry in &playlist_dir.entries {
|
||||
@@ -190,7 +193,10 @@ impl Disc {
|
||||
/// Read disc title from META/DL/bdmt_eng.xml (Blu-ray Disc Meta Table).
|
||||
/// Prefers English, falls back to first available language.
|
||||
/// Returns None if META directory is empty or XML has no usable title.
|
||||
pub(super) fn read_meta_title(reader: &mut dyn SectorReader, udf_fs: &udf::UdfFs) -> Option<String> {
|
||||
pub(super) fn read_meta_title(
|
||||
reader: &mut dyn SectorReader,
|
||||
udf_fs: &udf::UdfFs,
|
||||
) -> Option<String> {
|
||||
let meta_dir = udf_fs.find_dir("/BDMV/META")?;
|
||||
for sub in &meta_dir.entries {
|
||||
if !sub.is_dir {
|
||||
|
||||
+7
-7
@@ -7,7 +7,10 @@ use crate::udf;
|
||||
|
||||
impl Disc {
|
||||
/// Scan DVD titles from IFO files (VIDEO_TS.IFO + VTS_XX_0.IFO).
|
||||
pub(super) fn scan_dvd_titles(reader: &mut dyn SectorReader, udf_fs: &udf::UdfFs) -> Vec<DiscTitle> {
|
||||
pub(super) fn scan_dvd_titles(
|
||||
reader: &mut dyn SectorReader,
|
||||
udf_fs: &udf::UdfFs,
|
||||
) -> Vec<DiscTitle> {
|
||||
let dvd_info = match ifo::parse_vmg(reader, udf_fs) {
|
||||
Ok(info) => info,
|
||||
Err(_) => return Vec::new(),
|
||||
@@ -83,8 +86,8 @@ impl Disc {
|
||||
.cells
|
||||
.iter()
|
||||
.map(|cell| {
|
||||
let start = ts.vob_start_sector + cell.first_sector;
|
||||
let count = cell.last_sector.saturating_sub(cell.first_sector) + 1;
|
||||
let start = ts.vob_start_sector.saturating_add(cell.first_sector);
|
||||
let count = cell.last_sector.saturating_sub(cell.first_sector).saturating_add(1);
|
||||
Extent {
|
||||
start_lba: start,
|
||||
sector_count: count,
|
||||
@@ -92,10 +95,7 @@ impl Disc {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let size_bytes: u64 = extents
|
||||
.iter()
|
||||
.map(|e| e.sector_count as u64 * 2048)
|
||||
.sum();
|
||||
let size_bytes: u64 = extents.iter().map(|e| e.sector_count as u64 * 2048).sum();
|
||||
|
||||
// Build pre-formatted palette codec_data for VobSub subtitle streams
|
||||
let codec_data = dvd_title
|
||||
|
||||
+5
-7
@@ -11,13 +11,15 @@ use crate::udf;
|
||||
pub(super) struct HandshakeResult {
|
||||
pub volume_id: [u8; 16],
|
||||
pub read_data_key: Option<[u8; 16]>,
|
||||
pub error: Option<crate::error::Error>,
|
||||
}
|
||||
|
||||
impl Disc {
|
||||
/// SCSI handshake result — volume ID and bus keys from ECDH authentication.
|
||||
/// Only available when scanning from a real drive (not ISO images).
|
||||
pub(super) fn do_handshake(session: &mut crate::drive::DriveSession, opts: &ScanOptions) -> Option<HandshakeResult> {
|
||||
pub(super) fn do_handshake(
|
||||
session: &mut crate::drive::DriveSession,
|
||||
opts: &ScanOptions,
|
||||
) -> Option<HandshakeResult> {
|
||||
use crate::aacs::{self, KeyDb};
|
||||
|
||||
let keydb_path = opts.resolve_keydb()?;
|
||||
@@ -35,7 +37,6 @@ impl Disc {
|
||||
return Some(HandshakeResult {
|
||||
volume_id,
|
||||
read_data_key,
|
||||
error: None,
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -45,10 +46,9 @@ impl Disc {
|
||||
}
|
||||
}
|
||||
}
|
||||
last_error.map(|e| HandshakeResult {
|
||||
last_error.map(|_e| HandshakeResult {
|
||||
volume_id: [0u8; 16],
|
||||
read_data_key: None,
|
||||
error: Some(e),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ impl Disc {
|
||||
// (KEYDB VUK lookup by disc hash works without volume ID)
|
||||
let volume_id = handshake.map(|h| h.volume_id).unwrap_or([0u8; 16]);
|
||||
let read_data_key = handshake.and_then(|h| h.read_data_key);
|
||||
let handshake_error = None;
|
||||
|
||||
// Resolve: tries all available paths — KEYDB VUK, media key, processing key, device key
|
||||
let resolved = aacs::resolve_keys(
|
||||
@@ -118,7 +117,6 @@ impl Disc {
|
||||
unit_keys: resolved.unit_keys,
|
||||
read_data_key,
|
||||
volume_id,
|
||||
handshake_error,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+22
-26
@@ -370,8 +370,6 @@ pub struct AacsState {
|
||||
pub read_data_key: Option<[u8; 16]>,
|
||||
/// Volume ID (16 bytes) -- from SCSI handshake
|
||||
pub volume_id: [u8; 16],
|
||||
/// Handshake error code if authentication failed (None = no HC, or success)
|
||||
pub handshake_error: Option<crate::error::Error>,
|
||||
}
|
||||
|
||||
/// How AACS keys were resolved.
|
||||
@@ -414,7 +412,6 @@ pub struct ScanOptions {
|
||||
pub keydb_path: Option<std::path::PathBuf>,
|
||||
}
|
||||
|
||||
|
||||
impl ScanOptions {
|
||||
/// Create options with a specific KEYDB path.
|
||||
pub fn with_keydb(path: impl Into<std::path::PathBuf>) -> Self {
|
||||
@@ -577,9 +574,15 @@ impl Disc {
|
||||
|
||||
// 3. Titles — BD (MPLS playlists) or DVD (IFO title sets)
|
||||
let (mut titles, content_format) = if udf_fs.find_dir("/BDMV").is_some() {
|
||||
(Self::scan_bluray_titles(reader, &udf_fs), ContentFormat::BdTs)
|
||||
(
|
||||
Self::scan_bluray_titles(reader, &udf_fs),
|
||||
ContentFormat::BdTs,
|
||||
)
|
||||
} else if udf_fs.find_dir("/VIDEO_TS").is_some() {
|
||||
(Self::scan_dvd_titles(reader, &udf_fs), ContentFormat::MpegPs)
|
||||
(
|
||||
Self::scan_dvd_titles(reader, &udf_fs),
|
||||
ContentFormat::MpegPs,
|
||||
)
|
||||
} else {
|
||||
(Vec::new(), ContentFormat::BdTs)
|
||||
};
|
||||
@@ -667,7 +670,6 @@ impl Disc {
|
||||
let lba = u32::from_be_bytes([buf[0], buf[1], buf[2], buf[3]]);
|
||||
Ok(lba + 1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ─── Decrypted reader ──────────────────────────────────────────────────────
|
||||
@@ -684,7 +686,6 @@ pub struct ContentReader<'a> {
|
||||
session: &'a mut DriveSession,
|
||||
aacs: Option<&'a AacsState>,
|
||||
css: Option<&'a crate::css::CssState>,
|
||||
content_format: ContentFormat,
|
||||
extents: Vec<Extent>,
|
||||
current_extent: usize,
|
||||
current_offset: u32,
|
||||
@@ -716,13 +717,10 @@ impl Disc {
|
||||
session: &'a mut DriveSession,
|
||||
title_idx: usize,
|
||||
) -> Result<ContentReader<'a>> {
|
||||
let title = self
|
||||
.titles
|
||||
.get(title_idx)
|
||||
.ok_or(Error::DiscTitleRange {
|
||||
index: title_idx,
|
||||
count: self.titles.len(),
|
||||
})?;
|
||||
let title = self.titles.get(title_idx).ok_or(Error::DiscTitleRange {
|
||||
index: title_idx,
|
||||
count: self.titles.len(),
|
||||
})?;
|
||||
|
||||
// Let the drive manage its own read speed after init.
|
||||
// SET_CD_SPEED is only used reactively by the error handler to slow
|
||||
@@ -735,7 +733,6 @@ impl Disc {
|
||||
session,
|
||||
aacs: self.aacs.as_ref(),
|
||||
css: self.css.as_ref(),
|
||||
content_format: title.content_format,
|
||||
extents: title.extents.clone(),
|
||||
current_extent: 0,
|
||||
current_offset: 0,
|
||||
@@ -756,7 +753,7 @@ impl Disc {
|
||||
/// Reads /sys/block/<dev>/queue/max_hw_sectors_kb on Linux.
|
||||
/// For sg devices, resolves the corresponding block device via sysfs.
|
||||
/// Returns a value aligned to 3 sectors (one aligned unit).
|
||||
fn detect_max_batch_sectors(device_path: &str) -> u16 {
|
||||
pub(crate) fn detect_max_batch_sectors(device_path: &str) -> u16 {
|
||||
let dev_name = device_path.rsplit('/').next().unwrap_or("");
|
||||
if dev_name.is_empty() {
|
||||
return DEFAULT_BATCH_SECTORS;
|
||||
@@ -793,12 +790,12 @@ fn detect_max_batch_sectors(device_path: &str) -> u16 {
|
||||
}
|
||||
|
||||
/// Read strategy constants
|
||||
const MAX_BATCH_SECTORS: u16 = 510; // absolute max (170 aligned units ≈ 1MB)
|
||||
const DEFAULT_BATCH_SECTORS: u16 = 60; // fallback: typical kernel limit (120KB = 60 sectors)
|
||||
const MIN_BATCH_SECTORS: u16 = 3; // 1 aligned unit = 6KB (error recovery)
|
||||
const RAMP_BATCH_AFTER: u32 = 5; // successes before doubling batch size
|
||||
const RAMP_SPEED_AFTER: u32 = 50; // successes at max batch before restoring speed
|
||||
const SLOW_SPEED_AFTER: u32 = 3; // consecutive errors before reducing disc speed
|
||||
pub(crate) const MAX_BATCH_SECTORS: u16 = 510; // absolute max (170 aligned units ≈ 1MB)
|
||||
pub(crate) const DEFAULT_BATCH_SECTORS: u16 = 60; // fallback: typical kernel limit (120KB = 60 sectors)
|
||||
pub(crate) const MIN_BATCH_SECTORS: u16 = 3; // 1 aligned unit = 6KB (error recovery)
|
||||
pub(crate) const RAMP_BATCH_AFTER: u32 = 5; // successes before doubling batch size
|
||||
pub(crate) const RAMP_SPEED_AFTER: u32 = 50; // successes at max batch before restoring speed
|
||||
pub(crate) const SLOW_SPEED_AFTER: u32 = 3; // consecutive errors before reducing disc speed
|
||||
|
||||
impl<'a> ContentReader<'a> {
|
||||
/// Total bytes across all extents (for progress display).
|
||||
@@ -814,10 +811,9 @@ impl<'a> ContentReader<'a> {
|
||||
/// Returns None when all extents are exhausted.
|
||||
pub fn read_unit(&mut self) -> Result<Option<Vec<u8>>> {
|
||||
// Refill buffer if empty
|
||||
if self.buf_pos >= self.buf_len
|
||||
&& !self.fill_buffer()? {
|
||||
return Ok(None);
|
||||
}
|
||||
if self.buf_pos >= self.buf_len && !self.fill_buffer()? {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
// Extract one aligned unit from buffer
|
||||
let start = self.buf_pos * crate::aacs::ALIGNED_UNIT_LEN;
|
||||
|
||||
Reference in New Issue
Block a user