Cache ISO, HSF and CDI record sizes.

This commit is contained in:
2019-07-31 19:44:27 +01:00
parent 816835e667
commit 62e14f275e
3 changed files with 22 additions and 24 deletions

View File

@@ -31,12 +31,15 @@
// ****************************************************************************/ // ****************************************************************************/
using System; using System;
using DiscImageChef.Helpers;
namespace DiscImageChef.Filesystems.ISO9660 namespace DiscImageChef.Filesystems.ISO9660
{ {
public partial class ISO9660 public partial class ISO9660
{ {
const string CDI_MAGIC = "CD-I "; const string CDI_MAGIC = "CD-I ";
static readonly int CdiDirectoryRecordSize = Marshal.SizeOf<CdiDirectoryRecord>();
static readonly int CdiSystemAreaSize = Marshal.SizeOf<CdiSystemArea>();
[Flags] [Flags]
enum CdiVolumeFlags : byte enum CdiVolumeFlags : byte

View File

@@ -30,10 +30,13 @@
// Copyright © 2011-2019 Natalia Portillo // Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using DiscImageChef.Helpers;
namespace DiscImageChef.Filesystems.ISO9660 namespace DiscImageChef.Filesystems.ISO9660
{ {
public partial class ISO9660 public partial class ISO9660
{ {
const string HIGH_SIERRA_MAGIC = "CDROM"; const string HIGH_SIERRA_MAGIC = "CDROM";
static readonly int HighSierraDirectoryRecordSize = Marshal.SizeOf<HighSierraDirectoryRecord>();
} }
} }

View File

@@ -137,11 +137,10 @@ namespace DiscImageChef.Filesystems.ISO9660
Dictionary<string, DecodedDirectoryEntry> entries = new Dictionary<string, DecodedDirectoryEntry>(); Dictionary<string, DecodedDirectoryEntry> entries = new Dictionary<string, DecodedDirectoryEntry>();
int entryOff = XattrLength; int entryOff = XattrLength;
while(entryOff + Marshal.SizeOf<CdiDirectoryRecord>() < data.Length) while(entryOff + CdiDirectoryRecordSize < data.Length)
{ {
CdiDirectoryRecord record = CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(data, entryOff, Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(data, entryOff, CdiDirectoryRecordSize);
Marshal.SizeOf<CdiDirectoryRecord>());
if(record.length == 0) break; if(record.length == 0) break;
@@ -174,8 +173,7 @@ namespace DiscImageChef.Filesystems.ISO9660
entry.CdiSystemArea = entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(data, Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(data,
entryOff + record.name_len + entryOff + record.name_len +
Marshal.SizeOf<CdiDirectoryRecord>(), CdiDirectoryRecordSize, CdiSystemAreaSize);
Marshal.SizeOf<CdiSystemArea>());
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory)) if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
{ {
@@ -201,8 +199,7 @@ namespace DiscImageChef.Filesystems.ISO9660
{ {
HighSierraDirectoryRecord record = HighSierraDirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(data, entryOff, Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(data, entryOff,
Marshal HighSierraDirectoryRecordSize);
.SizeOf<DirectoryRecord>());
if(record.length == 0) break; if(record.length == 0) break;
@@ -251,8 +248,7 @@ namespace DiscImageChef.Filesystems.ISO9660
while(entryOff + DirectoryRecordSize < data.Length) while(entryOff + DirectoryRecordSize < data.Length)
{ {
DirectoryRecord record = DirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(data, entryOff, Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(data, entryOff, DirectoryRecordSize);
Marshal.SizeOf<DirectoryRecord>());
if(record.length == 0) break; if(record.length == 0) break;
@@ -303,8 +299,8 @@ namespace DiscImageChef.Filesystems.ISO9660
entry.Filename = entry.Filename.Substring(0, entry.Filename.Length - 2); entry.Filename = entry.Filename.Substring(0, entry.Filename.Length - 2);
// TODO: XA // TODO: XA
int systemAreaStart = entryOff + record.name_len + Marshal.SizeOf<DirectoryRecord>(); int systemAreaStart = entryOff + record.name_len + DirectoryRecordSize;
int systemAreaLength = record.length - record.name_len - Marshal.SizeOf<DirectoryRecord>(); int systemAreaLength = record.length - record.name_len - DirectoryRecordSize;
if(systemAreaStart % 2 != 0) if(systemAreaStart % 2 != 0)
{ {
@@ -973,7 +969,7 @@ namespace DiscImageChef.Filesystems.ISO9660
byte[] sector = ReadSectors(tEntry.Extent, 1); byte[] sector = ReadSectors(tEntry.Extent, 1);
CdiDirectoryRecord record = CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(sector, tEntry.XattrLength, Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(sector, tEntry.XattrLength,
Marshal.SizeOf<CdiDirectoryRecord>()); CdiDirectoryRecordSize);
if(record.length == 0) break; if(record.length == 0) break;
@@ -993,9 +989,8 @@ namespace DiscImageChef.Filesystems.ISO9660
entry.CdiSystemArea = entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(sector, Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(sector,
record.name_len + record.name_len + CdiDirectoryRecordSize,
Marshal.SizeOf<CdiDirectoryRecord>(), CdiSystemAreaSize);
Marshal.SizeOf<CdiSystemArea>());
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory)) if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
entry.Flags |= FileFlags.Directory; entry.Flags |= FileFlags.Directory;
@@ -1015,7 +1010,7 @@ namespace DiscImageChef.Filesystems.ISO9660
byte[] sector = ReadSectors(tEntry.Extent, 1); byte[] sector = ReadSectors(tEntry.Extent, 1);
DirectoryRecord record = DirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(sector, tEntry.XattrLength, Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(sector, tEntry.XattrLength,
Marshal.SizeOf<DirectoryRecord>()); DirectoryRecordSize);
if(record.length == 0) break; if(record.length == 0) break;
@@ -1034,8 +1029,8 @@ namespace DiscImageChef.Filesystems.ISO9660
if(record.size != 0) entry.Extents = new List<(uint extent, uint size)> {(record.extent, record.size)}; if(record.size != 0) entry.Extents = new List<(uint extent, uint size)> {(record.extent, record.size)};
// TODO: XA // TODO: XA
int systemAreaStart = record.name_len + Marshal.SizeOf<DirectoryRecord>(); int systemAreaStart = record.name_len + DirectoryRecordSize;
int systemAreaLength = record.length - record.name_len - Marshal.SizeOf<DirectoryRecord>(); int systemAreaLength = record.length - record.name_len - DirectoryRecordSize;
if(systemAreaStart % 2 != 0) if(systemAreaStart % 2 != 0)
{ {
@@ -1060,10 +1055,7 @@ namespace DiscImageChef.Filesystems.ISO9660
byte[] sector = ReadSectors(tEntry.Extent, 1); byte[] sector = ReadSectors(tEntry.Extent, 1);
HighSierraDirectoryRecord record = HighSierraDirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(sector, tEntry.XattrLength, Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(sector, tEntry.XattrLength,
Marshal HighSierraDirectoryRecordSize);
.SizeOf<
HighSierraDirectoryRecord
>());
DecodedDirectoryEntry entry = new DecodedDirectoryEntry DecodedDirectoryEntry entry = new DecodedDirectoryEntry
{ {