Index: trunk/src/VBox/Devices/Storage/DrvVD.cpp
===================================================================
--- trunk/src/VBox/Devices/Storage/DrvVD.cpp	(revision 7276)
+++ trunk/src/VBox/Devices/Storage/DrvVD.cpp	(revision 7277)
@@ -62,6 +62,4 @@
     /** Pointer to the driver instance. */
     PPDMDRVINS      pDrvIns;
-    /** Name of the image format backend. */
-    char            szFormat[16];
     /** Flag whether suspend has changed image open mode to read only. */
     bool            fTempReadOnly;
@@ -255,5 +253,6 @@
     PVBOXDISK pData = PDMINS2DATA(pDrvIns, PVBOXDISK);
     int rc = VINF_SUCCESS;
-    char *pszName;          /**< The path of the disk image file. */
+    char *pszName = NULL;   /**< The path of the disk image file. */
+    char *pszFormat = NULL; /**< The format backed to use for this image. */
     bool fReadOnly;         /**< True if the media is readonly. */
     bool fHonorZeroWrites;  /**< True if zero blocks should be written. */
@@ -263,6 +262,7 @@
      */
     pDrvIns->IBase.pfnQueryInterface    = drvvdQueryInterface;
-    pData->pDrvIns = pDrvIns;
-    pData->fTempReadOnly = false;
+    pData->pDrvIns                      = pDrvIns;
+    pData->fTempReadOnly                = false;
+    pData->pDisk                        = NULL;
 
     /* IMedia */
@@ -290,14 +290,15 @@
         if (pCurNode == pCfgHandle)
         {
-            /* Toplevel configuration contains the format backend name and
-             * full image open information. */
+            /* Toplevel configuration additionally contains the global image
+             * open flags. Some might be converted to per-image flags later. */
             fValid = CFGMR3AreValuesValid(pCurNode,
-                                          "Format\0"
-                                          "Path\0ReadOnly\0HonorZeroWrites\0");
+                                          "Format\0Path\0"
+                                          "ReadOnly\0HonorZeroWrites\0");
         }
         else
         {
-            /* All other image configurations only contain image name. */
-            fValid = CFGMR3AreValuesValid(pCurNode, "Path\0");
+            /* All other image configurations only contain image name and
+             * the format information. */
+            fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0");
         }
         if (!fValid)
