VirtualBox

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

Last change on this file since 86716 was 85889, checked in by vboxsync, 4 years ago

VDISKRAWPARTDESC: Unconst some the pointers, it makes for ugly casts in new VMDK code. bugref:9224

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 76.5 KB
Line 
1/** @file
2 * VBox HDD Container API.
3 */
4
5/*
6 * Copyright (C) 2006-2020 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_INCLUDED_vd_h
27#define VBOX_INCLUDED_vd_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/assert.h>
33#include <iprt/string.h>
34#include <iprt/mem.h>
35#include <iprt/file.h>
36#include <iprt/net.h>
37#include <iprt/sg.h>
38#include <iprt/vfs.h>
39#include <VBox/cdefs.h>
40#include <VBox/types.h>
41#include <VBox/vdmedia.h>
42#include <VBox/vd-ifs.h>
43
44RT_C_DECLS_BEGIN
45
46#ifdef IN_RING0
47# error "There are no VBox HDD Container APIs available in Ring-0 Host Context!"
48#endif
49
50/** @defgroup grp_vd Virtual Disk Container
51 * @{
52 */
53
54/** Current VMDK image version. */
55#define VMDK_IMAGE_VERSION (0x0001)
56
57/** Current VDI image major version. */
58#define VDI_IMAGE_VERSION_MAJOR (0x0001)
59/** Current VDI image minor version. */
60#define VDI_IMAGE_VERSION_MINOR (0x0001)
61/** Current VDI image version. */
62#define VDI_IMAGE_VERSION ((VDI_IMAGE_VERSION_MAJOR << 16) | VDI_IMAGE_VERSION_MINOR)
63
64/** Get VDI major version from combined version. */
65#define VDI_GET_VERSION_MAJOR(uVer) ((uVer) >> 16)
66/** Get VDI minor version from combined version. */
67#define VDI_GET_VERSION_MINOR(uVer) ((uVer) & 0xffff)
68
69/** Placeholder for specifying the last opened image. */
70#define VD_LAST_IMAGE 0xffffffffU
71
72/** Placeholder for VDCopyEx to indicate that the image content is unknown. */
73#define VD_IMAGE_CONTENT_UNKNOWN 0xffffffffU
74
75/** @name VBox HDD container image flags
76 * Same values as MediumVariant API enum.
77 * @{
78 */
79/** No flags. */
80#define VD_IMAGE_FLAGS_NONE (0)
81/** Fixed image. */
82#define VD_IMAGE_FLAGS_FIXED (0x10000)
83/** Diff image. Mutually exclusive with fixed image. */
84#define VD_IMAGE_FLAGS_DIFF (0x20000)
85/** VMDK: Split image into 2GB extents. */
86#define VD_VMDK_IMAGE_FLAGS_SPLIT_2G (0x0001)
87/** VMDK: Raw disk image (giving access to a number of host partitions). */
88#define VD_VMDK_IMAGE_FLAGS_RAWDISK (0x0002)
89/** VMDK: stream optimized image, read only. */
90#define VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED (0x0004)
91/** VMDK: ESX variant, use in addition to other flags. */
92#define VD_VMDK_IMAGE_FLAGS_ESX (0x0008)
93/** VDI: Fill new blocks with zeroes while expanding image file. Only valid
94 * for newly created images, never set for opened existing images. */
95#define VD_VDI_IMAGE_FLAGS_ZERO_EXPAND (0x0100)
96
97/** Mask of valid image flags for VMDK. */
98#define VD_VMDK_IMAGE_FLAGS_MASK ( VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE \
99 | VD_VMDK_IMAGE_FLAGS_SPLIT_2G | VD_VMDK_IMAGE_FLAGS_RAWDISK \
100 | VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED | VD_VMDK_IMAGE_FLAGS_ESX)
101
102/** Mask of valid image flags for VDI. */
103#define VD_VDI_IMAGE_FLAGS_MASK (VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF | VD_IMAGE_FLAGS_NONE | VD_VDI_IMAGE_FLAGS_ZERO_EXPAND)
104
105/** Mask of all valid image flags for all formats. */
106#define VD_IMAGE_FLAGS_MASK (VD_VMDK_IMAGE_FLAGS_MASK | VD_VDI_IMAGE_FLAGS_MASK)
107
108/** Default image flags. */
109#define VD_IMAGE_FLAGS_DEFAULT (VD_IMAGE_FLAGS_NONE)
110/** @} */
111
112/** @name VD image repair flags
113 * @{
114 */
115/** Don't repair the image but check what needs to be done. */
116#define VD_REPAIR_DRY_RUN RT_BIT_32(0)
117
118/** Mask of all valid repair flags. */
119#define VD_REPAIR_FLAGS_MASK (VD_REPAIR_DRY_RUN)
120/** @} */
121
122/** @name VD image VFS file flags
123 * @{
124 */
125/** Destroy the VD disk container when the VFS file is released. */
126#define VD_VFSFILE_DESTROY_ON_RELEASE RT_BIT_32(0)
127
128/** Mask of all valid repair flags. */
129#define VD_VFSFILE_FLAGS_MASK (VD_VFSFILE_DESTROY_ON_RELEASE)
130/** @} */
131
132/** @name VDISKRAW_XXX - VBox raw disk or partition flags
133 * @{
134 */
135/** No special treatment. */
136#define VDISKRAW_NORMAL 0
137/** Whether this is a raw disk (where the partition information is ignored) or
138 * not. Valid only in the raw disk descriptor. */
139#define VDISKRAW_DISK RT_BIT(0)
140/** Open the corresponding raw disk or partition for reading only, no matter
141 * how the image is created or opened. */
142#define VDISKRAW_READONLY RT_BIT(1)
143/** @} */
144
145/**
146 * Auxiliary type for describing partitions on raw disks.
147 *
148 * The entries must be in ascending order (as far as uStart is concerned), and
149 * must not overlap. Note that this does not correspond 1:1 to partitions, it is
150 * describing the general meaning of contiguous areas on the disk.
151 */
152typedef struct VDISKRAWPARTDESC
153{
154 /** Device to use for this partition/data area. Can be the disk device if
155 * the offset field is set appropriately. If this is NULL, then this
156 * partition will not be accessible to the guest. The size of the data area
157 * must still be set correctly. */
158 char *pszRawDevice;
159 /** Pointer to the partitioning info. NULL means this is a regular data
160 * area on disk, non-NULL denotes data which should be copied to the
161 * partition data overlay. */
162 void *pvPartitionData;
163 /** Offset where the data starts in this device. */
164 uint64_t offStartInDevice;
165 /** Offset where the data starts in the disk. */
166 uint64_t offStartInVDisk;
167 /** Size of the data area. */
168 uint64_t cbData;
169 /** Flags for special treatment, see VDISKRAW_XXX. */
170 uint32_t uFlags;
171} VDISKRAWPARTDESC, *PVDISKRAWPARTDESC;
172
173/**
174 * Auxiliary data structure for difference between GPT and MBR disks.
175 */
176typedef enum VDISKPARTTYPE
177{
178 VDISKPARTTYPE_MBR = 0,
179 VDISKPARTTYPE_GPT
180} VDISKPARTTYPE;
181
182/**
183 * Auxiliary data structure for creating raw disks.
184 */
185typedef struct VDISKRAW
186{
187 /** Signature for structure. Must be 'R', 'A', 'W', '\\0'. Actually a trick
188 * to make logging of the comment string produce sensible results. */
189 char szSignature[4];
190 /** Flags for special treatment, see VDISKRAW_XXX. */
191 uint32_t uFlags;
192 /** Filename for the raw disk. Ignored for partitioned raw disks.
193 * For Linux e.g. /dev/sda, and for Windows e.g. //./PhysicalDisk0. */
194 char *pszRawDisk;
195 /** Partitioning type of the disk */
196 VDISKPARTTYPE enmPartitioningType;
197 /** Number of entries in the partition descriptor array. */
198 uint32_t cPartDescs;
199 /** Pointer to the partition descriptor array. */
200 PVDISKRAWPARTDESC pPartDescs;
201} VDISKRAW, *PVDISKRAW;
202
203
204/** @name VBox HDD container image open mode flags
205 * @{
206 */
207/** Try to open image in read/write exclusive access mode if possible, or in read-only elsewhere. */
208#define VD_OPEN_FLAGS_NORMAL 0
209/** Open image in read-only mode with sharing access with others. */
210#define VD_OPEN_FLAGS_READONLY RT_BIT(0)
211/** Honor zero block writes instead of ignoring them whenever possible.
212 * This is not supported by all formats. It is silently ignored in this case. */
213#define VD_OPEN_FLAGS_HONOR_ZEROES RT_BIT(1)
214/** Honor writes of the same data instead of ignoring whenever possible.
215 * This is handled generically, and is only meaningful for differential image
216 * formats. It is silently ignored otherwise. */
217#define VD_OPEN_FLAGS_HONOR_SAME RT_BIT(2)
218/** Do not perform the base/diff image check on open. This does NOT imply
219 * opening the image as readonly (would break e.g. adding UUIDs to VMDK files
220 * created by other products). Images opened with this flag should only be
221 * used for querying information, and nothing else. */
222#define VD_OPEN_FLAGS_INFO RT_BIT(3)
223/** Open image for asynchronous access. Only available if VD_CAP_ASYNC_IO is
224 * set. VDOpen fails with VERR_NOT_SUPPORTED if this operation is not supported for
225 * this kind of image. */
226#define VD_OPEN_FLAGS_ASYNC_IO RT_BIT(4)
227/** Allow sharing of the image for writable images. May be ignored if the
228 * format backend doesn't support this type of concurrent access. */
229#define VD_OPEN_FLAGS_SHAREABLE RT_BIT(5)
230/** Ask the backend to switch to sequential accesses if possible. Opening
231 * will not fail if it cannot do this, the flag will be simply ignored. */
232#define VD_OPEN_FLAGS_SEQUENTIAL RT_BIT(6)
233/** Allow the discard operation if supported. Only available if VD_CAP_DISCARD
234 * is set. VDOpen fails with VERR_VD_DISCARD_NOT_SUPPORTED if discarding is not
235 * supported. */
236#define VD_OPEN_FLAGS_DISCARD RT_BIT(7)
237/** Ignore all flush requests to workaround certain filesystems which are slow
238 * when writing a lot of cached data to the medium.
239 * Use with extreme care as a host crash can result in completely corrupted and
240 * unusable images.
241 */
242#define VD_OPEN_FLAGS_IGNORE_FLUSH RT_BIT(8)
243/**
244 * Return VINF_VD_NEW_ZEROED_BLOCK for reads from unallocated blocks.
245 * The caller who uses the flag has to make sure that the read doesn't cross
246 * a block boundary. Because the block size can differ between images reading one
247 * sector at a time is the safest solution.
248 */
249#define VD_OPEN_FLAGS_INFORM_ABOUT_ZERO_BLOCKS RT_BIT(9)
250/**
251 * Don't do unnecessary consistency checks when opening the image.
252 * Only valid when the image is opened in readonly because inconsistencies
253 * can lead to corrupted images in read-write mode.
254 */
255#define VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS RT_BIT(10)
256/** Mask of valid flags. */
257#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)
258/** @}*/
259
260/** @name VBox HDD container filter flags
261 * @{
262 */
263/** The filter is applied during writes. */
264#define VD_FILTER_FLAGS_WRITE RT_BIT(0)
265/** The filter is applied during reads. */
266#define VD_FILTER_FLAGS_READ RT_BIT(1)
267/** Open the filter in info mode. */
268#define VD_FILTER_FLAGS_INFO RT_BIT(2)
269/** Default set of filter flags. */
270#define VD_FILTER_FLAGS_DEFAULT (VD_FILTER_FLAGS_WRITE | VD_FILTER_FLAGS_READ)
271/** Mask of valid flags. */
272#define VD_FILTER_FLAGS_MASK (VD_FILTER_FLAGS_WRITE | VD_FILTER_FLAGS_READ | VD_FILTER_FLAGS_INFO)
273/** @} */
274
275/**
276 * Helper functions to handle open flags.
277 */
278
279/**
280 * Translate VD_OPEN_FLAGS_* to RTFile open flags.
281 *
282 * @return RTFile open flags.
283 * @param fOpenFlags VD_OPEN_FLAGS_* open flags.
284 * @param fCreate Flag that the file should be created.
285 */
286DECLINLINE(uint32_t) VDOpenFlagsToFileOpenFlags(unsigned fOpenFlags, bool fCreate)
287{
288 uint32_t fOpen;
289 AssertMsg(!(fOpenFlags & VD_OPEN_FLAGS_READONLY) || !fCreate, ("Image can't be opened readonly while being created\n"));
290
291 if (fOpenFlags & VD_OPEN_FLAGS_READONLY)
292 fOpen = RTFILE_O_READ | RTFILE_O_DENY_NONE;
293 else
294 {
295 fOpen = RTFILE_O_READWRITE;
296
297 if (fOpenFlags & VD_OPEN_FLAGS_SHAREABLE)
298 fOpen |= RTFILE_O_DENY_NONE;
299 else
300 fOpen |= RTFILE_O_DENY_WRITE;
301 }
302
303 if (!fCreate)
304 fOpen |= RTFILE_O_OPEN;
305 else
306 fOpen |= RTFILE_O_CREATE | RTFILE_O_NOT_CONTENT_INDEXED;
307
308 return fOpen;
309}
310
311
312/** @name VBox HDD container backend capability flags
313 * @{
314 */
315/** Supports UUIDs as expected by VirtualBox code. */
316#define VD_CAP_UUID RT_BIT(0)
317/** Supports creating fixed size images, allocating all space instantly. */
318#define VD_CAP_CREATE_FIXED RT_BIT(1)
319/** Supports creating dynamically growing images, allocating space on demand. */
320#define VD_CAP_CREATE_DYNAMIC RT_BIT(2)
321/** Supports creating images split in chunks of a bit less than 2GBytes. */
322#define VD_CAP_CREATE_SPLIT_2G RT_BIT(3)
323/** Supports being used as differencing image format backend. */
324#define VD_CAP_DIFF RT_BIT(4)
325/** Supports asynchronous I/O operations for at least some configurations. */
326#define VD_CAP_ASYNC RT_BIT(5)
327/** The backend operates on files. The caller needs to know to handle the
328 * location appropriately. */
329#define VD_CAP_FILE RT_BIT(6)
330/** The backend uses the config interface. The caller needs to know how to
331 * provide the mandatory configuration parts this way. */
332#define VD_CAP_CONFIG RT_BIT(7)
333/** The backend uses the network stack interface. The caller has to provide
334 * the appropriate interface. */
335#define VD_CAP_TCPNET RT_BIT(8)
336/** The backend supports VFS (virtual filesystem) functionality since it uses
337 * VDINTERFACEIO exclusively for all file operations. */
338#define VD_CAP_VFS RT_BIT(9)
339/** The backend supports the discard operation. */
340#define VD_CAP_DISCARD RT_BIT(10)
341/** This is a frequently used backend. */
342#define VD_CAP_PREFERRED RT_BIT(11)
343/** @}*/
344
345/** @name Configuration interface key handling flags.
346 * @{
347 */
348/** Mandatory config key. Not providing a value for this key will cause
349 * the backend to fail. */
350#define VD_CFGKEY_MANDATORY RT_BIT(0)
351/** Expert config key. Not showing it by default in the GUI is is probably
352 * a good idea, as the average user won't understand it easily. */
353#define VD_CFGKEY_EXPERT RT_BIT(1)
354/** Key only need at media creation, not to be retained in registry.
355 * Should not be exposed in the GUI */
356#define VD_CFGKEY_CREATEONLY RT_BIT(2)
357/** @}*/
358
359
360/**
361 * Configuration value type for configuration information interface.
362 */
363typedef enum VDCFGVALUETYPE
364{
365 /** Integer value. */
366 VDCFGVALUETYPE_INTEGER = 1,
367 /** String value. */
368 VDCFGVALUETYPE_STRING,
369 /** Bytestring value. */
370 VDCFGVALUETYPE_BYTES
371} VDCFGVALUETYPE;
372
373
374/**
375 * Structure describing configuration keys required/supported by a backend
376 * through the config interface.
377 */
378typedef struct VDCONFIGINFO
379{
380 /** Key name of the configuration. */
381 const char *pszKey;
382 /** Pointer to default value (descriptor). NULL if no useful default value
383 * can be specified. */
384 const char *pszDefaultValue;
385 /** Value type for this key. */
386 VDCFGVALUETYPE enmValueType;
387 /** Key handling flags (a combination of VD_CFGKEY_* flags). */
388 uint64_t uKeyFlags;
389} VDCONFIGINFO;
390
391/** Pointer to structure describing configuration keys. */
392typedef VDCONFIGINFO *PVDCONFIGINFO;
393
394/** Pointer to const structure describing configuration keys. */
395typedef const VDCONFIGINFO *PCVDCONFIGINFO;
396
397/**
398 * Structure describing a file extension.
399 */
400typedef struct VDFILEEXTENSION
401{
402 /** Pointer to the NULL-terminated string containing the extension. */
403 const char *pszExtension;
404 /** The device type the extension supports. */
405 VDTYPE enmType;
406} VDFILEEXTENSION;
407
408/** Pointer to a structure describing a file extension. */
409typedef VDFILEEXTENSION *PVDFILEEXTENSION;
410
411/** Pointer to a const structure describing a file extension. */
412typedef const VDFILEEXTENSION *PCVDFILEEXTENSION;
413
414/**
415 * Data structure for returning a list of backend capabilities.
416 */
417typedef struct VDBACKENDINFO
418{
419 /** Name of the backend. Must be unique even with case insensitive comparison. */
420 const char *pszBackend;
421 /** Capabilities of the backend (a combination of the VD_CAP_* flags). */
422 uint64_t uBackendCaps;
423 /** Pointer to a NULL-terminated array of strings, containing the supported
424 * file extensions. Note that some backends do not work on files, so this
425 * pointer may just contain NULL. */
426 PCVDFILEEXTENSION paFileExtensions;
427 /** Pointer to an array of structs describing each supported config key.
428 * Terminated by a NULL config key. Note that some backends do not support
429 * the configuration interface, so this pointer may just contain NULL.
430 * Mandatory if the backend sets VD_CAP_CONFIG. */
431 PCVDCONFIGINFO paConfigInfo;
432 /** Returns a human readable hard disk location string given a
433 * set of hard disk configuration keys. The returned string is an
434 * equivalent of the full file path for image-based hard disks.
435 * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
436 DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
437 /** Returns a human readable hard disk name string given a
438 * set of hard disk configuration keys. The returned string is an
439 * equivalent of the file name part in the full file path for
440 * image-based hard disks. Mandatory for backends with no
441 * VD_CAP_FILE and NULL otherwise. */
442 DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
443} VDBACKENDINFO, *PVDBACKENDINFO;
444
445/**
446 * Data structure for returning a list of filter capabilities.
447 */
448typedef struct VDFILTERINFO
449{
450 /** Name of the filter. Must be unique even with case insensitive comparison. */
451 const char *pszFilter;
452 /** Pointer to an array of structs describing each supported config key.
453 * Terminated by a NULL config key. Note that some filters do not support
454 * the configuration interface, so this pointer may just contain NULL. */
455 PCVDCONFIGINFO paConfigInfo;
456} VDFILTERINFO, *PVDFILTERINFO;
457
458
459/**
460 * Request completion callback for the async read/write API.
461 */
462typedef DECLCALLBACKTYPE(void, FNVDASYNCTRANSFERCOMPLETE,(void *pvUser1, void *pvUser2, int rcReq));
463/** Pointer to a transfer compelte callback. */
464typedef FNVDASYNCTRANSFERCOMPLETE *PFNVDASYNCTRANSFERCOMPLETE;
465
466/**
467 * VD Container main structure.
468 */
469/* Forward declaration, VDISK structure is visible only inside VD module. */
470struct VDISK;
471typedef struct VDISK VDISK;
472typedef VDISK *PVDISK;
473
474/**
475 * Initializes HDD backends.
476 *
477 * @returns VBox status code.
478 */
479VBOXDDU_DECL(int) VDInit(void);
480
481/**
482 * Destroys loaded HDD backends.
483 *
484 * @returns VBox status code.
485 */
486VBOXDDU_DECL(int) VDShutdown(void);
487
488/**
489 * Loads a single plugin given by filename.
490 *
491 * @returns VBox status code.
492 * @param pszFilename The plugin filename to load.
493 */
494VBOXDDU_DECL(int) VDPluginLoadFromFilename(const char *pszFilename);
495
496/**
497 * Load all plugins from a given path.
498 *
499 * @returns VBox statuse code.
500 * @param pszPath The path to load plugins from.
501 */
502VBOXDDU_DECL(int) VDPluginLoadFromPath(const char *pszPath);
503
504/**
505 * Unloads a single plugin given by filename.
506 *
507 * @returns VBox status code.
508 * @param pszFilename The plugin filename to unload.
509 */
510VBOXDDU_DECL(int) VDPluginUnloadFromFilename(const char *pszFilename);
511
512/**
513 * Unload all plugins from a given path.
514 *
515 * @returns VBox statuse code.
516 * @param pszPath The path to unload plugins from.
517 */
518VBOXDDU_DECL(int) VDPluginUnloadFromPath(const char *pszPath);
519
520/**
521 * Lists all HDD backends and their capabilities in a caller-provided buffer.
522 *
523 * @return VBox status code.
524 * VERR_BUFFER_OVERFLOW if not enough space is passed.
525 * @param cEntriesAlloc Number of list entries available.
526 * @param pEntries Pointer to array for the entries.
527 * @param pcEntriesUsed Number of entries returned.
528 */
529VBOXDDU_DECL(int) VDBackendInfo(unsigned cEntriesAlloc, PVDBACKENDINFO pEntries,
530 unsigned *pcEntriesUsed);
531
532/**
533 * Lists the capabilities of a backend identified by its name.
534 *
535 * @return VBox status code.
536 * @param pszBackend The backend name (case insensitive).
537 * @param pEntry Pointer to an entry.
538 */
539VBOXDDU_DECL(int) VDBackendInfoOne(const char *pszBackend, PVDBACKENDINFO pEntry);
540
541/**
542 * Lists all filters and their capabilities in a caller-provided buffer.
543 *
544 * @return VBox status code.
545 * VERR_BUFFER_OVERFLOW if not enough space is passed.
546 * @param cEntriesAlloc Number of list entries available.
547 * @param pEntries Pointer to array for the entries.
548 * @param pcEntriesUsed Number of entries returned.
549 */
550VBOXDDU_DECL(int) VDFilterInfo(unsigned cEntriesAlloc, PVDFILTERINFO pEntries,
551 unsigned *pcEntriesUsed);
552
553/**
554 * Lists the capabilities of a filter identified by its name.
555 *
556 * @return VBox status code.
557 * @param pszFilter The filter name (case insensitive).
558 * @param pEntry Pointer to an entry.
559 */
560VBOXDDU_DECL(int) VDFilterInfoOne(const char *pszFilter, PVDFILTERINFO pEntry);
561
562/**
563 * Allocates and initializes an empty HDD container.
564 * No image files are opened.
565 *
566 * @return VBox status code.
567 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
568 * @param enmType Type of the image container.
569 * @param ppDisk Where to store the reference to HDD container.
570 */
571VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, VDTYPE enmType, PVDISK *ppDisk);
572
573/**
574 * Destroys HDD container.
575 * If container has opened image files they will be closed.
576 *
577 * @return VBox status code.
578 * @param pDisk Pointer to HDD container.
579 */
580VBOXDDU_DECL(int) VDDestroy(PVDISK pDisk);
581
582/**
583 * Try to get the backend name which can use this image.
584 *
585 * @return VBox status code.
586 * VINF_SUCCESS if a plugin was found.
587 * ppszFormat contains the string which can be used as backend name.
588 * VERR_NOT_SUPPORTED if no backend was found.
589 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
590 * @param pVDIfsImage Pointer to the per-image VD interface list.
591 * @param pszFilename Name of the image file for which the backend is queried.
592 * @param enmDesiredType The desired image type, VDTYPE_INVALID if anything goes.
593 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name.
594 * The returned pointer must be freed using RTStrFree().
595 * @param penmType Where to store the type of the image.
596 */
597VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
598 const char *pszFilename, VDTYPE enmDesiredType,
599 char **ppszFormat, VDTYPE *penmType);
600
601/**
602 * Opens an image file.
603 *
604 * The first opened image file in HDD container must have a base image type,
605 * others (next opened images) must be differencing or undo images.
606 * Linkage is checked for differencing image to be consistent with the previously opened image.
607 * When another differencing image is opened and the last image was opened in read/write access
608 * mode, then the last image is reopened in read-only with deny write sharing mode. This allows
609 * other processes to use images in read-only mode too.
610 *
611 * Note that the image is opened in read-only mode if a read/write open is not possible.
612 * Use VDIsReadOnly to check open mode.
613 *
614 * @return VBox status code.
615 * @param pDisk Pointer to HDD container.
616 * @param pszBackend Name of the image file backend to use (case insensitive).
617 * @param pszFilename Name of the image file to open.
618 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
619 * @param pVDIfsImage Pointer to the per-image VD interface list.
620 */
621VBOXDDU_DECL(int) VDOpen(PVDISK pDisk, const char *pszBackend,
622 const char *pszFilename, unsigned uOpenFlags,
623 PVDINTERFACE pVDIfsImage);
624
625/**
626 * Opens a cache image.
627 *
628 * @return VBox status code.
629 * @param pDisk Pointer to the HDD container which should use the cache image.
630 * @param pszBackend Name of the cache file backend to use (case insensitive).
631 * @param pszFilename Name of the cache image to open.
632 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
633 * @param pVDIfsCache Pointer to the per-cache VD interface list.
634 */
635VBOXDDU_DECL(int) VDCacheOpen(PVDISK pDisk, const char *pszBackend,
636 const char *pszFilename, unsigned uOpenFlags,
637 PVDINTERFACE pVDIfsCache);
638
639/**
640 * Adds a filter to the disk.
641 *
642 * @returns VBox status code.
643 * @param pDisk Pointer to the HDD container which should use the filter.
644 * @param pszFilter Name of the filter backend to use (case insensitive).
645 * @param fFlags Flags which apply to the filter, combination of VD_FILTER_FLAGS_*
646 * defines.
647 * @param pVDIfsFilter Pointer to the per-filter VD interface list.
648 */
649VBOXDDU_DECL(int) VDFilterAdd(PVDISK pDisk, const char *pszFilter, uint32_t fFlags,
650 PVDINTERFACE pVDIfsFilter);
651
652/**
653 * Creates and opens a new base image file.
654 *
655 * @return VBox status code.
656 * @param pDisk Pointer to HDD container.
657 * @param pszBackend Name of the image file backend to use (case insensitive).
658 * @param pszFilename Name of the image file to create.
659 * @param cbSize Image size in bytes.
660 * @param uImageFlags Flags specifying special image features.
661 * @param pszComment Pointer to image comment. NULL is ok.
662 * @param pPCHSGeometry Pointer to physical disk geometry <= (16383,16,63). Not NULL.
663 * @param pLCHSGeometry Pointer to logical disk geometry <= (x,255,63). Not NULL.
664 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
665 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
666 * @param pVDIfsImage Pointer to the per-image VD interface list.
667 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
668 */
669VBOXDDU_DECL(int) VDCreateBase(PVDISK pDisk, const char *pszBackend,
670 const char *pszFilename, uint64_t cbSize,
671 unsigned uImageFlags, const char *pszComment,
672 PCVDGEOMETRY pPCHSGeometry,
673 PCVDGEOMETRY pLCHSGeometry,
674 PCRTUUID pUuid, unsigned uOpenFlags,
675 PVDINTERFACE pVDIfsImage,
676 PVDINTERFACE pVDIfsOperation);
677
678/**
679 * Creates and opens a new differencing image file in HDD container.
680 * See comments for VDOpen function about differencing images.
681 *
682 * @return VBox status code.
683 * @param pDisk Pointer to HDD container.
684 * @param pszBackend Name of the image file backend to use (case insensitive).
685 * @param pszFilename Name of the differencing image file to create.
686 * @param uImageFlags Flags specifying special image features.
687 * @param pszComment Pointer to image comment. NULL is ok.
688 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
689 * @param pParentUuid New parent UUID of the image. If NULL, the UUID is queried automatically.
690 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
691 * @param pVDIfsImage Pointer to the per-image VD interface list.
692 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
693 */
694VBOXDDU_DECL(int) VDCreateDiff(PVDISK pDisk, const char *pszBackend,
695 const char *pszFilename, unsigned uImageFlags,
696 const char *pszComment, PCRTUUID pUuid,
697 PCRTUUID pParentUuid, unsigned uOpenFlags,
698 PVDINTERFACE pVDIfsImage,
699 PVDINTERFACE pVDIfsOperation);
700
701/**
702 * Creates and opens new cache image file in HDD container.
703 *
704 * @return VBox status code.
705 * @param pDisk Name of the cache file backend to use (case insensitive).
706 * @param pszBackend Name of the image file backend to use (case insensitive).
707 * @param pszFilename Name of the differencing cache file to create.
708 * @param cbSize Maximum size of the cache.
709 * @param uImageFlags Flags specifying special cache features.
710 * @param pszComment Pointer to image comment. NULL is ok.
711 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
712 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
713 * @param pVDIfsCache Pointer to the per-cache VD interface list.
714 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
715 */
716VBOXDDU_DECL(int) VDCreateCache(PVDISK pDisk, const char *pszBackend,
717 const char *pszFilename, uint64_t cbSize,
718 unsigned uImageFlags, const char *pszComment,
719 PCRTUUID pUuid, unsigned uOpenFlags,
720 PVDINTERFACE pVDIfsCache, PVDINTERFACE pVDIfsOperation);
721
722/**
723 * Merges two images (not necessarily with direct parent/child relationship).
724 * As a side effect the source image and potentially the other images which
725 * are also merged to the destination are deleted from both the disk and the
726 * images in the HDD container.
727 *
728 * @return VBox status code.
729 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
730 * @param pDisk Pointer to HDD container.
731 * @param nImageFrom Image number to merge from, counts from 0. 0 is always base image of container.
732 * @param nImageTo Image number to merge to, counts from 0. 0 is always base image of container.
733 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
734 */
735VBOXDDU_DECL(int) VDMerge(PVDISK pDisk, unsigned nImageFrom,
736 unsigned nImageTo, PVDINTERFACE pVDIfsOperation);
737
738/**
739 * Copies an image from one HDD container to another - extended version.
740 *
741 * The copy is opened in the target HDD container. It is possible to convert
742 * between different image formats, because the backend for the destination may
743 * be different from the source. If both the source and destination reference
744 * the same HDD container, then the image is moved (by copying/deleting or
745 * renaming) to the new location. The source container is unchanged if the move
746 * operation fails, otherwise the image at the new location is opened in the
747 * same way as the old one was.
748 *
749 * @note The read/write accesses across disks are not synchronized, just the
750 * accesses to each disk. Once there is a use case which requires a defined
751 * read/write behavior in this situation this needs to be extended.
752 *
753 * @return VBox status code.
754 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
755 *
756 * @param pDiskFrom Pointer to source HDD container.
757 * @param nImage Image number, counts from 0. 0 is always base image
758 * of container.
759 * @param pDiskTo Pointer to destination HDD container.
760 * @param pszBackend Name of the image file backend to use (may be NULL
761 * to use the same as the source, case insensitive).
762 * @param pszFilename New name of the image (may be NULL to specify that
763 * the copy destination is the destination container,
764 * or if pDiskFrom == pDiskTo, i.e. when moving).
765 * @param fMoveByRename If true, attempt to perform a move by renaming (if
766 * successful the new size is ignored).
767 * @param cbSize New image size (0 means leave unchanged).
768 * @param nImageFromSame The number of the last image in the source chain
769 * having the same content as the image in the
770 * destination chain given by nImageToSame or
771 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the
772 * content of both containers is unknown. See the
773 * notes for further information.
774 * @param nImageToSame The number of the last image in the destination
775 * chain having the same content as the image in the
776 * source chain given by nImageFromSame or
777 * VD_IMAGE_CONTENT_UNKNOWN to indicate that the
778 * content of both containers is unknown. See the notes
779 * for further information.
780 * @param uImageFlags Flags specifying special destination image features.
781 * @param pDstUuid New UUID of the destination image. If NULL, a new
782 * UUID is created. This parameter is used if and only
783 * if a true copy is created. In all rename/move cases
784 * or copy to existing image cases the modification
785 * UUIDs are copied over.
786 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
787 * Only used if the destination image is created.
788 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
789 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
790 * destination image.
791 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
792 * for the destination operation.
793 *
794 * @note Using nImageFromSame and nImageToSame can lead to a significant speedup
795 * when copying an image but can also lead to a corrupted copy if used
796 * incorrectly. It is mainly useful when cloning a chain of images and it
797 * is known that the virtual disk content of the two chains is exactly the
798 * same upto a certain image. Example:
799 * Imagine the chain of images which consist of a base and one diff
800 * image. Copying the chain starts with the base image. When copying
801 * the first diff image VDCopy() will read the data from the diff of
802 * the source chain and probably from the base image again in case the
803 * diff doesn't has data for the block. However the block will be
804 * optimized away because VDCopy() reads data from the base image of
805 * the destination chain compares the to and suppresses the write
806 * because the data is unchanged. For a lot of diff images this will be
807 * a huge waste of I/O bandwidth if the diff images contain only few
808 * changes. Because it is known that the base image of the source and
809 * the destination chain have the same content it is enough to check
810 * the diff image for changed data and copy it to the destination diff
811 * image which is achieved with nImageFromSame and nImageToSame.
812 * Setting both to 0 can suppress a lot of I/O.
813 */
814VBOXDDU_DECL(int) VDCopyEx(PVDISK pDiskFrom, unsigned nImage, PVDISK pDiskTo,
815 const char *pszBackend, const char *pszFilename,
816 bool fMoveByRename, uint64_t cbSize,
817 unsigned nImageFromSame, unsigned nImageToSame,
818 unsigned uImageFlags, PCRTUUID pDstUuid,
819 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
820 PVDINTERFACE pDstVDIfsImage,
821 PVDINTERFACE pDstVDIfsOperation);
822
823/**
824 * Copies an image from one HDD container to another.
825 * The copy is opened in the target HDD container.
826 * It is possible to convert between different image formats, because the
827 * backend for the destination may be different from the source.
828 * If both the source and destination reference the same HDD container,
829 * then the image is moved (by copying/deleting or renaming) to the new location.
830 * The source container is unchanged if the move operation fails, otherwise
831 * the image at the new location is opened in the same way as the old one was.
832 *
833 * @note The read/write accesses across disks are not synchronized, just the
834 * accesses to each disk. Once there is a use case which requires a defined
835 * read/write behavior in this situation this needs to be extended.
836 *
837 * @return VBox status code.
838 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
839 * @param pDiskFrom Pointer to source HDD container.
840 * @param nImage Image number, counts from 0. 0 is always base image of container.
841 * @param pDiskTo Pointer to destination HDD container.
842 * @param pszBackend Name of the image file backend to use (may be NULL to use the same as the source, case insensitive).
843 * @param pszFilename New name of the image (may be NULL to specify that the
844 * copy destination is the destination container, or
845 * if pDiskFrom == pDiskTo, i.e. when moving).
846 * @param fMoveByRename If true, attempt to perform a move by renaming (if successful the new size is ignored).
847 * @param cbSize New image size (0 means leave unchanged).
848 * @param uImageFlags Flags specifying special destination image features.
849 * @param pDstUuid New UUID of the destination image. If NULL, a new UUID is created.
850 * This parameter is used if and only if a true copy is created.
851 * In all rename/move cases or copy to existing image cases the modification UUIDs are copied over.
852 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
853 * Only used if the destination image is created.
854 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
855 * @param pDstVDIfsImage Pointer to the per-image VD interface list, for the
856 * destination image.
857 * @param pDstVDIfsOperation Pointer to the per-operation VD interface list,
858 * for the destination operation.
859 */
860VBOXDDU_DECL(int) VDCopy(PVDISK pDiskFrom, unsigned nImage, PVDISK pDiskTo,
861 const char *pszBackend, const char *pszFilename,
862 bool fMoveByRename, uint64_t cbSize,
863 unsigned uImageFlags, PCRTUUID pDstUuid,
864 unsigned uOpenFlags, PVDINTERFACE pVDIfsOperation,
865 PVDINTERFACE pDstVDIfsImage,
866 PVDINTERFACE pDstVDIfsOperation);
867
868/**
869 * Optimizes the storage consumption of an image. Typically the unused blocks
870 * have to be wiped with zeroes to achieve a substantial reduced storage use.
871 * Another optimization done is reordering the image blocks, which can provide
872 * a significant performance boost, as reads and writes tend to use less random
873 * file offsets.
874 *
875 * @note Compaction is treated as a single operation with regard to thread
876 * synchronization, which means that it potentially blocks other activities for
877 * a long time. The complexity of compaction would grow even more if concurrent
878 * accesses have to be handled.
879 *
880 * @return VBox status code.
881 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
882 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
883 * @return VERR_NOT_SUPPORTED if this kind of image can be compacted, but
884 * this isn't supported yet.
885 * @param pDisk Pointer to HDD container.
886 * @param nImage Image number, counts from 0. 0 is always base image of container.
887 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
888 */
889VBOXDDU_DECL(int) VDCompact(PVDISK pDisk, unsigned nImage, PVDINTERFACE pVDIfsOperation);
890
891/**
892 * Resizes the given disk image to the given size. It is OK if there are
893 * multiple images open in the container. In this case the last disk image
894 * will be resized.
895 *
896 * @return VBox status
897 * @return VERR_VD_IMAGE_READ_ONLY if image is not writable.
898 * @return VERR_NOT_SUPPORTED if this kind of image can't be compacted.
899 *
900 * @param pDisk Pointer to the HDD container.
901 * @param cbSize New size of the image.
902 * @param pPCHSGeometry Pointer to the new physical disk geometry <= (16383,16,63). Not NULL.
903 * @param pLCHSGeometry Pointer to the new logical disk geometry <= (x,255,63). Not NULL.
904 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
905 */
906VBOXDDU_DECL(int) VDResize(PVDISK pDisk, uint64_t cbSize,
907 PCVDGEOMETRY pPCHSGeometry,
908 PCVDGEOMETRY pLCHSGeometry,
909 PVDINTERFACE pVDIfsOperation);
910
911/**
912 * Prepares the given disk for use by the added filters. This applies to all
913 * opened images in the chain which might be opened read/write temporary.
914 *
915 * @return VBox status code.
916 *
917 * @param pDisk Pointer to the HDD container.
918 * @param pVDIfsOperation Pointer to the per-operation VD interface list.
919 */
920VBOXDDU_DECL(int) VDPrepareWithFilters(PVDISK pDisk, PVDINTERFACE pVDIfsOperation);
921
922/**
923 * Closes the last opened image file in HDD container.
924 * If previous image file was opened in read-only mode (the normal case) and
925 * the last opened image is in read-write mode then the previous image will be
926 * reopened in read/write mode.
927 *
928 * @return VBox status code.
929 * @return VERR_VD_NOT_OPENED if no image is opened in HDD container.
930 * @param pDisk Pointer to HDD container.
931 * @param fDelete If true, delete the image from the host disk.
932 */
933VBOXDDU_DECL(int) VDClose(PVDISK pDisk, bool fDelete);
934
935/**
936 * Removes the last added filter in the HDD container from the specified chain.
937 *
938 * @return VBox status code.
939 * @retval VERR_VD_NOT_OPENED if no filter is present for the disk.
940 * @param pDisk Pointer to HDD container.
941 * @param fFlags Combination of VD_FILTER_FLAGS_* defines.
942 */
943VBOXDDU_DECL(int) VDFilterRemove(PVDISK pDisk, uint32_t fFlags);
944
945/**
946 * Closes the currently opened cache image file in HDD container.
947 *
948 * @return VBox status code.
949 * @return VERR_VD_NOT_OPENED if no cache is opened in HDD container.
950 * @param pDisk Pointer to HDD container.
951 * @param fDelete If true, delete the image from the host disk.
952 */
953VBOXDDU_DECL(int) VDCacheClose(PVDISK pDisk, bool fDelete);
954
955/**
956 * Closes all opened image files in HDD container.
957 *
958 * @return VBox status code.
959 * @param pDisk Pointer to HDD container.
960 */
961VBOXDDU_DECL(int) VDCloseAll(PVDISK pDisk);
962
963/**
964 * Removes all filters of the given HDD container.
965 *
966 * @return VBox status code.
967 * @param pDisk Pointer to HDD container.
968 */
969VBOXDDU_DECL(int) VDFilterRemoveAll(PVDISK pDisk);
970
971/**
972 * Read data from virtual HDD.
973 *
974 * @return VBox status code.
975 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
976 * @param pDisk Pointer to HDD container.
977 * @param uOffset Offset of first reading byte from start of disk.
978 * Must be aligned to a sector boundary.
979 * @param pvBuf Pointer to buffer for reading data.
980 * @param cbRead Number of bytes to read.
981 * Must be aligned to a sector boundary.
982 */
983VBOXDDU_DECL(int) VDRead(PVDISK pDisk, uint64_t uOffset, void *pvBuf, size_t cbRead);
984
985/**
986 * Write data to virtual HDD.
987 *
988 * @return VBox status code.
989 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
990 * @param pDisk Pointer to HDD container.
991 * @param uOffset Offset of first writing byte from start of disk.
992 * Must be aligned to a sector boundary.
993 * @param pvBuf Pointer to buffer for writing data.
994 * @param cbWrite Number of bytes to write.
995 * Must be aligned to a sector boundary.
996 */
997VBOXDDU_DECL(int) VDWrite(PVDISK pDisk, uint64_t uOffset, const void *pvBuf, size_t cbWrite);
998
999/**
1000 * Make sure the on disk representation of a virtual HDD is up to date.
1001 *
1002 * @return VBox status code.
1003 * @retval VERR_VD_NOT_OPENED if no image is opened in HDD container.
1004 * @param pDisk Pointer to HDD container.
1005 */
1006VBOXDDU_DECL(int) VDFlush(PVDISK pDisk);
1007
1008/**
1009 * Get number of opened images in HDD container.
1010 *
1011 * @return Number of opened images for HDD container. 0 if no images have been opened.
1012 * @param pDisk Pointer to HDD container.
1013 */
1014VBOXDDU_DECL(unsigned) VDGetCount(PVDISK pDisk);
1015
1016/**
1017 * Get read/write mode of HDD container.
1018 *
1019 * @return Virtual disk ReadOnly status.
1020 * @return true if no image is opened in HDD container.
1021 * @param pDisk Pointer to HDD container.
1022 */
1023VBOXDDU_DECL(bool) VDIsReadOnly(PVDISK pDisk);
1024
1025/**
1026 * Get sector size of an image in HDD container.
1027 *
1028 * @return Virtual disk sector size in bytes.
1029 * @return 0 if image with specified number was not opened.
1030 * @param pDisk Pointer to HDD container.
1031 * @param nImage Image number, counts from 0. 0 is always base image of container.
1032 */
1033VBOXDDU_DECL(uint32_t) VDGetSectorSize(PVDISK pDisk, unsigned nImage);
1034
1035/**
1036 * Get total capacity of an image in HDD container.
1037 *
1038 * @return Virtual disk size in bytes.
1039 * @return 0 if image with specified number was not opened.
1040 * @param pDisk Pointer to HDD container.
1041 * @param nImage Image number, counts from 0. 0 is always base image of container.
1042 */
1043VBOXDDU_DECL(uint64_t) VDGetSize(PVDISK pDisk, unsigned nImage);
1044
1045/**
1046 * Get total file size of an image in HDD container.
1047 *
1048 * @return Virtual disk size in bytes.
1049 * @return 0 if image with specified number was not opened.
1050 * @param pDisk Pointer to HDD container.
1051 * @param nImage Image number, counts from 0. 0 is always base image of container.
1052 */
1053VBOXDDU_DECL(uint64_t) VDGetFileSize(PVDISK pDisk, unsigned nImage);
1054
1055/**
1056 * Get virtual disk PCHS geometry of an image in HDD container.
1057 *
1058 * @return VBox status code.
1059 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1060 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1061 * @param pDisk Pointer to HDD container.
1062 * @param nImage Image number, counts from 0. 0 is always base image of container.
1063 * @param pPCHSGeometry Where to store PCHS geometry. Not NULL.
1064 */
1065VBOXDDU_DECL(int) VDGetPCHSGeometry(PVDISK pDisk, unsigned nImage, PVDGEOMETRY pPCHSGeometry);
1066
1067/**
1068 * Store virtual disk PCHS geometry of an image in HDD container.
1069 *
1070 * @return VBox status code.
1071 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1072 * @param pDisk Pointer to HDD container.
1073 * @param nImage Image number, counts from 0. 0 is always base image of container.
1074 * @param pPCHSGeometry Where to load PCHS geometry from. Not NULL.
1075 */
1076VBOXDDU_DECL(int) VDSetPCHSGeometry(PVDISK pDisk, unsigned nImage, PCVDGEOMETRY pPCHSGeometry);
1077
1078/**
1079 * Get virtual disk LCHS geometry of an image in HDD container.
1080 *
1081 * @return VBox status code.
1082 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1083 * @return VERR_VD_GEOMETRY_NOT_SET if no geometry present in the HDD container.
1084 * @param pDisk Pointer to HDD container.
1085 * @param nImage Image number, counts from 0. 0 is always base image of container.
1086 * @param pLCHSGeometry Where to store LCHS geometry. Not NULL.
1087 */
1088VBOXDDU_DECL(int) VDGetLCHSGeometry(PVDISK pDisk, unsigned nImage, PVDGEOMETRY pLCHSGeometry);
1089
1090/**
1091 * Store virtual disk LCHS geometry of an image in HDD container.
1092 *
1093 * @return VBox status code.
1094 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1095 * @param pDisk Pointer to HDD container.
1096 * @param nImage Image number, counts from 0. 0 is always base image of container.
1097 * @param pLCHSGeometry Where to load LCHS geometry from. Not NULL.
1098 */
1099VBOXDDU_DECL(int) VDSetLCHSGeometry(PVDISK pDisk, unsigned nImage, PCVDGEOMETRY pLCHSGeometry);
1100
1101/**
1102 * Queries the available regions of an image in the given VD container.
1103 *
1104 * @return VBox status code.
1105 * @retval VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1106 * @retval VERR_NOT_SUPPORTED if the image backend doesn't support region lists.
1107 * @param pDisk Pointer to HDD container.
1108 * @param nImage Image number, counts from 0. 0 is always base image of container.
1109 * @param fFlags Combination of VD_REGION_LIST_F_* flags.
1110 * @param ppRegionList Where to store the pointer to the region list on success, must be freed
1111 * with VDRegionListFree().
1112 */
1113VBOXDDU_DECL(int) VDQueryRegions(PVDISK pDisk, unsigned nImage, uint32_t fFlags,
1114 PPVDREGIONLIST ppRegionList);
1115
1116/**
1117 * Frees a region list previously queried with VDQueryRegions().
1118 *
1119 * @return nothing.
1120 * @param pRegionList The region list to free.
1121 */
1122VBOXDDU_DECL(void) VDRegionListFree(PVDREGIONLIST pRegionList);
1123
1124/**
1125 * Get version of image in HDD container.
1126 *
1127 * @return VBox status code.
1128 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1129 * @param pDisk Pointer to HDD container.
1130 * @param nImage Image number, counts from 0. 0 is always base image of container.
1131 * @param puVersion Where to store the image version.
1132 */
1133VBOXDDU_DECL(int) VDGetVersion(PVDISK pDisk, unsigned nImage, unsigned *puVersion);
1134
1135/**
1136 * List the capabilities of image backend in HDD container.
1137 *
1138 * @return VBox status code.
1139 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1140 * @param pDisk Pointer to the HDD container.
1141 * @param nImage Image number, counts from 0. 0 is always base image of container.
1142 * @param pBackendInfo Where to store the backend information.
1143 */
1144VBOXDDU_DECL(int) VDBackendInfoSingle(PVDISK pDisk, unsigned nImage, PVDBACKENDINFO pBackendInfo);
1145
1146/**
1147 * Get flags of image in HDD container.
1148 *
1149 * @return VBox status code.
1150 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1151 * @param pDisk Pointer to HDD container.
1152 * @param nImage Image number, counts from 0. 0 is always base image of container.
1153 * @param puImageFlags Where to store the image flags.
1154 */
1155VBOXDDU_DECL(int) VDGetImageFlags(PVDISK pDisk, unsigned nImage, unsigned *puImageFlags);
1156
1157/**
1158 * Get open flags of image in HDD container.
1159 *
1160 * @return VBox status code.
1161 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1162 * @param pDisk Pointer to HDD container.
1163 * @param nImage Image number, counts from 0. 0 is always base image of container.
1164 * @param puOpenFlags Where to store the image open flags.
1165 */
1166VBOXDDU_DECL(int) VDGetOpenFlags(PVDISK pDisk, unsigned nImage, unsigned *puOpenFlags);
1167
1168/**
1169 * Set open flags of image in HDD container.
1170 * This operation may cause file locking changes and/or files being reopened.
1171 * Note that in case of unrecoverable error all images in HDD container will be closed.
1172 *
1173 * @return VBox status code.
1174 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1175 * @param pDisk Pointer to HDD container.
1176 * @param nImage Image number, counts from 0. 0 is always base image of container.
1177 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
1178 */
1179VBOXDDU_DECL(int) VDSetOpenFlags(PVDISK pDisk, unsigned nImage, unsigned uOpenFlags);
1180
1181/**
1182 * Get base filename of image in HDD container. Some image formats use
1183 * other filenames as well, so don't use this for anything but informational
1184 * purposes.
1185 *
1186 * @return VBox status code.
1187 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1188 * @return VERR_BUFFER_OVERFLOW if pszFilename buffer too small to hold filename.
1189 * @param pDisk Pointer to HDD container.
1190 * @param nImage Image number, counts from 0. 0 is always base image of container.
1191 * @param pszFilename Where to store the image file name.
1192 * @param cbFilename Size of buffer pszFilename points to.
1193 */
1194VBOXDDU_DECL(int) VDGetFilename(PVDISK pDisk, unsigned nImage, char *pszFilename, unsigned cbFilename);
1195
1196/**
1197 * Get the comment line of image in HDD container.
1198 *
1199 * @return VBox status code.
1200 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1201 * @return VERR_BUFFER_OVERFLOW if pszComment buffer too small to hold comment text.
1202 * @param pDisk Pointer to HDD container.
1203 * @param nImage Image number, counts from 0. 0 is always base image of container.
1204 * @param pszComment Where to store the comment string of image. NULL is ok.
1205 * @param cbComment The size of pszComment buffer. 0 is ok.
1206 */
1207VBOXDDU_DECL(int) VDGetComment(PVDISK pDisk, unsigned nImage, char *pszComment, unsigned cbComment);
1208
1209/**
1210 * Changes the comment line of image in HDD container.
1211 *
1212 * @return VBox status code.
1213 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1214 * @param pDisk Pointer to HDD container.
1215 * @param nImage Image number, counts from 0. 0 is always base image of container.
1216 * @param pszComment New comment string (UTF-8). NULL is allowed to reset the comment.
1217 */
1218VBOXDDU_DECL(int) VDSetComment(PVDISK pDisk, unsigned nImage, const char *pszComment);
1219
1220/**
1221 * Get UUID of image in HDD container.
1222 *
1223 * @return VBox status code.
1224 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1225 * @param pDisk Pointer to HDD container.
1226 * @param nImage Image number, counts from 0. 0 is always base image of container.
1227 * @param pUuid Where to store the image UUID.
1228 */
1229VBOXDDU_DECL(int) VDGetUuid(PVDISK pDisk, unsigned nImage, PRTUUID pUuid);
1230
1231/**
1232 * Set the image's UUID. Should not be used by normal applications.
1233 *
1234 * @return VBox status code.
1235 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1236 * @param pDisk Pointer to HDD container.
1237 * @param nImage Image number, counts from 0. 0 is always base image of container.
1238 * @param pUuid New UUID of the image. If NULL, a new UUID is created.
1239 */
1240VBOXDDU_DECL(int) VDSetUuid(PVDISK pDisk, unsigned nImage, PCRTUUID pUuid);
1241
1242/**
1243 * Get last modification UUID of image in HDD container.
1244 *
1245 * @return VBox status code.
1246 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1247 * @param pDisk Pointer to HDD container.
1248 * @param nImage Image number, counts from 0. 0 is always base image of container.
1249 * @param pUuid Where to store the image modification UUID.
1250 */
1251VBOXDDU_DECL(int) VDGetModificationUuid(PVDISK pDisk, unsigned nImage, PRTUUID pUuid);
1252
1253/**
1254 * Set the image's last modification UUID. Should not be used by normal applications.
1255 *
1256 * @return VBox status code.
1257 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1258 * @param pDisk Pointer to HDD container.
1259 * @param nImage Image number, counts from 0. 0 is always base image of container.
1260 * @param pUuid New modification UUID of the image. If NULL, a new UUID is created.
1261 */
1262VBOXDDU_DECL(int) VDSetModificationUuid(PVDISK pDisk, unsigned nImage, PCRTUUID pUuid);
1263
1264/**
1265 * Get parent UUID of image in HDD container.
1266 *
1267 * @return VBox status code.
1268 * @return VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.
1269 * @param pDisk Pointer to HDD container.
1270 * @param nImage Image number, counts from 0. 0 is always base image of the container.
1271 * @param pUuid Where to store the parent image UUID.
1272 */
1273VBOXDDU_DECL(int) VDGetParentUuid(PVDISK pDisk, unsigned nImage, PRTUUID pUuid);
1274
1275/**
1276 * Set the image's parent UUID. Should not be used by normal applications.
1277 *
1278 * @return VBox status code.
1279 * @param pDisk Pointer to HDD container.
1280 * @param nImage Image number, counts from 0. 0 is always base image of container.
1281 * @param pUuid New parent UUID of the image. If NULL, a new UUID is created.
1282 */
1283VBOXDDU_DECL(int) VDSetParentUuid(PVDISK pDisk, unsigned nImage, PCRTUUID pUuid);
1284
1285
1286/**
1287 * Debug helper - dumps all opened images in HDD container into the log file.
1288 *
1289 * @param pDisk Pointer to HDD container.
1290 */
1291VBOXDDU_DECL(void) VDDumpImages(PVDISK pDisk);
1292
1293
1294/**
1295 * Discards unused ranges given as a list.
1296 *
1297 * @return VBox status code.
1298 * @param pDisk Pointer to HDD container.
1299 * @param paRanges The array of ranges to discard.
1300 * @param cRanges Number of entries in the array.
1301 *
1302 * @note In contrast to VDCompact() the ranges are always discarded even if they
1303 * appear to contain data. This method is mainly used to implement TRIM support.
1304 */
1305VBOXDDU_DECL(int) VDDiscardRanges(PVDISK pDisk, PCRTRANGE paRanges, unsigned cRanges);
1306
1307
1308/**
1309 * Start an asynchronous read request.
1310 *
1311 * @return VBox status code.
1312 * @param pDisk Pointer to the HDD container.
1313 * @param off The offset of the virtual disk to read from.
1314 * @param cbRead How many bytes to read.
1315 * @param pcSgBuf Pointer to the S/G buffer to read into.
1316 * @param pfnComplete Completion callback.
1317 * @param pvUser1 User data which is passed on completion.
1318 * @param pvUser2 User data which is passed on completion.
1319 */
1320VBOXDDU_DECL(int) VDAsyncRead(PVDISK pDisk, uint64_t off, size_t cbRead,
1321 PCRTSGBUF pcSgBuf,
1322 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1323 void *pvUser1, void *pvUser2);
1324
1325
1326/**
1327 * Start an asynchronous write request.
1328 *
1329 * @return VBox status code.
1330 * @param pDisk Pointer to the HDD container.
1331 * @param off The offset of the virtual disk to write to.
1332 * @param cbWrite How many bytes to write.
1333 * @param pcSgBuf Pointer to the S/G buffer to write from.
1334 * @param pfnComplete Completion callback.
1335 * @param pvUser1 User data which is passed on completion.
1336 * @param pvUser2 User data which is passed on completion.
1337 */
1338VBOXDDU_DECL(int) VDAsyncWrite(PVDISK pDisk, uint64_t off, size_t cbWrite,
1339 PCRTSGBUF pcSgBuf,
1340 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1341 void *pvUser1, void *pvUser2);
1342
1343
1344/**
1345 * Start an asynchronous flush request.
1346 *
1347 * @return VBox status code.
1348 * @param pDisk Pointer to the HDD container.
1349 * @param pfnComplete Completion callback.
1350 * @param pvUser1 User data which is passed on completion.
1351 * @param pvUser2 User data which is passed on completion.
1352 */
1353VBOXDDU_DECL(int) VDAsyncFlush(PVDISK pDisk,
1354 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1355 void *pvUser1, void *pvUser2);
1356
1357/**
1358 * Start an asynchronous discard request.
1359 *
1360 * @return VBox status code.
1361 * @param pDisk Pointer to HDD container.
1362 * @param paRanges The array of ranges to discard.
1363 * @param cRanges Number of entries in the array.
1364 * @param pfnComplete Completion callback.
1365 * @param pvUser1 User data which is passed on completion.
1366 * @param pvUser2 User data which is passed on completion.
1367 */
1368VBOXDDU_DECL(int) VDAsyncDiscardRanges(PVDISK pDisk, PCRTRANGE paRanges, unsigned cRanges,
1369 PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
1370 void *pvUser1, void *pvUser2);
1371
1372/**
1373 * Tries to repair a corrupted image.
1374 *
1375 * @return VBox status code.
1376 * @retval VERR_VD_IMAGE_REPAIR_NOT_SUPPORTED if the backend does not support repairing the image.
1377 * @retval VERR_VD_IMAGE_REPAIR_IMPOSSIBLE if the corruption is to severe to repair the image.
1378 * @param pVDIfsDisk Pointer to the per-disk VD interface list.
1379 * @param pVDIfsImage Pointer to the per-image VD interface list.
1380 * @param pszFilename Name of the image file to repair.
1381 * @param pszBackend The backend to use.
1382 * @param fFlags Combination of the VD_REPAIR_* flags.
1383 */
1384VBOXDDU_DECL(int) VDRepair(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
1385 const char *pszFilename, const char *pszBackend, uint32_t fFlags);
1386
1387/**
1388 * Create a VFS file handle from the given HDD container.
1389 *
1390 * @return VBox status code.
1391 * @param pDisk Pointer to HDD container.
1392 * @param fFlags Combination of the VD_VFSFILE_* flags.
1393 * @param phVfsFile Where to store the handle to the VFS file on
1394 * success.
1395 */
1396VBOXDDU_DECL(int) VDCreateVfsFileFromDisk(PVDISK pDisk, uint32_t fFlags,
1397 PRTVFSFILE phVfsFile);
1398
1399
1400
1401/** @defgroup grp_vd_ifs_def Default implementations for certain VD interfaces.
1402 * @{
1403 */
1404/** Internal per interface instance data. */
1405typedef struct VDIFINSTINT *VDIFINST;
1406/** Pointer to the per instance interface data. */
1407typedef VDIFINST *PVDIFINST;
1408
1409/**
1410 * Creates a new VD TCP/IP interface instance and adds it to the given interface list.
1411 *
1412 * @returns VBox status code.
1413 * @param phTcpNetInst Where to store the TCP/IP interface handle on success.
1414 * @param ppVdIfs Pointer to the VD interface list.
1415 */
1416VBOXDDU_DECL(int) VDIfTcpNetInstDefaultCreate(PVDIFINST phTcpNetInst, PVDINTERFACE *ppVdIfs);
1417
1418/**
1419 * Destroys the given VD TCP/IP interface instance.
1420 *
1421 * @returns nothing.
1422 * @param hTcpNetInst The TCP/IP interface instance handle.
1423 */
1424VBOXDDU_DECL(void) VDIfTcpNetInstDefaultDestroy(VDIFINST hTcpNetInst);
1425/** @} */
1426
1427
1428
1429/** @defgroup grp_vd_ioiter I/O iterator
1430 * @{
1431 */
1432
1433/** Read metadata coming before each main data block addressed in the segment. */
1434#define VD_IOITER_SEG_F_PRE_METADATA RT_BIT_32(0)
1435/** Read the main user data of each addressed block in the segment. */
1436#define VD_IOITER_SEG_F_MAIN_DATA RT_BIT_32(1)
1437/** Read metadata coming after each main data block addressed in the segment. */
1438#define VD_IOITER_SEG_F_POST_METADATA RT_BIT_32(2)
1439/** Read checksum data of each data block addressed in the segment. */
1440#define VD_IOITER_SEG_F_CHKSUM RT_BIT_32(3)
1441/** Read all available data for each addressed block in the segment. */
1442#define VD_IOITER_SEG_F_AVAILABLE RT_BIT_32(4)
1443
1444/** The offset and size members in the segments use byte granularity instead of a
1445 * block address and number of blocks respectively. */
1446#define VDIOITER_F_BYTE_OFFSET_AND_SIZE RT_BIT_32(0)
1447
1448/**
1449 * VD I/O iterator segment.
1450 */
1451typedef struct VDIOITERSEG
1452{
1453 /** Start offset for this segment. */
1454 uint64_t offStartSeg;
1455 /** Size of the segment (bytes or blocks). */
1456 uint64_t cSizeSeg;
1457 /** Flags for this segment, see VD_IOITER_SEG_F_*. */
1458 uint32_t fFlags;
1459} VDIOITERSEG;
1460/** Pointer to a I/O iterator segment. */
1461typedef VDIOITERSEG *PVDIOITERSEG;
1462/** Pointer to a constant I/O iterator segment. */
1463typedef VDIOITERSEG *PCVDIOITERSEG;
1464
1465/** I/O iterator handle. */
1466typedef struct VDIOITERINT *VDIOITER;
1467/** Pointer to a I/O iterator handle. */
1468typedef VDIOITER *PVDIOITER;
1469
1470/**
1471 * Create a new I/O iterator.
1472 *
1473 * @returns VBox status code.
1474 * @param pDisk The disk to create the iterator for.
1475 * @param phVdIoIter Where to store the handle to the I/O iterator on success.
1476 * @param paIoIterSegs The segments for the iterator, can be destroyed after the call.
1477 * @param cIoIterSegs Number of segments.
1478 * @param fFlags Flags for the iterator, see VDIOITER_F_*
1479 */
1480VBOXDDU_DECL(int) VDIoIterCreate(PVDISK pDisk, PVDIOITER phVdIoIter, PCVDIOITERSEG paIoIterSegs,
1481 uint32_t cIoIterSegs, uint32_t fFlags);
1482
1483/**
1484 * Retains the reference count of the given I/O iterator.
1485 *
1486 * @returns New reference count.
1487 * @param hVdIoIter The I/O iterator handle.
1488 */
1489VBOXDDU_DECL(uint32_t) VDIoIterRetain(VDIOITER hVdIoIter);
1490
1491/**
1492 * Releases the reference count of the given I/O iterator.
1493 *
1494 * @returns New reference count, on 0 the iterator is destroyed.
1495 * @param hVdIoIter The I/O iterator handle.
1496 */
1497VBOXDDU_DECL(uint32_t) VDIoIterRelease(VDIOITER hVdIoIter);
1498
1499/**
1500 * Returns the number of segments in the given I/O iterator.
1501 *
1502 * @returns Number of segments.
1503 * @param hVdIoIter The I/O iterator handle.
1504 */
1505VBOXDDU_DECL(uint32_t) VDIoIterGetSegmentCount(VDIOITER hVdIoIter);
1506
1507/**
1508 * Returns the flags of the given I/O iterator.
1509 *
1510 * @returns Flags.
1511 * @param hVdIoIter The I/O iterator handle.
1512 */
1513VBOXDDU_DECL(uint32_t) VDIoIterGetFlags(VDIOITER hVdIoIter);
1514
1515/**
1516 * Queries the properties of the given segment for the given I/O iterator.
1517 *
1518 * @returns VBox status code.
1519 * @param hVdIoIter The I/O iterator handle.
1520 * @param idx The segment index to query.
1521 * @param pSegment Where to store the segment properties on success.
1522 */
1523VBOXDDU_DECL(int) VDIoIterQuerySegment(VDIOITER hVdIoIter, uint32_t idx, PVDIOITERSEG pSegment);
1524
1525/** @} */
1526
1527
1528/** @defgroup grp_vd_io_buf I/O buffer management API.
1529 * @{
1530 */
1531
1532/** VD I/O buffer manager handle. */
1533typedef struct VDIOBUFMGRINT *VDIOBUFMGR;
1534/** Pointer to VD I/O buffer manager handle. */
1535typedef VDIOBUFMGR *PVDIOBUFMGR;
1536
1537/** VD I/O buffer handle. */
1538typedef struct VDIOBUFINT *VDIOBUF;
1539/** Pointer to a VD I/O buffer handle. */
1540typedef VDIOBUF *PVDIOBUF;
1541
1542/** Default I/O buffer manager flags. */
1543#define VD_IOBUFMGR_F_DEFAULT (0)
1544/** I/O buffer memory needs to be non pageable (for example because it contains sensitive data
1545 * which shouldn't end up in swap unencrypted). */
1546#define VD_IOBUFMGR_F_REQUIRE_NOT_PAGABLE RT_BIT(0)
1547
1548/** Pointer to VD I/O buffer callbacks. */
1549typedef struct VDIOBUFCALLBACKS *PVDIOBUFCALLBACKS;
1550/** Pointer to const VD I/O buffer callbacks. */
1551typedef const struct VDIOBUFCALLBACKS *PCVDIOBUFCALLBACKS;
1552
1553/**
1554 * VD I/O buffer callbacks.
1555 */
1556typedef struct VDIOBUFCALLBACKS
1557{
1558 /**
1559 * Copy data from the memory buffer of the caller to the callees memory buffer for the given request.
1560 *
1561 * @returns VBox status code.
1562 * @retval VERR_PDM_MEDIAEX_IOBUF_OVERFLOW if there is not enough room to store the data.
1563 * @param pInterface Pointer to the interface structure containing the called function pointer.
1564 * @param hIoBuf The I/O request handle.
1565 * @param pvIoBufAlloc The allocator specific memory for this request.
1566 * @param offDst The destination offset from the start to write the data to.
1567 * @param pSgBuf The S/G buffer to read the data from.
1568 * @param cbCopy How many bytes to copy.
1569 */
1570 DECLR3CALLBACKMEMBER(int, pfnIoBufCopyFromBuf, (PVDIOBUFCALLBACKS pInterface, VDIOBUF hIoBuf,
1571 void *pvIoBufAlloc, uint32_t offDst, PRTSGBUF pSgBuf,
1572 size_t cbCopy));
1573
1574 /**
1575 * Copy data to the memory buffer of the caller from the callees memory buffer for the given request.
1576 *
1577 * @returns VBox status code.
1578 * @retval VERR_PDM_MEDIAEX_IOBUF_UNDERRUN if there is not enough data to copy from the buffer.
1579 * @param pInterface Pointer to the interface structure containing the called function pointer.
1580 * @param hIoBuf The I/O request handle.
1581 * @param pvIoBufAlloc The allocator specific memory for this request.
1582 * @param offSrc The offset from the start of the buffer to read the data from.
1583 * @param pSgBuf The S/G buffer to write the data to.
1584 * @param cbCopy How many bytes to copy.
1585 */
1586 DECLR3CALLBACKMEMBER(int, pfnIoBufCopyToBuf, (PVDIOBUFCALLBACKS pInterface, VDIOBUF hIoBuf,
1587 void *pvIoBufAlloc, uint32_t offSrc, PRTSGBUF pSgBuf,
1588 size_t cbCopy));
1589
1590 /**
1591 * Queries a pointer to the memory buffer for the request from the drive/device above.
1592 *
1593 * @returns VBox status code.
1594 * @retval VERR_NOT_SUPPORTED if this is not supported for this request.
1595 * @param pInterface Pointer to the interface structure containing the called function pointer.
1596 * @param hIoBuf The I/O request handle.
1597 * @param pvIoBufAlloc The allocator specific memory for this request.
1598 * @param offBuf The offset from the start of the buffer to get the buffer address.
1599 * @param cbBuf The number of bytes requested.
1600 * @param ppvBuf Where to store the pointer to the guest buffer on success.
1601 * @param pcbBuf Where to store the size of the buffer on success.
1602 *
1603 * @note This is an optional feature of the entity implementing this interface to avoid overhead
1604 * by copying the data between buffers. If NULL it is not supported at all and the caller
1605 * has to resort to VDIOBUFCALLBACKS::pfnIoBufCopyToBuf and VDIOBUFCALLBACKS::pfnIoBufCopyFromBuf.
1606 * The same holds when VERR_NOT_SUPPORTED is returned.
1607 *
1608 * On the upside the caller of this interface might not call this method at all and just
1609 * use the before mentioned methods to copy the data between the buffers.
1610 */
1611 DECLR3CALLBACKMEMBER(int, pfnIoBufQueryBuf, (PVDIOBUFCALLBACKS pInterface, VDIOBUF hIoBuf,
1612 void *pvIoBufAlloc, uint32_t offBuf, size_t cbBuf,
1613 void **ppvBuf, size_t *pcbBuf));
1614
1615} VDIOBUFCALLBACKS;
1616
1617/**
1618 * Creates a new I/O buffer manager.
1619 *
1620 * @returns VBox status code.
1621 * @param phIoBufMgr Where to store the handle to the I/O buffer manager on success.
1622 * @param cbMax The maximum amount of I/O memory to allow. Trying to allocate more than
1623 * this will lead to out of memory errors. 0 for "unlimited" size (only restriction
1624 * is the available memory on the host).
1625 * @param fFlags Combination of VD_IOBUFMGR_F_*.
1626 * @param pIoBufClbks Memory copy callbacks between source and target memory regions, optional.
1627 * When NULL all I/O buffers must be allocated with a valid S/G buffer laying out the
1628 * memory.
1629 * @param cbIoBufAlloc How much to allocate extra in the I/O buffer for private use.
1630 */
1631VBOXDDU_DECL(int) VDIoBufMgrCreate(PVDIOBUFMGR phIoBufMgr, size_t cbMax, uint32_t fFlags,
1632 PVDIOBUFCALLBACKS pIoBufClbks, size_t cbIoBufAlloc);
1633
1634/**
1635 * Destroys the given I/O buffer manager.
1636 *
1637 * @returns VBox status code.
1638 * @retval VERR_INVALID_STATE if there are still buffers allocated by the given manager.
1639 * @param hIoBufMgr The I/O buffer manager.
1640 */
1641VBOXDDU_DECL(int) VDIoBufMgrDestroy(VDIOBUFMGR hIoBufMgr);
1642
1643/**
1644 * Allocate a new I/O buffer handle.
1645 *
1646 * @returns VBox status code.
1647 * @param hIoBufMgr The I/O buffer manager to use.
1648 * @param phIoBuf Where to store the I/O buffer handle on success.
1649 * @param ppvIoBufAlloc Where to store the pointe to the private party on success.
1650 * @param pSgBuf The S/G buffer to use, optional. If NULL the I/O buffer callbacks
1651 * supplied when creating the owning manager are used to transfer the
1652 * data.
1653 * @param cbBuf Size of the buffer in bytes.
1654 */
1655VBOXDDU_DECL(int) VDIoBufMgrAllocBuf(VDIOBUFMGR hIoBufMgr, PVDIOBUF phIoBuf, void **ppvIoBufAlloc,
1656 PCRTSGBUF pSgBuf, size_t cbBuf);
1657
1658/**
1659 * Retains the I/O buffer reference count.
1660 *
1661 * @returns New reference count.
1662 * @param hIoBuf The I/O buffer handle.
1663 */
1664VBOXDDU_DECL(uint32_t) VDIoBufRetain(VDIOBUF hIoBuf);
1665
1666/**
1667 * Releases the given I/O buffer reference.
1668 *
1669 * @returns New reference count, on 0 the I/O buffer is destroyed.
1670 * @param hIoBuf The I/O buffer handle.
1671 */
1672VBOXDDU_DECL(uint32_t) VDIoBufRelease(VDIOBUF hIoBuf);
1673
1674/** @} */
1675
1676
1677/** @defgroup grp_vd_ioqueue I/O queues
1678 * @{
1679 */
1680
1681/** VD I/O queue handle. */
1682typedef struct VDIOQUEUEINT *VDIOQUEUE;
1683/** Pointer to an VD I/O queue handle. */
1684typedef VDIOQUEUE *PVDIOQUEUE;
1685
1686/** VD I/O queue request handle. */
1687typedef struct VDIOREQINT *VDIOREQ;
1688/** Pointer to an VD I/O queue request handle. */
1689typedef VDIOREQ *PVDIOREQ;
1690
1691/** A I/O request ID. */
1692typedef uint64_t VDIOREQID;
1693
1694/**
1695 * I/O request type.
1696 */
1697typedef enum VDIOREQTYPE
1698{
1699 /** Invalid request type. */
1700 VDIOREQTYPE_INVALID = 0,
1701 /** Read request. */
1702 VDIOREQTYPE_READ,
1703 /** Write request. */
1704 VDIOREQTYPE_WRITE,
1705 /** Flush request. */
1706 VDIOREQTYPE_FLUSH,
1707 /** Discard request. */
1708 VDIOREQTYPE_DISCARD,
1709 /** 32bit hack. */
1710 VDIOREQTYPE_32BIT_HACK = 0x7fffffff
1711} VDIOREQTYPE;
1712/** Pointer to a request type. */
1713typedef VDIOREQTYPE *PVDIOREQTYPE;
1714
1715/**
1716 * I/O queue request completion callback.
1717 *
1718 * @returns nothing.
1719 * @param hVdIoQueue The VD I/O queue handle.
1720 * @param pDisk The disk the queue is attached to.
1721 * @param hVdIoReq The VD I/O request which completed.
1722 * @param pvVdIoReq Pointer to the allocator specific memory for this request.
1723 * @param rcReq The completion status code.
1724 */
1725typedef DECLCALLBACKTYPE(void, FNVDIOQUEUEREQCOMPLETE,(VDIOQUEUE hVdIoQueue, PVDISK pDisk,
1726 VDIOREQ hVdIoReq, void *pvVdIoReq, int rcReq));
1727/** Pointer to a VD I/O queue request completion callback. */
1728typedef FNVDIOQUEUEREQCOMPLETE *PFNVDIOQUEUEREQCOMPLETE;
1729
1730
1731/**
1732 * Creates a new I/O queue.
1733 *
1734 * @returns VBox status code.
1735 * @param phVdIoQueue Where to store the handle to the I/O queue on success.
1736 * @param pfnIoReqComplete The completion handle to call when a request on the specified queue completes.
1737 * @param cbIoReqAlloc The extra amount of memory to allocate and associate with allocated requests
1738 * for use by the caller.
1739 * @param iPriority The priority of the queue from 0..UINT32_MAX. The lower the number the higher
1740 * the priority of the queue.
1741 */
1742VBOXDDU_DECL(int) VDIoQueueCreate(PVDIOQUEUE phVdIoQueue, PFNVDIOQUEUEREQCOMPLETE pfnIoReqComplete,
1743 size_t cbIoReqAlloc, uint32_t iPriority);
1744
1745/**
1746 * Destroys the given I/O queue.
1747 *
1748 * @returns VBox status code.
1749 * @param hVdIoQueue The I/O queue handle.
1750 */
1751VBOXDDU_DECL(int) VDIoQueueDestroy(VDIOQUEUE hVdIoQueue);
1752
1753/**
1754 * Attaches the given I/O queue to the given virtual disk container.
1755 *
1756 * @returns VBox status code.
1757 * @param pDisk The disk container handle.
1758 * @param hVdIoQueue The I/O queue to attach.
1759 */
1760VBOXDDU_DECL(int) VDIoQueueAttach(PVDISK pDisk, VDIOQUEUE hVdIoQueue);
1761
1762/**
1763 * Detaches the given I/O queue from the currently attached disk container.
1764 *
1765 * @returns VBox status code.
1766 * @param hVdIoQueue The I/O queue.
1767 * @param fPurge Flag whether to cancel all active requests on this queue
1768 * before detaching.
1769 */
1770VBOXDDU_DECL(int) VDIoQueueDetach(VDIOQUEUE hVdIoQueue, bool fPurge);
1771
1772/**
1773 * Purges all requests on the given queue.
1774 *
1775 * @returns VBox status code.
1776 * @param hVdIoQueue The I/O queue.
1777 */
1778VBOXDDU_DECL(int) VDIoQueuePurge(VDIOQUEUE hVdIoQueue);
1779
1780/**
1781 * Allocates a new request from the given queue.
1782 *
1783 * @returns VBox status code.
1784 * @param hVdIoQueue The I/O queue.
1785 * @param phVdIoReq Where to store the handle of the request on success.
1786 * @param ppvVdIoReq Where to store the pointer to the allocator usable memory on success.
1787 * @param uIoReqId The request ID to assign to the request for canceling.
1788 */
1789VBOXDDU_DECL(int) VDIoQueueReqAlloc(VDIOQUEUE hVdIoQueue, PVDIOREQ phVdIoReq,
1790 void **ppvVdIoReq, VDIOREQID uIoReqId);
1791
1792/**
1793 * Frees a given non active request.
1794 *
1795 * @returns VBox status code.
1796 * @param hVdIoReq The I/O request to free.
1797 */
1798VBOXDDU_DECL(int) VDIoQueueReqFree(VDIOREQ hVdIoReq);
1799
1800/**
1801 * Cancels an active request by the given request ID.
1802 *
1803 * @returns VBox status code.
1804 * @param hVdIoQueue The I/O queue to cancel the request on.
1805 * @param uIoReqId The request ID.
1806 */
1807VBOXDDU_DECL(int) VDIoQueueReqCancelById(VDIOQUEUE hVdIoQueue, VDIOREQID uIoReqId);
1808
1809/**
1810 * Cancels an active request by the given handle.
1811 *
1812 * @returns VBox status code.
1813 * @param hVdIoReq The I/O request handle to cancel.
1814 */
1815VBOXDDU_DECL(int) VDIoQueueReqCancelByHandle(VDIOREQ hVdIoReq);
1816
1817/**
1818 * Submit a new request to the queue the request was allocated from.
1819 *
1820 * @returns VBox status code.
1821 * @param hVdIoReq The I/O request handle to submit.
1822 * @param enmType The type of the request.
1823 * @param hVdIoIter The iterator to use, NULL for flush requests.
1824 * @param hVdIoBuf The I/O buffer handle to use, NULL for flush and discard requests.
1825 */
1826VBOXDDU_DECL(int) VDIoQueueReqSubmit(VDIOREQ hVdIoReq, VDIOREQTYPE enmType,
1827 VDIOITER hVdIoIter, VDIOBUF hVdIoBuf);
1828
1829/** @} */
1830
1831
1832RT_C_DECLS_END
1833
1834/** @} */
1835
1836#endif /* !VBOX_INCLUDED_vd_h */
1837
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