Start calculating LBAs
This commit is contained in:
parent
ee2c2d8ebd
commit
2761cca70b
|
@ -1,7 +1,8 @@
|
|||
mod helper;
|
||||
pub mod layout;
|
||||
|
||||
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord};
|
||||
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::sector_count_mode2_form1, sector::*};
|
||||
use layout::LayoutMut;
|
||||
use tool_helper::Error;
|
||||
|
||||
pub struct CDDesc {
|
||||
|
@ -11,6 +12,8 @@ pub struct CDDesc {
|
|||
}
|
||||
|
||||
impl CDDesc {
|
||||
const DEFAULT_DATA_SIZE_FOR_NOW:usize = Mode2Form1::DATA_SIZE;
|
||||
|
||||
pub fn new() -> CDDesc {
|
||||
match Directory::new("root") {
|
||||
Ok(root) => CDDesc{system_area: SystemArea::new(), pvd: PrimaryVolumeDescriptor::new(), root},
|
||||
|
@ -27,9 +30,24 @@ impl CDDesc {
|
|||
}
|
||||
|
||||
pub fn calculate_lbas(&mut self) {
|
||||
let mut cur_lba = 0;
|
||||
|
||||
Self::for_each_dir_mut(&mut self.root, &|dir| {dir.update_content_size();});
|
||||
|
||||
// Now layout iterate?
|
||||
for element in self.get_memory_layout_mut() {
|
||||
match element {
|
||||
LayoutMut::SystemArea(system_area) => {
|
||||
let system_area_props = &mut system_area.properties;
|
||||
|
||||
system_area_props.lba = cur_lba;
|
||||
cur_lba += system_area_props.sector_count_xa_data(Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
|
||||
println!("cur_lba: {}", cur_lba);
|
||||
}
|
||||
}
|
||||
|
||||
fn for_each_dir_mut<T: Fn(&mut Directory)>(dir: &mut Directory, function: &T) {
|
||||
|
@ -41,11 +59,14 @@ impl CDDesc {
|
|||
}
|
||||
|
||||
pub struct SystemArea {
|
||||
pub properties: Properties
|
||||
}
|
||||
|
||||
impl SystemArea {
|
||||
const DEFAULT_SIZE:usize = (16*Mode2Form1::DATA_SIZE);
|
||||
|
||||
pub fn new() -> SystemArea {
|
||||
SystemArea{}
|
||||
SystemArea{properties: Properties{lba: 0, overwrite_size_bytes: Some(Self::DEFAULT_SIZE), is_hidden: false}}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +108,7 @@ impl Directory {
|
|||
}
|
||||
|
||||
self.properties.overwrite_size_bytes = Some(size_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
fn _update_content(&mut self) {
|
||||
let dir_member = helper::collect_directory_record_member(&self.files, &self.dirs);
|
||||
|
@ -196,6 +217,22 @@ pub struct Properties {
|
|||
pub is_hidden: bool
|
||||
}
|
||||
|
||||
impl Properties {
|
||||
pub fn sector_count_xa_data(&self, content_size: usize) -> usize {
|
||||
let size_bytes = {
|
||||
if let Some(forced_bytes) = self.overwrite_size_bytes {
|
||||
forced_bytes
|
||||
}
|
||||
|
||||
else {
|
||||
content_size
|
||||
}
|
||||
};
|
||||
|
||||
sector_count_mode2_form1(size_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Properties {
|
||||
fn default() -> Self {
|
||||
Properties{lba: 0, overwrite_size_bytes: None, is_hidden: false}
|
||||
|
|
Loading…
Reference in New Issue