VirtualBox

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

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

VBoxHDD-new: VDGetInterface* has a pointer to the interface descriptor now instead of the opaque pointer to the callback table - better type checking during compilation which reduces mistakes

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