From b7621c2f904e67c012d96460bca5dfcc8e23fca5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 21 Oct 2025 02:17:58 +0100 Subject: [PATCH] [AmigaDOS] Use new source generator based big endian marshaller --- Aaru.Filesystems/AmigaDOS/Helpers.cs | 2 +- Aaru.Filesystems/AmigaDOS/Info.cs | 12 +++--- Aaru.Filesystems/AmigaDOS/Structs.cs | 57 +++++++++++++++------------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/Aaru.Filesystems/AmigaDOS/Helpers.cs b/Aaru.Filesystems/AmigaDOS/Helpers.cs index afcb131e5..38ec1daf5 100644 --- a/Aaru.Filesystems/AmigaDOS/Helpers.cs +++ b/Aaru.Filesystems/AmigaDOS/Helpers.cs @@ -40,7 +40,7 @@ public sealed partial class AmigaDOSPlugin var tmp = new byte[228]; Array.Copy(block, 0, tmp, 0, 24); Array.Copy(block, block.Length - 200, tmp, 28, 200); - RootBlock root = Marshal.ByteArrayToStructureBigEndian(tmp); + RootBlock root = Marshal.ByteArrayToStructureBigEndianGenerated(tmp); root.hashTable = new uint[(block.Length - 224) / 4]; for(var i = 0; i < root.hashTable.Length; i++) diff --git a/Aaru.Filesystems/AmigaDOS/Info.cs b/Aaru.Filesystems/AmigaDOS/Info.cs index 553842d6f..5f65adb88 100644 --- a/Aaru.Filesystems/AmigaDOS/Info.cs +++ b/Aaru.Filesystems/AmigaDOS/Info.cs @@ -60,7 +60,7 @@ public sealed partial class AmigaDOSPlugin if(errno != ErrorNumber.NoError) return false; - BootBlock bblk = Marshal.ByteArrayToStructureBigEndian(sector); + BootBlock bblk = Marshal.ByteArrayToStructureBigEndianGenerated(sector); // AROS boot floppies... if(sector.Length >= 512 && @@ -73,7 +73,7 @@ public sealed partial class AmigaDOSPlugin if(errno != ErrorNumber.NoError) return false; - bblk = Marshal.ByteArrayToStructureBigEndian(sector); + bblk = Marshal.ByteArrayToStructureBigEndianGenerated(sector); } // Not FFS or MuFS? @@ -124,7 +124,7 @@ public sealed partial class AmigaDOSPlugin AaruLogging.Debug(MODULE_NAME, "rblk.hashTableSize = {0}", rblk.hashTableSize); uint blockSize = (rblk.hashTableSize + 56) * 4; - uint sectorsPerBlock = (uint)(blockSize / sector.Length); + var sectorsPerBlock = (uint)(blockSize / sector.Length); AaruLogging.Debug(MODULE_NAME, "blockSize = {0}", blockSize); AaruLogging.Debug(MODULE_NAME, "sectorsPerBlock = {0}", sectorsPerBlock); @@ -166,7 +166,7 @@ public sealed partial class AmigaDOSPlugin if(errno != ErrorNumber.NoError) return; - BootBlock bootBlk = Marshal.ByteArrayToStructureBigEndian(bootBlockSectors); + BootBlock bootBlk = Marshal.ByteArrayToStructureBigEndianGenerated(bootBlockSectors); bootBlk.bootCode = new byte[bootBlockSectors.Length - 12]; Array.Copy(bootBlockSectors, 12, bootBlk.bootCode, 0, bootBlk.bootCode.Length); bootBlockSectors[4] = bootBlockSectors[5] = bootBlockSectors[6] = bootBlockSectors[7] = 0; @@ -192,7 +192,7 @@ public sealed partial class AmigaDOSPlugin var rootBlk = new RootBlock(); byte[] rootBlockSector = null; - bool rootFound = false; + var rootFound = false; uint blockSize = 0; // So to handle even number of sectors @@ -214,7 +214,7 @@ public sealed partial class AmigaDOSPlugin AaruLogging.Debug(MODULE_NAME, "rootBlk.hashTableSize = {0}", rootBlk.hashTableSize); blockSize = (rootBlk.hashTableSize + 56) * 4; - uint sectorsPerBlock = (uint)(blockSize / rootBlockSector.Length); + var sectorsPerBlock = (uint)(blockSize / rootBlockSector.Length); AaruLogging.Debug(MODULE_NAME, "blockSize = {0}", blockSize); AaruLogging.Debug(MODULE_NAME, "sectorsPerBlock = {0}", sectorsPerBlock); diff --git a/Aaru.Filesystems/AmigaDOS/Structs.cs b/Aaru.Filesystems/AmigaDOS/Structs.cs index da26ead83..14d86c0ca 100644 --- a/Aaru.Filesystems/AmigaDOS/Structs.cs +++ b/Aaru.Filesystems/AmigaDOS/Structs.cs @@ -27,6 +27,7 @@ // ****************************************************************************/ using System.Runtime.InteropServices; +using Aaru.CommonTypes.Attributes; namespace Aaru.Filesystems; @@ -38,14 +39,15 @@ public sealed partial class AmigaDOSPlugin /// Boot block, first 2 sectors [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct BootBlock + [SwapEndian] + partial struct BootBlock { /// Offset 0x00, "DOSx" disk type - public readonly uint diskType; + public uint diskType; /// Offset 0x04, Checksum - public readonly uint checksum; + public uint checksum; /// Offset 0x08, Pointer to root block, mostly invalid - public readonly uint root_ptr; + public uint root_ptr; /// Offset 0x0C, Boot code, til completion. Size is intentionally incorrect to allow marshaling to work. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] bootCode; @@ -56,18 +58,19 @@ public sealed partial class AmigaDOSPlugin #region Nested type: RootBlock [StructLayout(LayoutKind.Sequential, Pack = 1)] - struct RootBlock + [SwapEndian] + partial struct RootBlock { /// Offset 0x00, block type, value = T_HEADER (2) public uint type; /// Offset 0x04, unused - public readonly uint headerKey; + public uint headerKey; /// Offset 0x08, unused - public readonly uint highSeq; + public uint highSeq; /// Offset 0x0C, longs used by hash table public uint hashTableSize; /// Offset 0x10, unused - public readonly uint firstData; + public uint firstData; /// Offset 0x14, Rootblock checksum public uint checksum; /// @@ -77,45 +80,45 @@ public sealed partial class AmigaDOSPlugin [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public uint[] hashTable; /// Offset 0x18+hashTableSize*4+0, bitmap flag, 0xFFFFFFFF if valid - public readonly uint bitmapFlag; + public uint bitmapFlag; /// Offset 0x18+hashTableSize*4+4, bitmap pages, 25 entries [MarshalAs(UnmanagedType.ByValArray, SizeConst = 25)] - public readonly uint[] bitmapPages; + public uint[] bitmapPages; /// Offset 0x18+hashTableSize*4+104, pointer to bitmap extension block - public readonly uint bitmapExtensionBlock; + public uint bitmapExtensionBlock; /// Offset 0x18+hashTableSize*4+108, last root alteration days since 1978/01/01 - public readonly uint rDays; + public uint rDays; /// Offset 0x18+hashTableSize*4+112, last root alteration minutes past midnight - public readonly uint rMins; + public uint rMins; /// Offset 0x18+hashTableSize*4+116, last root alteration ticks (1/50 secs) - public readonly uint rTicks; + public uint rTicks; /// Offset 0x18+hashTableSize*4+120, disk name, pascal string, 31 bytes [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)] - public readonly byte[] diskName; + public byte[] diskName; /// Offset 0x18+hashTableSize*4+151, unused - public readonly byte padding; + public byte padding; /// Offset 0x18+hashTableSize*4+152, unused - public readonly uint reserved1; + public uint reserved1; /// Offset 0x18+hashTableSize*4+156, unused - public readonly uint reserved2; + public uint reserved2; /// Offset 0x18+hashTableSize*4+160, last disk alteration days since 1978/01/01 - public readonly uint vDays; + public uint vDays; /// Offset 0x18+hashTableSize*4+164, last disk alteration minutes past midnight - public readonly uint vMins; + public uint vMins; /// Offset 0x18+hashTableSize*4+168, last disk alteration ticks (1/50 secs) - public readonly uint vTicks; + public uint vTicks; /// Offset 0x18+hashTableSize*4+172, filesystem creation days since 1978/01/01 - public readonly uint cDays; + public uint cDays; /// Offset 0x18+hashTableSize*4+176, filesystem creation minutes since 1978/01/01 - public readonly uint cMins; + public uint cMins; /// Offset 0x18+hashTableSize*4+180, filesystem creation ticks since 1978/01/01 - public readonly uint cTicks; + public uint cTicks; /// Offset 0x18+hashTableSize*4+184, unused - public readonly uint nextHash; + public uint nextHash; /// Offset 0x18+hashTableSize*4+188, unused - public readonly uint parentDir; + public uint parentDir; /// Offset 0x18+hashTableSize*4+192, first directory cache block - public readonly uint extension; + public uint extension; /// Offset 0x18+hashTableSize*4+196, block secondary type = ST_ROOT (1) public uint sec_type; }