Click here to Skip to main content
14,663,756 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1914-Aug-20 3:30
Membercazorla1914-Aug-20 3:30 
AnswerRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Gerry Schmitz14-Aug-20 5:04
mveGerry Schmitz14-Aug-20 5:04 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1918-Aug-20 0:57
Membercazorla1918-Aug-20 0:57 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Gerry Schmitz18-Aug-20 5:34
mveGerry Schmitz18-Aug-20 5:34 
AnswerRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 14-Aug-20 8:54
professional Randor 14-Aug-20 8:54 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1918-Aug-20 0:55
Membercazorla1918-Aug-20 0:55 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 19-Aug-20 19:04
professional Randor 19-Aug-20 19:04 
QuestionRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1919-Aug-20 20:26
Membercazorla1919-Aug-20 20:26 
Many thanks for your inputs.
Tried your sample code in my environment, OpenVirtualDisk failed with 32 ERROR_SHARING_VIOLATION.

Steps I have followed till now,
1. Create a production snapshot on the VM.
2. Convert the snapshot to the reference point(snapshot gets merged automatically) using wmi commands.
3. Added some files to VM disk.
4. Create another production snapshot on the VM so that any changes in VM will be written to avhdx file.
5. Try to open the parent vhdx using VHD APIs.
6. Get a resilient change tracking identifier using ChangeTrackingState.MostRecentId
7. Query for changed areas using VHD API QueryChangesVirtualDisk.

So far I am able to get till step six by passing only VIRTUAL_DISK_ACCESS_GET_INFO flag for OpenVirtualDisk. step 7 gives ACCESS_DENIED.


void openDiskEx()
{
    HANDLE vhdHandle = NULL;
    VIRTUAL_STORAGE_TYPE storageType = {};
    ULONG  status = 0L;

    storageType.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN;
    storageType.VendorId = VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN;

    PCWSTR virtualDiskPath = L"C:\\Hyper-V\\Virtual Hard Disks\\Lacazette\\Windows2016.vhdx";

    OPEN_VIRTUAL_DISK_PARAMETERS* pOpenParameter = NULL;

    status = OpenVirtualDisk(&storageType, virtualDiskPath, VIRTUAL_DISK_ACCESS_ATTACH_RW | VIRTUAL_DISK_ACCESS_GET_INFO | VIRTUAL_DISK_ACCESS_DETACH, OPEN_VIRTUAL_DISK_FLAG_NONE, pOpenParameter, &vhdHandle);
    std::cout << "opendisk:" << status<< std::endl;
    if (ERROR_SUCCESS == status)
    {
        DWORD sizeUsed = GET_VIRTUAL_DISK_INFO_SIZE;
        WCHAR changeTrackingInfo[sizeof(GET_VIRTUAL_DISK_INFO) + sizeof(GUID)];
        ::ZeroMemory(changeTrackingInfo, sizeof(changeTrackingInfo));
        PGET_VIRTUAL_DISK_INFO virtualDiskInfo = (GET_VIRTUAL_DISK_INFO*)changeTrackingInfo;
        virtualDiskInfo->Version = (GET_VIRTUAL_DISK_INFO_VERSION)GET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE;
        ULONG virtualDiskInfoSize = sizeof(changeTrackingInfo);

        status = GetVirtualDiskInformation(vhdHandle, &virtualDiskInfoSize, virtualDiskInfo, &sizeUsed);
        std::cout << "GetVirtualDiskInformation:" << status << std::endl;
        if (ERROR_SUCCESS == status)
        {
            ULONG64 virtualDiskSize = virtualDiskInfo->Size.VirtualSize;
            printf("Disk Infomation:\n");
            GUID virtualDiskGuid = virtualDiskInfo->Identifier;
            wchar_t szGUID[64] = { 0 };
            StringFromGUID2(virtualDiskGuid, szGUID, 64);
            wprintf(L"ChangeTrackingState.Enabled:%d\n", virtualDiskInfo->ChangeTrackingState.Enabled);
            wprintf(L"ChangeTrackingState.MostRecentId:%s\n", virtualDiskInfo->ChangeTrackingState.MostRecentId);
            wprintf(L"Identifier\t= %s\n", szGUID);
            wprintf(L"Physical Size\t= %I64u\n", virtualDiskInfo->Size.PhysicalSize);
            wprintf(L"Virtual Size\t= %I64u\n", virtualDiskInfo->Size.VirtualSize);
            wprintf(L"Sector Size\t= %u\n", virtualDiskInfo->Size.SectorSize);
            wprintf(L"Block Size\t= %u\n", virtualDiskInfo->Size.BlockSize);
        }
    }
    CloseHandle(vhdHandle);
}


Regards,
Hari
AnswerRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 19-Aug-20 20:57
professional Randor 19-Aug-20 20:57 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1919-Aug-20 21:29
Membercazorla1919-Aug-20 21:29 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 19-Aug-20 21:47
professional Randor 19-Aug-20 21:47 
QuestionMicrosoft Media Foundation AAC Decoder using C++ Pin
sabid12-Aug-20 18:32
Membersabid12-Aug-20 18:32 
AnswerRe: Microsoft Media Foundation AAC Decoder using C++ Pin
Richard MacCutchan12-Aug-20 21:04
mveRichard MacCutchan12-Aug-20 21:04 
AnswerRe: Microsoft Media Foundation AAC Decoder using C++ Pin
11917640 Member 2-Sep-20 1:06
Member11917640 Member 2-Sep-20 1:06 
QuestionIs there an entry point for CppUnitTestFramework unit tests ? Pin
Maximilien11-Aug-20 10:01
MemberMaximilien11-Aug-20 10:01 
AnswerRe: Is there an entry point for CppUnitTestFramework unit tests ? Pin
Richard MacCutchan11-Aug-20 22:23
mveRichard MacCutchan11-Aug-20 22:23 
GeneralRe: Is there an entry point for CppUnitTestFramework unit tests ? Pin
Maximilien12-Aug-20 7:31
MemberMaximilien12-Aug-20 7:31 
Questioncomputer science Pin
Member 1491094810-Aug-20 0:26
MemberMember 1491094810-Aug-20 0:26 
AnswerRe: computer science Pin
Daniel Pfeffer10-Aug-20 0:45
professionalDaniel Pfeffer10-Aug-20 0:45 
AnswerRe: computer science Pin
Richard MacCutchan10-Aug-20 3:24
mveRichard MacCutchan10-Aug-20 3:24 
Questionsorce code grid line Pin
SADEGH20771-Aug-20 7:44
MemberSADEGH20771-Aug-20 7:44 
AnswerRe: sorce code grid line Pin
Victor Nijegorodov1-Aug-20 8:15
MemberVictor Nijegorodov1-Aug-20 8:15 
GeneralRe: sorce code grid line Pin
SADEGH20771-Aug-20 8:24
MemberSADEGH20771-Aug-20 8:24 
GeneralRe: sorce code grid line Pin
SADEGH20771-Aug-20 8:25
MemberSADEGH20771-Aug-20 8:25 
GeneralRe: sorce code grid line Pin
Victor Nijegorodov1-Aug-20 8:32
MemberVictor Nijegorodov1-Aug-20 8:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.