diff --git a/Aaru.Partitions/BSD.cs b/Aaru.Partitions/BSD.cs
index a293dac08..1dcc874f1 100644
--- a/Aaru.Partitions/BSD.cs
+++ b/Aaru.Partitions/BSD.cs
@@ -36,6 +36,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;
using Aaru.CommonTypes;
+using Aaru.CommonTypes.Attributes;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
@@ -47,7 +48,7 @@ namespace Aaru.Partitions;
///
/// Implements decoding of BSD disklabels
[SuppressMessage("ReSharper", "UnusedMember.Local")]
-public sealed class BSD : IPartition
+public sealed partial class BSD : IPartition
{
const uint DISK_MAGIC = 0x82564557;
const uint DISK_CIGAM = 0x57455682;
@@ -99,12 +100,12 @@ public sealed class BSD : IPartition
dl = Marshal.ByteArrayToStructureLittleEndian(sector);
AaruLogging.Debug(MODULE_NAME,
- Localization
- .BSD_GetInformation_dl_magic_on_sector_0_at_offset_1_equals_2_X8_expected_3_X8,
- location + sectorOffset,
- offset,
- dl.d_magic,
- DISK_MAGIC);
+ Localization
+ .BSD_GetInformation_dl_magic_on_sector_0_at_offset_1_equals_2_X8_expected_3_X8,
+ location + sectorOffset,
+ offset,
+ dl.d_magic,
+ DISK_MAGIC);
if((dl.d_magic != DISK_MAGIC || dl.d_magic2 != DISK_MAGIC) &&
(dl.d_magic != DISK_CIGAM || dl.d_magic2 != DISK_CIGAM))
@@ -120,7 +121,7 @@ public sealed class BSD : IPartition
if(!found) return false;
- if(dl is { d_magic: DISK_CIGAM, d_magic2: DISK_CIGAM }) dl = SwapDiskLabel(dl);
+ if(dl is { d_magic: DISK_CIGAM, d_magic2: DISK_CIGAM }) dl = dl.SwapEndian();
AaruLogging.Debug(MODULE_NAME, "dl.d_type = {0}", dl.d_type);
AaruLogging.Debug(MODULE_NAME, "dl.d_subtype = {0}", dl.d_subtype);
@@ -168,9 +169,9 @@ public sealed class BSD : IPartition
AaruLogging.Debug(MODULE_NAME, "dl.d_partitions[i].p_size = {0}", dl.d_partitions[i].p_size);
AaruLogging.Debug(MODULE_NAME,
- "dl.d_partitions[i].p_fstype = {0} ({1})",
- dl.d_partitions[i].p_fstype,
- FSTypeToString(dl.d_partitions[i].p_fstype));
+ "dl.d_partitions[i].p_fstype = {0} ({1})",
+ dl.d_partitions[i].p_fstype,
+ FSTypeToString(dl.d_partitions[i].p_fstype));
var part = new Partition
{
@@ -241,37 +242,24 @@ public sealed class BSD : IPartition
};
}
- static DiskLabel SwapDiskLabel(DiskLabel dl)
- {
- dl = (DiskLabel)Marshal.SwapStructureMembersEndian(dl);
-
- for(int i = 0; i < dl.d_drivedata.Length; i++) dl.d_drivedata[i] = Swapping.Swap(dl.d_drivedata[i]);
-
- for(int i = 0; i < dl.d_spare.Length; i++) dl.d_spare[i] = Swapping.Swap(dl.d_spare[i]);
-
- for(int i = 0; i < dl.d_partitions.Length; i++)
- dl.d_partitions[i] = (BSDPartition)Marshal.SwapStructureMembersEndian(dl.d_partitions[i]);
-
- return dl;
- }
-
#region Nested type: BSDPartition
[StructLayout(LayoutKind.Sequential, Pack = 1)]
- struct BSDPartition
+ [SwapEndian]
+ partial struct BSDPartition
{
/// Sectors in partition
- public readonly uint p_size;
+ public uint p_size;
/// Starting sector
- public readonly uint p_offset;
+ public uint p_offset;
/// Fragment size
- public readonly uint p_fsize;
+ public uint p_fsize;
/// Filesystem type,
- public readonly fsType p_fstype;
+ public fsType p_fstype;
/// Fragment size
- public readonly byte p_frag;
+ public byte p_frag;
/// Cylinder per group
- public readonly ushort p_cpg;
+ public ushort p_cpg;
}
#endregion
@@ -302,77 +290,78 @@ public sealed class BSD : IPartition
#region Nested type: DiskLabel
[StructLayout(LayoutKind.Sequential, Pack = 1)]
- struct DiskLabel
+ [SwapEndian]
+ partial struct DiskLabel
{
///
///
///
- public readonly uint d_magic;
+ public uint d_magic;
///
///
///
- public readonly dType d_type;
+ public dType d_type;
/// Disk subtype
- public readonly ushort d_subtype;
+ public ushort d_subtype;
/// Type name
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
- public readonly byte[] d_typename;
+ public byte[] d_typename;
/// Pack identifier
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
- public readonly byte[] d_packname;
+ public byte[] d_packname;
/// Bytes per sector
- public readonly uint d_secsize;
+ public uint d_secsize;
/// Sectors per track
- public readonly uint d_nsectors;
+ public uint d_nsectors;
/// Tracks per cylinder
- public readonly uint d_ntracks;
+ public uint d_ntracks;
/// Cylinders per unit
- public readonly uint d_ncylinders;
+ public uint d_ncylinders;
/// Sectors per cylinder
- public readonly uint d_secpercyl;
+ public uint d_secpercyl;
/// Sectors per unit
- public readonly uint d_secperunit;
+ public uint d_secperunit;
/// Spare sectors per track
- public readonly ushort d_sparespertrack;
+ public ushort d_sparespertrack;
/// Spare sectors per cylinder
- public readonly ushort d_sparespercyl;
+ public ushort d_sparespercyl;
/// Alternate cylinders
- public readonly uint d_acylinders;
+ public uint d_acylinders;
/// Rotational speed
- public readonly ushort d_rpm;
+ public ushort d_rpm;
/// Hardware sector interleave
- public readonly ushort d_interleave;
+ public ushort d_interleave;
/// Sector 0 skew per track
- public readonly ushort d_trackskew;
+ public ushort d_trackskew;
/// Sector 0 sker per cylinder
- public readonly ushort d_cylskeew;
+ public ushort d_cylskeew;
/// Head switch time in microseconds
- public readonly uint d_headswitch;
+ public uint d_headswitch;
/// Track to track seek in microseconds
- public readonly uint d_trkseek;
+ public uint d_trkseek;
///
///
///
- public readonly dFlags d_flags;
+ public dFlags d_flags;
/// Drive-specific information
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
- public readonly uint[] d_drivedata;
+ public uint[] d_drivedata;
/// Reserved
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
- public readonly uint[] d_spare;
+ public uint[] d_spare;
/// again
- public readonly uint d_magic2;
+ public uint d_magic2;
/// XOR of data
- public readonly ushort d_checksum;
+ public ushort d_checksum;
/// How many partitions
- public readonly ushort d_npartitions;
+ public ushort d_npartitions;
/// Size of boot area in bytes
- public readonly uint d_bbsize;
+ public uint d_bbsize;
/// Maximum size of superblock in bytes
- public readonly uint d_sbsize;
+ public uint d_sbsize;
/// Partitions
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 22)]
- public readonly BSDPartition[] d_partitions;
+ public BSDPartition[] d_partitions;
}
#endregion