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