VMware {code} Community
_nada_
Contributor
Contributor

Mount vstor2-mntapi20-shared volume to Windows folder

Hello,

using some examples provided by vmware, i'm able to mount a remote vmdk disk to Windows Drive Letter but i can't find a way to mount it to a Windows folder..

Tried with:

- SetVolumeMountPoint

     Where can i find the GUID of vstor2-mntapi20-shared symLink device?

- DefineDosDevice

     No success mounting to a folder

static void DoMntApi(VixDiskLibConnection connection, const char* disk, uint32 openFlags)

{

   printf("\nCalling VixMntapi_OpenDisks...\n");

   const char* diskNames[1];

   diskNames[0] = static_cast<const char*>(disk);

   VixDiskSetHandle diskSetHandle = NULL;

   VixError err = VixMntapi_OpenDisks(connection,

         diskNames,

         1,

         VIXDISKLIB_FLAG_OPEN_READ_ONLY,

         &diskSetHandle);

   if (VIX_FAILED(err)) {

      throw VixDiskLibErrWrapper(err, __FILE__, __LINE__);

   }

   DiskSetHdl dsh(diskSetHandle, VixMntapi_CloseDiskSet);

   printf("\nCalling VixMntapi_GetDiskSetInfo...\n");

   VixDiskSetInfo *diskSetInfo = NULL;

   err  = VixMntapi_GetDiskSetInfo(diskSetHandle, &diskSetInfo);

   if (VIX_FAILED(err)) {

      throw VixDiskLibErrWrapper(err, __FILE__, __LINE__);

   }

   DiskSetInfo dsi(diskSetInfo, VixMntapi_FreeDiskSetInfo);

   printf("DiskSet Info - flags %u (passed - %u), mountPoint %s.\n",

         diskSetInfo->openFlags, openFlags,

         diskSetInfo->mountPath);

   printf("\nCalling VixMntapi_GetVolumeHandles...\n");

   VixVolumeHandle *volumeHandles = NULL;

   size_t numVolumes = 0;

   err = VixMntapi_GetVolumeHandles(diskSetHandle,

         &numVolumes,

         &volumeHandles);

   if (VIX_FAILED(err)) {

      throw VixDiskLibErrWrapper(err, __FILE__, __LINE__);

   }

   VolumeHdls vh(volumeHandles, VixMntapi_FreeVolumeHandles);

   printf("Num Volumes %zd\n", numVolumes);

   printf("\nEnter the volume number from which to start the mounting: ");

   int j = 0;

   scanf("%d", &j);

   vector<shared_ptr<VolumeHdl> > vhset;

   vector<shared_ptr<VolumeInfo> > viset;

   for (int i = j-1; i < numVolumes; ++i) {

      printf("\nCalling VixMntapi_MountVolume on volume %d\n", i+1);

      err = VixMntapi_MountVolume(volumeHandles[i], TRUE);

      if (VIX_FAILED(err)) {

         VixDiskLibErrWrapper errWrap(err, __FILE__, __LINE__);

         cout << endl << "Error: " << errWrap.Description() << endl;

         continue;

      }

      VolumeHdl*a = new VolumeHdl(volumeHandles[i], VixMntapi_DismountVolume_True);

      vhset.push_back(shared_ptr<VolumeHdl>(a));

      printf("\nCalling VixMntapi_GetVolumeInfo on volume %d\n", i+1);

      VixVolumeInfo* volInfo = NULL;

      err = VixMntapi_GetVolumeInfo(volumeHandles[i], &volInfo);

      if (VIX_FAILED(err)) {

         VixDiskLibErrWrapper errWrap(err, __FILE__, __LINE__);

         cout << endl << "Error: " << errWrap.Description() << endl;

         continue;

      }

      viset.push_back(shared_ptr<VolumeInfo>(new VolumeInfo(volInfo, VixMntapi_FreeVolumeInfo)));

      printf("\nMounted Volume %d, Type %d, isMounted %d, symLink %s, numGuestMountPoints %zd (%s)\n\n",

            i+1, volInfo->type, volInfo->isMounted,

            volInfo->symbolicLink == NULL ? "<null>" : volInfo->symbolicLink,

            volInfo->numGuestMountPoints,

            (volInfo->numGuestMountPoints == 1) ? (volInfo->inGuestMountPoints[0]) : "<null>");

      /*

      *----------------------------------------------------------------------

      *

      * Mount Device to system unit

      *

      *----------------------------------------------------------------------

      */

      std::wstringstream ansiSS;

      ansiSS << volInfo->symbolicLink;

      std::wstring sVolumeName = ansiSS.str();

      sVolumeName = sVolumeName.substr(3);

      sVolumeName.erase(sVolumeName.length() - 1);

      sVolumeName = L"\\Device" + sVolumeName;

      cout << endl << endl << "Defining MS-DOS device name \"U:\" for volume " << volInfo->symbolicLink << endl;

      cout << "=====================================================================================" << endl;

/*

*

*

* MOUNT TO A FOLDER INSTEAD OF U: LETTER

*

*

*/

      if (DefineDosDeviceW(DDD_RAW_TARGET_PATH, L"U:", sVolumeName.c_str())) {

          HANDLE hDevice;

          std::wstring wsVolume = L"\\\\.\\U:";

          hDevice = CreateFileW(wsVolume.c_str(),

              GENERIC_READ,

              0, //FILE_SHARE_READ | FILE_SHARE_WRITE

              NULL,

              OPEN_EXISTING,

              FILE_ATTRIBUTE_NORMAL,

              NULL);

          if (hDevice == INVALID_HANDLE_VALUE) {

              printf("Error opening volume, err = %d\n", GetLastError());

          }

          else {

              WIN32_FIND_DATAW fdFile;

              std::wstring wsPath = L"U:\\*.*";

              HANDLE hFind = FindFirstFileW(wsPath.c_str(), &fdFile);

              std::string MountPoint = (volInfo->numGuestMountPoints == 1) ? (volInfo->inGuestMountPoints[0]) : "<null>";

              cout << "=====================================================================================" << endl;

              cout << "=== Dumping contents of target VM's (" << MountPoint << ") drive (Mounted at U: drive on proxy) ===" << endl;

              cout << "=====================================================================================" << endl;

              while (hFind != INVALID_HANDLE_VALUE) {

                  if (hFind != INVALID_HANDLE_VALUE) {

                      printf("Successfully read Object = '%S'\n", fdFile.cFileName);

                  }

                  else {

                      printf("Failed to read Object. Volume/NTFS filesystem is corrupt (%d)\n", GetLastError());

                  }

                  if (!FindNextFileW(hFind, &fdFile)) {

                      FindClose(hFind);

                      hFind = INVALID_HANDLE_VALUE;

                  }

              }

              ::MessageBoxW(NULL, L"Volume mounted under U: drive, press OK to unmount", L"Info", NULL);

              DefineDosDeviceW(DDD_RAW_TARGET_PATH |

                  DDD_REMOVE_DEFINITION |

                  DDD_EXACT_MATCH_ON_REMOVE, L"U:", sVolumeName.c_str());

          }

      }

   }

}

Is there a way to mount the vstor2 device to a folder?

Thanks,

Reply
0 Kudos
0 Replies