@@ -320,21 +321,6 @@
     if (VBOX_SUCCESS(rc))
     {
-        rc = CFGMR3QueryString(pCfgHandle, "Format", &pData->szFormat[0],
-                               sizeof(pData->szFormat));
-        if (rc == VERR_CFGM_VALUE_NOT_FOUND)
-        {
-            /* Default disk image format is VMDK. */
-            rc = VINF_SUCCESS;
-            strncpy(&pData->szFormat[0], "VMDK", sizeof(pData->szFormat));
-            pData->szFormat[sizeof(pData->szFormat) - 1] = '\0';
-        }
-        if (VBOX_SUCCESS(rc))
-        {
-            rc = VDCreate(pData->szFormat, drvvdErrorCallback, pDrvIns, &pData->pDisk);
-            /* Error message is already set correctly. */
-        }
-        else
-            rc = PDMDRV_SET_ERROR(pDrvIns, rc,
-                                  N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
+        rc = VDCreate(drvvdErrorCallback, pDrvIns, &pData->pDisk);
+        /* Error message is already set correctly. */
     }
 
@@ -347,7 +333,14 @@
         if (VBOX_FAILURE(rc))
         {
-            VDDestroy(pData->pDisk);
             rc = PDMDRV_SET_ERROR(pDrvIns, rc,
                                   N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
+            break;
+        }
+
+        rc = CFGMR3QueryStringAlloc(pCfgHandle, "Format", &pszFormat);
+        if (VBOX_FAILURE(rc))
+        {
+            rc = PDMDRV_SET_ERROR(pDrvIns, rc,
+                                  N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
             break;
         }
@@ -360,6 +353,4 @@
             else if (VBOX_FAILURE(rc))
             {
-                MMR3HeapFree(pszName);
-                VDDestroy(pData->pDisk);
                 rc = PDMDRV_SET_ERROR(pDrvIns, rc,
                                       N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
@@ -372,6 +363,4 @@
             else if (VBOX_FAILURE(rc))
             {
-                MMR3HeapFree(pszName);
-                VDDestroy(pData->pDisk);
                 rc = PDMDRV_SET_ERROR(pDrvIns, rc,
                                       N_("DrvVD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
@@ -395,5 +384,5 @@
         if (fHonorZeroWrites)
             uOpenFlags |= VD_OPEN_FLAGS_HONOR_ZEROES;
-        rc = VDOpen(pData->pDisk, pszName, uOpenFlags);
+        rc = VDOpen(pData->pDisk, pszFormat, pszName, uOpenFlags);
         if (VBOX_SUCCESS(rc))
             Log(("%s: %d - Opened '%s' in %s mode\n", __FUNCTION__,
@@ -403,12 +392,27 @@
         {
             AssertMsgFailed(("Failed to open image '%s' rc=%Vrc\n", pszName, rc));
-            VDDestroy(pData->pDisk);
             break;
         }
         MMR3HeapFree(pszName);
+        pszName = NULL;
+        MMR3HeapFree(pszFormat);
+        pszFormat = NULL;
 
         /* next */
         iLevel--;
         pCurNode = CFGMR3GetParent(pCurNode);
+    }
+
+    if (VBOX_FAILURE(rc))
+    {
+        if (VALID_PTR(pData->pDisk))
+        {
+            VDDestroy(pData->pDisk);
+            pData->pDisk = NULL;
+        }
+        if (VALID_PTR(pszName))
+            MMR3HeapFree(pszName);
+        if (VALID_PTR(pszFormat))
+            MMR3HeapFree(pszFormat);
     }
 
Index: trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp
===================================================================
--- trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp	(revision 7276)
+++ trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp	(revision 7277)
@@ -59,4 +59,9 @@
      * the backends will never ever see). */
     unsigned        uOpenFlags;
+
+    /** Handle for the shared object / DLL. */
+    RTLDRMOD            hPlugin;
+    /** Function pointers for the various backend methods. */
+    PCVBOXHDDBACKEND    Backend;
 } VDIMAGE, *PVDIMAGE;
 
@@ -101,9 +106,4 @@
     /** Opaque data for error callback. */
     void                *pvErrorUser;
-
-    /** Handle for the shared object / DLL. */
-    RTLDRMOD            hPlugin;
-    /** Function pointers for the various backend methods. */
-    PCVBOXHDDBACKEND    Backend;
 };
 
@@ -127,18 +127,4 @@
 
 /**
- * internal: issue early error message.
- */
-static int vdEarlyError(PFNVDERROR pfnError, void *pvErrorUser, int rc,
-                        RT_SRC_POS_DECL, const char *pszFormat, ...)
-{
-    va_list va;
-    va_start(va, pszFormat);
-    if (pfnError)
-        pfnError(pvErrorUser, rc, RT_SRC_POS_ARGS, pszFormat, va);
-    va_end(va);
-    return rc;
-}
-
-/**
  * internal: issue error message.
  */
@@ -151,4 +137,91 @@
         pDisk->pfnError(pDisk->pvErrorUser, rc, RT_SRC_POS_ARGS, pszFormat, va);
     va_end(va);
+    return rc;
+}
+
+/**
+ * internal: find image format backend.
+ */
+static int vdFindBackend(const char *pszBackend, PCVBOXHDDBACKEND *ppBackend,
+                         RTLDRMOD *phPlugin)
+{
+    int rc = VINF_SUCCESS;
+    PCVBOXHDDBACKEND pBackend = NULL;
+    RTLDRMOD hPlugin = NIL_RTLDRMOD;
+
+    for (unsigned i = 0; aBackends[i] != NULL; i++)
+    {
+        if (!strcmp(pszBackend, aBackends[i]->pszBackendName))
+        {
+            pBackend = aBackends[i];
+            break;
+        }
+    }
+
+    /* If no static backend is found try loading a shared module with
+     * pszBackend as filename. */
+    if (!pBackend)
+    {
+        char *pszPluginName;
+
+        /* HDD Format Plugins have VBoxHDD as prefix, prepend it. */
+        RTStrAPrintf(&pszPluginName, "%s%s",
+                     VBOX_HDDFORMAT_PLUGIN_PREFIX, pszBackend);
+        if (!pszPluginName)
+        {
+            rc = VERR_NO_MEMORY;
+            goto out;
+        }
+
+        /* Try to load the plugin (RTldrLoad takes care of the suffix). */
+        rc = RTLdrLoad(pszPluginName, &hPlugin);
+        if (VBOX_SUCCESS(rc))
+        {
+            PFNVBOXHDDFORMATLOAD pfnHDDFormatLoad;
+
+            rc = RTLdrGetSymbol(hPlugin, VBOX_HDDFORMAT_LOAD_NAME,
+                                (void**)&pfnHDDFormatLoad);
+            if (VBOX_FAILURE(rc) || !pfnHDDFormatLoad)
+            {
+                LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pszPluginName, rc, pfnHDDFormatLoad));
+                if (VBOX_SUCCESS(rc))
+                    rc = VERR_SYMBOL_NOT_FOUND;
+                goto out;
+            }
+
+            /* Get the function table. */
+            PVBOXHDDBACKEND pBE;
+            rc = pfnHDDFormatLoad(&pBE);
+            if (VBOX_FAILURE(rc))
+                goto out;
+            /* Check if the sizes match. If not this plugin is too old. */
+            if (pBE->cbSize != sizeof(VBOXHDDBACKEND))
+            {
+                rc = VERR_VDI_UNSUPPORTED_VERSION;
+                goto out;
+            }
+            pBackend = pBE;
+        }
+        else
+        {
+            /* If the backend plugin doesn't exist, don't treat this as an
+             * error. Just return the NULL pointers. */
+            rc = VINF_SUCCESS;
+        }
+
+        RTStrFree(pszPluginName);
+    }
+
+out:
+    if (VBOX_FAILURE(rc))
+    {
+        if (hPlugin != NIL_RTLDRMOD)
+            RTLdrClose(hPlugin);
+        hPlugin = NIL_RTLDRMOD;
+        pBackend = NULL;
+    }
+
+    *ppBackend = pBackend;
+    *phPlugin = hPlugin;
     return rc;
 }
@@ -240,6 +313,7 @@
              pCurrImage = pCurrImage->pPrev)
         {
-            rc = pDisk->Backend->pfnRead(pCurrImage->pvBackendData, uOffset,
-                                         pvBuf, cbThisRead, &cbThisRead);
+            rc = pCurrImage->Backend->pfnRead(pCurrImage->pvBackendData,
+                                              uOffset, pvBuf, cbThisRead,
+                                              &cbThisRead);
         }
 
@@ -272,6 +346,6 @@
 
             RTUuidCreate(&Uuid);
-            pDisk->Backend->pfnSetModificationUuid(pDisk->pLast->pvBackendData,
-                                                   &Uuid);
+            pDisk->pLast->Backend->pfnSetModificationUuid(pDisk->pLast->pvBackendData,
+                                                          &Uuid);
         }
 
@@ -294,5 +368,5 @@
 
         if (!(pDisk->uModified | VD_IMAGE_MODIFIED_DISABLE_UUID_UPDATE))
-            pDisk->Backend->pfnFlush(pDisk->pLast->pvBackendData);
+            pDisk->pLast->Backend->pfnFlush(pDisk->pLast->pvBackendData);
     }
 }
@@ -364,9 +438,9 @@
 
     /* Write the full block to the virtual disk. */
-    rc = pDisk->Backend->pfnWrite(pImage->pvBackendData,
-                                  uOffset - cbPreRead, pvTmp,
-                                  cbPreRead + cbThisWrite + cbPostRead,
-                                  NULL,
-                                  &cbPreRead, &cbPostRead);
+    rc = pImage->Backend->pfnWrite(pImage->pvBackendData,
+                                   uOffset - cbPreRead, pvTmp,
+                                   cbPreRead + cbThisWrite + cbPostRead,
+                                   NULL,
+                                   &cbPreRead, &cbPostRead);
     Assert(rc != VERR_VDI_BLOCK_FREE);
     Assert(cbPreRead == 0);
@@ -444,9 +518,9 @@
 
     /* Write the full block to the virtual disk. */
-    rc = pDisk->Backend->pfnWrite(pImage->pvBackendData,
-                                  uOffset - cbPreRead, pvTmp,
-                                  cbPreRead + cbThisWrite + cbPostRead,
-                                  NULL,
-                                  &cbPreRead, &cbPostRead);
+    rc = pImage->Backend->pfnWrite(pImage->pvBackendData,
+                                   uOffset - cbPreRead, pvTmp,
+                                   cbPreRead + cbThisWrite + cbPostRead,
+                                   NULL,
+                                   &cbPreRead, &cbPostRead);
     Assert(rc != VERR_VDI_BLOCK_FREE);
     Assert(cbPreRead == 0);
@@ -475,7 +549,7 @@
          * block if needed. */
         cbThisWrite = cbWrite;
