VD.cpp revision 501cf203a1a41f541b0765f21fb0dd3740404e5a
2N/A * VBoxHDD - VBox HDD Container implementation. 2N/A * Copyright (C) 2006-2011 Oracle Corporation 2N/A * This file is part of VirtualBox Open Source Edition (OSE), as 2N/A * you can redistribute it and/or modify it under the terms of the GNU 2N/A * General Public License (GPL) as published by the Free Software 2N/A * Foundation, in version 2 as it comes in the "COPYING" file of the 2N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the 2N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 2N/A/******************************************************************************* 2N/A*******************************************************************************/ 2N/A/** Buffer size used for merging images. */ 2N/A/** Maximum number of segments in one I/O task. */ 2N/A/** Threshold after not recently used blocks are removed from the list. */ 2N/A * VD async I/O interface storage descriptor. 2N/A /** Completion callback. */ 2N/A /** Thread for async access. */ * Structure containing everything I/O related * for the image and cache descriptors. /** I/O interface to the upper layer. */ /** Per image internal I/O interface. */ /** Fallback I/O interface, only used if the caller doesn't provide it. */ /** Opaque backend data. */ /** Disk this image is part of */ * VBox HDD Container image descriptor. /** Link to parent image descriptor, if any. */ /** Link to child image descriptor, if any. */ /** Container base filename. (UTF-8) */ /** Data managed by the backend which keeps the actual info. */ /** Cached sanitized image flags. */ /** Image open flags (only those handled generically in this code and which * the backends will never ever see). */ /** Function pointers for the various backend methods. */ /** Pointer to list of VD interfaces, per-image. */ /** I/O related things. */ * VBox HDD Cache image descriptor. /** Cache base filename. (UTF-8) */ /** Data managed by the backend which keeps the actual info. */ /** Cached sanitized image flags. */ /** Image open flags (only those handled generically in this code and which * the backends will never ever see). */ /** Function pointers for the various backend methods. */ /** Pointer to list of VD interfaces, per-cache. */ /** I/O related things. */ * A block waiting for a discard. /** Number of bytes to discard. */ /** Bitmap of allocated sectors. */ /** Number of bytes waiting for a discard. */ /** AVL tree with blocks waiting for a discard. * The uOffset + cbDiscard range is the search key. */ /** LRU list of the least frequently discarded blocks. * If there are to many blocks waiting the least frequently used * will be removed and the range will be set to 0. * VBox HDD Container main structure, private part. /** Structure signature (VBOXHDDDISK_SIGNATURE). */ /** Number of opened images. */ /** Last opened image in the chain. * The same as pBase if only one image is used. */ /** If a merge to one of the parents is running this may be non-NULL * to indicate to what image the writes should be additionally relayed. */ /** Flags representing the modification state. */ /** Cached size of this disk. */ /** Cached PCHS geometry for this disk. */ /** Cached LCHS geometry for this disk. */ /** Pointer to list of VD interfaces, per-disk. */ /** Pointer to the common interface structure for error reporting. */ /** Pointer to the optional thread synchronization callbacks. */ /** Memory cache for I/O contexts */ /** Memory cache for I/O tasks. */ /** Critical section protecting the disk against concurrent access. */ /** Flag whether the disk is currently locked by growing write or a flush * request. Other flush or growing write requests need to wait until * the current one completes. /** List of waiting requests. - Protected by the critical section. */ /** I/O context which locked the disk. */ /** Pointer to the L2 disk cache if any. */ /** Pointer to the discard state if any. */ (
"Thread does not own critical section\n"));\
* VBox parent read descriptor, used internally for compaction. /** Pointer to disk descriptor. */ /** Pointer to image descriptor. */ /** Pointer to a transfer function. */ /** Disk this is request is for. */ /** Transfer direction */ /** Number of bytes left until this context completes. */ /** Number of bytes to transfer */ /** Current image in the chain. */ /** Start image to read from. pImageCur is reset to this * value after it reached the first image in the chain. */ /** Flag whether the I/O context is blocked because it is in the growing list. */ /** Number of data transfers currently pending. */ /** How many meta data transfers are pending. */ /** Flag whether the request finished */ /** Temporary allocated memory which is freed * when the context completes. */ /** Transfer function. */ /** Next transfer part after the current one completed. */ /** Parent I/O context if any. Sets the type of the context (root/child) */ /** Completion callback */ /** User argument 1 passed on completion. */ /** User argument 1 passed on completion. */ /** Saved start offset */ /** Saved transfer size */ /** Number of bytes transferred from the parent if this context completes. */ /** Number of bytes to pre read */ /** Number of bytes to post read. */ /** Number of bytes to write left in the parent. */ /** Write type dependent data. */ /** Bytes to fill to satisfy the block size. Not part of the virtual disk. */ /** Bytes to copy instead of reading from the parent */ /** Bytes to read from the image. */ /** Node in the list of deferred requests. * A request can be deferred if the image is growing * and the request accesses the same range or if * the backend needs to read or write metadata from the disk * before it can continue. */ /** I/O context this entry points to. */ /** Storage this task belongs to. */ /** Optional completion callback. */ /** Flag whether this is a meta data transfer. */ /** Type dependent data. */ /** User data transfer. */ /** Number of bytes this task transferred. */ /** Pointer to the I/O context the task belongs. */ /** Meta data transfer. */ /** Meta transfer this task is for. */ /** Image I/O state this storage handle belongs to. */ /** AVL tree for pending async metadata transfers. */ * @note This entry can't be freed if either the list is not empty or * the reference counter is not 0. * The assumption is that the backends don't need to read huge amounts of * metadata to complete a transfer so the additional memory overhead should /** AVL core for fast search (the file offset is the key) */ /** I/O storage for this transfer. */ /** List of I/O contexts waiting for this metadata transfer to complete. */ /** Number of references to this entry. */ /** Size of the data stored with this entry. */ /** Data stored - variable size. */ * The transfer direction for the metadata. * Supported backends for the disk cache. * internal: add several backends. * internal: add single backend. * internal: add several cache backends. * internal: add single cache backend. * internal: issue error message. * internal: thread synchronization, start read. * internal: thread synchronization, finish read. * internal: thread synchronization, start write. * internal: thread synchronization, finish write. * internal: find image format backend. * internal: find cache format backend. * internal: add image structure to the end of images list. * internal: remove image structure from the images list. * internal: find image by index into the images list. * Internal: Tries to read the desired range from the given cache. * @returns VBox status code. * @retval VERR_VD_BLOCK_FREE if the block is not in the cache. * pcbRead will be set to the number of bytes not in the cache. * Everything thereafter might be in the cache. * @param pCache The cache to read from. * @param uOffset Offset of the virtual disk to read. * @param pvBuf Where to store the read data. * @param cbRead How much to read. * @param pcbRead Where to store the number of bytes actually read. * On success this indicates the number of bytes read from the cache. * If VERR_VD_BLOCK_FREE is returned this gives the number of bytes * which are not in the cache. * In both cases everything beyond this value * might or might not be in the cache. LogFlowFunc((
"pCache=%#p uOffset=%llu pvBuf=%#p cbRead=%zu pcbRead=%#p\n",
* Internal: Writes data for the given block into the cache. * @returns VBox status code. * @param pCache The cache to write to. * @param uOffset Offset of the virtual disk to write to teh cache. * @param pcvBuf The data to write. * @param cbWrite How much to write. * @param pcbWritten How much data could be written, optional. LogFlowFunc((
"pCache=%#p uOffset=%llu pvBuf=%#p cbWrite=%zu pcbWritten=%#p\n",
* Internal: Reads a given amount of data from the image chain of the disk. * Try to read from the given image. * If the block is not allocated read from override chain if present. * Extended version of vdReadHelper(), implementing certain optimizations * @returns VBox status code. * @param pDisk The disk to read from. * @param pImage The image to start reading from. * @param pImageParentOverride The parent image to read from * if the starting image returns a free block. * If NULL is passed the real parent of the image * @param uOffset Offset in the disk to start reading from. * @param pvBuf Where to store the read data. * @param cbRead How much to read. * @param fZeroFreeBlocks Flag whether free blocks should be zeroed. * If false and no image has data for sepcified * range VERR_VD_BLOCK_FREE is returned. * Note that unallocated blocks are still zeroed * if at least one image has valid data for a part * @param fUpdateCache Flag whether to update the attached cache if * @param cImagesRead Number of images in the chain to read until * the read is cut off. A value of 0 disables the cut off. /* Loop until all read. */ /* 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. */ /* If the read was successful, write the data back into the cache. */ /** @todo can be be replaced by vdDiskReadHelper if it proves to be reliable, * don't want to be responsible for data corruption... * Try to read from the given image. * If the block is not allocated read from override chain if present. /* No image in the chain contains the data for the block. */ /* Fill the free space with 0 if we are told to do so * or a previous read returned valid data. */ /* First not free block, fill the space before with 0. */ * internal: read the specified amount of data in whatever blocks the backend * Creates a new empty discard state. * @returns Pointer to the new discard state or NULL if out of memory. * Removes the least recently used blocks from the waiting list until * the new value is reached. * @returns VBox status code. * @param pDisk VD disk container. * @param pDiscard The discard state. * @param cbDiscardingNew How many bytes should be waiting on success. * The number of bytes waiting can be less. LogFlowFunc((
"pDisk=%#p pDiscard=%#p cbDiscardingNew=%zu\n",
/* Go over the allocation bitmap and mark all discarded sectors as unused. */ /* Check for the first unallocated bit. */ /* Mark as unused and check for the first set bit. */ * Destroys the current discard state, writing any waiting blocks to the image. * @returns VBox status code. * @param pDisk VD disk container. * Discards the given range from the underlying block. * @returns VBox status code. * @param pDisk VD container data. * @param offStart Where to start discarding. * @param cbDiscard How many bytes to discard. LogFlowFunc((
"pDisk=%#p pDiscard=%#p offStart=%llu cbDiscard=%zu\n",
/* Look for a matching block in the AVL tree first. */ /* Clip range to remain in the current block. */ /* No block found, try to discard using the backend first. */ /* Create new discard block. */ /* Range lies partly in the block, update allocation bitmap. */ /* Call the backend to discard the block if it is completely unallocated now. */ /* Remove the block on success. */ * @returns VBox status code. * @param pDisk VD container data. * @param paRanges The array of ranges to discard. * @param cRanges The number of ranges in the array. /* Go over the range array and discard individual blocks. */ for (
unsigned i = 0; i <
cRanges; i++)
* Marks the given range as allocated in the image. * Required if there are discards in progress and a write to a block which can get discarded * @returns VBox status code. * @param pDisk VD container data. * @param uOffset First byte to mark as allocated. * @param cbRange Number of bytes to mark as allocated. /* There is no S/G list for a flush request. */ * We complete the I/O context in case of an error * if there is no I/O task pending. /* Don't change anything if there is a metadata transfer pending or we are blocked. */ /* Call the transfer function advancing to the next while there is no error. */ /* Advance to the next part of the transfer if the current one succeeded. */ * The I/O context completed if we have an error and there is no data * or meta data transfer pending. LogFlowFunc((
"pIoCtx=%#p rc=%Rrc cbTransferLeft=%u cMetaTransfersPending=%u fComplete=%RTbool\n",
LogFlowFunc((
"pDisk=%#p pIoCtx=%#p fProcessDeferredReqs=%RTbool\n",
/* Process any pending writes if the current request didn't caused another growing. */ * internal: read the specified amount of data in whatever blocks the backend * will give us - async version. /* Loop until all reads started or we have a backend which needs to read metadata. */ /* 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. */ * Try to read from the given image. * If the block is not allocated read from override chain if present. /* The task state will be updated on success already, don't do it here!. */ /* No image in the chain contains the data for the block. */ /* Save the current state. */ * internal: parent image read wrapper for compacting. * internal: mark the disk as not modified. /* generate new last-modified 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). /* Read the data that goes before the write to fill the block. */ * Updating the cache doesn't make sense here because * this will be done after the complete block was written. true /* fZeroFreeBlocks*/,
false /* fUpdateCache */, 0);
/* Copy the data to the right place in the buffer. */ /* Read the data that goes after the write to fill the block. */ /* If we have data to be written, use that instead of reading * data from the image. */ /* Figure out how much we cannot read from the image, because * the last block to write might exceed the nominal size of the * image for technical reasons. */ /* The rest must be read from the image. */ /* Now assemble the remaining data. */ false /* fUpdateCache */, 0);
/* Zero out the remainder of this block. Will never be visible, as this * is beyond the limit of the image. */ /* Write the full block to the virtual disk. */ * 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. /* Figure out how much we cannot 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. */ /* 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. */ true /* fZeroFreeBlocks */,
false /* fUpdateCache */,
/* Check if the write would modify anything in this block. */ /* Block is completely unchanged, so no need to write anything. */ /* Copy the data to the right place in the buffer. */ /* Handle the data that goes after the write to fill the block. */ /* Now assemble the remaining data. */ /* Zero out the remainder of this block. Will never be visible, as this * is beyond the limit of the image. */ /* Write the full block to the virtual disk. */ * internal: write buffer to the image, taking care of block boundaries and /* Loop until all written. */ /* 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. */ /* Optimized write, suppress writing to a so far unallocated * block if the data is in fact not changed. */ /* 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. */ /* Update the cache on success */ * internal: write buffer to the image, taking care of block boundaries and * Internal: Copies the content of one disk to another one applying optimizations * to speed up the copy process if possible. LogFlowFunc((
"pDiskFrom=%#p pImageFrom=%#p pDiskTo=%#p cbSize=%llu cImagesFromRead=%u cImagesToRead=%u fSuppressRedundantIo=%RTbool pIfProgress=%#p pDstIfProgress=%#p\n",
/* Allocate tmp buffer. */ /* Note that we don't attempt to synchronize cross-disk accesses. * It wouldn't be very difficult to do, just the lock order would * need to be defined somehow to prevent deadlocks. Postpone such * magic as there is no use case for this. */ /* Read the source data. */ false /* fUpdateCache */);
/* Only do collapsed I/O if we are copying the data blockwise. */ else /* Don't propagate the error to the outside */ * Flush helper async version. * internal: mark the disk as modified - async version. /* 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) - async version. /* Read the data that goes before the write to fill the block. */ /* Copy the data to the right place in the buffer. */ /* Read the data that goes after the write to fill the block. */ /* If we have data to be written, use that instead of reading * data from the image. */ /* Figure out how much we cannot read from the image, because * the last block to write might exceed the nominal size of the * image for technical reasons. */ /* The rest must be read from the image. */ /* Now assemble the remaining data. */ /* Zero out the remainder of this block. Will never be visible, as this * is beyond the limit of the image. */ /* Write the full block to the virtual disk. */ LogFlow((
"cbTransferLeft=%u cMetaTransfersPending=%u fComplete=%RTbool\n",
/* Check if the write would modify anything in this block. */ /* Block is completely unchanged, so no need to write anything. */ /* Copy the data to the right place in the buffer. */ /* Handle the data that goes after the write to fill the block. */ /* Now assemble the remaining data. */ * The S/G buffer of the parent needs to be cloned because * it is not allowed to modify the state. /* Zero out the remainder of this block. Will never be visible, as this * is beyond the limit of the image. */ /* Write the full block to the virtual disk. */ * 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. /* Figure out how much we cannot 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. */ /* 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. */ * internal: write buffer to the image, taking care of block boundaries and * write optimizations - async version. /* Loop until all written. */ /* 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. */ * Allocate segment and buffer in one go. * A bit hackish but avoids the need to allocate memory twice. LogFlowFunc((
"Disk is growing because of pIoCtx=%#p pIoCtxWrite=%#p\n",
/* Process the write request */ LogFlow((
"Child write request completed\n"));
LogFlow((
"Child write pending\n"));
* Tell the caller that we don't need to go back here because all * Flush helper async version. * internal: scans plugin directory and loads the backends have been found. /* Enumerate plugin backends. */ /* To get all entries with VBoxHDD as prefix. */ /* The plugins are in the same directory as the other shared libs. */ /* On Windows the above immediately signals that there are no * files matching, while on other platforms enumerating the * files below fails. Either way: no plugins. */ /* allocate new buffer. */ /* We got the new entry. */ /* Prepend the path to the libraries. */ /* Get the function table. */ * internal: scans plugin directory and loads the cache backends have been found. /* Enumerate plugin backends. */ /* To get all entries with VBoxHDD as prefix. */ /* The plugins are in the same directory as the other shared libs. */ /* On Windows the above immediately signals that there are no * files matching, while on other platforms enumerating the * files below fails. Either way: no plugins. */ /* allocate new buffer. */ /* We got the new entry. */ /* Prepend the path to the libraries. */ LogFunc((
"error resolving the entry point %s in plugin %s, rc=%Rrc, pfnVDCacheLoad=%#p\n",
/* Get the function table. */ * VD async I/O interface open callback. * VD async I/O interface close callback. * VD async I/O interface callback for retrieving the file size. * VD async I/O interface callback for setting the file size. * VD async I/O interface callback for a synchronous write to the file. * VD async I/O interface callback for a synchronous read from the file. * VD async I/O interface callback for a synchronous flush of the file data. * VD async I/O interface callback for a asynchronous read from the file. * VD async I/O interface callback for a asynchronous write to the file. * VD async I/O interface callback for a asynchronous flush of the file data. * Internal - Continues an I/O context after * it was halted because of an active transfer. /* Continue the transfer */ LogFlowFunc((
"I/O context transferred %u bytes for the parent pIoCtxParent=%p\n",
/* Update the parent state. */ * A completed child write means that we finished growing the image. * We have to process any pending writes now. /* Process any pending writes if the current request didn't caused another growing. */ * Internal - Called when user transfer completed. LogFlowFunc((
"pIoStorage=%#p pIoCtx=%#p pfnComplete=%#p pvUser=%#p cbTransfer=%zu rcReq=%Rrc\n",
* Internal - Called when a meta transfer completed. LogFlowFunc((
"pIoStorage=%#p pfnComplete=%#p pvUser=%#p pMetaXfer=%#p rcReq=%Rrc\n",
/* Remove from the AVL tree. */ /* Increase the reference counter to make sure it doesn't go away before the last context is processed. */ /* Go through the waiting list and continue the I/O contexts. */ LogFlow((
"Completion callback for I/O context %#p returned %Rrc\n",
pIoCtx,
rc));
/* Remove if not used anymore. */ /* Remove from the AVL tree. */ * VD I/O interface callback for opening a file. /* Create the AVl tree. */ LogFlowFunc((
"pvUser=%#p pIoStorage=%#p uOffset=%llu pIoCtx=%#p cbRead=%u\n",
/* Build the S/G array and spawn a new I/O task */ (
"Segment %u is invalid\n", i));
LogFlowFunc((
"pvUser=%#p pIoStorage=%#p uOffset=%llu pIoCtx=%#p cbWrite=%u\n",
/* Build the S/G array and spawn a new I/O task */ (
"Segment %u is invalid\n", i));
LogFlowFunc((
"pvUser=%#p pIoStorage=%#p uOffset=%llu pvBuf=%#p cbRead=%u\n",
(
"Overlapping meta transfers!\n"));
/* Allocate a new meta transfer. */ /* If it is pending add the request to the list. */ LogFlowFunc((
"pvUser=%#p pIoStorage=%#p uOffset=%llu pvBuf=%#p cbWrite=%u\n",
/* Allocate a new meta transfer. */ /* Free the meta data entry. */ /* Allocate a new meta transfer. */ * Grab the disk critical section to avoid races with other threads which * might still modify the I/O context. * Example is that iSCSI is doing an asynchronous write but calls us already * while the other thread is still hanging in vdWriteHelperAsync and couldn't update * the fBlocked state yet. * It can overwrite the state to true before we call vdIoCtxContinue and the * the request would hang indefinite. /* Clear the pointer to next transfer function in case we have nothing to transfer anymore. * @todo: Find a better way to prevent vdIoCtxContinue from calling the read/write helper again. */ * VD I/O interface callback for opening a file (limited version for VDGetFormat). * internal: send output to the log (unconditionally). * internal: adjust PCHS geometry /* Fix broken PCHS geometry. Can happen for two reasons: either the backend * mixes up PCHS and LCHS, or the application used to create the source * image has put garbage in it. Additionally, if the PCHS geometry covers * more than the image size, set it back to the default. */ * internal: adjust PCHS geometry /* Fix broken LCHS geometry. Can happen for two reasons: either the backend * mixes up PCHS and LCHS, or the application used to create the source * image has put garbage in it. The fix in this case is to clear the LCHS * geometry to trigger autodetection when it is used next. If the geometry * already says "please autodetect" (cylinders=0) keep it. */ /* Always recompute the number of cylinders stored in the LCHS * geometry if it isn't set to "autotedetect" at the moment. * This is very useful if the destination image size is * larger or smaller than the source image size. Do not modify * the number of heads and sectors. Windows guests hate it. */ * Sets the I/O callbacks of the given interface to the fallback methods * @param pIfIo The I/O interface to setup. * Sets the internal I/O callbacks of the given interface. * @param pIfIoInt The internal I/O interface to setup. * Initializes HDD backends. * @returns VBox status code. LogRel((
"VDInit finished\n"));
* Destroys loaded HDD backends. * @returns VBox status code. /* Clear the supported cache backends. */ * 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. * Lists the capabilities of a backend identified by its name. * @returns VBox status code. * @param pszBackend The backend name. * @param pEntries Pointer to an entry. /* Go through loaded backends. */ * Allocates and initializes an empty HDD container. * No image files are opened. * @returns VBox status code. * @param pVDIfsDisk Pointer to the per-disk VD interface list. * @param enmType Type of the image container. * @param ppDisk Where to store the reference to HDD container. /* Create the I/O ctx cache */ /* Create the I/O task cache */ /* Create critical section. */ * Destroys HDD container. * If container has opened image files they will be closed. * @param pDisk Pointer to HDD container. * 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 pVDIfsDisk Pointer to the per-disk VD interface list. * @param pVDIfsImage Pointer to the per-image VD interface list. * @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(). * Caller doesn't provide an I/O interface, create our own using the /* Set up the internal I/O interface. */ /* Find the backend supporting this file format. */ /* The correct backend has been found, but there is a small * incompatibility so that the file cannot be used. Stop here * and signal success - the actual open will of course fail, * but that will create a really sensible error message. */ /* Copy the name into the new string. */ /* Try the cache backends. */ /* Copy the name into the new string. */ * 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. * When another differencing image is opened and the last image was opened in read/write access * 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. * Note that the image is opened in read-only mode if a read/write open is not possible. * 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. * @param pVDIfsImage Pointer to the per-image VD interface list. LogFlowFunc((
"pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uOpenFlags=%#x, pVDIfsImage=%#p\n",
* Destroy the current discard state first which might still have pending blocks * for the currently opened image which will be switched to readonly mode. /* Lock disk for writing, as we modify pDisk information below. */ /* Set up image descriptor. */ * Fail if the the backend can't do async I/O but the N_(
"VD: Backend '%s' does not support async I/O"),
pszBackend);
* Fail if the the backend doesn't support the discard operation but the N_(
"VD: Backend '%s' does not support discard"),
pszBackend);
/* Set up the I/O interface. */ /* Set up the internal I/O interface. */ /* If the open in read-write mode failed, retry in read-only mode. */ /* Lock disk for writing, as we modify pDisk information below. */ /* Check image type. As the image itself has only partial knowledge * whether it's a base image or not, this info is derived here. The * base image can be fixed or normal, all others must be normal or * diff images. Some image formats don't distinguish between normal * and diff images, so this must be corrected here. */ /* Ensure we always get correct diff information, even if the backend * doesn't actually have a stored flag for this. It must not return * bogus information for the parent UUID if it is not a diff image. */ /* Force sane optimization settings. It's not worth avoiding writes * to fixed size images. The overhead would have almost no payback. */ /** @todo optionally check UUIDs */ /* Cache disk information. */ /* Cache PCHS geometry. */ /* Make sure the PCHS geometry is properly clipped. */ /* Cache LCHS geometry. */ /* Make sure the LCHS geometry is properly clipped. */ /* Switch previous image to read-only mode. */ /* Image successfully opened, make it the last image. */ /* Error detected, but image opened. Close image. */ * @return VBox status code. * @param pDisk Pointer to the HDD container which should use the cache image. * @param pszBackend Name of the cache file backend to use (case insensitive). * @param pszFilename Name of the cache image to open. * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants. * @param pVDIfsCache Pointer to the per-cache VD interface list. LogFlowFunc((
"pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uOpenFlags=%#x, pVDIfsCache=%#p\n",
/* Set up image descriptor. */ /* Set up the I/O interface. */ /* Set up the internal I/O interface. */ /* If the open in read-write mode failed, retry in read-only mode. */ /* Lock disk for writing, as we modify pDisk information below. */ * Check that the modification UUID of the cache and last image * match. If not the image was modified in-between without the cache. * The cache might contain stale data. * We assume that the user knows what he is doing if one of the images * doesn't support the modification uuid. /* Cache successfully opened, make it the current one. */ /* Error detected, but image opened. Close image. */ * 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 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 <= (x,255,63). Not NULL. * @param pUuid New UUID of the image. If NULL, a new UUID is created. * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants. * @param pVDIfsImage Pointer to the per-image VD interface list. * @param pVDIfsOperation Pointer to the per-operation VD interface list. LogFlowFunc((
"pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" PCHS=%u/%u/%u LCHS=%u/%u/%u Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n",
/* The PCHS geometry fields may be 0 to leave it for later. */ /* The LCHS geometry fields may be 0 to leave it to later autodetection. */ /* The UUID may be NULL. */ /* Check state. Needs a temporary read lock. Holding the write lock * all the time would be blocking other activities for too long. */ (
"Create base image cannot be done with other images open\n"),
/* Set up image descriptor. */ /* Set up the I/O interface. */ /* Set up the internal I/O interface. */ N_(
"VD: backend '%s' cannot create base images"),
pszBackend);
/* Create UUID if the caller didn't specify one. */ N_(
"VD: cannot generate UUID for image '%s'"),
/* Force sane optimization settings. It's not worth avoiding writes * to fixed size images. The overhead would have almost no payback. */ /* Lock disk for writing, as we modify pDisk information below. */ /** @todo optionally check UUIDs */ /* Re-check state, as the lock wasn't held and another image * creation call could have been done by another thread. */ (
"Create base image cannot be done with other images open\n"),
/* Cache disk information. */ /* Cache PCHS geometry. */ /* Make sure the CHS geometry is properly clipped. */ /* Cache LCHS geometry. */ /* Make sure the CHS geometry is properly clipped. */ /* Image successfully opened, make it the last image. */ /* Error detected, image may or may not be opened. Close and delete * image if it was opened. */ * 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 pUuid New UUID of the image. If NULL, a new UUID is created. * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically. * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants. * @param pVDIfsImage Pointer to the per-image VD interface list. * @param pVDIfsOperation Pointer to the per-operation VD interface list. LogFlowFunc((
"pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uImageFlags=%#x pszComment=\"%s\" Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n",
/* The UUID may be NULL. */ /* The parent UUID may be NULL. */ /* Check state. Needs a temporary read lock. Holding the write lock * all the time would be blocking other activities for too long. */ (
"Create diff image cannot be done without other images open\n"),
* Destroy the current discard state first which might still have pending blocks * for the currently opened image which will be switched to readonly mode. /* Lock disk for writing, as we modify pDisk information below. */ /* Set up image descriptor. */ N_(
"VD: backend '%s' cannot create diff images"),
pszBackend);
/* Set up the I/O interface. */ /* Set up the internal I/O interface. */ /* Create UUID if the caller didn't specify one. */ N_(
"VD: cannot generate UUID for image '%s'"),
/* Lock disk for writing, as we modify pDisk information below. */ /* Switch previous image to read-only mode. */ /** @todo optionally check UUIDs */ /* Re-check state, as the lock wasn't held and another image * creation call could have been done by another thread. */ (
"Create diff image cannot be done without other images open\n"),
/* Image successfully opened, make it the last image. */ /* Error detected, but image opened. Close and delete image. */ * Creates and opens new cache image file in HDD container. * @return VBox status code. * @param pDisk Name of the cache file backend to use (case insensitive). * @param pszFilename Name of the differencing cache file to create. * @param cbSize Maximum size of the cache. * @param uImageFlags Flags specifying special cache features. * @param pszComment Pointer to image comment. NULL is ok. * @param pUuid New UUID of the image. If NULL, a new UUID is created. * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants. * @param pVDIfsCache Pointer to the per-cache VD interface list. * @param pVDIfsOperation Pointer to the per-operation VD interface list. LogFlowFunc((
"pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n",
/* The UUID may be NULL. */ /* Check state. Needs a temporary read lock. Holding the write lock * all the time would be blocking other activities for too long. */ (
"Create cache image cannot be done with a cache already attached\n"),
/* Set up image descriptor. */ /* Set up the I/O interface. */ /* Set up the internal I/O interface. */ /* Create UUID if the caller didn't specify one. */ N_(
"VD: cannot generate UUID for image '%s'"),
/* Lock disk for writing, as we modify pDisk information below. */ /* Re-check state, as the lock wasn't held and another image * creation call could have been done by another thread. */ (
"Create cache image cannot be done with another cache open\n"),
/* Set same modification Uuid as the last image. */ /* Cache successfully created. */ /* Error detected, but image opened. Close and delete image. */ * Merges two images (not necessarily with direct parent/child relationship). * 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_VD_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 pVDIfsOperation Pointer to the per-operation VD interface list. LogFlowFunc((
"pDisk=%#p nImageFrom=%u nImageTo=%u pVDIfsOperation=%#p\n",
/* For simplicity reasons lock for writing as the image reopen below * might need it. After all the reopen is usually needed. */ /* Make sure destination image is writable. */ /* Get size of destination image. */ /* Allocate tmp buffer. */ /* Merging is done directly on the images itself. This potentially * causes trouble if the disk is full in the middle of operation. */ /* 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. */ /* Need to hold the write lock during a read-write operation. */ /* 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. */ /* Updating the cache is required because this might be a live merge. */ true /* fUpdateCache */, 0);
/** @todo r=klaus: this can update the progress to the same * percentage over and over again if the image format makes * relatively small increments. */ * We may need to update the parent uuid of the child coming after * the last image to be merged. We have to reopen it read/write. * This is done before we do the actual merge to prevent an * inconsistent chain if the mode change fails for some reason. /* Take the write lock. */ /* We need to open the image in read/write mode. */ /* If the merge is from the last image we have to relay all writes * to the merge destination as well, so that concurrent writes * (in case of a live merge) are handled correctly. */ /* Take the write lock. */ /* Merge child state into parent. This means writing all blocks * which are allocated in the image up to the source image to the /* Need to hold the write lock during a read-write operation. */ /* 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. */ /** @todo r=klaus: this can update the progress to the same * percentage over and over again if the image format makes * relatively small increments. */ /* In case we set up a "write proxy" image above we must clear * this again now to prevent stray writes. Failure or not. */ /* Take the write lock. */ * Leave in case of an error to avoid corrupted data in the image chain * (includes cancelling the operation by the user). /* Need to hold the write lock while finishing the merge. */ /* Update parent UUID so that image chain is consistent. */ /* Update the parent uuid of the child of the last merged image. */ /* Delete the no longer needed images. */ /* Make sure destination image is back to read only if necessary. */ * Make sure the child is readonly * for the child -> parent merge direction * Copies an image from one HDD container to another - extended version. * 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, * then the image is moved (by copying/deleting or renaming) to the new location. * 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. * @note The read/write accesses across disks are not synchronized, just the * accesses to each disk. Once there is a use case which requires a defined * read/write behavior in this situation this needs to be extended. * @return VBox status code. * @return VERR_VD_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 (may be NULL to use the same as the source, case insensitive). * @param pszFilename New name of the image (may be NULL to specify that the * copy destination is the destination container, or * if pDiskFrom == pDiskTo, i.e. when moving). * @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 nImageSameFrom todo * @param nImageSameTo todo * @param uImageFlags Flags specifying special destination image features. * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created. * This parameter is used if and only if a true copy is created. * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over. * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants. * Only used if the destination image is created. * @param pVDIfsOperation Pointer to the per-operation VD interface list. * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the * @param pDstVDIfsOperation Pointer to the per-operation VD interface list, * for the destination operation. LogFlowFunc((
"pDiskFrom=%#p nImage=%u pDiskTo=%#p pszBackend=\"%s\" pszFilename=\"%s\" fMoveByRename=%d cbSize=%llu nImageFromSame=%u nImageToSame=%u uImageFlags=%#x pDstUuid=%#p uOpenFlags=%#x pVDIfsOperation=%#p pDstVDIfsImage=%#p pDstVDIfsOperation=%#p\n",
pDiskFrom,
nImage,
pDiskTo,
pszBackend,
pszFilename,
fMoveByRename,
cbSize,
nImageFromSame,
nImageToSame,
uImageFlags,
pDstUuid,
uOpenFlags,
pVDIfsOperation,
pDstVDIfsImage,
pDstVDIfsOperation));
/* Rename only works when backends are the same, are file based * and the rename method is implemented. */ * requested, but the rename attempt failed or it wasn't possible. * Must now copy image to temp location. */ /* pszFilename is allowed to be NULL, as this indicates copy to the existing image. */ /* Create destination image with the properties of source image. */ * calls to the backend. Unifies the code and reduces the API * dependencies. Would also make the synchronization explicit. */ /** @todo hack to force creation of a fixed image for * the RAW backend, which can't handle anything else. */ /* Update the geometry in the destination image. */ /* Whether we can take the optimized copy path (false) or not. * Don't optimize if the image existed or if it is a child image. */ /* Only set modification UUID if it is non-null, since the source * backend might not provide a valid modification UUID. */ /* Set the requested open flags if they differ from the value * required for creating the image and copying the contents. */ /* Take the write lock only if it is not taken. Not worth making the * above code even more complicated. */ /* Error detected, but new image created. Remove image from list. */ /* Close and delete image. */ /* Free remaining resources. */ * 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, * then the image is moved (by copying/deleting or renaming) to the new location. * 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_VD_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 uImageFlags Flags specifying special destination image features. * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created. * This parameter is used if and only if a true copy is created. * In all rename/move cases the UUIDs are copied over. * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants. * Only used if the destination image is created. * @param pVDIfsOperation Pointer to the per-operation VD interface list. * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the * @param pDstVDIfsOperation Pointer to the per-image VD interface list, * for the destination image. * Optimizes the storage consumption of an image. Typically the unused blocks * have to be wiped with zeroes to achieve a substantial reduced storage use. * Another optimization done is reordering the image blocks, which can provide * a significant performance boost, as reads and writes tend to use less random * @return VBox status code. * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened. * @return VERR_VD_IMAGE_READ_ONLY if image is not writable. * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but * the code for this isn't implemented yet. * @param pDisk Pointer to HDD container. * @param nImage Image number, counts from 0. 0 is always base image of container. * @param pVDIfsOperation Pointer to the per-operation VD interface list. LogFlowFunc((
"pDisk=%#p nImage=%u pVDIfsOperation=%#p\n",
/* If there is no compact callback for not file based backends then * the backend doesn't need compaction. No need to make much fuss about * this. For file based ones signal this as not yet supported. */ /* Insert interface for reading parent state into per-operation list, * if there is a parent image. */ * Resizes the the given disk image to the given size. * @return VERR_VD_IMAGE_READ_ONLY if image is not writable. * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but * @param pDisk Pointer to the HDD container. * @param cbSize New size of the image. * @param pPCHSGeometry Pointer to the new physical disk geometry <= (16383,16,63). Not NULL. * @param pLCHSGeometry Pointer to the new logical disk geometry <= (x,255,63). Not NULL. * @param pVDIfsOperation Pointer to the per-operation VD interface list. /** @todo r=klaus resizing was designed to be part of VDCopy, so having a separate function is not desirable. */ LogFlowFunc((
"pDisk=%#p cbSize=%llu pVDIfsOperation=%#p\n",
/* Not supported if the disk has child images attached. */ /* If there is no compact callback for not file based backends then * the backend doesn't need compaction. No need to make much fuss about * this. For file based ones signal this as not yet supported. */ /* Auto-detect marker, calculate new value ourself. */ /* Auto-detect marker, calculate new value ourself. */ * Closes the last opened image file in HDD container. * If previous image file was opened in read-only mode (the normal case) and * the last opened image is in read-write mode then the previous image will be * @returns VBox status code. * @returns VERR_VD_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. /* Not worth splitting this up into a read lock phase and write * lock phase, as closing an image is a relatively fast operation * dominated by the part which needs the write lock. */ /* Destroy the current discard state first which might still have pending blocks. */ /* Remove image from list of opened images. */ /* Close (and optionally delete) image. */ /* Free remaining resources related to the image. */ /* If disk was previously in read/write mode, make sure it will stay * like this (if possible) after closing this image. Set the open flags /* Cache disk information. */ /* Cache PCHS geometry. */ /* Make sure the PCHS geometry is properly clipped. */ /* Cache LCHS geometry. */ /* Make sure the LCHS geometry is properly clipped. */ * Closes the currently opened cache image file in HDD container. * @return VBox status code. * @return VERR_VD_NOT_OPENED if no cache is opened in HDD container. * @param pDisk Pointer to HDD container. * @param fDelete If true, delete the image from the host disk. * Closes all opened image files in HDD container. * @returns VBox status code. * @param pDisk Pointer to HDD container. /* Lock the entire operation. */ /* Remove image from list of opened images. */ /* Free remaining resources related to the image. */ * Read data from virtual HDD. * @returns VBox status code. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p uOffset=%llu pvBuf=%p cbRead=%zu\n",
(
"uOffset=%llu cbRead=%zu pDisk->cbSize=%llu\n",
true /* fUpdateCache */);
* Write data to virtual HDD. * @returns VBox status code. * @returns VERR_VD_NOT_OPENED if no image is opened in HDD container. * @param pDisk Pointer to HDD container. * @param uOffset Offset of the first byte being * written from start of disk. * @param pvBuf Pointer to buffer for writing data. * @param cbWrite Number of bytes to write. LogFlowFunc((
"pDisk=%#p uOffset=%llu pvBuf=%p cbWrite=%zu\n",
(
"uOffset=%llu cbWrite=%zu pDisk->cbSize=%llu\n",
true /* fUpdateCache */);
/* If there is a merge (in the direction towards a parent) running * concurrently then we have to also "relay" the write to this parent, * as the merge position might be already past the position where * this write is going. The "context" of the write can come from the * natural chain, since merging either already did or will take care * of the "other" content which is might be needed to fill the block * to a full allocation size. The cache doesn't need to be touched * as this write is covered by the previous one. */ * Make sure the on disk representation of a virtual HDD is up to date. * @returns VBox status code. * @returns VERR_VD_NOT_OPENED if no image is opened in HDD container. * @param pDisk Pointer to HDD container. * 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. * @returns Virtual disk ReadOnly status. * @returns true if no image is opened in HDD container. * @param pDisk Pointer to HDD container. * 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, counts from 0. 0 is always base image of container. * 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. * Get virtual disk PCHS geometry stored in HDD container. * @returns VBox status code. * @returns VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pPCHSGeometry=%#p\n",
/* Use cached information if possible. */ * 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_VD_IMAGE_NOT_FOUND if image with specified number was not opened. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pPCHSGeometry=%#p PCHS=%u/%u/%u\n",
/* 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 /* Cache new geometry values in any case. */ /* Make sure the CHS geometry is properly clipped. */ /* 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 * Get virtual disk LCHS geometry stored in HDD container. * @returns VBox status code. * @returns VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pLCHSGeometry=%#p\n",
/* Use cached information if possible. */ * 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_VD_IMAGE_NOT_FOUND if image with specified number was not opened. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pLCHSGeometry=%#p LCHS=%u/%u/%u\n",
/* 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 /* Cache new geometry values in any case. */ /* Make sure the CHS geometry is properly clipped. */ /* 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 * Get version of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. * List the capabilities of image backend in HDD container. * @returns VBox status code. * @returns VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened. * @param pDisk Pointer to the HDD container. * @param nImage Image number, counts from 0. 0 is always base image of container. * @param pbackendInfo Where to store the backend information. * Get flags of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. * Get open flags of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. * Set open flags of image in HDD container. * This operation may cause file locking changes and/or files being reopened. * Note that in case of unrecoverable error all images in HDD container will be closed. * @returns VBox status code. * @returns VERR_VD_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. /* Destroy any discard state because the image might be changed to readonly mode. */ * 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 * @returns VBox status code. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pszFilename=%#p cbFilename=%u\n",
* Get the comment line of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pszComment=%#p cbComment=%u\n",
* Changes the comment line of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pszComment=%#p \"%s\"\n",
* Get UUID of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. * Set the image's UUID. Should not be used by normal applications. * @returns VBox status code. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pUuid=%#p {%RTuuid}\n",
* Get last modification UUID of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. * Set the image's last modification UUID. Should not be used by normal applications. * @returns VBox status code. * @returns VERR_VD_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. LogFlowFunc((
"pDisk=%#p nImage=%u pUuid=%#p {%RTuuid}\n",
* Get parent UUID of image in HDD container. * @returns VBox status code. * @returns VERR_VD_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. * 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. LogFlowFunc((
"pDisk=%#p nImage=%u pUuid=%#p {%RTuuid}\n",
* Debug helper - dumps all opened images in HDD container into the log file. * @param pDisk Pointer to HDD container. (
"Discarding not supported\n"),
LogFlowFunc((
"pDisk=%#p uOffset=%llu pcSgBuf=%#p cbRead=%zu pvUser1=%#p pvUser2=%#p\n",
(
"uOffset=%llu cbRead=%zu pDisk->cbSize=%llu\n",
LogFlowFunc((
"pDisk=%#p uOffset=%llu cSgBuf=%#p cbWrite=%zu pvUser1=%#p pvUser2=%#p\n",
(
"uOffset=%llu cbWrite=%zu pDisk->cbSize=%llu\n",