DrvVD.cpp revision 548ca31b6b47c36bacce49bed3339cb8075b9681
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VBox storage devices:
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Media implementation for VBox disk container
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * available from http://www.virtualbox.org. This file is free software;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * you can redistribute it and/or modify it under the terms of the GNU
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * General Public License (GPL) as published by the Free Software
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * additional information or have any questions.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Header files *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Defined types, constants and macros *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to VDIDISK::IMedia to a PVBOXDISK. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMedia)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PPDMDRVINS. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( (PPDMDRVINS)((uintptr_t)pInterface - RT_OFFSETOF(PDMDRVINS, IBase)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to PDMDRVINS::IBase to a PVBOXDISK. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( PDMINS_2_DATA(PDMIBASE_2_DRVINS(pInterface), PVBOXDISK) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to VBOXDISK::IMediaAsync to a PVBOXDISK. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, IMediaAsync)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Converts a pointer to VBOXDISK::ITransportAsyncPort to a PVBOXDISK. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync#define PDMITRANSPORTASYNCPORT_2_VBOXDISK(pInterface) \
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync ( (PVBOXDISK)((uintptr_t)pInterface - RT_OFFSETOF(VBOXDISK, ITransportAsyncPort)) )
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync * Structure for an async I/O task.
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Callback which is called on completion. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Opqaue user data which is passed on completion. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Opaque user data the caller passed on transfer initiation. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VBox disk container media main structure, private part.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsynctypedef struct VBOXDISK
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** The VBox disk container. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** The media interface. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Pointer to the driver instance. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Flag whether suspend has changed image open mode to read only. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Common structure for the supported error interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Callback table for error interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Common structure for the supported async I/O interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Callback table for async I/O interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Common structure for the configuration information interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Callback table for the configuration information interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Flag whether opened disk suppports async I/O operations. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** The async media interface. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** The async media port interface above. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Pointer to the asynchronous media driver below. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Async transport port interface. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Our cache to reduce allocation overhead. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Error reporting callback *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic void drvvdErrorCallback(void *pvUser, int rc, RT_SRC_POS_DECL,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pDrvIns->pDrvHlp->pfnVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* VD Async I/O interface implementation *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOOpen(void *pvUser, const char *pszLocation, bool fReadonly, void **ppStorage)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnOpen(pDrvVD->pDrvTransportAsync, pszLocation, fReadonly, ppStorage);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOClose(void *pvUser, void *pStorage)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return pDrvVD->pDrvTransportAsync->pfnClose(pDrvVD->pDrvTransportAsync, pStorage);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIORead(void *pvUser, void *pStorage, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return pDrvVD->pDrvTransportAsync->pfnReadSynchronous(pDrvVD->pDrvTransportAsync,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOWrite(void *pvUser, void *pStorage, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbWrite, const void *pvBuf, size_t *pcbWritten)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync return pDrvVD->pDrvTransportAsync->pfnWriteSynchronous(pDrvVD->pDrvTransportAsync,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOFlush(void *pvUser, void *pStorage)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return pDrvVD->pDrvTransportAsync->pfnFlushSynchronous(pDrvVD->pDrvTransportAsync, pStorage);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOPrepareRead(void *pvUser, void *pStorage, uint64_t uOffset, void *pvBuf, size_t cbRead, void **ppTask)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnPrepareRead(pDrvVD->pDrvTransportAsync, pStorage, uOffset, pvBuf, cbRead, ppTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOPrepareWrite(void *pvUser, void *pStorage, uint64_t uOffset, void *pvBuf, size_t cbWrite, void **ppTask)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnPrepareWrite(pDrvVD->pDrvTransportAsync, pStorage, uOffset, pvBuf, cbWrite, ppTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdAsyncIOTasksSubmit(void *pvUser, void *apTasks[], unsigned cTasks, void *pvUser2,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync void *pvUserCaller, PFNVDCOMPLETED pfnTasksCompleted)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsg(pDrvVD->pDrvTransportAsync, ("Asynchronous function called but no async transport interface below\n"));
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync rc = RTCacheRequest(pDrvVD->pCache, (void **)&pDrvVDAsyncTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pDrvVD->pDrvTransportAsync->pfnTasksSubmit(pDrvVD->pDrvTransportAsync, apTasks, cTasks, pDrvVDAsyncTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* VD Configuration interface implementation *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic bool drvvdCfgAreValuesValid(PVDCFGNODE pNode, const char *pszzValid)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3AreValuesValid((PCFGMNODE)pNode, pszzValid);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic int drvvdCfgQueryType(PVDCFGNODE pNode, const char *pszName, PVDCFGVALUETYPE penmType)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync Assert(VDCFGVALUETYPE_INTEGER == CFGMVALUETYPE_INTEGER);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Assert(VDCFGVALUETYPE_STRING == CFGMVALUETYPE_STRING);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync Assert(VDCFGVALUETYPE_BYTES == CFGMVALUETYPE_BYTES);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryType((PCFGMNODE)pNode, pszName, (PCFGMVALUETYPE)penmType);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQuerySize(PVDCFGNODE pNode, const char *pszName, size_t *pcb)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QuerySize((PCFGMNODE)pNode, pszName, pcb);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQueryInteger(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQueryIntegerDef(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsyncstatic int drvvdCfgQueryString(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return CFGMR3QueryString((PCFGMNODE)pNode, pszName, pszString, cchString);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic int drvvdCfgQueryStringDef(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return CFGMR3QueryStringDef((PCFGMNODE)pNode, pszName, pszString, cchString, pszDef);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic int drvvdCfgQueryBytes(PVDCFGNODE pNode, const char *pszName, void *pvData, size_t cbData)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return CFGMR3QueryBytes((PCFGMNODE)pNode, pszName, pvData, cbData);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* Media interface methods *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnRead */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdRead(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: off=%#llx pvBuf=%p cbRead=%d\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Log2(("%s: off=%#llx pvBuf=%p cbRead=%d %.*Vhxd\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnWrite */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdWrite(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: off=%#llx pvBuf=%p cbWrite=%d\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d %.*Vhxd\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnFlush */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdFlush(PPDMIMEDIA pInterface)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnGetSize */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(uint64_t) drvvdGetSize(PPDMIMEDIA pInterface)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t cb = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %#llx (%llu)\n", __FUNCTION__, cb, cb));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnIsReadOnly */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(bool) drvvdIsReadOnly(PPDMIMEDIA pInterface)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetPCHSGeometry */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync int rc = VDGetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pPCHSGeometry);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync Log(("%s: geometry not available.\n", __FUNCTION__));
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync LogFlow(("%s: returns %Vrc (CHS=%d/%d/%d)\n", __FUNCTION__,
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnBiosSetPCHSGeometry */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDSetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pPCHSGeometry);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnBiosGetLCHSGeometry */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDGetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pLCHSGeometry);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Log(("%s: geometry not available.\n", __FUNCTION__));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc (CHS=%d/%d/%d)\n", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnBiosSetLCHSGeometry */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDSetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, pLCHSGeometry);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnGetUuid */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Vrc ({%Vuuid})\n", __FUNCTION__, rc, pUuid));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* Async Media interface methods *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdStartRead(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: uOffset=%#llx paSeg=%#p cSeg=%u cbRead=%d\n pvUser=%#p", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, paSeg, cSeg, pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdStartWrite(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: uOffset=%#llx paSeg=%#p cSeg=%u cbWrite=%d\n pvUser=%#p", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, paSeg, cSeg, pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* Async transport port interface methods *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvvdTasksCompleteNotify(PPDMITRANSPORTASYNCPORT pInterface, void *pvUser)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PVBOXDISK pThis = PDMITRANSPORTASYNCPORT_2_VBOXDISK(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVVDASYNCTASK pDrvVDAsyncTask = (PDRVVDASYNCTASK)pvUser;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Having a completion callback for a task is not mandatory. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync rc = pDrvVDAsyncTask->pfnCompleted(pDrvVDAsyncTask->pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Check if the request is finished. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort, pDrvVDAsyncTask->pvUserCaller);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = RTCacheInsert(pThis->pCache, pDrvVDAsyncTask);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Base interface methods *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIBASE::pfnQueryInterface */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(void *) drvvdQueryInterface(PPDMIBASE pInterface,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_DRVINS(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->fAsyncIOSupported ? &pThis->IMediaAsync : NULL;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Driver methods *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Construct a VBox disk media driver instance.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @returns VBox status.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @param pDrvIns The driver instance data.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * If the registration structure is needed, pDrvIns->pDrvReg points to it.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * of the driver instance. It's also found in pDrvIns->pCfgHandle as it's expected
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * to be used frequently in this function.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvvdConstruct(PPDMDRVINS pDrvIns,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync char *pszName = NULL; /**< The path of the disk image file. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync char *pszFormat = NULL; /**< The format backed to use for this image. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fReadOnly; /**< True if the media is readonly. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fHonorZeroWrites; /**< True if zero blocks should be written. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Init the static parts.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pDrvIns->IBase.pfnQueryInterface = drvvdQueryInterface;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* IMedia */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnBiosGetPCHSGeometry = drvvdBiosGetPCHSGeometry;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->IMedia.pfnBiosSetPCHSGeometry = drvvdBiosSetPCHSGeometry;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->IMedia.pfnBiosGetLCHSGeometry = drvvdBiosGetLCHSGeometry;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMedia.pfnBiosSetLCHSGeometry = drvvdBiosSetLCHSGeometry;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* IMediaAsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMediaAsync.pfnStartWrite = drvvdStartWrite;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* ITransportAsyncPort */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->ITransportAsyncPort.pfnTaskCompleteNotify = drvvdTasksCompleteNotify;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Initialize supported VD interfaces. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIErrorCallbacks.pfnError = drvvdErrorCallback;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VDInterfaceCreate(&pThis->VDIError, "DrvVD_VDIError", VDINTERFACETYPE_ERROR,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.cbSize = sizeof(VDINTERFACEASYNCIO);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.enmInterface = VDINTERFACETYPE_ASYNCIO;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnOpen = drvvdAsyncIOOpen;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnClose = drvvdAsyncIOClose;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnRead = drvvdAsyncIORead;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnWrite = drvvdAsyncIOWrite;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->VDIAsyncIOCallbacks.pfnFlush = drvvdAsyncIOFlush;
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis->VDIAsyncIOCallbacks.pfnPrepareRead = drvvdAsyncIOPrepareRead;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnPrepareWrite = drvvdAsyncIOPrepareWrite;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIAsyncIOCallbacks.pfnTasksSubmit = drvvdAsyncIOTasksSubmit;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VDInterfaceCreate(&pThis->VDIAsyncIO, "DrvVD_AsyncIO", VDINTERFACETYPE_ASYNCIO,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync &pThis->VDIAsyncIOCallbacks, pThis, &pThis->VDIError);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.cbSize = sizeof(VDINTERFACECONFIG);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.enmInterface = VDINTERFACETYPE_CONFIG;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnAreValuesValid = drvvdCfgAreValuesValid;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryType = drvvdCfgQueryType;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQuerySize = drvvdCfgQuerySize;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryInteger = drvvdCfgQueryInteger;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryIntegerDef = drvvdCfgQueryIntegerDef;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryString = drvvdCfgQueryString;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryStringDef = drvvdCfgQueryStringDef;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->VDIConfigCallbacks.pfnQueryBytes = drvvdCfgQueryBytes;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** @todo TEMP! this isn't really correct - this needs to be made per image,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * as CFGM needs access to the right configuration node for each image.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * At the moment this is harmless, as iSCSI can only be used as a base
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * image, and no other backend uses the private data for these callbacks. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = VDInterfaceCreate(&pThis->VDIConfig, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync &pThis->VDIConfigCallbacks, NULL /**< @todo TEMP */, &pThis->VDIAsyncIO);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Try to attach async media port interface above.*/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->pDrvMediaAsyncPort = (PPDMIMEDIAASYNCPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MEDIA_ASYNC_PORT);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Attach the async transport driver below of the device above us implements the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * async interface.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Try to attach the driver. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Though the device supports async I/O the backend seems to not support it.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Revert to non async I/O.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsgFailed(("Failed to attach async transport driver below rc=%Vrc\n", rc));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Success query the async transport interface. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->pDrvTransportAsync = (PPDMITRANSPORTASYNC)pBase->pfnQueryInterface(pBase, PDMINTERFACE_TRANSPORT_ASYNC);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Whoops. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsgFailed(("Configuration error: No async transport interface below!\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Validate configuration and find all parent images.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * It's sort of up side down from the image dependency tree.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync unsigned iLevel = 0;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Toplevel configuration additionally contains the global image
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * open flags. Some might be converted to per-image flags later. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "Format\0Path\0"
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "ReadOnly\0HonorZeroWrites\0");
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* All other image configurations only contain image name and
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * the format information. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync fValid = CFGMR3AreValuesValid(pCurNode, "Format\0Path\0");
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RT_SRC_POS, N_("DrvVD: Configuration error: keys incorrect at level %d"), iLevel);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PCFGMNODE pParent = CFGMR3GetChild(pCurNode, "Parent");
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Open the images.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** @todo TEMP! later the iSCSI config callbacks won't be included here */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Error message is already set correctly. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Read the image configuration.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryStringAlloc(pCfgHandle, "Format", &pszFormat);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryBool(pCurNode, "ReadOnly", &fReadOnly);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync N_("DrvVD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync rc = CFGMR3QueryBool(pCfgHandle, "HonorZeroWrites", &fHonorZeroWrites);
fReadOnly = true;
fHonorZeroWrites = false;
unsigned uOpenFlags;
if (fReadOnly)
if (fHonorZeroWrites)
iLevel--;
return rc;
int rc;
unsigned uOpenFlags;
unsigned uOpenFlags;
sizeof(VBOXDISK),
NULL,
NULL,
NULL,
NULL,