VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 weeks 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
RevLine 
[12638]1/* $Id: RAW.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
[2358]2/** @file
[12638]3 * RawHDDCore - Raw Disk image, Core Code.
[2358]4 */
5
6/*
[106061]7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
[2358]8 *
[96407]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
[2358]26 */
27
[57358]28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
[7654]32#define LOG_GROUP LOG_GROUP_VD_RAW
[33567]33#include <VBox/vd-plugin.h>
[2358]34#include <VBox/err.h>
35
36#include <VBox/log.h>
37#include <iprt/assert.h>
38#include <iprt/alloc.h>
[33524]39#include <iprt/path.h>
[79965]40#include <iprt/formats/iso9660.h>
41#include <iprt/formats/udf.h>
[2358]42
[50988]43#include "VDBackends.h"
[66492]44#include "VDBackendsInline.h"
[50988]45
[2358]46
[57358]47/*********************************************************************************************************************************
48* Constants And Macros, Structures and Typedefs *
49*********************************************************************************************************************************/
50
[2358]51/**
[7654]52 * Raw image data structure.
[2358]53 */
[7654]54typedef struct RAWIMAGE
[2358]55{
[32536]56 /** Image name. */
[33234]57 const char *pszFilename;
[27808]58 /** Storage handle. */
[33234]59 PVDIOSTORAGE pStorage;
[2358]60
[11444]61 /** Pointer to the per-disk VD interface list. */
[33234]62 PVDINTERFACE pVDIfsDisk;
[28620]63 /** Pointer to the per-image VD interface list. */
[33234]64 PVDINTERFACE pVDIfsImage;
[38469]65 /** Error interface. */
66 PVDINTERFACEERROR pIfError;
67 /** I/O interface. */
68 PVDINTERFACEIOINT pIfIo;
[11444]69
[2358]70 /** Open flags passed by VBoxHD layer. */
[33234]71 unsigned uOpenFlags;
[2661]72 /** Image flags defined during creation or determined during open. */
[33234]73 unsigned uImageFlags;
[2358]74 /** Total size of the image. */
[33234]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;
[6291]80 /** Physical geometry of this image. */
[33234]81 VDGEOMETRY PCHSGeometry;
[6291]82 /** Logical geometry of this image. */
[33234]83 VDGEOMETRY LCHSGeometry;
[48743]84 /** Sector size of the image. */
85 uint32_t cbSector;
[66486]86 /** The static region list. */
87 VDREGIONLIST RegionList;
[7654]88} RAWIMAGE, *PRAWIMAGE;
[2358]89
[33234]90
91/** Size of write operations when filling an image with zeroes. */
92#define RAW_FILL_SIZE (128 * _1K)
93
[103227]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
[40399]98/** The maximum reasonable size of a floppy image (big format 2.88MB medium). */
[103227]99# define RAW_MAX_FLOPPY_IMG_SIZE (512 * 82 * 48 * 2)
100#endif
[33773]101
[2358]102
[57358]103/*********************************************************************************************************************************
104* Static Variables *
105*********************************************************************************************************************************/
106
[11421]107/** NULL-terminated array of supported file extensions. */
[33524]108static const VDFILEEXTENSION s_aRawFileExtensions[] =
[11421]109{
[66211]110 {"iso", VDTYPE_OPTICAL_DISC},
111 {"cdr", VDTYPE_OPTICAL_DISC},
[33524]112 {"img", VDTYPE_FLOPPY},
113 {"ima", VDTYPE_FLOPPY},
[33786]114 {"dsk", VDTYPE_FLOPPY},
[47297]115 {"flp", VDTYPE_FLOPPY},
[35045]116 {"vfd", VDTYPE_FLOPPY},
[33524]117 {NULL, VDTYPE_INVALID}
[11421]118};
119
[2358]120
[57358]121/*********************************************************************************************************************************
122* Internal Functions *
123*********************************************************************************************************************************/
124
[7155]125/**
[32536]126 * Internal. Flush image data to disk.
127 */
128static int rawFlushImage(PRAWIMAGE pImage)
[22966]129{
130 int rc = VINF_SUCCESS;
131
[32536]132 if ( pImage->pStorage
133 && !(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
[38469]134 rc = vdIfIoIntFileFlushSync(pImage->pIfIo, pImage->pStorage);
[22966]135
136 return rc;
137}
138
[32536]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)
[22966]144{
145 int rc = VINF_SUCCESS;
146
[32536]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)
[33234]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);
[63784]166 if (RT_LIKELY(pvBuf))
[33234]167 {
[63784]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);
[33234]174
[63784]175 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage,
176 uOff, pvBuf, cbChunk);
177 if (RT_FAILURE(rc))
178 break;
[33234]179
[63784]180 uOff += cbChunk;
181 }
182
183 RTMemTmpFree(pvBuf);
[33234]184 }
[63784]185 else
186 rc = VERR_NO_MEMORY;
[33234]187 }
[32536]188 rawFlushImage(pImage);
[33234]189 }
[22966]190
[46613]191 rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
[32536]192 pImage->pStorage = NULL;
193 }
194
195 if (fDelete && pImage->pszFilename)
[38469]196 vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename);
[32536]197 }
198
199 LogFlowFunc(("returns %Rrc\n", rc));
[22966]200 return rc;
201}
202
[2742]203/**
[7155]204 * Internal: Open an image, constructing all necessary data structures.
205 */
[7654]206static int rawOpenImage(PRAWIMAGE pImage, unsigned uOpenFlags)
[2358]207{
208 pImage->uOpenFlags = uOpenFlags;
[33234]209 pImage->fCreate = false;
[2358]210
[38469]211 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
212 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
213 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
[11435]214
[63784]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))
[2358]221 {
[63784]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;
[2358]228 }
[63784]229 /* else: Do NOT signal an appropriate error here, as the VD layer has the
230 * choice of retrying the open if it failed. */
[7155]231
[66486]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
[7654]247 rawFreeImage(pImage, false);
[2650]248 return rc;
249}
250
[7155]251/**
[7654]252 * Internal: Create a raw image.
[7155]253 */
[17970]254static int rawCreateImage(PRAWIMAGE pImage, uint64_t cbSize,
255 unsigned uImageFlags, const char *pszComment,
[32536]256 PCVDGEOMETRY pPCHSGeometry,
257 PCVDGEOMETRY pLCHSGeometry, unsigned uOpenFlags,
[63784]258 PVDINTERFACEPROGRESS pIfProgress,
[7654]259 unsigned uPercentStart, unsigned uPercentSpan)
[2650]260{
[62747]261 RT_NOREF1(pszComment);
[63784]262 int rc = VINF_SUCCESS;
[2650]263
[63784]264 pImage->fCreate = true;
265 pImage->uOpenFlags = uOpenFlags & ~VD_OPEN_FLAGS_READONLY;
266 pImage->uImageFlags = uImageFlags | VD_IMAGE_FLAGS_FIXED;
[7654]267 pImage->PCHSGeometry = *pPCHSGeometry;
268 pImage->LCHSGeometry = *pLCHSGeometry;
[63784]269 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
270 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
[38469]271 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
[11435]272
[63784]273 if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_DIFF))
[38469]274 {
[63784]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;
[22966]285
[63784]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 */,
[63811]292 pIfProgress, uPercentStart, uPercentSpan);
[63784]293 if (RT_SUCCESS(rc))
294 {
295 vdIfProgress(pIfProgress, uPercentStart + uPercentSpan * 98 / 100);
[7654]296
[63784]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 }
[66110]304 else
305 {
306 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, cbSize);
307 if (RT_SUCCESS(rc))
308 pImage->cbSize = cbSize;
309 }
[33234]310 }
[63784]311 else
312 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: cannot create image '%s'"), pImage->pszFilename);
[2650]313 }
[63784]314 else
315 rc = vdIfError(pImage->pIfError, VERR_VD_RAW_INVALID_TYPE, RT_SRC_POS, N_("Raw: cannot create diff image '%s'"), pImage->pszFilename);
[2650]316
[63784]317 if (RT_SUCCESS(rc))
[66486]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
[63784]331 vdIfProgress(pIfProgress, uPercentStart + uPercentSpan);
[66486]332 }
[6291]333
[11266]334 if (RT_FAILURE(rc))
[7654]335 rawFreeImage(pImage, rc != VERR_ALREADY_EXISTS);
[2358]336 return rc;
337}
338
[79965]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;
[7155]354
[79965]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
[63802]533/** @copydoc VDIMAGEBACKEND::pfnProbe */
534static DECLCALLBACK(int) rawProbe(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
[79965]535 PVDINTERFACE pVDIfsImage, VDTYPE enmDesiredType, VDTYPE *penmType)
[2358]536{
[79965]537 RT_NOREF(pVDIfsDisk, enmDesiredType);
[33524]538 LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p\n", pszFilename, pVDIfsDisk, pVDIfsImage));
539 PVDIOSTORAGE pStorage = NULL;
[63784]540 PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
[7155]541
[38469]542 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
[90802]543 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
544 AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
[33524]545
546 /*
547 * Open the file and read the footer.
548 */
[63784]549 int rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
550 VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
551 false /* fCreate */),
552 &pStorage);
[33524]553 if (RT_SUCCESS(rc))
[62747]554 {
[63784]555 uint64_t cbFile;
[38469]556 rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
[79965]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);
[33524]583
[79965]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)
[33524]591 {
[79965]592 int rc2 = rawProbeIsIso9660OrUdf(pIfIo, pStorage);
593 if (RT_SUCCESS(rc2))
[62747]594 {
[79965]595 /* *puScore = VDPROBE_SCORE_HIGH; */
[66211]596 *penmType = VDTYPE_OPTICAL_DISC;
[62747]597 rc = VINF_SUCCESS;
598 }
[79965]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 }
[33524]606 }
[79965]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
[86500]616 && cbFile >= 512
[79965]617 && cbFile <= RAW_MAX_FLOPPY_IMG_SIZE)
[33524]618 {
[79965]619 /** @todo check if the content is DOSish. */
620 if (false)
[62747]621 {
[79965]622 /* *puScore = VDPROBE_SCORE_HIGH; */
[62747]623 *penmType = VDTYPE_FLOPPY;
624 rc = VINF_SUCCESS;
625 }
[79965]626 else if (rawProbeContainsExtension(s_aRawFileExtensions, pszSuffix, VDTYPE_FLOPPY))
627 {
628 /* *puScore = VDPROBE_SCORE_LOW; */
629 *penmType = VDTYPE_FLOPPY;
630 rc = VINF_SUCCESS;
631 }
[33524]632 }
[79965]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 }
[33524]670 }
[35480]671 else
672 rc = VERR_VD_RAW_INVALID_HEADER;
[33524]673 }
674
675 if (pStorage)
[38469]676 vdIfIoIntFileClose(pIfIo, pStorage);
[33524]677
[11284]678 LogFlowFunc(("returns %Rrc\n", rc));
[6291]679 return rc;
680}
681
[63784]682/** @copydoc VDIMAGEBACKEND::pfnOpen */
[57388]683static DECLCALLBACK(int) rawOpen(const char *pszFilename, unsigned uOpenFlags,
684 PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
685 VDTYPE enmType, void **ppBackendData)
[6291]686{
[63784]687 LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p enmType=%u ppBackendData=%#p\n",
688 pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
[2650]689 int rc;
[7654]690 PRAWIMAGE pImage;
[2358]691
[2650]692 /* Check open flags. All valid flags are supported. */
[63784]693 AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
[90802]694 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
695 AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
[2358]696
[66486]697 pImage = (PRAWIMAGE)RTMemAllocZ(RT_UOFFSETOF(RAWIMAGE, RegionList.aRegions[1]));
[63784]698 if (RT_LIKELY(pImage))
[2358]699 {
[63784]700 pImage->pszFilename = pszFilename;
701 pImage->pStorage = NULL;
702 pImage->pVDIfsDisk = pVDIfsDisk;
703 pImage->pVDIfsImage = pVDIfsImage;
[2358]704
[66489]705 if (enmType == VDTYPE_OPTICAL_DISC)
706 pImage->cbSector = 2048;
707 else
708 pImage->cbSector = 512;
709
[63784]710 rc = rawOpenImage(pImage, uOpenFlags);
711 if (RT_SUCCESS(rc))
712 *ppBackendData = pImage;
[48743]713 else
[63784]714 RTMemFree(pImage);
[48743]715 }
[23913]716 else
[63784]717 rc = VERR_NO_MEMORY;
[2358]718
[11284]719 LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
[2358]720 return rc;
721}
722
[63784]723/** @copydoc VDIMAGEBACKEND::pfnCreate */
[57388]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)
[2564]732{
[62747]733 RT_NOREF1(pUuid);
[54430]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));
[2650]736
[54430]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. */
[66211]739 if (enmType != VDTYPE_HDD && enmType != VDTYPE_OPTICAL_DISC && enmType != VDTYPE_FLOPPY)
[63784]740 return VERR_VD_INVALID_TYPE;
[54430]741
[63784]742 int rc = VINF_SUCCESS;
743 PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation);
[2650]744
[63784]745 /* Check arguments. */
746 AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
[90802]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);
[7155]751
[66486]752 PRAWIMAGE pImage = (PRAWIMAGE)RTMemAllocZ(RT_UOFFSETOF(RAWIMAGE, RegionList.aRegions[1]));
[63784]753 if (RT_LIKELY(pImage))
[2650]754 {
[63784]755 pImage->pszFilename = pszFilename;
756 pImage->pStorage = NULL;
757 pImage->pVDIfsDisk = pVDIfsDisk;
758 pImage->pVDIfsImage = pVDIfsImage;
[2650]759
[63784]760 rc = rawCreateImage(pImage, cbSize, uImageFlags, pszComment,
761 pPCHSGeometry, pLCHSGeometry, uOpenFlags,
762 pIfProgress, uPercentStart, uPercentSpan);
763 if (RT_SUCCESS(rc))
[2650]764 {
[63784]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)
[23913]768 {
[63784]769 rawFreeImage(pImage, false);
770 rc = rawOpenImage(pImage, uOpenFlags);
[23913]771 }
[63784]772
773 if (RT_SUCCESS(rc))
774 *ppBackendData = pImage;
[2650]775 }
[63784]776
777 if (RT_FAILURE(rc))
778 RTMemFree(pImage);
[2650]779 }
[23913]780 else
[63784]781 rc = VERR_NO_MEMORY;
[2650]782
[11284]783 LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
[2650]784 return rc;
[2564]785}
786
[63784]787/** @copydoc VDIMAGEBACKEND::pfnRename */
[57388]788static DECLCALLBACK(int) rawRename(void *pBackendData, const char *pszFilename)
[6291]789{
[7155]790 LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
[32536]791 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[7155]792
[63784]793 AssertReturn((pImage && pszFilename && *pszFilename), VERR_INVALID_PARAMETER);
[32536]794
795 /* Close the image. */
[63784]796 int rc = rawFreeImage(pImage, false);
797 if (RT_SUCCESS(rc))
[32536]798 {
[63784]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;
[32536]805
[63784]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 }
[32536]816 }
817
[11284]818 LogFlowFunc(("returns %Rrc\n", rc));
[7155]819 return rc;
[6291]820}
821
[63784]822/** @copydoc VDIMAGEBACKEND::pfnClose */
[57388]823static DECLCALLBACK(int) rawClose(void *pBackendData, bool fDelete)
[2358]824{
[7155]825 LogFlowFunc(("pBackendData=%#p fDelete=%d\n", pBackendData, fDelete));
[7654]826 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[63784]827 int rc = rawFreeImage(pImage, fDelete);
[32536]828 RTMemFree(pImage);
[2358]829
[11284]830 LogFlowFunc(("returns %Rrc\n", rc));
[2358]831 return rc;
832}
833
[63784]834/** @copydoc VDIMAGEBACKEND::pfnRead */
[64272]835static DECLCALLBACK(int) rawRead(void *pBackendData, uint64_t uOffset, size_t cbToRead,
[57388]836 PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
[2358]837{
[44252]838 int rc = VINF_SUCCESS;
[7654]839 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[2358]840
[58258]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
[44252]849 rc = vdIfIoIntFileReadUser(pImage->pIfIo, pImage->pStorage, uOffset,
[64272]850 pIoCtx, cbToRead);
[44252]851 if (RT_SUCCESS(rc))
[58258]852 {
[64272]853 *pcbActuallyRead = cbToRead;
854 pImage->offAccess = uOffset + cbToRead;
[58258]855 }
[2358]856
857 return rc;
858}
859
[63784]860/** @copydoc VDIMAGEBACKEND::pfnWrite */
[64272]861static DECLCALLBACK(int) rawWrite(void *pBackendData, uint64_t uOffset, size_t cbToWrite,
[57388]862 PVDIOCTX pIoCtx, size_t *pcbWriteProcess, size_t *pcbPreRead,
863 size_t *pcbPostRead, unsigned fWrite)
[2358]864{
[62747]865 RT_NOREF1(fWrite);
[44252]866 int rc = VINF_SUCCESS;
[7654]867 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[2358]868
[58258]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
[44252]879 rc = vdIfIoIntFileWriteUser(pImage->pIfIo, pImage->pStorage, uOffset,
[64272]880 pIoCtx, cbToWrite, NULL, NULL);
[44252]881 if (RT_SUCCESS(rc))
[2358]882 {
[64272]883 *pcbWriteProcess = cbToWrite;
[44252]884 *pcbPostRead = 0;
885 *pcbPreRead = 0;
[64272]886 pImage->offAccess = uOffset + cbToWrite;
[2358]887 }
888
889 return rc;
890}
891
[63784]892/** @copydoc VDIMAGEBACKEND::pfnFlush */
[57388]893static DECLCALLBACK(int) rawFlush(void *pBackendData, PVDIOCTX pIoCtx)
[2358]894{
[44252]895 int rc = VINF_SUCCESS;
[7654]896 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[2358]897
[44252]898 if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
899 rc = vdIfIoIntFileFlush(pImage->pIfIo, pImage->pStorage, pIoCtx,
900 NULL, NULL);
901
[2358]902 return rc;
903}
904
[63784]905/** @copydoc VDIMAGEBACKEND::pfnGetVersion */
[57388]906static DECLCALLBACK(unsigned) rawGetVersion(void *pBackendData)
[6291]907{
[7155]908 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
[7654]909 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[6291]910
[63784]911 AssertPtrReturn(pImage, 0);
[6291]912
[63784]913 return 1;
[6291]914}
915
[63784]916/** @copydoc VDIMAGEBACKEND::pfnGetFileSize */
[57388]917static DECLCALLBACK(uint64_t) rawGetFileSize(void *pBackendData)
[2358]918{
[7155]919 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
[7654]920 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[6291]921
[63784]922 AssertPtrReturn(pImage, 0);
[6291]923
[63784]924 uint64_t cbFile = 0;
925 if (pImage->pStorage)
[6291]926 {
[63784]927 int rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile);
928 if (RT_FAILURE(rc))
929 cbFile = 0; /* Make sure it is 0 */
[6291]930 }
[7155]931
[63784]932 LogFlowFunc(("returns %lld\n", cbFile));
933 return cbFile;
[6291]934}
935
[63784]936/** @copydoc VDIMAGEBACKEND::pfnGetPCHSGeometry */
[57388]937static DECLCALLBACK(int) rawGetPCHSGeometry(void *pBackendData,
938 PVDGEOMETRY pPCHSGeometry)
[6291]939{
[7155]940 LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p\n", pBackendData, pPCHSGeometry));
[7654]941 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[63784]942 int rc = VINF_SUCCESS;
[2358]943
[63784]944 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
[2358]945
[63784]946 if (pImage->PCHSGeometry.cCylinders)
947 *pPCHSGeometry = pImage->PCHSGeometry;
[2358]948 else
[63784]949 rc = VERR_VD_GEOMETRY_NOT_SET;
[7155]950
[11284]951 LogFlowFunc(("returns %Rrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
[2358]952 return rc;
953}
954
[63784]955/** @copydoc VDIMAGEBACKEND::pfnSetPCHSGeometry */
[57388]956static DECLCALLBACK(int) rawSetPCHSGeometry(void *pBackendData,
957 PCVDGEOMETRY pPCHSGeometry)
[2358]958{
[63784]959 LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n",
960 pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
[7654]961 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[63784]962 int rc = VINF_SUCCESS;
[2358]963
[63784]964 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
[2358]965
[63784]966 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
967 rc = VERR_VD_IMAGE_READ_ONLY;
968 else
[6291]969 pImage->PCHSGeometry = *pPCHSGeometry;
[2358]970
[11284]971 LogFlowFunc(("returns %Rrc\n", rc));
[2358]972 return rc;
973}
974
[63784]975/** @copydoc VDIMAGEBACKEND::pfnGetLCHSGeometry */
[57388]976static DECLCALLBACK(int) rawGetLCHSGeometry(void *pBackendData,
977 PVDGEOMETRY pLCHSGeometry)
[2358]978{
[7155]979 LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
[7654]980 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[63784]981 int rc = VINF_SUCCESS;
[2358]982
[63784]983 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
[2358]984
[63784]985 if (pImage->LCHSGeometry.cCylinders)
986 *pLCHSGeometry = pImage->LCHSGeometry;
[2358]987 else
[63784]988 rc = VERR_VD_GEOMETRY_NOT_SET;
[7155]989
[11284]990 LogFlowFunc(("returns %Rrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
[2358]991 return rc;
992}
993
[63784]994/** @copydoc VDIMAGEBACKEND::pfnSetLCHSGeometry */
[57388]995static DECLCALLBACK(int) rawSetLCHSGeometry(void *pBackendData,
996 PCVDGEOMETRY pLCHSGeometry)
[2358]997{
[63784]998 LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n",
999 pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
[7654]1000 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[63784]1001 int rc = VINF_SUCCESS;
[2358]1002
[63784]1003 AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
[2358]1004
[63784]1005 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
1006 rc = VERR_VD_IMAGE_READ_ONLY;
1007 else
[6291]1008 pImage->LCHSGeometry = *pLCHSGeometry;
1009
[11284]1010 LogFlowFunc(("returns %Rrc\n", rc));
[2358]1011 return rc;
1012}
1013
[66486]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
[63784]1038/** @copydoc VDIMAGEBACKEND::pfnGetImageFlags */
[57388]1039static DECLCALLBACK(unsigned) rawGetImageFlags(void *pBackendData)
[6291]1040{
[7155]1041 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
[7654]1042 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[6291]1043
[63784]1044 AssertPtrReturn(pImage, 0);
[6291]1045
[63784]1046 LogFlowFunc(("returns %#x\n", pImage->uImageFlags));
1047 return pImage->uImageFlags;
[6291]1048}
1049
[63784]1050/** @copydoc VDIMAGEBACKEND::pfnGetOpenFlags */
[57388]1051static DECLCALLBACK(unsigned) rawGetOpenFlags(void *pBackendData)
[2358]1052{
[7155]1053 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
[7654]1054 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[2358]1055
[63784]1056 AssertPtrReturn(pImage, 0);
[2358]1057
[63784]1058 LogFlowFunc(("returns %#x\n", pImage->uOpenFlags));
1059 return pImage->uOpenFlags;
[2358]1060}
1061
[63784]1062/** @copydoc VDIMAGEBACKEND::pfnSetOpenFlags */
[57388]1063static DECLCALLBACK(int) rawSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
[2358]1064{
[7155]1065 LogFlowFunc(("pBackendData=%#p\n uOpenFlags=%#x", pBackendData, uOpenFlags));
[7654]1066 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[63784]1067 int rc = VINF_SUCCESS;
[2358]1068
[33182]1069 /* Image must be opened and the new flags must be valid. */
[44232]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)))
[63784]1073 rc = VERR_INVALID_PARAMETER;
1074 else
[2358]1075 {
[63784]1076 /* Implement this operation via reopening the image. */
1077 rc = rawFreeImage(pImage, false);
1078 if (RT_SUCCESS(rc))
1079 rc = rawOpenImage(pImage, uOpenFlags);
[2358]1080 }
1081
[11284]1082 LogFlowFunc(("returns %Rrc\n", rc));
[2358]1083 return rc;
1084}
1085
[63784]1086/** @copydoc VDIMAGEBACKEND::pfnGetComment */
[66492]1087VD_BACKEND_CALLBACK_GET_COMMENT_DEF_NOT_SUPPORTED(rawGetComment);
[2742]1088
[63784]1089/** @copydoc VDIMAGEBACKEND::pfnSetComment */
[66492]1090VD_BACKEND_CALLBACK_SET_COMMENT_DEF_NOT_SUPPORTED(rawSetComment, PRAWIMAGE);
[2742]1091
[63784]1092/** @copydoc VDIMAGEBACKEND::pfnGetUuid */
[66492]1093VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetUuid);
[2358]1094
[63784]1095/** @copydoc VDIMAGEBACKEND::pfnSetUuid */
[66492]1096VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetUuid, PRAWIMAGE);
[2358]1097
[63784]1098/** @copydoc VDIMAGEBACKEND::pfnGetModificationUuid */
[66492]1099VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetModificationUuid);
[2358]1100
[63784]1101/** @copydoc VDIMAGEBACKEND::pfnSetModificationUuid */
[66492]1102VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetModificationUuid, PRAWIMAGE);
[2358]1103
[63784]1104/** @copydoc VDIMAGEBACKEND::pfnGetParentUuid */
[66492]1105VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetParentUuid);
[2358]1106
[63784]1107/** @copydoc VDIMAGEBACKEND::pfnSetParentUuid */
[66492]1108VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetParentUuid, PRAWIMAGE);
[2358]1109
[63784]1110/** @copydoc VDIMAGEBACKEND::pfnGetParentModificationUuid */
[66492]1111VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetParentModificationUuid);
[7155]1112
[63784]1113/** @copydoc VDIMAGEBACKEND::pfnSetParentModificationUuid */
[66492]1114VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetParentModificationUuid, PRAWIMAGE);
[7155]1115
[63784]1116/** @copydoc VDIMAGEBACKEND::pfnDump */
[57388]1117static DECLCALLBACK(void) rawDump(void *pBackendData)
[6291]1118{
[7654]1119 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
[2358]1120
[63784]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);
[6291]1126}
1127
[28154]1128
1129
[63781]1130const VDIMAGEBACKEND g_RawBackend =
[2358]1131{
[63905]1132 /* u32Version */
1133 VD_IMGBACKEND_VERSION,
[6291]1134 /* pszBackendName */
[33524]1135 "RAW",
[7780]1136 /* uBackendCaps */
[32536]1137 VD_CAP_CREATE_FIXED | VD_CAP_FILE | VD_CAP_ASYNC | VD_CAP_VFS,
[33524]1138 /* paFileExtensions */
1139 s_aRawFileExtensions,
[11484]1140 /* paConfigInfo */
1141 NULL,
[63802]1142 /* pfnProbe */
1143 rawProbe,
[2358]1144 /* pfnOpen */
[7654]1145 rawOpen,
[2564]1146 /* pfnCreate */
[7654]1147 rawCreate,
[6291]1148 /* pfnRename */
[7654]1149 rawRename,
[2358]1150 /* pfnClose */
[7654]1151 rawClose,
[2358]1152 /* pfnRead */
[7654]1153 rawRead,
[2358]1154 /* pfnWrite */
[7654]1155 rawWrite,
[2358]1156 /* pfnFlush */
[7654]1157 rawFlush,
[44252]1158 /* pfnDiscard */
1159 NULL,
[6291]1160 /* pfnGetVersion */
[7654]1161 rawGetVersion,
[6291]1162 /* pfnGetFileSize */
[7654]1163 rawGetFileSize,
[6291]1164 /* pfnGetPCHSGeometry */
[7654]1165 rawGetPCHSGeometry,
[6291]1166 /* pfnSetPCHSGeometry */
[7654]1167 rawSetPCHSGeometry,
[6291]1168 /* pfnGetLCHSGeometry */
[7654]1169 rawGetLCHSGeometry,
[6291]1170 /* pfnSetLCHSGeometry */
[7654]1171 rawSetLCHSGeometry,
[66110]1172 /* pfnQueryRegions */
[66486]1173 rawQueryRegions,
[66110]1174 /* pfnRegionListRelease */
[66486]1175 rawRegionListRelease,
[6291]1176 /* pfnGetImageFlags */
[7654]1177 rawGetImageFlags,
[2358]1178 /* pfnGetOpenFlags */
[7654]1179 rawGetOpenFlags,
[2358]1180 /* pfnSetOpenFlags */
[7654]1181 rawSetOpenFlags,
[2742]1182 /* pfnGetComment */
[7654]1183 rawGetComment,
[2742]1184 /* pfnSetComment */
[7654]1185 rawSetComment,
[2358]1186 /* pfnGetUuid */
[7654]1187 rawGetUuid,
[2742]1188 /* pfnSetUuid */
[7654]1189 rawSetUuid,
[2358]1190 /* pfnGetModificationUuid */
[7654]1191 rawGetModificationUuid,
[2358]1192 /* pfnSetModificationUuid */
[7654]1193 rawSetModificationUuid,
[2358]1194 /* pfnGetParentUuid */
[7654]1195 rawGetParentUuid,
[2358]1196 /* pfnSetParentUuid */
[7654]1197 rawSetParentUuid,
[7155]1198 /* pfnGetParentModificationUuid */
[7654]1199 rawGetParentModificationUuid,
[7155]1200 /* pfnSetParentModificationUuid */
[7654]1201 rawSetParentModificationUuid,
[6291]1202 /* pfnDump */
[10715]1203 rawDump,
[58132]1204 /* pfnGetTimestamp */
[32536]1205 NULL,
[58132]1206 /* pfnGetParentTimestamp */
[32536]1207 NULL,
[58132]1208 /* pfnSetParentTimestamp */
[32536]1209 NULL,
[10715]1210 /* pfnGetParentFilename */
[32536]1211 NULL,
[10715]1212 /* pfnSetParentFilename */
[32536]1213 NULL,
[14967]1214 /* pfnComposeLocation */
1215 genericFileComposeLocation,
1216 /* pfnComposeName */
[26291]1217 genericFileComposeName,
1218 /* pfnCompact */
[31776]1219 NULL,
1220 /* pfnResize */
[38621]1221 NULL,
[39519]1222 /* pfnRepair */
[50988]1223 NULL,
1224 /* pfnTraverseMetadata */
[63905]1225 NULL,
1226 /* u32VersionEnd */
1227 VD_IMGBACKEND_VERSION
[2358]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