VirtualBox

source: vbox/trunk/src/VBox/Storage/Parallels.cpp@ 99040

Last change on this file since 99040 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.8 KB
Line 
1/* $Id: Parallels.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 *
4 * Parallels hdd disk image, core code.
5 */
6
7/*
8 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
9 *
10 * This file is part of VirtualBox base platform packages, as
11 * available from https://www.virtualbox.org.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation, in version 3 of the
16 * License.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <https://www.gnu.org/licenses>.
25 *
26 * SPDX-License-Identifier: GPL-3.0-only
27 */
28
29#define LOG_GROUP LOG_GROUP_VD_PARALLELS
30#include <VBox/vd-plugin.h>
31#include <VBox/err.h>
32
33#include <VBox/log.h>
34#include <iprt/assert.h>
35#include <iprt/mem.h>
36#include <iprt/uuid.h>
37#include <iprt/path.h>
38#include <iprt/string.h>
39#include <iprt/asm.h>
40
41#include "VDBackends.h"
42
43#define PARALLELS_HEADER_MAGIC "WithoutFreeSpace"
44#define PARALLELS_DISK_VERSION 2
45
46/** The header of the parallels disk. */
47#pragma pack(1)
48typedef struct ParallelsHeader
49{
50 /** The magic header to identify a parallels hdd image. */
51 char HeaderIdentifier[16];
52 /** The version of the disk image. */
53 uint32_t uVersion;
54 /** The number of heads the hdd has. */
55 uint32_t cHeads;
56 /** Number of cylinders. */
57 uint32_t cCylinders;
58 /** Number of sectors per track. */
59 uint32_t cSectorsPerTrack;
60 /** Number of entries in the allocation bitmap. */
61 uint32_t cEntriesInAllocationBitmap;
62 /** Total number of sectors. */
63 uint32_t cSectors;
64 /** Padding. */
65 char Padding[24];
66} ParallelsHeader;
67#pragma pack()
68
69/**
70 * Parallels image structure.
71 */
72typedef struct PARALLELSIMAGE
73{
74 /** Image file name. */
75 const char *pszFilename;
76 /** Opaque storage handle. */
77 PVDIOSTORAGE pStorage;
78
79 /** Pointer to the per-disk VD interface list. */
80 PVDINTERFACE pVDIfsDisk;
81 /** Pointer to the per-image VD interface list. */
82 PVDINTERFACE pVDIfsImage;
83 /** Error interface. */
84 PVDINTERFACEERROR pIfError;
85 /** I/O interface. */
86 PVDINTERFACEIOINT pIfIo;
87
88 /** Open flags passed by VBoxHDD layer. */
89 unsigned uOpenFlags;
90 /** Image flags defined during creation or determined during open. */
91 unsigned uImageFlags;
92 /** Total size of the image. */
93 uint64_t cbSize;
94
95 /** Physical geometry of this image. */
96 VDGEOMETRY PCHSGeometry;
97 /** Logical geometry of this image. */
98 VDGEOMETRY LCHSGeometry;
99
100 /** Pointer to the allocation bitmap. */
101 uint32_t *pAllocationBitmap;
102 /** Entries in the allocation bitmap. */
103 uint64_t cAllocationBitmapEntries;
104 /** Flag whether the allocation bitmap was changed. */
105 bool fAllocationBitmapChanged;
106 /** Current file size. */
107 uint64_t cbFileCurrent;
108 /** The static region list. */
109 VDREGIONLIST RegionList;
110} PARALLELSIMAGE, *PPARALLELSIMAGE;
111
112
113/*********************************************************************************************************************************
114* Static Variables *
115*********************************************************************************************************************************/
116
117/** NULL-terminated array of supported file extensions. */
118static const VDFILEEXTENSION s_aParallelsFileExtensions[] =
119{
120 {"hdd", VDTYPE_HDD},
121 {NULL, VDTYPE_INVALID}
122};
123
124/***************************************************
125 * Internal functions *
126 **************************************************/
127
128/**
129 * Internal. Flush image data to disk.
130 */
131static int parallelsFlushImage(PPARALLELSIMAGE pImage)
132{
133 int rc = VINF_SUCCESS;
134
135 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
136 return VINF_SUCCESS;
137
138 if ( !(pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED)
139 && (pImage->fAllocationBitmapChanged))
140 {
141 pImage->fAllocationBitmapChanged = false;
142 /* Write the allocation bitmap to the file. */
143 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage,
144 sizeof(ParallelsHeader), pImage->pAllocationBitmap,
145 pImage->cAllocationBitmapEntries * sizeof(uint32_t));
146 if (RT_FAILURE(rc))
147 return rc;
148 }
149
150 /* Flush file. */
151 rc = vdIfIoIntFileFlushSync(pImage->pIfIo, pImage->pStorage);
152
153 LogFlowFunc(("returns %Rrc\n", rc));
154 return rc;
155}
156
157/**
158 * Internal. Free all allocated space for representing an image except pImage,
159 * and optionally delete the image from disk.
160 */
161static int parallelsFreeImage(PPARALLELSIMAGE pImage, bool fDelete)
162{
163 int rc = VINF_SUCCESS;
164
165 /* Freeing a never allocated image (e.g. because the open failed) is
166 * not signalled as an error. After all nothing bad happens. */
167 if (pImage)
168 {
169 if (pImage->pStorage)
170 {
171 /* No point updating the file that is deleted anyway. */
172 if (!fDelete)
173 parallelsFlushImage(pImage);
174
175 rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
176 pImage->pStorage = NULL;
177 }
178
179 if (pImage->pAllocationBitmap)
180 {
181 RTMemFree(pImage->pAllocationBitmap);
182 pImage->pAllocationBitmap = NULL;
183 }
184
185 if (fDelete && pImage->pszFilename)
186 vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename);
187 }
188
189 return rc;
190}
191
192static int parallelsOpenImage(PPARALLELSIMAGE pImage, unsigned uOpenFlags)
193{
194 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
195 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
196 pImage->uOpenFlags = uOpenFlags;
197 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
198
199 int rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename,
200 VDOpenFlagsToFileOpenFlags(uOpenFlags,
201 false /* fCreate */),
202 &pImage->pStorage);
203 if (RT_SUCCESS(rc))
204 {
205 rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &pImage->cbFileCurrent);
206 if (RT_SUCCESS(rc)
207 && !(pImage->cbFileCurrent % 512))
208 {
209 ParallelsHeader parallelsHeader;
210
211 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, 0,
212 &parallelsHeader, sizeof(parallelsHeader));
213 if (RT_SUCCESS(rc))
214 {
215 if (memcmp(parallelsHeader.HeaderIdentifier, PARALLELS_HEADER_MAGIC, 16))
216 {
217 /* Check if the file has hdd as extension. It is a fixed size raw image then. */
218 char *pszSuffix = RTPathSuffix(pImage->pszFilename);
219 if (!strcmp(pszSuffix, ".hdd"))
220 {
221 /* This is a fixed size image. */
222 pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED;
223 pImage->cbSize = pImage->cbFileCurrent;
224
225 pImage->PCHSGeometry.cHeads = 16;
226 pImage->PCHSGeometry.cSectors = 63;
227 uint64_t cCylinders = pImage->cbSize / (512 * pImage->PCHSGeometry.cSectors * pImage->PCHSGeometry.cHeads);
228 pImage->PCHSGeometry.cCylinders = (uint32_t)cCylinders;
229 }
230 else
231 rc = VERR_VD_PARALLELS_INVALID_HEADER;
232 }
233 else
234 {
235 if ( parallelsHeader.uVersion == PARALLELS_DISK_VERSION
236 && parallelsHeader.cEntriesInAllocationBitmap <= (1 << 30))
237 {
238 Log(("cSectors=%u\n", parallelsHeader.cSectors));
239 pImage->cbSize = ((uint64_t)parallelsHeader.cSectors) * 512;
240 pImage->uImageFlags = VD_IMAGE_FLAGS_NONE;
241 pImage->PCHSGeometry.cCylinders = parallelsHeader.cCylinders;
242 pImage->PCHSGeometry.cHeads = parallelsHeader.cHeads;
243 pImage->PCHSGeometry.cSectors = parallelsHeader.cSectorsPerTrack;
244 pImage->cAllocationBitmapEntries = parallelsHeader.cEntriesInAllocationBitmap;
245 pImage->pAllocationBitmap = (uint32_t *)RTMemAllocZ((uint32_t)pImage->cAllocationBitmapEntries * sizeof(uint32_t));
246 if (RT_LIKELY(pImage->pAllocationBitmap))
247 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage,
248 sizeof(ParallelsHeader), pImage->pAllocationBitmap,
249 pImage->cAllocationBitmapEntries * sizeof(uint32_t));
250 else
251 rc = VERR_NO_MEMORY;
252 }
253 else
254 rc = VERR_NOT_SUPPORTED;
255 }
256 }
257 }
258 else if (RT_SUCCESS(rc))
259 rc = VERR_VD_PARALLELS_INVALID_HEADER;
260 }
261
262 if (RT_SUCCESS(rc))
263 {
264 PVDREGIONDESC pRegion = &pImage->RegionList.aRegions[0];
265 pImage->RegionList.fFlags = 0;
266 pImage->RegionList.cRegions = 1;
267
268 pRegion->offRegion = 0; /* Disk start. */
269 pRegion->cbBlock = 512;
270 pRegion->enmDataForm = VDREGIONDATAFORM_RAW;
271 pRegion->enmMetadataForm = VDREGIONMETADATAFORM_NONE;
272 pRegion->cbData = 512;
273 pRegion->cbMetadata = 0;
274 pRegion->cRegionBlocksOrBytes = pImage->cbSize;
275 }
276 else
277 parallelsFreeImage(pImage, false);
278
279 LogFlowFunc(("returns %Rrc\n", rc));
280 return rc;
281}
282
283/**
284 * Internal: Create a parallels image.
285 */
286static int parallelsCreateImage(PPARALLELSIMAGE pImage, uint64_t cbSize,
287 unsigned uImageFlags, const char *pszComment,
288 PCVDGEOMETRY pPCHSGeometry,
289 PCVDGEOMETRY pLCHSGeometry, unsigned uOpenFlags,
290 PFNVDPROGRESS pfnProgress, void *pvUser,
291 unsigned uPercentStart, unsigned uPercentSpan)
292{
293 RT_NOREF1(pszComment);
294 int rc = VINF_SUCCESS;
295 int32_t fOpen;
296
297 if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED))
298 {
299 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
300 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
301 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
302
303 pImage->uOpenFlags = uOpenFlags & ~VD_OPEN_FLAGS_READONLY;
304 pImage->uImageFlags = uImageFlags;
305 pImage->PCHSGeometry = *pPCHSGeometry;
306 pImage->LCHSGeometry = *pLCHSGeometry;
307 if (!pImage->PCHSGeometry.cCylinders)
308 {
309 /* Set defaults. */
310 pImage->PCHSGeometry.cSectors = 63;
311 pImage->PCHSGeometry.cHeads = 16;
312 pImage->PCHSGeometry.cCylinders = pImage->cbSize / (512 * pImage->PCHSGeometry.cSectors * pImage->PCHSGeometry.cHeads);
313 }
314
315 /* Create image file. */
316 fOpen = VDOpenFlagsToFileOpenFlags(pImage->uOpenFlags, true /* fCreate */);
317 rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename, fOpen, &pImage->pStorage);
318 if (RT_SUCCESS(rc))
319 {
320 if (pfnProgress)
321 pfnProgress(pvUser, uPercentStart + uPercentSpan * 98 / 100);
322
323 /* Setup image state. */
324 pImage->cbSize = cbSize;
325 pImage->cAllocationBitmapEntries = cbSize / 512 / pImage->PCHSGeometry.cSectors;
326 if (pImage->cAllocationBitmapEntries * pImage->PCHSGeometry.cSectors * 512 < cbSize)
327 pImage->cAllocationBitmapEntries++;
328 pImage->fAllocationBitmapChanged = true;
329 pImage->cbFileCurrent = sizeof(ParallelsHeader) + pImage->cAllocationBitmapEntries * sizeof(uint32_t);
330 /* Round to next sector boundary. */
331 pImage->cbFileCurrent += 512 - pImage->cbFileCurrent % 512;
332 Assert(!(pImage->cbFileCurrent % 512));
333 pImage->pAllocationBitmap = (uint32_t *)RTMemAllocZ(pImage->cAllocationBitmapEntries * sizeof(uint32_t));
334 if (pImage->pAllocationBitmap)
335 {
336 ParallelsHeader Header;
337
338 memcpy(Header.HeaderIdentifier, PARALLELS_HEADER_MAGIC, sizeof(Header.HeaderIdentifier));
339 Header.uVersion = RT_H2LE_U32(PARALLELS_DISK_VERSION);
340 Header.cHeads = RT_H2LE_U32(pImage->PCHSGeometry.cHeads);
341 Header.cCylinders = RT_H2LE_U32(pImage->PCHSGeometry.cCylinders);
342 Header.cSectorsPerTrack = RT_H2LE_U32(pImage->PCHSGeometry.cSectors);
343 Header.cEntriesInAllocationBitmap = RT_H2LE_U32(pImage->cAllocationBitmapEntries);
344 Header.cSectors = RT_H2LE_U32(pImage->cbSize / 512);
345 memset(Header.Padding, 0, sizeof(Header.Padding));
346
347 /* Write header and allocation bitmap. */
348 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, pImage->cbFileCurrent);
349 if (RT_SUCCESS(rc))
350 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, 0,
351 &Header, sizeof(Header));
352 if (RT_SUCCESS(rc))
353 rc = parallelsFlushImage(pImage); /* Writes the allocation bitmap. */
354 }
355 else
356 rc = VERR_NO_MEMORY;
357 }
358 else
359 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Parallels: cannot create image '%s'"), pImage->pszFilename);
360 }
361 else
362 rc = vdIfError(pImage->pIfError, VERR_VD_INVALID_TYPE, RT_SRC_POS, N_("Parallels: cannot create fixed image '%s'. Create a raw image"), pImage->pszFilename);
363
364 if (RT_SUCCESS(rc) && pfnProgress)
365 pfnProgress(pvUser, uPercentStart + uPercentSpan);
366
367 if (RT_SUCCESS(rc))
368 {
369 PVDREGIONDESC pRegion = &pImage->RegionList.aRegions[0];
370 pImage->RegionList.fFlags = 0;
371 pImage->RegionList.cRegions = 1;
372
373 pRegion->offRegion = 0; /* Disk start. */
374 pRegion->cbBlock = 512;
375 pRegion->enmDataForm = VDREGIONDATAFORM_RAW;
376 pRegion->enmMetadataForm = VDREGIONMETADATAFORM_NONE;
377 pRegion->cbData = 512;
378 pRegion->cbMetadata = 0;
379 pRegion->cRegionBlocksOrBytes = pImage->cbSize;
380 }
381 else
382 parallelsFreeImage(pImage, rc != VERR_ALREADY_EXISTS);
383 return rc;
384}
385
386/** @copydoc VDIMAGEBACKEND::pfnProbe */
387static DECLCALLBACK(int) parallelsProbe(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
388 PVDINTERFACE pVDIfsImage, VDTYPE enmDesiredType, VDTYPE *penmType)
389{
390 RT_NOREF(pVDIfsDisk, enmDesiredType);
391 int rc;
392 PVDIOSTORAGE pStorage;
393 ParallelsHeader parallelsHeader;
394
395 PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
396 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
397
398 rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
399 VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
400 false /* fCreate */),
401 &pStorage);
402 if (RT_FAILURE(rc))
403 return rc;
404
405 rc = vdIfIoIntFileReadSync(pIfIo, pStorage, 0, &parallelsHeader,
406 sizeof(ParallelsHeader));
407 if (RT_SUCCESS(rc))
408 {
409 if ( !memcmp(parallelsHeader.HeaderIdentifier, PARALLELS_HEADER_MAGIC, 16)
410 && (parallelsHeader.uVersion == PARALLELS_DISK_VERSION))
411 rc = VINF_SUCCESS;
412 else
413 {
414 /*
415 * The image may be an fixed size image.
416 * Unfortunately fixed sized parallels images
417 * are just raw files hence no magic header to
418 * check for.
419 * The code succeeds if the file is a multiple
420 * of 512 and if the file extensions is *.hdd
421 */
422 uint64_t cbFile;
423 char *pszSuffix;
424
425 rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
426 if (RT_FAILURE(rc) || ((cbFile % 512) != 0))
427 {
428 vdIfIoIntFileClose(pIfIo, pStorage);
429 return VERR_VD_PARALLELS_INVALID_HEADER;
430 }
431
432 pszSuffix = RTPathSuffix(pszFilename);
433 if (!pszSuffix || strcmp(pszSuffix, ".hdd"))
434 rc = VERR_VD_PARALLELS_INVALID_HEADER;
435 else
436 rc = VINF_SUCCESS;
437 }
438 }
439
440 if (RT_SUCCESS(rc))
441 *penmType = VDTYPE_HDD;
442
443 vdIfIoIntFileClose(pIfIo, pStorage);
444 return rc;
445}
446
447/** @copydoc VDIMAGEBACKEND::pfnOpen */
448static DECLCALLBACK(int) parallelsOpen(const char *pszFilename, unsigned uOpenFlags,
449 PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
450 VDTYPE enmType, void **ppBackendData)
451{
452 LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p enmType=%u ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
453 int rc;
454 PPARALLELSIMAGE pImage;
455
456 NOREF(enmType); /**< @todo r=klaus make use of the type info. */
457
458 /* Check parameters. */
459 AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
460 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
461 AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
462
463
464 pImage = (PPARALLELSIMAGE)RTMemAllocZ(RT_UOFFSETOF(PARALLELSIMAGE, RegionList.aRegions[1]));
465 if (RT_LIKELY(pImage))
466 {
467 pImage->pszFilename = pszFilename;
468 pImage->pStorage = NULL;
469 pImage->pVDIfsDisk = pVDIfsDisk;
470 pImage->pVDIfsImage = pVDIfsImage;
471 pImage->fAllocationBitmapChanged = false;
472
473 rc = parallelsOpenImage(pImage, uOpenFlags);
474 if (RT_SUCCESS(rc))
475 *ppBackendData = pImage;
476 else
477 RTMemFree(pImage);
478 }
479 else
480 rc = VERR_NO_MEMORY;
481
482 LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
483 return rc;
484}
485
486/** @copydoc VDIMAGEBACKEND::pfnCreate */
487static DECLCALLBACK(int) parallelsCreate(const char *pszFilename, uint64_t cbSize,
488 unsigned uImageFlags, const char *pszComment,
489 PCVDGEOMETRY pPCHSGeometry,
490 PCVDGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
491 unsigned uOpenFlags, unsigned uPercentStart,
492 unsigned uPercentSpan, PVDINTERFACE pVDIfsDisk,
493 PVDINTERFACE pVDIfsImage,
494 PVDINTERFACE pVDIfsOperation, VDTYPE enmType,
495 void **ppBackendData)
496{
497 RT_NOREF1(pUuid);
498 LogFlowFunc(("pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" pPCHSGeometry=%#p pLCHSGeometry=%#p Uuid=%RTuuid uOpenFlags=%#x uPercentStart=%u uPercentSpan=%u pVDIfsDisk=%#p pVDIfsImage=%#p pVDIfsOperation=%#p enmType=%u ppBackendData=%#p",
499 pszFilename, cbSize, uImageFlags, pszComment, pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, uPercentStart, uPercentSpan, pVDIfsDisk, pVDIfsImage, pVDIfsOperation, enmType, ppBackendData));
500
501 /* Check the VD container type. */
502 if (enmType != VDTYPE_HDD)
503 return VERR_VD_INVALID_TYPE;
504
505 /* Check arguments. */
506 AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
507 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
508 AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
509 AssertPtrReturn(pPCHSGeometry, VERR_INVALID_POINTER);
510 AssertPtrReturn(pLCHSGeometry, VERR_INVALID_POINTER);
511
512 int rc = VINF_SUCCESS;
513 PPARALLELSIMAGE pImage;
514 PFNVDPROGRESS pfnProgress = NULL;
515 void *pvUser = NULL;
516 PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation);
517 if (pIfProgress)
518 {
519 pfnProgress = pIfProgress->pfnProgress;
520 pvUser = pIfProgress->Core.pvUser;
521 }
522
523 pImage = (PPARALLELSIMAGE)RTMemAllocZ(RT_UOFFSETOF(PARALLELSIMAGE, RegionList.aRegions[1]));
524 if (RT_LIKELY(pImage))
525 {
526 pImage->pszFilename = pszFilename;
527 pImage->pStorage = NULL;
528 pImage->pVDIfsDisk = pVDIfsDisk;
529 pImage->pVDIfsImage = pVDIfsImage;
530
531 rc = parallelsCreateImage(pImage, cbSize, uImageFlags, pszComment,
532 pPCHSGeometry, pLCHSGeometry, uOpenFlags,
533 pfnProgress, pvUser, uPercentStart, uPercentSpan);
534 if (RT_SUCCESS(rc))
535 {
536 /* So far the image is opened in read/write mode. Make sure the
537 * image is opened in read-only mode if the caller requested that. */
538 if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
539 {
540 parallelsFreeImage(pImage, false);
541 rc = parallelsOpenImage(pImage, uOpenFlags);
542 }
543
544 if (RT_SUCCESS(rc))
545 *ppBackendData = pImage;
546 }
547
548 if (RT_FAILURE(rc))
549 RTMemFree(pImage);
550 }
551 else
552 rc = VERR_NO_MEMORY;
553
554 LogFlowFunc(("returns %Rrc\n", rc));
555 return rc;
556}
557
558/** @copydoc VDIMAGEBACKEND::pfnRename */
559static DECLCALLBACK(int) parallelsRename(void *pBackendData, const char *pszFilename)
560{
561 LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
562 int rc = VINF_SUCCESS;
563 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
564
565 /* Check arguments. */
566 AssertReturn((pImage && pszFilename && *pszFilename), VERR_INVALID_PARAMETER);
567
568 /* Close the image. */
569 rc = parallelsFreeImage(pImage, false);
570 if (RT_SUCCESS(rc))
571 {
572 /* Rename the file. */
573 rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
574 if (RT_SUCCESS(rc))
575 {
576 /* Update pImage with the new information. */
577 pImage->pszFilename = pszFilename;
578
579 /* Open the old image with new name. */
580 rc = parallelsOpenImage(pImage, pImage->uOpenFlags);
581 }
582 else
583 {
584 /* The move failed, try to reopen the original image. */
585 int rc2 = parallelsOpenImage(pImage, pImage->uOpenFlags);
586 if (RT_FAILURE(rc2))
587 rc = rc2;
588 }
589 }
590
591 LogFlowFunc(("returns %Rrc\n", rc));
592 return rc;
593}
594
595/** @copydoc VDIMAGEBACKEND::pfnClose */
596static DECLCALLBACK(int) parallelsClose(void *pBackendData, bool fDelete)
597{
598 LogFlowFunc(("pBackendData=%#p fDelete=%d\n", pBackendData, fDelete));
599 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
600 int rc = parallelsFreeImage(pImage, fDelete);
601 RTMemFree(pImage);
602
603 LogFlowFunc(("returns %Rrc\n", rc));
604 return rc;
605}
606
607/** @copydoc VDIMAGEBACKEND::pfnRead */
608static DECLCALLBACK(int) parallelsRead(void *pBackendData, uint64_t uOffset, size_t cbToRead,
609 PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
610{
611 LogFlowFunc(("pBackendData=%#p uOffset=%llu pIoCtx=%#p cbToRead=%zu pcbActuallyRead=%#p\n",
612 pBackendData, uOffset, pIoCtx, cbToRead, pcbActuallyRead));
613 int rc = VINF_SUCCESS;
614 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
615 uint64_t uSector;
616 uint64_t uOffsetInFile;
617 uint32_t iIndexInAllocationTable;
618
619 AssertPtr(pImage);
620 Assert(uOffset % 512 == 0);
621 Assert(cbToRead % 512 == 0);
622
623 if (pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED)
624 rc = vdIfIoIntFileReadUser(pImage->pIfIo, pImage->pStorage, uOffset,
625 pIoCtx, cbToRead);
626 else
627 {
628 /* Calculate offset in the real file. */
629 uSector = uOffset / 512;
630 /* One chunk in the file is always one track big. */
631 iIndexInAllocationTable = (uint32_t)(uSector / pImage->PCHSGeometry.cSectors);
632 uSector = uSector % pImage->PCHSGeometry.cSectors;
633
634 cbToRead = RT_MIN(cbToRead, (pImage->PCHSGeometry.cSectors - uSector)*512);
635
636 if (pImage->pAllocationBitmap[iIndexInAllocationTable] == 0)
637 rc = VERR_VD_BLOCK_FREE;
638 else
639 {
640 uOffsetInFile = (pImage->pAllocationBitmap[iIndexInAllocationTable] + uSector) * 512;
641 rc = vdIfIoIntFileReadUser(pImage->pIfIo, pImage->pStorage, uOffsetInFile,
642 pIoCtx, cbToRead);
643 }
644 }
645
646 *pcbActuallyRead = cbToRead;
647
648 LogFlowFunc(("returns %Rrc\n", rc));
649 return rc;
650}
651
652/** @copydoc VDIMAGEBACKEND::pfnWrite */
653static DECLCALLBACK(int) parallelsWrite(void *pBackendData, uint64_t uOffset, size_t cbToWrite,
654 PVDIOCTX pIoCtx, size_t *pcbWriteProcess, size_t *pcbPreRead,
655 size_t *pcbPostRead, unsigned fWrite)
656{
657 LogFlowFunc(("pBackendData=%#p uOffset=%llu pIoCtx=%#p cbToWrite=%zu pcbWriteProcess=%#p\n",
658 pBackendData, uOffset, pIoCtx, cbToWrite, pcbWriteProcess));
659 int rc = VINF_SUCCESS;
660 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
661 uint64_t uSector;
662 uint64_t uOffsetInFile;
663 uint32_t iIndexInAllocationTable;
664
665 AssertPtr(pImage);
666 Assert(uOffset % 512 == 0);
667 Assert(cbToWrite % 512 == 0);
668
669 if (pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED)
670 rc = vdIfIoIntFileWriteUser(pImage->pIfIo, pImage->pStorage, uOffset,
671 pIoCtx, cbToWrite, NULL, NULL);
672 else
673 {
674 /* Calculate offset in the real file. */
675 uSector = uOffset / 512;
676 /* One chunk in the file is always one track big. */
677 iIndexInAllocationTable = (uint32_t)(uSector / pImage->PCHSGeometry.cSectors);
678 uSector = uSector % pImage->PCHSGeometry.cSectors;
679
680 cbToWrite = RT_MIN(cbToWrite, (pImage->PCHSGeometry.cSectors - uSector)*512);
681
682 if (pImage->pAllocationBitmap[iIndexInAllocationTable] == 0)
683 {
684 if (fWrite & VD_WRITE_NO_ALLOC)
685 {
686 *pcbPreRead = uSector * 512;
687 *pcbPostRead = pImage->PCHSGeometry.cSectors * 512 - cbToWrite - *pcbPreRead;
688
689 if (pcbWriteProcess)
690 *pcbWriteProcess = cbToWrite;
691 return VERR_VD_BLOCK_FREE;
692 }
693
694 /* Allocate new chunk in the file. */
695 Assert(uSector == 0);
696 AssertMsg(pImage->cbFileCurrent % 512 == 0, ("File size is not a multiple of 512\n"));
697 pImage->pAllocationBitmap[iIndexInAllocationTable] = (uint32_t)(pImage->cbFileCurrent / 512);
698 pImage->cbFileCurrent += pImage->PCHSGeometry.cSectors * 512;
699 pImage->fAllocationBitmapChanged = true;
700 uOffsetInFile = (uint64_t)pImage->pAllocationBitmap[iIndexInAllocationTable] * 512;
701
702 /*
703 * Write the new block at the current end of the file.
704 */
705 rc = vdIfIoIntFileWriteUser(pImage->pIfIo, pImage->pStorage,
706 uOffsetInFile, pIoCtx, cbToWrite, NULL, NULL);
707 if (RT_SUCCESS(rc) || (rc == VERR_VD_ASYNC_IO_IN_PROGRESS))
708 {
709 /* Write the changed allocation bitmap entry. */
710 /** @todo Error handling. */
711 rc = vdIfIoIntFileWriteMeta(pImage->pIfIo, pImage->pStorage,
712 sizeof(ParallelsHeader) + iIndexInAllocationTable * sizeof(uint32_t),
713 &pImage->pAllocationBitmap[iIndexInAllocationTable],
714 sizeof(uint32_t), pIoCtx,
715 NULL, NULL);
716 }
717
718 *pcbPreRead = 0;
719 *pcbPostRead = 0;
720 }
721 else
722 {
723 uOffsetInFile = (pImage->pAllocationBitmap[iIndexInAllocationTable] + uSector) * 512;
724 rc = vdIfIoIntFileWriteUser(pImage->pIfIo, pImage->pStorage,
725 uOffsetInFile, pIoCtx, cbToWrite, NULL, NULL);
726 }
727 }
728
729 if (pcbWriteProcess)
730 *pcbWriteProcess = cbToWrite;
731
732 LogFlowFunc(("returns %Rrc\n", rc));
733 return rc;
734}
735
736/** @copydoc VDIMAGEBACKEND::pfnFlush */
737static DECLCALLBACK(int) parallelsFlush(void *pBackendData, PVDIOCTX pIoCtx)
738{
739 int rc = VINF_SUCCESS;
740 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
741
742 LogFlowFunc(("pImage=#%p\n", pImage));
743
744 /* Flush the file, everything is up to date already. */
745 rc = vdIfIoIntFileFlush(pImage->pIfIo, pImage->pStorage, pIoCtx, NULL, NULL);
746
747 LogFlowFunc(("returns %Rrc\n", rc));
748 return rc;
749}
750
751/** @copydoc VDIMAGEBACKEND::pfnGetVersion */
752static DECLCALLBACK(unsigned) parallelsGetVersion(void *pBackendData)
753{
754 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
755 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
756
757 AssertPtrReturn(pImage, 0);
758
759 return PARALLELS_DISK_VERSION;
760}
761
762/** @copydoc VDIMAGEBACKEND::pfnGetFileSize */
763static DECLCALLBACK(uint64_t) parallelsGetFileSize(void *pBackendData)
764{
765 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
766 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
767 uint64_t cb = 0;
768
769 AssertPtrReturn(pImage, 0);
770
771 if (pImage->pStorage)
772 cb = pImage->cbFileCurrent;
773
774 LogFlowFunc(("returns %lld\n", cb));
775 return cb;
776}
777
778/** @copydoc VDIMAGEBACKEND::pfnGetPCHSGeometry */
779static DECLCALLBACK(int) parallelsGetPCHSGeometry(void *pBackendData,
780 PVDGEOMETRY pPCHSGeometry)
781{
782 LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p\n", pBackendData, pPCHSGeometry));
783 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
784 int rc = VINF_SUCCESS;
785
786 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
787
788 if (pImage->PCHSGeometry.cCylinders)
789 *pPCHSGeometry = pImage->PCHSGeometry;
790 else
791 rc = VERR_VD_GEOMETRY_NOT_SET;
792
793 LogFlowFunc(("returns %Rrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
794 return rc;
795}
796
797/** @copydoc VDIMAGEBACKEND::pfnSetPCHSGeometry */
798static DECLCALLBACK(int) parallelsSetPCHSGeometry(void *pBackendData,
799 PCVDGEOMETRY pPCHSGeometry)
800{
801 LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n", pBackendData,
802 pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
803 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
804 int rc = VINF_SUCCESS;
805
806 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
807
808 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
809 rc = VERR_VD_IMAGE_READ_ONLY;
810 else
811 pImage->PCHSGeometry = *pPCHSGeometry;
812
813 LogFlowFunc(("returns %Rrc\n", rc));
814 return rc;
815}
816
817/** @copydoc VDIMAGEBACKEND::pfnGetLCHSGeometry */
818static DECLCALLBACK(int) parallelsGetLCHSGeometry(void *pBackendData,
819 PVDGEOMETRY pLCHSGeometry)
820{
821 LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
822 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
823 int rc = VINF_SUCCESS;
824
825 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
826
827 if (pImage->LCHSGeometry.cCylinders)
828 *pLCHSGeometry = pImage->LCHSGeometry;
829 else
830 rc = VERR_VD_GEOMETRY_NOT_SET;
831
832 LogFlowFunc(("returns %Rrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
833 return rc;
834}
835
836/** @copydoc VDIMAGEBACKEND::pfnSetLCHSGeometry */
837static DECLCALLBACK(int) parallelsSetLCHSGeometry(void *pBackendData,
838 PCVDGEOMETRY pLCHSGeometry)
839{
840 LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n", pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
841 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
842 int rc = VINF_SUCCESS;
843
844 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
845
846 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
847 rc = VERR_VD_IMAGE_READ_ONLY;
848 else
849 pImage->LCHSGeometry = *pLCHSGeometry;
850
851 LogFlowFunc(("returns %Rrc\n", rc));
852 return rc;
853}
854
855/** @copydoc VDIMAGEBACKEND::pfnQueryRegions */
856static DECLCALLBACK(int) parallelsQueryRegions(void *pBackendData, PCVDREGIONLIST *ppRegionList)
857{
858 LogFlowFunc(("pBackendData=%#p ppRegionList=%#p\n", pBackendData, ppRegionList));
859 PPARALLELSIMAGE pThis = (PPARALLELSIMAGE)pBackendData;
860
861 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
862
863 *ppRegionList = &pThis->RegionList;
864 LogFlowFunc(("returns %Rrc\n", VINF_SUCCESS));
865 return VINF_SUCCESS;
866}
867
868/** @copydoc VDIMAGEBACKEND::pfnRegionListRelease */
869static DECLCALLBACK(void) parallelsRegionListRelease(void *pBackendData, PCVDREGIONLIST pRegionList)
870{
871 RT_NOREF1(pRegionList);
872 LogFlowFunc(("pBackendData=%#p pRegionList=%#p\n", pBackendData, pRegionList));
873 PPARALLELSIMAGE pThis = (PPARALLELSIMAGE)pBackendData;
874 AssertPtr(pThis); RT_NOREF(pThis);
875
876 /* Nothing to do here. */
877}
878
879/** @copydoc VDIMAGEBACKEND::pfnGetImageFlags */
880static DECLCALLBACK(unsigned) parallelsGetImageFlags(void *pBackendData)
881{
882 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
883 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
884
885 AssertPtrReturn(pImage, 0);
886
887 LogFlowFunc(("returns %#x\n", pImage->uImageFlags));
888 return pImage->uImageFlags;
889}
890
891/** @copydoc VDIMAGEBACKEND::pfnGetOpenFlags */
892static DECLCALLBACK(unsigned) parallelsGetOpenFlags(void *pBackendData)
893{
894 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
895 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
896
897 AssertPtrReturn(pImage, 0);
898
899 LogFlowFunc(("returns %#x\n", pImage->uOpenFlags));
900 return pImage->uOpenFlags;
901}
902
903/** @copydoc VDIMAGEBACKEND::pfnSetOpenFlags */
904static DECLCALLBACK(int) parallelsSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
905{
906 LogFlowFunc(("pBackendData=%#p\n uOpenFlags=%#x", pBackendData, uOpenFlags));
907 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
908 int rc = VINF_SUCCESS;
909
910 /* Image must be opened and the new flags must be valid. */
911 if (!pImage || (uOpenFlags & ~( VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_INFO
912 | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE
913 | VD_OPEN_FLAGS_SEQUENTIAL | VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS)))
914 rc = VERR_INVALID_PARAMETER;
915 else
916 {
917 /* Implement this operation via reopening the image. */
918 parallelsFreeImage(pImage, false);
919 rc = parallelsOpenImage(pImage, uOpenFlags);
920 }
921
922 LogFlowFunc(("returns %Rrc\n", rc));
923 return rc;
924}
925
926/** @copydoc VDIMAGEBACKEND::pfnGetComment */
927static DECLCALLBACK(int) parallelsGetComment(void *pBackendData, char *pszComment,
928 size_t cbComment)
929{
930 RT_NOREF2(pszComment, cbComment);
931 LogFlowFunc(("pBackendData=%#p pszComment=%#p cbComment=%zu\n", pBackendData, pszComment, cbComment));
932 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
933
934 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
935
936 LogFlowFunc(("returns %Rrc comment='%s'\n", VERR_NOT_SUPPORTED, pszComment));
937 return VERR_NOT_SUPPORTED;
938}
939
940/** @copydoc VDIMAGEBACKEND::pfnSetComment */
941static DECLCALLBACK(int) parallelsSetComment(void *pBackendData, const char *pszComment)
942{
943 RT_NOREF1(pszComment);
944 LogFlowFunc(("pBackendData=%#p pszComment=\"%s\"\n", pBackendData, pszComment));
945 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
946
947 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
948
949 int rc;
950 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
951 rc = VERR_VD_IMAGE_READ_ONLY;
952 else
953 rc = VERR_NOT_SUPPORTED;
954
955 LogFlowFunc(("returns %Rrc\n", rc));
956 return rc;
957}
958
959/** @copydoc VDIMAGEBACKEND::pfnGetUuid */
960static DECLCALLBACK(int) parallelsGetUuid(void *pBackendData, PRTUUID pUuid)
961{
962 RT_NOREF1(pUuid);
963 LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
964 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
965
966 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
967
968 LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
969 return VERR_NOT_SUPPORTED;
970}
971
972/** @copydoc VDIMAGEBACKEND::pfnSetUuid */
973static DECLCALLBACK(int) parallelsSetUuid(void *pBackendData, PCRTUUID pUuid)
974{
975 RT_NOREF1(pUuid);
976 LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
977 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
978
979 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
980
981 int rc;
982 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
983 rc = VERR_VD_IMAGE_READ_ONLY;
984 else
985 rc = VERR_NOT_SUPPORTED;
986
987 LogFlowFunc(("returns %Rrc\n", rc));
988 return rc;
989}
990
991/** @copydoc VDIMAGEBACKEND::pfnGetModificationUuid */
992static DECLCALLBACK(int) parallelsGetModificationUuid(void *pBackendData, PRTUUID pUuid)
993{
994 RT_NOREF1(pUuid);
995 LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
996 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
997
998 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
999
1000 LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
1001 return VERR_NOT_SUPPORTED;
1002}
1003
1004/** @copydoc VDIMAGEBACKEND::pfnSetModificationUuid */
1005static DECLCALLBACK(int) parallelsSetModificationUuid(void *pBackendData, PCRTUUID pUuid)
1006{
1007 RT_NOREF1(pUuid);
1008 LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
1009 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
1010
1011 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
1012
1013 int rc;
1014 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
1015 rc = VERR_VD_IMAGE_READ_ONLY;
1016 else
1017 rc = VERR_NOT_SUPPORTED;
1018
1019 LogFlowFunc(("returns %Rrc\n", rc));
1020 return rc;
1021}
1022
1023/** @copydoc VDIMAGEBACKEND::pfnGetParentUuid */
1024static DECLCALLBACK(int) parallelsGetParentUuid(void *pBackendData, PRTUUID pUuid)
1025{
1026 RT_NOREF1(pUuid);
1027 LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
1028 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
1029
1030 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
1031
1032 LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
1033 return VERR_NOT_SUPPORTED;
1034}
1035
1036/** @copydoc VDIMAGEBACKEND::pfnSetParentUuid */
1037static DECLCALLBACK(int) parallelsSetParentUuid(void *pBackendData, PCRTUUID pUuid)
1038{
1039 RT_NOREF1(pUuid);
1040 LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
1041 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
1042
1043 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
1044
1045 int rc;
1046 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
1047 rc = VERR_VD_IMAGE_READ_ONLY;
1048 else
1049 rc = VERR_NOT_SUPPORTED;
1050
1051 LogFlowFunc(("returns %Rrc\n", rc));
1052 return rc;
1053}
1054
1055/** @copydoc VDIMAGEBACKEND::pfnGetParentModificationUuid */
1056static DECLCALLBACK(int) parallelsGetParentModificationUuid(void *pBackendData, PRTUUID pUuid)
1057{
1058 RT_NOREF1(pUuid);
1059 LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
1060 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
1061
1062 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
1063
1064 int rc;
1065 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
1066 rc = VERR_VD_IMAGE_READ_ONLY;
1067 else
1068 rc = VERR_NOT_SUPPORTED;
1069
1070 LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
1071 return rc;
1072}
1073
1074/** @copydoc VDIMAGEBACKEND::pfnSetParentModificationUuid */
1075static DECLCALLBACK(int) parallelsSetParentModificationUuid(void *pBackendData, PCRTUUID pUuid)
1076{
1077 RT_NOREF1(pUuid);
1078 LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
1079 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
1080
1081 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
1082
1083 int rc;
1084 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
1085 rc = VERR_VD_IMAGE_READ_ONLY;
1086 else
1087 rc = VERR_NOT_SUPPORTED;
1088
1089 LogFlowFunc(("returns %Rrc\n", rc));
1090 return rc;
1091}
1092
1093/** @copydoc VDIMAGEBACKEND::pfnDump */
1094static DECLCALLBACK(void) parallelsDump(void *pBackendData)
1095{
1096 PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pBackendData;
1097
1098 AssertPtrReturnVoid(pImage);
1099 vdIfErrorMessage(pImage->pIfError, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u\n",
1100 pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors,
1101 pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors);
1102}
1103
1104
1105
1106const VDIMAGEBACKEND g_ParallelsBackend =
1107{
1108 /* u32Version */
1109 VD_IMGBACKEND_VERSION,
1110 /* pszBackendName */
1111 "Parallels",
1112 /* uBackendCaps */
1113 VD_CAP_FILE | VD_CAP_ASYNC | VD_CAP_VFS | VD_CAP_CREATE_DYNAMIC | VD_CAP_DIFF,
1114 /* paFileExtensions */
1115 s_aParallelsFileExtensions,
1116 /* paConfigInfo */
1117 NULL,
1118 /* pfnProbe */
1119 parallelsProbe,
1120 /* pfnOpen */
1121 parallelsOpen,
1122 /* pfnCreate */
1123 parallelsCreate,
1124 /* pfnRename */
1125 parallelsRename,
1126 /* pfnClose */
1127 parallelsClose,
1128 /* pfnRead */
1129 parallelsRead,
1130 /* pfnWrite */
1131 parallelsWrite,
1132 /* pfnFlush */
1133 parallelsFlush,
1134 /* pfnDiscard */
1135 NULL,
1136 /* pfnGetVersion */
1137 parallelsGetVersion,
1138 /* pfnGetFileSize */
1139 parallelsGetFileSize,
1140 /* pfnGetPCHSGeometry */
1141 parallelsGetPCHSGeometry,
1142 /* pfnSetPCHSGeometry */
1143 parallelsSetPCHSGeometry,
1144 /* pfnGetLCHSGeometry */
1145 parallelsGetLCHSGeometry,
1146 /* pfnSetLCHSGeometry */
1147 parallelsSetLCHSGeometry,
1148 /* pfnQueryRegions */
1149 parallelsQueryRegions,
1150 /* pfnRegionListRelease */
1151 parallelsRegionListRelease,
1152 /* pfnGetImageFlags */
1153 parallelsGetImageFlags,
1154 /* pfnGetOpenFlags */
1155 parallelsGetOpenFlags,
1156 /* pfnSetOpenFlags */
1157 parallelsSetOpenFlags,
1158 /* pfnGetComment */
1159 parallelsGetComment,
1160 /* pfnSetComment */
1161 parallelsSetComment,
1162 /* pfnGetUuid */
1163 parallelsGetUuid,
1164 /* pfnSetUuid */
1165 parallelsSetUuid,
1166 /* pfnGetModificationUuid */
1167 parallelsGetModificationUuid,
1168 /* pfnSetModificationUuid */
1169 parallelsSetModificationUuid,
1170 /* pfnGetParentUuid */
1171 parallelsGetParentUuid,
1172 /* pfnSetParentUuid */
1173 parallelsSetParentUuid,
1174 /* pfnGetParentModificationUuid */
1175 parallelsGetParentModificationUuid,
1176 /* pfnSetParentModificationUuid */
1177 parallelsSetParentModificationUuid,
1178 /* pfnDump */
1179 parallelsDump,
1180 /* pfnGetTimestamp */
1181 NULL,
1182 /* pfnGetParentTimestamp */
1183 NULL,
1184 /* pfnSetParentTimestamp */
1185 NULL,
1186 /* pfnGetParentFilename */
1187 NULL,
1188 /* pfnSetParentFilename */
1189 NULL,
1190 /* pfnComposeLocation */
1191 genericFileComposeLocation,
1192 /* pfnComposeName */
1193 genericFileComposeName,
1194 /* pfnCompact */
1195 NULL,
1196 /* pfnResize */
1197 NULL,
1198 /* pfnRepair */
1199 NULL,
1200 /* pfnTraverseMetadata */
1201 NULL,
1202 /* u32VersionEnd */
1203 VD_IMGBACKEND_VERSION
1204};
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