[Opera] Use new source generator based big endian marshaller

This commit is contained in:
2025-10-21 03:38:16 +01:00
parent aa940f19b5
commit 40c33a3dbb
4 changed files with 39 additions and 35 deletions

View File

@@ -171,7 +171,7 @@ public sealed partial class OperaFS
if(errno != ErrorNumber.NoError) break;
header = Marshal.ByteArrayToStructureBigEndian<DirectoryHeader>(data);
header = Marshal.ByteArrayToStructureBigEndianGenerated<DirectoryHeader>(data);
nextBlock = header.next_block + firstBlock;
var off = (int)header.first_used;
@@ -180,7 +180,7 @@ public sealed partial class OperaFS
while(off + _directoryEntrySize < data.Length)
{
entry = Marshal.ByteArrayToStructureBigEndian<DirectoryEntry>(data, off, _directoryEntrySize);
entry = Marshal.ByteArrayToStructureBigEndianGenerated<DirectoryEntry>(data, off, _directoryEntrySize);
string name = StringHandlers.CToString(entry.name, _encoding);
var entryWithPointers = new DirectoryEntryWithPointers

View File

@@ -74,7 +74,7 @@ public sealed partial class OperaFS
if(errno != ErrorNumber.NoError) return;
SuperBlock sb = Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sbSector);
SuperBlock sb = Marshal.ByteArrayToStructureBigEndianGenerated<SuperBlock>(sbSector);
if(sb.record_type != 1 || sb.record_version != 1) return;

View File

@@ -27,6 +27,7 @@
// ****************************************************************************/
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Filesystems;
@@ -36,29 +37,30 @@ public sealed partial class OperaFS
#region Nested type: DirectoryEntry
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct DirectoryEntry
[SwapEndian]
partial struct DirectoryEntry
{
/// <summary>File flags, see <see cref="FileFlags" /></summary>
public readonly uint flags;
public uint flags;
/// <summary>Unique file identifier</summary>
public readonly uint id;
public uint id;
/// <summary>Entry type</summary>
public readonly uint type;
public uint type;
/// <summary>Block size</summary>
public readonly uint block_size;
public uint block_size;
/// <summary>Size in bytes</summary>
public readonly uint byte_count;
public uint byte_count;
/// <summary>Block count</summary>
public readonly uint block_count;
public uint block_count;
/// <summary>Unknown</summary>
public readonly uint burst;
public uint burst;
/// <summary>Unknown</summary>
public readonly uint gap;
public uint gap;
/// <summary>Filename</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_NAME)]
public readonly byte[] name;
public byte[] name;
/// <summary>Last copy</summary>
public readonly uint last_copy;
public uint last_copy;
}
#endregion
@@ -76,18 +78,19 @@ public sealed partial class OperaFS
#region Nested type: DirectoryHeader
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct DirectoryHeader
[SwapEndian]
partial struct DirectoryHeader
{
/// <summary>Next block from this directory, -1 if last</summary>
public readonly int next_block;
public int next_block;
/// <summary>Previous block from this directory, -1 if first</summary>
public readonly int prev_block;
public int prev_block;
/// <summary>Directory flags</summary>
public readonly uint flags;
public uint flags;
/// <summary>Offset to first free unused byte in the directory</summary>
public readonly uint first_free;
public uint first_free;
/// <summary>Offset to first directory entry</summary>
public readonly uint first_used;
public uint first_used;
}
#endregion
@@ -134,37 +137,38 @@ public sealed partial class OperaFS
#region Nested type: SuperBlock
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct SuperBlock
[SwapEndian]
partial struct SuperBlock
{
/// <summary>0x000, Record type, must be 1</summary>
public readonly byte record_type;
public byte record_type;
/// <summary>0x001, 5 bytes, "ZZZZZ"</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public readonly byte[] sync_bytes;
public byte[] sync_bytes;
/// <summary>0x006, Record version, must be 1</summary>
public readonly byte record_version;
public byte record_version;
/// <summary>0x007, Volume flags</summary>
public readonly byte volume_flags;
public byte volume_flags;
/// <summary>0x008, 32 bytes, volume comment</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_NAME)]
public readonly byte[] volume_comment;
public byte[] volume_comment;
/// <summary>0x028, 32 bytes, volume label</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_NAME)]
public readonly byte[] volume_label;
public byte[] volume_label;
/// <summary>0x048, Volume ID</summary>
public readonly uint volume_id;
public uint volume_id;
/// <summary>0x04C, Block size in bytes</summary>
public readonly uint block_size;
public uint block_size;
/// <summary>0x050, Blocks in volume</summary>
public readonly uint block_count;
public uint block_count;
/// <summary>0x054, Root directory ID</summary>
public readonly uint root_dirid;
public uint root_dirid;
/// <summary>0x058, Root directory blocks</summary>
public readonly uint rootdir_blocks;
public uint rootdir_blocks;
/// <summary>0x05C, Root directory block size</summary>
public readonly uint rootdir_bsize;
public uint rootdir_bsize;
/// <summary>0x060, Last root directory copy</summary>
public readonly uint last_root_copy;
public uint last_root_copy;
}
#endregion

View File

@@ -57,7 +57,7 @@ public sealed partial class OperaFS
if(errno != ErrorNumber.NoError) return errno;
SuperBlock sb = Marshal.ByteArrayToStructureBigEndian<SuperBlock>(sbSector);
SuperBlock sb = Marshal.ByteArrayToStructureBigEndianGenerated<SuperBlock>(sbSector);
if(sb.record_type != 1 || sb.record_version != 1) return ErrorNumber.InvalidArgument;