VirtualBox

source: vbox/trunk/include/VBox/vd.h@ 55466

Last change on this file since 55466 was 54835, checked in by vboxsync, 10 years ago

Encryption: Add a way to retrieve the encryption settings without providing the password. Returns only the used cipher and the password ID

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 59.1 KB
Line 
1/** @file
2 * VBox HDD Container API.
3 */
4
5/*
6 * Copyright (C) 2006-2014 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_VD_h
27#define ___VBox_VD_h
28
29#include <iprt/assert.h>
30#include <iprt/string.h>
31#include <iprt/mem.h>
32#include <iprt/file.h>
33#include <iprt/net.h>
34#include <iprt/sg.h>
35#include <iprt/vfs.h>
36#include <VBox/cdefs.h>
37#include <VBox/types.h>
38#include <VBox/err.h>
39#include <VBox/vd-ifs.h>
40
41RT_C_DECLS_BEGIN
42
43#ifdef IN_RING0
44# error "There are no VBox HDD Container APIs available in Ring-0 Host Context!"
45#endif
46
47/** @defgroup grp_vd VBox HDD Container
48 * @{
49 */
50
51/** Current VMDK image version. */
52#define VMDK_IMAGE_VERSION (0x0001)
53
54/** Current VDI image major version. */
55#define VDI_IMAGE_VERSION_MAJOR (0x0001)
56/** Current VDI image minor version. */
57#define VDI_IMAGE_VERSION_MINOR (0x0001)
58/** Current VDI image version. */
59#define VDI_IMAGE_VERSION ((VDI_IMAGE_VERSION_MAJOR << 16) | VDI_IMAGE_VERSION_MINOR)
60
61/** Get VDI major version from combined version. */
62#define VDI_GET_VERSION_MAJOR(uVer) ((uVer) >> 16)
63/** Get VDI minor version from combined version. */
64#define VDI_GET_VERSION_MINOR(uVer) ((uVer) & 0xffff)
65
66/** Placeholder for specifying the last opened image. */
67#define VD_LAST_IMAGE 0xffffffffU
68
69/** Placeholder for VDCopyEx to indicate that the image content is unknown. */
70#define VD_IMAGE_CONTENT_UNKNOWN 0xffffffffU
71
72/** @name VBox HDD container image flags
73 * Same values as MediumVariant API enum.
74 * @{
75 */
76/** No flags. */
77#define VD_IMAGE_FLAGS_NONE (0)
78/** Fixed image. */
79#define VD_IMAGE_FLAGS_FIXED (0x10000)
80/** Diff image. Mutually exclusive with fixed image. */
81#define VD_IMAGE_FLAGS_DIFF (0x20000)
82/** VMDK: Split image into 2GB extents. */
83#define VD_VMDK_IMAGE_FLAGS_SPLIT_2G (0x0001)
84/** VMDK: Raw disk image (giving access to a number of host partitions). */
85#define VD_VMDK_IMAGE_FLAGS_RAWDISK (0x0002)
86/** VMDK: stream optimized image, read only. */
87#define VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED (0x0004)
88/** VMDK: ESX variant, use in addition to other flags. */
89#define VD_VMDK_IMAGE_FLAGS_ESX (0x0008)
90/** VDI: Fill new blocks with zeroes while expanding image file. Only valid
91 * for newly created images, never set for opened existing images. */
92#define VD_VDI_IMAGE_FLAGS_ZERO_EXPAND (0x0100)
93
94/** Mask of valid image flags for VMDK. */
95#define VD_VMDK_IMAGE_FLAGS_MASK ( VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE \
96 | VD_VMDK_IMAGE_FLAGS_SPLIT_2G | VD_VMDK_IMAGE_FLAGS_RAWDISK \
97 | VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED | VD_VMDK_IMAGE_FLAGS_ESX)
98
99/** Mask of valid image flags for VDI. */
100#define VD_VDI_IMAGE_FLAGS_MASK (VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE | VD_VDI_IMAGE_FLAGS_ZERO_EXPAND)
101
102/** Mask of all valid image flags for all formats. */
103#define VD_IMAGE_FLAGS_MASK (VD_VMDK_IMAGE_FLAGS_MASK | VD_VDI_IMAGE_FLAGS_MASK)
104
105/** Default image flags. */
106#define VD_IMAGE_FLAGS_DEFAULT (VD_IMAGE_FLAGS_NONE)
107/** @} */
108
109/** @name VD image repair flags
110 * @{
111 */
112/** Don't repair the image but check what needs to be done. */
113#define VD_REPAIR_DRY_RUN RT_BIT_32(0)
114
115/** Mask of all valid repair flags. */
116#define VD_REPAIR_FLAGS_MASK (VD_REPAIR_DRY_RUN)
117/** @} */
118
119/** @name VD image VFS file flags
120 * @{
121 */
122/** Destroy the VD disk container when the VFS file is released. */
123#define VD_VFSFILE_DESTROY_ON_RELEASE RT_BIT_32(0)
124
125/** Mask of all valid repair flags. */
126#define VD_VFSFILE_FLAGS_MASK (VD_VFSFILE_DESTROY_ON_RELEASE)
127/** @} */
128
129/**
130 * Auxiliary type for describing partitions on raw disks. The entries must be
131 * in ascending order (as far as uStart is concerned), and must not overlap.
132 * Note that this does not correspond 1:1 to partitions, it is describing the
133 * general meaning of contiguous areas on the disk.
134 */
135typedef struct VBOXHDDRAWPARTDESC
136{
137 /** Device to use for this partition/data area. Can be the disk device if
138 * the offset field is set appropriately. If this is NULL, then this
139 * partition will not be accessible to the guest. The size of the data area
140 * must still be set correctly. */
141 const char *pszRawDevice;
142 /** Pointer to the partitioning info. NULL means this is a regular data
143 * area on disk, non-NULL denotes data which should be copied to the
144 * partition data overlay. */
145 const void *pvPartitionData;
146 /** Offset where the data starts in this device. */
147 uint64_t uStartOffset;
148 /** Offset where the data starts in the disk. */
149 uint64_t uStart;
150 /** Size of the data area. */
151 uint64_t cbData;
152} VBOXHDDRAWPARTDESC, *PVBOXHDDRAWPARTDESC;
153
154/**
155 * Auxiliary data structure for difference between GPT and MBR
156 * disks.
157 */
158typedef enum VBOXHDDPARTTYPE
159{
160 MBR,
161 GPT
162} VBOXHDDPARTTYPE;
163
164/**
165 * Auxiliary data structure for creating raw disks.
166 */
167typedef struct VBOXHDDRAW
168{
169 /** Signature for structure. Must be 'R', 'A', 'W', '\\0'. Actually a trick
170 * to make logging of the comment string produce sensible results. */
171 char szSignature[4];
172 /** Flag whether access to full disk should be given (ignoring the
173 * partition information below). */
174 bool fRawDisk;
175 /** Filename for the raw disk. Ignored for partitioned raw disks.
176 * For Linux e.g. /dev/sda, and for Windows e.g. \\\\.\\PhysicalDisk0. */
177 const char *pszRawDisk;
178 /** Number of entries in the partition descriptor array. */
179 unsigned cPartDescs;
180 /** Pointer to the partition descriptor array. */
181 PVBOXHDDRAWPARTDESC pPartDescs;
182 /** Partitioning type of the disk */
183 VBOXHDDPARTTYPE uPartitioningType;
184
185} VBOXHDDRAW, *PVBOXHDDRAW;
186
187
188/** @name VBox HDD container image open mode flags
189 * @{
190 */
191/** Try to open image in read/write exclusive access mode if possible, or in read-only elsewhere. */
192#define VD_OPEN_FLAGS_NORMAL 0
193/** Open image in read-only mode with sharing access with others. */
194#define VD_OPEN_FLAGS_READONLY RT_BIT(0)
195/** Honor zero block writes instead of ignoring them whenever possible.
196 * This is not supported by all formats. It is silently ignored in this case. */
197#define VD_OPEN_FLAGS_HONOR_ZEROES RT_BIT(1)
198/** Honor writes of the same data instead of ignoring whenever possible.
199 * This is handled generically, and is only meaningful for differential image
200 * formats. It is silently ignored otherwise. */
201#define VD_OPEN_FLAGS_HONOR_SAME RT_BIT(2)
202/** Do not perform the base/diff image check on open. This does NOT imply
203 * opening the image as readonly (would break e.g. adding UUIDs to VMDK files
204 * created by other products). Images opened with this flag should only be
205 * used for querying information, and nothing else. */
206#define VD_OPEN_FLAGS_INFO RT_BIT(3)
207/** Open image for asynchronous access. Only available if VD_CAP_ASYNC_IO is
208 * set. VDOpen fails with VERR_NOT_SUPPORTED if this operation is not supported for
209 * this kind of image. */
210#define VD_OPEN_FLAGS_ASYNC_IO RT_BIT(4)
211/** Allow sharing of the image for writable images. May be ignored if the
212 * format backend doesn't support this type of concurrent access. */
213#define VD_OPEN_FLAGS_SHAREABLE RT_BIT(5)
214/** Ask the backend to switch to sequential accesses if possible. Opening
215 * will not fail if it cannot do this, the flag will be simply ignored. */
216#define VD_OPEN_FLAGS_SEQUENTIAL RT_BIT(6)
217/** Allow the discard operation if supported. Only available if VD_CAP_DISCARD
218 * is set. VDOpen fails with VERR_VD_DISCARD_NOT_SUPPORTED if discarding is not
219 * supported. */
220#define VD_OPEN_FLAGS_DISCARD RT_BIT(7)
221/** Ignore all flush requests to workaround certain filesystems which are slow
222 * when writing a lot of cached data to the medium.
223 * Use with extreme care as a host crash can result in completely corrupted and
224 * unusable images.
225 */
226#define VD_OPEN_FLAGS_IGNORE_FLUSH RT_BIT(8)
227/**
228 * Return VINF_VD_NEW_ZEROED_BLOCK for reads from unallocated blocks.
229 * The caller who uses the flag has to make sure that the read doesn't cross
230 * a block boundary. Because the block size can differ between images reading one
231 * sector at a time is the safest solution.
232 */
233#define VD_OPEN_FLAGS_INFORM_ABOUT_ZERO_BLOCKS RT_BIT(9)
234/**
235 * Don't do unnecessary consistency checks when opening the image.
236 * Only valid when the image is opened in readonly because inconsistencies
237 * can lead to corrupted images in read-write mode.
238 */
239#define VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS RT_BIT(10)
240/** Mask of valid flags. */
241#define VD_OPEN_FLAGS_MASK (VD_OPEN_FLAGS_NORMAL | VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_HONOR_ZEROES | VD_OPEN_FLAGS_HONOR_SAME | VD_OPEN_FLAGS_INFO | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE | VD_OPEN_FLAGS_SEQUENTIAL | VD_OPEN_FLAGS_DISCARD | VD_OPEN_FLAGS_IGNORE_FLUSH | VD_OPEN_FLAGS_INFORM_ABOUT_ZERO_BLOCKS | VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS)
242/** @}*/
243
244/** @name VBox HDD container filter flags
245 * @{
246 */
247/** The filter is applied during writes. */
248#define VD_FILTER_FLAGS_WRITE RT_BIT(0)
249/** The filter is applied during reads. */
250#define VD_FILTER_FLAGS_READ RT_BIT(1)
251/** Open the filter in info mode. */
252#define VD_FILTER_FLAGS_INFO RT_BIT(2)
253/** Default set of filter flags. */
254#define VD_FILTER_FLAGS_DEFAULT (VD_FILTER_FLAGS_WRITE | VD_FILTER_FLAGS_READ)
255/** Mask of valid flags. */
256#define VD_FILTER_FLAGS_MASK (VD_FILTER_FLAGS_WRITE | VD_FILTER_FLAGS_READ | VD_FILTER_FLAGS_INFO)
257/** @} */
258
259/**
260 * Helper functions to handle open flags.
261 */
262
263/**
264 * Translate VD_OPEN_FLAGS_* to RTFile open flags.
265 *
266 * @return RTFile open flags.
267 * @param uOpenFlags VD_OPEN_FLAGS_* open flags.
268 * @param fCreate Flag that the file should be created.
269 */
270DECLINLINE(uint32_t) VDOpenFlagsToFileOpenFlags(unsigned uOpenFlags, bool fCreate)
271{
272 AssertMsg(!((uOpenFlags & VD_OPEN_FLAGS_READONLY) && fCreate), ("Image can't be opened readonly while being created\n"));
273
274 uint32_t fOpen = 0;
275
276 if (RT_UNLIKELY(uOpenFlags & VD_OPEN_FLAGS_READONLY))
277 fOpen |= RTFILE_O_READ | RTFILE_O_DENY_NONE;
278 else
279 {
280 fOpen |= RTFILE_O_READWRITE;
281
282 if (RT_UNLIKELY(uOpenFlags & VD_OPEN_FLAGS_SHAREABLE))
283 fOpen |= RTFILE_O_DENY_NONE;
284 else
285 fOpen |= RTFILE_O_DENY_WRITE;
286 }
287
288 if (RT_UNLIKELY(fCreate))
289 fOpen |= RTFILE_O_CREATE | RTFILE_O_NOT_CONTENT_INDEXED;
290 else
291 fOpen |= RTFILE_O_OPEN;
292
293 return fOpen;
294}
295
296
297/** @name VBox HDD container backend capability flags
298 * @{
299 */
300/** Supports UUIDs as expected by VirtualBox code. */
301#define VD_CAP_UUID RT_BIT(0)
302/** Supports creating fixed size images, allocating all space instantly. */
303#define VD_CAP_CREATE_FIXED RT_BIT(1)
304/** Supports creating dynamically growing images, allocating space on demand. */
305#define VD_CAP_CREATE_DYNAMIC RT_BIT(2)
306/** Supports creating images split in chunks of a bit less than 2GBytes. */
307#define VD_CAP_CREATE_SPLIT_2G RT_BIT(3)
308/** Supports being used as differencing image format backend. */
309#define VD_CAP_DIFF RT_BIT(4)
310/** Supports asynchronous I/O operations for at least some configurations. */
311#define VD_CAP_ASYNC RT_BIT(5)
312/** The backend operates on files. The caller needs to know to handle the
313 * location appropriately. */
314#define VD_CAP_FILE RT_BIT(6)
315/** The backend uses the config interface. The caller needs to know how to
316 * provide the mandatory configuration parts this way. */
317#define VD_CAP_CONFIG RT_BIT(7)
318/** The backend uses the network stack interface. The caller has to provide
319 * the appropriate interface. */
320#define VD_CAP_TCPNET RT_BIT(8)
321/** The backend supports VFS (virtual filesystem) functionality since it uses
322 * VDINTERFACEIO exclusively for all file operations. */
323#define VD_CAP_VFS RT_BIT(9)
324/** The backend supports the discard operation. */
325#define VD_CAP_DISCARD RT_BIT(10)
326/** @}*/
327
328/** @name VBox HDD container type.
329 * @{
330 */
331typedef enum VDTYPE
332{
333 /** Invalid. */
334 VDTYPE_INVALID = 0,
335 /** HardDisk */
336 VDTYPE_HDD,
337 /** CD/DVD */
338 VDTYPE_DVD,
339 /** Floppy. */
340 VDTYPE_FLOPPY
341} VDTYPE;
342/** @}*/
343
344
345/** @name Configuration interface key handling flags.
346 * @{
347 */
348/** Mandatory config key. Not providing a value for this key will cause
349 * the backend to fail. */
350#define VD_CFGKEY_MANDATORY RT_BIT(0)
351/** Expert config key. Not showing it by default in the GUI is is probably
352 * a good idea, as the average user won't understand it easily. */
353#define VD_CFGKEY_EXPERT RT_BIT(1)
354/** @}*/
355
356
357/**
358 * Configuration value type for configuration information interface.
359 */
360typedef enum VDCFGVALUETYPE
361{
362 /** Integer value. */
363 VDCFGVALUETYPE_INTEGER = 1,
364 /** String value. */
365 VDCFGVALUETYPE_STRING,
366 /** Bytestring value. */
367 VDCFGVALUETYPE_BYTES
368} VDCFGVALUETYPE;
369
370
371/**
372 * Structure describing configuration keys required/supported by a backend
373 * through the config interface.
374 */
375typedef struct VDCONFIGINFO
376{
377 /** Key name of the configuration. */
378 const char *pszKey;
379 /** Pointer to default value (descriptor). NULL if no useful default value
380 * can be specified. */
381 const char *pszDefaultValue;
382 /** Value type for this key. */
383 VDCFGVALUETYPE enmValueType;
384 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
385 uint64_t uKeyFlags;
386} VDCONFIGINFO;
387
388/** Pointer to structure describing configuration keys. */
389typedef VDCONFIGINFO *PVDCONFIGINFO;
390
391/** Pointer to const structure describing configuration keys. */
392typedef const VDCONFIGINFO *PCVDCONFIGINFO;
393
394/**
395 * Structure describing a file extension.
396 */
397typedef struct VDFILEEXTENSION
398{
399 /** Pointer to the NULL-terminated string containing the extension. */
400 const char *pszExtension;
401 /** The device type the extension supports. */
402 VDTYPE enmType;
403} VDFILEEXTENSION;
404
405/** Pointer to a structure describing a file extension. */
406typedef VDFILEEXTENSION *PVDFILEEXTENSION;
407
408/** Pointer to a const structure describing a file extension. */
409typedef const VDFILEEXTENSION *PCVDFILEEXTENSION;
410
411/**
412 * Data structure for returning a list of backend capabilities.
413 */
414typedef struct VDBACKENDINFO
415{
416 /** Name of the backend. Must be unique even with case insensitive comparison. */
417 const char *pszBackend;
418 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
419 uint64_t uBackendCaps;
420 /** Pointer to a NULL-terminated array of strings, containing the supported
421 * file extensions. Note that some backends do not work on files, so this
422 * pointer may just contain NULL. */
423 PCVDFILEEXTENSION paFileExtensions;
424 /** Pointer to an array of structs describing each supported config key.
425 * Terminated by a NULL config key. Note that some backends do not support
426 * the configuration interface, so this pointer may just contain NULL.
427 * Mandatory if the backend sets VD_CAP_CONFIG. */
428 PCVDCONFIGINFO paConfigInfo;
429 /** Returns a human readable hard disk location string given a
430 * set of hard disk configuration keys. The returned string is an
431 * equivalent of the full file path for image-based hard disks.
432 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
433 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
434 /** Returns a human readable hard disk name string given a
435 * set of hard disk configuration keys. The returned string is an
436 * equivalent of the file name part in the full file path for
437 * image-based hard disks. Mandatory for backends with no
438 * VD_CAP_FILE and NULL otherwise. */
439 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
440} VDBACKENDINFO, *PVDBACKENDINFO;
441
442/**
443 * Data structure for returning a list of filter capabilities.
444 */
445typedef struct VDFILTERINFO
446{
447 /** Name of the filter. Must be unique even with case insensitive comparison. */
448 const char *pszFilter;
449 /** Pointer to an array of structs describing each supported config key.
450 * Terminated by a NULL config key. Note that some filters do not support
451 * the configuration interface, so this pointer may just contain NULL. */
452 PCVDCONFIGINFO paConfigInfo;
453} VDFILTERINFO, *PVDFILTERINFO;
454
455
456/**
457 * Request completion callback for the async read/write API.
458 */
459typedef void (FNVDASYNCTRANSFERCOMPLETE) (void *pvUser1, void *pvUser2, int rcReq);
460/** Pointer to a transfer compelte callback. */
461typedef FNVDASYNCTRANSFERCOMPLETE *PFNVDASYNCTRANSFERCOMPLETE;
462
463/**
464 * Disk geometry.
465 */
466typedef struct VDGEOMETRY
467{
468 /** Number of cylinders. */
469 uint32_t cCylinders;
470 /** Number of heads. */
471 uint32_t cHeads;
472 /** Number of sectors. */
473 uint32_t cSectors;
474} VDGEOMETRY;
475
476/** Pointer to disk geometry. */
477typedef VDGEOMETRY *PVDGEOMETRY;
478/** Pointer to constant disk geometry. */
479typedef const VDGEOMETRY *PCVDGEOMETRY;
480
481/**
482 * VBox HDD Container main structure.
483 */
484/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
485struct VBOXHDD;
486typedef struct VBOXHDD VBOXHDD;
487typedef VBOXHDD *PVBOXHDD;
488
489/**
490 * Initializes HDD backends.
491 *
492 * @returns VBox status code.
493 */
494VBOXDDU_DECL(int) VDInit(void);
495
496/**
497 * Destroys loaded HDD backends.
498 *
499 * @returns VBox status code.
500 */
501VBOXDDU_DECL(int) VDShutdown(void);
502
503/**
504 * Loads a single plugin given by filename.
505 *
506 * @returns VBox status code.
507 * @param pszFilename The plugin filename to load.
508 */
509VBOXDDU_DECL(int) VDPluginLoadFromFilename(const char *pszFilename);
510
511/**
512 * Load all plugins from a given path.
513 *
514 * @returns VBox statuse code.
515 * @param pszPath The path to load plugins from.
516 */
517VBOXDDU_DECL(int) VDPluginLoadFromPath(const char *pszPath);
518
519/**
520 * Unloads a single plugin given by filename.
521 *
522 * @returns VBox status code.
523 * @param pszFilename The plugin filename to unload.
524 */
525VBOXDDU_DECL(int) VDPluginUnloadFromFilename(const char *pszFilename);
526
527/**
528 * Unload all plugins from a given path.
529 *
530 * @returns VBox statuse code.
531 * @param pszPath The path to unload plugins from.
532 */
533VBOXDDU_DECL(int) VDPluginUnloadFromPath(const char *pszPath);
534
535/**
536 * Lists all HDD backends and their capabilities in a caller-provided buffer.
537 *
538 * @return VBox status code.
539 * VERR_BUFFER_OVERFLOW if not enough space is passed.
540 * @param cEntriesAlloc Number of list entries available.
541 * @param pEntries Pointer to array for the entries.
542 * @param pcEntriesUsed Number of entries returned.
543 */
544VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
545 unsigned *pcEntriesUsed);
546
547/**
548 * Lists the capabilities of a backend identified by its name.
549 *
550 * @return VBox status code.
551 * @param pszBackend The backend name (case insensitive).
552 * @param pEntries Pointer to an entry.
553 */
554VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
555
556/**
557 * Lists all filters and their capabilities in a caller-provided buffer.
558 *
559 * @return VBox status code.
560 * VERR_BUFFER_OVERFLOW if not enough space is passed.
561 * @param cEntriesAlloc Number of list entries available.
562 * @param pEntries Pointer to array for the entries.
563 * @param pcEntriesUsed Number of entries returned.
564 */
565VBOXDDU_DECL(int) VDFilterInfo(unsigned cEntriesAlloc, PVDFILTERINFO pEntries,
566 unsigned *pcEntriesUsed);
567
568/**
569 * Lists the capabilities of a filter identified by its name.
570 *
571 * @return VBox status code.
572 * @param pszFilter The filter name (case insensitive).
573 * @param pEntries Pointer to an entry.
574 */
575VBOXDDU_DECL(int) VDFilterInfoOne(const char *pszFilter, PVDFILTERINFO pEntry);
576
577/**
578 * Allocates and initializes an empty HDD container.
579 * No image files are opened.
580 *
581 * @return VBox status code.
582 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
583 * @param enmType Type of the image container.
584 * @param ppDisk Where to store the reference to HDD container.
585 */
586VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, VDTYPE enmType, PVBOXHDD *ppDisk);
587
588/**
589 * Destroys HDD container.
590 * If container has opened image files they will be closed.
591 *
592 * @return VBox status code.
593 * @param pDisk Pointer to HDD container.
594 */
595VBOXDDU_DECL(int) VDDestroy(PVBOXHDD pDisk);
596
597/**
598 * Try to get the backend name which can use this image.
599 *
600 * @return VBox status code.
601 * VINF_SUCCESS if a plugin was found.
602 * ppszFormat contains the string which can be used as backend name.
603 * VERR_NOT_SUPPORTED if no backend was found.
604 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
605 * @param pVDIfsImage Pointer to the per-image VD interface list.
606 * @param pszFilename Name of the image file for which the backend is queried.
607 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
608 * The returned pointer must be freed using RTStrFree().
609 * @param penmType Where to store the type of the image.
610 */
611VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
612 const char *pszFilename, char **ppszFormat, VDTYPE *penmType);
613
614/**
615 * Opens an image file.
616 *
617 * The first opened image file in HDD container must have a base image type,
618 * others (next opened images) must be differencing or undo images.
619 * Linkage is checked for differencing image to be consistent with the previously opened image.
620 * When another differencing image is opened and the last image was opened in read/write access
621 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
622 * other processes to use images in read-only mode too.
623 *
624 * Note that the image is opened in read-only mode if a read/write open is not possible.
625 * Use VDIsReadOnly to check open mode.
626 *
627 * @return VBox status code.
628 * @param pDisk Pointer to HDD container.
629 * @param pszBackend Name of the image file backend to use (case insensitive).
630 * @param pszFilename Name of the image file to open.
631 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
632 * @param pVDIfsImage Pointer to the per-image VD interface list.
633 */
634VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
635 const char *pszFilename, unsigned uOpenFlags,
636 PVDINTERFACE pVDIfsImage);
637
638/**
639 * Opens a cache image.
640 *
641 * @return VBox status code.
642 * @param pDisk Pointer to the HDD container which should use the cache image.
643 * @param pszBackend Name of the cache file backend to use (case insensitive).
644 * @param pszFilename Name of the cache image to open.
645 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
646 * @param pVDIfsCache Pointer to the per-cache VD interface list.
647 */
648VBOXDDU_DECL(int) VDCacheOpen(PVBOXHDD pDisk, const char *pszBackend,
649 const char *pszFilename, unsigned uOpenFlags,
650 PVDINTERFACE pVDIfsCache);
651
652/**
653 * Adds a filter to the disk.
654 *
655 * @returns VBox status code.
656 * @param pDisk Pointer to the HDD container which should use the filter.
657 * @param pszFilter Name of the filter backend to use (case insensitive).
658 * @param fFlags Flags which apply to the filter, combination of VD_FILTER_FLAGS_*
659 * defines.
660 * @param pVDIfsFilter Pointer to the per-filter VD interface list.
661 */
662VBOXDDU_DECL(int) VDFilterAdd(PVBOXHDD pDisk, const char *pszFilter, uint32_t fFlags,
663 PVDINTERFACE pVDIfsFilter);
664
665/**
666 * Creates and opens a new base image file.
667 *
668 * @return VBox status code.
669 * @param pDisk Pointer to HDD container.
670 * @param pszBackend Name of the image file backend to use (case insensitive).
671 * @param pszFilename Name of the image file to create.
672 * @param cbSize Image size in bytes.
673 * @param uImageFlags Flags specifying special image features.
674 * @param pszComment Pointer to image comment. NULL is ok.
675 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
676 * @param pLCHSGeometry Pointer to logical disk geometry <= (x,255,63). Not NULL.
677 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
678 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
679 * @param pVDIfsImage Pointer to the per-image VD interface list.
680 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
681 */
682VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
683 const char *pszFilename, uint64_t cbSize,
684 unsigned uImageFlags, const char *pszComment,
685 PCVDGEOMETRY pPCHSGeometry,
686 PCVDGEOMETRY pLCHSGeometry,
687 PCRTUUID pUuid, unsigned uOpenFlags,
688 PVDINTERFACE pVDIfsImage,
689 PVDINTERFACE pVDIfsOperation);
690
691/**
692 * Creates and opens a new differencing image file in HDD container.
693 * See comments for VDOpen function about differencing images.
694 *
695 * @return VBox status code.
696 * @param pDisk Pointer to HDD container.
697 * @param pszBackend Name of the image file backend to use (case insensitive).
698 * @param pszFilename Name of the differencing image file to create.
699 * @param uImageFlags Flags specifying special image features.
700 * @param pszComment Pointer to image comment. NULL is ok.
701 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
702 * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically.
703 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
704 * @param pVDIfsImage Pointer to the per-image VD interface list.
705 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
706 */
707VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
708 const char *pszFilename, unsigned uImageFlags,
709 const char *pszComment, PCRTUUID pUuid,
710 PCRTUUID pParentUuid, unsigned uOpenFlags,
711 PVDINTERFACE pVDIfsImage,
712 PVDINTERFACE pVDIfsOperation);
713
714/**
715 * Creates and opens new cache image file in HDD container.
716 *
717 * @return VBox status code.
718 * @param pDisk Name of the cache file backend to use (case insensitive).
719 * @param pszFilename Name of the differencing cache file to create.
720 * @param cbSize Maximum size of the cache.
721 * @param uImageFlags Flags specifying special cache features.
722 * @param pszComment Pointer to image comment. NULL is ok.
723 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
724 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
725 * @param pVDIfsCache Pointer to the per-cache VD interface list.
726 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
727 */
728VBOXDDU_DECL(int) VDCreateCache(PVBOXHDD pDisk, const char *pszBackend,
729 const char *pszFilename, uint64_t cbSize,
730 unsigned uImageFlags, const char *pszComment,
731 PCRTUUID pUuid, unsigned uOpenFlags,
732 PVDINTERFACE pVDIfsCache, PVDINTERFACE pVDIfsOperation);
733
734/**
735 * Merges two images (not necessarily with direct parent/child relationship).
736 * As a side effect the source image and potentially the other images which
737 * are also merged to the destination are deleted from both the disk and the
738 * images in the HDD container.
739 *
740 * @return VBox status code.
741 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
742 * @param pDisk Pointer to HDD container.
743 * @param nImageFrom Image number to merge from, counts from 0. 0 is always base image of container.
744 * @param nImageTo Image number to merge to, counts from 0. 0 is always base image of container.
745 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
746 */
747VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
748 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
749
750/**
751 * Copies an image from one HDD container to another - extended version.
752 * The copy is opened in the target HDD container.
753 * It is possible to convert between different image formats, because the
754 * backend for the destination may be different from the source.
755 * If both the source and destination reference the same HDD container,
756 * then the image is moved (by copying/deleting or renaming) to the new location.
757 * The source container is unchanged if the move operation fails, otherwise
758 * the image at the new location is opened in the same way as the old one was.
759 *
760 * @note The read/write accesses across disks are not synchronized, just the
761 * accesses to each disk. Once there is a use case which requires a defined
762 * read/write behavior in this situation this needs to be extended.
763 *
764 * @return VBox status code.
765 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
766 * @param pDiskFrom Pointer to source HDD container.
767 * @param nImage Image number, counts from 0. 0 is always base image of container.
768 * @param pDiskTo Pointer to destination HDD container.
769 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
770 * @param pszFilename New name of the image (may be NULL to specify that the
771 * copy destination is the destination container, or
772 * if pDiskFrom == pDiskTo, i.e. when moving).
773 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
774 * @param cbSize New image size (0 means leave unchanged).
775 * @param nImageSameFrom The number of the last image in the source chain having the same content as the
776 * image in the destination chain given by nImageSameTo or
777 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the content of both containers is unknown.
778 * See the notes for further information.
779 * @param nImageSameTo The number of the last image in the destination chain having the same content as the
780 * image in the source chain given by nImageSameFrom or
781 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the content of both containers is unknown.
782 * See the notes for further information.
783 * @param uImageFlags Flags specifying special destination image features.
784 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
785 * This parameter is used if and only if a true copy is created.
786 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
787 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
788 * Only used if the destination image is created.
789 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
790 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
791 * destination image.
792 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
793 * for the destination operation.
794 *
795 * @note Using nImageSameFrom and nImageSameTo can lead to a significant speedup
796 * when copying an image but can also lead to a corrupted copy if used incorrectly.
797 * It is mainly useful when cloning a chain of images and it is known that
798 * the virtual disk content of the two chains is exactly the same upto a certain image.
799 * Example:
800 * Imagine the chain of images which consist of a base and one diff image.
801 * Copying the chain starts with the base image. When copying the first
802 * diff image VDCopy() will read the data from the diff of the source chain
803 * and probably from the base image again in case the diff doesn't has data
804 * for the block. However the block will be optimized away because VDCopy()
805 * reads data from the base image of the destination chain compares the to
806 * and suppresses the write because the data is unchanged.
807 * For a lot of diff images this will be a huge waste of I/O bandwidth if
808 * the diff images contain only few changes.
809 * Because it is known that the base image of the source and the destination chain
810 * have the same content it is enough to check the diff image for changed data
811 * and copy it to the destination diff image which is achieved with
812 * nImageSameFrom and nImageSameTo. Setting both to 0 can suppress a lot of I/O.
813 */
814VBOXDDU_DECL(int) VDCopyEx(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
815 const char *pszBackend, const char *pszFilename,
816 bool fMoveByRename, uint64_t cbSize,
817 unsigned nImageFromSame, unsigned nImageToSame,
818 unsigned uImageFlags, PCRTUUID pDstUuid,
819 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
820 PVDINTERFACE pDstVDIfsImage,
821 PVDINTERFACE pDstVDIfsOperation);
822
823/**
824 * Copies an image from one HDD container to another.
825 * The copy is opened in the target HDD container.
826 * It is possible to convert between different image formats, because the
827 * backend for the destination may be different from the source.
828 * If both the source and destination reference the same HDD container,
829 * then the image is moved (by copying/deleting or renaming) to the new location.
830 * The source container is unchanged if the move operation fails, otherwise
831 * the image at the new location is opened in the same way as the old one was.
832 *
833 * @note The read/write accesses across disks are not synchronized, just the
834 * accesses to each disk. Once there is a use case which requires a defined
835 * read/write behavior in this situation this needs to be extended.
836 *
837 * @return VBox status code.
838 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
839 * @param pDiskFrom Pointer to source HDD container.
840 * @param nImage Image number, counts from 0. 0 is always base image of container.
841 * @param pDiskTo Pointer to destination HDD container.
842 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
843 * @param pszFilename New name of the image (may be NULL to specify that the
844 * copy destination is the destination container, or
845 * if pDiskFrom == pDiskTo, i.e. when moving).
846 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
847 * @param cbSize New image size (0 means leave unchanged).
848 * @param uImageFlags Flags specifying special destination image features.
849 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
850 * This parameter is used if and only if a true copy is created.
851 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
852 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
853 * Only used if the destination image is created.
854 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
855 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
856 * destination image.
857 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
858 * for the destination operation.
859 */
860VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
861 const char *pszBackend, const char *pszFilename,
862 bool fMoveByRename, uint64_t cbSize,
863 unsigned uImageFlags, PCRTUUID pDstUuid,
864 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
865 PVDINTERFACE pDstVDIfsImage,
866 PVDINTERFACE pDstVDIfsOperation);
867
868/**
869 * Optimizes the storage consumption of an image. Typically the unused blocks
870 * have to be wiped with zeroes to achieve a substantial reduced storage use.
871 * Another optimization done is reordering the image blocks, which can provide
872 * a significant performance boost, as reads and writes tend to use less random
873 * file offsets.
874 *
875 * @note Compaction is treated as a single operation with regard to thread
876 * synchronization, which means that it potentially blocks other activities for
877 * a long time. The complexity of compaction would grow even more if concurrent
878 * accesses have to be handled.
879 *
880 * @return VBox status code.
881 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
882 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
883 * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but
884 * this isn't supported yet.
885 * @param pDisk Pointer to HDD container.
886 * @param nImage Image number, counts from 0. 0 is always base image of container.
887 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
888 */
889VBOXDDU_DECL(int) VDCompact(PVBOXHDD pDisk, unsigned nImage,
890 PVDINTERFACE pVDIfsOperation);
891
892/**
893 * Resizes the given disk image to the given size. It is OK if there are
894 * multiple images open in the container. In this case the last disk image
895 * will be resized.
896 *
897 * @return VBox status
898 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
899 * @return VERR_NOT_SUPPORTED if this kind of image can't be compacted.
900 *
901 * @param pDisk Pointer to the HDD container.
902 * @param cbSize New size of the image.
903 * @param pPCHSGeometry Pointer to the new physical disk geometry <= (16383,16,63). Not NULL.
904 * @param pLCHSGeometry Pointer to the new logical disk geometry <= (x,255,63). Not NULL.
905 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
906 */
907VBOXDDU_DECL(int) VDResize(PVBOXHDD pDisk, uint64_t cbSize,
908 PCVDGEOMETRY pPCHSGeometry,
909 PCVDGEOMETRY pLCHSGeometry,
910 PVDINTERFACE pVDIfsOperation);
911
912/**
913 * Prepares the given disk for use by the added filters. This applies to all
914 * opened images in the chain which might be opened read/write temporary.
915 *
916 * @return VBox status code.
917 *
918 * @param pDisk Pointer to the HDD container.
919 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
920 */
921VBOXDDU_DECL(int) VDPrepareWithFilters(PVBOXHDD pDisk, PVDINTERFACE pVDIfsOperation);
922
923/**
924 * Closes the last opened image file in HDD container.
925 * If previous image file was opened in read-only mode (the normal case) and
926 * the last opened image is in read-write mode then the previous image will be
927 * reopened in read/write mode.
928 *
929 * @return VBox status code.
930 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
931 * @param pDisk Pointer to HDD container.
932 * @param fDelete If true, delete the image from the host disk.
933 */
934VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
935
936/**
937 * Removes the last added filter in the HDD container from the specified chain.
938 *
939 * @return VBox status code.
940 * @retval VERR_VD_NOT_OPENED if no filter is present for the disk.
941 * @param pDisk Pointer to HDD container.
942 * @param fFlags Combination of VD_FILTER_FLAGS_* defines.
943 */
944VBOXDDU_DECL(int) VDFilterRemove(PVBOXHDD pDisk, uint32_t fFlags);
945
946/**
947 * Closes the currently opened cache image file in HDD container.
948 *
949 * @return VBox status code.
950 * @return VERR_VD_NOT_OPENED if no cache is opened in HDD container.
951 * @param pDisk Pointer to HDD container.
952 * @param fDelete If true, delete the image from the host disk.
953 */
954VBOXDDU_DECL(int) VDCacheClose(PVBOXHDD pDisk, bool fDelete);
955
956/**
957 * Closes all opened image files in HDD container.
958 *
959 * @return VBox status code.
960 * @param pDisk Pointer to HDD container.
961 */
962VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
963
964/**
965 * Removes all filters of the given HDD container.
966 *
967 * @return VBox status code.
968 * @param pDisk Pointer to HDD container.
969 */
970VBOXDDU_DECL(int) VDFilterRemoveAll(PVBOXHDD pDisk);
971
972/**
973 * Read data from virtual HDD.
974 *
975 * @return VBox status code.
976 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
977 * @param pDisk Pointer to HDD container.
978 * @param uOffset Offset of first reading byte from start of disk.
979 * Must be aligned to a sector boundary.
980 * @param pvBuffer Pointer to buffer for reading data.
981 * @param cbBuffer Number of bytes to read.
982 * Must be aligned to a sector boundary.
983 */
984VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuffer, size_t cbBuffer);
985
986/**
987 * Write data to virtual HDD.
988 *
989 * @return VBox status code.
990 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
991 * @param pDisk Pointer to HDD container.
992 * @param uOffset Offset of first writing byte from start of disk.
993 * Must be aligned to a sector boundary.
994 * @param pvBuffer Pointer to buffer for writing data.
995 * @param cbBuffer Number of bytes to write.
996 * Must be aligned to a sector boundary.
997 */
998VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuffer, size_t cbBuffer);
999
1000/**
1001 * Make sure the on disk representation of a virtual HDD is up to date.
1002 *
1003 * @return VBox status code.
1004 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1005 * @param pDisk Pointer to HDD container.
1006 */
1007VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
1008
1009/**
1010 * Get number of opened images in HDD container.
1011 *
1012 * @return Number of opened images for HDD container. 0 if no images have been opened.
1013 * @param pDisk Pointer to HDD container.
1014 */
1015VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
1016
1017/**
1018 * Get read/write mode of HDD container.
1019 *
1020 * @return Virtual disk ReadOnly status.
1021 * @return true if no image is opened in HDD container.
1022 * @param pDisk Pointer to HDD container.
1023 */
1024VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
1025
1026/**
1027 * Get sector size of an image in HDD container.
1028 *
1029 * @return Virtual disk sector size in bytes.
1030 * @return 0 if image with specified number was not opened.
1031 * @param pDisk Pointer to HDD container.
1032 * @param nImage Image number, counts from 0. 0 is always base image of container.
1033 */
1034VBOXDDU_DECL(uint32_t) VDGetSectorSize(PVBOXHDD pDisk, unsigned nImage);
1035
1036/**
1037 * Get total capacity of an image in HDD container.
1038 *
1039 * @return Virtual disk size in bytes.
1040 * @return 0 if image with specified number was not opened.
1041 * @param pDisk Pointer to HDD container.
1042 * @param nImage Image number, counts from 0. 0 is always base image of container.
1043 */
1044VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
1045
1046/**
1047 * Get total file size of an image in HDD container.
1048 *
1049 * @return Virtual disk size in bytes.
1050 * @return 0 if image with specified number was not opened.
1051 * @param pDisk Pointer to HDD container.
1052 * @param nImage Image number, counts from 0. 0 is always base image of container.
1053 */
1054VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
1055
1056/**
1057 * Get virtual disk PCHS geometry of an image in HDD container.
1058 *
1059 * @return VBox status code.
1060 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1061 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1062 * @param pDisk Pointer to HDD container.
1063 * @param nImage Image number, counts from 0. 0 is always base image of container.
1064 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1065 */
1066VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1067 PVDGEOMETRY pPCHSGeometry);
1068
1069/**
1070 * Store virtual disk PCHS geometry of an image in HDD container.
1071 *
1072 * @return VBox status code.
1073 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1074 * @param pDisk Pointer to HDD container.
1075 * @param nImage Image number, counts from 0. 0 is always base image of container.
1076 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1077 */
1078VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1079 PCVDGEOMETRY pPCHSGeometry);
1080
1081/**
1082 * Get virtual disk LCHS geometry of an image in HDD container.
1083 *
1084 * @return VBox status code.
1085 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1086 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1087 * @param pDisk Pointer to HDD container.
1088 * @param nImage Image number, counts from 0. 0 is always base image of container.
1089 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1090 */
1091VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1092 PVDGEOMETRY pLCHSGeometry);
1093
1094/**
1095 * Store virtual disk LCHS geometry of an image in HDD container.
1096 *
1097 * @return VBox status code.
1098 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1099 * @param pDisk Pointer to HDD container.
1100 * @param nImage Image number, counts from 0. 0 is always base image of container.
1101 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1102 */
1103VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
1104 PCVDGEOMETRY pLCHSGeometry);
1105
1106/**
1107 * Get version of image in HDD container.
1108 *
1109 * @return VBox status code.
1110 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1111 * @param pDisk Pointer to HDD container.
1112 * @param nImage Image number, counts from 0. 0 is always base image of container.
1113 * @param puVersion Where to store the image version.
1114 */
1115VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
1116 unsigned *puVersion);
1117
1118/**
1119 * List the capabilities of image backend in HDD container.
1120 *
1121 * @return VBox status code.
1122 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1123 * @param pDisk Pointer to the HDD container.
1124 * @param nImage Image number, counts from 0. 0 is always base image of container.
1125 * @param pbackendInfo Where to store the backend information.
1126 */
1127VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
1128 PVDBACKENDINFO pBackendInfo);
1129
1130/**
1131 * Get flags of image in HDD container.
1132 *
1133 * @return VBox status code.
1134 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1135 * @param pDisk Pointer to HDD container.
1136 * @param nImage Image number, counts from 0. 0 is always base image of container.
1137 * @param puImageFlags Where to store the image flags.
1138 */
1139VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
1140
1141/**
1142 * Get open flags of image in HDD container.
1143 *
1144 * @return VBox status code.
1145 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1146 * @param pDisk Pointer to HDD container.
1147 * @param nImage Image number, counts from 0. 0 is always base image of container.
1148 * @param puOpenFlags Where to store the image open flags.
1149 */
1150VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1151 unsigned *puOpenFlags);
1152
1153/**
1154 * Set open flags of image in HDD container.
1155 * This operation may cause file locking changes and/or files being reopened.
1156 * Note that in case of unrecoverable error all images in HDD container will be closed.
1157 *
1158 * @return VBox status code.
1159 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1160 * @param pDisk Pointer to HDD container.
1161 * @param nImage Image number, counts from 0. 0 is always base image of container.
1162 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1163 */
1164VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
1165 unsigned uOpenFlags);
1166
1167/**
1168 * Get base filename of image in HDD container. Some image formats use
1169 * other filenames as well, so don't use this for anything but informational
1170 * purposes.
1171 *
1172 * @return VBox status code.
1173 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1174 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1175 * @param pDisk Pointer to HDD container.
1176 * @param nImage Image number, counts from 0. 0 is always base image of container.
1177 * @param pszFilename Where to store the image file name.
1178 * @param cbFilename Size of buffer pszFilename points to.
1179 */
1180VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
1181 char *pszFilename, unsigned cbFilename);
1182
1183/**
1184 * Get the comment line of image in HDD container.
1185 *
1186 * @return VBox status code.
1187 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1188 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1189 * @param pDisk Pointer to HDD container.
1190 * @param nImage Image number, counts from 0. 0 is always base image of container.
1191 * @param pszComment Where to store the comment string of image. NULL is ok.
1192 * @param cbComment The size of pszComment buffer. 0 is ok.
1193 */
1194VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
1195 char *pszComment, unsigned cbComment);
1196
1197/**
1198 * Changes the comment line of image in HDD container.
1199 *
1200 * @return VBox status code.
1201 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1202 * @param pDisk Pointer to HDD container.
1203 * @param nImage Image number, counts from 0. 0 is always base image of container.
1204 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1205 */
1206VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
1207 const char *pszComment);
1208
1209/**
1210 * Get UUID of image in HDD container.
1211 *
1212 * @return VBox status code.
1213 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1214 * @param pDisk Pointer to HDD container.
1215 * @param nImage Image number, counts from 0. 0 is always base image of container.
1216 * @param pUuid Where to store the image UUID.
1217 */
1218VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1219
1220/**
1221 * Set the image's UUID. Should not be used by normal applications.
1222 *
1223 * @return VBox status code.
1224 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1225 * @param pDisk Pointer to HDD container.
1226 * @param nImage Image number, counts from 0. 0 is always base image of container.
1227 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1228 */
1229VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1230
1231/**
1232 * Get last modification UUID of image in HDD container.
1233 *
1234 * @return VBox status code.
1235 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1236 * @param pDisk Pointer to HDD container.
1237 * @param nImage Image number, counts from 0. 0 is always base image of container.
1238 * @param pUuid Where to store the image modification UUID.
1239 */
1240VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1241 PRTUUID pUuid);
1242
1243/**
1244 * Set the image's last modification UUID. Should not be used by normal applications.
1245 *
1246 * @return VBox status code.
1247 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1248 * @param pDisk Pointer to HDD container.
1249 * @param nImage Image number, counts from 0. 0 is always base image of container.
1250 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1251 */
1252VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage,
1253 PCRTUUID pUuid);
1254
1255/**
1256 * Get parent UUID of image in HDD container.
1257 *
1258 * @return VBox status code.
1259 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1260 * @param pDisk Pointer to HDD container.
1261 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1262 * @param pUuid Where to store the parent image UUID.
1263 */
1264VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1265 PRTUUID pUuid);
1266
1267/**
1268 * Set the image's parent UUID. Should not be used by normal applications.
1269 *
1270 * @return VBox status code.
1271 * @param pDisk Pointer to HDD container.
1272 * @param nImage Image number, counts from 0. 0 is always base image of container.
1273 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1274 */
1275VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
1276 PCRTUUID pUuid);
1277
1278
1279/**
1280 * Debug helper - dumps all opened images in HDD container into the log file.
1281 *
1282 * @param pDisk Pointer to HDD container.
1283 */
1284VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
1285
1286
1287/**
1288 * Discards unused ranges given as a list.
1289 *
1290 * @return VBox status code.
1291 * @param pDisk Pointer to HDD container.
1292 * @param paRanges The array of ranges to discard.
1293 * @param cRanges Number of entries in the array.
1294 *
1295 * @note In contrast to VDCompact() the ranges are always discarded even if they
1296 * appear to contain data. This method is mainly used to implement TRIM support.
1297 */
1298VBOXDDU_DECL(int) VDDiscardRanges(PVBOXHDD pDisk, PCRTRANGE paRanges, unsigned cRanges);
1299
1300
1301/**
1302 * Start an asynchronous read request.
1303 *
1304 * @return VBox status code.
1305 * @param pDisk Pointer to the HDD container.
1306 * @param uOffset The offset of the virtual disk to read from.
1307 * @param cbRead How many bytes to read.
1308 * @param pcSgBuf Pointer to the S/G buffer to read into.
1309 * @param pfnComplete Completion callback.
1310 * @param pvUser User data which is passed on completion
1311 */
1312VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
1313 PCRTSGBUF pcSgBuf,
1314 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1315 void *pvUser1, void *pvUser2);
1316
1317
1318/**
1319 * Start an asynchronous write request.
1320 *
1321 * @return VBox status code.
1322 * @param pDisk Pointer to the HDD container.
1323 * @param uOffset The offset of the virtual disk to write to.
1324 * @param cbWrtie How many bytes to write.
1325 * @param pcSgBuf Pointer to the S/G buffer to write from.
1326 * @param pfnComplete Completion callback.
1327 * @param pvUser User data which is passed on completion.
1328 */
1329VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
1330 PCRTSGBUF pcSgBuf,
1331 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1332 void *pvUser1, void *pvUser2);
1333
1334
1335/**
1336 * Start an asynchronous flush request.
1337 *
1338 * @return VBox status code.
1339 * @param pDisk Pointer to the HDD container.
1340 * @param pfnComplete Completion callback.
1341 * @param pvUser User data which is passed on completion.
1342 */
1343VBOXDDU_DECL(int) VDAsyncFlush(PVBOXHDD pDisk,
1344 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1345 void *pvUser1, void *pvUser2);
1346
1347/**
1348 * Start an asynchronous discard request.
1349 *
1350 * @return VBox status code.
1351 * @param pDisk Pointer to HDD container.
1352 * @param paRanges The array of ranges to discard.
1353 * @param cRanges Number of entries in the array.
1354 * @param pfnComplete Completion callback.
1355 * @param pvUser1 User data which is passed on completion.
1356 * @param pvUser2 User data which is passed on completion.
1357 */
1358VBOXDDU_DECL(int) VDAsyncDiscardRanges(PVBOXHDD pDisk, PCRTRANGE paRanges, unsigned cRanges,
1359 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1360 void *pvUser1, void *pvUser);
1361
1362/**
1363 * Tries to repair a corrupted image.
1364 *
1365 * @return VBox status code.
1366 * @retval VERR_VD_IMAGE_REPAIR_NOT_SUPPORTED if the backend does not support repairing the image.
1367 * @retval VERR_VD_IMAGE_REPAIR_IMPOSSIBLE if the corruption is to severe to repair the image.
1368 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1369 * @param pVDIfsImage Pointer to the per-image VD interface list.
1370 * @param pszFilename Name of the image file to repair.
1371 * @param pszFormat The backend to use.
1372 * @param fFlags Combination of the VD_REPAIR_* flags.
1373 */
1374VBOXDDU_DECL(int) VDRepair(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
1375 const char *pszFilename, const char *pszBackend,
1376 uint32_t fFlags);
1377
1378/**
1379 * Create a VFS file handle from the given HDD container.
1380 *
1381 * @return VBox status code.
1382 * @param pDisk Pointer to HDD container.
1383 * @param fFlags Combination of the VD_VFSFILE_* flags.
1384 * @param phVfsFile Where to store the handle to the VFS file on
1385 * success.
1386 */
1387VBOXDDU_DECL(int) VDCreateVfsFileFromDisk(PVBOXHDD pDisk, uint32_t fFlags,
1388 PRTVFSFILE phVfsFile);
1389
1390RT_C_DECLS_END
1391
1392/** @} */
1393
1394#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