VirtualBox

source: vbox/trunk/src/VBox/Storage/RAW.cpp@ 106579

Last change on this file since 106579 was 106061, checked in by vboxsync, 3 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: 45.4 KB
Line 
1/* $Id: RAW.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * RawHDDCore - Raw Disk image, Core Code.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_VD_RAW
33#include <VBox/vd-plugin.h>
34#include <VBox/err.h>
35
36#include <VBox/log.h>
37#include <iprt/assert.h>
38#include <iprt/alloc.h>
39#include <iprt/path.h>
40#include <iprt/formats/iso9660.h>
41#include <iprt/formats/udf.h>
42
43#include "VDBackends.h"
44#include "VDBackendsInline.h"
45
46
47/*********************************************************************************************************************************
48* Constants And Macros, Structures and Typedefs *
49*********************************************************************************************************************************/
50
51/**
52 * Raw image data structure.
53 */
54typedef struct RAWIMAGE
55{
56 /** Image name. */
57 const char *pszFilename;
58 /** Storage handle. */
59 PVDIOSTORAGE pStorage;
60
61 /** Pointer to the per-disk VD interface list. */
62 PVDINTERFACE pVDIfsDisk;
63 /** Pointer to the per-image VD interface list. */
64 PVDINTERFACE pVDIfsImage;
65 /** Error interface. */
66 PVDINTERFACEERROR pIfError;
67 /** I/O interface. */
68 PVDINTERFACEIOINT pIfIo;
69
70 /** Open flags passed by VBoxHD layer. */
71 unsigned uOpenFlags;
72 /** Image flags defined during creation or determined during open. */
73 unsigned uImageFlags;
74 /** Total size of the image. */
75 uint64_t cbSize;
76 /** Position in the image (only truly used for sequential access). */
77 uint64_t offAccess;
78 /** Flag if this is a newly created image. */
79 bool fCreate;
80 /** Physical geometry of this image. */
81 VDGEOMETRY PCHSGeometry;
82 /** Logical geometry of this image. */
83 VDGEOMETRY LCHSGeometry;
84 /** Sector size of the image. */
85 uint32_t cbSector;
86 /** The static region list. */
87 VDREGIONLIST RegionList;
88} RAWIMAGE, *PRAWIMAGE;
89
90
91/** Size of write operations when filling an image with zeroes. */
92#define RAW_FILL_SIZE (128 * _1K)
93
94#if 1
95/** The maximum reasonable size of a floppy image - (fake 63.5MB valkit floppies). */
96# define RAW_MAX_FLOPPY_IMG_SIZE (255 * 2 * 255 * 512)
97#else
98/** The maximum reasonable size of a floppy image (big format 2.88MB medium). */
99# define RAW_MAX_FLOPPY_IMG_SIZE (512 * 82 * 48 * 2)
100#endif
101
102
103/*********************************************************************************************************************************
104* Static Variables *
105*********************************************************************************************************************************/
106
107/** NULL-terminated array of supported file extensions. */
108static const VDFILEEXTENSION s_aRawFileExtensions[] =
109{
110 {"iso", VDTYPE_OPTICAL_DISC},
111 {"cdr", VDTYPE_OPTICAL_DISC},
112 {"img", VDTYPE_FLOPPY},
113 {"ima", VDTYPE_FLOPPY},
114 {"dsk", VDTYPE_FLOPPY},
115 {"flp", VDTYPE_FLOPPY},
116 {"vfd", VDTYPE_FLOPPY},
117 {NULL, VDTYPE_INVALID}
118};
119
120
121/*********************************************************************************************************************************
122* Internal Functions *
123*********************************************************************************************************************************/
124
125/**
126 * Internal. Flush image data to disk.
127 */
128static int rawFlushImage(PRAWIMAGE pImage)
129{
130 int rc = VINF_SUCCESS;
131
132 if ( pImage->pStorage
133 && !(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
134 rc = vdIfIoIntFileFlushSync(pImage->pIfIo, pImage->pStorage);
135
136 return rc;
137}
138
139/**
140 * Internal. Free all allocated space for representing an image except pImage,
141 * and optionally delete the image from disk.
142 */
143static int rawFreeImage(PRAWIMAGE pImage, bool fDelete)
144{
145 int rc = VINF_SUCCESS;
146
147 /* Freeing a never allocated image (e.g. because the open failed) is
148 * not signalled as an error. After all nothing bad happens. */
149 if (pImage)
150 {
151 if (pImage->pStorage)
152 {
153 /* No point updating the file that is deleted anyway. */
154 if (!fDelete)
155 {
156 /* For newly created images in sequential mode fill it to
157 * the nominal size. */
158 if ( pImage->uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL
159 && !(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
160 && pImage->fCreate)
161 {
162 /* Fill rest of image with zeroes, a must for sequential
163 * images to reach the nominal size. */
164 uint64_t uOff;
165 void *pvBuf = RTMemTmpAllocZ(RAW_FILL_SIZE);
166 if (RT_LIKELY(pvBuf))
167 {
168 uOff = pImage->offAccess;
169 /* Write data to all image blocks. */
170 while (uOff < pImage->cbSize)
171 {
172 unsigned cbChunk = (unsigned)RT_MIN(pImage->cbSize - uOff,
173 RAW_FILL_SIZE);
174
175 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage,
176 uOff, pvBuf, cbChunk);
177 if (RT_FAILURE(rc))
178 break;
179
180 uOff += cbChunk;
181 }
182
183 RTMemTmpFree(pvBuf);
184 }
185 else
186 rc = VERR_NO_MEMORY;
187 }
188 rawFlushImage(pImage);
189 }
190
191 rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
192 pImage->pStorage = NULL;
193 }
194
195 if (fDelete && pImage->pszFilename)
196 vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename);
197 }
198
199 LogFlowFunc(("returns %Rrc\n", rc));
200 return rc;
201}
202
203/**
204 * Internal: Open an image, constructing all necessary data structures.
205 */
206static int rawOpenImage(PRAWIMAGE pImage, unsigned uOpenFlags)
207{
208 pImage->uOpenFlags = uOpenFlags;
209 pImage->fCreate = false;
210
211 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
212 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
213 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
214
215 /* Open the image. */
216 int rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename,
217 VDOpenFlagsToFileOpenFlags(uOpenFlags,
218 false /* fCreate */),
219 &pImage->pStorage);
220 if (RT_SUCCESS(rc))
221 {
222 rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &pImage->cbSize);
223 if ( RT_SUCCESS(rc)
224 && !(pImage->cbSize % 512))
225 pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED;
226 else if (RT_SUCCESS(rc))
227 rc = VERR_VD_RAW_SIZE_MODULO_512;
228 }
229 /* else: Do NOT signal an appropriate error here, as the VD layer has the
230 * choice of retrying the open if it failed. */
231
232 if (RT_SUCCESS(rc))
233 {
234 PVDREGIONDESC pRegion = &pImage->RegionList.aRegions[0];
235 pImage->RegionList.fFlags = 0;
236 pImage->RegionList.cRegions = 1;
237
238 pRegion->offRegion = 0; /* Disk start. */
239 pRegion->cbBlock = pImage->cbSector;
240 pRegion->enmDataForm = VDREGIONDATAFORM_RAW;
241 pRegion->enmMetadataForm = VDREGIONMETADATAFORM_NONE;
242 pRegion->cbData = pImage->cbSector;
243 pRegion->cbMetadata = 0;
244 pRegion->cRegionBlocksOrBytes = pImage->cbSize;
245 }
246 else
247 rawFreeImage(pImage, false);
248 return rc;
249}
250
251/**
252 * Internal: Create a raw image.
253 */
254static int rawCreateImage(PRAWIMAGE pImage, uint64_t cbSize,
255 unsigned uImageFlags, const char *pszComment,
256 PCVDGEOMETRY pPCHSGeometry,
257 PCVDGEOMETRY pLCHSGeometry, unsigned uOpenFlags,
258 PVDINTERFACEPROGRESS pIfProgress,
259 unsigned uPercentStart, unsigned uPercentSpan)
260{
261 RT_NOREF1(pszComment);
262 int rc = VINF_SUCCESS;
263
264 pImage->fCreate = true;
265 pImage->uOpenFlags = uOpenFlags & ~VD_OPEN_FLAGS_READONLY;
266 pImage->uImageFlags = uImageFlags | VD_IMAGE_FLAGS_FIXED;
267 pImage->PCHSGeometry = *pPCHSGeometry;
268 pImage->LCHSGeometry = *pLCHSGeometry;
269 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
270 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
271 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
272
273 if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_DIFF))
274 {
275 /* Create image file. */
276 uint32_t fOpen = VDOpenFlagsToFileOpenFlags(pImage->uOpenFlags, true /* fCreate */);
277 if (uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL)
278 fOpen &= ~RTFILE_O_READ;
279 rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename, fOpen, &pImage->pStorage);
280 if (RT_SUCCESS(rc))
281 {
282 if (!(uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL))
283 {
284 RTFOFF cbFree = 0;
285
286 /* Check the free space on the disk and leave early if there is not
287 * sufficient space available. */
288 rc = vdIfIoIntFileGetFreeSpace(pImage->pIfIo, pImage->pszFilename, &cbFree);
289 if (RT_FAILURE(rc) /* ignore errors */ || ((uint64_t)cbFree >= cbSize))
290 {
291 rc = vdIfIoIntFileSetAllocationSize(pImage->pIfIo, pImage->pStorage, cbSize, 0 /* fFlags */,
292 pIfProgress, uPercentStart, uPercentSpan);
293 if (RT_SUCCESS(rc))
294 {
295 vdIfProgress(pIfProgress, uPercentStart + uPercentSpan * 98 / 100);
296
297 pImage->cbSize = cbSize;
298 rc = rawFlushImage(pImage);
299 }
300 }
301 else
302 rc = vdIfError(pImage->pIfError, VERR_DISK_FULL, RT_SRC_POS, N_("Raw: disk would overflow creating image '%s'"), pImage->pszFilename);
303 }
304 else
305 {
306 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, cbSize);
307 if (RT_SUCCESS(rc))
308 pImage->cbSize = cbSize;
309 }
310 }
311 else
312 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: cannot create image '%s'"), pImage->pszFilename);
313 }
314 else
315 rc = vdIfError(pImage->pIfError, VERR_VD_RAW_INVALID_TYPE, RT_SRC_POS, N_("Raw: cannot create diff image '%s'"), pImage->pszFilename);
316
317 if (RT_SUCCESS(rc))
318 {
319 PVDREGIONDESC pRegion = &pImage->RegionList.aRegions[0];
320 pImage->RegionList.fFlags = 0;
321 pImage->RegionList.cRegions = 1;
322
323 pRegion->offRegion = 0; /* Disk start. */
324 pRegion->cbBlock = pImage->cbSector;
325 pRegion->enmDataForm = VDREGIONDATAFORM_RAW;
326 pRegion->enmMetadataForm = VDREGIONMETADATAFORM_NONE;
327 pRegion->cbData = pImage->cbSector;
328 pRegion->cbMetadata = 0;
329 pRegion->cRegionBlocksOrBytes = pImage->cbSize;
330
331 vdIfProgress(pIfProgress, uPercentStart + uPercentSpan);
332 }
333
334 if (RT_FAILURE(rc))
335 rawFreeImage(pImage, rc != VERR_ALREADY_EXISTS);
336 return rc;
337}
338
339/**
340 * Worker for rawProbe that checks if the file looks like it contains an ISO
341 * 9660 or UDF descriptor sequence at the expected offset.
342 *
343 * Caller already checked if the size is suitable for ISOs.
344 *
345 * @returns IPRT status code. Success if detected ISO 9660 or UDF, failure if
346 * not.
347 *
348 * @note Code is a modified version of rtFsIsoVolTryInit() IPRT (isovfs.cpp).
349 */
350static int rawProbeIsIso9660OrUdf(PVDINTERFACEIOINT pIfIo, PVDIOSTORAGE pStorage)
351{
352 PRTERRINFO pErrInfo = NULL;
353 const uint32_t cbSector = _2K;
354
355 union
356 {
357 uint8_t ab[_2K];
358 ISO9660VOLDESCHDR VolDescHdr;
359 } Buf;
360 Assert(cbSector <= sizeof(Buf));
361 RT_ZERO(Buf);
362
363 uint8_t uUdfLevel = 0;
364 uint64_t offUdfBootVolDesc = UINT64_MAX;
365
366 uint32_t cPrimaryVolDescs = 0;
367 uint32_t cSupplementaryVolDescs = 0;
368 uint32_t cBootRecordVolDescs = 0;
369 uint32_t offVolDesc = 16 * cbSector;
370 enum
371 {
372 kStateStart = 0,
373 kStateNoSeq,
374 kStateCdSeq,
375 kStateUdfSeq
376 } enmState = kStateStart;
377 for (uint32_t iVolDesc = 0; ; iVolDesc++, offVolDesc += cbSector)
378 {
379 if (iVolDesc > 32)
380 return RTERRINFO_LOG_SET(pErrInfo, VERR_VFS_BOGUS_FORMAT, "More than 32 volume descriptors, doesn't seem right...");
381
382 /* Read the next one and check the signature. */
383 int rc = vdIfIoIntFileReadSync(pIfIo, pStorage, offVolDesc, &Buf, cbSector);
384 if (RT_FAILURE(rc))
385 return RTERRINFO_LOG_SET_F(pErrInfo, rc, "Unable to read volume descriptor #%u", iVolDesc);
386
387#define MATCH_STD_ID(a_achStdId1, a_szStdId2) \
388 ( (a_achStdId1)[0] == (a_szStdId2)[0] \
389 && (a_achStdId1)[1] == (a_szStdId2)[1] \
390 && (a_achStdId1)[2] == (a_szStdId2)[2] \
391 && (a_achStdId1)[3] == (a_szStdId2)[3] \
392 && (a_achStdId1)[4] == (a_szStdId2)[4] )
393#define MATCH_HDR(a_pStd, a_bType2, a_szStdId2, a_bVer2) \
394 ( MATCH_STD_ID((a_pStd)->achStdId, a_szStdId2) \
395 && (a_pStd)->bDescType == (a_bType2) \
396 && (a_pStd)->bDescVersion == (a_bVer2) )
397
398 /*
399 * ISO 9660 ("CD001").
400 */
401 if ( ( enmState == kStateStart
402 || enmState == kStateCdSeq
403 || enmState == kStateNoSeq)
404 && MATCH_STD_ID(Buf.VolDescHdr.achStdId, ISO9660VOLDESC_STD_ID) )
405 {
406 enmState = kStateCdSeq;
407
408 /* Do type specific handling. */
409 Log(("RAW/ISO9660: volume desc #%u: type=%#x\n", iVolDesc, Buf.VolDescHdr.bDescType));
410 if (Buf.VolDescHdr.bDescType == ISO9660VOLDESC_TYPE_PRIMARY)
411 {
412 cPrimaryVolDescs++;
413 if (Buf.VolDescHdr.bDescVersion != ISO9660PRIMARYVOLDESC_VERSION)
414 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_UNSUPPORTED_FORMAT,
415 "Unsupported primary volume descriptor version: %#x", Buf.VolDescHdr.bDescVersion);
416 if (cPrimaryVolDescs == 1)
417 { /*rc = rtFsIsoVolHandlePrimaryVolDesc(pThis, &Buf.PrimaryVolDesc, offVolDesc, &RootDir, &offRootDirRec, pErrInfo);*/ }
418 else if (cPrimaryVolDescs == 2)
419 Log(("RAW/ISO9660: ignoring 2nd primary descriptor\n")); /* so we can read the w2k3 ifs kit */
420 else
421 return RTERRINFO_LOG_SET(pErrInfo, VERR_VFS_UNSUPPORTED_FORMAT, "More than one primary volume descriptor");
422 }
423 else if (Buf.VolDescHdr.bDescType == ISO9660VOLDESC_TYPE_SUPPLEMENTARY)
424 {
425 cSupplementaryVolDescs++;
426 if (Buf.VolDescHdr.bDescVersion != ISO9660SUPVOLDESC_VERSION)
427 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_UNSUPPORTED_FORMAT,
428 "Unsupported supplemental volume descriptor version: %#x", Buf.VolDescHdr.bDescVersion);
429 /*rc = rtFsIsoVolHandleSupplementaryVolDesc(pThis, &Buf.SupVolDesc, offVolDesc, &bJolietUcs2Level, &JolietRootDir,
430 &offJolietRootDirRec, pErrInfo);*/
431 }
432 else if (Buf.VolDescHdr.bDescType == ISO9660VOLDESC_TYPE_BOOT_RECORD)
433 {
434 cBootRecordVolDescs++;
435 }
436 else if (Buf.VolDescHdr.bDescType == ISO9660VOLDESC_TYPE_TERMINATOR)
437 {
438 if (!cPrimaryVolDescs)
439 return RTERRINFO_LOG_SET(pErrInfo, VERR_VFS_BOGUS_FORMAT, "No primary volume descriptor");
440 enmState = kStateNoSeq;
441 }
442 else
443 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_UNSUPPORTED_FORMAT,
444 "Unknown volume descriptor: %#x", Buf.VolDescHdr.bDescType);
445 }
446 /*
447 * UDF volume recognition sequence (VRS).
448 */
449 else if ( ( enmState == kStateNoSeq
450 || enmState == kStateStart)
451 && MATCH_HDR(&Buf.VolDescHdr, UDF_EXT_VOL_DESC_TYPE, UDF_EXT_VOL_DESC_STD_ID_BEGIN, UDF_EXT_VOL_DESC_VERSION) )
452 {
453 if (uUdfLevel == 0)
454 enmState = kStateUdfSeq;
455 else
456 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_BOGUS_FORMAT, "Only one BEA01 sequence is supported");
457 }
458 else if ( enmState == kStateUdfSeq
459 && MATCH_HDR(&Buf.VolDescHdr, UDF_EXT_VOL_DESC_TYPE, UDF_EXT_VOL_DESC_STD_ID_NSR_02, UDF_EXT_VOL_DESC_VERSION) )
460 uUdfLevel = 2;
461 else if ( enmState == kStateUdfSeq
462 && MATCH_HDR(&Buf.VolDescHdr, UDF_EXT_VOL_DESC_TYPE, UDF_EXT_VOL_DESC_STD_ID_NSR_03, UDF_EXT_VOL_DESC_VERSION) )
463 uUdfLevel = 3;
464 else if ( enmState == kStateUdfSeq
465 && MATCH_HDR(&Buf.VolDescHdr, UDF_EXT_VOL_DESC_TYPE, UDF_EXT_VOL_DESC_STD_ID_BOOT, UDF_EXT_VOL_DESC_VERSION) )
466 {
467 if (offUdfBootVolDesc == UINT64_MAX)
468 offUdfBootVolDesc = iVolDesc * cbSector;
469 else
470 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_BOGUS_FORMAT, "Only one BOOT2 descriptor is supported");
471 }
472 else if ( enmState == kStateUdfSeq
473 && MATCH_HDR(&Buf.VolDescHdr, UDF_EXT_VOL_DESC_TYPE, UDF_EXT_VOL_DESC_STD_ID_TERM, UDF_EXT_VOL_DESC_VERSION) )
474 {
475 if (uUdfLevel != 0)
476 enmState = kStateNoSeq;
477 else
478 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_BOGUS_FORMAT, "Found BEA01 & TEA01, but no NSR02 or NSR03 descriptors");
479 }
480 /*
481 * Unknown, probably the end.
482 */
483 else if (enmState == kStateNoSeq)
484 break;
485 else if (enmState == kStateStart)
486 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_UNKNOWN_FORMAT,
487 "Not ISO? Unable to recognize volume descriptor signature: %.5Rhxs", Buf.VolDescHdr.achStdId);
488 else if (enmState == kStateCdSeq)
489 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_BOGUS_FORMAT,
490 "Missing ISO 9660 terminator volume descriptor? (Found %.5Rhxs)", Buf.VolDescHdr.achStdId);
491 else if (enmState == kStateUdfSeq)
492 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_BOGUS_FORMAT,
493 "Missing UDF terminator volume descriptor? (Found %.5Rhxs)", Buf.VolDescHdr.achStdId);
494 else
495 return RTERRINFO_LOG_SET_F(pErrInfo, VERR_VFS_UNKNOWN_FORMAT,
496 "Unknown volume descriptor signature found at sector %u: %.5Rhxs",
497 16 + iVolDesc, Buf.VolDescHdr.achStdId);
498 }
499
500 return VINF_SUCCESS;
501}
502
503/**
504 * Checks the given extension array for the given suffix and type.
505 *
506 * @returns true if found in the list, false if not.
507 * @param paExtensions The extension array to check against.
508 * @param pszSuffix The suffix to look for. Can be NULL.
509 * @param enmType The image type to look for.
510 */
511static bool rawProbeContainsExtension(const VDFILEEXTENSION *paExtensions, const char *pszSuffix, VDTYPE enmType)
512{
513 if (pszSuffix)
514 {
515 if (*pszSuffix == '.')
516 pszSuffix++;
517 if (*pszSuffix != '\0')
518 {
519 for (size_t i = 0;; i++)
520 {
521 if (!paExtensions[i].pszExtension)
522 break;
523 if ( paExtensions[i].enmType == enmType
524 && RTStrICmpAscii(paExtensions[i].pszExtension, pszSuffix) == 0)
525 return true;
526 }
527 }
528 }
529 return false;
530}
531
532
533/** @copydoc VDIMAGEBACKEND::pfnProbe */
534static DECLCALLBACK(int) rawProbe(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
535 PVDINTERFACE pVDIfsImage, VDTYPE enmDesiredType, VDTYPE *penmType)
536{
537 RT_NOREF(pVDIfsDisk, enmDesiredType);
538 LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p\n", pszFilename, pVDIfsDisk, pVDIfsImage));
539 PVDIOSTORAGE pStorage = NULL;
540 PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
541
542 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
543 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
544 AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
545
546 /*
547 * Open the file and read the footer.
548 */
549 int rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
550 VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
551 false /* fCreate */),
552 &pStorage);
553 if (RT_SUCCESS(rc))
554 {
555 uint64_t cbFile;
556 rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
557 if (RT_SUCCESS(rc))
558 {
559 /*
560 * Detecting raw ISO and floppy images and keeping them apart isn't all
561 * that simple.
562 *
563 * - Both must be a multiple of their sector sizes, though
564 * that means that any ISO can also be a floppy, since 2048 is 512 * 4.
565 * - The ISO images must be 32KB and floppies are generally not larger
566 * than 2.88MB, but that leaves quite a bit of size overlap,
567 *
568 * So, the size cannot conclusively say whether something is one or the other.
569 *
570 * - The content of a normal ISO image is detectable, but not all ISO
571 * images need to follow that spec to work in a DVD ROM drive.
572 * - It is common for ISO images to start like a floppy with a boot sector
573 * at the very start of the image.
574 * - Floppies doesn't need to contain a DOS-style boot sector, it depends
575 * on the system it is formatted and/or intended for.
576 *
577 * So, the content cannot conclusively determine the type either.
578 *
579 * However, there are a number of cases, especially for ISOs, where we can
580 * say we a deal of confidence that something is an ISO image.
581 */
582 const char * const pszSuffix = RTPathSuffix(pszFilename);
583
584 /*
585 * Start by checking for sure signs of an ISO 9660 / UDF image.
586 */
587 rc = VERR_VD_RAW_INVALID_HEADER;
588 if ( (enmDesiredType == VDTYPE_INVALID || enmDesiredType == VDTYPE_OPTICAL_DISC)
589 && (cbFile % 2048) == 0
590 && cbFile > 32768)
591 {
592 int rc2 = rawProbeIsIso9660OrUdf(pIfIo, pStorage);
593 if (RT_SUCCESS(rc2))
594 {
595 /* *puScore = VDPROBE_SCORE_HIGH; */
596 *penmType = VDTYPE_OPTICAL_DISC;
597 rc = VINF_SUCCESS;
598 }
599 /* If that didn't work out, check by extension (the old way): */
600 else if (rawProbeContainsExtension(s_aRawFileExtensions, pszSuffix, VDTYPE_OPTICAL_DISC))
601 {
602 /* *puScore = VDPROBE_SCORE_LOW; */
603 *penmType = VDTYPE_OPTICAL_DISC;
604 rc = VINF_SUCCESS;
605 }
606 }
607
608 /*
609 * We could do something similar for floppies, i.e. check for a
610 * DOS'ish boot sector and thereby get a good match on most of the
611 * relevant floppy images out there.
612 */
613 if ( RT_FAILURE(rc)
614 && (enmDesiredType == VDTYPE_INVALID || enmDesiredType == VDTYPE_FLOPPY)
615 && (cbFile % 512) == 0
616 && cbFile >= 512
617 && cbFile <= RAW_MAX_FLOPPY_IMG_SIZE)
618 {
619 /** @todo check if the content is DOSish. */
620 if (false)
621 {
622 /* *puScore = VDPROBE_SCORE_HIGH; */
623 *penmType = VDTYPE_FLOPPY;
624 rc = VINF_SUCCESS;
625 }
626 else if (rawProbeContainsExtension(s_aRawFileExtensions, pszSuffix, VDTYPE_FLOPPY))
627 {
628 /* *puScore = VDPROBE_SCORE_LOW; */
629 *penmType = VDTYPE_FLOPPY;
630 rc = VINF_SUCCESS;
631 }
632 }
633
634 /*
635 * No luck? Go exclusively by extension like we've done since
636 * for ever and complain about the size if it doesn't fit expectations.
637 * We can get here if the desired type doesn't match the extension and such.
638 */
639 if (RT_FAILURE(rc))
640 {
641 if (rawProbeContainsExtension(s_aRawFileExtensions, pszSuffix, VDTYPE_OPTICAL_DISC))
642 {
643 if (cbFile % 2048)
644 rc = VERR_VD_RAW_SIZE_MODULO_2048;
645 else if (cbFile <= 32768)
646 rc = VERR_VD_RAW_SIZE_OPTICAL_TOO_SMALL;
647 else
648 {
649 Assert(enmDesiredType != VDTYPE_OPTICAL_DISC);
650 *penmType = VDTYPE_OPTICAL_DISC;
651 rc = VINF_SUCCESS;
652 }
653 }
654 else if (rawProbeContainsExtension(s_aRawFileExtensions, pszSuffix, VDTYPE_FLOPPY))
655 {
656 if (cbFile % 512)
657 rc = VERR_VD_RAW_SIZE_MODULO_512;
658 else if (cbFile > RAW_MAX_FLOPPY_IMG_SIZE)
659 rc = VERR_VD_RAW_SIZE_FLOPPY_TOO_BIG;
660 else
661 {
662 Assert(cbFile == 0 || enmDesiredType != VDTYPE_FLOPPY);
663 *penmType = VDTYPE_FLOPPY;
664 rc = VINF_SUCCESS;
665 }
666 }
667 else
668 rc = VERR_VD_RAW_INVALID_HEADER;
669 }
670 }
671 else
672 rc = VERR_VD_RAW_INVALID_HEADER;
673 }
674
675 if (pStorage)
676 vdIfIoIntFileClose(pIfIo, pStorage);
677
678 LogFlowFunc(("returns %Rrc\n", rc));
679 return rc;
680}
681
682/** @copydoc VDIMAGEBACKEND::pfnOpen */
683static DECLCALLBACK(int) rawOpen(const char *pszFilename, unsigned uOpenFlags,
684 PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
685 VDTYPE enmType, void **ppBackendData)
686{
687 LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p enmType=%u ppBackendData=%#p\n",
688 pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
689 int rc;
690 PRAWIMAGE pImage;
691
692 /* Check open flags. All valid flags are supported. */
693 AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
694 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
695 AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
696
697 pImage = (PRAWIMAGE)RTMemAllocZ(RT_UOFFSETOF(RAWIMAGE, RegionList.aRegions[1]));
698 if (RT_LIKELY(pImage))
699 {
700 pImage->pszFilename = pszFilename;
701 pImage->pStorage = NULL;
702 pImage->pVDIfsDisk = pVDIfsDisk;
703 pImage->pVDIfsImage = pVDIfsImage;
704
705 if (enmType == VDTYPE_OPTICAL_DISC)
706 pImage->cbSector = 2048;
707 else
708 pImage->cbSector = 512;
709
710 rc = rawOpenImage(pImage, uOpenFlags);
711 if (RT_SUCCESS(rc))
712 *ppBackendData = pImage;
713 else
714 RTMemFree(pImage);
715 }
716 else
717 rc = VERR_NO_MEMORY;
718
719 LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
720 return rc;
721}
722
723/** @copydoc VDIMAGEBACKEND::pfnCreate */
724static DECLCALLBACK(int) rawCreate(const char *pszFilename, uint64_t cbSize,
725 unsigned uImageFlags, const char *pszComment,
726 PCVDGEOMETRY pPCHSGeometry, PCVDGEOMETRY pLCHSGeometry,
727 PCRTUUID pUuid, unsigned uOpenFlags,
728 unsigned uPercentStart, unsigned uPercentSpan,
729 PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
730 PVDINTERFACE pVDIfsOperation, VDTYPE enmType,
731 void **ppBackendData)
732{
733 RT_NOREF1(pUuid);
734 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",
735 pszFilename, cbSize, uImageFlags, pszComment, pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, uPercentStart, uPercentSpan, pVDIfsDisk, pVDIfsImage, pVDIfsOperation, enmType, ppBackendData));
736
737 /* Check the VD container type. Yes, hard disk must be allowed, otherwise
738 * various tools using this backend for hard disk images will fail. */
739 if (enmType != VDTYPE_HDD && enmType != VDTYPE_OPTICAL_DISC && enmType != VDTYPE_FLOPPY)
740 return VERR_VD_INVALID_TYPE;
741
742 int rc = VINF_SUCCESS;
743 PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation);
744
745 /* Check arguments. */
746 AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
747 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
748 AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
749 AssertPtrReturn(pPCHSGeometry, VERR_INVALID_POINTER);
750 AssertPtrReturn(pLCHSGeometry, VERR_INVALID_POINTER);
751
752 PRAWIMAGE pImage = (PRAWIMAGE)RTMemAllocZ(RT_UOFFSETOF(RAWIMAGE, RegionList.aRegions[1]));
753 if (RT_LIKELY(pImage))
754 {
755 pImage->pszFilename = pszFilename;
756 pImage->pStorage = NULL;
757 pImage->pVDIfsDisk = pVDIfsDisk;
758 pImage->pVDIfsImage = pVDIfsImage;
759
760 rc = rawCreateImage(pImage, cbSize, uImageFlags, pszComment,
761 pPCHSGeometry, pLCHSGeometry, uOpenFlags,
762 pIfProgress, uPercentStart, uPercentSpan);
763 if (RT_SUCCESS(rc))
764 {
765 /* So far the image is opened in read/write mode. Make sure the
766 * image is opened in read-only mode if the caller requested that. */
767 if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
768 {
769 rawFreeImage(pImage, false);
770 rc = rawOpenImage(pImage, uOpenFlags);
771 }
772
773 if (RT_SUCCESS(rc))
774 *ppBackendData = pImage;
775 }
776
777 if (RT_FAILURE(rc))
778 RTMemFree(pImage);
779 }
780 else
781 rc = VERR_NO_MEMORY;
782
783 LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
784 return rc;
785}
786
787/** @copydoc VDIMAGEBACKEND::pfnRename */
788static DECLCALLBACK(int) rawRename(void *pBackendData, const char *pszFilename)
789{
790 LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
791 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
792
793 AssertReturn((pImage && pszFilename && *pszFilename), VERR_INVALID_PARAMETER);
794
795 /* Close the image. */
796 int rc = rawFreeImage(pImage, false);
797 if (RT_SUCCESS(rc))
798 {
799 /* Rename the file. */
800 rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
801 if (RT_SUCCESS(rc))
802 {
803 /* Update pImage with the new information. */
804 pImage->pszFilename = pszFilename;
805
806 /* Open the old image with new name. */
807 rc = rawOpenImage(pImage, pImage->uOpenFlags);
808 }
809 else
810 {
811 /* The move failed, try to reopen the original image. */
812 int rc2 = rawOpenImage(pImage, pImage->uOpenFlags);
813 if (RT_FAILURE(rc2))
814 rc = rc2;
815 }
816 }
817
818 LogFlowFunc(("returns %Rrc\n", rc));
819 return rc;
820}
821
822/** @copydoc VDIMAGEBACKEND::pfnClose */
823static DECLCALLBACK(int) rawClose(void *pBackendData, bool fDelete)
824{
825 LogFlowFunc(("pBackendData=%#p fDelete=%d\n", pBackendData, fDelete));
826 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
827 int rc = rawFreeImage(pImage, fDelete);
828 RTMemFree(pImage);
829
830 LogFlowFunc(("returns %Rrc\n", rc));
831 return rc;
832}
833
834/** @copydoc VDIMAGEBACKEND::pfnRead */
835static DECLCALLBACK(int) rawRead(void *pBackendData, uint64_t uOffset, size_t cbToRead,
836 PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
837{
838 int rc = VINF_SUCCESS;
839 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
840
841 /* For sequential access do not allow to go back. */
842 if ( pImage->uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL
843 && uOffset < pImage->offAccess)
844 {
845 *pcbActuallyRead = 0;
846 return VERR_INVALID_PARAMETER;
847 }
848
849 rc = vdIfIoIntFileReadUser(pImage->pIfIo, pImage->pStorage, uOffset,
850 pIoCtx, cbToRead);
851 if (RT_SUCCESS(rc))
852 {
853 *pcbActuallyRead = cbToRead;
854 pImage->offAccess = uOffset + cbToRead;
855 }
856
857 return rc;
858}
859
860/** @copydoc VDIMAGEBACKEND::pfnWrite */
861static DECLCALLBACK(int) rawWrite(void *pBackendData, uint64_t uOffset, size_t cbToWrite,
862 PVDIOCTX pIoCtx, size_t *pcbWriteProcess, size_t *pcbPreRead,
863 size_t *pcbPostRead, unsigned fWrite)
864{
865 RT_NOREF1(fWrite);
866 int rc = VINF_SUCCESS;
867 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
868
869 /* For sequential access do not allow to go back. */
870 if ( pImage->uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL
871 && uOffset < pImage->offAccess)
872 {
873 *pcbWriteProcess = 0;
874 *pcbPostRead = 0;
875 *pcbPreRead = 0;
876 return VERR_INVALID_PARAMETER;
877 }
878
879 rc = vdIfIoIntFileWriteUser(pImage->pIfIo, pImage->pStorage, uOffset,
880 pIoCtx, cbToWrite, NULL, NULL);
881 if (RT_SUCCESS(rc))
882 {
883 *pcbWriteProcess = cbToWrite;
884 *pcbPostRead = 0;
885 *pcbPreRead = 0;
886 pImage->offAccess = uOffset + cbToWrite;
887 }
888
889 return rc;
890}
891
892/** @copydoc VDIMAGEBACKEND::pfnFlush */
893static DECLCALLBACK(int) rawFlush(void *pBackendData, PVDIOCTX pIoCtx)
894{
895 int rc = VINF_SUCCESS;
896 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
897
898 if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
899 rc = vdIfIoIntFileFlush(pImage->pIfIo, pImage->pStorage, pIoCtx,
900 NULL, NULL);
901
902 return rc;
903}
904
905/** @copydoc VDIMAGEBACKEND::pfnGetVersion */
906static DECLCALLBACK(unsigned) rawGetVersion(void *pBackendData)
907{
908 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
909 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
910
911 AssertPtrReturn(pImage, 0);
912
913 return 1;
914}
915
916/** @copydoc VDIMAGEBACKEND::pfnGetFileSize */
917static DECLCALLBACK(uint64_t) rawGetFileSize(void *pBackendData)
918{
919 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
920 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
921
922 AssertPtrReturn(pImage, 0);
923
924 uint64_t cbFile = 0;
925 if (pImage->pStorage)
926 {
927 int rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile);
928 if (RT_FAILURE(rc))
929 cbFile = 0; /* Make sure it is 0 */
930 }
931
932 LogFlowFunc(("returns %lld\n", cbFile));
933 return cbFile;
934}
935
936/** @copydoc VDIMAGEBACKEND::pfnGetPCHSGeometry */
937static DECLCALLBACK(int) rawGetPCHSGeometry(void *pBackendData,
938 PVDGEOMETRY pPCHSGeometry)
939{
940 LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p\n", pBackendData, pPCHSGeometry));
941 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
942 int rc = VINF_SUCCESS;
943
944 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
945
946 if (pImage->PCHSGeometry.cCylinders)
947 *pPCHSGeometry = pImage->PCHSGeometry;
948 else
949 rc = VERR_VD_GEOMETRY_NOT_SET;
950
951 LogFlowFunc(("returns %Rrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
952 return rc;
953}
954
955/** @copydoc VDIMAGEBACKEND::pfnSetPCHSGeometry */
956static DECLCALLBACK(int) rawSetPCHSGeometry(void *pBackendData,
957 PCVDGEOMETRY pPCHSGeometry)
958{
959 LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n",
960 pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
961 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
962 int rc = VINF_SUCCESS;
963
964 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
965
966 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
967 rc = VERR_VD_IMAGE_READ_ONLY;
968 else
969 pImage->PCHSGeometry = *pPCHSGeometry;
970
971 LogFlowFunc(("returns %Rrc\n", rc));
972 return rc;
973}
974
975/** @copydoc VDIMAGEBACKEND::pfnGetLCHSGeometry */
976static DECLCALLBACK(int) rawGetLCHSGeometry(void *pBackendData,
977 PVDGEOMETRY pLCHSGeometry)
978{
979 LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
980 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
981 int rc = VINF_SUCCESS;
982
983 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
984
985 if (pImage->LCHSGeometry.cCylinders)
986 *pLCHSGeometry = pImage->LCHSGeometry;
987 else
988 rc = VERR_VD_GEOMETRY_NOT_SET;
989
990 LogFlowFunc(("returns %Rrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
991 return rc;
992}
993
994/** @copydoc VDIMAGEBACKEND::pfnSetLCHSGeometry */
995static DECLCALLBACK(int) rawSetLCHSGeometry(void *pBackendData,
996 PCVDGEOMETRY pLCHSGeometry)
997{
998 LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n",
999 pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
1000 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
1001 int rc = VINF_SUCCESS;
1002
1003 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
1004
1005 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
1006 rc = VERR_VD_IMAGE_READ_ONLY;
1007 else
1008 pImage->LCHSGeometry = *pLCHSGeometry;
1009
1010 LogFlowFunc(("returns %Rrc\n", rc));
1011 return rc;
1012}
1013
1014/** @copydoc VDIMAGEBACKEND::pfnQueryRegions */
1015static DECLCALLBACK(int) rawQueryRegions(void *pBackendData, PCVDREGIONLIST *ppRegionList)
1016{
1017 LogFlowFunc(("pBackendData=%#p ppRegionList=%#p\n", pBackendData, ppRegionList));
1018 PRAWIMAGE pThis = (PRAWIMAGE)pBackendData;
1019
1020 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
1021
1022 *ppRegionList = &pThis->RegionList;
1023 LogFlowFunc(("returns %Rrc\n", VINF_SUCCESS));
1024 return VINF_SUCCESS;
1025}
1026
1027/** @copydoc VDIMAGEBACKEND::pfnRegionListRelease */
1028static DECLCALLBACK(void) rawRegionListRelease(void *pBackendData, PCVDREGIONLIST pRegionList)
1029{
1030 RT_NOREF1(pRegionList);
1031 LogFlowFunc(("pBackendData=%#p pRegionList=%#p\n", pBackendData, pRegionList));
1032 PRAWIMAGE pThis = (PRAWIMAGE)pBackendData;
1033 AssertPtr(pThis); RT_NOREF(pThis);
1034
1035 /* Nothing to do here. */
1036}
1037
1038/** @copydoc VDIMAGEBACKEND::pfnGetImageFlags */
1039static DECLCALLBACK(unsigned) rawGetImageFlags(void *pBackendData)
1040{
1041 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
1042 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
1043
1044 AssertPtrReturn(pImage, 0);
1045
1046 LogFlowFunc(("returns %#x\n", pImage->uImageFlags));
1047 return pImage->uImageFlags;
1048}
1049
1050/** @copydoc VDIMAGEBACKEND::pfnGetOpenFlags */
1051static DECLCALLBACK(unsigned) rawGetOpenFlags(void *pBackendData)
1052{
1053 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
1054 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
1055
1056 AssertPtrReturn(pImage, 0);
1057
1058 LogFlowFunc(("returns %#x\n", pImage->uOpenFlags));
1059 return pImage->uOpenFlags;
1060}
1061
1062/** @copydoc VDIMAGEBACKEND::pfnSetOpenFlags */
1063static DECLCALLBACK(int) rawSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
1064{
1065 LogFlowFunc(("pBackendData=%#p\n uOpenFlags=%#x", pBackendData, uOpenFlags));
1066 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
1067 int rc = VINF_SUCCESS;
1068
1069 /* Image must be opened and the new flags must be valid. */
1070 if (!pImage || (uOpenFlags & ~( VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_INFO
1071 | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE
1072 | VD_OPEN_FLAGS_SEQUENTIAL | VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS)))
1073 rc = VERR_INVALID_PARAMETER;
1074 else
1075 {
1076 /* Implement this operation via reopening the image. */
1077 rc = rawFreeImage(pImage, false);
1078 if (RT_SUCCESS(rc))
1079 rc = rawOpenImage(pImage, uOpenFlags);
1080 }
1081
1082 LogFlowFunc(("returns %Rrc\n", rc));
1083 return rc;
1084}
1085
1086/** @copydoc VDIMAGEBACKEND::pfnGetComment */
1087VD_BACKEND_CALLBACK_GET_COMMENT_DEF_NOT_SUPPORTED(rawGetComment);
1088
1089/** @copydoc VDIMAGEBACKEND::pfnSetComment */
1090VD_BACKEND_CALLBACK_SET_COMMENT_DEF_NOT_SUPPORTED(rawSetComment, PRAWIMAGE);
1091
1092/** @copydoc VDIMAGEBACKEND::pfnGetUuid */
1093VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetUuid);
1094
1095/** @copydoc VDIMAGEBACKEND::pfnSetUuid */
1096VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetUuid, PRAWIMAGE);
1097
1098/** @copydoc VDIMAGEBACKEND::pfnGetModificationUuid */
1099VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetModificationUuid);
1100
1101/** @copydoc VDIMAGEBACKEND::pfnSetModificationUuid */
1102VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetModificationUuid, PRAWIMAGE);
1103
1104/** @copydoc VDIMAGEBACKEND::pfnGetParentUuid */
1105VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetParentUuid);
1106
1107/** @copydoc VDIMAGEBACKEND::pfnSetParentUuid */
1108VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetParentUuid, PRAWIMAGE);
1109
1110/** @copydoc VDIMAGEBACKEND::pfnGetParentModificationUuid */
1111VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetParentModificationUuid);
1112
1113/** @copydoc VDIMAGEBACKEND::pfnSetParentModificationUuid */
1114VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetParentModificationUuid, PRAWIMAGE);
1115
1116/** @copydoc VDIMAGEBACKEND::pfnDump */
1117static DECLCALLBACK(void) rawDump(void *pBackendData)
1118{
1119 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
1120
1121 AssertPtrReturnVoid(pImage);
1122 vdIfErrorMessage(pImage->pIfError, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u cbSector=%llu\n",
1123 pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors,
1124 pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors,
1125 pImage->cbSize / 512);
1126}
1127
1128
1129
1130const VDIMAGEBACKEND g_RawBackend =
1131{
1132 /* u32Version */
1133 VD_IMGBACKEND_VERSION,
1134 /* pszBackendName */
1135 "RAW",
1136 /* uBackendCaps */
1137 VD_CAP_CREATE_FIXED | VD_CAP_FILE | VD_CAP_ASYNC | VD_CAP_VFS,
1138 /* paFileExtensions */
1139 s_aRawFileExtensions,
1140 /* paConfigInfo */
1141 NULL,
1142 /* pfnProbe */
1143 rawProbe,
1144 /* pfnOpen */
1145 rawOpen,
1146 /* pfnCreate */
1147 rawCreate,
1148 /* pfnRename */
1149 rawRename,
1150 /* pfnClose */
1151 rawClose,
1152 /* pfnRead */
1153 rawRead,
1154 /* pfnWrite */
1155 rawWrite,
1156 /* pfnFlush */
1157 rawFlush,
1158 /* pfnDiscard */
1159 NULL,
1160 /* pfnGetVersion */
1161 rawGetVersion,
1162 /* pfnGetFileSize */
1163 rawGetFileSize,
1164 /* pfnGetPCHSGeometry */
1165 rawGetPCHSGeometry,
1166 /* pfnSetPCHSGeometry */
1167 rawSetPCHSGeometry,
1168 /* pfnGetLCHSGeometry */
1169 rawGetLCHSGeometry,
1170 /* pfnSetLCHSGeometry */
1171 rawSetLCHSGeometry,
1172 /* pfnQueryRegions */
1173 rawQueryRegions,
1174 /* pfnRegionListRelease */
1175 rawRegionListRelease,
1176 /* pfnGetImageFlags */
1177 rawGetImageFlags,
1178 /* pfnGetOpenFlags */
1179 rawGetOpenFlags,
1180 /* pfnSetOpenFlags */
1181 rawSetOpenFlags,
1182 /* pfnGetComment */
1183 rawGetComment,
1184 /* pfnSetComment */
1185 rawSetComment,
1186 /* pfnGetUuid */
1187 rawGetUuid,
1188 /* pfnSetUuid */
1189 rawSetUuid,
1190 /* pfnGetModificationUuid */
1191 rawGetModificationUuid,
1192 /* pfnSetModificationUuid */
1193 rawSetModificationUuid,
1194 /* pfnGetParentUuid */
1195 rawGetParentUuid,
1196 /* pfnSetParentUuid */
1197 rawSetParentUuid,
1198 /* pfnGetParentModificationUuid */
1199 rawGetParentModificationUuid,
1200 /* pfnSetParentModificationUuid */
1201 rawSetParentModificationUuid,
1202 /* pfnDump */
1203 rawDump,
1204 /* pfnGetTimestamp */
1205 NULL,
1206 /* pfnGetParentTimestamp */
1207 NULL,
1208 /* pfnSetParentTimestamp */
1209 NULL,
1210 /* pfnGetParentFilename */
1211 NULL,
1212 /* pfnSetParentFilename */
1213 NULL,
1214 /* pfnComposeLocation */
1215 genericFileComposeLocation,
1216 /* pfnComposeName */
1217 genericFileComposeName,
1218 /* pfnCompact */
1219 NULL,
1220 /* pfnResize */
1221 NULL,
1222 /* pfnRepair */
1223 NULL,
1224 /* pfnTraverseMetadata */
1225 NULL,
1226 /* u32VersionEnd */
1227 VD_IMGBACKEND_VERSION
1228};
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