Changeset 75380 in vbox for trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
- Timestamp:
- Nov 9, 2018 10:25:30 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r75361 r75380 1516 1516 //static 1517 1517 const char *Console::sSSMConsoleUnit = "ConsoleData"; 1518 //static 1519 uint32_t Console::sSSMConsoleVer = 0x00010001; 1518 /** The saved state version. */ 1519 #define CONSOLE_SAVED_STATE_VERSION UINT32_C(0x00010002) 1520 /** The saved state version, pre shared folder autoMountPoint. */ 1521 #define CONSOLE_SAVED_STATE_VERSION_PRE_AUTO_MOUNT_POINT UINT32_C(0x00010001) 1520 1522 1521 1523 inline static const char *networkAdapterTypeToName(NetworkAdapterType_T adapterType) … … 1569 1571 uint32_t version = 0; 1570 1572 vrc = SSMR3Seek(ssm, sSSMConsoleUnit, 0 /* iInstance */, &version); 1571 if (SSM_VERSION_MAJOR(version) == SSM_VERSION_MAJOR( sSSMConsoleVer))1573 if (SSM_VERSION_MAJOR(version) == SSM_VERSION_MAJOR(CONSOLE_SAVED_STATE_VERSION)) 1572 1574 { 1573 1575 if (RT_SUCCESS(vrc)) … … 1614 1616 AutoReadLock alock(that COMMA_LOCKVAL_SRC_POS); 1615 1617 1616 int vrc = SSMR3PutU32(pSSM, (uint32_t)that->m_mapSharedFolders.size()); 1617 AssertRC(vrc); 1618 SSMR3PutU32(pSSM, (uint32_t)that->m_mapSharedFolders.size()); 1618 1619 1619 1620 for (SharedFolderMap::const_iterator it = that->m_mapSharedFolders.begin(); … … 1625 1626 AutoReadLock sfLock(pSF COMMA_LOCKVAL_SRC_POS); 1626 1627 1627 Utf8Str name = pSF->i_getName(); 1628 vrc = SSMR3PutU32(pSSM, (uint32_t)name.length() + 1 /* term. 0 */); 1629 AssertRC(vrc); 1630 vrc = SSMR3PutStrZ(pSSM, name.c_str()); 1631 AssertRC(vrc); 1632 1633 Utf8Str hostPath = pSF->i_getHostPath(); 1634 vrc = SSMR3PutU32(pSSM, (uint32_t)hostPath.length() + 1 /* term. 0 */); 1635 AssertRC(vrc); 1636 vrc = SSMR3PutStrZ(pSSM, hostPath.c_str()); 1637 AssertRC(vrc); 1638 1639 vrc = SSMR3PutBool(pSSM, !!pSF->i_isWritable()); 1640 AssertRC(vrc); 1641 1642 vrc = SSMR3PutBool(pSSM, !!pSF->i_isAutoMounted()); 1643 AssertRC(vrc); 1644 } 1645 1646 return; 1628 const Utf8Str &name = pSF->i_getName(); 1629 SSMR3PutU32(pSSM, (uint32_t)name.length() + 1 /* term. 0 */); 1630 SSMR3PutStrZ(pSSM, name.c_str()); 1631 1632 const Utf8Str &hostPath = pSF->i_getHostPath(); 1633 SSMR3PutU32(pSSM, (uint32_t)hostPath.length() + 1 /* term. 0 */); 1634 SSMR3PutStrZ(pSSM, hostPath.c_str()); 1635 1636 SSMR3PutBool(pSSM, !!pSF->i_isWritable()); 1637 SSMR3PutBool(pSSM, !!pSF->i_isAutoMounted()); 1638 1639 const Utf8Str &rStrAutoMountPoint = pSF->i_getAutoMountPoint(); 1640 SSMR3PutU32(pSSM, (uint32_t)rStrAutoMountPoint.length() + 1 /* term. 0 */); 1641 SSMR3PutStrZ(pSSM, rStrAutoMountPoint.c_str()); 1642 } 1647 1643 } 1648 1644 … … 1665 1661 LogFlowFunc(("\n")); 1666 1662 1667 if (SSM_VERSION_MAJOR_CHANGED(uVersion, sSSMConsoleVer))1663 if (SSM_VERSION_MAJOR_CHANGED(uVersion, CONSOLE_SAVED_STATE_VERSION)) 1668 1664 return VERR_VERSION_MISMATCH; 1669 1665 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass); … … 1706 1702 bool autoMount = false; 1707 1703 1708 uint32_t szBuf= 0;1704 uint32_t cbStr = 0; 1709 1705 char *buf = NULL; 1710 1706 1711 vrc = SSMR3GetU32(pSSM, & szBuf);1707 vrc = SSMR3GetU32(pSSM, &cbStr); 1712 1708 AssertRCReturn(vrc, vrc); 1713 buf = new char[ szBuf];1714 vrc = SSMR3GetStrZ(pSSM, buf, szBuf);1709 buf = new char[cbStr]; 1710 vrc = SSMR3GetStrZ(pSSM, buf, cbStr); 1715 1711 AssertRC(vrc); 1716 1712 strName = buf; 1717 1713 delete[] buf; 1718 1714 1719 vrc = SSMR3GetU32(pSSM, & szBuf);1715 vrc = SSMR3GetU32(pSSM, &cbStr); 1720 1716 AssertRCReturn(vrc, vrc); 1721 buf = new char[ szBuf];1722 vrc = SSMR3GetStrZ(pSSM, buf, szBuf);1717 buf = new char[cbStr]; 1718 vrc = SSMR3GetStrZ(pSSM, buf, cbStr); 1723 1719 AssertRC(vrc); 1724 1720 strHostPath = buf; 1725 1721 delete[] buf; 1726 1722 1727 if (u32Version > 0x00010000)1723 if (u32Version >= CONSOLE_SAVED_STATE_VERSION_PRE_AUTO_MOUNT_POINT) 1728 1724 SSMR3GetBool(pSSM, &writable); 1729 1725 1730 if (u32Version > 0x00010000) // ??? 1726 if ( u32Version >= CONSOLE_SAVED_STATE_VERSION_PRE_AUTO_MOUNT_POINT 1727 #ifndef VBOX_OSE /* This broke saved state when introduced in r63916 (4.0). */ 1728 && SSMR3HandleRevision(pSSM) >= 63916 1729 #endif 1730 ) 1731 1731 SSMR3GetBool(pSSM, &autoMount); 1732 1733 Utf8Str strAutoMountPoint; 1734 if (u32Version >= CONSOLE_SAVED_STATE_VERSION) 1735 { 1736 vrc = SSMR3GetU32(pSSM, &cbStr); 1737 AssertRCReturn(vrc, vrc); 1738 vrc = strAutoMountPoint.reserveNoThrow(cbStr); 1739 AssertRCReturn(vrc, vrc); 1740 vrc = SSMR3GetStrZ(pSSM, strAutoMountPoint.mutableRaw(), cbStr); 1741 AssertRCReturn(vrc, vrc); 1742 strAutoMountPoint.jolt(); 1743 } 1732 1744 1733 1745 ComObjPtr<SharedFolder> pSharedFolder; … … 1738 1750 writable, 1739 1751 autoMount, 1752 strAutoMountPoint, 1740 1753 false /* fFailOnError */); 1741 1754 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); … … 2941 2954 } 2942 2955 2943 HRESULT Console::createSharedFolder(const com::Utf8Str &aName, const com::Utf8Str &aHostPath, BOOL aWritable, BOOL aAutomount) 2956 HRESULT Console::createSharedFolder(const com::Utf8Str &aName, const com::Utf8Str &aHostPath, BOOL aWritable, 2957 BOOL aAutomount, const com::Utf8Str &aAutoMountPoint) 2944 2958 { 2945 2959 LogFlowThisFunc(("Entering for '%s' -> '%s'\n", aName.c_str(), aHostPath.c_str())); … … 2974 2988 !!aWritable, 2975 2989 !!aAutomount, 2990 aAutoMountPoint, 2976 2991 true /* fFailOnError */); 2977 2992 if (FAILED(rc)) return rc; … … 2995 3010 2996 3011 /* second, create the given folder */ 2997 rc = i_createSharedFolder(aName, SharedFolderData(aHostPath, !!aWritable, !!aAutomount ));3012 rc = i_createSharedFolder(aName, SharedFolderData(aHostPath, !!aWritable, !!aAutomount, aAutoMountPoint)); 2998 3013 if (FAILED(rc)) 2999 3014 return rc; … … 7683 7698 sharedFolders[it->first] = SharedFolderData(pSF->i_getHostPath(), 7684 7699 pSF->i_isWritable(), 7685 pSF->i_isAutoMounted()); 7700 pSF->i_isAutoMounted(), 7701 pSF->i_getAutoMountPoint()); 7686 7702 } 7687 7703 } … … 8441 8457 ComPtr<ISharedFolder> pSharedFolder = folders[i]; 8442 8458 8443 Bstr bstrName; 8444 Bstr bstrHostPath; 8459 Bstr bstr; 8460 rc = pSharedFolder->COMGETTER(Name)(bstr.asOutParam()); 8461 if (FAILED(rc)) throw rc; 8462 Utf8Str strName(bstr); 8463 8464 rc = pSharedFolder->COMGETTER(HostPath)(bstr.asOutParam()); 8465 if (FAILED(rc)) throw rc; 8466 Utf8Str strHostPath(bstr); 8467 8445 8468 BOOL writable; 8446 BOOL autoMount;8447 8448 rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam());8449 if (FAILED(rc)) throw rc;8450 Utf8Str strName(bstrName);8451 8452 rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam());8453 if (FAILED(rc)) throw rc;8454 Utf8Str strHostPath(bstrHostPath);8455 8456 8469 rc = pSharedFolder->COMGETTER(Writable)(&writable); 8457 8470 if (FAILED(rc)) throw rc; 8458 8471 8472 BOOL autoMount; 8459 8473 rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount); 8460 8474 if (FAILED(rc)) throw rc; 8461 8475 8476 rc = pSharedFolder->COMGETTER(AutoMountPoint)(bstr.asOutParam()); 8477 if (FAILED(rc)) throw rc; 8478 Utf8Str strAutoMountPoint(bstr); 8479 8462 8480 m_mapMachineSharedFolders.insert(std::make_pair(strName, 8463 SharedFolderData(strHostPath, !!writable, !!autoMount))); 8481 SharedFolderData(strHostPath, !!writable, 8482 !!autoMount, strAutoMountPoint))); 8464 8483 8465 8484 /* send changes to HGCM if the VM is running */ … … 8488 8507 /* create the new machine folder */ 8489 8508 rc = i_createSharedFolder(strName, 8490 SharedFolderData(strHostPath, !!writable, !!autoMount ));8509 SharedFolderData(strHostPath, !!writable, !!autoMount, strAutoMountPoint)); 8491 8510 if (FAILED(rc)) throw rc; 8492 8511 } … … 8577 8596 HRESULT Console::i_createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData) 8578 8597 { 8598 Log(("Adding shared folder '%s' -> '%s'\n", strName.c_str(), aData.m_strHostPath.c_str())); 8599 8600 /* 8601 * Sanity checks 8602 */ 8579 8603 ComAssertRet(strName.isNotEmpty(), E_FAIL); 8580 8604 ComAssertRet(aData.m_strHostPath.isNotEmpty(), E_FAIL); 8581 8605 8582 /* sanity checks */8583 8606 AssertReturn(mpUVM, E_FAIL); 8584 8607 AssertReturn(m_pVMMDev && m_pVMMDev->isShFlActive(), E_FAIL); 8585 8608 8586 VBOXHGCMSVCPARM parms[SHFL_CPARMS_ADD_MAPPING]; 8587 SHFLSTRING *pFolderName, *pMapName; 8588 size_t cbString; 8589 8590 Bstr value; 8591 HRESULT hrc = mMachine->GetExtraData(BstrFmt("VBoxInternal2/SharedFoldersEnableSymlinksCreate/%s", 8592 strName.c_str()).raw(), 8593 value.asOutParam()); 8594 bool fSymlinksCreate = hrc == S_OK && value == "1"; 8595 8596 Log(("Adding shared folder '%s' -> '%s'\n", strName.c_str(), aData.m_strHostPath.c_str())); 8597 8598 // check whether the path is valid and exists 8599 char hostPathFull[RTPATH_MAX]; 8600 int vrc = RTPathAbsEx(NULL, 8601 aData.m_strHostPath.c_str(), 8602 hostPathFull, 8603 sizeof(hostPathFull)); 8604 8605 bool fMissing = false; 8609 /* 8610 * Find out whether we should allow symbolic link creation. 8611 */ 8612 Bstr bstrValue; 8613 HRESULT hrc = mMachine->GetExtraData(BstrFmt("VBoxInternal2/SharedFoldersEnableSymlinksCreate/%s", strName.c_str()).raw(), 8614 bstrValue.asOutParam()); 8615 bool fSymlinksCreate = hrc == S_OK && bstrValue == "1"; 8616 8617 /* 8618 * Check whether the path is valid and exists. 8619 */ 8620 char szAbsHostPath[RTPATH_MAX]; 8621 int vrc = RTPathAbsEx(NULL, aData.m_strHostPath.c_str(), szAbsHostPath, sizeof(szAbsHostPath)); 8606 8622 if (RT_FAILURE(vrc)) 8607 8623 return setErrorBoth(E_INVALIDARG, vrc, tr("Invalid shared folder path: '%s' (%Rrc)"), aData.m_strHostPath.c_str(), vrc); 8608 if (!RTPathExists(hostPathFull)) 8609 fMissing = true; 8610 8611 /* Check whether the path is full (absolute) */ 8612 if (RTPathCompare(aData.m_strHostPath.c_str(), hostPathFull) != 0) 8624 8625 /* Check whether the path is full (absolute). ASSUMING a RTPATH_MAX of ~4K 8626 this also checks that the length is within bounds of a SHFLSTRING. */ 8627 if (RTPathCompare(aData.m_strHostPath.c_str(), szAbsHostPath) != 0) 8613 8628 return setError(E_INVALIDARG, 8614 8629 tr("Shared folder path '%s' is not absolute"), 8615 8630 aData.m_strHostPath.c_str()); 8616 8631 8617 // now that we know the path is good, give it to HGCM 8618 8619 Bstr bstrName(strName); 8620 Bstr bstrHostPath(aData.m_strHostPath); 8621 8622 cbString = (bstrHostPath.length() + 1) * sizeof(RTUTF16); 8623 if (cbString >= UINT16_MAX) 8624 return setError(E_INVALIDARG, tr("The name is too long")); 8625 pFolderName = (SHFLSTRING*)RTMemAllocZ(SHFLSTRING_HEADER_SIZE + cbString); 8626 Assert(pFolderName); 8627 memcpy(pFolderName->String.ucs2, bstrHostPath.raw(), cbString); 8628 8629 pFolderName->u16Size = (uint16_t)cbString; 8630 pFolderName->u16Length = (uint16_t)(cbString - sizeof(RTUTF16)); 8631 8632 parms[0].type = VBOX_HGCM_SVC_PARM_PTR; 8633 parms[0].u.pointer.addr = pFolderName; 8634 parms[0].u.pointer.size = ShflStringSizeOfBuffer(pFolderName); 8635 8636 cbString = (bstrName.length() + 1) * sizeof(RTUTF16); 8637 if (cbString >= UINT16_MAX) 8638 { 8639 RTMemFree(pFolderName); 8640 return setError(E_INVALIDARG, tr("The host path is too long")); 8641 } 8642 pMapName = (SHFLSTRING*)RTMemAllocZ(SHFLSTRING_HEADER_SIZE + cbString); 8643 Assert(pMapName); 8644 memcpy(pMapName->String.ucs2, bstrName.raw(), cbString); 8645 8646 pMapName->u16Size = (uint16_t)cbString; 8647 pMapName->u16Length = (uint16_t)(cbString - sizeof(RTUTF16)); 8648 8649 parms[1].type = VBOX_HGCM_SVC_PARM_PTR; 8650 parms[1].u.pointer.addr = pMapName; 8651 parms[1].u.pointer.size = ShflStringSizeOfBuffer(pMapName); 8652 8653 parms[2].type = VBOX_HGCM_SVC_PARM_32BIT; 8654 parms[2].u.uint32 = (aData.m_fWritable ? SHFL_ADD_MAPPING_F_WRITABLE : 0) 8655 | (aData.m_fAutoMount ? SHFL_ADD_MAPPING_F_AUTOMOUNT : 0) 8656 | (fSymlinksCreate ? SHFL_ADD_MAPPING_F_CREATE_SYMLINKS : 0) 8657 | (fMissing ? SHFL_ADD_MAPPING_F_MISSING : 0) 8658 ; 8659 8660 vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders", 8661 SHFL_FN_ADD_MAPPING, 8662 SHFL_CPARMS_ADD_MAPPING, &parms[0]); 8663 RTMemFree(pFolderName); 8664 RTMemFree(pMapName); 8665 8666 if (RT_FAILURE(vrc)) 8667 return setErrorBoth(E_FAIL, vrc, tr("Could not create a shared folder '%s' mapped to '%s' (%Rrc)"), 8668 strName.c_str(), aData.m_strHostPath.c_str(), vrc); 8669 8670 if (fMissing) 8671 return setError(E_INVALIDARG, 8672 tr("Shared folder path '%s' does not exist on the host"), 8673 aData.m_strHostPath.c_str()); 8674 8675 return S_OK; 8632 bool const fMissing = !RTPathExists(szAbsHostPath); 8633 8634 /* 8635 * Check the other two string lengths before converting them all to SHFLSTRINGS. 8636 */ 8637 if (strName.length() >= _2K) 8638 return setError(E_INVALIDARG, tr("Shared folder name is too long: %zu bytes"), strName.length()); 8639 if (aData.m_strAutoMountPoint.length() >= RTPATH_MAX) 8640 return setError(E_INVALIDARG, tr("Shared folder mountp point too long: %zu bytes"), aData.m_strAutoMountPoint.length()); 8641 8642 PSHFLSTRING pHostPath = ShflStringDupUtf8AsUtf16(aData.m_strHostPath.c_str()); 8643 PSHFLSTRING pName = ShflStringDupUtf8AsUtf16(strName.c_str()); 8644 PSHFLSTRING pAutoMountPoint = ShflStringDupUtf8AsUtf16(aData.m_strAutoMountPoint.c_str()); 8645 if (pHostPath && pName && pAutoMountPoint) 8646 { 8647 /* 8648 * Make a SHFL_FN_ADD_MAPPING call to tell the service about folder. 8649 */ 8650 VBOXHGCMSVCPARM aParams[SHFL_CPARMS_ADD_MAPPING]; 8651 SHFLSTRING_TO_HGMC_PARAM(&aParams[0], pHostPath); 8652 SHFLSTRING_TO_HGMC_PARAM(&aParams[1], pName); 8653 aParams[2].setUInt32( (aData.m_fWritable ? SHFL_ADD_MAPPING_F_WRITABLE : 0) 8654 | (aData.m_fAutoMount ? SHFL_ADD_MAPPING_F_AUTOMOUNT : 0) 8655 | (fSymlinksCreate ? SHFL_ADD_MAPPING_F_CREATE_SYMLINKS : 0) 8656 | (fMissing ? SHFL_ADD_MAPPING_F_MISSING : 0)); 8657 SHFLSTRING_TO_HGMC_PARAM(&aParams[3], pAutoMountPoint); 8658 AssertCompile(SHFL_CPARMS_ADD_MAPPING == 4); 8659 8660 vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders", SHFL_FN_ADD_MAPPING, SHFL_CPARMS_ADD_MAPPING, aParams); 8661 if (RT_FAILURE(vrc)) 8662 hrc = setErrorBoth(E_FAIL, vrc, tr("Could not create a shared folder '%s' mapped to '%s' (%Rrc)"), 8663 strName.c_str(), aData.m_strHostPath.c_str(), vrc); 8664 8665 else if (fMissing) 8666 hrc = setError(E_INVALIDARG, 8667 tr("Shared folder path '%s' does not exist on the host"), 8668 aData.m_strHostPath.c_str()); 8669 else 8670 hrc = S_OK; 8671 } 8672 else 8673 hrc = E_OUTOFMEMORY; 8674 RTMemFree(pAutoMountPoint); 8675 RTMemFree(pName); 8676 RTMemFree(pHostPath); 8677 return hrc; 8676 8678 } 8677 8679 … … 10176 10178 * Register our load/save state file handlers 10177 10179 */ 10178 vrc = SSMR3RegisterExternal(pConsole->mpUVM, sSSMConsoleUnit, 0 /*iInstance*/, sSSMConsoleVer, 0 /* cbGuess */, 10180 vrc = SSMR3RegisterExternal(pConsole->mpUVM, sSSMConsoleUnit, 0 /*iInstance*/, 10181 CONSOLE_SAVED_STATE_VERSION, 0 /* cbGuess */, 10179 10182 NULL, NULL, NULL, 10180 10183 NULL, i_saveStateFileExec, NULL,
Note:
See TracChangeset
for help on using the changeset viewer.