Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenVirtualDiskParameters structure is incorrect #2

Open
jtwine opened this issue Aug 4, 2015 · 0 comments
Open

OpenVirtualDiskParameters structure is incorrect #2

jtwine opened this issue Aug 4, 2015 · 0 comments

Comments

@jtwine
Copy link

jtwine commented Aug 4, 2015

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant