VBoxHDD.cpp revision c98fb3e16fcd571a790eab772c0c66173d225205
/** $Id$ */
/** @file
*
* VBox storage devices:
* VBox HDD container implementation
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DRV_VBOXHDD
#include "VDICore.h"
#include "Builtins.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Converts a pointer to VDIDISK::IMedia to a PVDIDISK. */
#define PDMIMEDIA_2_VDIDISK(pInterface) ( (PVDIDISK)((uintptr_t)pInterface - RT_OFFSETOF(VDIDISK, IMedia)) )
/** Converts a pointer to PDMDRVINS::IBase to a PPDMDRVINS. */
#define PDMIBASE_2_DRVINS(pInterface) ( (PPDMDRVINS)((uintptr_t)pInterface - RT_OFFSETOF(PDMDRVINS, IBase)) )
/** Converts a pointer to PDMDRVINS::IBase to a PVDIDISK. */
/** @copydoc PDMIMEDIA::pfnGetSize */
{
return cb;
}
/**
* Get stored media geometry - BIOS property.
*
* @see PDMIMEDIA::pfnBiosGetGeometry for details.
*/
static DECLCALLBACK(int) vdiBiosGetGeometry(PPDMIMEDIA pInterface, uint32_t *pcCylinders, uint32_t *pcHeads, uint32_t *pcSectors)
{
if (VBOX_SUCCESS(rc))
{
LogFlow(("vdiBiosGetGeometry: returns VINF_SUCCESS\n"));
return VINF_SUCCESS;
}
Log(("vdiBiosGetGeometry: The Bios geometry data was not available.\n"));
return VERR_PDM_GEOMETRY_NOT_SET;
}
/**
* Set stored media geometry - BIOS property.
*
* @see PDMIMEDIA::pfnBiosSetGeometry for details.
*/
static DECLCALLBACK(int) vdiBiosSetGeometry(PPDMIMEDIA pInterface, uint32_t cCylinders, uint32_t cHeads, uint32_t cSectors)
{
return rc;
}
/**
* Read bits.
*
* @see PDMIMEDIA::pfnRead for details.
*/
{
if (VBOX_SUCCESS(rc))
Log2(("vdiRead: off=%#llx pvBuf=%p cbRead=%d\n"
"%.*Vhxd\n",
return rc;
}
/**
* Write bits.
*
* @see PDMIMEDIA::pfnWrite for details.
*/
static DECLCALLBACK(int) vdiWrite(PPDMIMEDIA pInterface, uint64_t off, const void *pvBuf, size_t cbWrite)
{
Log2(("vdiWrite: off=%#llx pvBuf=%p cbWrite=%d\n"
"%.*Vhxd\n",
return rc;
}
/**
* Flush bits to media.
*
* @see PDMIMEDIA::pfnFlush for details.
*/
{
LogFlow(("vdiFlush:\n"));
int rc = VINF_SUCCESS;
return rc;
}
/** @copydoc PDMIMEDIA::pfnGetUuid */
{
return rc;
}
/** @copydoc PDMIMEDIA::pfnIsReadOnly */
{
return VDIDiskIsReadOnly(pData);
}
/** @copydoc PDMIMEDIA::pfnBiosGetTranslation */
{
return rc;
}
/** @copydoc PDMIMEDIA::pfnBiosSetTranslation */
{
return rc;
}
/**
* Queries an interface to the driver.
*
* @returns Pointer to interface.
* @returns NULL if the interface was not supported by the driver.
* @param pInterface Pointer to this interface structure.
* @param enmInterface The requested interface identification.
* @thread Any thread.
*/
{
switch (enmInterface)
{
case PDMINTERFACE_BASE:
case PDMINTERFACE_MEDIA:
default:
return NULL;
}
}
/**
* Before the VM resumes we'll have to undo the read-only mode change
* done in vdiSuspend.
*
* @param pDrvIns The driver instance data.
*/
{
LogFlow(("vdiSuspend:\n"));
#if 1 //#ifdef DEBUG_dmik
{
}
#endif
}
/**
* When the VM has been suspended we'll change the image mode to read-only
* so that main and others can read the VDIs. This is important when
* saving state and so forth.
*
* @param pDrvIns The driver instance data.
*/
{
LogFlow(("vdiSuspend:\n"));
#if 1 // #ifdef DEBUG_dmik
{
}
#endif
}
/**
* Destruct a driver instance.
*
* Most VM resources are freed by the VM. This callback is provided so that any non-VM
* resources can be freed correctly.
*
* @param pDrvIns The driver instance data.
*/
{
LogFlow(("vdiDestruct:\n"));
}
/**
* Construct a VBox HDD media driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
* If the registration structure is needed, pDrvIns->pDrvReg points to it.
* @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
* of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
* iInstance it's expected to be used a bit in this function.
*/
{
LogFlow(("vdiConstruct:\n"));
char *pszName; /**< The path of the disk image file. */
bool fReadOnly; /**< True if the media is readonly. */
bool fHonorZeroWrites = false;
/*
* Init the static parts.
*/
/* IMedia */
/*
* Validate configuration and find the great to the level of umpteen grandparent.
* The parents are found in the 'Parent' subtree, so it's sorta up side down
* from the image dependency tree.
*/
unsigned iLevel = 0;
for (;;)
{
if (!pParent)
break;
iLevel++;
}
/*
* Open the images.
*/
int rc = VINF_SUCCESS;
{
/*
* Read the image configuration.
*/
if (VBOX_FAILURE(rc))
N_("VHDD: Configuration error: Querying \"Path\" as string failed"));
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
fReadOnly = false;
else if (VBOX_FAILURE(rc))
{
N_("VHDD: Configuration error: Querying \"ReadOnly\" as boolean failed"));
}
if (!fHonorZeroWrites)
{
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
fHonorZeroWrites = false;
else if (VBOX_FAILURE(rc))
{
N_("VHDD: Configuration error: Querying \"HonorZeroWrites\" as boolean failed"));
}
}
/*
* Open the image.
*/
if (VBOX_SUCCESS(rc))
Log(("vdiConstruct: %d - Opened '%s' in %s mode\n",
else
/* next */
iLevel--;
}
/* If any of the images has the flag set, handle zero writes like normal. */
if (VBOX_SUCCESS(rc))
/* On failure, vdiDestruct will be called, so no need to clean up here. */
if (rc == VERR_ACCESS_DENIED)
/* This should never happen here since this case is covered by Console::PowerUp */
N_("Cannot open virtual disk image '%s' for %s access"),
return rc;
}
/**
* VBox HDD driver registration record.
*/
const PDMDRVREG g_DrvVBoxHDD =
{
/* u32Version */
/* szDriverName */
"VBoxHDD",
/* pszDescription */
"VBoxHDD media driver.",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(VDIDISK),
/* pfnConstruct */
/* pfnDestruct */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
/* pfnResume */
/* pfnDetach */
};