VirtualBox

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

Last change on this file since 15051 was 14967, checked in by vboxsync, 16 years ago

#3162: Another attempt to introduce compose name and location callbacks, better version of r40315.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 63.6 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 (including
635 * the terminator, for compatibility with CFGMR3QuerySize).
636 *
637 * @return VBox status code.
638 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
639 * @param pvUser The opaque user data associated with this interface.
640 * @param pszName Name of the key to query.
641 * @param pcbValue Where to store the value length. Non-NULL.
642 */
643 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
644
645 /**
646 * Query the string value associated with a key.
647 *
648 * @return VBox status code.
649 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
650 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
651 * @param pvUser The opaque user data associated with this interface.
652 * @param pszName Name of the key to query.
653 * @param pszValue Pointer to buffer where to store value.
654 * @param cchValue Length of value buffer.
655 */
656 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
657} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
658
659/**
660 * Get configuration information interface from opaque callback table.
661 *
662 * @return Pointer to the callback table.
663 * @param pInterface Pointer to the interface descriptor.
664 */
665DECLINLINE(PVDINTERFACECONFIG) VDGetInterfaceConfig(PVDINTERFACE pInterface)
666{
667 /* Check that the interface descriptor is a config interface. */
668 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_CONFIG)
669 && (pInterface->cbSize == sizeof(VDINTERFACE)),
670 ("Not a config interface"), NULL);
671
672 PVDINTERFACECONFIG pInterfaceConfig = (PVDINTERFACECONFIG)pInterface->pCallbacks;
673
674 /* Do basic checks. */
675 AssertMsgReturn( (pInterfaceConfig->cbSize == sizeof(VDINTERFACECONFIG))
676 && (pInterfaceConfig->enmInterface == VDINTERFACETYPE_CONFIG),
677 ("A non config callback table attached to a config interface descriptor\n"), NULL);
678
679 return pInterfaceConfig;
680}
681
682/**
683 * Query configuration, validates that the keys are within a set of valid names.
684 *
685 * @return true if all key names are found in pszzAllowed.
686 * @return false if not.
687 * @param pCfgIf Pointer to configuration callback table.
688 * @param pvUser The opaque user data associated with this interface.
689 * @param pszzValid List of valid names separated by '\\0' and ending with
690 * a double '\\0'.
691 */
692DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, void *pvUser,
693 const char *pszzValid)
694{
695 return pCfgIf->pfnAreKeysValid(pvUser, pszzValid);
696}
697
698/**
699 * Query configuration, unsigned 64-bit integer value with default.
700 *
701 * @return VBox status code.
702 * @param pCfgIf Pointer to configuration callback table.
703 * @param pvUser The opaque user data associated with this interface.
704 * @param pszName Name of an integer value
705 * @param pu64 Where to store the value. Set to default on failure.
706 * @param u64Def The default value.
707 */
708DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
709 const char *pszName, uint64_t *pu64,
710 uint64_t u64Def)
711{
712 char aszBuf[32];
713 int rc = pCfgIf->pfnQuery(pvUser, pszName, aszBuf, sizeof(aszBuf));
714 if (RT_SUCCESS(rc))
715 {
716 rc = RTStrToUInt64Full(aszBuf, 0, pu64);
717 }
718 else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
719 {
720 rc = VINF_SUCCESS;
721 *pu64 = u64Def;
722 }
723 return rc;
724}
725
726/**
727 * Query configuration, unsigned 32-bit integer value with default.
728 *
729 * @return VBox status code.
730 * @param pCfgIf Pointer to configuration callback table.
731 * @param pvUser The opaque user data associated with this interface.
732 * @param pszName Name of an integer value
733 * @param pu32 Where to store the value. Set to default on failure.
734 * @param u32Def The default value.
735 */
736DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
737 const char *pszName, uint32_t *pu32,
738 uint32_t u32Def)
739{
740 uint64_t u64;
741 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, u32Def);
742 if (RT_SUCCESS(rc))
743 {
744 if (!(u64 & UINT64_C(0xffffffff00000000)))
745 *pu32 = (uint32_t)u64;
746 else
747 rc = VERR_CFGM_INTEGER_TOO_BIG;
748 }
749 return rc;
750}
751
752/**
753 * Query configuration, bool value with default.
754 *
755 * @return VBox status code.
756 * @param pCfgIf Pointer to configuration callback table.
757 * @param pvUser The opaque user data associated with this interface.
758 * @param pszName Name of an integer value
759 * @param pf Where to store the value. Set to default on failure.
760 * @param fDef The default value.
761 */
762DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, void *pvUser,
763 const char *pszName, bool *pf,
764 bool fDef)
765{
766 uint64_t u64;
767 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, fDef);
768 if (RT_SUCCESS(rc))
769 *pf = u64 ? true : false;
770 return rc;
771}
772
773/**
774 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
775 * character value.
776 *
777 * @return VBox status code.
778 * @param pCfgIf Pointer to configuration callback table.
779 * @param pvUser The opaque user data associated with this interface.
780 * @param pszName Name of an zero terminated character value
781 * @param ppszString Where to store the string pointer. Not set on failure.
782 * Free this using RTMemFree().
783 */
784DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
785 void *pvUser, const char *pszName,
786 char **ppszString)
787{
788 size_t cch;
789 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch);
790 if (RT_SUCCESS(rc))
791 {
792 char *pszString = (char *)RTMemAlloc(cch);
793 if (pszString)
794 {
795 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch);
796 if (RT_SUCCESS(rc))
797 *ppszString = pszString;
798 else
799 RTMemFree(pszString);
800 }
801 else
802 rc = VERR_NO_MEMORY;
803 }
804 return rc;
805}
806
807/**
808 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
809 * character value with default.
810 *
811 * @return VBox status code.
812 * @param pCfgIf Pointer to configuration callback table.
813 * @param pvUser The opaque user data associated with this interface.
814 * @param pszName Name of an zero terminated character value
815 * @param ppszString Where to store the string pointer. Not set on failure.
816 * Free this using RTMemFree().
817 * @param pszDef The default value.
818 */
819DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
820 void *pvUser, const char *pszName,
821 char **ppszString,
822 const char *pszDef)
823{
824 size_t cch;
825 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch);
826 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
827 {
828 cch = strlen(pszDef) + 1;
829 rc = VINF_SUCCESS;
830 }
831 if (RT_SUCCESS(rc))
832 {
833 char *pszString = (char *)RTMemAlloc(cch);
834 if (pszString)
835 {
836 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch);
837 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
838 {
839 memcpy(pszString, pszDef, cch);
840 rc = VINF_SUCCESS;
841 }
842 if (RT_SUCCESS(rc))
843 *ppszString = pszString;
844 else
845 RTMemFree(pszString);
846 }
847 else
848 rc = VERR_NO_MEMORY;
849 }
850 return rc;
851}
852
853/**
854 * Query configuration, dynamically allocated (RTMemAlloc) byte string value.
855 *
856 * @return VBox status code.
857 * @param pCfgIf Pointer to configuration callback table.
858 * @param pvUser The opaque user data associated with this interface.
859 * @param pszName Name of an zero terminated character value
860 * @param ppvData Where to store the byte string pointer. Not set on failure.
861 * Free this using RTMemFree().
862 * @param pcbData Where to store the byte string length.
863 */
864DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
865 void *pvUser, const char *pszName,
866 void **ppvData, size_t *pcbData)
867{
868 size_t cb;
869 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
870 if (RT_SUCCESS(rc))
871 {
872 char *pvData = (char *)RTMemAlloc(cb);
873 if (pvData)
874 {
875 rc = pCfgIf->pfnQuery(pvUser, pszName, pvData, cb);
876 if (RT_SUCCESS(rc))
877 {
878 *ppvData = pvData;
879 *pcbData = cb;
880 }
881 else
882 RTMemFree(pvData);
883 }
884 else
885 rc = VERR_NO_MEMORY;
886 }
887 return rc;
888}
889
890
891/**
892 * TCP network stack interface
893 *
894 * Per-disk. Mandatory for backends which have the VD_CAP_TCPNET bit set.
895 */
896typedef struct VDINTERFACETCPNET
897{
898 /**
899 * Size of the configuration interface.
900 */
901 uint32_t cbSize;
902
903 /**
904 * Interface type.
905 */
906 VDINTERFACETYPE enmInterface;
907
908 /**
909 * Connect as a client to a TCP port.
910 *
911 * @return iprt status code.
912 * @param pszAddress The address to connect to.
913 * @param uPort The port to connect to.
914 * @param pSock Where to store the handle to the established connect
915ion.
916 */
917 DECLR3CALLBACKMEMBER(int, pfnClientConnect, (const char *pszAddress, uint32_t uPort, PRTSOCKET pSock));
918
919 /**
920 * Close a TCP connection.
921 *
922 * @return iprt status code.
923 * @param Sock Socket descriptor.
924ion.
925 */
926 DECLR3CALLBACKMEMBER(int, pfnClientClose, (RTSOCKET Sock));
927
928 /**
929 * Socket I/O multiplexing.
930 * Checks if the socket is ready for reading.
931 *
932 * @return iprt status code.
933 * @param Sock Socket descriptor.
934 * @param cMillies Number of milliseconds to wait for the socket.
935 * Use RT_INDEFINITE_WAIT to wait for ever.
936 */
937 DECLR3CALLBACKMEMBER(int, pfnSelectOne, (RTSOCKET Sock, unsigned cMillies));
938
939 /**
940 * Receive data from a socket.
941 *
942 * @return iprt status code.
943 * @param Sock Socket descriptor.
944 * @param pvBuffer Where to put the data we read.
945 * @param cbBuffer Read buffer size.
946 * @param pcbRead Number of bytes read.
947 * If NULL the entire buffer will be filled upon successful return.
948 * If not NULL a partial read can be done successfully.
949 */
950 DECLR3CALLBACKMEMBER(int, pfnRead, (RTSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
951
952 /**
953 * Send data from a socket.
954 *
955 * @return iprt status code.
956 * @param Sock Socket descriptor.
957 * @param pvBuffer Buffer to write data to socket.
958 * @param cbBuffer How much to write.
959 * @param pcbRead Number of bytes read.
960 */
961 DECLR3CALLBACKMEMBER(int, pfnWrite, (RTSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
962
963 /**
964 * Flush socket write buffers.
965 *
966 * @return iprt status code.
967 * @param Sock Socket descriptor.
968 */
969 DECLR3CALLBACKMEMBER(int, pfnFlush, (RTSOCKET Sock));
970
971} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
972
973/**
974 * Get TCP network stack interface from opaque callback table.
975 *
976 * @return Pointer to the callback table.
977 * @param pInterface Pointer to the interface descriptor.
978 */
979DECLINLINE(PVDINTERFACETCPNET) VDGetInterfaceTcpNet(PVDINTERFACE pInterface)
980{
981 /* Check that the interface descriptor is a TCP network stack interface. */
982 AssertMsgReturn( (pInterface->enmInterface == VDINTERFACETYPE_TCPNET)
983 && (pInterface->cbSize == sizeof(VDINTERFACE)),
984 ("Not a TCP network stack interface"), NULL);
985
986 PVDINTERFACETCPNET pInterfaceTcpNet = (PVDINTERFACETCPNET)pInterface->pCallbacks;
987
988 /* Do basic checks. */
989 AssertMsgReturn( (pInterfaceTcpNet->cbSize == sizeof(VDINTERFACETCPNET))
990 && (pInterfaceTcpNet->enmInterface == VDINTERFACETYPE_TCPNET),
991 ("A non TCP network stack callback table attached to a TCP network stack interface descriptor\n"), NULL);
992
993 return pInterfaceTcpNet;
994}
995
996
997/** @name Configuration interface key handling flags.
998 * @{
999 */
1000/** Mandatory config key. Not providing a value for this key will cause
1001 * the backend to fail. */
1002#define VD_CFGKEY_MANDATORY RT_BIT(0)
1003/** Expert config key. Not showing it by default in the GUI is is probably
1004 * a good idea, as the average user won't understand it easily. */
1005#define VD_CFGKEY_EXPERT RT_BIT(1)
1006/** @}*/
1007
1008
1009/**
1010 * Configuration value type for configuration information interface.
1011 */
1012typedef enum VDCFGVALUETYPE
1013{
1014 /** Integer value. */
1015 VDCFGVALUETYPE_INTEGER = 1,
1016 /** String value. */
1017 VDCFGVALUETYPE_STRING,
1018 /** Bytestring value. */
1019 VDCFGVALUETYPE_BYTES
1020} VDCFGVALUETYPE;
1021
1022
1023/**
1024 * Structure describing configuration keys required/supported by a backend
1025 * through the config interface.
1026 */
1027typedef struct VDCONFIGINFO
1028{
1029 /** Key name of the configuration. */
1030 const char *pszKey;
1031 /** Pointer to default value (descriptor). NULL if no useful default value
1032 * can be specified. */
1033 const char *pszDefaultValue;
1034 /** Value type for this key. */
1035 VDCFGVALUETYPE enmValueType;
1036 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
1037 uint64_t uKeyFlags;
1038} VDCONFIGINFO;
1039
1040/** Pointer to structure describing configuration keys. */
1041typedef VDCONFIGINFO *PVDCONFIGINFO;
1042
1043/** Pointer to const structure describing configuration keys. */
1044typedef const VDCONFIGINFO *PCVDCONFIGINFO;
1045
1046/**
1047 * Data structure for returning a list of backend capabilities.
1048 */
1049typedef struct VDBACKENDINFO
1050{
1051 /** Name of the backend. */
1052 const char *pszBackend;
1053 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
1054 uint64_t uBackendCaps;
1055 /** Pointer to a NULL-terminated array of strings, containing the supported
1056 * file extensions. Note that some backends do not work on files, so this
1057 * pointer may just contain NULL. */
1058 const char * const *papszFileExtensions;
1059 /** Pointer to an array of structs describing each supported config key.
1060 * Terminated by a NULL config key. Note that some backends do not support
1061 * the configuration interface, so this pointer may just contain NULL.
1062 * Mandatory if the backend sets VD_CAP_CONFIG. */
1063 PCVDCONFIGINFO paConfigInfo;
1064 /** Returns a human readable hard disk location string given a
1065 * set of hard disk configuration keys. The returned string is an
1066 * equivalent of the full file path for image-based hard disks.
1067 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
1068 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
1069 /** Returns a human readable hard disk name string given a
1070 * set of hard disk configuration keys. The returned string is an
1071 * equivalent of the file name part in the full file path for
1072 * image-based hard disks. Mandatory for backends with no
1073 * VD_CAP_FILE and NULL otherwise. */
1074 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
1075} VDBACKENDINFO, *PVDBACKENDINFO;
1076
1077
1078/**
1079 * VBox HDD Container main structure.
1080 */
1081/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
1082struct VBOXHDD;
1083typedef struct VBOXHDD VBOXHDD;
1084typedef VBOXHDD *PVBOXHDD;
1085
1086/**
1087 * Initializes HDD backends.
1088 *
1089 * @returns VBox status code.
1090 */
1091VBOXDDU_DECL(int) VDInit();
1092
1093/**
1094 * Destroys loaded HDD backends.
1095 *
1096 * @returns VBox status code.
1097 */
1098VBOXDDU_DECL(int) VDShutdown();
1099
1100/**
1101 * Lists all HDD backends and their capabilities in a caller-provided buffer.
1102 * Free all returned names with RTStrFree() when you no longer need them.
1103 *
1104 * @return VBox status code.
1105 * VERR_BUFFER_OVERFLOW if not enough space is passed.
1106 * @param cEntriesAlloc Number of list entries available.
1107 * @param pEntries Pointer to array for the entries.
1108 * @param pcEntriesUsed Number of entries returned.
1109 */
1110VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
1111 unsigned *pcEntriesUsed);
1112
1113/**
1114 * Lists the capablities of a backend indentified by its name.
1115 * Free all returned names with RTStrFree() when you no longer need them.
1116 *
1117 * @return VBox status code.
1118 * @param pszBackend The backend name.
1119 * @param pEntries Pointer to an entry.
1120 */
1121VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
1122
1123/**
1124 * Allocates and initializes an empty HDD container.
1125 * No image files are opened.
1126 *
1127 * @return VBox status code.
1128 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1129 * @param ppDisk Where to store the reference to HDD container.
1130 */
1131VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, PVBOXHDD *ppDisk);
1132
1133/**
1134 * Destroys HDD container.
1135 * If container has opened image files they will be closed.
1136 *
1137 * @param pDisk Pointer to HDD container.
1138 */
1139VBOXDDU_DECL(void) VDDestroy(PVBOXHDD pDisk);
1140
1141/**
1142 * Try to get the backend name which can use this image.
1143 *
1144 * @return VBox status code.
1145 * @param pszFilename Name of the image file for which the backend is queried.
1146 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
1147 * The returned pointer must be freed using RTStrFree().
1148 */
1149VBOXDDU_DECL(int) VDGetFormat(const char *pszFilename, char **ppszFormat);
1150
1151/**
1152 * Opens an image file.
1153 *
1154 * The first opened image file in HDD container must have a base image type,
1155 * others (next opened images) must be differencing or undo images.
1156 * Linkage is checked for differencing image to be consistent with the previously opened image.
1157 * When another differencing image is opened and the last image was opened in read/write access
1158 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
1159 * other processes to use images in read-only mode too.
1160 *
1161 * Note that the image is opened in read-only mode if a read/write open is not possible.
1162 * Use VDIsReadOnly to check open mode.
1163 *
1164 * @return VBox status code.
1165 * @param pDisk Pointer to HDD container.
1166 * @param pszBackend Name of the image file backend to use.
1167 * @param pszFilename Name of the image file to open.
1168 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1169 * @param pVDIfsImage Pointer to the per-image VD interface list.
1170 */
1171VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
1172 const char *pszFilename, unsigned uOpenFlags,
1173 PVDINTERFACE pVDIfsImage);
1174
1175/**
1176 * Creates and opens a new base image file.
1177 *
1178 * @return VBox status code.
1179 * @param pDisk Pointer to HDD container.
1180 * @param pszBackend Name of the image file backend to use.
1181 * @param pszFilename Name of the image file to create.
1182 * @param enmType Image type, only base image types are acceptable.
1183 * @param cbSize Image size in bytes.
1184 * @param uImageFlags Flags specifying special image features.
1185 * @param pszComment Pointer to image comment. NULL is ok.
1186 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
1187 * @param pLCHSGeometry Pointer to logical disk geometry <= (1024,255,63). Not NULL.
1188 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1189 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1190 * @param pVDIfsImage Pointer to the per-image VD interface list.
1191 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1192 */
1193VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
1194 const char *pszFilename, VDIMAGETYPE enmType,
1195 uint64_t cbSize, unsigned uImageFlags,
1196 const char *pszComment,
1197 PCPDMMEDIAGEOMETRY pPCHSGeometry,
1198 PCPDMMEDIAGEOMETRY pLCHSGeometry,
1199 PCRTUUID pUuid, unsigned uOpenFlags,
1200 PVDINTERFACE pVDIfsImage,
1201 PVDINTERFACE pVDIfsOperation);
1202
1203/**
1204 * Creates and opens a new differencing image file in HDD container.
1205 * See comments for VDOpen function about differencing images.
1206 *
1207 * @return VBox status code.
1208 * @param pDisk Pointer to HDD container.
1209 * @param pszBackend Name of the image file backend to use.
1210 * @param pszFilename Name of the differencing image file to create.
1211 * @param uImageFlags Flags specifying special image features.
1212 * @param pszComment Pointer to image comment. NULL is ok.
1213 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1214 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1215 * @param pVDIfsImage Pointer to the per-image VD interface list.
1216 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1217 */
1218VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
1219 const char *pszFilename, unsigned uImageFlags,
1220 const char *pszComment, PCRTUUID pUuid,
1221 unsigned uOpenFlags, PVDINTERFACE pVDIfsImage,
1222 PVDINTERFACE pVDIfsOperation);
1223
1224/**
1225 * Merges two images (not necessarily with direct parent/child relationship).
1226 * As a side effect the source image and potentially the other images which
1227 * are also merged to the destination are deleted from both the disk and the
1228 * images in the HDD container.
1229 *
1230 * @return VBox status code.
1231 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1232 * @param pDisk Pointer to HDD container.
1233 * @param nImageFrom Name of the image file to merge from.
1234 * @param nImageTo Name of the image file to merge to.
1235 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1236 */
1237VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
1238 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
1239
1240/**
1241 * Copies an image from one HDD container to another.
1242 * The copy is opened in the target HDD container.
1243 * It is possible to convert between different image formats, because the
1244 * backend for the destination may be different from the source.
1245 * If both the source and destination reference the same HDD container,
1246 * then the image is moved (by copying/deleting or renaming) to the new location.
1247 * The source container is unchanged if the move operation fails, otherwise
1248 * the image at the new location is opened in the same way as the old one was.
1249 *
1250 * @return VBox status code.
1251 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1252 * @param pDiskFrom Pointer to source HDD container.
1253 * @param nImage Image number, counts from 0. 0 is always base image of container.
1254 * @param pDiskTo Pointer to destination HDD container.
1255 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source).
1256 * @param pszFilename New name of the image (may be NULL if pDiskFrom == pDiskTo).
1257 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
1258 * @param cbSize New image size (0 means leave unchanged).
1259 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1260 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
1261 * destination image.
1262 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
1263 * for the destination operation.
1264 */
1265VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
1266 const char *pszBackend, const char *pszFilename,
1267 bool fMoveByRename, uint64_t cbSize,
1268 PVDINTERFACE pVDIfsOperation,
1269 PVDINTERFACE pDstVDIfsImage,
1270 PVDINTERFACE pDstVDIfsOperation);
1271
1272/**
1273 * Closes the last opened image file in HDD container.
1274 * If previous image file was opened in read-only mode (that is normal) and closing image
1275 * was opened in read-write mode (the whole disk was in read-write mode) - the previous image
1276 * will be reopened in read/write mode.
1277 *
1278 * @return VBox status code.
1279 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1280 * @param pDisk Pointer to HDD container.
1281 * @param fDelete If true, delete the image from the host disk.
1282 */
1283VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
1284
1285/**
1286 * Closes all opened image files in HDD container.
1287 *
1288 * @return VBox status code.
1289 * @param pDisk Pointer to HDD container.
1290 */
1291VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
1292
1293/**
1294 * Read data from virtual HDD.
1295 *
1296 * @return VBox status code.
1297 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1298 * @param pDisk Pointer to HDD container.
1299 * @param uOffset Offset of first reading byte from start of disk.
1300 * Must be aligned to a sector boundary.
1301 * @param pvBuf Pointer to buffer for reading data.
1302 * @param cbRead Number of bytes to read.
1303 * Must be aligned to a sector boundary.
1304 */
1305VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
1306
1307/**
1308 * Write data to virtual HDD.
1309 *
1310 * @return VBox status code.
1311 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1312 * @param pDisk Pointer to HDD container.
1313 * @param uOffset Offset of first writing byte from start of disk.
1314 * Must be aligned to a sector boundary.
1315 * @param pvBuf Pointer to buffer for writing data.
1316 * @param cbWrite Number of bytes to write.
1317 * Must be aligned to a sector boundary.
1318 */
1319VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
1320
1321/**
1322 * Make sure the on disk representation of a virtual HDD is up to date.
1323 *
1324 * @return VBox status code.
1325 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1326 * @param pDisk Pointer to HDD container.
1327 */
1328VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
1329
1330/**
1331 * Get number of opened images in HDD container.
1332 *
1333 * @return Number of opened images for HDD container. 0 if no images have been opened.
1334 * @param pDisk Pointer to HDD container.
1335 */
1336VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
1337
1338/**
1339 * Get read/write mode of HDD container.
1340 *
1341 * @return Virtual disk ReadOnly status.
1342 * @return true if no image is opened in HDD container.
1343 * @param pDisk Pointer to HDD container.
1344 */
1345VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
1346
1347/**
1348 * Get total capacity of an image in HDD container.
1349 *
1350 * @return Virtual disk size in bytes.
1351 * @return 0 if image with specified number was not opened.
1352 * @param pDisk Pointer to HDD container.
1353 * @param nImage Image number, counts from 0. 0 is always base image of container.
1354 */
1355VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
1356
1357/**
1358 * Get total file size of an image in HDD container.
1359 *
1360 * @return Virtual disk size in bytes.
1361 * @return 0 if image with specified number was not opened.
1362 * @param pDisk Pointer to HDD container.
1363 * @param nImage Image number, counts from 0. 0 is always base image of container.
1364 */
1365VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
1366
1367/**
1368 * Get virtual disk PCHS geometry of an image in HDD container.
1369 *
1370 * @return VBox status code.
1371 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1372 * @return VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
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 store PCHS geometry. Not NULL.
1376 */
1377VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1378 PPDMMEDIAGEOMETRY pPCHSGeometry);
1379
1380/**
1381 * Store virtual disk PCHS 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 * @param pDisk Pointer to HDD container.
1386 * @param nImage Image number, counts from 0. 0 is always base image of container.
1387 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1388 */
1389VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1390 PCPDMMEDIAGEOMETRY pPCHSGeometry);
1391
1392/**
1393 * Get virtual disk LCHS geometry of an image in HDD container.
1394 *
1395 * @return VBox status code.
1396 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1397 * @return VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
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 store LCHS geometry. Not NULL.
1401 */
1402VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1403 PPDMMEDIAGEOMETRY pLCHSGeometry);
1404
1405/**
1406 * Store virtual disk LCHS geometry of an 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 pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1413 */
1414VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1415 PCPDMMEDIAGEOMETRY pLCHSGeometry);
1416
1417/**
1418 * Get version 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 puVersion Where to store the image version.
1425 */
1426VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
1427 unsigned *puVersion);
1428
1429/**
1430 * Get type of image 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 HDD container.
1435 * @param nImage Image number, counts from 0. 0 is always base image of container.
1436 * @param penmType Where to store the image type.
1437 */
1438VBOXDDU_DECL(int) VDGetImageType(PVBOXHDD pDisk, unsigned nImage,
1439 PVDIMAGETYPE penmType);
1440
1441/**
1442 * List the capabilities of image backend 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 the HDD container.
1447 * @param nImage Image number, counts from 0. 0 is always base image of container.
1448 * @param pbackendInfo Where to store the backend information.
1449 */
1450VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
1451 PVDBACKENDINFO pBackendInfo);
1452
1453/**
1454 * Get flags of image in HDD container.
1455 *
1456 * @return VBox status code.
1457 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1458 * @param pDisk Pointer to HDD container.
1459 * @param nImage Image number, counts from 0. 0 is always base image of container.
1460 * @param puImageFlags Where to store the image flags.
1461 */
1462VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
1463
1464/**
1465 * Get open flags of image in HDD container.
1466 *
1467 * @return VBox status code.
1468 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1469 * @param pDisk Pointer to HDD container.
1470 * @param nImage Image number, counts from 0. 0 is always base image of container.
1471 * @param puOpenFlags Where to store the image open flags.
1472 */
1473VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1474 unsigned *puOpenFlags);
1475
1476/**
1477 * Set open flags of image in HDD container.
1478 * This operation may cause file locking changes and/or files being reopened.
1479 * Note that in case of unrecoverable error all images in HDD container will be closed.
1480 *
1481 * @return VBox status code.
1482 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1483 * @param pDisk Pointer to HDD container.
1484 * @param nImage Image number, counts from 0. 0 is always base image of container.
1485 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1486 */
1487VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1488 unsigned uOpenFlags);
1489
1490/**
1491 * Get base filename of image in HDD container. Some image formats use
1492 * other filenames as well, so don't use this for anything but informational
1493 * purposes.
1494 *
1495 * @return VBox status code.
1496 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1497 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1498 * @param pDisk Pointer to HDD container.
1499 * @param nImage Image number, counts from 0. 0 is always base image of container.
1500 * @param pszFilename Where to store the image file name.
1501 * @param cbFilename Size of buffer pszFilename points to.
1502 */
1503VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
1504 char *pszFilename, unsigned cbFilename);
1505
1506/**
1507 * Get the comment line of image in HDD container.
1508 *
1509 * @return VBox status code.
1510 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1511 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1512 * @param pDisk Pointer to HDD container.
1513 * @param nImage Image number, counts from 0. 0 is always base image of container.
1514 * @param pszComment Where to store the comment string of image. NULL is ok.
1515 * @param cbComment The size of pszComment buffer. 0 is ok.
1516 */
1517VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
1518 char *pszComment, unsigned cbComment);
1519
1520/**
1521 * Changes the comment line 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 pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1528 */
1529VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
1530 const char *pszComment);
1531
1532/**
1533 * Get UUID of image in HDD container.
1534 *
1535 * @return VBox status code.
1536 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1537 * @param pDisk Pointer to HDD container.
1538 * @param nImage Image number, counts from 0. 0 is always base image of container.
1539 * @param pUuid Where to store the image UUID.
1540 */
1541VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1542
1543/**
1544 * Set the image's UUID. Should not be used by normal applications.
1545 *
1546 * @return VBox status code.
1547 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1548 * @param pDisk Pointer to HDD container.
1549 * @param nImage Image number, counts from 0. 0 is always base image of container.
1550 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1551 */
1552VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1553
1554/**
1555 * Get last modification UUID of image in HDD container.
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 Where to store the image modification UUID.
1562 */
1563VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1564 PRTUUID pUuid);
1565
1566/**
1567 * Set the image's last modification UUID. Should not be used by normal applications.
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 container.
1573 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1574 */
1575VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1576 PCRTUUID pUuid);
1577
1578/**
1579 * Get parent UUID of image in HDD container.
1580 *
1581 * @return VBox status code.
1582 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1583 * @param pDisk Pointer to HDD container.
1584 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1585 * @param pUuid Where to store the parent image UUID.
1586 */
1587VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1588 PRTUUID pUuid);
1589
1590/**
1591 * Set the image's parent UUID. Should not be used by normal applications.
1592 *
1593 * @return VBox status code.
1594 * @param pDisk Pointer to HDD container.
1595 * @param nImage Image number, counts from 0. 0 is always base image of container.
1596 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1597 */
1598VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1599 PCRTUUID pUuid);
1600
1601
1602/**
1603 * Debug helper - dumps all opened images in HDD container into the log file.
1604 *
1605 * @param pDisk Pointer to HDD container.
1606 */
1607VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
1608
1609
1610/**
1611 * Query if asynchronous operations are supported for this disk.
1612 *
1613 * @return VBox status code.
1614 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1615 * @param pDisk Pointer to the HDD container.
1616 * @param nImage Image number, counts from 0. 0 is always base image of container.
1617 * @param pfAIOSupported Where to store if async IO is supported.
1618 */
1619VBOXDDU_DECL(int) VDImageIsAsyncIOSupported(PVBOXHDD pDisk, unsigned nImage, bool *pfAIOSupported);
1620
1621
1622/**
1623 * Start a asynchronous read request.
1624 *
1625 * @return VBox status code.
1626 * @param pDisk Pointer to the HDD container.
1627 * @param uOffset The offset of the virtual disk to read from.
1628 * @param cbRead How many bytes to read.
1629 * @param paSeg Pointer to an array of segments.
1630 * @param cSeg Number of segments in the array.
1631 * @param pvUser User data which is passed on completion
1632 */
1633VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
1634 PPDMDATASEG paSeg, unsigned cSeg,
1635 void *pvUser);
1636
1637
1638/**
1639 * Start a asynchronous write request.
1640 *
1641 * @return VBox status code.
1642 * @param pDisk Pointer to the HDD container.
1643 * @param uOffset The offset of the virtual disk to write to.
1644 * @param cbWrtie How many bytes to write.
1645 * @param paSeg Pointer to an array of segments.
1646 * @param cSeg Number of segments in the array.
1647 * @param pvUser User data which is passed on completion.
1648 */
1649VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
1650 PPDMDATASEG paSeg, unsigned cSeg,
1651 void *pvUser);
1652
1653
1654__END_DECLS
1655
1656/** @} */
1657
1658#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