VirtualBox

source: vbox/trunk/src/VBox/Storage/VISO.cpp@ 67524

Last change on this file since 67524 was 67465, checked in by vboxsync, 7 years ago

Storage/VISO: Don't bother constructing the image for info queries. Provide an image UUID.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.1 KB
Line 
1/* $Id: VISO.cpp 67465 2017-06-19 10:09:26Z vboxsync $ */
2/** @file
3 * VISO - Virtual ISO disk image, Core Code.
4 */
5
6/*
7 * Copyright (C) 2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_VD
23#include <VBox/vd-plugin.h>
24#include <VBox/err.h>
25
26#include <VBox/log.h>
27//#include <VBox/scsiinline.h>
28#include <iprt/assert.h>
29#include <iprt/ctype.h>
30#include <iprt/fsisomaker.h>
31#include <iprt/getopt.h>
32#include <iprt/mem.h>
33#include <iprt/string.h>
34#include <iprt/uuid.h>
35
36#include "VDBackends.h"
37#include "VDBackendsInline.h"
38
39
40/*********************************************************************************************************************************
41* Defined Constants And Macros *
42*********************************************************************************************************************************/
43/** The maximum file size. */
44#if ARCH_BITS >= 64
45# define VISO_MAX_FILE_SIZE _32M
46#else
47# define VISO_MAX_FILE_SIZE _8M
48#endif
49
50
51/*********************************************************************************************************************************
52* Structures and Typedefs *
53*********************************************************************************************************************************/
54
55/**
56 * VBox ISO maker image instance.
57 */
58typedef struct VISOIMAGE
59{
60 /** The ISO maker output file handle.
61 * This is NIL if in VD_OPEN_FLAGS_INFO mode. */
62 RTVFSFILE hIsoFile;
63 /** The image size. */
64 uint64_t cbImage;
65 /** The UUID ofr the image. */
66 RTUUID Uuid;
67
68 /** Open flags passed by VD layer. */
69 uint32_t fOpenFlags;
70 /** Image name (for debug).
71 * Allocation follows the region list, no need to free. */
72 const char *pszFilename;
73
74 /** I/O interface. */
75 PVDINTERFACEIOINT pIfIo;
76 /** Error interface. */
77 PVDINTERFACEERROR pIfError;
78
79 /** Internal region list (variable size). */
80 VDREGIONLIST RegionList;
81} VISOIMAGE;
82/** Pointer to an VBox ISO make image instance. */
83typedef VISOIMAGE *PVISOIMAGE;
84
85
86/*********************************************************************************************************************************
87* Global Variables *
88*********************************************************************************************************************************/
89/** NULL-terminated array of supported file extensions. */
90static const VDFILEEXTENSION g_aVBoXIsoMakerFileExtensions[] =
91{
92 //{ "vbox-iso-maker", VDTYPE_OPTICAL_DISC }, - clumsy.
93 { "viso", VDTYPE_OPTICAL_DISC },
94 { NULL, VDTYPE_INVALID }
95};
96
97
98/**
99 * Parses the UUID that follows the marker argument.
100 *
101 * @returns IPRT status code.
102 * @param pszMarker The marker.
103 * @param pUuid Where to return the UUID.
104 */
105static int visoParseUuid(char *pszMarker, PRTUUID pUuid)
106{
107 /* Skip the marker. */
108 char ch;
109 while ( (ch = *pszMarker) != '\0'
110 && !RT_C_IS_SPACE(ch)
111 && ch != ':'
112 && ch != '=')
113 pszMarker++;
114
115 /* Skip chars before the value. */
116 if ( ch == ':'
117 || ch == '=')
118 ch = *++pszMarker;
119 else
120 while (RT_C_IS_SPACE(ch))
121 ch = *++pszMarker;
122 const char * const pszUuid = pszMarker;
123
124 /* Find the end of the UUID value. */
125 while ( ch != '\0'
126 && !RT_C_IS_SPACE(ch))
127 ch = *++pszMarker;
128
129 /* Validate the value (temporarily terminate the value string) */
130 *pszMarker = '\0';
131 int rc = RTUuidFromStr(pUuid, pszUuid);
132 if (RT_SUCCESS(rc))
133 {
134 *pszMarker = ch;
135 return VINF_SUCCESS;
136 }
137
138 /* Complain and return VERR_VD_IMAGE_CORRUPTED to indicate we've identified
139 the right image format, but the producer got something wrong. */
140 if (pszUuid != pszMarker)
141 LogRel(("visoParseUuid: Malformed UUID '%s': %Rrc\n", pszUuid, rc));
142 else
143 LogRel(("visoParseUuid: Empty/missing UUID!\n"));
144 *pszMarker = ch;
145
146 return VERR_VD_IMAGE_CORRUPTED;
147}
148
149
150static int visoProbeWorker(const char *pszFilename, PVDINTERFACEIOINT pIfIo, PRTUUID pUuid)
151{
152 PVDIOSTORAGE pStorage = NULL;
153 int rc = vdIfIoIntFileOpen(pIfIo, pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, &pStorage);
154 if (RT_SUCCESS(rc))
155 {
156 /*
157 * Read the first part of the file.
158 */
159 uint64_t cbFile = 0;
160 rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
161 if (RT_SUCCESS(rc))
162 {
163 char szChunk[_1K];
164 size_t cbToRead = (size_t)RT_MIN(sizeof(szChunk) - 1, cbFile);
165 rc = vdIfIoIntFileReadSync(pIfIo, pStorage, 0 /*off*/, szChunk, cbToRead);
166 if (RT_SUCCESS(rc))
167 {
168 szChunk[cbToRead] = '\0';
169
170 /*
171 * Skip leading spaces and check for the eye-catcher.
172 */
173 char *psz = szChunk;
174 while (RT_C_IS_SPACE(*psz))
175 psz++;
176 if (strncmp(psz, RT_STR_TUPLE("--iprt-iso-maker-file-marker")) == 0)
177 {
178 rc = visoParseUuid(psz, pUuid);
179 if (RT_SUCCESS(rc))
180 {
181 /*
182 * Check the file size.
183 */
184 if (cbFile <= VISO_MAX_FILE_SIZE)
185 rc = VINF_SUCCESS;
186 else
187 {
188 LogRel(("visoProbeWorker: VERR_VD_INVALID_SIZE - cbFile=%#RX64 cbMaxFile=%#RX64\n",
189 cbFile, (uint64_t)VISO_MAX_FILE_SIZE));
190 rc = VERR_VD_INVALID_SIZE;
191 }
192 }
193 }
194 else
195 rc = VERR_VD_GEN_INVALID_HEADER;
196 }
197 }
198 vdIfIoIntFileClose(pIfIo, pStorage);
199 }
200 LogFlowFunc(("returns %Rrc\n", rc));
201 return rc;
202}
203
204/**
205 * @interface_method_impl{VDIMAGEBACKEND,pfnProbe}
206 */
207static DECLCALLBACK(int) visoProbe(const char *pszFilename, PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
208{
209 /*
210 * Validate input.
211 */
212 AssertPtrReturn(penmType, VERR_INVALID_POINTER);
213 *penmType = VDTYPE_INVALID;
214
215 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
216 AssertReturn(*pszFilename, VERR_INVALID_POINTER);
217
218 PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
219 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
220
221 RT_NOREF(pVDIfsDisk);
222
223 /*
224 * Share worker with visoOpen and visoSetFlags.
225 */
226 RTUUID UuidIgn;
227 int rc = visoProbeWorker(pszFilename, pIfIo, &UuidIgn);
228 if (RT_SUCCESS(rc))
229 *penmType = VDTYPE_OPTICAL_DISC;
230
231 LogFlowFunc(("returns %Rrc - *penmType=%d\n", rc, *penmType));
232 return rc;
233}
234
235
236/**
237 * Worker for visoOpen and visoSetOpenFlags that creates a VFS file for the ISO.
238 *
239 * This also updates cbImage and the Uuid members.
240 *
241 * @returns
242 * @param pThis .
243 */
244static int visoOpenWorker(PVISOIMAGE pThis)
245{
246 /*
247 * Open the file and read it into memory.
248 */
249 PVDIOSTORAGE pStorage = NULL;
250 int rc = vdIfIoIntFileOpen(pThis->pIfIo, pThis->pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, &pStorage);
251 if (RT_FAILURE(rc))
252 return rc;
253
254 /*
255 * Read the file into memory, prefixing it with a dummy command name.
256 */
257 uint64_t cbFile = 0;
258 rc = vdIfIoIntFileGetSize(pThis->pIfIo, pStorage, &cbFile);
259 if (RT_SUCCESS(rc))
260 {
261 if (cbFile <= VISO_MAX_FILE_SIZE)
262 {
263 static char const s_szCmdPrefix[] = "VBox-Iso-Maker ";
264
265 char *pszContent = (char *)RTMemTmpAlloc(sizeof(s_szCmdPrefix) + cbFile);
266 if (pszContent)
267 {
268 char *pszReadDst = &pszContent[sizeof(s_szCmdPrefix) - 1];
269 rc = vdIfIoIntFileReadSync(pThis->pIfIo, pStorage, 0 /*off*/, pszReadDst, (size_t)cbFile);
270 if (RT_SUCCESS(rc))
271 {
272 /*
273 * Check the file marker and get the UUID that follows it.
274 * Ignore leading blanks.
275 */
276 pszReadDst[(size_t)cbFile] = '\0';
277 memcpy(pszContent, s_szCmdPrefix, sizeof(s_szCmdPrefix) - 1);
278
279 while (RT_C_IS_SPACE(*pszReadDst))
280 pszReadDst++;
281 if (strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker")) == 0)
282 {
283 rc = visoParseUuid(pszReadDst, &pThis->Uuid);
284 if (RT_SUCCESS(rc))
285 {
286 /*
287 * Convert it into an argument vector.
288 * Free the content afterwards to reduce memory pressure.
289 */
290 uint32_t fGetOpt = strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker-ms")) != 0
291 ? RTGETOPTARGV_CNV_QUOTE_BOURNE_SH : RTGETOPTARGV_CNV_QUOTE_MS_CRT;
292 char **papszArgs;
293 int cArgs;
294 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszContent, fGetOpt, NULL);
295
296 RTMemTmpFree(pszContent);
297 pszContent = NULL;
298
299 if (RT_SUCCESS(rc))
300 {
301 /*
302 * Try instantiate the ISO image maker.
303 * Free the argument vector afterward to reduce memory pressure.
304 */
305 RTVFSFILE hVfsFile;
306 RTERRINFOSTATIC ErrInfo;
307 rc = RTFsIsoMakerCmdEx(cArgs, papszArgs, &hVfsFile, RTErrInfoInitStatic(&ErrInfo));
308
309 RTGetOptArgvFree(papszArgs);
310 papszArgs = NULL;
311
312 if (RT_SUCCESS(rc))
313 {
314 uint64_t cbImage;
315 rc = RTVfsFileGetSize(hVfsFile, &cbImage);
316 if (RT_SUCCESS(rc))
317 {
318 /*
319 * Update the state.
320 */
321 pThis->cbImage = cbImage;
322 pThis->RegionList.aRegions[0].cRegionBlocksOrBytes = cbImage;
323
324 pThis->hIsoFile = hVfsFile;
325 hVfsFile = NIL_RTVFSFILE;
326
327 rc = VINF_SUCCESS;
328 }
329
330 RTVfsFileRelease(hVfsFile);
331 }
332 else
333 {
334 /** @todo better error reporting! */
335 if (RTErrInfoIsSet(&ErrInfo.Core))
336 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg));
337 else
338 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc\n", rc));
339 }
340 }
341 }
342 }
343 else
344 rc = VERR_VD_GEN_INVALID_HEADER;
345 }
346
347 RTMemTmpFree(pszContent);
348 }
349 else
350 rc = VERR_NO_TMP_MEMORY;
351 }
352 else
353 {
354 LogRel(("visoOpen: VERR_VD_INVALID_SIZE - cbFile=%#RX64 cbMaxFile=%#RX64\n",
355 cbFile, (uint64_t)VISO_MAX_FILE_SIZE));
356 rc = VERR_VD_INVALID_SIZE;
357 }
358 }
359
360 vdIfIoIntFileClose(pThis->pIfIo, pStorage);
361 return rc;
362}
363
364
365/**
366 * @interface_method_impl{VDIMAGEBACKEND,pfnOpen}
367 */
368static DECLCALLBACK(int) visoOpen(const char *pszFilename, unsigned uOpenFlags, PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
369 VDTYPE enmType, void **ppBackendData)
370{
371 uint32_t const fOpenFlags = uOpenFlags;
372 LogFlowFunc(("pszFilename='%s' fOpenFlags=%#x pVDIfsDisk=%p pVDIfsImage=%p enmType=%u ppBackendData=%p\n",
373 pszFilename, fOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
374
375 /*
376 * Validate input.
377 */
378 AssertPtrReturn(ppBackendData, VERR_INVALID_POINTER);
379 *ppBackendData = NULL;
380
381 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
382 AssertReturn(*pszFilename, VERR_INVALID_POINTER);
383
384 AssertReturn(!(fOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_FLAGS);
385
386 PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
387 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
388
389 PVDINTERFACEERROR pIfError = VDIfErrorGet(pVDIfsDisk);
390
391 AssertReturn(enmType == VDTYPE_OPTICAL_DISC, VERR_NOT_SUPPORTED);
392
393 /*
394 * Allocate and initialize the backend image instance data.
395 */
396 int rc;
397 size_t cbFilename = strlen(pszFilename) + 1;
398 PVISOIMAGE pThis = (PVISOIMAGE)RTMemAllocZ(RT_UOFFSETOF(VISOIMAGE, RegionList.aRegions[1]) + cbFilename);
399 if (pThis)
400 {
401 pThis->hIsoFile = NIL_RTVFSFILE;
402 pThis->cbImage = 0;
403 pThis->fOpenFlags = fOpenFlags;
404 pThis->pszFilename = (char *)memcpy(&pThis->RegionList.aRegions[1], pszFilename, cbFilename);
405 pThis->pIfIo = pIfIo;
406 pThis->pIfError = pIfError;
407
408 pThis->RegionList.fFlags = 0;
409 pThis->RegionList.cRegions = 1;
410 pThis->RegionList.aRegions[0].offRegion = 0;
411 pThis->RegionList.aRegions[0].cRegionBlocksOrBytes = 0;
412 pThis->RegionList.aRegions[0].cbBlock = 2048;
413 pThis->RegionList.aRegions[0].enmDataForm = VDREGIONDATAFORM_RAW;
414 pThis->RegionList.aRegions[0].enmMetadataForm = VDREGIONMETADATAFORM_NONE;
415 pThis->RegionList.aRegions[0].cbData = 2048;
416 pThis->RegionList.aRegions[0].cbMetadata = 0;
417
418 /*
419 * Only go all the way if this isn't an info query. Re-mastering an ISO
420 * can potentially be a lot of work and we don't want to go thru with it
421 * just because the GUI wants to display the image size.
422 */
423 if (!(fOpenFlags & VD_OPEN_FLAGS_INFO))
424 rc = visoOpenWorker(pThis);
425 else
426 rc = visoProbeWorker(pThis->pszFilename, pThis->pIfIo, &pThis->Uuid);
427 if (RT_SUCCESS(rc))
428 {
429 *ppBackendData = pThis;
430 LogFlowFunc(("returns VINF_SUCCESS (UUID=%RTuuid, pszFilename=%s)\n", &pThis->Uuid, pThis->pszFilename));
431 return VINF_SUCCESS;
432 }
433
434 RTMemFree(pThis);
435 }
436 else
437 rc = VERR_NO_MEMORY;
438 LogFlowFunc(("returns %Rrc\n", rc));
439 return rc;
440}
441
442
443/**
444 * @interface_method_impl{VDIMAGEBACKEND,pfnClose}
445 */
446static DECLCALLBACK(int) visoClose(void *pBackendData, bool fDelete)
447{
448 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
449 LogFlowFunc(("pThis=%p fDelete=%RTbool\n", pThis, fDelete));
450
451 if (pThis)
452 {
453 if (fDelete)
454 vdIfIoIntFileDelete(pThis->pIfIo, pThis->pszFilename);
455
456 if (pThis->hIsoFile != NIL_RTVFSFILE)
457 {
458 RTVfsFileRelease(pThis->hIsoFile);
459 pThis->hIsoFile = NIL_RTVFSFILE;
460 }
461
462 RTMemFree(pThis);
463 }
464
465 LogFlowFunc(("returns VINF_SUCCESS\n"));
466 return VINF_SUCCESS;
467}
468
469/**
470 * @interface_method_impl{VDIMAGEBACKEND,pfnRead}
471 */
472static DECLCALLBACK(int) visoRead(void *pBackendData, uint64_t uOffset, size_t cbToRead, PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
473{
474 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
475 uint64_t off = uOffset;
476 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
477 AssertReturn(pThis->hIsoFile != NIL_RTVFSFILE, VERR_VD_NOT_OPENED);
478 LogFlowFunc(("pThis=%p off=%#RX64 cbToRead=%#zx pIoCtx=%p pcbActuallyRead=%p\n", pThis, off, cbToRead, pIoCtx, pcbActuallyRead));
479
480 /*
481 * Check request.
482 */
483 AssertReturn( off < pThis->cbImage
484 || (off == pThis->cbImage && cbToRead == 0), VERR_EOF);
485
486 uint64_t cbLeftInImage = pThis->cbImage - off;
487 if (cbToRead >= cbLeftInImage)
488 cbToRead = cbLeftInImage; /* ASSUMES the caller can deal with this, given the pcbActuallyRead parameter... */
489
490 /*
491 * Work the I/O context using vdIfIoIntIoCtxSegArrayCreate.
492 */
493 int rc = VINF_SUCCESS;
494 size_t cbActuallyRead = 0;
495 while (cbToRead > 0)
496 {
497 RTSGSEG Seg;
498 unsigned cSegs = 1;
499 size_t cbThisRead = vdIfIoIntIoCtxSegArrayCreate(pThis->pIfIo, pIoCtx, &Seg, &cSegs, cbToRead);
500 AssertBreakStmt(cbThisRead != 0, rc = VERR_INTERNAL_ERROR_2);
501 Assert(cbThisRead == Seg.cbSeg);
502
503 rc = RTVfsFileReadAt(pThis->hIsoFile, off, Seg.pvSeg, cbThisRead, NULL);
504 AssertRCBreak(rc);
505
506 /* advance. */
507 cbActuallyRead += cbThisRead;
508 off += cbThisRead;
509 cbToRead -= cbThisRead;
510 }
511
512 *pcbActuallyRead = cbActuallyRead;
513 return rc;
514}
515
516/**
517 * @interface_method_impl{VDIMAGEBACKEND,pfnWrite}
518 */
519static DECLCALLBACK(int) visoWrite(void *pBackendData, uint64_t uOffset, size_t cbToWrite,
520 PVDIOCTX pIoCtx, size_t *pcbWriteProcess, size_t *pcbPreRead,
521 size_t *pcbPostRead, unsigned fWrite)
522{
523 RT_NOREF(uOffset, cbToWrite, pIoCtx, pcbWriteProcess, pcbPreRead, pcbPostRead, fWrite);
524 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
525 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
526 AssertReturn(pThis->hIsoFile != NIL_RTVFSFILE, VERR_VD_NOT_OPENED);
527 LogFlowFunc(("pThis=%p off=%#RX64 pIoCtx=%p cbToWrite=%#zx pcbWriteProcess=%p pcbPreRead=%p pcbPostRead=%p -> VERR_VD_IMAGE_READ_ONLY\n",
528 pThis, uOffset, pIoCtx, cbToWrite, pcbWriteProcess, pcbPreRead, pcbPostRead));
529 return VERR_VD_IMAGE_READ_ONLY;
530}
531
532/**
533 * @interface_method_impl{VDIMAGEBACKEND,pfnFlush}
534 */
535static DECLCALLBACK(int) visoFlush(void *pBackendData, PVDIOCTX pIoCtx)
536{
537 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
538 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
539 AssertReturn(pThis->hIsoFile != NIL_RTVFSFILE, VERR_VD_NOT_OPENED);
540 RT_NOREF(pIoCtx);
541 return VINF_SUCCESS;
542}
543
544/**
545 * @interface_method_impl{VDIMAGEBACKEND,pfnGetVersion}
546 */
547static DECLCALLBACK(unsigned) visoGetVersion(void *pBackendData)
548{
549 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
550 AssertPtrReturn(pThis, 0);
551 LogFlowFunc(("pThis=%#p -> 1\n", pThis));
552 return 1;
553}
554
555/**
556 * @interface_method_impl{VDIMAGEBACKEND,pfnGetFileSize}
557 */
558static DECLCALLBACK(uint64_t) visoGetFileSize(void *pBackendData)
559{
560 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
561 AssertPtrReturn(pThis, 0);
562 LogFlowFunc(("pThis=%p -> %RX64 (%s)\n", pThis, pThis->cbImage, pThis->hIsoFile == NIL_RTVFSFILE ? "fake!" : "real"));
563 return pThis->cbImage;
564}
565
566/**
567 * @interface_method_impl{VDIMAGEBACKEND,pfnGetPCHSGeometry}
568 */
569static DECLCALLBACK(int) visoGetPCHSGeometry(void *pBackendData, PVDGEOMETRY pPCHSGeometry)
570{
571 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
572 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
573 LogFlowFunc(("pThis=%p pPCHSGeometry=%p -> VERR_NOT_SUPPORTED\n", pThis, pPCHSGeometry));
574 RT_NOREF(pPCHSGeometry);
575 return VERR_NOT_SUPPORTED;
576}
577
578/**
579 * @interface_method_impl{VDIMAGEBACKEND,pfnSetPCHSGeometry}
580 */
581static DECLCALLBACK(int) visoSetPCHSGeometry(void *pBackendData, PCVDGEOMETRY pPCHSGeometry)
582{
583 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
584 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
585 LogFlowFunc(("pThis=%p pPCHSGeometry=%p:{%u/%u/%u} -> VERR_VD_IMAGE_READ_ONLY\n",
586 pThis, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
587 RT_NOREF(pPCHSGeometry);
588 return VERR_VD_IMAGE_READ_ONLY;
589}
590
591/**
592 * @interface_method_impl{VDIMAGEBACKEND,pfnGetLCHSGeometry}
593 */
594static DECLCALLBACK(int) visoGetLCHSGeometry(void *pBackendData, PVDGEOMETRY pLCHSGeometry)
595{
596 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
597 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
598 LogFlowFunc(("pThis=%p pLCHSGeometry=%p -> VERR_NOT_SUPPORTED\n", pThis, pLCHSGeometry));
599 RT_NOREF(pLCHSGeometry);
600 return VERR_NOT_SUPPORTED;
601}
602
603/**
604 * @interface_method_impl{VDIMAGEBACKEND,pfnSetLCHSGeometry}
605 */
606static DECLCALLBACK(int) visoSetLCHSGeometry(void *pBackendData, PCVDGEOMETRY pLCHSGeometry)
607{
608 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
609 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
610 LogFlowFunc(("pThis=%p pLCHSGeometry=%p:{%u/%u/%u} -> VERR_VD_IMAGE_READ_ONLY\n",
611 pThis, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
612 RT_NOREF(pLCHSGeometry);
613 return VERR_VD_IMAGE_READ_ONLY;
614}
615
616/**
617 * @interface_method_impl{VDIMAGEBACKEND,pfnQueryRegions}
618 */
619static DECLCALLBACK(int) visoQueryRegions(void *pBackendData, PCVDREGIONLIST *ppRegionList)
620{
621 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
622 *ppRegionList = NULL;
623 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
624
625 *ppRegionList = &pThis->RegionList;
626 LogFlowFunc(("returns VINF_SUCCESS (one region: 0 LB %RX64; pThis=%p)\n", pThis->RegionList.aRegions[0].cbData, pThis));
627 return VINF_SUCCESS;
628}
629
630/**
631 * @interface_method_impl{VDIMAGEBACKEND,pfnRegionListRelease}
632 */
633static DECLCALLBACK(void) visoRegionListRelease(void *pBackendData, PCVDREGIONLIST pRegionList)
634{
635 /* Nothing to do here. Just assert the input to avoid unused parameter warnings. */
636 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
637 LogFlowFunc(("pThis=%p pRegionList=%p\n", pThis, pRegionList));
638 AssertPtrReturnVoid(pThis);
639 AssertReturnVoid(pRegionList == &pThis->RegionList || pRegionList == 0);
640}
641
642/**
643 * @interface_method_impl{VDIMAGEBACKEND,pfnGetImageFlags}
644 */
645static DECLCALLBACK(unsigned) visoGetImageFlags(void *pBackendData)
646{
647 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
648 LogFlowFunc(("pThis=%p -> VD_IMAGE_FLAGS_NONE\n", pThis));
649 AssertPtrReturn(pThis, VD_IMAGE_FLAGS_NONE);
650 return VD_IMAGE_FLAGS_NONE;
651}
652
653/**
654 * @interface_method_impl{VDIMAGEBACKEND,pfnGetOpenFlags}
655 */
656static DECLCALLBACK(unsigned) visoGetOpenFlags(void *pBackendData)
657{
658 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
659 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
660 AssertPtrReturn(pThis, 0);
661
662 LogFlowFunc(("returns %#x\n", pThis->fOpenFlags));
663 return pThis->fOpenFlags;
664}
665
666/**
667 * @interface_method_impl{VDIMAGEBACKEND,pfnSetOpenFlags}
668 */
669static DECLCALLBACK(int) visoSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
670{
671 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
672 LogFlowFunc(("pThis=%p fOpenFlags=%#x\n", pThis, uOpenFlags));
673
674 AssertPtrReturn(pThis, VERR_INVALID_POINTER);
675 uint32_t const fSupported = VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_INFO
676 | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE
677 | VD_OPEN_FLAGS_SEQUENTIAL | VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS;
678 AssertMsgReturn(!(uOpenFlags & ~fSupported), ("fOpenFlags=%#x\n", uOpenFlags), VERR_INVALID_FLAGS);
679
680 /*
681 * Only react if we switch from VD_OPEN_FLAGS_INFO to non-VD_OPEN_FLAGS_INFO mode,
682 * becuase that means we need to open the image.
683 */
684 if ( (pThis->fOpenFlags & VD_OPEN_FLAGS_INFO)
685 && !(uOpenFlags & VD_OPEN_FLAGS_INFO)
686 && pThis->hIsoFile == NIL_RTVFSFILE)
687 {
688 int rc = visoOpenWorker(pThis);
689 if (RT_FAILURE(rc))
690 {
691 LogFlowFunc(("returns %Rrc\n", rc));
692 return rc;
693 }
694 }
695
696 /*
697 * Update the flags.
698 */
699 pThis->fOpenFlags &= ~fSupported;
700 pThis->fOpenFlags |= fSupported & uOpenFlags;
701 pThis->fOpenFlags |= VD_OPEN_FLAGS_READONLY;
702 if (pThis->hIsoFile != NIL_RTVFSFILE)
703 pThis->fOpenFlags &= ~VD_OPEN_FLAGS_INFO;
704
705 return VINF_SUCCESS;
706}
707
708#define uOpenFlags fOpenFlags /* sigh */
709
710/**
711 * @interface_method_impl{VDIMAGEBACKEND,pfnGetComment}
712 */
713VD_BACKEND_CALLBACK_GET_COMMENT_DEF_NOT_SUPPORTED(visoGetComment);
714
715/**
716 * @interface_method_impl{VDIMAGEBACKEND,pfnSetComment}
717 */
718VD_BACKEND_CALLBACK_SET_COMMENT_DEF_NOT_SUPPORTED(visoSetComment, PVISOIMAGE);
719
720/**
721 * @interface_method_impl{VDIMAGEBACKEND,pfnGetUuid}
722 */
723static DECLCALLBACK(int) visoGetUuid(void *pBackendData, PRTUUID pUuid)
724{
725 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
726 *pUuid = pThis->Uuid;
727 LogFlowFunc(("returns VIF_SUCCESS (%RTuuid)\n", pUuid));
728 return VINF_SUCCESS;
729}
730
731/**
732 * @interface_method_impl{VDIMAGEBACKEND,pfnSetUuid}
733 */
734VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetUuid, PVISOIMAGE);
735
736/**
737 * @interface_method_impl{VDIMAGEBACKEND,pfnGetModificationUuid}
738 */
739VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(visoGetModificationUuid);
740
741/**
742 * @interface_method_impl{VDIMAGEBACKEND,pfnSetModificationUuid}
743 */
744VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetModificationUuid, PVISOIMAGE);
745
746/**
747 * @interface_method_impl{VDIMAGEBACKEND,pfnGetParentUuid}
748 */
749VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(visoGetParentUuid);
750
751/**
752 * @interface_method_impl{VDIMAGEBACKEND,pfnSetParentUuid}
753 */
754VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetParentUuid, PVISOIMAGE);
755
756/**
757 * @interface_method_impl{VDIMAGEBACKEND,pfnGetParentModificationUuid}
758 */
759VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(visoGetParentModificationUuid);
760
761/**
762 * @interface_method_impl{VDIMAGEBACKEND,pfnSetParentModificationUuid}
763 */
764VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetParentModificationUuid, PVISOIMAGE);
765
766#undef uOpenFlags
767
768/**
769 * @interface_method_impl{VDIMAGEBACKEND,pfnDump}
770 */
771static DECLCALLBACK(void) visoDump(void *pBackendData)
772{
773 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
774 AssertPtrReturnVoid(pThis);
775
776 vdIfErrorMessage(pThis->pIfError, "Dumping CUE image '%s' fOpenFlags=%x cbImage=%#RX64\n",
777 pThis->pszFilename, pThis->fOpenFlags, pThis->cbImage);
778}
779
780
781
782/**
783 * VBox ISO maker backend.
784 */
785const VDIMAGEBACKEND g_VBoxIsoMakerBackend =
786{
787 /* u32Version */
788 VD_IMGBACKEND_VERSION,
789 /* pszBackendName */
790 "VBoxIsoMaker",
791 /* uBackendCaps */
792 VD_CAP_FILE,
793 /* paFileExtensions */
794 g_aVBoXIsoMakerFileExtensions,
795 /* paConfigInfo */
796 NULL,
797 /* pfnProbe */
798 visoProbe,
799 /* pfnOpen */
800 visoOpen,
801 /* pfnCreate */
802 NULL,
803 /* pfnRename */
804 NULL,
805 /* pfnClose */
806 visoClose,
807 /* pfnRead */
808 visoRead,
809 /* pfnWrite */
810 visoWrite,
811 /* pfnFlush */
812 visoFlush,
813 /* pfnDiscard */
814 NULL,
815 /* pfnGetVersion */
816 visoGetVersion,
817 /* pfnGetFileSize */
818 visoGetFileSize,
819 /* pfnGetPCHSGeometry */
820 visoGetPCHSGeometry,
821 /* pfnSetPCHSGeometry */
822 visoSetPCHSGeometry,
823 /* pfnGetLCHSGeometry */
824 visoGetLCHSGeometry,
825 /* pfnSetLCHSGeometry */
826 visoSetLCHSGeometry,
827 /* pfnQueryRegions */
828 visoQueryRegions,
829 /* pfnRegionListRelease */
830 visoRegionListRelease,
831 /* pfnGetImageFlags */
832 visoGetImageFlags,
833 /* pfnGetOpenFlags */
834 visoGetOpenFlags,
835 /* pfnSetOpenFlags */
836 visoSetOpenFlags,
837 /* pfnGetComment */
838 visoGetComment,
839 /* pfnSetComment */
840 visoSetComment,
841 /* pfnGetUuid */
842 visoGetUuid,
843 /* pfnSetUuid */
844 visoSetUuid,
845 /* pfnGetModificationUuid */
846 visoGetModificationUuid,
847 /* pfnSetModificationUuid */
848 visoSetModificationUuid,
849 /* pfnGetParentUuid */
850 visoGetParentUuid,
851 /* pfnSetParentUuid */
852 visoSetParentUuid,
853 /* pfnGetParentModificationUuid */
854 visoGetParentModificationUuid,
855 /* pfnSetParentModificationUuid */
856 visoSetParentModificationUuid,
857 /* pfnDump */
858 visoDump,
859 /* pfnGetTimestamp */
860 NULL,
861 /* pfnGetParentTimestamp */
862 NULL,
863 /* pfnSetParentTimestamp */
864 NULL,
865 /* pfnGetParentFilename */
866 NULL,
867 /* pfnSetParentFilename */
868 NULL,
869 /* pfnComposeLocation */
870 genericFileComposeLocation,
871 /* pfnComposeName */
872 genericFileComposeName,
873 /* pfnCompact */
874 NULL,
875 /* pfnResize */
876 NULL,
877 /* pfnRepair */
878 NULL,
879 /* pfnTraverseMetadata */
880 NULL,
881 /* u32VersionEnd */
882 VD_IMGBACKEND_VERSION
883};
884
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