mirror of
https://github.com/encounter/nod-rs.git
synced 2025-12-13 15:16:21 +00:00
Strip partitions from WBFS
This commit is contained in:
@@ -38,6 +38,8 @@ pub enum Format {
|
|||||||
Rvz,
|
Rvz,
|
||||||
/// WBFS
|
/// WBFS
|
||||||
Wbfs,
|
Wbfs,
|
||||||
|
/// Partition stripped WBFS
|
||||||
|
StrippedWbfs([bool; 64]),
|
||||||
/// WIA
|
/// WIA
|
||||||
Wia,
|
Wia,
|
||||||
/// TGC
|
/// TGC
|
||||||
@@ -53,6 +55,7 @@ impl Format {
|
|||||||
Format::Gcz => crate::io::gcz::DEFAULT_BLOCK_SIZE,
|
Format::Gcz => crate::io::gcz::DEFAULT_BLOCK_SIZE,
|
||||||
Format::Rvz => crate::io::wia::RVZ_DEFAULT_CHUNK_SIZE,
|
Format::Rvz => crate::io::wia::RVZ_DEFAULT_CHUNK_SIZE,
|
||||||
Format::Wbfs => crate::io::wbfs::DEFAULT_BLOCK_SIZE,
|
Format::Wbfs => crate::io::wbfs::DEFAULT_BLOCK_SIZE,
|
||||||
|
Format::StrippedWbfs(_) => crate::io::wbfs::DEFAULT_BLOCK_SIZE,
|
||||||
Format::Wia => crate::io::wia::WIA_DEFAULT_CHUNK_SIZE,
|
Format::Wia => crate::io::wia::WIA_DEFAULT_CHUNK_SIZE,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
}
|
}
|
||||||
@@ -80,6 +83,7 @@ impl fmt::Display for Format {
|
|||||||
Format::Nfs => write!(f, "NFS"),
|
Format::Nfs => write!(f, "NFS"),
|
||||||
Format::Rvz => write!(f, "RVZ"),
|
Format::Rvz => write!(f, "RVZ"),
|
||||||
Format::Wbfs => write!(f, "WBFS"),
|
Format::Wbfs => write!(f, "WBFS"),
|
||||||
|
Format::StrippedWbfs(_) => write!(f, "Stripped WBFS"),
|
||||||
Format::Wia => write!(f, "WIA"),
|
Format::Wia => write!(f, "WIA"),
|
||||||
Format::Tgc => write!(f, "TGC"),
|
Format::Tgc => write!(f, "TGC"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,12 +200,18 @@ pub(crate) fn check_block(
|
|||||||
lfg: &mut LaggedFibonacci,
|
lfg: &mut LaggedFibonacci,
|
||||||
disc_id: [u8; 4],
|
disc_id: [u8; 4],
|
||||||
disc_num: u8,
|
disc_num: u8,
|
||||||
|
strip_partitions: [bool; 64]
|
||||||
) -> io::Result<CheckBlockResult> {
|
) -> io::Result<CheckBlockResult> {
|
||||||
let start_sector = (input_position / SECTOR_SIZE as u64) as u32;
|
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;
|
let end_sector = ((input_position + buf.len() as u64) / SECTOR_SIZE as u64) as u32;
|
||||||
if let Some(partition) = partition_info.iter().find(|p| {
|
if let Some(partition) = partition_info.iter().find(|p| {
|
||||||
p.has_hashes && start_sector >= p.data_start_sector && end_sector < p.data_end_sector
|
p.has_hashes && start_sector >= p.data_start_sector && end_sector < p.data_end_sector
|
||||||
}) {
|
}) {
|
||||||
|
// Strip partition data
|
||||||
|
if strip_partitions[partition.index] {
|
||||||
|
return Ok(CheckBlockResult::Zeroed);
|
||||||
|
}
|
||||||
|
|
||||||
if input_position % SECTOR_SIZE as u64 != 0 {
|
if input_position % SECTOR_SIZE as u64 != 0 {
|
||||||
return Err(io::Error::other("Partition block not aligned to sector boundary"));
|
return Err(io::Error::other("Partition block not aligned to sector boundary"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ pub fn new(mut stream: Box<dyn DiscStream>) -> Result<Box<dyn BlockReader>> {
|
|||||||
Some(Format::Nfs) => {
|
Some(Format::Nfs) => {
|
||||||
return Err(Error::DiscFormat("NFS requires a filesystem path".to_string()));
|
return Err(Error::DiscFormat("NFS requires a filesystem path".to_string()));
|
||||||
}
|
}
|
||||||
Some(Format::Wbfs) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
Some(Format::Wbfs | Format::StrippedWbfs(_)) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
||||||
Some(Format::Wia | Format::Rvz) => crate::io::wia::BlockReaderWIA::new(stream)?,
|
Some(Format::Wia | Format::Rvz) => crate::io::wia::BlockReaderWIA::new(stream)?,
|
||||||
Some(Format::Tgc) => crate::io::tgc::BlockReaderTGC::new(stream)?,
|
Some(Format::Tgc) => crate::io::tgc::BlockReaderTGC::new(stream)?,
|
||||||
None => return Err(Error::DiscFormat("Unknown disc format".to_string())),
|
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::Tgc) => crate::io::tgc::BlockReaderTGC::new(stream)?,
|
||||||
Some(Format::Wbfs) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
Some(Format::Wbfs | Format::StrippedWbfs(_)) => crate::io::wbfs::BlockReaderWBFS::new(stream)?,
|
||||||
Some(Format::Wia | Format::Rvz) => crate::io::wia::BlockReaderWIA::new(stream)?,
|
Some(Format::Wia | Format::Rvz) => crate::io::wia::BlockReaderWIA::new(stream)?,
|
||||||
None => return Err(Error::DiscFormat("Unknown disc format".to_string())),
|
None => return Err(Error::DiscFormat("Unknown disc format".to_string())),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ impl BlockProcessor for BlockProcessorCISO {
|
|||||||
&mut self.lfg,
|
&mut self.lfg,
|
||||||
self.disc_id,
|
self.disc_id,
|
||||||
self.disc_num,
|
self.disc_num,
|
||||||
|
[false; 64]
|
||||||
)? {
|
)? {
|
||||||
CheckBlockResult::Normal => {
|
CheckBlockResult::Normal => {
|
||||||
BlockResult { block_idx, disc_data, block_data, meta: CheckBlockResult::Normal }
|
BlockResult { block_idx, disc_data, block_data, meta: CheckBlockResult::Normal }
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ struct BlockProcessorWBFS {
|
|||||||
lfg: LaggedFibonacci,
|
lfg: LaggedFibonacci,
|
||||||
disc_id: [u8; 4],
|
disc_id: [u8; 4],
|
||||||
disc_num: u8,
|
disc_num: u8,
|
||||||
|
strip_partitions: [bool; 64]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for BlockProcessorWBFS {
|
impl Clone for BlockProcessorWBFS {
|
||||||
@@ -177,6 +178,7 @@ impl Clone for BlockProcessorWBFS {
|
|||||||
lfg: LaggedFibonacci::default(),
|
lfg: LaggedFibonacci::default(),
|
||||||
disc_id: self.disc_id,
|
disc_id: self.disc_id,
|
||||||
disc_num: self.disc_num,
|
disc_num: self.disc_num,
|
||||||
|
strip_partitions: self.strip_partitions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,6 +201,7 @@ impl BlockProcessor for BlockProcessorWBFS {
|
|||||||
&mut self.lfg,
|
&mut self.lfg,
|
||||||
self.disc_id,
|
self.disc_id,
|
||||||
self.disc_num,
|
self.disc_num,
|
||||||
|
self.strip_partitions
|
||||||
)? {
|
)? {
|
||||||
CheckBlockResult::Normal => {
|
CheckBlockResult::Normal => {
|
||||||
BlockResult { block_idx, disc_data, block_data, meta: CheckBlockResult::Normal }
|
BlockResult { block_idx, disc_data, block_data, meta: CheckBlockResult::Normal }
|
||||||
@@ -226,15 +229,19 @@ pub struct DiscWriterWBFS {
|
|||||||
header: WBFSHeader,
|
header: WBFSHeader,
|
||||||
disc_table: Box<[u8]>,
|
disc_table: Box<[u8]>,
|
||||||
block_count: u16,
|
block_count: u16,
|
||||||
|
strip_partitions: [bool; 64],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const DEFAULT_BLOCK_SIZE: u32 = 0x200000; // 2 MiB
|
pub const DEFAULT_BLOCK_SIZE: u32 = 0x200000; // 2 MiB
|
||||||
|
|
||||||
impl DiscWriterWBFS {
|
impl DiscWriterWBFS {
|
||||||
pub fn new(mut inner: DiscReader, options: &FormatOptions) -> Result<Box<dyn DiscWriter>> {
|
pub fn new(mut inner: DiscReader, options: &FormatOptions) -> Result<Box<dyn DiscWriter>> {
|
||||||
if options.format != Format::Wbfs {
|
let strip_partitions = match options.format {
|
||||||
return Err(Error::DiscFormat("Invalid format for WBFS writer".to_string()));
|
Format::Wbfs => [false; 64],
|
||||||
}
|
Format::StrippedWbfs(strip_partitions) => strip_partitions,
|
||||||
|
_ => return Err(Error::DiscFormat("Invalid format for WBFS writer".to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
if options.compression != Compression::None {
|
if options.compression != Compression::None {
|
||||||
return Err(Error::DiscFormat("WBFS does not support compression".to_string()));
|
return Err(Error::DiscFormat("WBFS does not support compression".to_string()));
|
||||||
}
|
}
|
||||||
@@ -275,7 +282,7 @@ impl DiscWriterWBFS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inner.rewind().context("Seeking to start")?;
|
inner.rewind().context("Seeking to start")?;
|
||||||
Ok(Box::new(Self { inner, header, disc_table, block_count }))
|
Ok(Box::new(Self { inner, header, disc_table, block_count, strip_partitions }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,6 +324,7 @@ impl DiscWriter for DiscWriterWBFS {
|
|||||||
lfg: LaggedFibonacci::default(),
|
lfg: LaggedFibonacci::default(),
|
||||||
disc_id,
|
disc_id,
|
||||||
disc_num,
|
disc_num,
|
||||||
|
strip_partitions: self.strip_partitions
|
||||||
},
|
},
|
||||||
self.block_count as u32,
|
self.block_count as u32,
|
||||||
options.processor_threads,
|
options.processor_threads,
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ impl DiscWriter {
|
|||||||
Format::Gcz => crate::io::gcz::DiscWriterGCZ::new(reader, &options)?,
|
Format::Gcz => crate::io::gcz::DiscWriterGCZ::new(reader, &options)?,
|
||||||
Format::Tgc => crate::io::tgc::DiscWriterTGC::new(reader, &options)?,
|
Format::Tgc => crate::io::tgc::DiscWriterTGC::new(reader, &options)?,
|
||||||
Format::Wbfs => crate::io::wbfs::DiscWriterWBFS::new(reader, &options)?,
|
Format::Wbfs => crate::io::wbfs::DiscWriterWBFS::new(reader, &options)?,
|
||||||
|
Format::StrippedWbfs(_) => crate::io::wbfs::DiscWriterWBFS::new(reader, &options)?,
|
||||||
Format::Wia | Format::Rvz => crate::io::wia::DiscWriterWIA::new(reader, &options)?,
|
Format::Wia | Format::Rvz => crate::io::wia::DiscWriterWIA::new(reader, &options)?,
|
||||||
format => return Err(Error::Other(format!("Unsupported write format: {format}"))),
|
format => return Err(Error::Other(format!("Unsupported write format: {format}"))),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user