DrvHostRawDisk.cpp revision 2e00eb43f4c5beb9652e4411370a0f41f8fe8ac9
/** @file
*
* VBox storage devices:
* Host Hard Disk media driver
*/
/*
* 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DRV_HOST_HDD
#ifdef RT_OS_WINDOWS
#include <windows.h>
#include <winioctl.h>
#include <errno.h>
#include <unistd.h>
#endif /* !RT_OS_WINDOWS && !RT_OS_LINUX */
#include "Builtins.h"
typedef struct DRVHOSTHDD *PDRVHOSTHDD;
typedef struct DRVHOSTHDD
{
/** File name for the host hard disk. */
char *pszPath;
/** Size of the disk. */
/** Disk geometry information, cylinders. */
/** Disk geometry information, heads. */
/** Disk geometry information, sectors. */
/** Translation mode. */
/** Flag if this drive should refuse write operations. */
bool fReadOnly;
/** File handle for the host hard disk. */
/** The media interface. */
/** Pointer to the driver instance. */
} DRVHOSTHDD;
/** Converts a pointer to DRVHOSTHDD::IMedia to a PDRVHOSTHDD. */
#define PDMIMEDIA_2_DRVHOSTHDD(pInterface) ( (PDRVHOSTHDD)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTHDD, IMedia)) )
/**
* 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.
*/
static DECLCALLBACK(void *) drvHostHDDQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
{
switch (enmInterface)
{
case PDMINTERFACE_BASE:
case PDMINTERFACE_MEDIA:
default:
return NULL;
}
}
/** @copydoc PDMIMEDIA::pfnRead */
static DECLCALLBACK(int) drvHostHDDRead(PPDMIMEDIA pInterface, uint64_t off, void *pvBuf, size_t cbRead)
{
int rc = VINF_SUCCESS;
/** @todo add partition filtering */
return rc;
}
/** @copydoc PDMIMEDIA::pfnWrite */
static DECLCALLBACK(int) drvHostHDDWrite(PPDMIMEDIA pInterface, uint64_t off, const void *pvBuf, size_t cbWrite)
{
int rc = VINF_SUCCESS;
/** @todo add partition filtering */
return rc;
}
/** @copydoc PDMIMEDIA::pfnFlush */
{
int rc = VINF_SUCCESS;
return rc;
}
/** @copydoc PDMIMEDIA::pfnGetSize */
{
return cbSize;
}
/** @copydoc PDMIMEDIA::pfnIsReadOnly */
{
bool fReadOnly;
return fReadOnly;
}
/** @copydoc PDMIMEDIA::pfnBiosGetGeometry */
static DECLCALLBACK(int) drvHostHDDBiosGetGeometry(PPDMIMEDIA pInterface, uint32_t *pcCylinders, uint32_t *pcHeads, uint32_t *pcSectors)
{
int rc = VINF_SUCCESS;
if (pThis->cCylinders != 0)
{
}
else
return rc;
}
/** @copydoc PDMIMEDIA::pfnBiosSetGeometry */
static DECLCALLBACK(int) drvHostHDDBiosSetGeometry(PPDMIMEDIA pInterface, uint32_t cCylinders, uint32_t cHeads, uint32_t cSectors)
{
int rc = VINF_SUCCESS;
return rc;
}
/** @copydoc PDMIMEDIA::pfnBiosGetTranslation */
static DECLCALLBACK(int) drvHostHDDBiosGetTranslation(PPDMIMEDIA pInterface, PPDMBIOSTRANSLATION penmTranslation)
{
int rc = VINF_SUCCESS;
return rc;
}
/** @copydoc PDMIMEDIA::pfnBiosSetTranslation */
static DECLCALLBACK(int) drvHostHDDBiosSetTranslation(PPDMIMEDIA pInterface, PDMBIOSTRANSLATION enmTranslation)
{
int rc = VINF_SUCCESS;
return rc;
}
/** @copydoc PDMIMEDIA::pfnGetUUID */
{
int rc = VINF_SUCCESS;
// PDRVHOSTHDD pThis = PDMIMEDIA_2_DRVHOSTHDD(pInterface);
return rc;
}
/* -=-=-=-=- driver interface -=-=-=-=- */
/**
* Construct a host hard disk (raw partition) 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.
*/
{
int rc = VINF_SUCCESS;
/*
* Validate configuration.
*/
return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, RT_SRC_POS, N_("RawHDD#%d: configuration keys other than \"Path\" and \"ReadOnly\" present"));
/*
* Init instance data.
*/
if (VBOX_FAILURE(rc))
return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("RawHDD#%d: configuration query for \"Path\" string returned %Vra"), rc);
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
{
rc = VINF_SUCCESS;
}
else if (VBOX_FAILURE(rc))
return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("RawHDD#%d: configuration query for \"ReadOnly\" boolean returned %Vra"), rc);
else
if (VBOX_SUCCESS(rc))
{
/* Get disk size (in case it's an image file). */
if (VBOX_FAILURE(rc))
}
else
{
/* Failed to open the raw disk. Specify a proper error message. */
rc = PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("RawHDD#%d: cannot open file \"%s\", error code %Vrc"), pDrvIns->iInstance, pThis->pszPath, rc);
}
if (VBOX_SUCCESS(rc))
{
pThis->cCylinders = 0;
#ifdef RT_OS_WINDOWS
{
{
{
/* Windows NT has no IOCTL_DISK_GET_LENGTH_INFORMATION
* ioctl. This was added to Windows XP, so use the
* available info from DriveGeo. */
}
}
else
}
else
#elif defined(RT_OS_LINUX)
{
struct hd_geometry DriveGeo;
{
{
long cBlocks;
else
}
}
else
}
#else
/** @todo add further host OS geometry detection mechanisms. */
AssertMsgFailed("Host disk support for this host is unimplemented.\n");
#endif
/* Do geometry cleanup common to all host operating systems.
* Very important, as Windows guests are very sensitive to odd
* PCHS settings, and for big disks they consider anything
* except the standard mapping as odd. */
if (pThis->cCylinders != 0)
{
{
/* For big disks, use dummy PCHS values and let the BIOS
* select an appropriate LCHS mapping. */
}
else
}
}
return rc;
}
/**
* 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.
*/
{
{
}
}
/**
* Block driver registration record.
*/
const PDMDRVREG g_DrvHostHDD =
{
/* u32Version */
/* szDriverName */
"HostHDD",
/* pszDescription */
"Host Hard Disk Media Driver.",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVHOSTHDD),
/* pfnConstruct */
/* pfnDestruct */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnDetach */
};