VirtualBox

source: vbox/trunk/include/VBox/VBoxHDD-new.h@ 16785

Last change on this file since 16785 was 16651, checked in by vboxsync, 16 years ago

VBoxHDD-new.h: Corrected PCVDINTERFACE.

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