Inital setup
This commit is contained in:
parent
4f3561c098
commit
597f1017cb
|
@ -20,9 +20,9 @@ fn populate() -> Result<CDDesc, Error> {
|
||||||
folder
|
folder
|
||||||
};
|
};
|
||||||
|
|
||||||
desc.root.add_dir(folder);
|
desc.root.borrow_mut().add_dir(folder);
|
||||||
desc.root.add_file(file);
|
desc.root.borrow_mut().add_file(file);
|
||||||
desc.root.add_file(file2);
|
desc.root.borrow_mut().add_file(file2);
|
||||||
|
|
||||||
desc.calculate_lbas();
|
desc.calculate_lbas();
|
||||||
Ok(desc)
|
Ok(desc)
|
||||||
|
@ -37,8 +37,8 @@ fn run_main() -> Result<(), Error> {
|
||||||
Layout::SystemArea(_) => println!("SystemArea:"),
|
Layout::SystemArea(_) => println!("SystemArea:"),
|
||||||
Layout::PVD(_) => println!("PVD:"),
|
Layout::PVD(_) => println!("PVD:"),
|
||||||
Layout::PathTables => println!("PathTables:"),
|
Layout::PathTables => println!("PathTables:"),
|
||||||
Layout::Directory{name, properties} => println!("Dir: {} @{}-{}", name, properties.lba, properties.overwrite_size_bytes.unwrap_or(0)),
|
Layout::Directory(dir) => println!("Dir: {} @{}-{}", dir.borrow().name, dir.borrow().properties.lba, dir.borrow().properties.overwrite_size_bytes.unwrap_or(0)),
|
||||||
Layout::File(file) => println!("File: {} @{}-{}", file, file.properties.lba, file.properties.overwrite_size_bytes.unwrap_or(0)),
|
Layout::File(file) => println!("File: {} @{}-{}", file.borrow(), file.borrow().properties.lba, file.borrow().properties.overwrite_size_bytes.unwrap_or(0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
const CURRENT_DIR_NAME:&'static str = "/x00";
|
const CURRENT_DIR_NAME:&'static str = "/x00";
|
||||||
const PARENT_DIR_NAME:&'static str = "/x01";
|
const PARENT_DIR_NAME:&'static str = "/x01";
|
||||||
|
@ -22,12 +23,12 @@ impl DirectoryRecordMember {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_path_table_member(root: &Directory) -> Vec<PathTableMember> {
|
pub fn collect_path_table_member(root: Rc<RefCell<Directory>>) -> Vec<PathTableMember> {
|
||||||
fn collect_path_table_for(collection: &mut Vec<PathTableMember>, dirs: &Vec<Directory>, parent_id: usize) {
|
fn collect_path_table_for(collection: &mut Vec<PathTableMember>, dirs: &Vec<Rc<RefCell<Directory>>>, parent_id: usize) {
|
||||||
let mut cur_dirs = Vec::new();
|
let mut cur_dirs = Vec::new();
|
||||||
|
|
||||||
for dir in dirs {
|
for dir in dirs {
|
||||||
cur_dirs.push(PathTableMember{name: dir.name.as_string().unwrap_or("".to_owned()), parent_table_id: parent_id});
|
cur_dirs.push(PathTableMember{name: dir.borrow().name.as_string().unwrap_or("".to_owned()), parent_table_id: parent_id});
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_dirs.sort_by(|a, b| {
|
cur_dirs.sort_by(|a, b| {
|
||||||
|
@ -37,22 +38,24 @@ pub fn collect_path_table_member(root: &Directory) -> Vec<PathTableMember> {
|
||||||
collection.append(&mut cur_dirs);
|
collection.append(&mut cur_dirs);
|
||||||
|
|
||||||
for dir in dirs {
|
for dir in dirs {
|
||||||
collect_path_table_for(collection, &dir.dirs, parent_id + 1);
|
collect_path_table_for(collection, &dir.borrow().dirs, parent_id + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut collection = Vec::new();
|
let mut collection = Vec::new();
|
||||||
|
let root = root.borrow();
|
||||||
|
|
||||||
collection.push(PathTableMember{name: CURRENT_DIR_NAME.to_owned(), parent_table_id: 1});
|
collection.push(PathTableMember{name: CURRENT_DIR_NAME.to_owned(), parent_table_id: 1});
|
||||||
collect_path_table_for(&mut collection, &root.dirs, 1);
|
collect_path_table_for(&mut collection, &root.dirs, 1);
|
||||||
collection
|
collection
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_directory_record_member(files: &Vec<File>, dirs: &Vec<Directory>) -> Vec<DirectoryRecordMember> {
|
pub fn collect_directory_record_member(files: &Vec<Rc<RefCell<File>>>, dirs: &Vec<Rc<RefCell<Directory>>>) -> Vec<DirectoryRecordMember> {
|
||||||
let mut collection = Vec::new();
|
let mut collection = Vec::new();
|
||||||
|
|
||||||
collection.push(DirectoryRecordMember::Directory{name: CURRENT_DIR_NAME.to_owned()});
|
collection.push(DirectoryRecordMember::Directory{name: CURRENT_DIR_NAME.to_owned()});
|
||||||
collection.push(DirectoryRecordMember::Directory{name: PARENT_DIR_NAME.to_owned()});
|
collection.push(DirectoryRecordMember::Directory{name: PARENT_DIR_NAME.to_owned()});
|
||||||
for file in files {
|
for file in files {
|
||||||
|
let file = file.borrow();
|
||||||
if !file.properties.is_hidden {
|
if !file.properties.is_hidden {
|
||||||
if let Some(name) = file.name.as_string() {
|
if let Some(name) = file.name.as_string() {
|
||||||
collection.push(DirectoryRecordMember::File{name});
|
collection.push(DirectoryRecordMember::File{name});
|
||||||
|
@ -61,8 +64,8 @@ pub fn collect_directory_record_member(files: &Vec<File>, dirs: &Vec<Directory>)
|
||||||
}
|
}
|
||||||
|
|
||||||
for dir in dirs {
|
for dir in dirs {
|
||||||
if !dir.properties.is_hidden {
|
if !dir.borrow().properties.is_hidden {
|
||||||
if let Some(name) = dir.name.as_string() {
|
if let Some(name) = dir.borrow().name.as_string() {
|
||||||
collection.push(DirectoryRecordMember::Directory{name});
|
collection.push(DirectoryRecordMember::Directory{name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
pub type MemoryLayout<'a> = Vec<Layout<'a>>;
|
pub type MemoryLayout = Vec<Layout>;
|
||||||
pub type MemoryLayoutMut<'a> = Vec<LayoutMut<'a>>;
|
pub type MemoryLayoutMut = Vec<LayoutMut>;
|
||||||
|
|
||||||
macro_rules! declare_memory_layout {
|
macro_rules! declare_memory_layout {
|
||||||
($($val:ident),*) => {
|
($($val:ident),*) => {
|
||||||
|
@ -18,31 +19,33 @@ macro_rules! declare_memory_layout {
|
||||||
pub fn new(parent: &$($val),* CDDesc) -> Vec<[< Layout$($val:camel),* >]> {
|
pub fn new(parent: &$($val),* CDDesc) -> Vec<[< Layout$($val:camel),* >]> {
|
||||||
let mut layout = Vec::new();
|
let mut layout = Vec::new();
|
||||||
|
|
||||||
layout.push([< Layout$($val:camel),* >]::SystemArea(&$($val),* parent.system_area));
|
layout.push([< Layout$($val:camel),* >]::SystemArea(parent.system_area.clone()));
|
||||||
layout.push([< Layout$($val:camel),* >]::PVD(&$($val),* parent.pvd));
|
layout.push([< Layout$($val:camel),* >]::PVD(parent.pvd.clone()));
|
||||||
layout.push(([< Layout$($val:camel),* >]::PathTables));
|
layout.push(([< Layout$($val:camel),* >]::PathTables));
|
||||||
|
|
||||||
[< add_dir_and_subdir $(_$val),* >](&mut layout, &$($val),* parent.root);
|
[< add_dir_and_subdir $(_$val),* >](&mut layout, parent.root.clone());
|
||||||
layout
|
layout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum [< Layout$($val:camel),* >]<'a> {
|
pub enum [< Layout$($val:camel),* >] {
|
||||||
SystemArea(&'a $($val),* SystemArea),
|
SystemArea(Rc<RefCell<SystemArea>>),
|
||||||
PVD(&'a $($val),* PrimaryVolumeDescriptor),
|
PVD(Rc<RefCell<PrimaryVolumeDescriptor>>),
|
||||||
PathTables,
|
PathTables,
|
||||||
Directory{name: &'a $($val),* DirectoryName, properties: &'a $($val),* Properties},
|
Directory(Rc<RefCell<Directory>>),
|
||||||
File(&'a $($val),* File)
|
File(Rc<RefCell<File>>)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn [< add_dir_and_subdir $(_$val),* >]<'a>(layout: &mut Vec<[< Layout$($val:camel),* >]::<'a>>, dir: &'a $($val),* Directory) {
|
fn [< add_dir_and_subdir $(_$val),* >]<'a>(layout: &mut Vec<[< Layout$($val:camel),* >]>, dir: Rc<RefCell<Directory>>) {
|
||||||
layout.push([< Layout$($val:camel),* >]::Directory{name: &$($val),* dir.name, properties: &$($val),* dir.properties});
|
layout.push([< Layout$($val:camel),* >]::Directory(dir.clone()));
|
||||||
|
|
||||||
|
let $($val),* dir = dir.[< borrow $(_$val),* >]();
|
||||||
for file in dir.files.[< iter$(_$val),* >]() {
|
for file in dir.files.[< iter$(_$val),* >]() {
|
||||||
layout.push([< Layout$($val:camel),* >]::File(file));
|
layout.push([< Layout$($val:camel),* >]::File(file.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for dir in dir.dirs.[< iter$(_$val),* >]() {
|
for dir in dir.dirs.[< iter$(_$val),* >]() {
|
||||||
[< add_dir_and_subdir $(_$val),* >](layout, dir);
|
[< add_dir_and_subdir $(_$val),* >](layout, dir.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,12 @@ pub mod layout;
|
||||||
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, sector::*, path_table::PathTableL};
|
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 layout::LayoutMut;
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
pub struct CDDesc {
|
pub struct CDDesc {
|
||||||
system_area: SystemArea,
|
system_area: Rc<RefCell<SystemArea>>,
|
||||||
pvd: PrimaryVolumeDescriptor,
|
pvd: Rc<RefCell<PrimaryVolumeDescriptor>>,
|
||||||
pub root: Directory
|
pub root: Rc<RefCell<Directory>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CDDesc {
|
impl CDDesc {
|
||||||
|
@ -16,7 +17,7 @@ impl CDDesc {
|
||||||
|
|
||||||
pub fn new() -> CDDesc {
|
pub fn new() -> CDDesc {
|
||||||
match Directory::new("root") {
|
match Directory::new("root") {
|
||||||
Ok(root) => CDDesc{system_area: SystemArea::new(), pvd: PrimaryVolumeDescriptor::new(), root},
|
Ok(root) => CDDesc{system_area: Rc::new(RefCell::new(SystemArea::new())), pvd: Rc::new(RefCell::new(PrimaryVolumeDescriptor::new())), root: Rc::new(RefCell::new(root))},
|
||||||
Err(error) => panic!("Creating root directory failed with: {}", error)
|
Err(error) => panic!("Creating root directory failed with: {}", error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +34,7 @@ impl CDDesc {
|
||||||
let mut path_table_properties = {
|
let mut path_table_properties = {
|
||||||
let mut size_bytes = 0;
|
let mut size_bytes = 0;
|
||||||
|
|
||||||
helper::collect_path_table_member(&self.root).into_iter().for_each(|element| {
|
helper::collect_path_table_member(self.root.clone()).into_iter().for_each(|element| {
|
||||||
println!("PT: {} ^{}", element.name, element.parent_table_id);
|
println!("PT: {} ^{}", element.name, element.parent_table_id);
|
||||||
size_bytes += PathTableL::calculate_size_for(element.name.as_ref());
|
size_bytes += PathTableL::calculate_size_for(element.name.as_ref());
|
||||||
});
|
});
|
||||||
|
@ -41,9 +42,9 @@ impl CDDesc {
|
||||||
size_bytes = round_bytes_mode2_form1(size_bytes)*4;
|
size_bytes = round_bytes_mode2_form1(size_bytes)*4;
|
||||||
Properties{lba: 0, overwrite_size_bytes: Some(size_bytes), is_hidden: false}
|
Properties{lba: 0, overwrite_size_bytes: Some(size_bytes), is_hidden: false}
|
||||||
};
|
};
|
||||||
let mut cur_lba = 0;
|
let mut cur_lba = 0;
|
||||||
|
|
||||||
Self::for_each_dir_mut(&mut self.root, &|dir| {dir.update_content_size();});
|
Self::for_each_dir_mut(self.root.clone(), &|dir| {dir.update_content_size();});
|
||||||
|
|
||||||
// Now layout iterate?
|
// Now layout iterate?
|
||||||
for element in self.get_memory_layout_mut() {
|
for element in self.get_memory_layout_mut() {
|
||||||
|
@ -54,18 +55,22 @@ impl CDDesc {
|
||||||
|
|
||||||
match element {
|
match element {
|
||||||
LayoutMut::SystemArea(system_area) => {
|
LayoutMut::SystemArea(system_area) => {
|
||||||
|
let mut system_area = system_area.borrow_mut();
|
||||||
cur_lba = update_lba(&mut system_area.properties, cur_lba, 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) => {
|
LayoutMut::PVD(pvd) => {
|
||||||
|
let mut pvd = pvd.borrow_mut();
|
||||||
cur_lba = update_lba(&mut pvd.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
cur_lba = update_lba(&mut pvd.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||||
},
|
},
|
||||||
LayoutMut::PathTables => {
|
LayoutMut::PathTables => {
|
||||||
cur_lba = update_lba(&mut path_table_properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
cur_lba = update_lba(&mut path_table_properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||||
},
|
},
|
||||||
LayoutMut::Directory{name: _, properties} => {
|
LayoutMut::Directory(dir) => {
|
||||||
cur_lba = update_lba(properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW)
|
let mut dir = dir.borrow_mut();
|
||||||
|
cur_lba = update_lba(&mut dir.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW)
|
||||||
},
|
},
|
||||||
LayoutMut::File(file) => {
|
LayoutMut::File(file) => {
|
||||||
|
let mut file = file.borrow_mut();
|
||||||
cur_lba = update_lba(&mut file.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
cur_lba = update_lba(&mut file.properties, cur_lba, Self::DEFAULT_DATA_SIZE_FOR_NOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,10 +79,12 @@ impl CDDesc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn for_each_dir_mut<T: Fn(&mut Directory)>(dir: &mut Directory, function: &T) {
|
fn for_each_dir_mut<T: Fn(&mut Directory)>(dir: Rc<RefCell<Directory>>, function: &T) {
|
||||||
function(dir);
|
let mut dir = dir.borrow_mut();
|
||||||
|
|
||||||
|
function(&mut dir);
|
||||||
for sub_dir in &mut dir.dirs {
|
for sub_dir in &mut dir.dirs {
|
||||||
Self::for_each_dir_mut(sub_dir, function);
|
Self::for_each_dir_mut(sub_dir.clone(), function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,8 +116,8 @@ impl PrimaryVolumeDescriptor {
|
||||||
pub struct Directory {
|
pub struct Directory {
|
||||||
pub name: DirectoryName,
|
pub name: DirectoryName,
|
||||||
pub properties: Properties,
|
pub properties: Properties,
|
||||||
files: Vec<File>,
|
files: Vec<Rc<RefCell<File>>>,
|
||||||
dirs: Vec<Directory>
|
dirs: Vec<Rc<RefCell<Directory>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Directory {
|
impl Directory {
|
||||||
|
@ -119,11 +126,11 @@ impl Directory {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_dir(&mut self, dir: Directory) {
|
pub fn add_dir(&mut self, dir: Directory) {
|
||||||
self.dirs.push(dir);
|
self.dirs.push(Rc::new(RefCell::new(dir)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_file(&mut self, file: File) {
|
pub fn add_file(&mut self, file: File) {
|
||||||
self.files.push(file);
|
self.files.push(Rc::new(RefCell::new(file)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_content_size(&mut self) {
|
fn update_content_size(&mut self) {
|
||||||
|
|
Loading…
Reference in New Issue