-        rc = pDisk->Backend->pfnWrite(pImage->pvBackendData, uOffset, pvBuf,
-                                      cbThisWrite, &cbThisWrite, &cbPreRead,
-                                      &cbPostRead);
+        rc = pImage->Backend->pfnWrite(pImage->pvBackendData, uOffset, pvBuf,
+                                       cbThisWrite, &cbThisWrite, &cbPreRead,
+                                       &cbPostRead);
         if (rc == VERR_VDI_BLOCK_FREE)
         {
@@ -520,25 +594,18 @@
  *
  * @returns VBox status code.
- * @param   pszBackend      Name of the image file backend to use.
  * @param   pfnError        Callback for setting extended error information.
  * @param   pvErrorUser     Opaque parameter for pfnError.
  * @param   ppDisk          Where to store the reference to HDD container.
  */
-VBOXDDU_DECL(int) VDCreate(const char *pszBackend, PFNVDERROR pfnError,
-                           void *pvErrorUser, PVBOXHDD *ppDisk)
+VBOXDDU_DECL(int) VDCreate(PFNVDERROR pfnError, void *pvErrorUser,
+                           PVBOXHDD *ppDisk)
 {
     int rc = VINF_SUCCESS;
-    PCVBOXHDDBACKEND pBackend = NULL;
     PVBOXHDD pDisk = NULL;
-    RTLDRMOD hPlugin = NULL;
-
-    LogFlowFunc(("pszBackend=\"%s\" pfnError=%#p pvErrorUser=%#p\n",
-                 pszBackend, pfnError, pvErrorUser));
+
+    LogFlowFunc(("pfnError=%#p pvErrorUser=%#p\n", pfnError, pvErrorUser));
     do
     {
         /* Check arguments. */
-        AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
-                       ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
-                       rc = VERR_INVALID_PARAMETER);
         AssertMsgBreak(VALID_PTR(pfnError),
                        ("pfnError=%#p\n", pfnError),
@@ -548,98 +615,28 @@
                        rc = VERR_INVALID_PARAMETER);
 
-        /* Find backend. */
-        for (unsigned i = 0; aBackends[i] != NULL; i++)
-        {
-            if (!strcmp(pszBackend, aBackends[i]->pszBackendName))
-            {
-                pBackend = aBackends[i];
-                break;
-            }
-        }
-
-        /* If no static backend is found try loading a shared module with
-         * pszBackend as filename. */
-        if (!pBackend)
-        {
-            char *pszPluginName;
-
-            /* HDD Format Plugins have VBoxHDD as prefix, prepend it. */
-            RTStrAPrintf(&pszPluginName, "%s%s",
-                         VBOX_HDDFORMAT_PLUGIN_PREFIX, pszBackend);
-            if (!pszPluginName)
-            {
-                rc = VERR_NO_MEMORY;
-                break;
-            }
-
-            /* Try to load the plugin (RTldrLoad takes care of the suffix). */
-            rc = RTLdrLoad(pszPluginName, &hPlugin);
-            if (VBOX_SUCCESS(rc))
-            {
-                PFNVBOXHDDFORMATLOAD pfnHDDFormatLoad;
-
-                rc = RTLdrGetSymbol(hPlugin, VBOX_HDDFORMAT_LOAD_NAME,
-                                    (void**)&pfnHDDFormatLoad);
-                if (VBOX_FAILURE(rc) || !pfnHDDFormatLoad)
-                {
-                    LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pszPluginName, rc, pfnHDDFormatLoad));
-                    if (VBOX_SUCCESS(rc))
-                        rc = VERR_SYMBOL_NOT_FOUND;
-                    break;
-                }
-
-                /* Get the function table. */
-                PVBOXHDDBACKEND pBE;
-                rc = pfnHDDFormatLoad(&pBE);
-                if (VBOX_FAILURE(rc))
-                    break;
-                /* Check if the sizes match. If not this plugin is too old. */
-                if (pBE->cbSize != sizeof(VBOXHDDBACKEND))
-                {
-                    rc = VERR_VDI_UNSUPPORTED_VERSION;
-                    break;
-                }
-                pBackend = pBE;
-            }
-
-            RTStrFree(pszPluginName);
-        }
-
-        if (pBackend)
-        {
-            pDisk = (PVBOXHDD)RTMemAllocZ(sizeof(VBOXHDD));
-            if (pDisk)
-            {
-                pDisk->u32Signature = VBOXHDDDISK_SIGNATURE;
-                pDisk->cImages      = 0;
-                pDisk->pBase        = NULL;
-                pDisk->pLast        = NULL;
-                pDisk->cbSize       = 0;
-                pDisk->PCHSGeometry.cCylinders = 0;
-                pDisk->PCHSGeometry.cHeads     = 0;
-                pDisk->PCHSGeometry.cSectors   = 0;
-                pDisk->LCHSGeometry.cCylinders = 0;
-                pDisk->LCHSGeometry.cHeads     = 0;
-                pDisk->LCHSGeometry.cSectors   = 0;
-                pDisk->pfnError     = pfnError;
-                pDisk->pvErrorUser  = pvErrorUser;
-                pDisk->Backend      = pBackend;
-                pDisk->hPlugin      = hPlugin;
-                *ppDisk = pDisk;
-            }
-            else
-            {
-                rc = VERR_NO_MEMORY;
-                break;
-            }
+        pDisk = (PVBOXHDD)RTMemAllocZ(sizeof(VBOXHDD));
+        if (pDisk)
+        {
+            pDisk->u32Signature = VBOXHDDDISK_SIGNATURE;
+            pDisk->cImages      = 0;
+            pDisk->pBase        = NULL;
+            pDisk->pLast        = NULL;
+            pDisk->cbSize       = 0;
+            pDisk->PCHSGeometry.cCylinders = 0;
+            pDisk->PCHSGeometry.cHeads     = 0;
+            pDisk->PCHSGeometry.cSectors   = 0;
+            pDisk->LCHSGeometry.cCylinders = 0;
+            pDisk->LCHSGeometry.cHeads     = 0;
+            pDisk->LCHSGeometry.cSectors   = 0;
+            pDisk->pfnError     = pfnError;
+            pDisk->pvErrorUser  = pvErrorUser;
+            *ppDisk = pDisk;
         }
         else
-            rc = vdEarlyError(pfnError, pvErrorUser, VERR_INVALID_PARAMETER,
-                              RT_SRC_POS, "VD: unknown backend name '%s'",
-                              pszBackend);
-    } while (0);
-
-    if (VBOX_FAILURE(rc) && hPlugin)
-        RTLdrClose(hPlugin);
+        {
+            rc = VERR_NO_MEMORY;
+            break;
+        }
+    } while (0);
 
     LogFlowFunc(("returns %Vrc (pDisk=%#p)\n", rc, pDisk));
@@ -665,9 +662,4 @@
         {
             VDCloseAll(pDisk);
-            if (pDisk->hPlugin != NIL_RTLDRMOD)
-            {
-                RTLdrClose(pDisk->hPlugin);
-                pDisk->hPlugin = NIL_RTLDRMOD;
-            }
             RTMemFree(pDisk);
         }
