VirtualBox

Changeset 7780 in vbox


Ignore:
Timestamp:
Apr 7, 2008 4:36:56 PM (17 years ago)
Author:
vboxsync
Message:

Add function to query all available VD backends, together with their capabilities. Also added a flag to the write operation (purely a dummy at the moment).

Location:
trunk/src/VBox/Devices/Storage
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/RawHDDCore.cpp

    r7654 r7780  
    466466static int rawWrite(void *pBackendData, uint64_t uOffset, const void *pvBuf,
    467467                    size_t cbToWrite, size_t *pcbWriteProcess,
    468                     size_t *pcbPreRead, size_t *pcbPostRead)
     468                    size_t *pcbPreRead, size_t *pcbPostRead, unsigned fWrite)
    469469{
    470470    LogFlowFunc(("pBackendData=%#p uOffset=%llu pvBuf=%#p cbToWrite=%zu pcbWriteProcess=%#p pcbPreRead=%#p pcbPostRead=%#p\n", pBackendData, uOffset, pvBuf, cbToWrite, pcbWriteProcess, pcbPreRead, pcbPostRead));
     
    990990    /* cbSize */
    991991    sizeof(VBOXHDDBACKEND),
     992    /* uBackendCaps */
     993    VD_CAP_CREATE_FIXED,
    992994    /* pfnCheckIfValid */
    993995    rawCheckIfValid,
  • trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp

    r7690 r7780  
    109109
    110110
     111extern VBOXHDDBACKEND g_RawBackend;
    111112extern VBOXHDDBACKEND g_VmdkBackend;
    112113extern VBOXHDDBACKEND g_VDIBackend;
     
    117118static PCVBOXHDDBACKEND aBackends[] =
    118119{
     120    &g_RawBackend,
    119121    &g_VmdkBackend,
    120122    &g_VDIBackend,
     
    441443                                   uOffset - cbPreRead, pvTmp,
    442444                                   cbPreRead + cbThisWrite + cbPostRead,
    443                                    NULL,
    444                                    &cbPreRead, &cbPostRead);
     445                                   NULL, &cbPreRead, &cbPostRead, 0);
    445446    Assert(rc != VERR_VDI_BLOCK_FREE);
    446447    Assert(cbPreRead == 0);
     
    521522                                   uOffset - cbPreRead, pvTmp,
    522523                                   cbPreRead + cbThisWrite + cbPostRead,
    523                                    NULL,
    524                                    &cbPreRead, &cbPostRead);
     524                                   NULL, &cbPreRead, &cbPostRead, 0);
    525525    Assert(rc != VERR_VDI_BLOCK_FREE);
    526526    Assert(cbPreRead == 0);
     
    551551        rc = pImage->Backend->pfnWrite(pImage->pvBackendData, uOffset, pvBuf,
    552552                                       cbThisWrite, &cbThisWrite, &cbPreRead,
    553                                        &cbPostRead);
     553                                       &cbPostRead, 0);
    554554        if (rc == VERR_VDI_BLOCK_FREE)
    555555        {
     
    585585    } while (cbWrite != 0 && VBOX_SUCCESS(rc));
    586586
     587    return rc;
     588}
     589
     590
     591/**
     592 * Lists all HDD backends and their capabilities in a caller-provided buffer.
     593 *
     594 * @returns VBox status code.
     595 *          VERR_BUFFER_OVERFLOW if not enough space is passed.
     596 * @param   cEntriesAlloc   Number of list entries available.
     597 * @param   pEntries        Pointer to array for the entries.
     598 * @param   pcEntriesUsed   Number of entries returned.
     599 */
     600VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
     601                                unsigned *pcEntriesUsed)
     602{
     603    int rc = VINF_SUCCESS;
     604    PRTDIR pPluginDir = NULL;
     605    unsigned cEntries = 0;
     606
     607    LogFlowFunc(("cEntriesAlloc=%u pEntries=%#p pcEntriesUsed=%#p\n", cEntriesAlloc, pEntries, pcEntriesUsed));
     608    do
     609    {
     610        /* Check arguments. */
     611        AssertMsgBreak(cEntriesAlloc,
     612                       ("cEntriesAlloc=%u\n", cEntriesAlloc),
     613                       rc = VERR_INVALID_PARAMETER);
     614        AssertMsgBreak(VALID_PTR(pEntries),
     615                       ("pEntries=%#p\n", pEntries),
     616                       rc = VERR_INVALID_PARAMETER);
     617        AssertMsgBreak(VALID_PTR(pcEntriesUsed),
     618                       ("pcEntriesUsed=%#p\n", pcEntriesUsed),
     619                       rc = VERR_INVALID_PARAMETER);
     620
     621        /* First enumerate static backends. */
     622        for (unsigned i = 0; aBackends[i] != NULL; i++)
     623        {
     624            char *pszName = RTStrDup(aBackends[i]->pszBackendName);
     625            if (!pszName)
     626            {
     627                rc = VERR_NO_MEMORY;
     628                break;
     629            }
     630            pEntries[cEntries].pszBackend = pszName;
     631            pEntries[cEntries].uBackendCaps = aBackends[i]->uBackendCaps;
     632            cEntries++;
     633            if (cEntries >= cEntriesAlloc)
     634            {
     635                rc = VERR_BUFFER_OVERFLOW;
     636                break;
     637            }
     638        }
     639        if (VBOX_FAILURE(rc))
     640            break;
     641
     642        /* Then enumerate plugin backends. */
     643        char szPath[RTPATH_MAX];
     644        rc = RTPathSharedLibs(szPath, sizeof(szPath));
     645        if (VBOX_FAILURE(rc))
     646            break;
     647
     648        /* To get all entries with VBoxHDD as prefix. */
     649        char *pszPluginFilter;
     650        rc = RTStrAPrintf(&pszPluginFilter, "%s/%s*", szPath,
     651                          VBOX_HDDFORMAT_PLUGIN_PREFIX);
     652        if (VBOX_FAILURE(rc))
     653        {
     654            rc = VERR_NO_MEMORY;
     655            break;
     656        }
     657
     658        /* The plugins are in the same directory as the other shared libs. */
     659        rc = RTDirOpenFiltered(&pPluginDir, pszPluginFilter, RTDIRFILTER_WINNT);
     660        if (VBOX_FAILURE(rc))
     661            break;
     662
     663        PRTDIRENTRY pPluginDirEntry = NULL;
     664        unsigned cbPluginDirEntry = sizeof(RTDIRENTRY);
     665        pPluginDirEntry = (PRTDIRENTRY)RTMemAllocZ(sizeof(RTDIRENTRY));
     666        if (!pPluginDirEntry)
     667        {
     668            rc = VERR_NO_MEMORY;
     669            break;
     670        }
     671
     672        while ((rc = RTDirRead(pPluginDir, pPluginDirEntry, &cbPluginDirEntry)) != VERR_NO_MORE_FILES)
     673        {
     674            RTLDRMOD hPlugin = NIL_RTLDRMOD;
     675            PFNVBOXHDDFORMATLOAD pfnHDDFormatLoad = NULL;
     676            PVBOXHDDBACKEND pBackend = NULL;
     677
     678            if (rc == VERR_BUFFER_OVERFLOW)
     679            {
     680                /* allocate new buffer. */
     681                RTMemFree(pPluginDirEntry);
     682                pPluginDirEntry = (PRTDIRENTRY)RTMemAllocZ(cbPluginDirEntry);
     683                /* Retry. */
     684                rc = RTDirRead(pPluginDir, pPluginDirEntry, &cbPluginDirEntry);
     685                if (VBOX_FAILURE(rc))
     686                    break;
     687            }
     688            else if (VBOX_FAILURE(rc))
     689                break;
     690
     691            /* We got the new entry. */
     692            if (pPluginDirEntry->enmType != RTDIRENTRYTYPE_FILE)
     693                continue;
     694
     695            rc = RTLdrLoad(pPluginDirEntry->szName, &hPlugin);
     696            if (VBOX_SUCCESS(rc))
     697            {
     698                rc = RTLdrGetSymbol(hPlugin, VBOX_HDDFORMAT_LOAD_NAME, (void**)&pfnHDDFormatLoad);
     699                if (VBOX_FAILURE(rc) || !pfnHDDFormatLoad)
     700                {
     701                    LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pPluginDirEntry->szName, rc, pfnHDDFormatLoad));
     702                    if (VBOX_SUCCESS(rc))
     703                        rc = VERR_SYMBOL_NOT_FOUND;
     704                }
     705
     706                if (VBOX_SUCCESS(rc))
     707                {
     708                    /* Get the function table. */
     709                    rc = pfnHDDFormatLoad(&pBackend);
     710                    if (VBOX_SUCCESS(rc) && pBackend->cbSize == sizeof(VBOXHDDBACKEND))
     711                    {
     712                        char *pszName = RTStrDup(pBackend->pszBackendName);
     713                        if (!pszName)
     714                        {
     715                            rc = VERR_NO_MEMORY;
     716                            break;
     717                        }
     718                        pEntries[cEntries].pszBackend = pszName;
     719                        pEntries[cEntries].uBackendCaps = pBackend->uBackendCaps;
     720                        cEntries++;
     721                        if (cEntries >= cEntriesAlloc)
     722                        {
     723                            rc = VERR_BUFFER_OVERFLOW;
     724                            break;
     725                        }
     726                    }
     727                }
     728                else
     729                    pBackend = NULL;
     730
     731                RTLdrClose(hPlugin);
     732            }
     733        }
     734        RTStrFree(pszPluginFilter);
     735        if (pPluginDirEntry)
     736            RTMemFree(pPluginDirEntry);
     737        if (pPluginDir)
     738            RTDirClose(pPluginDir);
     739    } while (0);
     740
     741    LogFlowFunc(("returns %Vrc *pcEntriesUsed=%u\n", rc, cEntries));
     742    *pcEntriesUsed = cEntries;
    587743    return rc;
    588744}
     
    30293185        {
    30303186            RTLogPrintf("Dumping VD image \"%s\" (Backend=%s)\n",
    3031                         pImage->Backend->pszBackendName, pImage->pszFilename);
     3187                        pImage->Backend->pszBackendName, pImage->pszFilename);
    30323188            pImage->Backend->pfnDump(pImage->pvBackendData);
    30333189        }
  • trunk/src/VBox/Devices/Storage/VBoxHDD-newInternal.h

    r7155 r7780  
    2121#include <VBox/VBoxHDD-new.h>
    2222
     23
     24/** @name VBox HDD backend write flags
     25 * @{
     26 */
     27/** Do not allocate a new block on this write. */
     28#define VD_WRITE_NO_ALLOC   RT_BIT(1)
     29/** @}*/
     30
     31
    2332/**
    2433 * Image format backend interface used by VBox HDD Container implementation.
     
    3544     */
    3645    uint32_t cbSize;
     46
     47    /**
     48     * The capabilities of the backend.
     49     */
     50    uint64_t uBackendCaps;
    3751
    3852    /**
     
    144158     * @param   pcbPostRead     Pointer to the returned amount of data that must
    145159     *                          be postfixed to perform a full block write.
    146      */
    147     DECLR3CALLBACKMEMBER(int, pfnWrite, (void *pvBackendData, uint64_t off, const void *pvBuf, size_t cbWrite, size_t *pcbWriteProcess, size_t *pcbPreRead, size_t *pcbPostRead));
     160     * @param   fWrite          Flags which affect write behavior. Combination
     161     *                          of the VD_WRITE_* flags.
     162     */
     163    DECLR3CALLBACKMEMBER(int, pfnWrite, (void *pvBackendData, uint64_t off, const void *pvBuf, size_t cbWrite, size_t *pcbWriteProcess, size_t *pcbPreRead, size_t *pcbPostRead, unsigned fWrite));
    148164
    149165    /**
  • trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp

    r7689 r7780  
    962962static int vdiWrite(void *pBackendData, uint64_t uOffset, const void *pvBuf,
    963963                    size_t cbToWrite, size_t *pcbWriteProcess,
    964                     size_t *pcbPreRead, size_t *pcbPostRead)
     964                    size_t *pcbPreRead, size_t *pcbPostRead, unsigned fWrite)
    965965{
    966966    LogFlowFunc(("pBackendData=%#p uOffset=%llu pvBuf=%#p cbToWrite=%zu pcbWriteProcess=%#p pcbPreRead=%#p pcbPostRead=%#p\n", pBackendData, uOffset, pvBuf, cbToWrite, pcbWriteProcess, pcbPreRead, pcbPostRead));
     
    17101710    /* cbSize */
    17111711    sizeof(VBOXHDDBACKEND),
     1712    /* uBackendCaps */
     1713      VD_CAP_UUID | VD_CAP_CREATE_FIXED | VD_CAP_CREATE_DYNAMIC
     1714    | VD_CAP_CREATE_SPLIT_2G | VD_CAP_DIFF,
    17121715    /* pfnCheckIfValid */
    17131716    vdiCheckIfValid,
  • trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp

    r7653 r7780  
    36833683static int vmdkWrite(void *pBackendData, uint64_t uOffset, const void *pvBuf,
    36843684                     size_t cbToWrite, size_t *pcbWriteProcess,
    3685                      size_t *pcbPreRead, size_t *pcbPostRead)
     3685                     size_t *pcbPreRead, size_t *pcbPostRead, unsigned fWrite)
    36863686{
    36873687    LogFlowFunc(("pBackendData=%#p uOffset=%llu pvBuf=%#p cbToWrite=%zu pcbWriteProcess=%#p pcbPreRead=%#p pcbPostRead=%#p\n", pBackendData, uOffset, pvBuf, cbToWrite, pcbWriteProcess, pcbPreRead, pcbPostRead));
     
    43504350    /* cbSize */
    43514351    sizeof(VBOXHDDBACKEND),
     4352    /* uBackendCaps */
     4353      VD_CAP_UUID | VD_CAP_CREATE_FIXED | VD_CAP_CREATE_DYNAMIC
     4354    | VD_CAP_CREATE_SPLIT_2G | VD_CAP_DIFF,
    43524355    /* pfnCheckIfValid */
    43534356    vmdkCheckIfValid,
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