VirtualBox

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

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

Storage/VBoxHDD-new: introduced VD interfaces per image and per operation, completely unifying callback handling.

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