VirtualBox

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

Last change on this file since 45012 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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