Fix TODOs and code cleanup.

This commit is contained in:
2019-07-31 19:53:47 +01:00
parent 62e14f275e
commit c51847b734
11 changed files with 143 additions and 150 deletions

View File

@@ -5,7 +5,7 @@ namespace DiscImageChef.Filesystems.ISO9660
{
public partial class ISO9660
{
DateTime? DecodeIsoDateTime(byte[] timestamp)
static DateTime? DecodeIsoDateTime(byte[] timestamp)
{
switch(timestamp?.Length)
{
@@ -15,7 +15,7 @@ namespace DiscImageChef.Filesystems.ISO9660
}
}
DateTime? DecodeIsoDateTime(IsoTimestamp timestamp)
static DateTime? DecodeIsoDateTime(IsoTimestamp timestamp)
{
try
{
@@ -26,14 +26,14 @@ namespace DiscImageChef.Filesystems.ISO9660
return TimeZoneInfo.ConvertTimeToUtc(date, TimeZoneInfo.FindSystemTimeZoneById("GMT"));
}
catch(Exception e)
catch(Exception)
{
// ISO says timestamp can be unspecified
return null;
}
}
DateTime? DecodeHighSierraDateTime(HighSierraTimestamp timestamp)
static DateTime? DecodeHighSierraDateTime(HighSierraTimestamp timestamp)
{
try
{
@@ -42,7 +42,7 @@ namespace DiscImageChef.Filesystems.ISO9660
return TimeZoneInfo.ConvertTimeToUtc(date, TimeZoneInfo.FindSystemTimeZoneById("GMT"));
}
catch(Exception e)
catch(Exception)
{
// ISO says timestamp can be unspecified, suppose same for High Sierra
return null;

View File

@@ -13,7 +13,6 @@ namespace DiscImageChef.Filesystems.ISO9660
{
Dictionary<string, Dictionary<string, DecodedDirectoryEntry>> directoryCache;
// TODO: Implement path table traversal
public Errno ReadDir(string path, out List<string> contents)
{
contents = null;
@@ -86,7 +85,6 @@ namespace DiscImageChef.Filesystems.ISO9660
directoryBuffer = ms.ToArray();
}
// TODO: Decode Joliet
currentDirectory = cdi
? DecodeCdiDirectory(directoryBuffer, entry.Value.XattrLength)
: highSierra
@@ -132,10 +130,10 @@ namespace DiscImageChef.Filesystems.ISO9660
return contents;
}
Dictionary<string, DecodedDirectoryEntry> DecodeCdiDirectory(byte[] data, byte XattrLength)
Dictionary<string, DecodedDirectoryEntry> DecodeCdiDirectory(byte[] data, byte xattrLength)
{
Dictionary<string, DecodedDirectoryEntry> entries = new Dictionary<string, DecodedDirectoryEntry>();
int entryOff = XattrLength;
int entryOff = xattrLength;
while(entryOff + CdiDirectoryRecordSize < data.Length)
{
@@ -190,10 +188,10 @@ namespace DiscImageChef.Filesystems.ISO9660
return entries;
}
Dictionary<string, DecodedDirectoryEntry> DecodeHighSierraDirectory(byte[] data, byte XattrLength)
Dictionary<string, DecodedDirectoryEntry> DecodeHighSierraDirectory(byte[] data, byte xattrLength)
{
Dictionary<string, DecodedDirectoryEntry> entries = new Dictionary<string, DecodedDirectoryEntry>();
int entryOff = XattrLength;
int entryOff = xattrLength;
while(entryOff + DirectoryRecordSize < data.Length)
{
@@ -240,10 +238,10 @@ namespace DiscImageChef.Filesystems.ISO9660
return entries;
}
Dictionary<string, DecodedDirectoryEntry> DecodeIsoDirectory(byte[] data, byte XattrLength)
Dictionary<string, DecodedDirectoryEntry> DecodeIsoDirectory(byte[] data, byte xattrLength)
{
Dictionary<string, DecodedDirectoryEntry> entries = new Dictionary<string, DecodedDirectoryEntry>();
int entryOff = XattrLength;
int entryOff = xattrLength;
while(entryOff + DirectoryRecordSize < data.Length)
{
@@ -298,7 +296,6 @@ namespace DiscImageChef.Filesystems.ISO9660
if(joliet && entry.Filename.EndsWith(";1", StringComparison.Ordinal))
entry.Filename = entry.Filename.Substring(0, entry.Filename.Length - 2);
// TODO: XA
int systemAreaStart = entryOff + record.name_len + DirectoryRecordSize;
int systemAreaLength = record.length - record.name_len - DirectoryRecordSize;
@@ -748,7 +745,6 @@ namespace DiscImageChef.Filesystems.ISO9660
systemAreaOff += nmLength;
break;
case RRIP_CHILDLINK:
// TODO
byte clLength = data[systemAreaOff + 2];
// If we are not in Rock Ridge namespace, or we are using the Path Table, skip it
@@ -926,7 +922,7 @@ namespace DiscImageChef.Filesystems.ISO9660
PathTableEntryInternal[] GetPathTableEntries(string path)
{
IEnumerable<PathTableEntryInternal> tableEntries = new PathTableEntryInternal[0];
IEnumerable<PathTableEntryInternal> tableEntries;
List<PathTableEntryInternal> pathTableList = new List<PathTableEntryInternal>(pathTable);
if(path == "" || path == "/") tableEntries = pathTable.Where(p => p.Parent == 1 && p != pathTable[0]);
@@ -1028,7 +1024,6 @@ namespace DiscImageChef.Filesystems.ISO9660
if(record.size != 0) entry.Extents = new List<(uint extent, uint size)> {(record.extent, record.size)};
// TODO: XA
int systemAreaStart = record.name_len + DirectoryRecordSize;
int systemAreaLength = record.length - record.name_len - DirectoryRecordSize;

View File

@@ -69,7 +69,6 @@ namespace DiscImageChef.Filesystems.ISO9660
offset += entry.XattrLength;
// TODO: XA
long firstSector = offset / 2048;
long offsetInSector = offset % 2048;
long sizeInSectors = (size + offsetInSector) / 2048;
@@ -227,7 +226,6 @@ namespace DiscImageChef.Filesystems.ISO9660
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.OwnerRead)) stat.Mode |= 256;
}
// TODO: XA
uint eaSizeInSectors = (uint)(entry.XattrLength / 2048);
if(entry.XattrLength % 2048 > 0) eaSizeInSectors++;
@@ -270,7 +268,7 @@ namespace DiscImageChef.Filesystems.ISO9660
{
entry = null;
string cutPath = path.StartsWith("/")
string cutPath = path.StartsWith("/", StringComparison.Ordinal)
? path.Substring(1).ToLower(CultureInfo.CurrentUICulture)
: path.ToLower(CultureInfo.CurrentUICulture);
string[] pieces = cutPath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
@@ -296,7 +294,6 @@ namespace DiscImageChef.Filesystems.ISO9660
if(string.IsNullOrEmpty(dirent.Key))
{
// TODO: RRIP
if(!joliet && !pieces[pieces.Length - 1].EndsWith(";1", StringComparison.Ordinal))
{
dirent = parent.FirstOrDefault(t => t.Key.ToLower(CultureInfo.CurrentUICulture) ==

View File

@@ -106,12 +106,12 @@ namespace DiscImageChef.Filesystems.ISO9660
byte[] vdSector = imagePlugin.ReadSector(16 + counter + partition.Start);
int xaOff = vdSector.Length == 2336 ? 8 : 0;
Array.Copy(vdSector, 0x009 + xaOff, hsMagic, 0, 5);
bool highSierra = Encoding.GetString(hsMagic) == HIGH_SIERRA_MAGIC;
int hsOff = 0;
if(highSierra) hsOff = 8;
bool cdi = false;
bool evd = false;
bool vpd = false;
bool highSierraInfo = Encoding.GetString(hsMagic) == HIGH_SIERRA_MAGIC;
int hsOff = 0;
if(highSierraInfo) hsOff = 8;
bool cdiInfo = false;
bool evd = false;
bool vpd = false;
while(true)
{
@@ -144,7 +144,7 @@ namespace DiscImageChef.Filesystems.ISO9660
break;
}
cdi |= Encoding.GetString(vdMagic) == CDI_MAGIC;
cdiInfo |= Encoding.GetString(vdMagic) == CDI_MAGIC;
switch(vdType)
{
@@ -167,10 +167,10 @@ namespace DiscImageChef.Filesystems.ISO9660
case 1:
{
if(highSierra)
if(highSierraInfo)
hsvd = Marshal
.ByteArrayToStructureLittleEndian<HighSierraPrimaryVolumeDescriptor>(vdSector);
else if(cdi)
else if(cdiInfo)
fsvd = Marshal.ByteArrayToStructureBigEndian<FileStructureVolumeDescriptor>(vdSector);
else pvd = Marshal.ByteArrayToStructureLittleEndian<PrimaryVolumeDescriptor>(vdSector);
@@ -218,9 +218,9 @@ namespace DiscImageChef.Filesystems.ISO9660
return;
}
if(highSierra) decodedVd = DecodeVolumeDescriptor(hsvd.Value);
else if(cdi) decodedVd = DecodeVolumeDescriptor(fsvd.Value);
else decodedVd = DecodeVolumeDescriptor(pvd.Value);
if(highSierraInfo) decodedVd = DecodeVolumeDescriptor(hsvd.Value);
else if(cdiInfo) decodedVd = DecodeVolumeDescriptor(fsvd.Value);
else decodedVd = DecodeVolumeDescriptor(pvd.Value);
if(jolietvd != null) decodedJolietVd = DecodeJolietDescriptor(jolietvd.Value);
@@ -228,13 +228,13 @@ namespace DiscImageChef.Filesystems.ISO9660
uint rootSize = 0;
// No need to read root on CD-i, as extensions are not supported...
if(!cdi)
if(!cdiInfo)
{
rootLocation = highSierra
rootLocation = highSierraInfo
? hsvd.Value.root_directory_record.extent
: pvd.Value.root_directory_record.extent;
if(highSierra)
if(highSierraInfo)
{
rootSize = hsvd.Value.root_directory_record.size / hsvd.Value.logical_block_size;
if(hsvd.Value.root_directory_record.size % hsvd.Value.logical_block_size > 0) rootSize++;
@@ -263,7 +263,7 @@ namespace DiscImageChef.Filesystems.ISO9660
rootDir = imagePlugin.ReadSectors(rootLocation, rootSize);
// Walk thru root directory to see system area extensions in use
while(rootOff + Marshal.SizeOf<DirectoryRecord>() < rootDir.Length && !cdi)
while(rootOff + Marshal.SizeOf<DirectoryRecord>() < rootDir.Length && !cdiInfo)
{
DirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(rootDir, rootOff,
@@ -397,9 +397,9 @@ namespace DiscImageChef.Filesystems.ISO9660
foreach(ContinuationArea ca in contareas)
{
uint caLen = (ca.ca_length_be + ca.offset_be) /
(highSierra ? hsvd.Value.logical_block_size : pvd.Value.logical_block_size);
(highSierraInfo ? hsvd.Value.logical_block_size : pvd.Value.logical_block_size);
if((ca.ca_length_be + ca.offset_be) %
(highSierra ? hsvd.Value.logical_block_size : pvd.Value.logical_block_size) > 0) caLen++;
(highSierraInfo ? hsvd.Value.logical_block_size : pvd.Value.logical_block_size) > 0) caLen++;
byte[] caSectors = imagePlugin.ReadSectors(ca.block_be, caLen);
byte[] caData = new byte[ca.ca_length_be];
@@ -469,9 +469,9 @@ namespace DiscImageChef.Filesystems.ISO9660
Dreamcast.IPBin? dreamcast = Dreamcast.DecodeIPBin(ipbinSector);
string fsFormat;
if(highSierra) fsFormat = "High Sierra Format";
else if(cdi) fsFormat = "CD-i";
else fsFormat = "ISO9660";
if(highSierraInfo) fsFormat = "High Sierra Format";
else if(cdiInfo) fsFormat = "CD-i";
else fsFormat = "ISO9660";
isoMetadata.AppendFormat("{0} file system", fsFormat).AppendLine();
if(xaExtensions) isoMetadata.AppendLine("CD-ROM XA extensions present.");
@@ -504,9 +504,12 @@ namespace DiscImageChef.Filesystems.ISO9660
isoMetadata.AppendLine(Dreamcast.Prettify(dreamcast));
}
isoMetadata.AppendFormat("{0}------------------------------", cdi ? "---------------" : "").AppendLine();
isoMetadata.AppendFormat("{0}VOLUME DESCRIPTOR INFORMATION:", cdi ? "FILE STRUCTURE " : "").AppendLine();
isoMetadata.AppendFormat("{0}------------------------------", cdi ? "---------------" : "").AppendLine();
isoMetadata.AppendFormat("{0}------------------------------", cdiInfo ? "---------------" : "")
.AppendLine();
isoMetadata.AppendFormat("{0}VOLUME DESCRIPTOR INFORMATION:", cdiInfo ? "FILE STRUCTURE " : "")
.AppendLine();
isoMetadata.AppendFormat("{0}------------------------------", cdiInfo ? "---------------" : "")
.AppendLine();
isoMetadata.AppendFormat("System identifier: {0}", decodedVd.SystemIdentifier).AppendLine();
isoMetadata.AppendFormat("Volume identifier: {0}", decodedVd.VolumeIdentifier).AppendLine();
isoMetadata.AppendFormat("Volume set identifier: {0}", decodedVd.VolumeSetIdentifier).AppendLine();

View File

@@ -39,10 +39,10 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AmigaEntry
{
public ushort signature;
public byte length;
public byte version;
public AmigaFlags flags;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
public readonly AmigaFlags flags;
// Followed by AmigaProtection if present
// Followed by length-prefixed string for comment if present
}
@@ -50,10 +50,10 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AmigaProtection
{
public byte User;
public byte Reserved;
public AmigaMultiuser Multiuser;
public AmigaAttributes Protection;
public readonly byte User;
public readonly byte Reserved;
public readonly AmigaMultiuser Multiuser;
public readonly AmigaAttributes Protection;
}
}
}

View File

@@ -39,77 +39,77 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ElToritoBootRecord
{
public byte type;
public readonly byte type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public byte[] id;
public byte version;
public readonly byte[] id;
public readonly byte version;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] system_id;
public readonly byte[] system_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] boot_id;
public uint catalog_sector;
public readonly byte[] boot_id;
public readonly uint catalog_sector;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1974)]
public byte[] boot_use;
public readonly byte[] boot_use;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ElToritoValidationEntry
{
public ElToritoIndicator header_id;
public ElToritoPlatform platform_id;
public ushort reserved;
public readonly ElToritoIndicator header_id;
public readonly ElToritoPlatform platform_id;
public readonly ushort reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public byte[] developer_id;
public ushort checksum;
public ushort signature;
public readonly byte[] developer_id;
public readonly ushort checksum;
public readonly ushort signature;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ElToritoInitialEntry
{
public ElToritoIndicator bootable;
public ElToritoEmulation boot_type;
public ushort load_seg;
public byte system_type;
public byte reserved1;
public ushort sector_count;
public uint load_rba;
public readonly ElToritoIndicator bootable;
public ElToritoEmulation boot_type;
public readonly ushort load_seg;
public readonly byte system_type;
public readonly byte reserved1;
public readonly ushort sector_count;
public readonly uint load_rba;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] reserved2;
public readonly byte[] reserved2;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ElToritoSectionHeaderEntry
{
public ElToritoIndicator header_id;
public ElToritoPlatform platform_id;
public ushort entries;
public readonly ElToritoIndicator header_id;
public readonly ElToritoPlatform platform_id;
public readonly ushort entries;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)]
public byte[] identifier;
public readonly byte[] identifier;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ElToritoSectionEntry
{
public ElToritoIndicator bootable;
public ElToritoEmulation boot_type;
public ushort load_seg;
public byte system_type;
public byte reserved1;
public ushort sector_count;
public uint load_rba;
public byte selection_criteria_type;
public readonly ElToritoIndicator bootable;
public readonly ElToritoEmulation boot_type;
public readonly ushort load_seg;
public readonly byte system_type;
public readonly byte reserved1;
public readonly ushort sector_count;
public readonly uint load_rba;
public readonly byte selection_criteria_type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 19)]
public byte[] selection_criterias;
public readonly byte[] selection_criterias;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ElToritoSectionEntryExtension
{
public ElToritoIndicator extension_indicator;
public ElToritoFlags extension_flags;
public readonly ElToritoIndicator extension_indicator;
public readonly ElToritoFlags extension_flags;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public byte[] selection_criterias;
public readonly byte[] selection_criterias;
}
}
}

View File

@@ -39,53 +39,53 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ContinuationArea
{
public ushort signature;
public byte length;
public byte version;
public uint block;
public uint block_be;
public uint offset;
public uint offset_be;
public uint ca_length;
public uint ca_length_be;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
public readonly uint block;
public readonly uint block_be;
public readonly uint offset;
public readonly uint offset_be;
public readonly uint ca_length;
public readonly uint ca_length_be;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct PaddingArea
{
public ushort signature;
public byte length;
public byte version;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct IndicatorArea
{
public ushort signature;
public byte length;
public byte version;
public ushort magic;
public byte skipped;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
public readonly ushort magic;
public readonly byte skipped;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct TerminatorArea
{
public ushort signature;
public byte length;
public byte version;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ReferenceArea
{
public ushort signature;
public byte length;
public byte version;
public byte id_len;
public byte des_len;
public byte src_len;
public byte ext_ver;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
public readonly byte id_len;
public readonly byte des_len;
public readonly byte src_len;
public readonly byte ext_ver;
// Follows extension identifier for id_len bytes
// Follows extension descriptor for des_len bytes
// Follows extension source for src_len bytes
@@ -94,10 +94,10 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct SelectorArea
{
public ushort signature;
public byte length;
public byte version;
public byte sequence;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
public readonly byte sequence;
}
}
}

View File

@@ -40,13 +40,13 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct CdromXa
{
public XaAttributes attributes;
public byte filenumber;
public ushort group;
public readonly XaAttributes attributes;
public readonly byte filenumber;
public readonly ushort group;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public byte[] reserved;
public ushort signature;
public ushort user;
public readonly byte[] reserved;
public readonly ushort signature;
public readonly ushort user;
}
}
}

View File

@@ -39,24 +39,24 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ZisofsHeader
{
public ulong magic;
public uint uncomp_len;
public uint uncomp_len_be;
public byte header_size; // Shifted >> 2
public byte block_size_log; // log2(block_size)
public readonly ulong magic;
public readonly uint uncomp_len;
public readonly uint uncomp_len_be;
public readonly byte header_size; // Shifted >> 2
public readonly byte block_size_log; // log2(block_size)
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ZisofsEntry
{
public ushort signature;
public byte length;
public byte version;
public ushort alogirhtm;
public byte header_size; // Shifted >> 2
public byte block_size_log; // log2(block_size)
public uint uncomp_len;
public uint uncomp_len_be;
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
public readonly ushort alogirhtm;
public readonly byte header_size; // Shifted >> 2
public readonly byte block_size_log; // log2(block_size)
public readonly uint uncomp_len;
public readonly uint uncomp_len_be;
}
}
}

View File

@@ -199,7 +199,7 @@ namespace DiscImageChef.Filesystems.ISO9660
string fsFormat;
byte[] pathTableData;
uint pathTableSizeInSectors = 0;
uint pathTableSizeInSectors;
uint pathTableMsbLocation;
uint pathTableLsbLocation = 0; // Initialize to 0 as ignored in CD-i
@@ -253,8 +253,8 @@ namespace DiscImageChef.Filesystems.ISO9660
if(jolietvd is null && this.@namespace == Namespace.Joliet) this.@namespace = Namespace.Normal;
uint rootLocation = 0;
uint rootSize = 0;
uint rootLocation;
uint rootSize;
byte rootXattrLength = 0;
if(!cdi)
@@ -341,11 +341,10 @@ namespace DiscImageChef.Filesystems.ISO9660
rootDirectoryCache.Add("$PATH_TABLE.LSB",
new DecodedDirectoryEntry
{
Extents =
new List<(uint extent, uint size)>
{
(rootLocation, (uint)pathTableData.Length)
},
Extents = new List<(uint extent, uint size)>
{
(pathTableLsbLocation, (uint)pathTableData.Length)
},
Filename = "$PATH_TABLE.LSB",
Size = (uint)pathTableData.Length,
Timestamp = decodedVd.CreationTime
@@ -357,7 +356,7 @@ namespace DiscImageChef.Filesystems.ISO9660
Extents =
new List<(uint extent, uint size)>
{
(rootLocation, (uint)pathTableData.Length)
(pathTableMsbLocation, (uint)pathTableData.Length)
},
Filename = "$PATH_TABLE.MSB",
Size = (uint)pathTableData.Length,

View File

@@ -43,7 +43,6 @@ namespace DiscImageChef.Filesystems.ISO9660
if(entry.Extents is null) return Errno.InvalidArgument;
// TODO: XA
uint eaSizeInSectors = (uint)(entry.XattrLength / 2048);
if(entry.XattrLength % 2048 > 0) eaSizeInSectors++;