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