[SGI VH] Use new source generator based big endian marshaller

This commit is contained in:
2025-10-21 11:21:38 +01:00
parent 432c1663fb
commit d2cffa661d
3 changed files with 185 additions and 194 deletions

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers; using Aaru.Helpers;
@@ -48,7 +49,7 @@ namespace Aaru.Partitions;
/// <inheritdoc /> /// <inheritdoc />
/// <summary>Implements decoding of the SGI Disk Volume Header</summary> /// <summary>Implements decoding of the SGI Disk Volume Header</summary>
[SuppressMessage("ReSharper", "InconsistentNaming")] [SuppressMessage("ReSharper", "InconsistentNaming")]
public sealed class SGI : IPartition public sealed partial class SGI : IPartition
{ {
const int SGI_MAGIC = 0x0BE5A941; const int SGI_MAGIC = 0x0BE5A941;
const string MODULE_NAME = "SGI Volume Header plugin"; const string MODULE_NAME = "SGI Volume Header plugin";
@@ -73,18 +74,15 @@ public sealed class SGI : IPartition
if(errno != ErrorNumber.NoError || sector.Length < 512) return false; if(errno != ErrorNumber.NoError || sector.Length < 512) return false;
Label dvh = Marshal.ByteArrayToStructureBigEndian<Label>(sector); Label dvh = Marshal.ByteArrayToStructureBigEndianGenerated<Label>(sector);
for(int i = 0; i < dvh.volume.Length; i++) for(var i = 0; i < dvh.volume.Length; i++)
dvh.volume[i] = (Volume)Marshal.SwapStructureMembersEndian(dvh.volume[i]); dvh.volume[i] = (Volume)Marshal.SwapStructureMembersEndian(dvh.volume[i]);
for(int i = 0; i < dvh.partitions.Length; i++) for(var i = 0; i < dvh.partitions.Length; i++)
dvh.partitions[i] = (Partition)Marshal.SwapStructureMembersEndian(dvh.partitions[i]); dvh.partitions[i] = (Partition)Marshal.SwapStructureMembersEndian(dvh.partitions[i]);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, Localization.dvh_magic_equals_0_X8_should_be_1_X8, dvh.magic, SGI_MAGIC);
Localization.dvh_magic_equals_0_X8_should_be_1_X8,
dvh.magic,
SGI_MAGIC);
if(dvh.magic != SGI_MAGIC) return false; if(dvh.magic != SGI_MAGIC) return false;
@@ -97,9 +95,7 @@ public sealed class SGI : IPartition
AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_gap1 = {0}", dvh.device_params.dp_gap1); AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_gap1 = {0}", dvh.device_params.dp_gap1);
AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_gap2 = {0}", dvh.device_params.dp_gap2); AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_gap2 = {0}", dvh.device_params.dp_gap2);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_spares_cyl = {0}", dvh.device_params.dp_spares_cyl);
"dvh.device_params.dp_spares_cyl = {0}",
dvh.device_params.dp_spares_cyl);
AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_cyls = {0}", dvh.device_params.dp_cyls); AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_cyls = {0}", dvh.device_params.dp_cyls);
AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_shd0 = {0}", dvh.device_params.dp_shd0); AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_shd0 = {0}", dvh.device_params.dp_shd0);
@@ -113,9 +109,7 @@ public sealed class SGI : IPartition
AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_secbytes = {0}", dvh.device_params.dp_secbytes); AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_secbytes = {0}", dvh.device_params.dp_secbytes);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_interleave = {0}", dvh.device_params.dp_interleave);
"dvh.device_params.dp_interleave = {0}",
dvh.device_params.dp_interleave);
AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_flags = {0}", dvh.device_params.dp_flags); AaruLogging.Debug(MODULE_NAME, "dvh.device_params.dp_flags = {0}", dvh.device_params.dp_flags);
@@ -135,17 +129,11 @@ public sealed class SGI : IPartition
ulong counter = 0; ulong counter = 0;
for(int i = 0; i < dvh.partitions.Length; i++) for(var i = 0; i < dvh.partitions.Length; i++)
{ {
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "dvh.partitions[{0}].num_blocks = {1}", i, dvh.partitions[i].num_blocks);
"dvh.partitions[{0}].num_blocks = {1}",
i,
dvh.partitions[i].num_blocks);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "dvh.partitions[{0}].first_block = {1}", i, dvh.partitions[i].first_block);
"dvh.partitions[{0}].first_block = {1}",
i,
dvh.partitions[i].first_block);
AaruLogging.Debug(MODULE_NAME, "dvh.partitions[{0}].type = {1}", i, dvh.partitions[i].type); AaruLogging.Debug(MODULE_NAME, "dvh.partitions[{0}].type = {1}", i, dvh.partitions[i].type);
@@ -195,7 +183,9 @@ public sealed class SGI : IPartition
#region Nested type: DeviceParameters #region Nested type: DeviceParameters
struct DeviceParameters [StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct DeviceParameters
{ {
public byte dp_skew; public byte dp_skew;
public byte dp_gap1; public byte dp_gap1;
@@ -227,20 +217,21 @@ public sealed class SGI : IPartition
#region Nested type: Label #region Nested type: Label
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct Label [SwapEndian]
partial struct Label
{ {
public readonly uint magic; public uint magic;
public readonly short root_part_num; public short root_part_num;
public readonly short swap_part_num; public short swap_part_num;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] boot_file; public byte[] boot_file;
public readonly DeviceParameters device_params; public DeviceParameters device_params;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
public readonly Volume[] volume; public Volume[] volume;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly Partition[] partitions; public Partition[] partitions;
public readonly uint csum; public uint csum;
public readonly uint padding; public uint padding;
} }
#endregion #endregion
@@ -248,11 +239,12 @@ public sealed class SGI : IPartition
#region Nested type: Partition #region Nested type: Partition
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Partition [SwapEndian]
partial struct Partition
{ {
public readonly uint num_blocks; public uint num_blocks;
public readonly uint first_block; public uint first_block;
public readonly SGIType type; public SGIType type;
} }
#endregion #endregion
@@ -285,12 +277,13 @@ public sealed class SGI : IPartition
#region Nested type: Volume #region Nested type: Volume
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct Volume [SwapEndian]
partial struct Volume
{ {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public readonly byte[] name; public byte[] name;
public readonly uint block_num; public uint block_num;
public readonly uint num_bytes; public uint num_bytes;
} }
#endregion #endregion

View File

@@ -36,6 +36,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Attributes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers; using Aaru.Helpers;
@@ -47,7 +48,7 @@ namespace Aaru.Partitions;
/// <inheritdoc /> /// <inheritdoc />
/// <summary>Implements decoding of UNIX VTOC partitions</summary> /// <summary>Implements decoding of UNIX VTOC partitions</summary>
[SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedMember.Local")]
public sealed class VTOC : IPartition public sealed partial class VTOC : IPartition
{ {
const uint PD_MAGIC = 0xCA5E600D; const uint PD_MAGIC = 0xCA5E600D;
const uint VTOC_SANE = 0x600DDEEE; const uint VTOC_SANE = 0x600DDEEE;
@@ -76,8 +77,8 @@ public sealed class VTOC : IPartition
uint magic = 0; uint magic = 0;
ulong pdloc = 0; ulong pdloc = 0;
byte[] pdsector = null; byte[] pdsector = null;
bool magicFound = false; var magicFound = false;
bool absolute = false; var absolute = false;
ErrorNumber errno; ErrorNumber errno;
foreach(ulong i in new ulong[] foreach(ulong i in new ulong[]
@@ -118,8 +119,8 @@ public sealed class VTOC : IPartition
} }
else else
{ {
pd = Marshal.ByteArrayToStructureBigEndian<PDInfo>(pdsector); pd = Marshal.ByteArrayToStructureBigEndianGenerated<PDInfo>(pdsector);
pdold = Marshal.ByteArrayToStructureBigEndian<PDInfoOld>(pdsector); pdold = Marshal.ByteArrayToStructureBigEndianGenerated<PDInfoOld>(pdsector);
} }
AaruLogging.Debug(MODULE_NAME, "pdinfo.driveid = {0}", pd.driveid); AaruLogging.Debug(MODULE_NAME, "pdinfo.driveid = {0}", pd.driveid);
@@ -167,7 +168,7 @@ public sealed class VTOC : IPartition
AaruLogging.Debug(MODULE_NAME, "pdinfo.pad[7] = {0}", pd.pad[7]); AaruLogging.Debug(MODULE_NAME, "pdinfo.pad[7] = {0}", pd.pad[7]);
magicFound = false; magicFound = false;
bool useOld = false; var useOld = false;
errno = imagePlugin.ReadSector(pdloc + sectorOffset + 1, out byte[] vtocsector); errno = imagePlugin.ReadSector(pdloc + sectorOffset + 1, out byte[] vtocsector);
if(errno != ErrorNumber.NoError) return false; if(errno != ErrorNumber.NoError) return false;
@@ -185,9 +186,9 @@ public sealed class VTOC : IPartition
vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocsector); vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocsector);
else else
{ {
vtoc = Marshal.ByteArrayToStructureBigEndian<Vtoc>(vtocsector); vtoc = Marshal.ByteArrayToStructureBigEndianGenerated<Vtoc>(vtocsector);
for(int i = 0; i < vtoc.v_part.Length; i++) for(var i = 0; i < vtoc.v_part.Length; i++)
{ {
vtoc.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtoc.v_part[i].p_tag); vtoc.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtoc.v_part[i].p_tag);
vtoc.v_part[i].p_flag = (pFlag)Swapping.Swap((ushort)vtoc.v_part[i].p_flag); vtoc.v_part[i].p_flag = (pFlag)Swapping.Swap((ushort)vtoc.v_part[i].p_flag);
@@ -212,9 +213,9 @@ public sealed class VTOC : IPartition
vtocOld = Marshal.ByteArrayToStructureLittleEndian<VTocOld>(vtocsector); vtocOld = Marshal.ByteArrayToStructureLittleEndian<VTocOld>(vtocsector);
else else
{ {
vtocOld = Marshal.ByteArrayToStructureBigEndian<VTocOld>(vtocsector); vtocOld = Marshal.ByteArrayToStructureBigEndianGenerated<VTocOld>(vtocsector);
for(int i = 0; i < vtocOld.v_part.Length; i++) for(var i = 0; i < vtocOld.v_part.Length; i++)
{ {
vtocOld.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtocOld.v_part[i].p_tag); vtocOld.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtocOld.v_part[i].p_tag);
vtocOld.v_part[i].p_flag = (pFlag)Swapping.Swap((ushort)vtocOld.v_part[i].p_flag); vtocOld.v_part[i].p_flag = (pFlag)Swapping.Swap((ushort)vtocOld.v_part[i].p_flag);
@@ -265,9 +266,9 @@ public sealed class VTOC : IPartition
vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocsector); vtoc = Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocsector);
else else
{ {
vtoc = Marshal.ByteArrayToStructureBigEndian<Vtoc>(vtocsector); vtoc = Marshal.ByteArrayToStructureBigEndianGenerated<Vtoc>(vtocsector);
for(int i = 0; i < vtoc.v_part.Length; i++) for(var i = 0; i < vtoc.v_part.Length; i++)
{ {
vtoc.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtoc.v_part[i].p_tag); vtoc.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtoc.v_part[i].p_tag);
vtoc.v_part[i].p_flag = (pFlag)Swapping.Swap((ushort)vtoc.v_part[i].p_flag); vtoc.v_part[i].p_flag = (pFlag)Swapping.Swap((ushort)vtoc.v_part[i].p_flag);
@@ -295,14 +296,12 @@ public sealed class VTOC : IPartition
AaruLogging.Debug(MODULE_NAME, "vtocOld.v_version = {0}", vtocOld.v_version); AaruLogging.Debug(MODULE_NAME, "vtocOld.v_version = {0}", vtocOld.v_version);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "vtocOld.v_volume = \"{0}\"", StringHandlers.CToString(vtocOld.v_volume));
"vtocOld.v_volume = \"{0}\"",
StringHandlers.CToString(vtocOld.v_volume));
AaruLogging.Debug(MODULE_NAME, "vtocOld.v_sectorsz = {0}", vtocOld.v_sectorsz); AaruLogging.Debug(MODULE_NAME, "vtocOld.v_sectorsz = {0}", vtocOld.v_sectorsz);
AaruLogging.Debug(MODULE_NAME, "vtocOld.v_nparts = {0}", vtocOld.v_nparts); AaruLogging.Debug(MODULE_NAME, "vtocOld.v_nparts = {0}", vtocOld.v_nparts);
for(int i = 0; i < V_NUMPAR; i++) for(var i = 0; i < V_NUMPAR; i++)
{ {
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME,
"vtocOld.v_part[{0}].p_tag = {1} ({2})", "vtocOld.v_part[{0}].p_tag = {1} ({2})",
@@ -316,15 +315,9 @@ public sealed class VTOC : IPartition
vtocOld.v_part[i].p_flag, vtocOld.v_part[i].p_flag,
(ushort)vtocOld.v_part[i].p_flag); (ushort)vtocOld.v_part[i].p_flag);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "vtocOld.v_part[{0}].p_start = {1}", i, vtocOld.v_part[i].p_start);
"vtocOld.v_part[{0}].p_start = {1}",
i,
vtocOld.v_part[i].p_start);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "vtocOld.v_part[{0}].p_size = {1}", i, vtocOld.v_part[i].p_size);
"vtocOld.v_part[{0}].p_size = {1}",
i,
vtocOld.v_part[i].p_size);
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME,
"vtocOld.timestamp[{0}] = {1}", "vtocOld.timestamp[{0}] = {1}",
@@ -334,10 +327,7 @@ public sealed class VTOC : IPartition
} }
else else
{ {
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME, "vtoc.v_sanity = 0x{0:X8} (should be 0x{1:X8})", vtoc.v_sanity, VTOC_SANE);
"vtoc.v_sanity = 0x{0:X8} (should be 0x{1:X8})",
vtoc.v_sanity,
VTOC_SANE);
AaruLogging.Debug(MODULE_NAME, "vtoc.v_version = {0}", vtoc.v_version); AaruLogging.Debug(MODULE_NAME, "vtoc.v_version = {0}", vtoc.v_version);
@@ -346,7 +336,7 @@ public sealed class VTOC : IPartition
AaruLogging.Debug(MODULE_NAME, "vtoc.v_pad = {0}", vtoc.v_pad); AaruLogging.Debug(MODULE_NAME, "vtoc.v_pad = {0}", vtoc.v_pad);
AaruLogging.Debug(MODULE_NAME, "vtoc.v_nparts = {0}", vtoc.v_nparts); AaruLogging.Debug(MODULE_NAME, "vtoc.v_nparts = {0}", vtoc.v_nparts);
for(int i = 0; i < V_NUMPAR; i++) for(var i = 0; i < V_NUMPAR; i++)
{ {
AaruLogging.Debug(MODULE_NAME, AaruLogging.Debug(MODULE_NAME,
"vtoc.v_part[{0}].p_tag = {1} ({2})", "vtoc.v_part[{0}].p_tag = {1} ({2})",
@@ -390,7 +380,7 @@ public sealed class VTOC : IPartition
// Check for a partition describing the VTOC whose start is the same as the start we know. // Check for a partition describing the VTOC whose start is the same as the start we know.
// This means partition starts are absolute, not relative, to the VTOC position // This means partition starts are absolute, not relative, to the VTOC position
for(int i = 0; i < V_NUMPAR; i++) for(var i = 0; i < V_NUMPAR; i++)
{ {
if(parts[i].p_tag != pTag.V_BACKUP || (ulong)parts[i].p_start != sectorOffset) continue; if(parts[i].p_tag != pTag.V_BACKUP || (ulong)parts[i].p_start != sectorOffset) continue;
@@ -399,7 +389,7 @@ public sealed class VTOC : IPartition
break; break;
} }
for(int i = 0; i < V_NUMPAR; i++) for(var i = 0; i < V_NUMPAR; i++)
{ {
if(parts[i].p_tag == pTag.V_UNUSED) continue; if(parts[i].p_tag == pTag.V_UNUSED) continue;
@@ -414,7 +404,7 @@ public sealed class VTOC : IPartition
Scheme = Name Scheme = Name
}; };
string info = ""; var info = "";
// Apparently old ones are absolute :? // Apparently old ones are absolute :?
if(!useOld && !absolute) if(!useOld && !absolute)
@@ -479,47 +469,48 @@ public sealed class VTOC : IPartition
#region Nested type: PDInfo #region Nested type: PDInfo
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
struct PDInfo partial struct PDInfo
{ {
public readonly uint driveid; /*identifies the device type*/ public uint driveid; /*identifies the device type*/
public readonly uint sanity; /*verifies device sanity*/ public uint sanity; /*verifies device sanity*/
public readonly uint version; /*version number*/ public uint version; /*version number*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public readonly byte[] serial; /*serial number of the device*/ public byte[] serial; /*serial number of the device*/
public readonly uint cyls; /*number of cylinders per drive*/ public uint cyls; /*number of cylinders per drive*/
public readonly uint tracks; /*number tracks per cylinder*/ public uint tracks; /*number tracks per cylinder*/
public readonly uint sectors; /*number sectors per track*/ public uint sectors; /*number sectors per track*/
public readonly uint bytes; /*number of bytes per sector*/ public uint bytes; /*number of bytes per sector*/
public readonly uint logicalst; /*sector address of logical sector 0*/ public uint logicalst; /*sector address of logical sector 0*/
public readonly uint errlogst; /*sector address of error log area*/ public uint errlogst; /*sector address of error log area*/
public readonly uint errlogsz; /*size in bytes of error log area*/ public uint errlogsz; /*size in bytes of error log area*/
public readonly uint mfgst; /*sector address of mfg. defect info*/ public uint mfgst; /*sector address of mfg. defect info*/
public readonly uint mfgsz; /*size in bytes of mfg. defect info*/ public uint mfgsz; /*size in bytes of mfg. defect info*/
public readonly uint defectst; /*sector address of the defect map*/ public uint defectst; /*sector address of the defect map*/
public readonly uint defectsz; /*size in bytes of defect map*/ public uint defectsz; /*size in bytes of defect map*/
public readonly uint relno; /*number of relocation areas*/ public uint relno; /*number of relocation areas*/
public readonly uint relst; /*sector address of relocation area*/ public uint relst; /*sector address of relocation area*/
public readonly uint relsz; /*size in sectors of relocation area*/ public uint relsz; /*size in sectors of relocation area*/
public readonly uint relnext; /*address of next avail reloc sector*/ public uint relnext; /*address of next avail reloc sector*/
/* the previous items are left intact from AT&T's 3b2 pdinfo. Following /* the previous items are left intact from AT&T's 3b2 pdinfo. Following
are added for the 80386 port */ are added for the 80386 port */
public readonly uint vtoc_ptr; /*byte offset of vtoc block*/ public uint vtoc_ptr; /*byte offset of vtoc block*/
public readonly ushort vtoc_len; /*byte length of vtoc block*/ public ushort vtoc_len; /*byte length of vtoc block*/
public readonly ushort vtoc_pad; /* pad for 16-bit machine alignment */ public ushort vtoc_pad; /* pad for 16-bit machine alignment */
public readonly uint alt_ptr; /*byte offset of alternates table*/ public uint alt_ptr; /*byte offset of alternates table*/
public readonly ushort alt_len; /*byte length of alternates table*/ public ushort alt_len; /*byte length of alternates table*/
/* new in version 3 */ /* new in version 3 */
public readonly uint pcyls; /*physical cylinders per drive*/ public uint pcyls; /*physical cylinders per drive*/
public readonly uint ptracks; /*physical tracks per cylinder*/ public uint ptracks; /*physical tracks per cylinder*/
public readonly uint psectors; /*physical sectors per track*/ public uint psectors; /*physical sectors per track*/
public readonly uint pbytes; /*physical bytes per sector*/ public uint pbytes; /*physical bytes per sector*/
public readonly uint secovhd; /*sector overhead bytes per sector*/ public uint secovhd; /*sector overhead bytes per sector*/
public readonly ushort interleave; /*interleave factor*/ public ushort interleave; /*interleave factor*/
public readonly ushort skew; /*skew factor*/ public ushort skew; /*skew factor*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public readonly uint[] pad; /*space for more stuff*/ public uint[] pad; /*space for more stuff*/
} }
#endregion #endregion
@@ -527,32 +518,33 @@ public sealed class VTOC : IPartition
#region Nested type: PDInfoOld #region Nested type: PDInfoOld
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
struct PDInfoOld partial struct PDInfoOld
{ {
public readonly uint driveid; /*identifies the device type*/ public uint driveid; /*identifies the device type*/
public readonly uint sanity; /*verifies device sanity*/ public uint sanity; /*verifies device sanity*/
public readonly uint version; /*version number*/ public uint version; /*version number*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public readonly byte[] serial; /*serial number of the device*/ public byte[] serial; /*serial number of the device*/
public readonly uint cyls; /*number of cylinders per drive*/ public uint cyls; /*number of cylinders per drive*/
public readonly uint tracks; /*number tracks per cylinder*/ public uint tracks; /*number tracks per cylinder*/
public readonly uint sectors; /*number sectors per track*/ public uint sectors; /*number sectors per track*/
public readonly uint bytes; /*number of bytes per sector*/ public uint bytes; /*number of bytes per sector*/
public readonly uint logicalst; /*sector address of logical sector 0*/ public uint logicalst; /*sector address of logical sector 0*/
public readonly uint errlogst; /*sector address of error log area*/ public uint errlogst; /*sector address of error log area*/
public readonly uint errlogsz; /*size in bytes of error log area*/ public uint errlogsz; /*size in bytes of error log area*/
public readonly uint mfgst; /*sector address of mfg. defect info*/ public uint mfgst; /*sector address of mfg. defect info*/
public readonly uint mfgsz; /*size in bytes of mfg. defect info*/ public uint mfgsz; /*size in bytes of mfg. defect info*/
public readonly uint defectst; /*sector address of the defect map*/ public uint defectst; /*sector address of the defect map*/
public readonly uint defectsz; /*size in bytes of defect map*/ public uint defectsz; /*size in bytes of defect map*/
public readonly uint relno; /*number of relocation areas*/ public uint relno; /*number of relocation areas*/
public readonly uint relst; /*sector address of relocation area*/ public uint relst; /*sector address of relocation area*/
public readonly uint relsz; /*size in sectors of relocation area*/ public uint relsz; /*size in sectors of relocation area*/
public readonly uint relnext; /*address of next avail reloc sector*/ public uint relnext; /*address of next avail reloc sector*/
public readonly uint allcstrt; /*start of the allocatable disk*/ public uint allcstrt; /*start of the allocatable disk*/
public readonly uint allcend; /*end of allocatable disk*/ public uint allcend; /*end of allocatable disk*/
} }
#endregion #endregion
@@ -630,22 +622,23 @@ public sealed class VTOC : IPartition
#region Nested type: Vtoc #region Nested type: Vtoc
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
struct Vtoc partial struct Vtoc
{ {
public readonly uint v_sanity; /*to verify vtoc sanity*/ public uint v_sanity; /*to verify vtoc sanity*/
public readonly uint v_version; /*layout version*/ public uint v_version; /*layout version*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public readonly byte[] v_volume; /*volume name*/ public byte[] v_volume; /*volume name*/
public readonly ushort v_nparts; /*number of partitions*/ public ushort v_nparts; /*number of partitions*/
public readonly ushort v_pad; /*pad for 286 compiler*/ public ushort v_pad; /*pad for 286 compiler*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public readonly uint[] v_reserved; /*free space*/ public uint[] v_reserved; /*free space*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)]
public readonly VtocPartition[] v_part; /*partition headers*/ public VtocPartition[] v_part; /*partition headers*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)]
public readonly int[] timestamp; /* SCSI time stamp */ public int[] timestamp; /* SCSI time stamp */
} }
#endregion #endregion
@@ -653,24 +646,25 @@ public sealed class VTOC : IPartition
#region Nested type: VTocOld #region Nested type: VTocOld
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
struct VTocOld partial struct VTocOld
{ {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public readonly uint[] v_bootinfo; /*info needed by mboot*/ public uint[] v_bootinfo; /*info needed by mboot*/
public readonly uint v_sanity; /*to verify vtoc sanity*/ public uint v_sanity; /*to verify vtoc sanity*/
public readonly uint v_version; /*layout version*/ public uint v_version; /*layout version*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public readonly byte[] v_volume; /*volume name*/ public byte[] v_volume; /*volume name*/
public readonly ushort v_sectorsz; /*sector size in bytes*/ public ushort v_sectorsz; /*sector size in bytes*/
public readonly ushort v_nparts; /*number of partitions*/ public ushort v_nparts; /*number of partitions*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public readonly uint[] v_reserved; /*free space*/ public uint[] v_reserved; /*free space*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)]
public readonly VtocPartition[] v_part; /*partition headers*/ public VtocPartition[] v_part; /*partition headers*/
[MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = V_NUMPAR)]
public readonly int[] timestamp; /* SCSI time stamp */ public int[] timestamp; /* SCSI time stamp */
} }
#endregion #endregion
@@ -678,9 +672,10 @@ public sealed class VTOC : IPartition
#region Nested type: VtocPartition #region Nested type: VtocPartition
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
struct VtocPartition partial struct VtocPartition
{ {
public pTag p_tag; /*ID tag of partition*/ public pTag p_tag; /*ID tag of partition*/
public pFlag p_flag; /*permision flags*/ public pFlag p_flag; /*permision flags*/

View File

@@ -35,6 +35,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using Aaru.CommonTypes.Attributes;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Interfaces;
using Marshal = Aaru.Helpers.Marshal; using Marshal = Aaru.Helpers.Marshal;
@@ -44,7 +45,7 @@ namespace Aaru.Partitions;
/// <inheritdoc /> /// <inheritdoc />
/// <summary>Implements decoding of Xbox partitions</summary> /// <summary>Implements decoding of Xbox partitions</summary>
[SuppressMessage("ReSharper", "UnusedMember.Local")] [SuppressMessage("ReSharper", "UnusedMember.Local")]
public sealed class Xbox : IPartition public sealed partial class Xbox : IPartition
{ {
const uint XBOX_CIGAM = 0x46415458; const uint XBOX_CIGAM = 0x46415458;
const uint XBOX_MAGIC = 0x58544146; const uint XBOX_MAGIC = 0x58544146;
@@ -87,7 +88,8 @@ public sealed class Xbox : IPartition
if(errno != ErrorNumber.NoError || sector.Length < 512) return false; if(errno != ErrorNumber.NoError || sector.Length < 512) return false;
Xbox360DevKitPartitionTable table = Marshal.ByteArrayToStructureBigEndian<Xbox360DevKitPartitionTable>(sector); Xbox360DevKitPartitionTable table =
Marshal.ByteArrayToStructureBigEndianGenerated<Xbox360DevKitPartitionTable>(sector);
if(table.magic == XBOX360_DEVKIT_MAGIC && if(table.magic == XBOX360_DEVKIT_MAGIC &&
table.contentOff + table.contentLen <= imagePlugin.Info.Sectors && table.contentOff + table.contentLen <= imagePlugin.Info.Sectors &&
@@ -269,14 +271,15 @@ public sealed class Xbox : IPartition
#region Nested type: Xbox360DevKitPartitionTable #region Nested type: Xbox360DevKitPartitionTable
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Xbox360DevKitPartitionTable [SwapEndian]
partial struct Xbox360DevKitPartitionTable
{ {
public readonly uint magic; public uint magic;
public readonly uint unknown; public uint unknown;
public readonly uint contentOff; public uint contentOff;
public readonly uint contentLen; public uint contentLen;
public readonly uint dashboardOff; public uint dashboardOff;
public readonly uint dashboardLen; public uint dashboardLen;
} }
#endregion #endregion