Introduce Content

This commit is contained in:
Jaby 2022-10-11 19:45:06 +02:00 committed by Jaby
parent e185b96205
commit 2a472a88de
3 changed files with 17 additions and 16 deletions

View File

@ -34,7 +34,7 @@ fn run_main() -> Result<(), Error> {
match element { match element {
Layout::SystemArea(_) => println!("SystemArea:"), Layout::SystemArea(_) => println!("SystemArea:"),
Layout::PVD(_) => println!("PVD:"), Layout::PVD(_) => println!("PVD:"),
Layout::Directory{name, properties} => println!("Dir: {} @{}", name, properties.lba), Layout::Directory{name, content} => println!("Dir: {} @{}", name, content.lba),
Layout::File(file) => println!("File: {} @{}", file, file.get_lba()), Layout::File(file) => println!("File: {} @{}", file, file.get_lba()),
} }
} }

View File

@ -29,12 +29,12 @@ macro_rules! declare_memory_layout {
pub enum [< Layout$($val:camel),* >]<'a> { pub enum [< Layout$($val:camel),* >]<'a> {
SystemArea(&'a $($val),* SystemArea), SystemArea(&'a $($val),* SystemArea),
PVD(&'a $($val),* PrimaryVolumeDescriptor), PVD(&'a $($val),* PrimaryVolumeDescriptor),
Directory{name: &'a $($val),* DirectoryName, properties: &'a $($val),* Properties}, Directory{name: &'a $($val),* DirectoryName, content: &'a $($val),* Content},
File(&'a $($val),* File) File(&'a $($val),* 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),* >]::<'a>>, dir: &'a $($val),* Directory) {
layout.push([< Layout$($val:camel),* >]::Directory{name: &$($val),* dir.name, properties: &$($val),* dir.properties}); layout.push([< Layout$($val:camel),* >]::Directory{name: &$($val),* dir.name, content: &$($val),* dir.content});
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));
} }

View File

@ -45,15 +45,15 @@ impl PrimaryVolumeDescriptor {
} }
pub struct Directory { pub struct Directory {
name: DirectoryName, name: DirectoryName,
properties: Properties, content: Content,
files: Vec<File>, files: Vec<File>,
dirs: Vec<Directory> dirs: Vec<Directory>
} }
impl Directory { impl Directory {
pub fn new(dir_name: &str) -> Result<Directory, Error> { pub fn new(dir_name: &str) -> Result<Directory, Error> {
Ok(Directory{name: DirectoryName::from_str(dir_name)?, properties: Properties::default(), files: Vec::new(), dirs: Vec::new()}) Ok(Directory{name: DirectoryName::from_str(dir_name)?, content: Content::default(), files: Vec::new(), dirs: Vec::new()})
} }
pub fn add_dir(&mut self, dir: Directory) { pub fn add_dir(&mut self, dir: Directory) {
@ -65,7 +65,7 @@ impl Directory {
} }
pub fn get_lba(&self) -> usize { pub fn get_lba(&self) -> usize {
self.properties.lba self.content.lba
} }
} }
@ -76,17 +76,17 @@ impl std::fmt::Display for Directory {
} }
pub struct File { pub struct File {
name: FileName, name: FileName,
properties: Properties content: Content
} }
impl File { impl File {
pub fn new(file_name: &str) -> Result<File, Error> { pub fn new(file_name: &str) -> Result<File, Error> {
Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default()}) Ok(File{name: FileName::from_str(file_name)?, content: Content::default()})
} }
pub fn get_lba(&self) -> usize { pub fn get_lba(&self) -> usize {
self.properties.lba self.content.lba
} }
} }
@ -151,15 +151,16 @@ impl std::fmt::Display for FileName {
} }
} }
pub struct Properties { pub struct Content {
pub lba: usize, pub lba: usize,
pub overwrite_size_sectors: Option<usize>, pub overwrite_size_sectors: Option<usize>,
pub data: Vec<u8>,
pub is_hidden: bool pub is_hidden: bool
} }
impl Default for Properties { impl Default for Content {
fn default() -> Self { fn default() -> Self {
Properties{lba: 0, overwrite_size_sectors: None, is_hidden: false} Content{lba: 0, overwrite_size_sectors: None, data: Vec::new(), is_hidden: false}
} }
} }