VirtualBox

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

Last change on this file since 76390 was 76390, checked in by vboxsync, 5 years ago

VBox/vd.h: Don't include VBox/err.h for no good reason. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 75.3 KB
Line 
1/** @file
2 * VBox HDD Container API.
3 */
4
5/*
6 * Copyright (C) 2006-2017 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/vdmedia.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 Virtual Disk 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 VDISKRAW_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 VDISKRAW_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 VDISKRAW_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 VDISKRAWPARTDESC
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 VDISKRAW_FLAGS_*. */
166 uint32_t uFlags;
167} VDISKRAWPARTDESC, *PVDISKRAWPARTDESC;
168
169/**
170 * Auxiliary data structure for difference between GPT and MBR
171 * disks.
172 */
173typedef enum VDISKPARTTYPE
174{
175 MBR,
176 GPT
177} VDISKPARTTYPE;
178
179/**
180 * Auxiliary data structure for creating raw disks.
181 */
182typedef struct VDISKRAW
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 VDISKRAW_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 PVDISKRAWPARTDESC pPartDescs;
198 /** Partitioning type of the disk */
199 VDISKPARTTYPE uPartitioningType;
200} VDISKRAW, *PVDISKRAW;
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 uint32_t fOpen;
288 AssertMsg(!(fOpenFlags & VD_OPEN_FLAGS_READONLY) || !fCreate, ("Image can't be opened readonly while being created\n"));
289
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 Configuration interface key handling flags.
345 * @{
346 */
347/** Mandatory config key. Not providing a value for this key will cause
348 * the backend to fail. */
349#define VD_CFGKEY_MANDATORY RT_BIT(0)
350/** Expert config key. Not showing it by default in the GUI is is probably
351 * a good idea, as the average user won't understand it easily. */
352#define VD_CFGKEY_EXPERT RT_BIT(1)
353/** @}*/
354
355
356/**
357 * Configuration value type for configuration information interface.
358 */
359typedef enum VDCFGVALUETYPE
360{
361 /** Integer value. */
362 VDCFGVALUETYPE_INTEGER = 1,
363 /** String value. */
364 VDCFGVALUETYPE_STRING,
365 /** Bytestring value. */
366 VDCFGVALUETYPE_BYTES
367} VDCFGVALUETYPE;
368
369
370/**
371 * Structure describing configuration keys required/supported by a backend
372 * through the config interface.
373 */
374typedef struct VDCONFIGINFO
375{
376 /** Key name of the configuration. */
377 const char *pszKey;
378 /** Pointer to default value (descriptor). NULL if no useful default value
379 * can be specified. */
380 const char *pszDefaultValue;
381 /** Value type for this key. */
382 VDCFGVALUETYPE enmValueType;
383 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
384 uint64_t uKeyFlags;
385} VDCONFIGINFO;
386
387/** Pointer to structure describing configuration keys. */
388typedef VDCONFIGINFO *PVDCONFIGINFO;
389
390/** Pointer to const structure describing configuration keys. */
391typedef const VDCONFIGINFO *PCVDCONFIGINFO;
392
393/**
394 * Structure describing a file extension.
395 */
396typedef struct VDFILEEXTENSION
397{
398 /** Pointer to the NULL-terminated string containing the extension. */
399 const char *pszExtension;
400 /** The device type the extension supports. */
401 VDTYPE enmType;
402} VDFILEEXTENSION;
403
404/** Pointer to a structure describing a file extension. */
405typedef VDFILEEXTENSION *PVDFILEEXTENSION;
406
407/** Pointer to a const structure describing a file extension. */
408typedef const VDFILEEXTENSION *PCVDFILEEXTENSION;
409
410/**
411 * Data structure for returning a list of backend capabilities.
412 */
413typedef struct VDBACKENDINFO
414{
415 /** Name of the backend. Must be unique even with case insensitive comparison. */
416 const char *pszBackend;
417 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
418 uint64_t uBackendCaps;
419 /** Pointer to a NULL-terminated array of strings, containing the supported
420 * file extensions. Note that some backends do not work on files, so this
421 * pointer may just contain NULL. */
422 PCVDFILEEXTENSION paFileExtensions;
423 /** Pointer to an array of structs describing each supported config key.
424 * Terminated by a NULL config key. Note that some backends do not support
425 * the configuration interface, so this pointer may just contain NULL.
426 * Mandatory if the backend sets VD_CAP_CONFIG. */
427 PCVDCONFIGINFO paConfigInfo;
428 /** Returns a human readable hard disk location string given a
429 * set of hard disk configuration keys. The returned string is an
430 * equivalent of the full file path for image-based hard disks.
431 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
432 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
433 /** Returns a human readable hard disk name string given a
434 * set of hard disk configuration keys. The returned string is an
435 * equivalent of the file name part in the full file path for
436 * image-based hard disks. Mandatory for backends with no
437 * VD_CAP_FILE and NULL otherwise. */
438 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
439} VDBACKENDINFO, *PVDBACKENDINFO;
440
441/**
442 * Data structure for returning a list of filter capabilities.
443 */
444typedef struct VDFILTERINFO
445{
446 /** Name of the filter. Must be unique even with case insensitive comparison. */
447 const char *pszFilter;
448 /** Pointer to an array of structs describing each supported config key.
449 * Terminated by a NULL config key. Note that some filters do not support
450 * the configuration interface, so this pointer may just contain NULL. */
451 PCVDCONFIGINFO paConfigInfo;
452} VDFILTERINFO, *PVDFILTERINFO;
453
454
455/**
456 * Request completion callback for the async read/write API.
457 */
458typedef DECLCALLBACK(void) FNVDASYNCTRANSFERCOMPLETE (void *pvUser1, void *pvUser2, int rcReq);
459/** Pointer to a transfer compelte callback. */
460typedef FNVDASYNCTRANSFERCOMPLETE *PFNVDASYNCTRANSFERCOMPLETE;
461
462/**
463 * VD Container main structure.
464 */
465/* Forward declaration, VDISK structure is visible only inside VD module. */
466struct VDISK;
467typedef struct VDISK VDISK;
468typedef VDISK *PVDISK;
469
470/**
471 * Initializes HDD backends.
472 *
473 * @returns VBox status code.
474 */
475VBOXDDU_DECL(int) VDInit(void);
476
477/**
478 * Destroys loaded HDD backends.
479 *
480 * @returns VBox status code.
481 */
482VBOXDDU_DECL(int) VDShutdown(void);
483
484/**
485 * Loads a single plugin given by filename.
486 *
487 * @returns VBox status code.
488 * @param pszFilename The plugin filename to load.
489 */
490VBOXDDU_DECL(int) VDPluginLoadFromFilename(const char *pszFilename);
491
492/**
493 * Load all plugins from a given path.
494 *
495 * @returns VBox statuse code.
496 * @param pszPath The path to load plugins from.
497 */
498VBOXDDU_DECL(int) VDPluginLoadFromPath(const char *pszPath);
499
500/**
501 * Unloads a single plugin given by filename.
502 *
503 * @returns VBox status code.
504 * @param pszFilename The plugin filename to unload.
505 */
506VBOXDDU_DECL(int) VDPluginUnloadFromFilename(const char *pszFilename);
507
508/**
509 * Unload all plugins from a given path.
510 *
511 * @returns VBox statuse code.
512 * @param pszPath The path to unload plugins from.
513 */
514VBOXDDU_DECL(int) VDPluginUnloadFromPath(const char *pszPath);
515
516/**
517 * Lists all HDD backends and their capabilities in a caller-provided buffer.
518 *
519 * @return VBox status code.
520 * VERR_BUFFER_OVERFLOW if not enough space is passed.
521 * @param cEntriesAlloc Number of list entries available.
522 * @param pEntries Pointer to array for the entries.
523 * @param pcEntriesUsed Number of entries returned.
524 */
525VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
526 unsigned *pcEntriesUsed);
527
528/**
529 * Lists the capabilities of a backend identified by its name.
530 *
531 * @return VBox status code.
532 * @param pszBackend The backend name (case insensitive).
533 * @param pEntry Pointer to an entry.
534 */
535VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
536
537/**
538 * Lists all filters and their capabilities in a caller-provided buffer.
539 *
540 * @return VBox status code.
541 * VERR_BUFFER_OVERFLOW if not enough space is passed.
542 * @param cEntriesAlloc Number of list entries available.
543 * @param pEntries Pointer to array for the entries.
544 * @param pcEntriesUsed Number of entries returned.
545 */
546VBOXDDU_DECL(int) VDFilterInfo(unsigned cEntriesAlloc, PVDFILTERINFO pEntries,
547 unsigned *pcEntriesUsed);
548
549/**
550 * Lists the capabilities of a filter identified by its name.
551 *
552 * @return VBox status code.
553 * @param pszFilter The filter name (case insensitive).
554 * @param pEntry Pointer to an entry.
555 */
556VBOXDDU_DECL(int) VDFilterInfoOne(const char *pszFilter, PVDFILTERINFO pEntry);
557
558/**
559 * Allocates and initializes an empty HDD container.
560 * No image files are opened.
561 *
562 * @return VBox status code.
563 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
564 * @param enmType Type of the image container.
565 * @param ppDisk Where to store the reference to HDD container.
566 */
567VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, VDTYPE enmType, PVDISK *ppDisk);
568
569/**
570 * Destroys HDD container.
571 * If container has opened image files they will be closed.
572 *
573 * @return VBox status code.
574 * @param pDisk Pointer to HDD container.
575 */
576VBOXDDU_DECL(int) VDDestroy(PVDISK pDisk);
577
578/**
579 * Try to get the backend name which can use this image.
580 *
581 * @return VBox status code.
582 * VINF_SUCCESS if a plugin was found.
583 * ppszFormat contains the string which can be used as backend name.
584 * VERR_NOT_SUPPORTED if no backend was found.
585 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
586 * @param pVDIfsImage Pointer to the per-image VD interface list.
587 * @param pszFilename Name of the image file for which the backend is queried.
588 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
589 * The returned pointer must be freed using RTStrFree().
590 * @param penmType Where to store the type of the image.
591 */
592VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
593 const char *pszFilename, char **ppszFormat, VDTYPE *penmType);
594
595/**
596 * Opens an image file.
597 *
598 * The first opened image file in HDD container must have a base image type,
599 * others (next opened images) must be differencing or undo images.
600 * Linkage is checked for differencing image to be consistent with the previously opened image.
601 * When another differencing image is opened and the last image was opened in read/write access
602 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
603 * other processes to use images in read-only mode too.
604 *
605 * Note that the image is opened in read-only mode if a read/write open is not possible.
606 * Use VDIsReadOnly to check open mode.
607 *
608 * @return VBox status code.
609 * @param pDisk Pointer to HDD container.
610 * @param pszBackend Name of the image file backend to use (case insensitive).
611 * @param pszFilename Name of the image file to open.
612 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
613 * @param pVDIfsImage Pointer to the per-image VD interface list.
614 */
615VBOXDDU_DECL(int) VDOpen(PVDISK pDisk, const char *pszBackend,
616 const char *pszFilename, unsigned uOpenFlags,
617 PVDINTERFACE pVDIfsImage);
618
619/**
620 * Opens a cache image.
621 *
622 * @return VBox status code.
623 * @param pDisk Pointer to the HDD container which should use the cache image.
624 * @param pszBackend Name of the cache file backend to use (case insensitive).
625 * @param pszFilename Name of the cache image to open.
626 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
627 * @param pVDIfsCache Pointer to the per-cache VD interface list.
628 */
629VBOXDDU_DECL(int) VDCacheOpen(PVDISK pDisk, const char *pszBackend,
630 const char *pszFilename, unsigned uOpenFlags,
631 PVDINTERFACE pVDIfsCache);
632
633/**
634 * Adds a filter to the disk.
635 *
636 * @returns VBox status code.
637 * @param pDisk Pointer to the HDD container which should use the filter.
638 * @param pszFilter Name of the filter backend to use (case insensitive).
639 * @param fFlags Flags which apply to the filter, combination of VD_FILTER_FLAGS_*
640 * defines.
641 * @param pVDIfsFilter Pointer to the per-filter VD interface list.
642 */
643VBOXDDU_DECL(int) VDFilterAdd(PVDISK pDisk, const char *pszFilter, uint32_t fFlags,
644 PVDINTERFACE pVDIfsFilter);
645
646/**
647 * Creates and opens a new base image file.
648 *
649 * @return VBox status code.
650 * @param pDisk Pointer to HDD container.
651 * @param pszBackend Name of the image file backend to use (case insensitive).
652 * @param pszFilename Name of the image file to create.
653 * @param cbSize Image size in bytes.
654 * @param uImageFlags Flags specifying special image features.
655 * @param pszComment Pointer to image comment. NULL is ok.
656 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
657 * @param pLCHSGeometry Pointer to logical disk geometry <= (x,255,63). Not NULL.
658 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
659 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
660 * @param pVDIfsImage Pointer to the per-image VD interface list.
661 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
662 */
663VBOXDDU_DECL(int) VDCreateBase(PVDISK pDisk, const char *pszBackend,
664 const char *pszFilename, uint64_t cbSize,
665 unsigned uImageFlags, const char *pszComment,
666 PCVDGEOMETRY pPCHSGeometry,
667 PCVDGEOMETRY pLCHSGeometry,
668 PCRTUUID pUuid, unsigned uOpenFlags,
669 PVDINTERFACE pVDIfsImage,
670 PVDINTERFACE pVDIfsOperation);
671
672/**
673 * Creates and opens a new differencing image file in HDD container.
674 * See comments for VDOpen function about differencing images.
675 *
676 * @return VBox status code.
677 * @param pDisk Pointer to HDD container.
678 * @param pszBackend Name of the image file backend to use (case insensitive).
679 * @param pszFilename Name of the differencing image file to create.
680 * @param uImageFlags Flags specifying special image features.
681 * @param pszComment Pointer to image comment. NULL is ok.
682 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
683 * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically.
684 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
685 * @param pVDIfsImage Pointer to the per-image VD interface list.
686 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
687 */
688VBOXDDU_DECL(int) VDCreateDiff(PVDISK pDisk, const char *pszBackend,
689 const char *pszFilename, unsigned uImageFlags,
690 const char *pszComment, PCRTUUID pUuid,
691 PCRTUUID pParentUuid, unsigned uOpenFlags,
692 PVDINTERFACE pVDIfsImage,
693 PVDINTERFACE pVDIfsOperation);
694
695/**
696 * Creates and opens new cache image file in HDD container.
697 *
698 * @return VBox status code.
699 * @param pDisk Name of the cache file backend to use (case insensitive).
700 * @param pszBackend Name of the image 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(PVDISK 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(PVDISK pDisk, unsigned nImageFrom,
730 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
731
732/**
733 * Copies an image from one HDD container to another - extended version.
734 *
735 * The copy is opened in the target HDD container. It is possible to convert
736 * between different image formats, because the backend for the destination may
737 * be different from the source. If both the source and destination reference
738 * the same HDD container, then the image is moved (by copying/deleting or
739 * renaming) to the new location. The source container is unchanged if the move
740 * operation fails, otherwise the image at the new location is opened in the
741 * same way as the old one was.
742 *
743 * @note The read/write accesses across disks are not synchronized, just the
744 * accesses to each disk. Once there is a use case which requires a defined
745 * read/write behavior in this situation this needs to be extended.
746 *
747 * @return VBox status code.
748 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
749 *
750 * @param pDiskFrom Pointer to source HDD container.
751 * @param nImage Image number, counts from 0. 0 is always base image
752 * of container.
753 * @param pDiskTo Pointer to destination HDD container.
754 * @param pszBackend Name of the image file backend to use (may be NULL
755 * to use the same as the source, case insensitive).
756 * @param pszFilename New name of the image (may be NULL to specify that
757 * the copy destination is the destination container,
758 * or if pDiskFrom == pDiskTo, i.e. when moving).
759 * @param fMoveByRename If true, attempt to perform a move by renaming (if
760 * successful the new size is ignored).
761 * @param cbSize New image size (0 means leave unchanged).
762 * @param nImageFromSame The number of the last image in the source chain
763 * having the same content as the image in the
764 * destination chain given by nImageToSame or
765 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the
766 * content of both containers is unknown. See the
767 * notes for further information.
768 * @param nImageToSame The number of the last image in the destination
769 * chain having the same content as the image in the
770 * source chain given by nImageFromSame or
771 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the
772 * content of both containers is unknown. See the notes
773 * for further information.
774 * @param uImageFlags Flags specifying special destination image features.
775 * @param pDstUuid New UUID of the destination image. If NULL, a new
776 * UUID is created. This parameter is used if and only
777 * if a true copy is created. In all rename/move cases
778 * or copy to existing image cases the modification
779 * UUIDs are copied over.
780 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
781 * Only used if the destination image is created.
782 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
783 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
784 * destination image.
785 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
786 * for the destination operation.
787 *
788 * @note Using nImageFromSame and nImageToSame can lead to a significant speedup
789 * when copying an image but can also lead to a corrupted copy if used
790 * incorrectly. It is mainly useful when cloning a chain of images and it
791 * is known that the virtual disk content of the two chains is exactly the
792 * same upto a certain image. Example:
793 * Imagine the chain of images which consist of a base and one diff
794 * image. Copying the chain starts with the base image. When copying
795 * the first diff image VDCopy() will read the data from the diff of
796 * the source chain and probably from the base image again in case the
797 * diff doesn't has data for the block. However the block will be
798 * optimized away because VDCopy() reads data from the base image of
799 * the destination chain compares the to and suppresses the write
800 * because the data is unchanged. For a lot of diff images this will be
801 * a huge waste of I/O bandwidth if the diff images contain only few
802 * changes. Because it is known that the base image of the source and
803 * the destination chain have the same content it is enough to check
804 * the diff image for changed data and copy it to the destination diff
805 * image which is achieved with nImageFromSame and nImageToSame.
806 * Setting both to 0 can suppress a lot of I/O.
807 */
808VBOXDDU_DECL(int) VDCopyEx(PVDISK pDiskFrom, unsigned nImage, PVDISK pDiskTo,
809 const char *pszBackend, const char *pszFilename,
810 bool fMoveByRename, uint64_t cbSize,
811 unsigned nImageFromSame, unsigned nImageToSame,
812 unsigned uImageFlags, PCRTUUID pDstUuid,
813 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
814 PVDINTERFACE pDstVDIfsImage,
815 PVDINTERFACE pDstVDIfsOperation);
816
817/**
818 * Copies an image from one HDD container to another.
819 * The copy is opened in the target HDD container.
820 * It is possible to convert between different image formats, because the
821 * backend for the destination may be different from the source.
822 * If both the source and destination reference the same HDD container,
823 * then the image is moved (by copying/deleting or renaming) to the new location.
824 * The source container is unchanged if the move operation fails, otherwise
825 * the image at the new location is opened in the same way as the old one was.
826 *
827 * @note The read/write accesses across disks are not synchronized, just the
828 * accesses to each disk. Once there is a use case which requires a defined
829 * read/write behavior in this situation this needs to be extended.
830 *
831 * @return VBox status code.
832 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
833 * @param pDiskFrom Pointer to source HDD container.
834 * @param nImage Image number, counts from 0. 0 is always base image of container.
835 * @param pDiskTo Pointer to destination HDD container.
836 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
837 * @param pszFilename New name of the image (may be NULL to specify that the
838 * copy destination is the destination container, or
839 * if pDiskFrom == pDiskTo, i.e. when moving).
840 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
841 * @param cbSize New image size (0 means leave unchanged).
842 * @param uImageFlags Flags specifying special destination image features.
843 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
844 * This parameter is used if and only if a true copy is created.
845 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
846 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
847 * Only used if the destination image is created.
848 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
849 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
850 * destination image.
851 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
852 * for the destination operation.
853 */
854VBOXDDU_DECL(int) VDCopy(PVDISK pDiskFrom, unsigned nImage, PVDISK pDiskTo,
855 const char *pszBackend, const char *pszFilename,
856 bool fMoveByRename, uint64_t cbSize,
857 unsigned uImageFlags, PCRTUUID pDstUuid,
858 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
859 PVDINTERFACE pDstVDIfsImage,
860 PVDINTERFACE pDstVDIfsOperation);
861
862/**
863 * Optimizes the storage consumption of an image. Typically the unused blocks
864 * have to be wiped with zeroes to achieve a substantial reduced storage use.
865 * Another optimization done is reordering the image blocks, which can provide
866 * a significant performance boost, as reads and writes tend to use less random
867 * file offsets.
868 *
869 * @note Compaction is treated as a single operation with regard to thread
870 * synchronization, which means that it potentially blocks other activities for
871 * a long time. The complexity of compaction would grow even more if concurrent
872 * accesses have to be handled.
873 *
874 * @return VBox status code.
875 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
876 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
877 * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but
878 * this isn't supported yet.
879 * @param pDisk Pointer to HDD container.
880 * @param nImage Image number, counts from 0. 0 is always base image of container.
881 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
882 */
883VBOXDDU_DECL(int) VDCompact(PVDISK pDisk, unsigned nImage, PVDINTERFACE pVDIfsOperation);
884
885/**
886 * Resizes the given disk image to the given size. It is OK if there are
887 * multiple images open in the container. In this case the last disk image
888 * will be resized.
889 *
890 * @return VBox status
891 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
892 * @return VERR_NOT_SUPPORTED if this kind of image can't be compacted.
893 *
894 * @param pDisk Pointer to the HDD container.
895 * @param cbSize New size of the image.
896 * @param pPCHSGeometry Pointer to the new physical disk geometry <= (16383,16,63). Not NULL.
897 * @param pLCHSGeometry Pointer to the new logical disk geometry <= (x,255,63). Not NULL.
898 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
899 */
900VBOXDDU_DECL(int) VDResize(PVDISK pDisk, uint64_t cbSize,
901 PCVDGEOMETRY pPCHSGeometry,
902 PCVDGEOMETRY pLCHSGeometry,
903 PVDINTERFACE pVDIfsOperation);
904
905/**
906 * Prepares the given disk for use by the added filters. This applies to all
907 * opened images in the chain which might be opened read/write temporary.
908 *
909 * @return VBox status code.
910 *
911 * @param pDisk Pointer to the HDD container.
912 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
913 */
914VBOXDDU_DECL(int) VDPrepareWithFilters(PVDISK pDisk, PVDINTERFACE pVDIfsOperation);
915
916/**
917 * Closes the last opened image file in HDD container.
918 * If previous image file was opened in read-only mode (the normal case) and
919 * the last opened image is in read-write mode then the previous image will be
920 * reopened in read/write mode.
921 *
922 * @return VBox status code.
923 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
924 * @param pDisk Pointer to HDD container.
925 * @param fDelete If true, delete the image from the host disk.
926 */
927VBOXDDU_DECL(int) VDClose(PVDISK pDisk, bool fDelete);
928
929/**
930 * Removes the last added filter in the HDD container from the specified chain.
931 *
932 * @return VBox status code.
933 * @retval VERR_VD_NOT_OPENED if no filter is present for the disk.
934 * @param pDisk Pointer to HDD container.
935 * @param fFlags Combination of VD_FILTER_FLAGS_* defines.
936 */
937VBOXDDU_DECL(int) VDFilterRemove(PVDISK pDisk, uint32_t fFlags);
938
939/**
940 * Closes the currently opened cache image file in HDD container.
941 *
942 * @return VBox status code.
943 * @return VERR_VD_NOT_OPENED if no cache is opened in HDD container.
944 * @param pDisk Pointer to HDD container.
945 * @param fDelete If true, delete the image from the host disk.
946 */
947VBOXDDU_DECL(int) VDCacheClose(PVDISK pDisk, bool fDelete);
948
949/**
950 * Closes all opened image files in HDD container.
951 *
952 * @return VBox status code.
953 * @param pDisk Pointer to HDD container.
954 */
955VBOXDDU_DECL(int) VDCloseAll(PVDISK pDisk);
956
957/**
958 * Removes all filters of the given HDD container.
959 *
960 * @return VBox status code.
961 * @param pDisk Pointer to HDD container.
962 */
963VBOXDDU_DECL(int) VDFilterRemoveAll(PVDISK pDisk);
964
965/**
966 * Read data from virtual HDD.
967 *
968 * @return VBox status code.
969 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
970 * @param pDisk Pointer to HDD container.
971 * @param uOffset Offset of first reading byte from start of disk.
972 * Must be aligned to a sector boundary.
973 * @param pvBuf Pointer to buffer for reading data.
974 * @param cbRead Number of bytes to read.
975 * Must be aligned to a sector boundary.
976 */
977VBOXDDU_DECL(int) VDRead(PVDISK pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
978
979/**
980 * Write data to virtual HDD.
981 *
982 * @return VBox status code.
983 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
984 * @param pDisk Pointer to HDD container.
985 * @param uOffset Offset of first writing byte from start of disk.
986 * Must be aligned to a sector boundary.
987 * @param pvBuf Pointer to buffer for writing data.
988 * @param cbWrite Number of bytes to write.
989 * Must be aligned to a sector boundary.
990 */
991VBOXDDU_DECL(int) VDWrite(PVDISK pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
992
993/**
994 * Make sure the on disk representation of a virtual HDD is up to date.
995 *
996 * @return VBox status code.
997 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
998 * @param pDisk Pointer to HDD container.
999 */
1000VBOXDDU_DECL(int) VDFlush(PVDISK pDisk);
1001
1002/**
1003 * Get number of opened images in HDD container.
1004 *
1005 * @return Number of opened images for HDD container. 0 if no images have been opened.
1006 * @param pDisk Pointer to HDD container.
1007 */
1008VBOXDDU_DECL(unsigned) VDGetCount(PVDISK pDisk);
1009
1010/**
1011 * Get read/write mode of HDD container.
1012 *
1013 * @return Virtual disk ReadOnly status.
1014 * @return true if no image is opened in HDD container.
1015 * @param pDisk Pointer to HDD container.
1016 */
1017VBOXDDU_DECL(bool) VDIsReadOnly(PVDISK pDisk);
1018
1019/**
1020 * Get sector size of an image in HDD container.
1021 *
1022 * @return Virtual disk sector size in bytes.
1023 * @return 0 if image with specified number was not opened.
1024 * @param pDisk Pointer to HDD container.
1025 * @param nImage Image number, counts from 0. 0 is always base image of container.
1026 */
1027VBOXDDU_DECL(uint32_t) VDGetSectorSize(PVDISK pDisk, unsigned nImage);
1028
1029/**
1030 * Get total capacity of an image in HDD container.
1031 *
1032 * @return Virtual disk size in bytes.
1033 * @return 0 if image with specified number was not opened.
1034 * @param pDisk Pointer to HDD container.
1035 * @param nImage Image number, counts from 0. 0 is always base image of container.
1036 */
1037VBOXDDU_DECL(uint64_t) VDGetSize(PVDISK pDisk, unsigned nImage);
1038
1039/**
1040 * Get total file size of an image in HDD container.
1041 *
1042 * @return Virtual disk size in bytes.
1043 * @return 0 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 */
1047VBOXDDU_DECL(uint64_t) VDGetFileSize(PVDISK pDisk, unsigned nImage);
1048
1049/**
1050 * Get virtual disk PCHS geometry of an image in HDD container.
1051 *
1052 * @return VBox status code.
1053 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1054 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1055 * @param pDisk Pointer to HDD container.
1056 * @param nImage Image number, counts from 0. 0 is always base image of container.
1057 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1058 */
1059VBOXDDU_DECL(int) VDGetPCHSGeometry(PVDISK pDisk, unsigned nImage, PVDGEOMETRY pPCHSGeometry);
1060
1061/**
1062 * Store virtual disk PCHS geometry of an image in HDD container.
1063 *
1064 * @return VBox status code.
1065 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1066 * @param pDisk Pointer to HDD container.
1067 * @param nImage Image number, counts from 0. 0 is always base image of container.
1068 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1069 */
1070VBOXDDU_DECL(int) VDSetPCHSGeometry(PVDISK pDisk, unsigned nImage, PCVDGEOMETRY pPCHSGeometry);
1071
1072/**
1073 * Get virtual disk LCHS geometry of an image in HDD container.
1074 *
1075 * @return VBox status code.
1076 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1077 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1078 * @param pDisk Pointer to HDD container.
1079 * @param nImage Image number, counts from 0. 0 is always base image of container.
1080 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1081 */
1082VBOXDDU_DECL(int) VDGetLCHSGeometry(PVDISK pDisk, unsigned nImage, PVDGEOMETRY pLCHSGeometry);
1083
1084/**
1085 * Store virtual disk LCHS geometry of an image in HDD container.
1086 *
1087 * @return VBox status code.
1088 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1089 * @param pDisk Pointer to HDD container.
1090 * @param nImage Image number, counts from 0. 0 is always base image of container.
1091 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1092 */
1093VBOXDDU_DECL(int) VDSetLCHSGeometry(PVDISK pDisk, unsigned nImage, PCVDGEOMETRY pLCHSGeometry);
1094
1095/**
1096 * Queries the available regions of an image in the given VD container.
1097 *
1098 * @return VBox status code.
1099 * @retval VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1100 * @retval VERR_NOT_SUPPORTED if the image backend doesn't support region lists.
1101 * @param pDisk Pointer to HDD container.
1102 * @param nImage Image number, counts from 0. 0 is always base image of container.
1103 * @param fFlags Combination of VD_REGION_LIST_F_* flags.
1104 * @param ppRegionList Where to store the pointer to the region list on success, must be freed
1105 * with VDRegionListFree().
1106 */
1107VBOXDDU_DECL(int) VDQueryRegions(PVDISK pDisk, unsigned nImage, uint32_t fFlags,
1108 PPVDREGIONLIST ppRegionList);
1109
1110/**
1111 * Frees a region list previously queried with VDQueryRegions().
1112 *
1113 * @return nothing.
1114 * @param pRegionList The region list to free.
1115 */
1116VBOXDDU_DECL(void) VDRegionListFree(PVDREGIONLIST pRegionList);
1117
1118/**
1119 * Get version of image in HDD container.
1120 *
1121 * @return VBox status code.
1122 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1123 * @param pDisk Pointer to HDD container.
1124 * @param nImage Image number, counts from 0. 0 is always base image of container.
1125 * @param puVersion Where to store the image version.
1126 */
1127VBOXDDU_DECL(int) VDGetVersion(PVDISK pDisk, unsigned nImage, unsigned *puVersion);
1128
1129/**
1130 * List the capabilities of image backend in HDD container.
1131 *
1132 * @return VBox status code.
1133 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1134 * @param pDisk Pointer to the HDD container.
1135 * @param nImage Image number, counts from 0. 0 is always base image of container.
1136 * @param pBackendInfo Where to store the backend information.
1137 */
1138VBOXDDU_DECL(int) VDBackendInfoSingle(PVDISK pDisk, unsigned nImage, PVDBACKENDINFO pBackendInfo);
1139
1140/**
1141 * Get flags of image in HDD container.
1142 *
1143 * @return VBox status code.
1144 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1145 * @param pDisk Pointer to HDD container.
1146 * @param nImage Image number, counts from 0. 0 is always base image of container.
1147 * @param puImageFlags Where to store the image flags.
1148 */
1149VBOXDDU_DECL(int) VDGetImageFlags(PVDISK pDisk, unsigned nImage, unsigned *puImageFlags);
1150
1151/**
1152 * Get open flags of image in HDD container.
1153 *
1154 * @return VBox status code.
1155 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1156 * @param pDisk Pointer to HDD container.
1157 * @param nImage Image number, counts from 0. 0 is always base image of container.
1158 * @param puOpenFlags Where to store the image open flags.
1159 */
1160VBOXDDU_DECL(int) VDGetOpenFlags(PVDISK pDisk, unsigned nImage, unsigned *puOpenFlags);
1161
1162/**
1163 * Set open flags of image in HDD container.
1164 * This operation may cause file locking changes and/or files being reopened.
1165 * Note that in case of unrecoverable error all images in HDD container will be closed.
1166 *
1167 * @return VBox status code.
1168 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1169 * @param pDisk Pointer to HDD container.
1170 * @param nImage Image number, counts from 0. 0 is always base image of container.
1171 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1172 */
1173VBOXDDU_DECL(int) VDSetOpenFlags(PVDISK pDisk, unsigned nImage, unsigned uOpenFlags);
1174
1175/**
1176 * Get base filename of image in HDD container. Some image formats use
1177 * other filenames as well, so don't use this for anything but informational
1178 * purposes.
1179 *
1180 * @return VBox status code.
1181 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1182 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1183 * @param pDisk Pointer to HDD container.
1184 * @param nImage Image number, counts from 0. 0 is always base image of container.
1185 * @param pszFilename Where to store the image file name.
1186 * @param cbFilename Size of buffer pszFilename points to.
1187 */
1188VBOXDDU_DECL(int) VDGetFilename(PVDISK pDisk, unsigned nImage, char *pszFilename, unsigned cbFilename);
1189
1190/**
1191 * Get the comment line of image in HDD container.
1192 *
1193 * @return VBox status code.
1194 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1195 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1196 * @param pDisk Pointer to HDD container.
1197 * @param nImage Image number, counts from 0. 0 is always base image of container.
1198 * @param pszComment Where to store the comment string of image. NULL is ok.
1199 * @param cbComment The size of pszComment buffer. 0 is ok.
1200 */
1201VBOXDDU_DECL(int) VDGetComment(PVDISK pDisk, unsigned nImage, char *pszComment, unsigned cbComment);
1202
1203/**
1204 * Changes the comment line of image in HDD container.
1205 *
1206 * @return VBox status code.
1207 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1208 * @param pDisk Pointer to HDD container.
1209 * @param nImage Image number, counts from 0. 0 is always base image of container.
1210 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1211 */
1212VBOXDDU_DECL(int) VDSetComment(PVDISK pDisk, unsigned nImage, const char *pszComment);
1213
1214/**
1215 * Get UUID of image in HDD container.
1216 *
1217 * @return VBox status code.
1218 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1219 * @param pDisk Pointer to HDD container.
1220 * @param nImage Image number, counts from 0. 0 is always base image of container.
1221 * @param pUuid Where to store the image UUID.
1222 */
1223VBOXDDU_DECL(int) VDGetUuid(PVDISK pDisk, unsigned nImage, PRTUUID pUuid);
1224
1225/**
1226 * Set the image's UUID. Should not be used by normal applications.
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 container.
1232 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1233 */
1234VBOXDDU_DECL(int) VDSetUuid(PVDISK pDisk, unsigned nImage, PCRTUUID pUuid);
1235
1236/**
1237 * Get last modification UUID of image in HDD container.
1238 *
1239 * @return VBox status code.
1240 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
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 Where to store the image modification UUID.
1244 */
1245VBOXDDU_DECL(int) VDGetModificationUuid(PVDISK pDisk, unsigned nImage, PRTUUID pUuid);
1246
1247/**
1248 * Set the image's last modification UUID. Should not be used by normal applications.
1249 *
1250 * @return VBox status code.
1251 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1252 * @param pDisk Pointer to HDD container.
1253 * @param nImage Image number, counts from 0. 0 is always base image of container.
1254 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1255 */
1256VBOXDDU_DECL(int) VDSetModificationUuid(PVDISK pDisk, unsigned nImage, PCRTUUID pUuid);
1257
1258/**
1259 * Get parent UUID of image in HDD container.
1260 *
1261 * @return VBox status code.
1262 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1263 * @param pDisk Pointer to HDD container.
1264 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1265 * @param pUuid Where to store the parent image UUID.
1266 */
1267VBOXDDU_DECL(int) VDGetParentUuid(PVDISK pDisk, unsigned nImage, PRTUUID pUuid);
1268
1269/**
1270 * Set the image's parent UUID. Should not be used by normal applications.
1271 *
1272 * @return VBox status code.
1273 * @param pDisk Pointer to HDD container.
1274 * @param nImage Image number, counts from 0. 0 is always base image of container.
1275 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1276 */
1277VBOXDDU_DECL(int) VDSetParentUuid(PVDISK pDisk, unsigned nImage, PCRTUUID pUuid);
1278
1279
1280/**
1281 * Debug helper - dumps all opened images in HDD container into the log file.
1282 *
1283 * @param pDisk Pointer to HDD container.
1284 */
1285VBOXDDU_DECL(void) VDDumpImages(PVDISK pDisk);
1286
1287
1288/**
1289 * Discards unused ranges given as a list.
1290 *
1291 * @return VBox status code.
1292 * @param pDisk Pointer to HDD container.
1293 * @param paRanges The array of ranges to discard.
1294 * @param cRanges Number of entries in the array.
1295 *
1296 * @note In contrast to VDCompact() the ranges are always discarded even if they
1297 * appear to contain data. This method is mainly used to implement TRIM support.
1298 */
1299VBOXDDU_DECL(int) VDDiscardRanges(PVDISK pDisk, PCRTRANGE paRanges, unsigned cRanges);
1300
1301
1302/**
1303 * Start an asynchronous read request.
1304 *
1305 * @return VBox status code.
1306 * @param pDisk Pointer to the HDD container.
1307 * @param off The offset of the virtual disk to read from.
1308 * @param cbRead How many bytes to read.
1309 * @param pcSgBuf Pointer to the S/G buffer to read into.
1310 * @param pfnComplete Completion callback.
1311 * @param pvUser1 User data which is passed on completion.
1312 * @param pvUser2 User data which is passed on completion.
1313 */
1314VBOXDDU_DECL(int) VDAsyncRead(PVDISK pDisk, uint64_t off, size_t cbRead,
1315 PCRTSGBUF pcSgBuf,
1316 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1317 void *pvUser1, void *pvUser2);
1318
1319
1320/**
1321 * Start an asynchronous write request.
1322 *
1323 * @return VBox status code.
1324 * @param pDisk Pointer to the HDD container.
1325 * @param off The offset of the virtual disk to write to.
1326 * @param cbWrite How many bytes to write.
1327 * @param pcSgBuf Pointer to the S/G buffer to write from.
1328 * @param pfnComplete Completion callback.
1329 * @param pvUser1 User data which is passed on completion.
1330 * @param pvUser2 User data which is passed on completion.
1331 */
1332VBOXDDU_DECL(int) VDAsyncWrite(PVDISK pDisk, uint64_t off, size_t cbWrite,
1333 PCRTSGBUF pcSgBuf,
1334 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1335 void *pvUser1, void *pvUser2);
1336
1337
1338/**
1339 * Start an asynchronous flush request.
1340 *
1341 * @return VBox status code.
1342 * @param pDisk Pointer to the HDD container.
1343 * @param pfnComplete Completion callback.
1344 * @param pvUser1 User data which is passed on completion.
1345 * @param pvUser2 User data which is passed on completion.
1346 */
1347VBOXDDU_DECL(int) VDAsyncFlush(PVDISK pDisk,
1348 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1349 void *pvUser1, void *pvUser2);
1350
1351/**
1352 * Start an asynchronous discard request.
1353 *
1354 * @return VBox status code.
1355 * @param pDisk Pointer to HDD container.
1356 * @param paRanges The array of ranges to discard.
1357 * @param cRanges Number of entries in the array.
1358 * @param pfnComplete Completion callback.
1359 * @param pvUser1 User data which is passed on completion.
1360 * @param pvUser2 User data which is passed on completion.
1361 */
1362VBOXDDU_DECL(int) VDAsyncDiscardRanges(PVDISK pDisk, PCRTRANGE paRanges, unsigned cRanges,
1363 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1364 void *pvUser1, void *pvUser2);
1365
1366/**
1367 * Tries to repair a corrupted image.
1368 *
1369 * @return VBox status code.
1370 * @retval VERR_VD_IMAGE_REPAIR_NOT_SUPPORTED if the backend does not support repairing the image.
1371 * @retval VERR_VD_IMAGE_REPAIR_IMPOSSIBLE if the corruption is to severe to repair the image.
1372 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1373 * @param pVDIfsImage Pointer to the per-image VD interface list.
1374 * @param pszFilename Name of the image file to repair.
1375 * @param pszBackend The backend to use.
1376 * @param fFlags Combination of the VD_REPAIR_* flags.
1377 */
1378VBOXDDU_DECL(int) VDRepair(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
1379 const char *pszFilename, const char *pszBackend, uint32_t fFlags);
1380
1381/**
1382 * Create a VFS file handle from the given HDD container.
1383 *
1384 * @return VBox status code.
1385 * @param pDisk Pointer to HDD container.
1386 * @param fFlags Combination of the VD_VFSFILE_* flags.
1387 * @param phVfsFile Where to store the handle to the VFS file on
1388 * success.
1389 */
1390VBOXDDU_DECL(int) VDCreateVfsFileFromDisk(PVDISK pDisk, uint32_t fFlags,
1391 PRTVFSFILE phVfsFile);
1392
1393/** @defgroup grp_vd_ioiter I/O iterator
1394 * @{
1395 */
1396
1397/** Read metadata coming before each main data block addressed in the segment. */
1398#define VD_IOITER_SEG_F_PRE_METADATA RT_BIT_32(0)
1399/** Read the main user data of each addressed block in the segment. */
1400#define VD_IOITER_SEG_F_MAIN_DATA RT_BIT_32(1)
1401/** Read metadata coming after each main data block addressed in the segment. */
1402#define VD_IOITER_SEG_F_POST_METADATA RT_BIT_32(2)
1403/** Read checksum data of each data block addressed in the segment. */
1404#define VD_IOITER_SEG_F_CHKSUM RT_BIT_32(3)
1405/** Read all available data for each addressed block in the segment. */
1406#define VD_IOITER_SEG_F_AVAILABLE RT_BIT_32(4)
1407
1408/** The offset and size members in the segments use byte granularity instead of a
1409 * block address and number of blocks respectively. */
1410#define VDIOITER_F_BYTE_OFFSET_AND_SIZE RT_BIT_32(0)
1411
1412/**
1413 * VD I/O iterator segment.
1414 */
1415typedef struct VDIOITERSEG
1416{
1417 /** Start offset for this segment. */
1418 uint64_t offStartSeg;
1419 /** Size of the segment (bytes or blocks). */
1420 uint64_t cSizeSeg;
1421 /** Flags for this segment, see VD_IOITER_SEG_F_*. */
1422 uint32_t fFlags;
1423} VDIOITERSEG;
1424/** Pointer to a I/O iterator segment. */
1425typedef VDIOITERSEG *PVDIOITERSEG;
1426/** Pointer to a constant I/O iterator segment. */
1427typedef VDIOITERSEG *PCVDIOITERSEG;
1428
1429/** I/O iterator handle. */
1430typedef struct VDIOITERINT *VDIOITER;
1431/** Pointer to a I/O iterator handle. */
1432typedef VDIOITER *PVDIOITER;
1433
1434/**
1435 * Create a new I/O iterator.
1436 *
1437 * @returns VBox status code.
1438 * @param pDisk The disk to create the iterator for.
1439 * @param phVdIoIter Where to store the handle to the I/O iterator on success.
1440 * @param paIoIterSegs The segments for the iterator, can be destroyed after the call.
1441 * @param cIoIterSegs Number of segments.
1442 * @param fFlags Flags for the iterator, see VDIOITER_F_*
1443 */
1444VBOXDDU_DECL(int) VDIoIterCreate(PVDISK pDisk, PVDIOITER phVdIoIter, PCVDIOITERSEG paIoIterSegs,
1445 uint32_t cIoIterSegs, uint32_t fFlags);
1446
1447/**
1448 * Retains the reference count of the given I/O iterator.
1449 *
1450 * @returns New reference count.
1451 * @param hVdIoIter The I/O iterator handle.
1452 */
1453VBOXDDU_DECL(uint32_t) VDIoIterRetain(VDIOITER hVdIoIter);
1454
1455/**
1456 * Releases the reference count of the given I/O iterator.
1457 *
1458 * @returns New reference count, on 0 the iterator is destroyed.
1459 * @param hVdIoIter The I/O iterator handle.
1460 */
1461VBOXDDU_DECL(uint32_t) VDIoIterRelease(VDIOITER hVdIoIter);
1462
1463/**
1464 * Returns the number of segments in the given I/O iterator.
1465 *
1466 * @returns Number of segments.
1467 * @param hVdIoIter The I/O iterator handle.
1468 */
1469VBOXDDU_DECL(uint32_t) VDIoIterGetSegmentCount(VDIOITER hVdIoIter);
1470
1471/**
1472 * Returns the flags of the given I/O iterator.
1473 *
1474 * @returns Flags.
1475 * @param hVdIoIter The I/O iterator handle.
1476 */
1477VBOXDDU_DECL(uint32_t) VDIoIterGetFlags(VDIOITER hVdIoIter);
1478
1479/**
1480 * Queries the properties of the given segment for the given I/O iterator.
1481 *
1482 * @returns VBox status code.
1483 * @param hVdIoIter The I/O iterator handle.
1484 * @param idx The segment index to query.
1485 * @param pSegment Where to store the segment properties on success.
1486 */
1487VBOXDDU_DECL(int) VDIoIterQuerySegment(VDIOITER hVdIoIter, uint32_t idx, PVDIOITERSEG pSegment);
1488
1489/** @} */
1490
1491
1492/** @defgroup grp_vd_io_buf I/O buffer management API.
1493 * @{
1494 */
1495
1496/** VD I/O buffer manager handle. */
1497typedef struct VDIOBUFMGRINT *VDIOBUFMGR;
1498/** Pointer to VD I/O buffer manager handle. */
1499typedef VDIOBUFMGR *PVDIOBUFMGR;
1500
1501/** VD I/O buffer handle. */
1502typedef struct VDIOBUFINT *VDIOBUF;
1503/** Pointer to a VD I/O buffer handle. */
1504typedef VDIOBUF *PVDIOBUF;
1505
1506/** Default I/O buffer manager flags. */
1507#define VD_IOBUFMGR_F_DEFAULT (0)
1508/** I/O buffer memory needs to be non pageable (for example because it contains sensitive data
1509 * which shouldn't end up in swap unencrypted). */
1510#define VD_IOBUFMGR_F_REQUIRE_NOT_PAGABLE RT_BIT(0)
1511
1512/** Pointer to VD I/O buffer callbacks. */
1513typedef struct VDIOBUFCALLBACKS *PVDIOBUFCALLBACKS;
1514/** Pointer to const VD I/O buffer callbacks. */
1515typedef const struct VDIOBUFCALLBACKS *PCVDIOBUFCALLBACKS;
1516
1517/**
1518 * VD I/O buffer callbacks.
1519 */
1520typedef struct VDIOBUFCALLBACKS
1521{
1522 /**
1523 * Copy data from the memory buffer of the caller to the callees memory buffer for the given request.
1524 *
1525 * @returns VBox status code.
1526 * @retval VERR_PDM_MEDIAEX_IOBUF_OVERFLOW if there is not enough room to store the data.
1527 * @param pInterface Pointer to the interface structure containing the called function pointer.
1528 * @param hIoBuf The I/O request handle.
1529 * @param pvIoBufAlloc The allocator specific memory for this request.
1530 * @param offDst The destination offset from the start to write the data to.
1531 * @param pSgBuf The S/G buffer to read the data from.
1532 * @param cbCopy How many bytes to copy.
1533 */
1534 DECLR3CALLBACKMEMBER(int, pfnIoBufCopyFromBuf, (PVDIOBUFCALLBACKS pInterface, VDIOBUF hIoBuf,
1535 void *pvIoBufAlloc, uint32_t offDst, PRTSGBUF pSgBuf,
1536 size_t cbCopy));
1537
1538 /**
1539 * Copy data to the memory buffer of the caller from the callees memory buffer for the given request.
1540 *
1541 * @returns VBox status code.
1542 * @retval VERR_PDM_MEDIAEX_IOBUF_UNDERRUN if there is not enough data to copy from the buffer.
1543 * @param pInterface Pointer to the interface structure containing the called function pointer.
1544 * @param hIoBuf The I/O request handle.
1545 * @param pvIoBufAlloc The allocator specific memory for this request.
1546 * @param offSrc The offset from the start of the buffer to read the data from.
1547 * @param pSgBuf The S/G buffer to write the data to.
1548 * @param cbCopy How many bytes to copy.
1549 */
1550 DECLR3CALLBACKMEMBER(int, pfnIoBufCopyToBuf, (PVDIOBUFCALLBACKS pInterface, VDIOBUF hIoBuf,
1551 void *pvIoBufAlloc, uint32_t offSrc, PRTSGBUF pSgBuf,
1552 size_t cbCopy));
1553
1554 /**
1555 * Queries a pointer to the memory buffer for the request from the drive/device above.
1556 *
1557 * @returns VBox status code.
1558 * @retval VERR_NOT_SUPPORTED if this is not supported for this request.
1559 * @param pInterface Pointer to the interface structure containing the called function pointer.
1560 * @param hIoBuf The I/O request handle.
1561 * @param pvIoBufAlloc The allocator specific memory for this request.
1562 * @param offBuf The offset from the start of the buffer to get the buffer address.
1563 * @param cbBuf The number of bytes requested.
1564 * @param ppvBuf Where to store the pointer to the guest buffer on success.
1565 * @param pcbBuf Where to store the size of the buffer on success.
1566 *
1567 * @note This is an optional feature of the entity implementing this interface to avoid overhead
1568 * by copying the data between buffers. If NULL it is not supported at all and the caller
1569 * has to resort to VDIOBUFCALLBACKS::pfnIoBufCopyToBuf and VDIOBUFCALLBACKS::pfnIoBufCopyFromBuf.
1570 * The same holds when VERR_NOT_SUPPORTED is returned.
1571 *
1572 * On the upside the caller of this interface might not call this method at all and just
1573 * use the before mentioned methods to copy the data between the buffers.
1574 */
1575 DECLR3CALLBACKMEMBER(int, pfnIoBufQueryBuf, (PVDIOBUFCALLBACKS pInterface, VDIOBUF hIoBuf,
1576 void *pvIoBufAlloc, uint32_t offBuf, size_t cbBuf,
1577 void **ppvBuf, size_t *pcbBuf));
1578
1579} VDIOBUFCALLBACKS;
1580
1581/**
1582 * Creates a new I/O buffer manager.
1583 *
1584 * @returns VBox status code.
1585 * @param phIoBufMgr Where to store the handle to the I/O buffer manager on success.
1586 * @param cbMax The maximum amount of I/O memory to allow. Trying to allocate more than
1587 * this will lead to out of memory errors. 0 for "unlimited" size (only restriction
1588 * is the available memory on the host).
1589 * @param fFlags Combination of VD_IOBUFMGR_F_*.
1590 * @param pIoBufClbks Memory copy callbacks between source and target memory regions, optional.
1591 * When NULL all I/O buffers must be allocated with a valid S/G buffer laying out the
1592 * memory.
1593 * @param cbIoBufAlloc How much to allocate extra in the I/O buffer for private use.
1594 */
1595VBOXDDU_DECL(int) VDIoBufMgrCreate(PVDIOBUFMGR phIoBufMgr, size_t cbMax, uint32_t fFlags,
1596 PVDIOBUFCALLBACKS pIoBufClbks, size_t cbIoBufAlloc);
1597
1598/**
1599 * Destroys the given I/O buffer manager.
1600 *
1601 * @returns VBox status code.
1602 * @retval VERR_INVALID_STATE if there are still buffers allocated by the given manager.
1603 * @param hIoBufMgr The I/O buffer manager.
1604 */
1605VBOXDDU_DECL(int) VDIoBufMgrDestroy(VDIOBUFMGR hIoBufMgr);
1606
1607/**-
1608 * Allocate a new I/O buffer.
1609 *
1610 * @returns VBox status code.
1611 * @param hIoBufMgr The I/O buffer manager to use.
1612 * @param phIoBuf Where to store the I/O buffer handle on success.
1613 * @param ppvIoBufAlloc Where to store the pointe to the private party on success.
1614 * @param pSgBuf The S/G buffer to use, optional. If NULL the I/O buffer callbacks
1615 * supplied when creating the owning manager are used to transfer the
1616 * data.
1617 * @param cbBuf Size of the buffer in bytes.
1618 */
1619VBOXDDU_DECL(int) VDIoBufMgrAllocBuf(VDIOBUFMGR hIoBufMgr, PVDIOBUF phIoBuf, void **ppvIoBufAlloc,
1620 PCRTSGBUF pSgBuf, size_t cbBuf);
1621
1622/**
1623 * Retains the I/O buffer reference count.
1624 *
1625 * @returns New reference count.
1626 * @param hIoBuf The I/O buffer handle.
1627 */
1628VBOXDDU_DECL(uint32_t) VDIoBufRetain(VDIOBUF hIoBuf);
1629
1630/**
1631 * Releases the given I/O buffer reference.
1632 *
1633 * @returns New reference count, on 0 the I/O buffer is destroyed.
1634 * @param hIoBuf The I/O buffer handle.
1635 */
1636VBOXDDU_DECL(uint32_t) VDIoBufRelease(VDIOBUF hIoBuf);
1637
1638/** @} */
1639
1640
1641/** @defgroup grp_vd_ioqueue I/O queues
1642 * @{
1643 */
1644
1645/** VD I/O queue handle. */
1646typedef struct VDIOQUEUEINT *VDIOQUEUE;
1647/** Pointer to an VD I/O queue handle. */
1648typedef VDIOQUEUE *PVDIOQUEUE;
1649
1650/** VD I/O queue request handle. */
1651typedef struct VDIOREQINT *VDIOREQ;
1652/** Pointer to an VD I/O queue request handle. */
1653typedef VDIOREQ *PVDIOREQ;
1654
1655/** A I/O request ID. */
1656typedef uint64_t VDIOREQID;
1657
1658/**
1659 * I/O request type.
1660 */
1661typedef enum VDIOREQTYPE
1662{
1663 /** Invalid request type. */
1664 VDIOREQTYPE_INVALID = 0,
1665 /** Read request. */
1666 VDIOREQTYPE_READ,
1667 /** Write request. */
1668 VDIOREQTYPE_WRITE,
1669 /** Flush request. */
1670 VDIOREQTYPE_FLUSH,
1671 /** Discard request. */
1672 VDIOREQTYPE_DISCARD,
1673 /** 32bit hack. */
1674 VDIOREQTYPE_32BIT_HACK = 0x7fffffff
1675} VDIOREQTYPE;
1676/** Pointer to a request type. */
1677typedef VDIOREQTYPE *PVDIOREQTYPE;
1678
1679/**
1680 * I/O queue request completion callback.
1681 *
1682 * @returns nothing.
1683 * @param hVdIoQueue The VD I/O queue handle.
1684 * @param pDisk The disk the queue is attached to.
1685 * @param hVdIoReq The VD I/O request which completed.
1686 * @param pvVdIoReq Pointer to the allocator specific memory for this request.
1687 * @param rcReq The completion status code.
1688 */
1689typedef DECLCALLBACK(void) FNVDIOQUEUEREQCOMPLETE(VDIOQUEUE hVdIoQueue, PVDISK pDisk,
1690 VDIOREQ hVdIoReq, void *pvVdIoReq,
1691 int rcReq);
1692/** Pointer to a VD I/O queue request completion callback. */
1693typedef FNVDIOQUEUEREQCOMPLETE *PFNVDIOQUEUEREQCOMPLETE;
1694
1695
1696/**
1697 * Creates a new I/O queue.
1698 *
1699 * @returns VBox status code.
1700 * @param phVdIoQueue Where to store the handle to the I/O queue on success.
1701 * @param pfnIoReqComplete The completion handle to call when a request on the specified queue completes.
1702 * @param cbIoReqAlloc The extra amount of memory to allocate and associate with allocated requests
1703 * for use by the caller.
1704 * @param iPriority The priority of the queue from 0..UINT32_MAX. The lower the number the higher
1705 * the priority of the queue.
1706 */
1707VBOXDDU_DECL(int) VDIoQueueCreate(PVDIOQUEUE phVdIoQueue, PFNVDIOQUEUEREQCOMPLETE pfnIoReqComplete,
1708 size_t cbIoReqAlloc, uint32_t iPriority);
1709
1710/**
1711 * Destroys the given I/O queue.
1712 *
1713 * @returns VBox status code.
1714 * @param hVdIoQueue The I/O queue handle.
1715 */
1716VBOXDDU_DECL(int) VDIoQueueDestroy(VDIOQUEUE hVdIoQueue);
1717
1718/**
1719 * Attaches the given I/O queue to the given virtual disk container.
1720 *
1721 * @returns VBox status code.
1722 * @param pDisk The disk container handle.
1723 * @param hVdIoQueue The I/O queue to attach.
1724 */
1725VBOXDDU_DECL(int) VDIoQueueAttach(PVDISK pDisk, VDIOQUEUE hVdIoQueue);
1726
1727/**
1728 * Detaches the given I/O queue from the currently attached disk container.
1729 *
1730 * @returns VBox status code.
1731 * @param hVdIoQueue The I/O queue.
1732 * @param fPurge Flag whether to cancel all active requests on this queue
1733 * before detaching.
1734 */
1735VBOXDDU_DECL(int) VDIoQueueDetach(VDIOQUEUE hVdIoQueue, bool fPurge);
1736
1737/**
1738 * Purges all requests on the given queue.
1739 *
1740 * @returns VBox status code.
1741 * @param hVdIoQueue The I/O queue.
1742 */
1743VBOXDDU_DECL(int) VDIoQueuePurge(VDIOQUEUE hVdIoQueue);
1744
1745/**
1746 * Allocates a new request from the given queue.
1747 *
1748 * @returns VBox status code.
1749 * @param hVdIoQueue The I/O queue.
1750 * @param phVdIoReq Where to store the handle of the request on success.
1751 * @param ppvVdIoReq Where to store the pointer to the allocator usable memory on success.
1752 * @param uIoReqId The request ID to assign to the request for canceling.
1753 */
1754VBOXDDU_DECL(int) VDIoQueueReqAlloc(VDIOQUEUE hVdIoQueue, PVDIOREQ phVdIoReq,
1755 void **ppvVdIoReq, VDIOREQID uIoReqId);
1756
1757/**
1758 * Frees a given non active request.
1759 *
1760 * @returns VBox status code.
1761 * @param hVdIoReq The I/O request to free.
1762 */
1763VBOXDDU_DECL(int) VDIoQueueReqFree(VDIOREQ hVdIoReq);
1764
1765/**
1766 * Cancels an active request by the given request ID.
1767 *
1768 * @returns VBox status code.
1769 * @param hVdIoQueue The I/O queue to cancel the request on.
1770 * @param uIoReqId The request ID.
1771 */
1772VBOXDDU_DECL(int) VDIoQueueReqCancelById(VDIOQUEUE hVdIoQueue, VDIOREQID uIoReqId);
1773
1774/**
1775 * Cancels an active request by the given handle.
1776 *
1777 * @returns VBox status code.
1778 * @param hVdIoReq The I/O request handle to cancel.
1779 */
1780VBOXDDU_DECL(int) VDIoQueueReqCancelByHandle(VDIOREQ hVdIoReq);
1781
1782/**
1783 * Submit a new request to the queue the request was allocated from.
1784 *
1785 * @returns VBox status code.
1786 * @param hVdIoReq The I/O request handle to submit.
1787 * @param enmType The type of the request.
1788 * @param hVdIoIter The iterator to use, NULL for flush requests.
1789 * @param hVdIoBuf The I/O buffer handle to use, NULL for flush and discard requests.
1790 */
1791VBOXDDU_DECL(int) VDIoQueueReqSubmit(VDIOREQ hVdIoReq, VDIOREQTYPE enmType,
1792 VDIOITER hVdIoIter, VDIOBUF hVdIoBuf);
1793
1794/** @} */
1795
1796
1797RT_C_DECLS_END
1798
1799/** @} */
1800
1801#endif
1802
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use