Prepare for calculating LBAs

This commit is contained in:
jaby 2022-10-10 22:06:11 +02:00
parent cb9ca1e678
commit 9737ca4551
3 changed files with 32 additions and 4 deletions

View File

@ -23,6 +23,8 @@ fn populate() -> Result<CDDesc, Error> {
desc.root.add_dir(folder);
desc.root.add_file(file);
desc.root.add_file(file2);
desc.calculate_lbas();
Ok(desc)
}
@ -31,10 +33,10 @@ fn run_main() -> Result<(), Error> {
for element in desc.get_memory_layout().iter() {
match element {
Layout::SystemArea(_) => println!("SystemArea:"),
Layout::PVD(_) => println!("PVD:"),
Layout::Directory{name, properties: _} => println!("Dir: {}", name),
Layout::File(file) => println!("File: {}", file),
Layout::SystemArea(_) => println!("SystemArea:"),
Layout::PVD(_) => println!("PVD:"),
Layout::Directory{name, properties} => println!("Dir: {} @{}", name, properties.lba.unwrap_or(0)),
Layout::File(file) => println!("File: {} @{}", file, file.get_lba().unwrap_or(0)),
}
}
Ok(())

View File

@ -0,0 +1,13 @@
use super::layout::MemoryLayoutMut;
pub fn calculate(layout: MemoryLayoutMut, start_lba: usize) -> usize {
let lba = start_lba;
for element in layout.into_iter() {
match element {
_ => println!("LBA calculation not implemented yet")
}
}
lba
}

View File

@ -1,4 +1,5 @@
pub mod layout;
mod lba_calculator;
use cdtypes::types::cdstring::DString;
use tool_helper::Error;
@ -17,6 +18,10 @@ impl CDDesc {
}
}
pub fn calculate_lbas(&mut self) {
lba_calculator::calculate(self.get_memory_layout_mut(), 0);
}
pub fn get_memory_layout(&self) -> layout::MemoryLayout {
layout::DefaultLayout::new(self)
}
@ -63,6 +68,10 @@ impl Directory {
pub fn add_file(&mut self, file: File) {
self.files.push(file);
}
pub fn get_lba(&self) -> Option<usize> {
self.properties.lba
}
}
impl std::fmt::Display for Directory {
@ -80,6 +89,10 @@ impl File {
pub fn new(file_name: &str) -> Result<File, Error> {
Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default()})
}
pub fn get_lba(&self) -> Option<usize> {
self.properties.lba
}
}
impl std::fmt::Display for File {