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 DiscImageChef.Helpers;
namespace DiscImageChef.Filesystems.ISO9660
{
public partial class ISO9660
{
const string CDI_MAGIC = "CD-I ";
static readonly int CdiDirectoryRecordSize = Marshal.SizeOf<CdiDirectoryRecord>();
static readonly int CdiSystemAreaSize = Marshal.SizeOf<CdiSystemArea>();
[Flags]
enum CdiVolumeFlags : byte

View File

@@ -30,10 +30,13 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using DiscImageChef.Helpers;
namespace DiscImageChef.Filesystems.ISO9660
{
public partial class ISO9660
{
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>();
int entryOff = XattrLength;
while(entryOff + Marshal.SizeOf<CdiDirectoryRecord>() < data.Length)
while(entryOff + CdiDirectoryRecordSize < data.Length)
{
CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(data, entryOff,
Marshal.SizeOf<CdiDirectoryRecord>());
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(data, entryOff, CdiDirectoryRecordSize);
if(record.length == 0) break;
@@ -174,8 +173,7 @@ namespace DiscImageChef.Filesystems.ISO9660
entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(data,
entryOff + record.name_len +
Marshal.SizeOf<CdiDirectoryRecord>(),
Marshal.SizeOf<CdiSystemArea>());
CdiDirectoryRecordSize, CdiSystemAreaSize);
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
{
@@ -201,8 +199,7 @@ namespace DiscImageChef.Filesystems.ISO9660
{
HighSierraDirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(data, entryOff,
Marshal
.SizeOf<DirectoryRecord>());
HighSierraDirectoryRecordSize);
if(record.length == 0) break;
@@ -251,8 +248,7 @@ namespace DiscImageChef.Filesystems.ISO9660
while(entryOff + DirectoryRecordSize < data.Length)
{
DirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(data, entryOff,
Marshal.SizeOf<DirectoryRecord>());
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(data, entryOff, DirectoryRecordSize);
if(record.length == 0) break;
@@ -303,8 +299,8 @@ namespace DiscImageChef.Filesystems.ISO9660
entry.Filename = entry.Filename.Substring(0, entry.Filename.Length - 2);
// TODO: XA
int systemAreaStart = entryOff + record.name_len + Marshal.SizeOf<DirectoryRecord>();
int systemAreaLength = record.length - record.name_len - Marshal.SizeOf<DirectoryRecord>();
int systemAreaStart = entryOff + record.name_len + DirectoryRecordSize;
int systemAreaLength = record.length - record.name_len - DirectoryRecordSize;
if(systemAreaStart % 2 != 0)
{
@@ -973,7 +969,7 @@ namespace DiscImageChef.Filesystems.ISO9660
byte[] sector = ReadSectors(tEntry.Extent, 1);
CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(sector, tEntry.XattrLength,
Marshal.SizeOf<CdiDirectoryRecord>());
CdiDirectoryRecordSize);
if(record.length == 0) break;
@@ -993,9 +989,8 @@ namespace DiscImageChef.Filesystems.ISO9660
entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(sector,
record.name_len +
Marshal.SizeOf<CdiDirectoryRecord>(),
Marshal.SizeOf<CdiSystemArea>());
record.name_len + CdiDirectoryRecordSize,
CdiSystemAreaSize);
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
entry.Flags |= FileFlags.Directory;
@@ -1015,7 +1010,7 @@ namespace DiscImageChef.Filesystems.ISO9660
byte[] sector = ReadSectors(tEntry.Extent, 1);
DirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(sector, tEntry.XattrLength,
Marshal.SizeOf<DirectoryRecord>());
DirectoryRecordSize);
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)};
// TODO: XA
int systemAreaStart = record.name_len + Marshal.SizeOf<DirectoryRecord>();
int systemAreaLength = record.length - record.name_len - Marshal.SizeOf<DirectoryRecord>();
int systemAreaStart = record.name_len + DirectoryRecordSize;
int systemAreaLength = record.length - record.name_len - DirectoryRecordSize;
if(systemAreaStart % 2 != 0)
{
@@ -1060,10 +1055,7 @@ namespace DiscImageChef.Filesystems.ISO9660
byte[] sector = ReadSectors(tEntry.Extent, 1);
HighSierraDirectoryRecord record =
Marshal.ByteArrayToStructureLittleEndian<HighSierraDirectoryRecord>(sector, tEntry.XattrLength,
Marshal
.SizeOf<
HighSierraDirectoryRecord
>());
HighSierraDirectoryRecordSize);
DecodedDirectoryEntry entry = new DecodedDirectoryEntry
{