VirtualBox

source: vbox/trunk/include/VBox/VBoxHDD.h@ 1

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.9 KB
Line 
1/** @file
2 * VBox HDD Container, Virtual Disk Image (VDI) API.
3 */
4
5/*
6 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21#ifndef __VBox_VBoxHDD_h__
22#define __VBox_VBoxHDD_h__
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <VBox/param.h>
27#include <VBox/pdm.h>
28#include <VBox/vmapi.h>
29
30__BEGIN_DECLS
31
32#ifdef IN_RING0
33# error "There are no VDI APIs available in Ring-0 Host Context!"
34#endif
35
36/** @defgroup grp_vbox_hdd VBox HDD Container
37 * @{
38 */
39
40/** Image info, not handled anyhow.
41 * Must be less than 64 bytes in length, including the trailing 0.
42 */
43#define VDI_IMAGE_FILE_INFO "<<< InnoTek VirtualBox Disk Image >>>\n"
44
45/** Current image major version. */
46#define VDI_IMAGE_VERSION_MAJOR (0x0001)
47/** Current image minor version. */
48#define VDI_IMAGE_VERSION_MINOR (0x0001)
49/** Current image version. */
50#define VDI_IMAGE_VERSION ((VDI_IMAGE_VERSION_MAJOR << 16) | VDI_IMAGE_VERSION_MINOR)
51
52/** Get major version from combined version. */
53#define VDI_GET_VERSION_MAJOR(uVer) ((uVer) >> 16)
54/** Get minor version from combined version. */
55#define VDI_GET_VERSION_MINOR(uVer) ((uVer) & 0xffff)
56
57/** @name VDI image types
58 * @{ */
59typedef enum VDIIMAGETYPE
60{
61 /** Normal dynamically growing base image file. */
62 VDI_IMAGE_TYPE_NORMAL = 1,
63 /** Preallocated base image file of a fixed size. */
64 VDI_IMAGE_TYPE_FIXED,
65 /** Dynamically growing image file for undo/commit changes support. */
66 VDI_IMAGE_TYPE_UNDO,
67 /** Dynamically growing image file for differencing support. */
68 VDI_IMAGE_TYPE_DIFF,
69
70 /** First valid image type value. */
71 VDI_IMAGE_TYPE_FIRST = VDI_IMAGE_TYPE_NORMAL,
72 /** Last valid image type value. */
73 VDI_IMAGE_TYPE_LAST = VDI_IMAGE_TYPE_DIFF
74} VDIIMAGETYPE;
75/** Pointer to VDI image type. */
76typedef VDIIMAGETYPE *PVDIIMAGETYPE;
77/** @} */
78
79/** @name VDI image flags
80 * @{ */
81/** No flags. */
82#define VDI_IMAGE_FLAGS_NONE (0x00)
83/** Fill new blocks with zeroes while expanding image file. */
84#define VDI_IMAGE_FLAGS_ZERO_EXPAND (0x01)
85
86/** Mask of valid image flags. */
87#define VDI_IMAGE_FLAGS_MASK (VDI_IMAGE_FLAGS_NONE | VDI_IMAGE_FLAGS_ZERO_EXPAND)
88
89/** Default image flags. */
90#define VDI_IMAGE_FLAGS_DEFAULT (VDI_IMAGE_FLAGS_NONE)
91/** @} */
92
93/** @name VDI image open mode flags
94 * @{
95 */
96/** Try to open image in read/write exclusive access mode if possible, or in read-only elsewhere. */
97#define VDI_OPEN_FLAGS_NORMAL (0)
98/** Open image in read-only mode with sharing access with others. */
99#define VDI_OPEN_FLAGS_READONLY (1)
100/** Mask of valid flags. */
101#define VDI_OPEN_FLAGS_MASK (VDI_OPEN_FLAGS_NORMAL | VDI_OPEN_FLAGS_READONLY)
102/** @}*/
103
104/**
105 * VBox VDI disk Container main structure.
106 */
107/* Forward declaration, VDIDISK structure is visible only inside VDI module. */
108struct VDIDISK;
109typedef struct VDIDISK VDIDISK;
110typedef VDIDISK *PVDIDISK;
111
112/**
113 * Creates a new base image file.
114 *
115 * @returns VBox status code.
116 * @param pszFilename Name of the image file to create.
117 * @param enmType Image type, only base image types are acceptable.
118 * @param cbSize Image size in bytes.
119 * @param pszComment Pointer to image comment. NULL is ok.
120 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
121 * @param pvUser User argument for the progress callback.
122 */
123IDER3DECL(int) VDICreateBaseImage(const char *pszFilename, VDIIMAGETYPE enmType, uint64_t cbSize, const char *pszComment,
124 PFNVMPROGRESS pfnProgress, void *pvUser);
125
126/**
127 * Creates a differencing dynamically growing image file for specified parent image.
128 *
129 * @returns VBox status code.
130 * @param pszFilename Name of the differencing image file to create.
131 * @param pszParent Name of the parent image file. May be base or diff image type.
132 * @param pszComment Pointer to image comment. NULL is ok.
133 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
134 * @param pvUser User argument for the progress callback.
135 */
136IDER3DECL(int) VDICreateDifferenceImage(const char *pszFilename, const char *pszParent, const char *pszComment,
137 PFNVMPROGRESS pfnProgress, void *pvUser);
138
139/**
140 * Checks if image is available and not broken, returns some useful image parameters if requested.
141 *
142 * @returns VBox status code.
143 * @param pszFilename Name of the image file to check.
144 * @param puVersion Where to store the version of image. NULL is ok.
145 * @param penmType Where to store the type of image. NULL is ok.
146 * @param pcbSize Where to store the size of image in bytes. NULL is ok.
147 * @param pUuid Where to store the uuid of image creation. NULL is ok.
148 * @param pParentUuid Where to store the uuid of the parent image (if any). NULL is ok.
149 * @param pszComment Where to store the comment string of image. NULL is ok.
150 * @param cbComment The size of pszComment buffer. 0 is ok.
151 */
152IDER3DECL(int) VDICheckImage(const char *pszFilename,
153 unsigned *puVersion,
154 PVDIIMAGETYPE penmType,
155 uint64_t *pcbSize,
156 PRTUUID pUuid,
157 PRTUUID pParentUuid,
158 char *pszComment,
159 unsigned cbComment);
160
161/**
162 * Changes an image's comment string.
163 *
164 * @returns VBox status code.
165 * @param pszFilename Name of the image file to operate on.
166 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
167 */
168IDER3DECL(int) VDISetImageComment(const char *pszFilename, const char *pszComment);
169
170/**
171 * Deletes a valid image file. Fails if specified file is not an image.
172 *
173 * @returns VBox status code.
174 * @param pszFilename Name of the image file to check.
175 */
176IDER3DECL(int) VDIDeleteImage(const char *pszFilename);
177
178/**
179 * Makes a copy of image file with a new (other) creation uuid.
180 *
181 * @returns VBox status code.
182 * @param pszDstFilename Name of the image file to create.
183 * @param pszSrcFilename Name of the image file to copy from.
184 * @param pszComment Pointer to image comment. If NULL, the comment
185 * will be copied from the source image.
186 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
187 * @param pvUser User argument for the progress callback.
188 */
189IDER3DECL(int) VDICopyImage(const char *pszDstFilename, const char *pszSrcFilename, const char *pszComment,
190 PFNVMPROGRESS pfnProgress, void *pvUser);
191
192/**
193 * Converts image file from older VDI formats to current one.
194 *
195 * @returns VBox status code.
196 * @param pszFilename Name of the image file to convert.
197 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
198 * @param pvUser User argument for the progress callback.
199 */
200IDER3DECL(int) VDIConvertImage(const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
201
202/**
203 * Shrinks growing image file by removing zeroed data blocks.
204 *
205 * @returns VBox status code.
206 * @param pszFilename Name of the image file to shrink.
207 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
208 * @param pvUser User argument for the progress callback.
209 */
210IDER3DECL(int) VDIShrinkImage(const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
211
212/**
213 * Queries the image's UUID and parent UUIDs.
214 *
215 * @returns VBox status code.
216 * @param pszFilename Name of the image file to operate on.
217 * @param pUuid Where to store image UUID (can be NULL).
218 * @param pModificationUuid Where to store modification UUID (can be NULL).
219 * @param pParentUuuid Where to store parent UUID (can be NULL).
220 * @param pParentModificationUuid Where to store parent modification UUID (can be NULL).
221 */
222IDER3DECL(int) VDIGetImageUUIDs(const char *pszFilename,
223 PRTUUID pUuid, PRTUUID pModificationUuid,
224 PRTUUID pParentUuid, PRTUUID pParentModificationUuid);
225
226
227/**
228 * Changes the image's UUID and parent UUIDs.
229 *
230 * @returns VBox status code.
231 * @param pszFilename Name of the image file to operate on.
232 * @param pUuid Optional parameter, new UUID of the image.
233 * @param pModificationUuid Optional parameter, new modification UUID of the image.
234 * @param pParentUuuid Optional parameter, new parent UUID of the image.
235 * @param pParentModificationUuid Optional parameter, new parent modification UUID of the image.
236 */
237IDER3DECL(int) VDISetImageUUIDs(const char *pszFilename,
238 PCRTUUID pUuid, PCRTUUID pModificationUuid,
239 PCRTUUID pParentUuid, PCRTUUID pParentModificationUuid);
240
241/**
242 * Merges two images having a parent/child relationship (both directions).
243 *
244 * @returns VBox status code.
245 * @param pszFilenameFrom Name of the image file to merge from.
246 * @param pszFilenameTo Name of the image file to merge into.
247 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
248 * @param pvUser User argument for the progress callback.
249 */
250IDER3DECL(int) VDIMergeImage(const char *pszFilenameFrom, const char *pszFilenameTo,
251 PFNVMPROGRESS pfnProgress, void *pvUser);
252
253
254/**
255 * Allocates and initializes an empty VDI HDD container.
256 * No image files are opened.
257 *
258 * @returns Pointer to newly created empty HDD container.
259 * @returns NULL on failure, typically out of memory.
260 */
261IDER3DECL(PVDIDISK) VDIDiskCreate(void);
262
263/**
264 * Destroys the VDI HDD container. If container has opened image files they will be closed.
265 *
266 * @param pDisk Pointer to VDI HDD container.
267 */
268IDER3DECL(void) VDIDiskDestroy(PVDIDISK pDisk);
269
270/**
271 * Opens an image file.
272 *
273 * The first opened image file in a HDD container must have a base image type,
274 * others (next opened images) must be a differencing or undo images.
275 * Linkage is checked for differencing image to be in consistence with the previously opened image.
276 * When a next differencing image is opened and the last image was opened in read/write access
277 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
278 * other processes to use images in read-only mode too.
279 *
280 * Note that the image can be opened in read-only mode if a read/write open is not possible.
281 * Use VDIDiskIsReadOnly to check open mode.
282 *
283 * @returns VBox status code.
284 * @param pDisk Pointer to VDI HDD container.
285 * @param pszFilename Name of the image file to open.
286 * @param fOpen Image file open mode, see VDI_OPEN_FLAGS_* constants.
287 */
288IDER3DECL(int) VDIDiskOpenImage(PVDIDISK pDisk, const char *pszFilename, unsigned fOpen);
289
290/**
291 * Creates and opens a new differencing image file in HDD container.
292 * See comments for VDIDiskOpenImage function about differencing images.
293 *
294 * @returns VBox status code.
295 * @param pDisk Pointer to VDI HDD container.
296 * @param pszFilename Name of the image file to create and open.
297 * @param pszComment Pointer to image comment. NULL is ok.
298 * @param pfnProgress Progress callback. Optional. NULL if not to be used.
299 * @param pvUser User argument for the progress callback.
300 */
301IDER3DECL(int) VDIDiskCreateOpenDifferenceImage(PVDIDISK pDisk, const char *pszFilename, const char *pszComment,
302 PFNVMPROGRESS pfnProgress, void *pvUser);
303
304/**
305 * Closes the last opened image file in the HDD container. Leaves all changes inside it.
306 * If previous image file was opened in read-only mode (that is normal) and closing image
307 * was opened in read-write mode (the whole disk was in read-write mode) - the previous image
308 * will be reopened in read/write mode.
309 *
310 * @param pDisk Pointer to VDI HDD container.
311 */
312IDER3DECL(void) VDIDiskCloseImage(PVDIDISK pDisk);
313
314/**
315 * Closes all opened image files in HDD container.
316 *
317 * @param pDisk Pointer to VDI HDD container.
318 */
319IDER3DECL(void) VDIDiskCloseAllImages(PVDIDISK pDisk);
320
321/**
322 * Commits last opened differencing/undo image file of the HDD container to previous image.
323 * If the previous image file was opened in read-only mode (that must be always so) it is reopened
324 * as read/write to do commit operation.
325 * After successfull commit the previous image file again reopened in read-only mode, last opened
326 * image file is cleared of data and remains open and active in HDD container.
327 * If you want to delete image after commit you must do it manually by VDIDiskCloseImage and
328 * VDIDeleteImage calls.
329 *
330 * Note that in case of unrecoverable error all images of HDD container will be closed.
331 *
332 * @returns VBox status code.
333 * @param pDisk Pointer to VDI HDD container.
334 * @param pfnProgress Progress callback. Optional.
335 * @param pvUser User argument for the progress callback.
336 */
337IDER3DECL(int) VDIDiskCommitLastDiff(PVDIDISK pDisk, PFNVMPROGRESS pfnProgress, void *pvUser);
338
339/**
340 * Get read/write mode of VDI HDD.
341 *
342 * @returns Disk ReadOnly status.
343 * @returns true if no one VDI image is opened in HDD container.
344 */
345IDER3DECL(bool) VDIDiskIsReadOnly(PVDIDISK pDisk);
346
347/**
348 * Get total disk size of the VDI HDD container.
349 *
350 * @returns Virtual disk size in bytes.
351 * @returns 0 if no one VDI image is opened in HDD container.
352 */
353IDER3DECL(uint64_t) VDIDiskGetSize(PVDIDISK pDisk);
354
355/**
356 * Get block size of the VDI HDD container.
357 *
358 * @returns VDI image block size in bytes.
359 * @returns 0 if no one VDI image is opened in HDD container.
360 */
361IDER3DECL(unsigned) VDIDiskGetBlockSize(PVDIDISK pDisk);
362
363/**
364 * Get working buffer size of the VDI HDD container.
365 *
366 * @returns Working buffer size in bytes.
367 */
368IDER3DECL(unsigned) VDIDiskGetBufferSize(PVDIDISK pDisk);
369
370/**
371 * Get virtual disk geometry stored in image file.
372 *
373 * @returns VBox status code.
374 * @returns VERR_VDI_NOT_OPENED if no one VDI image is opened in HDD container.
375 * @returns VERR_VDI_GEOMETRY_NOT_SET if no geometry present in the HDD container.
376 * @param pDisk Pointer to VDI HDD container.
377 * @param pcCylinders Where to store the number of cylinders. NULL is ok.
378 * @param pcHeads Where to store the number of heads. NULL is ok.
379 * @param pcSectors Where to store the number of sectors. NULL is ok.
380 */
381IDER3DECL(int) VDIDiskGetGeometry(PVDIDISK pDisk, unsigned *pcCylinders, unsigned *pcHeads, unsigned *pcSectors);
382
383/**
384 * Store virtual disk geometry into base image file of HDD container.
385 *
386 * Note that in case of unrecoverable error all images of HDD container will be closed.
387 *
388 * @returns VBox status code.
389 * @returns VERR_VDI_NOT_OPENED if no one VDI image is opened in HDD container.
390 * @param pDisk Pointer to VDI HDD container.
391 * @param cCylinders Number of cylinders.
392 * @param cHeads Number of heads.
393 * @param cSectors Number of sectors.
394 */
395IDER3DECL(int) VDIDiskSetGeometry(PVDIDISK pDisk, unsigned cCylinders, unsigned cHeads, unsigned cSectors);
396
397/**
398 * Get virtual disk translation mode stored in image file.
399 *
400 * @returns VBox status code.
401 * @returns VERR_VDI_NOT_OPENED if no one VDI image is opened in HDD container.
402 * @param pDisk Pointer to VDI HDD container.
403 * @param penmTranslation Where to store the translation mode (see pdm.h).
404 */
405IDER3DECL(int) VDIDiskGetTranslation(PVDIDISK pDisk, PPDMBIOSTRANSLATION penmTranslation);
406
407/**
408 * Store virtual disk translation mode into base image file of HDD container.
409 *
410 * Note that in case of unrecoverable error all images of HDD container will be closed.
411 *
412 * @returns VBox status code.
413 * @returns VERR_VDI_NOT_OPENED if no one VDI image is opened in HDD container.
414 * @param pDisk Pointer to VDI HDD container.
415 * @param enmTranslation Translation mode (see pdm.h).
416 */
417IDER3DECL(int) VDIDiskSetTranslation(PVDIDISK pDisk, PDMBIOSTRANSLATION enmTranslation);
418
419/**
420 * Get number of opened images in HDD container.
421 *
422 * @returns Number of opened images for HDD container. 0 if no images has been opened.
423 * @param pDisk Pointer to VDI HDD container.
424 */
425IDER3DECL(int) VDIDiskGetImagesCount(PVDIDISK pDisk);
426
427/**
428 * Get version of opened image of HDD container.
429 *
430 * @returns VBox status code.
431 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
432 * @param pDisk Pointer to VDI HDD container.
433 * @param nImage Image number, counts from 0. 0 is always base image of container.
434 * @param puVersion Where to store the image version.
435 */
436IDER3DECL(int) VDIDiskGetImageVersion(PVDIDISK pDisk, int nImage, unsigned *puVersion);
437
438/**
439 * Get type of opened image of HDD container.
440 *
441 * @returns VBox status code.
442 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
443 * @param pDisk Pointer to VDI HDD container.
444 * @param nImage Image number, counts from 0. 0 is always base image of container.
445 * @param penmType Where to store the image type.
446 */
447IDER3DECL(int) VDIDiskGetImageType(PVDIDISK pDisk, int nImage, PVDIIMAGETYPE penmType);
448
449/**
450 * Get flags of opened image of HDD container.
451 *
452 * @returns VBox status code.
453 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
454 * @param pDisk Pointer to VDI HDD container.
455 * @param nImage Image number, counts from 0. 0 is always base image of container.
456 * @param pfFlags Where to store the image flags.
457 */
458IDER3DECL(int) VDIDiskGetImageFlags(PVDIDISK pDisk, int nImage, unsigned *pfFlags);
459
460/**
461 * Get filename of opened image of HDD container.
462 *
463 * @returns VBox status code.
464 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
465 * @returns VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
466 * @param pDisk Pointer to VDI HDD container.
467 * @param nImage Image number, counts from 0. 0 is always base image of container.
468 * @param pszFilename Where to store the image file name.
469 * @param cbFilename Size of buffer pszFilename points to.
470 */
471IDER3DECL(int) VDIDiskGetImageFilename(PVDIDISK pDisk, int nImage, char *pszFilename, unsigned cbFilename);
472
473/**
474 * Get the comment line of opened image of HDD container.
475 *
476 * @returns VBox status code.
477 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
478 * @returns VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
479 * @param pDisk Pointer to VDI HDD container.
480 * @param nImage Image number, counts from 0. 0 is always base image of container.
481 * @param pszComment Where to store the comment string of image. NULL is ok.
482 * @param cbComment The size of pszComment buffer. 0 is ok.
483 */
484IDER3DECL(int) VDIDiskGetImageComment(PVDIDISK pDisk, int nImage, char *pszComment, unsigned cbComment);
485
486/**
487 * Get Uuid of opened image of HDD container.
488 *
489 * @returns VBox status code.
490 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
491 * @param pDisk Pointer to VDI HDD container.
492 * @param nImage Image number, counts from 0. 0 is always base image of container.
493 * @param pUuid Where to store the image creation uuid.
494 */
495IDER3DECL(int) VDIDiskGetImageUuid(PVDIDISK pDisk, int nImage, PRTUUID pUuid);
496
497/**
498 * Get last modification Uuid of opened image of HDD container.
499 *
500 * @returns VBox status code.
501 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
502 * @param pDisk Pointer to VDI HDD container.
503 * @param nImage Image number, counts from 0. 0 is always base image of container.
504 * @param pUuid Where to store the image modification uuid.
505 */
506IDER3DECL(int) VDIDiskGetImageModificationUuid(PVDIDISK pDisk, int nImage, PRTUUID pUuid);
507
508/**
509 * Get Uuid of opened image's parent image.
510 *
511 * @returns VBox status code.
512 * @returns VERR_VDI_IMAGE_NOT_FOUND if image with specified number was not opened.
513 * @param pDisk Pointer to VDI HDD container.
514 * @param nImage Image number, counts from 0. 0 is always base image of the container.
515 * @param pUuid Where to store the image creation uuid.
516 */
517IDER3DECL(int) VDIDiskGetParentImageUuid(PVDIDISK pDisk, int nImage, PRTUUID pUuid);
518
519/**
520 * Read data from virtual HDD.
521 *
522 * @returns VBox status code.
523 * @param pDisk Pointer to VDI HDD container.
524 * @param offStart Offset of first reading byte from start of disk.
525 * @param pvBuf Pointer to buffer for reading data.
526 * @param cbToRead Number of bytes to read.
527 */
528IDER3DECL(int) VDIDiskRead(PVDIDISK pDisk, uint64_t offStart, void *pvBuf, unsigned cbToRead);
529
530/**
531 * Write data to virtual HDD.
532 *
533 * @returns VBox status code.
534 * @param pDisk Pointer to VDI HDD container.
535 * @param offStart Offset of first writing byte from start of HDD.
536 * @param pvBuf Pointer to buffer of writing data.
537 * @param cbToWrite Number of bytes to write.
538 */
539IDER3DECL(int) VDIDiskWrite(PVDIDISK pDisk, uint64_t offStart, const void *pvBuf, unsigned cbToWrite);
540
541
542
543/**
544 * Debug helper - dumps all opened images of HDD container into the log file.
545 *
546 * @param pDisk Pointer to VDI HDD container.
547 */
548IDER3DECL(void) VDIDiskDumpImages(PVDIDISK pDisk);
549
550__END_DECLS
551
552/** @} */
553
554#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