Refactored code
This commit is contained in:
parent
e08c6a85e6
commit
c2e45a833b
|
@ -42,7 +42,7 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
||||||
|
|
||||||
for element in cd_desc.get_memory_layout() {
|
for element in cd_desc.get_memory_layout() {
|
||||||
fn update_lba(properties: &mut Properties, cur_lba: usize, track_offset: usize, content_sector_size: usize) -> usize {
|
fn update_lba(properties: &mut Properties, cur_lba: usize, track_offset: usize, content_sector_size: usize) -> usize {
|
||||||
properties.track_rel_lba.overwrite(cur_lba, track_offset);
|
properties.lba.overwrite(cur_lba, track_offset);
|
||||||
cur_lba + content_sector_size
|
cur_lba + content_sector_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,21 +51,21 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
||||||
Layout::SystemArea(system_area) => {
|
Layout::SystemArea(system_area) => {
|
||||||
let mut system_area = system_area.borrow_mut();
|
let mut system_area = system_area.borrow_mut();
|
||||||
|
|
||||||
system_area.track_rel_lba.overwrite(cur_lba, track_offset);
|
system_area.lba.overwrite(cur_lba, track_offset);
|
||||||
cur_lba += element_size_info.sectors;
|
cur_lba += element_size_info.sectors;
|
||||||
},
|
},
|
||||||
|
|
||||||
Layout::PVD(pvd) => {
|
Layout::PVD(pvd) => {
|
||||||
let mut pvd = pvd.borrow_mut();
|
let mut pvd = pvd.borrow_mut();
|
||||||
|
|
||||||
pvd.track_rel_lba.overwrite(cur_lba, track_offset);
|
pvd.lba.overwrite(cur_lba, track_offset);
|
||||||
cur_lba += element_size_info.sectors;
|
cur_lba += element_size_info.sectors;
|
||||||
},
|
},
|
||||||
|
|
||||||
Layout::PathTables(_, path_table) => {
|
Layout::PathTables(_, path_table) => {
|
||||||
let mut path_table = path_table.borrow_mut();
|
let mut path_table = path_table.borrow_mut();
|
||||||
|
|
||||||
path_table.track_rel_lba.overwrite(cur_lba, track_offset);
|
path_table.lba.overwrite(cur_lba, track_offset);
|
||||||
path_table.size_bytes = element_size_info.bytes.unwrap_or(0);
|
path_table.size_bytes = element_size_info.bytes.unwrap_or(0);
|
||||||
|
|
||||||
cur_lba += element_size_info.sectors*4;
|
cur_lba += element_size_info.sectors*4;
|
||||||
|
@ -77,7 +77,7 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
||||||
|
|
||||||
cd_desc.vol_sector_count += element_size_info.sectors;
|
cd_desc.vol_sector_count += element_size_info.sectors;
|
||||||
if properties.is_hidden {
|
if properties.is_hidden {
|
||||||
properties.track_rel_lba.overwrite(0, 0);
|
properties.lba.overwrite(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@ -186,7 +186,7 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
let system_area_lba = system_area.track_rel_lba.get_for_cur_track();
|
let system_area_lba = system_area.lba.get_track_relative();
|
||||||
if system_area_lba != 0 {
|
if system_area_lba != 0 {
|
||||||
return Err(Error::from_text(format!("System Area required to start at sector 0 of Track - found LBA: {}", system_area_lba)));
|
return Err(Error::from_text(format!("System Area required to start at sector 0 of Track - found LBA: {}", system_area_lba)));
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>,
|
||||||
|
|
||||||
let path_table = validate_and_unwrap_path_table(&path_table)?;
|
let path_table = validate_and_unwrap_path_table(&path_table)?;
|
||||||
let root_dir = root_dir.borrow();
|
let root_dir = root_dir.borrow();
|
||||||
let pvd_lba = pvd.track_rel_lba.get_for_cur_track();
|
let pvd_lba = pvd.lba.get_track_relative();
|
||||||
|
|
||||||
if pvd_lba != 16 {
|
if pvd_lba != 16 {
|
||||||
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)));
|
||||||
|
@ -434,7 +434,7 @@ fn write_dir_record(dir_record: &mut [u8], dir_member: &DirectoryRecordMember, h
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba, round_bytes_mode2_form1(*real_size as usize) as u32, system_use)?;
|
let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba as u32, round_bytes_mode2_form1(*real_size as usize) as u32, system_use)?;
|
||||||
|
|
||||||
dir_record.set_directory();
|
dir_record.set_directory();
|
||||||
return Ok(dir_record.length[0] as usize);
|
return Ok(dir_record.length[0] as usize);
|
||||||
|
@ -454,7 +454,7 @@ fn write_dir_record(dir_record: &mut [u8], dir_member: &DirectoryRecordMember, h
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba, *real_size, system_use)?;
|
let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba as u32, *real_size as u32, system_use)?;
|
||||||
|
|
||||||
dir_record.set_file();
|
dir_record.set_file();
|
||||||
return Ok(dir_record.length[0] as usize);
|
return Ok(dir_record.length[0] as usize);
|
||||||
|
|
|
@ -10,17 +10,17 @@ pub struct PathTableMember {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum DirectoryRecordMember {
|
pub enum DirectoryRecordMember {
|
||||||
Directory{name: String, track_rel_lba: u32, real_size: u32},
|
Directory{name: String, track_rel_lba: usize, real_size: usize},
|
||||||
File{name: String, track_rel_lba: u32, real_size: u32},
|
File{name: String, track_rel_lba: usize, real_size: usize},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DirectoryRecordMember {
|
impl DirectoryRecordMember {
|
||||||
pub fn new_dir(name: String, properties: &Properties) -> DirectoryRecordMember {
|
pub fn new_dir(name: String, properties: &Properties) -> DirectoryRecordMember {
|
||||||
DirectoryRecordMember::Directory{name, track_rel_lba: properties.track_rel_lba.get_for_cur_track() as u32, real_size: properties.get_real_size() as u32}
|
DirectoryRecordMember::Directory{name, track_rel_lba: properties.lba.get_track_relative(), real_size: properties.get_real_size()}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_file(name: String, properties: &Properties) -> DirectoryRecordMember {
|
pub fn new_file(name: String, properties: &Properties) -> DirectoryRecordMember {
|
||||||
DirectoryRecordMember::File{name, track_rel_lba: properties.track_rel_lba.get_for_cur_track() as u32, real_size: properties.get_real_size() as u32}
|
DirectoryRecordMember::File{name, track_rel_lba: properties.lba.get_track_relative(), real_size: properties.get_real_size()}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_name(&self) -> &String {
|
pub fn get_name(&self) -> &String {
|
||||||
|
|
|
@ -57,24 +57,24 @@ impl CDDesc {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SystemArea {
|
pub struct SystemArea {
|
||||||
pub(in super) track_rel_lba: LBA,
|
pub(in super) lba: LBA,
|
||||||
pub(in super) license_file_path: Option<PathBuf>,
|
pub(in super) license_file_path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemArea {
|
impl SystemArea {
|
||||||
pub fn new() -> SystemArea {
|
pub fn new() -> SystemArea {
|
||||||
SystemArea{track_rel_lba: LBA::default(), license_file_path: None}
|
SystemArea{lba: LBA::default(), license_file_path: None}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PathTable {
|
pub struct PathTable {
|
||||||
pub(super) track_rel_lba: LBA,
|
pub(super) lba: LBA,
|
||||||
pub(super) size_bytes: usize,
|
pub(super) size_bytes: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathTable {
|
impl PathTable {
|
||||||
pub fn new() -> PathTable {
|
pub fn new() -> PathTable {
|
||||||
PathTable{track_rel_lba: LBA::default(), size_bytes: 0}
|
PathTable{lba: LBA::default(), size_bytes: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_member(root: SharedPtr<Directory>) -> Vec<helper::PathTableMember> {
|
pub fn collect_member(root: SharedPtr<Directory>) -> Vec<helper::PathTableMember> {
|
||||||
|
@ -93,18 +93,18 @@ impl PathTable {
|
||||||
|
|
||||||
pub fn get_track_rel_lba_for(&self, table_num: usize, sector_count_func: fn(data_size: usize) -> usize) -> usize {
|
pub fn get_track_rel_lba_for(&self, table_num: usize, sector_count_func: fn(data_size: usize) -> usize) -> usize {
|
||||||
let table_num = table_num - 1;
|
let table_num = table_num - 1;
|
||||||
self.track_rel_lba.get_for_cur_track() + (table_num*sector_count_func(self.size_bytes))
|
self.lba.get_track_relative() + (table_num*sector_count_func(self.size_bytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PrimaryVolumeDescriptor {
|
pub struct PrimaryVolumeDescriptor {
|
||||||
pub(super) track_rel_lba: LBA,
|
pub(super) lba: LBA,
|
||||||
pub(super) publisher: String,
|
pub(super) publisher: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrimaryVolumeDescriptor {
|
impl PrimaryVolumeDescriptor {
|
||||||
pub fn new() -> PrimaryVolumeDescriptor {
|
pub fn new() -> PrimaryVolumeDescriptor {
|
||||||
PrimaryVolumeDescriptor{track_rel_lba: LBA::default(), publisher: String::new()}
|
PrimaryVolumeDescriptor{lba: LBA::default(), publisher: String::new()}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_publisher(&mut self, publisher: String) {
|
pub fn set_publisher(&mut self, publisher: String) {
|
||||||
|
@ -139,11 +139,11 @@ impl Directory {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_track_rel_lba(&self) -> usize {
|
pub fn get_track_rel_lba(&self) -> usize {
|
||||||
self.properties.borrow().track_rel_lba.get_for_cur_track()
|
self.properties.borrow().lba.get_track_relative()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_absolute_lba(&self) -> usize {
|
pub fn get_absolute_lba(&self) -> usize {
|
||||||
self.properties.borrow().track_rel_lba.get_for_track1()
|
self.properties.borrow().lba.get_track_absolute()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_extended_size(&self) -> usize {
|
pub fn get_extended_size(&self) -> usize {
|
||||||
|
@ -210,11 +210,11 @@ impl File {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_track_rel_lba(&self) -> usize {
|
pub fn get_track_rel_lba(&self) -> usize {
|
||||||
self.properties.track_rel_lba.get_for_cur_track()
|
self.properties.lba.get_track_relative()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_absolute_lba(&self) -> usize {
|
pub fn get_absolute_lba(&self) -> usize {
|
||||||
self.properties.track_rel_lba.get_for_track1()
|
self.properties.lba.get_track_absolute()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_extended_size(&self) -> usize {
|
pub fn get_extended_size(&self) -> usize {
|
||||||
|
@ -312,7 +312,7 @@ impl std::fmt::Display for FileName {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Properties {
|
pub struct Properties {
|
||||||
pub(super) track_rel_lba: LBA,
|
pub(super) lba: LBA,
|
||||||
pub(super) size_bytes: usize,
|
pub(super) size_bytes: usize,
|
||||||
pub(super) padded_size_bytes: Option<usize>,
|
pub(super) padded_size_bytes: Option<usize>,
|
||||||
pub(super) is_hidden: bool
|
pub(super) is_hidden: bool
|
||||||
|
@ -340,7 +340,7 @@ impl Properties {
|
||||||
|
|
||||||
impl Default for Properties {
|
impl Default for Properties {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Properties{track_rel_lba: LBA::default(), size_bytes: 0, padded_size_bytes: None, is_hidden: false}
|
Properties{lba: LBA::default(), size_bytes: 0, padded_size_bytes: None, is_hidden: false}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,11 +372,11 @@ impl LBA {
|
||||||
self.set_track_rel(rel_lba);
|
self.set_track_rel(rel_lba);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_for_cur_track(&self) -> usize {
|
pub fn get_track_relative(&self) -> usize {
|
||||||
self.track_rel
|
self.track_rel
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_for_track1(&self) -> usize {
|
pub fn get_track_absolute(&self) -> usize {
|
||||||
self.track_rel + self.track_offset
|
self.track_rel + self.track_offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue