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