VirtualBox

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

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

Storage: Convert the backends to use the interface for I/O rather than using the RTFile* API directly.

For a VM the PDMAsyncCompletion is used now as the I/O layer (fixing the I/O load problems).
Still disabled by default until it was tested on all supported platforms to not risk corruption
of images. To enable compile with VBOX_WITH_NEW_IO_CODE set.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.7 KB
Line 
1/** @file
2 * VBox HDD Container API.
3 */
4
5/*
6 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_VD_h
31#define ___VBox_VD_h
32
33#include <iprt/assert.h>
34#include <iprt/string.h>
35#include <iprt/mem.h>
36#include <VBox/cdefs.h>
37#include <VBox/types.h>
38#include <VBox/err.h>
39#include <VBox/pdmifs.h>
40/** @todo remove this dependency, using PFNVMPROGRESS outside VMM is *WRONG*. */
41#include <VBox/vmapi.h>
42
43RT_C_DECLS_BEGIN
44
45#ifdef IN_RING0
46# error "There are no VBox HDD Container APIs available in Ring-0 Host Context!"
47#endif
48
49/** @defgroup grp_vd VBox HDD Container
50 * @{
51 */
52
53/** Current VMDK image version. */
54#define VMDK_IMAGE_VERSION (0x0001)
55
56/** Current VDI image major version. */
57#define VDI_IMAGE_VERSION_MAJOR (0x0001)
58/** Current VDI image minor version. */
59#define VDI_IMAGE_VERSION_MINOR (0x0001)
60/** Current VDI image version. */
61#define VDI_IMAGE_VERSION ((VDI_IMAGE_VERSION_MAJOR << 16) | VDI_IMAGE_VERSION_MINOR)
62
63/** Get VDI major version from combined version. */
64#define VDI_GET_VERSION_MAJOR(uVer) ((uVer) >> 16)
65/** Get VDI minor version from combined version. */
66#define VDI_GET_VERSION_MINOR(uVer) ((uVer) & 0xffff)
67
68/** Placeholder for specifying the last opened image. */
69#define VD_LAST_IMAGE 0xffffffffU
70
71/** @name VBox HDD container image flags
72 * @{
73 */
74/** No flags. */
75#define VD_IMAGE_FLAGS_NONE (0)
76/** Fixed image. */
77#define VD_IMAGE_FLAGS_FIXED (0x10000)
78/** Diff image. Mutually exclusive with fixed image. */
79#define VD_IMAGE_FLAGS_DIFF (0x20000)
80/** VMDK: Split image into 2GB extents. */
81#define VD_VMDK_IMAGE_FLAGS_SPLIT_2G (0x0001)
82/** VMDK: Raw disk image (giving access to a number of host partitions). */
83#define VD_VMDK_IMAGE_FLAGS_RAWDISK (0x0002)
84/** VMDK: stream optimized image, read only. */
85#define VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED (0x0004)
86/** VMDK: ESX variant, use in addition to other flags. */
87#define VD_VMDK_IMAGE_FLAGS_ESX (0x0008)
88/** VDI: Fill new blocks with zeroes while expanding image file. Only valid
89 * for newly created images, never set for opened existing images. */
90#define VD_VDI_IMAGE_FLAGS_ZERO_EXPAND (0x0100)
91
92/** Mask of valid image flags for VMDK. */
93#define VD_VMDK_IMAGE_FLAGS_MASK ( VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE \
94 | VD_VMDK_IMAGE_FLAGS_SPLIT_2G | VD_VMDK_IMAGE_FLAGS_RAWDISK \
95 | VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED | VD_VMDK_IMAGE_FLAGS_ESX)
96
97/** Mask of valid image flags for VDI. */
98#define VD_VDI_IMAGE_FLAGS_MASK (VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE | VD_VDI_IMAGE_FLAGS_ZERO_EXPAND)
99
100/** Mask of all valid image flags for all formats. */
101#define VD_IMAGE_FLAGS_MASK (VD_VMDK_IMAGE_FLAGS_MASK | VD_VDI_IMAGE_FLAGS_MASK)
102
103/** Default image flags. */
104#define VD_IMAGE_FLAGS_DEFAULT (VD_IMAGE_FLAGS_NONE)
105/** @} */
106
107
108/**
109 * Auxiliary type for describing partitions on raw disks.
110 */
111typedef struct VBOXHDDRAWPART
112{
113 /** Device to use for this partition. Can be the disk device if the offset
114 * field is set appropriately. If this is NULL, then this partition will
115 * not be accessible to the guest. The size of the partition must still
116 * be set correctly. */
117 const char *pszRawDevice;
118 /** Offset where the partition data starts in this device. */
119 uint64_t uPartitionStartOffset;
120 /** Offset where the partition data starts in the disk. */
121 uint64_t uPartitionStart;
122 /** Size of the partition. */
123 uint64_t cbPartition;
124 /** Size of the partitioning info to prepend. */
125 uint64_t cbPartitionData;
126 /** Offset where the partitioning info starts in the disk. */
127 uint64_t uPartitionDataStart;
128 /** Pointer to the partitioning info to prepend. */
129 const void *pvPartitionData;
130} VBOXHDDRAWPART, *PVBOXHDDRAWPART;
131
132/**
133 * Auxiliary data structure for creating raw disks.
134 */
135typedef struct VBOXHDDRAW
136{
137 /** Signature for structure. Must be 'R', 'A', 'W', '\0'. Actually a trick
138 * to make logging of the comment string produce sensible results. */
139 char szSignature[4];
140 /** Flag whether access to full disk should be given (ignoring the
141 * partition information below). */
142 bool fRawDisk;
143 /** Filename for the raw disk. Ignored for partitioned raw disks.
144 * For Linux e.g. /dev/sda, and for Windows e.g. \\.\PhysicalDisk0. */
145 const char *pszRawDisk;
146 /** Number of entries in the partitions array. */
147 unsigned cPartitions;
148 /** Pointer to the partitions array. */
149 PVBOXHDDRAWPART pPartitions;
150} VBOXHDDRAW, *PVBOXHDDRAW;
151
152/** @name VBox HDD container image open mode flags
153 * @{
154 */
155/** Try to open image in read/write exclusive access mode if possible, or in read-only elsewhere. */
156#define VD_OPEN_FLAGS_NORMAL 0
157/** Open image in read-only mode with sharing access with others. */
158#define VD_OPEN_FLAGS_READONLY RT_BIT(0)
159/** Honor zero block writes instead of ignoring them whenever possible.
160 * This is not supported by all formats. It is silently ignored in this case. */
161#define VD_OPEN_FLAGS_HONOR_ZEROES RT_BIT(1)
162/** Honor writes of the same data instead of ignoring whenever possible.
163 * This is handled generically, and is only meaningful for differential image
164 * formats. It is silently ignored otherwise. */
165#define VD_OPEN_FLAGS_HONOR_SAME RT_BIT(2)
166/** Do not perform the base/diff image check on open. This does NOT imply
167 * opening the image as readonly (would break e.g. adding UUIDs to VMDK files
168 * created by other products). Images opened with this flag should only be
169 * used for querying information, and nothing else. */
170#define VD_OPEN_FLAGS_INFO RT_BIT(3)
171/** Open image for asynchronous access.
172 * Only available if VD_CAP_ASYNC_IO is set
173 * Check with VDIsAsynchonousIoSupported wether
174 * asynchronous I/O is really supported for this file.
175 */
176#define VD_OPEN_FLAGS_ASYNC_IO RT_BIT(4)
177/** Mask of valid flags. */
178#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)
179/** @}*/
180
181
182/** @name VBox HDD container backend capability flags
183 * @{
184 */
185/** Supports UUIDs as expected by VirtualBox code. */
186#define VD_CAP_UUID RT_BIT(0)
187/** Supports creating fixed size images, allocating all space instantly. */
188#define VD_CAP_CREATE_FIXED RT_BIT(1)
189/** Supports creating dynamically growing images, allocating space on demand. */
190#define VD_CAP_CREATE_DYNAMIC RT_BIT(2)
191/** Supports creating images split in chunks of a bit less than 2GBytes. */
192#define VD_CAP_CREATE_SPLIT_2G RT_BIT(3)
193/** Supports being used as differencing image format backend. */
194#define VD_CAP_DIFF RT_BIT(4)
195/** Supports asynchronous I/O operations for at least some configurations. */
196#define VD_CAP_ASYNC RT_BIT(5)
197/** The backend operates on files. The caller needs to know to handle the
198 * location appropriately. */
199#define VD_CAP_FILE RT_BIT(6)
200/** The backend uses the config interface. The caller needs to know how to
201 * provide the mandatory configuration parts this way. */
202#define VD_CAP_CONFIG RT_BIT(7)
203/** The backend uses the network stack interface. The caller has to provide
204 * the appropriate interface. */
205#define VD_CAP_TCPNET RT_BIT(8)
206/** @}*/
207
208/**
209 * Supported interface types.
210 */
211typedef enum VDINTERFACETYPE
212{
213 /** First valid interface. */
214 VDINTERFACETYPE_FIRST = 0,
215 /** Interface to pass error message to upper layers. Per-disk. */
216 VDINTERFACETYPE_ERROR = VDINTERFACETYPE_FIRST,
217 /** Interface for asynchronous I/O operations. Per-disk. */
218 VDINTERFACETYPE_ASYNCIO,
219 /** Interface for progress notification. Per-operation. */
220 VDINTERFACETYPE_PROGRESS,
221 /** Interface for configuration information. Per-image. */
222 VDINTERFACETYPE_CONFIG,
223 /** Interface for TCP network stack. Per-disk. */
224 VDINTERFACETYPE_TCPNET,
225 /** Interface for getting parent image state. Per-operation. */
226 VDINTERFACETYPE_PARENTSTATE,
227 /** invalid interface. */
228 VDINTERFACETYPE_INVALID
229} VDINTERFACETYPE;
230
231/**
232 * Common structure for all interfaces.
233 */
234typedef struct VDINTERFACE
235{
236 /** Human readable interface name. */
237 const char *pszInterfaceName;
238 /** The size of the struct. */
239 uint32_t cbSize;
240 /** Pointer to the next common interface structure. */
241 struct VDINTERFACE *pNext;
242 /** Interface type. */
243 VDINTERFACETYPE enmInterface;
244 /** Opaque user data which is passed on every call. */
245 void *pvUser;
246 /** Pointer to the function call table of the interface.
247 * As this is opaque this must be casted to the right interface
248 * struct defined below based on the interface type in enmInterface. */
249 void *pCallbacks;
250} VDINTERFACE;
251/** Pointer to a VDINTERFACE. */
252typedef VDINTERFACE *PVDINTERFACE;
253/** Pointer to a const VDINTERFACE. */
254typedef const VDINTERFACE *PCVDINTERFACE;
255
256/**
257 * Helper functions to handle interface lists.
258 *
259 * @note These interface lists are used consistently to pass per-disk,
260 * per-image and/or per-operation callbacks. Those three purposes are strictly
261 * separate. See the individual interface declarations for what context they
262 * apply to. The caller is responsible for ensuring that the lifetime of the
263 * interface descriptors is appropriate for the category of interface.
264 */
265
266/**
267 * Get a specific interface from a list of interfaces specified by the type.
268 *
269 * @return Pointer to the matching interface or NULL if none was found.
270 * @param pVDIfs Pointer to the VD interface list.
271 * @param enmInterface Interface to search for.
272 */
273DECLINLINE(PVDINTERFACE) VDInterfaceGet(PVDINTERFACE pVDIfs, VDINTERFACETYPE enmInterface)
274{
275 AssertMsgReturn( (enmInterface >= VDINTERFACETYPE_FIRST)
276 && (enmInterface < VDINTERFACETYPE_INVALID),
277 ("enmInterface=%u", enmInterface), NULL);
278
279 while (pVDIfs)
280 {
281 /* Sanity checks. */
282 AssertMsgBreak(pVDIfs->cbSize == sizeof(VDINTERFACE),
283 ("cbSize=%u\n", pVDIfs->cbSize));
284
285 if (pVDIfs->enmInterface == enmInterface)
286 return pVDIfs;
287 pVDIfs = pVDIfs->pNext;
288 }
289
290 /* No matching interface was found. */
291 return NULL;
292}
293
294/**
295 * Add an interface to a list of interfaces.
296 *
297 * @return VBox status code.
298 * @param pInterface Pointer to an unitialized common interface structure.
299 * @param pszName Name of the interface.
300 * @param enmInterface Type of the interface.
301 * @param pCallbacks The callback table of the interface.
302 * @param pvUser Opaque user data passed on every function call.
303 * @param ppVDIfs Pointer to the VD interface list.
304 */
305DECLINLINE(int) VDInterfaceAdd(PVDINTERFACE pInterface, const char *pszName,
306 VDINTERFACETYPE enmInterface, void *pCallbacks,
307 void *pvUser, PVDINTERFACE *ppVDIfs)
308{
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 * Interface to deliver error messages (and also informational messages)
339 * to upper layers.
340 *
341 * Per disk interface. Optional, but think twice if you want to miss the
342 * opportunity of reporting better human-readable error messages.
343 */
344typedef struct VDINTERFACEERROR
345{
346 /**
347 * Size of the error interface.
348 */
349 uint32_t cbSize;
350
351 /**
352 * Interface type.
353 */
354 VDINTERFACETYPE enmInterface;
355
356 /**
357 * Error message callback. Must be able to accept special IPRT format
358 * strings.
359 *
360 * @param pvUser The opaque data passed on container creation.
361 * @param rc The VBox error code.
362 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
363 * @param pszFormat Error message format string.
364 * @param va Error message arguments.
365 */
366 DECLR3CALLBACKMEMBER(void, pfnError, (void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
367
368 /**
369 * Informational message callback. May be NULL. Used e.g. in
370 * VDDumpImages(). Must be able to accept special IPRT format strings.
371 *
372 * @return VBox status code.
373 * @param pvUser The opaque data passed on container creation.
374 * @param pszFormat Error message format string.
375 * @param ... Error message arguments.
376 */
377 DECLR3CALLBACKMEMBER(int, pfnMessage, (void *pvUser, const char *pszFormat, ...));
378
379} VDINTERFACEERROR, *PVDINTERFACEERROR;
380
381/**
382 * Get error interface from opaque callback table.
383 *
384 * @return Pointer to the callback table.
385 * @param pInterface Pointer to the interface descriptor.
386 */
387DECLINLINE(PVDINTERFACEERROR) VDGetInterfaceError(PVDINTERFACE pInterface)
388{
389 /* Check that the interface descriptor is a error interface. */
390 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_ERROR)
391 && (pInterface->cbSize == sizeof(VDINTERFACE)),
392 ("Not an error interface"), NULL);
393
394 PVDINTERFACEERROR pInterfaceError = (PVDINTERFACEERROR)pInterface->pCallbacks;
395
396 /* Do basic checks. */
397 AssertMsgReturn( (pInterfaceError->cbSize == sizeof(VDINTERFACEERROR))
398 && (pInterfaceError->enmInterface == VDINTERFACETYPE_ERROR),
399 ("A non error callback table attached to a error interface descriptor\n"), NULL);
400
401 return pInterfaceError;
402}
403
404/**
405 * Completion callback which is called by the interface owner
406 * to inform the backend that a task finished.
407 *
408 * @return VBox status code.
409 * @param pvUser Opaque user data which is passed on request submission.
410 * @param ppvCaller Where to store the opaque user data the caller of
411 * VDAsyncRead or VDAsyncWrite passed.
412 */
413typedef DECLCALLBACK(int) FNVDCOMPLETED(void *pvUser, void **ppvCaller);
414/** Pointer to FNVDCOMPLETED() */
415typedef FNVDCOMPLETED *PFNVDCOMPLETED;
416
417/** Open the storage readonly. */
418#define VD_INTERFACEASYNCIO_OPEN_FLAGS_READONLY RT_BIT(0)
419/** Create the storage backend if it doesn't exist. */
420#define VD_INTERFACEASYNCIO_OPEN_FLAGS_CREATE RT_BIT(1)
421
422/**
423 * Support interface for asynchronous I/O
424 *
425 * Per-disk. Optional.
426 */
427typedef struct VDINTERFACEASYNCIO
428{
429 /**
430 * Size of the async interface.
431 */
432 uint32_t cbSize;
433
434 /**
435 * Interface type.
436 */
437 VDINTERFACETYPE enmInterface;
438
439 /**
440 * Open callback
441 *
442 * @return VBox status code.
443 * @param pvUser The opaque data passed on container creation.
444 * @param pszLocation Name of the location to open.
445 * @param uOpenFlags Flags for opening the backend.
446 * See VD_INTERFACEASYNCIO_OPEN_FLAGS_* #defines
447 * @param pfnCompleted The callabck which is called whenever a task
448 * completed. The backend has to pass the user data
449 * of the request initiator (ie the one who calls
450 * VDAsyncRead or VDAsyncWrite) in pvCompletion
451 * if this is NULL.
452 * @param ppStorage Where to store the opaque storage handle.
453 */
454 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation, unsigned uOpenFlags,
455 PFNVDCOMPLETED pfnCompleted, void **ppStorage));
456
457 /**
458 * Close callback.
459 *
460 * @return VBox status code.
461 * @param pvUser The opaque data passed on container creation.
462 * @param pStorage The opaque storage handle to close.
463 */
464 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, void *pStorage));
465
466 /**
467 * Returns the size of the opened storage backend.
468 *
469 * @return VBox status code.
470 * @param pvUser The opaque data passed on container creation.
471 * @param pStorage The opaque storage handle to close.
472 * @param pcbSize Where to store the size of the storage backend.
473 */
474 DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, void *pStorage, uint64_t *pcbSize));
475
476 /**
477 * Sets the size of the opened storage backend if possible.
478 *
479 * @return VBox status code.
480 * @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
481 * @param pvUser The opaque data passed on container creation.
482 * @param pStorage The opaque storage handle to close.
483 * @param cbSize The new size of the image.
484 */
485 DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, void *pStorage, uint64_t cbSize));
486
487 /**
488 * Synchronous write callback.
489 *
490 * @return VBox status code.
491 * @param pvUser The opaque data passed on container creation.
492 * @param pStorage The storage handle to use.
493 * @param uOffset The offset to start from.
494 * @param cbWrite How many bytes to write.
495 * @param pvBuf Pointer to the bits need to be written.
496 * @param pcbWritten Where to store how many bytes where actually written.
497 */
498 DECLR3CALLBACKMEMBER(int, pfnWriteSync, (void *pvUser, void *pStorage, uint64_t uOffset,
499 size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
500
501 /**
502 * Synchronous read callback.
503 *
504 * @return VBox status code.
505 * @param pvUser The opaque data passed on container creation.
506 * @param pStorage The storage handle to use.
507 * @param uOffset The offset to start from.
508 * @param cbRead How many bytes to read.
509 * @param pvBuf Where to store the read bits.
510 * @param pcbRead Where to store how many bytes where actually read.
511 */
512 DECLR3CALLBACKMEMBER(int, pfnReadSync, (void *pvUser, void *pStorage, uint64_t uOffset,
513 size_t cbRead, void *pvBuf, size_t *pcbRead));
514
515 /**
516 * Flush data to the storage backend.
517 *
518 * @return VBox statis code.
519 * @param pvUser The opaque data passed on container creation.
520 * @param pStorage The storage handle to flush.
521 */
522 DECLR3CALLBACKMEMBER(int, pfnFlushSync, (void *pvUser, void *pStorage));
523
524 /**
525 * Initiate a asynchronous read request.
526 *
527 * @return VBox status code.
528 * @param pvUser The opqaue user data passed on container creation.
529 * @param pStorage The storage handle.
530 * @param uOffset The offset to start reading from.
531 * @param paSegments Scatter gather list to store the data in.
532 * @param cSegments Number of segments in the list.
533 * @param cbRead How many bytes to read.
534 * @param pvCompletion The opaque user data which is returned upon completion.
535 * @param ppTask Where to store the opaque task handle.
536 */
537 DECLR3CALLBACKMEMBER(int, pfnReadAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
538 PCPDMDATASEG paSegments, size_t cSegments,
539 size_t cbRead, void *pvCompletion,
540 void **ppTask));
541
542 /**
543 * Initiate a asynchronous write request.
544 *
545 * @return VBox status code.
546 * @param pvUser The opaque user data passed on conatiner creation.
547 * @param pStorage The storage handle.
548 * @param uOffset The offset to start writing to.
549 * @param paSegments Scatter gather list of the data to write
550 * @param cSegments Number of segments in the list.
551 * @param cbWrite How many bytes to write.
552 * @param pvCompletion The opaque user data which is returned upon completion.
553 * @param ppTask Where to store the opaque task handle.
554 */
555 DECLR3CALLBACKMEMBER(int, pfnWriteAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
556 PCPDMDATASEG paSegments, size_t cSegments,
557 size_t cbWrite, void *pvCompletion,
558 void **ppTask));
559
560 /**
561 * Initiates a async flush request.
562 *
563 * @return VBox statis code.
564 * @param pvUser The opaque data passed on container creation.
565 * @param pStorage The storage handle to flush.
566 * @param pvCompletion The opaque user data which is returned upon completion.
567 * @param ppTask Where to store the opaque task handle.
568 */
569 DECLR3CALLBACKMEMBER(int, pfnFlushAsync, (void *pvUser, void *pStorage,
570 void *pvCompletion, void **ppTask));
571
572} VDINTERFACEASYNCIO, *PVDINTERFACEASYNCIO;
573
574/**
575 * Get async I/O interface from opaque callback table.
576 *
577 * @return Pointer to the callback table.
578 * @param pInterface Pointer to the interface descriptor.
579 */
580DECLINLINE(PVDINTERFACEASYNCIO) VDGetInterfaceAsyncIO(PVDINTERFACE pInterface)
581{
582 /* Check that the interface descriptor is a async I/O interface. */
583 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_ASYNCIO)
584 && (pInterface->cbSize == sizeof(VDINTERFACE)),
585 ("Not an async I/O interface"), NULL);
586
587 PVDINTERFACEASYNCIO pInterfaceAsyncIO = (PVDINTERFACEASYNCIO)pInterface->pCallbacks;
588
589 /* Do basic checks. */
590 AssertMsgReturn( (pInterfaceAsyncIO->cbSize == sizeof(VDINTERFACEASYNCIO))
591 && (pInterfaceAsyncIO->enmInterface == VDINTERFACETYPE_ASYNCIO),
592 ("A non async I/O callback table attached to a async I/O interface descriptor\n"), NULL);
593
594 return pInterfaceAsyncIO;
595}
596
597/**
598 * Progress notification interface
599 *
600 * Per-operation. Optional.
601 */
602typedef struct VDINTERFACEPROGRESS
603{
604 /**
605 * Size of the progress interface.
606 */
607 uint32_t cbSize;
608
609 /**
610 * Interface type.
611 */
612 VDINTERFACETYPE enmInterface;
613
614 /**
615 * Progress notification callbacks.
616 * @todo r=bird: Why the heck are we using PFNVMPROGRESS here?
617 */
618 PFNVMPROGRESS pfnProgress;
619} VDINTERFACEPROGRESS, *PVDINTERFACEPROGRESS;
620
621/**
622 * Get progress interface from opaque callback table.
623 *
624 * @return Pointer to the callback table.
625 * @param pInterface Pointer to the interface descriptor.
626 */
627DECLINLINE(PVDINTERFACEPROGRESS) VDGetInterfaceProgress(PVDINTERFACE pInterface)
628{
629 /* Check that the interface descriptor is a progress interface. */
630 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PROGRESS)
631 && (pInterface->cbSize == sizeof(VDINTERFACE)),
632 ("Not a progress interface"), NULL);
633
634
635 PVDINTERFACEPROGRESS pInterfaceProgress = (PVDINTERFACEPROGRESS)pInterface->pCallbacks;
636
637 /* Do basic checks. */
638 AssertMsgReturn( (pInterfaceProgress->cbSize == sizeof(VDINTERFACEPROGRESS))
639 && (pInterfaceProgress->enmInterface == VDINTERFACETYPE_PROGRESS),
640 ("A non progress callback table attached to a progress interface descriptor\n"), NULL);
641
642 return pInterfaceProgress;
643}
644
645
646/**
647 * Configuration information interface
648 *
649 * Per-image. Optional for most backends, but mandatory for images which do
650 * not operate on files (including standard block or character devices).
651 */
652typedef struct VDINTERFACECONFIG
653{
654 /**
655 * Size of the configuration interface.
656 */
657 uint32_t cbSize;
658
659 /**
660 * Interface type.
661 */
662 VDINTERFACETYPE enmInterface;
663
664 /**
665 * Validates that the keys are within a set of valid names.
666 *
667 * @return true if all key names are found in pszzAllowed.
668 * @return false if not.
669 * @param pvUser The opaque user data associated with this interface.
670 * @param pszzValid List of valid key names separated by '\\0' and ending with
671 * a double '\\0'.
672 */
673 DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid));
674
675 /**
676 * Retrieves the length of the string value associated with a key (including
677 * the terminator, for compatibility with CFGMR3QuerySize).
678 *
679 * @return VBox status code.
680 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
681 * @param pvUser The opaque user data associated with this interface.
682 * @param pszName Name of the key to query.
683 * @param pcbValue Where to store the value length. Non-NULL.
684 */
685 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
686
687 /**
688 * Query the string value associated with a key.
689 *
690 * @return VBox status code.
691 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
692 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
693 * @param pvUser The opaque user data associated with this interface.
694 * @param pszName Name of the key to query.
695 * @param pszValue Pointer to buffer where to store value.
696 * @param cchValue Length of value buffer.
697 */
698 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
699} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
700
701/**
702 * Get configuration information interface from opaque callback table.
703 *
704 * @return Pointer to the callback table.
705 * @param pInterface Pointer to the interface descriptor.
706 */
707DECLINLINE(PVDINTERFACECONFIG) VDGetInterfaceConfig(PVDINTERFACE pInterface)
708{
709 /* Check that the interface descriptor is a config interface. */
710 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_CONFIG)
711 && (pInterface->cbSize == sizeof(VDINTERFACE)),
712 ("Not a config interface"), NULL);
713
714 PVDINTERFACECONFIG pInterfaceConfig = (PVDINTERFACECONFIG)pInterface->pCallbacks;
715
716 /* Do basic checks. */
717 AssertMsgReturn( (pInterfaceConfig->cbSize == sizeof(VDINTERFACECONFIG))
718 && (pInterfaceConfig->enmInterface == VDINTERFACETYPE_CONFIG),
719 ("A non config callback table attached to a config interface descriptor\n"), NULL);
720
721 return pInterfaceConfig;
722}
723
724/**
725 * Query configuration, validates that the keys are within a set of valid names.
726 *
727 * @return true if all key names are found in pszzAllowed.
728 * @return false if not.
729 * @param pCfgIf Pointer to configuration callback table.
730 * @param pvUser The opaque user data associated with this interface.
731 * @param pszzValid List of valid names separated by '\\0' and ending with
732 * a double '\\0'.
733 */
734DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, void *pvUser,
735 const char *pszzValid)
736{
737 return pCfgIf->pfnAreKeysValid(pvUser, pszzValid);
738}
739
740/**
741 * Query configuration, unsigned 64-bit integer value with default.
742 *
743 * @return VBox status code.
744 * @param pCfgIf Pointer to configuration callback table.
745 * @param pvUser The opaque user data associated with this interface.
746 * @param pszName Name of an integer value
747 * @param pu64 Where to store the value. Set to default on failure.
748 * @param u64Def The default value.
749 */
750DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
751 const char *pszName, uint64_t *pu64,
752 uint64_t u64Def)
753{
754 char aszBuf[32];
755 int rc = pCfgIf->pfnQuery(pvUser, pszName, aszBuf, sizeof(aszBuf));
756 if (RT_SUCCESS(rc))
757 {
758 rc = RTStrToUInt64Full(aszBuf, 0, pu64);
759 }
760 else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
761 {
762 rc = VINF_SUCCESS;
763 *pu64 = u64Def;
764 }
765 return rc;
766}
767
768/**
769 * Query configuration, unsigned 32-bit integer value with default.
770 *
771 * @return VBox status code.
772 * @param pCfgIf Pointer to configuration callback table.
773 * @param pvUser The opaque user data associated with this interface.
774 * @param pszName Name of an integer value
775 * @param pu32 Where to store the value. Set to default on failure.
776 * @param u32Def The default value.
777 */
778DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
779 const char *pszName, uint32_t *pu32,
780 uint32_t u32Def)
781{
782 uint64_t u64;
783 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, u32Def);
784 if (RT_SUCCESS(rc))
785 {
786 if (!(u64 & UINT64_C(0xffffffff00000000)))
787 *pu32 = (uint32_t)u64;
788 else
789 rc = VERR_CFGM_INTEGER_TOO_BIG;
790 }
791 return rc;
792}
793
794/**
795 * Query configuration, bool value with default.
796 *
797 * @return VBox status code.
798 * @param pCfgIf Pointer to configuration callback table.
799 * @param pvUser The opaque user data associated with this interface.
800 * @param pszName Name of an integer value
801 * @param pf Where to store the value. Set to default on failure.
802 * @param fDef The default value.
803 */
804DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, void *pvUser,
805 const char *pszName, bool *pf,
806 bool fDef)
807{
808 uint64_t u64;
809 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, fDef);
810 if (RT_SUCCESS(rc))
811 *pf = u64 ? true : false;
812 return rc;
813}
814
815/**
816 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
817 * character value.
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 zero terminated character value
823 * @param ppszString Where to store the string pointer. Not set on failure.
824 * Free this using RTMemFree().
825 */
826DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
827 void *pvUser, const char *pszName,
828 char **ppszString)
829{
830 size_t cb;
831 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
832 if (RT_SUCCESS(rc))
833 {
834 char *pszString = (char *)RTMemAlloc(cb);
835 if (pszString)
836 {
837 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cb);
838 if (RT_SUCCESS(rc))
839 *ppszString = pszString;
840 else
841 RTMemFree(pszString);
842 }
843 else
844 rc = VERR_NO_MEMORY;
845 }
846 return rc;
847}
848
849/**
850 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
851 * character value with default.
852 *
853 * @return VBox status code.
854 * @param pCfgIf Pointer to configuration callback table.
855 * @param pvUser The opaque user data associated with this interface.
856 * @param pszName Name of an zero terminated character value
857 * @param ppszString Where to store the string pointer. Not set on failure.
858 * Free this using RTMemFree().
859 * @param pszDef The default value.
860 */
861DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
862 void *pvUser, const char *pszName,
863 char **ppszString,
864 const char *pszDef)
865{
866 size_t cb;
867 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
868 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
869 {
870 cb = strlen(pszDef) + 1;
871 rc = VINF_SUCCESS;
872 }
873 if (RT_SUCCESS(rc))
874 {
875 char *pszString = (char *)RTMemAlloc(cb);
876 if (pszString)
877 {
878 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cb);
879 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
880 {
881 memcpy(pszString, pszDef, cb);
882 rc = VINF_SUCCESS;
883 }
884 if (RT_SUCCESS(rc))
885 *ppszString = pszString;
886 else
887 RTMemFree(pszString);
888 }
889 else
890 rc = VERR_NO_MEMORY;
891 }
892 return rc;
893}
894
895/**
896 * Query configuration, dynamically allocated (RTMemAlloc) byte string value.
897 *
898 * @return VBox status code.
899 * @param pCfgIf Pointer to configuration callback table.
900 * @param pvUser The opaque user data associated with this interface.
901 * @param pszName Name of an zero terminated character value
902 * @param ppvData Where to store the byte string pointer. Not set on failure.
903 * Free this using RTMemFree().
904 * @param pcbData Where to store the byte string length.
905 */
906DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
907 void *pvUser, const char *pszName,
908 void **ppvData, size_t *pcbData)
909{
910 size_t cb;
911 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
912 if (RT_SUCCESS(rc))
913 {
914 char *pvData = (char *)RTMemAlloc(cb);
915 if (pvData)
916 {
917 rc = pCfgIf->pfnQuery(pvUser, pszName, pvData, cb);
918 if (RT_SUCCESS(rc))
919 {
920 *ppvData = pvData;
921 *pcbData = cb;
922 }
923 else
924 RTMemFree(pvData);
925 }
926 else
927 rc = VERR_NO_MEMORY;
928 }
929 return rc;
930}
931
932
933/**
934 * TCP network stack interface
935 *
936 * Per-disk. Mandatory for backends which have the VD_CAP_TCPNET bit set.
937 */
938typedef struct VDINTERFACETCPNET
939{
940 /**
941 * Size of the configuration interface.
942 */
943 uint32_t cbSize;
944
945 /**
946 * Interface type.
947 */
948 VDINTERFACETYPE enmInterface;
949
950 /**
951 * Connect as a client to a TCP port.
952 *
953 * @return iprt status code.
954 * @param pszAddress The address to connect to.
955 * @param uPort The port to connect to.
956 * @param pSock Where to store the handle to the established connect
957ion.
958 */
959 DECLR3CALLBACKMEMBER(int, pfnClientConnect, (const char *pszAddress, uint32_t uPort, PRTSOCKET pSock));
960
961 /**
962 * Close a TCP connection.
963 *
964 * @return iprt status code.
965 * @param Sock Socket descriptor.
966ion.
967 */
968 DECLR3CALLBACKMEMBER(int, pfnClientClose, (RTSOCKET Sock));
969
970 /**
971 * Socket I/O multiplexing.
972 * Checks if the socket is ready for reading.
973 *
974 * @return iprt status code.
975 * @param Sock Socket descriptor.
976 * @param cMillies Number of milliseconds to wait for the socket.
977 * Use RT_INDEFINITE_WAIT to wait for ever.
978 */
979 DECLR3CALLBACKMEMBER(int, pfnSelectOne, (RTSOCKET Sock, unsigned cMillies));
980
981 /**
982 * Receive data from a socket.
983 *
984 * @return iprt status code.
985 * @param Sock Socket descriptor.
986 * @param pvBuffer Where to put the data we read.
987 * @param cbBuffer Read buffer size.
988 * @param pcbRead Number of bytes read.
989 * If NULL the entire buffer will be filled upon successful return.
990 * If not NULL a partial read can be done successfully.
991 */
992 DECLR3CALLBACKMEMBER(int, pfnRead, (RTSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
993
994 /**
995 * Send data from a socket.
996 *
997 * @return iprt status code.
998 * @param Sock Socket descriptor.
999 * @param pvBuffer Buffer to write data to socket.
1000 * @param cbBuffer How much to write.
1001 * @param pcbRead Number of bytes read.
1002 */
1003 DECLR3CALLBACKMEMBER(int, pfnWrite, (RTSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
1004
1005 /**
1006 * Flush socket write buffers.
1007 *
1008 * @return iprt status code.
1009 * @param Sock Socket descriptor.
1010 */
1011 DECLR3CALLBACKMEMBER(int, pfnFlush, (RTSOCKET Sock));
1012
1013} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
1014
1015/**
1016 * Get TCP network stack interface from opaque callback table.
1017 *
1018 * @return Pointer to the callback table.
1019 * @param pInterface Pointer to the interface descriptor.
1020 */
1021DECLINLINE(PVDINTERFACETCPNET) VDGetInterfaceTcpNet(PVDINTERFACE pInterface)
1022{
1023 /* Check that the interface descriptor is a TCP network stack interface. */
1024 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_TCPNET)
1025 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1026 ("Not a TCP network stack interface"), NULL);
1027
1028 PVDINTERFACETCPNET pInterfaceTcpNet = (PVDINTERFACETCPNET)pInterface->pCallbacks;
1029
1030 /* Do basic checks. */
1031 AssertMsgReturn( (pInterfaceTcpNet->cbSize == sizeof(VDINTERFACETCPNET))
1032 && (pInterfaceTcpNet->enmInterface == VDINTERFACETYPE_TCPNET),
1033 ("A non TCP network stack callback table attached to a TCP network stack interface descriptor\n"), NULL);
1034
1035 return pInterfaceTcpNet;
1036}
1037
1038/**
1039 * Interface to get the parent state.
1040 *
1041 * Per operation interface. Optional, present only if there is a parent, and
1042 * used only internally for compacting.
1043 */
1044typedef struct VDINTERFACEPARENTSTATE
1045{
1046 /**
1047 * Size of the parent state interface.
1048 */
1049 uint32_t cbSize;
1050
1051 /**
1052 * Interface type.
1053 */
1054 VDINTERFACETYPE enmInterface;
1055
1056 /**
1057 * Read data callback.
1058 *
1059 * @return VBox status code.
1060 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1061 * @param pvUser The opaque data passed for the operation.
1062 * @param uOffset Offset of first reading byte from start of disk.
1063 * Must be aligned to a sector boundary.
1064 * @param pvBuf Pointer to buffer for reading data.
1065 * @param cbRead Number of bytes to read.
1066 * Must be aligned to a sector boundary.
1067 */
1068 DECLR3CALLBACKMEMBER(int, pfnParentRead, (void *pvUser, uint64_t uOffset, void *pvBuf, size_t cbRead));
1069
1070} VDINTERFACEPARENTSTATE, *PVDINTERFACEPARENTSTATE;
1071
1072
1073/**
1074 * Get parent state interface from opaque callback table.
1075 *
1076 * @return Pointer to the callback table.
1077 * @param pInterface Pointer to the interface descriptor.
1078 */
1079DECLINLINE(PVDINTERFACEPARENTSTATE) VDGetInterfaceParentState(PVDINTERFACE pInterface)
1080{
1081 /* Check that the interface descriptor is a parent state interface. */
1082 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PARENTSTATE)
1083 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1084 ("Not a parent state interface"), NULL);
1085
1086 PVDINTERFACEPARENTSTATE pInterfaceParentState = (PVDINTERFACEPARENTSTATE)pInterface->pCallbacks;
1087
1088 /* Do basic checks. */
1089 AssertMsgReturn( (pInterfaceParentState->cbSize == sizeof(VDINTERFACEPARENTSTATE))
1090 && (pInterfaceParentState->enmInterface == VDINTERFACETYPE_PARENTSTATE),
1091 ("A non parent state callback table attached to a parent state interface descriptor\n"), NULL);
1092
1093 return pInterfaceParentState;
1094}
1095
1096
1097/** @name Configuration interface key handling flags.
1098 * @{
1099 */
1100/** Mandatory config key. Not providing a value for this key will cause
1101 * the backend to fail. */
1102#define VD_CFGKEY_MANDATORY RT_BIT(0)
1103/** Expert config key. Not showing it by default in the GUI is is probably
1104 * a good idea, as the average user won't understand it easily. */
1105#define VD_CFGKEY_EXPERT RT_BIT(1)
1106/** @}*/
1107
1108
1109/**
1110 * Configuration value type for configuration information interface.
1111 */
1112typedef enum VDCFGVALUETYPE
1113{
1114 /** Integer value. */
1115 VDCFGVALUETYPE_INTEGER = 1,
1116 /** String value. */
1117 VDCFGVALUETYPE_STRING,
1118 /** Bytestring value. */
1119 VDCFGVALUETYPE_BYTES
1120} VDCFGVALUETYPE;
1121
1122
1123/**
1124 * Structure describing configuration keys required/supported by a backend
1125 * through the config interface.
1126 */
1127typedef struct VDCONFIGINFO
1128{
1129 /** Key name of the configuration. */
1130 const char *pszKey;
1131 /** Pointer to default value (descriptor). NULL if no useful default value
1132 * can be specified. */
1133 const char *pszDefaultValue;
1134 /** Value type for this key. */
1135 VDCFGVALUETYPE enmValueType;
1136 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
1137 uint64_t uKeyFlags;
1138} VDCONFIGINFO;
1139
1140/** Pointer to structure describing configuration keys. */
1141typedef VDCONFIGINFO *PVDCONFIGINFO;
1142
1143/** Pointer to const structure describing configuration keys. */
1144typedef const VDCONFIGINFO *PCVDCONFIGINFO;
1145
1146/**
1147 * Data structure for returning a list of backend capabilities.
1148 */
1149typedef struct VDBACKENDINFO
1150{
1151 /** Name of the backend. Must be unique even with case insensitive comparison. */
1152 const char *pszBackend;
1153 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
1154 uint64_t uBackendCaps;
1155 /** Pointer to a NULL-terminated array of strings, containing the supported
1156 * file extensions. Note that some backends do not work on files, so this
1157 * pointer may just contain NULL. */
1158 const char * const *papszFileExtensions;
1159 /** Pointer to an array of structs describing each supported config key.
1160 * Terminated by a NULL config key. Note that some backends do not support
1161 * the configuration interface, so this pointer may just contain NULL.
1162 * Mandatory if the backend sets VD_CAP_CONFIG. */
1163 PCVDCONFIGINFO paConfigInfo;
1164 /** Returns a human readable hard disk location string given a
1165 * set of hard disk configuration keys. The returned string is an
1166 * equivalent of the full file path for image-based hard disks.
1167 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
1168 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
1169 /** Returns a human readable hard disk name string given a
1170 * set of hard disk configuration keys. The returned string is an
1171 * equivalent of the file name part in the full file path for
1172 * image-based hard disks. Mandatory for backends with no
1173 * VD_CAP_FILE and NULL otherwise. */
1174 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
1175} VDBACKENDINFO, *PVDBACKENDINFO;
1176
1177
1178/**
1179 * VBox HDD Container main structure.
1180 */
1181/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
1182struct VBOXHDD;
1183typedef struct VBOXHDD VBOXHDD;
1184typedef VBOXHDD *PVBOXHDD;
1185
1186/**
1187 * Initializes HDD backends.
1188 *
1189 * @returns VBox status code.
1190 */
1191VBOXDDU_DECL(int) VDInit(void);
1192
1193/**
1194 * Destroys loaded HDD backends.
1195 *
1196 * @returns VBox status code.
1197 */
1198VBOXDDU_DECL(int) VDShutdown(void);
1199
1200/**
1201 * Lists all HDD backends and their capabilities in a caller-provided buffer.
1202 * Free all returned names with RTStrFree() when you no longer need them.
1203 *
1204 * @return VBox status code.
1205 * VERR_BUFFER_OVERFLOW if not enough space is passed.
1206 * @param cEntriesAlloc Number of list entries available.
1207 * @param pEntries Pointer to array for the entries.
1208 * @param pcEntriesUsed Number of entries returned.
1209 */
1210VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
1211 unsigned *pcEntriesUsed);
1212
1213/**
1214 * Lists the capablities of a backend indentified by its name.
1215 * Free all returned names with RTStrFree() when you no longer need them.
1216 *
1217 * @return VBox status code.
1218 * @param pszBackend The backend name (case insensitive).
1219 * @param pEntries Pointer to an entry.
1220 */
1221VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
1222
1223/**
1224 * Allocates and initializes an empty HDD container.
1225 * No image files are opened.
1226 *
1227 * @return VBox status code.
1228 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1229 * @param ppDisk Where to store the reference to HDD container.
1230 */
1231VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, PVBOXHDD *ppDisk);
1232
1233/**
1234 * Destroys HDD container.
1235 * If container has opened image files they will be closed.
1236 *
1237 * @param pDisk Pointer to HDD container.
1238 */
1239VBOXDDU_DECL(void) VDDestroy(PVBOXHDD pDisk);
1240
1241/**
1242 * Try to get the backend name which can use this image.
1243 *
1244 * @return VBox status code.
1245 * @param pszFilename Name of the image file for which the backend is queried.
1246 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
1247 * The returned pointer must be freed using RTStrFree().
1248 */
1249VBOXDDU_DECL(int) VDGetFormat(const char *pszFilename, char **ppszFormat);
1250
1251/**
1252 * Opens an image file.
1253 *
1254 * The first opened image file in HDD container must have a base image type,
1255 * others (next opened images) must be differencing or undo images.
1256 * Linkage is checked for differencing image to be consistent with the previously opened image.
1257 * When another differencing image is opened and the last image was opened in read/write access
1258 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
1259 * other processes to use images in read-only mode too.
1260 *
1261 * Note that the image is opened in read-only mode if a read/write open is not possible.
1262 * Use VDIsReadOnly to check open mode.
1263 *
1264 * @return VBox status code.
1265 * @param pDisk Pointer to HDD container.
1266 * @param pszBackend Name of the image file backend to use (case insensitive).
1267 * @param pszFilename Name of the image file to open.
1268 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1269 * @param pVDIfsImage Pointer to the per-image VD interface list.
1270 */
1271VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
1272 const char *pszFilename, unsigned uOpenFlags,
1273 PVDINTERFACE pVDIfsImage);
1274
1275/**
1276 * Creates and opens a new base image file.
1277 *
1278 * @return VBox status code.
1279 * @param pDisk Pointer to HDD container.
1280 * @param pszBackend Name of the image file backend to use (case insensitive).
1281 * @param pszFilename Name of the image file to create.
1282 * @param cbSize Image size in bytes.
1283 * @param uImageFlags Flags specifying special image features.
1284 * @param pszComment Pointer to image comment. NULL is ok.
1285 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
1286 * @param pLCHSGeometry Pointer to logical disk geometry <= (x,255,63). Not NULL.
1287 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1288 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1289 * @param pVDIfsImage Pointer to the per-image VD interface list.
1290 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1291 */
1292VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
1293 const char *pszFilename, uint64_t cbSize,
1294 unsigned uImageFlags, const char *pszComment,
1295 PCPDMMEDIAGEOMETRY pPCHSGeometry,
1296 PCPDMMEDIAGEOMETRY pLCHSGeometry,
1297 PCRTUUID pUuid, unsigned uOpenFlags,
1298 PVDINTERFACE pVDIfsImage,
1299 PVDINTERFACE pVDIfsOperation);
1300
1301/**
1302 * Creates and opens a new differencing image file in HDD container.
1303 * See comments for VDOpen function about differencing images.
1304 *
1305 * @return VBox status code.
1306 * @param pDisk Pointer to HDD container.
1307 * @param pszBackend Name of the image file backend to use (case insensitive).
1308 * @param pszFilename Name of the differencing image file to create.
1309 * @param uImageFlags Flags specifying special image features.
1310 * @param pszComment Pointer to image comment. NULL is ok.
1311 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1312 * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically.
1313 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1314 * @param pVDIfsImage Pointer to the per-image VD interface list.
1315 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1316 */
1317VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
1318 const char *pszFilename, unsigned uImageFlags,
1319 const char *pszComment, PCRTUUID pUuid,
1320 PCRTUUID pParentUuid, unsigned uOpenFlags,
1321 PVDINTERFACE pVDIfsImage,
1322 PVDINTERFACE pVDIfsOperation);
1323
1324/**
1325 * Merges two images (not necessarily with direct parent/child relationship).
1326 * As a side effect the source image and potentially the other images which
1327 * are also merged to the destination are deleted from both the disk and the
1328 * images in the HDD container.
1329 *
1330 * @return VBox status code.
1331 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1332 * @param pDisk Pointer to HDD container.
1333 * @param nImageFrom Image number to merge from, counts from 0. 0 is always base image of container.
1334 * @param nImageTo Image number to merge to, counts from 0. 0 is always base image of container.
1335 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1336 */
1337VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
1338 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
1339
1340/**
1341 * Copies an image from one HDD container to another.
1342 * The copy is opened in the target HDD container.
1343 * It is possible to convert between different image formats, because the
1344 * backend for the destination may be different from the source.
1345 * If both the source and destination reference the same HDD container,
1346 * then the image is moved (by copying/deleting or renaming) to the new location.
1347 * The source container is unchanged if the move operation fails, otherwise
1348 * the image at the new location is opened in the same way as the old one was.
1349 *
1350 * @return VBox status code.
1351 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1352 * @param pDiskFrom Pointer to source HDD container.
1353 * @param nImage Image number, counts from 0. 0 is always base image of container.
1354 * @param pDiskTo Pointer to destination HDD container.
1355 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
1356 * @param pszFilename New name of the image (may be NULL to specify that the
1357 * copy destination is the destination container, or
1358 * if pDiskFrom == pDiskTo, i.e. when moving).
1359 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
1360 * @param cbSize New image size (0 means leave unchanged).
1361 * @param uImageFlags Flags specifying special destination image features.
1362 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
1363 * This parameter is used if and only if a true copy is created.
1364 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
1365 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1366 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
1367 * destination image.
1368 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
1369 * for the destination operation.
1370 */
1371VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
1372 const char *pszBackend, const char *pszFilename,
1373 bool fMoveByRename, uint64_t cbSize,
1374 unsigned uImageFlags, PCRTUUID pDstUuid,
1375 PVDINTERFACE pVDIfsOperation,
1376 PVDINTERFACE pDstVDIfsImage,
1377 PVDINTERFACE pDstVDIfsOperation);
1378
1379/**
1380 * Optimizes the storage consumption of an image. Typically the unused blocks
1381 * have to be wiped with zeroes to achieve a substantial reduced storage use.
1382 * Another optimization done is reordering the image blocks, which can provide
1383 * a significant performance boost, as reads and writes tend to use less random
1384 * file offsets.
1385 *
1386 * @return VBox status code.
1387 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1388 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
1389 * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but
1390 * this isn't supported yet.
1391 * @param pDisk Pointer to HDD container.
1392 * @param nImage Image number, counts from 0. 0 is always base image of container.
1393 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1394 */
1395VBOXDDU_DECL(int) VDCompact(PVBOXHDD pDisk, unsigned nImage,
1396 PVDINTERFACE pVDIfsOperation);
1397
1398/**
1399 * Closes the last opened image file in HDD container.
1400 * If previous image file was opened in read-only mode (that is normal) and closing image
1401 * was opened in read-write mode (the whole disk was in read-write mode) - the previous image
1402 * will be reopened in read/write mode.
1403 *
1404 * @return VBox status code.
1405 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1406 * @param pDisk Pointer to HDD container.
1407 * @param fDelete If true, delete the image from the host disk.
1408 */
1409VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
1410
1411/**
1412 * Closes all opened image files in HDD container.
1413 *
1414 * @return VBox status code.
1415 * @param pDisk Pointer to HDD container.
1416 */
1417VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
1418
1419/**
1420 * Read data from virtual HDD.
1421 *
1422 * @return VBox status code.
1423 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1424 * @param pDisk Pointer to HDD container.
1425 * @param uOffset Offset of first reading byte from start of disk.
1426 * Must be aligned to a sector boundary.
1427 * @param pvBuf Pointer to buffer for reading data.
1428 * @param cbRead Number of bytes to read.
1429 * Must be aligned to a sector boundary.
1430 */
1431VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
1432
1433/**
1434 * Write data to virtual HDD.
1435 *
1436 * @return VBox status code.
1437 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1438 * @param pDisk Pointer to HDD container.
1439 * @param uOffset Offset of first writing byte from start of disk.
1440 * Must be aligned to a sector boundary.
1441 * @param pvBuf Pointer to buffer for writing data.
1442 * @param cbWrite Number of bytes to write.
1443 * Must be aligned to a sector boundary.
1444 */
1445VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
1446
1447/**
1448 * Make sure the on disk representation of a virtual HDD is up to date.
1449 *
1450 * @return VBox status code.
1451 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1452 * @param pDisk Pointer to HDD container.
1453 */
1454VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
1455
1456/**
1457 * Get number of opened images in HDD container.
1458 *
1459 * @return Number of opened images for HDD container. 0 if no images have been opened.
1460 * @param pDisk Pointer to HDD container.
1461 */
1462VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
1463
1464/**
1465 * Get read/write mode of HDD container.
1466 *
1467 * @return Virtual disk ReadOnly status.
1468 * @return true if no image is opened in HDD container.
1469 * @param pDisk Pointer to HDD container.
1470 */
1471VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
1472
1473/**
1474 * Get total capacity of an image in HDD container.
1475 *
1476 * @return Virtual disk size in bytes.
1477 * @return 0 if image with specified number was not opened.
1478 * @param pDisk Pointer to HDD container.
1479 * @param nImage Image number, counts from 0. 0 is always base image of container.
1480 */
1481VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
1482
1483/**
1484 * Get total file size of an image in HDD container.
1485 *
1486 * @return Virtual disk size in bytes.
1487 * @return 0 if image with specified number was not opened.
1488 * @param pDisk Pointer to HDD container.
1489 * @param nImage Image number, counts from 0. 0 is always base image of container.
1490 */
1491VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
1492
1493/**
1494 * Get virtual disk PCHS geometry of an image in HDD container.
1495 *
1496 * @return VBox status code.
1497 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1498 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1499 * @param pDisk Pointer to HDD container.
1500 * @param nImage Image number, counts from 0. 0 is always base image of container.
1501 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1502 */
1503VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1504 PPDMMEDIAGEOMETRY pPCHSGeometry);
1505
1506/**
1507 * Store virtual disk PCHS geometry of an image in HDD container.
1508 *
1509 * @return VBox status code.
1510 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1511 * @param pDisk Pointer to HDD container.
1512 * @param nImage Image number, counts from 0. 0 is always base image of container.
1513 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1514 */
1515VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1516 PCPDMMEDIAGEOMETRY pPCHSGeometry);
1517
1518/**
1519 * Get virtual disk LCHS geometry of an image in HDD container.
1520 *
1521 * @return VBox status code.
1522 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1523 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1524 * @param pDisk Pointer to HDD container.
1525 * @param nImage Image number, counts from 0. 0 is always base image of container.
1526 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1527 */
1528VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1529 PPDMMEDIAGEOMETRY pLCHSGeometry);
1530
1531/**
1532 * Store virtual disk LCHS geometry of an image in HDD container.
1533 *
1534 * @return VBox status code.
1535 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1536 * @param pDisk Pointer to HDD container.
1537 * @param nImage Image number, counts from 0. 0 is always base image of container.
1538 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1539 */
1540VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1541 PCPDMMEDIAGEOMETRY pLCHSGeometry);
1542
1543/**
1544 * Get version of image in HDD container.
1545 *
1546 * @return VBox status code.
1547 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1548 * @param pDisk Pointer to HDD container.
1549 * @param nImage Image number, counts from 0. 0 is always base image of container.
1550 * @param puVersion Where to store the image version.
1551 */
1552VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
1553 unsigned *puVersion);
1554
1555/**
1556 * List the capabilities of image backend in HDD container.
1557 *
1558 * @return VBox status code.
1559 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1560 * @param pDisk Pointer to the HDD container.
1561 * @param nImage Image number, counts from 0. 0 is always base image of container.
1562 * @param pbackendInfo Where to store the backend information.
1563 */
1564VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
1565 PVDBACKENDINFO pBackendInfo);
1566
1567/**
1568 * Get flags of image in HDD container.
1569 *
1570 * @return VBox status code.
1571 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1572 * @param pDisk Pointer to HDD container.
1573 * @param nImage Image number, counts from 0. 0 is always base image of container.
1574 * @param puImageFlags Where to store the image flags.
1575 */
1576VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
1577
1578/**
1579 * Get open flags of image in HDD container.
1580 *
1581 * @return VBox status code.
1582 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1583 * @param pDisk Pointer to HDD container.
1584 * @param nImage Image number, counts from 0. 0 is always base image of container.
1585 * @param puOpenFlags Where to store the image open flags.
1586 */
1587VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1588 unsigned *puOpenFlags);
1589
1590/**
1591 * Set open flags of image in HDD container.
1592 * This operation may cause file locking changes and/or files being reopened.
1593 * Note that in case of unrecoverable error all images in HDD container will be closed.
1594 *
1595 * @return VBox status code.
1596 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1597 * @param pDisk Pointer to HDD container.
1598 * @param nImage Image number, counts from 0. 0 is always base image of container.
1599 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1600 */
1601VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1602 unsigned uOpenFlags);
1603
1604/**
1605 * Get base filename of image in HDD container. Some image formats use
1606 * other filenames as well, so don't use this for anything but informational
1607 * purposes.
1608 *
1609 * @return VBox status code.
1610 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1611 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1612 * @param pDisk Pointer to HDD container.
1613 * @param nImage Image number, counts from 0. 0 is always base image of container.
1614 * @param pszFilename Where to store the image file name.
1615 * @param cbFilename Size of buffer pszFilename points to.
1616 */
1617VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
1618 char *pszFilename, unsigned cbFilename);
1619
1620/**
1621 * Get the comment line of image in HDD container.
1622 *
1623 * @return VBox status code.
1624 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1625 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1626 * @param pDisk Pointer to HDD container.
1627 * @param nImage Image number, counts from 0. 0 is always base image of container.
1628 * @param pszComment Where to store the comment string of image. NULL is ok.
1629 * @param cbComment The size of pszComment buffer. 0 is ok.
1630 */
1631VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
1632 char *pszComment, unsigned cbComment);
1633
1634/**
1635 * Changes the comment line of image in HDD container.
1636 *
1637 * @return VBox status code.
1638 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1639 * @param pDisk Pointer to HDD container.
1640 * @param nImage Image number, counts from 0. 0 is always base image of container.
1641 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1642 */
1643VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
1644 const char *pszComment);
1645
1646/**
1647 * Get UUID of image in HDD container.
1648 *
1649 * @return VBox status code.
1650 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1651 * @param pDisk Pointer to HDD container.
1652 * @param nImage Image number, counts from 0. 0 is always base image of container.
1653 * @param pUuid Where to store the image UUID.
1654 */
1655VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1656
1657/**
1658 * Set the image's UUID. Should not be used by normal applications.
1659 *
1660 * @return VBox status code.
1661 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1662 * @param pDisk Pointer to HDD container.
1663 * @param nImage Image number, counts from 0. 0 is always base image of container.
1664 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1665 */
1666VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1667
1668/**
1669 * Get last modification UUID of image in HDD container.
1670 *
1671 * @return VBox status code.
1672 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1673 * @param pDisk Pointer to HDD container.
1674 * @param nImage Image number, counts from 0. 0 is always base image of container.
1675 * @param pUuid Where to store the image modification UUID.
1676 */
1677VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1678 PRTUUID pUuid);
1679
1680/**
1681 * Set the image's last modification UUID. Should not be used by normal applications.
1682 *
1683 * @return VBox status code.
1684 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1685 * @param pDisk Pointer to HDD container.
1686 * @param nImage Image number, counts from 0. 0 is always base image of container.
1687 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1688 */
1689VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1690 PCRTUUID pUuid);
1691
1692/**
1693 * Get parent UUID of image in HDD container.
1694 *
1695 * @return VBox status code.
1696 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1697 * @param pDisk Pointer to HDD container.
1698 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1699 * @param pUuid Where to store the parent image UUID.
1700 */
1701VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1702 PRTUUID pUuid);
1703
1704/**
1705 * Set the image's parent UUID. Should not be used by normal applications.
1706 *
1707 * @return VBox status code.
1708 * @param pDisk Pointer to HDD container.
1709 * @param nImage Image number, counts from 0. 0 is always base image of container.
1710 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1711 */
1712VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1713 PCRTUUID pUuid);
1714
1715
1716/**
1717 * Debug helper - dumps all opened images in HDD container into the log file.
1718 *
1719 * @param pDisk Pointer to HDD container.
1720 */
1721VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
1722
1723
1724/**
1725 * Query if asynchronous operations are supported for this disk.
1726 *
1727 * @return VBox status code.
1728 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1729 * @param pDisk Pointer to the HDD container.
1730 * @param nImage Image number, counts from 0. 0 is always base image of container.
1731 * @param pfAIOSupported Where to store if async IO is supported.
1732 */
1733VBOXDDU_DECL(int) VDImageIsAsyncIOSupported(PVBOXHDD pDisk, unsigned nImage, bool *pfAIOSupported);
1734
1735
1736/**
1737 * Start a asynchronous read request.
1738 *
1739 * @return VBox status code.
1740 * @param pDisk Pointer to the HDD container.
1741 * @param uOffset The offset of the virtual disk to read from.
1742 * @param cbRead How many bytes to read.
1743 * @param paSeg Pointer to an array of segments.
1744 * @param cSeg Number of segments in the array.
1745 * @param pvUser User data which is passed on completion
1746 */
1747VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
1748 PPDMDATASEG paSeg, unsigned cSeg,
1749 void *pvUser);
1750
1751
1752/**
1753 * Start a asynchronous write request.
1754 *
1755 * @return VBox status code.
1756 * @param pDisk Pointer to the HDD container.
1757 * @param uOffset The offset of the virtual disk to write to.
1758 * @param cbWrtie How many bytes to write.
1759 * @param paSeg Pointer to an array of segments.
1760 * @param cSeg Number of segments in the array.
1761 * @param pvUser User data which is passed on completion.
1762 */
1763VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
1764 PPDMDATASEG paSeg, unsigned cSeg,
1765 void *pvUser);
1766
1767
1768RT_C_DECLS_END
1769
1770/** @} */
1771
1772#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