// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Natalia Portillo // // Component : Disk image plugins. // // --[ Description ] ---------------------------------------------------------- // // Contains structures for Microsoft Hyper-V 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; using System.Runtime.InteropServices; namespace Aaru.DiscImages { public sealed partial class Vhdx { [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct Identifier { /// Signature, public readonly ulong signature; /// UTF-16 string containing creator [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] public readonly byte[] creator; } #pragma warning disable 649 #pragma warning disable 169 struct Header { /// Signature, public uint Signature; /// CRC-32C of whole 4096 bytes header with this field set to 0 public uint Checksum; /// Sequence number public ulong Sequence; /// Unique identifier for file contents, must be changed on first write to metadata public Guid FileWriteGuid; /// Unique identifier for disk contents, must be changed on first write to metadata or data public Guid DataWriteGuid; /// Unique identifier for log entries public Guid LogGuid; /// Version of log format public ushort LogVersion; /// Version of VHDX format public ushort Version; /// Length in bytes of the log public uint LogLength; /// Offset from image start to the log public ulong LogOffset; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4016)] public byte[] Reserved; } #pragma warning restore 649 #pragma warning restore 169 [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct RegionTableHeader { /// Signature, public readonly uint signature; /// CRC-32C of whole 64Kb table with this field set to 0 public readonly uint checksum; /// How many entries follow this table public readonly uint entries; /// Reserved public readonly uint reserved; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct RegionTableEntry { /// Object identifier public readonly Guid guid; /// Offset in image of the object public readonly ulong offset; /// Length in bytes of the object public readonly uint length; /// Flags public readonly uint flags; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct MetadataTableHeader { /// Signature public readonly ulong signature; /// Reserved public readonly ushort reserved; /// How many entries are in the table public readonly ushort entries; /// Reserved [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)] public readonly uint[] reserved2; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct MetadataTableEntry { /// Metadata ID public readonly Guid itemId; /// Offset relative to start of metadata region public readonly uint offset; /// Length in bytes public readonly uint length; /// Flags public readonly uint flags; /// Reserved public readonly uint reserved; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct FileParameters { /// Block size in bytes public uint blockSize; /// Flags public uint flags; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct ParentLocatorHeader { /// Type of parent virtual disk public readonly Guid locatorType; public readonly ushort reserved; /// How many KVPs are in this parent locator public readonly ushort keyValueCount; } [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct ParentLocatorEntry { /// Offset from metadata to key public readonly uint keyOffset; /// Offset from metadata to value public readonly uint valueOffset; /// Size of key public readonly ushort keyLength; /// Size of value public readonly ushort valueLength; } } }