mirror of
https://github.com/encounter/nod-rs.git
synced 2025-12-14 15:46:29 +00:00
Draft: add ProcessOptions::scrub_update_partition
This commit is contained in:
@@ -38,8 +38,6 @@ pub enum Format {
|
||||
Rvz,
|
||||
/// WBFS
|
||||
Wbfs,
|
||||
/// Partition stripped WBFS
|
||||
StrippedWbfs([bool; 64]),
|
||||
/// WIA
|
||||
Wia,
|
||||
/// TGC
|
||||
@@ -54,7 +52,7 @@ impl Format {
|
||||
#[cfg(feature = "compress-zlib")]
|
||||
Format::Gcz => crate::io::gcz::DEFAULT_BLOCK_SIZE,
|
||||
Format::Rvz => crate::io::wia::RVZ_DEFAULT_CHUNK_SIZE,
|
||||
Format::Wbfs | Format::StrippedWbfs(_) => crate::io::wbfs::DEFAULT_BLOCK_SIZE,
|
||||
Format::Wbfs => crate::io::wbfs::DEFAULT_BLOCK_SIZE,
|
||||
Format::Wia => crate::io::wia::WIA_DEFAULT_CHUNK_SIZE,
|
||||
_ => 0,
|
||||
}
|
||||
@@ -82,7 +80,6 @@ impl fmt::Display for Format {
|
||||
Format::Nfs => write!(f, "NFS"),
|
||||
Format::Rvz => write!(f, "RVZ"),
|
||||
Format::Wbfs => write!(f, "WBFS"),
|
||||
Format::StrippedWbfs(_) => write!(f, "Stripped WBFS"),
|
||||
Format::Wia => write!(f, "WIA"),
|
||||
Format::Tgc => write!(f, "TGC"),
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use crate::{
|
||||
util::{aes::decrypt_sector_b2b, array_ref, array_ref_mut, lfg::LaggedFibonacci},
|
||||
write::{DataCallback, DiscFinalization, DiscWriterWeight, ProcessOptions},
|
||||
};
|
||||
use crate::common::PartitionKind;
|
||||
|
||||
/// A trait for writing disc images.
|
||||
pub trait DiscWriter: DynClone {
|
||||
@@ -200,15 +201,15 @@ pub(crate) fn check_block(
|
||||
lfg: &mut LaggedFibonacci,
|
||||
disc_id: [u8; 4],
|
||||
disc_num: u8,
|
||||
strip_partitions: [bool; 64]
|
||||
scrub_update_partition: bool,
|
||||
) -> io::Result<CheckBlockResult> {
|
||||
let start_sector = (input_position / SECTOR_SIZE as u64) as u32;
|
||||
let end_sector = ((input_position + buf.len() as u64) / SECTOR_SIZE as u64) as u32;
|
||||
if let Some(partition) = partition_info.iter().find(|p| {
|
||||
p.has_hashes && start_sector >= p.data_start_sector && end_sector < p.data_end_sector
|
||||
}) {
|
||||
// Strip partition data
|
||||
if strip_partitions[partition.index] {
|
||||
// Ignore update partition data
|
||||
if scrub_update_partition && partition.kind == PartitionKind::Update {
|
||||
return Ok(CheckBlockResult::Zeroed);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ pub fn new(mut stream: Box<dyn DiscStream>) -> Result<Box<dyn BlockReader>> {
|
||||
Some(Format::Nfs) => {
|
||||
return Err(Error::DiscFormat("NFS requires a filesystem path".to_string()));
|
||||
}
|
||||
Some(Format::Wbfs | Format::StrippedWbfs(_)) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
||||
Some(Format::Wbfs) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
||||
Some(Format::Wia | Format::Rvz) => crate::io::wia::BlockReaderWIA::new(stream)?,
|
||||
Some(Format::Tgc) => crate::io::tgc::BlockReaderTGC::new(stream)?,
|
||||
None => return Err(Error::DiscFormat("Unknown disc format".to_string())),
|
||||
@@ -99,7 +99,7 @@ pub fn open(filename: &Path) -> Result<Box<dyn BlockReader>> {
|
||||
}
|
||||
},
|
||||
Some(Format::Tgc) => crate::io::tgc::BlockReaderTGC::new(stream)?,
|
||||
Some(Format::Wbfs | Format::StrippedWbfs(_)) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
||||
Some(Format::Wbfs) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
||||
Some(Format::Wia | Format::Rvz) => crate::io::wia::BlockReaderWIA::new(stream)?,
|
||||
None => return Err(Error::DiscFormat("Unknown disc format".to_string())),
|
||||
};
|
||||
|
||||
@@ -178,7 +178,7 @@ impl BlockProcessor for BlockProcessorCISO {
|
||||
&mut self.lfg,
|
||||
self.disc_id,
|
||||
self.disc_num,
|
||||
[false; 64]
|
||||
false
|
||||
)? {
|
||||
CheckBlockResult::Normal => {
|
||||
BlockResult { block_idx, disc_data, block_data, meta: CheckBlockResult::Normal }
|
||||
|
||||
@@ -165,7 +165,7 @@ struct BlockProcessorWBFS {
|
||||
lfg: LaggedFibonacci,
|
||||
disc_id: [u8; 4],
|
||||
disc_num: u8,
|
||||
strip_partitions: [bool; 64]
|
||||
scrub_update_partition: bool,
|
||||
}
|
||||
|
||||
impl Clone for BlockProcessorWBFS {
|
||||
@@ -178,7 +178,7 @@ impl Clone for BlockProcessorWBFS {
|
||||
lfg: LaggedFibonacci::default(),
|
||||
disc_id: self.disc_id,
|
||||
disc_num: self.disc_num,
|
||||
strip_partitions: self.strip_partitions,
|
||||
scrub_update_partition: self.scrub_update_partition,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ impl BlockProcessor for BlockProcessorWBFS {
|
||||
&mut self.lfg,
|
||||
self.disc_id,
|
||||
self.disc_num,
|
||||
self.strip_partitions
|
||||
self.scrub_update_partition
|
||||
)? {
|
||||
CheckBlockResult::Normal => {
|
||||
BlockResult { block_idx, disc_data, block_data, meta: CheckBlockResult::Normal }
|
||||
@@ -229,18 +229,15 @@ pub struct DiscWriterWBFS {
|
||||
header: WBFSHeader,
|
||||
disc_table: Box<[u8]>,
|
||||
block_count: u16,
|
||||
strip_partitions: [bool; 64],
|
||||
}
|
||||
|
||||
pub const DEFAULT_BLOCK_SIZE: u32 = 0x200000; // 2 MiB
|
||||
|
||||
impl DiscWriterWBFS {
|
||||
pub fn new(mut inner: DiscReader, options: &FormatOptions) -> Result<Box<dyn DiscWriter>> {
|
||||
let strip_partitions = match options.format {
|
||||
Format::Wbfs => [false; 64],
|
||||
Format::StrippedWbfs(strip_partitions) => strip_partitions,
|
||||
_ => return Err(Error::DiscFormat("Invalid format for WBFS writer".to_string())),
|
||||
};
|
||||
if options.format != Format::Wbfs {
|
||||
return Err(Error::DiscFormat("Invalid format for WBFS writer".to_string()));
|
||||
}
|
||||
|
||||
if options.compression != Compression::None {
|
||||
return Err(Error::DiscFormat("WBFS does not support compression".to_string()));
|
||||
@@ -282,7 +279,7 @@ impl DiscWriterWBFS {
|
||||
}
|
||||
|
||||
inner.rewind().context("Seeking to start")?;
|
||||
Ok(Box::new(Self { inner, header, disc_table, block_count, strip_partitions }))
|
||||
Ok(Box::new(Self { inner, header, disc_table, block_count }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +321,7 @@ impl DiscWriter for DiscWriterWBFS {
|
||||
lfg: LaggedFibonacci::default(),
|
||||
disc_id,
|
||||
disc_num,
|
||||
strip_partitions: self.strip_partitions
|
||||
scrub_update_partition: options.scrub_update_partition
|
||||
},
|
||||
self.block_count as u32,
|
||||
options.processor_threads,
|
||||
|
||||
@@ -70,6 +70,10 @@ pub struct ProcessOptions {
|
||||
/// Each digest calculation will run on a separate thread, unaffected by the processor thread
|
||||
/// count.
|
||||
pub digest_xxh64: bool,
|
||||
/// Strip out the update partition to save space.
|
||||
///
|
||||
/// This is implemented only for WBFS for now.
|
||||
pub scrub_update_partition: bool
|
||||
}
|
||||
|
||||
/// A callback for writing disc data.
|
||||
@@ -106,7 +110,7 @@ impl DiscWriter {
|
||||
#[cfg(feature = "compress-zlib")]
|
||||
Format::Gcz => crate::io::gcz::DiscWriterGCZ::new(reader, &options)?,
|
||||
Format::Tgc => crate::io::tgc::DiscWriterTGC::new(reader, &options)?,
|
||||
Format::Wbfs | Format::StrippedWbfs(_) => crate::io::wbfs::DiscWriterWBFS::new(reader, &options)?,
|
||||
Format::Wbfs => crate::io::wbfs::DiscWriterWBFS::new(reader, &options)?,
|
||||
Format::Wia | Format::Rvz => crate::io::wia::DiscWriterWIA::new(reader, &options)?,
|
||||
format => return Err(Error::Other(format!("Unsupported write format: {format}"))),
|
||||
};
|
||||
|
||||
@@ -192,6 +192,7 @@ fn load_disc(path: &Path, name: &str, full_verify: bool) -> Result<DiscHashes> {
|
||||
digest_md5: false,
|
||||
digest_sha1: true,
|
||||
digest_xxh64: false,
|
||||
scrub_update_partition: false
|
||||
},
|
||||
)?;
|
||||
pb.finish();
|
||||
|
||||
@@ -123,6 +123,7 @@ pub fn convert_and_verify(
|
||||
digest_md5: md5,
|
||||
digest_sha1: true,
|
||||
digest_xxh64: true,
|
||||
scrub_update_partition: false
|
||||
},
|
||||
)?;
|
||||
pb.finish();
|
||||
|
||||
Reference in New Issue
Block a user