VirtualBox

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

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

Devices/Storage: iSCSI stuff, including bringing IntNet support back to life. Should build, but otherwise untested.

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