VirtualBox

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

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

vd.h: Typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 64.1 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 * Disk region data form known to us from various standards.
499 */
500typedef enum VDREGIONDATAFORM
501{
502 /** Invalid data form. */
503 VDREGIONDATAFORM_INVALID = 0,
504 /** Raw data, no standardized format. */
505 VDREGIONDATAFORM_RAW,
506 /** CD-DA (audio CD), 2352 bytes of data. */
507 VDREGIONDATAFORM_CDDA,
508 /** CDDA data is pause. */
509 VDREGIONDATAFORM_CDDA_PAUSE,
510 /** Mode 1 with 2048 bytes sector size. */
511 VDREGIONDATAFORM_MODE1_2048,
512 /** Mode 1 with 2352 bytes sector size. */
513 VDREGIONDATAFORM_MODE1_2352,
514 /** Mode 1 with 0 bytes sector size (generated by the drive). */
515 VDREGIONDATAFORM_MODE1_0,
516 /** XA Mode with 2336 bytes sector size. */
517 VDREGIONDATAFORM_XA_2336,
518 /** XA Mode with 2352 bytes sector size. */
519 VDREGIONDATAFORM_XA_2352,
520 /** XA Mode with 0 bytes sector size (generated by the drive). */
521 VDREGIONDATAFORM_XA_0,
522 /** Mode 2 with 2336 bytes sector size. */
523 VDREGIONDATAFORM_MODE2_2336,
524 /** Mode 2 with 2352 bytes sector size. */
525 VDREGIONDATAFORM_MODE2_2352,
526 /** Mode 2 with 0 bytes sector size (generated by the drive). */
527 VDREGIONDATAFORM_MODE2_0
528} VDREGIONDATAFORM;
529
530/**
531 * Disk region metadata forms known to us.
532 */
533typedef enum VDREGIONMETADATAFORM
534{
535 /** Invalid metadata form. */
536 VDREGIONMETADATAFORM_INVALID = 0,
537 /** No metadata assined to the region. */
538 VDREGIONMETADATAFORM_NONE,
539 /** Raw metadata, no standardized format. */
540 VDREGIONMETADATAFORM_RAW
541} VDREGIONMETADATAFORM;
542
543/**
544 * Disk region descriptor.
545 */
546typedef struct VDREGIONDESC
547{
548 /** Start of the region in bytes or LBA number (depending on the flag in the
549 * list header). */
550 uint64_t offRegion;
551 /** Overall size of the region in bytes or number of blocks (depending on the
552 * flag in the list header). */
553 uint64_t cRegionBlocksOrBytes;
554 /** Size of one block in bytes, containing user and metadata. */
555 uint64_t cbBlock;
556 /** User data form of the block. */
557 VDREGIONDATAFORM enmDataForm;
558 /** Metadata form of the block. */
559 VDREGIONMETADATAFORM enmMetadataForm;
560 /** Size of the data block in bytes. */
561 uint64_t cbData;
562 /** Size of the metadata in a block in bytes. */
563 uint64_t cbMetadata;
564} VDREGIONDESC;
565/** Pointer to a region descriptor. */
566typedef VDREGIONDESC *PVDREGIONDESC;
567/** Pointer to a constant region descriptor. */
568typedef const VDREGIONDESC *PCVDREGIONDESC;
569
570/**
571 * Disk region list.
572 */
573typedef struct VDREGIONLIST
574{
575 /** Flags valid for the region list. */
576 uint32_t fFlags;
577 /** Number of regions in the descriptor array. */
578 uint32_t cRegions;
579 /** Region descriptors - variable in size. */
580 VDREGIONDESC aRegions[RT_FLEXIBLE_ARRAY];
581} VDREGIONLIST;
582/** Pointer to a region list. */
583typedef VDREGIONLIST *PVDREGIONLIST;
584/** Pointer to a constant region list. */
585typedef const VDREGIONLIST *PCVDREGIONLIST;
586/** Pointer to a region list pointer. */
587typedef PVDREGIONLIST *PPVDREGIONLIST;
588
589/** @name Valid region list flags.
590 * @{
591 */
592/** When set the region start offset and size are given in numbers of blocks
593 * instead of byte offsets and sizes. */
594#define VD_REGION_LIST_F_LOC_SIZE_BLOCKS RT_BIT_32(0)
595/** Mask of all valid flags. */
596#define VD_REGION_LIST_F_VALID (VD_REGION_LIST_F_LOC_SIZE_BLOCKS)
597/** @} */
598
599/**
600 * VBox HDD Container main structure.
601 */
602/* Forward declaration, VBOXHDD structure is visible only inside VBox HDD module. */
603struct VBOXHDD;
604typedef struct VBOXHDD VBOXHDD;
605typedef VBOXHDD *PVBOXHDD;
606
607/**
608 * Initializes HDD backends.
609 *
610 * @returns VBox status code.
611 */
612VBOXDDU_DECL(int) VDInit(void);
613
614/**
615 * Destroys loaded HDD backends.
616 *
617 * @returns VBox status code.
618 */
619VBOXDDU_DECL(int) VDShutdown(void);
620
621/**
622 * Loads a single plugin given by filename.
623 *
624 * @returns VBox status code.
625 * @param pszFilename The plugin filename to load.
626 */
627VBOXDDU_DECL(int) VDPluginLoadFromFilename(const char *pszFilename);
628
629/**
630 * Load all plugins from a given path.
631 *
632 * @returns VBox statuse code.
633 * @param pszPath The path to load plugins from.
634 */
635VBOXDDU_DECL(int) VDPluginLoadFromPath(const char *pszPath);
636
637/**
638 * Unloads a single plugin given by filename.
639 *
640 * @returns VBox status code.
641 * @param pszFilename The plugin filename to unload.
642 */
643VBOXDDU_DECL(int) VDPluginUnloadFromFilename(const char *pszFilename);
644
645/**
646 * Unload all plugins from a given path.
647 *
648 * @returns VBox statuse code.
649 * @param pszPath The path to unload plugins from.
650 */
651VBOXDDU_DECL(int) VDPluginUnloadFromPath(const char *pszPath);
652
653/**
654 * Lists all HDD backends and their capabilities in a caller-provided buffer.
655 *
656 * @return VBox status code.
657 * VERR_BUFFER_OVERFLOW if not enough space is passed.
658 * @param cEntriesAlloc Number of list entries available.
659 * @param pEntries Pointer to array for the entries.
660 * @param pcEntriesUsed Number of entries returned.
661 */
662VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
663 unsigned *pcEntriesUsed);
664
665/**
666 * Lists the capabilities of a backend identified by its name.
667 *
668 * @return VBox status code.
669 * @param pszBackend The backend name (case insensitive).
670 * @param pEntry Pointer to an entry.
671 */
672VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
673
674/**
675 * Lists all filters and their capabilities in a caller-provided buffer.
676 *
677 * @return VBox status code.
678 * VERR_BUFFER_OVERFLOW if not enough space is passed.
679 * @param cEntriesAlloc Number of list entries available.
680 * @param pEntries Pointer to array for the entries.
681 * @param pcEntriesUsed Number of entries returned.
682 */
683VBOXDDU_DECL(int) VDFilterInfo(unsigned cEntriesAlloc, PVDFILTERINFO pEntries,
684 unsigned *pcEntriesUsed);
685
686/**
687 * Lists the capabilities of a filter identified by its name.
688 *
689 * @return VBox status code.
690 * @param pszFilter The filter name (case insensitive).
691 * @param pEntry Pointer to an entry.
692 */
693VBOXDDU_DECL(int) VDFilterInfoOne(const char *pszFilter, PVDFILTERINFO pEntry);
694
695/**
696 * Allocates and initializes an empty HDD container.
697 * No image files are opened.
698 *
699 * @return VBox status code.
700 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
701 * @param enmType Type of the image container.
702 * @param ppDisk Where to store the reference to HDD container.
703 */
704VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, VDTYPE enmType, PVBOXHDD *ppDisk);
705
706/**
707 * Destroys HDD container.
708 * If container has opened image files they will be closed.
709 *
710 * @return VBox status code.
711 * @param pDisk Pointer to HDD container.
712 */
713VBOXDDU_DECL(int) VDDestroy(PVBOXHDD pDisk);
714
715/**
716 * Try to get the backend name which can use this image.
717 *
718 * @return VBox status code.
719 * VINF_SUCCESS if a plugin was found.
720 * ppszFormat contains the string which can be used as backend name.
721 * VERR_NOT_SUPPORTED if no backend was found.
722 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
723 * @param pVDIfsImage Pointer to the per-image VD interface list.
724 * @param pszFilename Name of the image file for which the backend is queried.
725 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
726 * The returned pointer must be freed using RTStrFree().
727 * @param penmType Where to store the type of the image.
728 */
729VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
730 const char *pszFilename, char **ppszFormat, VDTYPE *penmType);
731
732/**
733 * Opens an image file.
734 *
735 * The first opened image file in HDD container must have a base image type,
736 * others (next opened images) must be differencing or undo images.
737 * Linkage is checked for differencing image to be consistent with the previously opened image.
738 * When another differencing image is opened and the last image was opened in read/write access
739 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
740 * other processes to use images in read-only mode too.
741 *
742 * Note that the image is opened in read-only mode if a read/write open is not possible.
743 * Use VDIsReadOnly to check open mode.
744 *
745 * @return VBox status code.
746 * @param pDisk Pointer to HDD container.
747 * @param pszBackend Name of the image file backend to use (case insensitive).
748 * @param pszFilename Name of the image file to open.
749 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
750 * @param pVDIfsImage Pointer to the per-image VD interface list.
751 */
752VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
753 const char *pszFilename, unsigned uOpenFlags,
754 PVDINTERFACE pVDIfsImage);
755
756/**
757 * Opens a cache image.
758 *
759 * @return VBox status code.
760 * @param pDisk Pointer to the HDD container which should use the cache image.
761 * @param pszBackend Name of the cache file backend to use (case insensitive).
762 * @param pszFilename Name of the cache image to open.
763 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
764 * @param pVDIfsCache Pointer to the per-cache VD interface list.
765 */
766VBOXDDU_DECL(int) VDCacheOpen(PVBOXHDD pDisk, const char *pszBackend,
767 const char *pszFilename, unsigned uOpenFlags,
768 PVDINTERFACE pVDIfsCache);
769
770/**
771 * Adds a filter to the disk.
772 *
773 * @returns VBox status code.
774 * @param pDisk Pointer to the HDD container which should use the filter.
775 * @param pszFilter Name of the filter backend to use (case insensitive).
776 * @param fFlags Flags which apply to the filter, combination of VD_FILTER_FLAGS_*
777 * defines.
778 * @param pVDIfsFilter Pointer to the per-filter VD interface list.
779 */
780VBOXDDU_DECL(int) VDFilterAdd(PVBOXHDD pDisk, const char *pszFilter, uint32_t fFlags,
781 PVDINTERFACE pVDIfsFilter);
782
783/**
784 * Creates and opens a new base image file.
785 *
786 * @return VBox status code.
787 * @param pDisk Pointer to HDD container.
788 * @param pszBackend Name of the image file backend to use (case insensitive).
789 * @param pszFilename Name of the image file to create.
790 * @param cbSize Image size in bytes.
791 * @param uImageFlags Flags specifying special image features.
792 * @param pszComment Pointer to image comment. NULL is ok.
793 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
794 * @param pLCHSGeometry Pointer to logical disk geometry <= (x,255,63). Not NULL.
795 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
796 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
797 * @param pVDIfsImage Pointer to the per-image VD interface list.
798 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
799 */
800VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
801 const char *pszFilename, uint64_t cbSize,
802 unsigned uImageFlags, const char *pszComment,
803 PCVDGEOMETRY pPCHSGeometry,
804 PCVDGEOMETRY pLCHSGeometry,
805 PCRTUUID pUuid, unsigned uOpenFlags,
806 PVDINTERFACE pVDIfsImage,
807 PVDINTERFACE pVDIfsOperation);
808
809/**
810 * Creates and opens a new differencing image file in HDD container.
811 * See comments for VDOpen function about differencing images.
812 *
813 * @return VBox status code.
814 * @param pDisk Pointer to HDD container.
815 * @param pszBackend Name of the image file backend to use (case insensitive).
816 * @param pszFilename Name of the differencing image file to create.
817 * @param uImageFlags Flags specifying special image features.
818 * @param pszComment Pointer to image comment. NULL is ok.
819 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
820 * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically.
821 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
822 * @param pVDIfsImage Pointer to the per-image VD interface list.
823 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
824 */
825VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
826 const char *pszFilename, unsigned uImageFlags,
827 const char *pszComment, PCRTUUID pUuid,
828 PCRTUUID pParentUuid, unsigned uOpenFlags,
829 PVDINTERFACE pVDIfsImage,
830 PVDINTERFACE pVDIfsOperation);
831
832/**
833 * Creates and opens new cache image file in HDD container.
834 *
835 * @return VBox status code.
836 * @param pDisk Name of the cache file backend to use (case insensitive).
837 * @param pszBackend Name of the image file backend to use (case insensitive).
838 * @param pszFilename Name of the differencing cache file to create.
839 * @param cbSize Maximum size of the cache.
840 * @param uImageFlags Flags specifying special cache features.
841 * @param pszComment Pointer to image comment. NULL is ok.
842 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
843 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
844 * @param pVDIfsCache Pointer to the per-cache VD interface list.
845 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
846 */
847VBOXDDU_DECL(int) VDCreateCache(PVBOXHDD pDisk, const char *pszBackend,
848 const char *pszFilename, uint64_t cbSize,
849 unsigned uImageFlags, const char *pszComment,
850 PCRTUUID pUuid, unsigned uOpenFlags,
851 PVDINTERFACE pVDIfsCache, PVDINTERFACE pVDIfsOperation);
852
853/**
854 * Merges two images (not necessarily with direct parent/child relationship).
855 * As a side effect the source image and potentially the other images which
856 * are also merged to the destination are deleted from both the disk and the
857 * images in the HDD container.
858 *
859 * @return VBox status code.
860 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
861 * @param pDisk Pointer to HDD container.
862 * @param nImageFrom Image number to merge from, counts from 0. 0 is always base image of container.
863 * @param nImageTo Image number to merge to, counts from 0. 0 is always base image of container.
864 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
865 */
866VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
867 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
868
869/**
870 * Copies an image from one HDD container to another - extended version.
871 *
872 * The copy is opened in the target HDD container. It is possible to convert
873 * between different image formats, because the backend for the destination may
874 * be different from the source. If both the source and destination reference
875 * the same HDD container, then the image is moved (by copying/deleting or
876 * renaming) to the new location. The source container is unchanged if the move
877 * operation fails, otherwise the image at the new location is opened in the
878 * same way as the old one was.
879 *
880 * @note The read/write accesses across disks are not synchronized, just the
881 * accesses to each disk. Once there is a use case which requires a defined
882 * read/write behavior in this situation this needs to be extended.
883 *
884 * @return VBox status code.
885 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
886 *
887 * @param pDiskFrom Pointer to source HDD container.
888 * @param nImage Image number, counts from 0. 0 is always base image
889 * of container.
890 * @param pDiskTo Pointer to destination HDD container.
891 * @param pszBackend Name of the image file backend to use (may be NULL
892 * to use the same as the source, case insensitive).
893 * @param pszFilename New name of the image (may be NULL to specify that
894 * the copy destination is the destination container,
895 * or if pDiskFrom == pDiskTo, i.e. when moving).
896 * @param fMoveByRename If true, attempt to perform a move by renaming (if
897 * successful the new size is ignored).
898 * @param cbSize New image size (0 means leave unchanged).
899 * @param nImageFromSame The number of the last image in the source chain
900 * having the same content as the image in the
901 * destination chain given by nImageToSame or
902 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the
903 * content of both containers is unknown. See the
904 * notes for further information.
905 * @param nImageToSame The number of the last image in the destination
906 * chain having the same content as the image in the
907 * source chain given by nImageFromSame or
908 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the
909 * content of both containers is unknown. See the notes
910 * for further information.
911 * @param uImageFlags Flags specifying special destination image features.
912 * @param pDstUuid New UUID of the destination image. If NULL, a new
913 * UUID is created. This parameter is used if and only
914 * if a true copy is created. In all rename/move cases
915 * or copy to existing image cases the modification
916 * UUIDs are copied over.
917 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
918 * Only used if the destination image is created.
919 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
920 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
921 * destination image.
922 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
923 * for the destination operation.
924 *
925 * @note Using nImageFromSame and nImageToSame can lead to a significant speedup
926 * when copying an image but can also lead to a corrupted copy if used
927 * incorrectly. It is mainly useful when cloning a chain of images and it
928 * is known that the virtual disk content of the two chains is exactly the
929 * same upto a certain image. Example:
930 * Imagine the chain of images which consist of a base and one diff
931 * image. Copying the chain starts with the base image. When copying
932 * the first diff image VDCopy() will read the data from the diff of
933 * the source chain and probably from the base image again in case the
934 * diff doesn't has data for the block. However the block will be
935 * optimized away because VDCopy() reads data from the base image of
936 * the destination chain compares the to and suppresses the write
937 * because the data is unchanged. For a lot of diff images this will be
938 * a huge waste of I/O bandwidth if the diff images contain only few
939 * changes. Because it is known that the base image of the source and
940 * the destination chain have the same content it is enough to check
941 * the diff image for changed data and copy it to the destination diff
942 * image which is achieved with nImageFromSame and nImageToSame.
943 * Setting both to 0 can suppress a lot of I/O.
944 */
945VBOXDDU_DECL(int) VDCopyEx(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
946 const char *pszBackend, const char *pszFilename,
947 bool fMoveByRename, uint64_t cbSize,
948 unsigned nImageFromSame, unsigned nImageToSame,
949 unsigned uImageFlags, PCRTUUID pDstUuid,
950 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
951 PVDINTERFACE pDstVDIfsImage,
952 PVDINTERFACE pDstVDIfsOperation);
953
954/**
955 * Copies an image from one HDD container to another.
956 * The copy is opened in the target HDD container.
957 * It is possible to convert between different image formats, because the
958 * backend for the destination may be different from the source.
959 * If both the source and destination reference the same HDD container,
960 * then the image is moved (by copying/deleting or renaming) to the new location.
961 * The source container is unchanged if the move operation fails, otherwise
962 * the image at the new location is opened in the same way as the old one was.
963 *
964 * @note The read/write accesses across disks are not synchronized, just the
965 * accesses to each disk. Once there is a use case which requires a defined
966 * read/write behavior in this situation this needs to be extended.
967 *
968 * @return VBox status code.
969 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
970 * @param pDiskFrom Pointer to source HDD container.
971 * @param nImage Image number, counts from 0. 0 is always base image of container.
972 * @param pDiskTo Pointer to destination HDD container.
973 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
974 * @param pszFilename New name of the image (may be NULL to specify that the
975 * copy destination is the destination container, or
976 * if pDiskFrom == pDiskTo, i.e. when moving).
977 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
978 * @param cbSize New image size (0 means leave unchanged).
979 * @param uImageFlags Flags specifying special destination image features.
980 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
981 * This parameter is used if and only if a true copy is created.
982 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
983 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
984 * Only used if the destination image is created.
985 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
986 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
987 * destination image.
988 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
989 * for the destination operation.
990 */
991VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
992 const char *pszBackend, const char *pszFilename,
993 bool fMoveByRename, uint64_t cbSize,
994 unsigned uImageFlags, PCRTUUID pDstUuid,
995 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
996 PVDINTERFACE pDstVDIfsImage,
997 PVDINTERFACE pDstVDIfsOperation);
998
999/**
1000 * Optimizes the storage consumption of an image. Typically the unused blocks
1001 * have to be wiped with zeroes to achieve a substantial reduced storage use.
1002 * Another optimization done is reordering the image blocks, which can provide
1003 * a significant performance boost, as reads and writes tend to use less random
1004 * file offsets.
1005 *
1006 * @note Compaction is treated as a single operation with regard to thread
1007 * synchronization, which means that it potentially blocks other activities for
1008 * a long time. The complexity of compaction would grow even more if concurrent
1009 * accesses have to be handled.
1010 *
1011 * @return VBox status code.
1012 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1013 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
1014 * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but
1015 * this isn't supported yet.
1016 * @param pDisk Pointer to HDD container.
1017 * @param nImage Image number, counts from 0. 0 is always base image of container.
1018 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1019 */
1020VBOXDDU_DECL(int) VDCompact(PVBOXHDD pDisk, unsigned nImage, PVDINTERFACE pVDIfsOperation);
1021
1022/**
1023 * Resizes the given disk image to the given size. It is OK if there are
1024 * multiple images open in the container. In this case the last disk image
1025 * will be resized.
1026 *
1027 * @return VBox status
1028 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
1029 * @return VERR_NOT_SUPPORTED if this kind of image can't be compacted.
1030 *
1031 * @param pDisk Pointer to the HDD container.
1032 * @param cbSize New size of the image.
1033 * @param pPCHSGeometry Pointer to the new physical disk geometry <= (16383,16,63). Not NULL.
1034 * @param pLCHSGeometry Pointer to the new logical disk geometry <= (x,255,63). Not NULL.
1035 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1036 */
1037VBOXDDU_DECL(int) VDResize(PVBOXHDD pDisk, uint64_t cbSize,
1038 PCVDGEOMETRY pPCHSGeometry,
1039 PCVDGEOMETRY pLCHSGeometry,
1040 PVDINTERFACE pVDIfsOperation);
1041
1042/**
1043 * Prepares the given disk for use by the added filters. This applies to all
1044 * opened images in the chain which might be opened read/write temporary.
1045 *
1046 * @return VBox status code.
1047 *
1048 * @param pDisk Pointer to the HDD container.
1049 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
1050 */
1051VBOXDDU_DECL(int) VDPrepareWithFilters(PVBOXHDD pDisk, PVDINTERFACE pVDIfsOperation);
1052
1053/**
1054 * Closes the last opened image file in HDD container.
1055 * If previous image file was opened in read-only mode (the normal case) and
1056 * the last opened image is in read-write mode then the previous image will be
1057 * reopened in read/write mode.
1058 *
1059 * @return VBox status code.
1060 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
1061 * @param pDisk Pointer to HDD container.
1062 * @param fDelete If true, delete the image from the host disk.
1063 */
1064VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete);
1065
1066/**
1067 * Removes the last added filter in the HDD container from the specified chain.
1068 *
1069 * @return VBox status code.
1070 * @retval VERR_VD_NOT_OPENED if no filter is present for the disk.
1071 * @param pDisk Pointer to HDD container.
1072 * @param fFlags Combination of VD_FILTER_FLAGS_* defines.
1073 */
1074VBOXDDU_DECL(int) VDFilterRemove(PVBOXHDD pDisk, uint32_t fFlags);
1075
1076/**
1077 * Closes the currently opened cache image file in HDD container.
1078 *
1079 * @return VBox status code.
1080 * @return VERR_VD_NOT_OPENED if no cache is opened in HDD container.
1081 * @param pDisk Pointer to HDD container.
1082 * @param fDelete If true, delete the image from the host disk.
1083 */
1084VBOXDDU_DECL(int) VDCacheClose(PVBOXHDD pDisk, bool fDelete);
1085
1086/**
1087 * Closes all opened image files in HDD container.
1088 *
1089 * @return VBox status code.
1090 * @param pDisk Pointer to HDD container.
1091 */
1092VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk);
1093
1094/**
1095 * Removes all filters of the given HDD container.
1096 *
1097 * @return VBox status code.
1098 * @param pDisk Pointer to HDD container.
1099 */
1100VBOXDDU_DECL(int) VDFilterRemoveAll(PVBOXHDD pDisk);
1101
1102/**
1103 * Read data from virtual HDD.
1104 *
1105 * @return VBox status code.
1106 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
1107 * @param pDisk Pointer to HDD container.
1108 * @param uOffset Offset of first reading byte from start of disk.
1109 * Must be aligned to a sector boundary.
1110 * @param pvBuf Pointer to buffer for reading data.
1111 * @param cbRead Number of bytes to read.
1112 * Must be aligned to a sector boundary.
1113 */
1114VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
1115
1116/**
1117 * Write data to virtual HDD.
1118 *
1119 * @return VBox status code.
1120 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
1121 * @param pDisk Pointer to HDD container.
1122 * @param uOffset Offset of first writing byte from start of disk.
1123 * Must be aligned to a sector boundary.
1124 * @param pvBuf Pointer to buffer for writing data.
1125 * @param cbWrite Number of bytes to write.
1126 * Must be aligned to a sector boundary.
1127 */
1128VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
1129
1130/**
1131 * Make sure the on disk representation of a virtual HDD is up to date.
1132 *
1133 * @return VBox status code.
1134 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
1135 * @param pDisk Pointer to HDD container.
1136 */
1137VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk);
1138
1139/**
1140 * Get number of opened images in HDD container.
1141 *
1142 * @return Number of opened images for HDD container. 0 if no images have been opened.
1143 * @param pDisk Pointer to HDD container.
1144 */
1145VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk);
1146
1147/**
1148 * Get read/write mode of HDD container.
1149 *
1150 * @return Virtual disk ReadOnly status.
1151 * @return true if no image is opened in HDD container.
1152 * @param pDisk Pointer to HDD container.
1153 */
1154VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk);
1155
1156/**
1157 * Get sector size of an image in HDD container.
1158 *
1159 * @return Virtual disk sector size in bytes.
1160 * @return 0 if image with specified number was not opened.
1161 * @param pDisk Pointer to HDD container.
1162 * @param nImage Image number, counts from 0. 0 is always base image of container.
1163 */
1164VBOXDDU_DECL(uint32_t) VDGetSectorSize(PVBOXHDD pDisk, unsigned nImage);
1165
1166/**
1167 * Get total capacity of an image in HDD container.
1168 *
1169 * @return Virtual disk size in bytes.
1170 * @return 0 if image with specified number was not opened.
1171 * @param pDisk Pointer to HDD container.
1172 * @param nImage Image number, counts from 0. 0 is always base image of container.
1173 */
1174VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage);
1175
1176/**
1177 * Get total file size of an image in HDD container.
1178 *
1179 * @return Virtual disk size in bytes.
1180 * @return 0 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 */
1184VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage);
1185
1186/**
1187 * Get virtual disk PCHS geometry of an image in HDD container.
1188 *
1189 * @return VBox status code.
1190 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1191 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1192 * @param pDisk Pointer to HDD container.
1193 * @param nImage Image number, counts from 0. 0 is always base image of container.
1194 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1195 */
1196VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage, PVDGEOMETRY pPCHSGeometry);
1197
1198/**
1199 * Store virtual disk PCHS geometry of an image in HDD container.
1200 *
1201 * @return VBox status code.
1202 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1203 * @param pDisk Pointer to HDD container.
1204 * @param nImage Image number, counts from 0. 0 is always base image of container.
1205 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1206 */
1207VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage, PCVDGEOMETRY pPCHSGeometry);
1208
1209/**
1210 * Get virtual disk LCHS geometry of an 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 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1215 * @param pDisk Pointer to HDD container.
1216 * @param nImage Image number, counts from 0. 0 is always base image of container.
1217 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1218 */
1219VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage, PVDGEOMETRY pLCHSGeometry);
1220
1221/**
1222 * Store virtual disk LCHS geometry of an image in HDD container.
1223 *
1224 * @return VBox status code.
1225 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1226 * @param pDisk Pointer to HDD container.
1227 * @param nImage Image number, counts from 0. 0 is always base image of container.
1228 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1229 */
1230VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage, PCVDGEOMETRY pLCHSGeometry);
1231
1232/**
1233 * Queries the available regions of an image in the given VD container.
1234 *
1235 * @return VBox status code.
1236 * @retval VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1237 * @retval VERR_NOT_SUPPORTED if the image backend doesn't support region lists.
1238 * @param pDisk Pointer to HDD container.
1239 * @param nImage Image number, counts from 0. 0 is always base image of container.
1240 * @param fFlags Combination of VD_REGION_LIST_F_* flags.
1241 * @param ppRegionList Where to store the pointer to the region list on success, must be freed
1242 * with VDRegionListFree().
1243 */
1244VBOXDDU_DECL(int) VDQueryRegions(PVBOXHDD pDisk, unsigned nImage, uint32_t fFlags,
1245 PPVDREGIONLIST ppRegionList);
1246
1247/**
1248 * Frees a region list previously queried with VDQueryRegions().
1249 *
1250 * @return nothing.
1251 * @param pRegionList The region list to free.
1252 */
1253VBOXDDU_DECL(void) VDRegionListFree(PVDREGIONLIST pRegionList);
1254
1255/**
1256 * Get version 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 container.
1262 * @param puVersion Where to store the image version.
1263 */
1264VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage, unsigned *puVersion);
1265
1266/**
1267 * List the capabilities of image backend in HDD container.
1268 *
1269 * @return VBox status code.
1270 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1271 * @param pDisk Pointer to the HDD container.
1272 * @param nImage Image number, counts from 0. 0 is always base image of container.
1273 * @param pBackendInfo Where to store the backend information.
1274 */
1275VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage, PVDBACKENDINFO pBackendInfo);
1276
1277/**
1278 * Get flags of image in HDD container.
1279 *
1280 * @return VBox status code.
1281 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1282 * @param pDisk Pointer to HDD container.
1283 * @param nImage Image number, counts from 0. 0 is always base image of container.
1284 * @param puImageFlags Where to store the image flags.
1285 */
1286VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puImageFlags);
1287
1288/**
1289 * Get open flags of image in HDD container.
1290 *
1291 * @return VBox status code.
1292 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1293 * @param pDisk Pointer to HDD container.
1294 * @param nImage Image number, counts from 0. 0 is always base image of container.
1295 * @param puOpenFlags Where to store the image open flags.
1296 */
1297VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage, unsigned *puOpenFlags);
1298
1299/**
1300 * Set open flags of image in HDD container.
1301 * This operation may cause file locking changes and/or files being reopened.
1302 * Note that in case of unrecoverable error all images in HDD container will be closed.
1303 *
1304 * @return VBox status code.
1305 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1306 * @param pDisk Pointer to HDD container.
1307 * @param nImage Image number, counts from 0. 0 is always base image of container.
1308 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1309 */
1310VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage, unsigned uOpenFlags);
1311
1312/**
1313 * Get base filename of image in HDD container. Some image formats use
1314 * other filenames as well, so don't use this for anything but informational
1315 * purposes.
1316 *
1317 * @return VBox status code.
1318 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1319 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1320 * @param pDisk Pointer to HDD container.
1321 * @param nImage Image number, counts from 0. 0 is always base image of container.
1322 * @param pszFilename Where to store the image file name.
1323 * @param cbFilename Size of buffer pszFilename points to.
1324 */
1325VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage, char *pszFilename, unsigned cbFilename);
1326
1327/**
1328 * Get the comment line of image in HDD container.
1329 *
1330 * @return VBox status code.
1331 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1332 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1333 * @param pDisk Pointer to HDD container.
1334 * @param nImage Image number, counts from 0. 0 is always base image of container.
1335 * @param pszComment Where to store the comment string of image. NULL is ok.
1336 * @param cbComment The size of pszComment buffer. 0 is ok.
1337 */
1338VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage, char *pszComment, unsigned cbComment);
1339
1340/**
1341 * Changes the comment line of image in HDD container.
1342 *
1343 * @return VBox status code.
1344 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1345 * @param pDisk Pointer to HDD container.
1346 * @param nImage Image number, counts from 0. 0 is always base image of container.
1347 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1348 */
1349VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage, const char *pszComment);
1350
1351/**
1352 * Get UUID of image in HDD container.
1353 *
1354 * @return VBox status code.
1355 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1356 * @param pDisk Pointer to HDD container.
1357 * @param nImage Image number, counts from 0. 0 is always base image of container.
1358 * @param pUuid Where to store the image UUID.
1359 */
1360VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1361
1362/**
1363 * Set the image's UUID. Should not be used by normal applications.
1364 *
1365 * @return VBox status code.
1366 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1367 * @param pDisk Pointer to HDD container.
1368 * @param nImage Image number, counts from 0. 0 is always base image of container.
1369 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1370 */
1371VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1372
1373/**
1374 * Get last modification UUID of image in HDD container.
1375 *
1376 * @return VBox status code.
1377 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1378 * @param pDisk Pointer to HDD container.
1379 * @param nImage Image number, counts from 0. 0 is always base image of container.
1380 * @param pUuid Where to store the image modification UUID.
1381 */
1382VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1383
1384/**
1385 * Set the image's last modification UUID. Should not be used by normal applications.
1386 *
1387 * @return VBox status code.
1388 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1389 * @param pDisk Pointer to HDD container.
1390 * @param nImage Image number, counts from 0. 0 is always base image of container.
1391 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1392 */
1393VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1394
1395/**
1396 * Get parent UUID of image in HDD container.
1397 *
1398 * @return VBox status code.
1399 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1400 * @param pDisk Pointer to HDD container.
1401 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1402 * @param pUuid Where to store the parent image UUID.
1403 */
1404VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid);
1405
1406/**
1407 * Set the image's parent UUID. Should not be used by normal applications.
1408 *
1409 * @return VBox status code.
1410 * @param pDisk Pointer to HDD container.
1411 * @param nImage Image number, counts from 0. 0 is always base image of container.
1412 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1413 */
1414VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid);
1415
1416
1417/**
1418 * Debug helper - dumps all opened images in HDD container into the log file.
1419 *
1420 * @param pDisk Pointer to HDD container.
1421 */
1422VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk);
1423
1424
1425/**
1426 * Discards unused ranges given as a list.
1427 *
1428 * @return VBox status code.
1429 * @param pDisk Pointer to HDD container.
1430 * @param paRanges The array of ranges to discard.
1431 * @param cRanges Number of entries in the array.
1432 *
1433 * @note In contrast to VDCompact() the ranges are always discarded even if they
1434 * appear to contain data. This method is mainly used to implement TRIM support.
1435 */
1436VBOXDDU_DECL(int) VDDiscardRanges(PVBOXHDD pDisk, PCRTRANGE paRanges, unsigned cRanges);
1437
1438
1439/**
1440 * Start an asynchronous read request.
1441 *
1442 * @return VBox status code.
1443 * @param pDisk Pointer to the HDD container.
1444 * @param off The offset of the virtual disk to read from.
1445 * @param cbRead How many bytes to read.
1446 * @param pcSgBuf Pointer to the S/G buffer to read into.
1447 * @param pfnComplete Completion callback.
1448 * @param pvUser1 User data which is passed on completion.
1449 * @param pvUser2 User data which is passed on completion.
1450 */
1451VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t off, size_t cbRead,
1452 PCRTSGBUF pcSgBuf,
1453 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1454 void *pvUser1, void *pvUser2);
1455
1456
1457/**
1458 * Start an asynchronous write request.
1459 *
1460 * @return VBox status code.
1461 * @param pDisk Pointer to the HDD container.
1462 * @param off The offset of the virtual disk to write to.
1463 * @param cbWrite How many bytes to write.
1464 * @param pcSgBuf Pointer to the S/G buffer to write from.
1465 * @param pfnComplete Completion callback.
1466 * @param pvUser1 User data which is passed on completion.
1467 * @param pvUser2 User data which is passed on completion.
1468 */
1469VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t off, size_t cbWrite,
1470 PCRTSGBUF pcSgBuf,
1471 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1472 void *pvUser1, void *pvUser2);
1473
1474
1475/**
1476 * Start an asynchronous flush request.
1477 *
1478 * @return VBox status code.
1479 * @param pDisk Pointer to the HDD container.
1480 * @param pfnComplete Completion callback.
1481 * @param pvUser1 User data which is passed on completion.
1482 * @param pvUser2 User data which is passed on completion.
1483 */
1484VBOXDDU_DECL(int) VDAsyncFlush(PVBOXHDD pDisk,
1485 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1486 void *pvUser1, void *pvUser2);
1487
1488/**
1489 * Start an asynchronous discard request.
1490 *
1491 * @return VBox status code.
1492 * @param pDisk Pointer to HDD container.
1493 * @param paRanges The array of ranges to discard.
1494 * @param cRanges Number of entries in the array.
1495 * @param pfnComplete Completion callback.
1496 * @param pvUser1 User data which is passed on completion.
1497 * @param pvUser2 User data which is passed on completion.
1498 */
1499VBOXDDU_DECL(int) VDAsyncDiscardRanges(PVBOXHDD pDisk, PCRTRANGE paRanges, unsigned cRanges,
1500 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1501 void *pvUser1, void *pvUser2);
1502
1503/**
1504 * Tries to repair a corrupted image.
1505 *
1506 * @return VBox status code.
1507 * @retval VERR_VD_IMAGE_REPAIR_NOT_SUPPORTED if the backend does not support repairing the image.
1508 * @retval VERR_VD_IMAGE_REPAIR_IMPOSSIBLE if the corruption is to severe to repair the image.
1509 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1510 * @param pVDIfsImage Pointer to the per-image VD interface list.
1511 * @param pszFilename Name of the image file to repair.
1512 * @param pszBackend The backend to use.
1513 * @param fFlags Combination of the VD_REPAIR_* flags.
1514 */
1515VBOXDDU_DECL(int) VDRepair(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
1516 const char *pszFilename, const char *pszBackend, uint32_t fFlags);
1517
1518/**
1519 * Create a VFS file handle from the given HDD container.
1520 *
1521 * @return VBox status code.
1522 * @param pDisk Pointer to HDD container.
1523 * @param fFlags Combination of the VD_VFSFILE_* flags.
1524 * @param phVfsFile Where to store the handle to the VFS file on
1525 * success.
1526 */
1527VBOXDDU_DECL(int) VDCreateVfsFileFromDisk(PVBOXHDD pDisk, uint32_t fFlags,
1528 PRTVFSFILE phVfsFile);
1529
1530RT_C_DECLS_END
1531
1532/** @} */
1533
1534#endif
1535
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