VirtualBox

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

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

Storage/iSCSI: switch to sending in a single call, avoiding separate sending of iSCSI PDU header separately on some IP stacks. Adjustments to VBoxHDD, DrvVD and MediumImpl to pass the required VD interface methods.

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