@@ -856,15 +848,16 @@
  * @returns VBox status code.
  * @param   pDisk           Pointer to HDD container.
+ * @param   pszBackend      Name of the image file backend to use.
  * @param   pszFilename     Name of the image file to open.
  * @param   uOpenFlags      Image file open mode, see VD_OPEN_FLAGS_* constants.
  */
-VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszFilename,
-                         unsigned uOpenFlags)
+VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
+                         const char *pszFilename, unsigned uOpenFlags)
 {
     int rc = VINF_SUCCESS;
     PVDIMAGE pImage = NULL;
 
-    LogFlowFunc(("pDisk=%#p pszFilename=\"%s\" uOpenFlags=%#x\n",
-                 pszFilename, uOpenFlags));
+    LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uOpenFlags=%#x\n",
+                 pDisk, pszBackend, pszFilename, uOpenFlags));
     do
     {
@@ -874,4 +867,7 @@
 
         /* Check arguments. */
+        AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
+                       ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
+                       rc = VERR_INVALID_PARAMETER);
         AssertMsgBreak(VALID_PTR(pszFilename) && *pszFilename,
                        ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
@@ -899,9 +895,19 @@
         }
 
+        rc = vdFindBackend(pszBackend, &pImage->Backend, &pImage->hPlugin);
+        if (VBOX_FAILURE(rc))
+            break;
+        if (!pImage->Backend)
+        {
+            rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
+                         N_("VD: unknown backend name '%s'"), pszBackend);
+            break;
+        }
+
         pImage->uOpenFlags = uOpenFlags & VD_OPEN_FLAGS_HONOR_SAME;
-        rc = pDisk->Backend->pfnOpen(pImage->pszFilename,
-                                     uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME,
-                                     pDisk->pfnError, pDisk->pvErrorUser,
-                                     &pImage->pvBackendData);
+        rc = pImage->Backend->pfnOpen(pImage->pszFilename,
+                                      uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME,
+                                      pDisk->pfnError, pDisk->pvErrorUser,
+                                      &pImage->pvBackendData);
         /* If the open in read-write mode failed, retry in read-only mode. */
         if (VBOX_FAILURE(rc))
@@ -913,9 +919,9 @@
                      || rc == VERR_SHARING_VIOLATION
                      || rc == VERR_FILE_LOCK_FAILED))
-                rc = pDisk->Backend->pfnOpen(pImage->pszFilename,
-                                               (uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME)
-                                             | VD_OPEN_FLAGS_READONLY,
-                                             pDisk->pfnError, pDisk->pvErrorUser,
-                                             &pImage->pvBackendData);
+                rc = pImage->Backend->pfnOpen(pImage->pszFilename,
+                                                (uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME)
+                                               | VD_OPEN_FLAGS_READONLY,
+                                               pDisk->pfnError, pDisk->pvErrorUser,
+                                               &pImage->pvBackendData);
             if (VBOX_FAILURE(rc))
             {
@@ -927,6 +933,6 @@
 
         VDIMAGETYPE enmImageType;
-        rc = pDisk->Backend->pfnGetImageType(pImage->pvBackendData,
-                                             &enmImageType);
+        rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData,
+                                              &enmImageType);
         /* Check image type. As the image itself has no idea whether it's a
          * base image or not, this info is derived here. Image 0 can be fixed
@@ -946,9 +952,9 @@
 
         /* Cache disk information. */
-        pDisk->cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
+        pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
 
         /* Cache PCHS geometry. */
-        rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
-                                                 &pDisk->PCHSGeometry);
+        rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
+                                                  &pDisk->PCHSGeometry);
         if (VBOX_FAILURE(rc2))
         {
@@ -966,6 +972,6 @@
 
         /* Cache LCHS geometry. */
-        rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
-                                                 &pDisk->LCHSGeometry);
+        rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
+                                                  &pDisk->LCHSGeometry);
         if (VBOX_FAILURE(rc2))
         {
@@ -986,9 +992,9 @@
             /* Switch previous image to read-only mode. */
             unsigned uOpenFlagsPrevImg;
-            uOpenFlagsPrevImg = pDisk->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
+            uOpenFlagsPrevImg = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
             if (!(uOpenFlagsPrevImg & VD_OPEN_FLAGS_READONLY))
             {
                 uOpenFlagsPrevImg |= VD_OPEN_FLAGS_READONLY;
-                rc = pDisk->Backend->pfnSetOpenFlags(pDisk->pLast->pvBackendData, uOpenFlagsPrevImg);
+                rc = pDisk->pLast->Backend->pfnSetOpenFlags(pDisk->pLast->pvBackendData, uOpenFlagsPrevImg);
             }
         }
@@ -1003,5 +1009,5 @@
             /* Error detected, but image opened. Close image. */
             int rc2;
-            rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, false);
+            rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, false);
             AssertRC(rc2);
             pImage->pvBackendData = NULL;
@@ -1011,4 +1017,7 @@
     if (VBOX_FAILURE(rc))
     {
+        if (pImage->hPlugin != NIL_RTLDRMOD)
+            RTLdrClose(pImage->hPlugin);
+
         if (pImage)
         {
@@ -1028,4 +1037,5 @@
  * @returns VBox status code.
  * @param   pDisk           Pointer to HDD container.
+ * @param   pszBackend      Name of the image file backend to use.
  * @param   pszFilename     Name of the image file to create.
  * @param   enmType         Image type, only base image types are acceptable.
@@ -1039,7 +1049,8 @@
  * @param   pvUser          User argument for the progress callback.
  */
-VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszFilename,
-                               VDIMAGETYPE enmType, uint64_t cbSize,
-                               unsigned uImageFlags, const char *pszComment,
+VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
+                               const char *pszFilename, VDIMAGETYPE enmType,
+                               uint64_t cbSize, unsigned uImageFlags,
+                               const char *pszComment,
                                PCPDMMEDIAGEOMETRY pPCHSGeometry,
                                PCPDMMEDIAGEOMETRY pLCHSGeometry,
@@ -1050,6 +1061,6 @@
     PVDIMAGE pImage = NULL;
 
-    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",
-                 pszFilename, enmType, cbSize, uImageFlags, pszComment,
+    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",
+                 pDisk, pszBackend, pszFilename, enmType, cbSize, uImageFlags, pszComment,
                  pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads,
                  pPCHSGeometry->cSectors, pLCHSGeometry->cCylinders,
@@ -1063,4 +1074,7 @@
 
         /* Check arguments. */
+        AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
+                       ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
+                       rc = VERR_INVALID_PARAMETER);
         AssertMsgBreak(VALID_PTR(pszFilename) && *pszFilename,
                        ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
@@ -1101,5 +1115,5 @@
         /* Check state. */
         AssertMsgBreak(pDisk->cImages == 0,
-	               ("Create base image cannot be done with other images open\n"),
+                       ("Create base image cannot be done with other images open\n"),
                        rc = VERR_VDI_INVALID_STATE);
 
@@ -1118,10 +1132,20 @@
         }
 
-        rc = pDisk->Backend->pfnCreate(pImage->pszFilename, enmType, cbSize,
-                                       uImageFlags, pszComment, pPCHSGeometry,
-                                       pLCHSGeometry, uOpenFlags, pfnProgress,
-                                       pvUser, 0, 99, pDisk->pfnError,
-                                       pDisk->pvErrorUser,
-                                       &pImage->pvBackendData);
+        rc = vdFindBackend(pszBackend, &pImage->Backend, &pImage->hPlugin);
+        if (VBOX_FAILURE(rc))
+            break;
+        if (!pImage->Backend)
+        {
+            rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
+                         N_("VD: unknown backend name '%s'"), pszBackend);
+            break;
+        }
+
+        rc = pImage->Backend->pfnCreate(pImage->pszFilename, enmType, cbSize,
+                                        uImageFlags, pszComment, pPCHSGeometry,
+                                        pLCHSGeometry, uOpenFlags, pfnProgress,
+                                        pvUser, 0, 99, pDisk->pfnError,
+                                        pDisk->pvErrorUser,
+                                        &pImage->pvBackendData);
 
         if (VBOX_SUCCESS(rc))
