VirtualBox

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

Last change on this file was 99739, checked in by vboxsync, 12 months ago

*: doxygen corrections (mostly about removing @returns from functions returning void).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.3 KB
Line 
1/** @file
2 * VD Container API - internal interfaces.
3 */
4
5/*
6 * Copyright (C) 2011-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_vd_ifs_internal_h
37#define VBOX_INCLUDED_vd_ifs_internal_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/sg.h>
43#include <VBox/vd-ifs.h>
44
45RT_C_DECLS_BEGIN
46
47/** @addtogroup grp_vd
48 * @internal
49 * @{ */
50
51/**
52 * Read data callback.
53 *
54 * @return VBox status code.
55 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
56 * @param pvUser The opaque data passed for the operation.
57 * @param uOffset Offset of first reading byte from start of disk.
58 * Must be aligned to a sector boundary.
59 * @param pvBuffer Pointer to buffer for reading data.
60 * @param cbBuffer Number of bytes to read.
61 * Must be aligned to a sector boundary.
62 */
63typedef DECLCALLBACKTYPE(int, FNVDPARENTREAD,(void *pvUser, uint64_t uOffset, void *pvBuffer, size_t cbBuffer));
64/** Pointer to a FNVDPARENTREAD. */
65typedef FNVDPARENTREAD *PFNVDPARENTREAD;
66
67/**
68 * Interface to get the parent state.
69 *
70 * Per-operation interface. Optional, present only if there is a parent, and
71 * used only internally for compacting.
72 */
73typedef struct VDINTERFACEPARENTSTATE
74{
75 /**
76 * Common interface header.
77 */
78 VDINTERFACE Core;
79
80 /**
81 * Read data callback, see FNVDPARENTREAD for details.
82 */
83 PFNVDPARENTREAD pfnParentRead;
84
85} VDINTERFACEPARENTSTATE, *PVDINTERFACEPARENTSTATE;
86
87
88/**
89 * Get parent state interface from interface list.
90 *
91 * @return Pointer to the first parent state interface in the list.
92 * @param pVDIfs Pointer to the interface list.
93 */
94DECLINLINE(PVDINTERFACEPARENTSTATE) VDIfParentStateGet(PVDINTERFACE pVDIfs)
95{
96 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_PARENTSTATE);
97
98 /* Check that the interface descriptor is a progress interface. */
99 AssertMsgReturn( !pIf
100 || ( (pIf->enmInterface == VDINTERFACETYPE_PARENTSTATE)
101 && (pIf->cbSize == sizeof(VDINTERFACEPARENTSTATE))),
102 ("Not a parent state interface"), NULL);
103
104 return (PVDINTERFACEPARENTSTATE)pIf;
105}
106
107/** Forward declaration. Only visible in the VBoxHDD module. */
108/** I/O context */
109typedef struct VDIOCTX *PVDIOCTX;
110/** Storage backend handle. */
111typedef struct VDIOSTORAGE *PVDIOSTORAGE;
112/** Pointer to a storage backend handle. */
113typedef PVDIOSTORAGE *PPVDIOSTORAGE;
114
115/**
116 * Completion callback for meta/userdata reads or writes.
117 *
118 * @return VBox status code.
119 * VINF_SUCCESS if everything was successful and the transfer can continue.
120 * VERR_VD_ASYNC_IO_IN_PROGRESS if there is another data transfer pending.
121 * @param pBackendData The opaque backend data.
122 * @param pIoCtx I/O context associated with this request.
123 * @param pvUser Opaque user data passed during a read/write request.
124 * @param rcReq Status code for the completed request.
125 */
126typedef DECLCALLBACKTYPE(int, FNVDXFERCOMPLETED,(void *pBackendData, PVDIOCTX pIoCtx, void *pvUser, int rcReq));
127/** Pointer to FNVDXFERCOMPLETED() */
128typedef FNVDXFERCOMPLETED *PFNVDXFERCOMPLETED;
129
130/** Metadata transfer handle. */
131typedef struct VDMETAXFER *PVDMETAXFER;
132/** Pointer to a metadata transfer handle. */
133typedef PVDMETAXFER *PPVDMETAXFER;
134
135
136/**
137 * Internal I/O interface between the generic VD layer and the backends.
138 *
139 * Per-image. Always passed to backends.
140 */
141typedef struct VDINTERFACEIOINT
142{
143 /**
144 * Common interface header.
145 */
146 VDINTERFACE Core;
147
148 /**
149 * Open callback
150 *
151 * @return VBox status code.
152 * @param pvUser The opaque data passed on container creation.
153 * @param pszLocation Name of the location to open.
154 * @param fOpen Flags for opening the backend.
155 * See RTFILE_O_* \#defines, inventing another set
156 * of open flags is not worth the mapping effort.
157 * @param ppStorage Where to store the storage handle.
158 */
159 DECLR3CALLBACKMEMBER(int, pfnOpen, (void *pvUser, const char *pszLocation,
160 uint32_t fOpen, PPVDIOSTORAGE ppStorage));
161
162 /**
163 * Close callback.
164 *
165 * @return VBox status code.
166 * @param pvUser The opaque data passed on container creation.
167 * @param pStorage The storage handle to close.
168 */
169 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvUser, PVDIOSTORAGE pStorage));
170
171 /**
172 * Delete callback.
173 *
174 * @return VBox status code.
175 * @param pvUser The opaque data passed on container creation.
176 * @param pcszFilename Name of the file to delete.
177 */
178 DECLR3CALLBACKMEMBER(int, pfnDelete, (void *pvUser, const char *pcszFilename));
179
180 /**
181 * Move callback.
182 *
183 * @return VBox status code.
184 * @param pvUser The opaque data passed on container creation.
185 * @param pcszSrc The path to the source file.
186 * @param pcszDst The path to the destination file.
187 * This file will be created.
188 * @param fMove A combination of the RTFILEMOVE_* flags.
189 */
190 DECLR3CALLBACKMEMBER(int, pfnMove, (void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned fMove));
191
192 /**
193 * Returns the free space on a disk.
194 *
195 * @return VBox status code.
196 * @param pvUser The opaque data passed on container creation.
197 * @param pcszFilename Name of a file to identify the disk.
198 * @param pcbFreeSpace Where to store the free space of the disk.
199 */
200 DECLR3CALLBACKMEMBER(int, pfnGetFreeSpace, (void *pvUser, const char *pcszFilename, int64_t *pcbFreeSpace));
201
202 /**
203 * Returns the last modification timestamp of a file.
204 *
205 * @return VBox status code.
206 * @param pvUser The opaque data passed on container creation.
207 * @param pcszFilename Name of a file to identify the disk.
208 * @param pModificationTime Where to store the timestamp of the file.
209 */
210 DECLR3CALLBACKMEMBER(int, pfnGetModificationTime, (void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime));
211
212 /**
213 * Returns the size of the opened storage backend.
214 *
215 * @return VBox status code.
216 * @param pvUser The opaque data passed on container creation.
217 * @param pStorage The storage handle to get the size from.
218 * @param pcbSize Where to store the size of the storage backend.
219 */
220 DECLR3CALLBACKMEMBER(int, pfnGetSize, (void *pvUser, PVDIOSTORAGE pStorage,
221 uint64_t *pcbSize));
222
223 /**
224 * Sets the size of the opened storage backend if possible.
225 *
226 * @return VBox status code.
227 * @retval VERR_NOT_SUPPORTED if the backend does not support this operation.
228 * @param pvUser The opaque data passed on container creation.
229 * @param pStorage The storage handle.
230 * @param cbSize The new size of the image.
231 *
232 * @note Depending on the host the underlying storage (backing file, etc.)
233 * might not have all required storage allocated (sparse file) which
234 * can delay writes or fail with a not enough free space error if there
235 * is not enough space on the storage medium when writing to the range for
236 * the first time.
237 * Use VDINTERFACEIOINT::pfnSetAllocationSize to make sure the storage is
238 * really alloacted.
239 */
240 DECLR3CALLBACKMEMBER(int, pfnSetSize, (void *pvUser, PVDIOSTORAGE pStorage,
241 uint64_t cbSize));
242
243 /**
244 * Sets the size of the opened storage backend making sure the given size
245 * is really allocated.
246 *
247 * @return VBox status code.
248 * @param pvUser The opaque data passed on container creation.
249 * @param pStorage The storage handle.
250 * @param cbSize The new size of the image.
251 * @param fFlags Flags for controlling the allocation strategy.
252 * Reserved for future use, MBZ.
253 * @param pIfProgress Progress interface (optional).
254 * @param uPercentStart Progress starting point.
255 * @param uPercentSpan Length of operation in percent.
256 */
257 DECLR3CALLBACKMEMBER(int, pfnSetAllocationSize, (void *pvUser, PVDIOSTORAGE pStorage,
258 uint64_t cbSize, uint32_t fFlags,
259 PVDINTERFACEPROGRESS pIfProgress,
260 unsigned uPercentStart, unsigned uPercentSpan));
261
262 /**
263 * Initiate a read request for user data.
264 *
265 * @return VBox status code.
266 * @param pvUser The opaque user data passed on container creation.
267 * @param pStorage The storage handle.
268 * @param uOffset The offset to start reading from.
269 * @param pIoCtx I/O context passed in the read/write callback.
270 * @param cbRead How many bytes to read.
271 */
272 DECLR3CALLBACKMEMBER(int, pfnReadUser, (void *pvUser, PVDIOSTORAGE pStorage,
273 uint64_t uOffset, PVDIOCTX pIoCtx,
274 size_t cbRead));
275
276 /**
277 * Initiate a write request for user data.
278 *
279 * @return VBox status code.
280 * @param pvUser The opaque user data passed on container creation.
281 * @param pStorage The storage handle.
282 * @param uOffset The offset to start writing to.
283 * @param pIoCtx I/O context passed in the read/write callback.
284 * @param cbWrite How many bytes to write.
285 * @param pfnCompleted Completion callback.
286 * @param pvCompleteUser Opaque user data passed in the completion callback.
287 */
288 DECLR3CALLBACKMEMBER(int, pfnWriteUser, (void *pvUser, PVDIOSTORAGE pStorage,
289 uint64_t uOffset, PVDIOCTX pIoCtx,
290 size_t cbWrite,
291 PFNVDXFERCOMPLETED pfnComplete,
292 void *pvCompleteUser));
293
294 /**
295 * Reads metadata from storage.
296 * The current I/O context will be halted.
297 *
298 * @returns VBox status code.
299 * @param pvUser The opaque user data passed on container creation.
300 * @param pStorage The storage handle.
301 * @param uOffset Offset to start reading from.
302 * @param pvBuffer Where to store the data.
303 * @param cbBuffer How many bytes to read.
304 * @param pIoCtx The I/O context which triggered the read.
305 * @param ppMetaXfer Where to store the metadata transfer handle on success.
306 * @param pfnCompleted Completion callback.
307 * @param pvCompleteUser Opaque user data passed in the completion callback.
308 *
309 * @note If pIoCtx is NULL the metadata read is handled synchronously
310 * i.e. the call returns only if the data is available in the given
311 * buffer. ppMetaXfer, pfnCompleted and pvCompleteUser are ignored in that case.
312 * Use the synchronous version only when opening/closing the image
313 * or when doing certain operations like resizing, compacting or repairing
314 * the disk.
315 */
316 DECLR3CALLBACKMEMBER(int, pfnReadMeta, (void *pvUser, PVDIOSTORAGE pStorage,
317 uint64_t uOffset, void *pvBuffer,
318 size_t cbBuffer, PVDIOCTX pIoCtx,
319 PPVDMETAXFER ppMetaXfer,
320 PFNVDXFERCOMPLETED pfnComplete,
321 void *pvCompleteUser));
322
323 /**
324 * Writes metadata to storage.
325 *
326 * @returns VBox status code.
327 * @param pvUser The opaque user data passed on container creation.
328 * @param pStorage The storage handle.
329 * @param uOffset Offset to start writing to.
330 * @param pvBuffer Written data.
331 * @param cbBuffer How many bytes to write.
332 * @param pIoCtx The I/O context which triggered the write.
333 * @param pfnCompleted Completion callback.
334 * @param pvCompleteUser Opaque user data passed in the completion callback.
335 *
336 * @sa VDINTERFACEIOINT::pfnReadMeta
337 */
338 DECLR3CALLBACKMEMBER(int, pfnWriteMeta, (void *pvUser, PVDIOSTORAGE pStorage,
339 uint64_t uOffset, const void *pvBuffer,
340 size_t cbBuffer, PVDIOCTX pIoCtx,
341 PFNVDXFERCOMPLETED pfnComplete,
342 void *pvCompleteUser));
343
344 /**
345 * Releases a metadata transfer handle.
346 * The free space can be used for another transfer.
347 *
348 * @param pvUser The opaque user data passed on container creation.
349 * @param pMetaXfer The metadata transfer handle to release.
350 */
351 DECLR3CALLBACKMEMBER(void, pfnMetaXferRelease, (void *pvUser, PVDMETAXFER pMetaXfer));
352
353 /**
354 * Initiates a flush request.
355 *
356 * @return VBox status code.
357 * @param pvUser The opaque data passed on container creation.
358 * @param pStorage The storage handle to flush.
359 * @param pIoCtx I/O context which triggered the flush.
360 * @param pfnCompleted Completion callback.
361 * @param pvCompleteUser Opaque user data passed in the completion callback.
362 *
363 * @sa VDINTERFACEIOINT::pfnReadMeta
364 */
365 DECLR3CALLBACKMEMBER(int, pfnFlush, (void *pvUser, PVDIOSTORAGE pStorage,
366 PVDIOCTX pIoCtx,
367 PFNVDXFERCOMPLETED pfnComplete,
368 void *pvCompleteUser));
369
370 /**
371 * Copies a buffer into the I/O context.
372 *
373 * @return Number of bytes copied.
374 * @param pvUser The opaque user data passed on container creation.
375 * @param pIoCtx I/O context to copy the data to.
376 * @param pvBuffer Buffer to copy.
377 * @param cbBuffer Number of bytes to copy.
378 */
379 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyTo, (void *pvUser, PVDIOCTX pIoCtx,
380 const void *pvBuffer, size_t cbBuffer));
381
382 /**
383 * Copies data from the I/O context into a buffer.
384 *
385 * @return Number of bytes copied.
386 * @param pvUser The opaque user data passed on container creation.
387 * @param pIoCtx I/O context to copy the data from.
388 * @param pvBuffer Destination buffer.
389 * @param cbBuffer Number of bytes to copy.
390 */
391 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyFrom, (void *pvUser, PVDIOCTX pIoCtx,
392 void *pvBuffer, size_t cbBuffer));
393
394 /**
395 * Sets the buffer of the given context to a specific byte.
396 *
397 * @return Number of bytes set.
398 * @param pvUser The opaque user data passed on container creation.
399 * @param pIoCtx I/O context to copy the data from.
400 * @param ch The byte to set.
401 * @param cbSet Number of bytes to set.
402 */
403 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSet, (void *pvUser, PVDIOCTX pIoCtx,
404 int ch, size_t cbSet));
405
406 /**
407 * Creates a segment array from the I/O context data buffer.
408 *
409 * @returns Number of bytes the array describes.
410 * @param pvUser The opaque user data passed on container creation.
411 * @param pIoCtx I/O context to copy the data from.
412 * @param paSeg The uninitialized segment array.
413 * If NULL pcSeg will contain the number of segments needed
414 * to describe the requested amount of data.
415 * @param pcSeg The number of segments the given array has.
416 * This will hold the actual number of entries needed upon return.
417 * @param cbData Number of bytes the new array should describe.
418 */
419 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSegArrayCreate, (void *pvUser, PVDIOCTX pIoCtx,
420 PRTSGSEG paSeg, unsigned *pcSeg,
421 size_t cbData));
422 /**
423 * Marks the given number of bytes as completed and continues the I/O context.
424 *
425 * @param pvUser The opaque user data passed on container creation.
426 * @param pIoCtx The I/O context.
427 * @param rcReq Status code the request completed with.
428 * @param cbCompleted Number of bytes completed.
429 */
430 DECLR3CALLBACKMEMBER(void, pfnIoCtxCompleted, (void *pvUser, PVDIOCTX pIoCtx,
431 int rcReq, size_t cbCompleted));
432
433 /**
434 * Returns whether the given I/O context must be treated synchronously.
435 *
436 * @returns true if the I/O context must be processed synchronously
437 * false otherwise.
438 * @param pvUser The opaque user data passed on container creation.
439 * @param pIoCtx The I/O context.
440 */
441 DECLR3CALLBACKMEMBER(bool, pfnIoCtxIsSynchronous, (void *pvUser, PVDIOCTX pIoCtx));
442
443 /**
444 * Returns whether the user buffer of the I/O context is complete zero
445 * from to current position upto the given number of bytes.
446 *
447 * @returns true if the I/O context user buffer consists solely of zeros
448 * false otherwise.
449 * @param pvUser The opaque user data passed on container creation.
450 * @param pIoCtx The I/O context.
451 * @param cbCheck Number of bytes to check for zeros.
452 * @param fAdvance Flag whether to advance the buffer pointer if true
453 * is returned.
454 */
455 DECLR3CALLBACKMEMBER(bool, pfnIoCtxIsZero, (void *pvUser, PVDIOCTX pIoCtx,
456 size_t cbCheck, bool fAdvance));
457
458 /**
459 * Returns the data unit size, i.e. the smallest size for a transfer.
460 * (similar to the sector size of disks).
461 *
462 * @returns The data unit size.
463 * @param pvUser The opaque user data passed on container creation.
464 * @param pIoCtx The I/O context.
465 */
466 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxGetDataUnitSize, (void *pvUser, PVDIOCTX pIoCtx));
467
468} VDINTERFACEIOINT, *PVDINTERFACEIOINT;
469
470/**
471 * Get internal I/O interface from interface list.
472 *
473 * @return Pointer to the first internal I/O interface in the list.
474 * @param pVDIfs Pointer to the interface list.
475 */
476DECLINLINE(PVDINTERFACEIOINT) VDIfIoIntGet(PVDINTERFACE pVDIfs)
477{
478 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_IOINT);
479
480 /* Check that the interface descriptor is a progress interface. */
481 AssertMsgReturn( !pIf
482 || ( (pIf->enmInterface == VDINTERFACETYPE_IOINT)
483 && (pIf->cbSize == sizeof(VDINTERFACEIOINT))),
484 ("Not an internal I/O interface"), NULL);
485
486 return (PVDINTERFACEIOINT)pIf;
487}
488
489DECLINLINE(int) vdIfIoIntFileOpen(PVDINTERFACEIOINT pIfIoInt, const char *pszFilename,
490 uint32_t fOpen, PPVDIOSTORAGE ppStorage)
491{
492 return pIfIoInt->pfnOpen(pIfIoInt->Core.pvUser, pszFilename, fOpen, ppStorage);
493}
494
495DECLINLINE(int) vdIfIoIntFileClose(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage)
496{
497 return pIfIoInt->pfnClose(pIfIoInt->Core.pvUser, pStorage);
498}
499
500DECLINLINE(int) vdIfIoIntFileDelete(PVDINTERFACEIOINT pIfIoInt, const char *pszFilename)
501{
502 return pIfIoInt->pfnDelete(pIfIoInt->Core.pvUser, pszFilename);
503}
504
505DECLINLINE(int) vdIfIoIntFileMove(PVDINTERFACEIOINT pIfIoInt, const char *pszSrc,
506 const char *pszDst, unsigned fMove)
507{
508 return pIfIoInt->pfnMove(pIfIoInt->Core.pvUser, pszSrc, pszDst, fMove);
509}
510
511DECLINLINE(int) vdIfIoIntFileGetFreeSpace(PVDINTERFACEIOINT pIfIoInt, const char *pszFilename,
512 int64_t *pcbFree)
513{
514 return pIfIoInt->pfnGetFreeSpace(pIfIoInt->Core.pvUser, pszFilename, pcbFree);
515}
516
517DECLINLINE(int) vdIfIoIntFileGetModificationTime(PVDINTERFACEIOINT pIfIoInt, const char *pcszFilename,
518 PRTTIMESPEC pModificationTime)
519{
520 return pIfIoInt->pfnGetModificationTime(pIfIoInt->Core.pvUser, pcszFilename,
521 pModificationTime);
522}
523
524DECLINLINE(int) vdIfIoIntFileGetSize(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
525 uint64_t *pcbSize)
526{
527 return pIfIoInt->pfnGetSize(pIfIoInt->Core.pvUser, pStorage, pcbSize);
528}
529
530DECLINLINE(int) vdIfIoIntFileSetSize(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
531 uint64_t cbSize)
532{
533 return pIfIoInt->pfnSetSize(pIfIoInt->Core.pvUser, pStorage, cbSize);
534}
535
536DECLINLINE(int) vdIfIoIntFileSetAllocationSize(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
537 uint64_t cbSize, uint32_t fFlags,
538 PVDINTERFACEPROGRESS pIfProgress,
539 unsigned uPercentStart, unsigned uPercentSpan)
540{
541 return pIfIoInt->pfnSetAllocationSize(pIfIoInt->Core.pvUser, pStorage, cbSize, fFlags,
542 pIfProgress, uPercentStart, uPercentSpan);
543}
544
545DECLINLINE(int) vdIfIoIntFileWriteSync(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
546 uint64_t uOffset, const void *pvBuffer, size_t cbBuffer)
547{
548 return pIfIoInt->pfnWriteMeta(pIfIoInt->Core.pvUser, pStorage,
549 uOffset, pvBuffer, cbBuffer, NULL,
550 NULL, NULL);
551}
552
553DECLINLINE(int) vdIfIoIntFileReadSync(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
554 uint64_t uOffset, void *pvBuffer, size_t cbBuffer)
555{
556 return pIfIoInt->pfnReadMeta(pIfIoInt->Core.pvUser, pStorage,
557 uOffset, pvBuffer, cbBuffer, NULL,
558 NULL, NULL, NULL);
559}
560
561DECLINLINE(int) vdIfIoIntFileFlushSync(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage)
562{
563 return pIfIoInt->pfnFlush(pIfIoInt->Core.pvUser, pStorage, NULL, NULL, NULL);
564}
565
566DECLINLINE(int) vdIfIoIntFileReadUser(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
567 uint64_t uOffset, PVDIOCTX pIoCtx, size_t cbRead)
568{
569 return pIfIoInt->pfnReadUser(pIfIoInt->Core.pvUser, pStorage,
570 uOffset, pIoCtx, cbRead);
571}
572
573DECLINLINE(int) vdIfIoIntFileWriteUser(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
574 uint64_t uOffset, PVDIOCTX pIoCtx, size_t cbWrite,
575 PFNVDXFERCOMPLETED pfnComplete,
576 void *pvCompleteUser)
577{
578 return pIfIoInt->pfnWriteUser(pIfIoInt->Core.pvUser, pStorage,
579 uOffset, pIoCtx, cbWrite, pfnComplete,
580 pvCompleteUser);
581}
582
583DECLINLINE(int) vdIfIoIntFileReadMeta(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
584 uint64_t uOffset, void *pvBuffer,
585 size_t cbBuffer, PVDIOCTX pIoCtx,
586 PPVDMETAXFER ppMetaXfer,
587 PFNVDXFERCOMPLETED pfnComplete,
588 void *pvCompleteUser)
589{
590 return pIfIoInt->pfnReadMeta(pIfIoInt->Core.pvUser, pStorage,
591 uOffset, pvBuffer, cbBuffer, pIoCtx,
592 ppMetaXfer, pfnComplete, pvCompleteUser);
593}
594
595DECLINLINE(int) vdIfIoIntFileWriteMeta(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
596 uint64_t uOffset, void *pvBuffer,
597 size_t cbBuffer, PVDIOCTX pIoCtx,
598 PFNVDXFERCOMPLETED pfnComplete,
599 void *pvCompleteUser)
600{
601 return pIfIoInt->pfnWriteMeta(pIfIoInt->Core.pvUser, pStorage,
602 uOffset, pvBuffer, cbBuffer, pIoCtx,
603 pfnComplete, pvCompleteUser);
604}
605
606DECLINLINE(void) vdIfIoIntMetaXferRelease(PVDINTERFACEIOINT pIfIoInt, PVDMETAXFER pMetaXfer)
607{
608 pIfIoInt->pfnMetaXferRelease(pIfIoInt->Core.pvUser, pMetaXfer);
609}
610
611DECLINLINE(int) vdIfIoIntFileFlush(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
612 PVDIOCTX pIoCtx, PFNVDXFERCOMPLETED pfnComplete,
613 void *pvCompleteUser)
614{
615 return pIfIoInt->pfnFlush(pIfIoInt->Core.pvUser, pStorage, pIoCtx, pfnComplete,
616 pvCompleteUser);
617}
618
619DECLINLINE(size_t) vdIfIoIntIoCtxCopyTo(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
620 const void *pvBuffer, size_t cbBuffer)
621{
622 return pIfIoInt->pfnIoCtxCopyTo(pIfIoInt->Core.pvUser, pIoCtx, pvBuffer, cbBuffer);
623}
624
625DECLINLINE(size_t) vdIfIoIntIoCtxCopyFrom(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
626 void *pvBuffer, size_t cbBuffer)
627{
628 return pIfIoInt->pfnIoCtxCopyFrom(pIfIoInt->Core.pvUser, pIoCtx, pvBuffer, cbBuffer);
629}
630
631DECLINLINE(size_t) vdIfIoIntIoCtxSet(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
632 int ch, size_t cbSet)
633{
634 return pIfIoInt->pfnIoCtxSet(pIfIoInt->Core.pvUser, pIoCtx, ch, cbSet);
635}
636
637DECLINLINE(size_t) vdIfIoIntIoCtxSegArrayCreate(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
638 PRTSGSEG paSeg, unsigned *pcSeg,
639 size_t cbData)
640{
641 return pIfIoInt->pfnIoCtxSegArrayCreate(pIfIoInt->Core.pvUser, pIoCtx, paSeg, pcSeg, cbData);
642}
643
644DECLINLINE(bool) vdIfIoIntIoCtxIsSynchronous(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx)
645{
646 return pIfIoInt->pfnIoCtxIsSynchronous(pIfIoInt->Core.pvUser, pIoCtx);
647}
648
649DECLINLINE(bool) vdIfIoIntIoCtxIsZero(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
650 size_t cbCheck, bool fAdvance)
651{
652 return pIfIoInt->pfnIoCtxIsZero(pIfIoInt->Core.pvUser, pIoCtx, cbCheck, fAdvance);
653}
654
655DECLINLINE(size_t) vdIfIoIntIoCtxGetDataUnitSize(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx)
656{
657 return pIfIoInt->pfnIoCtxGetDataUnitSize(pIfIoInt->Core.pvUser, pIoCtx);
658}
659
660/**
661 * Interface for the metadata traverse callback.
662 *
663 * Per-operation interface. Present only for the metadata traverse callback.
664 */
665typedef struct VDINTERFACETRAVERSEMETADATA
666{
667 /**
668 * Common interface header.
669 */
670 VDINTERFACE Core;
671
672 /**
673 * Traverse callback.
674 *
675 * @returns VBox status code.
676 * @param pvUser The opaque data passed for the operation.
677 * @param pvMetadataChunk Pointer to a chunk of the image metadata.
678 * @param cbMetadataChunk Size of the metadata chunk
679 */
680 DECLR3CALLBACKMEMBER(int, pfnMetadataCallback, (void *pvUser, const void *pvMetadataChunk,
681 size_t cbMetadataChunk));
682
683} VDINTERFACETRAVERSEMETADATA, *PVDINTERFACETRAVERSEMETADATA;
684
685
686/**
687 * Get parent state interface from interface list.
688 *
689 * @return Pointer to the first parent state interface in the list.
690 * @param pVDIfs Pointer to the interface list.
691 */
692DECLINLINE(PVDINTERFACETRAVERSEMETADATA) VDIfTraverseMetadataGet(PVDINTERFACE pVDIfs)
693{
694 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_TRAVERSEMETADATA);
695
696 /* Check that the interface descriptor the correct interface. */
697 AssertMsgReturn( !pIf
698 || ( (pIf->enmInterface == VDINTERFACETYPE_TRAVERSEMETADATA)
699 && (pIf->cbSize == sizeof(VDINTERFACETRAVERSEMETADATA))),
700 ("Not a traverse metadata interface"), NULL);
701
702 return (PVDINTERFACETRAVERSEMETADATA)pIf;
703}
704
705/** @} */
706RT_C_DECLS_END
707
708#endif /* !VBOX_INCLUDED_vd_ifs_internal_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use