VBoxHDD-new.cpp revision ba05e817d7a96898c4c39ed92b06749274a30ee1
/** $Id$ */
/** @file
* VBox HDD Container implementation.
*/
/*
* Copyright (C) 2006-2008 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_VD
#include <VBox/VBoxHDD-new.h>
#include "VBoxHDD-newInternal.h"
#define VBOXHDDDISK_SIGNATURE 0x6f0e2a7d
/** Buffer size used for merging images. */
/**
* 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;
/** Handle for the shared object / DLL. */
/** Function pointers for the various backend methods. */
/**
* 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 PCHS geometry for this disk. */
/** Cached LCHS geometry for this disk. */
/** Error message processing callback. */
/** Opaque data for error callback. */
void *pvErrorUser;
};
extern VBOXHDDBACKEND g_RawBackend;
extern VBOXHDDBACKEND g_VmdkBackend;
extern VBOXHDDBACKEND g_VDIBackend;
#ifndef VBOX_OSE
extern VBOXHDDBACKEND g_VhdBackend;
#endif
static PCVBOXHDDBACKEND aBackends[] =
{
#ifndef VBOX_OSE
#endif
};
/**
* internal: issue error message.
*/
const char *pszFormat, ...)
{
return rc;
}
/**
* internal: find image format backend.
*/
{
int rc = VINF_SUCCESS;
{
{
break;
}
}
/* If no static backend is found try loading a shared module with
* pszBackend as filename. */
if (!pBackend)
{
char *pszPluginName;
/* HDD Format Plugins have VBoxHDD as prefix, prepend it. */
if (!pszPluginName)
{
rc = VERR_NO_MEMORY;
goto out;
}
/* Try to load the plugin (RTldrLoad takes care of the suffix). */
if (VBOX_SUCCESS(rc))
{
(void**)&pfnHDDFormatLoad);
{
LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pszPluginName, rc, pfnHDDFormatLoad));
if (VBOX_SUCCESS(rc))
goto out;
}
/* Get the function table. */
if (VBOX_FAILURE(rc))
goto out;
/* Check if the sizes match. If not this plugin is too old. */
{
goto out;
}
}
else
{
/* If the backend plugin doesn't exist, don't treat this as an
* error. Just return the NULL pointers. */
rc = VINF_SUCCESS;
}
}
out:
if (VBOX_FAILURE(rc))
{
if (hPlugin != NIL_RTLDRMOD)
}
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.
*/
{
if (nImage == VD_LAST_IMAGE)
{
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;
{
&cbThisRead);
}
/* No image in the chain contains the data for the block. */
if (rc == VERR_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. */
Assert(cbPostRead == 0);
return rc;
}
/**
* internal: write a complete block (only used for diff images), taking the
* remaining data from parent images. This implementation optimizes 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. */
Assert(cbPostRead == 0);
return rc;
}
/**
* internal: write buffer to the image, taking care of block boundaries and
* write optimizations.
*/
{
int rc;
unsigned fWrite;
/* 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 (and allocation isn't suppressed below).
* For image formats which don't support zero blocks, it's beneficial
* to avoid unnecessarily allocating unchanged blocks. This prevents
* unwanted expanding of images. VMDK is an example. */
? 0 : VD_WRITE_NO_ALLOC;
&cbPostRead, fWrite);
if (rc == VERR_VDI_BLOCK_FREE)
{
{
/* Optimized write, suppress writing to a so far unallocated
* block if the data is in fact not changed. */
}
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;
return rc;
}
/**
* Lists all HDD backends and their capabilities in a caller-provided buffer.
*
* @returns VBox status code.
* VERR_BUFFER_OVERFLOW if not enough space is passed.
* @param cEntriesAlloc Number of list entries available.
* @param pEntries Pointer to array for the entries.
* @param pcEntriesUsed Number of entries returned.
*/
unsigned *pcEntriesUsed)
{
int rc = VINF_SUCCESS;
unsigned cEntries = 0;
LogFlowFunc(("cEntriesAlloc=%u pEntries=%#p pcEntriesUsed=%#p\n", cEntriesAlloc, pEntries, pcEntriesUsed));
do
{
/* Check arguments. */
("cEntriesAlloc=%u\n", cEntriesAlloc),
("pEntries=%#p\n", pEntries),
("pcEntriesUsed=%#p\n", pcEntriesUsed),
/* First enumerate static backends. */
{
if (!pszName)
{
rc = VERR_NO_MEMORY;
break;
}
cEntries++;
if (cEntries >= cEntriesAlloc)
{
break;
}
}
if (VBOX_FAILURE(rc))
break;
/* Then enumerate plugin backends. */
char szPath[RTPATH_MAX];
if (VBOX_FAILURE(rc))
break;
/* To get all entries with VBoxHDD as prefix. */
char *pszPluginFilter;
if (VBOX_FAILURE(rc))
{
rc = VERR_NO_MEMORY;
break;
}
/* The plugins are in the same directory as the other shared libs. */
if (VBOX_FAILURE(rc))
break;
unsigned cbPluginDirEntry = sizeof(RTDIRENTRY);
if (!pPluginDirEntry)
{
rc = VERR_NO_MEMORY;
break;
}
{
if (rc == VERR_BUFFER_OVERFLOW)
{
/* allocate new buffer. */
/* Retry. */
if (VBOX_FAILURE(rc))
break;
}
else if (VBOX_FAILURE(rc))
break;
/* We got the new entry. */
continue;
if (VBOX_SUCCESS(rc))
{
{
LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pPluginDirEntry->szName, rc, pfnHDDFormatLoad));
if (VBOX_SUCCESS(rc))
}
if (VBOX_SUCCESS(rc))
{
/* Get the function table. */
{
if (!pszName)
{
rc = VERR_NO_MEMORY;
break;
}
cEntries++;
if (cEntries >= cEntriesAlloc)
{
break;
}
}
}
else
}
}
if (pPluginDirEntry)
if (pPluginDir)
} while (0);
return rc;
}
/**
* Allocates and initializes an empty HDD container.
* No image files are opened.
*
* @returns VBox status code.
* @param pfnError Callback for setting extended error information.
* @param pvErrorUser Opaque parameter for pfnError.
* @param ppDisk Where to store the reference to HDD container.
*/
{
int rc = VINF_SUCCESS;
do
{
/* Check arguments. */
("pfnError=%#p\n", pfnError),
("ppDisk=%#p\n", ppDisk),
if (pDisk)
{
}
else
{
rc = VERR_NO_MEMORY;
break;
}
} while (0);
return rc;
}
/**
* Destroys HDD container.
* If container has opened image files they will be closed.
*
* @param pDisk Pointer to HDD container.
*/
{
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
if (pDisk)
{
}
} while (0);
LogFlowFunc(("returns\n"));
}
/**
* 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 backend was found.
* @param pszFilename Name of the image file for which the backend is queried.
* @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
* The returned pointer must be freed using RTStrFree().
*/
{
int rc = VERR_NOT_SUPPORTED;
bool fPluginFound = false;
do
{
/* Check arguments. */
("ppszFormat=%#p\n", ppszFormat),
/* First check if static backends support this file format. */
{
if (aBackends[i]->pfnCheckIfValid)
{
if (VBOX_SUCCESS(rc))
{
fPluginFound = true;
/* Copy the name into the new string. */
if (!pszFormat)
{
rc = VERR_NO_MEMORY;
break;
}
*ppszFormat = pszFormat;
break;
}
}
}
if (fPluginFound)
break;
/* Then check if plugin backends support this file format. */
char szPath[RTPATH_MAX];
if (VBOX_FAILURE(rc))
break;
/* To get all entries with VBoxHDD as prefix. */
char *pszPluginFilter;
if (VBOX_FAILURE(rc))
{
rc = VERR_NO_MEMORY;
break;
}
/* The plugins are in the same directory as the other shared libs. */
if (VBOX_FAILURE(rc))
break;
unsigned cbPluginDirEntry = sizeof(RTDIRENTRY);
if (!pPluginDirEntry)
{
rc = VERR_NO_MEMORY;
break;
}
{
if (rc == VERR_BUFFER_OVERFLOW)
{
/* allocate new buffer. */
/* Retry. */
if (VBOX_FAILURE(rc))
break;
}
else if (VBOX_FAILURE(rc))
break;
/* We got the new entry. */
continue;
if (VBOX_SUCCESS(rc))
{
{
LogFunc(("error resolving the entry point %s in plugin %s, rc=%Vrc, pfnHDDFormat=%#p\n", VBOX_HDDFORMAT_LOAD_NAME, pPluginDirEntry->szName, rc, pfnHDDFormatLoad));
if (VBOX_SUCCESS(rc))
}
if (VBOX_SUCCESS(rc))
{
/* Get the function table. */
{
/* Check if the plugin can handle this file. */
if (VBOX_SUCCESS(rc))
{
fPluginFound = true;
rc = VINF_SUCCESS;
/* Report the format name. */
rc = VERR_INVALID_NAME);
if (!pszFormat)
rc = VERR_NO_MEMORY;
*ppszFormat = pszFormat;
}
}
}
else
}
/*
* We take the first plugin which can handle this file.
*/
if (fPluginFound)
break;
}
if (rc == VERR_NO_MORE_FILES)
if (pPluginDirEntry)
if (pPluginDir)
} while (0);
return rc;
}
/**
* Opens an image file.
*
* The first opened image file in 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 HDD container.
* @param pszBackend Name of the image file backend to use.
* @param pszFilename Name of the image file to open.
* @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
*/
const char *pszFilename, unsigned uOpenFlags)
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uOpenFlags=%#x\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("uOpenFlags=%#x\n", uOpenFlags),
if (uOpenFlags & VD_OPEN_FLAGS_INFO)
/* Set up image descriptor. */
if (!pImage)
{
rc = VERR_NO_MEMORY;
break;
}
if (!pImage->pszFilename)
{
rc = VERR_NO_MEMORY;
break;
}
if (VBOX_FAILURE(rc))
break;
{
break;
}
&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))
{
break;
}
}
&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)
{
break;
}
/* Force sane optimization settings. It's not worth avoiding writes
* to fixed size images. The overhead would have almost no payback. */
if (enmImageType == VD_IMAGE_TYPE_FIXED)
/** @todo optionally check UUIDs */
int rc2;
/* Cache disk information. */
/* Cache PCHS geometry. */
&pDisk->PCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the PCHS geometry is properly clipped. */
}
/* Cache LCHS geometry. */
&pDisk->LCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the LCHS geometry is properly clipped. */
}
{
/* 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. */
if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY))
}
else
{
/* Error detected, but image opened. Close image. */
int rc2;
}
} while (0);
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 HDD container.
* @param pszBackend Name of the image file backend to use.
* @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 pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
* @param pLCHSGeometry Pointer to logical disk geometry <= (1024,255,63). Not NULL.
* @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.
*/
const char *pszComment,
void *pvUser)
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" enmType=%#x cbSize=%llu uImageFlags=%#x pszComment=\"%s\" PCHS=%u/%u/%u LCHS=%u/%u/%u uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
pfnProgress, pvUser));
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("enmType=%#x\n", enmType),
("cbSize=%llu\n", cbSize),
("uImageFlags=%#x\n", uImageFlags),
/* The PCHS geometry fields may be 0 to leave it for later. */
("pPCHSGeometry=%#p PCHS=%u/%u/%u\n", pPCHSGeometry,
/* The LCHS geometry fields may be 0 to leave it to later autodetection. */
("pLCHSGeometry=%#p LCHS=%u/%u/%u\n", pLCHSGeometry,
("uOpenFlags=%#x\n", uOpenFlags),
/* Check state. */
("Create base image cannot be done with other images open\n"),
/* Set up image descriptor. */
if (!pImage)
{
rc = VERR_NO_MEMORY;
break;
}
if (!pImage->pszFilename)
{
rc = VERR_NO_MEMORY;
break;
}
if (VBOX_FAILURE(rc))
break;
{
break;
}
&pImage->pvBackendData);
if (VBOX_SUCCESS(rc))
{
/* Force sane optimization settings. It's not worth avoiding writes
* to fixed size images. The overhead would have almost no payback. */
if (enmType == VD_IMAGE_TYPE_FIXED)
/** @todo optionally check UUIDs */
int rc2;
/* Cache disk information. */
/* Cache PCHS geometry. */
&pDisk->PCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the CHS geometry is properly clipped. */
}
/* Cache LCHS geometry. */
&pDisk->LCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the CHS geometry is properly clipped. */
}
}
if (VBOX_SUCCESS(rc))
{
/* Image successfully opened, make it the last image. */
if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY))
}
else
{
/* Error detected, but image opened. Close and delete image. */
int rc2;
}
} while (0);
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 HDD container.
* @param pszBackend Name of the image file backend to use.
* @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.
*/
const char *pszFilename, unsigned uImageFlags,
const char *pszComment, unsigned uOpenFlags,
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uImageFlags=%#x pszComment=\"%s\" uOpenFlags=%#x pfnProgress=%#p pvUser=%#p\n",
pfnProgress, pvUser));
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("uImageFlags=%#x\n", uImageFlags),
("uOpenFlags=%#x\n", uOpenFlags),
/* Check state. */
("Create diff image cannot be done without other images open\n"),
/* Set up image descriptor. */
if (!pImage)
{
rc = VERR_NO_MEMORY;
break;
}
if (!pImage->pszFilename)
{
rc = VERR_NO_MEMORY;
break;
}
if (VBOX_FAILURE(rc))
break;
{
break;
}
&pImage->pvBackendData);
{
/* Switch previous image to read-only mode. */
unsigned uOpenFlagsPrevImg;
if (!(uOpenFlagsPrevImg & VD_OPEN_FLAGS_READONLY))
{
}
}
if (VBOX_SUCCESS(rc))
{
int rc2;
&Uuid);
if (VBOX_SUCCESS(rc2))
&Uuid);
if (VBOX_SUCCESS(rc2))
&Uuid);
}
if (VBOX_SUCCESS(rc))
{
/** @todo optionally check UUIDs */
}
if (VBOX_SUCCESS(rc))
{
/* Image successfully opened, make it the last image. */
if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY))
}
else
{
/* Error detected, but image opened. Close and delete image. */
int rc2;
}
} while (0);
if (VBOX_FAILURE(rc))
{
if (pImage)
{
if (pImage->pszFilename)
}
}
return rc;
}
/**
* As a side effect the source image and potentially the other images which
* are also merged to the destination are deleted from both the disk and the
* images in the HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to 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)
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImageFrom=%u nImageTo=%u pfnProgress=%#p pvUser=%#p\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
if (!pImageFrom || !pImageTo)
{
break;
}
/* Make sure destination image is writable. */
if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
{
if (VBOX_FAILURE(rc))
break;
}
/* Get size of destination image. */
/* Allocate tmp buffer. */
if (!pvBuf)
{
rc = VERR_NO_MEMORY;
break;
}
/* Merging is done directly on the images itself. This potentially
* causes trouble if the disk is full in the middle of operation. */
/** @todo write alternative implementation which works with temporary
* images (which is safer, but requires even more space). Also has the
* drawback that merging into a raw disk parent simply isn't possible
* this way (but in that case disk full isn't really a problem). */
if (nImageFrom < nImageTo)
{
/* Merge parent state into child. This means writing all not
* allocated blocks in the destination image which are allocated in
* the images to be merged. */
do
{
&cbThisRead);
if (rc == VERR_VDI_BLOCK_FREE)
{
/* 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);
}
if (rc != VERR_VDI_BLOCK_FREE)
{
if (VBOX_FAILURE(rc))
break;
if (VBOX_FAILURE(rc))
break;
}
else
rc = VINF_SUCCESS;
}
else if (VBOX_FAILURE(rc))
break;
uOffset += cbThisRead;
}
else
{
/* Merge child state into parent. This means writing all blocks
* which are allocated in the image up to the source image to the
* destination image. */
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, &cbThisRead);
}
if (rc != VERR_VDI_BLOCK_FREE)
{
if (VBOX_FAILURE(rc))
break;
if (VBOX_FAILURE(rc))
break;
}
else
rc = VINF_SUCCESS;
uOffset += cbThisRead;
}
/* Update parent UUID so that image chain is consistent. */
if (nImageFrom < nImageTo)
{
{
&Uuid);
}
else
RTUuidClear(&Uuid);
&Uuid);
}
else
{
if (pImageFrom->pNext)
{
&Uuid);
&Uuid);
}
}
/* Make sure destination image is back to read only if necessary. */
{
if (VBOX_FAILURE(rc))
break;
}
/* Delete the no longer needed images. */
{
if (nImageFrom < nImageTo)
else
}
} while (0);
if (pvBuf)
return rc;
}
/**
* Copies an image from one HDD container to another.
* The copy is opened in the target HDD container.
* It is possible to convert between different image formats, because the
* backend for the destination may be different from the source.
* If both the source and destination reference the same 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.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDiskFrom Pointer to source HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pDiskTo Pointer to destination HDD container.
* @param pszBackend Name of the image file backend to use.
* @param pszFilename New name of the image (may be NULL if pDiskFrom == pDiskTo).
* @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
* @param cbSize New image size (0 means leave unchanged).
* @param pfnProgress Progress callback. Optional. NULL if not to be used.
* @param pvUser User argument for the progress callback.
*/
const char *pszBackend, const char *pszFilename,
{
LogFlowFunc(("pDiskFrom=%#p nImage=%u pDiskTo=%#p pszBackend=\"%s\" pszFilename=\"%s\" fMoveByRename=%d cbSize=%llu pfnProgress=%#p pvUser=%#p\n",
do {
/* Check arguments. */
/* If the containers are equal and the backend is the same, rename the image. */
{
/* Rename the image. */
rc = pImageFrom->Backend->pfnRename(pImageFrom->pvBackendData, pszFilename ? pszFilename : pImageFrom->pszFilename);
break;
}
/* If the fMoveByRename flag is set and the backend is the same, rename the image. */
if ( (fMoveByRename == true)
{
/* Close the source image. */
if (VBOX_FAILURE(rc))
break;
/* Open the source image in the destination container. */
rc = VDOpen(pDiskTo, pImageFrom->Backend->pszBackendName, pImageFrom->pszFilename, pImageFrom->uOpenFlags);
if (VBOX_FAILURE(rc))
goto movefail;
/* Rename the image. */
rc = pImageTo->Backend->pfnRename(pImageTo->pvBackendData, pszFilename ? pszFilename : pImageTo->pszFilename);
if (VBOX_FAILURE(rc))
goto movefail;
/* Cleanup the leftovers. */
if (pImageFrom->pszFilename)
break;
/* In case of failure, re-open the source image in the source container. */
rc2 = VDOpen(pDiskFrom, pImageFrom->Backend->pszBackendName, pImageFrom->pszFilename, pImageFrom->uOpenFlags);
if (VBOX_FAILURE(rc2))
/* @todo Uncertain what to do on error. If this happens pImageFrom and pImageTo are both closed. */
break;
}
/* If fMoveByRename is set pszFilename is allowed to be NULL, so do the parameter check here. */
/* Collect properties of source image. */
if (VBOX_FAILURE(rc))
break;
if (cbSizeFrom == 0)
{
break;
}
if (cbSize == 0)
cbSize = cbSizeFrom;
unsigned uImageFlagsFrom;
if (VBOX_FAILURE(rc))
break;
/* @todo Get this from the source image. */
PDMMEDIAGEOMETRY PCHSGeometryFrom = {0, 0, 0};
PDMMEDIAGEOMETRY LCHSGeometryFrom = {0, 0, 0};
unsigned uOpenFlagsFrom;
if (VBOX_FAILURE(rc))
break;
/* Create destination image with the properties of the source image. */
/* @todo Copy the comment. */
if (enmTypeFrom == VD_IMAGE_TYPE_DIFF)
{
} else {
}
if (VBOX_FAILURE(rc))
break;
/* Allocate tmp buffer. */
if (!pvBuf)
{
rc = VERR_NO_MEMORY;
break;
}
/* Copy the data. */
do
{
if (VBOX_FAILURE(rc))
break;
if (VBOX_FAILURE(rc))
break;
uOffset += cbThisRead;
if (pfnProgress)
{
pvUser);
if (VBOX_FAILURE(rc))
break;
}
/* If fMoveByRename is set but the backend is different, close and delete pImageFrom. */
if ( (fMoveByRename == true)
{
/* Close and delete image. */
/* Free remaining resources. */
if (pImageFrom->pszFilename)
}
} while (0);
{
/* Error detected, but new image created. Remove image from list. */
/* Close and delete image. */
/* Free remaining resources. */
if (pImageTo->pszFilename)
}
if (pvBuf)
return rc;
}
/**
* Closes the last opened image file in HDD container.
* 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
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to HDD container.
* @param fDelete If true, delete the image from the host disk.
*/
{
int rc = VINF_SUCCESS;;
do
{
/* 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. */
{
}
if (!pImage)
break;
* like this (if possible) after closing this image. Set the open flags
* accordingly. */
if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY))
{
}
int rc2;
/* Cache disk information. */
/* Cache PCHS geometry. */
&pDisk->PCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the PCHS geometry is properly clipped. */
}
/* Cache LCHS geometry. */
&pDisk->LCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the LCHS geometry is properly clipped. */
}
} while (0);
return rc;
}
/**
* Closes all opened image files in HDD container.
*
* @returns VBox status code.
* @param pDisk Pointer to HDD container.
*/
{
int rc = VINF_SUCCESS;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
{
/* Remove image from list of opened images. */
/* Close image. */
/* Free remaining resources related to the image. */
{
}
}
} while (0);
return rc;
}
/**
* Read data from virtual HDD.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to 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.
*/
{
int rc;
LogFlowFunc(("pDisk=%#p uOffset=%llu pvBuf=%p cbRead=%zu\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pvBuf=%#p\n", pvBuf),
("cbRead=%zu\n", cbRead),
("uOffset=%llu cbRead=%zu pDisk->cbSize=%llu\n",
} while (0);
return rc;
}
/**
* Write data to virtual HDD.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to 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.
*/
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p uOffset=%llu pvBuf=%p cbWrite=%zu\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pvBuf=%#p\n", pvBuf),
("cbWrite=%zu\n", cbWrite),
("uOffset=%llu cbWrite=%zu pDisk->cbSize=%llu\n",
} while (0);
return rc;
}
/**
* Make sure the on disk representation of a virtual HDD is up to date.
*
* @returns VBox status code.
* @returns VERR_VDI_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to HDD container.
*/
{
int rc = VINF_SUCCESS;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
} while (0);
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 HDD container.
*/
{
unsigned cImages;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
} while (0);
return cImages;
}
/**
*
* @returns Virtual disk ReadOnly status.
* @returns true if no image is opened in HDD container.
* @param pDisk Pointer to HDD container.
*/
{
bool fReadOnly;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
unsigned uOpenFlags;
} while (0);
return fReadOnly;
}
/**
* Get total capacity of an image in HDD container.
*
* @returns Virtual disk size in bytes.
* @returns 0 if no image with specified number was not opened.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counds from 0. 0 is always base image of container.
*/
{
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
} while (0);
return cbSize;
}
/**
* Get total file size of an image in HDD container.
*
* @returns Virtual disk size in bytes.
* @returns 0 if no image is opened in HDD container.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
*/
{
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
} while (0);
return cbSize;
}
/**
* Get virtual disk PCHS geometry stored in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
*/
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImage=%u pPCHSGeometry=%#p\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pPCHSGeometry=%#p\n", pPCHSGeometry),
{
/* Use cached information if possible. */
else
}
else
} while (0);
return rc;
}
/**
* Store virtual disk PCHS 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_IMAGE_NOT_FOUND if image with specified number was not opened.
* @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
*/
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImage=%u pPCHSGeometry=%#p PCHS=%u/%u/%u\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pPCHSGeometry=%#p PCHS=%u/%u/%u\n", pPCHSGeometry,
{
{
/* 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. */
&pDisk->PCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the CHS geometry is properly clipped. */
}
}
}
else
{
&PCHS);
if ( VBOX_FAILURE(rc)
{
/* 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. */
}
}
} while (0);
return rc;
}
/**
* Get virtual disk LCHS geometry stored in HDD container.
*
* @returns VBox status code.
* @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
* @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
*/
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImage=%u pLCHSGeometry=%#p\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pLCHSGeometry=%#p\n", pLCHSGeometry),
{
/* Use cached information if possible. */
else
}
else
} while (0);
return rc;
}
/**
* Store virtual disk LCHS 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_IMAGE_NOT_FOUND if image with specified number was not opened.
* @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
*/
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImage=%u pLCHSGeometry=%#p LCHS=%u/%u/%u\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pLCHSGeometry=%#p LCHS=%u/%u/%u\n", pLCHSGeometry,
{
{
/* 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. */
&pDisk->LCHSGeometry);
if (VBOX_FAILURE(rc2))
{
}
else
{
/* Make sure the CHS geometry is properly clipped. */
}
}
}
else
{
&LCHS);
if ( VBOX_FAILURE(rc)
{
/* 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. */
}
}
} while (0);
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 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)
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImage=%u puVersion=%#p\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("puVersion=%#p\n", puVersion),
} while (0);
return rc;
}
/**
* 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 HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param penmType Where to store the image type.
*/
{
int rc;
LogFlowFunc(("pDisk=%#p nImage=%u penmType=%#p\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("penmType=%#p\n", penmType),
penmType);
} while (0);
return rc;
}
/**
* 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 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)
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImage=%u puImageFlags=%#p\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("puImageFlags=%#p\n", puImageFlags),
} while (0);
return rc;
}
/**
* Get open 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 HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param puOpenFlags Where to store the image open flags.
*/
unsigned *puOpenFlags)
{
int rc = VINF_SUCCESS;
LogFlowFunc(("pDisk=%#p nImage=%u puOpenFlags=%#p\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("puOpenFlags=%#p\n", puOpenFlags),
} while (0);
return rc;
}
/**
* Set open flags of image 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_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
*/
unsigned uOpenFlags)
{
int rc;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("uOpenFlags=%#x\n", uOpenFlags),
} while (0);
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 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 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)
{
int rc;
LogFlowFunc(("pDisk=%#p nImage=%u pszFilename=%#p cbFilename=%u\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("cbFilename=%u\n", cbFilename),
if (cb <= cbFilename)
{
rc = VINF_SUCCESS;
}
else
{
}
} while (0);
return rc;
}
/**
* 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 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)
{
int rc;
LogFlowFunc(("pDisk=%#p nImage=%u pszComment=%#p cbComment=%u\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("cbComment=%u\n", cbComment),
} while (0);
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 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)
{
int rc;
LogFlowFunc(("pDisk=%#p nImage=%u pszComment=%#p \"%s\"\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
} while (0);
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 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.
*/
{
int rc;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pUuid=%#p\n", pUuid),
} while (0);
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 HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid New UUID of the image. If NULL, a new UUID is created.
*/
{
int rc;
LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p {%Vuuid}\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
("pUuid=%#p\n", pUuid),
if (!pUuid)
{
RTUuidCreate(&Uuid);
}
} while (0);
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 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.
*/
{
int rc = VINF_SUCCESS;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pUuid=%#p\n", pUuid),
pUuid);
} while (0);
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 HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
*/
{
int rc;
LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p {%Vuuid}\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pUuid=%#p\n", pUuid),
if (!pUuid)
{
RTUuidCreate(&Uuid);
}
pUuid);
} while (0);
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 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.
*/
{
int rc = VINF_SUCCESS;
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pUuid=%#p\n", pUuid),
} while (0);
return rc;
}
/**
* Set the image's parent UUID. Should not be used by normal applications.
*
* @returns VBox status code.
* @param pDisk Pointer to HDD container.
* @param nImage Image number, counts from 0. 0 is always base image of container.
* @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
*/
{
int rc;
LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p {%Vuuid}\n",
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
/* Check arguments. */
("pUuid=%#p\n", pUuid),
if (!pUuid)
{
RTUuidCreate(&Uuid);
}
} while (0);
return rc;
}
/**
* Debug helper - dumps all opened images in HDD container into the log file.
*
* @param pDisk Pointer to HDD container.
*/
{
do
{
/* sanity check */
AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
{
RTLogPrintf("Dumping VD image \"%s\" (Backend=%s)\n",
}
} while (0);
}