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