VBoxHDD.h revision 617fbf5ba046109c0555dbafd6e9de76f76ba026
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @file
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VBox HDD Container API.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Copyright (C) 2006-2010 Oracle Corporation
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * available from http://www.virtualbox.org. This file is free software;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * General Public License (GPL) as published by the Free Software
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * The contents of this file may alternatively be used under the terms
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * of the Common Development and Distribution License Version 1.0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution, in which case the provisions of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * CDDL are applicable instead of those of the GPL.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * You may elect to license modified versions of this file under the
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * terms and conditions of either the GPL or the CDDL or both.
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync */
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#ifndef ___VBox_VD_h
b0db50948c349fa76655abf252f7946b515e8204vboxsync#define ___VBox_VD_h
2f0d866e126dd288169fed591c259c1c6b4016e5vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/assert.h>
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#include <iprt/string.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/mem.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <iprt/net.h>
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#include <iprt/sg.h>
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#include <VBox/cdefs.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/types.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/err.h>
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#include <VBox/pdmifs.h>
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsyncRT_C_DECLS_BEGIN
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#ifdef IN_RING0
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync# error "There are no VBox HDD Container APIs available in Ring-0 Host Context!"
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#endif
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/** @defgroup grp_vd VBox HDD Container
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Current VMDK image version. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VMDK_IMAGE_VERSION (0x0001)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Current VDI image major version. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VDI_IMAGE_VERSION_MAJOR (0x0001)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Current VDI image minor version. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VDI_IMAGE_VERSION_MINOR (0x0001)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Current VDI image version. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VDI_IMAGE_VERSION ((VDI_IMAGE_VERSION_MAJOR << 16) | VDI_IMAGE_VERSION_MINOR)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Get VDI major version from combined version. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VDI_GET_VERSION_MAJOR(uVer) ((uVer) >> 16)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Get VDI minor version from combined version. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VDI_GET_VERSION_MINOR(uVer) ((uVer) & 0xffff)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Placeholder for specifying the last opened image. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_LAST_IMAGE 0xffffffffU
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @name VBox HDD container image flags
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** No flags. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_IMAGE_FLAGS_NONE (0)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Fixed image. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_IMAGE_FLAGS_FIXED (0x10000)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Diff image. Mutually exclusive with fixed image. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_IMAGE_FLAGS_DIFF (0x20000)
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/** VMDK: Split image into 2GB extents. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync#define VD_VMDK_IMAGE_FLAGS_SPLIT_2G (0x0001)
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/** VMDK: Raw disk image (giving access to a number of host partitions). */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_VMDK_IMAGE_FLAGS_RAWDISK (0x0002)
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/** VMDK: stream optimized image, read only. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED (0x0004)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** VMDK: ESX variant, use in addition to other flags. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_VMDK_IMAGE_FLAGS_ESX (0x0008)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** VDI: Fill new blocks with zeroes while expanding image file. Only valid
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * for newly created images, never set for opened existing images. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_VDI_IMAGE_FLAGS_ZERO_EXPAND (0x0100)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Mask of valid image flags for VMDK. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_VMDK_IMAGE_FLAGS_MASK ( VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE \
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync | VD_VMDK_IMAGE_FLAGS_SPLIT_2G | VD_VMDK_IMAGE_FLAGS_RAWDISK \
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync | VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED | VD_VMDK_IMAGE_FLAGS_ESX)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Mask of valid image flags for VDI. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define VD_VDI_IMAGE_FLAGS_MASK (VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE | VD_VDI_IMAGE_FLAGS_ZERO_EXPAND)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync/** Mask of all valid image flags for all formats. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync#define VD_IMAGE_FLAGS_MASK (VD_VMDK_IMAGE_FLAGS_MASK | VD_VDI_IMAGE_FLAGS_MASK)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Default image flags. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_IMAGE_FLAGS_DEFAULT (VD_IMAGE_FLAGS_NONE)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @} */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync/**
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync * Auxiliary type for describing partitions on raw disks. The entries must be
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync * in ascending order (as far as uStart is concerned), and must not overlap.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Note that this does not correspond 1:1 to partitions, it is describing the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * general meaning of contiguous areas on the disk.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsynctypedef struct VBOXHDDRAWPARTDESC
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Device to use for this partition/data area. Can be the disk device if
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * the offset field is set appropriately. If this is NULL, then this
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * partition will not be accessible to the guest. The size of the data area
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * must still be set correctly. */
0381007ae929f1a0885e69644b7d586a1dbb3a2avboxsync const char *pszRawDevice;
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync /** Pointer to the partitioning info. NULL means this is a regular data
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync * area on disk, non-NULL denotes data which should be copied to the
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync * partition data overlay. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync const void *pvPartitionData;
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync /** Offset where the data starts in this device. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync uint64_t uStartOffset;
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync /** Offset where the data starts in the disk. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync uint64_t uStart;
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync /** Size of the data area. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync uint64_t cbData;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync} VBOXHDDRAWPARTDESC, *PVBOXHDDRAWPARTDESC;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Auxiliary data structure for creating raw disks.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsynctypedef struct VBOXHDDRAW
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Signature for structure. Must be 'R', 'A', 'W', '\\0'. Actually a trick
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * to make logging of the comment string produce sensible results. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync char szSignature[4];
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Flag whether access to full disk should be given (ignoring the
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * partition information below). */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool fRawDisk;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Filename for the raw disk. Ignored for partitioned raw disks.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * For Linux e.g. /dev/sda, and for Windows e.g. \\\\.\\PhysicalDisk0. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync const char *pszRawDisk;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Number of entries in the partition descriptor array. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync unsigned cPartDescs;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Pointer to the partition descriptor array. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync PVBOXHDDRAWPARTDESC pPartDescs;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync} VBOXHDDRAW, *PVBOXHDDRAW;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @name VBox HDD container image open mode flags
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Try to open image in read/write exclusive access mode if possible, or in read-only elsewhere. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_OPEN_FLAGS_NORMAL 0
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Open image in read-only mode with sharing access with others. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_OPEN_FLAGS_READONLY RT_BIT(0)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Honor zero block writes instead of ignoring them whenever possible.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This is not supported by all formats. It is silently ignored in this case. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_OPEN_FLAGS_HONOR_ZEROES RT_BIT(1)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Honor writes of the same data instead of ignoring whenever possible.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * This is handled generically, and is only meaningful for differential image
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * formats. It is silently ignored otherwise. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_OPEN_FLAGS_HONOR_SAME RT_BIT(2)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Do not perform the base/diff image check on open. This does NOT imply
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * opening the image as readonly (would break e.g. adding UUIDs to VMDK files
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * created by other products). Images opened with this flag should only be
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * used for querying information, and nothing else. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync#define VD_OPEN_FLAGS_INFO RT_BIT(3)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Open image for asynchronous access.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Only available if VD_CAP_ASYNC_IO is set
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Check with VDIsAsynchonousIoSupported wether
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * asynchronous I/O is really supported for this file. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_OPEN_FLAGS_ASYNC_IO RT_BIT(4)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Allow sharing of the image for writable images. May be ignored if the
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * format backend doesn't support this type of concurrent access. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_OPEN_FLAGS_SHAREABLE RT_BIT(5)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Mask of valid flags. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync#define VD_OPEN_FLAGS_MASK (VD_OPEN_FLAGS_NORMAL | VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_HONOR_ZEROES | VD_OPEN_FLAGS_HONOR_SAME | VD_OPEN_FLAGS_INFO | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** @}*/
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
93f91841f87620d1cb6d0238b3d0d5e52cd3b9a4vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** @name VBox HDD container backend capability flags
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Supports UUIDs as expected by VirtualBox code. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_CAP_UUID RT_BIT(0)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Supports creating fixed size images, allocating all space instantly. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_CAP_CREATE_FIXED RT_BIT(1)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Supports creating dynamically growing images, allocating space on demand. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_CAP_CREATE_DYNAMIC RT_BIT(2)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Supports creating images split in chunks of a bit less than 2GBytes. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_CAP_CREATE_SPLIT_2G RT_BIT(3)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** Supports being used as differencing image format backend. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_CAP_DIFF RT_BIT(4)
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync/** Supports asynchronous I/O operations for at least some configurations. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync#define VD_CAP_ASYNC RT_BIT(5)
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync/** The backend operates on files. The caller needs to know to handle the
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync * location appropriately. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_CAP_FILE RT_BIT(6)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** The backend uses the config interface. The caller needs to know how to
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * provide the mandatory configuration parts this way. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_CAP_CONFIG RT_BIT(7)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/** The backend uses the network stack interface. The caller has to provide
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * the appropriate interface. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync#define VD_CAP_TCPNET RT_BIT(8)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @}*/
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Supported interface types.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef enum VDINTERFACETYPE
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** First valid interface. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync VDINTERFACETYPE_FIRST = 0,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Interface to pass error message to upper layers. Per-disk. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync VDINTERFACETYPE_ERROR = VDINTERFACETYPE_FIRST,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Interface for asynchronous I/O operations. Per-disk. */
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync VDINTERFACETYPE_ASYNCIO,
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync /** Interface for progress notification. Per-operation. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync VDINTERFACETYPE_PROGRESS,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Interface for configuration information. Per-image. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync VDINTERFACETYPE_CONFIG,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Interface for TCP network stack. Per-disk. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync VDINTERFACETYPE_TCPNET,
ead016c68c61b5f2e1fe4d237054eebea9327d4bvboxsync /** Interface for getting parent image state. Per-operation. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync VDINTERFACETYPE_PARENTSTATE,
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync /** Interface for synchronizing accesses from several threads. Per-disk. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync VDINTERFACETYPE_THREADSYNC,
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync /** Interface for I/O between the generic VBoxHDD code and the backend. Per-image. */
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync VDINTERFACETYPE_IO,
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync /** invalid interface. */
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync VDINTERFACETYPE_INVALID
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync} VDINTERFACETYPE;
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync/**
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync * Common structure for all interfaces.
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync */
64f58e4154eaa20c47782b429eeaff09070369bfvboxsynctypedef struct VDINTERFACE
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync{
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync /** Human readable interface name. */
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync const char *pszInterfaceName;
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync /** The size of the struct. */
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync uint32_t cbSize;
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync /** Pointer to the next common interface structure. */
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync struct VDINTERFACE *pNext;
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync /** Interface type. */
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync VDINTERFACETYPE enmInterface;
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync /** Opaque user data which is passed on every call. */
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync void *pvUser;
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync /** Pointer to the function call table of the interface.
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync * As this is opaque this must be casted to the right interface
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync * struct defined below based on the interface type in enmInterface. */
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync void *pCallbacks;
64f58e4154eaa20c47782b429eeaff09070369bfvboxsync} VDINTERFACE;
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync/** Pointer to a VDINTERFACE. */
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsynctypedef VDINTERFACE *PVDINTERFACE;
7ccfefe49db4cd93c3701d7b60873ebf404b5b87vboxsync/** Pointer to a const VDINTERFACE. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef const VDINTERFACE *PCVDINTERFACE;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Helper functions to handle interface lists.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @note These interface lists are used consistently to pass per-disk,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * per-image and/or per-operation callbacks. Those three purposes are strictly
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * separate. See the individual interface declarations for what context they
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * apply to. The caller is responsible for ensuring that the lifetime of the
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * interface descriptors is appropriate for the category of interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * Get a specific interface from a list of interfaces specified by the type.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return Pointer to the matching interface or NULL if none was found.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param pVDIfs Pointer to the VD interface list.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param enmInterface Interface to search for.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(PVDINTERFACE) VDInterfaceGet(PVDINTERFACE pVDIfs, VDINTERFACETYPE enmInterface)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertMsgReturn( enmInterface >= VDINTERFACETYPE_FIRST
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync && enmInterface < VDINTERFACETYPE_INVALID,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ("enmInterface=%u", enmInterface), NULL);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync while (pVDIfs)
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync {
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync /* Sanity checks. */
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync AssertMsgBreak(pVDIfs->cbSize == sizeof(VDINTERFACE),
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync ("cbSize=%u\n", pVDIfs->cbSize));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (pVDIfs->enmInterface == enmInterface)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync return pVDIfs;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pVDIfs = pVDIfs->pNext;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /* No matching interface was found. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync return NULL;
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync}
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Add an interface to a list of interfaces.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pInterface Pointer to an unitialized common interface structure.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pszName Name of the interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param enmInterface Type of the interface.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pCallbacks The callback table of the interface.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pvUser Opaque user data passed on every function call.
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync * @param ppVDIfs Pointer to the VD interface list.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsyncDECLINLINE(int) VDInterfaceAdd(PVDINTERFACE pInterface, const char *pszName,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync VDINTERFACETYPE enmInterface, void *pCallbacks,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync void *pvUser, PVDINTERFACE *ppVDIfs)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync{
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /* Argument checks. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync AssertMsgReturn( enmInterface >= VDINTERFACETYPE_FIRST
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync && enmInterface < VDINTERFACETYPE_INVALID,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync ("enmInterface=%u", enmInterface), VERR_INVALID_PARAMETER);
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync AssertMsgReturn(VALID_PTR(pCallbacks),
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync ("pCallbacks=%#p", pCallbacks),
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync VERR_INVALID_PARAMETER);
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync AssertMsgReturn(VALID_PTR(ppVDIfs),
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync ("pInterfaceList=%#p", ppVDIfs),
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync VERR_INVALID_PARAMETER);
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync /* Fill out interface descriptor. */
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync pInterface->cbSize = sizeof(VDINTERFACE);
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync pInterface->pszInterfaceName = pszName;
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync pInterface->enmInterface = enmInterface;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pInterface->pCallbacks = pCallbacks;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pInterface->pvUser = pvUser;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pInterface->pNext = *ppVDIfs;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Remember the new start of the list. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync *ppVDIfs = pInterface;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync return VINF_SUCCESS;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync}
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync/**
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * Removes an interface from a list of interfaces.
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync *
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * @return VBox status code
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync * @param pInterface Pointer to an initialized common interface structure to remove.
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync * @param ppVDIfs Pointer to the VD interface list to remove from.
c2f2661efd8da5281e2a3af6ddd10e737d333909vboxsync */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsyncDECLINLINE(int) VDInterfaceRemove(PVDINTERFACE pInterface, PVDINTERFACE *ppVDIfs)
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync{
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync int rc = VERR_NOT_FOUND;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /* Argument checks. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync AssertMsgReturn(VALID_PTR(pInterface),
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync ("pInterface=%#p", pInterface),
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync VERR_INVALID_PARAMETER);
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync AssertMsgReturn(VALID_PTR(ppVDIfs),
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync ("pInterfaceList=%#p", ppVDIfs),
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync VERR_INVALID_PARAMETER);
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync
4569bf0ad094b40d2e177299a00d37e94d28616cvboxsync if (*ppVDIfs)
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync {
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync PVDINTERFACE pPrev = NULL;
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync PVDINTERFACE pCurr = *ppVDIfs;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync while ( pCurr
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync && (pCurr != pInterface))
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pPrev = pCurr;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync pCurr = pCurr->pNext;
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* First interface */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!pPrev)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *ppVDIfs = pCurr->pNext;
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync rc = VINF_SUCCESS;
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else if (pCurr)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pPrev = pCurr->pNext;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync rc = VINF_SUCCESS;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync }
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync }
96a7e06717e2d7398642eadb5ebab1bf13fbe2dbvboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync return rc;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync}
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Interface to deliver error messages (and also informational messages)
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * to upper layers.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync *
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Per disk interface. Optional, but think twice if you want to miss the
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * opportunity of reporting better human-readable error messages.
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync */
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsynctypedef struct VDINTERFACEERROR
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync{
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /**
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * Size of the error interface.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync uint32_t cbSize;
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync /**
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * Interface type.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync VDINTERFACETYPE enmInterface;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Error message callback. Must be able to accept special IPRT format
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * strings.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser The opaque data passed on container creation.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param rc The VBox error code.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param RT_SRC_POS_DECL Use RT_SRC_POS.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pszFormat Error message format string.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param va Error message arguments.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync DECLR3CALLBACKMEMBER(void, pfnError, (void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Informational message callback. May be NULL. Used e.g. in
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * VDDumpImages(). Must be able to accept special IPRT format strings.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser The opaque data passed on container creation.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pszFormat Error message format string.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param ... Error message arguments.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync DECLR3CALLBACKMEMBER(int, pfnMessage, (void *pvUser, const char *pszFormat, ...));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync} VDINTERFACEERROR, *PVDINTERFACEERROR;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Get error interface from opaque callback table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return Pointer to the callback table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pInterface Pointer to the interface descriptor.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(PVDINTERFACEERROR) VDGetInterfaceError(PVDINTERFACE pInterface)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PVDINTERFACEERROR pInterfaceError;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Check that the interface descriptor is a error interface. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync AssertMsgReturn( pInterface->enmInterface == VDINTERFACETYPE_ERROR
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync && pInterface->cbSize == sizeof(VDINTERFACE),
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync ("Not an error interface"), NULL);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync pInterfaceError = (PVDINTERFACEERROR)pInterface->pCallbacks;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /* Do basic checks. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync AssertMsgReturn( pInterfaceError->cbSize == sizeof(VDINTERFACEERROR)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync && pInterfaceError->enmInterface == VDINTERFACETYPE_ERROR,
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync ("A non error callback table attached to a error interface descriptor\n"), NULL);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
8a339f91959bb7a3315b51a23461b68c7b0cb50evboxsync return pInterfaceError;
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync}
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync/**
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Completion callback which is called by the interface owner
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * to inform the backend that a task finished.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync *
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @return VBox status code.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param pvUser Opaque user data which is passed on request submission.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param rcReq Status code of the completed request.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef DECLCALLBACK(int) FNVDCOMPLETED(void *pvUser, int rcReq);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Pointer to FNVDCOMPLETED() */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsynctypedef FNVDCOMPLETED *PFNVDCOMPLETED;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Open the storage readonly. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define VD_INTERFACEASYNCIO_OPEN_FLAGS_READONLY RT_BIT(0)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync/** Create the storage backend if it doesn't exist. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define VD_INTERFACEASYNCIO_OPEN_FLAGS_CREATE RT_BIT(1)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync/** Don't write lock the opened file. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define VD_INTERFACEASYNCIO_OPEN_FLAGS_DONT_LOCK RT_BIT(2)
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync/**
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Support interface for asynchronous I/O
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync *
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync * Per-disk. Optional.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsynctypedef struct VDINTERFACEASYNCIO
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync{
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /**
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Size of the async interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t cbSize;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Interface type.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
b0db50948c349fa76655abf252f7946b515e8204vboxsync VDINTERFACETYPE enmInterface;
b0db50948c349fa76655abf252f7946b515e8204vboxsync
b0db50948c349fa76655abf252f7946b515e8204vboxsync /**
b0db50948c349fa76655abf252f7946b515e8204vboxsync * Open callback
b0db50948c349fa76655abf252f7946b515e8204vboxsync *
b0db50948c349fa76655abf252f7946b515e8204vboxsync * @return VBox status code.
b0db50948c349fa76655abf252f7946b515e8204vboxsync * @param pvUser The opaque data passed on container creation.
b0db50948c349fa76655abf252f7946b515e8204vboxsync * @param pszLocation Name of the location to open.
b0db50948c349fa76655abf252f7946b515e8204vboxsync * @param uOpenFlags Flags for opening the backend.
b0db50948c349fa76655abf252f7946b515e8204vboxsync * See VD_INTERFACEASYNCIO_OPEN_FLAGS_* #defines
b0db50948c349fa76655abf252f7946b515e8204vboxsync * @param pfnCompleted The callback which is called whenever a task
b0db50948c349fa76655abf252f7946b515e8204vboxsync * completed. The backend has to pass the user data
b0db50948c349fa76655abf252f7946b515e8204vboxsync * of the request initiator (ie the one who calls
b0db50948c349fa76655abf252f7946b515e8204vboxsync * VDAsyncRead or VDAsyncWrite) in pvCompletion
b0db50948c349fa76655abf252f7946b515e8204vboxsync * if this is NULL.
b0db50948c349fa76655abf252f7946b515e8204vboxsync * @param pVDIfsDisk Pointer to the per-disk VD interface list.
b0db50948c349fa76655abf252f7946b515e8204vboxsync * @param ppStorage Where to store the opaque storage handle.
b0db50948c349fa76655abf252f7946b515e8204vboxsync */
b0db50948c349fa76655abf252f7946b515e8204vboxsync DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation,
b0db50948c349fa76655abf252f7946b515e8204vboxsync unsigned uOpenFlags,
b0db50948c349fa76655abf252f7946b515e8204vboxsync PFNVDCOMPLETED pfnCompleted,
b0db50948c349fa76655abf252f7946b515e8204vboxsync PVDINTERFACE pVDIfsDisk,
b0db50948c349fa76655abf252f7946b515e8204vboxsync void **ppStorage));
b0db50948c349fa76655abf252f7946b515e8204vboxsync
b0db50948c349fa76655abf252f7946b515e8204vboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Close callback.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser The opaque data passed on container creation.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pStorage The opaque storage handle to close.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, void *pStorage));
b0db50948c349fa76655abf252f7946b515e8204vboxsync
b0db50948c349fa76655abf252f7946b515e8204vboxsync /**
b0db50948c349fa76655abf252f7946b515e8204vboxsync * Returns the size of the opened storage backend.
b0db50948c349fa76655abf252f7946b515e8204vboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return VBox status code.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pvUser The opaque data passed on container creation.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pStorage The opaque storage handle to close.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pcbSize Where to store the size of the storage backend.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, void *pStorage, uint64_t *pcbSize));
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Sets the size of the opened storage backend if possible.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return VBox status code.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser The opaque data passed on container creation.
faee255cc48bfbf17cb9f72fca70c8b9d3020ec4vboxsync * @param pStorage The opaque storage handle to close.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param cbSize The new size of the image.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, void *pStorage, uint64_t cbSize));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Synchronous write callback.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @return VBox status code.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @param pvUser The opaque data passed on container creation.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @param pStorage The storage handle to use.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @param uOffset The offset to start from.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param cbWrite How many bytes to write.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvBuf Pointer to the bits need to be written.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @param pcbWritten Where to store how many bytes where actually written.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync */
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync DECLR3CALLBACKMEMBER(int, pfnWriteSync, (void *pvUser, void *pStorage, uint64_t uOffset,
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /**
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * Synchronous read callback.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * @param pvUser The opaque data passed on container creation.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * @param pStorage The storage handle to use.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * @param uOffset The offset to start from.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * @param cbRead How many bytes to read.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * @param pvBuf Where to store the read bits.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * @param pcbRead Where to store how many bytes where actually read.
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync */
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync DECLR3CALLBACKMEMBER(int, pfnReadSync, (void *pvUser, void *pStorage, uint64_t uOffset,
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync size_t cbRead, void *pvBuf, size_t *pcbRead));
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync /**
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * Flush data to the storage backend.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync *
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @return VBox statis code.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param pvUser The opaque data passed on container creation.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pStorage The storage handle to flush.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync DECLR3CALLBACKMEMBER(int, pfnFlushSync, (void *pvUser, void *pStorage));
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync /**
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * Initiate a asynchronous read request.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync *
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @return VBox status code.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param pvUser The opqaue user data passed on container creation.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param pStorage The storage handle.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param uOffset The offset to start reading from.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param paSegments Scatter gather list to store the data in.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param cSegments Number of segments in the list.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param cbRead How many bytes to read.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param pvCompletion The opaque user data which is returned upon completion.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param ppTask Where to store the opaque task handle.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync DECLR3CALLBACKMEMBER(int, pfnReadAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync PCRTSGSEG paSegments, size_t cSegments,
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync size_t cbRead, void *pvCompletion,
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync void **ppTask));
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync /**
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * Initiate a asynchronous write request.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync *
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @return VBox status code.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param pvUser The opaque user data passed on conatiner creation.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param pStorage The storage handle.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param uOffset The offset to start writing to.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param paSegments Scatter gather list of the data to write
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param cSegments Number of segments in the list.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param cbWrite How many bytes to write.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param pvCompletion The opaque user data which is returned upon completion.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param ppTask Where to store the opaque task handle.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync */
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync DECLR3CALLBACKMEMBER(int, pfnWriteAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync PCRTSGSEG paSegments, size_t cSegments,
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync size_t cbWrite, void *pvCompletion,
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync void **ppTask));
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /**
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Initiates a async flush request.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync *
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @return VBox statis code.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param pvUser The opaque data passed on container creation.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pStorage The storage handle to flush.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pvCompletion The opaque user data which is returned upon completion.
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync * @param ppTask Where to store the opaque task handle.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync DECLR3CALLBACKMEMBER(int, pfnFlushAsync, (void *pvUser, void *pStorage,
0c4004948fca34f2db87e7b38013137e9472c306vboxsync void *pvCompletion, void **ppTask));
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync} VDINTERFACEASYNCIO, *PVDINTERFACEASYNCIO;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync/**
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * Get async I/O interface from opaque callback table.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync *
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @return Pointer to the callback table.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * @param pInterface Pointer to the interface descriptor.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync */
71f6a34b72f9cc873da208630959de49df1a28a5vboxsyncDECLINLINE(PVDINTERFACEASYNCIO) VDGetInterfaceAsyncIO(PVDINTERFACE pInterface)
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync{
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync PVDINTERFACEASYNCIO pInterfaceAsyncIO;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync /* Check that the interface descriptor is a async I/O interface. */
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_ASYNCIO)
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync && (pInterface->cbSize == sizeof(VDINTERFACE)),
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync ("Not an async I/O interface"), NULL);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync pInterfaceAsyncIO = (PVDINTERFACEASYNCIO)pInterface->pCallbacks;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync /* Do basic checks. */
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync AssertMsgReturn( (pInterfaceAsyncIO->cbSize == sizeof(VDINTERFACEASYNCIO))
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync && (pInterfaceAsyncIO->enmInterface == VDINTERFACETYPE_ASYNCIO),
0c4004948fca34f2db87e7b38013137e9472c306vboxsync ("A non async I/O callback table attached to a async I/O interface descriptor\n"), NULL);
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync return pInterfaceAsyncIO;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync}
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync/**
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * Callback which provides progress information about a currently running
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * lengthy operation.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync *
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @return VBox status code.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param pvUser The opaque user data associated with this interface.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * @param uPercent Completion percentage.
0c4004948fca34f2db87e7b38013137e9472c306vboxsync */
0c4004948fca34f2db87e7b38013137e9472c306vboxsynctypedef DECLCALLBACK(int) FNVDPROGRESS(void *pvUser, unsigned uPercentage);
0c4004948fca34f2db87e7b38013137e9472c306vboxsync/** Pointer to FNVDPROGRESS() */
0c4004948fca34f2db87e7b38013137e9472c306vboxsynctypedef FNVDPROGRESS *PFNVDPROGRESS;
0c4004948fca34f2db87e7b38013137e9472c306vboxsync
0c4004948fca34f2db87e7b38013137e9472c306vboxsync/**
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * Progress notification interface
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync *
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Per-operation. Optional.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync */
71f6a34b72f9cc873da208630959de49df1a28a5vboxsynctypedef struct VDINTERFACEPROGRESS
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync{
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync /**
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * Size of the progress interface.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync */
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync uint32_t cbSize;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync /**
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync * Interface type.
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync */
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync VDINTERFACETYPE enmInterface;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync /**
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * Progress notification callbacks.
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync */
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync PFNVDPROGRESS pfnProgress;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync} VDINTERFACEPROGRESS, *PVDINTERFACEPROGRESS;
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync/**
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Get progress interface from opaque callback table.
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync *
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * @return Pointer to the callback table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pInterface Pointer to the interface descriptor.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(PVDINTERFACEPROGRESS) VDGetInterfaceProgress(PVDINTERFACE pInterface)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PVDINTERFACEPROGRESS pInterfaceProgress;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Check that the interface descriptor is a progress interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PROGRESS)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && (pInterface->cbSize == sizeof(VDINTERFACE)),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ("Not a progress interface"), NULL);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pInterfaceProgress = (PVDINTERFACEPROGRESS)pInterface->pCallbacks;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Do basic checks. */
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync AssertMsgReturn( (pInterfaceProgress->cbSize == sizeof(VDINTERFACEPROGRESS))
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync && (pInterfaceProgress->enmInterface == VDINTERFACETYPE_PROGRESS),
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsync ("A non progress callback table attached to a progress interface descriptor\n"), NULL);
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return pInterfaceProgress;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync/**
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync * Configuration information interface
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync *
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync * Per-image. Optional for most backends, but mandatory for images which do
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync * not operate on files (including standard block or character devices).
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync */
26947320577c481b4afefdb0afbb855181e5b2e8vboxsynctypedef struct VDINTERFACECONFIG
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync{
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Size of the configuration interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint32_t cbSize;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /**
cba6719bd64ec749967bbe931230452664109857vboxsync * Interface type.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync VDINTERFACETYPE enmInterface;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Validates that the keys are within a set of valid names.
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync *
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync * @return true if all key names are found in pszzAllowed.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return false if not.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser The opaque user data associated with this interface.
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync * @param pszzValid List of valid key names separated by '\\0' and ending with
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * a double '\\0'.
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync */
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid));
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync
a8139954a84d6e9090dd3a8371aa788351d45bc3vboxsync /**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Retrieves the length of the string value associated with a key (including
cab115cfa31c584def7069312a1e23c3fc88533bvboxsync * the terminator, for compatibility with CFGMR3QuerySize).
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return VBox status code.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * @param pvUser The opaque user data associated with this interface.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * @param pszName Name of the key to query.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * @param pcbValue Where to store the value length. Non-NULL.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync */
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync /**
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * Query the string value associated with a key.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync *
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * @return VBox status code.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * @param pvUser The opaque user data associated with this interface.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * @param pszName Name of the key to query.
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync * @param pszValue Pointer to buffer where to store value.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param cchValue Length of value buffer.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
4c42ef40805493bd6d76103b90f71bcd6dbc0f00vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Get configuration information interface from opaque callback table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync * @return Pointer to the callback table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pInterface Pointer to the interface descriptor.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(PVDINTERFACECONFIG) VDGetInterfaceConfig(PVDINTERFACE pInterface)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync PVDINTERFACECONFIG pInterfaceConfig;
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Check that the interface descriptor is a config interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_CONFIG)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync && (pInterface->cbSize == sizeof(VDINTERFACE)),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ("Not a config interface"), NULL);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pInterfaceConfig = (PVDINTERFACECONFIG)pInterface->pCallbacks;
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /* Do basic checks. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync AssertMsgReturn( (pInterfaceConfig->cbSize == sizeof(VDINTERFACECONFIG))
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync && (pInterfaceConfig->enmInterface == VDINTERFACETYPE_CONFIG),
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync ("A non config callback table attached to a config interface descriptor\n"), NULL);
cba6719bd64ec749967bbe931230452664109857vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return pInterfaceConfig;
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync}
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync/**
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Query configuration, validates that the keys are within a set of valid names.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return true if all key names are found in pszzAllowed.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @return false if not.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pCfgIf Pointer to configuration callback table.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pvUser The opaque user data associated with this interface.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @param pszzValid List of valid names separated by '\\0' and ending with
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * a double '\\0'.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncDECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, void *pvUser,
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync const char *pszzValid)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return pCfgIf->pfnAreKeysValid(pvUser, pszzValid);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync/**
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsync * Query configuration, unsigned 64-bit integer value with default.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
c91345f92b829d3fba05ce7a97206d83c5183ce0vboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pCfgIf Pointer to configuration callback table.
c91345f92b829d3fba05ce7a97206d83c5183ce0vboxsync * @param pvUser The opaque user data associated with this interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pszName Name of an integer value
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync * @param pu64 Where to store the value. Set to default on failure.
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync * @param u64Def The default value.
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync */
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsyncDECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync const char *pszName, uint64_t *pu64,
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync uint64_t u64Def)
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync{
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync char aszBuf[32];
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync int rc = pCfgIf->pfnQuery(pvUser, pszName, aszBuf, sizeof(aszBuf));
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync if (RT_SUCCESS(rc))
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync {
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync rc = RTStrToUInt64Full(aszBuf, 0, pu64);
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync }
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
b0db50948c349fa76655abf252f7946b515e8204vboxsync {
b0db50948c349fa76655abf252f7946b515e8204vboxsync rc = VINF_SUCCESS;
71f6a34b72f9cc873da208630959de49df1a28a5vboxsync *pu64 = u64Def;
b0db50948c349fa76655abf252f7946b515e8204vboxsync }
b0db50948c349fa76655abf252f7946b515e8204vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Query configuration, unsigned 32-bit integer value with default.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pCfgIf Pointer to configuration callback table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser The opaque user data associated with this interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pszName Name of an integer value
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pu32 Where to store the value. Set to default on failure.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param u32Def The default value.
5b465a7c1237993faf8bb50120d247f3f0319adavboxsync */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncDECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync const char *pszName, uint32_t *pu32,
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync uint32_t u32Def)
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync{
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync uint64_t u64;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, u32Def);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (RT_SUCCESS(rc))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync {
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (!(u64 & UINT64_C(0xffffffff00000000)))
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *pu32 = (uint32_t)u64;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync else
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = VERR_CFGM_INTEGER_TOO_BIG;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync }
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/**
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Query configuration, bool value with default.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync *
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync * @return VBox status code.
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync * @param pCfgIf Pointer to configuration callback table.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pvUser The opaque user data associated with this interface.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pszName Name of an integer value
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pf Where to store the value. Set to default on failure.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param fDef The default value.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsyncDECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, void *pvUser,
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync const char *pszName, bool *pf,
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync bool fDef)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync{
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint64_t u64;
cba6719bd64ec749967bbe931230452664109857vboxsync int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, fDef);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (RT_SUCCESS(rc))
cba6719bd64ec749967bbe931230452664109857vboxsync *pf = u64 ? true : false;
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync return rc;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync}
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync
cba6719bd64ec749967bbe931230452664109857vboxsync/**
cba6719bd64ec749967bbe931230452664109857vboxsync * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
cba6719bd64ec749967bbe931230452664109857vboxsync * character value.
cba6719bd64ec749967bbe931230452664109857vboxsync *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @return VBox status code.
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync * @param pCfgIf Pointer to configuration callback table.
* @param pvUser The opaque user data associated with this interface.
* @param pszName Name of an zero terminated character value
* @param ppszString Where to store the string pointer. Not set on failure.
* Free this using RTMemFree().
*/
DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
void *pvUser, const char *pszName,
char **ppszString)
{
size_t cb;
int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
if (RT_SUCCESS(rc))
{
char *pszString = (char *)RTMemAlloc(cb);
if (pszString)
{
rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cb);
if (RT_SUCCESS(rc))
*ppszString = pszString;
else
RTMemFree(pszString);
}
else
rc = VERR_NO_MEMORY;
}
return rc;
}
/**
* Query configuration, dynamically allocated (RTMemAlloc) zero terminated
* character value with default.
*
* @return VBox status code.
* @param pCfgIf Pointer to configuration callback table.
* @param pvUser The opaque user data associated with this interface.
* @param pszName Name of an zero terminated character value
* @param ppszString Where to store the string pointer. Not set on failure.
* Free this using RTMemFree().
* @param pszDef The default value.
*/
DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
void *pvUser, const char *pszName,
char **ppszString,
const char *pszDef)
{
size_t cb;
int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
{
cb = strlen(pszDef) + 1;
rc = VINF_SUCCESS;
}
if (RT_SUCCESS(rc))
{
char *pszString = (char *)RTMemAlloc(cb);
if (pszString)
{
rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cb);
if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
{
memcpy(pszString, pszDef, cb);
rc = VINF_SUCCESS;
}
if (RT_SUCCESS(rc))
*ppszString = pszString;
else
RTMemFree(pszString);
}
else
rc = VERR_NO_MEMORY;
}
return rc;
}
/**
* Query configuration, dynamically allocated (RTMemAlloc) byte string value.
*
* @return VBox status code.
* @param pCfgIf Pointer to configuration callback table.
* @param pvUser The opaque user data associated with this interface.
* @param pszName Name of an zero terminated character value
* @param ppvData Where to store the byte string pointer. Not set on failure.
* Free this using RTMemFree().
* @param pcbData Where to store the byte string length.
*/
DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
void *pvUser, const char *pszName,
void **ppvData, size_t *pcbData)
{
size_t cb;
int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
if (RT_SUCCESS(rc))
{
char *pbData;
Assert(cb);
pbData = (char *)RTMemAlloc(cb);
if (pbData)
{
rc = pCfgIf->pfnQuery(pvUser, pszName, pbData, cb);
if (RT_SUCCESS(rc))
{
*ppvData = pbData;
*pcbData = cb - 1; /* Exclude terminator of the queried string. */
}
else
RTMemFree(pbData);
}
else
rc = VERR_NO_MEMORY;
}
return rc;
}
/** Forward declaration of a VD socket. */
typedef struct VDSOCKETINT *VDSOCKET;
/** Pointer to a VD socket. */
typedef VDSOCKET *PVDSOCKET;
/** Nil socket handle. */
#define NIL_VDSOCKET ((VDSOCKET)0)
/** Connect flag to indicate that the backend wants to use the extended
* socket I/O multiplexing call. This might not be supported on all configurations
* (internal networking and iSCSI)
* and the backend needs to take appropriate action.
*/
#define VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT RT_BIT_32(0)
/** @name Select events
* @{ */
/** Readable without blocking. */
#define VD_INTERFACETCPNET_EVT_READ RT_BIT_32(0)
/** Writable without blocking. */
#define VD_INTERFACETCPNET_EVT_WRITE RT_BIT_32(1)
/** Error condition, hangup, exception or similar. */
#define VD_INTERFACETCPNET_EVT_ERROR RT_BIT_32(2)
/** Hint for the select that getting interrupted while waiting is more likely.
* The interface implementation can optimize the waiting strategy based on this.
* It is assumed that it is more likely to get one of the above socket events
* instead of being interrupted if the flag is not set. */
#define VD_INTERFACETCPNET_HINT_INTERRUPT RT_BIT_32(3)
/** Mask of the valid bits. */
#define VD_INTERFACETCPNET_EVT_VALID_MASK UINT32_C(0x0000000f)
/** @} */
/**
* TCP network stack interface
*
* Per-disk. Mandatory for backends which have the VD_CAP_TCPNET bit set.
*/
typedef struct VDINTERFACETCPNET
{
/**
* Size of the configuration interface.
*/
uint32_t cbSize;
/**
* Interface type.
*/
VDINTERFACETYPE enmInterface;
/**
* Creates a socket. The socket is not connected if this succeeds.
*
* @return iprt status code.
* @retval VERR_NOT_SUPPORTED if the combination of flags is not supported.
* @param fFlags Combination of the VD_INTERFACETCPNET_CONNECT_* #defines.
* @param pSock Where to store the handle.
*/
DECLR3CALLBACKMEMBER(int, pfnSocketCreate, (uint32_t fFlags, PVDSOCKET pSock));
/**
* Destroys the socket.
*
* @return iprt status code.
* @param Sock Socket descriptor.
*/
DECLR3CALLBACKMEMBER(int, pfnSocketDestroy, (VDSOCKET Sock));
/**
* Connect as a client to a TCP port.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pszAddress The address to connect to.
* @param uPort The port to connect to.
*/
DECLR3CALLBACKMEMBER(int, pfnClientConnect, (VDSOCKET Sock, const char *pszAddress, uint32_t uPort));
/**
* Close a TCP connection.
*
* @return iprt status code.
* @param Sock Socket descriptor.
*/
DECLR3CALLBACKMEMBER(int, pfnClientClose, (VDSOCKET Sock));
/**
* Returns whether the socket is currently connected to the client.
*
* @returns true if the socket is connected.
* false otherwise.
* @param Sock Socket descriptor.
*/
DECLR3CALLBACKMEMBER(bool, pfnIsClientConnected, (VDSOCKET Sock));
/**
* Socket I/O multiplexing.
* Checks if the socket is ready for reading.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param cMillies Number of milliseconds to wait for the socket.
* Use RT_INDEFINITE_WAIT to wait for ever.
*/
DECLR3CALLBACKMEMBER(int, pfnSelectOne, (VDSOCKET Sock, RTMSINTERVAL cMillies));
/**
* Receive data from a socket.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pvBuffer Where to put the data we read.
* @param cbBuffer Read buffer size.
* @param pcbRead Number of bytes read.
* If NULL the entire buffer will be filled upon successful return.
* If not NULL a partial read can be done successfully.
*/
DECLR3CALLBACKMEMBER(int, pfnRead, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
/**
* Send data to a socket.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pvBuffer Buffer to write data to socket.
* @param cbBuffer How much to write.
*/
DECLR3CALLBACKMEMBER(int, pfnWrite, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
/**
* Send data from scatter/gather buffer to a socket.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pSgBuf Scatter/gather buffer to write data to socket.
*/
DECLR3CALLBACKMEMBER(int, pfnSgWrite, (VDSOCKET Sock, PCRTSGBUF pSgBuf));
/**
* Receive data from a socket - not blocking.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pvBuffer Where to put the data we read.
* @param cbBuffer Read buffer size.
* @param pcbRead Number of bytes read.
*/
DECLR3CALLBACKMEMBER(int, pfnReadNB, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
/**
* Send data to a socket - not blocking.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pvBuffer Buffer to write data to socket.
* @param cbBuffer How much to write.
* @param pcbWritten Number of bytes written.
*/
DECLR3CALLBACKMEMBER(int, pfnWriteNB, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten));
/**
* Send data from scatter/gather buffer to a socket - not blocking.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pSgBuf Scatter/gather buffer to write data to socket.
* @param pcbWritten Number of bytes written.
*/
DECLR3CALLBACKMEMBER(int, pfnSgWriteNB, (VDSOCKET Sock, PRTSGBUF pSgBuf, size_t *pcbWritten));
/**
* Flush socket write buffers.
*
* @return iprt status code.
* @param Sock Socket descriptor.
*/
DECLR3CALLBACKMEMBER(int, pfnFlush, (VDSOCKET Sock));
/**
* Enables or disables delaying sends to coalesce packets.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param fEnable When set to true enables coalescing.
*/
DECLR3CALLBACKMEMBER(int, pfnSetSendCoalescing, (VDSOCKET Sock, bool fEnable));
/**
* Gets the address of the local side.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pAddr Where to store the local address on success.
*/
DECLR3CALLBACKMEMBER(int, pfnGetLocalAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
/**
* Gets the address of the other party.
*
* @return iprt status code.
* @param Sock Socket descriptor.
* @param pAddr Where to store the peer address on success.
*/
DECLR3CALLBACKMEMBER(int, pfnGetPeerAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
/**
* Socket I/O multiplexing - extended version which can be woken up.
* Checks if the socket is ready for reading or writing.
*
* @return iprt status code.
* @retval VERR_INTERRUPTED if the thread was woken up by a pfnPoke call.
* @param Sock Socket descriptor.
* @param fEvents Mask of events to wait for.
* @param pfEvents Where to store the received events.
* @param cMillies Number of milliseconds to wait for the socket.
* Use RT_INDEFINITE_WAIT to wait for ever.
*/
DECLR3CALLBACKMEMBER(int, pfnSelectOneEx, (VDSOCKET Sock, uint32_t fEvents,
uint32_t *pfEvents, RTMSINTERVAL cMillies));
/**
* Wakes up the thread waiting in pfnSelectOneEx.
*
* @return iprt status code.
* @param Sock Socket descriptor.
*/
DECLR3CALLBACKMEMBER(int, pfnPoke, (VDSOCKET Sock));
} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
/**
* Get TCP network stack interface from opaque callback table.
*
* @return Pointer to the callback table.
* @param pInterface Pointer to the interface descriptor.
*/
DECLINLINE(PVDINTERFACETCPNET) VDGetInterfaceTcpNet(PVDINTERFACE pInterface)
{
PVDINTERFACETCPNET pInterfaceTcpNet;
/* Check that the interface descriptor is a TCP network stack interface. */
AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_TCPNET)
&& (pInterface->cbSize == sizeof(VDINTERFACE)),
("Not a TCP network stack interface"), NULL);
pInterfaceTcpNet = (PVDINTERFACETCPNET)pInterface->pCallbacks;
/* Do basic checks. */
AssertMsgReturn( (pInterfaceTcpNet->cbSize == sizeof(VDINTERFACETCPNET))
&& (pInterfaceTcpNet->enmInterface == VDINTERFACETYPE_TCPNET),
("A non TCP network stack callback table attached to a TCP network stack interface descriptor\n"), NULL);
return pInterfaceTcpNet;
}
/**
* Interface to get the parent state.
*
* Per operation interface. Optional, present only if there is a parent, and
* used only internally for compacting.
*/
typedef struct VDINTERFACEPARENTSTATE
{
/**
* Size of the parent state interface.
*/
uint32_t cbSize;
/**
* Interface type.
*/
VDINTERFACETYPE enmInterface;
/**
* Read data callback.
*
* @return VBox status code.
* @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
* @param pvUser The opaque data passed for the operation.
* @param uOffset Offset of first reading byte from start of disk.
* Must be aligned to a sector boundary.
* @param pvBuf Pointer to buffer for reading data.
* @param cbRead Number of bytes to read.
* Must be aligned to a sector boundary.
*/
DECLR3CALLBACKMEMBER(int, pfnParentRead, (void *pvUser, uint64_t uOffset, void *pvBuf, size_t cbRead));
} VDINTERFACEPARENTSTATE, *PVDINTERFACEPARENTSTATE;
/**
* Get parent state interface from opaque callback table.
*
* @return Pointer to the callback table.
* @param pInterface Pointer to the interface descriptor.
*/
DECLINLINE(PVDINTERFACEPARENTSTATE) VDGetInterfaceParentState(PVDINTERFACE pInterface)
{
PVDINTERFACEPARENTSTATE pInterfaceParentState;
/* Check that the interface descriptor is a parent state interface. */
AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PARENTSTATE)
&& (pInterface->cbSize == sizeof(VDINTERFACE)),
("Not a parent state interface"), NULL);
pInterfaceParentState = (PVDINTERFACEPARENTSTATE)pInterface->pCallbacks;
/* Do basic checks. */
AssertMsgReturn( (pInterfaceParentState->cbSize == sizeof(VDINTERFACEPARENTSTATE))
&& (pInterfaceParentState->enmInterface == VDINTERFACETYPE_PARENTSTATE),
("A non parent state callback table attached to a parent state interface descriptor\n"), NULL);
return pInterfaceParentState;
}
/**
* Interface to synchronize concurrent accesses by several threads.
*
* @note The scope of this interface is to manage concurrent accesses after
* the HDD container has been created, and they must stop before destroying the
* container. Opening or closing images is covered by the synchronization, but
* that does not mean it is safe to close images while a thread executes
* <link to="VDMerge"/> or <link to="VDCopy"/> operating on these images.
* Making them safe would require the lock to be held during the entire
* operation, which prevents other concurrent acitivities.
*
* @note Right now this is kept as simple as possible, and does not even
* attempt to provide enough information to allow e.g. concurrent write
* accesses to different areas of the disk. The reason is that it is very
* difficult to predict which area of a disk is affected by a write,
* especially when different image formats are mixed. Maybe later a more
* sophisticated interface will be provided which has the necessary information
* about worst case affected areas.
*
* Per disk interface. Optional, needed if the disk is accessed concurrently
* by several threads, e.g. when merging diff images while a VM is running.
*/
typedef struct VDINTERFACETHREADSYNC
{
/**
* Size of the thread synchronization interface.
*/
uint32_t cbSize;
/**
* Interface type.
*/
VDINTERFACETYPE enmInterface;
/**
* Start a read operation.
*/
DECLR3CALLBACKMEMBER(int, pfnStartRead, (void *pvUser));
/**
* Finish a read operation.
*/
DECLR3CALLBACKMEMBER(int, pfnFinishRead, (void *pvUser));
/**
* Start a write operation.
*/
DECLR3CALLBACKMEMBER(int, pfnStartWrite, (void *pvUser));
/**
* Finish a write operation.
*/
DECLR3CALLBACKMEMBER(int, pfnFinishWrite, (void *pvUser));
} VDINTERFACETHREADSYNC, *PVDINTERFACETHREADSYNC;
/**
* Get thread synchronization interface from opaque callback table.
*
* @return Pointer to the callback table.
* @param pInterface Pointer to the interface descriptor.
*/
DECLINLINE(PVDINTERFACETHREADSYNC) VDGetInterfaceThreadSync(PVDINTERFACE pInterface)
{
PVDINTERFACETHREADSYNC pInterfaceThreadSync;
/* Check that the interface descriptor is a thread synchronization interface. */
AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_THREADSYNC)
&& (pInterface->cbSize == sizeof(VDINTERFACE)),
("Not a thread synchronization interface"), NULL);
pInterfaceThreadSync = (PVDINTERFACETHREADSYNC)pInterface->pCallbacks;
/* Do basic checks. */
AssertMsgReturn( (pInterfaceThreadSync->cbSize == sizeof(VDINTERFACETHREADSYNC))
&& (pInterfaceThreadSync->enmInterface == VDINTERFACETYPE_THREADSYNC),
("A non thread synchronization callback table attached to a thread synchronization interface descriptor\n"), NULL);
return pInterfaceThreadSync;
}
/** @name Configuration interface key handling flags.
* @{
*/
/** Mandatory config key. Not providing a value for this key will cause
* the backend to fail. */
#define VD_CFGKEY_MANDATORY RT_BIT(0)
/** Expert config key. Not showing it by default in the GUI is is probably
* a good idea, as the average user won't understand it easily. */
#define VD_CFGKEY_EXPERT RT_BIT(1)
/** @}*/
/**
* Configuration value type for configuration information interface.
*/
typedef enum VDCFGVALUETYPE
{
/** Integer value. */
VDCFGVALUETYPE_INTEGER = 1,
/** String value. */
VDCFGVALUETYPE_STRING,
/** Bytestring value. */
VDCFGVALUETYPE_BYTES
} VDCFGVALUETYPE;
/**
* Structure describing configuration keys required/supported by a backend
* through the config interface.
*/
typedef struct VDCONFIGINFO
{
/** Key name of the configuration. */
const char *pszKey;
/** Pointer to default value (descriptor). NULL if no useful default value
* can be specified. */
const char *pszDefaultValue;
/** Value type for this key. */
VDCFGVALUETYPE enmValueType;
/** Key handling flags (a combination of VD_CFGKEY_* flags). */
uint64_t uKeyFlags;
} VDCONFIGINFO;
/** Pointer to structure describing configuration keys. */
typedef VDCONFIGINFO *PVDCONFIGINFO;
/** Pointer to const structure describing configuration keys. */
typedef const VDCONFIGINFO *PCVDCONFIGINFO;
/**
* Data structure for returning a list of backend capabilities.
*/
typedef struct VDBACKENDINFO
{
/** Name of the backend. Must be unique even with case insensitive comparison. */
const char *pszBackend;
/** Capabilities of the backend (a combination of the VD_CAP_* flags). */
uint64_t uBackendCaps;
/** Pointer to a NULL-terminated array of strings, containing the supported
* file extensions. Note that some backends do not work on files, so this
* pointer may just contain NULL. */
const char * const *papszFileExtensions;
/** Pointer to an array of structs describing each supported config key.
* Terminated by a NULL config key. Note that some backends do not support
* the configuration interface, so this pointer may just contain NULL.
* Mandatory if the backend sets VD_CAP_CONFIG. */
PCVDCONFIGINFO paConfigInfo;
/** Returns a human readable hard disk location string given a
* set of hard disk configuration keys. The returned string is an
* equivalent of the full file path for image-based hard disks.
* Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
/** Returns a human readable hard disk name string given a
* set of hard disk configuration keys. The returned string is an
* equivalent of the file name part in the full file path for
* image-based hard disks. Mandatory for backends with no
* VD_CAP_FILE and NULL otherwise. */
DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
} VDBACKENDINFO, *PVDBACKENDINFO;
/** Forward declaration. Only visible in the VBoxHDD module. */
/** I/O context */
typedef struct VDIOCTX *PVDIOCTX;
/** Storage backend handle. */
typedef struct VDIOSTORAGE *PVDIOSTORAGE;
/** Pointer to a storage backend handle. */
typedef PVDIOSTORAGE *PPVDIOSTORAGE;
/**
* Completion callback for meta/userdata reads or writes.
*
* @return VBox status code.
* VINF_SUCCESS if everything was successful and the transfer can continue.
* VERR_VD_ASYNC_IO_IN_PROGRESS if there is another data transfer pending.
* @param pvBackendData The opaque backend data.
* @param pIoCtx I/O context associated with this request.
* @param pvUser Opaque user data passed during a read/write request.
* @param rcReq Status code for the completed request.
*/
typedef DECLCALLBACK(int) FNVDXFERCOMPLETED(void *pvBackendData, PVDIOCTX pIoCtx, void *pvUser, int rcReq);
/** Pointer to FNVDXFERCOMPLETED() */
typedef FNVDXFERCOMPLETED *PFNVDXFERCOMPLETED;
/** Metadata transfer handle. */
typedef struct VDMETAXFER *PVDMETAXFER;
/** Pointer to a metadata transfer handle. */
typedef PVDMETAXFER *PPVDMETAXFER;
/**
* Support interface for I/O
*
* Per-image. Required.
*/
typedef struct VDINTERFACEIO
{
/**
* Size of the I/O interface.
*/
uint32_t cbSize;
/**
* Interface type.
*/
VDINTERFACETYPE enmInterface;
/**
* Open callback
*
* @return VBox status code.
* @param pvUser The opaque data passed on container creation.
* @param pszLocation Name of the location to open.
* @param uOpenFlags Flags for opening the backend.
* See VD_INTERFACEASYNCIO_OPEN_FLAGS_* #defines
* @param ppStorage Where to store the storage handle.
*/
DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation,
unsigned uOpenFlags, PPVDIOSTORAGE ppStorage));
/**
* Close callback.
*
* @return VBox status code.
* @param pvUser The opaque data passed on container creation.
* @param pStorage The storage handle to close.
*/
DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, PVDIOSTORAGE pStorage));
/**
* Returns the size of the opened storage backend.
*
* @return VBox status code.
* @param pvUser The opaque data passed on container creation.
* @param pStorage The storage handle to get the size from.
* @param pcbSize Where to store the size of the storage backend.
*/
DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, PVDIOSTORAGE pStorage,
uint64_t *pcbSize));
/**
* Sets the size of the opened storage backend if possible.
*
* @return VBox status code.
* @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
* @param pvUser The opaque data passed on container creation.
* @param pStorage The storage handle.
* @param cbSize The new size of the image.
*/
DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, PVDIOSTORAGE pStorage,
uint64_t cbSize));
/**
* Synchronous write callback.
*
* @return VBox status code.
* @param pvUser The opaque data passed on container creation.
* @param pStorage The storage handle to use.
* @param uOffset The offset to start from.
* @param cbWrite How many bytes to write.
* @param pvBuf Pointer to the bits need to be written.
* @param pcbWritten Where to store how many bytes where actually written.
*
* @notes Do not use in code called from the async read/write entry points in the backends.
* This should be only used during open/close of images and for the support functions
* which are not called while a VM is running (pfnCompact).
*/
DECLR3CALLBACKMEMBER(int, pfnWriteSync, (void *pvUser, PVDIOSTORAGE pStorage, uint64_t uOffset,
size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
/**
* Synchronous read callback.
*
* @return VBox status code.
* @param pvUser The opaque data passed on container creation.
* @param pStorage The storage handle to use.
* @param uOffset The offset to start from.
* @param cbRead How many bytes to read.
* @param pvBuf Where to store the read bits.
* @param pcbRead Where to store how many bytes where actually read.
*
* @notes See pfnWriteSync()
*/
DECLR3CALLBACKMEMBER(int, pfnReadSync, (void *pvUser, PVDIOSTORAGE pStorage, uint64_t uOffset,
size_t cbRead, void *pvBuf, size_t *pcbRead));
/**
* Flush data to the storage backend.
*
* @return VBox status code.
* @param pvUser The opaque data passed on container creation.
* @param pStorage The storage handle to flush.
*
* @notes See pfnWriteSync()
*/
DECLR3CALLBACKMEMBER(int, pfnFlushSync, (void *pvUser, PVDIOSTORAGE pStorage));
/**
* Initiate a asynchronous read request for user data.
*
* @return VBox status code.
* @param pvUser The opaque user data passed on container creation.
* @param pStorage The storage handle.
* @param uOffset The offset to start reading from.
* @param pIoCtx I/O context passed in VDAsyncRead/Write.
* @param cbRead How many bytes to read.
*/
DECLR3CALLBACKMEMBER(int, pfnReadUserAsync, (void *pvUser, PVDIOSTORAGE pStorage,
uint64_t uOffset, PVDIOCTX pIoCtx,
size_t cbRead));
/**
* Initiate a asynchronous write request for user data.
*
* @return VBox status code.
* @param pvUser The opaque user data passed on container creation.
* @param pStorage The storage handle.
* @param uOffset The offset to start writing to.
* @param pIoCtx I/O context passed in VDAsyncRead/Write
* @param cbWrite How many bytes to write.
* @param pfnCompleted Completion callback.
* @param pvCompleteUser Opaque user data passed in the completion callback.
*/
DECLR3CALLBACKMEMBER(int, pfnWriteUserAsync, (void *pvUser, PVDIOSTORAGE pStorage,
uint64_t uOffset, PVDIOCTX pIoCtx,
size_t cbWrite,
PFNVDXFERCOMPLETED pfnComplete,
void *pvCompleteUser));
/**
* Reads metadata asynchronously from storage.
* The current I/O context will be halted.
*
* @returns VBox status code.
* @param pvUser The opaque user data passed on container creation.
* @param pStorage The storage handle.
* @param uOffset Offset to start reading from.
* @param pvBuf Where to store the data.
* @param cbRead How many bytes to read.
* @param pIoCtx The I/O context which triggered the read.
* @param ppMetaXfer Where to store the metadata transfer handle on success.
* @param pfnCompleted Completion callback.
* @param pvCompleteUser Opaque user data passed in the completion callback.
*/
DECLR3CALLBACKMEMBER(int, pfnReadMetaAsync, (void *pvUser, PVDIOSTORAGE pStorage,
uint64_t uOffset, void *pvBuf,
size_t cbRead, PVDIOCTX pIoCtx,
PPVDMETAXFER ppMetaXfer,
PFNVDXFERCOMPLETED pfnComplete,
void *pvCompleteUser));
/**
* Writes metadata asynchronously to storage.
*
* @returns VBox status code.
* @param pvUser The opaque user data passed on container creation.
* @param pStorage The storage handle.
* @param uOffset Offset to start writing to.
* @param pvBuf Written data.
* @param cbWrite How many bytes to write.
* @param pIoCtx The I/O context which triggered the write.
* @param pfnCompleted Completion callback.
* @param pvCompleteUser Opaque user data passed in the completion callback.
*/
DECLR3CALLBACKMEMBER(int, pfnWriteMetaAsync, (void *pvUser, PVDIOSTORAGE pStorage,
uint64_t uOffset, void *pvBuf,
size_t cbWrite, PVDIOCTX pIoCtx,
PFNVDXFERCOMPLETED pfnComplete,
void *pvCompleteUser));
/**
* Releases a metadata transfer handle.
* The free space can be used for another transfer.
*
* @returns nothing.
* @param pvUser The opaque user data passed on container creation.
* @param pMetaXfer The metadata transfer handle to release.
*/
DECLR3CALLBACKMEMBER(void, pfnMetaXferRelease, (void *pvUser, PVDMETAXFER pMetaXfer));
/**
* Initiates a async flush request.
*
* @return VBox status code.
* @param pvUser The opaque data passed on container creation.
* @param pStorage The storage handle to flush.
* @param pIoCtx I/O context which triggered the flush.
* @param pfnCompleted Completion callback.
* @param pvCompleteUser Opaque user data passed in the completion callback.
*/
DECLR3CALLBACKMEMBER(int, pfnFlushAsync, (void *pvUser, PVDIOSTORAGE pStorage,
PVDIOCTX pIoCtx,
PFNVDXFERCOMPLETED pfnComplete,
void *pvCompleteUser));
/**
* Copies a buffer into the I/O context.
*
* @return Number of bytes copied.
* @param pvUser The opaque user data passed on container creation.
* @param pIoCtx I/O context to copy the data to.
* @param pvBuf Buffer to copy.
* @param cbBuf Number of bytes to copy.
*/
DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyTo, (void *pvUser, PVDIOCTX pIoCtx,
void *pvBuf, size_t cbBuf));
/**
* Copies data from the I/O context into a buffer.
*
* @return Number of bytes copied.
* @param pvUser The opaque user data passed on container creation.
* @param pIoCtx I/O context to copy the data from.
* @param pvBuf Destination buffer.
* @param cbBuf Number of bytes to copy.
*/
DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyFrom, (void *pvUser, PVDIOCTX pIoCtx,
void *pvBuf, size_t cbBuf));
/**
* Sets the buffer of the given context to a specific byte.
*
* @return Number of bytes set.
* @param pvUser The opaque user data passed on container creation.
* @param pIoCtx I/O context to copy the data from.
* @param ch The byte to set.
* @param cbSet Number of bytes to set.
*/
DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSet, (void *pvUser, PVDIOCTX pIoCtx,
int ch, size_t cbSet));
/**
* Creates a segment array from the I/O context data buffer.
*
* @returns Number of bytes the array describes.
* @param pvUser The opaque user data passed on container creation.
* @param pIoCtx I/O context to copy the data from.
* @param paSeg The uninitialized segment array.
* If NULL pcSeg will contain the number of segments needed
* to describe the requested amount of data.
* @param pcSeg The number of segments the given array has.
* This will hold the actual number of entries needed upon return.
* @param cbData Number of bytes the new array should describe.
*/
DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSegArrayCreate, (void *pvUser, PVDIOCTX pIoCtx,
PRTSGSEG paSeg, unsigned *pcSeg,
size_t cbData));
/**
* Marks the given number of bytes as completed and continues the I/O context.
*
* @returns nothing.
* @param pvUser The opaque user data passed on container creation.
* @param pIoCtx The I/O context.
* @param rcReq Status code the request completed with.
* @param cbCompleted Number of bytes completed.
*/
DECLR3CALLBACKMEMBER(void, pfnIoCtxCompleted, (void *pvUser, PVDIOCTX pIoCtx,
int rcReq, size_t cbCompleted));
} VDINTERFACEIO, *PVDINTERFACEIO;
/**
* Get async I/O interface from opaque callback table.
*
* @return Pointer to the callback table.
* @param pInterface Pointer to the interface descriptor.
*/
DECLINLINE(PVDINTERFACEIO) VDGetInterfaceIO(PVDINTERFACE pInterface)
{
PVDINTERFACEIO pInterfaceIO;
/* Check that the interface descriptor is a async I/O interface. */
AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_IO)
&& (pInterface->cbSize == sizeof(VDINTERFACE)),
("Not an I/O interface"), NULL);
pInterfaceIO = (PVDINTERFACEIO)pInterface->pCallbacks;
/* Do basic checks. */
AssertMsgReturn( (pInterfaceIO->cbSize == sizeof(VDINTERFACEIO))
&& (pInterfaceIO->enmInterface == VDINTERFACETYPE_IO),
("A non I/O callback table attached to a I/O interface descriptor\n"), NULL);
return pInterfaceIO;
}
/**
* VBox HDD Container main structure.
*/
/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
struct VBOXHDD;
typedef struct VBOXHDD VBOXHDD;
typedef VBOXHDD *PVBOXHDD;
/**
* Request completion callback for the async read/write API.
*/
typedef void (FNVDASYNCTRANSFERCOMPLETE) (void *pvUser1, void *pvUser2, int rcReq);
/** Pointer to a transfer compelte callback. */
typedef FNVDASYNCTRANSFERCOMPLETE *PFNVDASYNCTRANSFERCOMPLETE;
/**
* Initializes HDD backends.
*
* @returns VBox status code.
*/
VBOXDDU_DECL(int) VDInit(void);
/**
* Destroys loaded HDD backends.
*
* @returns VBox status code.
*/
VBOXDDU_DECL(int) VDShutdown(void);
/**
* Lists all HDD backends and their capabilities in a caller-provided buffer.
*
* @return 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.
*/
VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
unsigned *pcEntriesUsed);
/**
* Lists the capablities of a backend indentified by its name.
*
* @return VBox status code.
* @param pszBackend The backend name (case insensitive).
* @param pEntries Pointer to an entry.
*/
VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
/**
* Allocates and initializes an empty HDD container.
* No image files are opened.
*
* @return VBox status code.
* @param pVDIfsDisk Pointer to the per-disk VD interface list.
* @param ppDisk Where to store the reference to HDD container.
*/
VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, PVBOXHDD *ppDisk);
/**
* Destroys HDD container.
* If container has opened image files they will be closed.
*
* @param pDisk Pointer to HDD container.
*/
VBOXDDU_DECL(void) VDDestroy(PVBOXHDD pDisk);
/**
* Try to get the backend name which can use this image.
*
* @return VBox status code.
* @param pVDIfsDisk Pointer to the per-disk 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().
*/
VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, const char *pszFilename, char **ppszFormat);
/**
* Opens an image file.
*
* The first opened image file in HDD container must have a base image type,
* others (next opened images) must be differencing or undo images.
* Linkage is checked for differencing image to be consistent 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.
*
* @return VBox status code.
* @param pDisk Pointer to HDD container.
* @param pszBackend Name of the image file backend to use (case insensitive).
* @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.
*/
VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
const char *pszFilename, unsigned uOpenFlags,
PVDINTERFACE pVDIfsImage);
/**
* Opens a cache 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.
*/
VBOXDDU_DECL(int) VDCacheOpen(PVBOXHDD pDisk, const char *pszBackend,
const char *pszFilename, unsigned uOpenFlags,
PVDINTERFACE pVDIfsCache);
/**
* Creates and opens a new base image file.
*
* @return VBox status code.
* @param pDisk Pointer to HDD container.
* @param pszBackend Name of the image file backend to use (case insensitive).
* @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.
*/
VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
const char *pszFilename, uint64_t cbSize,
unsigned uImageFlags, const char *pszComment,
PCPDMMEDIAGEOMETRY pPCHSGeometry,
PCPDMMEDIAGEOMETRY pLCHSGeometry,
PCRTUUID pUuid, unsigned uOpenFlags,
PVDINTERFACE pVDIfsImage,
PVDINTERFACE pVDIfsOperation);
/**
* Creates and opens a new differencing image file in HDD container.
* See comments for VDOpen function about differencing images.
*
* @return VBox status code.
* @param pDisk Pointer to HDD container.
* @param pszBackend Name of the image file backend to use (case insensitive).
* @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.
*/
VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
const char *pszFilename, unsigned uImageFlags,
const char *pszComment, PCRTUUID pUuid,
PCRTUUID pParentUuid, unsigned uOpenFlags,
PVDINTERFACE pVDIfsImage,
PVDINTERFACE pVDIfsOperation);
/**
* 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.
*/
VBOXDDU_DECL(int) VDCreateCache(PVBOXHDD pDisk, const char *pszBackend,
const char *pszFilename, uint64_t cbSize,
unsigned uImageFlags, const char *pszComment,
PCRTUUID pUuid, unsigned uOpenFlags,
PVDINTERFACE pVDIfsCache, PVDINTERFACE pVDIfsOperation);
/**
* 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.
*
* @return VBox status code.
* @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
* @param pDisk Pointer to HDD container.
* @param nImageFrom Image number to merge from, counts from 0. 0 is always base image of container.
* @param nImageTo Image number to merge to, counts from 0. 0 is always base image of container.
* @param pVDIfsOperation Pointer to the per-operation VD interface list.
*/
VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
/**
* 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.
*
* @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 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 pVDIfsOperation Pointer to the per-operation VD interface list.
* @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
* destination image.
* @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
* for the destination operation.
*/
VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
const char *pszBackend, const char *pszFilename,
bool fMoveByRename, uint64_t cbSize,
unsigned uImageFlags, PCRTUUID pDstUuid,
PVDINTERFACE pVDIfsOperation,
PVDINTERFACE pDstVDIfsImage,
PVDINTERFACE pDstVDIfsOperation);
/**
* 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
* file offsets.
*
* @note Compaction is treated as a single operation with regard to thread
* synchronization, which means that it potentially blocks other activities for
* a long time. The complexity of compaction would grow even more if concurrent
* accesses have to be handled.
*
* @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
* this isn't supported 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.
*/
VBOXDDU_DECL(int) VDCompact(PVBOXHDD pDisk, unsigned nImage,
PVDINTERFACE pVDIfsOperation);
/**
* Resizes the given disk image to the given size.
*
* @return VBox status
* @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.
*/
VBOXDDU_DECL(int) VDResize(PVBOXHDD pDisk, uint64_t cbSize,
PCPDMMEDIAGEOMETRY pPCHSGeometry,
PCPDMMEDIAGEOMETRY pLCHSGeometry,
PVDINTERFACE pVDIfsOperation);
/**
* 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
* reopened in read/write mode.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
/**
* 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.
*/
VBOXDDU_DECL(int) VDCacheClose(PVBOXHDD pDisk, bool fDelete);
/**
* Closes all opened image files in HDD container.
*
* @return VBox status code.
* @param pDisk Pointer to HDD container.
*/
VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
/**
* Read data from virtual HDD.
*
* @return VBox status code.
* @return 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.
* Must be aligned to a sector boundary.
* @param pvBuf Pointer to buffer for reading data.
* @param cbRead Number of bytes to read.
* Must be aligned to a sector boundary.
*/
VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
/**
* Write data to virtual HDD.
*
* @return VBox status code.
* @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to HDD container.
* @param uOffset Offset of first writing byte from start of disk.
* Must be aligned to a sector boundary.
* @param pvBuf Pointer to buffer for writing data.
* @param cbWrite Number of bytes to write.
* Must be aligned to a sector boundary.
*/
VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
/**
* Make sure the on disk representation of a virtual HDD is up to date.
*
* @return VBox status code.
* @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
* @param pDisk Pointer to HDD container.
*/
VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
/**
* Get number of opened images in HDD container.
*
* @return Number of opened images for HDD container. 0 if no images have been opened.
* @param pDisk Pointer to HDD container.
*/
VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
/**
* Get read/write mode of HDD container.
*
* @return Virtual disk ReadOnly status.
* @return true if no image is opened in HDD container.
* @param pDisk Pointer to HDD container.
*/
VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
/**
* Get total capacity of an image in HDD container.
*
* @return Virtual disk size in bytes.
* @return 0 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.
*/
VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
/**
* Get total file size of an image in HDD container.
*
* @return Virtual disk size in bytes.
* @return 0 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.
*/
VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
/**
* Get virtual disk PCHS geometry of an image in HDD container.
*
* @return VBox status code.
* @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
PPDMMEDIAGEOMETRY pPCHSGeometry);
/**
* Store virtual disk PCHS geometry of an image in HDD container.
*
* @return VBox status code.
* @return 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 pPCHSGeometry Where to load PCHS geometry from. Not NULL.
*/
VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
PCPDMMEDIAGEOMETRY pPCHSGeometry);
/**
* Get virtual disk LCHS geometry of an image in HDD container.
*
* @return VBox status code.
* @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
PPDMMEDIAGEOMETRY pLCHSGeometry);
/**
* Store virtual disk LCHS geometry of an image in HDD container.
*
* @return VBox status code.
* @return 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 pLCHSGeometry Where to load LCHS geometry from. Not NULL.
*/
VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
PCPDMMEDIAGEOMETRY pLCHSGeometry);
/**
* Get version of image in HDD container.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
unsigned *puVersion);
/**
* List the capabilities of image backend in HDD container.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
PVDBACKENDINFO pBackendInfo);
/**
* Get flags of image in HDD container.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
/**
* Get open flags of image in HDD container.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
unsigned *puOpenFlags);
/**
* 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.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
unsigned uOpenFlags);
/**
* 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.
*
* @return VBox status code.
* @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
char *pszFilename, unsigned cbFilename);
/**
* Get the comment line of image in HDD container.
*
* @return VBox status code.
* @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
char *pszComment, unsigned cbComment);
/**
* Changes the comment line of image in HDD container.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
const char *pszComment);
/**
* Get UUID of image in HDD container.
*
* @return VBox status code.
* @return 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 UUID.
*/
VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
/**
* Set the image's UUID. Should not be used by normal applications.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
/**
* Get last modification UUID of image in HDD container.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
PRTUUID pUuid);
/**
* Set the image's last modification UUID. Should not be used by normal applications.
*
* @return VBox status code.
* @return 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.
*/
VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
PCRTUUID pUuid);
/**
* Get parent UUID of image in HDD container.
*
* @return VBox status code.
* @return 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 the container.
* @param pUuid Where to store the parent image UUID.
*/
VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
PRTUUID pUuid);
/**
* Set the image's parent UUID. Should not be used by normal applications.
*
* @return 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.
*/
VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
PCRTUUID pUuid);
/**
* Debug helper - dumps all opened images in HDD container into the log file.
*
* @param pDisk Pointer to HDD container.
*/
VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
/**
* Query if asynchronous operations are supported for this disk.
*
* @return VBox status code.
* @return 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 pfAIOSupported Where to store if async IO is supported.
*/
VBOXDDU_DECL(int) VDImageIsAsyncIOSupported(PVBOXHDD pDisk, unsigned nImage, bool *pfAIOSupported);
/**
* Start a asynchronous read request.
*
* @return VBox status code.
* @param pDisk Pointer to the HDD container.
* @param uOffset The offset of the virtual disk to read from.
* @param cbRead How many bytes to read.
* @param paSeg Pointer to an array of segments.
* @param cSeg Number of segments in the array.
* @param pfnComplete Completion callback.
* @param pvUser User data which is passed on completion
*/
VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
PCRTSGSEG paSeg, unsigned cSeg,
PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
void *pvUser1, void *pvUser2);
/**
* Start a asynchronous write request.
*
* @return VBox status code.
* @param pDisk Pointer to the HDD container.
* @param uOffset The offset of the virtual disk to write to.
* @param cbWrtie How many bytes to write.
* @param paSeg Pointer to an array of segments.
* @param cSeg Number of segments in the array.
* @param pfnComplete Completion callback.
* @param pvUser User data which is passed on completion.
*/
VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
PCRTSGSEG paSeg, unsigned cSeg,
PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
void *pvUser1, void *pvUser2);
/**
* Start a asynchronous flush request.
*
* @return VBox status code.
* @param pDisk Pointer to the HDD container.
* @param pfnComplete Completion callback.
* @param pvUser User data which is passed on completion.
*/
VBOXDDU_DECL(int) VDAsyncFlush(PVBOXHDD pDisk,
PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
void *pvUser1, void *pvUser2);
RT_C_DECLS_END
/** @} */
#endif