mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[NeXT disklabel] Use new source generator based big endian marshaller
This commit is contained in:
@@ -39,6 +39,7 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Attributes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Helpers;
|
||||
@@ -51,7 +52,7 @@ namespace Aaru.Partitions;
|
||||
/// <summary>Implements decoding of NeXT disklabels</summary>
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||
[SuppressMessage("ReSharper", "UnusedType.Local")]
|
||||
public sealed class NeXTDisklabel : IPartition
|
||||
public sealed partial class NeXTDisklabel : IPartition
|
||||
{
|
||||
/// <summary>"NeXT"</summary>
|
||||
const uint NEXT_MAGIC1 = 0x4E655854;
|
||||
@@ -79,7 +80,7 @@ public sealed class NeXTDisklabel : IPartition
|
||||
/// <inheritdoc />
|
||||
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
||||
{
|
||||
bool magicFound = false;
|
||||
var magicFound = false;
|
||||
byte[] labelSector;
|
||||
|
||||
uint sectorSize = imagePlugin.Info.SectorSize is 2352 or 2448 ? 2048 : imagePlugin.Info.SectorSize;
|
||||
@@ -98,7 +99,7 @@ public sealed class NeXTDisklabel : IPartition
|
||||
|
||||
if(errno != ErrorNumber.NoError) continue;
|
||||
|
||||
uint magic = BigEndianBitConverter.ToUInt32(labelSector, 0x00);
|
||||
var magic = BigEndianBitConverter.ToUInt32(labelSector, 0x00);
|
||||
|
||||
if(magic != NEXT_MAGIC1 && magic != NEXT_MAGIC2 && magic != NEXT_MAGIC3) continue;
|
||||
|
||||
@@ -118,10 +119,10 @@ public sealed class NeXTDisklabel : IPartition
|
||||
|
||||
if(errno != ErrorNumber.NoError) return false;
|
||||
|
||||
Label label = Marshal.ByteArrayToStructureBigEndian<Label>(labelSector);
|
||||
byte[] disktabB = new byte[498];
|
||||
Label label = Marshal.ByteArrayToStructureBigEndianGenerated<Label>(labelSector);
|
||||
var disktabB = new byte[498];
|
||||
Array.Copy(labelSector, 44, disktabB, 0, 498);
|
||||
label.dl_dt = Marshal.ByteArrayToStructureBigEndian<DiskTab>(disktabB);
|
||||
label.dl_dt = Marshal.ByteArrayToStructureBigEndianGenerated<DiskTab>(disktabB);
|
||||
label.dl_dt.d_partitions = new Entry[8];
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_version = 0x{0:X8}", label.dl_version);
|
||||
@@ -133,13 +134,9 @@ public sealed class NeXTDisklabel : IPartition
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_flags = {0}", label.dl_flags);
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_tag = 0x{0:X8}", label.dl_tag);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_name = \"{0}\"",
|
||||
StringHandlers.CToString(label.dl_dt.d_name));
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_dt.d_name = \"{0}\"", StringHandlers.CToString(label.dl_dt.d_name));
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_type = \"{0}\"",
|
||||
StringHandlers.CToString(label.dl_dt.d_type));
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_dt.d_type = \"{0}\"", StringHandlers.CToString(label.dl_dt.d_type));
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_dt.d_secsize = {0}", label.dl_dt.d_secsize);
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_dt.d_ntracks = {0}", label.dl_dt.d_ntracks);
|
||||
@@ -158,81 +155,81 @@ public sealed class NeXTDisklabel : IPartition
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_dt.d_boot0_blkno[1] = {0}", label.dl_dt.d_boot0_blkno[1]);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_bootfile = \"{0}\"",
|
||||
StringHandlers.CToString(label.dl_dt.d_bootfile));
|
||||
"label.dl_dt.d_bootfile = \"{0}\"",
|
||||
StringHandlers.CToString(label.dl_dt.d_bootfile));
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_hostname = \"{0}\"",
|
||||
StringHandlers.CToString(label.dl_dt.d_hostname));
|
||||
"label.dl_dt.d_hostname = \"{0}\"",
|
||||
StringHandlers.CToString(label.dl_dt.d_hostname));
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_dt.d_rootpartition = {0}", label.dl_dt.d_rootpartition);
|
||||
AaruLogging.Debug(MODULE_NAME, "label.dl_dt.d_rwpartition = {0}", label.dl_dt.d_rwpartition);
|
||||
|
||||
for(int i = 0; i < 8; i++)
|
||||
for(var i = 0; i < 8; i++)
|
||||
{
|
||||
byte[] partB = new byte[44];
|
||||
var partB = new byte[44];
|
||||
Array.Copy(labelSector, 44 + 146 + 44 * i, partB, 0, 44);
|
||||
label.dl_dt.d_partitions[i] = Marshal.ByteArrayToStructureBigEndian<Entry>(partB);
|
||||
label.dl_dt.d_partitions[i] = Marshal.ByteArrayToStructureBigEndianGenerated<Entry>(partB);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_base = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_base);
|
||||
"label.dl_dt.d_partitions[{0}].p_base = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_base);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_size = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_size);
|
||||
"label.dl_dt.d_partitions[{0}].p_size = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_size);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_bsize = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_bsize);
|
||||
"label.dl_dt.d_partitions[{0}].p_bsize = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_bsize);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_fsize = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_fsize);
|
||||
"label.dl_dt.d_partitions[{0}].p_fsize = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_fsize);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_opt = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_opt);
|
||||
"label.dl_dt.d_partitions[{0}].p_opt = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_opt);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_cpg = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_cpg);
|
||||
"label.dl_dt.d_partitions[{0}].p_cpg = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_cpg);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_density = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_density);
|
||||
"label.dl_dt.d_partitions[{0}].p_density = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_density);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_minfree = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_minfree);
|
||||
"label.dl_dt.d_partitions[{0}].p_minfree = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_minfree);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_newfs = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_newfs);
|
||||
"label.dl_dt.d_partitions[{0}].p_newfs = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_newfs);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_mountpt = \"{1}\"",
|
||||
i,
|
||||
StringHandlers.CToString(label.dl_dt.d_partitions[i].p_mountpt));
|
||||
"label.dl_dt.d_partitions[{0}].p_mountpt = \"{1}\"",
|
||||
i,
|
||||
StringHandlers.CToString(label.dl_dt.d_partitions[i].p_mountpt));
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_automnt = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_automnt);
|
||||
"label.dl_dt.d_partitions[{0}].p_automnt = {1}",
|
||||
i,
|
||||
label.dl_dt.d_partitions[i].p_automnt);
|
||||
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
"label.dl_dt.d_partitions[{0}].p_type = \"{1}\"",
|
||||
i,
|
||||
StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type));
|
||||
"label.dl_dt.d_partitions[{0}].p_type = \"{1}\"",
|
||||
i,
|
||||
StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type));
|
||||
|
||||
if(label.dl_dt.d_partitions[i].p_size <= 0 ||
|
||||
label.dl_dt.d_partitions[i].p_base < 0 ||
|
||||
@@ -300,49 +297,50 @@ public sealed class NeXTDisklabel : IPartition
|
||||
|
||||
/// <summary>NeXT disktab and partitions, 498 bytes</summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct DiskTab
|
||||
[SwapEndian]
|
||||
partial struct DiskTab
|
||||
{
|
||||
/// <summary>Drive name</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
|
||||
public readonly byte[] d_name;
|
||||
public byte[] d_name;
|
||||
/// <summary>Drive type</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
|
||||
public readonly byte[] d_type;
|
||||
public byte[] d_type;
|
||||
/// <summary>Sector size</summary>
|
||||
public readonly int d_secsize;
|
||||
public int d_secsize;
|
||||
/// <summary>tracks/cylinder</summary>
|
||||
public readonly int d_ntracks;
|
||||
public int d_ntracks;
|
||||
/// <summary>sectors/track</summary>
|
||||
public readonly int d_nsectors;
|
||||
public int d_nsectors;
|
||||
/// <summary>cylinders</summary>
|
||||
public readonly int d_ncylinders;
|
||||
public int d_ncylinders;
|
||||
/// <summary>revolutions/minute</summary>
|
||||
public readonly int d_rpm;
|
||||
public int d_rpm;
|
||||
/// <summary>size of front porch in sectors</summary>
|
||||
public readonly short d_front;
|
||||
public short d_front;
|
||||
/// <summary>size of back porch in sectors</summary>
|
||||
public readonly short d_back;
|
||||
public short d_back;
|
||||
/// <summary>number of alt groups</summary>
|
||||
public readonly short d_ngroups;
|
||||
public short d_ngroups;
|
||||
/// <summary>alt group size in sectors</summary>
|
||||
public readonly short d_ag_size;
|
||||
public short d_ag_size;
|
||||
/// <summary>alternate sectors per alt group</summary>
|
||||
public readonly short d_ag_alts;
|
||||
public short d_ag_alts;
|
||||
/// <summary>sector offset to first alternate</summary>
|
||||
public readonly short d_ag_off;
|
||||
public short d_ag_off;
|
||||
/// <summary>"blk 0" boot locations</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
|
||||
public readonly int[] d_boot0_blkno;
|
||||
public int[] d_boot0_blkno;
|
||||
/// <summary>default bootfile</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
|
||||
public readonly byte[] d_bootfile;
|
||||
public byte[] d_bootfile;
|
||||
/// <summary>host name</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
||||
public readonly byte[] d_hostname;
|
||||
public byte[] d_hostname;
|
||||
/// <summary>root partition</summary>
|
||||
public readonly byte d_rootpartition;
|
||||
public byte d_rootpartition;
|
||||
/// <summary>r/w partition</summary>
|
||||
public readonly byte d_rwpartition;
|
||||
public byte d_rwpartition;
|
||||
/// <summary>partitions</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public Entry[] d_partitions;
|
||||
@@ -354,34 +352,35 @@ public sealed class NeXTDisklabel : IPartition
|
||||
|
||||
/// <summary>Partition entries, 44 bytes each</summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
struct Entry
|
||||
[SwapEndian]
|
||||
partial struct Entry
|
||||
{
|
||||
/// <summary>Sector of start, counting from front porch</summary>
|
||||
public readonly int p_base;
|
||||
public int p_base;
|
||||
/// <summary>Length in sectors</summary>
|
||||
public readonly int p_size;
|
||||
public int p_size;
|
||||
/// <summary>Filesystem's block size</summary>
|
||||
public readonly short p_bsize;
|
||||
public short p_bsize;
|
||||
/// <summary>Filesystem's fragment size</summary>
|
||||
public readonly short p_fsize;
|
||||
public short p_fsize;
|
||||
/// <summary>'s'pace or 't'ime</summary>
|
||||
public readonly byte p_opt;
|
||||
public byte p_opt;
|
||||
/// <summary>Cylinders per group</summary>
|
||||
public readonly short p_cpg;
|
||||
public short p_cpg;
|
||||
/// <summary>Bytes per inode</summary>
|
||||
public readonly short p_density;
|
||||
public short p_density;
|
||||
/// <summary>% of minimum free space</summary>
|
||||
public readonly byte p_minfree;
|
||||
public byte p_minfree;
|
||||
/// <summary>Should newfs be run on first start?</summary>
|
||||
public readonly byte p_newfs;
|
||||
public byte p_newfs;
|
||||
/// <summary>Mount point or empty if mount where you want</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||
public readonly byte[] p_mountpt;
|
||||
public byte[] p_mountpt;
|
||||
/// <summary>Should automount</summary>
|
||||
public readonly byte p_automnt;
|
||||
public byte p_automnt;
|
||||
/// <summary>Filesystem type, always "4.3BSD"?</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public readonly byte[] p_type;
|
||||
public byte[] p_type;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -390,25 +389,26 @@ public sealed class NeXTDisklabel : IPartition
|
||||
|
||||
/// <summary>NeXT v3 disklabel, 544 bytes</summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct Label
|
||||
[SwapEndian]
|
||||
partial struct Label
|
||||
{
|
||||
/// <summary>Signature</summary>
|
||||
public readonly uint dl_version;
|
||||
public uint dl_version;
|
||||
/// <summary>Block on which this label resides</summary>
|
||||
public readonly int dl_label_blkno;
|
||||
public int dl_label_blkno;
|
||||
/// <summary>Device size in blocks</summary>
|
||||
public readonly int dl_size;
|
||||
public int dl_size;
|
||||
/// <summary>Device name</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
|
||||
public readonly byte[] dl_label;
|
||||
public byte[] dl_label;
|
||||
/// <summary>Device flags</summary>
|
||||
public readonly uint dl_flags;
|
||||
public uint dl_flags;
|
||||
/// <summary>Device tag</summary>
|
||||
public readonly uint dl_tag;
|
||||
public uint dl_tag;
|
||||
/// <summary>Device info and partitions</summary>
|
||||
public DiskTab dl_dt;
|
||||
/// <summary>Checksum</summary>
|
||||
public readonly ushort dl_v3_checksum;
|
||||
public ushort dl_v3_checksum;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -417,28 +417,29 @@ public sealed class NeXTDisklabel : IPartition
|
||||
|
||||
/// <summary>NeXT v1 and v2 disklabel, 7224 bytes</summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
readonly struct LabelOld
|
||||
[SwapEndian]
|
||||
partial struct LabelOld
|
||||
{
|
||||
/// <summary>Signature</summary>
|
||||
public readonly uint dl_version;
|
||||
public uint dl_version;
|
||||
/// <summary>Block on which this label resides</summary>
|
||||
public readonly int dl_label_blkno;
|
||||
public int dl_label_blkno;
|
||||
/// <summary>Device size in blocks</summary>
|
||||
public readonly int dl_size;
|
||||
public int dl_size;
|
||||
/// <summary>Device name</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
|
||||
public readonly byte[] dl_label;
|
||||
public byte[] dl_label;
|
||||
/// <summary>Device flags</summary>
|
||||
public readonly uint dl_flags;
|
||||
public uint dl_flags;
|
||||
/// <summary>Device tag</summary>
|
||||
public readonly uint dl_tag;
|
||||
public uint dl_tag;
|
||||
/// <summary>Device info and partitions</summary>
|
||||
public readonly DiskTab dl_dt;
|
||||
public DiskTab dl_dt;
|
||||
/// <summary>Bad sector table</summary>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1670)]
|
||||
public readonly int[] dl_bad;
|
||||
public int[] dl_bad;
|
||||
/// <summary>Checksum</summary>
|
||||
public readonly ushort dl_checksum;
|
||||
public ushort dl_checksum;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user