// /*************************************************************************** // 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-2021 Natalia Portillo // ****************************************************************************/ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace Aaru.DiscImages { [SuppressMessage("ReSharper", "UnusedType.Local")] public sealed partial class Chd { // 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)] readonly struct HeaderV1 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public readonly byte[] tag; /// Length of header public readonly uint length; /// Image format version public readonly uint version; /// Image flags, public readonly uint flags; /// Compression algorithm, public readonly uint compression; /// Sectors per hunk public readonly uint hunksize; /// Total # of hunk in image public readonly uint totalhunks; /// Cylinders on disk public readonly uint cylinders; /// Heads per cylinder public readonly uint heads; /// Sectors per track public readonly uint sectors; /// MD5 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] md5; /// MD5 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] parentmd5; } // Hunks are represented in a 64 bit integer with 44 bit as offset, 20 bits as length [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct HeaderV2 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public readonly byte[] tag; /// Length of header public readonly uint length; /// Image format version public readonly uint version; /// Image flags, public readonly uint flags; /// Compression algorithm, public readonly uint compression; /// Sectors per hunk public readonly uint hunksize; /// Total # of hunk in image public readonly uint totalhunks; /// Cylinders on disk public readonly uint cylinders; /// Heads per cylinder public readonly uint heads; /// Sectors per track public readonly uint sectors; /// MD5 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] md5; /// MD5 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] parentmd5; /// Bytes per sector public readonly uint seclen; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct HeaderV3 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public readonly byte[] tag; /// Length of header public readonly uint length; /// Image format version public readonly uint version; /// Image flags, public readonly uint flags; /// Compression algorithm, public readonly uint compression; /// Total # of hunk in image public readonly uint totalhunks; /// Total bytes in image public readonly ulong logicalbytes; /// Offset to first metadata blob public readonly ulong metaoffset; /// MD5 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] md5; /// MD5 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] parentmd5; /// Bytes per hunk public readonly uint hunkbytes; /// SHA1 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] sha1; /// SHA1 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] parentsha1; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct MapEntryV3 { /// Offset to hunk from start of image public readonly ulong offset; /// CRC32 of uncompressed hunk public readonly uint crc; /// Lower 16 bits of length public readonly ushort lengthLsb; /// Upper 8 bits of length public readonly byte length; /// Hunk flags public readonly byte flags; } [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; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct HeaderV4 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public readonly byte[] tag; /// Length of header public readonly uint length; /// Image format version public readonly uint version; /// Image flags, public readonly uint flags; /// Compression algorithm, public readonly uint compression; /// Total # of hunk in image public readonly uint totalhunks; /// Total bytes in image public readonly ulong logicalbytes; /// Offset to first metadata blob public readonly ulong metaoffset; /// Bytes per hunk public readonly uint hunkbytes; /// SHA1 of raw+meta data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] sha1; /// SHA1 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] parentsha1; /// SHA1 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] rawsha1; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct HeaderV5 { /// Magic identifier, 'MComprHD' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public readonly byte[] tag; /// Length of header public readonly uint length; /// Image format version public readonly uint version; /// Compressor 0 public readonly uint compressor0; /// Compressor 1 public readonly uint compressor1; /// Compressor 2 public readonly uint compressor2; /// Compressor 3 public readonly uint compressor3; /// Total bytes in image public readonly ulong logicalbytes; /// Offset to hunk map public readonly ulong mapoffset; /// Offset to first metadata blob public readonly ulong metaoffset; /// Bytes per hunk public readonly uint hunkbytes; /// Bytes per unit within hunk public readonly uint unitbytes; /// SHA1 of raw data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] rawsha1; /// SHA1 of raw+meta data [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] sha1; /// SHA1 of parent file [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly byte[] parentsha1; } [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; } [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; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct MetadataHeader { public readonly uint tag; public readonly uint flagsAndLength; public readonly ulong next; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct HunkSector { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public readonly ulong[] hunkEntry; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct HunkSectorSmall { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] public readonly uint[] hunkEntry; } } }