VirtualBox

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

Last change on this file since 98818 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.4 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 * @returns nothing.
349 * @param pvUser The opaque user data passed on container creation.
350 * @param pMetaXfer The metadata transfer handle to release.
351 */
352 DECLR3CALLBACKMEMBER(void, pfnMetaXferRelease, (void *pvUser, PVDMETAXFER pMetaXfer));
353
354 /**
355 * Initiates a flush request.
356 *
357 * @return VBox status code.
358 * @param pvUser The opaque data passed on container creation.
359 * @param pStorage The storage handle to flush.
360 * @param pIoCtx I/O context which triggered the flush.
361 * @param pfnCompleted Completion callback.
362 * @param pvCompleteUser Opaque user data passed in the completion callback.
363 *
364 * @sa VDINTERFACEIOINT::pfnReadMeta
365 */
366 DECLR3CALLBACKMEMBER(int, pfnFlush, (void *pvUser, PVDIOSTORAGE pStorage,
367 PVDIOCTX pIoCtx,
368 PFNVDXFERCOMPLETED pfnComplete,
369 void *pvCompleteUser));
370
371 /**
372 * Copies a buffer into the I/O context.
373 *
374 * @return Number of bytes copied.
375 * @param pvUser The opaque user data passed on container creation.
376 * @param pIoCtx I/O context to copy the data to.
377 * @param pvBuffer Buffer to copy.
378 * @param cbBuffer Number of bytes to copy.
379 */
380 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyTo, (void *pvUser, PVDIOCTX pIoCtx,
381 const void *pvBuffer, size_t cbBuffer));
382
383 /**
384 * Copies data from the I/O context into a buffer.
385 *
386 * @return Number of bytes copied.
387 * @param pvUser The opaque user data passed on container creation.
388 * @param pIoCtx I/O context to copy the data from.
389 * @param pvBuffer Destination buffer.
390 * @param cbBuffer Number of bytes to copy.
391 */
392 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxCopyFrom, (void *pvUser, PVDIOCTX pIoCtx,
393 void *pvBuffer, size_t cbBuffer));
394
395 /**
396 * Sets the buffer of the given context to a specific byte.
397 *
398 * @return Number of bytes set.
399 * @param pvUser The opaque user data passed on container creation.
400 * @param pIoCtx I/O context to copy the data from.
401 * @param ch The byte to set.
402 * @param cbSet Number of bytes to set.
403 */
404 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSet, (void *pvUser, PVDIOCTX pIoCtx,
405 int ch, size_t cbSet));
406
407 /**
408 * Creates a segment array from the I/O context data buffer.
409 *
410 * @returns Number of bytes the array describes.
411 * @param pvUser The opaque user data passed on container creation.
412 * @param pIoCtx I/O context to copy the data from.
413 * @param paSeg The uninitialized segment array.
414 * If NULL pcSeg will contain the number of segments needed
415 * to describe the requested amount of data.
416 * @param pcSeg The number of segments the given array has.
417 * This will hold the actual number of entries needed upon return.
418 * @param cbData Number of bytes the new array should describe.
419 */
420 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxSegArrayCreate, (void *pvUser, PVDIOCTX pIoCtx,
421 PRTSGSEG paSeg, unsigned *pcSeg,
422 size_t cbData));
423 /**
424 * Marks the given number of bytes as completed and continues the I/O context.
425 *
426 * @returns nothing.
427 * @param pvUser The opaque user data passed on container creation.
428 * @param pIoCtx The I/O context.
429 * @param rcReq Status code the request completed with.
430 * @param cbCompleted Number of bytes completed.
431 */
432 DECLR3CALLBACKMEMBER(void, pfnIoCtxCompleted, (void *pvUser, PVDIOCTX pIoCtx,
433 int rcReq, size_t cbCompleted));
434
435 /**
436 * Returns whether the given I/O context must be treated synchronously.
437 *
438 * @returns true if the I/O context must be processed synchronously
439 * false otherwise.
440 * @param pvUser The opaque user data passed on container creation.
441 * @param pIoCtx The I/O context.
442 */
443 DECLR3CALLBACKMEMBER(bool, pfnIoCtxIsSynchronous, (void *pvUser, PVDIOCTX pIoCtx));
444
445 /**
446 * Returns whether the user buffer of the I/O context is complete zero
447 * from to current position upto the given number of bytes.
448 *
449 * @returns true if the I/O context user buffer consists solely of zeros
450 * false otherwise.
451 * @param pvUser The opaque user data passed on container creation.
452 * @param pIoCtx The I/O context.
453 * @param cbCheck Number of bytes to check for zeros.
454 * @param fAdvance Flag whether to advance the buffer pointer if true
455 * is returned.
456 */
457 DECLR3CALLBACKMEMBER(bool, pfnIoCtxIsZero, (void *pvUser, PVDIOCTX pIoCtx,
458 size_t cbCheck, bool fAdvance));
459
460 /**
461 * Returns the data unit size, i.e. the smallest size for a transfer.
462 * (similar to the sector size of disks).
463 *
464 * @returns The data unit size.
465 * @param pvUser The opaque user data passed on container creation.
466 * @param pIoCtx The I/O context.
467 */
468 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxGetDataUnitSize, (void *pvUser, PVDIOCTX pIoCtx));
469
470} VDINTERFACEIOINT, *PVDINTERFACEIOINT;
471
472/**
473 * Get internal I/O interface from interface list.
474 *
475 * @return Pointer to the first internal I/O interface in the list.
476 * @param pVDIfs Pointer to the interface list.
477 */
478DECLINLINE(PVDINTERFACEIOINT) VDIfIoIntGet(PVDINTERFACE pVDIfs)
479{
480 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_IOINT);
481
482 /* Check that the interface descriptor is a progress interface. */
483 AssertMsgReturn( !pIf
484 || ( (pIf->enmInterface == VDINTERFACETYPE_IOINT)
485 && (pIf->cbSize == sizeof(VDINTERFACEIOINT))),
486 ("Not an internal I/O interface"), NULL);
487
488 return (PVDINTERFACEIOINT)pIf;
489}
490
491DECLINLINE(int) vdIfIoIntFileOpen(PVDINTERFACEIOINT pIfIoInt, const char *pszFilename,
492 uint32_t fOpen, PPVDIOSTORAGE ppStorage)
493{
494 return pIfIoInt->pfnOpen(pIfIoInt->Core.pvUser, pszFilename, fOpen, ppStorage);
495}
496
497DECLINLINE(int) vdIfIoIntFileClose(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage)
498{
499 return pIfIoInt->pfnClose(pIfIoInt->Core.pvUser, pStorage);
500}
501
502DECLINLINE(int) vdIfIoIntFileDelete(PVDINTERFACEIOINT pIfIoInt, const char *pszFilename)
503{
504 return pIfIoInt->pfnDelete(pIfIoInt->Core.pvUser, pszFilename);
505}
506
507DECLINLINE(int) vdIfIoIntFileMove(PVDINTERFACEIOINT pIfIoInt, const char *pszSrc,
508 const char *pszDst, unsigned fMove)
509{
510 return pIfIoInt->pfnMove(pIfIoInt->Core.pvUser, pszSrc, pszDst, fMove);
511}
512
513DECLINLINE(int) vdIfIoIntFileGetFreeSpace(PVDINTERFACEIOINT pIfIoInt, const char *pszFilename,
514 int64_t *pcbFree)
515{
516 return pIfIoInt->pfnGetFreeSpace(pIfIoInt->Core.pvUser, pszFilename, pcbFree);
517}
518
519DECLINLINE(int) vdIfIoIntFileGetModificationTime(PVDINTERFACEIOINT pIfIoInt, const char *pcszFilename,
520 PRTTIMESPEC pModificationTime)
521{
522 return pIfIoInt->pfnGetModificationTime(pIfIoInt->Core.pvUser, pcszFilename,
523 pModificationTime);
524}
525
526DECLINLINE(int) vdIfIoIntFileGetSize(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
527 uint64_t *pcbSize)
528{
529 return pIfIoInt->pfnGetSize(pIfIoInt->Core.pvUser, pStorage, pcbSize);
530}
531
532DECLINLINE(int) vdIfIoIntFileSetSize(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
533 uint64_t cbSize)
534{
535 return pIfIoInt->pfnSetSize(pIfIoInt->Core.pvUser, pStorage, cbSize);
536}
537
538DECLINLINE(int) vdIfIoIntFileSetAllocationSize(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
539 uint64_t cbSize, uint32_t fFlags,
540 PVDINTERFACEPROGRESS pIfProgress,
541 unsigned uPercentStart, unsigned uPercentSpan)
542{
543 return pIfIoInt->pfnSetAllocationSize(pIfIoInt->Core.pvUser, pStorage, cbSize, fFlags,
544 pIfProgress, uPercentStart, uPercentSpan);
545}
546
547DECLINLINE(int) vdIfIoIntFileWriteSync(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
548 uint64_t uOffset, const void *pvBuffer, size_t cbBuffer)
549{
550 return pIfIoInt->pfnWriteMeta(pIfIoInt->Core.pvUser, pStorage,
551 uOffset, pvBuffer, cbBuffer, NULL,
552 NULL, NULL);
553}
554
555DECLINLINE(int) vdIfIoIntFileReadSync(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
556 uint64_t uOffset, void *pvBuffer, size_t cbBuffer)
557{
558 return pIfIoInt->pfnReadMeta(pIfIoInt->Core.pvUser, pStorage,
559 uOffset, pvBuffer, cbBuffer, NULL,
560 NULL, NULL, NULL);
561}
562
563DECLINLINE(int) vdIfIoIntFileFlushSync(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage)
564{
565 return pIfIoInt->pfnFlush(pIfIoInt->Core.pvUser, pStorage, NULL, NULL, NULL);
566}
567
568DECLINLINE(int) vdIfIoIntFileReadUser(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
569 uint64_t uOffset, PVDIOCTX pIoCtx, size_t cbRead)
570{
571 return pIfIoInt->pfnReadUser(pIfIoInt->Core.pvUser, pStorage,
572 uOffset, pIoCtx, cbRead);
573}
574
575DECLINLINE(int) vdIfIoIntFileWriteUser(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
576 uint64_t uOffset, PVDIOCTX pIoCtx, size_t cbWrite,
577 PFNVDXFERCOMPLETED pfnComplete,
578 void *pvCompleteUser)
579{
580 return pIfIoInt->pfnWriteUser(pIfIoInt->Core.pvUser, pStorage,
581 uOffset, pIoCtx, cbWrite, pfnComplete,
582 pvCompleteUser);
583}
584
585DECLINLINE(int) vdIfIoIntFileReadMeta(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
586 uint64_t uOffset, void *pvBuffer,
587 size_t cbBuffer, PVDIOCTX pIoCtx,
588 PPVDMETAXFER ppMetaXfer,
589 PFNVDXFERCOMPLETED pfnComplete,
590 void *pvCompleteUser)
591{
592 return pIfIoInt->pfnReadMeta(pIfIoInt->Core.pvUser, pStorage,
593 uOffset, pvBuffer, cbBuffer, pIoCtx,
594 ppMetaXfer, pfnComplete, pvCompleteUser);
595}
596
597DECLINLINE(int) vdIfIoIntFileWriteMeta(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
598 uint64_t uOffset, void *pvBuffer,
599 size_t cbBuffer, PVDIOCTX pIoCtx,
600 PFNVDXFERCOMPLETED pfnComplete,
601 void *pvCompleteUser)
602{
603 return pIfIoInt->pfnWriteMeta(pIfIoInt->Core.pvUser, pStorage,
604 uOffset, pvBuffer, cbBuffer, pIoCtx,
605 pfnComplete, pvCompleteUser);
606}
607
608DECLINLINE(void) vdIfIoIntMetaXferRelease(PVDINTERFACEIOINT pIfIoInt, PVDMETAXFER pMetaXfer)
609{
610 pIfIoInt->pfnMetaXferRelease(pIfIoInt->Core.pvUser, pMetaXfer);
611}
612
613DECLINLINE(int) vdIfIoIntFileFlush(PVDINTERFACEIOINT pIfIoInt, PVDIOSTORAGE pStorage,
614 PVDIOCTX pIoCtx, PFNVDXFERCOMPLETED pfnComplete,
615 void *pvCompleteUser)
616{
617 return pIfIoInt->pfnFlush(pIfIoInt->Core.pvUser, pStorage, pIoCtx, pfnComplete,
618 pvCompleteUser);
619}
620
621DECLINLINE(size_t) vdIfIoIntIoCtxCopyTo(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
622 const void *pvBuffer, size_t cbBuffer)
623{
624 return pIfIoInt->pfnIoCtxCopyTo(pIfIoInt->Core.pvUser, pIoCtx, pvBuffer, cbBuffer);
625}
626
627DECLINLINE(size_t) vdIfIoIntIoCtxCopyFrom(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
628 void *pvBuffer, size_t cbBuffer)
629{
630 return pIfIoInt->pfnIoCtxCopyFrom(pIfIoInt->Core.pvUser, pIoCtx, pvBuffer, cbBuffer);
631}
632
633DECLINLINE(size_t) vdIfIoIntIoCtxSet(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
634 int ch, size_t cbSet)
635{
636 return pIfIoInt->pfnIoCtxSet(pIfIoInt->Core.pvUser, pIoCtx, ch, cbSet);
637}
638
639DECLINLINE(size_t) vdIfIoIntIoCtxSegArrayCreate(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
640 PRTSGSEG paSeg, unsigned *pcSeg,
641 size_t cbData)
642{
643 return pIfIoInt->pfnIoCtxSegArrayCreate(pIfIoInt->Core.pvUser, pIoCtx, paSeg, pcSeg, cbData);
644}
645
646DECLINLINE(bool) vdIfIoIntIoCtxIsSynchronous(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx)
647{
648 return pIfIoInt->pfnIoCtxIsSynchronous(pIfIoInt->Core.pvUser, pIoCtx);
649}
650
651DECLINLINE(bool) vdIfIoIntIoCtxIsZero(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx,
652 size_t cbCheck, bool fAdvance)
653{
654 return pIfIoInt->pfnIoCtxIsZero(pIfIoInt->Core.pvUser, pIoCtx, cbCheck, fAdvance);
655}
656
657DECLINLINE(size_t) vdIfIoIntIoCtxGetDataUnitSize(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx)
658{
659 return pIfIoInt->pfnIoCtxGetDataUnitSize(pIfIoInt->Core.pvUser, pIoCtx);
660}
661
662/**
663 * Interface for the metadata traverse callback.
664 *
665 * Per-operation interface. Present only for the metadata traverse callback.
666 */
667typedef struct VDINTERFACETRAVERSEMETADATA
668{
669 /**
670 * Common interface header.
671 */
672 VDINTERFACE Core;
673
674 /**
675 * Traverse callback.
676 *
677 * @returns VBox status code.
678 * @param pvUser The opaque data passed for the operation.
679 * @param pvMetadataChunk Pointer to a chunk of the image metadata.
680 * @param cbMetadataChunk Size of the metadata chunk
681 */
682 DECLR3CALLBACKMEMBER(int, pfnMetadataCallback, (void *pvUser, const void *pvMetadataChunk,
683 size_t cbMetadataChunk));
684
685} VDINTERFACETRAVERSEMETADATA, *PVDINTERFACETRAVERSEMETADATA;
686
687
688/**
689 * Get parent state interface from interface list.
690 *
691 * @return Pointer to the first parent state interface in the list.
692 * @param pVDIfs Pointer to the interface list.
693 */
694DECLINLINE(PVDINTERFACETRAVERSEMETADATA) VDIfTraverseMetadataGet(PVDINTERFACE pVDIfs)
695{
696 PVDINTERFACE pIf = VDInterfaceGet(pVDIfs, VDINTERFACETYPE_TRAVERSEMETADATA);
697
698 /* Check that the interface descriptor the correct interface. */
699 AssertMsgReturn( !pIf
700 || ( (pIf->enmInterface == VDINTERFACETYPE_TRAVERSEMETADATA)
701 && (pIf->cbSize == sizeof(VDINTERFACETRAVERSEMETADATA))),
702 ("Not a traverse metadata interface"), NULL);
703
704 return (PVDINTERFACETRAVERSEMETADATA)pIf;
705}
706
707/** @} */
708RT_C_DECLS_END
709
710#endif /* !VBOX_INCLUDED_vd_ifs_internal_h */
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