VirtualBox

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

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