VirtualBox

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

Last change on this file since 48849 was 48849, checked in by vboxsync, 11 years ago

VDIfVfs.cpp: Added file interface wrapper - VDIfCreateVfsFile.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.7 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 * Create a VFS file handle around a VD I/O interface.
626 *
627 * The I/O interface will not be closed or free by the VFS file, the caller will
628 * do so after it is done with the VFS file and has released the instances of
629 * the VFS object returned by this API.
630 *
631 * @return VBox status code.
632 * @param pVDIfsIo Pointer to the VD I/O interface.
633 * @param pvStorage The storage argument to pass to the interface
634 * methods.
635 * @param fFlags RTFILE_O_XXX, access mask requied.
636 * @param phVfsFile Where to return the VFS file handle on success.
637 */
638VBOXDDU_DECL(int) VDIfCreateVfsFile(PVDINTERFACEIO pVDIfsIo, void *pvStorage, uint32_t fFlags, PRTVFSFILE phVfsFile);
639
640
641/**
642 * Callback which provides progress information about a currently running
643 * lengthy operation.
644 *
645 * @return VBox status code.
646 * @param pvUser The opaque user data associated with this interface.
647 * @param uPercent Completion percentage.
648 */
649typedef DECLCALLBACK(int) FNVDPROGRESS(void *pvUser, unsigned uPercentage);
650/** Pointer to FNVDPROGRESS() */
651typedef FNVDPROGRESS *PFNVDPROGRESS;
652
653/**
654 * Progress notification interface
655 *
656 * Per-operation. Optional.
657 */
658typedef struct VDINTERFACEPROGRESS
659{
660 /**
661 * Common interface header.
662 */
663 VDINTERFACE Core;
664
665 /**
666 * Progress notification callbacks.
667 */
668 PFNVDPROGRESS pfnProgress;
669
670} VDINTERFACEPROGRESS, *PVDINTERFACEPROGRESS;
671
672/**
673 * Get progress interface from interface list.
674 *
675 * @return Pointer to the first progress interface in the list.
676 * @param pVDIfs Pointer to the interface list.
677 */
678DECLINLINE(PVDINTERFACEPROGRESS) VDIfProgressGet(PVDINTERFACE pVDIfs)
679{
680 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_PROGRESS);
681
682 /* Check that the interface descriptor is a progress interface. */
683 AssertMsgReturn( !pIf
684 || ( (pIf->enmInterface == VDINTERFACETYPE_PROGRESS)
685 && (pIf->cbSize == sizeof(VDINTERFACEPROGRESS))),
686 ("Not a progress interface"), NULL);
687
688 return (PVDINTERFACEPROGRESS)pIf;
689}
690
691
692/**
693 * Configuration information interface
694 *
695 * Per-image. Optional for most backends, but mandatory for images which do
696 * not operate on files (including standard block or character devices).
697 */
698typedef struct VDINTERFACECONFIG
699{
700 /**
701 * Common interface header.
702 */
703 VDINTERFACE Core;
704
705 /**
706 * Validates that the keys are within a set of valid names.
707 *
708 * @return true if all key names are found in pszzAllowed.
709 * @return false if not.
710 * @param pvUser The opaque user data associated with this interface.
711 * @param pszzValid List of valid key names separated by '\\0' and ending with
712 * a double '\\0'.
713 */
714 DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid));
715
716 /**
717 * Retrieves the length of the string value associated with a key (including
718 * the terminator, for compatibility with CFGMR3QuerySize).
719 *
720 * @return VBox status code.
721 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
722 * @param pvUser The opaque user data associated with this interface.
723 * @param pszName Name of the key to query.
724 * @param pcbValue Where to store the value length. Non-NULL.
725 */
726 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
727
728 /**
729 * Query the string value associated with a key.
730 *
731 * @return VBox status code.
732 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
733 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
734 * @param pvUser The opaque user data associated with this interface.
735 * @param pszName Name of the key to query.
736 * @param pszValue Pointer to buffer where to store value.
737 * @param cchValue Length of value buffer.
738 */
739 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
740
741} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
742
743/**
744 * Get configuration information interface from interface list.
745 *
746 * @return Pointer to the first configuration information interface in the list.
747 * @param pVDIfs Pointer to the interface list.
748 */
749DECLINLINE(PVDINTERFACECONFIG) VDIfConfigGet(PVDINTERFACE pVDIfs)
750{
751 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_CONFIG);
752
753 /* Check that the interface descriptor is a progress interface. */
754 AssertMsgReturn( !pIf
755 || ( (pIf->enmInterface == VDINTERFACETYPE_CONFIG)
756 && (pIf->cbSize == sizeof(VDINTERFACECONFIG))),
757 ("Not a config interface"), NULL);
758
759 return (PVDINTERFACECONFIG)pIf;
760}
761
762/**
763 * Query configuration, validates that the keys are within a set of valid names.
764 *
765 * @return true if all key names are found in pszzAllowed.
766 * @return false if not.
767 * @param pCfgIf Pointer to configuration callback table.
768 * @param pszzValid List of valid names separated by '\\0' and ending with
769 * a double '\\0'.
770 */
771DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, const char *pszzValid)
772{
773 return pCfgIf->pfnAreKeysValid(pCfgIf->Core.pvUser, pszzValid);
774}
775
776/**
777 * Query configuration, unsigned 64-bit integer value with default.
778 *
779 * @return VBox status code.
780 * @param pCfgIf Pointer to configuration callback table.
781 * @param pszName Name of an integer value
782 * @param pu64 Where to store the value. Set to default on failure.
783 * @param u64Def The default value.
784 */
785DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf,
786 const char *pszName, uint64_t *pu64,
787 uint64_t u64Def)
788{
789 char aszBuf[32];
790 int rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, aszBuf, sizeof(aszBuf));
791 if (RT_SUCCESS(rc))
792 {
793 rc = RTStrToUInt64Full(aszBuf, 0, pu64);
794 }
795 else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
796 {
797 rc = VINF_SUCCESS;
798 *pu64 = u64Def;
799 }
800 return rc;
801}
802
803/**
804 * Query configuration, unsigned 32-bit integer value with default.
805 *
806 * @return VBox status code.
807 * @param pCfgIf Pointer to configuration callback table.
808 * @param pszName Name of an integer value
809 * @param pu32 Where to store the value. Set to default on failure.
810 * @param u32Def The default value.
811 */
812DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf,
813 const char *pszName, uint32_t *pu32,
814 uint32_t u32Def)
815{
816 uint64_t u64;
817 int rc = VDCFGQueryU64Def(pCfgIf, pszName, &u64, u32Def);
818 if (RT_SUCCESS(rc))
819 {
820 if (!(u64 & UINT64_C(0xffffffff00000000)))
821 *pu32 = (uint32_t)u64;
822 else
823 rc = VERR_CFGM_INTEGER_TOO_BIG;
824 }
825 return rc;
826}
827
828/**
829 * Query configuration, bool value with default.
830 *
831 * @return VBox status code.
832 * @param pCfgIf Pointer to configuration callback table.
833 * @param pszName Name of an integer value
834 * @param pf Where to store the value. Set to default on failure.
835 * @param fDef The default value.
836 */
837DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf,
838 const char *pszName, bool *pf,
839 bool fDef)
840{
841 uint64_t u64;
842 int rc = VDCFGQueryU64Def(pCfgIf, pszName, &u64, fDef);
843 if (RT_SUCCESS(rc))
844 *pf = u64 ? true : false;
845 return rc;
846}
847
848/**
849 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
850 * character value.
851 *
852 * @return VBox status code.
853 * @param pCfgIf Pointer to configuration callback table.
854 * @param pszName Name of an zero terminated character value
855 * @param ppszString Where to store the string pointer. Not set on failure.
856 * Free this using RTMemFree().
857 */
858DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
859 const char *pszName, char **ppszString)
860{
861 size_t cb;
862 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
863 if (RT_SUCCESS(rc))
864 {
865 char *pszString = (char *)RTMemAlloc(cb);
866 if (pszString)
867 {
868 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb);
869 if (RT_SUCCESS(rc))
870 *ppszString = pszString;
871 else
872 RTMemFree(pszString);
873 }
874 else
875 rc = VERR_NO_MEMORY;
876 }
877 return rc;
878}
879
880/**
881 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
882 * character value with default.
883 *
884 * @return VBox status code.
885 * @param pCfgIf Pointer to configuration callback table.
886 * @param pszName Name of an zero terminated character value
887 * @param ppszString Where to store the string pointer. Not set on failure.
888 * Free this using RTMemFree().
889 * @param pszDef The default value.
890 */
891DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
892 const char *pszName,
893 char **ppszString,
894 const char *pszDef)
895{
896 size_t cb;
897 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
898 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
899 {
900 cb = strlen(pszDef) + 1;
901 rc = VINF_SUCCESS;
902 }
903 if (RT_SUCCESS(rc))
904 {
905 char *pszString = (char *)RTMemAlloc(cb);
906 if (pszString)
907 {
908 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb);
909 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
910 {
911 memcpy(pszString, pszDef, cb);
912 rc = VINF_SUCCESS;
913 }
914 if (RT_SUCCESS(rc))
915 *ppszString = pszString;
916 else
917 RTMemFree(pszString);
918 }
919 else
920 rc = VERR_NO_MEMORY;
921 }
922 return rc;
923}
924
925/**
926 * Query configuration, dynamically allocated (RTMemAlloc) byte string value.
927 *
928 * @return VBox status code.
929 * @param pCfgIf Pointer to configuration callback table.
930 * @param pszName Name of an zero terminated character value
931 * @param ppvData Where to store the byte string pointer. Not set on failure.
932 * Free this using RTMemFree().
933 * @param pcbData Where to store the byte string length.
934 */
935DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
936 const char *pszName, void **ppvData, size_t *pcbData)
937{
938 size_t cb;
939 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
940 if (RT_SUCCESS(rc))
941 {
942 char *pbData;
943 Assert(cb);
944
945 pbData = (char *)RTMemAlloc(cb);
946 if (pbData)
947 {
948 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pbData, cb);
949 if (RT_SUCCESS(rc))
950 {
951 *ppvData = pbData;
952 *pcbData = cb - 1; /* Exclude terminator of the queried string. */
953 }
954 else
955 RTMemFree(pbData);
956 }
957 else
958 rc = VERR_NO_MEMORY;
959 }
960 return rc;
961}
962
963/** Forward declaration of a VD socket. */
964typedef struct VDSOCKETINT *VDSOCKET;
965/** Pointer to a VD socket. */
966typedef VDSOCKET *PVDSOCKET;
967/** Nil socket handle. */
968#define NIL_VDSOCKET ((VDSOCKET)0)
969
970/** Connect flag to indicate that the backend wants to use the extended
971 * socket I/O multiplexing call. This might not be supported on all configurations
972 * (internal networking and iSCSI)
973 * and the backend needs to take appropriate action.
974 */
975#define VD_INTERFACETCPNET_CONNECT_EXTENDED_SELECT RT_BIT_32(0)
976
977/** @name Select events
978 * @{ */
979/** Readable without blocking. */
980#define VD_INTERFACETCPNET_EVT_READ RT_BIT_32(0)
981/** Writable without blocking. */
982#define VD_INTERFACETCPNET_EVT_WRITE RT_BIT_32(1)
983/** Error condition, hangup, exception or similar. */
984#define VD_INTERFACETCPNET_EVT_ERROR RT_BIT_32(2)
985/** Hint for the select that getting interrupted while waiting is more likely.
986 * The interface implementation can optimize the waiting strategy based on this.
987 * It is assumed that it is more likely to get one of the above socket events
988 * instead of being interrupted if the flag is not set. */
989#define VD_INTERFACETCPNET_HINT_INTERRUPT RT_BIT_32(3)
990/** Mask of the valid bits. */
991#define VD_INTERFACETCPNET_EVT_VALID_MASK UINT32_C(0x0000000f)
992/** @} */
993
994/**
995 * TCP network stack interface
996 *
997 * Per-image. Mandatory for backends which have the VD_CAP_TCPNET bit set.
998 */
999typedef struct VDINTERFACETCPNET
1000{
1001 /**
1002 * Common interface header.
1003 */
1004 VDINTERFACE Core;
1005
1006 /**
1007 * Creates a socket. The socket is not connected if this succeeds.
1008 *
1009 * @return iprt status code.
1010 * @retval VERR_NOT_SUPPORTED if the combination of flags is not supported.
1011 * @param fFlags Combination of the VD_INTERFACETCPNET_CONNECT_* #defines.
1012 * @param pSock Where to store the handle.
1013 */
1014 DECLR3CALLBACKMEMBER(int, pfnSocketCreate, (uint32_t fFlags, PVDSOCKET pSock));
1015
1016 /**
1017 * Destroys the socket.
1018 *
1019 * @return iprt status code.
1020 * @param Sock Socket descriptor.
1021 */
1022 DECLR3CALLBACKMEMBER(int, pfnSocketDestroy, (VDSOCKET Sock));
1023
1024 /**
1025 * Connect as a client to a TCP port.
1026 *
1027 * @return iprt status code.
1028 * @param Sock Socket descriptor.
1029 * @param pszAddress The address to connect to.
1030 * @param uPort The port to connect to.
1031 */
1032 DECLR3CALLBACKMEMBER(int, pfnClientConnect, (VDSOCKET Sock, const char *pszAddress, uint32_t uPort));
1033
1034 /**
1035 * Close a TCP connection.
1036 *
1037 * @return iprt status code.
1038 * @param Sock Socket descriptor.
1039 */
1040 DECLR3CALLBACKMEMBER(int, pfnClientClose, (VDSOCKET Sock));
1041
1042 /**
1043 * Returns whether the socket is currently connected to the client.
1044 *
1045 * @returns true if the socket is connected.
1046 * false otherwise.
1047 * @param Sock Socket descriptor.
1048 */
1049 DECLR3CALLBACKMEMBER(bool, pfnIsClientConnected, (VDSOCKET Sock));
1050
1051 /**
1052 * Socket I/O multiplexing.
1053 * Checks if the socket is ready for reading.
1054 *
1055 * @return iprt status code.
1056 * @param Sock Socket descriptor.
1057 * @param cMillies Number of milliseconds to wait for the socket.
1058 * Use RT_INDEFINITE_WAIT to wait for ever.
1059 */
1060 DECLR3CALLBACKMEMBER(int, pfnSelectOne, (VDSOCKET Sock, RTMSINTERVAL cMillies));
1061
1062 /**
1063 * Receive data from a socket.
1064 *
1065 * @return iprt status code.
1066 * @param Sock Socket descriptor.
1067 * @param pvBuffer Where to put the data we read.
1068 * @param cbBuffer Read buffer size.
1069 * @param pcbRead Number of bytes read.
1070 * If NULL the entire buffer will be filled upon successful return.
1071 * If not NULL a partial read can be done successfully.
1072 */
1073 DECLR3CALLBACKMEMBER(int, pfnRead, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
1074
1075 /**
1076 * Send data to a socket.
1077 *
1078 * @return iprt status code.
1079 * @param Sock Socket descriptor.
1080 * @param pvBuffer Buffer to write data to socket.
1081 * @param cbBuffer How much to write.
1082 */
1083 DECLR3CALLBACKMEMBER(int, pfnWrite, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer));
1084
1085 /**
1086 * Send data from scatter/gather buffer to a socket.
1087 *
1088 * @return iprt status code.
1089 * @param Sock Socket descriptor.
1090 * @param pSgBuffer Scatter/gather buffer to write data to socket.
1091 */
1092 DECLR3CALLBACKMEMBER(int, pfnSgWrite, (VDSOCKET Sock, PCRTSGBUF pSgBuffer));
1093
1094 /**
1095 * Receive data from a socket - not blocking.
1096 *
1097 * @return iprt status code.
1098 * @param Sock Socket descriptor.
1099 * @param pvBuffer Where to put the data we read.
1100 * @param cbBuffer Read buffer size.
1101 * @param pcbRead Number of bytes read.
1102 */
1103 DECLR3CALLBACKMEMBER(int, pfnReadNB, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
1104
1105 /**
1106 * Send data to a socket - not blocking.
1107 *
1108 * @return iprt status code.
1109 * @param Sock Socket descriptor.
1110 * @param pvBuffer Buffer to write data to socket.
1111 * @param cbBuffer How much to write.
1112 * @param pcbWritten Number of bytes written.
1113 */
1114 DECLR3CALLBACKMEMBER(int, pfnWriteNB, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten));
1115
1116 /**
1117 * Send data from scatter/gather buffer to a socket - not blocking.
1118 *
1119 * @return iprt status code.
1120 * @param Sock Socket descriptor.
1121 * @param pSgBuffer Scatter/gather buffer to write data to socket.
1122 * @param pcbWritten Number of bytes written.
1123 */
1124 DECLR3CALLBACKMEMBER(int, pfnSgWriteNB, (VDSOCKET Sock, PRTSGBUF pSgBuffer, size_t *pcbWritten));
1125
1126 /**
1127 * Flush socket write buffers.
1128 *
1129 * @return iprt status code.
1130 * @param Sock Socket descriptor.
1131 */
1132 DECLR3CALLBACKMEMBER(int, pfnFlush, (VDSOCKET Sock));
1133
1134 /**
1135 * Enables or disables delaying sends to coalesce packets.
1136 *
1137 * @return iprt status code.
1138 * @param Sock Socket descriptor.
1139 * @param fEnable When set to true enables coalescing.
1140 */
1141 DECLR3CALLBACKMEMBER(int, pfnSetSendCoalescing, (VDSOCKET Sock, bool fEnable));
1142
1143 /**
1144 * Gets the address of the local side.
1145 *
1146 * @return iprt status code.
1147 * @param Sock Socket descriptor.
1148 * @param pAddr Where to store the local address on success.
1149 */
1150 DECLR3CALLBACKMEMBER(int, pfnGetLocalAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
1151
1152 /**
1153 * Gets the address of the other party.
1154 *
1155 * @return iprt status code.
1156 * @param Sock Socket descriptor.
1157 * @param pAddr Where to store the peer address on success.
1158 */
1159 DECLR3CALLBACKMEMBER(int, pfnGetPeerAddress, (VDSOCKET Sock, PRTNETADDR pAddr));
1160
1161 /**
1162 * Socket I/O multiplexing - extended version which can be woken up.
1163 * Checks if the socket is ready for reading or writing.
1164 *
1165 * @return iprt status code.
1166 * @retval VERR_INTERRUPTED if the thread was woken up by a pfnPoke call.
1167 * @param Sock Socket descriptor.
1168 * @param fEvents Mask of events to wait for.
1169 * @param pfEvents Where to store the received events.
1170 * @param cMillies Number of milliseconds to wait for the socket.
1171 * Use RT_INDEFINITE_WAIT to wait for ever.
1172 */
1173 DECLR3CALLBACKMEMBER(int, pfnSelectOneEx, (VDSOCKET Sock, uint32_t fEvents,
1174 uint32_t *pfEvents, RTMSINTERVAL cMillies));
1175
1176 /**
1177 * Wakes up the thread waiting in pfnSelectOneEx.
1178 *
1179 * @return iprt status code.
1180 * @param Sock Socket descriptor.
1181 */
1182 DECLR3CALLBACKMEMBER(int, pfnPoke, (VDSOCKET Sock));
1183
1184} VDINTERFACETCPNET, *PVDINTERFACETCPNET;
1185
1186/**
1187 * Get TCP network stack interface from interface list.
1188 *
1189 * @return Pointer to the first TCP network stack interface in the list.
1190 * @param pVDIfs Pointer to the interface list.
1191 */
1192DECLINLINE(PVDINTERFACETCPNET) VDIfTcpNetGet(PVDINTERFACE pVDIfs)
1193{
1194 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_TCPNET);
1195
1196 /* Check that the interface descriptor is a progress interface. */
1197 AssertMsgReturn( !pIf
1198 || ( (pIf->enmInterface == VDINTERFACETYPE_TCPNET)
1199 && (pIf->cbSize == sizeof(VDINTERFACETCPNET))),
1200 ("Not a TCP net interface"), NULL);
1201
1202 return (PVDINTERFACETCPNET)pIf;
1203}
1204
1205
1206/**
1207 * Interface to synchronize concurrent accesses by several threads.
1208 *
1209 * @note The scope of this interface is to manage concurrent accesses after
1210 * the HDD container has been created, and they must stop before destroying the
1211 * container. Opening or closing images is covered by the synchronization, but
1212 * that does not mean it is safe to close images while a thread executes
1213 * <link to="VDMerge"/> or <link to="VDCopy"/> operating on these images.
1214 * Making them safe would require the lock to be held during the entire
1215 * operation, which prevents other concurrent acitivities.
1216 *
1217 * @note Right now this is kept as simple as possible, and does not even
1218 * attempt to provide enough information to allow e.g. concurrent write
1219 * accesses to different areas of the disk. The reason is that it is very
1220 * difficult to predict which area of a disk is affected by a write,
1221 * especially when different image formats are mixed. Maybe later a more
1222 * sophisticated interface will be provided which has the necessary information
1223 * about worst case affected areas.
1224 *
1225 * Per-disk interface. Optional, needed if the disk is accessed concurrently
1226 * by several threads, e.g. when merging diff images while a VM is running.
1227 */
1228typedef struct VDINTERFACETHREADSYNC
1229{
1230 /**
1231 * Common interface header.
1232 */
1233 VDINTERFACE Core;
1234
1235 /**
1236 * Start a read operation.
1237 */
1238 DECLR3CALLBACKMEMBER(int, pfnStartRead, (void *pvUser));
1239
1240 /**
1241 * Finish a read operation.
1242 */
1243 DECLR3CALLBACKMEMBER(int, pfnFinishRead, (void *pvUser));
1244
1245 /**
1246 * Start a write operation.
1247 */
1248 DECLR3CALLBACKMEMBER(int, pfnStartWrite, (void *pvUser));
1249
1250 /**
1251 * Finish a write operation.
1252 */
1253 DECLR3CALLBACKMEMBER(int, pfnFinishWrite, (void *pvUser));
1254
1255} VDINTERFACETHREADSYNC, *PVDINTERFACETHREADSYNC;
1256
1257/**
1258 * Get thread synchronization interface from interface list.
1259 *
1260 * @return Pointer to the first thread synchronization interface in the list.
1261 * @param pVDIfs Pointer to the interface list.
1262 */
1263DECLINLINE(PVDINTERFACETHREADSYNC) VDIfThreadSyncGet(PVDINTERFACE pVDIfs)
1264{
1265 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_THREADSYNC);
1266
1267 /* Check that the interface descriptor is a progress interface. */
1268 AssertMsgReturn( !pIf
1269 || ( (pIf->enmInterface == VDINTERFACETYPE_THREADSYNC)
1270 && (pIf->cbSize == sizeof(VDINTERFACETHREADSYNC))),
1271 ("Not a thread synchronization interface"), NULL);
1272
1273 return (PVDINTERFACETHREADSYNC)pIf;
1274}
1275
1276/**
1277 * Interface to query usage of disk ranges.
1278 *
1279 * Per-operation interface. Optional.
1280 */
1281typedef struct VDINTERFACEQUERYRANGEUSE
1282{
1283 /**
1284 * Common interface header.
1285 */
1286 VDINTERFACE Core;
1287
1288 /**
1289 * Query use of a disk range.
1290 */
1291 DECLR3CALLBACKMEMBER(int, pfnQueryRangeUse, (void *pvUser, uint64_t off, uint64_t cb,
1292 bool *pfUsed));
1293
1294} VDINTERFACEQUERYRANGEUSE, *PVDINTERFACEQUERYRANGEUSE;
1295
1296/**
1297 * Get query range use interface from interface list.
1298 *
1299 * @return Pointer to the first thread synchronization interface in the list.
1300 * @param pVDIfs Pointer to the interface list.
1301 */
1302DECLINLINE(PVDINTERFACEQUERYRANGEUSE) VDIfQueryRangeUseGet(PVDINTERFACE pVDIfs)
1303{
1304 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_QUERYRANGEUSE);
1305
1306 /* Check that the interface descriptor is a progress interface. */
1307 AssertMsgReturn( !pIf
1308 || ( (pIf->enmInterface == VDINTERFACETYPE_QUERYRANGEUSE)
1309 && (pIf->cbSize == sizeof(VDINTERFACEQUERYRANGEUSE))),
1310 ("Not a query range use interface"), NULL);
1311
1312 return (PVDINTERFACEQUERYRANGEUSE)pIf;
1313}
1314
1315DECLINLINE(int) vdIfQueryRangeUse(PVDINTERFACEQUERYRANGEUSE pIfQueryRangeUse, uint64_t off, uint64_t cb,
1316 bool *pfUsed)
1317{
1318 return pIfQueryRangeUse->pfnQueryRangeUse(pIfQueryRangeUse->Core.pvUser, off, cb, pfUsed);
1319}
1320
1321RT_C_DECLS_END
1322
1323/** @} */
1324
1325#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