VirtualBox

source: vbox/trunk/include/VBox/vd-cache-backend.h@ 96399

Last change on this file since 96399 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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