1 | /** @file
|
---|
2 | * Virtual Disk Image (VDI), Core Code.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 |
|
---|
17 | /*******************************************************************************
|
---|
18 | * Header Files *
|
---|
19 | *******************************************************************************/
|
---|
20 | #define LOG_GROUP LOG_GROUP_VD_VDI
|
---|
21 | #include "VBoxHDD-newInternal.h"
|
---|
22 | #define VBOX_VDICORE_VD /* Signal that the header is included from here. */
|
---|
23 | #include "VDICore.h"
|
---|
24 | #include <VBox/err.h>
|
---|
25 |
|
---|
26 | #include <VBox/log.h>
|
---|
27 | #include <iprt/alloc.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/uuid.h>
|
---|
30 | #include <iprt/file.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 | #include <iprt/asm.h>
|
---|
33 |
|
---|
34 | #define VDI_IMAGE_DEFAULT_BLOCK_SIZE _1M
|
---|
35 |
|
---|
36 | /*******************************************************************************
|
---|
37 | * Internal Functions *
|
---|
38 | *******************************************************************************/
|
---|
39 | static unsigned getPowerOfTwo(unsigned uNumber);
|
---|
40 | static void vdiInitPreHeader(PVDIPREHEADER pPreHdr);
|
---|
41 | static int vdiValidatePreHeader(PVDIPREHEADER pPreHdr);
|
---|
42 | static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, uint32_t uImageFlags,
|
---|
43 | const char *pszComment, uint64_t cbDisk, uint32_t cbBlock,
|
---|
44 | uint32_t cbBlockExtra);
|
---|
45 | static int vdiValidateHeader(PVDIHEADER pHeader);
|
---|
46 | static void vdiSetupImageDesc(PVDIIMAGEDESC pImage);
|
---|
47 | static int vdiUpdateHeader(PVDIIMAGEDESC pImage);
|
---|
48 | static int vdiUpdateBlockInfo(PVDIIMAGEDESC pImage, unsigned uBlock);
|
---|
49 | static void vdiFreeImage(PVDIIMAGEDESC pImage, bool fDelete);
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Internal: signal an error to the frontend.
|
---|
54 | */
|
---|
55 | DECLINLINE(int) vdiError(PVDIIMAGEDESC pImage, int rc, RT_SRC_POS_DECL,
|
---|
56 | const char *pszFormat, ...)
|
---|
57 | {
|
---|
58 | va_list va;
|
---|
59 | va_start(va, pszFormat);
|
---|
60 | if (pImage->pfnError)
|
---|
61 | pImage->pfnError(pImage->pvErrorUser, rc, RT_SRC_POS_ARGS,
|
---|
62 | pszFormat, va);
|
---|
63 | va_end(va);
|
---|
64 | return rc;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * internal: return power of 2 or 0 if num error.
|
---|
70 | */
|
---|
71 | static unsigned getPowerOfTwo(unsigned uNumber)
|
---|
72 | {
|
---|
73 | if (uNumber == 0)
|
---|
74 | return 0;
|
---|
75 | unsigned uPower2 = 0;
|
---|
76 | while ((uNumber & 1) == 0)
|
---|
77 | {
|
---|
78 | uNumber >>= 1;
|
---|
79 | uPower2++;
|
---|
80 | }
|
---|
81 | return uNumber == 1 ? uPower2 : 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Internal: Init VDI preheader.
|
---|
87 | */
|
---|
88 | static void vdiInitPreHeader(PVDIPREHEADER pPreHdr)
|
---|
89 | {
|
---|
90 | pPreHdr->u32Signature = VDI_IMAGE_SIGNATURE;
|
---|
91 | pPreHdr->u32Version = VDI_IMAGE_VERSION;
|
---|
92 | memset(pPreHdr->szFileInfo, 0, sizeof(pPreHdr->szFileInfo));
|
---|
93 | strncat(pPreHdr->szFileInfo, VDI_IMAGE_FILE_INFO, sizeof(pPreHdr->szFileInfo));
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Internal: check VDI preheader.
|
---|
98 | */
|
---|
99 | static int vdiValidatePreHeader(PVDIPREHEADER pPreHdr)
|
---|
100 | {
|
---|
101 | if (pPreHdr->u32Signature != VDI_IMAGE_SIGNATURE)
|
---|
102 | return VERR_VDI_INVALID_SIGNATURE;
|
---|
103 |
|
---|
104 | if ( VDI_GET_VERSION_MAJOR(pPreHdr->u32Version) != VDI_IMAGE_VERSION_MAJOR
|
---|
105 | && pPreHdr->u32Version != 0x00000002) /* old version. */
|
---|
106 | return VERR_VDI_UNSUPPORTED_VERSION;
|
---|
107 |
|
---|
108 | return VINF_SUCCESS;
|
---|
109 | }
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Internal: Init VDI header. Always use latest header version.
|
---|
113 | * @param pHeader Assumes it was initially initialized to all zeros.
|
---|
114 | */
|
---|
115 | static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, uint32_t uImageFlags,
|
---|
116 | const char *pszComment, uint64_t cbDisk, uint32_t cbBlock,
|
---|
117 | uint32_t cbBlockExtra)
|
---|
118 | {
|
---|
119 | pHeader->uVersion = VDI_IMAGE_VERSION;
|
---|
120 | pHeader->u.v1.cbHeader = sizeof(VDIHEADER1);
|
---|
121 | pHeader->u.v1.u32Type = (uint32_t)( enmType == VD_IMAGE_TYPE_NORMAL
|
---|
122 | ? VDI_IMAGE_TYPE_NORMAL
|
---|
123 | : VDI_IMAGE_TYPE_DIFF);
|
---|
124 | pHeader->u.v1.fFlags = uImageFlags;
|
---|
125 | #ifdef VBOX_STRICT
|
---|
126 | char achZero[VDI_IMAGE_COMMENT_SIZE] = {0};
|
---|
127 | Assert(!memcmp(pHeader->u.v1.szComment, achZero, VDI_IMAGE_COMMENT_SIZE));
|
---|
128 | #endif
|
---|
129 | pHeader->u.v1.szComment[0] = '\0';
|
---|
130 | if (pszComment)
|
---|
131 | {
|
---|
132 | AssertMsg(strlen(pszComment) < sizeof(pHeader->u.v1.szComment),
|
---|
133 | ("HDD Comment is too long, cb=%d\n", strlen(pszComment)));
|
---|
134 | strncat(pHeader->u.v1.szComment, pszComment, sizeof(pHeader->u.v1.szComment));
|
---|
135 | }
|
---|
136 |
|
---|
137 | /* Mark the legacy geometry not-calculated. */
|
---|
138 | pHeader->u.v1.LegacyGeometry.cCylinders = 0;
|
---|
139 | pHeader->u.v1.LegacyGeometry.cHeads = 0;
|
---|
140 | pHeader->u.v1.LegacyGeometry.cSectors = 0;
|
---|
141 | pHeader->u.v1.LegacyGeometry.cbSector = VDI_GEOMETRY_SECTOR_SIZE;
|
---|
142 | pHeader->u.v1.u32Dummy = 0; /* used to be the translation value */
|
---|
143 |
|
---|
144 | pHeader->u.v1.cbDisk = cbDisk;
|
---|
145 | pHeader->u.v1.cbBlock = cbBlock;
|
---|
146 | pHeader->u.v1.cBlocks = (uint32_t)(cbDisk / cbBlock);
|
---|
147 | if (cbDisk % cbBlock)
|
---|
148 | pHeader->u.v1.cBlocks++;
|
---|
149 | pHeader->u.v1.cbBlockExtra = cbBlockExtra;
|
---|
150 | pHeader->u.v1.cBlocksAllocated = 0;
|
---|
151 |
|
---|
152 | /* Init offsets. */
|
---|
153 | pHeader->u.v1.offBlocks = RT_ALIGN_32(sizeof(VDIPREHEADER) + sizeof(VDIHEADER1), VDI_GEOMETRY_SECTOR_SIZE);
|
---|
154 | pHeader->u.v1.offData = RT_ALIGN_32(pHeader->u.v1.offBlocks + (pHeader->u.v1.cBlocks * sizeof(VDIIMAGEBLOCKPOINTER)), VDI_GEOMETRY_SECTOR_SIZE);
|
---|
155 |
|
---|
156 | /* Init uuids. */
|
---|
157 | RTUuidCreate(&pHeader->u.v1.uuidCreate);
|
---|
158 | RTUuidClear(&pHeader->u.v1.uuidModify);
|
---|
159 | RTUuidClear(&pHeader->u.v1.uuidLinkage);
|
---|
160 | RTUuidClear(&pHeader->u.v1.uuidParentModify);
|
---|
161 |
|
---|
162 | /* Mark LCHS geometry not-calculated. */
|
---|
163 | pHeader->u.v1plus.LCHSGeometry.cCylinders = 0;
|
---|
164 | pHeader->u.v1plus.LCHSGeometry.cHeads = 0;
|
---|
165 | pHeader->u.v1plus.LCHSGeometry.cSectors = 0;
|
---|
166 | pHeader->u.v1plus.LCHSGeometry.cbSector = VDI_GEOMETRY_SECTOR_SIZE;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Internal: Check VDI header.
|
---|
171 | */
|
---|
172 | static int vdiValidateHeader(PVDIHEADER pHeader)
|
---|
173 | {
|
---|
174 | /* Check version-dependend header parameters. */
|
---|
175 | switch (GET_MAJOR_HEADER_VERSION(pHeader))
|
---|
176 | {
|
---|
177 | case 0:
|
---|
178 | {
|
---|
179 | /* Old header version. */
|
---|
180 | break;
|
---|
181 | }
|
---|
182 | case 1:
|
---|
183 | {
|
---|
184 | /* Current header version. */
|
---|
185 |
|
---|
186 | if (pHeader->u.v1.cbHeader < sizeof(VDIHEADER1))
|
---|
187 | {
|
---|
188 | LogRel(("VDI: v1 header size wrong (%d < %d)\n",
|
---|
189 | pHeader->u.v1.cbHeader, sizeof(VDIHEADER1)));
|
---|
190 | return VERR_VDI_INVALID_HEADER;
|
---|
191 | }
|
---|
192 |
|
---|
193 | if (getImageBlocksOffset(pHeader) < (sizeof(VDIPREHEADER) + sizeof(VDIHEADER1)))
|
---|
194 | {
|
---|
195 | LogRel(("VDI: v1 blocks offset wrong (%d < %d)\n",
|
---|
196 | getImageBlocksOffset(pHeader), sizeof(VDIPREHEADER) + sizeof(VDIHEADER1)));
|
---|
197 | return VERR_VDI_INVALID_HEADER;
|
---|
198 | }
|
---|
199 |
|
---|
200 | if (getImageDataOffset(pHeader) < (getImageBlocksOffset(pHeader) + getImageBlocks(pHeader) * sizeof(VDIIMAGEBLOCKPOINTER)))
|
---|
201 | {
|
---|
202 | LogRel(("VDI: v1 image data offset wrong (%d < %d)\n",
|
---|
203 | getImageDataOffset(pHeader), getImageBlocksOffset(pHeader) + getImageBlocks(pHeader) * sizeof(VDIIMAGEBLOCKPOINTER)));
|
---|
204 | return VERR_VDI_INVALID_HEADER;
|
---|
205 | }
|
---|
206 |
|
---|
207 | break;
|
---|
208 | }
|
---|
209 | default:
|
---|
210 | /* Unsupported. */
|
---|
211 | return VERR_VDI_UNSUPPORTED_VERSION;
|
---|
212 | }
|
---|
213 |
|
---|
214 | /* Check common header parameters. */
|
---|
215 |
|
---|
216 | bool fFailed = false;
|
---|
217 |
|
---|
218 | if ( getImageType(pHeader) < VDI_IMAGE_TYPE_FIRST
|
---|
219 | || getImageType(pHeader) > VDI_IMAGE_TYPE_LAST)
|
---|
220 | {
|
---|
221 | LogRel(("VDI: bad image type %d\n", getImageType(pHeader)));
|
---|
222 | fFailed = true;
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (getImageFlags(pHeader) & ~VD_VDI_IMAGE_FLAGS_MASK)
|
---|
226 | {
|
---|
227 | LogRel(("VDI: bad image flags %08x\n", getImageFlags(pHeader)));
|
---|
228 | fFailed = true;
|
---|
229 | }
|
---|
230 |
|
---|
231 | if ( getImageLCHSGeometry(pHeader)
|
---|
232 | && (getImageLCHSGeometry(pHeader))->cbSector != VDI_GEOMETRY_SECTOR_SIZE)
|
---|
233 | {
|
---|
234 | LogRel(("VDI: wrong sector size (%d != %d)\n",
|
---|
235 | (getImageLCHSGeometry(pHeader))->cbSector, VDI_GEOMETRY_SECTOR_SIZE));
|
---|
236 | fFailed = true;
|
---|
237 | }
|
---|
238 |
|
---|
239 | if ( getImageDiskSize(pHeader) == 0
|
---|
240 | || getImageBlockSize(pHeader) == 0
|
---|
241 | || getImageBlocks(pHeader) == 0
|
---|
242 | || getPowerOfTwo(getImageBlockSize(pHeader)) == 0)
|
---|
243 | {
|
---|
244 | LogRel(("VDI: wrong size (%lld, %d, %d, %d)\n",
|
---|
245 | getImageDiskSize(pHeader), getImageBlockSize(pHeader),
|
---|
246 | getImageBlocks(pHeader), getPowerOfTwo(getImageBlockSize(pHeader))));
|
---|
247 | fFailed = true;
|
---|
248 | }
|
---|
249 |
|
---|
250 | if (getImageBlocksAllocated(pHeader) > getImageBlocks(pHeader))
|
---|
251 | {
|
---|
252 | LogRel(("VDI: too many blocks allocated (%d > %d)\n"
|
---|
253 | " blocksize=%d disksize=%lld\n",
|
---|
254 | getImageBlocksAllocated(pHeader), getImageBlocks(pHeader),
|
---|
255 | getImageBlockSize(pHeader), getImageDiskSize(pHeader)));
|
---|
256 | fFailed = true;
|
---|
257 | }
|
---|
258 |
|
---|
259 | if ( getImageExtraBlockSize(pHeader) != 0
|
---|
260 | && getPowerOfTwo(getImageExtraBlockSize(pHeader)) == 0)
|
---|
261 | {
|
---|
262 | LogRel(("VDI: wrong extra size (%d, %d)\n",
|
---|
263 | getImageExtraBlockSize(pHeader), getPowerOfTwo(getImageExtraBlockSize(pHeader))));
|
---|
264 | fFailed = true;
|
---|
265 | }
|
---|
266 |
|
---|
267 | if ((uint64_t)getImageBlockSize(pHeader) * getImageBlocks(pHeader) < getImageDiskSize(pHeader))
|
---|
268 | {
|
---|
269 | LogRel(("VDI: wrong disk size (%d, %d, %lld)\n",
|
---|
270 | getImageBlockSize(pHeader), getImageBlocks(pHeader), getImageDiskSize(pHeader)));
|
---|
271 | fFailed = true;
|
---|
272 | }
|
---|
273 |
|
---|
274 | if (RTUuidIsNull(getImageCreationUUID(pHeader)))
|
---|
275 | {
|
---|
276 | LogRel(("VDI: uuid of creator is 0\n"));
|
---|
277 | fFailed = true;
|
---|
278 | }
|
---|
279 |
|
---|
280 | if (RTUuidIsNull(getImageModificationUUID(pHeader)))
|
---|
281 | {
|
---|
282 | LogRel(("VDI: uuid of modificator is 0\n"));
|
---|
283 | fFailed = true;
|
---|
284 | }
|
---|
285 |
|
---|
286 | return fFailed ? VERR_VDI_INVALID_HEADER : VINF_SUCCESS;
|
---|
287 | }
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Internal: Set up VDIIMAGEDESC structure by image header.
|
---|
291 | */
|
---|
292 | static void vdiSetupImageDesc(PVDIIMAGEDESC pImage)
|
---|
293 | {
|
---|
294 | pImage->uImageFlags = getImageFlags(&pImage->Header);
|
---|
295 | pImage->offStartBlocks = getImageBlocksOffset(&pImage->Header);
|
---|
296 | pImage->offStartData = getImageDataOffset(&pImage->Header);
|
---|
297 | pImage->uBlockMask = getImageBlockSize(&pImage->Header) - 1;
|
---|
298 | pImage->uShiftIndex2Offset =
|
---|
299 | pImage->uShiftOffset2Index = getPowerOfTwo(getImageBlockSize(&pImage->Header));
|
---|
300 | pImage->offStartBlockData = getImageExtraBlockSize(&pImage->Header);
|
---|
301 | if (pImage->offStartBlockData != 0)
|
---|
302 | pImage->uShiftIndex2Offset += getPowerOfTwo(pImage->offStartBlockData);
|
---|
303 | }
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Internal: Create VDI image file.
|
---|
307 | */
|
---|
308 | static int vdiCreateImage(PVDIIMAGEDESC pImage, VDIMAGETYPE enmType,
|
---|
309 | uint64_t cbSize, unsigned uImageFlags,
|
---|
310 | const char *pszComment,
|
---|
311 | PCPDMMEDIAGEOMETRY pPCHSGeometry,
|
---|
312 | PCPDMMEDIAGEOMETRY pLCHSGeometry,
|
---|
313 | PFNVMPROGRESS pfnProgress, void *pvUser,
|
---|
314 | unsigned uPercentStart, unsigned uPercentSpan)
|
---|
315 | {
|
---|
316 | int rc;
|
---|
317 | RTFILE File;
|
---|
318 | uint64_t cbTotal;
|
---|
319 | uint64_t cbFill;
|
---|
320 | uint64_t uOff;
|
---|
321 |
|
---|
322 | /* Special check for comment length. */
|
---|
323 | if ( VALID_PTR(pszComment)
|
---|
324 | && strlen(pszComment) >= VDI_IMAGE_COMMENT_SIZE)
|
---|
325 | {
|
---|
326 | rc = vdiError(pImage, VERR_VDI_COMMENT_TOO_LONG, RT_SRC_POS, N_("VDI: comment is too long for '%s'"), pImage->pszFilename);
|
---|
327 | goto out;
|
---|
328 | }
|
---|
329 | Assert(VALID_PTR(pPCHSGeometry));
|
---|
330 | Assert(VALID_PTR(pLCHSGeometry));
|
---|
331 |
|
---|
332 | vdiInitPreHeader(&pImage->PreHeader);
|
---|
333 | vdiInitHeader(&pImage->Header, enmType, uImageFlags, pszComment, cbSize, VDI_IMAGE_DEFAULT_BLOCK_SIZE, 0);
|
---|
334 | /* Save PCHS geometry. Not much work, and makes the flow of information
|
---|
335 | * quite a bit clearer - relying on the higher level isn't obvious. */
|
---|
336 | pImage->PCHSGeometry = *pPCHSGeometry;
|
---|
337 | /* Set LCHS geometry (legacy geometry is ignored for the current 1.1+). */
|
---|
338 | pImage->Header.u.v1plus.LCHSGeometry.cCylinders = pLCHSGeometry->cCylinders;
|
---|
339 | pImage->Header.u.v1plus.LCHSGeometry.cHeads = pLCHSGeometry->cHeads;
|
---|
340 | pImage->Header.u.v1plus.LCHSGeometry.cSectors = pLCHSGeometry->cSectors;
|
---|
341 | pImage->Header.u.v1plus.LCHSGeometry.cbSector = VDI_GEOMETRY_SECTOR_SIZE;
|
---|
342 |
|
---|
343 | pImage->paBlocks = (PVDIIMAGEBLOCKPOINTER)RTMemAlloc(sizeof(VDIIMAGEBLOCKPOINTER) * getImageBlocks(&pImage->Header));
|
---|
344 | if (!pImage->paBlocks)
|
---|
345 | {
|
---|
346 | rc = VERR_NO_MEMORY;
|
---|
347 | goto out;
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (enmType != VD_IMAGE_TYPE_FIXED)
|
---|
351 | {
|
---|
352 | /* for growing images mark all blocks in paBlocks as free. */
|
---|
353 | for (unsigned i = 0; i < pImage->Header.u.v1.cBlocks; i++)
|
---|
354 | pImage->paBlocks[i] = VDI_IMAGE_BLOCK_FREE;
|
---|
355 | }
|
---|
356 | else
|
---|
357 | {
|
---|
358 | /* for fixed images mark all blocks in paBlocks as allocated */
|
---|
359 | for (unsigned i = 0; i < pImage->Header.u.v1.cBlocks; i++)
|
---|
360 | pImage->paBlocks[i] = i;
|
---|
361 | pImage->Header.u.v1.cBlocksAllocated = pImage->Header.u.v1.cBlocks;
|
---|
362 | }
|
---|
363 |
|
---|
364 | /* Setup image parameters. */
|
---|
365 | vdiSetupImageDesc(pImage);
|
---|
366 |
|
---|
367 | /* create file */
|
---|
368 | rc = RTFileOpen(&File, pImage->pszFilename,
|
---|
369 | RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_ALL);
|
---|
370 | if (VBOX_FAILURE(rc))
|
---|
371 | {
|
---|
372 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: cannot create image '%s'"), pImage->pszFilename);
|
---|
373 | goto out;
|
---|
374 | }
|
---|
375 |
|
---|
376 | cbTotal = pImage->offStartData
|
---|
377 | + ((uint64_t)getImageBlocks(&pImage->Header) << pImage->uShiftIndex2Offset);
|
---|
378 |
|
---|
379 | if (enmType == VD_IMAGE_TYPE_FIXED)
|
---|
380 | {
|
---|
381 | /* check the free space on the disk and leave early if there is not
|
---|
382 | * sufficient space available */
|
---|
383 | RTFOFF cbFree = 0;
|
---|
384 | rc = RTFsQuerySizes(pImage->pszFilename, NULL, &cbFree, NULL, NULL);
|
---|
385 | if (VBOX_SUCCESS(rc) /* ignore errors */ && ((uint64_t)cbFree < cbTotal))
|
---|
386 | {
|
---|
387 | rc = vdiError(pImage, VERR_DISK_FULL, RT_SRC_POS, N_("VDI: disk would overflow creating image '%s'"), pImage->pszFilename);
|
---|
388 | goto out;
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | if (enmType == VD_IMAGE_TYPE_FIXED)
|
---|
393 | {
|
---|
394 | /*
|
---|
395 | * Allocate & commit whole file if fixed image, it must be more
|
---|
396 | * effective than expanding file by write operations.
|
---|
397 | */
|
---|
398 | rc = RTFileSetSize(pImage->File, cbTotal);
|
---|
399 | }
|
---|
400 | else
|
---|
401 | {
|
---|
402 | /* Set file size to hold header and blocks array. */
|
---|
403 | rc = RTFileSetSize(pImage->File, pImage->offStartData);
|
---|
404 | }
|
---|
405 | if (VBOX_FAILURE(rc))
|
---|
406 | {
|
---|
407 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: setting image size failed for '%s'"), pImage->pszFilename);
|
---|
408 | goto out;
|
---|
409 | }
|
---|
410 |
|
---|
411 | /* Generate image last-modify uuid */
|
---|
412 | RTUuidCreate(getImageModificationUUID(&pImage->Header));
|
---|
413 |
|
---|
414 | /* Write pre-header. */
|
---|
415 | rc = RTFileWriteAt(pImage->File, 0, &pImage->PreHeader, sizeof(pImage->PreHeader), NULL);
|
---|
416 | if (VBOX_FAILURE(rc))
|
---|
417 | {
|
---|
418 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: writing pre-header failed for '%s'"), pImage->pszFilename);
|
---|
419 | goto out;
|
---|
420 | }
|
---|
421 |
|
---|
422 | /* Write header. */
|
---|
423 | rc = RTFileWriteAt(pImage->File, sizeof(pImage->PreHeader), &pImage->Header.u.v1plus, sizeof(pImage->Header.u.v1plus), NULL);
|
---|
424 | if (VBOX_FAILURE(rc))
|
---|
425 | {
|
---|
426 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: writing header failed for '%s'"), pImage->pszFilename);
|
---|
427 | goto out;
|
---|
428 | }
|
---|
429 |
|
---|
430 | rc = RTFileWriteAt(pImage->File, pImage->offStartBlocks,
|
---|
431 | pImage->paBlocks,
|
---|
432 | getImageBlocks(&pImage->Header) * sizeof(VDIIMAGEBLOCKPOINTER),
|
---|
433 | NULL);
|
---|
434 | if (VBOX_FAILURE(rc))
|
---|
435 | {
|
---|
436 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: writing block pointers failed for '%s'"), pImage->pszFilename);
|
---|
437 | goto out;
|
---|
438 | }
|
---|
439 |
|
---|
440 | if (enmType == VD_IMAGE_TYPE_FIXED)
|
---|
441 | {
|
---|
442 | /* Fill image with zeroes. We do this for every fixed-size image since on some systems
|
---|
443 | * (for example Windows Vista), it takes ages to write a block near the end of a sparse
|
---|
444 | * file and the guest could complain about an ATA timeout. */
|
---|
445 |
|
---|
446 | /** @todo Starting with Linux 2.6.23, there is an fallocate() system call.
|
---|
447 | * Currently supported file systems are ext4 and ocfs2. */
|
---|
448 |
|
---|
449 | /* Allocate a temporary zero-filled buffer. Use a bigger block size to optimize writing */
|
---|
450 | const size_t cbBuf = 128 * _1K;
|
---|
451 | void *pvBuf = RTMemTmpAllocZ(cbBuf);
|
---|
452 | if (!pvBuf)
|
---|
453 | {
|
---|
454 | rc = VERR_NO_MEMORY;
|
---|
455 | goto out;
|
---|
456 | }
|
---|
457 |
|
---|
458 | cbFill = (uint64_t)getImageBlocks(&pImage->Header) << pImage->uShiftIndex2Offset;
|
---|
459 | uOff = 0;
|
---|
460 | /* do loop to fill all image. */
|
---|
461 | while (uOff < cbFill)
|
---|
462 | {
|
---|
463 | unsigned cbChunk = (unsigned)RT_MIN(cbFill, cbBuf);
|
---|
464 |
|
---|
465 | rc = RTFileWriteAt(pImage->File, pImage->offStartData + uOff,
|
---|
466 | pvBuf, cbChunk, NULL);
|
---|
467 | if (VBOX_FAILURE(rc))
|
---|
468 | {
|
---|
469 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: writing block failed for '%s'"), pImage->pszFilename);
|
---|
470 | goto out;
|
---|
471 | }
|
---|
472 |
|
---|
473 | uOff += cbChunk;
|
---|
474 |
|
---|
475 | if (pfnProgress)
|
---|
476 | {
|
---|
477 | rc = pfnProgress(NULL /* WARNING! pVM=NULL */,
|
---|
478 | uPercentStart + uOff * uPercentSpan / cbFill,
|
---|
479 | pvUser);
|
---|
480 | if (VBOX_FAILURE(rc))
|
---|
481 | goto out;
|
---|
482 | }
|
---|
483 | }
|
---|
484 | RTMemTmpFree(pvBuf);
|
---|
485 | }
|
---|
486 |
|
---|
487 | out:
|
---|
488 | if (VBOX_SUCCESS(rc) && pfnProgress)
|
---|
489 | pfnProgress(NULL /* WARNING! pVM=NULL */,
|
---|
490 | uPercentStart + uPercentSpan, pvUser);
|
---|
491 |
|
---|
492 | if (VBOX_FAILURE(rc))
|
---|
493 | vdiFreeImage(pImage, rc != VERR_ALREADY_EXISTS);
|
---|
494 | return rc;
|
---|
495 | }
|
---|
496 |
|
---|
497 | /**
|
---|
498 | * Internal: Open a VDI image.
|
---|
499 | */
|
---|
500 | static int vdiOpenImage(PVDIIMAGEDESC pImage, unsigned uOpenFlags)
|
---|
501 | {
|
---|
502 | int rc;
|
---|
503 | RTFILE File;
|
---|
504 |
|
---|
505 | pImage->uOpenFlags = uOpenFlags;
|
---|
506 |
|
---|
507 | /*
|
---|
508 | * Open the image.
|
---|
509 | */
|
---|
510 | rc = RTFileOpen(&File, pImage->pszFilename,
|
---|
511 | uOpenFlags & VD_OPEN_FLAGS_READONLY
|
---|
512 | ? RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE
|
---|
513 | : RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
|
---|
514 | if (VBOX_FAILURE(rc))
|
---|
515 | {
|
---|
516 | /* Do NOT signal an appropriate error here, as the VD layer has the
|
---|
517 | * choice of retrying the open if it failed. */
|
---|
518 | goto out;
|
---|
519 | }
|
---|
520 | pImage->File = File;
|
---|
521 |
|
---|
522 | /* Read pre-header. */
|
---|
523 | rc = RTFileReadAt(File, 0, &pImage->PreHeader, sizeof(pImage->PreHeader),
|
---|
524 | NULL);
|
---|
525 | if (VBOX_FAILURE(rc))
|
---|
526 | {
|
---|
527 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: error reading pre-header in '%s'"), pImage->pszFilename);
|
---|
528 | goto out;
|
---|
529 | }
|
---|
530 | rc = vdiValidatePreHeader(&pImage->PreHeader);
|
---|
531 | if (VBOX_FAILURE(rc))
|
---|
532 | {
|
---|
533 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: invalid pre-header in '%s'"), pImage->pszFilename);
|
---|
534 | goto out;
|
---|
535 | }
|
---|
536 |
|
---|
537 | /* Read header. */
|
---|
538 | pImage->Header.uVersion = pImage->PreHeader.u32Version;
|
---|
539 | switch (GET_MAJOR_HEADER_VERSION(&pImage->Header))
|
---|
540 | {
|
---|
541 | case 0:
|
---|
542 | rc = RTFileReadAt(File, sizeof(pImage->PreHeader),
|
---|
543 | &pImage->Header.u.v0, sizeof(pImage->Header.u.v0),
|
---|
544 | NULL);
|
---|
545 | if (VBOX_FAILURE(rc))
|
---|
546 | {
|
---|
547 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: error reading v0 header in '%s'"), pImage->pszFilename);
|
---|
548 | goto out;
|
---|
549 | }
|
---|
550 | break;
|
---|
551 | case 1:
|
---|
552 | rc = RTFileReadAt(File, sizeof(pImage->PreHeader),
|
---|
553 | &pImage->Header.u.v1, sizeof(pImage->Header.u.v1),
|
---|
554 | NULL);
|
---|
555 | if (VBOX_FAILURE(rc))
|
---|
556 | {
|
---|
557 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: error reading v1 header in '%s'"), pImage->pszFilename);
|
---|
558 | goto out;
|
---|
559 | }
|
---|
560 | /* Convert VDI 1.1 images to VDI 1.1+ on open in read/write mode.
|
---|
561 | * Conversion is harmless, as any VirtualBox version supporting VDI
|
---|
562 | * 1.1 doesn't touch fields it doesn't know about. */
|
---|
563 | if ( !(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
564 | && GET_MINOR_HEADER_VERSION(&pImage->Header) == 1
|
---|
565 | && pImage->Header.u.v1.cbHeader < sizeof(pImage->Header.u.v1plus))
|
---|
566 | {
|
---|
567 | pImage->Header.u.v1plus.cbHeader = sizeof(pImage->Header.u.v1plus);
|
---|
568 | /* Mark LCHS geometry not-calculated. */
|
---|
569 | pImage->Header.u.v1plus.LCHSGeometry.cCylinders = 0;
|
---|
570 | pImage->Header.u.v1plus.LCHSGeometry.cHeads = 0;
|
---|
571 | pImage->Header.u.v1plus.LCHSGeometry.cSectors = 0;
|
---|
572 | pImage->Header.u.v1plus.LCHSGeometry.cbSector = VDI_GEOMETRY_SECTOR_SIZE;
|
---|
573 | }
|
---|
574 | else if (pImage->Header.u.v1.cbHeader >= sizeof(pImage->Header.u.v1plus))
|
---|
575 | {
|
---|
576 | /* Read the actual VDI 1.1+ header completely. */
|
---|
577 | rc = RTFileReadAt(File, sizeof(pImage->PreHeader), &pImage->Header.u.v1plus, sizeof(pImage->Header.u.v1plus), NULL);
|
---|
578 | if (VBOX_FAILURE(rc))
|
---|
579 | {
|
---|
580 | rc = vdiError(pImage, rc, RT_SRC_POS, N_("VDI: error reading v1.1+ header in '%s'"), pImage->pszFilename);
|
---|
581 | goto out;
|
---|
582 | }
|
---|
583 | }
|
---|
584 | break;
|
---|
585 | default:
|
---|
586 | rc = vdiError(pImage, VERR_VDI_UNSUPPORTED_VERSION, RT_SRC_POS, N_("VDI: unsupported major version %u in '%s'"), GET_MAJOR_HEADER_VERSION(&pImage->Header), pImage->pszFilename);
|
---|
587 | goto out;
|
---|
588 | }
|
---|
589 |
|
---|
590 | rc = vdiValidateHeader(&pImage->Header);
|
---|
591 | if (VBOX_FAILURE(rc))
|
---|
592 | {
|
---|
593 | rc = vdiError(pImage, VERR_VDI_UNSUPPORTED_VERSION, RT_SRC_POS, N_("VDI: invalid header in '%s'"), pImage->pszFilename);
|
---|
594 | goto out;
|
---|
595 | }
|
---|
596 |
|
---|
597 | /* Setup image parameters by header. */
|
---|
598 | vdiSetupImageDesc(pImage);
|
---|
599 |
|
---|
600 | /* Allocate memory for blocks array. */
|
---|
601 | pImage->paBlocks = (PVDIIMAGEBLOCKPOINTER)RTMemAlloc(sizeof(VDIIMAGEBLOCKPOINTER) * getImageBlocks(&pImage->Header));
|
---|
602 | if (!pImage->paBlocks)
|
---|
603 | {
|
---|
604 | rc = VERR_NO_MEMORY;
|
---|
605 | goto out;
|
---|
606 | }
|
---|
607 |
|
---|
608 | /* Read blocks array. */
|
---|
609 | rc = RTFileReadAt(pImage->File, pImage->offStartBlocks, pImage->paBlocks,
|
---|
610 | getImageBlocks(&pImage->Header) * sizeof(VDIIMAGEBLOCKPOINTER),
|
---|
611 | NULL);
|
---|
612 |
|
---|
613 | out:
|
---|
614 | if (VBOX_FAILURE(rc))
|
---|
615 | vdiFreeImage(pImage, false);
|
---|
616 | return rc;
|
---|
617 | }
|
---|
618 |
|
---|
619 | /**
|
---|
620 | * Internal: Save header to file.
|
---|
621 | */
|
---|
622 | static int vdiUpdateHeader(PVDIIMAGEDESC pImage)
|
---|
623 | {
|
---|
624 | int rc;
|
---|
625 | switch (GET_MAJOR_HEADER_VERSION(&pImage->Header))
|
---|
626 | {
|
---|
627 | case 0:
|
---|
628 | rc = RTFileWriteAt(pImage->File, sizeof(VDIPREHEADER), &pImage->Header.u.v0, sizeof(pImage->Header.u.v0), NULL);
|
---|
629 | break;
|
---|
630 | case 1:
|
---|
631 | if (pImage->Header.u.v1plus.cbHeader < sizeof(pImage->Header.u.v1plus))
|
---|
632 | rc = RTFileWriteAt(pImage->File, sizeof(VDIPREHEADER), &pImage->Header.u.v1, sizeof(pImage->Header.u.v1), NULL);
|
---|
633 | else
|
---|
634 | rc = RTFileWriteAt(pImage->File, sizeof(VDIPREHEADER), &pImage->Header.u.v1plus, sizeof(pImage->Header.u.v1plus), NULL);
|
---|
635 | break;
|
---|
636 | default:
|
---|
637 | rc = VERR_VDI_UNSUPPORTED_VERSION;
|
---|
638 | break;
|
---|
639 | }
|
---|
640 | AssertMsgRC(rc, ("vdiUpdateHeader failed, filename=\"%s\" rc=%Vrc\n", pImage->pszFilename, rc));
|
---|
641 | return rc;
|
---|
642 | }
|
---|
643 |
|
---|
644 | /**
|
---|
645 | * Internal: Save block pointer to file, save header to file.
|
---|
646 | */
|
---|
647 | static int vdiUpdateBlockInfo(PVDIIMAGEDESC pImage, unsigned uBlock)
|
---|
648 | {
|
---|
649 | /* Update image header. */
|
---|
650 | int rc = vdiUpdateHeader(pImage);
|
---|
651 | if (VBOX_SUCCESS(rc))
|
---|
652 | {
|
---|
653 | /* write only one block pointer. */
|
---|
654 | rc = RTFileWriteAt(pImage->File,
|
---|
655 | pImage->offStartBlocks + uBlock * sizeof(VDIIMAGEBLOCKPOINTER),
|
---|
656 | &pImage->paBlocks[uBlock],
|
---|
657 | sizeof(VDIIMAGEBLOCKPOINTER),
|
---|
658 | NULL);
|
---|
659 | AssertMsgRC(rc, ("vdiUpdateBlockInfo failed to update block=%u, filename=\"%s\", rc=%Vrc\n",
|
---|
660 | uBlock, pImage->pszFilename, rc));
|
---|
661 | }
|
---|
662 | return rc;
|
---|
663 | }
|
---|
664 |
|
---|
665 | /**
|
---|
666 | * Internal: Flush the image file to disk.
|
---|
667 | */
|
---|
668 | static void vdiFlushImage(PVDIIMAGEDESC pImage)
|
---|
669 | {
|
---|
670 | if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
|
---|
671 | {
|
---|
672 | /* Save header. */
|
---|
673 | int rc = vdiUpdateHeader(pImage);
|
---|
674 | AssertMsgRC(rc, ("vdiUpdateHeader() failed, filename=\"%s\", rc=%Vrc\n",
|
---|
675 | pImage->pszFilename, rc));
|
---|
676 | RTFileFlush(pImage->File);
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 | /**
|
---|
681 | * Internal: Free all allocated space for representing an image, and optionally
|
---|
682 | * delete the image from disk.
|
---|
683 | */
|
---|
684 | static void vdiFreeImage(PVDIIMAGEDESC pImage, bool fDelete)
|
---|
685 | {
|
---|
686 | Assert(pImage);
|
---|
687 |
|
---|
688 | vdiFlushImage(pImage);
|
---|
689 | if (pImage->File != NIL_RTFILE)
|
---|
690 | {
|
---|
691 | RTFileClose(pImage->File);
|
---|
692 | pImage->File = NIL_RTFILE;
|
---|
693 | }
|
---|
694 | if (pImage->paBlocks)
|
---|
695 | {
|
---|
696 | RTMemFree(pImage->paBlocks);
|
---|
697 | pImage->paBlocks = NULL;
|
---|
698 | }
|
---|
699 | if (fDelete && pImage->pszFilename)
|
---|
700 | RTFileDelete(pImage->pszFilename);
|
---|
701 | }
|
---|
702 |
|
---|
703 |
|
---|
704 | /** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
|
---|
705 | static int vdiCheckIfValid(const char *pszFilename)
|
---|
706 | {
|
---|
707 | LogFlowFunc(("pszFilename=\"%s\"\n", pszFilename));
|
---|
708 | int rc = VINF_SUCCESS;
|
---|
709 | PVDIIMAGEDESC pImage;
|
---|
710 |
|
---|
711 | if ( !pszFilename
|
---|
712 | || !*pszFilename)
|
---|
713 | {
|
---|
714 | rc = VERR_INVALID_PARAMETER;
|
---|
715 | goto out;
|
---|
716 | }
|
---|
717 |
|
---|
718 | pImage = (PVDIIMAGEDESC)RTMemAllocZ(sizeof(VDIIMAGEDESC));
|
---|
719 | if (!pImage)
|
---|
720 | {
|
---|
721 | rc = VERR_NO_MEMORY;
|
---|
722 | goto out;
|
---|
723 | }
|
---|
724 | pImage->pszFilename = pszFilename;
|
---|
725 |
|
---|
726 | rc = vdiOpenImage(pImage, VD_OPEN_FLAGS_INFO | VD_OPEN_FLAGS_READONLY);
|
---|
727 | vdiFreeImage(pImage, false);
|
---|
728 |
|
---|
729 | out:
|
---|
730 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
731 | return rc;
|
---|
732 | }
|
---|
733 |
|
---|
734 | /** @copydoc VBOXHDDBACKEND::pfnOpen */
|
---|
735 | static int vdiOpen(const char *pszFilename, unsigned uOpenFlags,
|
---|
736 | PFNVDERROR pfnError, void *pvErrorUser,
|
---|
737 | void **ppBackendData)
|
---|
738 | {
|
---|
739 | LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x ppBackendData=%#p\n", pszFilename, uOpenFlags, ppBackendData));
|
---|
740 | int rc;
|
---|
741 | PVDIIMAGEDESC pImage;
|
---|
742 |
|
---|
743 | /* Check open flags. All valid flags are supported. */
|
---|
744 | if (uOpenFlags & ~VD_OPEN_FLAGS_MASK)
|
---|
745 | {
|
---|
746 | rc = VERR_INVALID_PARAMETER;
|
---|
747 | goto out;
|
---|
748 | }
|
---|
749 |
|
---|
750 | /* Check remaining arguments. */
|
---|
751 | if ( !VALID_PTR(pszFilename)
|
---|
752 | || !*pszFilename)
|
---|
753 | {
|
---|
754 | rc = VERR_INVALID_PARAMETER;
|
---|
755 | goto out;
|
---|
756 | }
|
---|
757 |
|
---|
758 | pImage = (PVDIIMAGEDESC)RTMemAllocZ(sizeof(VDIIMAGEDESC));
|
---|
759 | if (!pImage)
|
---|
760 | {
|
---|
761 | rc = VERR_NO_MEMORY;
|
---|
762 | goto out;
|
---|
763 | }
|
---|
764 | pImage->pszFilename = pszFilename;
|
---|
765 | pImage->paBlocks = NULL;
|
---|
766 | pImage->pfnError = pfnError;
|
---|
767 | pImage->pvErrorUser = pvErrorUser;
|
---|
768 |
|
---|
769 | rc = vdiOpenImage(pImage, uOpenFlags);
|
---|
770 | if (VBOX_SUCCESS(rc))
|
---|
771 | *ppBackendData = pImage;
|
---|
772 |
|
---|
773 | out:
|
---|
774 | LogFlowFunc(("returns %Vrc (pBackendData=%#p)\n", rc, *ppBackendData));
|
---|
775 | return rc;
|
---|
776 | }
|
---|
777 |
|
---|
778 | /** @copydoc VBOXHDDBACKEND::pfnCreate */
|
---|
779 | static int vdiCreate(const char *pszFilename, VDIMAGETYPE enmType,
|
---|
780 | uint64_t cbSize, unsigned uImageFlags,
|
---|
781 | const char *pszComment,
|
---|
782 | PCPDMMEDIAGEOMETRY pPCHSGeometry,
|
---|
783 | PCPDMMEDIAGEOMETRY pLCHSGeometry,
|
---|
784 | unsigned uOpenFlags, PFNVMPROGRESS pfnProgress,
|
---|
785 | void *pvUser, unsigned uPercentStart,
|
---|
786 | unsigned uPercentSpan, PFNVDERROR pfnError,
|
---|
787 | void *pvErrorUser, void **ppBackendData)
|
---|
788 | {
|
---|
789 | LogFlowFunc(("pszFilename=\"%s\" enmType=%d cbSize=%llu uImageFlags=%#x pszComment=\"%s\" pPCHSGeometry=%#p pLCHSGeometry=%#p uOpenFlags=%#x pfnProgress=%#p pvUser=%#p uPercentStart=%u uPercentSpan=%u pfnError=%#p pvErrorUser=%#p ppBackendData=%#p", pszFilename, enmType, cbSize, uImageFlags, pszComment, pPCHSGeometry, pLCHSGeometry, uOpenFlags, pfnProgress, pvUser, uPercentStart, uPercentSpan, pfnError, pvErrorUser, ppBackendData));
|
---|
790 | int rc;
|
---|
791 | PVDIIMAGEDESC pImage;
|
---|
792 |
|
---|
793 | /* Check open flags. All valid flags are supported. */
|
---|
794 | if (uOpenFlags & ~VD_OPEN_FLAGS_MASK)
|
---|
795 | {
|
---|
796 | rc = VERR_INVALID_PARAMETER;
|
---|
797 | goto out;
|
---|
798 | }
|
---|
799 |
|
---|
800 | /* Check remaining arguments. */
|
---|
801 | if ( !pszFilename
|
---|
802 | || !*pszFilename
|
---|
803 | || (enmType != VD_IMAGE_TYPE_NORMAL && enmType != VD_IMAGE_TYPE_FIXED)
|
---|
804 | || cbSize < VDI_IMAGE_DEFAULT_BLOCK_SIZE
|
---|
805 | || !VALID_PTR(pPCHSGeometry)
|
---|
806 | || !VALID_PTR(pLCHSGeometry))
|
---|
807 | {
|
---|
808 | rc = VERR_INVALID_PARAMETER;
|
---|
809 | goto out;
|
---|
810 | }
|
---|
811 |
|
---|
812 | pImage = (PVDIIMAGEDESC)RTMemAllocZ(sizeof(VDIIMAGEDESC));
|
---|
813 | if (!pImage)
|
---|
814 | {
|
---|
815 | rc = VERR_NO_MEMORY;
|
---|
816 | goto out;
|
---|
817 | }
|
---|
818 | pImage->pszFilename = pszFilename;
|
---|
819 | pImage->paBlocks = NULL;
|
---|
820 | pImage->pfnError = pfnError;
|
---|
821 | pImage->pvErrorUser = pvErrorUser;
|
---|
822 |
|
---|
823 | rc = vdiCreateImage(pImage, enmType, cbSize, uImageFlags, pszComment,
|
---|
824 | pPCHSGeometry, pLCHSGeometry,
|
---|
825 | pfnProgress, pvUser, uPercentStart, uPercentSpan);
|
---|
826 | if (VBOX_SUCCESS(rc))
|
---|
827 | {
|
---|
828 | /* So far the image is opened in read/write mode. Make sure the
|
---|
829 | * image is opened in read-only mode if the caller requested that. */
|
---|
830 | if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
831 | {
|
---|
832 | vdiFreeImage(pImage, false);
|
---|
833 | rc = vdiOpenImage(pImage, uOpenFlags);
|
---|
834 | if (VBOX_FAILURE(rc))
|
---|
835 | goto out;
|
---|
836 | }
|
---|
837 | *ppBackendData = pImage;
|
---|
838 | }
|
---|
839 |
|
---|
840 | out:
|
---|
841 | LogFlowFunc(("returns %Vrc (pBackendData=%#p)\n", rc, *ppBackendData));
|
---|
842 | return rc;
|
---|
843 | }
|
---|
844 |
|
---|
845 | /** @copydoc VBOXHDDBACKEND::pfnRename */
|
---|
846 | static int vdiRename(void *pBackendData, const char *pszFilename)
|
---|
847 | {
|
---|
848 | LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
|
---|
849 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
850 |
|
---|
851 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
852 | return rc;
|
---|
853 | }
|
---|
854 |
|
---|
855 | /** @copydoc VBOXHDDBACKEND::pfnClose */
|
---|
856 | static int vdiClose(void *pBackendData, bool fDelete)
|
---|
857 | {
|
---|
858 | LogFlowFunc(("pBackendData=%#p fDelete=%d\n", pBackendData, fDelete));
|
---|
859 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
860 | int rc = VINF_SUCCESS;
|
---|
861 |
|
---|
862 | /* Freeing a never allocated image (e.g. because the open failed) is
|
---|
863 | * not signalled as an error. After all nothing bad happens. */
|
---|
864 | if (pImage)
|
---|
865 | vdiFreeImage(pImage, fDelete);
|
---|
866 |
|
---|
867 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
868 | return rc;
|
---|
869 | }
|
---|
870 |
|
---|
871 | /** @copydoc VBOXHDDBACKEND::pfnRead */
|
---|
872 | static int vdiRead(void *pBackendData, uint64_t uOffset, void *pvBuf,
|
---|
873 | size_t cbToRead, size_t *pcbActuallyRead)
|
---|
874 | {
|
---|
875 | LogFlowFunc(("pBackendData=%#p uOffset=%llu pvBuf=%#p cbToRead=%zu pcbActuallyRead=%#p\n", pBackendData, uOffset, pvBuf, cbToRead, pcbActuallyRead));
|
---|
876 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
877 | unsigned uBlock;
|
---|
878 | unsigned offRead;
|
---|
879 | int rc;
|
---|
880 |
|
---|
881 | Assert(pImage);
|
---|
882 | Assert(uOffset % 512 == 0);
|
---|
883 | Assert(cbToRead % 512 == 0);
|
---|
884 |
|
---|
885 | if ( uOffset + cbToRead > getImageDiskSize(&pImage->Header)
|
---|
886 | || cbToRead == 0)
|
---|
887 | {
|
---|
888 | rc = VERR_INVALID_PARAMETER;
|
---|
889 | goto out;
|
---|
890 | }
|
---|
891 |
|
---|
892 | /* Calculate starting block number and offset inside it. */
|
---|
893 | uBlock = (unsigned)(uOffset >> pImage->uShiftOffset2Index);
|
---|
894 | offRead = (unsigned)uOffset & pImage->uBlockMask;
|
---|
895 |
|
---|
896 | /* Clip read range to at most the rest of the block. */
|
---|
897 | cbToRead = RT_MIN(cbToRead, getImageBlockSize(&pImage->Header) - offRead);
|
---|
898 | Assert(!(cbToRead % 512));
|
---|
899 |
|
---|
900 | if (pImage->paBlocks[uBlock] == VDI_IMAGE_BLOCK_FREE)
|
---|
901 | rc = VERR_VDI_BLOCK_FREE;
|
---|
902 | else if (pImage->paBlocks[uBlock] == VDI_IMAGE_BLOCK_ZERO)
|
---|
903 | {
|
---|
904 | memset(pvBuf, 0, cbToRead);
|
---|
905 | rc = VINF_SUCCESS;
|
---|
906 | }
|
---|
907 | else
|
---|
908 | {
|
---|
909 | /* block present in image file */
|
---|
910 | uint64_t u64Offset = ((uint64_t)pImage->paBlocks[uBlock] << pImage->uShiftIndex2Offset)
|
---|
911 | + (pImage->offStartData + pImage->offStartBlockData + offRead);
|
---|
912 | rc = RTFileReadAt(pImage->File, u64Offset, pvBuf, cbToRead, NULL);
|
---|
913 | }
|
---|
914 |
|
---|
915 | if (VBOX_SUCCESS(rc))
|
---|
916 | *pcbActuallyRead = cbToRead;
|
---|
917 |
|
---|
918 | out:
|
---|
919 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
920 | return rc;
|
---|
921 | }
|
---|
922 |
|
---|
923 | /**@copydoc VBOXHDDBACKEND::pfnWrite */
|
---|
924 | static int vdiWrite(void *pBackendData, uint64_t uOffset, const void *pvBuf,
|
---|
925 | size_t cbToWrite, size_t *pcbWriteProcess,
|
---|
926 | size_t *pcbPreRead, size_t *pcbPostRead)
|
---|
927 | {
|
---|
928 | LogFlowFunc(("pBackendData=%#p uOffset=%llu pvBuf=%#p cbToWrite=%zu pcbWriteProcess=%#p pcbPreRead=%#p pcbPostRead=%#p\n", pBackendData, uOffset, pvBuf, cbToWrite, pcbWriteProcess, pcbPreRead, pcbPostRead));
|
---|
929 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
930 | unsigned uBlock;
|
---|
931 | unsigned offWrite;
|
---|
932 | int rc = VINF_SUCCESS;
|
---|
933 |
|
---|
934 | Assert(pImage);
|
---|
935 | Assert(uOffset % 512 == 0);
|
---|
936 | Assert(cbToWrite % 512 == 0);
|
---|
937 |
|
---|
938 | if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
939 | {
|
---|
940 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
941 | goto out;
|
---|
942 | }
|
---|
943 |
|
---|
944 | if (cbToWrite == 0)
|
---|
945 | {
|
---|
946 | rc = VERR_INVALID_PARAMETER;
|
---|
947 | goto out;
|
---|
948 | }
|
---|
949 |
|
---|
950 | /* No size check here, will do that later. For dynamic images which are
|
---|
951 | * not multiples of the block size in length, this would prevent writing to
|
---|
952 | * the last grain. */
|
---|
953 |
|
---|
954 | /* Calculate starting block number and offset inside it. */
|
---|
955 | uBlock = (unsigned)(uOffset >> pImage->uShiftOffset2Index);
|
---|
956 | offWrite = (unsigned)uOffset & pImage->uBlockMask;
|
---|
957 |
|
---|
958 | /* Clip write range to at most the rest of the block. */
|
---|
959 | cbToWrite = RT_MIN(cbToWrite, getImageBlockSize(&pImage->Header) - offWrite);
|
---|
960 | Assert(!(cbToWrite % 512));
|
---|
961 |
|
---|
962 | if (!IS_VDI_IMAGE_BLOCK_ALLOCATED(pImage->paBlocks[uBlock]))
|
---|
963 | {
|
---|
964 | /* Block is either free or zero. */
|
---|
965 | if ( !(pImage->uOpenFlags & VD_OPEN_FLAGS_HONOR_ZEROES)
|
---|
966 | && ( pImage->paBlocks[uBlock] == VDI_IMAGE_BLOCK_ZERO
|
---|
967 | || cbToWrite == getImageBlockSize(&pImage->Header)))
|
---|
968 | {
|
---|
969 | /* If the destination block is unallocated at this point, it's
|
---|
970 | * either a zero block or a block which hasn't been used so far
|
---|
971 | * (which also means that it's a zero block. Don't need to write
|
---|
972 | * anything to this block if the data consists of just zeroes. */
|
---|
973 | Assert(cbToWrite % 4 == 0);
|
---|
974 | Assert(cbToWrite * 8 <= UINT32_MAX);
|
---|
975 | if (ASMBitFirstSet((volatile void *)pvBuf, (uint32_t)cbToWrite * 8) == -1)
|
---|
976 | {
|
---|
977 | pImage->paBlocks[uBlock] = VDI_IMAGE_BLOCK_ZERO;
|
---|
978 | goto out;
|
---|
979 | }
|
---|
980 | }
|
---|
981 |
|
---|
982 | if (cbToWrite == getImageBlockSize(&pImage->Header))
|
---|
983 | {
|
---|
984 | /* Full block write to previously unallocated block.
|
---|
985 | * Allocate block and write data. */
|
---|
986 | unsigned cBlocksAllocated = getImageBlocksAllocated(&pImage->Header);
|
---|
987 | rc = RTFileWriteAt(pImage->File,
|
---|
988 | ((uint64_t)cBlocksAllocated << pImage->uShiftIndex2Offset)
|
---|
989 | + pImage->offStartData,
|
---|
990 | pvBuf, cbToWrite, NULL);
|
---|
991 | if (VBOX_FAILURE(rc))
|
---|
992 | goto out;
|
---|
993 | pImage->paBlocks[uBlock] = cBlocksAllocated;
|
---|
994 | setImageBlocksAllocated(&pImage->Header, cBlocksAllocated + 1);
|
---|
995 |
|
---|
996 | rc = vdiUpdateBlockInfo(pImage, uBlock);
|
---|
997 | if (VBOX_FAILURE(rc))
|
---|
998 | goto out;
|
---|
999 |
|
---|
1000 | *pcbPreRead = 0;
|
---|
1001 | *pcbPostRead = 0;
|
---|
1002 | }
|
---|
1003 | else
|
---|
1004 | {
|
---|
1005 | /* Trying to do a partial write to an unallocated block. Don't do
|
---|
1006 | * anything except letting the upper layer know what to do. */
|
---|
1007 | *pcbPreRead = offWrite % getImageBlockSize(&pImage->Header);
|
---|
1008 | *pcbPostRead = getImageBlockSize(&pImage->Header) - cbToWrite - *pcbPreRead;
|
---|
1009 | rc = VERR_VDI_BLOCK_FREE;
|
---|
1010 | }
|
---|
1011 | }
|
---|
1012 | else
|
---|
1013 | rc = RTFileWriteAt(pImage->File,
|
---|
1014 | ((uint64_t)pImage->paBlocks[uBlock] << pImage->uShiftIndex2Offset)
|
---|
1015 | + pImage->offStartData + pImage->offStartBlockData + offWrite,
|
---|
1016 | pvBuf, cbToWrite, NULL);
|
---|
1017 |
|
---|
1018 | out:
|
---|
1019 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1020 | return rc;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | /** @copydoc VBOXHDDBACKEND::pfnFlush */
|
---|
1024 | static int vdiFlush(void *pBackendData)
|
---|
1025 | {
|
---|
1026 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
1027 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1028 | int rc = VINF_SUCCESS;
|
---|
1029 |
|
---|
1030 | vdiFlushImage(pImage);
|
---|
1031 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1032 | return rc;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | /** @copydoc VBOXHDDBACKEND::pfnGetVersion */
|
---|
1036 | static unsigned vdiGetVersion(void *pBackendData)
|
---|
1037 | {
|
---|
1038 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
1039 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1040 | unsigned uVersion;
|
---|
1041 |
|
---|
1042 | Assert(pImage);
|
---|
1043 |
|
---|
1044 | if (pImage)
|
---|
1045 | uVersion = pImage->PreHeader.u32Version;
|
---|
1046 | else
|
---|
1047 | uVersion = 0;
|
---|
1048 |
|
---|
1049 | LogFlowFunc(("returns %#x\n", uVersion));
|
---|
1050 | return uVersion;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | /** @copydoc VBOXHDDBACKEND::pfnGetImageType */
|
---|
1054 | static int vdiGetImageType(void *pBackendData, PVDIMAGETYPE penmImageType)
|
---|
1055 | {
|
---|
1056 | LogFlowFunc(("pBackendData=%#p penmImageType=%#p\n", pBackendData, penmImageType));
|
---|
1057 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1058 | int rc = VINF_SUCCESS;
|
---|
1059 |
|
---|
1060 | Assert(pImage);
|
---|
1061 | Assert(penmImageType);
|
---|
1062 |
|
---|
1063 | if (pImage)
|
---|
1064 | *penmImageType = getImageType(&pImage->Header) == VDI_IMAGE_TYPE_NORMAL
|
---|
1065 | ? VD_IMAGE_TYPE_NORMAL
|
---|
1066 | : VD_IMAGE_TYPE_DIFF;
|
---|
1067 | else
|
---|
1068 | rc = VERR_VDI_NOT_OPENED;
|
---|
1069 |
|
---|
1070 | LogFlowFunc(("returns %Vrc enmImageType=%u\n", rc, *penmImageType));
|
---|
1071 | return rc;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | /** @copydoc VBOXHDDBACKEND::pfnGetSize */
|
---|
1075 | static uint64_t vdiGetSize(void *pBackendData)
|
---|
1076 | {
|
---|
1077 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
1078 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1079 | uint64_t cbSize;
|
---|
1080 |
|
---|
1081 | Assert(pImage);
|
---|
1082 |
|
---|
1083 | if (pImage)
|
---|
1084 | cbSize = getImageDiskSize(&pImage->Header);
|
---|
1085 | else
|
---|
1086 | cbSize = 0;
|
---|
1087 |
|
---|
1088 | LogFlowFunc(("returns %llu\n", cbSize));
|
---|
1089 | return cbSize;
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | /** @copydoc VBOXHDDBACKEND::pfnGetFileSize */
|
---|
1093 | static uint64_t vdiGetFileSize(void *pBackendData)
|
---|
1094 | {
|
---|
1095 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
1096 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1097 | uint64_t cb = 0;
|
---|
1098 |
|
---|
1099 | Assert(pImage);
|
---|
1100 |
|
---|
1101 | if (pImage)
|
---|
1102 | {
|
---|
1103 | uint64_t cbFile;
|
---|
1104 | if (pImage->File != NIL_RTFILE)
|
---|
1105 | {
|
---|
1106 | int rc = RTFileGetSize(pImage->File, &cbFile);
|
---|
1107 | if (VBOX_SUCCESS(rc))
|
---|
1108 | cb += cbFile;
|
---|
1109 | }
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | LogFlowFunc(("returns %lld\n", cb));
|
---|
1113 | return cb;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | /** @copydoc VBOXHDDBACKEND::pfnGetPCHSGeometry */
|
---|
1117 | static int vdiGetPCHSGeometry(void *pBackendData,
|
---|
1118 | PPDMMEDIAGEOMETRY pPCHSGeometry)
|
---|
1119 | {
|
---|
1120 | LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p\n", pBackendData, pPCHSGeometry));
|
---|
1121 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1122 | int rc;
|
---|
1123 |
|
---|
1124 | Assert(pImage);
|
---|
1125 |
|
---|
1126 | if (pImage)
|
---|
1127 | {
|
---|
1128 | if (pImage->PCHSGeometry.cCylinders)
|
---|
1129 | {
|
---|
1130 | *pPCHSGeometry = pImage->PCHSGeometry;
|
---|
1131 | rc = VINF_SUCCESS;
|
---|
1132 | }
|
---|
1133 | else
|
---|
1134 | rc = VERR_VDI_GEOMETRY_NOT_SET;
|
---|
1135 | }
|
---|
1136 | else
|
---|
1137 | rc = VERR_VDI_NOT_OPENED;
|
---|
1138 |
|
---|
1139 | LogFlowFunc(("returns %Vrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
|
---|
1140 | return rc;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | /** @copydoc VBOXHDDBACKEND::pfnSetPCHSGeometry */
|
---|
1144 | static int vdiSetPCHSGeometry(void *pBackendData,
|
---|
1145 | PCPDMMEDIAGEOMETRY pPCHSGeometry)
|
---|
1146 | {
|
---|
1147 | LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n", pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
|
---|
1148 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1149 | int rc;
|
---|
1150 |
|
---|
1151 | Assert(pImage);
|
---|
1152 |
|
---|
1153 | if (pImage)
|
---|
1154 | {
|
---|
1155 | if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
1156 | {
|
---|
1157 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
1158 | goto out;
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | pImage->PCHSGeometry = *pPCHSGeometry;
|
---|
1162 | rc = VINF_SUCCESS;
|
---|
1163 | }
|
---|
1164 | else
|
---|
1165 | rc = VERR_VDI_NOT_OPENED;
|
---|
1166 |
|
---|
1167 | out:
|
---|
1168 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1169 | return rc;
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | /** @copydoc VBOXHDDBACKEND::pfnGetLCHSGeometry */
|
---|
1173 | static int vdiGetLCHSGeometry(void *pBackendData,
|
---|
1174 | PPDMMEDIAGEOMETRY pLCHSGeometry)
|
---|
1175 | {
|
---|
1176 | LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
|
---|
1177 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1178 | int rc;
|
---|
1179 |
|
---|
1180 | Assert(pImage);
|
---|
1181 |
|
---|
1182 | if (pImage)
|
---|
1183 | {
|
---|
1184 | VDIDISKGEOMETRY DummyGeo = { 0, 0, 0, VDI_GEOMETRY_SECTOR_SIZE };
|
---|
1185 | PVDIDISKGEOMETRY pGeometry = getImageLCHSGeometry(&pImage->Header);
|
---|
1186 | if (!pGeometry)
|
---|
1187 | pGeometry = &DummyGeo;
|
---|
1188 |
|
---|
1189 | if ( pGeometry->cCylinders > 0
|
---|
1190 | && pGeometry->cHeads > 0
|
---|
1191 | && pGeometry->cSectors > 0)
|
---|
1192 | {
|
---|
1193 | pLCHSGeometry->cCylinders = pGeometry->cCylinders;
|
---|
1194 | pLCHSGeometry->cHeads = pGeometry->cHeads;
|
---|
1195 | pLCHSGeometry->cSectors = pGeometry->cSectors;
|
---|
1196 | rc = VINF_SUCCESS;
|
---|
1197 | }
|
---|
1198 | else
|
---|
1199 | rc = VERR_VDI_GEOMETRY_NOT_SET;
|
---|
1200 | }
|
---|
1201 | else
|
---|
1202 | rc = VERR_VDI_NOT_OPENED;
|
---|
1203 |
|
---|
1204 | LogFlowFunc(("returns %Vrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
|
---|
1205 | return rc;
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | /** @copydoc VBOXHDDBACKEND::pfnSetLCHSGeometry */
|
---|
1209 | static int vdiSetLCHSGeometry(void *pBackendData,
|
---|
1210 | PCPDMMEDIAGEOMETRY pLCHSGeometry)
|
---|
1211 | {
|
---|
1212 | LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n", pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
|
---|
1213 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1214 | PVDIDISKGEOMETRY pGeometry;
|
---|
1215 | int rc;
|
---|
1216 |
|
---|
1217 | Assert(pImage);
|
---|
1218 |
|
---|
1219 | if (pImage)
|
---|
1220 | {
|
---|
1221 | if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
1222 | {
|
---|
1223 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
1224 | goto out;
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | pGeometry = getImageLCHSGeometry(&pImage->Header);
|
---|
1228 | if (pGeometry)
|
---|
1229 | {
|
---|
1230 | pGeometry->cCylinders = pLCHSGeometry->cCylinders;
|
---|
1231 | pGeometry->cHeads = pLCHSGeometry->cHeads;
|
---|
1232 | pGeometry->cSectors = pLCHSGeometry->cSectors;
|
---|
1233 | pGeometry->cbSector = VDI_GEOMETRY_SECTOR_SIZE;
|
---|
1234 |
|
---|
1235 | /* Update header information in base image file. */
|
---|
1236 | vdiFlushImage(pImage);
|
---|
1237 | }
|
---|
1238 | rc = VINF_SUCCESS;
|
---|
1239 | }
|
---|
1240 | else
|
---|
1241 | rc = VERR_VDI_NOT_OPENED;
|
---|
1242 |
|
---|
1243 | out:
|
---|
1244 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1245 | return rc;
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | /** @copydoc VBOXHDDBACKEND::pfnGetImageFlags */
|
---|
1249 | static unsigned vdiGetImageFlags(void *pBackendData)
|
---|
1250 | {
|
---|
1251 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
1252 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1253 | unsigned uImageFlags;
|
---|
1254 |
|
---|
1255 | Assert(pImage);
|
---|
1256 |
|
---|
1257 | if (pImage)
|
---|
1258 | uImageFlags = getImageFlags(&pImage->Header);
|
---|
1259 | else
|
---|
1260 | uImageFlags = 0;
|
---|
1261 |
|
---|
1262 | LogFlowFunc(("returns %#x\n", uImageFlags));
|
---|
1263 | return uImageFlags;
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | /** @copydoc VBOXHDDBACKEND::pfnGetOpenFlags */
|
---|
1267 | static unsigned vdiGetOpenFlags(void *pBackendData)
|
---|
1268 | {
|
---|
1269 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
1270 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1271 | unsigned uOpenFlags;
|
---|
1272 |
|
---|
1273 | Assert(pImage);
|
---|
1274 |
|
---|
1275 | if (pImage)
|
---|
1276 | uOpenFlags = pImage->uOpenFlags;
|
---|
1277 | else
|
---|
1278 | uOpenFlags = 0;
|
---|
1279 |
|
---|
1280 | LogFlowFunc(("returns %#x\n", uOpenFlags));
|
---|
1281 | return uOpenFlags;
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | /** @copydoc VBOXHDDBACKEND::pfnSetOpenFlags */
|
---|
1285 | static int vdiSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
|
---|
1286 | {
|
---|
1287 | LogFlowFunc(("pBackendData=%#p\n uOpenFlags=%#x", pBackendData, uOpenFlags));
|
---|
1288 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1289 | int rc;
|
---|
1290 | const char *pszFilename;
|
---|
1291 |
|
---|
1292 | /* Image must be opened and the new flags must be valid. Just readonly flag
|
---|
1293 | * is supported. */
|
---|
1294 | if (!pImage || uOpenFlags & ~VD_OPEN_FLAGS_READONLY)
|
---|
1295 | {
|
---|
1296 | rc = VERR_INVALID_PARAMETER;
|
---|
1297 | goto out;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | /* Implement this operation via reopening the image. */
|
---|
1301 | pszFilename = pImage->pszFilename;
|
---|
1302 | vdiFreeImage(pImage, false);
|
---|
1303 | rc = vdiOpenImage(pImage, uOpenFlags);
|
---|
1304 |
|
---|
1305 | out:
|
---|
1306 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1307 | return rc;
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | /** @copydoc VBOXHDDBACKEND::pfnGetComment */
|
---|
1311 | static int vdiGetComment(void *pBackendData, char *pszComment,
|
---|
1312 | size_t cbComment)
|
---|
1313 | {
|
---|
1314 | LogFlowFunc(("pBackendData=%#p pszComment=%#p cbComment=%zu\n", pBackendData, pszComment, cbComment));
|
---|
1315 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1316 | int rc = VINF_SUCCESS;
|
---|
1317 |
|
---|
1318 | Assert(pImage);
|
---|
1319 |
|
---|
1320 | if (pImage)
|
---|
1321 | {
|
---|
1322 | char *pszTmp = getImageComment(&pImage->Header);
|
---|
1323 | unsigned cb = strlen(pszTmp);
|
---|
1324 | if (cb < cbComment)
|
---|
1325 | {
|
---|
1326 | /* memcpy is much better than strncpy. */
|
---|
1327 | memcpy(pszComment, pszTmp, cb + 1);
|
---|
1328 | }
|
---|
1329 | else
|
---|
1330 | rc = VERR_BUFFER_OVERFLOW;
|
---|
1331 | }
|
---|
1332 | else
|
---|
1333 | rc = VERR_VDI_NOT_OPENED;
|
---|
1334 |
|
---|
1335 | LogFlowFunc(("returns %Vrc comment=\"%s\"\n", rc, pszComment));
|
---|
1336 | return rc;
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | /** @copydoc VBOXHDDBACKEND::pfnGetComment */
|
---|
1340 | static int vdiSetComment(void *pBackendData, const char *pszComment)
|
---|
1341 | {
|
---|
1342 | LogFlowFunc(("pBackendData=%#p pszComment=\"%s\"\n", pBackendData, pszComment));
|
---|
1343 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1344 | int rc;
|
---|
1345 |
|
---|
1346 | Assert(pImage);
|
---|
1347 |
|
---|
1348 | if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
1349 | {
|
---|
1350 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
1351 | goto out;
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | if (pImage)
|
---|
1355 | {
|
---|
1356 | size_t cchComment = pszComment ? strlen(pszComment) : 0;
|
---|
1357 | if (cchComment >= VDI_IMAGE_COMMENT_SIZE)
|
---|
1358 | {
|
---|
1359 | LogFunc(("pszComment is too long, %d bytes!\n", cchComment));
|
---|
1360 | rc = VERR_VDI_COMMENT_TOO_LONG;
|
---|
1361 | goto out;
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 | /* we don't support old style images */
|
---|
1365 | if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 1)
|
---|
1366 | {
|
---|
1367 | /*
|
---|
1368 | * Update the comment field, making sure to zero out all of the previous comment.
|
---|
1369 | */
|
---|
1370 | memset(pImage->Header.u.v1.szComment, '\0', VDI_IMAGE_COMMENT_SIZE);
|
---|
1371 | memcpy(pImage->Header.u.v1.szComment, pszComment, cchComment);
|
---|
1372 |
|
---|
1373 | /* write out new the header */
|
---|
1374 | rc = vdiUpdateHeader(pImage);
|
---|
1375 | }
|
---|
1376 | else
|
---|
1377 | rc = VERR_VDI_UNSUPPORTED_VERSION;
|
---|
1378 | }
|
---|
1379 | else
|
---|
1380 | rc = VERR_VDI_NOT_OPENED;
|
---|
1381 |
|
---|
1382 | out:
|
---|
1383 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1384 | return rc;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | /** @copydoc VBOXHDDBACKEND::pfnGetUuid */
|
---|
1388 | static int vdiGetUuid(void *pBackendData, PRTUUID pUuid)
|
---|
1389 | {
|
---|
1390 | LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
|
---|
1391 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1392 | int rc;
|
---|
1393 |
|
---|
1394 | Assert(pImage);
|
---|
1395 |
|
---|
1396 | if (pImage)
|
---|
1397 | {
|
---|
1398 | *pUuid = *getImageCreationUUID(&pImage->Header);
|
---|
1399 | rc = VINF_SUCCESS;
|
---|
1400 | }
|
---|
1401 | else
|
---|
1402 | rc = VERR_VDI_NOT_OPENED;
|
---|
1403 |
|
---|
1404 | LogFlowFunc(("returns %Vrc (%Vuuid)\n", rc, pUuid));
|
---|
1405 | return rc;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | /** @copydoc VBOXHDDBACKEND::pfnSetUuid */
|
---|
1409 | static int vdiSetUuid(void *pBackendData, PCRTUUID pUuid)
|
---|
1410 | {
|
---|
1411 | LogFlowFunc(("pBackendData=%#p Uuid=%Vuuid\n", pBackendData, pUuid));
|
---|
1412 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1413 | int rc = VINF_SUCCESS;
|
---|
1414 |
|
---|
1415 | Assert(pImage);
|
---|
1416 |
|
---|
1417 | if (pImage)
|
---|
1418 | {
|
---|
1419 | if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
|
---|
1420 | {
|
---|
1421 | if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 1)
|
---|
1422 | pImage->Header.u.v1.uuidCreate = *pUuid;
|
---|
1423 | /* Make it possible to clone old VDIs. */
|
---|
1424 | else if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 0)
|
---|
1425 | pImage->Header.u.v0.uuidCreate = *pUuid;
|
---|
1426 | else
|
---|
1427 | {
|
---|
1428 | LogFunc(("Version is not supported!\n"));
|
---|
1429 | rc = VERR_VDI_UNSUPPORTED_VERSION;
|
---|
1430 | }
|
---|
1431 | }
|
---|
1432 | else
|
---|
1433 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
1434 | }
|
---|
1435 | else
|
---|
1436 | rc = VERR_VDI_NOT_OPENED;
|
---|
1437 |
|
---|
1438 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1439 | return rc;
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 | /** @copydoc VBOXHDDBACKEND::pfnGetModificationUuid */
|
---|
1443 | static int vdiGetModificationUuid(void *pBackendData, PRTUUID pUuid)
|
---|
1444 | {
|
---|
1445 | LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
|
---|
1446 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1447 | int rc;
|
---|
1448 |
|
---|
1449 | Assert(pImage);
|
---|
1450 |
|
---|
1451 | if (pImage)
|
---|
1452 | {
|
---|
1453 | *pUuid = *getImageModificationUUID(&pImage->Header);
|
---|
1454 | rc = VINF_SUCCESS;
|
---|
1455 | }
|
---|
1456 | else
|
---|
1457 | rc = VERR_VDI_NOT_OPENED;
|
---|
1458 |
|
---|
1459 | LogFlowFunc(("returns %Vrc (%Vuuid)\n", rc, pUuid));
|
---|
1460 | return rc;
|
---|
1461 | }
|
---|
1462 |
|
---|
1463 | /** @copydoc VBOXHDDBACKEND::pfnSetModificationUuid */
|
---|
1464 | static int vdiSetModificationUuid(void *pBackendData, PCRTUUID pUuid)
|
---|
1465 | {
|
---|
1466 | LogFlowFunc(("pBackendData=%#p Uuid=%Vuuid\n", pBackendData, pUuid));
|
---|
1467 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1468 | int rc = VINF_SUCCESS;
|
---|
1469 |
|
---|
1470 | Assert(pImage);
|
---|
1471 |
|
---|
1472 | if (pImage)
|
---|
1473 | {
|
---|
1474 | if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
|
---|
1475 | {
|
---|
1476 | if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 1)
|
---|
1477 | pImage->Header.u.v1.uuidModify = *pUuid;
|
---|
1478 | /* Make it possible to clone old VDIs. */
|
---|
1479 | else if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 0)
|
---|
1480 | pImage->Header.u.v0.uuidModify = *pUuid;
|
---|
1481 | else
|
---|
1482 | {
|
---|
1483 | LogFunc(("Version is not supported!\n"));
|
---|
1484 | rc = VERR_VDI_UNSUPPORTED_VERSION;
|
---|
1485 | }
|
---|
1486 | }
|
---|
1487 | else
|
---|
1488 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
1489 | }
|
---|
1490 | else
|
---|
1491 | rc = VERR_VDI_NOT_OPENED;
|
---|
1492 |
|
---|
1493 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1494 | return rc;
|
---|
1495 | }
|
---|
1496 |
|
---|
1497 | /** @copydoc VBOXHDDBACKEND::pfnGetParentUuid */
|
---|
1498 | static int vdiGetParentUuid(void *pBackendData, PRTUUID pUuid)
|
---|
1499 | {
|
---|
1500 | LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
|
---|
1501 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1502 | int rc;
|
---|
1503 |
|
---|
1504 | Assert(pImage);
|
---|
1505 |
|
---|
1506 | if (pImage)
|
---|
1507 | {
|
---|
1508 | *pUuid = *getImageParentUUID(&pImage->Header);
|
---|
1509 | rc = VINF_SUCCESS;
|
---|
1510 | }
|
---|
1511 | else
|
---|
1512 | rc = VERR_VDI_NOT_OPENED;
|
---|
1513 |
|
---|
1514 | LogFlowFunc(("returns %Vrc (%Vuuid)\n", rc, pUuid));
|
---|
1515 | return rc;
|
---|
1516 | }
|
---|
1517 |
|
---|
1518 | /** @copydoc VBOXHDDBACKEND::pfnSetParentUuid */
|
---|
1519 | static int vdiSetParentUuid(void *pBackendData, PCRTUUID pUuid)
|
---|
1520 | {
|
---|
1521 | LogFlowFunc(("pBackendData=%#p Uuid=%Vuuid\n", pBackendData, pUuid));
|
---|
1522 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1523 | int rc = VINF_SUCCESS;
|
---|
1524 |
|
---|
1525 | Assert(pImage);
|
---|
1526 |
|
---|
1527 | if (pImage)
|
---|
1528 | {
|
---|
1529 | if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
|
---|
1530 | {
|
---|
1531 | if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 1)
|
---|
1532 | pImage->Header.u.v1.uuidLinkage = *pUuid;
|
---|
1533 | /* Make it possible to clone old VDIs. */
|
---|
1534 | else if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 0)
|
---|
1535 | pImage->Header.u.v0.uuidLinkage = *pUuid;
|
---|
1536 | else
|
---|
1537 | {
|
---|
1538 | LogFunc(("Version is not supported!\n"));
|
---|
1539 | rc = VERR_VDI_UNSUPPORTED_VERSION;
|
---|
1540 | }
|
---|
1541 | }
|
---|
1542 | else
|
---|
1543 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
1544 | }
|
---|
1545 | else
|
---|
1546 | rc = VERR_VDI_NOT_OPENED;
|
---|
1547 |
|
---|
1548 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1549 | return rc;
|
---|
1550 | }
|
---|
1551 |
|
---|
1552 | /** @copydoc VBOXHDDBACKEND::pfnGetParentModificationUuid */
|
---|
1553 | static int vdiGetParentModificationUuid(void *pBackendData, PRTUUID pUuid)
|
---|
1554 | {
|
---|
1555 | LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
|
---|
1556 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1557 | int rc;
|
---|
1558 |
|
---|
1559 | Assert(pImage);
|
---|
1560 |
|
---|
1561 | if (pImage)
|
---|
1562 | {
|
---|
1563 | *pUuid = *getImageParentModificationUUID(&pImage->Header);
|
---|
1564 | rc = VINF_SUCCESS;
|
---|
1565 | }
|
---|
1566 | else
|
---|
1567 | rc = VERR_VDI_NOT_OPENED;
|
---|
1568 |
|
---|
1569 | LogFlowFunc(("returns %Vrc (%Vuuid)\n", rc, pUuid));
|
---|
1570 | return rc;
|
---|
1571 | }
|
---|
1572 |
|
---|
1573 | /** @copydoc VBOXHDDBACKEND::pfnSetParentModificationUuid */
|
---|
1574 | static int vdiSetParentModificationUuid(void *pBackendData, PCRTUUID pUuid)
|
---|
1575 | {
|
---|
1576 | LogFlowFunc(("pBackendData=%#p Uuid=%Vuuid\n", pBackendData, pUuid));
|
---|
1577 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1578 | int rc = VINF_SUCCESS;
|
---|
1579 |
|
---|
1580 | Assert(pImage);
|
---|
1581 |
|
---|
1582 | if (pImage)
|
---|
1583 | {
|
---|
1584 | if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
|
---|
1585 | {
|
---|
1586 | if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 1)
|
---|
1587 | pImage->Header.u.v1.uuidParentModify = *pUuid;
|
---|
1588 | else
|
---|
1589 | {
|
---|
1590 | LogFunc(("Version is not supported!\n"));
|
---|
1591 | rc = VERR_VDI_UNSUPPORTED_VERSION;
|
---|
1592 | }
|
---|
1593 | }
|
---|
1594 | else
|
---|
1595 | rc = VERR_VDI_IMAGE_READ_ONLY;
|
---|
1596 | }
|
---|
1597 | else
|
---|
1598 | rc = VERR_VDI_NOT_OPENED;
|
---|
1599 |
|
---|
1600 | LogFlowFunc(("returns %Vrc\n", rc));
|
---|
1601 | return rc;
|
---|
1602 | }
|
---|
1603 |
|
---|
1604 | /** @copydoc VBOXHDDBACKEND::pfnDump */
|
---|
1605 | static void vdiDump(void *pBackendData)
|
---|
1606 | {
|
---|
1607 | PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
|
---|
1608 |
|
---|
1609 | RTLogPrintf("Dumping VDI image \"%s\" mode=%s uOpenFlags=%X File=%08X\n",
|
---|
1610 | pImage->pszFilename,
|
---|
1611 | (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY) ? "r/o" : "r/w",
|
---|
1612 | pImage->uOpenFlags,
|
---|
1613 | pImage->File);
|
---|
1614 | RTLogPrintf("Header: Version=%08X Type=%X Flags=%X Size=%llu\n",
|
---|
1615 | pImage->PreHeader.u32Version,
|
---|
1616 | getImageType(&pImage->Header),
|
---|
1617 | getImageFlags(&pImage->Header),
|
---|
1618 | getImageDiskSize(&pImage->Header));
|
---|
1619 | RTLogPrintf("Header: cbBlock=%u cbBlockExtra=%u cBlocks=%u cBlocksAllocated=%u\n",
|
---|
1620 | getImageBlockSize(&pImage->Header),
|
---|
1621 | getImageExtraBlockSize(&pImage->Header),
|
---|
1622 | getImageBlocks(&pImage->Header),
|
---|
1623 | getImageBlocksAllocated(&pImage->Header));
|
---|
1624 | RTLogPrintf("Header: offBlocks=%u offData=%u\n",
|
---|
1625 | getImageBlocksOffset(&pImage->Header),
|
---|
1626 | getImageDataOffset(&pImage->Header));
|
---|
1627 | PVDIDISKGEOMETRY pg = getImageLCHSGeometry(&pImage->Header);
|
---|
1628 | if (pg)
|
---|
1629 | RTLogPrintf("Header: Geometry: C/H/S=%u/%u/%u cbSector=%u\n",
|
---|
1630 | pg->cCylinders, pg->cHeads, pg->cSectors, pg->cbSector);
|
---|
1631 | RTLogPrintf("Header: uuidCreation={%Vuuid}\n", getImageCreationUUID(&pImage->Header));
|
---|
1632 | RTLogPrintf("Header: uuidModification={%Vuuid}\n", getImageModificationUUID(&pImage->Header));
|
---|
1633 | RTLogPrintf("Header: uuidParent={%Vuuid}\n", getImageParentUUID(&pImage->Header));
|
---|
1634 | if (GET_MAJOR_HEADER_VERSION(&pImage->Header) >= 1)
|
---|
1635 | RTLogPrintf("Header: uuidParentModification={%Vuuid}\n", getImageParentModificationUUID(&pImage->Header));
|
---|
1636 | RTLogPrintf("Image: fFlags=%08X offStartBlocks=%u offStartData=%u\n",
|
---|
1637 | pImage->uImageFlags, pImage->offStartBlocks, pImage->offStartData);
|
---|
1638 | RTLogPrintf("Image: uBlockMask=%08X uShiftIndex2Offset=%u uShiftOffset2Index=%u offStartBlockData=%u\n",
|
---|
1639 | pImage->uBlockMask,
|
---|
1640 | pImage->uShiftIndex2Offset,
|
---|
1641 | pImage->uShiftOffset2Index,
|
---|
1642 | pImage->offStartBlockData);
|
---|
1643 |
|
---|
1644 | unsigned uBlock, cBlocksNotFree, cBadBlocks, cBlocks = getImageBlocks(&pImage->Header);
|
---|
1645 | for (uBlock=0, cBlocksNotFree=0, cBadBlocks=0; uBlock<cBlocks; uBlock++)
|
---|
1646 | {
|
---|
1647 | if (IS_VDI_IMAGE_BLOCK_ALLOCATED(pImage->paBlocks[uBlock]))
|
---|
1648 | {
|
---|
1649 | cBlocksNotFree++;
|
---|
1650 | if (pImage->paBlocks[uBlock] >= cBlocks)
|
---|
1651 | cBadBlocks++;
|
---|
1652 | }
|
---|
1653 | }
|
---|
1654 | if (cBlocksNotFree != getImageBlocksAllocated(&pImage->Header))
|
---|
1655 | {
|
---|
1656 | RTLogPrintf("!! WARNING: %u blocks actually allocated (cBlocksAllocated=%u) !!\n",
|
---|
1657 | cBlocksNotFree, getImageBlocksAllocated(&pImage->Header));
|
---|
1658 | }
|
---|
1659 | if (cBadBlocks)
|
---|
1660 | {
|
---|
1661 | RTLogPrintf("!! WARNING: %u bad blocks found !!\n",
|
---|
1662 | cBadBlocks);
|
---|
1663 | }
|
---|
1664 | }
|
---|
1665 |
|
---|
1666 | VBOXHDDBACKEND g_VDIBackend =
|
---|
1667 | {
|
---|
1668 | /* pszBackendName */
|
---|
1669 | "VDI",
|
---|
1670 | /* cbSize */
|
---|
1671 | sizeof(VBOXHDDBACKEND),
|
---|
1672 | /* pfnCheckIfValid */
|
---|
1673 | vdiCheckIfValid,
|
---|
1674 | /* pfnOpen */
|
---|
1675 | vdiOpen,
|
---|
1676 | /* pfnCreate */
|
---|
1677 | vdiCreate,
|
---|
1678 | /* pfnRename */
|
---|
1679 | vdiRename,
|
---|
1680 | /* pfnClose */
|
---|
1681 | vdiClose,
|
---|
1682 | /* pfnRead */
|
---|
1683 | vdiRead,
|
---|
1684 | /* pfnWrite */
|
---|
1685 | vdiWrite,
|
---|
1686 | /* pfnFlush */
|
---|
1687 | vdiFlush,
|
---|
1688 | /* pfnGetVersion */
|
---|
1689 | vdiGetVersion,
|
---|
1690 | /* pfnGetImageType */
|
---|
1691 | vdiGetImageType,
|
---|
1692 | /* pfnGetSize */
|
---|
1693 | vdiGetSize,
|
---|
1694 | /* pfnGetFileSize */
|
---|
1695 | vdiGetFileSize,
|
---|
1696 | /* pfnGetPCHSGeometry */
|
---|
1697 | vdiGetPCHSGeometry,
|
---|
1698 | /* pfnSetPCHSGeometry */
|
---|
1699 | vdiSetPCHSGeometry,
|
---|
1700 | /* pfnGetLCHSGeometry */
|
---|
1701 | vdiGetLCHSGeometry,
|
---|
1702 | /* pfnSetLCHSGeometry */
|
---|
1703 | vdiSetLCHSGeometry,
|
---|
1704 | /* pfnGetImageFlags */
|
---|
1705 | vdiGetImageFlags,
|
---|
1706 | /* pfnGetOpenFlags */
|
---|
1707 | vdiGetOpenFlags,
|
---|
1708 | /* pfnSetOpenFlags */
|
---|
1709 | vdiSetOpenFlags,
|
---|
1710 | /* pfnGetComment */
|
---|
1711 | vdiGetComment,
|
---|
1712 | /* pfnSetComment */
|
---|
1713 | vdiSetComment,
|
---|
1714 | /* pfnGetUuid */
|
---|
1715 | vdiGetUuid,
|
---|
1716 | /* pfnSetUuid */
|
---|
1717 | vdiSetUuid,
|
---|
1718 | /* pfnGetModificationUuid */
|
---|
1719 | vdiGetModificationUuid,
|
---|
1720 | /* pfnSetModificationUuid */
|
---|
1721 | vdiSetModificationUuid,
|
---|
1722 | /* pfnGetParentUuid */
|
---|
1723 | vdiGetParentUuid,
|
---|
1724 | /* pfnSetParentUuid */
|
---|
1725 | vdiSetParentUuid,
|
---|
1726 | /* pfnGetParentModificationUuid */
|
---|
1727 | vdiGetParentModificationUuid,
|
---|
1728 | /* pfnSetParentModificationUuid */
|
---|
1729 | vdiSetParentModificationUuid,
|
---|
1730 | /* pfnDump */
|
---|
1731 | vdiDump
|
---|
1732 | };
|
---|
1733 |
|
---|