VirtualBox

source: vbox/trunk/include/VBox/vd-ifs.h@ 47560

Last change on this file since 47560 was 47349, checked in by vboxsync, 12 years ago

Added VDIfCreateVfsStream for OVA importing/exporting - completely untested.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.9 KB
Line 
1/** @file
2 * VD Container API - interfaces.
3 */
4
5/*
6 * Copyright (C) 2011-2012 Oracle Corporation
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
26#ifndef ___VBox_VD_Interfaces_h
27#define ___VBox_VD_Interfaces_h
28
29#include <iprt/assert.h>
30#include <iprt/string.h>
31#include <iprt/mem.h>
32#include <iprt/file.h>
33#include <iprt/net.h>
34#include <iprt/sg.h>
35#include <VBox/cdefs.h>
36#include <VBox/types.h>
37#include <VBox/err.h>
38
39RT_C_DECLS_BEGIN
40
41/** Interface header magic. */
42#define VDINTERFACE_MAGIC UINT32_C(0x19701015)
43
44/**
45 * Supported interface types.
46 */
47typedef enum VDINTERFACETYPE
48{
49 /** First valid interface. */
50 VDINTERFACETYPE_FIRST = 0,
51 /** Interface to pass error message to upper layers. Per-disk. */
52 VDINTERFACETYPE_ERROR = VDINTERFACETYPE_FIRST,
53 /** Interface for I/O operations. Per-image. */
54 VDINTERFACETYPE_IO,
55 /** Interface for progress notification. Per-operation. */
56 VDINTERFACETYPE_PROGRESS,
57 /** Interface for configuration information. Per-image. */
58 VDINTERFACETYPE_CONFIG,
59 /** Interface for TCP network stack. Per-image. */
60 VDINTERFACETYPE_TCPNET,
61 /** Interface for getting parent image state. Per-operation. */
62 VDINTERFACETYPE_PARENTSTATE,
63 /** Interface for synchronizing accesses from several threads. Per-disk. */
64 VDINTERFACETYPE_THREADSYNC,
65 /** Interface for I/O between the generic VBoxHDD code and the backend. Per-image (internal).
66 * This interface is completely internal and must not be used elsewhere. */
67 VDINTERFACETYPE_IOINT,
68 /** Interface to query the use of block ranges on the disk. Per-operation. */
69 VDINTERFACETYPE_QUERYRANGEUSE,
70 /** invalid interface. */
71 VDINTERFACETYPE_INVALID
72} VDINTERFACETYPE;
73
74/**
75 * Common structure for all interfaces and at the beginning of all types.
76 */
77typedef struct VDINTERFACE
78{
79 uint32_t u32Magic;
80 /** Human readable interface name. */
81 const char *pszInterfaceName;
82 /** Pointer to the next common interface structure. */
83 struct VDINTERFACE *pNext;
84 /** Interface type. */
85 VDINTERFACETYPE enmInterface;
86 /** Size of the interface. */
87 size_t cbSize;
88 /** Opaque user data which is passed on every call. */
89 void *pvUser;
90} VDINTERFACE;
91/** Pointer to a VDINTERFACE. */
92typedef VDINTERFACE *PVDINTERFACE;
93/** Pointer to a const VDINTERFACE. */
94typedef const VDINTERFACE *PCVDINTERFACE;
95
96/**
97 * Helper functions to handle interface lists.
98 *
99 * @note These interface lists are used consistently to pass per-disk,
100 * per-image and/or per-operation callbacks. Those three purposes are strictly
101 * separate. See the individual interface declarations for what context they
102 * apply to. The caller is responsible for ensuring that the lifetime of the
103 * interface descriptors is appropriate for the category of interface.
104 */
105
106/**
107 * Get a specific interface from a list of interfaces specified by the type.
108 *
109 * @return Pointer to the matching interface or NULL if none was found.
110 * @param pVDIfs Pointer to the VD interface list.
111 * @param enmInterface Interface to search for.
112 */
113DECLINLINE(PVDINTERFACE) VDInterfaceGet(PVDINTERFACE pVDIfs, VDINTERFACETYPE enmInterface)
114{
115 AssertMsgReturn( enmInterface >= VDINTERFACETYPE_FIRST
116 && enmInterface < VDINTERFACETYPE_INVALID,
117 ("enmInterface=%u", enmInterface), NULL);
118
119 while (pVDIfs)
120 {
121 AssertMsgBreak(pVDIfs->u32Magic == VDINTERFACE_MAGIC,
122 ("u32Magic=%#x\n", pVDIfs->u32Magic));
123
124 if (pVDIfs->enmInterface == enmInterface)
125 return pVDIfs;
126 pVDIfs = pVDIfs->pNext;
127 }
128
129 /* No matching interface was found. */
130 return NULL;
131}
132
133/**
134 * Add an interface to a list of interfaces.
135 *
136 * @return VBox status code.
137 * @param pInterface Pointer to an unitialized common interface structure.
138 * @param pszName Name of the interface.
139 * @param enmInterface Type of the interface.
140 * @param pvUser Opaque user data passed on every function call.
141 * @param ppVDIfs Pointer to the VD interface list.
142 */
143DECLINLINE(int) VDInterfaceAdd(PVDINTERFACE pInterface, const char *pszName,
144 VDINTERFACETYPE enmInterface, void *pvUser,
145 size_t cbInterface, PVDINTERFACE *ppVDIfs)
146{
147 /* Argument checks. */
148 AssertMsgReturn( enmInterface >= VDINTERFACETYPE_FIRST
149 && enmInterface < VDINTERFACETYPE_INVALID,
150 ("enmInterface=%u", enmInterface), VERR_INVALID_PARAMETER);
151
152 AssertMsgReturn(VALID_PTR(ppVDIfs),
153 ("pInterfaceList=%#p", ppVDIfs),
154 VERR_INVALID_PARAMETER);
155
156 /* Fill out interface descriptor. */
157 pInterface->u32Magic = VDINTERFACE_MAGIC;
158 pInterface->cbSize = cbInterface;
159 pInterface->pszInterfaceName = pszName;
160 pInterface->enmInterface = enmInterface;
161 pInterface->pvUser = pvUser;
162 pInterface->pNext = *ppVDIfs;
163
164 /* Remember the new start of the list. */
165 *ppVDIfs = pInterface;
166
167 return VINF_SUCCESS;
168}
169
170/**
171 * Removes an interface from a list of interfaces.
172 *
173 * @return VBox status code
174 * @param pInterface Pointer to an initialized common interface structure to remove.
175 * @param ppVDIfs Pointer to the VD interface list to remove from.
176 */
177DECLINLINE(int) VDInterfaceRemove(PVDINTERFACE pInterface, PVDINTERFACE *ppVDIfs)
178{
179 int rc = VERR_NOT_FOUND;
180
181 /* Argument checks. */
182 AssertMsgReturn(VALID_PTR(pInterface),
183 ("pInterface=%#p", pInterface),
184 VERR_INVALID_PARAMETER);
185
186 AssertMsgReturn(VALID_PTR(ppVDIfs),
187 ("pInterfaceList=%#p", ppVDIfs),
188 VERR_INVALID_PARAMETER);
189
190 if (*ppVDIfs)
191 {
192 PVDINTERFACE pPrev = NULL;
193 PVDINTERFACE pCurr = *ppVDIfs;
194
195 while ( pCurr
196 && (pCurr != pInterface))
197 {
198 pPrev = pCurr;
199 pCurr = pCurr->pNext;
200 }
201
202 /* First interface */
203 if (!pPrev)
204 {
205 *ppVDIfs = pCurr->pNext;
206 rc = VINF_SUCCESS;
207 }
208 else if (pCurr)
209 {
210 pPrev = pCurr->pNext;
211 rc = VINF_SUCCESS;
212 }
213 }
214
215 return rc;
216}
217
218/**
219 * Interface to deliver error messages (and also informational messages)
220 * to upper layers.
221 *
222 * Per-disk interface. Optional, but think twice if you want to miss the
223 * opportunity of reporting better human-readable error messages.
224 */
225typedef struct VDINTERFACEERROR
226{
227 /**
228 * Common interface header.
229 */
230 VDINTERFACE Core;
231
232 /**
233 * Error message callback. Must be able to accept special IPRT format
234 * strings.
235 *
236 * @param pvUser The opaque data passed on container creation.
237 * @param rc The VBox error code.
238 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
239 * @param pszFormat Error message format string.
240 * @param va Error message arguments.
241 */
242 DECLR3CALLBACKMEMBER(void, pfnError, (void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
243
244 /**
245 * Informational message callback. May be NULL. Used e.g. in
246 * VDDumpImages(). Must be able to accept special IPRT format strings.
247 *
248 * @return VBox status code.
249 * @param pvUser The opaque data passed on container creation.
250 * @param pszFormat Message format string.
251 * @param va Message arguments.
252 */
253 DECLR3CALLBACKMEMBER(int, pfnMessage, (void *pvUser, const char *pszFormat, va_list va));
254
255} VDINTERFACEERROR, *PVDINTERFACEERROR;
256
257/**
258 * Get error interface from interface list.
259 *
260 * @return Pointer to the first error interface in the list.
261 * @param pVDIfs Pointer to the interface list.
262 */
263DECLINLINE(PVDINTERFACEERROR) VDIfErrorGet(PVDINTERFACE pVDIfs)
264{
265 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_ERROR);
266
267 /* Check that the interface descriptor is a progress interface. */
268 AssertMsgReturn( !pIf
269 || ( (pIf->enmInterface == VDINTERFACETYPE_ERROR)
270 && (pIf->cbSize == sizeof(VDINTERFACEERROR))),
271 ("Not an error interface\n"), NULL);
272
273 return (PVDINTERFACEERROR)pIf;
274}
275
276/**
277 * Signal an error to the frontend.
278 *
279 * @returns VBox status code.
280 * @param pIfError The error interface.
281 * @param rc The status code.
282 * @param RT_SRC_POS_DECL The position in the source code.
283 * @param pszFormat The format string to pass.
284 * @param ... Arguments to the format string.
285 */
286DECLINLINE(int) vdIfError(PVDINTERFACEERROR pIfError, int rc, RT_SRC_POS_DECL,
287 const char *pszFormat, ...)
288{
289 va_list va;
290 va_start(va, pszFormat);
291 if (pIfError)
292 pIfError->pfnError(pIfError->Core.pvUser, rc, RT_SRC_POS_ARGS, pszFormat, va);
293 va_end(va);
294 return rc;
295}
296
297/**
298 * Signal an informational message to the frontend.
299 *
300 * @returns VBox status code.
301 * @param pIfError The error interface.
302 * @param pszFormat The format string to pass.
303 * @param ... Arguments to the format string.
304 */
305DECLINLINE(int) vdIfErrorMessage(PVDINTERFACEERROR pIfError, const char *pszFormat, ...)
306{
307 int rc = VINF_SUCCESS;
308 va_list va;
309 va_start(va, pszFormat);
310 if (pIfError && pIfError->pfnMessage)
311 rc = pIfError->pfnMessage(pIfError->Core.pvUser, pszFormat, va);
312 va_end(va);
313 return rc;
314}
315
316/**
317 * Completion callback which is called by the interface owner
318 * to inform the backend that a task finished.
319 *
320 * @return VBox status code.
321 * @param pvUser Opaque user data which is passed on request submission.
322 * @param rcReq Status code of the completed request.
323 */
324typedef DECLCALLBACK(int) FNVDCOMPLETED(void *pvUser, int rcReq);
325/** Pointer to FNVDCOMPLETED() */
326typedef FNVDCOMPLETED *PFNVDCOMPLETED;
327
328/**
329 * Support interface for I/O
330 *
331 * Per-image. Optional as input.
332 */
333typedef struct VDINTERFACEIO
334{
335 /**
336 * Common interface header.
337 */
338 VDINTERFACE Core;
339
340 /**
341 * Open callback
342 *
343 * @return VBox status code.
344 * @param pvUser The opaque data passed on container creation.
345 * @param pszLocation Name of the location to open.
346 * @param fOpen Flags for opening the backend.
347 * See RTFILE_O_* #defines, inventing another set
348 * of open flags is not worth the mapping effort.
349 * @param pfnCompleted The callback which is called whenever a task
350 * completed. The backend has to pass the user data
351 * of the request initiator (ie the one who calls
352 * VDAsyncRead or VDAsyncWrite) in pvCompletion
353 * if this is NULL.
354 * @param ppStorage Where to store the opaque storage handle.
355 */
356 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation,
357 uint32_t fOpen,
358 PFNVDCOMPLETED pfnCompleted,
359 void **ppStorage));
360
361 /**
362 * Close callback.
363 *
364 * @return VBox status code.
365 * @param pvUser The opaque data passed on container creation.
366 * @param pStorage The opaque storage handle to close.
367 */
368 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, void *pStorage));
369
370 /**
371 * Delete callback.
372 *
373 * @return VBox status code.
374 * @param pvUser The opaque data passed on container creation.
375 * @param pcszFilename Name of the file to delete.
376 */
377 DECLR3CALLBACKMEMBER(int, pfnDelete, (void *pvUser, const char *pcszFilename));
378
379 /**
380 * Move callback.
381 *
382 * @return VBox status code.
383 * @param pvUser The opaque data passed on container creation.
384 * @param pcszSrc The path to the source file.
385 * @param pcszDst The path to the destination file.
386 * This file will be created.
387 * @param fMove A combination of the RTFILEMOVE_* flags.
388 */
389 DECLR3CALLBACKMEMBER(int, pfnMove, (void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned fMove));
390
391 /**
392 * Returns the free space on a disk.
393 *
394 * @return VBox status code.
395 * @param pvUser The opaque data passed on container creation.
396 * @param pcszFilename Name of a file to identify the disk.
397 * @param pcbFreeSpace Where to store the free space of the disk.
398 */
399 DECLR3CALLBACKMEMBER(int, pfnGetFreeSpace, (void *pvUser, const char *pcszFilename, int64_t *pcbFreeSpace));
400
401 /**
402 * Returns the last modification timestamp of a file.
403 *
404 * @return VBox status code.
405 * @param pvUser The opaque data passed on container creation.
406 * @param pcszFilename Name of a file to identify the disk.
407 * @param pModificationTime Where to store the timestamp of the file.
408 */
409 DECLR3CALLBACKMEMBER(int, pfnGetModificationTime, (void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime));
410
411 /**
412 * Returns the size of the opened storage backend.
413 *
414 * @return VBox status code.
415 * @param pvUser The opaque data passed on container creation.
416 * @param pStorage The opaque storage handle to close.
417 * @param pcbSize Where to store the size of the storage backend.
418 */
419 DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, void *pStorage, uint64_t *pcbSize));
420
421 /**
422 * Sets the size of the opened storage backend if possible.
423 *
424 * @return VBox status code.
425 * @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
426 * @param pvUser The opaque data passed on container creation.
427 * @param pStorage The opaque storage handle to close.
428 * @param cbSize The new size of the image.
429 */
430 DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, void *pStorage, uint64_t cbSize));
431
432 /**
433 * Synchronous write callback.
434 *
435 * @return VBox status code.
436 * @param pvUser The opaque data passed on container creation.
437 * @param pStorage The storage handle to use.
438 * @param uOffset The offset to start from.
439 * @param pvBuffer Pointer to the bits need to be written.
440 * @param cbBuffer How many bytes to write.
441 * @param pcbWritten Where to store how many bytes were actually written.
442 */
443 DECLR3CALLBACKMEMBER(int, pfnWriteSync, (void *pvUser, void *pStorage, uint64_t uOffset,
444 const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten));
445
446 /**
447 * Synchronous read callback.
448 *
449 * @return VBox status code.
450 * @param pvUser The opaque data passed on container creation.
451 * @param pStorage The storage handle to use.
452 * @param uOffset The offset to start from.
453 * @param pvBuffer Where to store the read bits.
454 * @param cbBuffer How many bytes to read.
455 * @param pcbRead Where to store how many bytes were actually read.
456 */
457 DECLR3CALLBACKMEMBER(int, pfnReadSync, (void *pvUser, void *pStorage, uint64_t uOffset,
458 void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
459
460 /**
461 * Flush data to the storage backend.
462 *
463 * @return VBox status code.
464 * @param pvUser The opaque data passed on container creation.
465 * @param pStorage The storage handle to flush.
466 */
467 DECLR3CALLBACKMEMBER(int, pfnFlushSync, (void *pvUser, void *pStorage));
468
469 /**
470 * Initiate an asynchronous read request.
471 *
472 * @return VBox status code.
473 * @param pvUser The opaque user data passed on container creation.
474 * @param pStorage The storage handle.
475 * @param uOffset The offset to start reading from.
476 * @param paSegments Scatter gather list to store the data in.
477 * @param cSegments Number of segments in the list.
478 * @param cbRead How many bytes to read.
479 * @param pvCompletion The opaque user data which is returned upon completion.
480 * @param ppTask Where to store the opaque task handle.
481 */
482 DECLR3CALLBACKMEMBER(int, pfnReadAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
483 PCRTSGSEG paSegments, size_t cSegments,
484 size_t cbRead, void *pvCompletion,
485 void **ppTask));
486
487 /**
488 * Initiate an asynchronous write request.
489 *
490 * @return VBox status code.
491 * @param pvUser The opaque user data passed on conatiner creation.
492 * @param pStorage The storage handle.
493 * @param uOffset The offset to start writing to.
494 * @param paSegments Scatter gather list of the data to write
495 * @param cSegments Number of segments in the list.
496 * @param cbWrite How many bytes to write.
497 * @param pvCompletion The opaque user data which is returned upon completion.
498 * @param ppTask Where to store the opaque task handle.
499 */
500 DECLR3CALLBACKMEMBER(int, pfnWriteAsync, (void *pvUser, void *pStorage, uint64_t uOffset,
501 PCRTSGSEG paSegments, size_t cSegments,
502 size_t cbWrite, void *pvCompletion,
503 void **ppTask));
504
505 /**
506 * Initiates an async flush request.
507 *
508 * @return VBox status code.
509 * @param pvUser The opaque data passed on container creation.
510 * @param pStorage The storage handle to flush.
511 * @param pvCompletion The opaque user data which is returned upon completion.
512 * @param ppTask Where to store the opaque task handle.
513 */
514 DECLR3CALLBACKMEMBER(int, pfnFlushAsync, (void *pvUser, void *pStorage,
515 void *pvCompletion, void **ppTask));
516
517} VDINTERFACEIO, *PVDINTERFACEIO;
518
519/**
520 * Get I/O interface from interface list.
521 *
522 * @return Pointer to the first I/O interface in the list.
523 * @param pVDIfs Pointer to the interface list.
524 */
525DECLINLINE(PVDINTERFACEIO) VDIfIoGet(PVDINTERFACE pVDIfs)
526{
527 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_IO);
528
529 /* Check that the interface descriptor is a progress interface. */
530 AssertMsgReturn( !pIf
531 || ( (pIf->enmInterface == VDINTERFACETYPE_IO)
532 && (pIf->cbSize == sizeof(VDINTERFACEIO))),
533 ("Not a I/O interface"), NULL);
534
535 return (PVDINTERFACEIO)pIf;
536}
537
538DECLINLINE(int) vdIfIoFileOpen(PVDINTERFACEIO pIfIo, const char *pszFilename,
539 uint32_t fOpen, PFNVDCOMPLETED pfnCompleted,
540 void **ppStorage)
541{
542 return pIfIo->pfnOpen(pIfIo->Core.pvUser, pszFilename, fOpen, pfnCompleted, ppStorage);
543}
544
545DECLINLINE(int) vdIfIoFileClose(PVDINTERFACEIO pIfIo, void *pStorage)
546{
547 return pIfIo->pfnClose(pIfIo->Core.pvUser, pStorage);
548}
549
550DECLINLINE(int) vdIfIoFileDelete(PVDINTERFACEIO pIfIo, const char *pszFilename)
551{
552 return pIfIo->pfnDelete(pIfIo->Core.pvUser, pszFilename);
553}
554
555DECLINLINE(int) vdIfIoFileMove(PVDINTERFACEIO pIfIo, const char *pszSrc,
556 const char *pszDst, unsigned fMove)
557{
558 return pIfIo->pfnMove(pIfIo->Core.pvUser, pszSrc, pszDst, fMove);
559}
560
561DECLINLINE(int) vdIfIoFileGetFreeSpace(PVDINTERFACEIO pIfIo, const char *pszFilename,
562 int64_t *pcbFree)
563{
564 return pIfIo->pfnGetFreeSpace(pIfIo->Core.pvUser, pszFilename, pcbFree);
565}
566
567DECLINLINE(int) vdIfIoFileGetModificationTime(PVDINTERFACEIO pIfIo, const char *pcszFilename,
568 PRTTIMESPEC pModificationTime)
569{
570 return pIfIo->pfnGetModificationTime(pIfIo->Core.pvUser, pcszFilename,
571 pModificationTime);
572}
573
574DECLINLINE(int) vdIfIoFileGetSize(PVDINTERFACEIO pIfIo, void *pStorage,
575 uint64_t *pcbSize)
576{
577 return pIfIo->pfnGetSize(pIfIo->Core.pvUser, pStorage, pcbSize);
578}
579
580DECLINLINE(int) vdIfIoFileSetSize(PVDINTERFACEIO pIfIo, void *pStorage,
581 uint64_t cbSize)
582{
583 return pIfIo->pfnSetSize(pIfIo->Core.pvUser, pStorage, cbSize);
584}
585
586DECLINLINE(int) vdIfIoFileWriteSync(PVDINTERFACEIO pIfIo, void *pStorage,
587 uint64_t uOffset, const void *pvBuffer, size_t cbBuffer,
588 size_t *pcbWritten)
589{
590 return pIfIo->pfnWriteSync(pIfIo->Core.pvUser, pStorage, uOffset,
591 pvBuffer, cbBuffer, pcbWritten);
592}
593
594DECLINLINE(int) vdIfIoFileReadSync(PVDINTERFACEIO pIfIo, void *pStorage,
595 uint64_t uOffset, void *pvBuffer, size_t cbBuffer,
596 size_t *pcbRead)
597{
598 return pIfIo->pfnReadSync(pIfIo->Core.pvUser, pStorage, uOffset,
599 pvBuffer, cbBuffer, pcbRead);
600}
601
602DECLINLINE(int) vdIfIoFileFlushSync(PVDINTERFACEIO pIfIo, void *pStorage)
603{
604 return pIfIo->pfnFlushSync(pIfIo->Core.pvUser, pStorage);
605}
606
607/**
608 * Create a VFS stream handle around a VD I/O interface.
609 *
610 * The I/O interface will not be closed or free by the stream, the caller will
611 * do so after it is done with the stream and has released the instances of the
612 * I/O stream object returned by this API.
613 *
614 * @return VBox status code.
615 * @param pVDIfsIo Pointer to the VD I/O interface.
616 * @param pvStorage The storage argument to pass to the interface
617 * methods.
618 * @param fFlags RTFILE_O_XXX, access mask requied.
619 * @param phVfsIos Where to return the VFS I/O stream handle on
620 * success.
621 */
622VBOXDDU_DECL(int) VDIfCreateVfsStream(PVDINTERFACEIO pVDIfsIo, void *pvStorage, uint32_t fFlags, PRTVFSIOSTREAM phVfsIos);
623
624
625/**
626 * Callback which provides progress information about a currently running
627 * lengthy operation.
628 *
629 * @return VBox status code.
630 * @param pvUser The opaque user data associated with this interface.
631 * @param uPercent Completion percentage.
632 */
633typedef DECLCALLBACK(int) FNVDPROGRESS(void *pvUser, unsigned uPercentage);
634/** Pointer to FNVDPROGRESS() */
635typedef FNVDPROGRESS *PFNVDPROGRESS;
636
637/**
638 * Progress notification interface
639 *
640 * Per-operation. Optional.
641 */
642typedef struct VDINTERFACEPROGRESS
643{
644 /**
645 * Common interface header.
646 */
647 VDINTERFACE Core;
648
649 /**
650 * Progress notification callbacks.
651 */
652 PFNVDPROGRESS pfnProgress;
653
654} VDINTERFACEPROGRESS, *PVDINTERFACEPROGRESS;
655
656/**
657 * Get progress interface from interface list.
658 *
659 * @return Pointer to the first progress interface in the list.
660 * @param pVDIfs Pointer to the interface list.
661 */
662DECLINLINE(PVDINTERFACEPROGRESS) VDIfProgressGet(PVDINTERFACE pVDIfs)
663{
664 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_PROGRESS);
665
666 /* Check that the interface descriptor is a progress interface. */
667 AssertMsgReturn( !pIf
668 || ( (pIf->enmInterface == VDINTERFACETYPE_PROGRESS)
669 && (pIf->cbSize == sizeof(VDINTERFACEPROGRESS))),
670 ("Not a progress interface"), NULL);
671
672 return (PVDINTERFACEPROGRESS)pIf;
673}
674
675
676/**
677 * Configuration information interface
678 *
679 * Per-image. Optional for most backends, but mandatory for images which do
680 * not operate on files (including standard block or character devices).
681 */
682typedef struct VDINTERFACECONFIG
683{
684 /**
685 * Common interface header.
686 */
687 VDINTERFACE Core;
688
689 /**
690 * Validates that the keys are within a set of valid names.
691 *
692 * @return true if all key names are found in pszzAllowed.
693 * @return false if not.
694 * @param pvUser The opaque user data associated with this interface.
695 * @param pszzValid List of valid key names separated by '\\0' and ending with
696 * a double '\\0'.
697 */
698 DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid));
699
700 /**
701 * Retrieves the length of the string value associated with a key (including
702 * the terminator, for compatibility with CFGMR3QuerySize).
703 *
704 * @return VBox status code.
705 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
706 * @param pvUser The opaque user data associated with this interface.
707 * @param pszName Name of the key to query.
708 * @param pcbValue Where to store the value length. Non-NULL.
709 */
710 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
711
712 /**
713 * Query the string value associated with a key.
714 *
715 * @return VBox status code.
716 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
717 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
718 * @param pvUser The opaque user data associated with this interface.
719 * @param pszName Name of the key to query.
720 * @param pszValue Pointer to buffer where to store value.
721 * @param cchValue Length of value buffer.
722 */
723 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
724
725} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
726
727/**
728 * Get configuration information interface from interface list.
729 *
730 * @return Pointer to the first configuration information interface in the list.
731 * @param pVDIfs Pointer to the interface list.
732 */
733DECLINLINE(PVDINTERFACECONFIG) VDIfConfigGet(PVDINTERFACE pVDIfs)
734{
735 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_CONFIG);
736
737 /* Check that the interface descriptor is a progress interface. */
738 AssertMsgReturn( !pIf
739 || ( (pIf->enmInterface == VDINTERFACETYPE_CONFIG)
740 && (pIf->cbSize == sizeof(VDINTERFACECONFIG))),
741 ("Not a config interface"), NULL);
742
743 return (PVDINTERFACECONFIG)pIf;
744}
745
746/**
747 * Query configuration, validates that the keys are within a set of valid names.
748 *
749 * @return true if all key names are found in pszzAllowed.
750 * @return false if not.
751 * @param pCfgIf Pointer to configuration callback table.
752 * @param pszzValid List of valid names separated by '\\0' and ending with
753 * a double '\\0'.
754 */
755DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, const char *pszzValid)
756{
757 return pCfgIf->pfnAreKeysValid(pCfgIf->Core.pvUser, pszzValid);
758}
759
760/**
761 * Query configuration, unsigned 64-bit integer value with default.
762 *
763 * @return VBox status code.
764 * @param pCfgIf Pointer to configuration callback table.
765 * @param pszName Name of an integer value
766 * @param pu64 Where to store the value. Set to default on failure.
767 * @param u64Def The default value.
768 */
769DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf,
770 const char *pszName, uint64_t *pu64,
771 uint64_t u64Def)
772{
773 char aszBuf[32];
774 int rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, aszBuf, sizeof(aszBuf));
775 if (RT_SUCCESS(rc))
776 {
777 rc = RTStrToUInt64Full(aszBuf, 0, pu64);
778 }
779 else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
780 {
781 rc = VINF_SUCCESS;
782 *pu64 = u64Def;
783 }
784 return rc;
785}
786
787/**
788 * Query configuration, unsigned 32-bit integer value with default.
789 *
790 * @return VBox status code.
791 * @param pCfgIf Pointer to configuration callback table.
792 * @param pszName Name of an integer value
793 * @param pu32 Where to store the value. Set to default on failure.
794 * @param u32Def The default value.
795 */
796DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf,
797 const char *pszName, uint32_t *pu32,
798 uint32_t u32Def)
799{
800 uint64_t u64;
801 int rc = VDCFGQueryU64Def(pCfgIf, pszName, &u64, u32Def);
802 if (RT_SUCCESS(rc))
803 {
804 if (!(u64 & UINT64_C(0xffffffff00000000)))
805 *pu32 = (uint32_t)u64;
806 else
807 rc = VERR_CFGM_INTEGER_TOO_BIG;
808 }
809 return rc;
810}
811
812/**
813 * Query configuration, bool value with default.
814 *
815 * @return VBox status code.
816 * @param pCfgIf Pointer to configuration callback table.
817 * @param pszName Name of an integer value
818 * @param pf Where to store the value. Set to default on failure.
819 * @param fDef The default value.
820 */
821DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf,
822 const char *pszName, bool *pf,
823 bool fDef)
824{
825 uint64_t u64;
826 int rc = VDCFGQueryU64Def(pCfgIf, pszName, &u64, fDef);
827 if (RT_SUCCESS(rc))
828 *pf = u64 ? true : false;
829 return rc;
830}
831
832/**
833 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
834 * character value.
835 *
836 * @return VBox status code.
837 * @param pCfgIf Pointer to configuration callback table.
838 * @param pszName Name of an zero terminated character value
839 * @param ppszString Where to store the string pointer. Not set on failure.
840 * Free this using RTMemFree().
841 */
842DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
843 const char *pszName, char **ppszString)
844{
845 size_t cb;
846 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
847 if (RT_SUCCESS(rc))
848 {
849 char *pszString = (char *)RTMemAlloc(cb);
850 if (pszString)
851 {
852 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb);
853 if (RT_SUCCESS(rc))
854 *ppszString = pszString;
855 else
856 RTMemFree(pszString);
857 }
858 else
859 rc = VERR_NO_MEMORY;
860 }
861 return rc;
862}
863
864/**
865 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
866 * character value with default.
867 *
868 * @return VBox status code.
869 * @param pCfgIf Pointer to configuration callback table.
870 * @param pszName Name of an zero terminated character value
871 * @param ppszString Where to store the string pointer. Not set on failure.
872 * Free this using RTMemFree().
873 * @param pszDef The default value.
874 */
875DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
876 const char *pszName,
877 char **ppszString,
878 const char *pszDef)
879{
880 size_t cb;
881 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
882 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
883 {
884 cb = strlen(pszDef) + 1;
885 rc = VINF_SUCCESS;
886 }
887 if (RT_SUCCESS(rc))
888 {
889 char *pszString = (char *)RTMemAlloc(cb);
890 if (pszString)
891 {
892 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb);
893 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
894 {
895 memcpy(pszString, pszDef, cb);
896 rc = VINF_SUCCESS;
897 }
898 if (RT_SUCCESS(rc))
899 *ppszString = pszString;
900 else
901 RTMemFree(pszString);
902 }
903 else
904 rc = VERR_NO_MEMORY;
905 }
906 return rc;
907}
908
909/**
910 * Query configuration, dynamically allocated (RTMemAlloc) byte string value.
911 *
912 * @return VBox status code.
913 * @param pCfgIf Pointer to configuration callback table.
914 * @param pszName Name of an zero terminated character value
915 * @param ppvData Where to store the byte string pointer. Not set on failure.
916 * Free this using RTMemFree().
917 * @param pcbData Where to store the byte string length.
918 */
919DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
920 const char *pszName, void **ppvData, size_t *pcbData)
921{
922 size_t cb;
923 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
924 if (RT_SUCCESS(rc))
925 {
926 char *pbData;
927 Assert(cb);
928
929 pbData = (char *)RTMemAlloc(cb);
930 if (pbData)
931 {
932 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pbData, cb);
933 if (RT_SUCCESS(rc))
934 {
935 *ppvData = pbData;
936 *pcbData = cb - 1; /* Exclude terminator of the queried string. */
937 }
938 else
939 RTMemFree(pbData);
940 }
941 else
942 rc = VERR_NO_MEMORY;
943 }
944 return rc;
945}
946
947/** Forward declaration of a VD socket. */
948typedef struct VDSOCKETINT *VDSOCKET;
949/** Pointer to a VD socket. */
950typedef VDSOCKET *PVDSOCKET;
951/** Nil socket handle. */
952#define NIL_VDSOCKET ((VDSOCKET)0)
953
954/** Connect flag to indicate that the backend wants to use the extended
955 * socket I/O multiplexing call. This might not be supported on all configurations
956 * (internal networking and iSCSI)
957 * and the backend needs to take appropriate action.
958 */
959#define VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT RT_BIT_32(0)
960
961/** @name Select events
962 * @{ */
963/** Readable without blocking. */
964#define VD_INTERFACETCPNET_EVT_READ RT_BIT_32(0)
965/** Writable without blocking. */
966#define VD_INTERFACETCPNET_EVT_WRITE RT_BIT_32(1)
967/** Error condition, hangup, exception or similar. */
968#define VD_INTERFACETCPNET_EVT_ERROR RT_BIT_32(2)
969/** Hint for the select that getting interrupted while waiting is more likely.
970 * The interface implementation can optimize the waiting strategy based on this.
971 * It is assumed that it is more likely to get one of the above socket events
972 * instead of being interrupted if the flag is not set. */
973#define VD_INTERFACETCPNET_HINT_INTERRUPT RT_BIT_32(3)
974/** Mask of the valid bits. */
975#define VD_INTERFACETCPNET_EVT_VALID_MASK UINT32_C(0x0000000f)
976/** @} */
977
978/**
979 * TCP network stack interface
980 *
981 * Per-image. Mandatory for backends which have the VD_CAP_TCPNET bit set.
982 */
983typedef struct VDINTERFACETCPNET
984{
985 /**
986 * Common interface header.
987 */
988 VDINTERFACE Core;
989
990 /**
991 * Creates a socket. The socket is not connected if this succeeds.
992 *
993 * @return iprt status code.
994 * @retval VERR_NOT_SUPPORTED if the combination of flags is not supported.
995 * @param fFlags Combination of the VD_INTERFACETCPNET_CONNECT_* #defines.
996 * @param pSock Where to store the handle.
997 */
998 DECLR3CALLBACKMEMBER(int, pfnSocketCreate, (uint32_t fFlags, PVDSOCKET pSock));
999
1000 /**
1001 * Destroys the socket.
1002 *
1003 * @return iprt status code.
1004 * @param Sock Socket descriptor.
1005 */
1006 DECLR3CALLBACKMEMBER(int, pfnSocketDestroy, (VDSOCKET Sock));
1007
1008 /**
1009 * Connect as a client to a TCP port.
1010 *
1011 * @return iprt status code.
1012 * @param Sock Socket descriptor.
1013 * @param pszAddress The address to connect to.
1014 * @param uPort The port to connect to.
1015 */
1016 DECLR3CALLBACKMEMBER(int, pfnClientConnect, (VDSOCKET Sock, const char *pszAddress, uint32_t uPort));
1017
1018 /**
1019 * Close a TCP connection.
1020 *
1021 * @return iprt status code.
1022 * @param Sock Socket descriptor.
1023 */
1024 DECLR3CALLBACKMEMBER(int, pfnClientClose, (VDSOCKET Sock));
1025
1026 /**
1027 * Returns whether the socket is currently connected to the client.
1028 *
1029 * @returns true if the socket is connected.
1030 * false otherwise.
1031 * @param Sock Socket descriptor.
1032 */
1033 DECLR3CALLBACKMEMBER(bool, pfnIsClientConnected, (VDSOCKET Sock));
1034
1035 /**
1036 * Socket I/O multiplexing.
1037 * Checks if the socket is ready for reading.
1038 *
1039 * @return iprt status code.
1040 * @param Sock Socket descriptor.
1041 * @param cMillies Number of milliseconds to wait for the socket.
1042 * Use RT_INDEFINITE_WAIT to wait for ever.
1043 */
1044 DECLR3CALLBACKMEMBER(int, pfnSelectOne, (VDSOCKET Sock, RTMSINTERVAL cMillies));
1045
1046 /**
1047 * Receive data from a socket.
1048 *
1049 * @return iprt status code.
1050 * @param Sock Socket descriptor.
1051 * @param pvBuffer Where to put the data we read.
1052 * @param cbBuffer Read buffer size.
1053 * @param pcbRead Number of bytes read.
1054 * If NULL the entire buffer will be filled upon successful return.
1055 * If not NULL a partial read can be done successfully.
1056 */
1057 DECLR3CALLBACKMEMBER(int, pfnRead, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
1058
1059 /**
1060 * Send data to a socket.
1061 *
1062 * @return iprt status code.
1063 * @param Sock Socket descriptor.
1064 * @param pvBuffer Buffer to write data to socket.
1065 * @param cbBuffer How much to write.
1066 */
1067 DECLR3CALLBACKMEMBER(int, pfnWrite, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
1068
1069 /**
1070 * Send data from scatter/gather buffer to a socket.
1071 *
1072 * @return iprt status code.
1073 * @param Sock Socket descriptor.
1074 * @param pSgBuffer Scatter/gather buffer to write data to socket.
1075 */
1076 DECLR3CALLBACKMEMBER(int, pfnSgWrite, (VDSOCKET Sock, PCRTSGBUF pSgBuffer));
1077
1078 /**
1079 * Receive data from a socket - not blocking.
1080 *
1081 * @return iprt status code.
1082 * @param Sock Socket descriptor.
1083 * @param pvBuffer Where to put the data we read.
1084 * @param cbBuffer Read buffer size.
1085 * @param pcbRead Number of bytes read.
1086 */
1087 DECLR3CALLBACKMEMBER(int, pfnReadNB, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
1088
1089 /**
1090 * Send data to a socket - not blocking.
1091 *
1092 * @return iprt status code.
1093 * @param Sock Socket descriptor.
1094 * @param pvBuffer Buffer to write data to socket.
1095 * @param cbBuffer How much to write.
1096 * @param pcbWritten Number of bytes written.
1097 */
1098 DECLR3CALLBACKMEMBER(int, pfnWriteNB, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten));
1099
1100 /**
1101 * Send data from scatter/gather buffer to a socket - not blocking.
1102 *
1103 * @return iprt status code.
1104 * @param Sock Socket descriptor.
1105 * @param pSgBuffer Scatter/gather buffer to write data to socket.
1106 * @param pcbWritten Number of bytes written.
1107 */
1108 DECLR3CALLBACKMEMBER(int, pfnSgWriteNB, (VDSOCKET Sock, PRTSGBUF pSgBuffer, size_t *pcbWritten));
1109
1110 /**
1111 * Flush socket write buffers.
1112 *
1113 * @return iprt status code.
1114 * @param Sock Socket descriptor.
1115 */
1116 DECLR3CALLBACKMEMBER(int, pfnFlush, (VDSOCKET Sock));
1117
1118 /**
1119 * Enables or disables delaying sends to coalesce packets.
1120 *
1121 * @return iprt status code.
1122 * @param Sock Socket descriptor.
1123 * @param fEnable When set to true enables coalescing.
1124 */
1125 DECLR3CALLBACKMEMBER(int, pfnSetSendCoalescing, (VDSOCKET Sock, bool fEnable));
1126
1127 /**
1128 * Gets the address of the local side.
1129 *
1130 * @return iprt status code.
1131 * @param Sock Socket descriptor.
1132 * @param pAddr Where to store the local address on success.
1133 */
1134 DECLR3CALLBACKMEMBER(int, pfnGetLocalAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
1135
1136 /**
1137 * Gets the address of the other party.
1138 *
1139 * @return iprt status code.
1140 * @param Sock Socket descriptor.
1141 * @param pAddr Where to store the peer address on success.
1142 */
1143 DECLR3CALLBACKMEMBER(int, pfnGetPeerAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
1144
1145 /**
1146 * Socket I/O multiplexing - extended version which can be woken up.
1147 * Checks if the socket is ready for reading or writing.
1148 *
1149 * @return iprt status code.
1150 * @retval VERR_INTERRUPTED if the thread was woken up by a pfnPoke call.
1151 * @param Sock Socket descriptor.
1152 * @param fEvents Mask of events to wait for.
1153 * @param pfEvents Where to store the received events.
1154 * @param cMillies Number of milliseconds to wait for the socket.
1155 * Use RT_INDEFINITE_WAIT to wait for ever.
1156 */
1157 DECLR3CALLBACKMEMBER(int, pfnSelectOneEx, (VDSOCKET Sock, uint32_t fEvents,
1158 uint32_t *pfEvents, RTMSINTERVAL cMillies));
1159
1160 /**
1161 * Wakes up the thread waiting in pfnSelectOneEx.
1162 *
1163 * @return iprt status code.
1164 * @param Sock Socket descriptor.
1165 */
1166 DECLR3CALLBACKMEMBER(int, pfnPoke, (VDSOCKET Sock));
1167
1168} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
1169
1170/**
1171 * Get TCP network stack interface from interface list.
1172 *
1173 * @return Pointer to the first TCP network stack interface in the list.
1174 * @param pVDIfs Pointer to the interface list.
1175 */
1176DECLINLINE(PVDINTERFACETCPNET) VDIfTcpNetGet(PVDINTERFACE pVDIfs)
1177{
1178 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_TCPNET);
1179
1180 /* Check that the interface descriptor is a progress interface. */
1181 AssertMsgReturn( !pIf
1182 || ( (pIf->enmInterface == VDINTERFACETYPE_TCPNET)
1183 && (pIf->cbSize == sizeof(VDINTERFACETCPNET))),
1184 ("Not a TCP net interface"), NULL);
1185
1186 return (PVDINTERFACETCPNET)pIf;
1187}
1188
1189
1190/**
1191 * Interface to synchronize concurrent accesses by several threads.
1192 *
1193 * @note The scope of this interface is to manage concurrent accesses after
1194 * the HDD container has been created, and they must stop before destroying the
1195 * container. Opening or closing images is covered by the synchronization, but
1196 * that does not mean it is safe to close images while a thread executes
1197 * <link to="VDMerge"/> or <link to="VDCopy"/> operating on these images.
1198 * Making them safe would require the lock to be held during the entire
1199 * operation, which prevents other concurrent acitivities.
1200 *
1201 * @note Right now this is kept as simple as possible, and does not even
1202 * attempt to provide enough information to allow e.g. concurrent write
1203 * accesses to different areas of the disk. The reason is that it is very
1204 * difficult to predict which area of a disk is affected by a write,
1205 * especially when different image formats are mixed. Maybe later a more
1206 * sophisticated interface will be provided which has the necessary information
1207 * about worst case affected areas.
1208 *
1209 * Per-disk interface. Optional, needed if the disk is accessed concurrently
1210 * by several threads, e.g. when merging diff images while a VM is running.
1211 */
1212typedef struct VDINTERFACETHREADSYNC
1213{
1214 /**
1215 * Common interface header.
1216 */
1217 VDINTERFACE Core;
1218
1219 /**
1220 * Start a read operation.
1221 */
1222 DECLR3CALLBACKMEMBER(int, pfnStartRead, (void *pvUser));
1223
1224 /**
1225 * Finish a read operation.
1226 */
1227 DECLR3CALLBACKMEMBER(int, pfnFinishRead, (void *pvUser));
1228
1229 /**
1230 * Start a write operation.
1231 */
1232 DECLR3CALLBACKMEMBER(int, pfnStartWrite, (void *pvUser));
1233
1234 /**
1235 * Finish a write operation.
1236 */
1237 DECLR3CALLBACKMEMBER(int, pfnFinishWrite, (void *pvUser));
1238
1239} VDINTERFACETHREADSYNC, *PVDINTERFACETHREADSYNC;
1240
1241/**
1242 * Get thread synchronization interface from interface list.
1243 *
1244 * @return Pointer to the first thread synchronization interface in the list.
1245 * @param pVDIfs Pointer to the interface list.
1246 */
1247DECLINLINE(PVDINTERFACETHREADSYNC) VDIfThreadSyncGet(PVDINTERFACE pVDIfs)
1248{
1249 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_THREADSYNC);
1250
1251 /* Check that the interface descriptor is a progress interface. */
1252 AssertMsgReturn( !pIf
1253 || ( (pIf->enmInterface == VDINTERFACETYPE_THREADSYNC)
1254 && (pIf->cbSize == sizeof(VDINTERFACETHREADSYNC))),
1255 ("Not a thread synchronization interface"), NULL);
1256
1257 return (PVDINTERFACETHREADSYNC)pIf;
1258}
1259
1260/**
1261 * Interface to query usage of disk ranges.
1262 *
1263 * Per-operation interface. Optional.
1264 */
1265typedef struct VDINTERFACEQUERYRANGEUSE
1266{
1267 /**
1268 * Common interface header.
1269 */
1270 VDINTERFACE Core;
1271
1272 /**
1273 * Query use of a disk range.
1274 */
1275 DECLR3CALLBACKMEMBER(int, pfnQueryRangeUse, (void *pvUser, uint64_t off, uint64_t cb,
1276 bool *pfUsed));
1277
1278} VDINTERFACEQUERYRANGEUSE, *PVDINTERFACEQUERYRANGEUSE;
1279
1280/**
1281 * Get query range use interface from interface list.
1282 *
1283 * @return Pointer to the first thread synchronization interface in the list.
1284 * @param pVDIfs Pointer to the interface list.
1285 */
1286DECLINLINE(PVDINTERFACEQUERYRANGEUSE) VDIfQueryRangeUseGet(PVDINTERFACE pVDIfs)
1287{
1288 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_QUERYRANGEUSE);
1289
1290 /* Check that the interface descriptor is a progress interface. */
1291 AssertMsgReturn( !pIf
1292 || ( (pIf->enmInterface == VDINTERFACETYPE_QUERYRANGEUSE)
1293 && (pIf->cbSize == sizeof(VDINTERFACEQUERYRANGEUSE))),
1294 ("Not a query range use interface"), NULL);
1295
1296 return (PVDINTERFACEQUERYRANGEUSE)pIf;
1297}
1298
1299DECLINLINE(int) vdIfQueryRangeUse(PVDINTERFACEQUERYRANGEUSE pIfQueryRangeUse, uint64_t off, uint64_t cb,
1300 bool *pfUsed)
1301{
1302 return pIfQueryRangeUse->pfnQueryRangeUse(pIfQueryRangeUse->Core.pvUser, off, cb, pfUsed);
1303}
1304
1305RT_C_DECLS_END
1306
1307/** @} */
1308
1309#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette