[ISO9660] Use new source generator based big endian marshaller

This commit is contained in:
2025-10-21 02:00:44 +01:00
parent 18679890c2
commit 7c1253a088
11 changed files with 395 additions and 366 deletions

View File

@@ -43,160 +43,6 @@ public sealed partial class ISO9660
{
Dictionary<string, Dictionary<string, DecodedDirectoryEntry>> _directoryCache;
#region IReadOnlyFilesystem Members
/// <inheritdoc />
public ErrorNumber OpenDir(string path, out IDirNode node)
{
node = null;
if(!_mounted) return ErrorNumber.AccessDenied;
if(string.IsNullOrWhiteSpace(path) || path == "/")
{
node = new Iso9660DirNode
{
Path = path,
Position = 0,
Entries = _rootDirectoryCache.Values.ToArray()
};
return ErrorNumber.NoError;
}
string cutPath = path.StartsWith("/", StringComparison.Ordinal)
? path[1..].ToLower(CultureInfo.CurrentUICulture)
: path.ToLower(CultureInfo.CurrentUICulture);
if(_directoryCache.TryGetValue(cutPath, out Dictionary<string, DecodedDirectoryEntry> currentDirectory))
{
node = new Iso9660DirNode
{
Path = path,
Position = 0,
Entries = currentDirectory.Values.ToArray()
};
return ErrorNumber.NoError;
}
string[] pieces = cutPath.Split(new[]
{
'/'
},
StringSplitOptions.RemoveEmptyEntries);
KeyValuePair<string, DecodedDirectoryEntry> entry =
_rootDirectoryCache.FirstOrDefault(t => t.Key.Equals(pieces[0], StringComparison.CurrentCultureIgnoreCase));
if(string.IsNullOrEmpty(entry.Key)) return ErrorNumber.NoSuchFile;
if(!entry.Value.Flags.HasFlag(FileFlags.Directory)) return ErrorNumber.NotDirectory;
string currentPath = pieces[0];
currentDirectory = _rootDirectoryCache;
for(var p = 0; p < pieces.Length; p++)
{
entry = currentDirectory.FirstOrDefault(t => t.Key.Equals(pieces[p],
StringComparison.CurrentCultureIgnoreCase));
if(string.IsNullOrEmpty(entry.Key)) return ErrorNumber.NoSuchFile;
if(!entry.Value.Flags.HasFlag(FileFlags.Directory)) return ErrorNumber.NotDirectory;
currentPath = p == 0 ? pieces[0] : $"{currentPath}/{pieces[p]}";
if(_directoryCache.TryGetValue(currentPath, out currentDirectory)) continue;
if(entry.Value.Extents.Count == 0) return ErrorNumber.InvalidArgument;
currentDirectory = _cdi
? DecodeCdiDirectory(entry.Value.Extents[0].extent + entry.Value.XattrLength,
entry.Value.Extents[0].size)
: _highSierra
? DecodeHighSierraDirectory(entry.Value.Extents[0].extent +
entry.Value.XattrLength,
entry.Value.Extents[0].size)
: DecodeIsoDirectory(entry.Value.Extents[0].extent + entry.Value.XattrLength,
entry.Value.Extents[0].size);
if(_usePathTable)
{
foreach(DecodedDirectoryEntry subDirectory in _cdi
? GetSubdirsFromCdiPathTable(currentPath)
: _highSierra
? GetSubdirsFromHighSierraPathTable(currentPath)
: GetSubdirsFromIsoPathTable(currentPath))
currentDirectory[subDirectory.Filename] = subDirectory;
}
_directoryCache.Add(currentPath, currentDirectory);
}
if(currentDirectory is null) return ErrorNumber.NoSuchFile;
node = new Iso9660DirNode
{
Path = path,
Position = 0,
Entries = currentDirectory.Values.ToArray()
};
return ErrorNumber.NoError;
}
/// <inheritdoc />
public ErrorNumber ReadDir(IDirNode node, out string filename)
{
filename = null;
if(!_mounted) return ErrorNumber.AccessDenied;
if(node is not Iso9660DirNode mynode) return ErrorNumber.InvalidArgument;
if(mynode.Position < 0) return ErrorNumber.InvalidArgument;
if(mynode.Position >= mynode.Entries.Length) return ErrorNumber.NoError;
switch(_namespace)
{
case Namespace.Normal:
filename = mynode.Entries[mynode.Position].Filename.EndsWith(";1", StringComparison.Ordinal)
? mynode.Entries[mynode.Position].Filename[..^2]
: mynode.Entries[mynode.Position].Filename;
break;
case Namespace.Vms:
case Namespace.Joliet:
case Namespace.Rrip:
case Namespace.Romeo:
filename = mynode.Entries[mynode.Position].Filename;
break;
default:
return ErrorNumber.InvalidArgument;
}
mynode.Position++;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public ErrorNumber CloseDir(IDirNode node)
{
if(node is not Iso9660DirNode mynode) return ErrorNumber.InvalidArgument;
mynode.Position = -1;
mynode.Entries = null;
return ErrorNumber.NoError;
}
#endregion
Dictionary<string, DecodedDirectoryEntry> DecodeCdiDirectory(ulong start, uint size)
{
Dictionary<string, DecodedDirectoryEntry> entries = new();
@@ -209,7 +55,9 @@ public sealed partial class ISO9660
while(entryOff + _cdiDirectoryRecordSize < data.Length)
{
CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(data, entryOff, _cdiDirectoryRecordSize);
Marshal.ByteArrayToStructureBigEndianGenerated<CdiDirectoryRecord>(data,
entryOff,
_cdiDirectoryRecordSize);
if(record.length == 0)
{
@@ -259,7 +107,9 @@ public sealed partial class ISO9660
if(systemAreaStart % 2 != 0) systemAreaStart++;
entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(data, systemAreaStart, _cdiSystemAreaSize);
Marshal.ByteArrayToStructureBigEndianGenerated<CdiSystemArea>(data,
systemAreaStart,
_cdiSystemAreaSize);
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
entry.Flags |= FileFlags.Directory;
@@ -609,7 +459,7 @@ public sealed partial class ISO9660
break;
case AppleId.HFS:
AppleHFSSystemUse appleHfsSystemUse =
Marshal.ByteArrayToStructureBigEndian<AppleHFSSystemUse>(data,
Marshal.ByteArrayToStructureBigEndianGenerated<AppleHFSSystemUse>(data,
systemAreaOff,
Marshal.SizeOf<AppleHFSSystemUse>());
@@ -650,7 +500,7 @@ public sealed partial class ISO9660
case AppleOldId.TypeCreator:
case AppleOldId.TypeCreatorBundle:
AppleHFSTypeCreatorSystemUse appleHfsTypeCreatorSystemUse =
Marshal.ByteArrayToStructureBigEndian<AppleHFSTypeCreatorSystemUse>(data,
Marshal.ByteArrayToStructureBigEndianGenerated<AppleHFSTypeCreatorSystemUse>(data,
systemAreaOff,
Marshal.SizeOf<AppleHFSTypeCreatorSystemUse>());
@@ -670,7 +520,7 @@ public sealed partial class ISO9660
case AppleOldId.TypeCreatorIcon:
case AppleOldId.TypeCreatorIconBundle:
AppleHFSIconSystemUse appleHfsIconSystemUse =
Marshal.ByteArrayToStructureBigEndian<AppleHFSIconSystemUse>(data,
Marshal.ByteArrayToStructureBigEndianGenerated<AppleHFSIconSystemUse>(data,
systemAreaOff,
Marshal.SizeOf<AppleHFSIconSystemUse>());
@@ -690,7 +540,7 @@ public sealed partial class ISO9660
break;
case AppleOldId.HFS:
AppleHFSOldSystemUse appleHfsSystemUse =
Marshal.ByteArrayToStructureBigEndian<AppleHFSOldSystemUse>(data,
Marshal.ByteArrayToStructureBigEndianGenerated<AppleHFSOldSystemUse>(data,
systemAreaOff,
Marshal.SizeOf<AppleHFSOldSystemUse>());
@@ -717,9 +567,9 @@ public sealed partial class ISO9660
break;
case XA_MAGIC:
entry.XA = Marshal.ByteArrayToStructureBigEndian<CdromXa>(data,
systemAreaOff,
Marshal.SizeOf<CdromXa>());
entry.XA = Marshal.ByteArrayToStructureBigEndianGenerated<CdromXa>(data,
systemAreaOff,
Marshal.SizeOf<CdromXa>());
systemAreaOff += Marshal.SizeOf<CdromXa>();
@@ -729,16 +579,16 @@ public sealed partial class ISO9660
case AAIP_MAGIC:
case AMIGA_MAGIC:
AmigaEntry amiga =
Marshal.ByteArrayToStructureBigEndian<AmigaEntry>(data,
systemAreaOff,
Marshal.SizeOf<AmigaEntry>());
Marshal.ByteArrayToStructureBigEndianGenerated<AmigaEntry>(data,
systemAreaOff,
Marshal.SizeOf<AmigaEntry>());
var protectionLength = 0;
if(amiga.flags.HasFlag(AmigaFlags.Protection))
{
entry.AmigaProtection =
Marshal.ByteArrayToStructureBigEndian<AmigaProtection>(data,
Marshal.ByteArrayToStructureBigEndianGenerated<AmigaProtection>(data,
systemAreaOff + Marshal.SizeOf<AmigaEntry>(),
Marshal.SizeOf<AmigaProtection>());
@@ -1145,9 +995,9 @@ public sealed partial class ISO9660
if(errno != ErrorNumber.NoError) continue;
CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(sector,
tEntry.XattrLength,
_cdiDirectoryRecordSize);
Marshal.ByteArrayToStructureBigEndianGenerated<CdiDirectoryRecord>(sector,
tEntry.XattrLength,
_cdiDirectoryRecordSize);
if(record.length == 0) break;
@@ -1170,7 +1020,9 @@ public sealed partial class ISO9660
if(systemAreaStart % 2 != 0) systemAreaStart++;
entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(sector, systemAreaStart, _cdiSystemAreaSize);
Marshal.ByteArrayToStructureBigEndianGenerated<CdiSystemArea>(sector,
systemAreaStart,
_cdiSystemAreaSize);
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
entry.Flags |= FileFlags.Directory;
@@ -1266,4 +1118,158 @@ public sealed partial class ISO9660
return entries.ToArray();
}
#region IReadOnlyFilesystem Members
/// <inheritdoc />
public ErrorNumber OpenDir(string path, out IDirNode node)
{
node = null;
if(!_mounted) return ErrorNumber.AccessDenied;
if(string.IsNullOrWhiteSpace(path) || path == "/")
{
node = new Iso9660DirNode
{
Path = path,
Position = 0,
Entries = _rootDirectoryCache.Values.ToArray()
};
return ErrorNumber.NoError;
}
string cutPath = path.StartsWith("/", StringComparison.Ordinal)
? path[1..].ToLower(CultureInfo.CurrentUICulture)
: path.ToLower(CultureInfo.CurrentUICulture);
if(_directoryCache.TryGetValue(cutPath, out Dictionary<string, DecodedDirectoryEntry> currentDirectory))
{
node = new Iso9660DirNode
{
Path = path,
Position = 0,
Entries = currentDirectory.Values.ToArray()
};
return ErrorNumber.NoError;
}
string[] pieces = cutPath.Split(new[]
{
'/'
},
StringSplitOptions.RemoveEmptyEntries);
KeyValuePair<string, DecodedDirectoryEntry> entry =
_rootDirectoryCache.FirstOrDefault(t => t.Key.Equals(pieces[0], StringComparison.CurrentCultureIgnoreCase));
if(string.IsNullOrEmpty(entry.Key)) return ErrorNumber.NoSuchFile;
if(!entry.Value.Flags.HasFlag(FileFlags.Directory)) return ErrorNumber.NotDirectory;
string currentPath = pieces[0];
currentDirectory = _rootDirectoryCache;
for(var p = 0; p < pieces.Length; p++)
{
entry = currentDirectory.FirstOrDefault(t => t.Key.Equals(pieces[p],
StringComparison.CurrentCultureIgnoreCase));
if(string.IsNullOrEmpty(entry.Key)) return ErrorNumber.NoSuchFile;
if(!entry.Value.Flags.HasFlag(FileFlags.Directory)) return ErrorNumber.NotDirectory;
currentPath = p == 0 ? pieces[0] : $"{currentPath}/{pieces[p]}";
if(_directoryCache.TryGetValue(currentPath, out currentDirectory)) continue;
if(entry.Value.Extents.Count == 0) return ErrorNumber.InvalidArgument;
currentDirectory = _cdi
? DecodeCdiDirectory(entry.Value.Extents[0].extent + entry.Value.XattrLength,
entry.Value.Extents[0].size)
: _highSierra
? DecodeHighSierraDirectory(entry.Value.Extents[0].extent +
entry.Value.XattrLength,
entry.Value.Extents[0].size)
: DecodeIsoDirectory(entry.Value.Extents[0].extent + entry.Value.XattrLength,
entry.Value.Extents[0].size);
if(_usePathTable)
{
foreach(DecodedDirectoryEntry subDirectory in _cdi
? GetSubdirsFromCdiPathTable(currentPath)
: _highSierra
? GetSubdirsFromHighSierraPathTable(currentPath)
: GetSubdirsFromIsoPathTable(currentPath))
currentDirectory[subDirectory.Filename] = subDirectory;
}
_directoryCache.Add(currentPath, currentDirectory);
}
if(currentDirectory is null) return ErrorNumber.NoSuchFile;
node = new Iso9660DirNode
{
Path = path,
Position = 0,
Entries = currentDirectory.Values.ToArray()
};
return ErrorNumber.NoError;
}
/// <inheritdoc />
public ErrorNumber ReadDir(IDirNode node, out string filename)
{
filename = null;
if(!_mounted) return ErrorNumber.AccessDenied;
if(node is not Iso9660DirNode mynode) return ErrorNumber.InvalidArgument;
if(mynode.Position < 0) return ErrorNumber.InvalidArgument;
if(mynode.Position >= mynode.Entries.Length) return ErrorNumber.NoError;
switch(_namespace)
{
case Namespace.Normal:
filename = mynode.Entries[mynode.Position].Filename.EndsWith(";1", StringComparison.Ordinal)
? mynode.Entries[mynode.Position].Filename[..^2]
: mynode.Entries[mynode.Position].Filename;
break;
case Namespace.Vms:
case Namespace.Joliet:
case Namespace.Rrip:
case Namespace.Romeo:
filename = mynode.Entries[mynode.Position].Filename;
break;
default:
return ErrorNumber.InvalidArgument;
}
mynode.Position++;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public ErrorNumber CloseDir(IDirNode node)
{
if(node is not Iso9660DirNode mynode) return ErrorNumber.InvalidArgument;
mynode.Position = -1;
mynode.Entries = null;
return ErrorNumber.NoError;
}
#endregion
}

View File

@@ -59,13 +59,13 @@ public sealed partial class ISO9660
if(errno != ErrorNumber.NoError) return false;
int xaOff = 0;
var xaOff = 0;
if(vdSector.Length == 2336) xaOff = 8;
byte vdType = vdSector[0 + xaOff];
byte[] vdMagic = new byte[5];
byte[] hsMagic = new byte[5];
byte vdType = vdSector[0 + xaOff];
var vdMagic = new byte[5];
var hsMagic = new byte[5];
// This indicates the end of a volume descriptor. HighSierra here would have 16 so no problem
if(vdType == 255) return false;
@@ -88,11 +88,11 @@ public sealed partial class ISO9660
encoding ??= Encoding.ASCII;
information = "";
metadata = new FileSystem();
var isoMetadata = new StringBuilder();
byte[] vdMagic = new byte[5]; // Volume Descriptor magic "CD001"
byte[] hsMagic = new byte[5]; // Volume Descriptor magic "CDROM"
var isoMetadata = new StringBuilder();
var vdMagic = new byte[5]; // Volume Descriptor magic "CD001"
var hsMagic = new byte[5]; // Volume Descriptor magic "CDROM"
string bootSpec = "";
var bootSpec = "";
PrimaryVolumeDescriptor? pvd = null;
PrimaryVolumeDescriptor? jolietvd = null;
@@ -116,13 +116,13 @@ public sealed partial class ISO9660
int xaOff = vdSector.Length == 2336 ? 8 : 0;
Array.Copy(vdSector, 0x009 + xaOff, hsMagic, 0, 5);
bool highSierraInfo = encoding.GetString(hsMagic) == HIGH_SIERRA_MAGIC;
int hsOff = 0;
var hsOff = 0;
if(highSierraInfo) hsOff = 8;
bool cdiInfo = false;
bool evd = false;
bool vpd = false;
var cdiInfo = false;
var evd = false;
var vpd = false;
while(true)
{
@@ -185,7 +185,7 @@ public sealed partial class ISO9660
if(highSierraInfo)
hsvd = Marshal.ByteArrayToStructureLittleEndian<HighSierraPrimaryVolumeDescriptor>(vdSector);
else if(cdiInfo)
fsvd = Marshal.ByteArrayToStructureBigEndian<FileStructureVolumeDescriptor>(vdSector);
fsvd = Marshal.ByteArrayToStructureBigEndianGenerated<FileStructureVolumeDescriptor>(vdSector);
else
pvd = Marshal.ByteArrayToStructureLittleEndian<PrimaryVolumeDescriptor>(vdSector);
@@ -276,14 +276,14 @@ public sealed partial class ISO9660
}
byte[] rootDir = [];
int rootOff = 0;
bool xaExtensions = false;
bool apple = false;
bool susp = false;
bool rrip = false;
bool ziso = false;
bool amiga = false;
bool aaip = false;
var rootOff = 0;
var xaExtensions = false;
var apple = false;
var susp = false;
var rrip = false;
var ziso = false;
var amiga = false;
var aaip = false;
List<ContinuationArea> contareas = [];
List<byte[]> refareas = [];
var suspInformation = new StringBuilder();
@@ -309,17 +309,17 @@ public sealed partial class ISO9660
if(saLen > 0 && rootOff + saOff + saLen <= rootDir.Length)
{
byte[] sa = new byte[saLen];
var sa = new byte[saLen];
Array.Copy(rootDir, rootOff + saOff, sa, 0, saLen);
saOff = 0;
while(saOff < saLen)
{
bool noneFound = true;
var noneFound = true;
if(Marshal.SizeOf<CdromXa>() + saOff <= saLen)
{
CdromXa xa = Marshal.ByteArrayToStructureBigEndian<CdromXa>(sa);
CdromXa xa = Marshal.ByteArrayToStructureBigEndianGenerated<CdromXa>(sa);
if(xa.signature == XA_MAGIC)
{
@@ -331,7 +331,7 @@ public sealed partial class ISO9660
if(saOff + 2 >= saLen) break;
ushort nextSignature = BigEndianBitConverter.ToUInt16(sa, saOff);
var nextSignature = BigEndianBitConverter.ToUInt16(sa, saOff);
switch(nextSignature)
{
@@ -393,17 +393,17 @@ public sealed partial class ISO9660
break;
case SUSP_CONTINUATION when saOff + sa[saOff + 2] <= saLen:
byte[] ce = new byte[sa[saOff + 2]];
var ce = new byte[sa[saOff + 2]];
Array.Copy(sa, saOff, ce, 0, ce.Length);
ContinuationArea ca =
Marshal.ByteArrayToStructureBigEndian<ContinuationArea>(ce);
Marshal.ByteArrayToStructureBigEndianGenerated<ContinuationArea>(ce);
contareas.Add(ca);
break;
case SUSP_REFERENCE when saOff + sa[saOff + 2] <= saLen:
byte[] er = new byte[sa[saOff + 2]];
var er = new byte[sa[saOff + 2]];
Array.Copy(sa, saOff, er, 0, er.Length);
refareas.Add(er);
@@ -458,13 +458,13 @@ public sealed partial class ISO9660
if(errno != ErrorNumber.NoError) return;
byte[] caData = new byte[ca.ca_length_be];
var caData = new byte[ca.ca_length_be];
Array.Copy(caSectors, ca.offset_be, caData, 0, ca.ca_length_be);
int caOff = 0;
var caOff = 0;
while(caOff < ca.ca_length_be)
{
ushort nextSignature = BigEndianBitConverter.ToUInt16(caData, caOff);
var nextSignature = BigEndianBitConverter.ToUInt16(caData, caOff);
switch(nextSignature)
{
@@ -477,7 +477,7 @@ public sealed partial class ISO9660
break;
case SUSP_REFERENCE when caOff + caData[caOff + 2] <= ca.ca_length_be:
byte[] er = new byte[caData[caOff + 2]];
var er = new byte[caData[caOff + 2]];
Array.Copy(caData, caOff, er, 0, er.Length);
refareas.Add(er);
@@ -515,7 +515,7 @@ public sealed partial class ISO9660
foreach(byte[] erb in refareas)
{
ReferenceArea er = Marshal.ByteArrayToStructureBigEndian<ReferenceArea>(erb);
ReferenceArea er = Marshal.ByteArrayToStructureBigEndianGenerated<ReferenceArea>(erb);
string extId = encoding.GetString(erb, Marshal.SizeOf<ReferenceArea>(), er.id_len);
string extDes = encoding.GetString(erb, Marshal.SizeOf<ReferenceArea>() + er.id_len, er.des_len);
@@ -684,7 +684,7 @@ public sealed partial class ISO9660
if(errno != ErrorNumber.NoError) return;
int toritoOff = 0;
var toritoOff = 0;
if(vdSector[toritoOff] != 1) goto exit_torito;
@@ -806,7 +806,7 @@ public sealed partial class ISO9660
isoMetadata.AppendFormat("\t" + Localization.Section_ID_0, encoding.GetString(sectionHeader.identifier))
.AppendLine();
for(int entryCounter = 1;
for(var entryCounter = 1;
entryCounter <= sectionHeader.entries && toritoOff < vdSector.Length;
entryCounter++)
{

View File

@@ -43,7 +43,7 @@ public sealed partial class ISO9660
var off = 0;
PathTableEntry entry =
Marshal.ByteArrayToStructureBigEndian<PathTableEntry>(data, off, Marshal.SizeOf<PathTableEntry>());
Marshal.ByteArrayToStructureBigEndianGenerated<PathTableEntry>(data, off, Marshal.SizeOf<PathTableEntry>());
if(entry.name_len != 1 ||
entry.parent_dirno != 1 ||
@@ -53,7 +53,9 @@ public sealed partial class ISO9660
while(off < data.Length)
{
entry = Marshal.ByteArrayToStructureBigEndian<PathTableEntry>(data, off, Marshal.SizeOf<PathTableEntry>());
entry = Marshal.ByteArrayToStructureBigEndianGenerated<PathTableEntry>(data,
off,
Marshal.SizeOf<PathTableEntry>());
if(entry.name_len == 0) break;
@@ -88,11 +90,9 @@ public sealed partial class ISO9660
while(off < data.Length)
{
HighSierraPathTableEntry entry =
Marshal.ByteArrayToStructureBigEndian<HighSierraPathTableEntry>(data,
off,
Marshal
.SizeOf<
HighSierraPathTableEntry>());
Marshal.ByteArrayToStructureBigEndianGenerated<HighSierraPathTableEntry>(data,
off,
Marshal.SizeOf<HighSierraPathTableEntry>());
if(entry.name_len == 0) break;

View File

@@ -28,6 +28,7 @@
// ****************************************************************************/
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
namespace Aaru.Filesystems;
@@ -36,12 +37,13 @@ public sealed partial class ISO9660
#region Nested type: AmigaEntry
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct AmigaEntry
[SwapEndian]
partial struct AmigaEntry
{
public readonly ushort signature;
public readonly byte length;
public readonly byte version;
public readonly AmigaFlags flags;
public ushort signature;
public byte length;
public byte version;
public AmigaFlags flags;
// Followed by AmigaProtection if present
// Followed by length-prefixed string for comment if present
@@ -52,12 +54,13 @@ public sealed partial class ISO9660
#region Nested type: AmigaProtection
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct AmigaProtection
[SwapEndian]
partial struct AmigaProtection
{
public readonly byte User;
public readonly byte Reserved;
public readonly AmigaMultiuser Multiuser;
public readonly AmigaAttributes Protection;
public byte User;
public byte Reserved;
public AmigaMultiuser Multiuser;
public AmigaAttributes Protection;
}
#endregion

View File

@@ -28,6 +28,7 @@
// ****************************************************************************/
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
namespace Aaru.Filesystems;
@@ -37,14 +38,15 @@ public sealed partial class ISO9660
// Big-endian
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct AppleHFSIconSystemUse
[SwapEndian]
partial struct AppleHFSIconSystemUse
{
public readonly ushort signature;
public readonly AppleOldId id;
public readonly uint type;
public readonly uint creator;
public ushort signature;
public AppleOldId id;
public uint type;
public uint creator;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public readonly byte[] icon;
public byte[] icon;
}
#endregion
@@ -53,13 +55,14 @@ public sealed partial class ISO9660
// Big-endian
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct AppleHFSOldSystemUse
[SwapEndian]
partial struct AppleHFSOldSystemUse
{
public readonly ushort signature;
public readonly AppleOldId id;
public readonly uint type;
public readonly uint creator;
public readonly ushort finder_flags;
public ushort signature;
public AppleOldId id;
public uint type;
public uint creator;
public ushort finder_flags;
}
#endregion
@@ -68,14 +71,15 @@ public sealed partial class ISO9660
// Big-endian
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct AppleHFSSystemUse
[SwapEndian]
partial struct AppleHFSSystemUse
{
public readonly ushort signature;
public readonly byte length;
public readonly AppleId id;
public readonly uint type;
public readonly uint creator;
public readonly AppleCommon.FinderFlags finder_flags;
public ushort signature;
public byte length;
public AppleId id;
public uint type;
public uint creator;
public AppleCommon.FinderFlags finder_flags;
}
#endregion
@@ -84,12 +88,13 @@ public sealed partial class ISO9660
// Big-endian
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct AppleHFSTypeCreatorSystemUse
[SwapEndian]
partial struct AppleHFSTypeCreatorSystemUse
{
public readonly ushort signature;
public readonly AppleOldId id;
public readonly uint type;
public readonly uint creator;
public ushort signature;
public AppleOldId id;
public uint type;
public uint creator;
}
#endregion

View File

@@ -33,6 +33,7 @@
using System;
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
using Aaru.Helpers;
namespace Aaru.Filesystems;
@@ -89,21 +90,22 @@ public sealed partial class ISO9660
#region Nested type: CdiDirectoryRecord
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct CdiDirectoryRecord
[SwapEndian]
partial struct CdiDirectoryRecord
{
public readonly byte length;
public readonly byte xattr_len;
public readonly uint reserved1;
public readonly uint start_lbn;
public readonly uint reserved2;
public readonly uint size;
public readonly HighSierraTimestamp date;
public readonly byte reserved3;
public readonly CdiFileFlags flags;
public readonly ushort file_unit_size;
public readonly ushort reserved4;
public readonly ushort volume_sequence_number;
public readonly byte name_len;
public byte length;
public byte xattr_len;
public uint reserved1;
public uint start_lbn;
public uint reserved2;
public uint size;
public HighSierraTimestamp date;
public byte reserved3;
public CdiFileFlags flags;
public ushort file_unit_size;
public ushort reserved4;
public ushort volume_sequence_number;
public byte name_len;
// Followed by name[name_len] and then CdiSystemArea until length arrives
}
@@ -114,14 +116,15 @@ public sealed partial class ISO9660
// Follows filename on directory record
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct CdiSystemArea
[SwapEndian]
partial struct CdiSystemArea
{
public readonly ushort group;
public readonly ushort owner;
public readonly CdiAttributes attributes;
public readonly ushort reserved1;
public readonly byte file_no;
public readonly byte reserved2;
public ushort group;
public ushort owner;
public CdiAttributes attributes;
public ushort reserved1;
public byte file_no;
public byte reserved2;
}
#endregion
@@ -129,74 +132,75 @@ public sealed partial class ISO9660
#region Nested type: FileStructureVolumeDescriptor
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct FileStructureVolumeDescriptor
[SwapEndian]
partial struct FileStructureVolumeDescriptor
{
public readonly byte type;
public byte type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public readonly byte[] id;
public readonly byte version;
public readonly CdiVolumeFlags flags;
public byte[] id;
public byte version;
public CdiVolumeFlags flags;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public readonly byte[] system_id;
public byte[] system_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public readonly byte[] volume_id;
public byte[] volume_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public readonly byte[] reserved1;
public readonly uint volume_space_size;
public byte[] reserved1;
public uint volume_space_size;
// Only used in SVDs
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public readonly byte[] escape_sequences;
public readonly ushort reserved2;
public readonly ushort volume_set_size;
public readonly ushort reserved3;
public readonly ushort volume_sequence_number;
public readonly ushort reserved4;
public readonly ushort logical_block_size;
public readonly uint reserved5;
public readonly uint path_table_size;
public readonly ulong reserved6;
public readonly uint path_table_addr;
public byte[] escape_sequences;
public ushort reserved2;
public ushort volume_set_size;
public ushort reserved3;
public ushort volume_sequence_number;
public ushort reserved4;
public ushort logical_block_size;
public uint reserved5;
public uint path_table_size;
public ulong reserved6;
public uint path_table_addr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 38)]
public readonly byte[] reserved7;
public byte[] reserved7;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public readonly byte[] volume_set_id;
public byte[] volume_set_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public readonly byte[] publisher_id;
public byte[] publisher_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public readonly byte[] preparer_id;
public byte[] preparer_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public readonly byte[] application_id;
public byte[] application_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public readonly byte[] copyright_file_id;
public byte[] copyright_file_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public readonly byte[] reserved8;
public byte[] reserved8;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public readonly byte[] abstract_file_id;
public byte[] abstract_file_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public readonly byte[] reserved9;
public byte[] reserved9;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public readonly byte[] bibliographic_file_id;
public byte[] bibliographic_file_id;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public readonly byte[] reserved10;
public byte[] reserved10;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] creation_date;
public readonly byte reserved11;
public byte[] creation_date;
public byte reserved11;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] modification_date;
public readonly byte reserved12;
public byte[] modification_date;
public byte reserved12;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] expiration_date;
public readonly byte reserved13;
public byte[] expiration_date;
public byte reserved13;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] effective_date;
public readonly byte reserved14;
public readonly byte file_structure_version;
public readonly byte reserved15;
public byte[] effective_date;
public byte reserved14;
public byte file_structure_version;
public byte reserved15;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public readonly byte[] application_data;
public byte[] application_data;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 653)]
public readonly byte[] reserved16;
public byte[] reserved16;
}
#endregion

View File

@@ -30,6 +30,7 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using Aaru.CommonTypes.Attributes;
using Aaru.Helpers;
namespace Aaru.Filesystems;
@@ -112,12 +113,13 @@ public sealed partial class ISO9660
// There are two tables one in little endian one in big endian
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct HighSierraPathTableEntry
[SwapEndian]
partial struct HighSierraPathTableEntry
{
public readonly uint start_lbn;
public readonly byte xattr_len;
public readonly byte name_len;
public readonly ushort parent_dirno;
public uint start_lbn;
public byte xattr_len;
public byte name_len;
public ushort parent_dirno;
// Followed by name[name_len]
}
@@ -198,14 +200,15 @@ public sealed partial class ISO9660
#region Nested type: HighSierraTimestamp
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct HighSierraTimestamp
[SwapEndian]
partial struct HighSierraTimestamp
{
public readonly byte Years;
public readonly byte Month;
public readonly byte Day;
public readonly byte Hour;
public readonly byte Minute;
public readonly byte Second;
public byte Years;
public byte Month;
public byte Day;
public byte Hour;
public byte Minute;
public byte Second;
}
#endregion

View File

@@ -32,6 +32,7 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using Aaru.CommonTypes.Attributes;
using Aaru.Helpers;
namespace Aaru.Filesystems;
@@ -210,12 +211,13 @@ public sealed partial class ISO9660
// There are two tables one in little endian one in big endian
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct PathTableEntry
[SwapEndian]
partial struct PathTableEntry
{
public readonly byte name_len;
public readonly byte xattr_len;
public readonly uint start_lbn;
public readonly ushort parent_dirno;
public byte name_len;
public byte xattr_len;
public uint start_lbn;
public ushort parent_dirno;
// Followed by name[name_len]
}

View File

@@ -30,6 +30,7 @@
// ReSharper disable UnusedType.Local
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
namespace Aaru.Filesystems;
@@ -38,17 +39,18 @@ public sealed partial class ISO9660
#region Nested type: ContinuationArea
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct ContinuationArea
[SwapEndian]
partial struct ContinuationArea
{
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;
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;
}
#endregion
@@ -82,15 +84,16 @@ public sealed partial class ISO9660
#region Nested type: ReferenceArea
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct ReferenceArea
[SwapEndian]
partial struct ReferenceArea
{
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;
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;
// Follows extension identifier for id_len bytes
// Follows extension descriptor for des_len bytes

View File

@@ -32,6 +32,7 @@
// ****************************************************************************/
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
namespace Aaru.Filesystems;
@@ -41,15 +42,16 @@ public sealed partial class ISO9660
// Big-endian
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct CdromXa
[SwapEndian]
partial struct CdromXa
{
public readonly ushort group;
public readonly ushort user;
public readonly XaAttributes attributes;
public readonly ushort signature;
public readonly byte filenumber;
public ushort group;
public ushort user;
public XaAttributes attributes;
public ushort signature;
public byte filenumber;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public readonly byte[] reserved;
public byte[] reserved;
}
#endregion

View File

@@ -55,8 +55,8 @@ public sealed partial class ISO9660
Dictionary<string, string> options, string @namespace)
{
_encoding = encoding ?? Encoding.GetEncoding(1252);
byte[] vdMagic = new byte[5]; // Volume Descriptor magic "CD001"
byte[] hsMagic = new byte[5]; // Volume Descriptor magic "CDROM"
var vdMagic = new byte[5]; // Volume Descriptor magic "CD001"
var hsMagic = new byte[5]; // Volume Descriptor magic "CDROM"
options ??= GetDefaultOptions();
@@ -120,7 +120,7 @@ public sealed partial class ISO9660
int xaOff = vdSector.Length == 2336 ? 8 : 0;
Array.Copy(vdSector, 0x009 + xaOff, hsMagic, 0, 5);
_highSierra = _encoding.GetString(hsMagic) == HIGH_SIERRA_MAGIC;
int hsOff = 0;
var hsOff = 0;
if(_highSierra) hsOff = 8;
@@ -182,7 +182,7 @@ public sealed partial class ISO9660
if(_highSierra)
hsvd = Marshal.ByteArrayToStructureLittleEndian<HighSierraPrimaryVolumeDescriptor>(vdSector);
else if(_cdi)
fsvd = Marshal.ByteArrayToStructureBigEndian<FileStructureVolumeDescriptor>(vdSector);
fsvd = Marshal.ByteArrayToStructureBigEndianGenerated<FileStructureVolumeDescriptor>(vdSector);
else
pvd = Marshal.ByteArrayToStructureLittleEndian<PrimaryVolumeDescriptor>(vdSector);
@@ -360,7 +360,7 @@ public sealed partial class ISO9660
if(errno != ErrorNumber.NoError) return errno;
bool pvdWrongRoot = false;
var pvdWrongRoot = false;
if(_highSierra)
{
@@ -382,7 +382,7 @@ public sealed partial class ISO9660
AaruLogging.Debug(MODULE_NAME,
Localization.PVD_does_not_point_to_correct_root_directory_checking_path_table);
bool pathTableWrongRoot = false;
var pathTableWrongRoot = false;
rootLocation = _pathTable[0].Extent;
@@ -422,7 +422,8 @@ public sealed partial class ISO9660
if(errno != ErrorNumber.NoError) return errno;
CdiDirectoryRecord rootEntry = Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(firstRootSector);
CdiDirectoryRecord rootEntry =
Marshal.ByteArrayToStructureBigEndianGenerated<CdiDirectoryRecord>(firstRootSector);
rootSize = rootEntry.size;
@@ -619,7 +620,7 @@ public sealed partial class ISO9660
Timestamp = decodedVd.CreationTime
});
for(int i = 0; i < bvdSectors.Count; i++)
for(var i = 0; i < bvdSectors.Count; i++)
{
_rootDirectoryCache.Add(i == 0 ? "$BOOT" : $"$BOOT_{i}",
new DecodedDirectoryEntry
@@ -631,7 +632,7 @@ public sealed partial class ISO9660
});
}
for(int i = 0; i < pvdSectors.Count; i++)
for(var i = 0; i < pvdSectors.Count; i++)
{
_rootDirectoryCache.Add(i == 0 ? "$PVD" : $"$PVD{i}",
new DecodedDirectoryEntry
@@ -643,7 +644,7 @@ public sealed partial class ISO9660
});
}
for(int i = 0; i < svdSectors.Count; i++)
for(var i = 0; i < svdSectors.Count; i++)
{
_rootDirectoryCache.Add(i == 0 ? "$SVD" : $"$SVD_{i}",
new DecodedDirectoryEntry
@@ -655,7 +656,7 @@ public sealed partial class ISO9660
});
}
for(int i = 0; i < evdSectors.Count; i++)
for(var i = 0; i < evdSectors.Count; i++)
{
_rootDirectoryCache.Add(i == 0 ? "$EVD" : $"$EVD_{i}",
new DecodedDirectoryEntry
@@ -667,7 +668,7 @@ public sealed partial class ISO9660
});
}
for(int i = 0; i < vpdSectors.Count; i++)
for(var i = 0; i < vpdSectors.Count; i++)
{
_rootDirectoryCache.Add(i == 0 ? "$VPD" : $"$VPD_{i}",
new DecodedDirectoryEntry
@@ -731,7 +732,7 @@ public sealed partial class ISO9660
Type = fsFormat
};
_directoryCache = new Dictionary<string, Dictionary<string, DecodedDirectoryEntry>>();
_directoryCache = [];
if(_usePathTable)
{