|
Hi Hari,
Kinda looks like you are breaking the rules of nearly everything in the Remarks section for the OpenVirtualDisk function for a permanently attached virtual disk.
This is working for me, code is ugly, there is no error handling... it's just a code sample:
#include <iostream>
#include <windows.h>
#include <virtdisk.h>
#include <tchar.h>
#include <comdef.h>
#include <atlcomcli.h>
#include <wbemidl.h>
#pragma comment(lib, "wbemuuid.lib")
#pragma comment(lib, "virtdisk.lib")
const GUID VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT = {0xec984aec, 0xa0f9, 0x47e9, 0x90, 0x1f, 0x71, 0x41, 0x5a, 0x66, 0x34, 0x5b};
const GUID VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN = { 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int main()
{
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"D:\\VirtualMachines\\x64_Windows8.1\\x64_Windows8.1\\Virtual Hard Disks\\x64_Windows8.1.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);
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);
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);
}
}
return 0;
}
Best Wishes,
-Rubeus Hagrid
|
|
|
|
|
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
|
|
|
|
|
cazorla19 wrote: OpenVirtualDisk failed with 32 ERROR_SHARING_VIOLATION.
That obviously means that the virtual disk is locked/mounted and being used by another process. Are you trying to read the change tracking on running Hyper-V virtual machine? I don't think you can do that.
|
|
|
|
|
Yes, I am trying to read the change tracking information when the Virtual machine is online.
|
|
|
|
|
Ok,
If you can't read the change tracking information from an Administrator account with both SE_BACKUP_NAME and SE_MANAGE_VOLUME_NAME privileges then I don't think it will be possible. Also since the virtual drive is mounted you should change the access mask from VIRTUAL_DISK_ACCESS_ATTACH_RW to VIRTUAL_DISK_ACCESS_ATTACH_RO.
I am actually in a Hyper-V environment right now so if I get some time later today I will look into it more. The code sample I gave you is working for me on my offline virtual machines.
Best Wishes,
-David Delaune
|
|
|
|
|
hi, have you resolve the problem?
|
|
|
|
|
How can I convert AAC file Wav file using C++ and Microsoft Media Foundation?
|
|
|
|
|
Study the documentation for the two file types. Then study the documentation for the framework you plan to use.
|
|
|
|
|
|
I need to initialize a 3rd party library when doing some/most of our unit tests.
We have a working homemade framework with an entry point (_tmain) where we can do all initialization for all our tests.
I can't seem to find the equivalent with CppUnitTestFramework.
I don't want to add a wrapper to do the 3rd party library initialization for each unit test.
Can I do such a thing ?
Thanks.
I'd rather be phishing!
|
|
|
|
|
|
Thanks,
I will look into it, but it seems to be run for each test and is not global to all my test cases and test classes. ?
"Defines methodName as a method that runs before each test method is run. TEST_METHOD_INITIALIZE can only be defined once in a test class and must be defined in the scope of the test class."
I'd rather be phishing!
|
|
|
|
|
An engineer stores a FIFO queue of bit in an int on a platform with 32bit ints and 8-bit chars using the following C++ class
Class bit queue{
Int valid_bits;
Int queue;
Public:
Bitqueue(): valid_bits(0), queue(0) {}
Void push(int val, int bsize);
Int pop(int bsize);
Int size();
};
1.Write implementation of bitqueue::size which should return the number of bits currently held in queue
2.Write an implementation of bitqueue::push which places the bsize least significant bits from val onto queue and update valid bits. An exception should be thrown in cases where data would otherwise be lost.
3.Write an implementation of bitqueue::pop which takes bsize bits from queue, provides them as the bsize least significant bits in the return value and updated valid bits. An exception should be thrown when any requested data is unavailable.
|
|
|
|
|
We do not do people's homework.
The idea of homework is to improve your understanding and skills. Having someone else do it for you misses the point, and gives your instructor and anyone else looking at your grades a false idea of your competence.
Try to solve the problem on your own. If you run into problems, come back, post your code, and ask how to solve the specific problem that you are having with your code. You will then find that people are happy to help you.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I don't know where this came from, but it needs correcting before you start. The terms Class, Int, Public and Void are all incorrectly spelled. The correct forms are class , int , public and void ; all lower case. Also the class definition is incorrect. You have Class bit queue , but class names are only one word. You also name the constructor Bitqueue , which may or may not match the correct class name. So there is really a lot to learn before you can venture into trying to solve this question.
|
|
|
|
|
You can help me gird line opengl cli I got it
|
|
|
|
|
Is it a question or an assertion?
|
|
|
|
|
|
|
What code?
|
|
|
|
|
|
|
|
SADEGH2077 wrote: yes
|
|
|
|
|
How do I project OpenGLApplication With cli I write
|
|
|
|
|