VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VBoxHDD-Internal.h@ 17995

Last change on this file since 17995 was 17970, checked in by vboxsync, 16 years ago

API/HardDisk, Storage/VBoxHDD, Frontend/VBoxManage: eliminated base image type, which led to much unnecessary code duplication. Was triggered by VBoxManage finally being able to create all image variants the backends can support.

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