VBoxHDD-new.cpp revision 8e2a44e69edf1a69a1aae4703f7692d62a6ff402
/** $Id$ */
/** @file
* 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 (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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_VD
#include <VBox/VBoxHDD-new.h>
#include "VBoxHDD-newInternal.h"
#define VBOXHDDDISK_SIGNATURE 0x6f0e2a7d
/**
* VBox HDD Container image descriptor.
*/
typedef struct VDIMAGE
{
/** Link to parent image descriptor, if any. */
/** Link to child image descriptor, if any. */
/** Container base filename. (UTF-8) */
char *pszFilename;
/** Data managed by the backend which keeps the actual info. */
void *pvBackendData;
/** Image open flags (only those handled generically in this code and which
* the backends will never ever see). */
unsigned uOpenFlags;
/**
* uModified bit flags.
*/
#define VD_IMAGE_MODIFIED_FLAG RT_BIT(0)
/**
* VBox HDD Container main structure, private part.
*/
struct VBOXHDD
{
/** Structure signature (VBOXHDDDISK_SIGNATURE). */
/** Number of opened images. */
unsigned cImages;
/** Base image. */
/** Last opened image in the chain.
* The same as pBase if only one image is used. */
/** Flags representing the modification state. */
unsigned uModified;
/** Cached size of this disk. */
/** Cached CHS geometry for this disk, cylinders. */
unsigned cCylinders;
/** Cached CHS geometry for this disk, heads. */
unsigned cHeads;
/** Cached CHS geometry for this disk, sectors. */
unsigned cSectors;
/** Cached translation mode for this disk. */
/** Error message processing callback. */
/** Opaque data for error callback. */
void *pvErrorUser;
/** Handle for the shared object / DLL. */
/** Function pointers for the various backend methods. */
};
typedef struct
{
const char *pszBackendName;
extern VBOXHDDBACKEND g_VmdkBackend;
#ifndef VBOX_OSE
extern VBOXHDDBACKEND g_VhdBackend;
#endif
static const VBOXHDDBACKENDENTRY aBackends[] =
{
{ "VMDK", &g_VmdkBackend },
#ifndef VBOX_OSE
{ "VHD", &g_VhdBackend},
#endif
};
/**
* internal: issue early error message.
*/
RT_SRC_POS_DECL, const char *pszFormat, ...)
{
if (pfnError)
return rc;
}
/**
* internal: issue error message.
*/
const char *pszFormat, ...)
{
return rc;
}
/**
* internal: add image structure to the end of images list.
*/
{
{
}
else
{
}
}
/**
* internal: remove image structure from the images list.
*/
{
else
else
}
/**
* internal: find image by index into the images list.
*/
{
{
nImage--;
}
return pImage;
}
/**
* internal: read the specified amount of data in whatever blocks the backend
* will give us.
*/
{
int rc;
/* Loop until all read. */
do
{
/* Search for image with allocated block. Do not attempt to read more
* than the previous reads marked as valid. Otherwise this would return
* stale data when different block sizes are used for the images. */
cbThisRead = cbRead;
for (pCurrImage = pImage;
{
}
/* No image in the chain contains the data for the block. */
if (rc == VINF_VDI_BLOCK_FREE)
{
rc = VINF_SUCCESS;
}
cbRead -= cbThisRead;
uOffset += cbThisRead;
return rc;
}
/**
* internal: mark the disk as not modified.
*/
{
{
/* generate new last-modified uuid */
{
RTUuidCreate(&Uuid);
&Uuid);
}
}
}
/**
* internal: mark the disk as modified.
*/
{
{
/* First modify, so create a UUID and ensure it's written to disk. */
}
}
/**
* internal: write a complete block (only used for diff images), taking the
* remaining data from parent images. This implementation does not optimize
* anything (except that it tries to read only that portions from parent
* images that are really needed).
*/
void *pvTmp)
{
int rc = VINF_SUCCESS;
/* Read the data that goes before the write to fill the block. */
if (cbPreRead)
{
if (VBOX_FAILURE(rc))
return rc;
}
/* Copy the data to the right place in the buffer. */
/* Read the data that goes after the write to fill the block. */
if (cbPostRead)
{
/* If we have data to be written, use that instead of reading
* data from the image. */
if (cbWrite > cbThisWrite)
else
cbWriteCopy = 0;
/* Figure out how much we cannnot read from the image, because
* the last block to write might exceed the nominal size of the
* image for technical reasons. */
else
cbFill = 0;
/* The rest must be read from the image. */
/* Now assemble the remaining data. */
if (cbWriteCopy)
if (cbReadImage)
if (VBOX_FAILURE(rc))
return rc;
/* Zero out the remainder of this block. Will never be visible, as this
* is beyond the limit of the image. */
if (cbFill)
'\0', cbFill);
}
/* Write the full block to the virtual disk. */
NULL,
&cbPreRead, &cbPostRead);
Assert(cbPostRead == 0);
return rc;
}
/**
* internal: write a complete block (only used for diff images), taking the
* remaining data from parent images. This implementation optimized out writes
* that do not change the data relative to the state as of the parent images.
* All backends which support differential/growing images support this.
*/
void *pvTmp)
{
size_t cbWriteCopy = 0;
size_t cbReadImage = 0;
int rc;
if (cbPostRead)
{
/* Figure out how much we cannnot read from the image, because
* the last block to write might exceed the nominal size of the
* image for technical reasons. */
/* If we have data to be written, use that instead of reading
* data from the image. */
if (cbWrite > cbThisWrite)
/* The rest must be read from the image. */
}
/* Read the entire data of the block so that we can compare whether it will
* be modified by the write or not. */
if (VBOX_FAILURE(rc))
return rc;
/* Check if the write would modify anything in this block. */
{
/* Block is completely unchanged, so no need to write anything. */
return VINF_SUCCESS;
}
/* Copy the data to the right place in the buffer. */
/* Handle the data that goes after the write to fill the block. */
if (cbPostRead)
{
/* Now assemble the remaining data. */
if (cbWriteCopy)
/* Zero out the remainder of this block. Will never be visible, as this
* is beyond the limit of the image. */
if (cbFill)
'\0', cbFill);
}
/* Write the full block to the virtual disk. */
NULL,
&cbPreRead, &cbPostRead);
Assert(cbPostRead == 0);
return rc;
}
/**
* Allocates and initializes an empty VBox HDD container.
* No image files are opened.
*
* @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 the VBox HDD container.
*/
{
int rc = VINF_SUCCESS;
/* Passing an error callback is strictly not necessary any more. Any code
* calling the HDD container functions should provide one, as otherwise
* many detailed error messages will go unnoticed. If you find a situation
* where you get no sensible error message from this code but you think
* there should be one, shout loudly. There are no error messages for rare
* and obvious error codes such as VERR_NO_MEMORY, and for situations which
* the user cannot be made responsible for, such as program bugs causing
* parameter checks to fail etc. */
/* Find backend. */
{
{
break;
}
}
/* If no static backend is found try loading a shared module with pszBackend as filename. */
if (!pBackend)
{
char *pszPluginName;
int cbPluginName;
/* HDD Format Plugins have VBoxHDD as prefix, thatswhy we have to prepend it.
* @todo: find out what to do if filenames are case sensitive.
*/
if (cbPluginName == -1)
{
rc = VERR_NO_MEMORY;
}
else
{
if (VBOX_SUCCESS(rc))
{
if (VBOX_FAILURE(rc))
{
Log(("%s: Error resolving the entry point %s, rc = %d, pfnHDDFormat = %p\n", VBOX_HDDFORMAT_LOAD_NAME, rc, pfnHDDFormatLoad));
if (VBOX_SUCCESS(rc))
}
else
{
/* Get the function table. */
if (VBOX_FAILURE(rc))
/*
* Check if the sizes match.
* If not this plugin is too old to load.
*/
{
}
}
}
}
}
if (pBackend)
{
if (pDisk)
{
pDisk->cCylinders = 0;
}
else
rc = VERR_NO_MEMORY;
}
else
RT_SRC_POS, "VD: unknown backend name '%s'",
return rc;
}
/**
* Try to get the backend name which can use this image.
*
* @returns VBox status code.
* VINF_SUCCESS if a plugin was found.
* ppszFormat contains the string which can be used as backend name.
* VERR_NOT_SUPPORTED if no plugin was found.
* @param pszFilename Name of the image file for which the backend is queried.
* @param ppszFormat Where to store the name of the plugin.
*/
{
char *pszPluginFilter;
unsigned cbPluginDirEntry;
int rc = VERR_NOT_SUPPORTED;
int rcCheck = VINF_SUCCESS;
bool fPluginFound = false;
if (!ppszFormat)
return VERR_INVALID_PARAMETER;
if (VBOX_FAILURE(rc))
return rc;
/* To get all entries with VBoxHDD as prefix. */
if (VBOX_FAILURE(rc))
{
return VERR_NO_MEMORY;
}
/* The plugins are in the same directory as the program. */
if (VBOX_FAILURE(rc))
goto out;
if (!pPluginDir)
{
rc = VERR_NO_MEMORY;
goto out;
}
{
if (rc == VERR_BUFFER_OVERFLOW)
{
/* allocate new buffer. */
/* Retry. */
}
if (VBOX_FAILURE(rc))
break;
/* We got the new entry. */
continue;
if (VBOX_SUCCESS(rc))
{
{
Log(("%s: Error resolving the entry point %s, rc = %d, pfnHDDFormat = %p\n", VBOX_HDDFORMAT_LOAD_NAME, rc, pfnHDDFormatLoad));
if (VBOX_SUCCESS(rc))
}
else
{
{
/* Check if the plugin can handle this file. */
if (VBOX_SUCCESS(rcCheck))
{
fPluginFound = true;
/* Report the format name. */
char *pszName = pPluginDirEntry->szName + VBOX_HDDFORMAT_PLUGIN_PREFIX_LENGTH; /* Point to the rest after the prefix. */
unsigned cbFormat = 0;
{
cbFormat++;
pszName++;
}
/* Copy the name into the new string. */
if (pszFormat)
{
*ppszFormat = pszFormat;
}
else
rc = VERR_NO_MEMORY;
}
else
}
else
}
/*
* We take the first plugin which can handle this file.
*/
if (fPluginFound)
break;
}
}
out:
if (pPluginDirEntry)
if (pPluginDir)
rc = VINF_SUCCESS;
return rc;
}
/**
* Destroys the VBox HDD container.
* If container has opened image files they will be closed.
*
* @param pDisk Pointer to VBox HDD container.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
if (pDisk)
{
{
}
}
}
/**
* Opens an image file.
*
* The first opened image file in a HDD container must have a base image type,
* others (next opened images) must be a differencing or undo images.
* Linkage is checked for differencing image to be in consistence with the previously opened image.
* mode, then the last image is reopened in read-only with deny write sharing mode. This allows
* other processes to use images in read-only mode too.
*
* Use VDIsReadOnly to check open mode.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param pszFilename Name of the image file to open.
* @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
*/
unsigned uOpenFlags)
{
int rc = VINF_SUCCESS;
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
if ( !pszFilename
|| *pszFilename == '\0'
|| (uOpenFlags & ~VD_OPEN_FLAGS_MASK))
{
return VERR_INVALID_PARAMETER;
}
if (uOpenFlags & VD_OPEN_FLAGS_INFO)
/* Set up image descriptor. */
if (!pImage)
return VERR_NO_MEMORY;
if (!pImage->pszFilename)
rc = VERR_NO_MEMORY;
if (VBOX_SUCCESS(rc))
{
&pImage->pvBackendData);
}
/* If the open in read-write mode failed, retry in read-only mode. */
if (VBOX_FAILURE(rc))
{
if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY)
&& (rc == VERR_ACCESS_DENIED
|| rc == VERR_PERMISSION_DENIED
|| rc == VERR_WRITE_PROTECT
|| rc == VERR_SHARING_VIOLATION
|| rc == VERR_FILE_LOCK_FAILED))
&pImage->pvBackendData);
if (VBOX_FAILURE(rc))
}
if (VBOX_SUCCESS(rc))
{
&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
* or normal, all others must be normal images. */
if ( VBOX_SUCCESS(rc)
&& !(uOpenFlags & VD_OPEN_FLAGS_INFO)
&& enmImageType != VD_IMAGE_TYPE_NORMAL)
/** @todo optionally check UUIDs */
if (VBOX_SUCCESS(rc))
{
{
/* Cache disk information. */
/* Cache CHS geometry. */
&pDisk->cCylinders,
if (VBOX_FAILURE(rc2))
{
pDisk->cCylinders = 0;
}
else
{
/* Make sure the CHS geometry is properly clipped. */
}
/* Cache translation mode. */
&pDisk->enmTranslation);
if (VBOX_FAILURE(rc2))
}
else
{
}
}
{
/* Switch previous image to read-only mode. */
unsigned uOpenFlagsPrevImg;
if (!(uOpenFlagsPrevImg & VD_OPEN_FLAGS_READONLY))
{
}
}
if (VBOX_SUCCESS(rc))
{
/* Image successfully opened, make it the last image. */
}
else
{
/* Error detected, but image opened. Close image. */
int rc2;
}
}
if (VBOX_FAILURE(rc))
{
if (pImage)
{
if (pImage->pszFilename)
}
}
return rc;
}
/**
* Creates and opens a new base image file.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param pszFilename Name of the image file to create.
* @param enmType Image type, only base image types are acceptable.
* @param cbSize Image size in bytes.
* @param uImageFlags Flags specifying special image features.
* @param pszComment Pointer to image comment. NULL is ok.
* @param cCylinders Number of cylinders (must be <= 16383).
* @param cHeads Number of heads (must be <= 16).
* @param cSectors Number of sectors (must be <= 63);
* @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
* @param pfnProgress Progress callback. Optional. NULL if not to be used.
* @param pvUser User argument for the progress callback.
*/
unsigned uImageFlags, const char *pszComment,
unsigned cCylinders, unsigned cHeads,
unsigned cSectors, unsigned uOpenFlags,
{
int rc = VINF_SUCCESS;
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
if ( !pszFilename
|| *pszFilename == '\0'
|| !cbSize
|| (uOpenFlags & ~VD_OPEN_FLAGS_MASK)
|| cCylinders == 0
|| cCylinders > 16383
|| cHeads == 0
|| cHeads > 16
|| cSectors == 0
|| cSectors > 63)
{
return VERR_INVALID_PARAMETER;
}
/* Check state. */
{
AssertMsgFailed(("Create base image cannot be done with other images open\n"));
return VERR_VDI_INVALID_STATE;
}
/* Set up image descriptor. */
if (!pImage)
return VERR_NO_MEMORY;
if (!pImage->pszFilename)
rc = VERR_NO_MEMORY;
if (VBOX_SUCCESS(rc))
&pImage->pvBackendData);
if (VBOX_SUCCESS(rc))
{
/** @todo optionally check UUIDs */
if (VBOX_SUCCESS(rc))
{
{
/* Cache disk information. */
/* Cache CHS geometry. */
&pDisk->cCylinders,
if (VBOX_FAILURE(rc2))
{
pDisk->cCylinders = 0;
}
else
{
/* Make sure the CHS geometry is properly clipped. */
}
/* Cache translation mode. */
&pDisk->enmTranslation);
if (VBOX_FAILURE(rc2))
}
else
{
}
}
if (VBOX_SUCCESS(rc))
{
/* Image successfully opened, make it the last image. */
}
else
{
/* Error detected, but image opened. Close and delete image. */
int rc2;
}
}
if (VBOX_FAILURE(rc))
{
if (pImage)
{
if (pImage->pszFilename)
}
}
return rc;
}
/**
* Creates and opens a new differencing image file in HDD container.
* See comments for VDOpen function about differencing images.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param pszFilename Name of the differencing image file to create.
* @param uImageFlags Flags specifying special image features.
* @param pszComment Pointer to image comment. NULL is ok.
* @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
* @param pfnProgress Progress callback. Optional. NULL if not to be used.
* @param pvUser User argument for the progress callback.
*/
unsigned uImageFlags, const char *pszComment,
unsigned uOpenFlags,
{
return VERR_NOT_IMPLEMENTED;
}
/**
* As a side effect the source image is deleted from both the disk and
* the images in the VBox HDD container.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param nImageFrom Name of the image file to merge from.
* @param nImageTo Name of the image file to merge to.
* @param pfnProgress Progress callback. Optional. NULL if not to be used.
* @param pvUser User argument for the progress callback.
*/
void *pvUser)
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Copies an image from one VBox HDD container to another.
* The copy is opened in the target VBox HDD container.
* It is possible to convert between different image formats, because the
* backend for the destination VBox HDD container may be different from the
* source container.
* If both the source and destination reference the same VBox HDD container,
* The source container is unchanged if the move operation fails, otherwise
* the image at the new location is opened in the same way as the old one was.
*
* @returns VBox status code.
* @param pDiskFrom Pointer to source VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pDiskTo Pointer to destination VBox HDD container.
* @param pfnProgress Progress callback. Optional. NULL if not to be used.
* @param pvUser User argument for the progress callback.
*/
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Compacts a growing image file by removing zeroed data blocks.
* Optionally defragments data in the image so that ascending sector numbers
* are stored in ascending location in the image file.
*
* @todo maybe include this function in VDCopy.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param fDefragment If true, reorder file data so that sectors are stored in ascending order.
* @param pfnProgress Progress callback. Optional. NULL if not to be used.
* @param pvUser User argument for the progress callback.
*/
bool fDefragment,
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Resizes an image. Allows setting the disk size to both larger and smaller
* values than the current disk size.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param cbSize New image size in bytes.
* @param pfnProgress Progress callback. Optional. NULL if not to be used.
* @param pvUser User argument for the progress callback.
*/
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Closes the last opened image file in the HDD container. Leaves all changes inside it.
* If previous image file was opened in read-only mode (that is normal) and closing image
* was opened in read-write mode (the whole disk was in read-write mode) - the previous image
*
* @param pDisk Pointer to VBox HDD container.
* @param fDelete If true, delete the image from the host disk.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Remove image from list of opened images. */
/* Close (and optionally delete) image. */
/* Free remaining resources related to the image. */
* this after closing this image. Set the open flags accordingly. */
if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY))
{
}
return rc;
}
/**
* Closes all opened image files in HDD container.
*
* @param pDisk Pointer to VDI HDD container.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
while (pImage)
{
/* Remove image from list of opened images. */
/* Close image. */
/* Free remaining resources related to the image. */
}
return rc;
}
/**
* Read data from virtual HDD.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param uOffset Offset of first reading byte from start of disk.
* @param pvBuf Pointer to buffer for reading data.
* @param cbRead Number of bytes to read.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
goto out;
}
/* Check params. */
{
return VERR_INVALID_PARAMETER;
}
out:
return rc;
}
/**
* Write data to virtual HDD.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param uOffset Offset of first reading byte from start of disk.
* @param pvBuf Pointer to buffer for writing data.
* @param cbWrite Number of bytes to write.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
goto out;
}
/* Check params. */
{
goto out;
}
/* Loop until all written. */
do
{
/* Try to write the possibly partial block to the last opened image.
* This works when the block is already allocated in this image or
* if it is a full-block write, which automatically allocates a new
* block if needed. */
&cbPreRead, &cbPostRead);
if (rc == VINF_VDI_BLOCK_FREE)
{
if (!pvBuf)
{
rc = VERR_NO_MEMORY;
break;
}
{
/* Optimized write, suppress writing to a so far unallocated
* block when the data is identical than as of the parent. */
}
else
{
/* Normal write, not optimized in any way. The block will be
* written no matter what. This will usually (unless the
* backend has some further optimization enabled) cause the
* block to be allocated. */
}
if (VBOX_FAILURE(rc))
break;
}
cbWrite -= cbThisWrite;
uOffset += cbThisWrite;
out:
return rc;
}
/**
* Make sure the on disk representation of a virtual HDD is up to date.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
}
else
{
}
return rc;
}
/**
* Get number of opened images in HDD container.
*
* @returns Number of opened images for HDD container. 0 if no images have been opened.
* @param pDisk Pointer to VBox HDD container.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
return c;
}
/**
*
* @returns Virtual disk ReadOnly status.
* @returns true if no image is opened in HDD container.
* @param pDisk Pointer to VBox HDD container.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
bool f;
{
unsigned uOpenFlags;
f = !!(uOpenFlags & VD_OPEN_FLAGS_READONLY);
}
else
{
AssertMsgFailed(("No disk image is opened!\n"));
f = true;
}
return f;
}
/**
* Get total disk size of the VBox HDD container.
*
* @returns Virtual disk size in bytes.
* @returns 0 if no image is opened in HDD container.
* @param pDisk Pointer to VBox HDD container.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
return cb;
}
/**
* Get virtual disk geometry stored in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
* @param pDisk Pointer to VBox HDD container.
* @param pcCylinders Where to store the number of cylinders. NULL is ok.
* @param pcHeads Where to store the number of heads. NULL is ok.
* @param pcSectors Where to store the number of sectors. NULL is ok.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
}
else
{
if (pDisk->cCylinders != 0)
{
if (pcCylinders)
if (pcHeads)
if (pcSectors)
}
else
}
return rc;
}
/**
* Store virtual disk geometry in HDD container.
*
* Note that in case of unrecoverable error all images in HDD container will be closed.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to VBox HDD container.
* @param cCylinders Number of cylinders.
* @param cHeads Number of heads.
* @param cSectors Number of sectors.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
}
else
{
{
/* Only update geometry if it is changed. Avoids similar checks
* in every backend. Most of the time the new geometry is set to
* the previous values, so no need to go through the hassle of
* updating an image which could be opened in read-only mode right
* now. */
/* Cache new geometry values in any case, whether successful or not. */
&pDisk->cCylinders,
if (VBOX_FAILURE(rc2))
{
pDisk->cCylinders = 0;
}
else
{
/* Make sure the CHS geometry is properly clipped. */
}
}
}
return rc;
}
/**
* Get virtual disk translation mode stored in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
* @param pDisk Pointer to VBox HDD container.
* @param penmTranslation Where to store the translation mode (see pdm.h).
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
}
else
{
if (pDisk->enmTranslation != 0)
else
}
pDisk->enmTranslation));
return rc;
}
/**
* Store virtual disk translation mode in HDD container.
*
* Note that in case of unrecoverable error all images in HDD container will be closed.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to VBox HDD container.
* @param enmTranslation Translation mode (see pdm.h).
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
}
else
{
if (enmTranslation == 0)
{
/* Only update translation mode if it is changed. Avoids similar
* checks in every backend. Most of the time the new translation
* mode is set to the previous value, so no need to go through the
* hassle of updating an image which could be opened in read-only
* mode right now. */
/* Cache new translation mode in any case, whether successful or not. */
&pDisk->enmTranslation);
if (VBOX_FAILURE(rc2))
}
}
return rc;
}
/**
* Get version of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param puVersion Where to store the image version.
*/
unsigned *puVersion)
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Get type of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param penmType Where to store the image type.
*/
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Get flags of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param puImageFlags Where to store the image flags.
*/
unsigned *puImageFlags)
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Get open flags of last opened image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to VBox HDD container.
* @param puOpenFlags Where to store the image open flags.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
unsigned uOpenFlags = 0;
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
}
else
{
}
return uOpenFlags;
}
/**
* Set open flags of last opened image in HDD container.
* Note that in case of unrecoverable error all images in HDD container will be closed.
*
* @returns Virtual disk block size in bytes.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pImage))
{
}
else
return rc;
}
/**
* Get base filename of image in HDD container. Some image formats use
* other filenames as well, so don't use this for anything but for informational
* purposes.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @returns VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pszFilename Where to store the image file name.
* @param cbFilename Size of buffer pszFilename points to.
*/
char *pszFilename, unsigned cbFilename)
{
return VERR_NOT_IMPLEMENTED;
}
/**
* Get the comment line of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @returns VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pszComment Where to store the comment string of image. NULL is ok.
* @param cbComment The size of pszComment buffer. 0 is ok.
*/
char *pszComment, unsigned cbComment)
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Changes the comment line of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
*/
const char *pszComment)
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Get UUID of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid Where to store the image creation UUID.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Set the image's UUID. Should not be used by normal applications.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid Optional parameter, new UUID of the image.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Get last modification UUID of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid Where to store the image modification UUID.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Set the image's last modification UUID. Should not be used by normal applications.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid Optional parameter, new last modification UUID of the image.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Get parent UUID of image in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid Where to store the parent image UUID.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Set the image's parent UUID. Should not be used by normal applications.
*
* @returns VBox status code.
* @param pDisk Pointer to VBox HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid Optional parameter, new parent UUID of the image.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
int rc;
if (pImage)
else
return rc;
}
/**
* Debug helper - dumps all opened images in HDD container into the log file.
*
* @param pDisk Pointer to VDI HDD container.
*/
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
{
/** @todo call backend to print its part. */
}
}