Files
Aaru/Aaru.Images/CHD/Structs.cs

346 lines
12 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Structs.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Contains structures for MAME Compressed Hunks of Data disk images.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
2020-07-20 07:47:12 +01:00
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
[SuppressMessage("ReSharper", "UnusedType.Local")]
public sealed partial class Chd
{
2023-10-03 23:34:59 +01:00
#region Nested type: CompressedMapHeaderV5
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct CompressedMapHeaderV5
{
/// <summary>Length of compressed map</summary>
public readonly uint length;
/// <summary>Offset of first block (48 bits) and CRC16 of map (16 bits)</summary>
public readonly ulong startAndCrc;
/// <summary>Bits used to encode compressed length on map entry</summary>
public readonly byte bitsUsedToEncodeCompLength;
/// <summary>Bits used to encode self-refs</summary>
public readonly byte bitsUsedToEncodeSelfRefs;
/// <summary>Bits used to encode parent unit refs</summary>
public readonly byte bitsUsedToEncodeParentUnits;
public readonly byte reserved;
}
#endregion
#region Nested type: HeaderV1
2022-03-06 13:29:38 +00:00
// Hunks are represented in a 64 bit integer with 44 bit as offset, 20 bits as length
// Sectors are fixed at 512 bytes/sector
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct HeaderV1
{
2022-03-06 13:29:38 +00:00
/// <summary>Magic identifier, 'MComprHD'</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] tag;
2022-03-06 13:29:38 +00:00
/// <summary>Length of header</summary>
public uint length;
2022-03-06 13:29:38 +00:00
/// <summary>Image format version</summary>
public uint version;
2022-03-06 13:29:38 +00:00
/// <summary>Image flags, <see cref="Flags" /></summary>
public uint flags;
2022-03-06 13:29:38 +00:00
/// <summary>Compression algorithm, <see cref="Compression" /></summary>
public uint compression;
2022-03-06 13:29:38 +00:00
/// <summary>Sectors per hunk</summary>
public uint hunksize;
2022-03-06 13:29:38 +00:00
/// <summary>Total # of hunk in image</summary>
public uint totalhunks;
2022-03-06 13:29:38 +00:00
/// <summary>Cylinders on disk</summary>
public uint cylinders;
2022-03-06 13:29:38 +00:00
/// <summary>Heads per cylinder</summary>
public uint heads;
2022-03-06 13:29:38 +00:00
/// <summary>Sectors per track</summary>
public uint sectors;
2022-03-06 13:29:38 +00:00
/// <summary>MD5 of raw data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] md5;
2022-03-06 13:29:38 +00:00
/// <summary>MD5 of parent file</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] parentmd5;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:34:59 +01:00
#endregion
#region Nested type: HeaderV2
2022-03-06 13:29:38 +00:00
// Hunks are represented in a 64 bit integer with 44 bit as offset, 20 bits as length
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct HeaderV2
2022-03-06 13:29:38 +00:00
{
/// <summary>Magic identifier, 'MComprHD'</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] tag;
2022-03-06 13:29:38 +00:00
/// <summary>Length of header</summary>
public uint length;
2022-03-06 13:29:38 +00:00
/// <summary>Image format version</summary>
public uint version;
2022-03-06 13:29:38 +00:00
/// <summary>Image flags, <see cref="Flags" /></summary>
public uint flags;
2022-03-06 13:29:38 +00:00
/// <summary>Compression algorithm, <see cref="Compression" /></summary>
public uint compression;
2022-03-06 13:29:38 +00:00
/// <summary>Sectors per hunk</summary>
public uint hunksize;
2022-03-06 13:29:38 +00:00
/// <summary>Total # of hunk in image</summary>
public uint totalhunks;
2022-03-06 13:29:38 +00:00
/// <summary>Cylinders on disk</summary>
public uint cylinders;
2022-03-06 13:29:38 +00:00
/// <summary>Heads per cylinder</summary>
public uint heads;
2022-03-06 13:29:38 +00:00
/// <summary>Sectors per track</summary>
public uint sectors;
2022-03-06 13:29:38 +00:00
/// <summary>MD5 of raw data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] md5;
2022-03-06 13:29:38 +00:00
/// <summary>MD5 of parent file</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] parentmd5;
2022-03-06 13:29:38 +00:00
/// <summary>Bytes per sector</summary>
public uint seclen;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:34:59 +01:00
#endregion
#region Nested type: HeaderV3
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct HeaderV3
2022-03-06 13:29:38 +00:00
{
/// <summary>Magic identifier, 'MComprHD'</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] tag;
2022-03-06 13:29:38 +00:00
/// <summary>Length of header</summary>
public uint length;
2022-03-06 13:29:38 +00:00
/// <summary>Image format version</summary>
public uint version;
2022-03-06 13:29:38 +00:00
/// <summary>Image flags, <see cref="Flags" /></summary>
public uint flags;
2022-03-06 13:29:38 +00:00
/// <summary>Compression algorithm, <see cref="Compression" /></summary>
public uint compression;
2022-03-06 13:29:38 +00:00
/// <summary>Total # of hunk in image</summary>
public uint totalhunks;
2022-03-06 13:29:38 +00:00
/// <summary>Total bytes in image</summary>
public ulong logicalbytes;
2022-03-06 13:29:38 +00:00
/// <summary>Offset to first metadata blob</summary>
public ulong metaoffset;
2022-03-06 13:29:38 +00:00
/// <summary>MD5 of raw data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] md5;
2022-03-06 13:29:38 +00:00
/// <summary>MD5 of parent file</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] parentmd5;
2022-03-06 13:29:38 +00:00
/// <summary>Bytes per hunk</summary>
public uint hunkbytes;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of raw data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] sha1;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of parent file</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] parentsha1;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:34:59 +01:00
#endregion
2023-10-03 23:34:59 +01:00
#region Nested type: HeaderV4
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct HeaderV4
2022-03-06 13:29:38 +00:00
{
/// <summary>Magic identifier, 'MComprHD'</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] tag;
2022-03-06 13:29:38 +00:00
/// <summary>Length of header</summary>
public uint length;
2022-03-06 13:29:38 +00:00
/// <summary>Image format version</summary>
public uint version;
2022-03-06 13:29:38 +00:00
/// <summary>Image flags, <see cref="Flags" /></summary>
public uint flags;
2022-03-06 13:29:38 +00:00
/// <summary>Compression algorithm, <see cref="Compression" /></summary>
public uint compression;
2022-03-06 13:29:38 +00:00
/// <summary>Total # of hunk in image</summary>
public uint totalhunks;
2022-03-06 13:29:38 +00:00
/// <summary>Total bytes in image</summary>
public ulong logicalbytes;
2022-03-06 13:29:38 +00:00
/// <summary>Offset to first metadata blob</summary>
public ulong metaoffset;
2022-03-06 13:29:38 +00:00
/// <summary>Bytes per hunk</summary>
public uint hunkbytes;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of raw+meta data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] sha1;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of parent file</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] parentsha1;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of raw data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] rawsha1;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:34:59 +01:00
#endregion
#region Nested type: HeaderV5
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct HeaderV5
2022-03-06 13:29:38 +00:00
{
/// <summary>Magic identifier, 'MComprHD'</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] tag;
2022-03-06 13:29:38 +00:00
/// <summary>Length of header</summary>
public uint length;
2022-03-06 13:29:38 +00:00
/// <summary>Image format version</summary>
public uint version;
2022-03-06 13:29:38 +00:00
/// <summary>Compressor 0</summary>
public uint compressor0;
2022-03-06 13:29:38 +00:00
/// <summary>Compressor 1</summary>
public uint compressor1;
2022-03-06 13:29:38 +00:00
/// <summary>Compressor 2</summary>
public uint compressor2;
2022-03-06 13:29:38 +00:00
/// <summary>Compressor 3</summary>
public uint compressor3;
2022-03-06 13:29:38 +00:00
/// <summary>Total bytes in image</summary>
public ulong logicalbytes;
2022-03-06 13:29:38 +00:00
/// <summary>Offset to hunk map</summary>
public ulong mapoffset;
2022-03-06 13:29:38 +00:00
/// <summary>Offset to first metadata blob</summary>
public ulong metaoffset;
2022-03-06 13:29:38 +00:00
/// <summary>Bytes per hunk</summary>
public uint hunkbytes;
2022-03-06 13:29:38 +00:00
/// <summary>Bytes per unit within hunk</summary>
public uint unitbytes;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of raw data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] rawsha1;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of raw+meta data</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] sha1;
2022-03-06 13:29:38 +00:00
/// <summary>SHA1 of parent file</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] parentsha1;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:34:59 +01:00
#endregion
#region Nested type: HunkSector
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
2023-10-03 23:34:59 +01:00
readonly struct HunkSector
2022-03-06 13:29:38 +00:00
{
2023-10-03 23:34:59 +01:00
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public readonly ulong[] hunkEntry;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:34:59 +01:00
#endregion
#region Nested type: HunkSectorSmall
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct HunkSectorSmall
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public readonly uint[] hunkEntry;
}
#endregion
#region Nested type: MapEntryV3
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct MapEntryV3
2023-10-03 23:34:59 +01:00
{
/// <summary>Offset to hunk from start of image</summary>
public ulong offset;
2023-10-03 23:34:59 +01:00
/// <summary>CRC32 of uncompressed hunk</summary>
public uint crc;
2023-10-03 23:34:59 +01:00
/// <summary>Lower 16 bits of length</summary>
public ushort lengthLsb;
2023-10-03 23:34:59 +01:00
/// <summary>Upper 8 bits of length</summary>
public byte length;
2023-10-03 23:34:59 +01:00
/// <summary>Hunk flags</summary>
public byte flags;
2023-10-03 23:34:59 +01:00
}
#endregion
#region Nested type: MapEntryV5
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct MapEntryV5
{
/// <summary>Compression (8 bits) and length (24 bits)</summary>
public readonly uint compAndLength;
/// <summary>Offset (48 bits) and CRC (16 bits)</summary>
public readonly ulong offsetAndCrc;
}
2023-10-03 23:34:59 +01:00
#endregion
#region Nested type: MetadataHeader
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
[SwapEndian]
partial struct MetadataHeader
2022-03-06 13:29:38 +00:00
{
public uint tag;
public uint flagsAndLength;
public ulong next;
2022-03-06 13:29:38 +00:00
}
2023-10-03 23:34:59 +01:00
#endregion
#region Nested type: TrackOld
2022-03-06 13:29:38 +00:00
[StructLayout(LayoutKind.Sequential, Pack = 1)]
2023-10-03 23:34:59 +01:00
struct TrackOld
2022-03-06 13:29:38 +00:00
{
2023-10-03 23:34:59 +01:00
public uint type;
public uint subType;
public uint dataSize;
public uint subSize;
public uint frames;
public uint extraFrames;
}
2023-10-03 23:34:59 +01:00
#endregion
}