VirtualBox

Changeset 105627 in vbox


Ignore:
Timestamp:
Aug 8, 2024 3:58:25 PM (6 months ago)
Author:
vboxsync
Message:

Main/NvramStore: Don't (debug) assert when getting the UEFI NVRAM store for non-UEFI VMs; some IPRT APIs being used don't like empty strings (paths) and assert in such cases. Be a bit more information wrt returning errors via the API about what's going on.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/NvramStoreImpl.h

    r99418 r105627  
    8585#endif
    8686
     87    int i_getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile);
    8788    com::Utf8Str i_getNonVolatileStorageFile();
    8889    void i_updateNonVolatileStorageFile(const com::Utf8Str &aNonVolatileStorageFile);
  • trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp

    r105383 r105627  
    354354}
    355355
    356 
    357356HRESULT NvramStore::getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile)
    358357{
    359 #ifndef VBOX_COM_INPROC
    360     Utf8Str strTmp;
    361     {
    362         AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    363         strTmp = m->bd->strNvramPath;
    364     }
    365 
    366     AutoReadLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
    367     if (strTmp.isEmpty())
    368         strTmp = m->pParent->i_getDefaultNVRAMFilename();
    369     if (strTmp.isNotEmpty())
    370         m->pParent->i_calculateFullPath(strTmp, aNonVolatileStorageFile);
    371 #else
    372     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    373     aNonVolatileStorageFile = m->bd->strNvramPath;
    374 #endif
     358    int vrc = i_getNonVolatileStorageFile(aNonVolatileStorageFile);
     359    if (RT_FAILURE(vrc))
     360        return setError(E_FAIL, tr("This machine does not have an NVRAM store file"));
    375361
    376362    return S_OK;
     
    382368#ifndef VBOX_COM_INPROC
    383369    Utf8Str strPath;
    384     NvramStore::getNonVolatileStorageFile(strPath);
     370    int vrc = i_getNonVolatileStorageFile(strPath);
     371    if (RT_FAILURE(vrc))
     372        return setError(E_FAIL, tr("No NVRAM store file found"));
     373
     374    HRESULT hrc;
    385375
    386376    /* We need a write lock because of the lazy initialization. */
     
    388378
    389379    /* Check if we have to create the UEFI variable store object */
    390     HRESULT hrc = S_OK;
    391380    if (!m->pUefiVarStore)
    392381    {
     
    394383        if (!m->mapNvram.size())
    395384        {
    396             int vrc = i_loadStore(strPath.c_str());
     385            vrc = i_loadStore(strPath.c_str());
    397386            if (RT_FAILURE(vrc))
    398387                hrc = setError(E_FAIL, tr("Loading the NVRAM store failed (%Rrc)\n"), vrc);
     
    408397            }
    409398            else
    410                 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The UEFI NVRAM file is not existing for this machine."));
     399                hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The UEFI NVRAM file is not existing for this machine"));
    411400        }
    412401    }
     
    464453    if (FAILED(adep.hrc())) return adep.hrc();
    465454
    466     Utf8Str strPath;
    467     NvramStore::getNonVolatileStorageFile(strPath);
     455    Utf8Str strPath = i_getNonVolatileStorageFile();
    468456
    469457    /* We need a write lock because of the lazy initialization. */
     
    526514
    527515
     516/**
     517 * Returns the path of the non-volatile storage file.
     518 *
     519 * @returns VBox status code.
     520 * @retval  VERR_FILE_NOT_FOUND if the storage file was not found.
     521 * @param   aNonVolatileStorageFile   Returns path to non-volatile stroage file on success.
     522 */
     523int NvramStore::i_getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile)
     524{
     525#ifndef VBOX_COM_INPROC
     526    Utf8Str strTmp;
     527    {
     528        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     529        strTmp = m->bd->strNvramPath;
     530    }
     531
     532    AutoReadLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
     533    if (strTmp.isEmpty())
     534        strTmp = m->pParent->i_getDefaultNVRAMFilename();
     535    if (strTmp.isNotEmpty())
     536        m->pParent->i_calculateFullPath(strTmp, aNonVolatileStorageFile);
     537#else
     538    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     539    aNonVolatileStorageFile = m->bd->strNvramPath;
     540#endif
     541
     542    if (aNonVolatileStorageFile.isEmpty())
     543        return VERR_FILE_NOT_FOUND;
     544
     545    return VINF_SUCCESS;
     546}
     547
     548
     549/**
     550 * Returns the path of the non-volatile stroage file.
     551 *
     552 * @returns Path to non-volatile stroage file. Empty if not supported / found.
     553 *
     554 * @note    Convenience function for machine object or other callers.
     555 */
    528556Utf8Str NvramStore::i_getNonVolatileStorageFile()
    529557{
     
    532560
    533561    Utf8Str strTmp;
    534     NvramStore::getNonVolatileStorageFile(strTmp);
     562    /* rc ignored */ i_getNonVolatileStorageFile(strTmp);
    535563    return strTmp;
    536564}
     
    695723int NvramStore::i_loadStore(const char *pszPath)
    696724{
     725    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
     726    AssertReturn(*pszPath, VERR_PATH_ZERO_LENGTH); /* IPRT below doesn't like empty strings. */
     727
    697728    uint64_t cbStore = 0;
    698729    int vrc = RTFileQuerySizeByPath(pszPath, &cbStore);
     
    912943    int vrc = VINF_SUCCESS;
    913944
    914     Utf8Str strTmp;
    915     NvramStore::getNonVolatileStorageFile(strTmp);
     945    Utf8Str strPath = i_getNonVolatileStorageFile();
    916946
    917947    /*
     
    920950     * see @bugref{10191}.
    921951     */
    922     if (strTmp.isNotEmpty())
     952    if (strPath.isNotEmpty())
    923953    {
    924954        /*
     
    937967
    938968            RTVFSIOSTREAM hVfsIosDst;
    939             vrc = RTVfsIoStrmOpenNormal(strTmp.c_str(), RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE,
     969            vrc = RTVfsIoStrmOpenNormal(strPath.c_str(), RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE,
    940970                                        &hVfsIosDst);
    941971            if (RT_SUCCESS(vrc))
     
    9721002        }
    9731003        else if (m->mapNvram.size())
    974             vrc = i_saveStoreAsTar(strTmp.c_str());
     1004            vrc = i_saveStoreAsTar(strPath.c_str());
    9751005        /* else: No NVRAM content to store so we are done here. */
    9761006    }
     
    10841114        }
    10851115        else
    1086             hrc = setError(E_FAIL, tr("Opening the UEFI variable store failed (%Rrc)."), vrc);
     1116            hrc = setError(E_FAIL, tr("Opening the UEFI variable store failed (%Rrc)"), vrc);
    10871117    }
    10881118    else
    1089         hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The UEFI NVRAM file is not existing for this machine."));
     1119        hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The UEFI NVRAM file is not existing for this machine"));
    10901120
    10911121    return hrc;
Note: See TracChangeset for help on using the changeset viewer.

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