VirtualBox

source: vbox/trunk/include/VBox/VBoxHDD.h@ 31297

Last change on this file since 31297 was 31185, checked in by vboxsync, 14 years ago

VBoxHDD: Add a flag to disable locking of an image file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 93.1 KB
Line 
1/** @file
2 * VBox HDD Container API.
3 */
4
5/*
6 * Copyright (C) 2006-2010 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_VD_h
27#define ___VBox_VD_h
28
29#include <iprt/assert.h>
30#include <iprt/string.h>
31#include <iprt/mem.h>
32#include <iprt/net.h>
33#include <iprt/sg.h>
34#include <VBox/cdefs.h>
35#include <VBox/types.h>
36#include <VBox/err.h>
37#include <VBox/pdmifs.h>
38
39RT_C_DECLS_BEGIN
40
41#ifdef IN_RING0
42# error "There are no VBox HDD Container APIs available in Ring-0 Host Context!"
43#endif
44
45/** @defgroup grp_vd VBox HDD Container
46 * @{
47 */
48
49/** Current VMDK image version. */
50#define VMDK_IMAGE_VERSION (0x0001)
51
52/** Current VDI image major version. */
53#define VDI_IMAGE_VERSION_MAJOR (0x0001)
54/** Current VDI image minor version. */
55#define VDI_IMAGE_VERSION_MINOR (0x0001)
56/** Current VDI image version. */
57#define VDI_IMAGE_VERSION ((VDI_IMAGE_VERSION_MAJOR << 16) | VDI_IMAGE_VERSION_MINOR)
58
59/** Get VDI major version from combined version. */
60#define VDI_GET_VERSION_MAJOR(uVer) ((uVer) >> 16)
61/** Get VDI minor version from combined version. */
62#define VDI_GET_VERSION_MINOR(uVer) ((uVer) & 0xffff)
63
64/** Placeholder for specifying the last opened image. */
65#define VD_LAST_IMAGE 0xffffffffU
66
67/** @name VBox HDD container image flags
68 * @{
69 */
70/** No flags. */
71#define VD_IMAGE_FLAGS_NONE (0)
72/** Fixed image. */
73#define VD_IMAGE_FLAGS_FIXED (0x10000)
74/** Diff image. Mutually exclusive with fixed image. */
75#define VD_IMAGE_FLAGS_DIFF (0x20000)
76/** VMDK: Split image into 2GB extents. */
77#define VD_VMDK_IMAGE_FLAGS_SPLIT_2G (0x0001)
78/** VMDK: Raw disk image (giving access to a number of host partitions). */
79#define VD_VMDK_IMAGE_FLAGS_RAWDISK (0x0002)
80/** VMDK: stream optimized image, read only. */
81#define VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED (0x0004)
82/** VMDK: ESX variant, use in addition to other flags. */
83#define VD_VMDK_IMAGE_FLAGS_ESX (0x0008)
84/** VDI: Fill new blocks with zeroes while expanding image file. Only valid
85 * for newly created images, never set for opened existing images. */
86#define VD_VDI_IMAGE_FLAGS_ZERO_EXPAND (0x0100)
87
88/** Mask of valid image flags for VMDK. */
89#define VD_VMDK_IMAGE_FLAGS_MASK ( VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE \
90 | VD_VMDK_IMAGE_FLAGS_SPLIT_2G | VD_VMDK_IMAGE_FLAGS_RAWDISK \
91 | VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED | VD_VMDK_IMAGE_FLAGS_ESX)
92
93/** Mask of valid image flags for VDI. */
94#define VD_VDI_IMAGE_FLAGS_MASK (VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE | VD_VDI_IMAGE_FLAGS_ZERO_EXPAND)
95
96/** Mask of all valid image flags for all formats. */
97#define VD_IMAGE_FLAGS_MASK (VD_VMDK_IMAGE_FLAGS_MASK | VD_VDI_IMAGE_FLAGS_MASK)
98
99/** Default image flags. */
100#define VD_IMAGE_FLAGS_DEFAULT (VD_IMAGE_FLAGS_NONE)
101/** @} */
102
103
104/**
105 * Auxiliary type for describing partitions on raw disks. The entries must be
106 * in ascending order (as far as uStart is concerned), and must not overlap.
107 * Note that this does not correspond 1:1 to partitions, it is describing the
108 * general meaning of contiguous areas on the disk.
109 */
110typedef struct VBOXHDDRAWPARTDESC
111{
112 /** Device to use for this partition/data area. Can be the disk device if
113 * the offset field is set appropriately. If this is NULL, then this
114 * partition will not be accessible to the guest. The size of the data area
115 * must still be set correctly. */
116 const char *pszRawDevice;
117 /** Pointer to the partitioning info. NULL means this is a regular data
118 * area on disk, non-NULL denotes data which should be copied to the
119 * partition data overlay. */
120 const void *pvPartitionData;
121 /** Offset where the data starts in this device. */
122 uint64_t uStartOffset;
123 /** Offset where the data starts in the disk. */
124 uint64_t uStart;
125 /** Size of the data area. */
126 uint64_t cbData;
127} VBOXHDDRAWPARTDESC, *PVBOXHDDRAWPARTDESC;
128
129/**
130 * Auxiliary data structure for creating raw disks.
131 */
132typedef struct VBOXHDDRAW
133{
134 /** Signature for structure. Must be 'R', 'A', 'W', '\\0'. Actually a trick
135 * to make logging of the comment string produce sensible results. */
136 char szSignature[4];
137 /** Flag whether access to full disk should be given (ignoring the
138 * partition information below). */
139 bool fRawDisk;
140 /** Filename for the raw disk. Ignored for partitioned raw disks.
141 * For Linux e.g. /dev/sda, and for Windows e.g. \\\\.\\PhysicalDisk0. */
142 const char *pszRawDisk;
143 /** Number of entries in the partition descriptor array. */
144 unsigned cPartDescs;
145 /** Pointer to the partition descriptor array. */
146 PVBOXHDDRAWPARTDESC pPartDescs;
147} VBOXHDDRAW, *PVBOXHDDRAW;
148
149/** @name VBox HDD container image open mode flags
150 * @{
151 */
152/** Try to open image in read/write exclusive access mode if possible, or in read-only elsewhere. */
153#define VD_OPEN_FLAGS_NORMAL 0
154/** Open image in read-only mode with sharing access with others. */
155#define VD_OPEN_FLAGS_READONLY RT_BIT(0)
156/** Honor zero block writes instead of ignoring them whenever possible.
157 * This is not supported by all formats. It is silently ignored in this case. */
158#define VD_OPEN_FLAGS_HONOR_ZEROES RT_BIT(1)
159/** Honor writes of the same data instead of ignoring whenever possible.
160 * This is handled generically, and is only meaningful for differential image
161 * formats. It is silently ignored otherwise. */
162#define VD_OPEN_FLAGS_HONOR_SAME RT_BIT(2)
163/** Do not perform the base/diff image check on open. This does NOT imply
164 * opening the image as readonly (would break e.g. adding UUIDs to VMDK files
165 * created by other products). Images opened with this flag should only be
166 * used for querying information, and nothing else. */
167#define VD_OPEN_FLAGS_INFO RT_BIT(3)
168/** Open image for asynchronous access.
169 * Only available if VD_CAP_ASYNC_IO is set
170 * Check with VDIsAsynchonousIoSupported wether
171 * asynchronous I/O is really supported for this file. */
172#define VD_OPEN_FLAGS_ASYNC_IO RT_BIT(4)
173/** Allow sharing of the image for writable images. May be ignored if the
174 * format backend doesn't support this type of concurrent access. */
175#define VD_OPEN_FLAGS_SHAREABLE RT_BIT(5)
176/** Mask of valid flags. */
177#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)
178/** @}*/
179
180
181/** @name VBox HDD container backend capability flags
182 * @{
183 */
184/** Supports UUIDs as expected by VirtualBox code. */
185#define VD_CAP_UUID RT_BIT(0)
186/** Supports creating fixed size images, allocating all space instantly. */
187#define VD_CAP_CREATE_FIXED RT_BIT(1)
188/** Supports creating dynamically growing images, allocating space on demand. */
189#define VD_CAP_CREATE_DYNAMIC RT_BIT(2)
190/** Supports creating images split in chunks of a bit less than 2GBytes. */
191#define VD_CAP_CREATE_SPLIT_2G RT_BIT(3)
192/** Supports being used as differencing image format backend. */
193#define VD_CAP_DIFF RT_BIT(4)
194/** Supports asynchronous I/O operations for at least some configurations. */
195#define VD_CAP_ASYNC RT_BIT(5)
196/** The backend operates on files. The caller needs to know to handle the
197 * location appropriately. */
198#define VD_CAP_FILE RT_BIT(6)
199/** The backend uses the config interface. The caller needs to know how to
200 * provide the mandatory configuration parts this way. */
201#define VD_CAP_CONFIG RT_BIT(7)
202/** The backend uses the network stack interface. The caller has to provide
203 * the appropriate interface. */
204#define VD_CAP_TCPNET RT_BIT(8)
205/** @}*/
206
207/**
208 * Supported interface types.
209 */
210typedef enum VDINTERFACETYPE
211{
212 /** First valid interface. */
213 VDINTERFACETYPE_FIRST = 0,
214 /** Interface to pass error message to upper layers. Per-disk. */
215 VDINTERFACETYPE_ERROR = VDINTERFACETYPE_FIRST,
216 /** Interface for asynchronous I/O operations. Per-disk. */
217 VDINTERFACETYPE_ASYNCIO,
218 /** Interface for progress notification. Per-operation. */
219 VDINTERFACETYPE_PROGRESS,
220 /** Interface for configuration information. Per-image. */
221 VDINTERFACETYPE_CONFIG,
222 /** Interface for TCP network stack. Per-disk. */
223 VDINTERFACETYPE_TCPNET,
224 /** Interface for getting parent image state. Per-operation. */
225 VDINTERFACETYPE_PARENTSTATE,
226 /** Interface for synchronizing accesses from several threads. Per-disk. */
227 VDINTERFACETYPE_THREADSYNC,
228 /** Interface for I/O between the generic VBoxHDD code and the backend. Per-image. */
229 VDINTERFACETYPE_IO,
230 /** invalid interface. */
231 VDINTERFACETYPE_INVALID
232} VDINTERFACETYPE;
233
234/**
235 * Common structure for all interfaces.
236 */
237typedef struct VDINTERFACE
238{
239 /** Human readable interface name. */
240 const char *pszInterfaceName;
241 /** The size of the struct. */
242 uint32_t cbSize;
243 /** Pointer to the next common interface structure. */
244 struct VDINTERFACE *pNext;
245 /** Interface type. */
246 VDINTERFACETYPE enmInterface;
247 /** Opaque user data which is passed on every call. */
248 void *pvUser;
249 /** Pointer to the function call table of the interface.
250 * As this is opaque this must be casted to the right interface
251 * struct defined below based on the interface type in enmInterface. */
252 void *pCallbacks;
253} VDINTERFACE;
254/** Pointer to a VDINTERFACE. */
255typedef VDINTERFACE *PVDINTERFACE;
256/** Pointer to a const VDINTERFACE. */
257typedef const VDINTERFACE *PCVDINTERFACE;
258
259/**
260 * Helper functions to handle interface lists.
261 *
262 * @note These interface lists are used consistently to pass per-disk,
263 * per-image and/or per-operation callbacks. Those three purposes are strictly
264 * separate. See the individual interface declarations for what context they
265 * apply to. The caller is responsible for ensuring that the lifetime of the
266 * interface descriptors is appropriate for the category of interface.
267 */
268
269/**
270 * Get a specific interface from a list of interfaces specified by the type.
271 *
272 * @return Pointer to the matching interface or NULL if none was found.
273 * @param pVDIfs Pointer to the VD interface list.
274 * @param enmInterface Interface to search for.
275 */
276DECLINLINE(PVDINTERFACE) VDInterfaceGet(PVDINTERFACE pVDIfs, VDINTERFACETYPE enmInterface)
277{
278 AssertMsgReturn( enmInterface >= VDINTERFACETYPE_FIRST
279 && enmInterface < VDINTERFACETYPE_INVALID,
280 ("enmInterface=%u", enmInterface), NULL);
281
282 while (pVDIfs)
283 {
284 /* Sanity checks. */
285 AssertMsgBreak(pVDIfs->cbSize == sizeof(VDINTERFACE),
286 ("cbSize=%u\n", pVDIfs->cbSize));
287
288 if (pVDIfs->enmInterface == enmInterface)
289 return pVDIfs;
290 pVDIfs = pVDIfs->pNext;
291 }
292
293 /* No matching interface was found. */
294 return NULL;
295}
296
297/**
298 * Add an interface to a list of interfaces.
299 *
300 * @return VBox status code.
301 * @param pInterface Pointer to an unitialized common interface structure.
302 * @param pszName Name of the interface.
303 * @param enmInterface Type of the interface.
304 * @param pCallbacks The callback table of the interface.
305 * @param pvUser Opaque user data passed on every function call.
306 * @param ppVDIfs Pointer to the VD interface list.
307 */
308DECLINLINE(int) VDInterfaceAdd(PVDINTERFACE pInterface, const char *pszName,
309 VDINTERFACETYPE enmInterface, void *pCallbacks,
310 void *pvUser, PVDINTERFACE *ppVDIfs)
311{
312 /* Argument checks. */
313 AssertMsgReturn( enmInterface >= VDINTERFACETYPE_FIRST
314 && enmInterface < VDINTERFACETYPE_INVALID,
315 ("enmInterface=%u", enmInterface), VERR_INVALID_PARAMETER);
316
317 AssertMsgReturn(VALID_PTR(pCallbacks),
318 ("pCallbacks=%#p", pCallbacks),
319 VERR_INVALID_PARAMETER);
320
321 AssertMsgReturn(VALID_PTR(ppVDIfs),
322 ("pInterfaceList=%#p", ppVDIfs),
323 VERR_INVALID_PARAMETER);
324
325 /* Fill out interface descriptor. */
326 pInterface->cbSize = sizeof(VDINTERFACE);
327 pInterface->pszInterfaceName = pszName;
328 pInterface->enmInterface = enmInterface;
329 pInterface->pCallbacks = pCallbacks;
330 pInterface->pvUser = pvUser;
331 pInterface->pNext = *ppVDIfs;
332
333 /* Remember the new start of the list. */
334 *ppVDIfs = pInterface;
335
336 return VINF_SUCCESS;
337}
338
339/**
340 * Removes an interface from a list of interfaces.
341 *
342 * @return VBox status code
343 * @param pInterface Pointer to an initialized common interface structure to remove.
344 * @param ppVDIfs Pointer to the VD interface list to remove from.
345 */
346DECLINLINE(int) VDInterfaceRemove(PVDINTERFACE pInterface, PVDINTERFACE *ppVDIfs)
347{
348 int rc = VERR_NOT_FOUND;
349
350 /* Argument checks. */
351 AssertMsgReturn(VALID_PTR(pInterface),
352 ("pInterface=%#p", pInterface),
353 VERR_INVALID_PARAMETER);
354
355 AssertMsgReturn(VALID_PTR(ppVDIfs),
356 ("pInterfaceList=%#p", ppVDIfs),
357 VERR_INVALID_PARAMETER);
358
359 if (*ppVDIfs)
360 {
361 PVDINTERFACE pPrev = NULL;
362 PVDINTERFACE pCurr = *ppVDIfs;
363
364 while ( pCurr
365 && (pCurr != pInterface))
366 {
367 pPrev = pCurr;
368 pCurr = pCurr->pNext;
369 }
370
371 /* First interface */
372 if (!pPrev)
373 {
374 *ppVDIfs = pCurr->pNext;
375 rc = VINF_SUCCESS;
376 }
377 else if (pCurr)
378 {
379 pPrev = pCurr->pNext;
380 rc = VINF_SUCCESS;
381 }
382 }
383
384 return rc;
385}
386
387/**
388 * Interface to deliver error messages (and also informational messages)
389 * to upper layers.
390 *
391 * Per disk interface. Optional, but think twice if you want to miss the
392 * opportunity of reporting better human-readable error messages.
393 */
394typedef struct VDINTERFACEERROR
395{
396 /**
397 * Size of the error interface.
398 */
399 uint32_t cbSize;
400
401 /**
402 * Interface type.
403 */
404 VDINTERFACETYPE enmInterface;
405
406 /**
407 * Error message callback. Must be able to accept special IPRT format
408 * strings.
409 *
410 * @param pvUser The opaque data passed on container creation.
411 * @param rc The VBox error code.
412 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
413 * @param pszFormat Error message format string.
414 * @param va Error message arguments.
415 */
416 DECLR3CALLBACKMEMBER(void, pfnError, (void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
417
418 /**
419 * Informational message callback. May be NULL. Used e.g. in
420 * VDDumpImages(). Must be able to accept special IPRT format strings.
421 *
422 * @return VBox status code.
423 * @param pvUser The opaque data passed on container creation.
424 * @param pszFormat Error message format string.
425 * @param ... Error message arguments.
426 */
427 DECLR3CALLBACKMEMBER(int, pfnMessage, (void *pvUser, const char *pszFormat, ...));
428
429} VDINTERFACEERROR, *PVDINTERFACEERROR;
430
431/**
432 * Get error interface from opaque callback table.
433 *
434 * @return Pointer to the callback table.
435 * @param pInterface Pointer to the interface descriptor.
436 */
437DECLINLINE(PVDINTERFACEERROR) VDGetInterfaceError(PVDINTERFACE pInterface)
438{
439 PVDINTERFACEERROR pInterfaceError;
440
441 /* Check that the interface descriptor is a error interface. */
442 AssertMsgReturn( pInterface->enmInterface == VDINTERFACETYPE_ERROR
443 && pInterface->cbSize == sizeof(VDINTERFACE),
444 ("Not an error interface"), NULL);
445
446 pInterfaceError = (PVDINTERFACEERROR)pInterface->pCallbacks;
447
448 /* Do basic checks. */
449 AssertMsgReturn( pInterfaceError->cbSize == sizeof(VDINTERFACEERROR)
450 && pInterfaceError->enmInterface == VDINTERFACETYPE_ERROR,
451 ("A non error callback table attached to a error interface descriptor\n"), NULL);
452
453 return pInterfaceError;
454}
455
456/**
457 * Completion callback which is called by the interface owner
458 * to inform the backend that a task finished.
459 *
460 * @return VBox status code.
461 * @param pvUser Opaque user data which is passed on request submission.
462 * @param rcReq Status code of the completed request.
463 */
464typedef DECLCALLBACK(int) FNVDCOMPLETED(void *pvUser, int rcReq);
465/** Pointer to FNVDCOMPLETED() */
466typedef FNVDCOMPLETED *PFNVDCOMPLETED;
467
468/** Open the storage readonly. */
469#define VD_INTERFACEASYNCIO_OPEN_FLAGS_READONLY RT_BIT(0)
470/** Create the storage backend if it doesn't exist. */
471#define VD_INTERFACEASYNCIO_OPEN_FLAGS_CREATE RT_BIT(1)
472/** Don't write lock the opened file. */
473#define VD_INTERFACEASYNCIO_OPEN_FLAGS_DONT_LOCK RT_BIT(2)
474
475/**
476 * Support interface for asynchronous I/O
477 *
478 * Per-disk. Optional.
479 */
480typedef struct VDINTERFACEASYNCIO
481{
482 /**
483 * Size of the async interface.
484 */
485 uint32_t cbSize;
486
487 /**
488 * Interface type.
489 */
490 VDINTERFACETYPE enmInterface;
491
492 /**
493 * Open callback
494 *
495 * @return VBox status code.
496 * @param pvUser The opaque data passed on container creation.
497 * @param pszLocation Name of the location to open.
498 * @param uOpenFlags Flags for opening the backend.
499 * See VD_INTERFACEASYNCIO_OPEN_FLAGS_* #defines
500 * @param pfnCompleted The callback which is called whenever a task
501 * completed. The backend has to pass the user data
502 * of the request initiator (ie the one who calls
503 * VDAsyncRead or VDAsyncWrite) in pvCompletion
504 * if this is NULL.
505 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
506 * @param ppStorage Where to store the opaque storage handle.
507 */
508 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation,
509 unsigned uOpenFlags,
510 PFNVDCOMPLETED pfnCompleted,
511 PVDINTERFACE pVDIfsDisk,
512 void **ppStorage));
513
514 /**
515 * Close callback.
516 *
517 * @return VBox status code.
518 * @param pvUser The opaque data passed on container creation.
519 * @param pStorage The opaque storage handle to close.
520 */
521 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, void *pStorage));
522
523 /**
524 * Returns the size of the opened storage backend.
525 *
526 * @return VBox status code.
527 * @param pvUser The opaque data passed on container creation.
528 * @param pStorage The opaque storage handle to close.
529 * @param pcbSize Where to store the size of the storage backend.
530 */
531 DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, void *pStorage, uint64_t *pcbSize));
532
533 /**
534 * Sets the size of the opened storage backend if possible.
535 *
536 * @return VBox status code.
537 * @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
538 * @param pvUser The opaque data passed on container creation.
539 * @param pStorage The opaque storage handle to close.
540 * @param cbSize The new size of the image.
541 */
542 DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, void *pStorage, uint64_t cbSize));
543
544 /**
545 * Synchronous write callback.
546 *
547 * @return VBox status code.
548 * @param pvUser The opaque data passed on container creation.
549 * @param pStorage The storage handle to use.
550 * @param uOffset The offset to start from.
551 * @param cbWrite How many bytes to write.
552 * @param pvBuf Pointer to the bits need to be written.
553 * @param pcbWritten Where to store how many bytes where actually written.
554 */
555 DECLR3CALLBACKMEMBER(int, pfnWriteSync, (void *pvUser, void *pStorage, uint64_t uOffset,
556 size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
557
558 /**
559 * Synchronous read callback.
560 *
561 * @return VBox status code.
562 * @param pvUser The opaque data passed on container creation.
563 * @param pStorage The storage handle to use.
564 * @param uOffset The offset to start from.
565 * @param cbRead How many bytes to read.
566 * @param pvBuf Where to store the read bits.
567 * @param pcbRead Where to store how many bytes where actually read.
568 */
569 DECLR3CALLBACKMEMBER(int, pfnReadSync, (void *pvUser, void *pStorage, uint64_t uOffset,
570 size_t cbRead, void *pvBuf, size_t *pcbRead));
571
572 /**
573 * Flush data to the storage backend.
574 *
575 * @return VBox statis code.
576 * @param pvUser The opaque data passed on container creation.
577 * @param pStorage The storage handle to flush.
578 */
579 DECLR3CALLBACKMEMBER(int, pfnFlushSync, (void *pvUser, void *pStorage));
580
581 /**
582 * Initiate a asynchronous read request.
583 *
584 * @return VBox status code.
585 * @param pvUser The opqaue user data passed on container creation.
586 * @param pStorage The storage handle.
587 * @param uOffset The offset to start reading from.
588 * @param paSegments Scatter gather list to store the data in.
589 * @param cSegments Number of segments in the list.
590 * @param cbRead How many bytes to read.
591 * @param pvCompletion The opaque user data which is returned upon completion.
592 * @param ppTask Where to store the opaque task handle.
593 */
594 DECLR3CALLBACKMEMBER(int, pfnReadAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
595 PCRTSGSEG paSegments, size_t cSegments,
596 size_t cbRead, void *pvCompletion,
597 void **ppTask));
598
599 /**
600 * Initiate a asynchronous write request.
601 *
602 * @return VBox status code.
603 * @param pvUser The opaque user data passed on conatiner creation.
604 * @param pStorage The storage handle.
605 * @param uOffset The offset to start writing to.
606 * @param paSegments Scatter gather list of the data to write
607 * @param cSegments Number of segments in the list.
608 * @param cbWrite How many bytes to write.
609 * @param pvCompletion The opaque user data which is returned upon completion.
610 * @param ppTask Where to store the opaque task handle.
611 */
612 DECLR3CALLBACKMEMBER(int, pfnWriteAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
613 PCRTSGSEG paSegments, size_t cSegments,
614 size_t cbWrite, void *pvCompletion,
615 void **ppTask));
616
617 /**
618 * Initiates a async flush request.
619 *
620 * @return VBox statis code.
621 * @param pvUser The opaque data passed on container creation.
622 * @param pStorage The storage handle to flush.
623 * @param pvCompletion The opaque user data which is returned upon completion.
624 * @param ppTask Where to store the opaque task handle.
625 */
626 DECLR3CALLBACKMEMBER(int, pfnFlushAsync, (void *pvUser, void *pStorage,
627 void *pvCompletion, void **ppTask));
628
629} VDINTERFACEASYNCIO, *PVDINTERFACEASYNCIO;
630
631/**
632 * Get async I/O interface from opaque callback table.
633 *
634 * @return Pointer to the callback table.
635 * @param pInterface Pointer to the interface descriptor.
636 */
637DECLINLINE(PVDINTERFACEASYNCIO) VDGetInterfaceAsyncIO(PVDINTERFACE pInterface)
638{
639 PVDINTERFACEASYNCIO pInterfaceAsyncIO;
640
641 /* Check that the interface descriptor is a async I/O interface. */
642 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_ASYNCIO)
643 && (pInterface->cbSize == sizeof(VDINTERFACE)),
644 ("Not an async I/O interface"), NULL);
645
646 pInterfaceAsyncIO = (PVDINTERFACEASYNCIO)pInterface->pCallbacks;
647
648 /* Do basic checks. */
649 AssertMsgReturn( (pInterfaceAsyncIO->cbSize == sizeof(VDINTERFACEASYNCIO))
650 && (pInterfaceAsyncIO->enmInterface == VDINTERFACETYPE_ASYNCIO),
651 ("A non async I/O callback table attached to a async I/O interface descriptor\n"), NULL);
652
653 return pInterfaceAsyncIO;
654}
655
656/**
657 * Callback which provides progress information about a currently running
658 * lengthy operation.
659 *
660 * @return VBox status code.
661 * @param pvUser The opaque user data associated with this interface.
662 * @param uPercent Completion percentage.
663 */
664typedef DECLCALLBACK(int) FNVDPROGRESS(void *pvUser, unsigned uPercentage);
665/** Pointer to FNVDPROGRESS() */
666typedef FNVDPROGRESS *PFNVDPROGRESS;
667
668/**
669 * Progress notification interface
670 *
671 * Per-operation. Optional.
672 */
673typedef struct VDINTERFACEPROGRESS
674{
675 /**
676 * Size of the progress interface.
677 */
678 uint32_t cbSize;
679
680 /**
681 * Interface type.
682 */
683 VDINTERFACETYPE enmInterface;
684
685 /**
686 * Progress notification callbacks.
687 */
688 PFNVDPROGRESS pfnProgress;
689
690} VDINTERFACEPROGRESS, *PVDINTERFACEPROGRESS;
691
692/**
693 * Get progress interface from opaque callback table.
694 *
695 * @return Pointer to the callback table.
696 * @param pInterface Pointer to the interface descriptor.
697 */
698DECLINLINE(PVDINTERFACEPROGRESS) VDGetInterfaceProgress(PVDINTERFACE pInterface)
699{
700 PVDINTERFACEPROGRESS pInterfaceProgress;
701
702 /* Check that the interface descriptor is a progress interface. */
703 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PROGRESS)
704 && (pInterface->cbSize == sizeof(VDINTERFACE)),
705 ("Not a progress interface"), NULL);
706
707
708 pInterfaceProgress = (PVDINTERFACEPROGRESS)pInterface->pCallbacks;
709
710 /* Do basic checks. */
711 AssertMsgReturn( (pInterfaceProgress->cbSize == sizeof(VDINTERFACEPROGRESS))
712 && (pInterfaceProgress->enmInterface == VDINTERFACETYPE_PROGRESS),
713 ("A non progress callback table attached to a progress interface descriptor\n"), NULL);
714
715 return pInterfaceProgress;
716}
717
718
719/**
720 * Configuration information interface
721 *
722 * Per-image. Optional for most backends, but mandatory for images which do
723 * not operate on files (including standard block or character devices).
724 */
725typedef struct VDINTERFACECONFIG
726{
727 /**
728 * Size of the configuration interface.
729 */
730 uint32_t cbSize;
731
732 /**
733 * Interface type.
734 */
735 VDINTERFACETYPE enmInterface;
736
737 /**
738 * Validates that the keys are within a set of valid names.
739 *
740 * @return true if all key names are found in pszzAllowed.
741 * @return false if not.
742 * @param pvUser The opaque user data associated with this interface.
743 * @param pszzValid List of valid key names separated by '\\0' and ending with
744 * a double '\\0'.
745 */
746 DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid));
747
748 /**
749 * Retrieves the length of the string value associated with a key (including
750 * the terminator, for compatibility with CFGMR3QuerySize).
751 *
752 * @return VBox status code.
753 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
754 * @param pvUser The opaque user data associated with this interface.
755 * @param pszName Name of the key to query.
756 * @param pcbValue Where to store the value length. Non-NULL.
757 */
758 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
759
760 /**
761 * Query the string value associated with a key.
762 *
763 * @return VBox status code.
764 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
765 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
766 * @param pvUser The opaque user data associated with this interface.
767 * @param pszName Name of the key to query.
768 * @param pszValue Pointer to buffer where to store value.
769 * @param cchValue Length of value buffer.
770 */
771 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
772
773} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
774
775/**
776 * Get configuration information interface from opaque callback table.
777 *
778 * @return Pointer to the callback table.
779 * @param pInterface Pointer to the interface descriptor.
780 */
781DECLINLINE(PVDINTERFACECONFIG) VDGetInterfaceConfig(PVDINTERFACE pInterface)
782{
783 PVDINTERFACECONFIG pInterfaceConfig;
784
785 /* Check that the interface descriptor is a config interface. */
786 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_CONFIG)
787 && (pInterface->cbSize == sizeof(VDINTERFACE)),
788 ("Not a config interface"), NULL);
789
790 pInterfaceConfig = (PVDINTERFACECONFIG)pInterface->pCallbacks;
791
792 /* Do basic checks. */
793 AssertMsgReturn( (pInterfaceConfig->cbSize == sizeof(VDINTERFACECONFIG))
794 && (pInterfaceConfig->enmInterface == VDINTERFACETYPE_CONFIG),
795 ("A non config callback table attached to a config interface descriptor\n"), NULL);
796
797 return pInterfaceConfig;
798}
799
800/**
801 * Query configuration, validates that the keys are within a set of valid names.
802 *
803 * @return true if all key names are found in pszzAllowed.
804 * @return false if not.
805 * @param pCfgIf Pointer to configuration callback table.
806 * @param pvUser The opaque user data associated with this interface.
807 * @param pszzValid List of valid names separated by '\\0' and ending with
808 * a double '\\0'.
809 */
810DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, void *pvUser,
811 const char *pszzValid)
812{
813 return pCfgIf->pfnAreKeysValid(pvUser, pszzValid);
814}
815
816/**
817 * Query configuration, unsigned 64-bit integer value with default.
818 *
819 * @return VBox status code.
820 * @param pCfgIf Pointer to configuration callback table.
821 * @param pvUser The opaque user data associated with this interface.
822 * @param pszName Name of an integer value
823 * @param pu64 Where to store the value. Set to default on failure.
824 * @param u64Def The default value.
825 */
826DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
827 const char *pszName, uint64_t *pu64,
828 uint64_t u64Def)
829{
830 char aszBuf[32];
831 int rc = pCfgIf->pfnQuery(pvUser, pszName, aszBuf, sizeof(aszBuf));
832 if (RT_SUCCESS(rc))
833 {
834 rc = RTStrToUInt64Full(aszBuf, 0, pu64);
835 }
836 else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
837 {
838 rc = VINF_SUCCESS;
839 *pu64 = u64Def;
840 }
841 return rc;
842}
843
844/**
845 * Query configuration, unsigned 32-bit integer value with default.
846 *
847 * @return VBox status code.
848 * @param pCfgIf Pointer to configuration callback table.
849 * @param pvUser The opaque user data associated with this interface.
850 * @param pszName Name of an integer value
851 * @param pu32 Where to store the value. Set to default on failure.
852 * @param u32Def The default value.
853 */
854DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
855 const char *pszName, uint32_t *pu32,
856 uint32_t u32Def)
857{
858 uint64_t u64;
859 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, u32Def);
860 if (RT_SUCCESS(rc))
861 {
862 if (!(u64 & UINT64_C(0xffffffff00000000)))
863 *pu32 = (uint32_t)u64;
864 else
865 rc = VERR_CFGM_INTEGER_TOO_BIG;
866 }
867 return rc;
868}
869
870/**
871 * Query configuration, bool value with default.
872 *
873 * @return VBox status code.
874 * @param pCfgIf Pointer to configuration callback table.
875 * @param pvUser The opaque user data associated with this interface.
876 * @param pszName Name of an integer value
877 * @param pf Where to store the value. Set to default on failure.
878 * @param fDef The default value.
879 */
880DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, void *pvUser,
881 const char *pszName, bool *pf,
882 bool fDef)
883{
884 uint64_t u64;
885 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, fDef);
886 if (RT_SUCCESS(rc))
887 *pf = u64 ? true : false;
888 return rc;
889}
890
891/**
892 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
893 * character value.
894 *
895 * @return VBox status code.
896 * @param pCfgIf Pointer to configuration callback table.
897 * @param pvUser The opaque user data associated with this interface.
898 * @param pszName Name of an zero terminated character value
899 * @param ppszString Where to store the string pointer. Not set on failure.
900 * Free this using RTMemFree().
901 */
902DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
903 void *pvUser, const char *pszName,
904 char **ppszString)
905{
906 size_t cb;
907 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
908 if (RT_SUCCESS(rc))
909 {
910 char *pszString = (char *)RTMemAlloc(cb);
911 if (pszString)
912 {
913 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cb);
914 if (RT_SUCCESS(rc))
915 *ppszString = pszString;
916 else
917 RTMemFree(pszString);
918 }
919 else
920 rc = VERR_NO_MEMORY;
921 }
922 return rc;
923}
924
925/**
926 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
927 * character value with default.
928 *
929 * @return VBox status code.
930 * @param pCfgIf Pointer to configuration callback table.
931 * @param pvUser The opaque user data associated with this interface.
932 * @param pszName Name of an zero terminated character value
933 * @param ppszString Where to store the string pointer. Not set on failure.
934 * Free this using RTMemFree().
935 * @param pszDef The default value.
936 */
937DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
938 void *pvUser, const char *pszName,
939 char **ppszString,
940 const char *pszDef)
941{
942 size_t cb;
943 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
944 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
945 {
946 cb = strlen(pszDef) + 1;
947 rc = VINF_SUCCESS;
948 }
949 if (RT_SUCCESS(rc))
950 {
951 char *pszString = (char *)RTMemAlloc(cb);
952 if (pszString)
953 {
954 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cb);
955 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
956 {
957 memcpy(pszString, pszDef, cb);
958 rc = VINF_SUCCESS;
959 }
960 if (RT_SUCCESS(rc))
961 *ppszString = pszString;
962 else
963 RTMemFree(pszString);
964 }
965 else
966 rc = VERR_NO_MEMORY;
967 }
968 return rc;
969}
970
971/**
972 * Query configuration, dynamically allocated (RTMemAlloc) byte string value.
973 *
974 * @return VBox status code.
975 * @param pCfgIf Pointer to configuration callback table.
976 * @param pvUser The opaque user data associated with this interface.
977 * @param pszName Name of an zero terminated character value
978 * @param ppvData Where to store the byte string pointer. Not set on failure.
979 * Free this using RTMemFree().
980 * @param pcbData Where to store the byte string length.
981 */
982DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
983 void *pvUser, const char *pszName,
984 void **ppvData, size_t *pcbData)
985{
986 size_t cb;
987 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
988 if (RT_SUCCESS(rc))
989 {
990 char *pbData;
991 Assert(cb);
992
993 pbData = (char *)RTMemAlloc(cb);
994 if (pbData)
995 {
996 rc = pCfgIf->pfnQuery(pvUser, pszName, pbData, cb);
997 if (RT_SUCCESS(rc))
998 {
999 *ppvData = pbData;
1000 *pcbData = cb - 1; /* Exclude terminator of the queried string. */
1001 }
1002 else
1003 RTMemFree(pbData);
1004 }
1005 else
1006 rc = VERR_NO_MEMORY;
1007 }
1008 return rc;
1009}
1010
1011/** Forward declaration of a VD socket. */
1012typedef struct VDSOCKETINT *VDSOCKET;
1013/** Pointer to a VD socket. */
1014typedef VDSOCKET *PVDSOCKET;
1015/** Nil socket handle. */
1016#define NIL_VDSOCKET ((VDSOCKET)0)
1017
1018/** Connect flag to indicate that the backend wants to use the extended
1019 * socket I/O multiplexing call. This might not be supported on all configurations
1020 * (internal networking and iSCSI)
1021 * and the backend needs to take appropriate action.
1022 */
1023#define VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT RT_BIT_32(0)
1024
1025/** @name Select events
1026 * @{ */
1027/** Readable without blocking. */
1028#define VD_INTERFACETCPNET_EVT_READ RT_BIT_32(0)
1029/** Writable without blocking. */
1030#define VD_INTERFACETCPNET_EVT_WRITE RT_BIT_32(1)
1031/** Error condition, hangup, exception or similar. */
1032#define VD_INTERFACETCPNET_EVT_ERROR RT_BIT_32(2)
1033/** Mask of the valid bits. */
1034#define VD_INTERFACETCPNET_EVT_VALID_MASK UINT32_C(0x00000007)
1035/** @} */
1036
1037/**
1038 * TCP network stack interface
1039 *
1040 * Per-disk. Mandatory for backends which have the VD_CAP_TCPNET bit set.
1041 */
1042typedef struct VDINTERFACETCPNET
1043{
1044 /**
1045 * Size of the configuration interface.
1046 */
1047 uint32_t cbSize;
1048
1049 /**
1050 * Interface type.
1051 */
1052 VDINTERFACETYPE enmInterface;
1053
1054 /**
1055 * Creates a socket. The socket is not connected if this succeeds.
1056 *
1057 * @return iprt status code.
1058 * @retval VERR_NOT_SUPPORTED if the combination of flags is not supported.
1059 * @param fFlags Combination of the VD_INTERFACETCPNET_CONNECT_* #defines.
1060 * @param pSock Where to store the handle.
1061 */
1062 DECLR3CALLBACKMEMBER(int, pfnSocketCreate, (uint32_t fFlags, PVDSOCKET pSock));
1063
1064 /**
1065 * Destroys the socket.
1066 *
1067 * @return iprt status code.
1068 * @param Sock Socket descriptor.
1069 */
1070 DECLR3CALLBACKMEMBER(int, pfnSocketDestroy, (VDSOCKET Sock));
1071
1072 /**
1073 * Connect as a client to a TCP port.
1074 *
1075 * @return iprt status code.
1076 * @param Sock Socket descriptor.
1077 * @param pszAddress The address to connect to.
1078 * @param uPort The port to connect to.
1079 */
1080 DECLR3CALLBACKMEMBER(int, pfnClientConnect, (VDSOCKET Sock, const char *pszAddress, uint32_t uPort));
1081
1082 /**
1083 * Close a TCP connection.
1084 *
1085 * @return iprt status code.
1086 * @param Sock Socket descriptor.
1087 */
1088 DECLR3CALLBACKMEMBER(int, pfnClientClose, (VDSOCKET Sock));
1089
1090 /**
1091 * Returns whether the socket is currently connected to the client.
1092 *
1093 * @returns true if the socket is connected.
1094 * false otherwise.
1095 * @param Sock Socket descriptor.
1096 */
1097 DECLR3CALLBACKMEMBER(bool, pfnIsClientConnected, (VDSOCKET Sock));
1098
1099 /**
1100 * Socket I/O multiplexing.
1101 * Checks if the socket is ready for reading.
1102 *
1103 * @return iprt status code.
1104 * @param Sock Socket descriptor.
1105 * @param cMillies Number of milliseconds to wait for the socket.
1106 * Use RT_INDEFINITE_WAIT to wait for ever.
1107 */
1108 DECLR3CALLBACKMEMBER(int, pfnSelectOne, (VDSOCKET Sock, RTMSINTERVAL cMillies));
1109
1110 /**
1111 * Receive data from a socket.
1112 *
1113 * @return iprt status code.
1114 * @param Sock Socket descriptor.
1115 * @param pvBuffer Where to put the data we read.
1116 * @param cbBuffer Read buffer size.
1117 * @param pcbRead Number of bytes read.
1118 * If NULL the entire buffer will be filled upon successful return.
1119 * If not NULL a partial read can be done successfully.
1120 */
1121 DECLR3CALLBACKMEMBER(int, pfnRead, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
1122
1123 /**
1124 * Send data to a socket.
1125 *
1126 * @return iprt status code.
1127 * @param Sock Socket descriptor.
1128 * @param pvBuffer Buffer to write data to socket.
1129 * @param cbBuffer How much to write.
1130 */
1131 DECLR3CALLBACKMEMBER(int, pfnWrite, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
1132
1133 /**
1134 * Send data from scatter/gather buffer to a socket.
1135 *
1136 * @return iprt status code.
1137 * @param Sock Socket descriptor.
1138 * @param pSgBuf Scatter/gather buffer to write data to socket.
1139 */
1140 DECLR3CALLBACKMEMBER(int, pfnSgWrite, (VDSOCKET Sock, PCRTSGBUF pSgBuf));
1141
1142 /**
1143 * Flush socket write buffers.
1144 *
1145 * @return iprt status code.
1146 * @param Sock Socket descriptor.
1147 */
1148 DECLR3CALLBACKMEMBER(int, pfnFlush, (VDSOCKET Sock));
1149
1150 /**
1151 * Enables or disables delaying sends to coalesce packets.
1152 *
1153 * @return iprt status code.
1154 * @param Sock Socket descriptor.
1155 * @param fEnable When set to true enables coalescing.
1156 */
1157 DECLR3CALLBACKMEMBER(int, pfnSetSendCoalescing, (VDSOCKET Sock, bool fEnable));
1158
1159 /**
1160 * Gets the address of the local side.
1161 *
1162 * @return iprt status code.
1163 * @param Sock Socket descriptor.
1164 * @param pAddr Where to store the local address on success.
1165 */
1166 DECLR3CALLBACKMEMBER(int, pfnGetLocalAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
1167
1168 /**
1169 * Gets the address of the other party.
1170 *
1171 * @return iprt status code.
1172 * @param Sock Socket descriptor.
1173 * @param pAddr Where to store the peer address on success.
1174 */
1175 DECLR3CALLBACKMEMBER(int, pfnGetPeerAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
1176
1177 /**
1178 * Socket I/O multiplexing - extended version which can be woken up.
1179 * Checks if the socket is ready for reading or writing.
1180 *
1181 * @return iprt status code.
1182 * @retval VERR_INTERRUPTED if the thread was woken up by a pfnPoke call.
1183 * @param Sock Socket descriptor.
1184 * @param pfEvents Where to store the received events.
1185 * @param cMillies Number of milliseconds to wait for the socket.
1186 * Use RT_INDEFINITE_WAIT to wait for ever.
1187 */
1188 DECLR3CALLBACKMEMBER(int, pfnSelectOneEx, (VDSOCKET Sock, uint32_t *pfEvents, RTMSINTERVAL cMillies));
1189
1190 /**
1191 * Wakes up the thread waiting in pfnSelectOneEx.
1192 *
1193 * @return iprt status code.
1194 * @param Sock Socket descriptor.
1195 */
1196 DECLR3CALLBACKMEMBER(int, pfnPoke, (VDSOCKET Sock));
1197
1198} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
1199
1200/**
1201 * Get TCP network stack interface from opaque callback table.
1202 *
1203 * @return Pointer to the callback table.
1204 * @param pInterface Pointer to the interface descriptor.
1205 */
1206DECLINLINE(PVDINTERFACETCPNET) VDGetInterfaceTcpNet(PVDINTERFACE pInterface)
1207{
1208 PVDINTERFACETCPNET pInterfaceTcpNet;
1209
1210 /* Check that the interface descriptor is a TCP network stack interface. */
1211 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_TCPNET)
1212 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1213 ("Not a TCP network stack interface"), NULL);
1214
1215 pInterfaceTcpNet = (PVDINTERFACETCPNET)pInterface->pCallbacks;
1216
1217 /* Do basic checks. */
1218 AssertMsgReturn( (pInterfaceTcpNet->cbSize == sizeof(VDINTERFACETCPNET))
1219 && (pInterfaceTcpNet->enmInterface == VDINTERFACETYPE_TCPNET),
1220 ("A non TCP network stack callback table attached to a TCP network stack interface descriptor\n"), NULL);
1221
1222 return pInterfaceTcpNet;
1223}
1224
1225/**
1226 * Interface to get the parent state.
1227 *
1228 * Per operation interface. Optional, present only if there is a parent, and
1229 * used only internally for compacting.
1230 */
1231typedef struct VDINTERFACEPARENTSTATE
1232{
1233 /**
1234 * Size of the parent state interface.
1235 */
1236 uint32_t cbSize;
1237
1238 /**
1239 * Interface type.
1240 */
1241 VDINTERFACETYPE enmInterface;
1242
1243 /**
1244 * Read data callback.
1245 *
1246 * @return VBox status code.
1247 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1248 * @param pvUser The opaque data passed for the operation.
1249 * @param uOffset Offset of first reading byte from start of disk.
1250 * Must be aligned to a sector boundary.
1251 * @param pvBuf Pointer to buffer for reading data.
1252 * @param cbRead Number of bytes to read.
1253 * Must be aligned to a sector boundary.
1254 */
1255 DECLR3CALLBACKMEMBER(int, pfnParentRead, (void *pvUser, uint64_t uOffset, void *pvBuf, size_t cbRead));
1256
1257} VDINTERFACEPARENTSTATE, *PVDINTERFACEPARENTSTATE;
1258
1259
1260/**
1261 * Get parent state interface from opaque callback table.
1262 *
1263 * @return Pointer to the callback table.
1264 * @param pInterface Pointer to the interface descriptor.
1265 */
1266DECLINLINE(PVDINTERFACEPARENTSTATE) VDGetInterfaceParentState(PVDINTERFACE pInterface)
1267{
1268 PVDINTERFACEPARENTSTATE pInterfaceParentState;
1269
1270 /* Check that the interface descriptor is a parent state interface. */
1271 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PARENTSTATE)
1272 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1273 ("Not a parent state interface"), NULL);
1274
1275 pInterfaceParentState = (PVDINTERFACEPARENTSTATE)pInterface->pCallbacks;
1276
1277 /* Do basic checks. */
1278 AssertMsgReturn( (pInterfaceParentState->cbSize == sizeof(VDINTERFACEPARENTSTATE))
1279 && (pInterfaceParentState->enmInterface == VDINTERFACETYPE_PARENTSTATE),
1280 ("A non parent state callback table attached to a parent state interface descriptor\n"), NULL);
1281
1282 return pInterfaceParentState;
1283}
1284
1285/**
1286 * Interface to synchronize concurrent accesses by several threads.
1287 *
1288 * @note The scope of this interface is to manage concurrent accesses after
1289 * the HDD container has been created, and they must stop before destroying the
1290 * container. Opening or closing images is covered by the synchronization, but
1291 * that does not mean it is safe to close images while a thread executes
1292 * <link to="VDMerge"/> or <link to="VDCopy"/> operating on these images.
1293 * Making them safe would require the lock to be held during the entire
1294 * operation, which prevents other concurrent acitivities.
1295 *
1296 * @note Right now this is kept as simple as possible, and does not even
1297 * attempt to provide enough information to allow e.g. concurrent write
1298 * accesses to different areas of the disk. The reason is that it is very
1299 * difficult to predict which area of a disk is affected by a write,
1300 * especially when different image formats are mixed. Maybe later a more
1301 * sophisticated interface will be provided which has the necessary information
1302 * about worst case affected areas.
1303 *
1304 * Per disk interface. Optional, needed if the disk is accessed concurrently
1305 * by several threads, e.g. when merging diff images while a VM is running.
1306 */
1307typedef struct VDINTERFACETHREADSYNC
1308{
1309 /**
1310 * Size of the thread synchronization interface.
1311 */
1312 uint32_t cbSize;
1313
1314 /**
1315 * Interface type.
1316 */
1317 VDINTERFACETYPE enmInterface;
1318
1319 /**
1320 * Start a read operation.
1321 */
1322 DECLR3CALLBACKMEMBER(int, pfnStartRead, (void *pvUser));
1323
1324 /**
1325 * Finish a read operation.
1326 */
1327 DECLR3CALLBACKMEMBER(int, pfnFinishRead, (void *pvUser));
1328
1329 /**
1330 * Start a write operation.
1331 */
1332 DECLR3CALLBACKMEMBER(int, pfnStartWrite, (void *pvUser));
1333
1334 /**
1335 * Finish a write operation.
1336 */
1337 DECLR3CALLBACKMEMBER(int, pfnFinishWrite, (void *pvUser));
1338
1339} VDINTERFACETHREADSYNC, *PVDINTERFACETHREADSYNC;
1340
1341/**
1342 * Get thread synchronization interface from opaque callback table.
1343 *
1344 * @return Pointer to the callback table.
1345 * @param pInterface Pointer to the interface descriptor.
1346 */
1347DECLINLINE(PVDINTERFACETHREADSYNC) VDGetInterfaceThreadSync(PVDINTERFACE pInterface)
1348{
1349 PVDINTERFACETHREADSYNC pInterfaceThreadSync;
1350
1351 /* Check that the interface descriptor is a thread synchronization interface. */
1352 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_THREADSYNC)
1353 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1354 ("Not a thread synchronization interface"), NULL);
1355
1356 pInterfaceThreadSync = (PVDINTERFACETHREADSYNC)pInterface->pCallbacks;
1357
1358 /* Do basic checks. */
1359 AssertMsgReturn( (pInterfaceThreadSync->cbSize == sizeof(VDINTERFACETHREADSYNC))
1360 && (pInterfaceThreadSync->enmInterface == VDINTERFACETYPE_THREADSYNC),
1361 ("A non thread synchronization callback table attached to a thread synchronization interface descriptor\n"), NULL);
1362
1363 return pInterfaceThreadSync;
1364}
1365
1366/** @name Configuration interface key handling flags.
1367 * @{
1368 */
1369/** Mandatory config key. Not providing a value for this key will cause
1370 * the backend to fail. */
1371#define VD_CFGKEY_MANDATORY RT_BIT(0)
1372/** Expert config key. Not showing it by default in the GUI is is probably
1373 * a good idea, as the average user won't understand it easily. */
1374#define VD_CFGKEY_EXPERT RT_BIT(1)
1375/** @}*/
1376
1377
1378/**
1379 * Configuration value type for configuration information interface.
1380 */
1381typedef enum VDCFGVALUETYPE
1382{
1383 /** Integer value. */
1384 VDCFGVALUETYPE_INTEGER = 1,
1385 /** String value. */
1386 VDCFGVALUETYPE_STRING,
1387 /** Bytestring value. */
1388 VDCFGVALUETYPE_BYTES
1389} VDCFGVALUETYPE;
1390
1391
1392/**
1393 * Structure describing configuration keys required/supported by a backend
1394 * through the config interface.
1395 */
1396typedef struct VDCONFIGINFO
1397{
1398 /** Key name of the configuration. */
1399 const char *pszKey;
1400 /** Pointer to default value (descriptor). NULL if no useful default value
1401 * can be specified. */
1402 const char *pszDefaultValue;
1403 /** Value type for this key. */
1404 VDCFGVALUETYPE enmValueType;
1405 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
1406 uint64_t uKeyFlags;
1407} VDCONFIGINFO;
1408
1409/** Pointer to structure describing configuration keys. */
1410typedef VDCONFIGINFO *PVDCONFIGINFO;
1411
1412/** Pointer to const structure describing configuration keys. */
1413typedef const VDCONFIGINFO *PCVDCONFIGINFO;
1414
1415/**
1416 * Data structure for returning a list of backend capabilities.
1417 */
1418typedef struct VDBACKENDINFO
1419{
1420 /** Name of the backend. Must be unique even with case insensitive comparison. */
1421 const char *pszBackend;
1422 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
1423 uint64_t uBackendCaps;
1424 /** Pointer to a NULL-terminated array of strings, containing the supported
1425 * file extensions. Note that some backends do not work on files, so this
1426 * pointer may just contain NULL. */
1427 const char * const *papszFileExtensions;
1428 /** Pointer to an array of structs describing each supported config key.
1429 * Terminated by a NULL config key. Note that some backends do not support
1430 * the configuration interface, so this pointer may just contain NULL.
1431 * Mandatory if the backend sets VD_CAP_CONFIG. */
1432 PCVDCONFIGINFO paConfigInfo;
1433 /** Returns a human readable hard disk location string given a
1434 * set of hard disk configuration keys. The returned string is an
1435 * equivalent of the full file path for image-based hard disks.
1436 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
1437 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
1438 /** Returns a human readable hard disk name string given a
1439 * set of hard disk configuration keys. The returned string is an
1440 * equivalent of the file name part in the full file path for
1441 * image-based hard disks. Mandatory for backends with no
1442 * VD_CAP_FILE and NULL otherwise. */
1443 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
1444} VDBACKENDINFO, *PVDBACKENDINFO;
1445
1446
1447/** Forward declaration. Only visible in the VBoxHDD module. */
1448/** I/O context */
1449typedef struct VDIOCTX *PVDIOCTX;
1450/** Storage backend handle. */
1451typedef struct VDIOSTORAGE *PVDIOSTORAGE;
1452/** Pointer to a storage backend handle. */
1453typedef PVDIOSTORAGE *PPVDIOSTORAGE;
1454
1455/**
1456 * Completion callback for meta/userdata reads or writes.
1457 *
1458 * @return VBox status code.
1459 * VINF_SUCCESS if everything was successful and the transfer can continue.
1460 * VERR_VD_ASYNC_IO_IN_PROGRESS if there is another data transfer pending.
1461 * @param pvBackendData The opaque backend data.
1462 * @param pIoCtx I/O context associated with this request.
1463 * @param pvUser Opaque user data passed during a read/write request.
1464 * @param rcReq Status code for the completed request.
1465 */
1466typedef DECLCALLBACK(int) FNVDXFERCOMPLETED(void *pvBackendData, PVDIOCTX pIoCtx, void *pvUser, int rcReq);
1467/** Pointer to FNVDXFERCOMPLETED() */
1468typedef FNVDXFERCOMPLETED *PFNVDXFERCOMPLETED;
1469
1470/** Metadata transfer handle. */
1471typedef struct VDMETAXFER *PVDMETAXFER;
1472/** Pointer to a metadata transfer handle. */
1473typedef PVDMETAXFER *PPVDMETAXFER;
1474
1475
1476/**
1477 * Support interface for I/O
1478 *
1479 * Per-image. Required.
1480 */
1481typedef struct VDINTERFACEIO
1482{
1483 /**
1484 * Size of the I/O interface.
1485 */
1486 uint32_t cbSize;
1487
1488 /**
1489 * Interface type.
1490 */
1491 VDINTERFACETYPE enmInterface;
1492
1493 /**
1494 * Open callback
1495 *
1496 * @return VBox status code.
1497 * @param pvUser The opaque data passed on container creation.
1498 * @param pszLocation Name of the location to open.
1499 * @param uOpenFlags Flags for opening the backend.
1500 * See VD_INTERFACEASYNCIO_OPEN_FLAGS_* #defines
1501 * @param ppStorage Where to store the storage handle.
1502 */
1503 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation,
1504 unsigned uOpenFlags, PPVDIOSTORAGE ppStorage));
1505
1506 /**
1507 * Close callback.
1508 *
1509 * @return VBox status code.
1510 * @param pvUser The opaque data passed on container creation.
1511 * @param pStorage The storage handle to close.
1512 */
1513 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, PVDIOSTORAGE pStorage));
1514
1515 /**
1516 * Returns the size of the opened storage backend.
1517 *
1518 * @return VBox status code.
1519 * @param pvUser The opaque data passed on container creation.
1520 * @param pStorage The storage handle to get the size from.
1521 * @param pcbSize Where to store the size of the storage backend.
1522 */
1523 DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, PVDIOSTORAGE pStorage,
1524 uint64_t *pcbSize));
1525
1526 /**
1527 * Sets the size of the opened storage backend if possible.
1528 *
1529 * @return VBox status code.
1530 * @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
1531 * @param pvUser The opaque data passed on container creation.
1532 * @param pStorage The storage handle.
1533 * @param cbSize The new size of the image.
1534 */
1535 DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, PVDIOSTORAGE pStorage,
1536 uint64_t cbSize));
1537
1538 /**
1539 * Synchronous write callback.
1540 *
1541 * @return VBox status code.
1542 * @param pvUser The opaque data passed on container creation.
1543 * @param pStorage The storage handle to use.
1544 * @param uOffset The offset to start from.
1545 * @param cbWrite How many bytes to write.
1546 * @param pvBuf Pointer to the bits need to be written.
1547 * @param pcbWritten Where to store how many bytes where actually written.
1548 *
1549 * @notes Do not use in code called from the async read/write entry points in the backends.
1550 * This should be only used during open/close of images and for the support functions
1551 * which are not called while a VM is running (pfnCompact).
1552 */
1553 DECLR3CALLBACKMEMBER(int, pfnWriteSync, (void *pvUser, PVDIOSTORAGE pStorage, uint64_t uOffset,
1554 size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
1555
1556 /**
1557 * Synchronous read callback.
1558 *
1559 * @return VBox status code.
1560 * @param pvUser The opaque data passed on container creation.
1561 * @param pStorage The storage handle to use.
1562 * @param uOffset The offset to start from.
1563 * @param cbRead How many bytes to read.
1564 * @param pvBuf Where to store the read bits.
1565 * @param pcbRead Where to store how many bytes where actually read.
1566 *
1567 * @notes See pfnWriteSync()
1568 */
1569 DECLR3CALLBACKMEMBER(int, pfnReadSync, (void *pvUser, PVDIOSTORAGE pStorage, uint64_t uOffset,
1570 size_t cbRead, void *pvBuf, size_t *pcbRead));
1571
1572 /**
1573 * Flush data to the storage backend.
1574 *
1575 * @return VBox status code.
1576 * @param pvUser The opaque data passed on container creation.
1577 * @param pStorage The storage handle to flush.
1578 *
1579 * @notes See pfnWriteSync()
1580 */
1581 DECLR3CALLBACKMEMBER(int, pfnFlushSync, (void *pvUser, PVDIOSTORAGE pStorage));
1582
1583 /**
1584 * Initiate a asynchronous read request for user data.
1585 *
1586 * @return VBox status code.
1587 * @param pvUser The opaque user data passed on container creation.
1588 * @param pStorage The storage handle.
1589 * @param uOffset The offset to start reading from.
1590 * @param pIoCtx I/O context passed in VDAsyncRead/Write.
1591 * @param cbRead How many bytes to read.
1592 */
1593 DECLR3CALLBACKMEMBER(int, pfnReadUserAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1594 uint64_t uOffset, PVDIOCTX pIoCtx,
1595 size_t cbRead));
1596
1597 /**
1598 * Initiate a asynchronous write request for user data.
1599 *
1600 * @return VBox status code.
1601 * @param pvUser The opaque user data passed on container creation.
1602 * @param pStorage The storage handle.
1603 * @param uOffset The offset to start writing to.
1604 * @param pIoCtx I/O context passed in VDAsyncRead/Write
1605 * @param cbWrite How many bytes to write.
1606 * @param pfnCompleted Completion callback.
1607 * @param pvCompleteUser Opaque user data passed in the completion callback.
1608 */
1609 DECLR3CALLBACKMEMBER(int, pfnWriteUserAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1610 uint64_t uOffset, PVDIOCTX pIoCtx,
1611 size_t cbWrite,
1612 PFNVDXFERCOMPLETED pfnComplete,
1613 void *pvCompleteUser));
1614
1615 /**
1616 * Reads metadata asynchronously from storage.
1617 * The current I/O context will be halted.
1618 *
1619 * @returns VBox status code.
1620 * @param pvUser The opaque user data passed on container creation.
1621 * @param pStorage The storage handle.
1622 * @param uOffset Offset to start reading from.
1623 * @param pvBuf Where to store the data.
1624 * @param cbRead How many bytes to read.
1625 * @param pIoCtx The I/O context which triggered the read.
1626 * @param ppMetaXfer Where to store the metadata transfer handle on success.
1627 * @param pfnCompleted Completion callback.
1628 * @param pvCompleteUser Opaque user data passed in the completion callback.
1629 */
1630 DECLR3CALLBACKMEMBER(int, pfnReadMetaAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1631 uint64_t uOffset, void *pvBuf,
1632 size_t cbRead, PVDIOCTX pIoCtx,
1633 PPVDMETAXFER ppMetaXfer,
1634 PFNVDXFERCOMPLETED pfnComplete,
1635 void *pvCompleteUser));
1636
1637 /**
1638 * Writes metadata asynchronously to storage.
1639 *
1640 * @returns VBox status code.
1641 * @param pvUser The opaque user data passed on container creation.
1642 * @param pStorage The storage handle.
1643 * @param uOffset Offset to start writing to.
1644 * @param pvBuf Written data.
1645 * @param cbWrite How many bytes to write.
1646 * @param pIoCtx The I/O context which triggered the write.
1647 * @param pfnCompleted Completion callback.
1648 * @param pvCompleteUser Opaque user data passed in the completion callback.
1649 */
1650 DECLR3CALLBACKMEMBER(int, pfnWriteMetaAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1651 uint64_t uOffset, void *pvBuf,
1652 size_t cbWrite, PVDIOCTX pIoCtx,
1653 PFNVDXFERCOMPLETED pfnComplete,
1654 void *pvCompleteUser));
1655
1656 /**
1657 * Releases a metadata transfer handle.
1658 * The free space can be used for another transfer.
1659 *
1660 * @returns nothing.
1661 * @param pvUser The opaque user data passed on container creation.
1662 * @param pMetaXfer The metadata transfer handle to release.
1663 */
1664 DECLR3CALLBACKMEMBER(void, pfnMetaXferRelease, (void *pvUser, PVDMETAXFER pMetaXfer));
1665
1666 /**
1667 * Initiates a async flush request.
1668 *
1669 * @return VBox status code.
1670 * @param pvUser The opaque data passed on container creation.
1671 * @param pStorage The storage handle to flush.
1672 * @param pIoCtx I/O context which triggered the flush.
1673 * @param pfnCompleted Completion callback.
1674 * @param pvCompleteUser Opaque user data passed in the completion callback.
1675 */
1676 DECLR3CALLBACKMEMBER(int, pfnFlushAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1677 PVDIOCTX pIoCtx,
1678 PFNVDXFERCOMPLETED pfnComplete,
1679 void *pvCompleteUser));
1680
1681 /**
1682 * Copies a buffer into the I/O context.
1683 *
1684 * @return Number of bytes copied.
1685 * @param pvUser The opaque user data passed on container creation.
1686 * @param pIoCtx I/O context to copy the data to.
1687 * @param pvBuf Buffer to copy.
1688 * @param cbBuf Number of bytes to copy.
1689 */
1690 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyTo, (void *pvUser, PVDIOCTX pIoCtx,
1691 void *pvBuf, size_t cbBuf));
1692
1693 /**
1694 * Copies data from the I/O context into a buffer.
1695 *
1696 * @return Number of bytes copied.
1697 * @param pvUser The opaque user data passed on container creation.
1698 * @param pIoCtx I/O context to copy the data from.
1699 * @param pvBuf Destination buffer.
1700 * @param cbBuf Number of bytes to copy.
1701 */
1702 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyFrom, (void *pvUser, PVDIOCTX pIoCtx,
1703 void *pvBuf, size_t cbBuf));
1704
1705 /**
1706 * Sets the buffer of the given context to a specific byte.
1707 *
1708 * @return Number of bytes set.
1709 * @param pvUser The opaque user data passed on container creation.
1710 * @param pIoCtx I/O context to copy the data from.
1711 * @param ch The byte to set.
1712 * @param cbSet Number of bytes to set.
1713 */
1714 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSet, (void *pvUser, PVDIOCTX pIoCtx,
1715 int ch, size_t cbSet));
1716
1717 /**
1718 * Marks the given number of bytes as completed and continues the I/O context.
1719 *
1720 * @returns nothing.
1721 * @param pvUser The opaque user data passed on container creation.
1722 * @param pIoCtx The I/O context.
1723 * @param cbCompleted Number of bytes completed.
1724 */
1725 DECLR3CALLBACKMEMBER(void, pfnIoCtxCompleted, (void *pvUser, PVDIOCTX pIoCtx,
1726 size_t cbCompleted));
1727} VDINTERFACEIO, *PVDINTERFACEIO;
1728
1729/**
1730 * Get async I/O interface from opaque callback table.
1731 *
1732 * @return Pointer to the callback table.
1733 * @param pInterface Pointer to the interface descriptor.
1734 */
1735DECLINLINE(PVDINTERFACEIO) VDGetInterfaceIO(PVDINTERFACE pInterface)
1736{
1737 PVDINTERFACEIO pInterfaceIO;
1738
1739 /* Check that the interface descriptor is a async I/O interface. */
1740 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_IO)
1741 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1742 ("Not an I/O interface"), NULL);
1743
1744 pInterfaceIO = (PVDINTERFACEIO)pInterface->pCallbacks;
1745
1746 /* Do basic checks. */
1747 AssertMsgReturn( (pInterfaceIO->cbSize == sizeof(VDINTERFACEIO))
1748 && (pInterfaceIO->enmInterface == VDINTERFACETYPE_IO),
1749 ("A non I/O callback table attached to a I/O interface descriptor\n"), NULL);
1750
1751 return pInterfaceIO;
1752}
1753
1754/**
1755 * VBox HDD Container main structure.
1756 */
1757/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
1758struct VBOXHDD;
1759typedef struct VBOXHDD VBOXHDD;
1760typedef VBOXHDD *PVBOXHDD;
1761
1762/**
1763 * Request completion callback for the async read/write API.
1764 */
1765typedef void (FNVDASYNCTRANSFERCOMPLETE) (void *pvUser1, void *pvUser2, int rcReq);
1766/** Pointer to a transfer compelte callback. */
1767typedef FNVDASYNCTRANSFERCOMPLETE *PFNVDASYNCTRANSFERCOMPLETE;
1768
1769/**
1770 * Initializes HDD backends.
1771 *
1772 * @returns VBox status code.
1773 */
1774VBOXDDU_DECL(int) VDInit(void);
1775
1776/**
1777 * Destroys loaded HDD backends.
1778 *
1779 * @returns VBox status code.
1780 */
1781VBOXDDU_DECL(int) VDShutdown(void);
1782
1783/**
1784 * Lists all HDD backends and their capabilities in a caller-provided buffer.
1785 *
1786 * @return VBox status code.
1787 * VERR_BUFFER_OVERFLOW if not enough space is passed.
1788 * @param cEntriesAlloc Number of list entries available.
1789 * @param pEntries Pointer to array for the entries.
1790 * @param pcEntriesUsed Number of entries returned.
1791 */
1792VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
1793 unsigned *pcEntriesUsed);
1794
1795/**
1796 * Lists the capablities of a backend indentified by its name.
1797 *
1798 * @return VBox status code.
1799 * @param pszBackend The backend name (case insensitive).
1800 * @param pEntries Pointer to an entry.
1801 */
1802VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
1803
1804/**
1805 * Allocates and initializes an empty HDD container.
1806 * No image files are opened.
1807 *
1808 * @return VBox status code.
1809 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1810 * @param ppDisk Where to store the reference to HDD container.
1811 */
1812VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, PVBOXHDD *ppDisk);
1813
1814/**
1815 * Destroys HDD container.
1816 * If container has opened image files they will be closed.
1817 *
1818 * @param pDisk Pointer to HDD container.
1819 */
1820VBOXDDU_DECL(void) VDDestroy(PVBOXHDD pDisk);
1821
1822/**
1823 * Try to get the backend name which can use this image.
1824 *
1825 * @return VBox status code.
1826 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1827 * @param pszFilename Name of the image file for which the backend is queried.
1828 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
1829 * The returned pointer must be freed using RTStrFree().
1830 */
1831VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, const char *pszFilename, char **ppszFormat);
1832
1833/**
1834 * Opens an image file.
1835 *
1836 * The first opened image file in HDD container must have a base image type,
1837 * others (next opened images) must be differencing or undo images.
1838 * Linkage is checked for differencing image to be consistent with the previously opened image.
1839 * When another differencing image is opened and the last image was opened in read/write access
1840 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
1841 * other processes to use images in read-only mode too.
1842 *
1843 * Note that the image is opened in read-only mode if a read/write open is not possible.
1844 * Use VDIsReadOnly to check open mode.
1845 *
1846 * @return VBox status code.
1847 * @param pDisk Pointer to HDD container.
1848 * @param pszBackend Name of the image file backend to use (case insensitive).
1849 * @param pszFilename Name of the image file to open.
1850 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1851 * @param pVDIfsImage Pointer to the per-image VD interface list.
1852 */
1853VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
1854 const char *pszFilename, unsigned uOpenFlags,
1855 PVDINTERFACE pVDIfsImage);
1856
1857/**
1858 * Creates and opens a new base image file.
1859 *
1860 * @return VBox status code.
1861 * @param pDisk Pointer to HDD container.
1862 * @param pszBackend Name of the image file backend to use (case insensitive).
1863 * @param pszFilename Name of the image file to create.
1864 * @param cbSize Image size in bytes.
1865 * @param uImageFlags Flags specifying special image features.
1866 * @param pszComment Pointer to image comment. NULL is ok.
1867 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
1868 * @param pLCHSGeometry Pointer to logical disk geometry <= (x,255,63). Not NULL.
1869 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1870 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1871 * @param pVDIfsImage Pointer to the per-image VD interface list.
1872 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1873 */
1874VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
1875 const char *pszFilename, uint64_t cbSize,
1876 unsigned uImageFlags, const char *pszComment,
1877 PCPDMMEDIAGEOMETRY pPCHSGeometry,
1878 PCPDMMEDIAGEOMETRY pLCHSGeometry,
1879 PCRTUUID pUuid, unsigned uOpenFlags,
1880 PVDINTERFACE pVDIfsImage,
1881 PVDINTERFACE pVDIfsOperation);
1882
1883/**
1884 * Creates and opens a new differencing image file in HDD container.
1885 * See comments for VDOpen function about differencing images.
1886 *
1887 * @return VBox status code.
1888 * @param pDisk Pointer to HDD container.
1889 * @param pszBackend Name of the image file backend to use (case insensitive).
1890 * @param pszFilename Name of the differencing image file to create.
1891 * @param uImageFlags Flags specifying special image features.
1892 * @param pszComment Pointer to image comment. NULL is ok.
1893 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1894 * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically.
1895 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1896 * @param pVDIfsImage Pointer to the per-image VD interface list.
1897 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1898 */
1899VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
1900 const char *pszFilename, unsigned uImageFlags,
1901 const char *pszComment, PCRTUUID pUuid,
1902 PCRTUUID pParentUuid, unsigned uOpenFlags,
1903 PVDINTERFACE pVDIfsImage,
1904 PVDINTERFACE pVDIfsOperation);
1905
1906/**
1907 * Merges two images (not necessarily with direct parent/child relationship).
1908 * As a side effect the source image and potentially the other images which
1909 * are also merged to the destination are deleted from both the disk and the
1910 * images in the HDD container.
1911 *
1912 * @return VBox status code.
1913 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1914 * @param pDisk Pointer to HDD container.
1915 * @param nImageFrom Image number to merge from, counts from 0. 0 is always base image of container.
1916 * @param nImageTo Image number to merge to, counts from 0. 0 is always base image of container.
1917 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1918 */
1919VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
1920 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
1921
1922/**
1923 * Copies an image from one HDD container to another.
1924 * The copy is opened in the target HDD container.
1925 * It is possible to convert between different image formats, because the
1926 * backend for the destination may be different from the source.
1927 * If both the source and destination reference the same HDD container,
1928 * then the image is moved (by copying/deleting or renaming) to the new location.
1929 * The source container is unchanged if the move operation fails, otherwise
1930 * the image at the new location is opened in the same way as the old one was.
1931 *
1932 * @note The read/write accesses across disks are not synchronized, just the
1933 * accesses to each disk. Once there is a use case which requires a defined
1934 * read/write behavior in this situation this needs to be extended.
1935 *
1936 * @return VBox status code.
1937 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1938 * @param pDiskFrom Pointer to source HDD container.
1939 * @param nImage Image number, counts from 0. 0 is always base image of container.
1940 * @param pDiskTo Pointer to destination HDD container.
1941 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
1942 * @param pszFilename New name of the image (may be NULL to specify that the
1943 * copy destination is the destination container, or
1944 * if pDiskFrom == pDiskTo, i.e. when moving).
1945 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
1946 * @param cbSize New image size (0 means leave unchanged).
1947 * @param uImageFlags Flags specifying special destination image features.
1948 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
1949 * This parameter is used if and only if a true copy is created.
1950 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
1951 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1952 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
1953 * destination image.
1954 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
1955 * for the destination operation.
1956 */
1957VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
1958 const char *pszBackend, const char *pszFilename,
1959 bool fMoveByRename, uint64_t cbSize,
1960 unsigned uImageFlags, PCRTUUID pDstUuid,
1961 PVDINTERFACE pVDIfsOperation,
1962 PVDINTERFACE pDstVDIfsImage,
1963 PVDINTERFACE pDstVDIfsOperation);
1964
1965/**
1966 * Optimizes the storage consumption of an image. Typically the unused blocks
1967 * have to be wiped with zeroes to achieve a substantial reduced storage use.
1968 * Another optimization done is reordering the image blocks, which can provide
1969 * a significant performance boost, as reads and writes tend to use less random
1970 * file offsets.
1971 *
1972 * @note Compaction is treated as a single operation with regard to thread
1973 * synchronization, which means that it potentially blocks other activities for
1974 * a long time. The complexity of compaction would grow even more if concurrent
1975 * accesses have to be handled.
1976 *
1977 * @return VBox status code.
1978 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1979 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
1980 * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but
1981 * this isn't supported yet.
1982 * @param pDisk Pointer to HDD container.
1983 * @param nImage Image number, counts from 0. 0 is always base image of container.
1984 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1985 */
1986VBOXDDU_DECL(int) VDCompact(PVBOXHDD pDisk, unsigned nImage,
1987 PVDINTERFACE pVDIfsOperation);
1988
1989/**
1990 * Closes the last opened image file in HDD container.
1991 * If previous image file was opened in read-only mode (the normal case) and
1992 * the last opened image is in read-write mode then the previous image will be
1993 * reopened in read/write mode.
1994 *
1995 * @return VBox status code.
1996 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1997 * @param pDisk Pointer to HDD container.
1998 * @param fDelete If true, delete the image from the host disk.
1999 */
2000VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
2001
2002/**
2003 * Closes all opened image files in HDD container.
2004 *
2005 * @return VBox status code.
2006 * @param pDisk Pointer to HDD container.
2007 */
2008VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
2009
2010/**
2011 * Read data from virtual HDD.
2012 *
2013 * @return VBox status code.
2014 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
2015 * @param pDisk Pointer to HDD container.
2016 * @param uOffset Offset of first reading byte from start of disk.
2017 * Must be aligned to a sector boundary.
2018 * @param pvBuf Pointer to buffer for reading data.
2019 * @param cbRead Number of bytes to read.
2020 * Must be aligned to a sector boundary.
2021 */
2022VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
2023
2024/**
2025 * Write data to virtual HDD.
2026 *
2027 * @return VBox status code.
2028 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
2029 * @param pDisk Pointer to HDD container.
2030 * @param uOffset Offset of first writing byte from start of disk.
2031 * Must be aligned to a sector boundary.
2032 * @param pvBuf Pointer to buffer for writing data.
2033 * @param cbWrite Number of bytes to write.
2034 * Must be aligned to a sector boundary.
2035 */
2036VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
2037
2038/**
2039 * Make sure the on disk representation of a virtual HDD is up to date.
2040 *
2041 * @return VBox status code.
2042 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
2043 * @param pDisk Pointer to HDD container.
2044 */
2045VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
2046
2047/**
2048 * Get number of opened images in HDD container.
2049 *
2050 * @return Number of opened images for HDD container. 0 if no images have been opened.
2051 * @param pDisk Pointer to HDD container.
2052 */
2053VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
2054
2055/**
2056 * Get read/write mode of HDD container.
2057 *
2058 * @return Virtual disk ReadOnly status.
2059 * @return true if no image is opened in HDD container.
2060 * @param pDisk Pointer to HDD container.
2061 */
2062VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
2063
2064/**
2065 * Get total capacity of an image in HDD container.
2066 *
2067 * @return Virtual disk size in bytes.
2068 * @return 0 if image with specified number was not opened.
2069 * @param pDisk Pointer to HDD container.
2070 * @param nImage Image number, counts from 0. 0 is always base image of container.
2071 */
2072VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
2073
2074/**
2075 * Get total file size of an image in HDD container.
2076 *
2077 * @return Virtual disk size in bytes.
2078 * @return 0 if image with specified number was not opened.
2079 * @param pDisk Pointer to HDD container.
2080 * @param nImage Image number, counts from 0. 0 is always base image of container.
2081 */
2082VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
2083
2084/**
2085 * Get virtual disk PCHS geometry of an image in HDD container.
2086 *
2087 * @return VBox status code.
2088 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2089 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
2090 * @param pDisk Pointer to HDD container.
2091 * @param nImage Image number, counts from 0. 0 is always base image of container.
2092 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
2093 */
2094VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
2095 PPDMMEDIAGEOMETRY pPCHSGeometry);
2096
2097/**
2098 * Store virtual disk PCHS geometry of an image in HDD container.
2099 *
2100 * @return VBox status code.
2101 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2102 * @param pDisk Pointer to HDD container.
2103 * @param nImage Image number, counts from 0. 0 is always base image of container.
2104 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
2105 */
2106VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
2107 PCPDMMEDIAGEOMETRY pPCHSGeometry);
2108
2109/**
2110 * Get virtual disk LCHS geometry of an image in HDD container.
2111 *
2112 * @return VBox status code.
2113 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2114 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
2115 * @param pDisk Pointer to HDD container.
2116 * @param nImage Image number, counts from 0. 0 is always base image of container.
2117 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
2118 */
2119VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
2120 PPDMMEDIAGEOMETRY pLCHSGeometry);
2121
2122/**
2123 * Store virtual disk LCHS geometry of an image in HDD container.
2124 *
2125 * @return VBox status code.
2126 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2127 * @param pDisk Pointer to HDD container.
2128 * @param nImage Image number, counts from 0. 0 is always base image of container.
2129 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
2130 */
2131VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
2132 PCPDMMEDIAGEOMETRY pLCHSGeometry);
2133
2134/**
2135 * Get version of image in HDD container.
2136 *
2137 * @return VBox status code.
2138 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2139 * @param pDisk Pointer to HDD container.
2140 * @param nImage Image number, counts from 0. 0 is always base image of container.
2141 * @param puVersion Where to store the image version.
2142 */
2143VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
2144 unsigned *puVersion);
2145
2146/**
2147 * List the capabilities of image backend in HDD container.
2148 *
2149 * @return VBox status code.
2150 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2151 * @param pDisk Pointer to the HDD container.
2152 * @param nImage Image number, counts from 0. 0 is always base image of container.
2153 * @param pbackendInfo Where to store the backend information.
2154 */
2155VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
2156 PVDBACKENDINFO pBackendInfo);
2157
2158/**
2159 * Get flags of image in HDD container.
2160 *
2161 * @return VBox status code.
2162 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2163 * @param pDisk Pointer to HDD container.
2164 * @param nImage Image number, counts from 0. 0 is always base image of container.
2165 * @param puImageFlags Where to store the image flags.
2166 */
2167VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
2168
2169/**
2170 * Get open flags of image in HDD container.
2171 *
2172 * @return VBox status code.
2173 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2174 * @param pDisk Pointer to HDD container.
2175 * @param nImage Image number, counts from 0. 0 is always base image of container.
2176 * @param puOpenFlags Where to store the image open flags.
2177 */
2178VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
2179 unsigned *puOpenFlags);
2180
2181/**
2182 * Set open flags of image in HDD container.
2183 * This operation may cause file locking changes and/or files being reopened.
2184 * Note that in case of unrecoverable error all images in HDD container will be closed.
2185 *
2186 * @return VBox status code.
2187 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2188 * @param pDisk Pointer to HDD container.
2189 * @param nImage Image number, counts from 0. 0 is always base image of container.
2190 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
2191 */
2192VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
2193 unsigned uOpenFlags);
2194
2195/**
2196 * Get base filename of image in HDD container. Some image formats use
2197 * other filenames as well, so don't use this for anything but informational
2198 * purposes.
2199 *
2200 * @return VBox status code.
2201 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2202 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
2203 * @param pDisk Pointer to HDD container.
2204 * @param nImage Image number, counts from 0. 0 is always base image of container.
2205 * @param pszFilename Where to store the image file name.
2206 * @param cbFilename Size of buffer pszFilename points to.
2207 */
2208VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
2209 char *pszFilename, unsigned cbFilename);
2210
2211/**
2212 * Get the comment line of image in HDD container.
2213 *
2214 * @return VBox status code.
2215 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2216 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
2217 * @param pDisk Pointer to HDD container.
2218 * @param nImage Image number, counts from 0. 0 is always base image of container.
2219 * @param pszComment Where to store the comment string of image. NULL is ok.
2220 * @param cbComment The size of pszComment buffer. 0 is ok.
2221 */
2222VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
2223 char *pszComment, unsigned cbComment);
2224
2225/**
2226 * Changes the comment line of image in HDD container.
2227 *
2228 * @return VBox status code.
2229 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2230 * @param pDisk Pointer to HDD container.
2231 * @param nImage Image number, counts from 0. 0 is always base image of container.
2232 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
2233 */
2234VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
2235 const char *pszComment);
2236
2237/**
2238 * Get UUID of image in HDD container.
2239 *
2240 * @return VBox status code.
2241 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2242 * @param pDisk Pointer to HDD container.
2243 * @param nImage Image number, counts from 0. 0 is always base image of container.
2244 * @param pUuid Where to store the image UUID.
2245 */
2246VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
2247
2248/**
2249 * Set the image's UUID. Should not be used by normal applications.
2250 *
2251 * @return VBox status code.
2252 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2253 * @param pDisk Pointer to HDD container.
2254 * @param nImage Image number, counts from 0. 0 is always base image of container.
2255 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
2256 */
2257VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
2258
2259/**
2260 * Get last modification UUID of image in HDD container.
2261 *
2262 * @return VBox status code.
2263 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2264 * @param pDisk Pointer to HDD container.
2265 * @param nImage Image number, counts from 0. 0 is always base image of container.
2266 * @param pUuid Where to store the image modification UUID.
2267 */
2268VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
2269 PRTUUID pUuid);
2270
2271/**
2272 * Set the image's last modification UUID. Should not be used by normal applications.
2273 *
2274 * @return VBox status code.
2275 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2276 * @param pDisk Pointer to HDD container.
2277 * @param nImage Image number, counts from 0. 0 is always base image of container.
2278 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
2279 */
2280VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
2281 PCRTUUID pUuid);
2282
2283/**
2284 * Get parent UUID of image in HDD container.
2285 *
2286 * @return VBox status code.
2287 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2288 * @param pDisk Pointer to HDD container.
2289 * @param nImage Image number, counts from 0. 0 is always base image of the container.
2290 * @param pUuid Where to store the parent image UUID.
2291 */
2292VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
2293 PRTUUID pUuid);
2294
2295/**
2296 * Set the image's parent UUID. Should not be used by normal applications.
2297 *
2298 * @return VBox status code.
2299 * @param pDisk Pointer to HDD container.
2300 * @param nImage Image number, counts from 0. 0 is always base image of container.
2301 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
2302 */
2303VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
2304 PCRTUUID pUuid);
2305
2306
2307/**
2308 * Debug helper - dumps all opened images in HDD container into the log file.
2309 *
2310 * @param pDisk Pointer to HDD container.
2311 */
2312VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
2313
2314
2315/**
2316 * Query if asynchronous operations are supported for this disk.
2317 *
2318 * @return VBox status code.
2319 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2320 * @param pDisk Pointer to the HDD container.
2321 * @param nImage Image number, counts from 0. 0 is always base image of container.
2322 * @param pfAIOSupported Where to store if async IO is supported.
2323 */
2324VBOXDDU_DECL(int) VDImageIsAsyncIOSupported(PVBOXHDD pDisk, unsigned nImage, bool *pfAIOSupported);
2325
2326
2327/**
2328 * Start a asynchronous read request.
2329 *
2330 * @return VBox status code.
2331 * @param pDisk Pointer to the HDD container.
2332 * @param uOffset The offset of the virtual disk to read from.
2333 * @param cbRead How many bytes to read.
2334 * @param paSeg Pointer to an array of segments.
2335 * @param cSeg Number of segments in the array.
2336 * @param pfnComplete Completion callback.
2337 * @param pvUser User data which is passed on completion
2338 */
2339VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
2340 PCRTSGSEG paSeg, unsigned cSeg,
2341 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
2342 void *pvUser1, void *pvUser2);
2343
2344
2345/**
2346 * Start a asynchronous write request.
2347 *
2348 * @return VBox status code.
2349 * @param pDisk Pointer to the HDD container.
2350 * @param uOffset The offset of the virtual disk to write to.
2351 * @param cbWrtie How many bytes to write.
2352 * @param paSeg Pointer to an array of segments.
2353 * @param cSeg Number of segments in the array.
2354 * @param pfnComplete Completion callback.
2355 * @param pvUser User data which is passed on completion.
2356 */
2357VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
2358 PCRTSGSEG paSeg, unsigned cSeg,
2359 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
2360 void *pvUser1, void *pvUser2);
2361
2362
2363/**
2364 * Start a asynchronous flush request.
2365 *
2366 * @return VBox status code.
2367 * @param pDisk Pointer to the HDD container.
2368 * @param pfnComplete Completion callback.
2369 * @param pvUser User data which is passed on completion.
2370 */
2371VBOXDDU_DECL(int) VDAsyncFlush(PVBOXHDD pDisk,
2372 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
2373 void *pvUser1, void *pvUser2);
2374RT_C_DECLS_END
2375
2376/** @} */
2377
2378#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette