mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[BSD disklabel] Use generator instead of reflection based swapping.
This commit is contained in:
@@ -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 BSD disklabels</summary>
|
/// <summary>Implements decoding of BSD disklabels</summary>
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||||
public sealed class BSD : IPartition
|
public sealed partial class BSD : IPartition
|
||||||
{
|
{
|
||||||
const uint DISK_MAGIC = 0x82564557;
|
const uint DISK_MAGIC = 0x82564557;
|
||||||
const uint DISK_CIGAM = 0x57455682;
|
const uint DISK_CIGAM = 0x57455682;
|
||||||
@@ -120,7 +121,7 @@ public sealed class BSD : IPartition
|
|||||||
|
|
||||||
if(!found) return false;
|
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_type = {0}", dl.d_type);
|
||||||
AaruLogging.Debug(MODULE_NAME, "dl.d_subtype = {0}", dl.d_subtype);
|
AaruLogging.Debug(MODULE_NAME, "dl.d_subtype = {0}", dl.d_subtype);
|
||||||
@@ -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
|
#region Nested type: BSDPartition
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
struct BSDPartition
|
[SwapEndian]
|
||||||
|
partial struct BSDPartition
|
||||||
{
|
{
|
||||||
/// <summary>Sectors in partition</summary>
|
/// <summary>Sectors in partition</summary>
|
||||||
public readonly uint p_size;
|
public uint p_size;
|
||||||
/// <summary>Starting sector</summary>
|
/// <summary>Starting sector</summary>
|
||||||
public readonly uint p_offset;
|
public uint p_offset;
|
||||||
/// <summary>Fragment size</summary>
|
/// <summary>Fragment size</summary>
|
||||||
public readonly uint p_fsize;
|
public uint p_fsize;
|
||||||
/// <summary>Filesystem type, <see cref="fsType" /></summary>
|
/// <summary>Filesystem type, <see cref="fsType" /></summary>
|
||||||
public readonly fsType p_fstype;
|
public fsType p_fstype;
|
||||||
/// <summary>Fragment size</summary>
|
/// <summary>Fragment size</summary>
|
||||||
public readonly byte p_frag;
|
public byte p_frag;
|
||||||
/// <summary>Cylinder per group</summary>
|
/// <summary>Cylinder per group</summary>
|
||||||
public readonly ushort p_cpg;
|
public ushort p_cpg;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -302,77 +290,78 @@ public sealed class BSD : IPartition
|
|||||||
#region Nested type: DiskLabel
|
#region Nested type: DiskLabel
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
struct DiskLabel
|
[SwapEndian]
|
||||||
|
partial struct DiskLabel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="BSD.DISK_MAGIC" />
|
/// <see cref="BSD.DISK_MAGIC" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly uint d_magic;
|
public uint d_magic;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="dType" />
|
/// <see cref="dType" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly dType d_type;
|
public dType d_type;
|
||||||
/// <summary>Disk subtype</summary>
|
/// <summary>Disk subtype</summary>
|
||||||
public readonly ushort d_subtype;
|
public ushort d_subtype;
|
||||||
/// <summary>Type name</summary>
|
/// <summary>Type name</summary>
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||||
public readonly byte[] d_typename;
|
public byte[] d_typename;
|
||||||
/// <summary>Pack identifier</summary>
|
/// <summary>Pack identifier</summary>
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||||
public readonly byte[] d_packname;
|
public byte[] d_packname;
|
||||||
/// <summary>Bytes per sector</summary>
|
/// <summary>Bytes per sector</summary>
|
||||||
public readonly uint d_secsize;
|
public uint d_secsize;
|
||||||
/// <summary>Sectors per track</summary>
|
/// <summary>Sectors per track</summary>
|
||||||
public readonly uint d_nsectors;
|
public uint d_nsectors;
|
||||||
/// <summary>Tracks per cylinder</summary>
|
/// <summary>Tracks per cylinder</summary>
|
||||||
public readonly uint d_ntracks;
|
public uint d_ntracks;
|
||||||
/// <summary>Cylinders per unit</summary>
|
/// <summary>Cylinders per unit</summary>
|
||||||
public readonly uint d_ncylinders;
|
public uint d_ncylinders;
|
||||||
/// <summary>Sectors per cylinder</summary>
|
/// <summary>Sectors per cylinder</summary>
|
||||||
public readonly uint d_secpercyl;
|
public uint d_secpercyl;
|
||||||
/// <summary>Sectors per unit</summary>
|
/// <summary>Sectors per unit</summary>
|
||||||
public readonly uint d_secperunit;
|
public uint d_secperunit;
|
||||||
/// <summary>Spare sectors per track</summary>
|
/// <summary>Spare sectors per track</summary>
|
||||||
public readonly ushort d_sparespertrack;
|
public ushort d_sparespertrack;
|
||||||
/// <summary>Spare sectors per cylinder</summary>
|
/// <summary>Spare sectors per cylinder</summary>
|
||||||
public readonly ushort d_sparespercyl;
|
public ushort d_sparespercyl;
|
||||||
/// <summary>Alternate cylinders</summary>
|
/// <summary>Alternate cylinders</summary>
|
||||||
public readonly uint d_acylinders;
|
public uint d_acylinders;
|
||||||
/// <summary>Rotational speed</summary>
|
/// <summary>Rotational speed</summary>
|
||||||
public readonly ushort d_rpm;
|
public ushort d_rpm;
|
||||||
/// <summary>Hardware sector interleave</summary>
|
/// <summary>Hardware sector interleave</summary>
|
||||||
public readonly ushort d_interleave;
|
public ushort d_interleave;
|
||||||
/// <summary>Sector 0 skew per track</summary>
|
/// <summary>Sector 0 skew per track</summary>
|
||||||
public readonly ushort d_trackskew;
|
public ushort d_trackskew;
|
||||||
/// <summary>Sector 0 sker per cylinder</summary>
|
/// <summary>Sector 0 sker per cylinder</summary>
|
||||||
public readonly ushort d_cylskeew;
|
public ushort d_cylskeew;
|
||||||
/// <summary>Head switch time in microseconds</summary>
|
/// <summary>Head switch time in microseconds</summary>
|
||||||
public readonly uint d_headswitch;
|
public uint d_headswitch;
|
||||||
/// <summary>Track to track seek in microseconds</summary>
|
/// <summary>Track to track seek in microseconds</summary>
|
||||||
public readonly uint d_trkseek;
|
public uint d_trkseek;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="dFlags" />
|
/// <see cref="dFlags" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly dFlags d_flags;
|
public dFlags d_flags;
|
||||||
/// <summary>Drive-specific information</summary>
|
/// <summary>Drive-specific information</summary>
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
||||||
public readonly uint[] d_drivedata;
|
public uint[] d_drivedata;
|
||||||
/// <summary>Reserved</summary>
|
/// <summary>Reserved</summary>
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
||||||
public readonly uint[] d_spare;
|
public uint[] d_spare;
|
||||||
/// <summary><see cref="BSD.DISK_MAGIC" /> again</summary>
|
/// <summary><see cref="BSD.DISK_MAGIC" /> again</summary>
|
||||||
public readonly uint d_magic2;
|
public uint d_magic2;
|
||||||
/// <summary>XOR of data</summary>
|
/// <summary>XOR of data</summary>
|
||||||
public readonly ushort d_checksum;
|
public ushort d_checksum;
|
||||||
/// <summary>How many partitions</summary>
|
/// <summary>How many partitions</summary>
|
||||||
public readonly ushort d_npartitions;
|
public ushort d_npartitions;
|
||||||
/// <summary>Size of boot area in bytes</summary>
|
/// <summary>Size of boot area in bytes</summary>
|
||||||
public readonly uint d_bbsize;
|
public uint d_bbsize;
|
||||||
/// <summary>Maximum size of superblock in bytes</summary>
|
/// <summary>Maximum size of superblock in bytes</summary>
|
||||||
public readonly uint d_sbsize;
|
public uint d_sbsize;
|
||||||
/// <summary>Partitions</summary>
|
/// <summary>Partitions</summary>
|
||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 22)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 22)]
|
||||||
public readonly BSDPartition[] d_partitions;
|
public BSDPartition[] d_partitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user