[Aaru.Images] Reformat and cleanup.

This commit is contained in:
2023-10-03 23:34:59 +01:00
parent 6ffde343ce
commit 2cfad87955
432 changed files with 12011 additions and 8261 deletions

View File

@@ -37,6 +37,21 @@ namespace Aaru.DiscImages;
[SuppressMessage("ReSharper", "UnusedMember.Local")]
public sealed partial class Vdi
{
#region Nested type: VdiImageFlags
enum VdiImageFlags : uint
{
/// <summary>
/// Fill new blocks with zeroes while expanding image file. Only valid for newly created images, never set for
/// opened existing images.
/// </summary>
ZeroExpand = 0x100
}
#endregion
#region Nested type: VdiImageType
enum VdiImageType : uint
{
/// <summary> Normal dynamically growing base image file.</summary>
@@ -54,12 +69,5 @@ public sealed partial class Vdi
Last = Differential
}
enum VdiImageFlags : uint
{
/// <summary>
/// Fill new blocks with zeroes while expanding image file. Only valid for newly created images, never set for
/// opened existing images.
/// </summary>
ZeroExpand = 0x100
}
#endregion
}

View File

@@ -38,6 +38,8 @@ namespace Aaru.DiscImages;
public sealed partial class Vdi
{
#region IWritableImage Members
/// <inheritdoc />
public bool Identify(IFilter imageFilter)
{
@@ -47,10 +49,12 @@ public sealed partial class Vdi
if(stream.Length < 512)
return false;
byte[] vHdrB = new byte[Marshal.SizeOf<Header>()];
var vHdrB = new byte[Marshal.SizeOf<Header>()];
stream.EnsureRead(vHdrB, 0, Marshal.SizeOf<Header>());
_vHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(vHdrB);
return _vHdr.magic == VDI_MAGIC;
}
#endregion
}

View File

