// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // // 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-2020 Natalia Portillo // ****************************************************************************/ using System.Runtime.InteropServices; namespace DiscImageChef.DiscImages { public 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)] struct ChdHeaderV1 { /// /// 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; } // Hunks are represented in a 64 bit integer with 44 bit as offset, 20 bits as length [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdHeaderV2 { /// /// 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; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdHeaderV3 { /// /// 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; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdMapV3Entry { /// /// 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; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdTrackOld { public uint type; public uint subType; public uint dataSize; public uint subSize; public uint frames; public uint extraFrames; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdHeaderV4 { /// /// 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; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdHeaderV5 { /// /// 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; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdCompressedMapHeaderV5 { /// /// Length of compressed map /// public uint length; /// /// Offset of first block (48 bits) and CRC16 of map (16 bits) /// public ulong startAndCrc; /// /// Bits used to encode compressed length on map entry /// public byte bitsUsedToEncodeCompLength; /// /// Bits used to encode self-refs /// public byte bitsUsedToEncodeSelfRefs; /// /// Bits used to encode parent unit refs /// public byte bitsUsedToEncodeParentUnits; public byte reserved; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdMapV5Entry { /// /// Compression (8 bits) and length (24 bits) /// public uint compAndLength; /// /// Offset (48 bits) and CRC (16 bits) /// public ulong offsetAndCrc; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct ChdMetadataHeader { public uint tag; public uint flagsAndLength; public ulong next; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct HunkSector { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public ulong[] hunkEntry; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct HunkSectorSmall { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] public uint[] hunkEntry; } } }