VirtualBox

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

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

Copyright year updates by scm.

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