// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Natalia Portillo // // 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 . // // ---------------------------------------------------------------------------- // Copyright © 2011-2025 Natalia Portillo // ****************************************************************************/ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using Aaru.CommonTypes.Attributes; namespace Aaru.Images; [SuppressMessage("ReSharper", "UnusedType.Local")] public sealed partial class Chd { #region Nested type: CompressedMapHeaderV5 [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct CompressedMapHeaderV5 { /// Length of compressed map public readonly uint length; /// Offset of first block (48 bits) and CRC16 of map (16 bits) public readonly ulong startAndCrc; /// Bits used to encode compressed length on map entry public readonly byte bitsUsedToEncodeCompLength; /// Bits used to encode self-refs public readonly byte bitsUsedToEncodeSelfRefs; /// Bits used to encode parent unit refs public readonly byte bitsUsedToEncodeParentUnits; public readonly byte reserved; } #endregion #region Nested type: HeaderV1 // 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 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] tag; /// Length of header public uint length; /// Image format version public uint version; /// Image flags, public uint flags; /// Compression algorithm, public uint compression; /// Sectors per hunk public uint hunksize; /// Total # of hunk in image public uint totalhunks; /// Cylinders on disk public uint cylinders; /// Heads per cylinder public uint heads; /// Sectors per track public uint sectors; /// MD5 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] md5; /// MD5 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] parentmd5; } #endregion #region Nested type: HeaderV2 // 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 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] tag; /// Length of header public uint length; /// Image format version public uint version; /// Image flags, public uint flags; /// Compression algorithm, public uint compression; /// Sectors per hunk public uint hunksize; /// Total # of hunk in image public uint totalhunks; /// Cylinders on disk public uint cylinders; /// Heads per cylinder public uint heads; /// Sectors per track public uint sectors; /// MD5 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] md5; /// MD5 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] parentmd5; /// Bytes per sector public uint seclen; } #endregion #region Nested type: HeaderV3 [StructLayout(LayoutKind.Sequential, Pack = 1)] [SwapEndian] partial struct HeaderV3 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] tag; /// Length of header public uint length; /// Image format version public uint version; /// Image flags, public uint flags; /// Compression algorithm, public uint compression; /// Total # of hunk in image public uint totalhunks; /// Total bytes in image public ulong logicalbytes; /// Offset to first metadata blob public ulong metaoffset; /// MD5 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] md5; /// MD5 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] parentmd5; /// Bytes per hunk public uint hunkbytes; /// SHA1 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] sha1; /// SHA1 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] parentsha1; } #endregion #region Nested type: HeaderV4 [StructLayout(LayoutKind.Sequential, Pack = 1)] [SwapEndian] partial struct HeaderV4 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] tag; /// Length of header public uint length; /// Image format version public uint version; /// Image flags, public uint flags; /// Compression algorithm, public uint compression; /// Total # of hunk in image public uint totalhunks; /// Total bytes in image public ulong logicalbytes; /// Offset to first metadata blob public ulong metaoffset; /// Bytes per hunk public uint hunkbytes; /// SHA1 of raw+meta data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] sha1; /// SHA1 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] parentsha1; /// SHA1 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] rawsha1; } #endregion #region Nested type: HeaderV5 [StructLayout(LayoutKind.Sequential, Pack = 1)] [SwapEndian] partial struct HeaderV5 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] tag; /// Length of header public uint length; /// Image format version public uint version; /// Compressor 0 public uint compressor0; /// Compressor 1 public uint compressor1; /// Compressor 2 public uint compressor2; /// Compressor 3 public uint compressor3; /// Total bytes in image public ulong logicalbytes; /// Offset to hunk map public ulong mapoffset; /// Offset to first metadata blob public ulong metaoffset; /// Bytes per hunk public uint hunkbytes; /// Bytes per unit within hunk public uint unitbytes; /// SHA1 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] rawsha1; /// SHA1 of raw+meta data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] sha1; /// SHA1 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public byte[] parentsha1; } #endregion #region Nested type: HunkSector [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct HunkSector { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public readonly ulong[] hunkEntry; } #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 { /// Offset to hunk from start of image public ulong offset; /// CRC32 of uncompressed hunk public uint crc; /// Lower 16 bits of length public ushort lengthLsb; /// Upper 8 bits of length public byte length; /// Hunk flags public byte flags; } #endregion #region Nested type: MapEntryV5 [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct MapEntryV5 { /// Compression (8 bits) and length (24 bits) public readonly uint compAndLength; /// Offset (48 bits) and CRC (16 bits) public readonly ulong offsetAndCrc; } #endregion #region Nested type: MetadataHeader [StructLayout(LayoutKind.Sequential, Pack = 1)] [SwapEndian] partial struct MetadataHeader { public uint tag; public uint flagsAndLength; public ulong next; } #endregion #region Nested type: TrackOld [StructLayout(LayoutKind.Sequential, Pack = 1)] struct TrackOld { public uint type; public uint subType; public uint dataSize; public uint subSize; public uint frames; public uint extraFrames; } #endregion }