Using Windows VixMntapi
For someone not too familiar with Windows volumes and devices, vixMntapi is not the easiest API to use. I will try and walk through a few basic steps here - hopefully it will clarify a few things:
The motivation behind VixMntapi is simple, you have a virtual disk, and you want to know which files are inside this disk. You may want to take a backup, check for virus, whatever.
So, at the bare minimum, you want to provide VixMntapi a virtual disk and you get a drive letter corresponding to that disk - somewhat like pushing a USB stick into your computer.
OK, that may lead you to expect something like VixMntapi_Mount(diskname) which returns say a drive letter. However, things are not that simple because a disk can have multiple partitions (and volumes) and a volume can span multiple disks.
To handle such cases, VixMntapi has a concept of a diskset which is just a collection of disks. This is a way to associate many disks (all backing the same volume for example). You call VixMntapi_OpenDisks, providing a number of disks and you will get back a handle that represents the diskset.
As part of opening diskset, VixMntapi walks through the partition tables of all the disks and collects all the volumes (including logical). VixMntapi can also look at the LDM disk database and figure out the details of dynamic volumes if any.
You can get details of these volumes by calling VixMntapi_GetVolumeHandles and querying for volume information on each of these handles using VixMntapi_GetVolumeInformation (Don't forget to call the corresponding free functions.)
So far, the procedure did not involve any operating system component. This is possible because VixMntapi has code to parse the partition details as well as the LDM databases. In other words, these 'volume objects' of VixMntapi are strictly known only to the VixMntapi and not to the OS.
But just having volume information is not that useful, you want to read files from this volume. And for this you need to mount the volume - or somehow make these volumes known to ths OS. To do this, you call VixMntapi_MountVolume. VixMntapi then creates a Windows device object representing this volume. To do this, VixMntapi needs the services of a kernel mode driver (which is part of VDDK and is installed when you install VDDK). This is roughly the equivalent to plugging in a USB stick into your computer. A new volume appears.
From now on, various Windows storage stack components come into play, finally resulting in a volume that is exposed to user mode programs. If this volume is formatted with a file system, the file system driver will take ownership of the volume, if not the volume is simply a raw stream of bytes.
Since there are only a limited number of drive letters, VixMntapi does not map the volume to a drive letter. Instead, it gives the volume device object a name that can be accessed from the application. This is what you see as symbolic link in the Volume Information structure. (As the name shows, this is not the real volume name but an alias - the details are not that important).
Once you extract the symbolic link, you can for example use a function like DefineDosDevice to map the volume to a drive letter. Or you can simply use CreateFile to start reading from the volume. The following snippet is mounting a system volume and reading the file boot.ini in the root directory.
....
VixMntapi_MountVolume(volHandle, TRUE);
VixMntapi_GetVolumeInfo(volHandle, &volInfo);
string filePath = volInfo->symbolicLink + "boot.ini";
handle = CreateFile(filePath.c_str(), ....);
ReadFile(handle, ...)
....
Last year VStorage was described as including an API for storage partners to construct virtual appliances utilizing the underlying array's capabilities for snapshots, provisioning, etc. The concept seems like Citrix's new StorageLink system. Are there still plans to implement this type of capability, and how would a storage partner like us be able to work with you in this area?
Posted by: Rich | 08/27/2009 at 12:43 PM
Hi Rich,
I am not sure where this initiative is right now, can you talk to your VMware TAP contact for more details?
Thanks
Sudarsan
Posted by: Sudarsan Piduri | 08/27/2009 at 01:19 PM
Dear Sudarsan,
one thing: We need a program, that mounts the image to a folder, not a drive letter, exactly what vmware-mount under Linux does, but vmware-mount.exe under Windows does not. mountvm.exe from VCB is exactly what we need, but is not able to read vmfs images.
Do you know, why it is complicated to mount the image to a folder under Windows? This requirement is very important from our point of view:
1) Drive letters are limited (max 25)
2) Mounting logical volumes is much easier (see mountvm.exe)
THANK YOU FOR ANY HELP!
Ciao Andreas
Posted by: SBS | 09/22/2009 at 03:14 AM
Dear Sudarsan, another thing: I read your presentation "VDDK coffee talk", there are two points interesting:
vmware-mount always maps to a drive letter
You can remove the mapping using a Win32 program
Directly use the device name
Do you have a sample code of doing this?
Bye Andreas
Posted by: SBS | 09/22/2009 at 03:34 AM
Hi Andreas,
Thanks for your comments.
Two points of note:
1. Unlike on Linux, on Windows, vmware-mount does not have the capability to mount a disk - but it looks like a volume mount is what you want any way.
2. You can use DefineDosDevice of Win32 API to define or deletes MS-DOS device names (including drive letter).
I don't have sample code available right now.
Thanks
Sudarsan
Posted by: Sudarsan Piduri | 09/22/2009 at 10:03 AM
Thank you for your reply! Regards Andreas
Posted by: SBS | 09/23/2009 at 04:51 AM