ParallelsHDDCore.cpp revision 5d0d754550d06b7d59a935e59caaf814462d53cc
/* $Id$ */
/** @file
*
* Parallels hdd disk image, core code.
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* 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 (GPL) 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "VBoxHDD-Internal.h"
#define PARALLELS_HEADER_MAGIC "WithoutFreeSpace"
#define PARALLELS_DISK_VERSION 2
/** The header of the parallels disk. */
#pragma pack(1)
typedef struct ParallelsHeader
{
/** The magic header to identify a parallels hdd image. */
char HeaderIdentifier[16];
/** The version of the disk image. */
/** The number of heads the hdd has. */
/** Number of cylinders. */
/** Number of sectors per track. */
/** Number of entries in the allocation bitmap. */
/** Total number of sectors. */
/** Padding. */
char Padding[24];
#pragma pack()
/**
* Parallels image structure.
*/
typedef struct PARALLELSIMAGE
{
/** Pointer to the per-disk VD interface list. */
/** Error interface. */
/** Error interface callbacks. */
#ifdef VBOX_WITH_NEW_IO_CODE
/** Async I/O interface. */
/** Async I/O interface callbacks. */
#endif
/** Image file name. */
const char *pszFilename;
#ifndef VBOX_WITH_NEW_IO_CODE
/** File descriptor. */
#else
/** Opaque storage handle. */
void *pvStorage;
#endif
/** Open flags passed by VBoxHD layer. */
unsigned uOpenFlags;
/** Image flags defined during creation or determined during open. */
unsigned uImageFlags;
/** Total size of the image. */
/** Physical geometry of this image. */
/** Logical geometry of this image. */
/** Pointer to the allocation bitmap. */
/** Entries in the allocation bitmap. */
/** Flag whether the allocation bitmap was changed. */
bool fAllocationBitmapChanged;
/** Current file size. */
/*******************************************************************************
* Static Variables *
*******************************************************************************/
/** NULL-terminated array of supported file extensions. */
static const char *const s_apszParallelsFileExtensions[] =
{
"hdd",
};
/***************************************************
* Internal functions *
**************************************************/
/**
* Internal: signal an error to the frontend.
*/
const char *pszFormat, ...)
{
return rc;
}
{
int rc = VINF_SUCCESS;
#ifndef VBOX_WITH_NEW_IO_CODE
if (fCreate)
else
#else
if (fCreate)
#endif
return rc;
}
{
int rc = VINF_SUCCESS;
#ifndef VBOX_WITH_NEW_IO_CODE
#else
#endif
return rc;
}
{
int rc = VINF_SUCCESS;
#ifndef VBOX_WITH_NEW_IO_CODE
#else
#endif
return rc;
}
{
int rc = VINF_SUCCESS;
#ifndef VBOX_WITH_NEW_IO_CODE
#else
pcbSize);
#endif
return rc;
}
{
int rc = VINF_SUCCESS;
#ifndef VBOX_WITH_NEW_IO_CODE
#else
cbSize);
#endif
return rc;
}
static int parallelsFileWriteSync(PPARALLELSIMAGE pImage, uint64_t off, const void *pcvBuf, size_t cbWrite, size_t *pcbWritten)
{
int rc = VINF_SUCCESS;
#ifndef VBOX_WITH_NEW_IO_CODE
#else
#endif
return rc;
}
static int parallelsFileReadSync(PPARALLELSIMAGE pImage, uint64_t off, void *pvBuf, size_t cbRead, size_t *pcbRead)
{
int rc = VINF_SUCCESS;
#ifndef VBOX_WITH_NEW_IO_CODE
#else
pcbRead);
#endif
return rc;
}
{
#ifndef VBOX_WITH_NEW_IO_CODE
#else
#endif
}
{
int rc = VINF_SUCCESS;
/* Try to get error interface. */
if (pImage->pInterfaceError)
#ifdef VBOX_WITH_NEW_IO_CODE
/* Try to get async I/O interface. */
#endif
if (RT_FAILURE(rc))
goto out;
if (RT_FAILURE(rc))
goto out;
if (RT_FAILURE(rc))
goto out;
{
/* Check if the file has hdd as extension. It is a fixed size raw image then. */
{
goto out;
}
/* This is a fixed size image. */
uint64_t cCylinders = pImage->cbSize / (512 * pImage->PCHSGeometry.cSectors * pImage->PCHSGeometry.cHeads);
}
else
{
{
goto out;
}
{
goto out;
}
pImage->pAllocationBitmap = (uint32_t *)RTMemAllocZ((uint32_t)pImage->cAllocationBitmapEntries * sizeof(uint32_t));
if (!pImage->pAllocationBitmap)
{
rc = VERR_NO_MEMORY;
goto out;
}
NULL);
if (RT_FAILURE(rc))
goto out;
}
out:
return rc;
}
{
int rc = VINF_SUCCESS;
&& (pImage->fAllocationBitmapChanged))
{
pImage->fAllocationBitmapChanged = false;
/* Write the allocation bitmap to the file. */
NULL);
if (RT_FAILURE(rc))
return rc;
}
/* Flush file. */
return rc;
}
{
(void)parallelsFlushImage(pImage);
if (pImage->pAllocationBitmap)
if (parallelsFileOpened(pImage))
}
/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
static int parallelsCheckIfValid(const char *pszFilename)
{
int rc;
if (RT_FAILURE(rc))
return VERR_VD_GEN_INVALID_HEADER;
if (RT_FAILURE(rc))
{
}
else
{
rc = VINF_SUCCESS;
else
{
/*
* The image may be an fixed size image.
* Unfortunately fixed sized parallels images
* are just raw files hence no magic header to
* check for.
* The code succeeds if the file is a multiple
* of 512 and if the file extensions is *.hdd
*/
char *pszExtension;
{
return VERR_VD_GEN_INVALID_HEADER;
}
else
rc = VINF_SUCCESS;
}
}
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnOpen */
void **ppBackendData)
{
LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
int rc;
/* Check open flags. All valid flags are supported. */
if (uOpenFlags & ~VD_OPEN_FLAGS_MASK)
{
goto out;
}
/* Check remaining arguments. */
if ( !VALID_PTR(pszFilename)
|| !*pszFilename
{
goto out;
}
if (uOpenFlags & VD_OPEN_FLAGS_ASYNC_IO)
{
goto out;
}
if (!pImage)
{
rc = VERR_NO_MEMORY;
goto out;
}
#ifndef VBOX_WITH_NEW_IO_CODE
#else
#endif
pImage->fAllocationBitmapChanged = false;
if (RT_SUCCESS(rc))
*ppBackendData = pImage;
out:
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnCreate */
unsigned uImageFlags, const char *pszComment,
unsigned uOpenFlags, unsigned uPercentStart,
void **ppBackendData)
{
LogFlowFunc(("pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" pPCHSGeometry=%#p pLCHSGeometry=%#p Uuid=%RTuuid uOpenFlags=%#x uPercentStart=%u uPercentSpan=%u pVDIfsDisk=%#p pVDIfsImage=%#p pVDIfsOperation=%#p ppBackendData=%#p", pszFilename, cbSize, uImageFlags, pszComment, pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, uPercentStart, uPercentSpan, pVDIfsDisk, pVDIfsImage, pVDIfsOperation, ppBackendData));
return VERR_NOT_IMPLEMENTED;
}
/** @copydoc VBOXHDDBACKEND::pfnRename */
{
return VERR_NOT_IMPLEMENTED;
}
/** @copydoc VBOXHDDBACKEND::pfnClose */
{
int rc = VINF_SUCCESS;
/* Freeing a never allocated image (e.g. because the open failed) is
* not signalled as an error. After all nothing bad happens. */
if (pImage)
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnRead */
{
LogFlowFunc(("pBackendData=%#p uOffset=%llu pvBuf=%#p cbToRead=%zu pcbActuallyRead=%#p\n", pBackendData, uOffset, pvBuf, cbToRead, pcbActuallyRead));
int rc = VINF_SUCCESS;
{
}
else
{
/** Calculate offset in the real file. */
/** One chunk in the file is always one track big. */
{
}
else
{
}
}
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnWrite */
{
LogFlowFunc(("pBackendData=%#p uOffset=%llu pvBuf=%#p cbToWrite=%zu pcbWriteProcess=%#p\n", pBackendData, uOffset, pvBuf, cbToWrite, pcbWriteProcess));
int rc = VINF_SUCCESS;
{
}
else
{
/** Calculate offset in the real file. */
/** One chunk in the file is always one track big. */
{
/* Allocate new chunk in the file. */
pImage->fAllocationBitmapChanged = true;
if (!pNewBlock)
return VERR_NO_MEMORY;
memcpy(pNewBlock + (uOffset - ((uint64_t)iIndexInAllocationTable * pImage->PCHSGeometry.cSectors * 512)),
/*
* Write the new block at the current end of the file.
*/
}
else
{
}
}
return rc;
}
static int parallelsFlush(void *pBackendData)
{
int rc = VINF_SUCCESS;
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetVersion */
static unsigned parallelsGetVersion(void *pBackendData)
{
if (pImage)
return PARALLELS_DISK_VERSION;
else
return 0;
}
/** @copydoc VBOXHDDBACKEND::pfnGetSize */
{
if (pImage)
else
return 0;
}
/** @copydoc VBOXHDDBACKEND::pfnGetFileSize */
{
if (pImage)
{
if (parallelsFileOpened(pImage))
}
return cb;
}
/** @copydoc VBOXHDDBACKEND::pfnGetPCHSGeometry */
static int parallelsGetPCHSGeometry(void *pBackendData,
{
int rc;
if (pImage)
{
{
rc = VINF_SUCCESS;
}
else
}
else
LogFlowFunc(("returns %Rrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnSetPCHSGeometry */
static int parallelsSetPCHSGeometry(void *pBackendData,
{
LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n", pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
int rc;
if (pImage)
{
{
goto out;
}
rc = VINF_SUCCESS;
}
else
out:
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetLCHSGeometry */
static int parallelsGetLCHSGeometry(void *pBackendData,
{
int rc;
if (pImage)
{
{
rc = VINF_SUCCESS;
}
else
}
else
LogFlowFunc(("returns %Rrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnSetLCHSGeometry */
static int parallelsSetLCHSGeometry(void *pBackendData,
{
LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n", pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
int rc;
if (pImage)
{
{
goto out;
}
rc = VINF_SUCCESS;
}
else
out:
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetImageFlags */
static unsigned parallelsGetImageFlags(void *pBackendData)
{
unsigned uImageFlags;
if (pImage)
else
uImageFlags = 0;
return uImageFlags;
}
/** @copydoc VBOXHDDBACKEND::pfnGetOpenFlags */
static unsigned parallelsGetOpenFlags(void *pBackendData)
{
unsigned uOpenFlags;
if (pImage)
else
uOpenFlags = 0;
return uOpenFlags;
}
/** @copydoc VBOXHDDBACKEND::pfnSetOpenFlags */
{
int rc;
/* Image must be opened and the new flags must be valid. Just readonly and
* info flags are supported. */
{
goto out;
}
/* Implement this operation via reopening the image. */
parallelsFreeImage(pImage, false);
out:
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetComment */
{
LogFlowFunc(("pBackendData=%#p pszComment=%#p cbComment=%zu\n", pBackendData, pszComment, cbComment));
int rc;
if (pImage)
{
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnSetComment */
{
int rc;
{
goto out;
}
if (pImage)
rc = VINF_SUCCESS;
else
out:
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetUuid */
{
int rc;
if (pImage)
{
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnSetUuid */
{
int rc;
if (pImage)
{
{
}
else
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetModificationUuid */
{
int rc;
if (pImage)
{
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnSetModificationUuid */
{
int rc;
if (pImage)
{
{
}
else
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetParentUuid */
{
int rc;
if (pImage)
{
rc = VINF_SUCCESS;
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnSetParentUuid */
{
int rc;
if (pImage)
{
{
}
else
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnGetParentModificationUuid */
{
int rc;
if (pImage)
{
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnSetParentModificationUuid */
{
int rc;
if (pImage)
{
{
}
else
}
else
return rc;
}
/** @copydoc VBOXHDDBACKEND::pfnDump */
static void parallelsDump(void *pBackendData)
{
if (pImage)
{
pImage->pInterfaceErrorCallbacks->pfnMessage(pImage->pInterfaceError->pvUser, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u\n",
}
}
{
int rc = VERR_NOT_IMPLEMENTED;
return rc;
}
{
int rc = VERR_NOT_IMPLEMENTED;
return rc;
}
{
int rc = VERR_NOT_IMPLEMENTED;
return rc;
}
{
int rc = VERR_NOT_IMPLEMENTED;
return rc;
}
{
int rc = VERR_NOT_IMPLEMENTED;
return rc;
}
static bool parallelsIsAsyncIOSupported(void *pvBackendData)
{
return false;
}
{
return VERR_NOT_SUPPORTED;
}
{
return VERR_NOT_SUPPORTED;
}
{
/* pszBackendName */
"Parallels",
/* cbSize */
sizeof(VBOXHDDBACKEND),
/* uBackendCaps */
/* papszFileExtensions */
/* paConfigInfo */
NULL,
/* hPlugin */
/* pfnCheckIfValid */
/* pfnOpen */
/* pfnCreate */
/* pfnRename */
/* pfnClose */
/* pfnRead */
/* pfnWrite */
/* pfnFlush */
/* pfnGetVersion */
/* pfnGetSize */
/* pfnGetFileSize */
/* pfnGetPCHSGeometry */
/* pfnSetPCHSGeometry */
/* pfnGetLCHSGeometry */
/* pfnSetLCHSGeometry */
/* pfnGetImageFlags */
/* pfnGetOpenFlags */
/* pfnSetOpenFlags */
/* pfnGetComment */
/* pfnSetComment */
/* pfnGetUuid */
/* pfnSetUuid */
/* pfnGetModificationUuid */
/* pfnSetModificationUuid */
/* pfnGetParentUuid */
/* pfnSetParentUuid */
/* pfnGetParentModificationUuid */
/* pfnSetParentModificationUuid */
/* pfnDump */
/* pfnGetTimeStamp */
/* pfnGetParentTimeStamp */
/* pfnSetParentTimeStamp */
/* pfnGetParentFilename */
/* pfnSetParentFilename */
/* pfnIsAsyncIOSupported */
/* pfnAsyncRead */
/* pfnAsyncWrite */
/* pfnComposeLocation */
/* pfnComposeName */
};