VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VBoxHDD-newInternal.h@ 11421

Last change on this file since 11421 was 11421, checked in by vboxsync, 17 years ago

Storage/VBoxHDD-new: Added backend info, listing the supported file extensions. Implemented a testcase anf fixed a small bug which it found.

  • Property svn:eol-style set to native
File size: 19.5 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_newInternal_h__
22
23
24#include <VBox/pdm.h>
25#include <VBox/VBoxHDD-new.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 * Check if a file is valid for the backend.
67 *
68 * @returns VBox status code.
69 * @param pszFilename Name of the image file.
70 */
71 DECLR3CALLBACKMEMBER(int, pfnCheckIfValid, (const char *pszFilename));
72
73 /**
74 * Open a disk image.
75 *
76 * @returns VBox status code.
77 * @param pszFilename Name of the image file to open. Guaranteed to be available and
78 * unchanged during the lifetime of this image.
79 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
80 * @param pInterfaces Pointer to the first element of supported interfaces of the caller.
81 * @param ppvBackendData Opaque state data for this image.
82 */
83 DECLR3CALLBACKMEMBER(int, pfnOpen, (const char *pszFilename, unsigned uOpenFlags,
84 PVDINTERFACE pInterfaces, void **ppvBackendData));
85
86 /**
87 * Create a disk image.
88 *
89 * @returns VBox status code.
90 * @param pszFilename Name of the image file to create. Guaranteed to be available and
91 * unchanged during the lifetime of this image.
92 * @param enmType Image type. Both base and diff image types are valid.
93 * @param cbSize Image size in bytes.
94 * @param uImageFlags Flags specifying special image features.
95 * @param pszComment Pointer to image comment. NULL is ok.
96 * @param pPCHSGeometry Physical drive geometry CHS <= (16383,16,255).
97 * @param pLCHSGeometry Logical drive geometry CHS <= (1024,255,63).
98 * @param pUuid New UUID of the image. Not NULL.
99 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
100 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
101 * @param pvUser User argument for the progress callback.
102 * @param uPercentStart Starting value for progress percentage.
103 * @param uPercentSpan Span for varying progress percentage.
104 * @param pInterfaces Pointer to the supported interfaces of the caller.
105 * @param ppvBackendData Opaque state data for this image.
106 */
107 DECLR3CALLBACKMEMBER(int, pfnCreate, (const char *pszFilename, VDIMAGETYPE enmType, uint64_t cbSize, unsigned uImageFlags, const char *pszComment, PCPDMMEDIAGEOMETRY pPCHSGeometry, PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, unsigned uOpenFlags, PFNVMPROGRESS pfnProgress, void *pvUser, unsigned uPercentStart, unsigned uPercentSpan, PVDINTERFACE pInterfaces, void **ppvBackendData));
108
109 /**
110 * Rename a disk image. Only needs to work as long as the operating
111 * system's rename file functionality is usable. If an attempt is made to
112 * rename an image to a location on another disk/filesystem, this function
113 * may just fail with an appropriate error code (not changing the opened
114 * image data at all). Also works only on images which actually refer to
115 * files (and not for raw disk images).
116 *
117 * @returns VBox status code.
118 * @param pvBackendData Opaque state data for this image.
119 * @param pszFilename New name of the image file. Guaranteed to be available and
120 * unchanged during the lifetime of this image.
121 */
122 DECLR3CALLBACKMEMBER(int, pfnRename, (void *pvBackendData, const char *pszFilename));
123
124 /**
125 * Close a disk image.
126 *
127 * @returns VBox status code.
128 * @param pvBackendData Opaque state data for this image.
129 * @param fDelete If true, delete the image from the host disk.
130 */
131 DECLR3CALLBACKMEMBER(int, pfnClose, (void *pvBackendData, bool fDelete));
132
133 /**
134 * Read data from a disk image. The area read never crosses a block
135 * boundary.
136 *
137 * @returns VBox status code.
138 * @returns VINF_VDI_BLOCK_FREE if this image contains no data for this block.
139 * @returns VINF_VDI_BLOCK_ZERO if this image contains a zero data block.
140 * @param pvBackendData Opaque state data for this image.
141 * @param off Offset to start reading from.
142 * @param pvBuf Where to store the read bits.
143 * @param cbRead Number of bytes to read.
144 * @param pcbActuallyRead Pointer to returned number of bytes read.
145 */
146 DECLR3CALLBACKMEMBER(int, pfnRead, (void *pvBackendData, uint64_t off, void *pvBuf, size_t cbRead, size_t *pcbActuallyRead));
147
148 /**
149 * Write data to a disk image. The area written never crosses a block
150 * boundary.
151 *
152 * @returns VBox status code.
153 * @returns VINF_VDI_BLOCK_FREE if this image contains no data for this block and
154 * this is not a full-block write. The write must be repeated with
155 * the correct amount of prefix/postfix data read from the images below
156 * in the image stack. This might not be the most convenient interface,
157 * but it works with arbitrary block sizes, especially when the image
158 * stack uses different block sizes.
159 * @param pvBackendData Opaque state data for this image.
160 * @param off Offset to start writing to.
161 * @param pvBuf Where to retrieve the written bits.
162 * @param cbWrite Number of bytes to write.
163 * @param pcbWriteProcess Pointer to returned number of bytes that could
164 * be processed. In case the function returned
165 * VINF_VDI_BLOCK_FREE this is the number of bytes
166 * that could be written in a full block write,
167 * when prefixed/postfixed by the appropriate
168 * amount of (previously read) padding data.
169 * @param pcbPreRead Pointer to the returned amount of data that must
170 * be prefixed to perform a full block write.
171 * @param pcbPostRead Pointer to the returned amount of data that must
172 * be postfixed to perform a full block write.
173 * @param fWrite Flags which affect write behavior. Combination
174 * of the VD_WRITE_* flags.
175 */
176 DECLR3CALLBACKMEMBER(int, pfnWrite, (void *pvBackendData, uint64_t off, const void *pvBuf, size_t cbWrite, size_t *pcbWriteProcess, size_t *pcbPreRead, size_t *pcbPostRead, unsigned fWrite));
177
178 /**
179 * Flush data to disk.
180 *
181 * @returns VBox status code.
182 * @param pvBackendData Opaque state data for this image.
183 */
184 DECLR3CALLBACKMEMBER(int, pfnFlush, (void *pvBackendData));
185
186 /**
187 * Get the version of a disk image.
188 *
189 * @returns version of disk image.
190 * @param pvBackendData Opaque state data for this image.
191 */
192 DECLR3CALLBACKMEMBER(unsigned, pfnGetVersion, (void *pvBackendData));
193
194 /**
195 * Get the type information for a disk image.
196 *
197 * @returns VBox status code.
198 * @param pvBackendData Opaque state data for this image.
199 * @param penmType Image type of this image.
200 */
201 DECLR3CALLBACKMEMBER(int, pfnGetImageType, (void *pvBackendData, PVDIMAGETYPE penmType));
202
203 /**
204 * Get the capacity of a disk image.
205 *
206 * @returns size of disk image in bytes.
207 * @param pvBackendData Opaque state data for this image.
208 */
209 DECLR3CALLBACKMEMBER(uint64_t, pfnGetSize, (void *pvBackendData));
210
211 /**
212 * Get the file size of a disk image.
213 *
214 * @returns size of disk image in bytes.
215 * @param pvBackendData Opaque state data for this image.
216 */
217 DECLR3CALLBACKMEMBER(uint64_t, pfnGetFileSize, (void *pvBackendData));
218
219 /**
220 * Get virtual disk PCHS geometry stored in a disk image.
221 *
222 * @returns VBox status code.
223 * @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the image.
224 * @param pvBackendData Opaque state data for this image.
225 * @param pPCHSGeometry Where to store the geometry. Not NULL.
226 */
227 DECLR3CALLBACKMEMBER(int, pfnGetPCHSGeometry, (void *pvBackendData, PPDMMEDIAGEOMETRY pPCHSGeometry));
228
229 /**
230 * Set virtual disk PCHS geometry stored in a disk image.
231 * Only called if geometry is different than before.
232 *
233 * @returns VBox status code.
234 * @param pvBackendData Opaque state data for this image.
235 * @param pPCHSGeometry Where to load the geometry from. Not NULL.
236 */
237 DECLR3CALLBACKMEMBER(int, pfnSetPCHSGeometry, (void *pvBackendData, PCPDMMEDIAGEOMETRY pPCHSGeometry));
238
239 /**
240 * Get virtual disk LCHS geometry stored in a disk image.
241 *
242 * @returns VBox status code.
243 * @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the image.
244 * @param pvBackendData Opaque state data for this image.
245 * @param pLCHSGeometry Where to store the geometry. Not NULL.
246 */
247 DECLR3CALLBACKMEMBER(int, pfnGetLCHSGeometry, (void *pvBackendData, PPDMMEDIAGEOMETRY pLCHSGeometry));
248
249 /**
250 * Set virtual disk LCHS geometry stored in a disk image.
251 * Only called if geometry is different than before.
252 *
253 * @returns VBox status code.
254 * @param pvBackendData Opaque state data for this image.
255 * @param pLCHSGeometry Where to load the geometry from. Not NULL.
256 */
257 DECLR3CALLBACKMEMBER(int, pfnSetLCHSGeometry, (void *pvBackendData, PCPDMMEDIAGEOMETRY pLCHSGeometry));
258
259 /**
260 * Get the image flags of a disk image.
261 *
262 * @returns image flags of disk image.
263 * @param pvBackendData Opaque state data for this image.
264 */
265 DECLR3CALLBACKMEMBER(unsigned, pfnGetImageFlags, (void *pvBackendData));
266
267 /**
268 * Get the open flags of a disk image.
269 *
270 * @returns open flags of disk image.
271 * @param pvBackendData Opaque state data for this image.
272 */
273 DECLR3CALLBACKMEMBER(unsigned, pfnGetOpenFlags, (void *pvBackendData));
274
275 /**
276 * Set the open flags of a disk image. May cause the image to be locked
277 * in a different mode or be reopened (which can fail).
278 *
279 * @returns VBox status code.
280 * @param pvBackendData Opaque state data for this image.
281 * @param uOpenFlags New open flags for this image.
282 */
283 DECLR3CALLBACKMEMBER(int, pfnSetOpenFlags, (void *pvBackendData, unsigned uOpenFlags));
284
285 /**
286 * Get comment of a disk image.
287 *
288 * @returns VBox status code.
289 * @param pvBackendData Opaque state data for this image.
290 * @param pszComment Where to store the comment.
291 * @param cbComment Size of the comment buffer.
292 */
293 DECLR3CALLBACKMEMBER(int, pfnGetComment, (void *pvBackendData, char *pszComment, size_t cbComment));
294
295 /**
296 * Set comment of a disk image.
297 *
298 * @returns VBox status code.
299 * @param pvBackendData Opaque state data for this image.
300 * @param pszComment Where to get the comment from. NULL resets comment.
301 * The comment is silently truncated if the image format
302 * limit is exceeded.
303 */
304 DECLR3CALLBACKMEMBER(int, pfnSetComment, (void *pvBackendData, const char *pszComment));
305
306 /**
307 * Get UUID of a disk image.
308 *
309 * @returns VBox status code.
310 * @param pvBackendData Opaque state data for this image.
311 * @param pUuid Where to store the image UUID.
312 */
313 DECLR3CALLBACKMEMBER(int, pfnGetUuid, (void *pvBackendData, PRTUUID pUuid));
314
315 /**
316 * Set UUID of a disk image.
317 *
318 * @returns VBox status code.
319 * @param pvBackendData Opaque state data for this image.
320 * @param pUuid Where to get the image UUID from.
321 */
322 DECLR3CALLBACKMEMBER(int, pfnSetUuid, (void *pvBackendData, PCRTUUID pUuid));
323
324 /**
325 * Get last modification 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 modification UUID.
330 */
331 DECLR3CALLBACKMEMBER(int, pfnGetModificationUuid, (void *pvBackendData, PRTUUID pUuid));
332
333 /**
334 * Set last modification 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 modification UUID from.
339 */
340 DECLR3CALLBACKMEMBER(int, pfnSetModificationUuid, (void *pvBackendData, PCRTUUID pUuid));
341
342 /**
343 * Get parent 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 parent image UUID.
348 */
349 DECLR3CALLBACKMEMBER(int, pfnGetParentUuid, (void *pvBackendData, PRTUUID pUuid));
350
351 /**
352 * Set parent 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 parent image UUID from.
357 */
358 DECLR3CALLBACKMEMBER(int, pfnSetParentUuid, (void *pvBackendData, PCRTUUID pUuid));
359
360 /**
361 * Get parent modification 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 modification UUID.
366 */
367 DECLR3CALLBACKMEMBER(int, pfnGetParentModificationUuid, (void *pvBackendData, PRTUUID pUuid));
368
369 /**
370 * Set parent modification 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 modification UUID from.
375 */
376 DECLR3CALLBACKMEMBER(int, pfnSetParentModificationUuid, (void *pvBackendData, PCRTUUID pUuid));
377
378 /**
379 * Dump information about a disk image.
380 *
381 * @param pvBackendData Opaque state data for this image.
382 */
383 DECLR3CALLBACKMEMBER(void, pfnDump, (void *pvBackendData));
384
385 /**
386 * Get a time stamp of a disk image.
387 *
388 * @returns VBox status code.
389 * @param pvBackendData Opaque state data for this image.
390 * @param pTimeStamp Where to store the time stamp.
391 */
392 DECLR3CALLBACKMEMBER(int, pfnGetTimeStamp, (void *pvBackendData, PRTTIMESPEC pTimeStamp));
393
394 /**
395 * Get the parent time stamp of a disk image.
396 *
397 * @returns VBox status code.
398 * @param pvBackendData Opaque state data for this image.
399 * @param pTimeStamp Where to store the time stamp.
400 */
401 DECLR3CALLBACKMEMBER(int, pfnGetParentTimeStamp, (void *pvBackendData, PRTTIMESPEC pTimeStamp));
402
403 /**
404 * Set the parent 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 get the time stamp from.
409 */
410 DECLR3CALLBACKMEMBER(int, pfnSetParentTimeStamp, (void *pvBackendData, PCRTTIMESPEC pTimeStamp));
411
412 /**
413 * Get the relative path to parent image.
414 *
415 * @returns VBox status code.
416 * @param pvBackendData Opaque state data for this image.
417 * @param pszParentFilename Where to store the path.
418 */
419 DECLR3CALLBACKMEMBER(int, pfnGetParentFilename, (void *pvBackendData, char **ppszParentFilename));
420
421 /**
422 * Set the relative path to parent image.
423 *
424 * @returns VBox status code.
425 * @param pvBackendData Opaque state data for this image.
426 * @param pszParentFilename Where to get the path from.
427 */
428 DECLR3CALLBACKMEMBER(int, pfnSetParentFilename, (void *pvBackendData, const char *pszParentFilename));
429
430 /**
431 * Return whether asynchronous I/O operations are supported for this image.
432 *
433 * @returns true if asynchronous I/O is supported
434 * false otherwise.
435 * @param pvBackendData Opaque state data for this image.
436 */
437 DECLR3CALLBACKMEMBER(bool, pfnIsAsyncIOSupported, (void *pvBackendData));
438
439 /**
440 * Start an asynchronous read request.
441 *
442 * @returns VBox status code.
443 * @param pvBackendData Opaque state data for this image.
444 * @param uOffset The offset of the virtual disk to read from.
445 * @param cbRead How many bytes to read.
446 * @param paSeg Pointer to the segment array.
447 * @param cSeg Number of segments.
448 * @param pvUser Opaque user data.
449 */
450 DECLR3CALLBACKMEMBER(int, pfnAsyncRead, (void *pvBackendData, uint64_t uOffset, size_t cbRead,
451 PPDMDATASEG paSeg, unsigned cSeg, void *pvUser));
452
453 /**
454 * Start an asynchronous write request.
455 *
456 * @returns VBox status code.
457 * @param pvBackendData Opaque state data for this image.
458 * @param uOffset The offset of the virtual disk to write to.
459 * @param cbWrite How many bytes to write.
460 * @param paSeg Pointer to the segment array.
461 * @param cSeg Number of segments.
462 * @param pvUser Oaque user data-
463 */
464 DECLR3CALLBACKMEMBER(int, pfnAsyncWrite, (void *pvBackendData, uint64_t uOffset, size_t cbWrite,
465 PPDMDATASEG paSeg, unsigned cSeg, void *pvUser));
466
467} VBOXHDDBACKEND;
468
469/** Pointer to VD backend. */
470typedef VBOXHDDBACKEND *PVBOXHDDBACKEND;
471
472/** Constant pointer to VD backend. */
473typedef const VBOXHDDBACKEND *PCVBOXHDDBACKEND;
474
475/** Initialization entry point. */
476typedef DECLCALLBACK(int) VBOXHDDFORMATLOAD(PVBOXHDDBACKEND *ppBackendTable);
477typedef VBOXHDDFORMATLOAD *PFNVBOXHDDFORMATLOAD;
478#define VBOX_HDDFORMAT_LOAD_NAME "VBoxHDDFormatLoad"
479
480/** The prefix to identify Storage Plugins. */
481#define VBOX_HDDFORMAT_PLUGIN_PREFIX "VBoxHDD"
482/** The size of the prefix excluding the '\0' terminator. */
483#define VBOX_HDDFORMAT_PLUGIN_PREFIX_LENGTH (sizeof(VBOX_HDDFORMAT_PLUGIN_PREFIX)-1)
484
485#endif
Note: See TracBrowser for help on using the repository browser.

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