Sample VixMntapi Code

You call the VixMntapi functions after initializing VixDiskLib, connecting to a virtual machine, and opening a disk handle. The following example shows test code for Windows with the correct order of function calls.

MountTest() {
     vixError = VIX_ERR_CODE(VixDiskLib_Init() );
     vixError = VIX_ERR_CODE(VixMntapi_Init() );
     VixDiskLib_ConnectEx(&connectParams, TRUE, NULL, NULL, &connection));
     diskHandles = GetMyDiskHandles(diskPaths, connection, &connectParams, flags, &numberOfDisks);
     vixError = VIX_ERR_CODE(VixMntapi_OpenDiskSet(diskHandles, numberOfDisks, flags, &diskSet));
     GetOsInfo(diskSet);
     vixError = VIX_ERR_CODE(VixMntapi_GetVolumeHandles(diskSet, &numberOfVolumes, &volumeHandles));
     for(size_t i = 0; i < numberOfVolumes; i++) {
          VixVolumeHandle volumeHandle = volumeHandles[i];
          VixVolumeInfo *volumeInfo;
          vixError = VIX_ERR_CODE( VixMntapi_MountVolume(volumeHandle, TRUE) );
          vixError = VIX_ERR_CODE( VixMntapi_GetVolumeInfo(volumeHandle, &volumeInfo) );
          VixMntapi_FreeVolumeInfo(volumeInfo);
          VerifyMountedVolume();
          CleanUpMountedVolume(volumeHandle, volumeInfo);
     }
     VixMntapi_FreeVolumeHandles(volumeHandles);
     vixError = VIX_ERR_CODE( VixMntapi_CloseDiskSet(diskSet) );
     FreeMyDiskHandles(diskHandles, numberOfDisks);
     VixMntapi_Exit();
     VixDiskLib_Exit();
}