@@ -1132,9 +1156,9 @@
 
             /* Cache disk information. */
-            pDisk->cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
+            pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
 
             /* Cache PCHS geometry. */
-            rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
-                                                     &pDisk->PCHSGeometry);
+            rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
+                                                      &pDisk->PCHSGeometry);
             if (VBOX_FAILURE(rc2))
             {
@@ -1152,6 +1176,6 @@
 
             /* Cache LCHS geometry. */
-            rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
-                                                     &pDisk->LCHSGeometry);
+            rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
+                                                      &pDisk->LCHSGeometry);
             if (VBOX_FAILURE(rc2))
             {
@@ -1178,5 +1202,5 @@
             /* Error detected, but image opened. Close and delete image. */
             int rc2;
-            rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, true);
+            rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, true);
             AssertRC(rc2);
             pImage->pvBackendData = NULL;
@@ -1186,4 +1210,7 @@
     if (VBOX_FAILURE(rc))
     {
+        if (pImage->hPlugin != NIL_RTLDRMOD)
+            RTLdrClose(pImage->hPlugin);
+
         if (pImage)
         {
@@ -1207,4 +1234,5 @@
  * @returns VBox status code.
  * @param   pDisk           Pointer to HDD container.
+ * @param   pszBackend      Name of the image file backend to use.
  * @param   pszFilename     Name of the differencing image file to create.
  * @param   uImageFlags     Flags specifying special image features.
@@ -1214,14 +1242,14 @@
  * @param   pvUser          User argument for the progress callback.
  */
-VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszFilename,
-                               unsigned uImageFlags, const char *pszComment,
-                               unsigned uOpenFlags, PFNVMPROGRESS pfnProgress,
-                               void *pvUser)
+VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
+                               const char *pszFilename, unsigned uImageFlags,
+                               const char *pszComment, unsigned uOpenFlags,
+                               PFNVMPROGRESS pfnProgress, void *pvUser)
 {
     int rc = VINF_SUCCESS;
     PVDIMAGE pImage = NULL;
 
-    LogFlowFunc(("pDisk=%#p pszFilename=\"%s\" uImageFlags=%#x pszComment=\"%s\" uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
-                 pDisk, pszFilename, uImageFlags, pszComment, uOpenFlags,
+    LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uImageFlags=%#x pszComment=\"%s\" uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
+                 pDisk, pszBackend, pszFilename, uImageFlags, pszComment, uOpenFlags,
                  pfnProgress, pvUser));
     do
@@ -1232,4 +1260,7 @@
 
         /* Check arguments. */
+        AssertMsgBreak(VALID_PTR(pszBackend) && *pszBackend,
+                       ("pszBackend=%#p \"%s\"\n", pszBackend, pszBackend),
+                       rc = VERR_INVALID_PARAMETER);
         AssertMsgBreak(VALID_PTR(pszFilename) && *pszFilename,
                        ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
@@ -1244,5 +1275,5 @@
         /* Check state. */
         AssertMsgBreak(pDisk->cImages != 0,
-	               ("Create diff image cannot be done without other images open\n"),
+                       ("Create diff image cannot be done without other images open\n"),
                        rc = VERR_VDI_INVALID_STATE);
 
@@ -1261,12 +1292,22 @@
         }
 
-        rc = pDisk->Backend->pfnCreate(pImage->pszFilename,
-                                       VD_IMAGE_TYPE_NORMAL, pDisk->cbSize,
-                                       uImageFlags, pszComment,
-                                       &pDisk->PCHSGeometry,
-                                       &pDisk->LCHSGeometry, uOpenFlags,
-                                       pfnProgress, pvUser, 0, 99,
-                                       pDisk->pfnError, pDisk->pvErrorUser,
-                                       &pImage->pvBackendData);
+        rc = vdFindBackend(pszBackend, &pImage->Backend, &pImage->hPlugin);
+        if (VBOX_FAILURE(rc))
+            break;
+        if (!pImage->Backend)
+        {
+            rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
+                         N_("VD: unknown backend name '%s'"), pszBackend);
+            break;
+        }
+
+        rc = pImage->Backend->pfnCreate(pImage->pszFilename,
+                                        VD_IMAGE_TYPE_NORMAL, pDisk->cbSize,
+                                        uImageFlags, pszComment,
+                                        &pDisk->PCHSGeometry,
+                                        &pDisk->LCHSGeometry, uOpenFlags,
+                                        pfnProgress, pvUser, 0, 99,
+                                        pDisk->pfnError, pDisk->pvErrorUser,
+                                        &pImage->pvBackendData);
 
         if (VBOX_SUCCESS(rc))
@@ -1284,5 +1325,5 @@
             /* Error detected, but image opened. Close and delete image. */
             int rc2;
-            rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, true);
+            rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, true);
             AssertRC(rc2);
             pImage->pvBackendData = NULL;
