VirtualBox

source: vbox/trunk/include/VBox/VBoxHDD-Plugin.h@ 29567

Last change on this file since 29567 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
File size: 23.8 KB
Line 
1/** @file
2 * Internal hard disk format support API for VBoxHDD.
3 */
4
5/*
6 * Copyright (C) 2006-2010 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 __VBoxHDD_Internal_h__
27
28
29#include <VBox/pdm.h>
30#include <VBox/VBoxHDD.h>
31
32
33/** @name VBox HDD backend write flags
34 * @{
35 */
36/** Do not allocate a new block on this write. This is just an advisory
37 * flag. The backend may still decide in some circumstances that it wants
38 * to ignore this flag (which may cause extra dynamic image expansion). */
39#define VD_WRITE_NO_ALLOC RT_BIT(1)
40/** @}*/
41
42
43/**
44 * Image format backend interface used by VBox HDD Container implementation.
45 */
46typedef struct VBOXHDDBACKEND
47{
48 /**
49 * The name of the backend (constant string).
50 */
51 const char *pszBackendName;
52
53 /**
54 * The size of the structure.
55 */
56 uint32_t cbSize;
57
58 /**
59 * The capabilities of the backend.
60 */
61 uint64_t uBackendCaps;
62
63 /**
64 * Pointer to a NULL-terminated array of strings, containing the supported
65 * file extensions. Note that some backends do not work on files, so this
66 * pointer may just contain NULL.
67 */
68 const char * const *papszFileExtensions;
69
70 /**
71 * Pointer to an array of structs describing each supported config key.
72 * Terminated by a NULL config key. Note that some backends do not support
73 * the configuration interface, so this pointer may just contain NULL.
74 * Mandatory if the backend sets VD_CAP_CONFIG.
75 */
76 PCVDCONFIGINFO paConfigInfo;
77
78 /**
79 * Handle of loaded plugin library, NIL_RTLDRMOD for static backends.
80 */
81 RTLDRMOD hPlugin;
82
83 /**
84 * Check if a file is valid for the backend.
85 *
86 * @returns VBox status code.
87 * @param pszFilename Name of the image file.
88 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
89 */
90 DECLR3CALLBACKMEMBER(int, pfnCheckIfValid, (const char *pszFilename, PVDINTERFACE pVDIfsDisk));
91
92 /**
93 * Open a disk image.
94 *
95 * @returns VBox status code.
96 * @param pszFilename Name of the image file to open. Guaranteed to be available and
97 * unchanged during the lifetime of this image.
98 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
99 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
100 * @param pVDIfsImage Pointer to the per-image VD interface list.
101 * @param ppvBackendData Opaque state data for this image.
102 */
103 DECLR3CALLBACKMEMBER(int, pfnOpen, (const char *pszFilename, unsigned uOpenFlags,
104 PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
105 void **ppvBackendData));
106
107 /**
108 * Create a disk image.
109 *
110 * @returns VBox status code.
111 * @param pszFilename Name of the image file to create. Guaranteed to be available and
112 * unchanged during the lifetime of this image.
113 * @param cbSize Image size in bytes.
114 * @param uImageFlags Flags specifying special image features.
115 * @param pszComment Pointer to image comment. NULL is ok.
116 * @param pPCHSGeometry Physical drive geometry CHS <= (16383,16,255).
117 * @param pLCHSGeometry Logical drive geometry CHS <= (1024,255,63).
118 * @param pUuid New UUID of the image. Not NULL.
119 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
120 * @param uPercentStart Starting value for progress percentage.
121 * @param uPercentSpan Span for varying progress percentage.
122 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
123 * @param pVDIfsImage Pointer to the per-image VD interface list.
124 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
125 * @param ppvBackendData Opaque state data for this image.
126 */
127 DECLR3CALLBACKMEMBER(int, pfnCreate, (const char *pszFilename, uint64_t cbSize,
128 unsigned uImageFlags, const char *pszComment,
129 PCPDMMEDIAGEOMETRY pPCHSGeometry,
130 PCPDMMEDIAGEOMETRY pLCHSGeometry,
131 PCRTUUID pUuid, unsigned uOpenFlags,
132 unsigned uPercentStart, unsigned uPercentSpan,
133 PVDINTERFACE pVDIfsDisk,
134 PVDINTERFACE pVDIfsImage,
135 PVDINTERFACE pVDIfsOperation,
136 void **ppvBackendData));
137
138 /**
139 * Rename a disk image. Only needs to work as long as the operating
140 * system's rename file functionality is usable. If an attempt is made to
141 * rename an image to a location on another disk/filesystem, this function
142 * may just fail with an appropriate error code (not changing the opened
143 * image data at all). Also works only on images which actually refer to
144 * files (and not for raw disk images).
145 *
146 * @returns VBox status code.
147 * @param pvBackendData Opaque state data for this image.
148 * @param pszFilename New name of the image file. Guaranteed to be available and
149 * unchanged during the lifetime of this image.
150 */
151 DECLR3CALLBACKMEMBER(int, pfnRename, (void *pvBackendData, const char *pszFilename));
152
153 /**
154 * Close a disk image.
155 *
156 * @returns VBox status code.
157 * @param pvBackendData Opaque state data for this image.
158 * @param fDelete If true, delete the image from the host disk.
159 */
160 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvBackendData, bool fDelete));
161
162 /**
163 * Read data from a disk image. The area read never crosses a block
164 * boundary.
165 *
166 * @returns VBox status code.
167 * @returns VERR_VD_BLOCK_FREE if this image contains no data for this block.
168 * @param pvBackendData Opaque state data for this image.
169 * @param uOffset Offset to start reading from.
170 * @param pvBuf Where to store the read bits.
171 * @param cbRead Number of bytes to read.
172 * @param pcbActuallyRead Pointer to returned number of bytes read.
173 */
174 DECLR3CALLBACKMEMBER(int, pfnRead, (void *pvBackendData, uint64_t uOffset, void *pvBuf,
175 size_t cbRead, size_t *pcbActuallyRead));
176
177 /**
178 * Write data to a disk image. The area written never crosses a block
179 * boundary.
180 *
181 * @returns VBox status code.
182 * @returns VERR_VD_BLOCK_FREE if this image contains no data for this block and
183 * this is not a full-block write. The write must be repeated with
184 * the correct amount of prefix/postfix data read from the images below
185 * in the image stack. This might not be the most convenient interface,
186 * but it works with arbitrary block sizes, especially when the image
187 * stack uses different block sizes.
188 * @param pvBackendData Opaque state data for this image.
189 * @param uOffset Offset to start writing to.
190 * @param pvBuf Where to retrieve the written bits.
191 * @param cbWrite Number of bytes to write.
192 * @param pcbWriteProcess Pointer to returned number of bytes that could
193 * be processed. In case the function returned
194 * VERR_VD_BLOCK_FREE this is the number of bytes
195 * that could be written in a full block write,
196 * when prefixed/postfixed by the appropriate
197 * amount of (previously read) padding data.
198 * @param pcbPreRead Pointer to the returned amount of data that must
199 * be prefixed to perform a full block write.
200 * @param pcbPostRead Pointer to the returned amount of data that must
201 * be postfixed to perform a full block write.
202 * @param fWrite Flags which affect write behavior. Combination
203 * of the VD_WRITE_* flags.
204 */
205 DECLR3CALLBACKMEMBER(int, pfnWrite, (void *pvBackendData, uint64_t uOffset,
206 const void *pvBuf, size_t cbWrite,
207 size_t *pcbWriteProcess, size_t *pcbPreRead,
208 size_t *pcbPostRead, unsigned fWrite));
209
210 /**
211 * Flush data to disk.
212 *
213 * @returns VBox status code.
214 * @param pvBackendData Opaque state data for this image.
215 */
216 DECLR3CALLBACKMEMBER(int, pfnFlush, (void *pvBackendData));
217
218 /**
219 * Get the version of a disk image.
220 *
221 * @returns version of disk image.
222 * @param pvBackendData Opaque state data for this image.
223 */
224 DECLR3CALLBACKMEMBER(unsigned, pfnGetVersion, (void *pvBackendData));
225
226 /**
227 * Get the capacity of a disk image.
228 *
229 * @returns size of disk image in bytes.
230 * @param pvBackendData Opaque state data for this image.
231 */
232 DECLR3CALLBACKMEMBER(uint64_t, pfnGetSize, (void *pvBackendData));
233
234 /**
235 * Get the file size of a disk image.
236 *
237 * @returns size of disk image in bytes.
238 * @param pvBackendData Opaque state data for this image.
239 */
240 DECLR3CALLBACKMEMBER(uint64_t, pfnGetFileSize, (void *pvBackendData));
241
242 /**
243 * Get virtual disk PCHS geometry stored in a disk image.
244 *
245 * @returns VBox status code.
246 * @returns VERR_VD_GEOMETRY_NOT_SET if no geometry present in the image.
247 * @param pvBackendData Opaque state data for this image.
248 * @param pPCHSGeometry Where to store the geometry. Not NULL.
249 */
250 DECLR3CALLBACKMEMBER(int, pfnGetPCHSGeometry, (void *pvBackendData, PPDMMEDIAGEOMETRY pPCHSGeometry));
251
252 /**
253 * Set virtual disk PCHS geometry stored in a disk image.
254 * Only called if geometry is different than before.
255 *
256 * @returns VBox status code.
257 * @param pvBackendData Opaque state data for this image.
258 * @param pPCHSGeometry Where to load the geometry from. Not NULL.
259 */
260 DECLR3CALLBACKMEMBER(int, pfnSetPCHSGeometry, (void *pvBackendData, PCPDMMEDIAGEOMETRY pPCHSGeometry));
261
262 /**
263 * Get virtual disk LCHS geometry stored in a disk image.
264 *
265 * @returns VBox status code.
266 * @returns VERR_VD_GEOMETRY_NOT_SET if no geometry present in the image.
267 * @param pvBackendData Opaque state data for this image.
268 * @param pLCHSGeometry Where to store the geometry. Not NULL.
269 */
270 DECLR3CALLBACKMEMBER(int, pfnGetLCHSGeometry, (void *pvBackendData, PPDMMEDIAGEOMETRY pLCHSGeometry));
271
272 /**
273 * Set virtual disk LCHS geometry stored in a disk image.
274 * Only called if geometry is different than before.
275 *
276 * @returns VBox status code.
277 * @param pvBackendData Opaque state data for this image.
278 * @param pLCHSGeometry Where to load the geometry from. Not NULL.
279 */
280 DECLR3CALLBACKMEMBER(int, pfnSetLCHSGeometry, (void *pvBackendData, PCPDMMEDIAGEOMETRY pLCHSGeometry));
281
282 /**
283 * Get the image flags of a disk image.
284 *
285 * @returns image flags of disk image.
286 * @param pvBackendData Opaque state data for this image.
287 */
288 DECLR3CALLBACKMEMBER(unsigned, pfnGetImageFlags, (void *pvBackendData));
289
290 /**
291 * Get the open flags of a disk image.
292 *
293 * @returns open flags of disk image.
294 * @param pvBackendData Opaque state data for this image.
295 */
296 DECLR3CALLBACKMEMBER(unsigned, pfnGetOpenFlags, (void *pvBackendData));
297
298 /**
299 * Set the open flags of a disk image. May cause the image to be locked
300 * in a different mode or be reopened (which can fail).
301 *
302 * @returns VBox status code.
303 * @param pvBackendData Opaque state data for this image.
304 * @param uOpenFlags New open flags for this image.
305 */
306 DECLR3CALLBACKMEMBER(int, pfnSetOpenFlags, (void *pvBackendData, unsigned uOpenFlags));
307
308 /**
309 * Get comment of a disk image.
310 *
311 * @returns VBox status code.
312 * @param pvBackendData Opaque state data for this image.
313 * @param pszComment Where to store the comment.
314 * @param cbComment Size of the comment buffer.
315 */
316 DECLR3CALLBACKMEMBER(int, pfnGetComment, (void *pvBackendData, char *pszComment, size_t cbComment));
317
318 /**
319 * Set comment of a disk image.
320 *
321 * @returns VBox status code.
322 * @param pvBackendData Opaque state data for this image.
323 * @param pszComment Where to get the comment from. NULL resets comment.
324 * The comment is silently truncated if the image format
325 * limit is exceeded.
326 */
327 DECLR3CALLBACKMEMBER(int, pfnSetComment, (void *pvBackendData, const char *pszComment));
328
329 /**
330 * Get UUID of a disk image.
331 *
332 * @returns VBox status code.
333 * @param pvBackendData Opaque state data for this image.
334 * @param pUuid Where to store the image UUID.
335 */
336 DECLR3CALLBACKMEMBER(int, pfnGetUuid, (void *pvBackendData, PRTUUID pUuid));
337
338 /**
339 * Set UUID of a disk image.
340 *
341 * @returns VBox status code.
342 * @param pvBackendData Opaque state data for this image.
343 * @param pUuid Where to get the image UUID from.
344 */
345 DECLR3CALLBACKMEMBER(int, pfnSetUuid, (void *pvBackendData, PCRTUUID pUuid));
346
347 /**
348 * Get last modification UUID of a disk image.
349 *
350 * @returns VBox status code.
351 * @param pvBackendData Opaque state data for this image.
352 * @param pUuid Where to store the image modification UUID.
353 */
354 DECLR3CALLBACKMEMBER(int, pfnGetModificationUuid, (void *pvBackendData, PRTUUID pUuid));
355
356 /**
357 * Set last modification UUID of a disk image.
358 *
359 * @returns VBox status code.
360 * @param pvBackendData Opaque state data for this image.
361 * @param pUuid Where to get the image modification UUID from.
362 */
363 DECLR3CALLBACKMEMBER(int, pfnSetModificationUuid, (void *pvBackendData, PCRTUUID pUuid));
364
365 /**
366 * Get parent UUID of a disk image.
367 *
368 * @returns VBox status code.
369 * @param pvBackendData Opaque state data for this image.
370 * @param pUuid Where to store the parent image UUID.
371 */
372 DECLR3CALLBACKMEMBER(int, pfnGetParentUuid, (void *pvBackendData, PRTUUID pUuid));
373
374 /**
375 * Set parent UUID of a disk image.
376 *
377 * @returns VBox status code.
378 * @param pvBackendData Opaque state data for this image.
379 * @param pUuid Where to get the parent image UUID from.
380 */
381 DECLR3CALLBACKMEMBER(int, pfnSetParentUuid, (void *pvBackendData, PCRTUUID pUuid));
382
383 /**
384 * Get parent modification UUID of a disk image.
385 *
386 * @returns VBox status code.
387 * @param pvBackendData Opaque state data for this image.
388 * @param pUuid Where to store the parent image modification UUID.
389 */
390 DECLR3CALLBACKMEMBER(int, pfnGetParentModificationUuid, (void *pvBackendData, PRTUUID pUuid));
391
392 /**
393 * Set parent modification UUID of a disk image.
394 *
395 * @returns VBox status code.
396 * @param pvBackendData Opaque state data for this image.
397 * @param pUuid Where to get the parent image modification UUID from.
398 */
399 DECLR3CALLBACKMEMBER(int, pfnSetParentModificationUuid, (void *pvBackendData, PCRTUUID pUuid));
400
401 /**
402 * Dump information about a disk image.
403 *
404 * @param pvBackendData Opaque state data for this image.
405 */
406 DECLR3CALLBACKMEMBER(void, pfnDump, (void *pvBackendData));
407
408 /**
409 * Get a time stamp of a disk image.
410 *
411 * @returns VBox status code.
412 * @param pvBackendData Opaque state data for this image.
413 * @param pTimeStamp Where to store the time stamp.
414 */
415 DECLR3CALLBACKMEMBER(int, pfnGetTimeStamp, (void *pvBackendData, PRTTIMESPEC pTimeStamp));
416
417 /**
418 * Get the parent time stamp of a disk image.
419 *
420 * @returns VBox status code.
421 * @param pvBackendData Opaque state data for this image.
422 * @param pTimeStamp Where to store the time stamp.
423 */
424 DECLR3CALLBACKMEMBER(int, pfnGetParentTimeStamp, (void *pvBackendData, PRTTIMESPEC pTimeStamp));
425
426 /**
427 * Set the parent time stamp of a disk image.
428 *
429 * @returns VBox status code.
430 * @param pvBackendData Opaque state data for this image.
431 * @param pTimeStamp Where to get the time stamp from.
432 */
433 DECLR3CALLBACKMEMBER(int, pfnSetParentTimeStamp, (void *pvBackendData, PCRTTIMESPEC pTimeStamp));
434
435 /**
436 * Get the relative path to parent image.
437 *
438 * @returns VBox status code.
439 * @param pvBackendData Opaque state data for this image.
440 * @param pszParentFilename Where to store the path.
441 */
442 DECLR3CALLBACKMEMBER(int, pfnGetParentFilename, (void *pvBackendData, char **ppszParentFilename));
443
444 /**
445 * Set the relative path to parent image.
446 *
447 * @returns VBox status code.
448 * @param pvBackendData Opaque state data for this image.
449 * @param pszParentFilename Where to get the path from.
450 */
451 DECLR3CALLBACKMEMBER(int, pfnSetParentFilename, (void *pvBackendData, const char *pszParentFilename));
452
453 /**
454 * Return whether asynchronous I/O operations are supported for this image.
455 *
456 * @returns true if asynchronous I/O is supported
457 * false otherwise.
458 * @param pvBackendData Opaque state data for this image.
459 */
460 DECLR3CALLBACKMEMBER(bool, pfnIsAsyncIOSupported, (void *pvBackendData));
461
462 /**
463 * Start an asynchronous read request.
464 *
465 * @returns VBox status code.
466 * @param pvBackendData Opaque state data for this image.
467 * @param uOffset The offset of the virtual disk to read from.
468 * @param cbRead How many bytes to read.
469 * @param pIoCtx I/O context associated with this request.
470 * @param pcbActuallyRead Pointer to returned number of bytes read.
471 */
472 DECLR3CALLBACKMEMBER(int, pfnAsyncRead, (void *pvBackendData, uint64_t uOffset, size_t cbRead,
473 PVDIOCTX pIoCtx, size_t *pcbActuallyRead));
474
475 /**
476 * Start an asynchronous write request.
477 *
478 * @returns VBox status code.
479 * @param pvBackendData Opaque state data for this image.
480 * @param uOffset The offset of the virtual disk to write to.
481 * @param cbWrite How many bytes to write.
482 * @param pIoCtx I/O context associated with this request.
483 * @param pcbWriteProcess Pointer to returned number of bytes that could
484 * be processed. In case the function returned
485 * VERR_VD_BLOCK_FREE this is the number of bytes
486 * that could be written in a full block write,
487 * when prefixed/postfixed by the appropriate
488 * amount of (previously read) padding data.
489 * @param pcbPreRead Pointer to the returned amount of data that must
490 * be prefixed to perform a full block write.
491 * @param pcbPostRead Pointer to the returned amount of data that must
492 * be postfixed to perform a full block write.
493 * @param fWrite Flags which affect write behavior. Combination
494 * of the VD_WRITE_* flags.
495 */
496 DECLR3CALLBACKMEMBER(int, pfnAsyncWrite, (void *pvBackendData, uint64_t uOffset, size_t cbWrite,
497 PVDIOCTX pIoCtx,
498 size_t *pcbWriteProcess, size_t *pcbPreRead,
499 size_t *pcbPostRead, unsigned fWrite));
500
501 /**
502 * Flush data to disk.
503 *
504 * @returns VBox status code.
505 * @param pvBackendData Opaque state data for this image.
506 * @param pIoCtx I/O context associated with this request.
507 */
508 DECLR3CALLBACKMEMBER(int, pfnAsyncFlush, (void *pvBackendData, PVDIOCTX pIoCtx));
509
510 /** Returns a human readable hard disk location string given a
511 * set of hard disk configuration keys. The returned string is an
512 * equivalent of the full file path for image-based hard disks.
513 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
514 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
515
516 /** Returns a human readable hard disk name string given a
517 * set of hard disk configuration keys. The returned string is an
518 * equivalent of the file name part in the full file path for
519 * image-based hard disks. Mandatory for backends with no
520 * VD_CAP_FILE and NULL otherwise. */
521 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
522
523 /**
524 * Compact the image. The pointer may be NULL, indicating that this
525 * isn't supported yet (for file-based images) or not necessary.
526 *
527 * @returns VBox status code.
528 * @returns VERR_NOT_SUPPORTED if this image cannot be compacted yet.
529 * @param pvBackendData Opaque state data for this image.
530 * @param uPercentStart Starting value for progress percentage.
531 * @param uPercentSpan Span for varying progress percentage.
532 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
533 * @param pVDIfsImage Pointer to the per-image VD interface list.
534 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
535 */
536 DECLR3CALLBACKMEMBER(int, pfnCompact, (void *pvBackendData,
537 unsigned uPercentStart, unsigned uPercentSpan,
538 PVDINTERFACE pVDIfsDisk,
539 PVDINTERFACE pVDIfsImage,
540 PVDINTERFACE pVDIfsOperation));
541
542} VBOXHDDBACKEND;
543
544/** Pointer to VD backend. */
545typedef VBOXHDDBACKEND *PVBOXHDDBACKEND;
546
547/** Constant pointer to VD backend. */
548typedef const VBOXHDDBACKEND *PCVBOXHDDBACKEND;
549
550/** @copydoc VBOXHDDBACKEND::pfnComposeLocation */
551DECLINLINE(int) genericFileComposeLocation(PVDINTERFACE pConfig, char **pszLocation)
552{
553 *pszLocation = NULL;
554 return VINF_SUCCESS;
555}
556/** @copydoc VBOXHDDBACKEND::pfnComposeName */
557DECLINLINE(int) genericFileComposeName(PVDINTERFACE pConfig, char **pszName)
558{
559 *pszName = NULL;
560 return VINF_SUCCESS;
561}
562
563/** Initialization entry point. */
564typedef DECLCALLBACK(int) VBOXHDDFORMATLOAD(PVBOXHDDBACKEND *ppBackendTable);
565typedef VBOXHDDFORMATLOAD *PFNVBOXHDDFORMATLOAD;
566#define VBOX_HDDFORMAT_LOAD_NAME "VBoxHDDFormatLoad"
567
568/** The prefix to identify Storage Plugins. */
569#define VBOX_HDDFORMAT_PLUGIN_PREFIX "VBoxHDD"
570/** The size of the prefix excluding the '\\0' terminator. */
571#define VBOX_HDDFORMAT_PLUGIN_PREFIX_LENGTH (sizeof(VBOX_HDDFORMAT_PLUGIN_PREFIX)-1)
572
573#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette