VirtualBox

Changeset 7277 in vbox


Ignore:
Timestamp:
Mar 4, 2008 2:12:17 PM (17 years ago)
Author:
vboxsync
Message:

Make the backend type a per-image property and get away from the per container property. Required e.g. for snapshotting iSCSI disks (whenever we get there).

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxHDD-new.h

    r6291 r7277  
    202202 *
    203203 * @returns VBox status code.
    204  * @param   pszBackend      Name of the image file backend to use.
    205204 * @param   pfnError        Callback for setting extended error information.
    206205 * @param   pvErrorUser     Opaque parameter for pfnError.
    207206 * @param   ppDisk          Where to store the reference to HDD container.
    208207 */
    209 VBOXDDU_DECL(int) VDCreate(const char *pszBackend, PFNVDERROR pfnError,
    210                            void *pvErrorUser, PVBOXHDD *ppDisk);
     208VBOXDDU_DECL(int) VDCreate(PFNVDERROR pfnError, void *pvErrorUser,
     209                           PVBOXHDD *ppDisk);
    211210
    212211/**
     
    243242 * @returns VBox status code.
    244243 * @param   pDisk           Pointer to HDD container.
     244 * @param   pszBackend      Name of the image file backend to use.
    245245 * @param   pszFilename     Name of the image file to open.
    246246 * @param   uOpenFlags      Image file open mode, see VD_OPEN_FLAGS_* constants.
    247247 */
    248 VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszFilename,
    249                          unsigned uOpenFlags);
     248VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
     249                         const char *pszFilename, unsigned uOpenFlags);
    250250
    251251/**
     
    254254 * @returns VBox status code.
    255255 * @param   pDisk           Pointer to HDD container.
     256 * @param   pszBackend      Name of the image file backend to use.
    256257 * @param   pszFilename     Name of the image file to create.
    257258 * @param   enmType         Image type, only base image types are acceptable.
     
    265266 * @param   pvUser          User argument for the progress callback.
    266267 */
    267 VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszFilename,
    268                                VDIMAGETYPE enmType, uint64_t cbSize,
    269                                unsigned uImageFlags, const char *pszComment,
     268VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
     269                               const char *pszFilename, VDIMAGETYPE enmType,
     270                               uint64_t cbSize, unsigned uImageFlags,
     271                               const char *pszComment,
    270272                               PCPDMMEDIAGEOMETRY pPCHSGeometry,
    271273                               PCPDMMEDIAGEOMETRY pLCHSGeometry,
     
    279281 * @returns VBox status code.
    280282 * @param   pDisk           Pointer to HDD container.
     283 * @param   pszBackend      Name of the image file backend to use.
    281284 * @param   pszFilename     Name of the differencing image file to create.
    282285 * @param   uImageFlags     Flags specifying special image features.
     
    286289 * @param   pvUser          User argument for the progress callback.
    287290 */
    288 VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszFilename,
    289                                unsigned uImageFlags, const char *pszComment,
    290                                unsigned uOpenFlags, PFNVMPROGRESS pfnProgress,
    291                                void *pvUser);
     291VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
     292                               const char *pszFilename, unsigned uImageFlags,
     293                               const char *pszComment, unsigned uOpenFlags,
     294                               PFNVMPROGRESS pfnProgress, void *pvUser);
    292295
    293296/**
     
    313316 * The copy is opened in the target HDD container.
    314317 * It is possible to convert between different image formats, because the
    315  * backend for the destination HDD container may be different from the
    316  * source container.
     318 * backend for the destination may be different from the source.
    317319 * If both the source and destination reference the same HDD container,
    318320 * then the image is moved (by copying/deleting or renaming) to the new location.
     
    325327 * @param   nImage          Image number, counts from 0. 0 is always base image of container.
    326328 * @param   pDiskTo         Pointer to destination HDD container.
     329 * @param   pszBackend      Name of the image file backend to use (may be NULL to use the same as the source).
    327330 * @param   pszFilename     New name of the image (may be NULL if pDiskFrom == pDiskTo).
    328331 * @param   fMoveByRename   If true, attempt to perform a move by renaming (if successful the new size is ignored).
     
    332335 */
    333336VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
    334                          const char *pszFilename, bool fMoveByRename,
    335                          uint64_t cbSize, PFNVMPROGRESS pfnProgress,
    336                          void *pvUser);
     337                         const char *pszBackend, const char *pszFilename,
     338                         bool fMoveByRename, uint64_t cbSize,
     339                         PFNVMPROGRESS pfnProgress, void *pvUser);
    337340
    338341/**
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r6324 r7277  
    6262    /** Pointer to the driver instance. */
    6363    PPDMDRVINS      pDrvIns;
    64     /** Name of the image format backend. */
    65     char            szFormat[16];
    6664    /** Flag whether suspend has changed image open mode to read only. */
    6765    bool            fTempReadOnly;
     
    255253    PVBOXDISK pData = PDMINS2DATA(pDrvIns, PVBOXDISK);
    256254    int rc = VINF_SUCCESS;
    257     char *pszName;          /**< The path of the disk image file. */
     255    char *pszName = NULL;   /**< The path of the disk image file. */
     256    char *pszFormat = NULL; /**< The format backed to use for this image. */
    258257    bool fReadOnly;         /**< True if the media is readonly. */
    259258    bool fHonorZeroWrites;  /**< True if zero blocks should be written. */
     
    263262     */
    264263    pDrvIns->IBase.pfnQueryInterface    = drvvdQueryInterface;
    265     pData->pDrvIns = pDrvIns;
    266     pData->fTempReadOnly = false;
     264    pData->pDrvIns                      = pDrvIns;
     265    pData->fTempReadOnly                = false;
     266    pData->pDisk                        = NULL;
    267267
    268268    /* IMedia */
     
    290290        if (pCurNode == pCfgHandle)
    291291        {
    292             /* Toplevel configuration contains the format backend name and
    293              * full image open information. */
     292            /* Toplevel configuration additionally contains the global image
     293             * open flags. Some might be converted to per-image flags later. */
    294294            fValid = CFGMR3AreValuesValid(pCurNode,
    295                                           "Format\0"
    296                                           "Path\0ReadOnly\0HonorZeroWrites\0");
     295                                          "Format\0Path\0"
     296                                          "ReadOnly\0HonorZeroWrites\0");
    297297        }
    298298        else
    299299        {
    300             /* All other image configurations only contain image name. */
    301             fValid = CFGMR3AreValuesValid(pCurNode, "Path\0");
     300            /* All other image configurations only contain image name and
     301             * the format information. */
     302            fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0");
    302303        }
    303304        if (!fValid)
     
    320321    if (VBOX_SUCCESS(rc))
    321322    {
    322         rc = CFGMR3QueryString(pCfgHandle, "Format", &pData->szFormat[0],
    323                                sizeof(pData->szFormat));
    324         if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    325         {
    326             /* Default disk image format is VMDK. */
    327             rc = VINF_SUCCESS;
    328             strncpy(&pData->szFormat[0], "VMDK", sizeof(pData->szFormat));
    329             pData->szFormat[sizeof(pData->szFormat) - 1] = '\0';
    330         }
    331         if (VBOX_SUCCESS(rc))
    332         {
    333             rc = VDCreate(pData->szFormat, drvvdErrorCallback, pDrvIns, &pData->pDisk);
    334             /* Error message is already set correctly. */
    335         }
    336         else
    337             rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    338                                   N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
     323        rc = VDCreate(drvvdErrorCallback, pDrvIns, &pData->pDisk);
     324        /* Error message is already set correctly. */
    339325    }
    340326
     
    347333        if (VBOX_FAILURE(rc))
    348334        {
    349             VDDestroy(pData->pDisk);
    350335            rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    351336                                  N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
     337            break;
     338        }
     339
     340        rc = CFGMR3QueryStringAlloc(pCfgHandle, "Format", &pszFormat);
     341        if (VBOX_FAILURE(rc))
     342        {
     343            rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     344                                  N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
    352345            break;
    353346        }
     
    360353            else if (VBOX_FAILURE(rc))
    361354            {
    362                 MMR3HeapFree(pszName);
    363                 VDDestroy(pData->pDisk);
    364355                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    365356                                      N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
     
    372363            else if (VBOX_FAILURE(rc))
    373364            {
    374                 MMR3HeapFree(pszName);
    375                 VDDestroy(pData->pDisk);
    376365                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    377366                                      N_("DrvVD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
     
    395384        if (fHonorZeroWrites)
    396385            uOpenFlags |= VD_OPEN_FLAGS_HONOR_ZEROES;
    397         rc = VDOpen(pData->pDisk, pszName, uOpenFlags);
     386        rc = VDOpen(pData->pDisk, pszFormat, pszName, uOpenFlags);
    398387        if (VBOX_SUCCESS(rc))
    399388            Log(("%s: %d - Opened '%s' in %s mode\n", __FUNCTION__,
     
    403392        {
    404393            AssertMsgFailed(("Failed to open image '%s' rc=%Vrc\n", pszName, rc));
    405             VDDestroy(pData->pDisk);
    406394            break;
    407395        }
    408396        MMR3HeapFree(pszName);
     397        pszName = NULL;
     398        MMR3HeapFree(pszFormat);
     399        pszFormat = NULL;
    409400
    410401        /* next */
    411402        iLevel--;
    412403        pCurNode = CFGMR3GetParent(pCurNode);
     404    }
     405
     406    if (VBOX_FAILURE(rc))
     407    {
     408        if (VALID_PTR(pData->pDisk))
     409        {
     410            VDDestroy(pData->pDisk);
     411            pData->pDisk = NULL;
     412        }
     413        if (VALID_PTR(pszName))
     414            MMR3HeapFree(pszName);
     415        if (VALID_PTR(pszFormat))
     416            MMR3HeapFree(pszFormat);
    413417    }
    414418
  • trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp

    r7199 r7277  
    5959     * the backends will never ever see). */
    6060    unsigned        uOpenFlags;
     61
     62    /** Handle for the shared object / DLL. */
     63    RTLDRMOD            hPlugin;
     64    /** Function pointers for the various backend methods. */
     65    PCVBOXHDDBACKEND    Backend;
    6166} VDIMAGE, *PVDIMAGE;
    6267
     
    101106    /** Opaque data for error callback. */
    102107    void                *pvErrorUser;
    103 
    104     /** Handle for the shared object / DLL. */
    105     RTLDRMOD            hPlugin;
    106     /** Function pointers for the various backend methods. */
    107     PCVBOXHDDBACKEND    Backend;
    108108};
    109109
     
    127127
    128128/**
    129  * internal: issue early error message.
    130  */
    131 static int vdEarlyError(PFNVDERROR pfnError, void *pvErrorUser, int rc,
    132                         RT_SRC_POS_DECL, const char *pszFormat, ...)
    133 {
    134     va_list va;
    135     va_start(va, pszFormat);
    136     if (pfnError)
    137         pfnError(pvErrorUser, rc, RT_SRC_POS_ARGS, pszFormat, va);
    138     va_end(va);
    139     return rc;
    140 }
    141 
    142 /**
    143129 * internal: issue error message.
    144130 */
     
    151137        pDisk->pfnError(pDisk->pvErrorUser, rc, RT_SRC_POS_ARGS, pszFormat, va);
    152138    va_end(va);
     139    return rc;
     140}
     141
     142/**
     143 * internal: find image format backend.
     144 */
     145static int vdFindBackend(const char *pszBackend, PCVBOXHDDBACKEND *ppBackend,
     146                         RTLDRMOD *phPlugin)
     147{
     148    int rc = VINF_SUCCESS;
     149    PCVBOXHDDBACKEND pBackend = NULL;
     150    RTLDRMOD hPlugin = NIL_RTLDRMOD;
     151
     152    for (unsigned i = 0; aBackends[i] != NULL; i++)
     153    {
     154        if (!strcmp(pszBackend, aBackends[i]->pszBackendName))
     155        {
     156            pBackend = aBackends[i];
     157            break;
     158        }
     159    }
     160
     161    /* If no static backend is found try loading a shared module with
     162     * pszBackend as filename. */
     163    if (!pBackend)
     164    {
     165        char *pszPluginName;
     166
     167        /* HDD Format Plugins have VBoxHDD as prefix, prepend it. */
     168        RTStrAPrintf(&pszPluginName, "%s%s",
     169                     VBOX_HDDFORMAT_PLUGIN_PREFIX, pszBackend);
     170        if (!pszPluginName)
     171        {
     172            rc = VERR_NO_MEMORY;
     173            goto out;
     174        }
     175
     176        /* Try to load the plugin (RTldrLoad takes care of the suffix). */
     177        rc = RTLdrLoad(pszPluginName, &hPlugin);
     178        if (VBOX_SUCCESS(rc))
     179        {
     180            PFNVBOXHDDFORMATLOAD pfnHDDFormatLoad;
     181
     182            rc = RTLdrGetSymbol(hPlugin, VBOX_HDDFORMAT_LOAD_NAME,
     183                                (void**)&pfnHDDFormatLoad);
     184            if (VBOX_FAILURE(rc) || !pfnHDDFormatLoad)
     185            {
     186                LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pszPluginName, rc, pfnHDDFormatLoad));
     187                if (VBOX_SUCCESS(rc))
     188                    rc = VERR_SYMBOL_NOT_FOUND;
     189                goto out;
     190            }
     191
     192            /* Get the function table. */
     193            PVBOXHDDBACKEND pBE;
     194            rc = pfnHDDFormatLoad(&pBE);
     195            if (VBOX_FAILURE(rc))
     196                goto out;
     197            /* Check if the sizes match. If not this plugin is too old. */
     198            if (pBE->cbSize != sizeof(VBOXHDDBACKEND))
     199            {
     200                rc = VERR_VDI_UNSUPPORTED_VERSION;
     201                goto out;
     202            }
     203            pBackend = pBE;
     204        }
     205        else
     206        {
     207            /* If the backend plugin doesn't exist, don't treat this as an
     208             * error. Just return the NULL pointers. */
     209            rc = VINF_SUCCESS;
     210        }
     211
     212        RTStrFree(pszPluginName);
     213    }
     214
     215out:
     216    if (VBOX_FAILURE(rc))
     217    {
     218        if (hPlugin != NIL_RTLDRMOD)
     219            RTLdrClose(hPlugin);
     220        hPlugin = NIL_RTLDRMOD;
     221        pBackend = NULL;
     222    }
     223
     224    *ppBackend = pBackend;
     225    *phPlugin = hPlugin;
    153226    return rc;
    154227}
     
    240313             pCurrImage = pCurrImage->pPrev)
    241314        {
    242             rc = pDisk->Backend->pfnRead(pCurrImage->pvBackendData, uOffset,
    243                                          pvBuf, cbThisRead, &cbThisRead);
     315            rc = pCurrImage->Backend->pfnRead(pCurrImage->pvBackendData,
     316                                              uOffset, pvBuf, cbThisRead,
     317                                              &cbThisRead);
    244318        }
    245319
     
    272346
    273347            RTUuidCreate(&Uuid);
    274             pDisk->Backend->pfnSetModificationUuid(pDisk->pLast->pvBackendData,
    275                                                    &Uuid);
     348            pDisk->pLast->Backend->pfnSetModificationUuid(pDisk->pLast->pvBackendData,
     349                                                          &Uuid);
    276350        }
    277351
     
    294368
    295369        if (!(pDisk->uModified | VD_IMAGE_MODIFIED_DISABLE_UUID_UPDATE))
    296             pDisk->Backend->pfnFlush(pDisk->pLast->pvBackendData);
     370            pDisk->pLast->Backend->pfnFlush(pDisk->pLast->pvBackendData);
    297371    }
    298372}
     
    364438
    365439    /* Write the full block to the virtual disk. */
    366     rc = pDisk->Backend->pfnWrite(pImage->pvBackendData,
    367                                   uOffset - cbPreRead, pvTmp,
    368                                   cbPreRead + cbThisWrite + cbPostRead,
    369                                   NULL,
    370                                   &cbPreRead, &cbPostRead);
     440    rc = pImage->Backend->pfnWrite(pImage->pvBackendData,
     441                                   uOffset - cbPreRead, pvTmp,
     442                                   cbPreRead + cbThisWrite + cbPostRead,
     443                                   NULL,
     444                                   &cbPreRead, &cbPostRead);
    371445    Assert(rc != VERR_VDI_BLOCK_FREE);
    372446    Assert(cbPreRead == 0);
     
    444518
    445519    /* Write the full block to the virtual disk. */
    446     rc = pDisk->Backend->pfnWrite(pImage->pvBackendData,
    447                                   uOffset - cbPreRead, pvTmp,
    448                                   cbPreRead + cbThisWrite + cbPostRead,
    449                                   NULL,
    450                                   &cbPreRead, &cbPostRead);
     520    rc = pImage->Backend->pfnWrite(pImage->pvBackendData,
     521                                   uOffset - cbPreRead, pvTmp,
     522                                   cbPreRead + cbThisWrite + cbPostRead,
     523                                   NULL,
     524                                   &cbPreRead, &cbPostRead);
    451525    Assert(rc != VERR_VDI_BLOCK_FREE);
    452526    Assert(cbPreRead == 0);
     
    475549         * block if needed. */
    476550        cbThisWrite = cbWrite;
    477         rc = pDisk->Backend->pfnWrite(pImage->pvBackendData, uOffset, pvBuf,
    478                                       cbThisWrite, &cbThisWrite, &cbPreRead,
    479                                       &cbPostRead);
     551        rc = pImage->Backend->pfnWrite(pImage->pvBackendData, uOffset, pvBuf,
     552                                       cbThisWrite, &cbThisWrite, &cbPreRead,
     553                                       &cbPostRead);
    480554        if (rc == VERR_VDI_BLOCK_FREE)
    481555        {
     
    520594 *
    521595 * @returns VBox status code.
    522  * @param   pszBackend      Name of the image file backend to use.
    523596 * @param   pfnError        Callback for setting extended error information.
    524597 * @param   pvErrorUser     Opaque parameter for pfnError.
    525598 * @param   ppDisk          Where to store the reference to HDD container.
    526599 */
    527 VBOXDDU_DECL(int) VDCreate(const char *pszBackend, PFNVDERROR pfnError,
    528                            void *pvErrorUser, PVBOXHDD *ppDisk)
     600VBOXDDU_DECL(int) VDCreate(PFNVDERROR pfnError, void *pvErrorUser,
     601                           PVBOXHDD *ppDisk)
    529602{
    530603    int rc = VINF_SUCCESS;
    531     PCVBOXHDDBACKEND pBackend = NULL;
    532604    PVBOXHDD pDisk = NULL;
    533     RTLDRMOD hPlugin = NULL;
    534 
    535     LogFlowFunc(("pszBackend=\"%s\" pfnError=%#p pvErrorUser=%#p\n",
    536                  pszBackend, pfnError, pvErrorUser));
     605
     606    LogFlowFunc(("pfnError=%#p pvErrorUser=%#p\n", pfnError, pvErrorUser));
    537607    do
    538608    {
    539609        /* Check arguments. */
    540         AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
    541                        ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
    542                        rc = VERR_INVALID_PARAMETER);
    543610        AssertMsgBreak(VALID_PTR(pfnError),
    544611                       ("pfnError=%#p\n", pfnError),
     
    548615                       rc = VERR_INVALID_PARAMETER);
    549616
    550         /* Find backend. */
    551         for (unsigned i = 0; aBackends[i] != NULL; i++)
    552         {
    553             if (!strcmp(pszBackend, aBackends[i]->pszBackendName))
    554             {
    555                 pBackend = aBackends[i];
    556                 break;
    557             }
    558         }
    559 
    560         /* If no static backend is found try loading a shared module with
    561          * pszBackend as filename. */
    562         if (!pBackend)
    563         {
    564             char *pszPluginName;
    565 
    566             /* HDD Format Plugins have VBoxHDD as prefix, prepend it. */
    567             RTStrAPrintf(&pszPluginName, "%s%s",
    568                          VBOX_HDDFORMAT_PLUGIN_PREFIX, pszBackend);
    569             if (!pszPluginName)
    570             {
    571                 rc = VERR_NO_MEMORY;
    572                 break;
    573             }
    574 
    575             /* Try to load the plugin (RTldrLoad takes care of the suffix). */
    576             rc = RTLdrLoad(pszPluginName, &hPlugin);
    577             if (VBOX_SUCCESS(rc))
    578             {
    579                 PFNVBOXHDDFORMATLOAD pfnHDDFormatLoad;
    580 
    581                 rc = RTLdrGetSymbol(hPlugin, VBOX_HDDFORMAT_LOAD_NAME,
    582                                     (void**)&pfnHDDFormatLoad);
    583                 if (VBOX_FAILURE(rc) || !pfnHDDFormatLoad)
    584                 {
    585                     LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pszPluginName, rc, pfnHDDFormatLoad));
    586                     if (VBOX_SUCCESS(rc))
    587                         rc = VERR_SYMBOL_NOT_FOUND;
    588                     break;
    589                 }
    590 
    591                 /* Get the function table. */
    592                 PVBOXHDDBACKEND pBE;
    593                 rc = pfnHDDFormatLoad(&pBE);
    594                 if (VBOX_FAILURE(rc))
    595                     break;
    596                 /* Check if the sizes match. If not this plugin is too old. */
    597                 if (pBE->cbSize != sizeof(VBOXHDDBACKEND))
    598                 {
    599                     rc = VERR_VDI_UNSUPPORTED_VERSION;
    600                     break;
    601                 }
    602                 pBackend = pBE;
    603             }
    604 
    605             RTStrFree(pszPluginName);
    606         }
    607 
    608         if (pBackend)
    609         {
    610             pDisk = (PVBOXHDD)RTMemAllocZ(sizeof(VBOXHDD));
    611             if (pDisk)
    612             {
    613                 pDisk->u32Signature = VBOXHDDDISK_SIGNATURE;
    614                 pDisk->cImages      = 0;
    615                 pDisk->pBase        = NULL;
    616                 pDisk->pLast        = NULL;
    617                 pDisk->cbSize       = 0;
    618                 pDisk->PCHSGeometry.cCylinders = 0;
    619                 pDisk->PCHSGeometry.cHeads     = 0;
    620                 pDisk->PCHSGeometry.cSectors   = 0;
    621                 pDisk->LCHSGeometry.cCylinders = 0;
    622                 pDisk->LCHSGeometry.cHeads     = 0;
    623                 pDisk->LCHSGeometry.cSectors   = 0;
    624                 pDisk->pfnError     = pfnError;
    625                 pDisk->pvErrorUser  = pvErrorUser;
    626                 pDisk->Backend      = pBackend;
    627                 pDisk->hPlugin      = hPlugin;
    628                 *ppDisk = pDisk;
    629             }
    630             else
    631             {
    632                 rc = VERR_NO_MEMORY;
    633                 break;
    634             }
     617        pDisk = (PVBOXHDD)RTMemAllocZ(sizeof(VBOXHDD));
     618        if (pDisk)
     619        {
     620            pDisk->u32Signature = VBOXHDDDISK_SIGNATURE;
     621            pDisk->cImages      = 0;
     622            pDisk->pBase        = NULL;
     623            pDisk->pLast        = NULL;
     624            pDisk->cbSize       = 0;
     625            pDisk->PCHSGeometry.cCylinders = 0;
     626            pDisk->PCHSGeometry.cHeads     = 0;
     627            pDisk->PCHSGeometry.cSectors   = 0;
     628            pDisk->LCHSGeometry.cCylinders = 0;
     629            pDisk->LCHSGeometry.cHeads     = 0;
     630            pDisk->LCHSGeometry.cSectors   = 0;
     631            pDisk->pfnError     = pfnError;
     632            pDisk->pvErrorUser  = pvErrorUser;
     633            *ppDisk = pDisk;
    635634        }
    636635        else
    637             rc = vdEarlyError(pfnError, pvErrorUser, VERR_INVALID_PARAMETER,
    638                               RT_SRC_POS, "VD: unknown backend name '%s'",
    639                               pszBackend);
    640     } while (0);
    641 
    642     if (VBOX_FAILURE(rc) && hPlugin)
    643         RTLdrClose(hPlugin);
     636        {
     637            rc = VERR_NO_MEMORY;
     638            break;
     639        }
     640    } while (0);
    644641
    645642    LogFlowFunc(("returns %Vrc (pDisk=%#p)\n", rc, pDisk));
     
    665662        {
    666663            VDCloseAll(pDisk);
    667             if (pDisk->hPlugin != NIL_RTLDRMOD)
    668             {
    669                 RTLdrClose(pDisk->hPlugin);
    670                 pDisk->hPlugin = NIL_RTLDRMOD;
    671             }
    672664            RTMemFree(pDisk);
    673665        }
     
    856848 * @returns VBox status code.
    857849 * @param   pDisk           Pointer to HDD container.
     850 * @param   pszBackend      Name of the image file backend to use.
    858851 * @param   pszFilename     Name of the image file to open.
    859852 * @param   uOpenFlags      Image file open mode, see VD_OPEN_FLAGS_* constants.
    860853 */
    861 VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszFilename,
    862                          unsigned uOpenFlags)
     854VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
     855                         const char *pszFilename, unsigned uOpenFlags)
    863856{
    864857    int rc = VINF_SUCCESS;
    865858    PVDIMAGE pImage = NULL;
    866859
    867     LogFlowFunc(("pDisk=%#p pszFilename=\"%s\" uOpenFlags=%#x\n",
    868                  pszFilename, uOpenFlags));
     860    LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uOpenFlags=%#x\n",
     861                 pDisk, pszBackend, pszFilename, uOpenFlags));
    869862    do
    870863    {
     
    874867
    875868        /* Check arguments. */
     869        AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
     870                       ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
     871                       rc = VERR_INVALID_PARAMETER);
    876872        AssertMsgBreak(VALID_PTR(pszFilename) && *pszFilename,
    877873                       ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
     
    899895        }
    900896
     897        rc = vdFindBackend(pszBackend, &pImage->Backend, &pImage->hPlugin);
     898        if (VBOX_FAILURE(rc))
     899            break;
     900        if (!pImage->Backend)
     901        {
     902            rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
     903                         N_("VD: unknown backend name '%s'"), pszBackend);
     904            break;
     905        }
     906
    901907        pImage->uOpenFlags = uOpenFlags & VD_OPEN_FLAGS_HONOR_SAME;
    902         rc = pDisk->Backend->pfnOpen(pImage->pszFilename,
    903                                      uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME,
    904                                      pDisk->pfnError, pDisk->pvErrorUser,
    905                                      &pImage->pvBackendData);
     908        rc = pImage->Backend->pfnOpen(pImage->pszFilename,
     909                                      uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME,
     910                                      pDisk->pfnError, pDisk->pvErrorUser,
     911                                      &pImage->pvBackendData);
    906912        /* If the open in read-write mode failed, retry in read-only mode. */
    907913        if (VBOX_FAILURE(rc))
     
    913919                     || rc == VERR_SHARING_VIOLATION
    914920                     || rc == VERR_FILE_LOCK_FAILED))
    915                 rc = pDisk->Backend->pfnOpen(pImage->pszFilename,
    916                                                (uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME)
    917                                              | VD_OPEN_FLAGS_READONLY,
    918                                              pDisk->pfnError, pDisk->pvErrorUser,
    919                                              &pImage->pvBackendData);
     921                rc = pImage->Backend->pfnOpen(pImage->pszFilename,
     922                                                (uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME)
     923                                               | VD_OPEN_FLAGS_READONLY,
     924                                               pDisk->pfnError, pDisk->pvErrorUser,
     925                                               &pImage->pvBackendData);
    920926            if (VBOX_FAILURE(rc))
    921927            {
     
    927933
    928934        VDIMAGETYPE enmImageType;
    929         rc = pDisk->Backend->pfnGetImageType(pImage->pvBackendData,
    930                                              &enmImageType);
     935        rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData,
     936                                              &enmImageType);
    931937        /* Check image type. As the image itself has no idea whether it's a
    932938         * base image or not, this info is derived here. Image 0 can be fixed
     
    946952
    947953        /* Cache disk information. */
    948         pDisk->cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
     954        pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
    949955
    950956        /* Cache PCHS geometry. */
    951         rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
    952                                                  &pDisk->PCHSGeometry);
     957        rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
     958                                                  &pDisk->PCHSGeometry);
    953959        if (VBOX_FAILURE(rc2))
    954960        {
     
    966972
    967973        /* Cache LCHS geometry. */
    968         rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
    969                                                  &pDisk->LCHSGeometry);
     974        rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
     975                                                  &pDisk->LCHSGeometry);
    970976        if (VBOX_FAILURE(rc2))
    971977        {
     
    986992            /* Switch previous image to read-only mode. */
    987993            unsigned uOpenFlagsPrevImg;
    988             uOpenFlagsPrevImg = pDisk->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
     994            uOpenFlagsPrevImg = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
    989995            if (!(uOpenFlagsPrevImg & VD_OPEN_FLAGS_READONLY))
    990996            {
    991997                uOpenFlagsPrevImg |= VD_OPEN_FLAGS_READONLY;
    992                 rc = pDisk->Backend->pfnSetOpenFlags(pDisk->pLast->pvBackendData, uOpenFlagsPrevImg);
     998                rc = pDisk->pLast->Backend->pfnSetOpenFlags(pDisk->pLast->pvBackendData, uOpenFlagsPrevImg);
    993999            }
    9941000        }
     
    10031009            /* Error detected, but image opened. Close image. */
    10041010            int rc2;
    1005             rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, false);
     1011            rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, false);
    10061012            AssertRC(rc2);
    10071013            pImage->pvBackendData = NULL;
     
    10111017    if (VBOX_FAILURE(rc))
    10121018    {
     1019        if (pImage->hPlugin != NIL_RTLDRMOD)
     1020            RTLdrClose(pImage->hPlugin);
     1021
    10131022        if (pImage)
    10141023        {
     
    10281037 * @returns VBox status code.
    10291038 * @param   pDisk           Pointer to HDD container.
     1039 * @param   pszBackend      Name of the image file backend to use.
    10301040 * @param   pszFilename     Name of the image file to create.
    10311041 * @param   enmType         Image type, only base image types are acceptable.
     
    10391049 * @param   pvUser          User argument for the progress callback.
    10401050 */
    1041 VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszFilename,
    1042                                VDIMAGETYPE enmType, uint64_t cbSize,
    1043                                unsigned uImageFlags, const char *pszComment,
     1051VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
     1052                               const char *pszFilename, VDIMAGETYPE enmType,
     1053                               uint64_t cbSize, unsigned uImageFlags,
     1054                               const char *pszComment,
    10441055                               PCPDMMEDIAGEOMETRY pPCHSGeometry,
    10451056                               PCPDMMEDIAGEOMETRY pLCHSGeometry,
     
    10501061    PVDIMAGE pImage = NULL;
    10511062
    1052     LogFlowFunc(("pszFilename=\"%s\" enmType=%#x cbSize=%llu uImageFlags=%#x pszComment=\"%s\" PCHS=%u/%u/%u LCHS=%u/%u/%u uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
    1053                  pszFilename, enmType, cbSize, uImageFlags, pszComment,
     1063    LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" enmType=%#x cbSize=%llu uImageFlags=%#x pszComment=\"%s\" PCHS=%u/%u/%u LCHS=%u/%u/%u uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
     1064                 pDisk, pszBackend, pszFilename, enmType, cbSize, uImageFlags, pszComment,
    10541065                 pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads,
    10551066                 pPCHSGeometry->cSectors, pLCHSGeometry->cCylinders,
     
    10631074
    10641075        /* Check arguments. */
     1076        AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
     1077                       ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
     1078                       rc = VERR_INVALID_PARAMETER);
    10651079        AssertMsgBreak(VALID_PTR(pszFilename) && *pszFilename,
    10661080                       ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
     
    11011115        /* Check state. */
    11021116        AssertMsgBreak(pDisk->cImages == 0,
    1103                        ("Create base image cannot be done with other images open\n"),
     1117                       ("Create base image cannot be done with other images open\n"),
    11041118                       rc = VERR_VDI_INVALID_STATE);
    11051119
     
    11181132        }
    11191133
    1120         rc = pDisk->Backend->pfnCreate(pImage->pszFilename, enmType, cbSize,
    1121                                        uImageFlags, pszComment, pPCHSGeometry,
    1122                                        pLCHSGeometry, uOpenFlags, pfnProgress,
    1123                                        pvUser, 0, 99, pDisk->pfnError,
    1124                                        pDisk->pvErrorUser,
    1125                                        &pImage->pvBackendData);
     1134        rc = vdFindBackend(pszBackend, &pImage->Backend, &pImage->hPlugin);
     1135        if (VBOX_FAILURE(rc))
     1136            break;
     1137        if (!pImage->Backend)
     1138        {
     1139            rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
     1140                         N_("VD: unknown backend name '%s'"), pszBackend);
     1141            break;
     1142        }
     1143
     1144        rc = pImage->Backend->pfnCreate(pImage->pszFilename, enmType, cbSize,
     1145                                        uImageFlags, pszComment, pPCHSGeometry,
     1146                                        pLCHSGeometry, uOpenFlags, pfnProgress,
     1147                                        pvUser, 0, 99, pDisk->pfnError,
     1148                                        pDisk->pvErrorUser,
     1149                                        &pImage->pvBackendData);
    11261150
    11271151        if (VBOX_SUCCESS(rc))
     
    11321156
    11331157            /* Cache disk information. */
    1134             pDisk->cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
     1158            pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
    11351159
    11361160            /* Cache PCHS geometry. */
    1137             rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
    1138                                                      &pDisk->PCHSGeometry);
     1161            rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
     1162                                                      &pDisk->PCHSGeometry);
    11391163            if (VBOX_FAILURE(rc2))
    11401164            {
     
    11521176
    11531177            /* Cache LCHS geometry. */
    1154             rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
    1155                                                      &pDisk->LCHSGeometry);
     1178            rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
     1179                                                      &pDisk->LCHSGeometry);
    11561180            if (VBOX_FAILURE(rc2))
    11571181            {
     
    11781202            /* Error detected, but image opened. Close and delete image. */
    11791203            int rc2;
    1180             rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, true);
     1204            rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, true);
    11811205            AssertRC(rc2);
    11821206            pImage->pvBackendData = NULL;
     
    11861210    if (VBOX_FAILURE(rc))
    11871211    {
     1212        if (pImage->hPlugin != NIL_RTLDRMOD)
     1213            RTLdrClose(pImage->hPlugin);
     1214
    11881215        if (pImage)
    11891216        {
     
    12071234 * @returns VBox status code.
    12081235 * @param   pDisk           Pointer to HDD container.
     1236 * @param   pszBackend      Name of the image file backend to use.
    12091237 * @param   pszFilename     Name of the differencing image file to create.
    12101238 * @param   uImageFlags     Flags specifying special image features.
     
    12141242 * @param   pvUser          User argument for the progress callback.
    12151243 */
    1216 VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszFilename,
    1217                                unsigned uImageFlags, const char *pszComment,
    1218                                unsigned uOpenFlags, PFNVMPROGRESS pfnProgress,
    1219                                void *pvUser)
     1244VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
     1245                               const char *pszFilename, unsigned uImageFlags,
     1246                               const char *pszComment, unsigned uOpenFlags,
     1247                               PFNVMPROGRESS pfnProgress, void *pvUser)
    12201248{
    12211249    int rc = VINF_SUCCESS;
    12221250    PVDIMAGE pImage = NULL;
    12231251
    1224     LogFlowFunc(("pDisk=%#p pszFilename=\"%s\" uImageFlags=%#x pszComment=\"%s\" uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
    1225                  pDisk, pszFilename, uImageFlags, pszComment, uOpenFlags,
     1252    LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uImageFlags=%#x pszComment=\"%s\" uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
     1253                 pDisk, pszBackend, pszFilename, uImageFlags, pszComment, uOpenFlags,
    12261254                 pfnProgress, pvUser));
    12271255    do
     
    12321260
    12331261        /* Check arguments. */
     1262        AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
     1263                       ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
     1264                       rc = VERR_INVALID_PARAMETER);
    12341265        AssertMsgBreak(VALID_PTR(pszFilename) && *pszFilename,
    12351266                       ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
     
    12441275        /* Check state. */
    12451276        AssertMsgBreak(pDisk->cImages != 0,
    1246                        ("Create diff image cannot be done without other images open\n"),
     1277                       ("Create diff image cannot be done without other images open\n"),
    12471278                       rc = VERR_VDI_INVALID_STATE);
    12481279
     
    12611292        }
    12621293
    1263         rc = pDisk->Backend->pfnCreate(pImage->pszFilename,
    1264                                        VD_IMAGE_TYPE_NORMAL, pDisk->cbSize,
    1265                                        uImageFlags, pszComment,
    1266                                        &pDisk->PCHSGeometry,
    1267                                        &pDisk->LCHSGeometry, uOpenFlags,
    1268                                        pfnProgress, pvUser, 0, 99,
    1269                                        pDisk->pfnError, pDisk->pvErrorUser,
    1270                                        &pImage->pvBackendData);
     1294        rc = vdFindBackend(pszBackend, &pImage->Backend, &pImage->hPlugin);
     1295        if (VBOX_FAILURE(rc))
     1296            break;
     1297        if (!pImage->Backend)
     1298        {
     1299            rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
     1300                         N_("VD: unknown backend name '%s'"), pszBackend);
     1301            break;
     1302        }
     1303
     1304        rc = pImage->Backend->pfnCreate(pImage->pszFilename,
     1305                                        VD_IMAGE_TYPE_NORMAL, pDisk->cbSize,
     1306                                        uImageFlags, pszComment,
     1307                                        &pDisk->PCHSGeometry,
     1308                                        &pDisk->LCHSGeometry, uOpenFlags,
     1309                                        pfnProgress, pvUser, 0, 99,
     1310                                        pDisk->pfnError, pDisk->pvErrorUser,
     1311                                        &pImage->pvBackendData);
    12711312
    12721313        if (VBOX_SUCCESS(rc))
     
    12841325            /* Error detected, but image opened. Close and delete image. */
    12851326            int rc2;
    1286             rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, true);
     1327            rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, true);
    12871328            AssertRC(rc2);
    12881329            pImage->pvBackendData = NULL;
     
    12921333    if (VBOX_FAILURE(rc))
    12931334    {
     1335        if (pImage->hPlugin != NIL_RTLDRMOD)
     1336            RTLdrClose(pImage->hPlugin);
     1337
    12941338        if (pImage)
    12951339        {
     
    13461390
    13471391        /* Check if destination image is writable. */
    1348         unsigned uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImageTo->pvBackendData);
     1392        unsigned uOpenFlags = pImageTo->Backend->pfnGetOpenFlags(pImageTo->pvBackendData);
    13491393        if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
    13501394        {
     
    13541398
    13551399        /* Get size of destination image. */
    1356         uint64_t cbSize = pDisk->Backend->pfnGetSize(pImageTo->pvBackendData);
     1400        uint64_t cbSize = pImageTo->Backend->pfnGetSize(pImageTo->pvBackendData);
    13571401
    13581402        /* Allocate tmp buffer. */
     
    13801424            {
    13811425                size_t cbThisRead = RT_MIN(VD_MERGE_BUFFER_SIZE, cbRemaining);
    1382                 rc = pDisk->Backend->pfnRead(pImageTo->pvBackendData, uOffset,
    1383                                              pvBuf, cbThisRead, &cbThisRead);
     1426                rc = pImageTo->Backend->pfnRead(pImageTo->pvBackendData,
     1427                                                uOffset, pvBuf, cbThisRead,
     1428                                                &cbThisRead);
    13841429                if (VBOX_FAILURE(rc))
    13851430                    break;
     
    13941439                         pCurrImage = pCurrImage->pPrev)
    13951440                    {
    1396                         rc = pDisk->Backend->pfnRead(pCurrImage->pvBackendData,
    1397                                                      uOffset, pvBuf,
    1398                                                      cbThisRead, &cbThisRead);
     1441                        rc = pCurrImage->Backend->pfnRead(pCurrImage->pvBackendData,
     1442                                                          uOffset, pvBuf,
     1443                                                          cbThisRead,
     1444                                                          &cbThisRead);
    13991445                    }
    14001446                    if (VBOX_FAILURE(rc))
     
    14321478                     pCurrImage = pCurrImage->pPrev)
    14331479                {
    1434                     rc = pDisk->Backend->pfnRead(pCurrImage->pvBackendData,
    1435                                                  uOffset, pvBuf,
    1436                                                  cbThisRead, &cbThisRead);
     1480                    rc = pCurrImage->Backend->pfnRead(pCurrImage->pvBackendData,
     1481                                                      uOffset, pvBuf,
     1482                                                      cbThisRead, &cbThisRead);
    14371483                }
    14381484                if (VBOX_FAILURE(rc))
     
    14581504            if (pImageTo->pPrev)
    14591505            {
    1460                 rc = pDisk->Backend->pfnGetUuid(pImageTo->pPrev->pvBackendData,
    1461                                                 &Uuid);
     1506                rc = pImageTo->Backend->pfnGetUuid(pImageTo->pPrev->pvBackendData,
     1507                                                   &Uuid);
    14621508                AssertRC(rc);
    14631509            }
    14641510            else
    14651511                RTUuidClear(&Uuid);
    1466             rc = pDisk->Backend->pfnSetParentUuid(pImageTo->pvBackendData,
    1467                                                   &Uuid);
     1512            rc = pImageTo->Backend->pfnSetParentUuid(pImageTo->pvBackendData,
     1513                                                     &Uuid);
    14681514            AssertRC(rc);
    14691515        }
     
    14721518            if (pImageFrom->pNext)
    14731519            {
    1474                 rc = pDisk->Backend->pfnGetUuid(pImageTo->pvBackendData,
    1475                                                 &Uuid);
     1520                rc = pImageTo->Backend->pfnGetUuid(pImageTo->pvBackendData,
     1521                                                   &Uuid);
    14761522                AssertRC(rc);
    1477                 rc = pDisk->Backend->pfnSetParentUuid(pImageFrom->pNext,
    1478                                                       &Uuid);
     1523                rc = pImageFrom->Backend->pfnSetParentUuid(pImageFrom->pNext,
     1524                                                           &Uuid);
    14791525                AssertRC(rc);
    14801526            }
     
    14901536                pTmp = pImg->pPrev;
    14911537            vdRemoveImageFromList(pDisk, pImg);
    1492             pDisk->Backend->pfnClose(pImg->pvBackendData, true);
     1538            pImg->Backend->pfnClose(pImg->pvBackendData, true);
    14931539            pImg = pTmp;
    14941540        }
     
    15091555 * The copy is opened in the target HDD container.
    15101556 * It is possible to convert between different image formats, because the
    1511  * backend for the destination HDD container may be different from the
    1512  * source container.
     1557 * backend for the destination may be different from the source.
    15131558 * If both the source and destination reference the same HDD container,
    15141559 * then the image is moved (by copying/deleting or renaming) to the new location.
     
    15211566 * @param   nImage          Image number, counts from 0. 0 is always base image of container.
    15221567 * @param   pDiskTo         Pointer to destination HDD container.
     1568 * @param   pszBackend      Name of the image file backend to use.
    15231569 * @param   pszFilename     New name of the image (may be NULL if pDiskFrom == pDiskTo).
    15241570 * @param   fMoveByRename   If true, attempt to perform a move by renaming (if successful the new size is ignored).
     
    15281574 */
    15291575VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
    1530                          const char *pszFilename, bool fMoveByRename,
    1531                          uint64_t cbSize, PFNVMPROGRESS pfnProgress,
    1532                          void *pvUser)
     1576                         const char *pszBackend, const char *pszFilename,
     1577                         bool fMoveByRename, uint64_t cbSize,
     1578                         PFNVMPROGRESS pfnProgress, void *pvUser)
    15331579{
    15341580    return VERR_NOT_IMPLEMENTED;
     
    15501596    int rc = VINF_SUCCESS;;
    15511597
    1552     LogFlowFunc(("fDelete=%d\n", fDelete));
     1598    LogFlowFunc(("pDisk=%#p fDelete=%d\n", pDisk, fDelete));
    15531599    do
    15541600    {
     
    15581604
    15591605        PVDIMAGE pImage = pDisk->pLast;
    1560         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_NOT_OPENED);
    1561         unsigned uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImage->pvBackendData);
     1606        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_NOT_OPENED);
     1607        unsigned uOpenFlags = pImage->Backend->pfnGetOpenFlags(pImage->pvBackendData);
    15621608        /* Remove image from list of opened images. */
    15631609        vdRemoveImageFromList(pDisk, pImage);
    15641610        /* Close (and optionally delete) image. */
    1565         rc = pDisk->Backend->pfnClose(pImage->pvBackendData, fDelete);
     1611        rc = pImage->Backend->pfnClose(pImage->pvBackendData, fDelete);
    15661612        /* Free remaining resources related to the image. */
     1613        if (pImage->hPlugin != NIL_RTLDRMOD)
     1614        {
     1615            RTLdrClose(pImage->hPlugin);
     1616            pImage->hPlugin = NIL_RTLDRMOD;
     1617        }
    15671618        RTStrFree(pImage->pszFilename);
    15681619        RTMemFree(pImage);
     
    15771628        if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY))
    15781629        {
    1579             uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImage->pvBackendData);
     1630            uOpenFlags = pImage->Backend->pfnGetOpenFlags(pImage->pvBackendData);
    15801631            uOpenFlags &= ~ VD_OPEN_FLAGS_READONLY;
    1581             rc = pDisk->Backend->pfnSetOpenFlags(pImage->pvBackendData, uOpenFlags);
     1632            rc = pImage->Backend->pfnSetOpenFlags(pImage->pvBackendData, uOpenFlags);
    15821633        }
    15831634
     
    15851636
    15861637        /* Cache disk information. */
    1587         pDisk->cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
     1638        pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
    15881639
    15891640        /* Cache PCHS geometry. */
    1590         rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
     1641        rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
    15911642                                                 &pDisk->PCHSGeometry);
    15921643        if (VBOX_FAILURE(rc2))
     
    16051656
    16061657        /* Cache LCHS geometry. */
    1607         rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
    1608                                                  &pDisk->LCHSGeometry);
     1658        rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
     1659                                                  &pDisk->LCHSGeometry);
    16091660        if (VBOX_FAILURE(rc2))
    16101661        {
     
    16501701            vdRemoveImageFromList(pDisk, pImage);
    16511702            /* Close image. */
    1652             int rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, false);
     1703            int rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, false);
    16531704            if (VBOX_FAILURE(rc2) && VBOX_SUCCESS(rc))
    16541705                rc = rc2;
    16551706            /* Free remaining resources related to the image. */
     1707            if (pImage->hPlugin != NIL_RTLDRMOD)
     1708            {
     1709                RTLdrClose(pImage->hPlugin);
     1710                pImage->hPlugin = NIL_RTLDRMOD;
     1711            }
    16561712            RTStrFree(pImage->pszFilename);
    16571713            RTMemFree(pImage);
     
    17781834
    17791835        vdResetModifiedFlag(pDisk);
    1780         rc = pDisk->Backend->pfnFlush(pImage->pvBackendData);
     1836        rc = pImage->Backend->pfnFlush(pImage->pvBackendData);
    17811837    } while (0);
    17821838
     
    18311887
    18321888        unsigned uOpenFlags;
    1833         uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
     1889        uOpenFlags = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
    18341890        fReadOnly = !!(uOpenFlags & VD_OPEN_FLAGS_READONLY);
    18351891    } while (0);
     
    18601916        PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
    18611917        AssertBreak(VALID_PTR(pImage), cbSize = 0);
    1862         cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
     1918        cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
    18631919    } while (0);
    18641920
     
    18881944        PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
    18891945        AssertBreak(VALID_PTR(pImage), cbSize = 0);
    1890         cbSize = pDisk->Backend->pfnGetFileSize(pImage->pvBackendData);
     1946        cbSize = pImage->Backend->pfnGetFileSize(pImage->pvBackendData);
    18911947    } while (0);
    18921948
     
    19351991        }
    19361992        else
    1937             rc = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
    1938                                                     pPCHSGeometry);
     1993            rc = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
     1994                                                     pPCHSGeometry);
    19391995    } while (0);
    19401996
     
    19982054                 * of updating an image which could be opened in read-only mode
    19992055                 * right now. */
    2000                 rc = pDisk->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
    2001                                                         pPCHSGeometry);
     2056                rc = pImage->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
     2057                                                         pPCHSGeometry);
    20022058
    20032059                /* Cache new geometry values in any case. */
    2004                 int rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
    2005                                                              &pDisk->PCHSGeometry);
     2060                int rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
     2061                                                              &pDisk->PCHSGeometry);
    20062062                if (VBOX_FAILURE(rc2))
    20072063                {
     
    20222078        {
    20232079            PDMMEDIAGEOMETRY PCHS;
    2024             rc = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
    2025                                                     &PCHS);
     2080            rc = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
     2081                                                     &PCHS);
    20262082            if (    VBOX_FAILURE(rc)
    20272083                ||  pPCHSGeometry->cCylinders != PCHS.cCylinders
     
    20342090                 * of updating an image which could be opened in read-only mode
    20352091                 * right now. */
    2036                 rc = pDisk->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
    2037                                                         pPCHSGeometry);
     2092                rc = pImage->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
     2093                                                         pPCHSGeometry);
    20382094            }
    20392095        }
     
    20842140        }
    20852141        else
    2086             rc = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
    2087                                                     pLCHSGeometry);
     2142            rc = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
     2143                                                     pLCHSGeometry);
    20882144    } while (0);
    20892145
     
    21442200                 * of updating an image which could be opened in read-only mode
    21452201                 * right now. */
    2146                 rc = pDisk->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
    2147                                                         pLCHSGeometry);
     2202                rc = pImage->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
     2203                                                         pLCHSGeometry);
    21482204
    21492205                /* Cache new geometry values in any case. */
    2150                 int rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
    2151                                                              &pDisk->LCHSGeometry);
     2206                int rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
     2207                                                              &pDisk->LCHSGeometry);
    21522208                if (VBOX_FAILURE(rc2))
    21532209                {
     
    21682224        {
    21692225            PDMMEDIAGEOMETRY LCHS;
    2170             rc = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
    2171                                                     &LCHS);
     2226            rc = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
     2227                                                     &LCHS);
    21722228            if (    VBOX_FAILURE(rc)
    21732229                ||  pLCHSGeometry->cCylinders != LCHS.cCylinders
     
    21802236                 * of updating an image which could be opened in read-only mode
    21812237                 * right now. */
    2182                 rc = pDisk->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
    2183                                                         pLCHSGeometry);
     2238                rc = pImage->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
     2239                                                         pLCHSGeometry);
    21842240            }
    21852241        }
     
    22202276        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    22212277
    2222         *puVersion = pDisk->Backend->pfnGetVersion(pImage->pvBackendData);
     2278        *puVersion = pImage->Backend->pfnGetVersion(pImage->pvBackendData);
    22232279    } while (0);
    22242280
     
    22572313        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    22582314
    2259         rc = pDisk->Backend->pfnGetImageType(pImage->pvBackendData,
    2260                                              penmType);
     2315        rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData,
     2316                                              penmType);
    22612317    } while (0);
    22622318
     
    22952351        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    22962352
    2297         *puImageFlags = pDisk->Backend->pfnGetImageFlags(pImage->pvBackendData);
     2353        *puImageFlags = pImage->Backend->pfnGetImageFlags(pImage->pvBackendData);
    22982354    } while (0);
    22992355
     
    23322388        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    23332389
    2334         *puOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImage->pvBackendData);
     2390        *puOpenFlags = pImage->Backend->pfnGetOpenFlags(pImage->pvBackendData);
    23352391    } while (0);
    23362392
     
    23702426        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    23712427
    2372         rc = pDisk->Backend->pfnSetOpenFlags(pImage->pvBackendData,
    2373                                              uOpenFlags);
     2428        rc = pImage->Backend->pfnSetOpenFlags(pImage->pvBackendData,
     2429                                              uOpenFlags);
    23742430    } while (0);
    23752431
     
    24682524        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    24692525
    2470         rc = pDisk->Backend->pfnGetComment(pImage->pvBackendData, pszComment,
    2471                                            cbComment);
     2526        rc = pImage->Backend->pfnGetComment(pImage->pvBackendData, pszComment,
     2527                                            cbComment);
    24722528    } while (0);
    24732529
     
    25062562        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    25072563
    2508         rc = pDisk->Backend->pfnSetComment(pImage->pvBackendData, pszComment);
     2564        rc = pImage->Backend->pfnSetComment(pImage->pvBackendData, pszComment);
    25092565    } while (0);
    25102566
     
    25422598        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    25432599
    2544         rc = pDisk->Backend->pfnGetUuid(pImage->pvBackendData, pUuid);
     2600        rc = pImage->Backend->pfnGetUuid(pImage->pvBackendData, pUuid);
    25452601    } while (0);
    25462602
     
    25832639            pUuid = &Uuid;
    25842640        }
    2585         rc = pDisk->Backend->pfnSetUuid(pImage->pvBackendData, pUuid);
     2641        rc = pImage->Backend->pfnSetUuid(pImage->pvBackendData, pUuid);
    25862642    } while (0);
    25872643
     
    26182674        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    26192675
    2620         rc = pDisk->Backend->pfnGetModificationUuid(pImage->pvBackendData,
    2621                                                     pUuid);
     2676        rc = pImage->Backend->pfnGetModificationUuid(pImage->pvBackendData,
     2677                                                     pUuid);
    26222678    } while (0);
    26232679
     
    26612717            pUuid = &Uuid;
    26622718        }
    2663         rc = pDisk->Backend->pfnSetModificationUuid(pImage->pvBackendData,
    2664                                                     pUuid);
     2719        rc = pImage->Backend->pfnSetModificationUuid(pImage->pvBackendData,
     2720                                                     pUuid);
    26652721    } while (0);
    26662722
     
    26982754        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
    26992755
    2700         rc = pDisk->Backend->pfnGetParentUuid(pImage->pvBackendData, pUuid);
     2756        rc = pImage->Backend->pfnGetParentUuid(pImage->pvBackendData, pUuid);
    27012757    } while (0);
    27022758
     
    27402796            pUuid = &Uuid;
    27412797        }
    2742         rc = pDisk->Backend->pfnSetParentUuid(pImage->pvBackendData, pUuid);
     2798        rc = pImage->Backend->pfnSetParentUuid(pImage->pvBackendData, pUuid);
    27432799    } while (0);
    27442800
     
    27612817        AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
    27622818
    2763         RTLogPrintf("--- Dumping VD Disk, Backend=%s, Images=%u\n",
    2764                     pDisk->Backend->pszBackendName, pDisk->cImages);
     2819        RTLogPrintf("--- Dumping VD Disk, Images=%u\n", pDisk->cImages);
    27652820        for (PVDIMAGE pImage = pDisk->pBase; pImage; pImage = pImage->pNext)
    27662821        {
    2767             RTLogPrintf("Dumping VD image \"%s\"\n", pImage->pszFilename);
    2768             pDisk->Backend->pfnDump(pImage->pvBackendData);
    2769         }
    2770     } while (0);
    2771 }
    2772 
     2822            RTLogPrintf("Dumping VD image \"%s\" (Backend=%s)\n",
     2823                        pImage->Backend->pszBackendName, pImage->pszFilename);
     2824            pImage->Backend->pfnDump(pImage->pvBackendData);
     2825        }
     2826    } while (0);
     2827}
     2828
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r7207 r7277  
    760760            rc = CFGMR3InsertString(pCfg,   "Path",             psz);                   RC_CHECK();
    761761            STR_FREE();
     762            rc = CFGMR3InsertString(pCfg,   "Format",           "VMDK");                RC_CHECK();
    762763        }
    763764        else if (hddType == HardDiskStorageType_CustomHardDisk)
  • trunk/src/VBox/Main/HardDiskImpl.cpp

    r7207 r7277  
    33813381
    33823382    /* initialize the container */
    3383     int vrc = VDCreate ("VMDK", VDError, this, &mContainer);
     3383    int vrc = VDCreate (VDError, this, &mContainer);
    33843384    ComAssertRCRet (vrc, E_FAIL);
    33853385
     
    40494049        /// obviously. This of course changes locking behavior, but for now
    40504050        /// this is acceptable. A better solution needs to be found later.
    4051         vrc = VDOpen (mContainer, filePath, VD_OPEN_FLAGS_NORMAL);
     4051        vrc = VDOpen (mContainer, "VMDK", filePath, VD_OPEN_FLAGS_NORMAL);
    40524052        if (VBOX_FAILURE (vrc))
    40534053            break;
     
    43164316
    43174317        /* initialize the container */
    4318         vrc = VDCreate (Utf8Str (mFormat), VDError, this, &mContainer);
     4318        vrc = VDCreate (VDError, this, &mContainer);
    43194319        if (VBOX_FAILURE (vrc))
    43204320        {
     
    44174417                break;
    44184418            }
     4419            mFormat = Bstr (pszFormat);
     4420            RTStrFree (pszFormat);
    44194421
    44204422            /* Create the corresponding container. */
    4421             vrc = VDCreate (pszFormat, VDError, this, &mContainer);
    4422 
    4423             if (VBOX_SUCCESS(vrc))
    4424                 mFormat = Bstr (pszFormat);
    4425 
    4426             RTStrFree (pszFormat);
     4423            vrc = VDCreate (VDError, this, &mContainer);
    44274424
    44284425            /* the format has been already checked for presence at this point */
     
    48854882        Guid id, parentId;
    48864883
    4887         vrc = VDOpen (mContainer, location, VD_OPEN_FLAGS_INFO);
     4884        vrc = VDOpen (mContainer, Utf8Str (mFormat), location, VD_OPEN_FLAGS_INFO);
    48884885        if (VBOX_FAILURE (vrc))
    48894886            break;
     
    50835080
    50845081    /* initialize the container */
    5085     int vrc = VDCreate ("VHD", VDError, this, &mContainer);
     5082    int vrc = VDCreate (VDError, this, &mContainer);
    50865083    ComAssertRCRet (vrc, E_FAIL);
    50875084
     
    57495746        /// obviously. This of course changes locking behavior, but for now
    57505747        /// this is acceptable. A better solution needs to be found later.
    5751         vrc = VDOpen (mContainer, filePath, VD_OPEN_FLAGS_NORMAL);
     5748        vrc = VDOpen (mContainer, "VHD", filePath, VD_OPEN_FLAGS_NORMAL);
    57525749        if (VBOX_FAILURE (vrc))
    57535750            break;
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