VirtualBox

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

Last change on this file since 52664 was 52585, checked in by vboxsync, 10 years ago

Storage/VD + Main/ExtPackManager+VirtualBox+SystemProperties: handle unloading of VD plugin from VBoxSVC when extpack is uninstalled, fixes extpack uninstall problems related to VDPluginCrypt.dll on Windows

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

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