VirtualBox

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

Last change on this file since 31098 was 31098, checked in by vboxsync, 15 years ago

iSCSI: First part for async I/O. Move I/O into a separate thread and handle NOP-in requests properly to prevent disconnects if the guest isn't doing any I/O.

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

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