Calculate LBAs for PathTables

This commit is contained in:
jaby 2022-10-12 21:11:51 +02:00
parent 2761cca70b
commit cf8f16fee3
2 changed files with 64 additions and 9 deletions

View File

@ -1,5 +1,13 @@
use super::*;
const CURRENT_DIR_NAME:&'static str = "/x00";
const PARENT_DIR_NAME:&'static str = "/x01";
pub struct PathTableMember {
pub name: String,
pub parent_table_id: usize,
}
pub enum DirectoryRecordMember {
Directory{name: String},
File{name: String},
@ -14,11 +22,36 @@ impl DirectoryRecordMember {
}
}
pub fn collect_path_table_member(root: &Directory) -> Vec<PathTableMember> {
fn collect_path_table_for(collection: &mut Vec<PathTableMember>, dirs: &Vec<Directory>, parent_id: usize) {
let mut cur_dirs = Vec::new();
for dir in dirs {
cur_dirs.push(PathTableMember{name: dir.name.as_string().unwrap_or("".to_owned()), parent_table_id: parent_id});
}
cur_dirs.sort_by(|a, b| {
a.name.cmp(&b.name)
});
collection.append(&mut cur_dirs);
for dir in dirs {
collect_path_table_for(collection, &dir.dirs, parent_id + 1);
}
}
let mut collection = Vec::new();
collection.push(PathTableMember{name: CURRENT_DIR_NAME.to_owned(), parent_table_id: 1});
collect_path_table_for(&mut collection, &root.dirs, 1);
collection
}
pub fn collect_directory_record_member(files: &Vec<File>, dirs: &Vec<Directory>) -> Vec<DirectoryRecordMember> {
let mut collection = Vec::new();
collection.push(DirectoryRecordMember::Directory{name: "\x00".to_owned()});
collection.push(DirectoryRecordMember::Directory{name: "\x01".to_owned()});
collection.push(DirectoryRecordMember::Directory{name: CURRENT_DIR_NAME.to_owned()});
collection.push(DirectoryRecordMember::Directory{name: PARENT_DIR_NAME.to_owned()});
for file in files {
if !file.properties.is_hidden {
if let Some(name) = file.name.as_string() {

View File

@ -1,7 +1,7 @@
mod helper;
pub mod layout;
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::sector_count_mode2_form1, sector::*};
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, sector::*, path_table::PathTableL};
use layout::LayoutMut;
use tool_helper::Error;
@ -30,18 +30,37 @@ impl CDDesc {
}
pub fn calculate_lbas(&mut self) {
let mut cur_lba = 0;
let mut path_table_properties = {
let mut size_bytes = 0;
helper::collect_path_table_member(&self.root).into_iter().for_each(|element| {
println!("PT: {} ^{}", element.name, element.parent_table_id);
size_bytes += PathTableL::calculate_size_for(element.name.as_ref());
});
size_bytes = round_bytes_mode2_form1(size_bytes)*4;
Properties{lba: 0, overwrite_size_bytes: Some(size_bytes), is_hidden: false}
};
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() {
fn update_lba(properties: &mut Properties, cur_lba: usize, content_size: usize) -> usize {
properties.lba = cur_lba;
cur_lba + properties.sector_count_xa_data(content_size)
}
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);
cur_lba = update_lba(&mut system_area.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
},
LayoutMut::PVD(pvd) => {
cur_lba = update_lba(&mut pvd.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
},
LayoutMut::PathTables => {
cur_lba = update_lba(&mut path_table_properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
},
_ => ()
}
@ -71,11 +90,14 @@ impl SystemArea {
}
pub struct PrimaryVolumeDescriptor {
pub properties: Properties
}
impl PrimaryVolumeDescriptor {
const DEFAULT_SIZE:usize = (2*Mode2Form1::DATA_SIZE);
pub fn new() -> PrimaryVolumeDescriptor {
PrimaryVolumeDescriptor{}
PrimaryVolumeDescriptor{properties: Properties{lba: 0, overwrite_size_bytes: Some(Self::DEFAULT_SIZE), is_hidden: false}}
}
}