Support absolute LBAs now
This commit is contained in:
parent
4c0d591c81
commit
86d1e1c32c
|
@ -72,9 +72,7 @@ namespace JabyEngine {
|
|||
}
|
||||
|
||||
static constexpr CDTimeStamp from(const FileInfo& file_info) {
|
||||
// Only for now
|
||||
const auto lba = file_info.lba + 2*MaxSector;
|
||||
return CDTimeStamp::from(lba);
|
||||
return CDTimeStamp::from(file_info.lba);
|
||||
}
|
||||
|
||||
constexpr uint8_t get_min_cd() const {
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
|||
|
||||
for element in cd_desc.get_memory_layout() {
|
||||
fn update_lba(properties: &mut Properties, cur_lba: usize, content_sector_size: usize) -> usize {
|
||||
properties.track_rel_lba = cur_lba;
|
||||
properties.track_rel_lba.set_track_rel(cur_lba);
|
||||
cur_lba + content_sector_size
|
||||
}
|
||||
|
||||
|
@ -50,21 +50,21 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
|||
Layout::SystemArea(system_area) => {
|
||||
let mut system_area = system_area.borrow_mut();
|
||||
|
||||
system_area.track_rel_lba = cur_lba;
|
||||
system_area.track_rel_lba.set_track_rel(cur_lba);
|
||||
cur_lba += element_size_info.sectors;
|
||||
},
|
||||
|
||||
Layout::PVD(pvd) => {
|
||||
let mut pvd = pvd.borrow_mut();
|
||||
|
||||
pvd.track_rel_lba = cur_lba;
|
||||
pvd.track_rel_lba.set_track_rel(cur_lba);
|
||||
cur_lba += element_size_info.sectors;
|
||||
},
|
||||
|
||||
Layout::PathTables(_, path_table) => {
|
||||
let mut path_table = path_table.borrow_mut();
|
||||
|
||||
path_table.track_rel_lba = cur_lba;
|
||||
path_table.track_rel_lba.set_track_rel(cur_lba);
|
||||
path_table.size_bytes = element_size_info.bytes.unwrap_or(0);
|
||||
|
||||
cur_lba += element_size_info.sectors*4;
|
||||
|
@ -76,7 +76,7 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) {
|
|||
|
||||
cd_desc.vol_sector_count += element_size_info.sectors;
|
||||
if properties.is_hidden {
|
||||
properties.track_rel_lba = 0;
|
||||
properties.track_rel_lba.set_track_rel(0);
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -185,7 +185,7 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let system_area_lba = system_area.track_rel_lba;
|
||||
let system_area_lba = system_area.track_rel_lba.get_for_cur_track();
|
||||
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)));
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr<PathTable>,
|
|||
|
||||
let path_table = validate_and_unwrap_path_table(&path_table)?;
|
||||
let root_dir = root_dir.borrow();
|
||||
let pvd_lba = pvd.track_rel_lba;
|
||||
let pvd_lba = pvd.track_rel_lba.get_for_cur_track();
|
||||
|
||||
if pvd_lba != 16 {
|
||||
return Err(Error::from_text(format!("PVD required to start at sector 16 of Track - found LBA: {}", pvd_lba)));
|
||||
|
|
|
@ -12,13 +12,13 @@ use types::{layout::Layout, CDDesc, Directory, File, FileType, FileSystemMap, Pr
|
|||
pub type LBAEmbeddedFiles = Vec<SharedPtr<File>>;
|
||||
|
||||
struct ContentDumpAlignment {
|
||||
name: usize,
|
||||
lba: usize,
|
||||
size: usize,
|
||||
ex_size: usize,
|
||||
name: usize,
|
||||
lba_pair: usize,
|
||||
size: usize,
|
||||
ex_size: usize,
|
||||
}
|
||||
|
||||
const DEFAULT_CONTENT_ALIGNMENT:ContentDumpAlignment = ContentDumpAlignment{name: 24, lba: 8, size: 8, ex_size: 8};
|
||||
const DEFAULT_CONTENT_ALIGNMENT:ContentDumpAlignment = ContentDumpAlignment{name: 24, lba_pair: 16, size: 8, ex_size: 8};
|
||||
|
||||
pub fn process(config: config_reader::Configuration, calculate_lba: LbaCalculatorFunction) -> Result<(CDDesc, LBAEmbeddedFiles), Error> {
|
||||
let (mut cd_desc, lba_embedded_files) = parse_configuration(config)?;
|
||||
|
@ -77,15 +77,19 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
fn write_file(out: &mut Output, indent: usize, file_name: String, properties: &Properties, file_lba: usize, file_size: usize, file_ex_size: usize) -> Result<(), Error> {
|
||||
Ok(writeln!(out, "{:>indent$}File: ({}) {:<name_align$} @{:<lba_align$} ={:<size_align$} >{:<ex_size_align$}", ARROW, get_visible_indicator(properties.is_hidden), file_name, file_lba, file_size, file_ex_size,
|
||||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_align=DEFAULT_CONTENT_ALIGNMENT.lba, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?)
|
||||
fn create_lba_display_string<T: std::fmt::Display>(rel_lba: T, abs_lba: T) -> String {
|
||||
format!("{}({})", rel_lba, abs_lba)
|
||||
}
|
||||
|
||||
fn write_dir(out: &mut Output, indent: usize, dir_name: &str, properties: &Properties, dir_lba: usize) -> Result<(), Error> {
|
||||
fn write_file(out: &mut Output, indent: usize, file_name: String, properties: &Properties, file_rel_lba: usize, file_abs_lba: usize, file_size: usize, file_ex_size: usize) -> Result<(), Error> {
|
||||
Ok(writeln!(out, "{:>indent$}File: ({}) {:<name_align$} @{:<lba_pair_align$} ={:<size_align$} >{:<ex_size_align$}", ARROW, get_visible_indicator(properties.is_hidden), file_name, create_lba_display_string(file_rel_lba, file_abs_lba), file_size, file_ex_size,
|
||||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?)
|
||||
}
|
||||
|
||||
fn write_dir(out: &mut Output, indent: usize, dir_name: &str, properties: &Properties, dir_rel_lba: usize, dir_abs_lba: usize) -> Result<(), Error> {
|
||||
macro_rules! LBA_OUT {
|
||||
() => {
|
||||
"{:<lba_align$}"
|
||||
"{:<lba_pair_align$}"
|
||||
};
|
||||
}
|
||||
let is_hidden = properties.is_hidden;
|
||||
|
@ -94,17 +98,17 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
|||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name)?;
|
||||
|
||||
if is_hidden {
|
||||
Ok(writeln!(out, LBA_OUT!(), "<None>", lba_align=DEFAULT_CONTENT_ALIGNMENT.lba)?)
|
||||
Ok(writeln!(out, LBA_OUT!(), create_lba_display_string("<None>", "<None>"), lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair)?)
|
||||
}
|
||||
|
||||
else {
|
||||
Ok(writeln!(out, LBA_OUT!(), dir_lba, lba_align=DEFAULT_CONTENT_ALIGNMENT.lba)?)
|
||||
Ok(writeln!(out, LBA_OUT!(), create_lba_display_string(dir_rel_lba, dir_abs_lba), lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair)?)
|
||||
}
|
||||
}
|
||||
|
||||
fn write_intro(out: &mut Output) -> Result<(), Error> {
|
||||
writeln!(out, "{:>indent$}Type: ( ) {:<name_align$} @{:<lba_align$} ={:<size_align$} >{:<ex_size_align$}", "", "NAME", "LBA", "SIZE", "EXTENDED SIZE",
|
||||
indent=ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_align=DEFAULT_CONTENT_ALIGNMENT.lba, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?;
|
||||
writeln!(out, "{:>indent$}Type: ( ) {:<name_align$} @{:<lba_pair_align$} ={:<size_align$} >{:<ex_size_align$}", "", "NAME", create_lba_display_string("LBA", "ABS LBA"), "SIZE", "EXTENDED SIZE",
|
||||
indent=ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?;
|
||||
Ok(writeln!(out, "")?)
|
||||
}
|
||||
|
||||
|
@ -113,20 +117,22 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
|||
let file = file.borrow();
|
||||
let file_name = file.name.as_string().unwrap_or(NO_NAME.to_owned());
|
||||
let properties = &file.properties;
|
||||
let file_lba = file.get_track_rel_lba();
|
||||
let file_rel_lba = file.get_track_rel_lba();
|
||||
let file_abs_lba = file.get_absolute_lba();
|
||||
let file_size = file.properties.get_real_size();
|
||||
let file_ex_size = file.get_extended_size();
|
||||
|
||||
write_file(out, indent, file_name, properties, file_lba, file_size, file_ex_size)?;
|
||||
write_file(out, indent, file_name, properties, file_rel_lba, file_abs_lba, file_size, file_ex_size)?;
|
||||
}
|
||||
|
||||
for dir in dir.dir_iter() {
|
||||
let dir = dir.borrow();
|
||||
let dir_name = dir.name.as_str().unwrap_or(NO_NAME);
|
||||
let properties = dir.properties.borrow();
|
||||
let dir_lba = dir.get_track_rel_lba();
|
||||
let dir = dir.borrow();
|
||||
let dir_name = dir.name.as_str().unwrap_or(NO_NAME);
|
||||
let properties = dir.properties.borrow();
|
||||
let dir_rel_lba = dir.get_track_rel_lba();
|
||||
let dir_abs_lba = dir.get_absolute_lba();
|
||||
|
||||
write_dir(out, indent, dir_name, &properties, dir_lba)?;
|
||||
write_dir(out, indent, dir_name, &properties, dir_rel_lba, dir_abs_lba)?;
|
||||
dump_dir(&dir, out, indent + INDENT_STEP)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,16 +11,16 @@ pub struct PathTableMember {
|
|||
|
||||
pub enum DirectoryRecordMember {
|
||||
Directory{name: String, track_rel_lba: u32, real_size: u32},
|
||||
File{name: String, track_rel_lba: u32, real_size: u32},
|
||||
File{name: String, track_rel_lba: u32, real_size: u32},
|
||||
}
|
||||
|
||||
impl DirectoryRecordMember {
|
||||
pub fn new_dir(name: String, properties: &Properties) -> DirectoryRecordMember {
|
||||
DirectoryRecordMember::Directory{name, track_rel_lba: properties.track_rel_lba as u32, real_size: properties.get_real_size() as u32}
|
||||
DirectoryRecordMember::Directory{name, track_rel_lba: properties.track_rel_lba.get_for_cur_track() as u32, real_size: properties.get_real_size() as u32}
|
||||
}
|
||||
|
||||
pub fn new_file(name: String, properties: &Properties) -> DirectoryRecordMember {
|
||||
DirectoryRecordMember::File{name, track_rel_lba: properties.track_rel_lba as u32, real_size: properties.get_real_size() as u32}
|
||||
DirectoryRecordMember::File{name, track_rel_lba: properties.track_rel_lba.get_for_cur_track() as u32, real_size: properties.get_real_size() as u32}
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> &String {
|
||||
|
|
|
@ -57,24 +57,24 @@ impl CDDesc {
|
|||
}
|
||||
|
||||
pub struct SystemArea {
|
||||
pub(in super) track_rel_lba: usize,
|
||||
pub(in super) track_rel_lba: LBA,
|
||||
pub(in super) license_file_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl SystemArea {
|
||||
pub fn new() -> SystemArea {
|
||||
SystemArea{track_rel_lba: 0, license_file_path: None}
|
||||
SystemArea{track_rel_lba: LBA::default(), license_file_path: None}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PathTable {
|
||||
pub(super) track_rel_lba: usize,
|
||||
pub(super) track_rel_lba: LBA,
|
||||
pub(super) size_bytes: usize,
|
||||
}
|
||||
|
||||
impl PathTable {
|
||||
pub fn new() -> PathTable {
|
||||
PathTable{track_rel_lba: 0, size_bytes: 0}
|
||||
PathTable{track_rel_lba: LBA::default(), size_bytes: 0}
|
||||
}
|
||||
|
||||
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 {
|
||||
let table_num = table_num - 1;
|
||||
self.track_rel_lba + (table_num*sector_count_func(self.size_bytes))
|
||||
self.track_rel_lba.get_for_cur_track() + (table_num*sector_count_func(self.size_bytes))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PrimaryVolumeDescriptor {
|
||||
pub(super) track_rel_lba: usize,
|
||||
pub(super) track_rel_lba: LBA,
|
||||
pub(super) publisher: String,
|
||||
}
|
||||
|
||||
impl PrimaryVolumeDescriptor {
|
||||
pub fn new() -> PrimaryVolumeDescriptor {
|
||||
PrimaryVolumeDescriptor{track_rel_lba: 0, publisher: String::new()}
|
||||
PrimaryVolumeDescriptor{track_rel_lba: LBA::default(), publisher: String::new()}
|
||||
}
|
||||
|
||||
pub fn set_publisher(&mut self, publisher: String) {
|
||||
|
@ -139,7 +139,11 @@ impl Directory {
|
|||
}
|
||||
|
||||
pub fn get_track_rel_lba(&self) -> usize {
|
||||
self.properties.borrow().track_rel_lba
|
||||
self.properties.borrow().track_rel_lba.get_for_cur_track()
|
||||
}
|
||||
|
||||
pub fn get_absolute_lba(&self) -> usize {
|
||||
self.properties.borrow().track_rel_lba.get_for_track1()
|
||||
}
|
||||
|
||||
pub fn get_extended_size(&self) -> usize {
|
||||
|
@ -206,7 +210,11 @@ impl File {
|
|||
}
|
||||
|
||||
pub fn get_track_rel_lba(&self) -> usize {
|
||||
self.properties.track_rel_lba
|
||||
self.properties.track_rel_lba.get_for_cur_track()
|
||||
}
|
||||
|
||||
pub fn get_absolute_lba(&self) -> usize {
|
||||
self.properties.track_rel_lba.get_for_track1()
|
||||
}
|
||||
|
||||
pub fn get_extended_size(&self) -> usize {
|
||||
|
@ -304,7 +312,7 @@ impl std::fmt::Display for FileName {
|
|||
}
|
||||
|
||||
pub struct Properties {
|
||||
pub(super) track_rel_lba: usize,
|
||||
pub(super) track_rel_lba: LBA,
|
||||
pub(super) size_bytes: usize,
|
||||
pub(super) padded_size_bytes: Option<usize>,
|
||||
pub(super) is_hidden: bool
|
||||
|
@ -332,7 +340,7 @@ impl Properties {
|
|||
|
||||
impl Default for Properties {
|
||||
fn default() -> Self {
|
||||
Properties{track_rel_lba: 0, size_bytes: 0, padded_size_bytes: None, is_hidden: false}
|
||||
Properties{track_rel_lba: LBA::default(), size_bytes: 0, padded_size_bytes: None, is_hidden: false}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,3 +350,29 @@ fn dstring_as_str<const SIZE: usize>(string: &DString<SIZE>, len: usize) -> Opti
|
|||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LBA {
|
||||
track_rel: usize
|
||||
}
|
||||
|
||||
impl LBA {
|
||||
pub fn set_track_rel(&mut self, new_track_rel: usize) {
|
||||
self.track_rel = new_track_rel;
|
||||
}
|
||||
|
||||
pub fn get_for_cur_track(&self) -> usize {
|
||||
self.track_rel
|
||||
}
|
||||
|
||||
pub fn get_for_track1(&self) -> usize {
|
||||
const START_OFFSET: usize = cdtypes::types::time::Time::cd_start().to_lba();
|
||||
|
||||
self.track_rel + START_OFFSET
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for LBA {
|
||||
fn default() -> Self {
|
||||
LBA{track_rel: 0}
|
||||
}
|
||||
}
|
|
@ -91,7 +91,7 @@ fn for_each_lba_name<F: FnMut(usize, (u16, usize)) -> Result<(), Error>>(lba_nam
|
|||
let mut idx = 0;
|
||||
for lba_name in lba_names {
|
||||
if let Some(file) = file_map.get(lba_name) {
|
||||
let (lba, bytes) = (format_if_error_drop_cause!(file.try_borrow(), "Failed accessing file \"{}\" for writing LBA information.\nNote: You can not inject the LBA information of a file into itself.", lba_name)?.get_track_rel_lba(), length_func(&Layout::File(file.clone())).bytes);
|
||||
let (lba, bytes) = (format_if_error_drop_cause!(file.try_borrow(), "Failed accessing file \"{}\" for writing LBA information.\nNote: You can not inject the LBA information of a file into itself.", lba_name)?.get_absolute_lba(), length_func(&Layout::File(file.clone())).bytes);
|
||||
|
||||
functor(idx, (lba as u16, bytes.ok_or(Error::from_text(format!("{} does not contain a size!", lba_name)))?))?;
|
||||
idx += 1;
|
||||
|
|
Loading…
Reference in New Issue