Changeset 72999 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Jul 9, 2018 7:59:18 AM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 123551
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MediumIOImpl.cpp
r72950 r72999 146 146 if (SUCCEEDED(hrc)) 147 147 { 148 hrc = pMedium->i_open HddForIO(fWritable, &m->PasswordStore, &m->pHdd, &m->LockList, &m->CryptoSettings);148 hrc = pMedium->i_openForIO(fWritable, &m->PasswordStore, &m->pHdd, &m->LockList, &m->CryptoSettings); 149 149 if (SUCCEEDED(hrc)) 150 150 { -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r72962 r72999 6115 6115 MediumLockList SourceMediumLockList; 6116 6116 PVDISK pHdd; 6117 hrc = i_open HddForReading(pKeyStore, &pHdd, &SourceMediumLockList, &CryptoSettingsRead);6117 hrc = i_openForIO(false /*fWritable*/, pKeyStore, &pHdd, &SourceMediumLockList, &CryptoSettingsRead); 6118 6118 if (SUCCEEDED(hrc)) 6119 6119 { … … 6203 6203 MediumLockList SourceMediumLockList; 6204 6204 PVDISK pSrcHdd; 6205 hrc = i_open HddForReading(pKeyStore, &pSrcHdd, &SourceMediumLockList, &CryptoSettingsRead);6205 hrc = i_openForIO(false /*fWritable*/, pKeyStore, &pSrcHdd, &SourceMediumLockList, &CryptoSettingsRead); 6206 6206 if (SUCCEEDED(hrc)) 6207 6207 { … … 6540 6540 6541 6541 return it->second; 6542 }6543 6544 /**6545 * This method is intended for MediumIO::initForMedium().6546 *6547 * @note Caller should not hold any medium related locks as this method will6548 * acquire the medium lock for writing and others (VirtualBox).6549 *6550 * @returns COM status code.6551 * @param fWritable Flag whether the medium should be opened for writing.6552 * @param pKeyStore Keystore containing the KeyId+password for6553 * an encrypted medium.6554 * @param ppHdd Where to return the pointer to the VDISK on6555 * success.6556 * @param pMediumLockList The lock list to populate and lock. Caller6557 * is responsible for calling the destructor or6558 * MediumLockList::Clear() after destroying6559 * @a *ppHdd6560 * @param pCryptoSettings The crypto settings to use for setting up6561 * decryption of the VDISK. This object must6562 * be alive until the VDISK is destroyed!6563 *6564 * @note Using a keystore here for the KeyId+password so we can share code6565 * with appliance. Not quite sure if that's a great idea or not...6566 */6567 HRESULT Medium::i_openHddForIO(bool fWritable, SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList,6568 MediumCryptoFilterSettings *pCryptoSettings)6569 {6570 *ppHdd = NULL;6571 if (!fWritable)6572 return i_openHddForReading(pKeyStore, ppHdd, pMediumLockList, pCryptoSettings);6573 /** @todo implement opening for writing. */6574 return E_NOTIMPL;6575 6542 } 6576 6543 … … 8010 7977 8011 7978 /** 8012 * Creates a read-onlyVDISK instance for this medium.7979 * Creates a VDISK instance for this medium. 8013 7980 * 8014 7981 * @note Caller should not hold any medium related locks as this method will … … 8016 7983 * 8017 7984 * @returns COM status code. 7985 * @param fWritable Whether to return a writable VDISK instance 7986 * (true) or a read-only one (false). 8018 7987 * @param pKeyStore The key store. 8019 7988 * @param ppHdd Where to return the pointer to the VDISK on … … 8027 7996 * must be alive until the VDISK is destroyed! 8028 7997 */ 8029 HRESULT Medium::i_open HddForReading(SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList,8030 7998 HRESULT Medium::i_openForIO(bool fWritable, SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList, 7999 MediumCryptoFilterSettings *pCryptoSettingsRead) 8031 8000 { 8032 8001 /* … … 8034 8003 */ 8035 8004 HRESULT hrc = i_createMediumLockList(true /* fFailIfInaccessible */, 8036 NULL /* pToLockWrite */,8005 fWritable ? this : NULL /* pToLockWrite */, 8037 8006 false /* fMediumLockWriteAll */, 8038 8007 NULL, … … 8128 8097 */ 8129 8098 MediumLockList::Base::const_iterator sourceListBegin = pMediumLockList->GetBegin(); 8130 MediumLockList::Base::const_iterator sourceListEnd = pMediumLockList->GetEnd(); 8099 MediumLockList::Base::const_iterator sourceListEnd = pMediumLockList->GetEnd(); 8100 MediumLockList::Base::const_iterator mediumListLast = sourceListEnd; 8101 --mediumListLast; 8102 8131 8103 for (MediumLockList::Base::const_iterator it = sourceListBegin; it != sourceListEnd; ++it) 8132 8104 { … … 8136 8108 8137 8109 /* sanity check */ 8138 Assert(pMedium->m->state == MediumState_LockedRead);8110 Assert(pMedium->m->state == (fWritable && it == mediumListLast ? MediumState_LockedWrite : MediumState_LockedRead)); 8139 8111 8140 8112 /* Open all media in read-only mode. */ … … 8142 8114 pMedium->m->strFormat.c_str(), 8143 8115 pMedium->m->strLocationFull.c_str(), 8144 VD_OPEN_FLAGS_READONLY | m->uOpenFlagsDef,8116 m->uOpenFlagsDef | (fWritable && it == mediumListLast ? VD_OPEN_FLAGS_NORMAL : VD_OPEN_FLAGS_READONLY), 8145 8117 pMedium->m->vdImageIfaces); 8146 8118 if (RT_FAILURE(vrc)) … … 8151 8123 } 8152 8124 8153 Assert(m->state == MediumState_LockedRead);8125 Assert(m->state == (fWritable ? MediumState_LockedWrite : MediumState_LockedRead)); 8154 8126 8155 8127 /* … … 8248 8220 { 8249 8221 if (vrc == VERR_VD_INVALID_TYPE) 8250 throw setError (VBOX_E_FILE_ERROR,8251 tr("Parameters for creating the medium storage unit '%s' are invalid%s"),8252 location.c_str(), i_vdError(vrc).c_str());8222 throw setErrorBoth(VBOX_E_FILE_ERROR, vrc, 8223 tr("Parameters for creating the medium storage unit '%s' are invalid%s"), 8224 location.c_str(), i_vdError(vrc).c_str()); 8253 8225 else 8254 throw setError (VBOX_E_FILE_ERROR,8255 tr("Could not create the medium storage unit '%s'%s"),8256 location.c_str(), i_vdError(vrc).c_str());8226 throw setErrorBoth(VBOX_E_FILE_ERROR, vrc, 8227 tr("Could not create the medium storage unit '%s'%s"), 8228 location.c_str(), i_vdError(vrc).c_str()); 8257 8229 } 8258 8230 … … 8260 8232 { 8261 8233 RTVFSFILE hVfsFile; 8262 vrc = RTVfsFileOpenNormal(location.c_str(), RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_ALL, &hVfsFile);8234 vrc = VDCreateVfsFileFromDisk(hdd, 0 /*fFlags*/, &hVfsFile); 8263 8235 if (RT_FAILURE(vrc)) 8264 throw setError (VBOX_E_FILE_ERROR,8265 tr("Opening medium storage unit '%s' failed%s"),8266 location.c_str(), i_vdError(vrc).c_str());8267 vrc = RTFsFatVolFormat(hVfsFile, 0 /* offVol */, 0 /* cbVol */, RTFSFATVOL_FMT_F_ QUICK,8236 throw setErrorBoth(VBOX_E_FILE_ERROR, vrc, tr("Opening medium storage unit '%s' failed%s"), 8237 location.c_str(), i_vdError(vrc).c_str()); 8238 RTERRINFOSTATIC ErrInfo; 8239 vrc = RTFsFatVolFormat(hVfsFile, 0 /* offVol */, 0 /* cbVol */, RTFSFATVOL_FMT_F_FULL, 8268 8240 0 /* cbSector */, 0 /* cbSectorPerCluster */, RTFSFATTYPE_INVALID, 8269 8241 0 /* cHeads */, 0 /* cSectorsPerTrack*/, 0 /* bMedia */, 8270 8242 0 /* cRootDirEntries */, 0 /* cHiddenSectors */, 8271 NULL /* pErrInfo */);8243 RTErrInfoInitStatic(&ErrInfo)); 8272 8244 RTVfsFileRelease(hVfsFile); 8245 if (RT_FAILURE(vrc) && RTErrInfoIsSet(&ErrInfo.Core)) 8246 throw setErrorBoth(VBOX_E_FILE_ERROR, vrc, tr("Formatting medium storage unit '%s' failed: %s"), 8247 location.c_str(), ErrInfo.Core.pszMsg); 8273 8248 if (RT_FAILURE(vrc)) 8274 throw setError(VBOX_E_FILE_ERROR, 8275 tr("Formatting medium storage unit '%s' failed%s"), 8276 location.c_str(), i_vdError(vrc).c_str()); 8249 throw setErrorBoth(VBOX_E_FILE_ERROR, vrc, tr("Formatting medium storage unit '%s' failed%s"), 8250 location.c_str(), i_vdError(vrc).c_str()); 8277 8251 } 8278 8252
Note:
See TracChangeset
for help on using the changeset viewer.