VirtualBox

Changeset 72999 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Jul 9, 2018 7:59:18 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123551
Message:

MediumImpl: Fixed MediumVariant_Formatted implementation and made it a long rather than quick format. Refactored i_openHddForReading to become flexible enough for opening for both read and write and make MediumIO use it.

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MediumIOImpl.cpp

    r72950 r72999  
    146146        if (SUCCEEDED(hrc))
    147147        {
    148             hrc = pMedium->i_openHddForIO(fWritable, &m->PasswordStore, &m->pHdd, &m->LockList, &m->CryptoSettings);
     148            hrc = pMedium->i_openForIO(fWritable, &m->PasswordStore, &m->pHdd, &m->LockList, &m->CryptoSettings);
    149149            if (SUCCEEDED(hrc))
    150150            {
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r72962 r72999  
    61156115        MediumLockList                  SourceMediumLockList;
    61166116        PVDISK                          pHdd;
    6117         hrc = i_openHddForReading(pKeyStore, &pHdd, &SourceMediumLockList, &CryptoSettingsRead);
     6117        hrc = i_openForIO(false /*fWritable*/, pKeyStore, &pHdd, &SourceMediumLockList, &CryptoSettingsRead);
    61186118        if (SUCCEEDED(hrc))
    61196119        {
     
    62036203                MediumLockList                  SourceMediumLockList;
    62046204                PVDISK                          pSrcHdd;
    6205                 hrc = i_openHddForReading(pKeyStore, &pSrcHdd, &SourceMediumLockList, &CryptoSettingsRead);
     6205                hrc = i_openForIO(false /*fWritable*/, pKeyStore, &pSrcHdd, &SourceMediumLockList, &CryptoSettingsRead);
    62066206                if (SUCCEEDED(hrc))
    62076207                {
     
    65406540
    65416541    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 will
    6548  *          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 for
    6553  *                                  an encrypted medium.
    6554  * @param   ppHdd                   Where to return the pointer to the VDISK on
    6555  *                                  success.
    6556  * @param   pMediumLockList         The lock list to populate and lock.  Caller
    6557  *                                  is responsible for calling the destructor or
    6558  *                                  MediumLockList::Clear() after destroying
    6559  *                                  @a *ppHdd
    6560  * @param   pCryptoSettings         The crypto settings to use for setting up
    6561  *                                  decryption of the VDISK.  This object must
    6562  *                                  be alive until the VDISK is destroyed!
    6563  *
    6564  * @note    Using a keystore here for the KeyId+password so we can share code
    6565  *          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;
    65756542}
    65766543
     
    80107977
    80117978/**
    8012  * Creates a read-only VDISK instance for this medium.
     7979 * Creates a VDISK instance for this medium.
    80137980 *
    80147981 * @note    Caller should not hold any medium related locks as this method will
     
    80167983 *
    80177984 * @returns COM status code.
     7985 * @param   fWritable               Whether to return a writable VDISK instance
     7986 *                                  (true) or a read-only one (false).
    80187987 * @param   pKeyStore               The key store.
    80197988 * @param   ppHdd                   Where to return the pointer to the VDISK on
     
    80277996 *                                  must be alive until the VDISK is destroyed!
    80287997 */
    8029 HRESULT Medium::i_openHddForReading(SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList,
    8030                                     MediumCryptoFilterSettings *pCryptoSettingsRead)
     7998HRESULT Medium::i_openForIO(bool fWritable, SecretKeyStore *pKeyStore, PVDISK *ppHdd, MediumLockList *pMediumLockList,
     7999                            MediumCryptoFilterSettings *pCryptoSettingsRead)
    80318000{
    80328001    /*
     
    80348003     */
    80358004    HRESULT hrc = i_createMediumLockList(true /* fFailIfInaccessible */,
    8036                                          NULL /* pToLockWrite */,
     8005                                         fWritable ? this : NULL /* pToLockWrite */,
    80378006                                         false /* fMediumLockWriteAll */,
    80388007                                         NULL,
     
    81288097         */
    81298098        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
    81318103        for (MediumLockList::Base::const_iterator it = sourceListBegin; it != sourceListEnd; ++it)
    81328104        {
     
    81368108
    81378109            /* sanity check */
    8138             Assert(pMedium->m->state == MediumState_LockedRead);
     8110            Assert(pMedium->m->state == (fWritable && it == mediumListLast ? MediumState_LockedWrite : MediumState_LockedRead));
    81398111
    81408112            /* Open all media in read-only mode. */
     
    81428114                         pMedium->m->strFormat.c_str(),
    81438115                         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),
    81458117                         pMedium->m->vdImageIfaces);
    81468118            if (RT_FAILURE(vrc))
     
    81518123        }
    81528124
    8153         Assert(m->state == MediumState_LockedRead);
     8125        Assert(m->state == (fWritable ? MediumState_LockedWrite : MediumState_LockedRead));
    81548126
    81558127        /*
     
    82488220            {
    82498221                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());
    82538225                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());
    82578229            }
    82588230
     
    82608232            {
    82618233                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);
    82638235                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,
    82688240                                       0 /* cbSector */, 0 /* cbSectorPerCluster */, RTFSFATTYPE_INVALID,
    82698241                                       0 /* cHeads */, 0 /* cSectorsPerTrack*/, 0 /* bMedia */,
    82708242                                       0 /* cRootDirEntries */, 0 /* cHiddenSectors */,
    8271                                        NULL /* pErrInfo */);
     8243                                       RTErrInfoInitStatic(&ErrInfo));
    82728244                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);
    82738248                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());
    82778251            }
    82788252
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette