VirtualBox

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

Last change on this file since 65904 was 64272, checked in by vboxsync, 8 years ago

Storage: Doxygen fixes

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