[32370] | 1 | /** @file
|
---|
| 2 | * Internal hard disk format support API for VBoxHDD cache images.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[44528] | 6 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
[32370] | 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 __VBoxHDD_CachePlugin_h__
|
---|
| 27 | #define __VBoxHDD_CachePlugin_h__
|
---|
| 28 |
|
---|
[33567] | 29 | #include <VBox/vd.h>
|
---|
[38469] | 30 | #include <VBox/vd-ifs-internal.h>
|
---|
[32370] | 31 |
|
---|
| 32 | /**
|
---|
| 33 | * Cache format backend interface used by VBox HDD Container implementation.
|
---|
| 34 | */
|
---|
| 35 | typedef struct VDCACHEBACKEND
|
---|
| 36 | {
|
---|
| 37 | /**
|
---|
| 38 | * The name of the backend (constant string).
|
---|
| 39 | */
|
---|
| 40 | const char *pszBackendName;
|
---|
| 41 |
|
---|
| 42 | /**
|
---|
| 43 | * The size of the structure.
|
---|
| 44 | */
|
---|
| 45 | uint32_t cbSize;
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * The capabilities of the backend.
|
---|
| 49 | */
|
---|
| 50 | uint64_t uBackendCaps;
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | * Pointer to a NULL-terminated array of strings, containing the supported
|
---|
| 54 | * file extensions. Note that some backends do not work on files, so this
|
---|
| 55 | * pointer may just contain NULL.
|
---|
| 56 | */
|
---|
| 57 | const char * const *papszFileExtensions;
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | * Pointer to an array of structs describing each supported config key.
|
---|
| 61 | * Terminated by a NULL config key. Note that some backends do not support
|
---|
| 62 | * the configuration interface, so this pointer may just contain NULL.
|
---|
| 63 | * Mandatory if the backend sets VD_CAP_CONFIG.
|
---|
| 64 | */
|
---|
| 65 | PCVDCONFIGINFO paConfigInfo;
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
| 68 | * Probes the given image.
|
---|
| 69 | *
|
---|
| 70 | * @returns VBox status code.
|
---|
| 71 | * @param pszFilename Name of the image file.
|
---|
[32536] | 72 | * @param pVDIfsDisk Pointer to the per-disk VD interface list.
|
---|
| 73 | * @param pVDIfsImage Pointer to the per-image VD interface list.
|
---|
[32370] | 74 | */
|
---|
[32536] | 75 | DECLR3CALLBACKMEMBER(int, pfnProbe, (const char *pszFilename, PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage));
|
---|
[32370] | 76 |
|
---|
| 77 | /**
|
---|
| 78 | * Open a cache image.
|
---|
| 79 | *
|
---|
| 80 | * @returns VBox status code.
|
---|
| 81 | * @param pszFilename Name of the image file to open. Guaranteed to be available and
|
---|
| 82 | * unchanged during the lifetime of this image.
|
---|
| 83 | * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
|
---|
| 84 | * @param pVDIfsDisk Pointer to the per-disk VD interface list.
|
---|
| 85 | * @param pVDIfsImage Pointer to the per-image VD interface list.
|
---|
[32536] | 86 | * @param ppBackendData Opaque state data for this image.
|
---|
[32370] | 87 | */
|
---|
| 88 | DECLR3CALLBACKMEMBER(int, pfnOpen, (const char *pszFilename, unsigned uOpenFlags,
|
---|
| 89 | PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
|
---|
[32536] | 90 | void **ppBackendData));
|
---|
[32370] | 91 |
|
---|
| 92 | /**
|
---|
| 93 | * Create a cache image.
|
---|
| 94 | *
|
---|
| 95 | * @returns VBox status code.
|
---|
| 96 | * @param pszFilename Name of the image file to create. Guaranteed to be available and
|
---|
| 97 | * unchanged during the lifetime of this image.
|
---|
| 98 | * @param cbSize Image size in bytes.
|
---|
| 99 | * @param uImageFlags Flags specifying special image features.
|
---|
| 100 | * @param pszComment Pointer to image comment. NULL is ok.
|
---|
| 101 | * @param pUuid New UUID of the image. Not NULL.
|
---|
| 102 | * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants.
|
---|
| 103 | * @param uPercentStart Starting value for progress percentage.
|
---|
| 104 | * @param uPercentSpan Span for varying progress percentage.
|
---|
| 105 | * @param pVDIfsDisk Pointer to the per-disk VD interface list.
|
---|
| 106 | * @param pVDIfsImage Pointer to the per-image VD interface list.
|
---|
| 107 | * @param pVDIfsOperation Pointer to the per-operation VD interface list.
|
---|
[32536] | 108 | * @param ppBackendData Opaque state data for this image.
|
---|
[32370] | 109 | */
|
---|
| 110 | DECLR3CALLBACKMEMBER(int, pfnCreate, (const char *pszFilename, uint64_t cbSize,
|
---|
| 111 | unsigned uImageFlags, const char *pszComment,
|
---|
| 112 | PCRTUUID pUuid, unsigned uOpenFlags,
|
---|
| 113 | unsigned uPercentStart, unsigned uPercentSpan,
|
---|
| 114 | PVDINTERFACE pVDIfsDisk,
|
---|
| 115 | PVDINTERFACE pVDIfsImage,
|
---|
| 116 | PVDINTERFACE pVDIfsOperation,
|
---|
[32536] | 117 | void **ppBackendData));
|
---|
[32370] | 118 |
|
---|
| 119 | /**
|
---|
| 120 | * Close a cache image.
|
---|
| 121 | *
|
---|
| 122 | * @returns VBox status code.
|
---|
[32536] | 123 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 124 | * @param fDelete If true, delete the image from the host disk.
|
---|
| 125 | */
|
---|
[32536] | 126 | DECLR3CALLBACKMEMBER(int, pfnClose, (void *pBackendData, bool fDelete));
|
---|
[32370] | 127 |
|
---|
| 128 | /**
|
---|
[44412] | 129 | * Start a read request.
|
---|
[32370] | 130 | *
|
---|
| 131 | * @returns VBox status code.
|
---|
[32536] | 132 | * @param pBackendData Opaque state data for this image.
|
---|
[44412] | 133 | * @param uOffset The offset of the virtual disk to read from.
|
---|
| 134 | * @param cbRead How many bytes to read.
|
---|
| 135 | * @param pIoCtx I/O context associated with this request.
|
---|
[32370] | 136 | * @param pcbActuallyRead Pointer to returned number of bytes read.
|
---|
| 137 | */
|
---|
[44412] | 138 | DECLR3CALLBACKMEMBER(int, pfnRead, (void *pBackendData, uint64_t uOffset, size_t cbRead,
|
---|
| 139 | PVDIOCTX pIoCtx, size_t *pcbActuallyRead));
|
---|
[32370] | 140 |
|
---|
| 141 | /**
|
---|
[44412] | 142 | * Start a write request.
|
---|
[32370] | 143 | *
|
---|
| 144 | * @returns VBox status code.
|
---|
[32536] | 145 | * @param pBackendData Opaque state data for this image.
|
---|
[44412] | 146 | * @param uOffset The offset of the virtual disk to write to.
|
---|
| 147 | * @param cbWrite How many bytes to write.
|
---|
| 148 | * @param pIoCtx I/O context associated with this request.
|
---|
[32370] | 149 | * @param pcbWriteProcess Pointer to returned number of bytes that could
|
---|
[44412] | 150 | * be processed. In case the function returned
|
---|
| 151 | * VERR_VD_BLOCK_FREE this is the number of bytes
|
---|
| 152 | * that could be written in a full block write,
|
---|
| 153 | * when prefixed/postfixed by the appropriate
|
---|
| 154 | * amount of (previously read) padding data.
|
---|
[32370] | 155 | */
|
---|
[44412] | 156 | DECLR3CALLBACKMEMBER(int, pfnWrite, (void *pBackendData, uint64_t uOffset, size_t cbWrite,
|
---|
| 157 | PVDIOCTX pIoCtx, size_t *pcbWriteProcess));
|
---|
[32370] | 158 |
|
---|
| 159 | /**
|
---|
| 160 | * Flush data to disk.
|
---|
| 161 | *
|
---|
| 162 | * @returns VBox status code.
|
---|
[32536] | 163 | * @param pBackendData Opaque state data for this image.
|
---|
[44412] | 164 | * @param pIoCtx I/O context associated with this request.
|
---|
[32370] | 165 | */
|
---|
[44412] | 166 | DECLR3CALLBACKMEMBER(int, pfnFlush, (void *pBackendData, PVDIOCTX pIoCtx));
|
---|
[32370] | 167 |
|
---|
| 168 | /**
|
---|
[44412] | 169 | * Discards the given amount of bytes from the cache.
|
---|
| 170 | *
|
---|
| 171 | * @returns VBox status code.
|
---|
| 172 | * @retval VERR_VD_DISCARD_ALIGNMENT_NOT_MET if the range doesn't meet the required alignment
|
---|
| 173 | * for the discard.
|
---|
| 174 | * @param pBackendData Opaque state data for this image.
|
---|
| 175 | * @param pIoCtx I/O context associated with this request.
|
---|
| 176 | * @param uOffset The offset of the first byte to discard.
|
---|
| 177 | * @param cbDiscard How many bytes to discard.
|
---|
| 178 | */
|
---|
| 179 | DECLR3CALLBACKMEMBER(int, pfnDiscard, (void *pBackendData, PVDIOCTX pIoCtx,
|
---|
| 180 | uint64_t uOffset, size_t cbDiscard,
|
---|
| 181 | size_t *pcbPreAllocated,
|
---|
| 182 | size_t *pcbPostAllocated,
|
---|
| 183 | size_t *pcbActuallyDiscarded,
|
---|
| 184 | void **ppbmAllocationBitmap,
|
---|
| 185 | unsigned fDiscard));
|
---|
| 186 |
|
---|
| 187 | /**
|
---|
[32370] | 188 | * Get the version of a cache image.
|
---|
| 189 | *
|
---|
| 190 | * @returns version of cache image.
|
---|
[32536] | 191 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 192 | */
|
---|
[32536] | 193 | DECLR3CALLBACKMEMBER(unsigned, pfnGetVersion, (void *pBackendData));
|
---|
[32370] | 194 |
|
---|
| 195 | /**
|
---|
| 196 | * Get the capacity of a cache image.
|
---|
| 197 | *
|
---|
| 198 | * @returns size of cache image in bytes.
|
---|
[32536] | 199 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 200 | */
|
---|
[32536] | 201 | DECLR3CALLBACKMEMBER(uint64_t, pfnGetSize, (void *pBackendData));
|
---|
[32370] | 202 |
|
---|
| 203 | /**
|
---|
| 204 | * Get the file size of a cache image.
|
---|
| 205 | *
|
---|
| 206 | * @returns size of cache image in bytes.
|
---|
[32536] | 207 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 208 | */
|
---|
[32536] | 209 | DECLR3CALLBACKMEMBER(uint64_t, pfnGetFileSize, (void *pBackendData));
|
---|
[32370] | 210 |
|
---|
| 211 | /**
|
---|
| 212 | * Get the image flags of a cache image.
|
---|
| 213 | *
|
---|
| 214 | * @returns image flags of cache image.
|
---|
[32536] | 215 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 216 | */
|
---|
[32536] | 217 | DECLR3CALLBACKMEMBER(unsigned, pfnGetImageFlags, (void *pBackendData));
|
---|
[32370] | 218 |
|
---|
| 219 | /**
|
---|
| 220 | * Get the open flags of a cache image.
|
---|
| 221 | *
|
---|
| 222 | * @returns open flags of cache image.
|
---|
[32536] | 223 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 224 | */
|
---|
[32536] | 225 | DECLR3CALLBACKMEMBER(unsigned, pfnGetOpenFlags, (void *pBackendData));
|
---|
[32370] | 226 |
|
---|
| 227 | /**
|
---|
| 228 | * Set the open flags of a cache image. May cause the image to be locked
|
---|
| 229 | * in a different mode or be reopened (which can fail).
|
---|
| 230 | *
|
---|
| 231 | * @returns VBox status code.
|
---|
[32536] | 232 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 233 | * @param uOpenFlags New open flags for this image.
|
---|
| 234 | */
|
---|
[32536] | 235 | DECLR3CALLBACKMEMBER(int, pfnSetOpenFlags, (void *pBackendData, unsigned uOpenFlags));
|
---|
[32370] | 236 |
|
---|
| 237 | /**
|
---|
| 238 | * Get comment of a cache image.
|
---|
| 239 | *
|
---|
| 240 | * @returns VBox status code.
|
---|
[32536] | 241 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 242 | * @param pszComment Where to store the comment.
|
---|
| 243 | * @param cbComment Size of the comment buffer.
|
---|
| 244 | */
|
---|
[32536] | 245 | DECLR3CALLBACKMEMBER(int, pfnGetComment, (void *pBackendData, char *pszComment, size_t cbComment));
|
---|
[32370] | 246 |
|
---|
| 247 | /**
|
---|
| 248 | * Set comment of a cache image.
|
---|
| 249 | *
|
---|
| 250 | * @returns VBox status code.
|
---|
[32536] | 251 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 252 | * @param pszComment Where to get the comment from. NULL resets comment.
|
---|
| 253 | * The comment is silently truncated if the image format
|
---|
| 254 | * limit is exceeded.
|
---|
| 255 | */
|
---|
[32536] | 256 | DECLR3CALLBACKMEMBER(int, pfnSetComment, (void *pBackendData, const char *pszComment));
|
---|
[32370] | 257 |
|
---|
| 258 | /**
|
---|
| 259 | * Get UUID of a cache image.
|
---|
| 260 | *
|
---|
| 261 | * @returns VBox status code.
|
---|
[32536] | 262 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 263 | * @param pUuid Where to store the image UUID.
|
---|
| 264 | */
|
---|
[32536] | 265 | DECLR3CALLBACKMEMBER(int, pfnGetUuid, (void *pBackendData, PRTUUID pUuid));
|
---|
[32370] | 266 |
|
---|
| 267 | /**
|
---|
| 268 | * Set UUID of a cache image.
|
---|
| 269 | *
|
---|
| 270 | * @returns VBox status code.
|
---|
[32536] | 271 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 272 | * @param pUuid Where to get the image UUID from.
|
---|
| 273 | */
|
---|
[32536] | 274 | DECLR3CALLBACKMEMBER(int, pfnSetUuid, (void *pBackendData, PCRTUUID pUuid));
|
---|
[32370] | 275 |
|
---|
| 276 | /**
|
---|
| 277 | * Get last modification UUID of a cache image.
|
---|
| 278 | *
|
---|
| 279 | * @returns VBox status code.
|
---|
[32536] | 280 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 281 | * @param pUuid Where to store the image modification UUID.
|
---|
| 282 | */
|
---|
[32536] | 283 | DECLR3CALLBACKMEMBER(int, pfnGetModificationUuid, (void *pBackendData, PRTUUID pUuid));
|
---|
[32370] | 284 |
|
---|
| 285 | /**
|
---|
| 286 | * Set last modification UUID of a cache image.
|
---|
| 287 | *
|
---|
| 288 | * @returns VBox status code.
|
---|
[32536] | 289 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 290 | * @param pUuid Where to get the image modification UUID from.
|
---|
| 291 | */
|
---|
[32536] | 292 | DECLR3CALLBACKMEMBER(int, pfnSetModificationUuid, (void *pBackendData, PCRTUUID pUuid));
|
---|
[32370] | 293 |
|
---|
| 294 | /**
|
---|
| 295 | * Dump information about a cache image.
|
---|
| 296 | *
|
---|
[32536] | 297 | * @param pBackendData Opaque state data for this image.
|
---|
[32370] | 298 | */
|
---|
[32536] | 299 | DECLR3CALLBACKMEMBER(void, pfnDump, (void *pBackendData));
|
---|
[32370] | 300 |
|
---|
| 301 | /** Returns a human readable hard disk location string given a
|
---|
| 302 | * set of hard disk configuration keys. The returned string is an
|
---|
| 303 | * equivalent of the full file path for image-based hard disks.
|
---|
| 304 | * Mandatory for backends with no VD_CAP_FILE and NULL otherwise. */
|
---|
| 305 | DECLR3CALLBACKMEMBER(int, pfnComposeLocation, (PVDINTERFACE pConfig, char **pszLocation));
|
---|
| 306 |
|
---|
| 307 | /** Returns a human readable hard disk name string given a
|
---|
| 308 | * set of hard disk configuration keys. The returned string is an
|
---|
| 309 | * equivalent of the file name part in the full file path for
|
---|
| 310 | * image-based hard disks. Mandatory for backends with no
|
---|
| 311 | * VD_CAP_FILE and NULL otherwise. */
|
---|
| 312 | DECLR3CALLBACKMEMBER(int, pfnComposeName, (PVDINTERFACE pConfig, char **pszName));
|
---|
| 313 |
|
---|
| 314 | } VDCACHEBACKEND;
|
---|
[50988] | 315 | /** Pointer to VD cache backend. */
|
---|
[32370] | 316 | typedef VDCACHEBACKEND *PVDCACHEBACKEND;
|
---|
| 317 | /** Constant pointer to VD backend. */
|
---|
| 318 | typedef const VDCACHEBACKEND *PCVDCACHEBACKEND;
|
---|
| 319 |
|
---|
| 320 | #endif
|
---|