[12638] | 1 | /* $Id: RAW.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
[2358] | 2 | /** @file
|
---|
[12638] | 3 | * RawHDDCore - Raw Disk image, Core Code.
|
---|
[2358] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[96407] | 7 | * Copyright (C) 2006-2022 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] | 54 | typedef 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 |
|
---|
[40399] | 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)
|
---|
[33773] | 96 |
|
---|
[2358] | 97 |
|
---|
[57358] | 98 | /*********************************************************************************************************************************
|
---|
| 99 | * Static Variables *
|
---|
| 100 | *********************************************************************************************************************************/
|
---|
| 101 |
|
---|
[11421] | 102 | /** NULL-terminated array of supported file extensions. */
|
---|
[33524] | 103 | static const VDFILEEXTENSION s_aRawFileExtensions[] =
|
---|
[11421] | 104 | {
|
---|
[66211] | 105 | {"iso", VDTYPE_OPTICAL_DISC},
|
---|
| 106 | {"cdr", VDTYPE_OPTICAL_DISC},
|
---|
[33524] | 107 | {"img", VDTYPE_FLOPPY},
|
---|
| 108 | {"ima", VDTYPE_FLOPPY},
|
---|
[33786] | 109 | {"dsk", VDTYPE_FLOPPY},
|
---|
[47297] | 110 | {"flp", VDTYPE_FLOPPY},
|
---|
[35045] | 111 | {"vfd", VDTYPE_FLOPPY},
|
---|
[33524] | 112 | {NULL, VDTYPE_INVALID}
|
---|
[11421] | 113 | };
|
---|
| 114 |
|
---|
[2358] | 115 |
|
---|
[57358] | 116 | /*********************************************************************************************************************************
|
---|
| 117 | * Internal Functions *
|
---|
| 118 | *********************************************************************************************************************************/
|
---|
| 119 |
|
---|
[7155] | 120 | /**
|
---|
[32536] | 121 | * Internal. Flush image data to disk.
|
---|
| 122 | */
|
---|
| 123 | static int rawFlushImage(PRAWIMAGE pImage)
|
---|
[22966] | 124 | {
|
---|
| 125 | int rc = VINF_SUCCESS;
|
---|
| 126 |
|
---|
[32536] | 127 | if ( pImage->pStorage
|
---|
| 128 | && !(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
|
---|
[38469] | 129 | rc = vdIfIoIntFileFlushSync(pImage->pIfIo, pImage->pStorage);
|
---|
[22966] | 130 |
|
---|
| 131 | return rc;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[32536] | 134 | /**
|
---|
| 135 | * Internal. Free all allocated space for representing an image except pImage,
|
---|
| 136 | * and optionally delete the image from disk.
|
---|
| 137 | */
|
---|
| 138 | static int rawFreeImage(PRAWIMAGE pImage, bool fDelete)
|
---|
[22966] | 139 | {
|
---|
| 140 | int rc = VINF_SUCCESS;
|
---|
| 141 |
|
---|
[32536] | 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)
|
---|
[33234] | 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);
|
---|
[63784] | 161 | if (RT_LIKELY(pvBuf))
|
---|
[33234] | 162 | {
|
---|
[63784] | 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);
|
---|
[33234] | 169 |
|
---|
[63784] | 170 | rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage,
|
---|
| 171 | uOff, pvBuf, cbChunk);
|
---|
| 172 | if (RT_FAILURE(rc))
|
---|
| 173 | break;
|
---|
[33234] | 174 |
|
---|
[63784] | 175 | uOff += cbChunk;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | RTMemTmpFree(pvBuf);
|
---|
[33234] | 179 | }
|
---|
[63784] | 180 | else
|
---|
| 181 | rc = VERR_NO_MEMORY;
|
---|
[33234] | 182 | }
|
---|
[32536] | 183 | rawFlushImage(pImage);
|
---|
[33234] | 184 | }
|
---|
[22966] | 185 |
|
---|
[46613] | 186 | rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
|
---|
[32536] | 187 | pImage->pStorage = NULL;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | if (fDelete && pImage->pszFilename)
|
---|
[38469] | 191 | vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename);
|
---|
[32536] | 192 | }
|
---|
| 193 |
|
---|
| 194 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
[22966] | 195 | return rc;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[2742] | 198 | /**
|
---|
[7155] | 199 | * Internal: Open an image, constructing all necessary data structures.
|
---|
| 200 | */
|
---|
[7654] | 201 | static int rawOpenImage(PRAWIMAGE pImage, unsigned uOpenFlags)
|
---|
[2358] | 202 | {
|
---|
| 203 | pImage->uOpenFlags = uOpenFlags;
|
---|
[33234] | 204 | pImage->fCreate = false;
|
---|
[2358] | 205 |
|
---|
[38469] | 206 | pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
|
---|
| 207 | pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
|
---|
| 208 | AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
|
---|
[11435] | 209 |
|
---|
[63784] | 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))
|
---|
[2358] | 216 | {
|
---|
[63784] | 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;
|
---|
[2358] | 223 | }
|
---|
[63784] | 224 | /* else: Do NOT signal an appropriate error here, as the VD layer has the
|
---|
| 225 | * choice of retrying the open if it failed. */
|
---|
[7155] | 226 |
|
---|
[66486] | 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
|
---|
[7654] | 242 | rawFreeImage(pImage, false);
|
---|
[2650] | 243 | return rc;
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[7155] | 246 | /**
|
---|
[7654] | 247 | * Internal: Create a raw image.
|
---|
[7155] | 248 | */
|
---|
[17970] | 249 | static int rawCreateImage(PRAWIMAGE pImage, uint64_t cbSize,
|
---|
| 250 | unsigned uImageFlags, const char *pszComment,
|
---|
[32536] | 251 | PCVDGEOMETRY pPCHSGeometry,
|
---|
| 252 | PCVDGEOMETRY pLCHSGeometry, unsigned uOpenFlags,
|
---|
[63784] | 253 | PVDINTERFACEPROGRESS pIfProgress,
|
---|
[7654] | 254 | unsigned uPercentStart, unsigned uPercentSpan)
|
---|
[2650] | 255 | {
|
---|
[62747] | 256 | RT_NOREF1(pszComment);
|
---|
[63784] | 257 | int rc = VINF_SUCCESS;
|
---|
[2650] | 258 |
|
---|
[63784] | 259 | pImage->fCreate = true;
|
---|
| 260 | pImage->uOpenFlags = uOpenFlags & ~VD_OPEN_FLAGS_READONLY;
|
---|
| 261 | pImage->uImageFlags = uImageFlags | VD_IMAGE_FLAGS_FIXED;
|
---|
[7654] | 262 | pImage->PCHSGeometry = *pPCHSGeometry;
|
---|
| 263 | pImage->LCHSGeometry = *pLCHSGeometry;
|
---|
[63784] | 264 | pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
|
---|
| 265 | pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
|
---|
[38469] | 266 | AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
|
---|
[11435] | 267 |
|
---|
[63784] | 268 | if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_DIFF))
|
---|
[38469] | 269 | {
|
---|
[63784] | 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;
|
---|
[22966] | 280 |
|
---|
[63784] | 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 */,
|
---|
[63811] | 287 | pIfProgress, uPercentStart, uPercentSpan);
|
---|
[63784] | 288 | if (RT_SUCCESS(rc))
|
---|
| 289 | {
|
---|
| 290 | vdIfProgress(pIfProgress, uPercentStart + uPercentSpan * 98 / 100);
|
---|
[7654] | 291 |
|
---|
[63784] | 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 | }
|
---|
[66110] | 299 | else
|
---|
| 300 | {
|
---|
| 301 | rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, cbSize);
|
---|
| 302 | if (RT_SUCCESS(rc))
|
---|
| 303 | pImage->cbSize = cbSize;
|
---|
| 304 | }
|
---|
[33234] | 305 | }
|
---|
[63784] | 306 | else
|
---|
| 307 | rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: cannot create image '%s'"), pImage->pszFilename);
|
---|
[2650] | 308 | }
|
---|
[63784] | 309 | else
|
---|
| 310 | rc = vdIfError(pImage->pIfError, VERR_VD_RAW_INVALID_TYPE, RT_SRC_POS, N_("Raw: cannot create diff image '%s'"), pImage->pszFilename);
|
---|
[2650] | 311 |
|
---|
[63784] | 312 | if (RT_SUCCESS(rc))
|
---|
[66486] | 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 |
|
---|
[63784] | 326 | vdIfProgress(pIfProgress, uPercentStart + uPercentSpan);
|
---|
[66486] | 327 | }
|
---|
[6291] | 328 |
|
---|
[11266] | 329 | if (RT_FAILURE(rc))
|
---|
[7654] | 330 | rawFreeImage(pImage, rc != VERR_ALREADY_EXISTS);
|
---|
[2358] | 331 | return rc;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
[79965] | 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 | */
|
---|
| 345 | static int rawProbeIsIso9660OrUdf(PVDINTERFACEIOINT pIfIo, PVDIOSTORAGE pStorage)
|
---|
| 346 | {
|
---|
| 347 | PRTERRINFO pErrInfo = NULL;
|
---|
| 348 | const uint32_t cbSector = _2K;
|
---|
[7155] | 349 |
|
---|
[79965] | 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 | */
|
---|
| 506 | static 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 |
|
---|
[63802] | 528 | /** @copydoc VDIMAGEBACKEND::pfnProbe */
|
---|
| 529 | static DECLCALLBACK(int) rawProbe(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
|
---|
[79965] | 530 | PVDINTERFACE pVDIfsImage, VDTYPE enmDesiredType, VDTYPE *penmType)
|
---|
[2358] | 531 | {
|
---|
[79965] | 532 | RT_NOREF(pVDIfsDisk, enmDesiredType);
|
---|
[33524] | 533 | LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p\n", pszFilename, pVDIfsDisk, pVDIfsImage));
|
---|
| 534 | PVDIOSTORAGE pStorage = NULL;
|
---|
[63784] | 535 | PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
|
---|
[7155] | 536 |
|
---|
[38469] | 537 | AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
|
---|
[90802] | 538 | AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
|
---|
| 539 | AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
|
---|
[33524] | 540 |
|
---|
| 541 | /*
|
---|
| 542 | * Open the file and read the footer.
|
---|
| 543 | */
|
---|
[63784] | 544 | int rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
|
---|
| 545 | VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
|
---|
| 546 | false /* fCreate */),
|
---|
| 547 | &pStorage);
|
---|
[33524] | 548 | if (RT_SUCCESS(rc))
|
---|
[62747] | 549 | {
|
---|
[63784] | 550 | uint64_t cbFile;
|
---|
[38469] | 551 | rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
|
---|
[79965] | 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);
|
---|
[33524] | 578 |
|
---|
[79965] | 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)
|
---|
[33524] | 586 | {
|
---|
[79965] | 587 | int rc2 = rawProbeIsIso9660OrUdf(pIfIo, pStorage);
|
---|
| 588 | if (RT_SUCCESS(rc2))
|
---|
[62747] | 589 | {
|
---|
[79965] | 590 | /* *puScore = VDPROBE_SCORE_HIGH; */
|
---|
[66211] | 591 | *penmType = VDTYPE_OPTICAL_DISC;
|
---|
[62747] | 592 | rc = VINF_SUCCESS;
|
---|
| 593 | }
|
---|
[79965] | 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 | }
|
---|
[33524] | 601 | }
|
---|
[79965] | 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
|
---|
[86500] | 611 | && cbFile >= 512
|
---|
[79965] | 612 | && cbFile <= RAW_MAX_FLOPPY_IMG_SIZE)
|
---|
[33524] | 613 | {
|
---|
[79965] | 614 | /** @todo check if the content is DOSish. */
|
---|
| 615 | if (false)
|
---|
[62747] | 616 | {
|
---|
[79965] | 617 | /* *puScore = VDPROBE_SCORE_HIGH; */
|
---|
[62747] | 618 | *penmType = VDTYPE_FLOPPY;
|
---|
| 619 | rc = VINF_SUCCESS;
|
---|
| 620 | }
|
---|
[79965] | 621 | else if (rawProbeContainsExtension(s_aRawFileExtensions, pszSuffix, VDTYPE_FLOPPY))
|
---|
| 622 | {
|
---|
| 623 | /* *puScore = VDPROBE_SCORE_LOW; */
|
---|
| 624 | *penmType = VDTYPE_FLOPPY;
|
---|
| 625 | rc = VINF_SUCCESS;
|
---|
| 626 | }
|
---|
[33524] | 627 | }
|
---|
[79965] | 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 | }
|
---|
[33524] | 665 | }
|
---|
[35480] | 666 | else
|
---|
| 667 | rc = VERR_VD_RAW_INVALID_HEADER;
|
---|
[33524] | 668 | }
|
---|
| 669 |
|
---|
| 670 | if (pStorage)
|
---|
[38469] | 671 | vdIfIoIntFileClose(pIfIo, pStorage);
|
---|
[33524] | 672 |
|
---|
[11284] | 673 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
[6291] | 674 | return rc;
|
---|
| 675 | }
|
---|
| 676 |
|
---|
[63784] | 677 | /** @copydoc VDIMAGEBACKEND::pfnOpen */
|
---|
[57388] | 678 | static DECLCALLBACK(int) rawOpen(const char *pszFilename, unsigned uOpenFlags,
|
---|
| 679 | PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
|
---|
| 680 | VDTYPE enmType, void **ppBackendData)
|
---|
[6291] | 681 | {
|
---|
[63784] | 682 | LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p enmType=%u ppBackendData=%#p\n",
|
---|
| 683 | pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
|
---|
[2650] | 684 | int rc;
|
---|
[7654] | 685 | PRAWIMAGE pImage;
|
---|
[2358] | 686 |
|
---|
[2650] | 687 | /* Check open flags. All valid flags are supported. */
|
---|
[63784] | 688 | AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
|
---|
[90802] | 689 | AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
|
---|
| 690 | AssertReturn(*pszFilename != '\0', VERR_INVALID_PARAMETER);
|
---|
[2358] | 691 |
|
---|
[66486] | 692 | pImage = (PRAWIMAGE)RTMemAllocZ(RT_UOFFSETOF(RAWIMAGE, RegionList.aRegions[1]));
|
---|
[63784] | 693 | if (RT_LIKELY(pImage))
|
---|
[2358] | 694 | {
|
---|
[63784] | 695 | pImage->pszFilename = pszFilename;
|
---|
| 696 | pImage->pStorage = NULL;
|
---|
| 697 | pImage->pVDIfsDisk = pVDIfsDisk;
|
---|
| 698 | pImage->pVDIfsImage = pVDIfsImage;
|
---|
[2358] | 699 |
|
---|
[66489] | 700 | if (enmType == VDTYPE_OPTICAL_DISC)
|
---|
| 701 | pImage->cbSector = 2048;
|
---|
| 702 | else
|
---|
| 703 | pImage->cbSector = 512;
|
---|
| 704 |
|
---|
[63784] | 705 | rc = rawOpenImage(pImage, uOpenFlags);
|
---|
| 706 | if (RT_SUCCESS(rc))
|
---|
| 707 | *ppBackendData = pImage;
|
---|
[48743] | 708 | else
|
---|
[63784] | 709 | RTMemFree(pImage);
|
---|
[48743] | 710 | }
|
---|
[23913] | 711 | else
|
---|
[63784] | 712 | rc = VERR_NO_MEMORY;
|
---|
[2358] | 713 |
|
---|
[11284] | 714 | LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
|
---|
[2358] | 715 | return rc;
|
---|
| 716 | }
|
---|
| 717 |
|
---|
[63784] | 718 | /** @copydoc VDIMAGEBACKEND::pfnCreate */
|
---|
[57388] | 719 | static 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)
|
---|
[2564] | 727 | {
|
---|
[62747] | 728 | RT_NOREF1(pUuid);
|
---|
[54430] | 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));
|
---|
[2650] | 731 |
|
---|
[54430] | 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. */
|
---|
[66211] | 734 | if (enmType != VDTYPE_HDD && enmType != VDTYPE_OPTICAL_DISC && enmType != VDTYPE_FLOPPY)
|
---|
[63784] | 735 | return VERR_VD_INVALID_TYPE;
|
---|
[54430] | 736 |
|
---|
[63784] | 737 | int rc = VINF_SUCCESS;
|
---|
| 738 | PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation);
|
---|
[2650] | 739 |
|
---|
[63784] | 740 | /* Check arguments. */
|
---|
| 741 | AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
|
---|
[90802] | 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);
|
---|
[7155] | 746 |
|
---|
[66486] | 747 | PRAWIMAGE pImage = (PRAWIMAGE)RTMemAllocZ(RT_UOFFSETOF(RAWIMAGE, RegionList.aRegions[1]));
|
---|
[63784] | 748 | if (RT_LIKELY(pImage))
|
---|
[2650] | 749 | {
|
---|
[63784] | 750 | pImage->pszFilename = pszFilename;
|
---|
| 751 | pImage->pStorage = NULL;
|
---|
| 752 | pImage->pVDIfsDisk = pVDIfsDisk;
|
---|
| 753 | pImage->pVDIfsImage = pVDIfsImage;
|
---|
[2650] | 754 |
|
---|
[63784] | 755 | rc = rawCreateImage(pImage, cbSize, uImageFlags, pszComment,
|
---|
| 756 | pPCHSGeometry, pLCHSGeometry, uOpenFlags,
|
---|
| 757 | pIfProgress, uPercentStart, uPercentSpan);
|
---|
| 758 | if (RT_SUCCESS(rc))
|
---|
[2650] | 759 | {
|
---|
[63784] | 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)
|
---|
[23913] | 763 | {
|
---|
[63784] | 764 | rawFreeImage(pImage, false);
|
---|
| 765 | rc = rawOpenImage(pImage, uOpenFlags);
|
---|
[23913] | 766 | }
|
---|
[63784] | 767 |
|
---|
| 768 | if (RT_SUCCESS(rc))
|
---|
| 769 | *ppBackendData = pImage;
|
---|
[2650] | 770 | }
|
---|
[63784] | 771 |
|
---|
| 772 | if (RT_FAILURE(rc))
|
---|
| 773 | RTMemFree(pImage);
|
---|
[2650] | 774 | }
|
---|
[23913] | 775 | else
|
---|
[63784] | 776 | rc = VERR_NO_MEMORY;
|
---|
[2650] | 777 |
|
---|
[11284] | 778 | LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
|
---|
[2650] | 779 | return rc;
|
---|
[2564] | 780 | }
|
---|
| 781 |
|
---|
[63784] | 782 | /** @copydoc VDIMAGEBACKEND::pfnRename */
|
---|
[57388] | 783 | static DECLCALLBACK(int) rawRename(void *pBackendData, const char *pszFilename)
|
---|
[6291] | 784 | {
|
---|
[7155] | 785 | LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
|
---|
[32536] | 786 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[7155] | 787 |
|
---|
[63784] | 788 | AssertReturn((pImage && pszFilename && *pszFilename), VERR_INVALID_PARAMETER);
|
---|
[32536] | 789 |
|
---|
| 790 | /* Close the image. */
|
---|
[63784] | 791 | int rc = rawFreeImage(pImage, false);
|
---|
| 792 | if (RT_SUCCESS(rc))
|
---|
[32536] | 793 | {
|
---|
[63784] | 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;
|
---|
[32536] | 800 |
|
---|
[63784] | 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 | }
|
---|
[32536] | 811 | }
|
---|
| 812 |
|
---|
[11284] | 813 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
[7155] | 814 | return rc;
|
---|
[6291] | 815 | }
|
---|
| 816 |
|
---|
[63784] | 817 | /** @copydoc VDIMAGEBACKEND::pfnClose */
|
---|
[57388] | 818 | static DECLCALLBACK(int) rawClose(void *pBackendData, bool fDelete)
|
---|
[2358] | 819 | {
|
---|
[7155] | 820 | LogFlowFunc(("pBackendData=%#p fDelete=%d\n", pBackendData, fDelete));
|
---|
[7654] | 821 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[63784] | 822 | int rc = rawFreeImage(pImage, fDelete);
|
---|
[32536] | 823 | RTMemFree(pImage);
|
---|
[2358] | 824 |
|
---|
[11284] | 825 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
[2358] | 826 | return rc;
|
---|
| 827 | }
|
---|
| 828 |
|
---|
[63784] | 829 | /** @copydoc VDIMAGEBACKEND::pfnRead */
|
---|
[64272] | 830 | static DECLCALLBACK(int) rawRead(void *pBackendData, uint64_t uOffset, size_t cbToRead,
|
---|
[57388] | 831 | PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
|
---|
[2358] | 832 | {
|
---|
[44252] | 833 | int rc = VINF_SUCCESS;
|
---|
[7654] | 834 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[2358] | 835 |
|
---|
[58258] | 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 |
|
---|
[44252] | 844 | rc = vdIfIoIntFileReadUser(pImage->pIfIo, pImage->pStorage, uOffset,
|
---|
[64272] | 845 | pIoCtx, cbToRead);
|
---|
[44252] | 846 | if (RT_SUCCESS(rc))
|
---|
[58258] | 847 | {
|
---|
[64272] | 848 | *pcbActuallyRead = cbToRead;
|
---|
| 849 | pImage->offAccess = uOffset + cbToRead;
|
---|
[58258] | 850 | }
|
---|
[2358] | 851 |
|
---|
| 852 | return rc;
|
---|
| 853 | }
|
---|
| 854 |
|
---|
[63784] | 855 | /** @copydoc VDIMAGEBACKEND::pfnWrite */
|
---|
[64272] | 856 | static DECLCALLBACK(int) rawWrite(void *pBackendData, uint64_t uOffset, size_t cbToWrite,
|
---|
[57388] | 857 | PVDIOCTX pIoCtx, size_t *pcbWriteProcess, size_t *pcbPreRead,
|
---|
| 858 | size_t *pcbPostRead, unsigned fWrite)
|
---|
[2358] | 859 | {
|
---|
[62747] | 860 | RT_NOREF1(fWrite);
|
---|
[44252] | 861 | int rc = VINF_SUCCESS;
|
---|
[7654] | 862 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[2358] | 863 |
|
---|
[58258] | 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 |
|
---|
[44252] | 874 | rc = vdIfIoIntFileWriteUser(pImage->pIfIo, pImage->pStorage, uOffset,
|
---|
[64272] | 875 | pIoCtx, cbToWrite, NULL, NULL);
|
---|
[44252] | 876 | if (RT_SUCCESS(rc))
|
---|
[2358] | 877 | {
|
---|
[64272] | 878 | *pcbWriteProcess = cbToWrite;
|
---|
[44252] | 879 | *pcbPostRead = 0;
|
---|
| 880 | *pcbPreRead = 0;
|
---|
[64272] | 881 | pImage->offAccess = uOffset + cbToWrite;
|
---|
[2358] | 882 | }
|
---|
| 883 |
|
---|
| 884 | return rc;
|
---|
| 885 | }
|
---|
| 886 |
|
---|
[63784] | 887 | /** @copydoc VDIMAGEBACKEND::pfnFlush */
|
---|
[57388] | 888 | static DECLCALLBACK(int) rawFlush(void *pBackendData, PVDIOCTX pIoCtx)
|
---|
[2358] | 889 | {
|
---|
[44252] | 890 | int rc = VINF_SUCCESS;
|
---|
[7654] | 891 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[2358] | 892 |
|
---|
[44252] | 893 | if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
|
---|
| 894 | rc = vdIfIoIntFileFlush(pImage->pIfIo, pImage->pStorage, pIoCtx,
|
---|
| 895 | NULL, NULL);
|
---|
| 896 |
|
---|
[2358] | 897 | return rc;
|
---|
| 898 | }
|
---|
| 899 |
|
---|
[63784] | 900 | /** @copydoc VDIMAGEBACKEND::pfnGetVersion */
|
---|
[57388] | 901 | static DECLCALLBACK(unsigned) rawGetVersion(void *pBackendData)
|
---|
[6291] | 902 | {
|
---|
[7155] | 903 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
[7654] | 904 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[6291] | 905 |
|
---|
[63784] | 906 | AssertPtrReturn(pImage, 0);
|
---|
[6291] | 907 |
|
---|
[63784] | 908 | return 1;
|
---|
[6291] | 909 | }
|
---|
| 910 |
|
---|
[63784] | 911 | /** @copydoc VDIMAGEBACKEND::pfnGetFileSize */
|
---|
[57388] | 912 | static DECLCALLBACK(uint64_t) rawGetFileSize(void *pBackendData)
|
---|
[2358] | 913 | {
|
---|
[7155] | 914 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
[7654] | 915 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[6291] | 916 |
|
---|
[63784] | 917 | AssertPtrReturn(pImage, 0);
|
---|
[6291] | 918 |
|
---|
[63784] | 919 | uint64_t cbFile = 0;
|
---|
| 920 | if (pImage->pStorage)
|
---|
[6291] | 921 | {
|
---|
[63784] | 922 | int rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile);
|
---|
| 923 | if (RT_FAILURE(rc))
|
---|
| 924 | cbFile = 0; /* Make sure it is 0 */
|
---|
[6291] | 925 | }
|
---|
[7155] | 926 |
|
---|
[63784] | 927 | LogFlowFunc(("returns %lld\n", cbFile));
|
---|
| 928 | return cbFile;
|
---|
[6291] | 929 | }
|
---|
| 930 |
|
---|
[63784] | 931 | /** @copydoc VDIMAGEBACKEND::pfnGetPCHSGeometry */
|
---|
[57388] | 932 | static DECLCALLBACK(int) rawGetPCHSGeometry(void *pBackendData,
|
---|
| 933 | PVDGEOMETRY pPCHSGeometry)
|
---|
[6291] | 934 | {
|
---|
[7155] | 935 | LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p\n", pBackendData, pPCHSGeometry));
|
---|
[7654] | 936 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[63784] | 937 | int rc = VINF_SUCCESS;
|
---|
[2358] | 938 |
|
---|
[63784] | 939 | AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
|
---|
[2358] | 940 |
|
---|
[63784] | 941 | if (pImage->PCHSGeometry.cCylinders)
|
---|
| 942 | *pPCHSGeometry = pImage->PCHSGeometry;
|
---|
[2358] | 943 | else
|
---|
[63784] | 944 | rc = VERR_VD_GEOMETRY_NOT_SET;
|
---|
[7155] | 945 |
|
---|
[11284] | 946 | LogFlowFunc(("returns %Rrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
|
---|
[2358] | 947 | return rc;
|
---|
| 948 | }
|
---|
| 949 |
|
---|
[63784] | 950 | /** @copydoc VDIMAGEBACKEND::pfnSetPCHSGeometry */
|
---|
[57388] | 951 | static DECLCALLBACK(int) rawSetPCHSGeometry(void *pBackendData,
|
---|
| 952 | PCVDGEOMETRY pPCHSGeometry)
|
---|
[2358] | 953 | {
|
---|
[63784] | 954 | LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n",
|
---|
| 955 | pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
|
---|
[7654] | 956 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[63784] | 957 | int rc = VINF_SUCCESS;
|
---|
[2358] | 958 |
|
---|
[63784] | 959 | AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
|
---|
[2358] | 960 |
|
---|
[63784] | 961 | if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
| 962 | rc = VERR_VD_IMAGE_READ_ONLY;
|
---|
| 963 | else
|
---|
[6291] | 964 | pImage->PCHSGeometry = *pPCHSGeometry;
|
---|
[2358] | 965 |
|
---|
[11284] | 966 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
[2358] | 967 | return rc;
|
---|
| 968 | }
|
---|
| 969 |
|
---|
[63784] | 970 | /** @copydoc VDIMAGEBACKEND::pfnGetLCHSGeometry */
|
---|
[57388] | 971 | static DECLCALLBACK(int) rawGetLCHSGeometry(void *pBackendData,
|
---|
| 972 | PVDGEOMETRY pLCHSGeometry)
|
---|
[2358] | 973 | {
|
---|
[7155] | 974 | LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
|
---|
[7654] | 975 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[63784] | 976 | int rc = VINF_SUCCESS;
|
---|
[2358] | 977 |
|
---|
[63784] | 978 | AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
|
---|
[2358] | 979 |
|
---|
[63784] | 980 | if (pImage->LCHSGeometry.cCylinders)
|
---|
| 981 | *pLCHSGeometry = pImage->LCHSGeometry;
|
---|
[2358] | 982 | else
|
---|
[63784] | 983 | rc = VERR_VD_GEOMETRY_NOT_SET;
|
---|
[7155] | 984 |
|
---|
[11284] | 985 | LogFlowFunc(("returns %Rrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
|
---|
[2358] | 986 | return rc;
|
---|
| 987 | }
|
---|
| 988 |
|
---|
[63784] | 989 | /** @copydoc VDIMAGEBACKEND::pfnSetLCHSGeometry */
|
---|
[57388] | 990 | static DECLCALLBACK(int) rawSetLCHSGeometry(void *pBackendData,
|
---|
| 991 | PCVDGEOMETRY pLCHSGeometry)
|
---|
[2358] | 992 | {
|
---|
[63784] | 993 | LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n",
|
---|
| 994 | pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
|
---|
[7654] | 995 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[63784] | 996 | int rc = VINF_SUCCESS;
|
---|
[2358] | 997 |
|
---|
[63784] | 998 | AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
|
---|
[2358] | 999 |
|
---|
[63784] | 1000 | if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
|
---|
| 1001 | rc = VERR_VD_IMAGE_READ_ONLY;
|
---|
| 1002 | else
|
---|
[6291] | 1003 | pImage->LCHSGeometry = *pLCHSGeometry;
|
---|
| 1004 |
|
---|
[11284] | 1005 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
[2358] | 1006 | return rc;
|
---|
| 1007 | }
|
---|
| 1008 |
|
---|
[66486] | 1009 | /** @copydoc VDIMAGEBACKEND::pfnQueryRegions */
|
---|
| 1010 | static 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 */
|
---|
| 1023 | static 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 |
|
---|
[63784] | 1033 | /** @copydoc VDIMAGEBACKEND::pfnGetImageFlags */
|
---|
[57388] | 1034 | static DECLCALLBACK(unsigned) rawGetImageFlags(void *pBackendData)
|
---|
[6291] | 1035 | {
|
---|
[7155] | 1036 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
[7654] | 1037 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[6291] | 1038 |
|
---|
[63784] | 1039 | AssertPtrReturn(pImage, 0);
|
---|
[6291] | 1040 |
|
---|
[63784] | 1041 | LogFlowFunc(("returns %#x\n", pImage->uImageFlags));
|
---|
| 1042 | return pImage->uImageFlags;
|
---|
[6291] | 1043 | }
|
---|
| 1044 |
|
---|
[63784] | 1045 | /** @copydoc VDIMAGEBACKEND::pfnGetOpenFlags */
|
---|
[57388] | 1046 | static DECLCALLBACK(unsigned) rawGetOpenFlags(void *pBackendData)
|
---|
[2358] | 1047 | {
|
---|
[7155] | 1048 | LogFlowFunc(("pBackendData=%#p\n", pBackendData));
|
---|
[7654] | 1049 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[2358] | 1050 |
|
---|
[63784] | 1051 | AssertPtrReturn(pImage, 0);
|
---|
[2358] | 1052 |
|
---|
[63784] | 1053 | LogFlowFunc(("returns %#x\n", pImage->uOpenFlags));
|
---|
| 1054 | return pImage->uOpenFlags;
|
---|
[2358] | 1055 | }
|
---|
| 1056 |
|
---|
[63784] | 1057 | /** @copydoc VDIMAGEBACKEND::pfnSetOpenFlags */
|
---|
[57388] | 1058 | static DECLCALLBACK(int) rawSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
|
---|
[2358] | 1059 | {
|
---|
[7155] | 1060 | LogFlowFunc(("pBackendData=%#p\n uOpenFlags=%#x", pBackendData, uOpenFlags));
|
---|
[7654] | 1061 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[63784] | 1062 | int rc = VINF_SUCCESS;
|
---|
[2358] | 1063 |
|
---|
[33182] | 1064 | /* Image must be opened and the new flags must be valid. */
|
---|
[44232] | 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)))
|
---|
[63784] | 1068 | rc = VERR_INVALID_PARAMETER;
|
---|
| 1069 | else
|
---|
[2358] | 1070 | {
|
---|
[63784] | 1071 | /* Implement this operation via reopening the image. */
|
---|
| 1072 | rc = rawFreeImage(pImage, false);
|
---|
| 1073 | if (RT_SUCCESS(rc))
|
---|
| 1074 | rc = rawOpenImage(pImage, uOpenFlags);
|
---|
[2358] | 1075 | }
|
---|
| 1076 |
|
---|
[11284] | 1077 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
[2358] | 1078 | return rc;
|
---|
| 1079 | }
|
---|
| 1080 |
|
---|
[63784] | 1081 | /** @copydoc VDIMAGEBACKEND::pfnGetComment */
|
---|
[66492] | 1082 | VD_BACKEND_CALLBACK_GET_COMMENT_DEF_NOT_SUPPORTED(rawGetComment);
|
---|
[2742] | 1083 |
|
---|
[63784] | 1084 | /** @copydoc VDIMAGEBACKEND::pfnSetComment */
|
---|
[66492] | 1085 | VD_BACKEND_CALLBACK_SET_COMMENT_DEF_NOT_SUPPORTED(rawSetComment, PRAWIMAGE);
|
---|
[2742] | 1086 |
|
---|
[63784] | 1087 | /** @copydoc VDIMAGEBACKEND::pfnGetUuid */
|
---|
[66492] | 1088 | VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetUuid);
|
---|
[2358] | 1089 |
|
---|
[63784] | 1090 | /** @copydoc VDIMAGEBACKEND::pfnSetUuid */
|
---|
[66492] | 1091 | VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetUuid, PRAWIMAGE);
|
---|
[2358] | 1092 |
|
---|
[63784] | 1093 | /** @copydoc VDIMAGEBACKEND::pfnGetModificationUuid */
|
---|
[66492] | 1094 | VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetModificationUuid);
|
---|
[2358] | 1095 |
|
---|
[63784] | 1096 | /** @copydoc VDIMAGEBACKEND::pfnSetModificationUuid */
|
---|
[66492] | 1097 | VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetModificationUuid, PRAWIMAGE);
|
---|
[2358] | 1098 |
|
---|
[63784] | 1099 | /** @copydoc VDIMAGEBACKEND::pfnGetParentUuid */
|
---|
[66492] | 1100 | VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetParentUuid);
|
---|
[2358] | 1101 |
|
---|
[63784] | 1102 | /** @copydoc VDIMAGEBACKEND::pfnSetParentUuid */
|
---|
[66492] | 1103 | VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetParentUuid, PRAWIMAGE);
|
---|
[2358] | 1104 |
|
---|
[63784] | 1105 | /** @copydoc VDIMAGEBACKEND::pfnGetParentModificationUuid */
|
---|
[66492] | 1106 | VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(rawGetParentModificationUuid);
|
---|
[7155] | 1107 |
|
---|
[63784] | 1108 | /** @copydoc VDIMAGEBACKEND::pfnSetParentModificationUuid */
|
---|
[66492] | 1109 | VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(rawSetParentModificationUuid, PRAWIMAGE);
|
---|
[7155] | 1110 |
|
---|
[63784] | 1111 | /** @copydoc VDIMAGEBACKEND::pfnDump */
|
---|
[57388] | 1112 | static DECLCALLBACK(void) rawDump(void *pBackendData)
|
---|
[6291] | 1113 | {
|
---|
[7654] | 1114 | PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
|
---|
[2358] | 1115 |
|
---|
[63784] | 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);
|
---|
[6291] | 1121 | }
|
---|
| 1122 |
|
---|
[28154] | 1123 |
|
---|
| 1124 |
|
---|
[63781] | 1125 | const VDIMAGEBACKEND g_RawBackend =
|
---|
[2358] | 1126 | {
|
---|
[63905] | 1127 | /* u32Version */
|
---|
| 1128 | VD_IMGBACKEND_VERSION,
|
---|
[6291] | 1129 | /* pszBackendName */
|
---|
[33524] | 1130 | "RAW",
|
---|
[7780] | 1131 | /* uBackendCaps */
|
---|
[32536] | 1132 | VD_CAP_CREATE_FIXED | VD_CAP_FILE | VD_CAP_ASYNC | VD_CAP_VFS,
|
---|
[33524] | 1133 | /* paFileExtensions */
|
---|
| 1134 | s_aRawFileExtensions,
|
---|
[11484] | 1135 | /* paConfigInfo */
|
---|
| 1136 | NULL,
|
---|
[63802] | 1137 | /* pfnProbe */
|
---|
| 1138 | rawProbe,
|
---|
[2358] | 1139 | /* pfnOpen */
|
---|
[7654] | 1140 | rawOpen,
|
---|
[2564] | 1141 | /* pfnCreate */
|
---|
[7654] | 1142 | rawCreate,
|
---|
[6291] | 1143 | /* pfnRename */
|
---|
[7654] | 1144 | rawRename,
|
---|
[2358] | 1145 | /* pfnClose */
|
---|
[7654] | 1146 | rawClose,
|
---|
[2358] | 1147 | /* pfnRead */
|
---|
[7654] | 1148 | rawRead,
|
---|
[2358] | 1149 | /* pfnWrite */
|
---|
[7654] | 1150 | rawWrite,
|
---|
[2358] | 1151 | /* pfnFlush */
|
---|
[7654] | 1152 | rawFlush,
|
---|
[44252] | 1153 | /* pfnDiscard */
|
---|
| 1154 | NULL,
|
---|
[6291] | 1155 | /* pfnGetVersion */
|
---|
[7654] | 1156 | rawGetVersion,
|
---|
[6291] | 1157 | /* pfnGetFileSize */
|
---|
[7654] | 1158 | rawGetFileSize,
|
---|
[6291] | 1159 | /* pfnGetPCHSGeometry */
|
---|
[7654] | 1160 | rawGetPCHSGeometry,
|
---|
[6291] | 1161 | /* pfnSetPCHSGeometry */
|
---|
[7654] | 1162 | rawSetPCHSGeometry,
|
---|
[6291] | 1163 | /* pfnGetLCHSGeometry */
|
---|
[7654] | 1164 | rawGetLCHSGeometry,
|
---|
[6291] | 1165 | /* pfnSetLCHSGeometry */
|
---|
[7654] | 1166 | rawSetLCHSGeometry,
|
---|
[66110] | 1167 | /* pfnQueryRegions */
|
---|
[66486] | 1168 | rawQueryRegions,
|
---|
[66110] | 1169 | /* pfnRegionListRelease */
|
---|
[66486] | 1170 | rawRegionListRelease,
|
---|
[6291] | 1171 | /* pfnGetImageFlags */
|
---|
[7654] | 1172 | rawGetImageFlags,
|
---|
[2358] | 1173 | /* pfnGetOpenFlags */
|
---|
[7654] | 1174 | rawGetOpenFlags,
|
---|
[2358] | 1175 | /* pfnSetOpenFlags */
|
---|
[7654] | 1176 | rawSetOpenFlags,
|
---|
[2742] | 1177 | /* pfnGetComment */
|
---|
[7654] | 1178 | rawGetComment,
|
---|
[2742] | 1179 | /* pfnSetComment */
|
---|
[7654] | 1180 | rawSetComment,
|
---|
[2358] | 1181 | /* pfnGetUuid */
|
---|
[7654] | 1182 | rawGetUuid,
|
---|
[2742] | 1183 | /* pfnSetUuid */
|
---|
[7654] | 1184 | rawSetUuid,
|
---|
[2358] | 1185 | /* pfnGetModificationUuid */
|
---|
[7654] | 1186 | rawGetModificationUuid,
|
---|
[2358] | 1187 | /* pfnSetModificationUuid */
|
---|
[7654] | 1188 | rawSetModificationUuid,
|
---|
[2358] | 1189 | /* pfnGetParentUuid */
|
---|
[7654] | 1190 | rawGetParentUuid,
|
---|
[2358] | 1191 | /* pfnSetParentUuid */
|
---|
[7654] | 1192 | rawSetParentUuid,
|
---|
[7155] | 1193 | /* pfnGetParentModificationUuid */
|
---|
[7654] | 1194 | rawGetParentModificationUuid,
|
---|
[7155] | 1195 | /* pfnSetParentModificationUuid */
|
---|
[7654] | 1196 | rawSetParentModificationUuid,
|
---|
[6291] | 1197 | /* pfnDump */
|
---|
[10715] | 1198 | rawDump,
|
---|
[58132] | 1199 | /* pfnGetTimestamp */
|
---|
[32536] | 1200 | NULL,
|
---|
[58132] | 1201 | /* pfnGetParentTimestamp */
|
---|
[32536] | 1202 | NULL,
|
---|
[58132] | 1203 | /* pfnSetParentTimestamp */
|
---|
[32536] | 1204 | NULL,
|
---|
[10715] | 1205 | /* pfnGetParentFilename */
|
---|
[32536] | 1206 | NULL,
|
---|
[10715] | 1207 | /* pfnSetParentFilename */
|
---|
[32536] | 1208 | NULL,
|
---|
[14967] | 1209 | /* pfnComposeLocation */
|
---|
| 1210 | genericFileComposeLocation,
|
---|
| 1211 | /* pfnComposeName */
|
---|
[26291] | 1212 | genericFileComposeName,
|
---|
| 1213 | /* pfnCompact */
|
---|
[31776] | 1214 | NULL,
|
---|
| 1215 | /* pfnResize */
|
---|
[38621] | 1216 | NULL,
|
---|
[39519] | 1217 | /* pfnRepair */
|
---|
[50988] | 1218 | NULL,
|
---|
| 1219 | /* pfnTraverseMetadata */
|
---|
[63905] | 1220 | NULL,
|
---|
| 1221 | /* u32VersionEnd */
|
---|
| 1222 | VD_IMGBACKEND_VERSION
|
---|
[2358] | 1223 | };
|
---|