Skip to content

OpenVirtualDiskParameters structure is incorrect #2

@jtwine

Description

@jtwine

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions