2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Structs.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.DiscImages
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed partial class Vhdx
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct Identifier
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Signature, <see cref="Vhdx.VHDX_SIGNATURE" /></summary>
|
|
|
|
|
|
public readonly ulong signature;
|
|
|
|
|
|
/// <summary>UTF-16 string containing creator</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly byte[] creator;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable 649
|
|
|
|
|
|
#pragma warning disable 169
|
2020-11-11 04:19:18 +00:00
|
|
|
|
struct Header
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Signature, <see cref="Vhdx.VHDX_HEADER_SIG" /></summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public uint Signature;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>CRC-32C of whole 4096 bytes header with this field set to 0</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public uint Checksum;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Sequence number</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public ulong Sequence;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Unique identifier for file contents, must be changed on first write to metadata</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public Guid FileWriteGuid;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Unique identifier for disk contents, must be changed on first write to metadata or data</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public Guid DataWriteGuid;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Unique identifier for log entries</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public Guid LogGuid;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Version of log format</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public ushort LogVersion;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Version of VHDX format</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public ushort Version;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Length in bytes of the log</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public uint LogLength;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Offset from image start to the log</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public ulong LogOffset;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4016)]
|
|
|
|
|
|
public byte[] Reserved;
|
|
|
|
|
|
}
|
|
|
|
|
|
#pragma warning restore 649
|
|
|
|
|
|
#pragma warning restore 169
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct RegionTableHeader
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Signature, <see cref="Vhdx.VHDX_REGION_SIG" /></summary>
|
|
|
|
|
|
public readonly uint signature;
|
|
|
|
|
|
/// <summary>CRC-32C of whole 64Kb table with this field set to 0</summary>
|
|
|
|
|
|
public readonly uint checksum;
|
|
|
|
|
|
/// <summary>How many entries follow this table</summary>
|
|
|
|
|
|
public readonly uint entries;
|
|
|
|
|
|
/// <summary>Reserved</summary>
|
|
|
|
|
|
public readonly uint reserved;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct RegionTableEntry
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Object identifier</summary>
|
|
|
|
|
|
public readonly Guid guid;
|
|
|
|
|
|
/// <summary>Offset in image of the object</summary>
|
|
|
|
|
|
public readonly ulong offset;
|
|
|
|
|
|
/// <summary>Length in bytes of the object</summary>
|
|
|
|
|
|
public readonly uint length;
|
|
|
|
|
|
/// <summary>Flags</summary>
|
|
|
|
|
|
public readonly uint flags;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct MetadataTableHeader
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Signature</summary>
|
|
|
|
|
|
public readonly ulong signature;
|
|
|
|
|
|
/// <summary>Reserved</summary>
|
|
|
|
|
|
public readonly ushort reserved;
|
|
|
|
|
|
/// <summary>How many entries are in the table</summary>
|
|
|
|
|
|
public readonly ushort entries;
|
|
|
|
|
|
/// <summary>Reserved</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
|
2020-02-29 18:03:35 +00:00
|
|
|
|
public readonly uint[] reserved2;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct MetadataTableEntry
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Metadata ID</summary>
|
|
|
|
|
|
public readonly Guid itemId;
|
|
|
|
|
|
/// <summary>Offset relative to start of metadata region</summary>
|
|
|
|
|
|
public readonly uint offset;
|
|
|
|
|
|
/// <summary>Length in bytes</summary>
|
|
|
|
|
|
public readonly uint length;
|
|
|
|
|
|
/// <summary>Flags</summary>
|
|
|
|
|
|
public readonly uint flags;
|
|
|
|
|
|
/// <summary>Reserved</summary>
|
|
|
|
|
|
public readonly uint reserved;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
struct FileParameters
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Block size in bytes</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public uint blockSize;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Flags</summary>
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public uint flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct ParentLocatorHeader
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Type of parent virtual disk</summary>
|
|
|
|
|
|
public readonly Guid locatorType;
|
|
|
|
|
|
public readonly ushort reserved;
|
|
|
|
|
|
/// <summary>How many KVPs are in this parent locator</summary>
|
|
|
|
|
|
public readonly ushort keyValueCount;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
2020-11-11 04:19:18 +00:00
|
|
|
|
readonly struct ParentLocatorEntry
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
|
/// <summary>Offset from metadata to key</summary>
|
|
|
|
|
|
public readonly uint keyOffset;
|
|
|
|
|
|
/// <summary>Offset from metadata to value</summary>
|
|
|
|
|
|
public readonly uint valueOffset;
|
|
|
|
|
|
/// <summary>Size of key</summary>
|
|
|
|
|
|
public readonly ushort keyLength;
|
|
|
|
|
|
/// <summary>Size of value</summary>
|
|
|
|
|
|
public readonly ushort valueLength;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|