VirtualBox

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

Last change on this file since 78345 was 77855, checked in by vboxsync, 6 years ago

Storage/VD: Move the TCP/NET implementation from DrvVD to a separate file in the VD storage library so it can be reused elsewhere

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