VirtualBox

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

Last change on this file since 14922 was 14852, checked in by vboxsync, 16 years ago

#3162: Plugin backends are now loaded upon startup, this should get rid of most memory leaks as most structures are now static.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 62.8 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, *PVDINTERFACE;
264/** Pointer to a const PVDINTERFACE. */
265typedef const PVDINTERFACE PCVDINTERFACE;
266
267/**
268 * Helper functions to handle interface lists.
269 *
270 * @note These interface lists are used consistently to pass per-disk,
271 * per-image and/or per-operation callbacks. Those three purposes are strictly
272 * separate. See the individual interface declarations for what context they
273 * apply to. The caller is responsible for ensuring that the lifetime of the
274 * interface descriptors is appropriate for the category of interface.
275 */
276
277/**
278 * Get a specific interface from a list of interfaces specified by the type.
279 *
280 * @return Pointer to the matching interface or NULL if none was found.
281 * @param pVDIfs Pointer to the VD interface list.
282 * @param enmInterface Interface to search for.
283 */
284DECLINLINE(PVDINTERFACE) VDInterfaceGet(PVDINTERFACE pVDIfs, VDINTERFACETYPE enmInterface)
285{
286 AssertMsgReturn( (enmInterface >= VDINTERFACETYPE_FIRST)
287 && (enmInterface < VDINTERFACETYPE_INVALID),
288 ("enmInterface=%u", enmInterface), NULL);
289
290 while (pVDIfs)
291 {
292 /* Sanity checks. */
293 AssertMsgBreak(pVDIfs->cbSize == sizeof(VDINTERFACE),
294 ("cbSize=%u\n", pVDIfs->cbSize));
295
296 if (pVDIfs->enmInterface == enmInterface)
297 return pVDIfs;
298 pVDIfs = pVDIfs->pNext;
299 }
300
301 /* No matching interface was found. */
302 return NULL;
303}
304
305/**
306 * Add an interface to a list of interfaces.
307 *
308 * @return VBox status code.
309 * @param pInterface Pointer to an unitialized common interface structure.
310 * @param pszName Name of the interface.
311 * @param enmInterface Type of the interface.
312 * @param pCallbacks The callback table of the interface.
313 * @param pvUser Opaque user data passed on every function call.
314 * @param ppVDIfs Pointer to the VD interface list.
315 */
316DECLINLINE(int) VDInterfaceAdd(PVDINTERFACE pInterface, const char *pszName,
317 VDINTERFACETYPE enmInterface, void *pCallbacks,
318 void *pvUser, PVDINTERFACE *ppVDIfs)
319{
320
321 /** Argument checks. */
322 AssertMsgReturn( (enmInterface >= VDINTERFACETYPE_FIRST)
323 && (enmInterface < VDINTERFACETYPE_INVALID),
324 ("enmInterface=%u", enmInterface), VERR_INVALID_PARAMETER);
325
326 AssertMsgReturn(VALID_PTR(pCallbacks),
327 ("pCallbacks=%#p", pCallbacks),
328 VERR_INVALID_PARAMETER);
329
330 AssertMsgReturn(VALID_PTR(ppVDIfs),
331 ("pInterfaceList=%#p", ppVDIfs),
332 VERR_INVALID_PARAMETER);
333
334 /* Fill out interface descriptor. */
335 pInterface->cbSize = sizeof(VDINTERFACE);
336 pInterface->pszInterfaceName = pszName;
337 pInterface->enmInterface = enmInterface;
338 pInterface->pCallbacks = pCallbacks;
339 pInterface->pvUser = pvUser;
340 pInterface->pNext = *ppVDIfs;
341
342 /* Remember the new start of the list. */
343 *ppVDIfs = pInterface;
344
345 return VINF_SUCCESS;
346}
347
348/**
349 * Interface to deliver error messages to upper layers.
350 *
351 * Per disk interface. Optional, but think twice if you want to miss the
352 * opportunity of reporting better human-readable error messages.
353 */
354typedef struct VDINTERFACEERROR
355{
356 /**
357 * Size of the error interface.
358 */
359 uint32_t cbSize;
360
361 /**
362 * Interface type.
363 */
364 VDINTERFACETYPE enmInterface;
365
366 /**
367 * Error message callback.
368 *
369 * @param pvUser The opaque data passed on container creation.
370 * @param rc The VBox error code.
371 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
372 * @param pszFormat Error message format string.
373 * @param va Error message arguments.
374 */
375 DECLR3CALLBACKMEMBER(void, pfnError, (void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
376
377} VDINTERFACEERROR, *PVDINTERFACEERROR;
378
379/**
380 * Get error interface from opaque callback table.
381 *
382 * @return Pointer to the callback table.
383 * @param pInterface Pointer to the interface descriptor.
384 */
385DECLINLINE(PVDINTERFACEERROR) VDGetInterfaceError(PVDINTERFACE pInterface)
386{
387 /* Check that the interface descriptor is a error interface. */
388 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_ERROR)
389 && (pInterface->cbSize == sizeof(VDINTERFACE)),
390 ("Not an error interface"), NULL);
391
392 PVDINTERFACEERROR pInterfaceError = (PVDINTERFACEERROR)pInterface->pCallbacks;
393
394 /* Do basic checks. */
395 AssertMsgReturn( (pInterfaceError->cbSize == sizeof(VDINTERFACEERROR))
396 && (pInterfaceError->enmInterface == VDINTERFACETYPE_ERROR),
397 ("A non error callback table attached to a error interface descriptor\n"), NULL);
398
399 return pInterfaceError;
400}
401
402/**
403 * Completion callback which is called by the interface owner
404 * to inform the backend that a task finished.
405 *
406 * @return VBox status code.
407 * @param pvUser Opaque user data which is passed on request submission.
408 */
409typedef DECLCALLBACK(int) FNVDCOMPLETED(void *pvUser);
410/** Pointer to FNVDCOMPLETED() */
411typedef FNVDCOMPLETED *PFNVDCOMPLETED;
412
413
414/**
415 * Support interface for asynchronous I/O
416 *
417 * Per-disk. Optional.
418 */
419typedef struct VDINTERFACEASYNCIO
420{
421 /**
422 * Size of the async interface.
423 */
424 uint32_t cbSize;
425
426 /**
427 * Interface type.
428 */
429 VDINTERFACETYPE enmInterface;
430
431 /**
432 * Open callback
433 *
434 * @return VBox status code.
435 * @param pvUser The opaque data passed on container creation.
436 * @param pszLocation Name of the location to open.
437 * @param fReadonly Whether to open the storage medium read only.
438 * @param ppStorage Where to store the opaque storage handle.
439 */
440 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation, bool fReadonly, void **ppStorage));
441
442 /**
443 * Close callback.
444 *
445 * @return VBox status code.
446 * @param pvUser The opaque data passed on container creation.
447 * @param pStorage The opaque storage handle to close.
448 */
449 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, void *pStorage));
450
451 /**
452 * Synchronous write callback.
453 *
454 * @return VBox status code.
455 * @param pvUser The opaque data passed on container creation.
456 * @param pStorage The storage handle to use.
457 * @param uOffset The offset to start from.
458 * @param cbWrite How many bytes to write.
459 * @param pvBuf Pointer to the bits need to be written.
460 * @param pcbWritten Where to store how many bytes where actually written.
461 */
462 DECLR3CALLBACKMEMBER(int, pfnWrite, (void *pvUser, void *pStorage, uint64_t uOffset,
463 size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
464
465 /**
466 * Synchronous read callback.
467 *
468 * @return VBox status code.
469 * @param pvUser The opaque data passed on container creation.
470 * @param pStorage The storage handle to use.
471 * @param uOffset The offset to start from.
472 * @param cbRead How many bytes to read.
473 * @param pvBuf Where to store the read bits.
474 * @param pcbRead Where to store how many bytes where actually read.
475 */
476 DECLR3CALLBACKMEMBER(int, pfnRead, (void *pvUser, void *pStorage, uint64_t uOffset,
477 size_t cbRead, void *pvBuf, size_t *pcbRead));
478
479 /**
480 * Flush data to the storage backend.
481 *
482 * @return VBox statis code.
483 * @param pvUser The opaque data passed on container creation.
484 * @param pStorage The storage handle to flush.
485 */
486 DECLR3CALLBACKMEMBER(int, pfnFlush, (void *pvUser, void *pStorage));
487
488 /**
489 * Prepare an asynchronous read task.
490 *
491 * @return VBox status code.
492 * @param pvUser The opqaue user data passed on container creation.
493 * @param pStorage The storage handle.
494 * @param uOffset The offset to start reading from.
495 * @param pvBuf Where to store read bits.
496 * @param cbRead How many bytes to read.
497 * @param ppTask Where to store the opaque task handle.
498 */
499 DECLR3CALLBACKMEMBER(int, pfnPrepareRead, (void *pvUser, void *pStorage, uint64_t uOffset,
500 void *pvBuf, size_t cbRead, void **ppTask));
501
502 /**
503 * Prepare an asynchronous write task.
504 *
505 * @return VBox status code.
506 * @param pvUser The opaque user data passed on conatiner creation.
507 * @param pStorage The storage handle.
508 * @param uOffset The offset to start writing to.
509 * @param pvBuf Where to read the data from.
510 * @param cbWrite How many bytes to write.
511 * @param ppTask Where to store the opaque task handle.
512 */
513 DECLR3CALLBACKMEMBER(int, pfnPrepareWrite, (void *pvUser, void *pStorage, uint64_t uOffset,
514 void *pvBuf, size_t cbWrite, void **ppTask));
515
516 /**
517 * Submit an array of tasks for processing
518 *
519 * @return VBox status code.
520 * @param pvUser The opaque user data passed on container creation.
521 * @param apTasks Array of task handles to submit.
522 * @param cTasks How many tasks to submit.
523 * @param pvUser2 User data which is passed on completion.
524 * @param pvUserCaller Opaque user data the caller of VDAsyncWrite/Read passed.
525 * @param pfnTasksCompleted Pointer to callback which is called on request completion.
526 */
527 DECLR3CALLBACKMEMBER(int, pfnTasksSubmit, (void *pvUser, void *apTasks[], unsigned cTasks, void *pvUser2,
528 void *pvUserCaller, PFNVDCOMPLETED pfnTasksCompleted));
529
530} VDINTERFACEASYNCIO, *PVDINTERFACEASYNCIO;
531
532/**
533 * Get async I/O interface from opaque callback table.
534 *
535 * @return Pointer to the callback table.
536 * @param pInterface Pointer to the interface descriptor.
537 */
538DECLINLINE(PVDINTERFACEASYNCIO) VDGetInterfaceAsyncIO(PVDINTERFACE pInterface)
539{
540 /* Check that the interface descriptor is a async I/O interface. */
541 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_ASYNCIO)
542 && (pInterface->cbSize == sizeof(VDINTERFACE)),
543 ("Not an async I/O interface"), NULL);
544
545 PVDINTERFACEASYNCIO pInterfaceAsyncIO = (PVDINTERFACEASYNCIO)pInterface->pCallbacks;
546
547 /* Do basic checks. */
548 AssertMsgReturn( (pInterfaceAsyncIO->cbSize == sizeof(VDINTERFACEASYNCIO))
549 && (pInterfaceAsyncIO->enmInterface == VDINTERFACETYPE_ASYNCIO),
550 ("A non async I/O callback table attached to a async I/O interface descriptor\n"), NULL);
551
552 return pInterfaceAsyncIO;
553}
554
555/**
556 * Progress notification interface
557 *
558 * Per-operation. Optional.
559 */
560typedef struct VDINTERFACEPROGRESS
561{
562 /**
563 * Size of the progress interface.
564 */
565 uint32_t cbSize;
566
567 /**
568 * Interface type.
569 */
570 VDINTERFACETYPE enmInterface;
571
572 /**
573 * Progress notification callbacks.
574 * @todo r=bird: Why the heck are we using PFNVMPROGRESS here?
575 */
576 PFNVMPROGRESS pfnProgress;
577} VDINTERFACEPROGRESS, *PVDINTERFACEPROGRESS;
578
579/**
580 * Get progress interface from opaque callback table.
581 *
582 * @return Pointer to the callback table.
583 * @param pInterface Pointer to the interface descriptor.
584 */
585DECLINLINE(PVDINTERFACEPROGRESS) VDGetInterfaceProgress(PVDINTERFACE pInterface)
586{
587 /* Check that the interface descriptor is a progress interface. */
588 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_PROGRESS)
589 && (pInterface->cbSize == sizeof(VDINTERFACE)),
590 ("Not a progress interface"), NULL);
591
592
593 PVDINTERFACEPROGRESS pInterfaceProgress = (PVDINTERFACEPROGRESS)pInterface->pCallbacks;
594
595 /* Do basic checks. */
596 AssertMsgReturn( (pInterfaceProgress->cbSize == sizeof(VDINTERFACEPROGRESS))
597 && (pInterfaceProgress->enmInterface == VDINTERFACETYPE_PROGRESS),
598 ("A non progress callback table attached to a progress interface descriptor\n"), NULL);
599
600 return pInterfaceProgress;
601}
602
603
604/**
605 * Configuration information interface
606 *
607 * Per-image. Optional for most backends, but mandatory for images which do
608 * not operate on files (including standard block or character devices).
609 */
610typedef struct VDINTERFACECONFIG
611{
612 /**
613 * Size of the configuration interface.
614 */
615 uint32_t cbSize;
616
617 /**
618 * Interface type.
619 */
620 VDINTERFACETYPE enmInterface;
621
622 /**
623 * Validates that the keys are within a set of valid names.
624 *
625 * @return true if all key names are found in pszzAllowed.
626 * @return false if not.
627 * @param pvUser The opaque user data associated with this interface.
628 * @param pszzValid List of valid key names separated by '\\0' and ending with
629 * a double '\\0'.
630 */
631 DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid));
632
633 /**
634 * Retrieves the length of the string value associated with a key.
635 *
636 * @return VBox status code.
637 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
638 * @param pvUser The opaque user data associated with this interface.
639 * @param pszName Name of the key to query.
640 * @param pcbValue Where to store the value length. Non-NULL.
641 */
642 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
643
644 /**
645 * Query the string value associated with a key.
646 *
647 * @return VBox status code.
648 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
649 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
650 * @param pvUser The opaque user data associated with this interface.
651 * @param pszName Name of the key to query.
652 * @param pszValue Pointer to buffer where to store value.
653 * @param cchValue Length of value buffer.
654 */
655 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
656} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
657
658/**
659 * Get configuration information interface from opaque callback table.
660 *
661 * @return Pointer to the callback table.
662 * @param pInterface Pointer to the interface descriptor.
663 */
664DECLINLINE(PVDINTERFACECONFIG) VDGetInterfaceConfig(PVDINTERFACE pInterface)
665{
666 /* Check that the interface descriptor is a config interface. */
667 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_CONFIG)
668 && (pInterface->cbSize == sizeof(VDINTERFACE)),
669 ("Not a config interface"), NULL);
670
671 PVDINTERFACECONFIG pInterfaceConfig = (PVDINTERFACECONFIG)pInterface->pCallbacks;
672
673 /* Do basic checks. */
674 AssertMsgReturn( (pInterfaceConfig->cbSize == sizeof(VDINTERFACECONFIG))
675 && (pInterfaceConfig->enmInterface == VDINTERFACETYPE_CONFIG),
676 ("A non config callback table attached to a config interface descriptor\n"), NULL);
677
678 return pInterfaceConfig;
679}
680
681/**
682 * Query configuration, validates that the keys are within a set of valid names.
683 *
684 * @return true if all key names are found in pszzAllowed.
685 * @return false if not.
686 * @param pCfgIf Pointer to configuration callback table.
687 * @param pvUser The opaque user data associated with this interface.
688 * @param pszzValid List of valid names separated by '\\0' and ending with
689 * a double '\\0'.
690 */
691DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, void *pvUser,
692 const char *pszzValid)
693{
694 return pCfgIf->pfnAreKeysValid(pvUser, pszzValid);
695}
696
697/**
698 * Query configuration, unsigned 64-bit integer value with default.
699 *
700 * @return VBox status code.
701 * @param pCfgIf Pointer to configuration callback table.
702 * @param pvUser The opaque user data associated with this interface.
703 * @param pszName Name of an integer value
704 * @param pu64 Where to store the value. Set to default on failure.
705 * @param u64Def The default value.
706 */
707DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
708 const char *pszName, uint64_t *pu64,
709 uint64_t u64Def)
710{
711 char aszBuf[32];
712 int rc = pCfgIf->pfnQuery(pvUser, pszName, aszBuf, sizeof(aszBuf));
713 if (RT_SUCCESS(rc))
714 {
715 rc = RTStrToUInt64Full(aszBuf, 0, pu64);
716 }
717 else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
718 {
719 rc = VINF_SUCCESS;
720 *pu64 = u64Def;
721 }
722 return rc;
723}
724
725/**
726 * Query configuration, unsigned 32-bit integer value with default.
727 *
728 * @return VBox status code.
729 * @param pCfgIf Pointer to configuration callback table.
730 * @param pvUser The opaque user data associated with this interface.
731 * @param pszName Name of an integer value
732 * @param pu32 Where to store the value. Set to default on failure.
733 * @param u32Def The default value.
734 */
735DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
736 const char *pszName, uint32_t *pu32,
737 uint32_t u32Def)
738{
739 uint64_t u64;
740 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, u32Def);
741 if (RT_SUCCESS(rc))
742 {
743 if (!(u64 & UINT64_C(0xffffffff00000000)))
744 *pu32 = (uint32_t)u64;
745 else
746 rc = VERR_CFGM_INTEGER_TOO_BIG;
747 }
748 return rc;
749}
750
751/**
752 * Query configuration, bool value with default.
753 *
754 * @return VBox status code.
755 * @param pCfgIf Pointer to configuration callback table.
756 * @param pvUser The opaque user data associated with this interface.
757 * @param pszName Name of an integer value
758 * @param pf Where to store the value. Set to default on failure.
759 * @param fDef The default value.
760 */
761DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, void *pvUser,
762 const char *pszName, bool *pf,
763 bool fDef)
764{
765 uint64_t u64;
766 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, fDef);
767 if (RT_SUCCESS(rc))
768 *pf = u64 ? true : false;
769 return rc;
770}
771
772/**
773 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
774 * character value.
775 *
776 * @return VBox status code.
777 * @param pCfgIf Pointer to configuration callback table.
778 * @param pvUser The opaque user data associated with this interface.
779 * @param pszName Name of an zero terminated character value
780 * @param ppszString Where to store the string pointer. Not set on failure.
781 * Free this using RTMemFree().
782 */
783DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
784 void *pvUser, const char *pszName,
785 char **ppszString)
786{
787 size_t cch;
788 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch);
789 if (RT_SUCCESS(rc))
790 {
791 char *pszString = (char *)RTMemAlloc(cch);
792 if (pszString)
793 {
794 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch);
795 if (RT_SUCCESS(rc))
796 *ppszString = pszString;
797 else
798 RTMemFree(pszString);
799 }
800 else
801 rc = VERR_NO_MEMORY;
802 }
803 return rc;
804}
805
806/**
807 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
808 * character value with default.
809 *
810 * @return VBox status code.
811 * @param pCfgIf Pointer to configuration callback table.
812 * @param pvUser The opaque user data associated with this interface.
813 * @param pszName Name of an zero terminated character value
814 * @param ppszString Where to store the string pointer. Not set on failure.
815 * Free this using RTMemFree().
816 * @param pszDef The default value.
817 */
818DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
819 void *pvUser, const char *pszName,
820 char **ppszString,
821 const char *pszDef)
822{
823 size_t cch;
824 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch);
825 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
826 {
827 cch = strlen(pszDef) + 1;
828 rc = VINF_SUCCESS;
829 }
830 if (RT_SUCCESS(rc))
831 {
832 char *pszString = (char *)RTMemAlloc(cch);
833 if (pszString)
834 {
835 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch);
836 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
837 {
838 memcpy(pszString, pszDef, cch);
839 rc = VINF_SUCCESS;
840 }
841 if (RT_SUCCESS(rc))
842 *ppszString = pszString;
843 else
844 RTMemFree(pszString);
845 }
846 else
847 rc = VERR_NO_MEMORY;
848 }
849 return rc;
850}
851
852/**
853 * Query configuration, dynamically allocated (RTMemAlloc) byte string value.
854 *
855 * @return VBox status code.
856 * @param pCfgIf Pointer to configuration callback table.
857 * @param pvUser The opaque user data associated with this interface.
858 * @param pszName Name of an zero terminated character value
859 * @param ppvData Where to store the byte string pointer. Not set on failure.
860 * Free this using RTMemFree().
861 * @param pcbData Where to store the byte string length.
862 */
863DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
864 void *pvUser, const char *pszName,
865 void **ppvData, size_t *pcbData)
866{
867 size_t cb;
868 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
869 if (RT_SUCCESS(rc))
870 {
871 char *pvData = (char *)RTMemAlloc(cb);
872 if (pvData)
873 {
874 rc = pCfgIf->pfnQuery(pvUser, pszName, pvData, cb);
875 if (RT_SUCCESS(rc))
876 {
877 *ppvData = pvData;
878 *pcbData = cb;
879 }
880 else
881 RTMemFree(pvData);
882 }
883 else
884 rc = VERR_NO_MEMORY;
885 }
886 return rc;
887}
888
889
890/**
891 * TCP network stack interface
892 *
893 * Per-disk. Mandatory for backends which have the VD_CAP_TCPNET bit set.
894 */
895typedef struct VDINTERFACETCPNET
896{
897 /**
898 * Size of the configuration interface.
899 */
900 uint32_t cbSize;
901
902 /**
903 * Interface type.
904 */
905 VDINTERFACETYPE enmInterface;
906
907 /**
908 * Connect as a client to a TCP port.
909 *
910 * @return iprt status code.
911 * @param pszAddress The address to connect to.
912 * @param uPort The port to connect to.
913 * @param pSock Where to store the handle to the established connect
914ion.
915 */
916 DECLR3CALLBACKMEMBER(int, pfnClientConnect, (const char *pszAddress, uint32_t uPort, PRTSOCKET pSock));
917
918 /**
919 * Close a TCP connection.
920 *
921 * @return iprt status code.
922 * @param Sock Socket descriptor.
923ion.
924 */
925 DECLR3CALLBACKMEMBER(int, pfnClientClose, (RTSOCKET Sock));
926
927 /**
928 * Socket I/O multiplexing.
929 * Checks if the socket is ready for reading.
930 *
931 * @return iprt status code.
932 * @param Sock Socket descriptor.
933 * @param cMillies Number of milliseconds to wait for the socket.
934 * Use RT_INDEFINITE_WAIT to wait for ever.
935 */
936 DECLR3CALLBACKMEMBER(int, pfnSelectOne, (RTSOCKET Sock, unsigned cMillies));
937
938 /**
939 * Receive data from a socket.
940 *
941 * @return iprt status code.
942 * @param Sock Socket descriptor.
943 * @param pvBuffer Where to put the data we read.
944 * @param cbBuffer Read buffer size.
945 * @param pcbRead Number of bytes read.
946 * If NULL the entire buffer will be filled upon successful return.
947 * If not NULL a partial read can be done successfully.
948 */
949 DECLR3CALLBACKMEMBER(int, pfnRead, (RTSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
950
951 /**
952 * Send data from a socket.
953 *
954 * @return iprt status code.
955 * @param Sock Socket descriptor.
956 * @param pvBuffer Buffer to write data to socket.
957 * @param cbBuffer How much to write.
958 * @param pcbRead Number of bytes read.
959 */
960 DECLR3CALLBACKMEMBER(int, pfnWrite, (RTSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
961
962 /**
963 * Flush socket write buffers.
964 *
965 * @return iprt status code.
966 * @param Sock Socket descriptor.
967 */
968 DECLR3CALLBACKMEMBER(int, pfnFlush, (RTSOCKET Sock));
969
970} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
971
972/**
973 * Get TCP network stack interface from opaque callback table.
974 *
975 * @return Pointer to the callback table.
976 * @param pInterface Pointer to the interface descriptor.
977 */
978DECLINLINE(PVDINTERFACETCPNET) VDGetInterfaceTcpNet(PVDINTERFACE pInterface)
979{
980 /* Check that the interface descriptor is a TCP network stack interface. */
981 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_TCPNET)
982 && (pInterface->cbSize == sizeof(VDINTERFACE)),
983 ("Not a TCP network stack interface"), NULL);
984
985 PVDINTERFACETCPNET pInterfaceTcpNet = (PVDINTERFACETCPNET)pInterface->pCallbacks;
986
987 /* Do basic checks. */
988 AssertMsgReturn( (pInterfaceTcpNet->cbSize == sizeof(VDINTERFACETCPNET))
989 && (pInterfaceTcpNet->enmInterface == VDINTERFACETYPE_TCPNET),
990 ("A non TCP network stack callback table attached to a TCP network stack interface descriptor\n"), NULL);
991
992 return pInterfaceTcpNet;
993}
994
995
996/** @name Configuration interface key handling flags.
997 * @{
998 */
999/** Mandatory config key. Not providing a value for this key will cause
1000 * the backend to fail. */
1001#define VD_CFGKEY_MANDATORY RT_BIT(0)
1002/** Expert config key. Not showing it by default in the GUI is is probably
1003 * a good idea, as the average user won't understand it easily. */
1004#define VD_CFGKEY_EXPERT RT_BIT(1)
1005/** @}*/
1006
1007
1008/**
1009 * Configuration value type for configuration information interface.
1010 */
1011typedef enum VDCFGVALUETYPE
1012{
1013 /** Integer value. */
1014 VDCFGVALUETYPE_INTEGER = 1,
1015 /** String value. */
1016 VDCFGVALUETYPE_STRING,
1017 /** Bytestring value. */
1018 VDCFGVALUETYPE_BYTES
1019} VDCFGVALUETYPE;
1020
1021
1022/**
1023 * Structure describing configuration keys required/supported by a backend
1024 * through the config interface.
1025 */
1026typedef struct VDCONFIGINFO
1027{
1028 /** Key name of the configuration. */
1029 const char *pszKey;
1030 /** Pointer to default value (descriptor). NULL if no useful default value
1031 * can be specified. */
1032 const char *pszDefaultValue;
1033 /** Value type for this key. */
1034 VDCFGVALUETYPE enmValueType;
1035 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
1036 uint64_t uKeyFlags;
1037} VDCONFIGINFO;
1038
1039/** Pointer to structure describing configuration keys. */
1040typedef VDCONFIGINFO *PVDCONFIGINFO;
1041
1042/** Pointer to const structure describing configuration keys. */
1043typedef const VDCONFIGINFO *PCVDCONFIGINFO;
1044
1045/**
1046 * Data structure for returning a list of backend capabilities.
1047 */
1048typedef struct VDBACKENDINFO
1049{
1050 /** Name of the backend. */
1051 const char *pszBackend;
1052 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
1053 uint64_t uBackendCaps;
1054 /** Pointer to a NULL-terminated array of strings, containing the supported
1055 * file extensions. Note that some backends do not work on files, so this
1056 * pointer may just contain NULL. */
1057 const char * const *papszFileExtensions;
1058 /** Pointer to an array of structs describing each supported config key.
1059 * Terminated by a NULL config key. Note that some backends do not support
1060 * the configuration interface, so this pointer may just contain NULL.
1061 * Mandatory if the backend sets VD_CAP_CONFIG. */
1062 PCVDCONFIGINFO paConfigInfo;
1063} VDBACKENDINFO, *PVDBACKENDINFO;
1064
1065
1066/**
1067 * VBox HDD Container main structure.
1068 */
1069/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
1070struct VBOXHDD;
1071typedef struct VBOXHDD VBOXHDD;
1072typedef VBOXHDD *PVBOXHDD;
1073
1074/**
1075 * Initializes HDD backends.
1076 *
1077 * @returns VBox status code.
1078 */
1079VBOXDDU_DECL(int) VDInit();
1080
1081/**
1082 * Destroys loaded HDD backends.
1083 *
1084 * @returns VBox status code.
1085 */
1086VBOXDDU_DECL(int) VDShutdown();
1087
1088/**
1089 * Lists all HDD backends and their capabilities in a caller-provided buffer.
1090 * Free all returned names with RTStrFree() when you no longer need them.
1091 *
1092 * @return VBox status code.
1093 * VERR_BUFFER_OVERFLOW if not enough space is passed.
1094 * @param cEntriesAlloc Number of list entries available.
1095 * @param pEntries Pointer to array for the entries.
1096 * @param pcEntriesUsed Number of entries returned.
1097 */
1098VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
1099 unsigned *pcEntriesUsed);
1100
1101/**
1102 * Lists the capablities of a backend indentified by its name.
1103 * Free all returned names with RTStrFree() when you no longer need them.
1104 *
1105 * @return VBox status code.
1106 * @param pszBackend The backend name.
1107 * @param pEntries Pointer to an entry.
1108 */
1109VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
1110
1111/**
1112 * Allocates and initializes an empty HDD container.
1113 * No image files are opened.
1114 *
1115 * @return VBox status code.
1116 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1117 * @param ppDisk Where to store the reference to HDD container.
1118 */
1119VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, PVBOXHDD *ppDisk);
1120
1121/**
1122 * Destroys HDD container.
1123 * If container has opened image files they will be closed.
1124 *
1125 * @param pDisk Pointer to HDD container.
1126 */
1127VBOXDDU_DECL(void) VDDestroy(PVBOXHDD pDisk);
1128
1129/**
1130 * Try to get the backend name which can use this image.
1131 *
1132 * @return VBox status code.
1133 * @param pszFilename Name of the image file for which the backend is queried.
1134 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
1135 * The returned pointer must be freed using RTStrFree().
1136 */
1137VBOXDDU_DECL(int) VDGetFormat(const char *pszFilename, char **ppszFormat);
1138
1139/**
1140 * Opens an image file.
1141 *
1142 * The first opened image file in HDD container must have a base image type,
1143 * others (next opened images) must be differencing or undo images.
1144 * Linkage is checked for differencing image to be consistent with the previously opened image.
1145 * When another differencing image is opened and the last image was opened in read/write access
1146 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
1147 * other processes to use images in read-only mode too.
1148 *
1149 * Note that the image is opened in read-only mode if a read/write open is not possible.
1150 * Use VDIsReadOnly to check open mode.
1151 *
1152 * @return VBox status code.
1153 * @param pDisk Pointer to HDD container.
1154 * @param pszBackend Name of the image file backend to use.
1155 * @param pszFilename Name of the image file to open.
1156 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1157 * @param pVDIfsImage Pointer to the per-image VD interface list.
1158 */
1159VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
1160 const char *pszFilename, unsigned uOpenFlags,
1161 PVDINTERFACE pVDIfsImage);
1162
1163/**
1164 * Creates and opens a new base image file.
1165 *
1166 * @return VBox status code.
1167 * @param pDisk Pointer to HDD container.
1168 * @param pszBackend Name of the image file backend to use.
1169 * @param pszFilename Name of the image file to create.
1170 * @param enmType Image type, only base image types are acceptable.
1171 * @param cbSize Image size in bytes.
1172 * @param uImageFlags Flags specifying special image features.
1173 * @param pszComment Pointer to image comment. NULL is ok.
1174 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
1175 * @param pLCHSGeometry Pointer to logical disk geometry <= (1024,255,63). Not NULL.
1176 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1177 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1178 * @param pVDIfsImage Pointer to the per-image VD interface list.
1179 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1180 */
1181VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
1182 const char *pszFilename, VDIMAGETYPE enmType,
1183 uint64_t cbSize, unsigned uImageFlags,
1184 const char *pszComment,
1185 PCPDMMEDIAGEOMETRY pPCHSGeometry,
1186 PCPDMMEDIAGEOMETRY pLCHSGeometry,
1187 PCRTUUID pUuid, unsigned uOpenFlags,
1188 PVDINTERFACE pVDIfsImage,
1189 PVDINTERFACE pVDIfsOperation);
1190
1191/**
1192 * Creates and opens a new differencing image file in HDD container.
1193 * See comments for VDOpen function about differencing images.
1194 *
1195 * @return VBox status code.
1196 * @param pDisk Pointer to HDD container.
1197 * @param pszBackend Name of the image file backend to use.
1198 * @param pszFilename Name of the differencing image file to create.
1199 * @param uImageFlags Flags specifying special image features.
1200 * @param pszComment Pointer to image comment. NULL is ok.
1201 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1202 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1203 * @param pVDIfsImage Pointer to the per-image VD interface list.
1204 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1205 */
1206VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
1207 const char *pszFilename, unsigned uImageFlags,
1208 const char *pszComment, PCRTUUID pUuid,
1209 unsigned uOpenFlags, PVDINTERFACE pVDIfsImage,
1210 PVDINTERFACE pVDIfsOperation);
1211
1212/**
1213 * Merges two images (not necessarily with direct parent/child relationship).
1214 * As a side effect the source image and potentially the other images which
1215 * are also merged to the destination are deleted from both the disk and the
1216 * images in the HDD container.
1217 *
1218 * @return VBox status code.
1219 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1220 * @param pDisk Pointer to HDD container.
1221 * @param nImageFrom Name of the image file to merge from.
1222 * @param nImageTo Name of the image file to merge to.
1223 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1224 */
1225VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
1226 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
1227
1228/**
1229 * Copies an image from one HDD container to another.
1230 * The copy is opened in the target HDD container.
1231 * It is possible to convert between different image formats, because the
1232 * backend for the destination may be different from the source.
1233 * If both the source and destination reference the same HDD container,
1234 * then the image is moved (by copying/deleting or renaming) to the new location.
1235 * The source container is unchanged if the move operation fails, otherwise
1236 * the image at the new location is opened in the same way as the old one was.
1237 *
1238 * @return VBox status code.
1239 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1240 * @param pDiskFrom Pointer to source HDD container.
1241 * @param nImage Image number, counts from 0. 0 is always base image of container.
1242 * @param pDiskTo Pointer to destination HDD container.
1243 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source).
1244 * @param pszFilename New name of the image (may be NULL if pDiskFrom == pDiskTo).
1245 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
1246 * @param cbSize New image size (0 means leave unchanged).
1247 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1248 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
1249 * destination image.
1250 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
1251 * for the destination operation.
1252 */
1253VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
1254 const char *pszBackend, const char *pszFilename,
1255 bool fMoveByRename, uint64_t cbSize,
1256 PVDINTERFACE pVDIfsOperation,
1257 PVDINTERFACE pDstVDIfsImage,
1258 PVDINTERFACE pDstVDIfsOperation);
1259
1260/**
1261 * Closes the last opened image file in HDD container.
1262 * If previous image file was opened in read-only mode (that is normal) and closing image
1263 * was opened in read-write mode (the whole disk was in read-write mode) - the previous image
1264 * will be reopened in read/write mode.
1265 *
1266 * @return VBox status code.
1267 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1268 * @param pDisk Pointer to HDD container.
1269 * @param fDelete If true, delete the image from the host disk.
1270 */
1271VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
1272
1273/**
1274 * Closes all opened image files in HDD container.
1275 *
1276 * @return VBox status code.
1277 * @param pDisk Pointer to HDD container.
1278 */
1279VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
1280
1281/**
1282 * Read data from virtual HDD.
1283 *
1284 * @return VBox status code.
1285 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1286 * @param pDisk Pointer to HDD container.
1287 * @param uOffset Offset of first reading byte from start of disk.
1288 * Must be aligned to a sector boundary.
1289 * @param pvBuf Pointer to buffer for reading data.
1290 * @param cbRead Number of bytes to read.
1291 * Must be aligned to a sector boundary.
1292 */
1293VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
1294
1295/**
1296 * Write data to virtual HDD.
1297 *
1298 * @return VBox status code.
1299 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1300 * @param pDisk Pointer to HDD container.
1301 * @param uOffset Offset of first writing byte from start of disk.
1302 * Must be aligned to a sector boundary.
1303 * @param pvBuf Pointer to buffer for writing data.
1304 * @param cbWrite Number of bytes to write.
1305 * Must be aligned to a sector boundary.
1306 */
1307VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
1308
1309/**
1310 * Make sure the on disk representation of a virtual HDD is up to date.
1311 *
1312 * @return VBox status code.
1313 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1314 * @param pDisk Pointer to HDD container.
1315 */
1316VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
1317
1318/**
1319 * Get number of opened images in HDD container.
1320 *
1321 * @return Number of opened images for HDD container. 0 if no images have been opened.
1322 * @param pDisk Pointer to HDD container.
1323 */
1324VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
1325
1326/**
1327 * Get read/write mode of HDD container.
1328 *
1329 * @return Virtual disk ReadOnly status.
1330 * @return true if no image is opened in HDD container.
1331 * @param pDisk Pointer to HDD container.
1332 */
1333VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
1334
1335/**
1336 * Get total capacity of an image in HDD container.
1337 *
1338 * @return Virtual disk size in bytes.
1339 * @return 0 if image with specified number was not opened.
1340 * @param pDisk Pointer to HDD container.
1341 * @param nImage Image number, counts from 0. 0 is always base image of container.
1342 */
1343VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
1344
1345/**
1346 * Get total file size of an image in HDD container.
1347 *
1348 * @return Virtual disk size in bytes.
1349 * @return 0 if image with specified number was not opened.
1350 * @param pDisk Pointer to HDD container.
1351 * @param nImage Image number, counts from 0. 0 is always base image of container.
1352 */
1353VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
1354
1355/**
1356 * Get virtual disk PCHS geometry of an image in HDD container.
1357 *
1358 * @return VBox status code.
1359 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1360 * @return VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1361 * @param pDisk Pointer to HDD container.
1362 * @param nImage Image number, counts from 0. 0 is always base image of container.
1363 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1364 */
1365VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1366 PPDMMEDIAGEOMETRY pPCHSGeometry);
1367
1368/**
1369 * Store virtual disk PCHS geometry of an image in HDD container.
1370 *
1371 * @return VBox status code.
1372 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1373 * @param pDisk Pointer to HDD container.
1374 * @param nImage Image number, counts from 0. 0 is always base image of container.
1375 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1376 */
1377VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1378 PCPDMMEDIAGEOMETRY pPCHSGeometry);
1379
1380/**
1381 * Get virtual disk LCHS geometry of an image in HDD container.
1382 *
1383 * @return VBox status code.
1384 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1385 * @return VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1386 * @param pDisk Pointer to HDD container.
1387 * @param nImage Image number, counts from 0. 0 is always base image of container.
1388 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1389 */
1390VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1391 PPDMMEDIAGEOMETRY pLCHSGeometry);
1392
1393/**
1394 * Store virtual disk LCHS geometry of an image in HDD container.
1395 *
1396 * @return VBox status code.
1397 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1398 * @param pDisk Pointer to HDD container.
1399 * @param nImage Image number, counts from 0. 0 is always base image of container.
1400 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1401 */
1402VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1403 PCPDMMEDIAGEOMETRY pLCHSGeometry);
1404
1405/**
1406 * Get version of image in HDD container.
1407 *
1408 * @return VBox status code.
1409 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1410 * @param pDisk Pointer to HDD container.
1411 * @param nImage Image number, counts from 0. 0 is always base image of container.
1412 * @param puVersion Where to store the image version.
1413 */
1414VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
1415 unsigned *puVersion);
1416
1417/**
1418 * Get type of image in HDD container.
1419 *
1420 * @return VBox status code.
1421 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1422 * @param pDisk Pointer to HDD container.
1423 * @param nImage Image number, counts from 0. 0 is always base image of container.
1424 * @param penmType Where to store the image type.
1425 */
1426VBOXDDU_DECL(int) VDGetImageType(PVBOXHDD pDisk, unsigned nImage,
1427 PVDIMAGETYPE penmType);
1428
1429/**
1430 * List the capabilities of image backend in HDD container.
1431 *
1432 * @return VBox status code.
1433 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1434 * @param pDisk Pointer to the HDD container.
1435 * @param nImage Image number, counts from 0. 0 is always base image of container.
1436 * @param pbackendInfo Where to store the backend information.
1437 */
1438VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
1439 PVDBACKENDINFO pBackendInfo);
1440
1441/**
1442 * Get flags of image in HDD container.
1443 *
1444 * @return VBox status code.
1445 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1446 * @param pDisk Pointer to HDD container.
1447 * @param nImage Image number, counts from 0. 0 is always base image of container.
1448 * @param puImageFlags Where to store the image flags.
1449 */
1450VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
1451
1452/**
1453 * Get open flags of image in HDD container.
1454 *
1455 * @return VBox status code.
1456 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1457 * @param pDisk Pointer to HDD container.
1458 * @param nImage Image number, counts from 0. 0 is always base image of container.
1459 * @param puOpenFlags Where to store the image open flags.
1460 */
1461VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1462 unsigned *puOpenFlags);
1463
1464/**
1465 * Set open flags of image in HDD container.
1466 * This operation may cause file locking changes and/or files being reopened.
1467 * Note that in case of unrecoverable error all images in HDD container will be closed.
1468 *
1469 * @return VBox status code.
1470 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1471 * @param pDisk Pointer to HDD container.
1472 * @param nImage Image number, counts from 0. 0 is always base image of container.
1473 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1474 */
1475VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1476 unsigned uOpenFlags);
1477
1478/**
1479 * Get base filename of image in HDD container. Some image formats use
1480 * other filenames as well, so don't use this for anything but informational
1481 * purposes.
1482 *
1483 * @return VBox status code.
1484 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1485 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1486 * @param pDisk Pointer to HDD container.
1487 * @param nImage Image number, counts from 0. 0 is always base image of container.
1488 * @param pszFilename Where to store the image file name.
1489 * @param cbFilename Size of buffer pszFilename points to.
1490 */
1491VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
1492 char *pszFilename, unsigned cbFilename);
1493
1494/**
1495 * Get the comment line of image in HDD container.
1496 *
1497 * @return VBox status code.
1498 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1499 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1500 * @param pDisk Pointer to HDD container.
1501 * @param nImage Image number, counts from 0. 0 is always base image of container.
1502 * @param pszComment Where to store the comment string of image. NULL is ok.
1503 * @param cbComment The size of pszComment buffer. 0 is ok.
1504 */
1505VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
1506 char *pszComment, unsigned cbComment);
1507
1508/**
1509 * Changes the comment line of image in HDD container.
1510 *
1511 * @return VBox status code.
1512 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1513 * @param pDisk Pointer to HDD container.
1514 * @param nImage Image number, counts from 0. 0 is always base image of container.
1515 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1516 */
1517VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
1518 const char *pszComment);
1519
1520/**
1521 * Get UUID of image in HDD container.
1522 *
1523 * @return VBox status code.
1524 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1525 * @param pDisk Pointer to HDD container.
1526 * @param nImage Image number, counts from 0. 0 is always base image of container.
1527 * @param pUuid Where to store the image UUID.
1528 */
1529VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1530
1531/**
1532 * Set the image's UUID. Should not be used by normal applications.
1533 *
1534 * @return VBox status code.
1535 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1536 * @param pDisk Pointer to HDD container.
1537 * @param nImage Image number, counts from 0. 0 is always base image of container.
1538 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1539 */
1540VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1541
1542/**
1543 * Get last modification UUID of image in HDD container.
1544 *
1545 * @return VBox status code.
1546 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1547 * @param pDisk Pointer to HDD container.
1548 * @param nImage Image number, counts from 0. 0 is always base image of container.
1549 * @param pUuid Where to store the image modification UUID.
1550 */
1551VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1552 PRTUUID pUuid);
1553
1554/**
1555 * Set the image's last modification UUID. Should not be used by normal applications.
1556 *
1557 * @return VBox status code.
1558 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1559 * @param pDisk Pointer to HDD container.
1560 * @param nImage Image number, counts from 0. 0 is always base image of container.
1561 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1562 */
1563VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1564 PCRTUUID pUuid);
1565
1566/**
1567 * Get parent UUID of image in HDD container.
1568 *
1569 * @return VBox status code.
1570 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1571 * @param pDisk Pointer to HDD container.
1572 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1573 * @param pUuid Where to store the parent image UUID.
1574 */
1575VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1576 PRTUUID pUuid);
1577
1578/**
1579 * Set the image's parent UUID. Should not be used by normal applications.
1580 *
1581 * @return VBox status code.
1582 * @param pDisk Pointer to HDD container.
1583 * @param nImage Image number, counts from 0. 0 is always base image of container.
1584 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1585 */
1586VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1587 PCRTUUID pUuid);
1588
1589
1590/**
1591 * Debug helper - dumps all opened images in HDD container into the log file.
1592 *
1593 * @param pDisk Pointer to HDD container.
1594 */
1595VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
1596
1597
1598/**
1599 * Query if asynchronous operations are supported for this disk.
1600 *
1601 * @return VBox status code.
1602 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1603 * @param pDisk Pointer to the HDD container.
1604 * @param nImage Image number, counts from 0. 0 is always base image of container.
1605 * @param pfAIOSupported Where to store if async IO is supported.
1606 */
1607VBOXDDU_DECL(int) VDImageIsAsyncIOSupported(PVBOXHDD pDisk, unsigned nImage, bool *pfAIOSupported);
1608
1609
1610/**
1611 * Start a asynchronous read request.
1612 *
1613 * @return VBox status code.
1614 * @param pDisk Pointer to the HDD container.
1615 * @param uOffset The offset of the virtual disk to read from.
1616 * @param cbRead How many bytes to read.
1617 * @param paSeg Pointer to an array of segments.
1618 * @param cSeg Number of segments in the array.
1619 * @param pvUser User data which is passed on completion
1620 */
1621VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
1622 PPDMDATASEG paSeg, unsigned cSeg,
1623 void *pvUser);
1624
1625
1626/**
1627 * Start a asynchronous write request.
1628 *
1629 * @return VBox status code.
1630 * @param pDisk Pointer to the HDD container.
1631 * @param uOffset The offset of the virtual disk to write to.
1632 * @param cbWrtie How many bytes to write.
1633 * @param paSeg Pointer to an array of segments.
1634 * @param cSeg Number of segments in the array.
1635 * @param pvUser User data which is passed on completion.
1636 */
1637VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
1638 PPDMDATASEG paSeg, unsigned cSeg,
1639 void *pvUser);
1640
1641
1642__END_DECLS
1643
1644/** @} */
1645
1646#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