VirtualBox

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

Last change on this file since 11106 was 11048, checked in by vboxsync, 17 years ago

Typo which wasn't caught by release build.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 53.5 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/** @todo eliminate this dependency by moving data type definitions to the
41 * right place. PFNVMPROGRESS and P*PDMMEDIAGEOMETRY are affected. */
42#include <VBox/pdm.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/** @}*/
216
217/**
218 * Data structure for returning a list of backend capabilities.
219 */
220typedef struct VDBACKENDINFO
221{
222 /** Name of the backend. */
223 char *pszBackend;
224 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
225 uint64_t uBackendCaps;
226} VDBACKENDINFO, *PVDBACKENDINFO;
227
228/**
229 * Supported interface types.
230 */
231typedef enum VDINTERFACETYPE
232{
233 /** First valid interface. */
234 VDINTERFACETYPE_FIRST = 0,
235 /** Interface to pass error message to upper layers. */
236 VDINTERFACETYPE_ERROR = VDINTERFACETYPE_FIRST,
237 /** Interface for asynchronous I/O operations. */
238 VDINTERFACETYPE_ASYNCIO,
239 /** Interface for progress notification. */
240 VDINTERFACETYPE_PROGRESS,
241 /** Interface for configuration information. */
242 VDINTERFACETYPE_CONFIG,
243 /** invalid interface. */
244 VDINTERFACETYPE_INVALID
245} VDINTERFACETYPE;
246
247/**
248 * Common structure for all interfaces.
249 */
250typedef struct VDINTERFACE
251{
252 /** Human readable interface name. */
253 const char *pszInterfaceName;
254 /** The size of the struct. */
255 uint32_t cbSize;
256 /** Pointer to the next common interface structure. */
257 struct VDINTERFACE *pNext;
258 /** Interface type. */
259 VDINTERFACETYPE enmInterface;
260 /** Opaque user data which is passed on every call. */
261 void *pvUser;
262 /** Pointer to the function call table of the interface.
263 * As this is opaque this must be casted to the right interface
264 * struct defined below based on the interface type in enmInterface. */
265 void *pCallbacks;
266} VDINTERFACE, *PVDINTERFACE;
267/** Pointer to a const PVDINTERFACE. */
268typedef const PVDINTERFACE PCVDINTERFACE;
269
270/**
271 * Helper functions to handle interface lists.
272 */
273
274/**
275 * Get a specific interface from a list of interfaces specified by the type.
276 *
277 * @return Pointer to the matching interface or NULL if none was found.
278 * @param pInterfaces Pointer to the first interface in the list.
279 * @param enmInterface Interface to search for.
280 */
281DECLINLINE(PVDINTERFACE) VDGetInterfaceFromList(PVDINTERFACE pInterfaces, VDINTERFACETYPE enmInterface)
282{
283 AssertMsgReturn( (enmInterface >= VDINTERFACETYPE_FIRST)
284 && (enmInterface < VDINTERFACETYPE_INVALID),
285 ("enmInterface=%u", enmInterface), NULL);
286
287 while (pInterfaces)
288 {
289 /* Sanity checks. */
290 AssertMsgBreak(pInterfaces->cbSize == sizeof(VDINTERFACE),
291 ("cbSize=%u\n", pInterfaces->cbSize));
292
293 if (pInterfaces->enmInterface == enmInterface)
294 return pInterfaces;
295 pInterfaces = pInterfaces->pNext;
296 }
297
298 /* No matching interface was found. */
299 return NULL;
300}
301
302/**
303 * Initialize a common interface structure.
304 *
305 * @return VBox status code.
306 * @param pInterface Pointer to an unitialized common interface structure.
307 * @param pszName Name of the interface.
308 * @param enmInterface Type of the interface.
309 * @param pCallbacks The callback table of the interface.
310 * @param pvUser Opaque user data passed on every function call.
311 * @param pNext Pointer to the next supported interface if any.
312 */
313DECLINLINE(int) VDInterfaceCreate(PVDINTERFACE pInterface, const char *pszName,
314 VDINTERFACETYPE enmInterface, void *pCallbacks,
315 void *pvUser, PVDINTERFACE pNext)
316{
317
318 /** Argument checks. */
319 AssertMsgReturn( (enmInterface >= VDINTERFACETYPE_FIRST)
320 && (enmInterface < VDINTERFACETYPE_INVALID),
321 ("enmInterface=%u", enmInterface), VERR_INVALID_PARAMETER);
322
323 AssertMsgReturn(VALID_PTR(pCallbacks),
324 ("pCallbacks=%#p", pCallbacks),
325 VERR_INVALID_PARAMETER);
326
327 pInterface->cbSize = sizeof(VDINTERFACE);
328 pInterface->pszInterfaceName = pszName;
329 pInterface->enmInterface = enmInterface;
330 pInterface->pCallbacks = pCallbacks;
331 pInterface->pvUser = pvUser;
332 pInterface->pNext = pNext;
333 return VINF_SUCCESS;
334}
335
336/**
337 * Interface to deliver error messages to upper layers.
338 */
339typedef struct VDINTERFACEERROR
340{
341 /**
342 * Size of the error interface.
343 */
344 uint32_t cbSize;
345
346 /**
347 * Interface type.
348 */
349 VDINTERFACETYPE enmInterface;
350
351 /**
352 * Error message callback.
353 *
354 * @param pvUser The opaque data passed on container creation.
355 * @param rc The VBox error code.
356 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
357 * @param pszFormat Error message format string.
358 * @param va Error message arguments.
359 */
360 DECLR3CALLBACKMEMBER(void, pfnError, (void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
361
362} VDINTERFACEERROR, *PVDINTERFACEERROR;
363
364/**
365 * Get error interface from opaque callback table.
366 *
367 * @return Pointer to the callback table.
368 * @param pCallbacks Opaque interface pointer.
369 */
370DECLINLINE(PVDINTERFACEERROR) VDGetInterfaceError(void *pCallbacks)
371{
372 PVDINTERFACEERROR pInterfaceError = (PVDINTERFACEERROR)pCallbacks;
373
374 /* Do basic checks. */
375 AssertMsgReturn( (pInterfaceError->cbSize == sizeof(VDINTERFACEERROR))
376 && (pInterfaceError->enmInterface == VDINTERFACETYPE_ERROR),
377 ("Not an error interface\n"), NULL);
378
379 return pInterfaceError;
380}
381
382/**
383 * Completion callback which is called by the interface owner
384 * to inform the backend that a task finished.
385 *
386 * @return VBox status code.
387 * @param pvUser Opaque user data which is passed on request submission.
388 */
389typedef DECLCALLBACK(int) FNVDCOMPLETED(void *pvUser);
390/** Pointer to FNVDCOMPLETED() */
391typedef FNVDCOMPLETED *PFNVDCOMPLETED;
392
393
394/**
395 * Support interface for asynchronous I/O
396 */
397typedef struct VDINTERFACEASYNCIO
398{
399 /**
400 * Size of the async interface.
401 */
402 uint32_t cbSize;
403
404 /**
405 * Interface type.
406 */
407 VDINTERFACETYPE enmInterface;
408
409 /**
410 * Open callback
411 *
412 * @return VBox status code.
413 * @param pvUser The opaque data passed on container creation.
414 * @param pszLocation Name of the location to open.
415 * @param fReadonly Whether to open the storage medium read only.
416 * @param ppStorage Where to store the opaque storage handle.
417 */
418 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation, bool fReadonly, void **ppStorage));
419
420 /**
421 * Close callback.
422 *
423 * @return VBox status code.
424 * @param pvUser The opaque data passed on container creation.
425 * @param pStorage The opaque storage handle to close.
426 */
427 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, void *pStorage));
428
429 /**
430 * Synchronous write callback.
431 *
432 * @return VBox status code.
433 * @param pvUser The opaque data passed on container creation.
434 * @param pStorage The storage handle to use.
435 * @param uOffset The offset to start from.
436 * @þaram cbWrite How many bytes to write.
437 * @param pvBuf Pointer to the bits need to be written.
438 * @param pcbWritten Where to store how many bytes where actually written.
439 */
440 DECLR3CALLBACKMEMBER(int, pfnWrite, (void *pvUser, void *pStorage, uint64_t uOffset,
441 size_t cbWrite, const void *pvBuf, size_t *pcbWritten));
442
443 /**
444 * Synchronous read callback.
445 *
446 * @return VBox status code.
447 * @param pvUser The opaque data passed on container creation.
448 * @param pStorage The storage handle to use.
449 * @param uOffset The offset to start from.
450 * @þaram cbRead How many bytes to read.
451 * @param pvBuf Where to store the read bits.
452 * @param pcbRead Where to store how many bytes where actually read.
453 */
454 DECLR3CALLBACKMEMBER(int, pfnRead, (void *pvUser, void *pStorage, uint64_t uOffset,
455 size_t cbRead, void *pvBuf, size_t *pcbRead));
456
457 /**
458 * Flush data to the storage backend.
459 *
460 * @return VBox statis code.
461 * @param pvUser The opaque data passed on container creation.
462 * @param pStorage The storage handle to flush.
463 */
464 DECLR3CALLBACKMEMBER(int, pfnFlush, (void *pvUser, void *pStorage));
465
466 /**
467 * Prepare an asynchronous read task.
468 *
469 * @return VBox status code.
470 * @param pvUser The opqaue user data passed on container creation.
471 * @param pStorage The storage handle.
472 * @param uOffset The offset to start reading from.
473 * @param pvBuf Where to store read bits.
474 * @param cbRead How many bytes to read.
475 * @param ppTask Where to store the opaque task handle.
476 */
477 DECLR3CALLBACKMEMBER(int, pfnPrepareRead, (void *pvUser, void *pStorage, uint64_t uOffset,
478 void *pvBuf, size_t cbRead, void **ppTask));
479
480 /**
481 * Prepare an asynchronous write task.
482 *
483 * @return VBox status code.
484 * @param pvUser The opaque user data passed on conatiner creation.
485 * @param pStorage The storage handle.
486 * @param uOffset The offset to start writing to.
487 * @param pvBuf Where to read the data from.
488 * @param cbWrite How many bytes to write.
489 * @param ppTask Where to store the opaque task handle.
490 */
491 DECLR3CALLBACKMEMBER(int, pfnPrepareWrite, (void *pvUser, void *pStorage, uint64_t uOffset,
492 void *pvBuf, size_t cbWrite, void **ppTask));
493
494 /**
495 * Submit an array of tasks for processing
496 *
497 * @return VBox status code.
498 * @param pvUser The opaque user data passed on container creation.
499 * @param apTasks Array of task handles to submit.
500 * @param cTasks How many tasks to submit.
501 * @param pvUser2 User data which is passed on completion.
502 * @param pvUserCaller Opaque user data the caller of VDAsyncWrite/Read passed.
503 * @param pfnTasksCompleted Pointer to callback which is called on request completion.
504 */
505 DECLR3CALLBACKMEMBER(int, pfnTasksSubmit, (void *pvUser, void *apTasks[], unsigned cTasks, void *pvUser2,
506 void *pvUserCaller, PFNVDCOMPLETED pfnTasksCompleted));
507
508} VDINTERFACEASYNCIO, *PVDINTERFACEASYNCIO;
509
510/**
511 * Get async I/O interface from opaque callback table.
512 *
513 * @return Pointer to the callback table.
514 * @param pCallbacks Opaque interface pointer.
515 */
516DECLINLINE(PVDINTERFACEASYNCIO) VDGetInterfaceAsyncIO(void *pCallbacks)
517{
518 PVDINTERFACEASYNCIO pInterfaceAsyncIO = (PVDINTERFACEASYNCIO)pCallbacks;
519
520 /* Do basic checks. */
521 AssertMsgReturn( (pInterfaceAsyncIO->cbSize == sizeof(VDINTERFACEASYNCIO))
522 && (pInterfaceAsyncIO->enmInterface == VDINTERFACETYPE_ASYNCIO),
523 ("Not an async I/O interface\n"), NULL);
524
525 return pInterfaceAsyncIO;
526}
527
528/**
529 * Progress notification interface
530 */
531typedef struct VDINTERFACEPROGRESS
532{
533 /**
534 * Size of the progress interface.
535 */
536 uint32_t cbSize;
537
538 /**
539 * Interface type.
540 */
541 VDINTERFACETYPE enmInterface;
542
543 /**
544 * Progress notification callbacks.
545 */
546 PFNVMPROGRESS pfnProgress;
547} VDINTERFACEPROGRESS, *PVDINTERFACEPROGRESS;
548
549/**
550 * Get progress interface from opaque callback table.
551 *
552 * @return Pointer to the callback table.
553 * @param pCallbacks Opaque interface pointer.
554 */
555DECLINLINE(PVDINTERFACEPROGRESS) VDGetInterfaceProgress(void *pCallbacks)
556{
557 PVDINTERFACEPROGRESS pInterfaceProgress = (PVDINTERFACEPROGRESS)pCallbacks;
558
559 /* Do basic checks. */
560 AssertMsgReturn( (pInterfaceProgress->cbSize == sizeof(VDINTERFACEPROGRESS))
561 && (pInterfaceProgress->enmInterface == VDINTERFACETYPE_PROGRESS),
562 ("Not a progress notification interface\n"), NULL);
563
564 return pInterfaceProgress;
565}
566
567/** Configuration node for configuration information interface. */
568typedef struct VDCFGNODE *PVDCFGNODE;
569
570/**
571 * Configuration value type for configuration information interface.
572 */
573typedef enum VDCFGVALUETYPE
574{
575 /** Integer value. */
576 VDCFGVALUETYPE_INTEGER = 1,
577 /** String value. */
578 VDCFGVALUETYPE_STRING,
579 /** Bytestring value. */
580 VDCFGVALUETYPE_BYTES
581} VDCFGVALUETYPE;
582/** Pointer to configuration value type for configuration information interface. */
583typedef VDCFGVALUETYPE *PVDCFGVALUETYPE;
584
585/**
586 * Configuration information interface
587 */
588typedef struct VDINTERFACECONFIG
589{
590 /**
591 * Size of the configuration interface.
592 */
593 uint32_t cbSize;
594
595 /**
596 * Interface type.
597 */
598 VDINTERFACETYPE enmInterface;
599
600 /**
601 * Validates that the values are within a set of valid names.
602 *
603 * @return true if all names are found in pszzAllowed.
604 * @return false if not.
605 * @param pNode The node which values should be examined.
606 * @param pszzValid List of valid names separated by '\\0' and ending with
607 * a double '\\0'.
608 */
609 DECLR3CALLBACKMEMBER(bool, pfnAreValuesValid, (PVDCFGNODE pNode, const char *pszzValid));
610 DECLR3CALLBACKMEMBER(int, pfnQueryType, (PVDCFGNODE pNode, const char *pszName, PVDCFGVALUETYPE penmType));
611 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (PVDCFGNODE pNode, const char *pszName, size_t *pcb));
612 DECLR3CALLBACKMEMBER(int, pfnQueryInteger, (PVDCFGNODE pNode, const char *pszName, uint64_t *pu64));
613 DECLR3CALLBACKMEMBER(int, pfnQueryIntegerDef, (PVDCFGNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def));
614 DECLR3CALLBACKMEMBER(int, pfnQueryString, (PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString));
615 DECLR3CALLBACKMEMBER(int, pfnQueryStringDef, (PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef));
616 DECLR3CALLBACKMEMBER(int, pfnQueryBytes, (PVDCFGNODE pNode, const char *pszName, void *pvData, size_t cbData));
617} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
618
619/**
620 * Get configuration information interface from opaque callback table.
621 *
622 * @return Pointer to the callback table.
623 * @param pCallbacks Opaque interface pointer.
624 */
625DECLINLINE(PVDINTERFACECONFIG) VDGetInterfaceConfig(void *pCallbacks)
626{
627 PVDINTERFACECONFIG pInterfaceConfig = (PVDINTERFACECONFIG)pCallbacks;
628
629 /* Do basic checks. */
630 AssertMsgReturn( (pInterfaceConfig->cbSize == sizeof(VDINTERFACECONFIG))
631 && (pInterfaceConfig->enmInterface == VDINTERFACETYPE_CONFIG),
632 ("Not a configuration informaion interface\n"), NULL);
633
634 return pInterfaceConfig;
635}
636
637/**
638 * Query configuration, validates that the values are within a set of valid names.
639 *
640 * @returns true if all names are found in pszzAllowed.
641 * @returns false if not.
642 * @param pCfgIf Pointer to configuration callback table.
643 * @param pNode The node which values should be examined.
644 * @param pszzValid List of valid names separated by '\\0' and ending with
645 * a double '\\0'.
646 */
647DECLINLINE(bool) VDCFGAreValuesValid(PVDINTERFACECONFIG pCfgIf,
648 PVDCFGNODE pNode,
649 const char *pszzValid)
650{
651 return pCfgIf->pfnAreValuesValid(pNode, pszzValid);
652}
653
654/**
655 * Query configuration, unsigned 64-bit integer value with default.
656 *
657 * @return VBox status code.
658 * @param pCfgIf Pointer to configuration callback table.
659 * @param pNode Which node to search for pszName in.
660 * @param pszName Name of an integer value
661 * @param pu64 Where to store the value. Set to default on failure.
662 * @param u64Def The default value.
663 */
664DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,
665 const char *pszName, uint64_t *pu64,
666 uint64_t u64Def)
667{
668 return pCfgIf->pfnQueryIntegerDef(pNode, pszName, pu64, u64Def);
669}
670
671/**
672 * Query configuration, unsigned 32-bit integer value with default.
673 *
674 * @return VBox status code.
675 * @param pCfgIf Pointer to configuration callback table.
676 * @param pNode Which node to search for pszName in.
677 * @param pszName Name of an integer value
678 * @param pu32 Where to store the value. Set to default on failure.
679 * @param u32Def The default value.
680 */
681DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,
682 const char *pszName, uint32_t *pu32,
683 uint32_t u32Def)
684{
685 uint64_t u64;
686 int rc = pCfgIf->pfnQueryIntegerDef(pNode, pszName, &u64, u32Def);
687 if (VBOX_SUCCESS(rc))
688 {
689 if (!(u64 & UINT64_C(0xffffffff00000000)))
690 *pu32 = (uint32_t)u64;
691 else
692 rc = VERR_CFGM_INTEGER_TOO_BIG;
693 }
694 return rc;
695}
696
697/**
698 * Query configuration, bool value with default.
699 *
700 * @return VBox status code.
701 * @param pCfgIf Pointer to configuration callback table.
702 * @param pNode Which node to search for pszName in.
703 * @param pszName Name of an integer value
704 * @param pf Where to store the value. Set to default on failure.
705 * @param fDef The default value.
706 */
707DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,
708 const char *pszName, bool *pf,
709 bool fDef)
710{
711 uint64_t u64;
712 int rc = pCfgIf->pfnQueryIntegerDef(pNode, pszName, &u64, fDef);
713 if (VBOX_SUCCESS(rc))
714 *pf = u64 ? true : false;
715 return rc;
716}
717
718/**
719 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
720 * character value.
721 *
722 * @return VBox status code.
723 * @param pCfgIf Pointer to configuration callback table.
724 * @param pNode Which node to search for pszName in.
725 * @param pszName Name of an zero terminated character value
726 * @param ppszString Where to store the string pointer. Not set on failure.
727 * Free this using RTMemFree().
728 */
729DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
730 PVDCFGNODE pNode,
731 const char *pszName,
732 char **ppszString)
733{
734 size_t cch;
735 int rc = pCfgIf->pfnQuerySize(pNode, pszName, &cch);
736 if (VBOX_SUCCESS(rc))
737 {
738 char *pszString = (char *)RTMemAlloc(cch);
739 if (pszString)
740 {
741 rc = pCfgIf->pfnQueryString(pNode, pszName, pszString, cch);
742 if (VBOX_SUCCESS(rc))
743 *ppszString = pszString;
744 else
745 RTMemFree(pszString);
746 }
747 else
748 rc = VERR_NO_MEMORY;
749 }
750 return rc;
751}
752
753/**
754 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
755 * character value with default.
756 *
757 * @return VBox status code.
758 * @param pCfgIf Pointer to configuration callback table.
759 * @param pNode Which node to search for pszName in.
760 * @param pszName Name of an zero terminated character value
761 * @param ppszString Where to store the string pointer. Not set on failure.
762 * Free this using RTMemFree().
763 * @param pszDef The default value.
764 */
765DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
766 PVDCFGNODE pNode,
767 const char *pszName,
768 char **ppszString,
769 const char *pszDef)
770{
771 size_t cch;
772 int rc = pCfgIf->pfnQuerySize(pNode, pszName, &cch);
773 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
774 {
775 cch = strlen(pszDef) + 1;
776 rc = VINF_SUCCESS;
777 }
778 if (VBOX_SUCCESS(rc))
779 {
780 char *pszString = (char *)RTMemAlloc(cch);
781 if (pszString)
782 {
783 rc = pCfgIf->pfnQueryStringDef(pNode, pszName, pszString, cch, pszDef);
784 if (VBOX_SUCCESS(rc))
785 *ppszString = pszString;
786 else
787 RTMemFree(pszString);
788 }
789 else
790 rc = VERR_NO_MEMORY;
791 }
792 return rc;
793}
794
795/**
796 * Query configuration, dynamically allocated (RTMemAlloc) byte string value.
797 *
798 * @return VBox status code.
799 * @param pCfgIf Pointer to configuration callback table.
800 * @param pNode Which node to search for pszName in.
801 * @param pszName Name of an zero terminated character value
802 * @param ppvData Where to store the byte string pointer. Not set on failure.
803 * Free this using RTMemFree().
804 * @param pcbData Where to store the byte string length.
805 */
806DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
807 PVDCFGNODE pNode, const char *pszName,
808 void **ppvData, size_t *pcbData)
809{
810 size_t cb;
811 int rc = pCfgIf->pfnQuerySize(pNode, pszName, &cb);
812 if (VBOX_SUCCESS(rc))
813 {
814 char *pvData = (char *)RTMemAlloc(cb);
815 if (pvData)
816 {
817 rc = pCfgIf->pfnQueryBytes(pNode, pszName, pvData, cb);
818 if (VBOX_SUCCESS(rc))
819 {
820 *ppvData = pvData;
821 *pcbData = cb;
822 }
823 else
824 RTMemFree(pvData);
825 }
826 else
827 rc = VERR_NO_MEMORY;
828 }
829 return rc;
830}
831
832
833/**
834 * VBox HDD Container main structure.
835 */
836/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
837struct VBOXHDD;
838typedef struct VBOXHDD VBOXHDD;
839typedef VBOXHDD *PVBOXHDD;
840
841
842/**
843 * Lists all HDD backends and their capabilities in a caller-provided buffer.
844 * Free all returned names with RTStrFree() when you no longer need them.
845 *
846 * @return VBox status code.
847 * VERR_BUFFER_OVERFLOW if not enough space is passed.
848 * @param cEntriesAlloc Number of list entries available.
849 * @param pEntries Pointer to array for the entries.
850 * @param pcEntriesUsed Number of entries returned.
851 */
852VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
853 unsigned *pcEntriesUsed);
854
855/**
856 * Lists the capablities of a backend indentified by its name.
857 * Free all returned names with RTStrFree() when you no longer need them.
858 *
859 * @return VBox status code.
860 * @param pszBackend The backend name.
861 * @param pEntries Pointer to an entry.
862 */
863VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
864
865/**
866 * Allocates and initializes an empty HDD container.
867 * No image files are opened.
868 *
869 * @return VBox status code.
870 * @param pInterfaces Pointer to the first supported interface.
871 * @param ppDisk Where to store the reference to HDD container.
872 */
873VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pInterfaces, PVBOXHDD *ppDisk);
874
875/**
876 * Destroys HDD container.
877 * If container has opened image files they will be closed.
878 *
879 * @param pDisk Pointer to HDD container.
880 */
881VBOXDDU_DECL(void) VDDestroy(PVBOXHDD pDisk);
882
883/**
884 * Try to get the backend name which can use this image.
885 *
886 * @return VBox status code.
887 * @param pszFilename Name of the image file for which the backend is queried.
888 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
889 * The returned pointer must be freed using RTStrFree().
890 */
891VBOXDDU_DECL(int) VDGetFormat(const char *pszFilename, char **ppszFormat);
892
893/**
894 * Opens an image file.
895 *
896 * The first opened image file in HDD container must have a base image type,
897 * others (next opened images) must be differencing or undo images.
898 * Linkage is checked for differencing image to be consistent with the previously opened image.
899 * When another differencing image is opened and the last image was opened in read/write access
900 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
901 * other processes to use images in read-only mode too.
902 *
903 * Note that the image is opened in read-only mode if a read/write open is not possible.
904 * Use VDIsReadOnly to check open mode.
905 *
906 * @return VBox status code.
907 * @param pDisk Pointer to HDD container.
908 * @param pszBackend Name of the image file backend to use.
909 * @param pszFilename Name of the image file to open.
910 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
911 */
912VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
913 const char *pszFilename, unsigned uOpenFlags);
914
915/**
916 * Creates and opens a new base image file.
917 *
918 * @return VBox status code.
919 * @param pDisk Pointer to HDD container.
920 * @param pszBackend Name of the image file backend to use.
921 * @param pszFilename Name of the image file to create.
922 * @param enmType Image type, only base image types are acceptable.
923 * @param cbSize Image size in bytes.
924 * @param uImageFlags Flags specifying special image features.
925 * @param pszComment Pointer to image comment. NULL is ok.
926 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
927 * @param pLCHSGeometry Pointer to logical disk geometry <= (1024,255,63). Not NULL.
928 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
929 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
930 * @param pvUser User argument for the progress callback.
931 */
932VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
933 const char *pszFilename, VDIMAGETYPE enmType,
934 uint64_t cbSize, unsigned uImageFlags,
935 const char *pszComment,
936 PCPDMMEDIAGEOMETRY pPCHSGeometry,
937 PCPDMMEDIAGEOMETRY pLCHSGeometry,
938 unsigned uOpenFlags, PFNVMPROGRESS pfnProgress,
939 void *pvUser);
940
941/**
942 * Creates and opens a new differencing image file in HDD container.
943 * See comments for VDOpen function about differencing images.
944 *
945 * @return VBox status code.
946 * @param pDisk Pointer to HDD container.
947 * @param pszBackend Name of the image file backend to use.
948 * @param pszFilename Name of the differencing image file to create.
949 * @param uImageFlags Flags specifying special image features.
950 * @param pszComment Pointer to image comment. NULL is ok.
951 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
952 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
953 * @param pvUser User argument for the progress callback.
954 */
955VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
956 const char *pszFilename, unsigned uImageFlags,
957 const char *pszComment, unsigned uOpenFlags,
958 PFNVMPROGRESS pfnProgress, void *pvUser);
959
960/**
961 * Merges two images (not necessarily with direct parent/child relationship).
962 * As a side effect the source image and potentially the other images which
963 * are also merged to the destination are deleted from both the disk and the
964 * images in the HDD container.
965 *
966 * @return VBox status code.
967 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
968 * @param pDisk Pointer to HDD container.
969 * @param nImageFrom Name of the image file to merge from.
970 * @param nImageTo Name of the image file to merge to.
971 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
972 * @param pvUser User argument for the progress callback.
973 */
974VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
975 unsigned nImageTo, PFNVMPROGRESS pfnProgress,
976 void *pvUser);
977
978/**
979 * Copies an image from one HDD container to another.
980 * The copy is opened in the target HDD container.
981 * It is possible to convert between different image formats, because the
982 * backend for the destination may be different from the source.
983 * If both the source and destination reference the same HDD container,
984 * then the image is moved (by copying/deleting or renaming) to the new location.
985 * The source container is unchanged if the move operation fails, otherwise
986 * the image at the new location is opened in the same way as the old one was.
987 *
988 * @return VBox status code.
989 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
990 * @param pDiskFrom Pointer to source HDD container.
991 * @param nImage Image number, counts from 0. 0 is always base image of container.
992 * @param pDiskTo Pointer to destination HDD container.
993 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source).
994 * @param pszFilename New name of the image (may be NULL if pDiskFrom == pDiskTo).
995 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
996 * @param cbSize New image size (0 means leave unchanged).
997 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
998 * @param pvUser User argument for the progress callback.
999 */
1000VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
1001 const char *pszBackend, const char *pszFilename,
1002 bool fMoveByRename, uint64_t cbSize,
1003 PFNVMPROGRESS pfnProgress, void *pvUser);
1004
1005/**
1006 * Closes the last opened image file in HDD container.
1007 * If previous image file was opened in read-only mode (that is normal) and closing image
1008 * was opened in read-write mode (the whole disk was in read-write mode) - the previous image
1009 * will be reopened in read/write mode.
1010 *
1011 * @return VBox status code.
1012 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1013 * @param pDisk Pointer to HDD container.
1014 * @param fDelete If true, delete the image from the host disk.
1015 */
1016VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
1017
1018/**
1019 * Closes all opened image files in HDD container.
1020 *
1021 * @return VBox status code.
1022 * @param pDisk Pointer to HDD container.
1023 */
1024VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
1025
1026/**
1027 * Read data from virtual HDD.
1028 *
1029 * @return VBox status code.
1030 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1031 * @param pDisk Pointer to HDD container.
1032 * @param uOffset Offset of first reading byte from start of disk.
1033 * @param pvBuf Pointer to buffer for reading data.
1034 * @param cbRead Number of bytes to read.
1035 */
1036VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
1037
1038/**
1039 * Write data to virtual HDD.
1040 *
1041 * @return VBox status code.
1042 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1043 * @param pDisk Pointer to HDD container.
1044 * @param uOffset Offset of first writing byte from start of disk.
1045 * @param pvBuf Pointer to buffer for writing data.
1046 * @param cbWrite Number of bytes to write.
1047 */
1048VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
1049
1050/**
1051 * Make sure the on disk representation of a virtual HDD is up to date.
1052 *
1053 * @return VBox status code.
1054 * @return VERR_VDI_NOT_OPENED if no image is opened in HDD container.
1055 * @param pDisk Pointer to HDD container.
1056 */
1057VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
1058
1059/**
1060 * Get number of opened images in HDD container.
1061 *
1062 * @return Number of opened images for HDD container. 0 if no images have been opened.
1063 * @param pDisk Pointer to HDD container.
1064 */
1065VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
1066
1067/**
1068 * Get read/write mode of HDD container.
1069 *
1070 * @return Virtual disk ReadOnly status.
1071 * @return true if no image is opened in HDD container.
1072 * @param pDisk Pointer to HDD container.
1073 */
1074VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
1075
1076/**
1077 * Get total capacity of an image in HDD container.
1078 *
1079 * @return Virtual disk size in bytes.
1080 * @return 0 if image with specified number was not opened.
1081 * @param pDisk Pointer to HDD container.
1082 * @param nImage Image number, counts from 0. 0 is always base image of container.
1083 */
1084VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
1085
1086/**
1087 * Get total file size of an image in HDD container.
1088 *
1089 * @return Virtual disk size in bytes.
1090 * @return 0 if image with specified number was not opened.
1091 * @param pDisk Pointer to HDD container.
1092 * @param nImage Image number, counts from 0. 0 is always base image of container.
1093 */
1094VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
1095
1096/**
1097 * Get virtual disk PCHS geometry of an image in HDD container.
1098 *
1099 * @return VBox status code.
1100 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1101 * @return VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1102 * @param pDisk Pointer to HDD container.
1103 * @param nImage Image number, counts from 0. 0 is always base image of container.
1104 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1105 */
1106VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1107 PPDMMEDIAGEOMETRY pPCHSGeometry);
1108
1109/**
1110 * Store virtual disk PCHS geometry of an image in HDD container.
1111 *
1112 * @return VBox status code.
1113 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1114 * @param pDisk Pointer to HDD container.
1115 * @param nImage Image number, counts from 0. 0 is always base image of container.
1116 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1117 */
1118VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1119 PCPDMMEDIAGEOMETRY pPCHSGeometry);
1120
1121/**
1122 * Get virtual disk LCHS geometry of an image in HDD container.
1123 *
1124 * @return VBox status code.
1125 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1126 * @return VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1127 * @param pDisk Pointer to HDD container.
1128 * @param nImage Image number, counts from 0. 0 is always base image of container.
1129 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1130 */
1131VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1132 PPDMMEDIAGEOMETRY pLCHSGeometry);
1133
1134/**
1135 * Store virtual disk LCHS geometry of an image in HDD container.
1136 *
1137 * @return VBox status code.
1138 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1139 * @param pDisk Pointer to HDD container.
1140 * @param nImage Image number, counts from 0. 0 is always base image of container.
1141 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1142 */
1143VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1144 PCPDMMEDIAGEOMETRY pLCHSGeometry);
1145
1146/**
1147 * Get version of image in HDD container.
1148 *
1149 * @return VBox status code.
1150 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1151 * @param pDisk Pointer to HDD container.
1152 * @param nImage Image number, counts from 0. 0 is always base image of container.
1153 * @param puVersion Where to store the image version.
1154 */
1155VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
1156 unsigned *puVersion);
1157
1158/**
1159 * Get type of image in HDD container.
1160 *
1161 * @return VBox status code.
1162 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1163 * @param pDisk Pointer to HDD container.
1164 * @param nImage Image number, counts from 0. 0 is always base image of container.
1165 * @param penmType Where to store the image type.
1166 */
1167VBOXDDU_DECL(int) VDGetImageType(PVBOXHDD pDisk, unsigned nImage,
1168 PVDIMAGETYPE penmType);
1169
1170/**
1171 * List the capabilities of image backend in HDD container.
1172 *
1173 * @return VBox status code.
1174 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1175 * @param pDisk Pointer to the HDD container.
1176 * @param nImage Image number, counts from 0. 0 is always base image of container.
1177 * @param pbackendInfo Where to store the backend information.
1178 */
1179VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
1180 PVDBACKENDINFO pBackendInfo);
1181
1182/**
1183 * Get flags of image in HDD container.
1184 *
1185 * @return VBox status code.
1186 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1187 * @param pDisk Pointer to HDD container.
1188 * @param nImage Image number, counts from 0. 0 is always base image of container.
1189 * @param puImageFlags Where to store the image flags.
1190 */
1191VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
1192
1193/**
1194 * Get open flags of image in HDD container.
1195 *
1196 * @return VBox status code.
1197 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1198 * @param pDisk Pointer to HDD container.
1199 * @param nImage Image number, counts from 0. 0 is always base image of container.
1200 * @param puOpenFlags Where to store the image open flags.
1201 */
1202VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1203 unsigned *puOpenFlags);
1204
1205/**
1206 * Set open flags of image in HDD container.
1207 * This operation may cause file locking changes and/or files being reopened.
1208 * Note that in case of unrecoverable error all images in HDD container will be closed.
1209 *
1210 * @return VBox status code.
1211 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1212 * @param pDisk Pointer to HDD container.
1213 * @param nImage Image number, counts from 0. 0 is always base image of container.
1214 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1215 */
1216VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1217 unsigned uOpenFlags);
1218
1219/**
1220 * Get base filename of image in HDD container. Some image formats use
1221 * other filenames as well, so don't use this for anything but informational
1222 * purposes.
1223 *
1224 * @return VBox status code.
1225 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1226 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1227 * @param pDisk Pointer to HDD container.
1228 * @param nImage Image number, counts from 0. 0 is always base image of container.
1229 * @param pszFilename Where to store the image file name.
1230 * @param cbFilename Size of buffer pszFilename points to.
1231 */
1232VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
1233 char *pszFilename, unsigned cbFilename);
1234
1235/**
1236 * Get the comment line of image in HDD container.
1237 *
1238 * @return VBox status code.
1239 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1240 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1241 * @param pDisk Pointer to HDD container.
1242 * @param nImage Image number, counts from 0. 0 is always base image of container.
1243 * @param pszComment Where to store the comment string of image. NULL is ok.
1244 * @param cbComment The size of pszComment buffer. 0 is ok.
1245 */
1246VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
1247 char *pszComment, unsigned cbComment);
1248
1249/**
1250 * Changes the comment line of image in HDD container.
1251 *
1252 * @return VBox status code.
1253 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1254 * @param pDisk Pointer to HDD container.
1255 * @param nImage Image number, counts from 0. 0 is always base image of container.
1256 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1257 */
1258VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
1259 const char *pszComment);
1260
1261/**
1262 * Get UUID of image in HDD container.
1263 *
1264 * @return VBox status code.
1265 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1266 * @param pDisk Pointer to HDD container.
1267 * @param nImage Image number, counts from 0. 0 is always base image of container.
1268 * @param pUuid Where to store the image UUID.
1269 */
1270VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1271
1272/**
1273 * Set the image's UUID. Should not be used by normal applications.
1274 *
1275 * @return VBox status code.
1276 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1277 * @param pDisk Pointer to HDD container.
1278 * @param nImage Image number, counts from 0. 0 is always base image of container.
1279 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1280 */
1281VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1282
1283/**
1284 * Get last modification UUID of image in HDD container.
1285 *
1286 * @return VBox status code.
1287 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1288 * @param pDisk Pointer to HDD container.
1289 * @param nImage Image number, counts from 0. 0 is always base image of container.
1290 * @param pUuid Where to store the image modification UUID.
1291 */
1292VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1293 PRTUUID pUuid);
1294
1295/**
1296 * Set the image's last modification UUID. Should not be used by normal applications.
1297 *
1298 * @return VBox status code.
1299 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1300 * @param pDisk Pointer to HDD container.
1301 * @param nImage Image number, counts from 0. 0 is always base image of container.
1302 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1303 */
1304VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1305 PCRTUUID pUuid);
1306
1307/**
1308 * Get parent UUID of image in HDD container.
1309 *
1310 * @return VBox status code.
1311 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1312 * @param pDisk Pointer to HDD container.
1313 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1314 * @param pUuid Where to store the parent image UUID.
1315 */
1316VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1317 PRTUUID pUuid);
1318
1319/**
1320 * Set the image's parent UUID. Should not be used by normal applications.
1321 *
1322 * @return VBox status code.
1323 * @param pDisk Pointer to HDD container.
1324 * @param nImage Image number, counts from 0. 0 is always base image of container.
1325 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1326 */
1327VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1328 PCRTUUID pUuid);
1329
1330
1331/**
1332 * Debug helper - dumps all opened images in HDD container into the log file.
1333 *
1334 * @param pDisk Pointer to HDD container.
1335 */
1336VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
1337
1338
1339/**
1340 * Query if asynchronous operations are supported for this disk.
1341 *
1342 * @return VBox status code.
1343 * @return VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
1344 * @param pDisk Pointer to the HDD container.
1345 * @param nImage Image number, counts from 0. 0 is always base image of container.
1346 * @param pfAIOSupported Where to store if async IO is supported.
1347 */
1348VBOXDDU_DECL(int) VDImageIsAsyncIOSupported(PVBOXHDD pDisk, unsigned nImage, bool *pfAIOSupported);
1349
1350
1351/**
1352 * Start a asynchronous read request.
1353 *
1354 * @return VBox status code.
1355 * @param pDisk Pointer to the HDD container.
1356 * @param uOffset The offset of the virtual disk to read from.
1357 * @param cbRead How many bytes to read.
1358 * @param paSeg Pointer to an array of segments.
1359 * @param cSeg Number of segments in the array.
1360 * @param pvUser User data which is passed on completion
1361 */
1362VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
1363 PPDMDATASEG paSeg, unsigned cSeg,
1364 void *pvUser);
1365
1366
1367/**
1368 * Start a asynchronous write request.
1369 *
1370 * @return VBox status code.
1371 * @param pDisk Pointer to the HDD container.
1372 * @param uOffset The offset of the virtual disk to write to.
1373 * @param cbWrtie How many bytes to write.
1374 * @param paSeg Pointer to an array of segments.
1375 * @param cSeg Number of segments in the array.
1376 * @param pvUser User data which is passed on completion.
1377 */
1378VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
1379 PPDMDATASEG paSeg, unsigned cSeg,
1380 void *pvUser);
1381
1382
1383__END_DECLS
1384
1385/** @} */
1386
1387#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