@@ -41,25 +41,35 @@ namespace Aaru.DiscImages;
public sealed partial class Vdi
{
#region IWritableImage Members
/// <inheritdoc />
public ImageInfo Info => _imageInfo;
/// <inheritdoc />
public string Name => Localization.Vdi_Name;
/// <inheritdoc />
public Guid Id => new("E314DE35-C103-48A3-AD36-990F68523C46");
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
/// <inheritdoc />
public string Format => "VDI";
/// <inheritdoc />
public List<DumpHardware> DumpHardware => null;
/// <inheritdoc />
public Metadata AaruMetadata => null;
/// <inheritdoc />
public IEnumerable<MediaTagType> SupportedMediaTags => Array.Empty<MediaTagType>();
/// <inheritdoc />
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public IEnumerable<MediaType> SupportedMediaTypes => new[]
{
@@ -72,13 +82,15 @@ public sealed partial class Vdi
/// <inheritdoc />
public IEnumerable<(string name, Type type, string description, object @default)> SupportedOptions =>
Array.Empty<(string name, Type type, string description, object @default)>();
/// <inheritdoc />
public IEnumerable<string> KnownExtensions => new[]
{
".vdi"
};
public IEnumerable<string> KnownExtensions => new[] { ".vdi" };
/// <inheritdoc />
public bool IsWriting { get; private set; }
/// <inheritdoc />
public string ErrorMessage { get; private set; }
#endregion
}

View File

@@ -46,6 +46,8 @@ namespace Aaru.DiscImages;
public sealed partial class Vdi
{
#region IWritableImage Members
/// <inheritdoc />
public ErrorNumber Open(IFilter imageFilter)
{
@@ -55,38 +57,38 @@ public sealed partial class Vdi
if(stream.Length < 512)
return ErrorNumber.InvalidArgument;
byte[] vHdrB = new byte[Marshal.SizeOf<Header>()];
var vHdrB = new byte[Marshal.SizeOf<Header>()];
stream.EnsureRead(vHdrB, 0, Marshal.SizeOf<Header>());
_vHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(vHdrB);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.creator = {0}", _vHdr.creator);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.magic = {0}", _vHdr.magic);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.magic = {0}", _vHdr.magic);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.version = {0}.{1}", _vHdr.majorVersion,
_vHdr.minorVersion);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.headerSize = {0}", _vHdr.headerSize);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.imageType = {0}", _vHdr.imageType);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.imageFlags = {0}", _vHdr.imageFlags);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.description = {0}", _vHdr.comments);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.offsetBlocks = {0}", _vHdr.offsetBlocks);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.offsetData = {0}", _vHdr.offsetData);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.cylinders = {0}", _vHdr.cylinders);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.heads = {0}", _vHdr.heads);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.spt = {0}", _vHdr.spt);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.sectorSize = {0}", _vHdr.sectorSize);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.size = {0}", _vHdr.size);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.blockSize = {0}", _vHdr.blockSize);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.blockExtraData = {0}", _vHdr.blockExtraData);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.blocks = {0}", _vHdr.blocks);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.allocatedBlocks = {0}", _vHdr.allocatedBlocks);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.uuid = {0}", _vHdr.uuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.snapshotUuid = {0}", _vHdr.snapshotUuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.linkUuid = {0}", _vHdr.linkUuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.parentUuid = {0}", _vHdr.parentUuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.logicalCylinders = {0}", _vHdr.logicalCylinders);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.logicalHeads = {0}", _vHdr.logicalHeads);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.logicalSpt = {0}", _vHdr.logicalSpt);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.headerSize = {0}", _vHdr.headerSize);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.imageType = {0}", _vHdr.imageType);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.imageFlags = {0}", _vHdr.imageFlags);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.description = {0}", _vHdr.comments);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.offsetBlocks = {0}", _vHdr.offsetBlocks);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.offsetData = {0}", _vHdr.offsetData);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.cylinders = {0}", _vHdr.cylinders);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.heads = {0}", _vHdr.heads);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.spt = {0}", _vHdr.spt);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.sectorSize = {0}", _vHdr.sectorSize);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.size = {0}", _vHdr.size);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.blockSize = {0}", _vHdr.blockSize);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.blockExtraData = {0}", _vHdr.blockExtraData);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.blocks = {0}", _vHdr.blocks);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.allocatedBlocks = {0}", _vHdr.allocatedBlocks);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.uuid = {0}", _vHdr.uuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.snapshotUuid = {0}", _vHdr.snapshotUuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.linkUuid = {0}", _vHdr.linkUuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.parentUuid = {0}", _vHdr.parentUuid);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.logicalCylinders = {0}", _vHdr.logicalCylinders);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.logicalHeads = {0}", _vHdr.logicalHeads);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.logicalSpt = {0}", _vHdr.logicalSpt);
AaruConsole.DebugWriteLine(MODULE_NAME, "vHdr.logicalSectorSize = {0}", _vHdr.logicalSectorSize);
if(_vHdr.imageType != VdiImageType.Normal)
@@ -101,7 +103,7 @@ public sealed partial class Vdi
blockMapStopwatch.Start();
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Reading_Image_Block_Map);
stream.Seek(_vHdr.offsetBlocks, SeekOrigin.Begin);
byte[] ibmB = new byte[_vHdr.blocks * 4];
var ibmB = new byte[_vHdr.blocks * 4];
stream.EnsureRead(ibmB, 0, ibmB.Length);
_ibm = MemoryMarshal.Cast<byte, uint>(ibmB).ToArray();
blockMapStopwatch.Stop();
@@ -221,9 +223,9 @@ public sealed partial class Vdi
return ErrorNumber.NoError;
}
ulong imageOff = _vHdr.offsetData + ((ulong)ibmOff * _vHdr.blockSize);
ulong imageOff = _vHdr.offsetData + (ulong)ibmOff * _vHdr.blockSize;
byte[] cluster = new byte[_vHdr.blockSize];
var cluster = new byte[_vHdr.blockSize];
_imageStream.Seek((long)imageOff, SeekOrigin.Begin);
_imageStream.EnsureRead(cluster, 0, (int)_vHdr.blockSize);
buffer = new byte[_vHdr.sectorSize];
@@ -264,4 +266,6 @@ public sealed partial class Vdi
return ErrorNumber.NoError;
}
#endregion
}