@@ -1292,4 +1333,7 @@
     if (VBOX_FAILURE(rc))
     {
+        if (pImage->hPlugin != NIL_RTLDRMOD)
+            RTLdrClose(pImage->hPlugin);
+
         if (pImage)
         {
@@ -1346,5 +1390,5 @@
 
         /* Check if destination image is writable. */
-        unsigned uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImageTo->pvBackendData);
+        unsigned uOpenFlags = pImageTo->Backend->pfnGetOpenFlags(pImageTo->pvBackendData);
         if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
         {
@@ -1354,5 +1398,5 @@
 
         /* Get size of destination image. */
-        uint64_t cbSize = pDisk->Backend->pfnGetSize(pImageTo->pvBackendData);
+        uint64_t cbSize = pImageTo->Backend->pfnGetSize(pImageTo->pvBackendData);
 
         /* Allocate tmp buffer. */
@@ -1380,6 +1424,7 @@
             {
                 size_t cbThisRead = RT_MIN(VD_MERGE_BUFFER_SIZE, cbRemaining);
-                rc = pDisk->Backend->pfnRead(pImageTo->pvBackendData, uOffset,
-                                             pvBuf, cbThisRead, &cbThisRead);
+                rc = pImageTo->Backend->pfnRead(pImageTo->pvBackendData,
+                                                uOffset, pvBuf, cbThisRead,
+                                                &cbThisRead);
                 if (VBOX_FAILURE(rc))
                     break;
@@ -1394,7 +1439,8 @@
                          pCurrImage = pCurrImage->pPrev)
                     {
-                        rc = pDisk->Backend->pfnRead(pCurrImage->pvBackendData,
-                                                     uOffset, pvBuf,
-                                                     cbThisRead, &cbThisRead);
+                        rc = pCurrImage->Backend->pfnRead(pCurrImage->pvBackendData,
+                                                          uOffset, pvBuf,
+                                                          cbThisRead,
+                                                          &cbThisRead);
                     }
                     if (VBOX_FAILURE(rc))
@@ -1432,7 +1478,7 @@
                      pCurrImage = pCurrImage->pPrev)
                 {
-                    rc = pDisk->Backend->pfnRead(pCurrImage->pvBackendData,
-                                                 uOffset, pvBuf,
-                                                 cbThisRead, &cbThisRead);
+                    rc = pCurrImage->Backend->pfnRead(pCurrImage->pvBackendData,
+                                                      uOffset, pvBuf,
+                                                      cbThisRead, &cbThisRead);
                 }
                 if (VBOX_FAILURE(rc))
@@ -1458,12 +1504,12 @@
             if (pImageTo->pPrev)
             {
-                rc = pDisk->Backend->pfnGetUuid(pImageTo->pPrev->pvBackendData,
-                                                &Uuid);
+                rc = pImageTo->Backend->pfnGetUuid(pImageTo->pPrev->pvBackendData,
+                                                   &Uuid);
                 AssertRC(rc);
             }
             else
                 RTUuidClear(&Uuid);
-            rc = pDisk->Backend->pfnSetParentUuid(pImageTo->pvBackendData,
-                                                  &Uuid);
+            rc = pImageTo->Backend->pfnSetParentUuid(pImageTo->pvBackendData,
+                                                     &Uuid);
             AssertRC(rc);
         }
@@ -1472,9 +1518,9 @@
             if (pImageFrom->pNext)
             {
-                rc = pDisk->Backend->pfnGetUuid(pImageTo->pvBackendData,
-                                                &Uuid);
+                rc = pImageTo->Backend->pfnGetUuid(pImageTo->pvBackendData,
+                                                   &Uuid);
                 AssertRC(rc);
-                rc = pDisk->Backend->pfnSetParentUuid(pImageFrom->pNext,
-                                                      &Uuid);
+                rc = pImageFrom->Backend->pfnSetParentUuid(pImageFrom->pNext,
+                                                           &Uuid);
                 AssertRC(rc);
             }
@@ -1490,5 +1536,5 @@
                 pTmp = pImg->pPrev;
             vdRemoveImageFromList(pDisk, pImg);
-            pDisk->Backend->pfnClose(pImg->pvBackendData, true);
+            pImg->Backend->pfnClose(pImg->pvBackendData, true);
             pImg = pTmp;
         }
@@ -1509,6 +1555,5 @@
  * The copy is opened in the target HDD container.
  * It is possible to convert between different image formats, because the
- * backend for the destination HDD container may be different from the
- * source container.
+ * backend for the destination may be different from the source.
  * If both the source and destination reference the same HDD container,
  * then the image is moved (by copying/deleting or renaming) to the new location.
@@ -1521,4 +1566,5 @@
  * @param   nImage          Image number, counts from 0. 0 is always base image of container.
  * @param   pDiskTo         Pointer to destination HDD container.
+ * @param   pszBackend      Name of the image file backend to use.
  * @param   pszFilename     New name of the image (may be NULL if pDiskFrom == pDiskTo).
  * @param   fMoveByRename   If true, attempt to perform a move by renaming (if successful the new size is ignored).
@@ -1528,7 +1574,7 @@
  */
 VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
-                         const char *pszFilename, bool fMoveByRename,
-                         uint64_t cbSize, PFNVMPROGRESS pfnProgress,
-                         void *pvUser)
+                         const char *pszBackend, const char *pszFilename,
+                         bool fMoveByRename, uint64_t cbSize,
+                         PFNVMPROGRESS pfnProgress, void *pvUser)
 {
     return VERR_NOT_IMPLEMENTED;
@@ -1550,5 +1596,5 @@
     int rc = VINF_SUCCESS;;
 
-    LogFlowFunc(("fDelete=%d\n", fDelete));
+    LogFlowFunc(("pDisk=%#p fDelete=%d\n", pDisk, fDelete));
     do
     {
@@ -1558,11 +1604,16 @@
 
         PVDIMAGE pImage = pDisk->pLast;
-	AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_NOT_OPENED);
-        unsigned uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImage->pvBackendData);
+        AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_NOT_OPENED);
+        unsigned uOpenFlags = pImage->Backend->pfnGetOpenFlags(pImage->pvBackendData);
         /* Remove image from list of opened images. */
         vdRemoveImageFromList(pDisk, pImage);
         /* Close (and optionally delete) image. */
-        rc = pDisk->Backend->pfnClose(pImage->pvBackendData, fDelete);
+        rc = pImage->Backend->pfnClose(pImage->pvBackendData, fDelete);
         /* Free remaining resources related to the image. */
+        if (pImage->hPlugin != NIL_RTLDRMOD)
+        {
+            RTLdrClose(pImage->hPlugin);
+            pImage->hPlugin = NIL_RTLDRMOD;
+        }
         RTStrFree(pImage->pszFilename);
         RTMemFree(pImage);
@@ -1577,7 +1628,7 @@
         if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY))
         {
-            uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImage->pvBackendData);
+            uOpenFlags = pImage->Backend->pfnGetOpenFlags(pImage->pvBackendData);
             uOpenFlags &= ~ VD_OPEN_FLAGS_READONLY;
-            rc = pDisk->Backend->pfnSetOpenFlags(pImage->pvBackendData, uOpenFlags);
+            rc = pImage->Backend->pfnSetOpenFlags(pImage->pvBackendData, uOpenFlags);
         }
 
