dotfiles
dotfiles copied to clipboard
OpenVirtualDiskParameters structure is incorrect
The current implementation of the OpenVirtualDiskParameters structure is incorrect and will not work correctly for either VDH version. The correct structure is as follows:
[StructLayout( LayoutKind.Explicit, CharSet = CharSet.Unicode )]
public struct OpenVirtualDiskParameters
{
[FieldOffset( 0 )]
public OpenVirtualDiskVersion Version;
// Version 1
[FieldOffset( 4 )]
public UInt32 RWDepth;
// Version 2
[FieldOffset( 4 )]
public Int32 GetInfoOnly;
[FieldOffset( 8 )]
public Int32 ReadOnly;
[FieldOffset( 12 )]
public Guid ResiliencyGuid;
}
And in the Open(...) method, code needs to be changed to make use of the previously ignored readWriteDepth parameter as follows:
// Select the correct version.
openParams.Version = ( virtualStorageDeviceType == NativeMethods.VirtualStorageDeviceType.VHD ) ?
NativeMethods.OpenVirtualDiskVersion.Version1 :
NativeMethods.OpenVirtualDiskVersion.Version2;
if( openParams.Version == NativeMethods.OpenVirtualDiskVersion.Version1 )
{
openParams.RWDepth = readWriteDepth;
}
else
{
openParams.GetInfoOnly = 0;
openParams.ReadOnly = 0;
}