Use function to update DirectoryRecord

This commit is contained in:
Jaby 2022-10-23 15:38:26 +02:00 committed by Jaby
parent ae08f17add
commit 5fef143171
2 changed files with 14 additions and 8 deletions

View File

@ -108,7 +108,6 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>,
return Err(Error::from_text(format!("PVD required to start at sector 16 of Track - found LBA: {}", pvd_lba))); return Err(Error::from_text(format!("PVD required to start at sector 16 of Track - found LBA: {}", pvd_lba)));
} }
let mut cd_pvd = cd_pvd::PrimaryVolumeDescriptor::new(); let mut cd_pvd = cd_pvd::PrimaryVolumeDescriptor::new();
let now = Date::now(); let now = Date::now();
@ -126,11 +125,7 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>,
//Set Root Directory Record //Set Root Directory Record
let root_dir_record = unsafe{std::mem::transmute::<&mut [u8; 34], &mut DirectoryRecord>(&mut cd_pvd.root_dir_record)}; let root_dir_record = unsafe{std::mem::transmute::<&mut [u8; 34], &mut DirectoryRecord>(&mut cd_pvd.root_dir_record)};
unsafe{root_dir_record.new("\x00", false)}; update_dir_record(root_dir_record, &root_dir)?;
root_dir_record.data_block_number.write(root_dir.properties.track_rel_lba as u32);
root_dir_record.data_size.write(root_dir.get_size() as u32);
root_dir_record.time_stamp = SmallDate::now();
root_dir_record.set_directory();
//Set other stuff //Set other stuff
cd_pvd.publisher_id = AString::from_str(pvd.publisher.as_str())?; cd_pvd.publisher_id = AString::from_str(pvd.publisher.as_str())?;
@ -157,3 +152,14 @@ fn validate_path_table(path_table: &SharedPtr<PathTable>) -> Result<std::cell::R
Ok(path_table) Ok(path_table)
} }
} }
fn update_dir_record(dir_record: &mut DirectoryRecord, dir: &Directory) -> Result<(), Error> {
unsafe{dir_record.new(dir.name.as_str().unwrap_or("\x00"), false)};
dir_record.data_block_number.write(dir.properties.track_rel_lba as u32);
dir_record.data_size.write(dir.get_size() as u32);
dir_record.time_stamp = SmallDate::now();
dir_record.set_directory();
Ok(())
}

View File

@ -23,7 +23,7 @@ pub struct CDDesc {
impl CDDesc { impl CDDesc {
pub fn new() -> CDDesc { pub fn new() -> CDDesc {
match Directory::new("root") { match Directory::new("\x00") {
Ok(root) => CDDesc{system_area: new_shared_ptr(SystemArea::new()), path_table: new_shared_ptr(PathTable::new()), pvd: new_shared_ptr(PrimaryVolumeDescriptor::new()), root: new_shared_ptr(root), vol_sector_count: 0}, Ok(root) => CDDesc{system_area: new_shared_ptr(SystemArea::new()), path_table: new_shared_ptr(PathTable::new()), pvd: new_shared_ptr(PrimaryVolumeDescriptor::new()), root: new_shared_ptr(root), vol_sector_count: 0},
Err(error) => panic!("Creating root directory failed with: {}", error) Err(error) => panic!("Creating root directory failed with: {}", error)
} }
@ -201,7 +201,7 @@ impl DirectoryName {
Some(self.as_str()?.to_owned()) Some(self.as_str()?.to_owned())
} }
fn as_str(&self) -> Option<&str> { pub fn as_str(&self) -> Option<&str> {
dstring_as_str(&self.name, self.len) dstring_as_str(&self.name, self.len)
} }
} }