@@ -1585,8 +1636,8 @@
 
         /* Cache disk information. */
-        pDisk->cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
+        pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
 
         /* Cache PCHS geometry. */
-        rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
+        rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
                                                  &pDisk->PCHSGeometry);
         if (VBOX_FAILURE(rc2))
@@ -1605,6 +1656,6 @@
 
         /* Cache LCHS geometry. */
-        rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
-                                                 &pDisk->LCHSGeometry);
+        rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
+                                                  &pDisk->LCHSGeometry);
         if (VBOX_FAILURE(rc2))
         {
@@ -1650,8 +1701,13 @@
             vdRemoveImageFromList(pDisk, pImage);
             /* Close image. */
-            int rc2 = pDisk->Backend->pfnClose(pImage->pvBackendData, false);
+            int rc2 = pImage->Backend->pfnClose(pImage->pvBackendData, false);
             if (VBOX_FAILURE(rc2) && VBOX_SUCCESS(rc))
                 rc = rc2;
             /* Free remaining resources related to the image. */
+            if (pImage->hPlugin != NIL_RTLDRMOD)
+            {
+                RTLdrClose(pImage->hPlugin);
+                pImage->hPlugin = NIL_RTLDRMOD;
+            }
             RTStrFree(pImage->pszFilename);
             RTMemFree(pImage);
@@ -1778,5 +1834,5 @@
 
         vdResetModifiedFlag(pDisk);
-        rc = pDisk->Backend->pfnFlush(pImage->pvBackendData);
+        rc = pImage->Backend->pfnFlush(pImage->pvBackendData);
     } while (0);
 
@@ -1831,5 +1887,5 @@
 
         unsigned uOpenFlags;
-        uOpenFlags = pDisk->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
+        uOpenFlags = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData);
         fReadOnly = !!(uOpenFlags & VD_OPEN_FLAGS_READONLY);
     } while (0);
@@ -1860,5 +1916,5 @@
         PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
         AssertBreak(VALID_PTR(pImage), cbSize = 0);
-        cbSize = pDisk->Backend->pfnGetSize(pImage->pvBackendData);
+        cbSize = pImage->Backend->pfnGetSize(pImage->pvBackendData);
     } while (0);
 
@@ -1888,5 +1944,5 @@
         PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
         AssertBreak(VALID_PTR(pImage), cbSize = 0);
-        cbSize = pDisk->Backend->pfnGetFileSize(pImage->pvBackendData);
+        cbSize = pImage->Backend->pfnGetFileSize(pImage->pvBackendData);
     } while (0);
 
@@ -1935,6 +1991,6 @@
         }
         else
-            rc = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
-                                                    pPCHSGeometry);
+            rc = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
+                                                     pPCHSGeometry);
     } while (0);
 
@@ -1998,10 +2054,10 @@
                  * of updating an image which could be opened in read-only mode
                  * right now. */
-                rc = pDisk->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
-                                                        pPCHSGeometry);
+                rc = pImage->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
+                                                         pPCHSGeometry);
 
                 /* Cache new geometry values in any case. */
-                int rc2 = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
-                                                             &pDisk->PCHSGeometry);
+                int rc2 = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
+                                                              &pDisk->PCHSGeometry);
                 if (VBOX_FAILURE(rc2))
                 {
@@ -2022,6 +2078,6 @@
         {
             PDMMEDIAGEOMETRY PCHS;
-            rc = pDisk->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
-                                                    &PCHS);
+            rc = pImage->Backend->pfnGetPCHSGeometry(pImage->pvBackendData,
+                                                     &PCHS);
             if (    VBOX_FAILURE(rc)
                 ||  pPCHSGeometry->cCylinders != PCHS.cCylinders
@@ -2034,6 +2090,6 @@
                  * of updating an image which could be opened in read-only mode
                  * right now. */
-                rc = pDisk->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
-                                                        pPCHSGeometry);
+                rc = pImage->Backend->pfnSetPCHSGeometry(pImage->pvBackendData,
+                                                         pPCHSGeometry);
             }
         }
@@ -2084,6 +2140,6 @@
         }
         else
-            rc = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
-                                                    pLCHSGeometry);
+            rc = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
+                                                     pLCHSGeometry);
     } while (0);
 
@@ -2144,10 +2200,10 @@
                  * of updating an image which could be opened in read-only mode
                  * right now. */
-                rc = pDisk->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
-                                                        pLCHSGeometry);
+                rc = pImage->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
+                                                         pLCHSGeometry);
 
                 /* Cache new geometry values in any case. */
-                int rc2 = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
-                                                             &pDisk->LCHSGeometry);
+                int rc2 = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
+                                                              &pDisk->LCHSGeometry);
                 if (VBOX_FAILURE(rc2))
                 {
@@ -2168,6 +2224,6 @@
         {
             PDMMEDIAGEOMETRY LCHS;
-            rc = pDisk->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
-                                                    &LCHS);
+            rc = pImage->Backend->pfnGetLCHSGeometry(pImage->pvBackendData,
+                                                     &LCHS);
             if (    VBOX_FAILURE(rc)
                 ||  pLCHSGeometry->cCylinders != LCHS.cCylinders
@@ -2180,6 +2236,6 @@
                  * of updating an image which could be opened in read-only mode
                  * right now. */
-                rc = pDisk->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
-                                                        pLCHSGeometry);
+                rc = pImage->Backend->pfnSetLCHSGeometry(pImage->pvBackendData,
+                                                         pLCHSGeometry);
             }
         }
@@ -2220,5 +2276,5 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        *puVersion = pDisk->Backend->pfnGetVersion(pImage->pvBackendData);
+        *puVersion = pImage->Backend->pfnGetVersion(pImage->pvBackendData);
     } while (0);
 
@@ -2257,6 +2313,6 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        rc = pDisk->Backend->pfnGetImageType(pImage->pvBackendData,
-                                             penmType);
+        rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData,
+                                              penmType);
     } while (0);
 
@@ -2295,5 +2351,5 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        *puImageFlags = pDisk->Backend->pfnGetImageFlags(pImage->pvBackendData);
+        *puImageFlags = pImage->Backend->pfnGetImageFlags(pImage->pvBackendData);
     } while (0);
 
@@ -2332,5 +2388,5 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        *puOpenFlags = pDisk->Backend->pfnGetOpenFlags(pImage->pvBackendData);
+        *puOpenFlags = pImage->Backend->pfnGetOpenFlags(pImage->pvBackendData);
     } while (0);
 
@@ -2370,6 +2426,6 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        rc = pDisk->Backend->pfnSetOpenFlags(pImage->pvBackendData,
-                                             uOpenFlags);
+        rc = pImage->Backend->pfnSetOpenFlags(pImage->pvBackendData,
+                                              uOpenFlags);
     } while (0);
 
