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