View File

@@ -37,6 +37,8 @@ namespace Aaru.DiscImages;
public sealed partial class Vdi
{
#region Nested type: Header
/// <summary>VDI disk image header, little-endian</summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Header
@@ -74,4 +76,6 @@ public sealed partial class Vdi
public uint logicalSpt;
public readonly uint logicalSectorSize;
}
#endregion
}

View File

@@ -36,6 +36,8 @@ namespace Aaru.DiscImages;
public sealed partial class Vdi
{
#region IWritableImage Members
/// <inheritdoc />
public ErrorNumber ReadSectorTag(ulong sectorAddress, SectorTagType tag, out byte[] buffer)
{
@@ -75,4 +77,6 @@ public sealed partial class Vdi
return ErrorNumber.NotSupported;
}
#endregion
}

View File

@@ -44,6 +44,7 @@ namespace Aaru.DiscImages;
/// <summary>Implements reading and writing VirtualBox disk images</summary>
public sealed partial class Vdi : IWritableImage
{
const string MODULE_NAME = "VirtualBox plugin";
ulong _currentWritingPosition;
uint[] _ibm;
ImageInfo _imageInfo;
@@ -75,6 +76,4 @@ public sealed partial class Vdi : IWritableImage
DriveSerialNumber = null,
DriveFirmwareRevision = null
};
const string MODULE_NAME = "VirtualBox plugin";
}

View File

@@ -46,9 +46,11 @@ namespace Aaru.DiscImages;
public sealed partial class Vdi
{
#region IWritableImage Members
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize)
uint sectorSize)
{
if(sectorSize != 512)
{
@@ -89,12 +91,12 @@ public sealed partial class Vdi
return false;
}
uint ibmEntries = (uint)(sectors * sectorSize / DEFAULT_BLOCK_SIZE);
var ibmEntries = (uint)(sectors * sectorSize / DEFAULT_BLOCK_SIZE);
if(sectors * sectorSize % DEFAULT_BLOCK_SIZE > 0)
ibmEntries++;
uint headerSectors = 1 + (ibmEntries * 4 / sectorSize);
uint headerSectors = 1 + ibmEntries * 4 / sectorSize;
if(ibmEntries * 4 % sectorSize != 0)
headerSectors++;
@@ -178,10 +180,10 @@ public sealed partial class Vdi
_vHdr.allocatedBlocks++;
}
ulong imageOff = _vHdr.offsetData + ((ulong)ibmOff * _vHdr.blockSize);
ulong imageOff = _vHdr.offsetData + (ulong)ibmOff * _vHdr.blockSize;
_writingStream.Seek((long)imageOff, SeekOrigin.Begin);
_writingStream.Seek((long)secOff, SeekOrigin.Current);
_writingStream.Seek((long)secOff, SeekOrigin.Current);
_writingStream.Write(data, 0, data.Length);
ErrorMessage = "";
@@ -220,7 +222,7 @@ public sealed partial class Vdi
for(uint i = 0; i < length; i++)
{
byte[] tmp = new byte[_imageInfo.SectorSize];
var tmp = new byte[_imageInfo.SectorSize];
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
if(!WriteSector(tmp, sectorAddress + i))
@@ -285,8 +287,8 @@ public sealed partial class Vdi
}
}
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
var hdr = new byte[Marshal.SizeOf<Header>()];
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
System.Runtime.InteropServices.Marshal.StructureToPtr(_vHdr, hdrPtr, true);
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
@@ -345,4 +347,6 @@ public sealed partial class Vdi
/// <inheritdoc />
public bool SetMetadata(Metadata metadata) => false;
#endregion
}