@@ -2468,6 +2524,6 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        rc = pDisk->Backend->pfnGetComment(pImage->pvBackendData, pszComment,
-                                           cbComment);
+        rc = pImage->Backend->pfnGetComment(pImage->pvBackendData, pszComment,
+                                            cbComment);
     } while (0);
 
@@ -2506,5 +2562,5 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        rc = pDisk->Backend->pfnSetComment(pImage->pvBackendData, pszComment);
+        rc = pImage->Backend->pfnSetComment(pImage->pvBackendData, pszComment);
     } while (0);
 
@@ -2542,5 +2598,5 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        rc = pDisk->Backend->pfnGetUuid(pImage->pvBackendData, pUuid);
+        rc = pImage->Backend->pfnGetUuid(pImage->pvBackendData, pUuid);
     } while (0);
 
@@ -2583,5 +2639,5 @@
             pUuid = &Uuid;
         }
-        rc = pDisk->Backend->pfnSetUuid(pImage->pvBackendData, pUuid);
+        rc = pImage->Backend->pfnSetUuid(pImage->pvBackendData, pUuid);
     } while (0);
 
@@ -2618,6 +2674,6 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        rc = pDisk->Backend->pfnGetModificationUuid(pImage->pvBackendData,
-                                                    pUuid);
+        rc = pImage->Backend->pfnGetModificationUuid(pImage->pvBackendData,
+                                                     pUuid);
     } while (0);
 
@@ -2661,6 +2717,6 @@
             pUuid = &Uuid;
         }
-        rc = pDisk->Backend->pfnSetModificationUuid(pImage->pvBackendData,
-                                                    pUuid);
+        rc = pImage->Backend->pfnSetModificationUuid(pImage->pvBackendData,
+                                                     pUuid);
     } while (0);
 
@@ -2698,5 +2754,5 @@
         AssertBreak(VALID_PTR(pImage), rc = VERR_VDI_IMAGE_NOT_FOUND);
 
-        rc = pDisk->Backend->pfnGetParentUuid(pImage->pvBackendData, pUuid);
+        rc = pImage->Backend->pfnGetParentUuid(pImage->pvBackendData, pUuid);
     } while (0);
 
@@ -2740,5 +2796,5 @@
             pUuid = &Uuid;
         }
-        rc = pDisk->Backend->pfnSetParentUuid(pImage->pvBackendData, pUuid);
+        rc = pImage->Backend->pfnSetParentUuid(pImage->pvBackendData, pUuid);
     } while (0);
 
@@ -2761,12 +2817,12 @@
         AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
 
-        RTLogPrintf("--- Dumping VD Disk, Backend=%s, Images=%u\n",
-                    pDisk->Backend->pszBackendName, pDisk->cImages);
+        RTLogPrintf("--- Dumping VD Disk, Images=%u\n", pDisk->cImages);
         for (PVDIMAGE pImage = pDisk->pBase; pImage; pImage = pImage->pNext)
         {
-            RTLogPrintf("Dumping VD image \"%s\"\n", pImage->pszFilename);
-            pDisk->Backend->pfnDump(pImage->pvBackendData);
-        }
-    } while (0);
-}
-
+            RTLogPrintf("Dumping VD image \"%s\" (Backend=%s)\n",
+	                pImage->Backend->pszBackendName, pImage->pszFilename);
+            pImage->Backend->pfnDump(pImage->pvBackendData);
+        }
+    } while (0);
+}
+
Index: trunk/src/VBox/Main/ConsoleImpl2.cpp
===================================================================
--- trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 7276)
+++ trunk/src/VBox/Main/ConsoleImpl2.cpp	(revision 7277)
@@ -760,4 +760,5 @@
             rc = CFGMR3InsertString(pCfg,   "Path",             psz);                   RC_CHECK();
             STR_FREE();
+            rc = CFGMR3InsertString(pCfg,   "Format",           "VMDK");                RC_CHECK();
         }
         else if (hddType == HardDiskStorageType_CustomHardDisk)
Index: trunk/src/VBox/Main/HardDiskImpl.cpp
===================================================================
--- trunk/src/VBox/Main/HardDiskImpl.cpp	(revision 7276)
+++ trunk/src/VBox/Main/HardDiskImpl.cpp	(revision 7277)
@@ -3381,5 +3381,5 @@
 
     /* initialize the container */
-    int vrc = VDCreate ("VMDK", VDError, this, &mContainer);
+    int vrc = VDCreate (VDError, this, &mContainer);
     ComAssertRCRet (vrc, E_FAIL);
 
@@ -4049,5 +4049,5 @@
         /// obviously. This of course changes locking behavior, but for now
         /// this is acceptable. A better solution needs to be found later.
-        vrc = VDOpen (mContainer, filePath, VD_OPEN_FLAGS_NORMAL);
+        vrc = VDOpen (mContainer, "VMDK", filePath, VD_OPEN_FLAGS_NORMAL);
         if (VBOX_FAILURE (vrc))
             break;
@@ -4316,5 +4316,5 @@
 
         /* initialize the container */
-        vrc = VDCreate (Utf8Str (mFormat), VDError, this, &mContainer);
+        vrc = VDCreate (VDError, this, &mContainer);
         if (VBOX_FAILURE (vrc))
         {
@@ -4417,12 +4417,9 @@
                 break;
             }
+            mFormat = Bstr (pszFormat);
+            RTStrFree (pszFormat);
 
             /* Create the corresponding container. */
-            vrc = VDCreate (pszFormat, VDError, this, &mContainer);
-
-            if (VBOX_SUCCESS(vrc))
-                mFormat = Bstr (pszFormat);
-
-            RTStrFree (pszFormat);
+            vrc = VDCreate (VDError, this, &mContainer);
 
             /* the format has been already checked for presence at this point */
@@ -4885,5 +4882,5 @@
         Guid id, parentId;
 
-        vrc = VDOpen (mContainer, location, VD_OPEN_FLAGS_INFO);
+        vrc = VDOpen (mContainer, Utf8Str (mFormat), location, VD_OPEN_FLAGS_INFO);
         if (VBOX_FAILURE (vrc))
             break;
@@ -5083,5 +5080,5 @@
 
     /* initialize the container */
-    int vrc = VDCreate ("VHD", VDError, this, &mContainer);
+    int vrc = VDCreate (VDError, this, &mContainer);
     ComAssertRCRet (vrc, E_FAIL);
 
@@ -5749,5 +5746,5 @@
         /// obviously. This of course changes locking behavior, but for now
         /// this is acceptable. A better solution needs to be found later.
-        vrc = VDOpen (mContainer, filePath, VD_OPEN_FLAGS_NORMAL);
+        vrc = VDOpen (mContainer, "VHD", filePath, VD_OPEN_FLAGS_NORMAL);
         if (VBOX_FAILURE (vrc))
             break;
