VirtualBox

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

Last change on this file since 53369 was 50988, checked in by vboxsync, 11 years ago

Storage/VD: Cleanup VD plugin handling. One shared object can now support an arbitrary number of image backends instead of just one like before

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