VirtualBox

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

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

Assertion

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 87.6 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 from 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 * @param pcbRead Number of bytes read.
1069 */
1070 DECLR3CALLBACKMEMBER(int, pfnWrite, (RTSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
1071
1072 /**
1073 * Flush socket write buffers.
1074 *
1075 * @return iprt status code.
1076 * @param Sock Socket descriptor.
1077 */
1078 DECLR3CALLBACKMEMBER(int, pfnFlush, (RTSOCKET Sock));
1079
1080 /**
1081 * Gets the address of the local side.
1082 *
1083 * @return iprt status code.
1084 * @param Sock Socket descriptor.
1085 * @param pAddr Where to store the local address on success.
1086 */
1087 DECLR3CALLBACKMEMBER(int, pfnGetLocalAddress, (RTSOCKET Sock, PRTNETADDR pAddr));
1088
1089 /**
1090 * Gets the address of the other party.
1091 *
1092 * @return iprt status code.
1093 * @param Sock Socket descriptor.
1094 * @param pAddr Where to store the peer address on success.
1095 */
1096 DECLR3CALLBACKMEMBER(int, pfnGetPeerAddress, (RTSOCKET Sock, PRTNETADDR pAddr));
1097
1098} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
1099
1100/**
1101 * Get TCP network stack interface from opaque callback table.
1102 *
1103 * @return Pointer to the callback table.
1104 * @param pInterface Pointer to the interface descriptor.
1105 */
1106DECLINLINE(PVDINTERFACETCPNET) VDGetInterfaceTcpNet(PVDINTERFACE pInterface)
1107{
1108 /* Check that the interface descriptor is a TCP network stack interface. */
1109 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_TCPNET)
1110 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1111 ("Not a TCP network stack interface"), NULL);
1112
1113 PVDINTERFACETCPNET pInterfaceTcpNet = (PVDINTERFACETCPNET)pInterface->pCallbacks;
1114
1115 /* Do basic checks. */
1116 AssertMsgReturn( (pInterfaceTcpNet->cbSize == sizeof(VDINTERFACETCPNET))
1117 && (pInterfaceTcpNet->enmInterface == VDINTERFACETYPE_TCPNET),
1118 ("A non TCP network stack callback table attached to a TCP network stack interface descriptor\n"), NULL);
1119
1120 return pInterfaceTcpNet;
1121}
1122
1123/**
1124 * Interface to get the parent state.
1125 *
1126 * Per operation interface. Optional, present only if there is a parent, and
1127 * used only internally for compacting.
1128 */
1129typedef struct VDINTERFACEPARENTSTATE
1130{
1131 /**
1132 * Size of the parent state interface.
1133 */
1134 uint32_t cbSize;
1135
1136 /**
1137 * Interface type.
1138 */
1139 VDINTERFACETYPE enmInterface;
1140
1141 /**
1142 * Read data callback.
1143 *
1144 * @return VBox status code.
1145 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1146 * @param pvUser The opaque data passed for the operation.
1147 * @param uOffset Offset of first reading byte from start of disk.
1148 * Must be aligned to a sector boundary.
1149 * @param pvBuf Pointer to buffer for reading data.
1150 * @param cbRead Number of bytes to read.
1151 * Must be aligned to a sector boundary.
1152 */
1153 DECLR3CALLBACKMEMBER(int, pfnParentRead, (void *pvUser, uint64_t uOffset, void *pvBuf, size_t cbRead));
1154
1155} VDINTERFACEPARENTSTATE, *PVDINTERFACEPARENTSTATE;
1156
1157
1158/**
1159 * Get parent state interface from opaque callback table.
1160 *
1161 * @return Pointer to the callback table.
1162 * @param pInterface Pointer to the interface descriptor.
1163 */
1164DECLINLINE(PVDINTERFACEPARENTSTATE) VDGetInterfaceParentState(PVDINTERFACE pInterface)
1165{
1166 /* Check that the interface descriptor is a parent state interface. */
1167 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PARENTSTATE)
1168 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1169 ("Not a parent state interface"), NULL);
1170
1171 PVDINTERFACEPARENTSTATE pInterfaceParentState = (PVDINTERFACEPARENTSTATE)pInterface->pCallbacks;
1172
1173 /* Do basic checks. */
1174 AssertMsgReturn( (pInterfaceParentState->cbSize == sizeof(VDINTERFACEPARENTSTATE))
1175 && (pInterfaceParentState->enmInterface == VDINTERFACETYPE_PARENTSTATE),
1176 ("A non parent state callback table attached to a parent state interface descriptor\n"), NULL);
1177
1178 return pInterfaceParentState;
1179}
1180
1181/**
1182 * Interface to synchronize concurrent accesses by several threads.
1183 *
1184 * @note The scope of this interface is to manage concurrent accesses after
1185 * the HDD container has been created, and they must stop before destroying the
1186 * container. Opening or closing images is covered by the synchronization, but
1187 * that does not mean it is safe to close images while a thread executes
1188 * <link to="VDMerge"/> or <link to="VDCopy"/> operating on these images.
1189 * Making them safe would require the lock to be held during the entire
1190 * operation, which prevents other concurrent acitivities.
1191 *
1192 * @note Right now this is kept as simple as possible, and does not even
1193 * attempt to provide enough information to allow e.g. concurrent write
1194 * accesses to different areas of the disk. The reason is that it is very
1195 * difficult to predict which area of a disk is affected by a write,
1196 * especially when different image formats are mixed. Maybe later a more
1197 * sophisticated interface will be provided which has the necessary information
1198 * about worst case affected areas.
1199 *
1200 * Per disk interface. Optional, needed if the disk is accessed concurrently
1201 * by several threads, e.g. when merging diff images while a VM is running.
1202 */
1203typedef struct VDINTERFACETHREADSYNC
1204{
1205 /**
1206 * Size of the thread synchronization interface.
1207 */
1208 uint32_t cbSize;
1209
1210 /**
1211 * Interface type.
1212 */
1213 VDINTERFACETYPE enmInterface;
1214
1215 /**
1216 * Start a read operation.
1217 */
1218 DECLR3CALLBACKMEMBER(int, pfnStartRead, (void *pvUser));
1219
1220 /**
1221 * Finish a read operation.
1222 */
1223 DECLR3CALLBACKMEMBER(int, pfnFinishRead, (void *pvUser));
1224
1225 /**
1226 * Start a write operation.
1227 */
1228 DECLR3CALLBACKMEMBER(int, pfnStartWrite, (void *pvUser));
1229
1230 /**
1231 * Finish a write operation.
1232 */
1233 DECLR3CALLBACKMEMBER(int, pfnFinishWrite, (void *pvUser));
1234
1235} VDINTERFACETHREADSYNC, *PVDINTERFACETHREADSYNC;
1236
1237/**
1238 * Get thread synchronization interface from opaque callback table.
1239 *
1240 * @return Pointer to the callback table.
1241 * @param pInterface Pointer to the interface descriptor.
1242 */
1243DECLINLINE(PVDINTERFACETHREADSYNC) VDGetInterfaceThreadSync(PVDINTERFACE pInterface)
1244{
1245 /* Check that the interface descriptor is a thread synchronization interface. */
1246 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_THREADSYNC)
1247 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1248 ("Not a thread synchronization interface"), NULL);
1249
1250 PVDINTERFACETHREADSYNC pInterfaceThreadSync = (PVDINTERFACETHREADSYNC)pInterface->pCallbacks;
1251
1252 /* Do basic checks. */
1253 AssertMsgReturn( (pInterfaceThreadSync->cbSize == sizeof(VDINTERFACETHREADSYNC))
1254 && (pInterfaceThreadSync->enmInterface == VDINTERFACETYPE_THREADSYNC),
1255 ("A non thread synchronization callback table attached to a thread synchronization interface descriptor\n"), NULL);
1256
1257 return pInterfaceThreadSync;
1258}
1259
1260/** @name Configuration interface key handling flags.
1261 * @{
1262 */
1263/** Mandatory config key. Not providing a value for this key will cause
1264 * the backend to fail. */
1265#define VD_CFGKEY_MANDATORY RT_BIT(0)
1266/** Expert config key. Not showing it by default in the GUI is is probably
1267 * a good idea, as the average user won't understand it easily. */
1268#define VD_CFGKEY_EXPERT RT_BIT(1)
1269/** @}*/
1270
1271
1272/**
1273 * Configuration value type for configuration information interface.
1274 */
1275typedef enum VDCFGVALUETYPE
1276{
1277 /** Integer value. */
1278 VDCFGVALUETYPE_INTEGER = 1,
1279 /** String value. */
1280 VDCFGVALUETYPE_STRING,
1281 /** Bytestring value. */
1282 VDCFGVALUETYPE_BYTES
1283} VDCFGVALUETYPE;
1284
1285
1286/**
1287 * Structure describing configuration keys required/supported by a backend
1288 * through the config interface.
1289 */
1290typedef struct VDCONFIGINFO
1291{
1292 /** Key name of the configuration. */
1293 const char *pszKey;
1294 /** Pointer to default value (descriptor). NULL if no useful default value
1295 * can be specified. */
1296 const char *pszDefaultValue;
1297 /** Value type for this key. */
1298 VDCFGVALUETYPE enmValueType;
1299 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
1300 uint64_t uKeyFlags;
1301} VDCONFIGINFO;
1302
1303/** Pointer to structure describing configuration keys. */
1304typedef VDCONFIGINFO *PVDCONFIGINFO;
1305
1306/** Pointer to const structure describing configuration keys. */
1307typedef const VDCONFIGINFO *PCVDCONFIGINFO;
1308
1309/**
1310 * Data structure for returning a list of backend capabilities.
1311 */
1312typedef struct VDBACKENDINFO
1313{
1314 /** Name of the backend. Must be unique even with case insensitive comparison. */
1315 const char *pszBackend;
1316 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
1317 uint64_t uBackendCaps;
1318 /** Pointer to a NULL-terminated array of strings, containing the supported
1319 * file extensions. Note that some backends do not work on files, so this
1320 * pointer may just contain NULL. */
1321 const char * const *papszFileExtensions;
1322 /** Pointer to an array of structs describing each supported config key.
1323 * Terminated by a NULL config key. Note that some backends do not support
1324 * the configuration interface, so this pointer may just contain NULL.
1325 * Mandatory if the backend sets VD_CAP_CONFIG. */
1326 PCVDCONFIGINFO paConfigInfo;
1327 /** Returns a human readable hard disk location string given a
1328 * set of hard disk configuration keys. The returned string is an
1329 * equivalent of the full file path for image-based hard disks.
1330 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
1331 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
1332 /** Returns a human readable hard disk name string given a
1333 * set of hard disk configuration keys. The returned string is an
1334 * equivalent of the file name part in the full file path for
1335 * image-based hard disks. Mandatory for backends with no
1336 * VD_CAP_FILE and NULL otherwise. */
1337 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
1338} VDBACKENDINFO, *PVDBACKENDINFO;
1339
1340
1341/** Forward declaration. Only visible in the VBoxHDD module. */
1342/** I/O context */
1343typedef struct VDIOCTX *PVDIOCTX;
1344/** Storage backend handle. */
1345typedef struct VDIOSTORAGE *PVDIOSTORAGE;
1346/** Pointer to a storage backend handle. */
1347typedef PVDIOSTORAGE *PPVDIOSTORAGE;
1348
1349/**
1350 * Completion callback for metadata reads or writes.
1351 *
1352 * @return nothing.
1353 * @param pvBackendData The opaque backend data.
1354 * @param pIoCtx I/O context associated with this request.
1355 * @param pvMetaUser Opaque user data passed during a metadata read/write request.
1356 */
1357typedef DECLCALLBACK(void) FNVDMETACOMPLETED(void *pvBackendData, PVDIOCTX pIoCtx, void *pvMetaUser);
1358/** Pointer to FNVDCOMPLETED() */
1359typedef FNVDMETACOMPLETED *PFNVDMETACOMPLETED;
1360
1361/**
1362 * Support interface for I/O
1363 *
1364 * Per-image. Required.
1365 */
1366typedef struct VDINTERFACEIO
1367{
1368 /**
1369 * Size of the I/O interface.
1370 */
1371 uint32_t cbSize;
1372
1373 /**
1374 * Interface type.
1375 */
1376 VDINTERFACETYPE enmInterface;
1377
1378 /**
1379 * Open callback
1380 *
1381 * @return VBox status code.
1382 * @param pvUser The opaque data passed on container creation.
1383 * @param pszLocation Name of the location to open.
1384 * @param uOpenFlags Flags for opening the backend.
1385 * See VD_INTERFACEASYNCIO_OPEN_FLAGS_* #defines
1386 * @param ppStorage Where to store the storage handle.
1387 */
1388 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation,
1389 unsigned uOpenFlags, PPVDIOSTORAGE ppStorage));
1390
1391 /**
1392 * Close callback.
1393 *
1394 * @return VBox status code.
1395 * @param pvUser The opaque data passed on container creation.
1396 * @param pStorage The storage handle to close.
1397 */
1398 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, PVDIOSTORAGE pStorage));
1399
1400 /**
1401 * Returns the size of the opened storage backend.
1402 *
1403 * @return VBox status code.
1404 * @param pvUser The opaque data passed on container creation.
1405 * @param pStorage The storage handle to get the size from.
1406 * @param pcbSize Where to store the size of the storage backend.
1407 */
1408 DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, PVDIOSTORAGE pStorage,
1409 uint64_t *pcbSize));
1410
1411 /**
1412 * Sets the size of the opened storage backend if possible.
1413 *
1414 * @return VBox status code.
1415 * @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
1416 * @param pvUser The opaque data passed on container creation.
1417 * @param pStorage The storage handle.
1418 * @param cbSize The new size of the image.
1419 */
1420 DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, PVDIOSTORAGE pStorage,
1421 uint64_t cbSize));
1422
1423 /**
1424 * Synchronous write callback.
1425 *
1426 * @return VBox status code.
1427 * @param pvUser The opaque data passed on container creation.
1428 * @param pStorage The storage handle to use.
1429 * @param uOffset The offset to start from.
1430 * @param cbWrite How many bytes to write.
1431 * @param pvBuf Pointer to the bits need to be written.
1432 * @param pcbWritten Where to store how many bytes where actually written.
1433 *
1434 * @notes Do not use in code called from the async read/write entry points in the backends.
1435 * This should be only used during open/close of images and for the support functions
1436 * which are not called while a VM is running (pfnCompact).
1437 */
1438 DECLR3CALLBACKMEMBER(int, pfnWriteSync, (void *pvUser, PVDIOSTORAGE pStorage, uint64_t uOffset,
1439 size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
1440
1441 /**
1442 * Synchronous read callback.
1443 *
1444 * @return VBox status code.
1445 * @param pvUser The opaque data passed on container creation.
1446 * @param pStorage The storage handle to use.
1447 * @param uOffset The offset to start from.
1448 * @param cbRead How many bytes to read.
1449 * @param pvBuf Where to store the read bits.
1450 * @param pcbRead Where to store how many bytes where actually read.
1451 *
1452 * @notes See pfnWriteSync()
1453 */
1454 DECLR3CALLBACKMEMBER(int, pfnReadSync, (void *pvUser, PVDIOSTORAGE pStorage, uint64_t uOffset,
1455 size_t cbRead, void *pvBuf, size_t *pcbRead));
1456
1457 /**
1458 * Flush data to the storage backend.
1459 *
1460 * @return VBox statis code.
1461 * @param pvUser The opaque data passed on container creation.
1462 * @param pStorage The storage handle to flush.
1463 *
1464 * @notes See pfnWriteSync()
1465 */
1466 DECLR3CALLBACKMEMBER(int, pfnFlushSync, (void *pvUser, PVDIOSTORAGE pStorage));
1467
1468 /**
1469 * Initiate a asynchronous read request for user data.
1470 *
1471 * @return VBox status code.
1472 * @param pvUser The opqaue user data passed on container creation.
1473 * @param pStorage The storage handle.
1474 * @param uOffset The offset to start reading from.
1475 * @param pIoCtx I/O context passed in VDAsyncRead/Write.
1476 * @param cbRead How many bytes to read.
1477 */
1478 DECLR3CALLBACKMEMBER(int, pfnReadUserAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1479 uint64_t uOffset, PVDIOCTX pIoCtx,
1480 size_t cbRead));
1481
1482 /**
1483 * Initiate a asynchronous write request for user data.
1484 *
1485 * @return VBox status code.
1486 * @param pvUser The opaque user data passed on container creation.
1487 * @param pStorage The storage handle.
1488 * @param uOffset The offset to start writing to.
1489 * @param pIoCtx I/O context passed in VDAsyncRead/Write
1490 * @param cbWrite How many bytes to write.
1491 */
1492 DECLR3CALLBACKMEMBER(int, pfnWriteUserAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1493 uint64_t uOffset, PVDIOCTX pIoCtx,
1494 size_t cbWrite));
1495
1496 /**
1497 * Reads metadata asynchronously from storage.
1498 * The current I/O context will be halted.
1499 *
1500 * @returns VBox status code.
1501 * @param pvUser The opaque user data passed on container creation.
1502 * @param pStorage The storage handle.
1503 * @param uOffset Offsete to start reading from.
1504 * @param pvBuf Where to store the data.
1505 * @param cbRead How many bytes to read.
1506 * @param pIoCtx The I/O context which triggered the read.
1507 * @param pfnMetaCompleted Callback to call when the read completes.
1508 * @param pvMetaUser Opaque user data which is passed in the callback.
1509 */
1510 DECLR3CALLBACKMEMBER(int, pfnReadMetaAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1511 uint64_t uOffset, void *pvBuf,
1512 size_t cbRead, PVDIOCTX pIoCtx,
1513 PFNVDMETACOMPLETED pfnMetaCompleted,
1514 void *pvMetaUser));
1515
1516 /**
1517 * Writes metadata asynchronously to storage.
1518 *
1519 * @returns VBox status code.
1520 * @param pvUser The opaque user data passed on container creation.
1521 * @param pStorage The storage handle.
1522 * @param uOffset Offsete to start writing to.
1523 * @param pvBuf Written data.
1524 * @param cbWrite How many bytes to write.
1525 * @param pIoCtx The I/O context which triggered the write.
1526 * @param pfnMetaCompleted Callback to call when the write completes.
1527 * @param pvMetaUser Opaque user data which is passed in the callback.
1528 */
1529 DECLR3CALLBACKMEMBER(int, pfnWriteMetaAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1530 uint64_t uOffset, void *pvBuf,
1531 size_t cbWrite, PVDIOCTX pIoCtx,
1532 PFNVDMETACOMPLETED pfnMetaCompleted,
1533 void *pvMetaUser));
1534
1535 /**
1536 * Initiates a async flush request.
1537 *
1538 * @return VBox statis code.
1539 * @param pvUser The opaque data passed on container creation.
1540 * @param pStorage The storage handle to flush.
1541 * @param pIoCtx I/O context which triggered the flush.
1542 */
1543 DECLR3CALLBACKMEMBER(int, pfnFlushAsync, (void *pvUser, PVDIOSTORAGE pStorage,
1544 PVDIOCTX pIoCtx));
1545
1546 /**
1547 * Copies a buffer into the I/O context.
1548 *
1549 * @return Number of bytes copied.
1550 * @param pvUser The opaque user data passed on conatiner creation.
1551 * @param pIoCtx I/O context to copy the data to.
1552 * @param pvBuf Buffer to copy.
1553 * @param cbBuf Number of bytes to copy.
1554 */
1555 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyTo, (void *pvUser, PVDIOCTX pIoCtx,
1556 void *pvBuf, size_t cbBuf));
1557
1558 /**
1559 * Copies data from the I/O context into a buffer.
1560 *
1561 * @return Number of bytes copied.
1562 * @param pvUser The opaque user data passed on conatiner creation.
1563 * @param pIoCtx I/O context to copy the data from.
1564 * @param pvBuf Destination buffer.
1565 * @param cbBuf Number of bytes to copy.
1566 */
1567 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyFrom, (void *pvUser, PVDIOCTX pIoCtx,
1568 void *pvBuf, size_t cbBuf));
1569
1570 /**
1571 * Sets the buffer of the given context to a specific byte.
1572 *
1573 * @return Number of bytes set.
1574 * @param pvUser The opaque user data passed on conatiner creation.
1575 * @param pIoCtx I/O context to copy the data from.
1576 * @param ch The byte to set.
1577 * @param cbSet Number of bytes to set.
1578 */
1579 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSet, (void *pvUser, PVDIOCTX pIoCtx,
1580 int ch, size_t cbSet));
1581
1582} VDINTERFACEIO, *PVDINTERFACEIO;
1583
1584/**
1585 * Get async I/O interface from opaque callback table.
1586 *
1587 * @return Pointer to the callback table.
1588 * @param pInterface Pointer to the interface descriptor.
1589 */
1590DECLINLINE(PVDINTERFACEIO) VDGetInterfaceIO(PVDINTERFACE pInterface)
1591{
1592 /* Check that the interface descriptor is a async I/O interface. */
1593 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_IO)
1594 && (pInterface->cbSize == sizeof(VDINTERFACE)),
1595 ("Not an I/O interface"), NULL);
1596
1597 PVDINTERFACEIO pInterfaceIO = (PVDINTERFACEIO)pInterface->pCallbacks;
1598
1599 /* Do basic checks. */
1600 AssertMsgReturn( (pInterfaceIO->cbSize == sizeof(VDINTERFACEIO))
1601 && (pInterfaceIO->enmInterface == VDINTERFACETYPE_IO),
1602 ("A non I/O callback table attached to a I/O interface descriptor\n"), NULL);
1603
1604 return pInterfaceIO;
1605}
1606
1607/**
1608 * VBox HDD Container main structure.
1609 */
1610/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
1611struct VBOXHDD;
1612typedef struct VBOXHDD VBOXHDD;
1613typedef VBOXHDD *PVBOXHDD;
1614
1615/**
1616 * Request completion callback for the async read/write API.
1617 */
1618typedef void (FNVDASYNCTRANSFERCOMPLETE) (void *pvUser1, void *pvUser2, int rcReq);
1619/** Pointer to a transfer compelte callback. */
1620typedef FNVDASYNCTRANSFERCOMPLETE *PFNVDASYNCTRANSFERCOMPLETE;
1621
1622/**
1623 * Initializes HDD backends.
1624 *
1625 * @returns VBox status code.
1626 */
1627VBOXDDU_DECL(int) VDInit(void);
1628
1629/**
1630 * Destroys loaded HDD backends.
1631 *
1632 * @returns VBox status code.
1633 */
1634VBOXDDU_DECL(int) VDShutdown(void);
1635
1636/**
1637 * Lists all HDD backends and their capabilities in a caller-provided buffer.
1638 *
1639 * @return VBox status code.
1640 * VERR_BUFFER_OVERFLOW if not enough space is passed.
1641 * @param cEntriesAlloc Number of list entries available.
1642 * @param pEntries Pointer to array for the entries.
1643 * @param pcEntriesUsed Number of entries returned.
1644 */
1645VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
1646 unsigned *pcEntriesUsed);
1647
1648/**
1649 * Lists the capablities of a backend indentified by its name.
1650 *
1651 * @return VBox status code.
1652 * @param pszBackend The backend name (case insensitive).
1653 * @param pEntries Pointer to an entry.
1654 */
1655VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
1656
1657/**
1658 * Allocates and initializes an empty HDD container.
1659 * No image files are opened.
1660 *
1661 * @return VBox status code.
1662 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1663 * @param ppDisk Where to store the reference to HDD container.
1664 */
1665VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, PVBOXHDD *ppDisk);
1666
1667/**
1668 * Destroys HDD container.
1669 * If container has opened image files they will be closed.
1670 *
1671 * @param pDisk Pointer to HDD container.
1672 */
1673VBOXDDU_DECL(void) VDDestroy(PVBOXHDD pDisk);
1674
1675/**
1676 * Try to get the backend name which can use this image.
1677 *
1678 * @return VBox status code.
1679 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1680 * @param pszFilename Name of the image file for which the backend is queried.
1681 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
1682 * The returned pointer must be freed using RTStrFree().
1683 */
1684VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, const char *pszFilename, char **ppszFormat);
1685
1686/**
1687 * Opens an image file.
1688 *
1689 * The first opened image file in HDD container must have a base image type,
1690 * others (next opened images) must be differencing or undo images.
1691 * Linkage is checked for differencing image to be consistent with the previously opened image.
1692 * When another differencing image is opened and the last image was opened in read/write access
1693 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
1694 * other processes to use images in read-only mode too.
1695 *
1696 * Note that the image is opened in read-only mode if a read/write open is not possible.
1697 * Use VDIsReadOnly to check open mode.
1698 *
1699 * @return VBox status code.
1700 * @param pDisk Pointer to HDD container.
1701 * @param pszBackend Name of the image file backend to use (case insensitive).
1702 * @param pszFilename Name of the image file to open.
1703 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1704 * @param pVDIfsImage Pointer to the per-image VD interface list.
1705 */
1706VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
1707 const char *pszFilename, unsigned uOpenFlags,
1708 PVDINTERFACE pVDIfsImage);
1709
1710/**
1711 * Creates and opens a new base image file.
1712 *
1713 * @return VBox status code.
1714 * @param pDisk Pointer to HDD container.
1715 * @param pszBackend Name of the image file backend to use (case insensitive).
1716 * @param pszFilename Name of the image file to create.
1717 * @param cbSize Image size in bytes.
1718 * @param uImageFlags Flags specifying special image features.
1719 * @param pszComment Pointer to image comment. NULL is ok.
1720 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
1721 * @param pLCHSGeometry Pointer to logical disk geometry <= (x,255,63). Not NULL.
1722 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1723 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1724 * @param pVDIfsImage Pointer to the per-image VD interface list.
1725 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1726 */
1727VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
1728 const char *pszFilename, uint64_t cbSize,
1729 unsigned uImageFlags, const char *pszComment,
1730 PCPDMMEDIAGEOMETRY pPCHSGeometry,
1731 PCPDMMEDIAGEOMETRY pLCHSGeometry,
1732 PCRTUUID pUuid, unsigned uOpenFlags,
1733 PVDINTERFACE pVDIfsImage,
1734 PVDINTERFACE pVDIfsOperation);
1735
1736/**
1737 * Creates and opens a new differencing image file in HDD container.
1738 * See comments for VDOpen function about differencing images.
1739 *
1740 * @return VBox status code.
1741 * @param pDisk Pointer to HDD container.
1742 * @param pszBackend Name of the image file backend to use (case insensitive).
1743 * @param pszFilename Name of the differencing image file to create.
1744 * @param uImageFlags Flags specifying special image features.
1745 * @param pszComment Pointer to image comment. NULL is ok.
1746 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1747 * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically.
1748 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1749 * @param pVDIfsImage Pointer to the per-image VD interface list.
1750 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1751 */
1752VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
1753 const char *pszFilename, unsigned uImageFlags,
1754 const char *pszComment, PCRTUUID pUuid,
1755 PCRTUUID pParentUuid, unsigned uOpenFlags,
1756 PVDINTERFACE pVDIfsImage,
1757 PVDINTERFACE pVDIfsOperation);
1758
1759/**
1760 * Merges two images (not necessarily with direct parent/child relationship).
1761 * As a side effect the source image and potentially the other images which
1762 * are also merged to the destination are deleted from both the disk and the
1763 * images in the HDD container.
1764 *
1765 * @return VBox status code.
1766 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1767 * @param pDisk Pointer to HDD container.
1768 * @param nImageFrom Image number to merge from, counts from 0. 0 is always base image of container.
1769 * @param nImageTo Image number to merge to, counts from 0. 0 is always base image of container.
1770 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1771 */
1772VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
1773 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
1774
1775/**
1776 * Copies an image from one HDD container to another.
1777 * The copy is opened in the target HDD container.
1778 * It is possible to convert between different image formats, because the
1779 * backend for the destination may be different from the source.
1780 * If both the source and destination reference the same HDD container,
1781 * then the image is moved (by copying/deleting or renaming) to the new location.
1782 * The source container is unchanged if the move operation fails, otherwise
1783 * the image at the new location is opened in the same way as the old one was.
1784 *
1785 * @note The read/write accesses across disks are not synchronized, just the
1786 * accesses to each disk. Once there is a use case which requires a defined
1787 * read/write behavior in this situation this needs to be extended.
1788 *
1789 * @return VBox status code.
1790 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1791 * @param pDiskFrom Pointer to source HDD container.
1792 * @param nImage Image number, counts from 0. 0 is always base image of container.
1793 * @param pDiskTo Pointer to destination HDD container.
1794 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
1795 * @param pszFilename New name of the image (may be NULL to specify that the
1796 * copy destination is the destination container, or
1797 * if pDiskFrom == pDiskTo, i.e. when moving).
1798 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
1799 * @param cbSize New image size (0 means leave unchanged).
1800 * @param uImageFlags Flags specifying special destination image features.
1801 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
1802 * This parameter is used if and only if a true copy is created.
1803 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
1804 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1805 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
1806 * destination image.
1807 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
1808 * for the destination operation.
1809 */
1810VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
1811 const char *pszBackend, const char *pszFilename,
1812 bool fMoveByRename, uint64_t cbSize,
1813 unsigned uImageFlags, PCRTUUID pDstUuid,
1814 PVDINTERFACE pVDIfsOperation,
1815 PVDINTERFACE pDstVDIfsImage,
1816 PVDINTERFACE pDstVDIfsOperation);
1817
1818/**
1819 * Optimizes the storage consumption of an image. Typically the unused blocks
1820 * have to be wiped with zeroes to achieve a substantial reduced storage use.
1821 * Another optimization done is reordering the image blocks, which can provide
1822 * a significant performance boost, as reads and writes tend to use less random
1823 * file offsets.
1824 *
1825 * @note Compaction is treated as a single operation with regard to thread
1826 * synchronization, which means that it potentially blocks other activities for
1827 * a long time. The complexity of compaction would grow even more if concurrent
1828 * accesses have to be handled.
1829 *
1830 * @return VBox status code.
1831 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1832 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
1833 * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but
1834 * this isn't supported yet.
1835 * @param pDisk Pointer to HDD container.
1836 * @param nImage Image number, counts from 0. 0 is always base image of container.
1837 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1838 */
1839VBOXDDU_DECL(int) VDCompact(PVBOXHDD pDisk, unsigned nImage,
1840 PVDINTERFACE pVDIfsOperation);
1841
1842/**
1843 * Closes the last opened image file in HDD container.
1844 * If previous image file was opened in read-only mode (the normal case) and
1845 * the last opened image is in read-write mode then the previous image will be
1846 * reopened in read/write mode.
1847 *
1848 * @return VBox status code.
1849 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1850 * @param pDisk Pointer to HDD container.
1851 * @param fDelete If true, delete the image from the host disk.
1852 */
1853VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
1854
1855/**
1856 * Closes all opened image files in HDD container.
1857 *
1858 * @return VBox status code.
1859 * @param pDisk Pointer to HDD container.
1860 */
1861VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
1862
1863/**
1864 * Read data from virtual HDD.
1865 *
1866 * @return VBox status code.
1867 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1868 * @param pDisk Pointer to HDD container.
1869 * @param uOffset Offset of first reading byte from start of disk.
1870 * Must be aligned to a sector boundary.
1871 * @param pvBuf Pointer to buffer for reading data.
1872 * @param cbRead Number of bytes to read.
1873 * Must be aligned to a sector boundary.
1874 */
1875VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
1876
1877/**
1878 * Write data to virtual HDD.
1879 *
1880 * @return VBox status code.
1881 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1882 * @param pDisk Pointer to HDD container.
1883 * @param uOffset Offset of first writing byte from start of disk.
1884 * Must be aligned to a sector boundary.
1885 * @param pvBuf Pointer to buffer for writing data.
1886 * @param cbWrite Number of bytes to write.
1887 * Must be aligned to a sector boundary.
1888 */
1889VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
1890
1891/**
1892 * Make sure the on disk representation of a virtual HDD is up to date.
1893 *
1894 * @return VBox status code.
1895 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1896 * @param pDisk Pointer to HDD container.
1897 */
1898VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
1899
1900/**
1901 * Get number of opened images in HDD container.
1902 *
1903 * @return Number of opened images for HDD container. 0 if no images have been opened.
1904 * @param pDisk Pointer to HDD container.
1905 */
1906VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
1907
1908/**
1909 * Get read/write mode of HDD container.
1910 *
1911 * @return Virtual disk ReadOnly status.
1912 * @return true if no image is opened in HDD container.
1913 * @param pDisk Pointer to HDD container.
1914 */
1915VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
1916
1917/**
1918 * Get total capacity of an image in HDD container.
1919 *
1920 * @return Virtual disk size in bytes.
1921 * @return 0 if image with specified number was not opened.
1922 * @param pDisk Pointer to HDD container.
1923 * @param nImage Image number, counts from 0. 0 is always base image of container.
1924 */
1925VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
1926
1927/**
1928 * Get total file size of an image in HDD container.
1929 *
1930 * @return Virtual disk size in bytes.
1931 * @return 0 if image with specified number was not opened.
1932 * @param pDisk Pointer to HDD container.
1933 * @param nImage Image number, counts from 0. 0 is always base image of container.
1934 */
1935VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
1936
1937/**
1938 * Get virtual disk PCHS geometry of an image in HDD container.
1939 *
1940 * @return VBox status code.
1941 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1942 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1943 * @param pDisk Pointer to HDD container.
1944 * @param nImage Image number, counts from 0. 0 is always base image of container.
1945 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1946 */
1947VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1948 PPDMMEDIAGEOMETRY pPCHSGeometry);
1949
1950/**
1951 * Store virtual disk PCHS geometry of an image in HDD container.
1952 *
1953 * @return VBox status code.
1954 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1955 * @param pDisk Pointer to HDD container.
1956 * @param nImage Image number, counts from 0. 0 is always base image of container.
1957 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1958 */
1959VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1960 PCPDMMEDIAGEOMETRY pPCHSGeometry);
1961
1962/**
1963 * Get virtual disk LCHS geometry of an image in HDD container.
1964 *
1965 * @return VBox status code.
1966 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1967 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1968 * @param pDisk Pointer to HDD container.
1969 * @param nImage Image number, counts from 0. 0 is always base image of container.
1970 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1971 */
1972VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1973 PPDMMEDIAGEOMETRY pLCHSGeometry);
1974
1975/**
1976 * Store virtual disk LCHS geometry of an image in HDD container.
1977 *
1978 * @return VBox status code.
1979 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1980 * @param pDisk Pointer to HDD container.
1981 * @param nImage Image number, counts from 0. 0 is always base image of container.
1982 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1983 */
1984VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1985 PCPDMMEDIAGEOMETRY pLCHSGeometry);
1986
1987/**
1988 * Get version of image in HDD container.
1989 *
1990 * @return VBox status code.
1991 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1992 * @param pDisk Pointer to HDD container.
1993 * @param nImage Image number, counts from 0. 0 is always base image of container.
1994 * @param puVersion Where to store the image version.
1995 */
1996VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
1997 unsigned *puVersion);
1998
1999/**
2000 * List the capabilities of image backend in HDD container.
2001 *
2002 * @return VBox status code.
2003 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2004 * @param pDisk Pointer to the HDD container.
2005 * @param nImage Image number, counts from 0. 0 is always base image of container.
2006 * @param pbackendInfo Where to store the backend information.
2007 */
2008VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
2009 PVDBACKENDINFO pBackendInfo);
2010
2011/**
2012 * Get flags of image in HDD container.
2013 *
2014 * @return VBox status code.
2015 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2016 * @param pDisk Pointer to HDD container.
2017 * @param nImage Image number, counts from 0. 0 is always base image of container.
2018 * @param puImageFlags Where to store the image flags.
2019 */
2020VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
2021
2022/**
2023 * Get open flags of image in HDD container.
2024 *
2025 * @return VBox status code.
2026 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2027 * @param pDisk Pointer to HDD container.
2028 * @param nImage Image number, counts from 0. 0 is always base image of container.
2029 * @param puOpenFlags Where to store the image open flags.
2030 */
2031VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
2032 unsigned *puOpenFlags);
2033
2034/**
2035 * Set open flags of image in HDD container.
2036 * This operation may cause file locking changes and/or files being reopened.
2037 * Note that in case of unrecoverable error all images in HDD container will be closed.
2038 *
2039 * @return VBox status code.
2040 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2041 * @param pDisk Pointer to HDD container.
2042 * @param nImage Image number, counts from 0. 0 is always base image of container.
2043 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
2044 */
2045VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
2046 unsigned uOpenFlags);
2047
2048/**
2049 * Get base filename of image in HDD container. Some image formats use
2050 * other filenames as well, so don't use this for anything but informational
2051 * purposes.
2052 *
2053 * @return VBox status code.
2054 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2055 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
2056 * @param pDisk Pointer to HDD container.
2057 * @param nImage Image number, counts from 0. 0 is always base image of container.
2058 * @param pszFilename Where to store the image file name.
2059 * @param cbFilename Size of buffer pszFilename points to.
2060 */
2061VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
2062 char *pszFilename, unsigned cbFilename);
2063
2064/**
2065 * Get the comment line of image in HDD container.
2066 *
2067 * @return VBox status code.
2068 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2069 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
2070 * @param pDisk Pointer to HDD container.
2071 * @param nImage Image number, counts from 0. 0 is always base image of container.
2072 * @param pszComment Where to store the comment string of image. NULL is ok.
2073 * @param cbComment The size of pszComment buffer. 0 is ok.
2074 */
2075VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
2076 char *pszComment, unsigned cbComment);
2077
2078/**
2079 * Changes the comment line of image in HDD container.
2080 *
2081 * @return VBox status code.
2082 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2083 * @param pDisk Pointer to HDD container.
2084 * @param nImage Image number, counts from 0. 0 is always base image of container.
2085 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
2086 */
2087VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
2088 const char *pszComment);
2089
2090/**
2091 * Get UUID of image in HDD container.
2092 *
2093 * @return VBox status code.
2094 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2095 * @param pDisk Pointer to HDD container.
2096 * @param nImage Image number, counts from 0. 0 is always base image of container.
2097 * @param pUuid Where to store the image UUID.
2098 */
2099VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
2100
2101/**
2102 * Set the image's UUID. Should not be used by normal applications.
2103 *
2104 * @return VBox status code.
2105 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2106 * @param pDisk Pointer to HDD container.
2107 * @param nImage Image number, counts from 0. 0 is always base image of container.
2108 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
2109 */
2110VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
2111
2112/**
2113 * Get last modification UUID of image in HDD container.
2114 *
2115 * @return VBox status code.
2116 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2117 * @param pDisk Pointer to HDD container.
2118 * @param nImage Image number, counts from 0. 0 is always base image of container.
2119 * @param pUuid Where to store the image modification UUID.
2120 */
2121VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
2122 PRTUUID pUuid);
2123
2124/**
2125 * Set the image's last modification UUID. Should not be used by normal applications.
2126 *
2127 * @return VBox status code.
2128 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2129 * @param pDisk Pointer to HDD container.
2130 * @param nImage Image number, counts from 0. 0 is always base image of container.
2131 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
2132 */
2133VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
2134 PCRTUUID pUuid);
2135
2136/**
2137 * Get parent UUID of image in HDD container.
2138 *
2139 * @return VBox status code.
2140 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2141 * @param pDisk Pointer to HDD container.
2142 * @param nImage Image number, counts from 0. 0 is always base image of the container.
2143 * @param pUuid Where to store the parent image UUID.
2144 */
2145VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
2146 PRTUUID pUuid);
2147
2148/**
2149 * Set the image's parent UUID. Should not be used by normal applications.
2150 *
2151 * @return VBox status code.
2152 * @param pDisk Pointer to HDD container.
2153 * @param nImage Image number, counts from 0. 0 is always base image of container.
2154 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
2155 */
2156VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
2157 PCRTUUID pUuid);
2158
2159
2160/**
2161 * Debug helper - dumps all opened images in HDD container into the log file.
2162 *
2163 * @param pDisk Pointer to HDD container.
2164 */
2165VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
2166
2167
2168/**
2169 * Query if asynchronous operations are supported for this disk.
2170 *
2171 * @return VBox status code.
2172 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
2173 * @param pDisk Pointer to the HDD container.
2174 * @param nImage Image number, counts from 0. 0 is always base image of container.
2175 * @param pfAIOSupported Where to store if async IO is supported.
2176 */
2177VBOXDDU_DECL(int) VDImageIsAsyncIOSupported(PVBOXHDD pDisk, unsigned nImage, bool *pfAIOSupported);
2178
2179
2180/**
2181 * Start a asynchronous read request.
2182 *
2183 * @return VBox status code.
2184 * @param pDisk Pointer to the HDD container.
2185 * @param uOffset The offset of the virtual disk to read from.
2186 * @param cbRead How many bytes to read.
2187 * @param paSeg Pointer to an array of segments.
2188 * @param cSeg Number of segments in the array.
2189 * @param pfnComplete Completion callback.
2190 * @param pvUser User data which is passed on completion
2191 */
2192VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
2193 PCRTSGSEG paSeg, unsigned cSeg,
2194 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
2195 void *pvUser1, void *pvUser2);
2196
2197
2198/**
2199 * Start a asynchronous write request.
2200 *
2201 * @return VBox status code.
2202 * @param pDisk Pointer to the HDD container.
2203 * @param uOffset The offset of the virtual disk to write to.
2204 * @param cbWrtie How many bytes to write.
2205 * @param paSeg Pointer to an array of segments.
2206 * @param cSeg Number of segments in the array.
2207 * @param pfnComplete Completion callback.
2208 * @param pvUser User data which is passed on completion.
2209 */
2210VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
2211 PCRTSGSEG paSeg, unsigned cSeg,
2212 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
2213 void *pvUser1, void *pvUser2);
2214
2215
2216/**
2217 * Start a asynchronous flush request.
2218 *
2219 * @return VBox status code.
2220 * @param pDisk Pointer to the HDD container.
2221 * @param pfnComplete Completion callback.
2222 * @param pvUser User data which is passed on completion.
2223 */
2224VBOXDDU_DECL(int) VDAsyncFlush(PVBOXHDD pDisk,
2225 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
2226 void *pvUser1, void *pvUser2);
2227RT_C_DECLS_END
2228
2229/** @} */
2230
2231#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