VirtualBox

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

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

Storage/VISO.cpp: Validate encoding; Avoid duplicating the file when converting to argv; Error handing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.2 KB
Line 
1/* $Id: VISO.cpp 67599 2017-06-26 09:18:19Z 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 VBox status code.
242 * @param pThis The VISO image instance.
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 * Make sure it's valid UTF-8 before letting
288 */
289 rc = RTStrValidateEncodingEx(pszContent, sizeof(s_szCmdPrefix) + cbFile,
290 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH
291 | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
292 if (RT_SUCCESS(rc))
293 {
294 /*
295 * Convert it into an argument vector.
296 * Free the content afterwards to reduce memory pressure.
297 */
298 uint32_t fGetOpt = strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker-ms")) != 0
299 ? RTGETOPTARGV_CNV_QUOTE_BOURNE_SH : RTGETOPTARGV_CNV_QUOTE_MS_CRT;
300 fGetOpt |= RTGETOPTARGV_CNV_MODIFY_INPUT;
301 char **papszArgs;
302 int cArgs;
303 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszContent, fGetOpt, NULL);
304
305 if (RT_SUCCESS(rc))
306 {
307 /*
308 * Try instantiate the ISO image maker.
309 * Free the argument vector afterward to reduce memory pressure.
310 */
311 RTVFSFILE hVfsFile;
312 RTERRINFOSTATIC ErrInfo;
313 rc = RTFsIsoMakerCmdEx(cArgs, papszArgs, &hVfsFile, RTErrInfoInitStatic(&ErrInfo));
314
315 RTGetOptArgvFreeEx(papszArgs, fGetOpt);
316 papszArgs = NULL;
317
318 if (RT_SUCCESS(rc))
319 {
320 uint64_t cbImage;
321 rc = RTVfsFileGetSize(hVfsFile, &cbImage);
322 if (RT_SUCCESS(rc))
323 {
324 /*
325 * Update the state.
326 */
327 pThis->cbImage = cbImage;
328 pThis->RegionList.aRegions[0].cRegionBlocksOrBytes = cbImage;
329
330 pThis->hIsoFile = hVfsFile;
331 hVfsFile = NIL_RTVFSFILE;
332
333 rc = VINF_SUCCESS;
334 }
335
336 RTVfsFileRelease(hVfsFile);
337 }
338 else if (RTErrInfoIsSet(&ErrInfo.Core))
339 {
340 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg));
341 vdIfError(pThis->pIfError, rc, RT_SRC_POS, "VISO: %s", ErrInfo.Core.pszMsg);
342 }
343 else
344 {
345 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc\n", rc));
346 vdIfError(pThis->pIfError, rc, RT_SRC_POS, "VISO: RTFsIsoMakerCmdEx failed: %Rrc", rc);
347 }
348 }
349 }
350 else
351 vdIfError(pThis->pIfError, rc, RT_SRC_POS, "VISO: Invalid file encoding");
352 }
353 }
354 else
355 rc = VERR_VD_GEN_INVALID_HEADER;
356 }
357
358 RTMemTmpFree(pszContent);
359 }
360 else
361 rc = VERR_NO_TMP_MEMORY;
362 }
363 else
364 {
365 LogRel(("visoOpen: VERR_VD_INVALID_SIZE - cbFile=%#RX64 cbMaxFile=%#RX64\n",
366 cbFile, (uint64_t)VISO_MAX_FILE_SIZE));
367 rc = VERR_VD_INVALID_SIZE;
368 }
369 }
370
371 vdIfIoIntFileClose(pThis->pIfIo, pStorage);
372 return rc;
373}
374
375
376/**
377 * @interface_method_impl{VDIMAGEBACKEND,pfnOpen}
378 */
379static DECLCALLBACK(int) visoOpen(const char *pszFilename, unsigned uOpenFlags, PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
380 VDTYPE enmType, void **ppBackendData)
381{
382 uint32_t const fOpenFlags = uOpenFlags;
383 LogFlowFunc(("pszFilename='%s' fOpenFlags=%#x pVDIfsDisk=%p pVDIfsImage=%p enmType=%u ppBackendData=%p\n",
384 pszFilename, fOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
385
386 /*
387 * Validate input.
388 */
389 AssertPtrReturn(ppBackendData, VERR_INVALID_POINTER);
390 *ppBackendData = NULL;
391
392 AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
393 AssertReturn(*pszFilename, VERR_INVALID_POINTER);
394
395 AssertReturn(!(fOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_FLAGS);
396
397 PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
398 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
399
400 PVDINTERFACEERROR pIfError = VDIfErrorGet(pVDIfsDisk);
401
402 AssertReturn(enmType == VDTYPE_OPTICAL_DISC, VERR_NOT_SUPPORTED);
403
404 /*
405 * Allocate and initialize the backend image instance data.
406 */
407 int rc;
408 size_t cbFilename = strlen(pszFilename) + 1;
409 PVISOIMAGE pThis = (PVISOIMAGE)RTMemAllocZ(RT_UOFFSETOF(VISOIMAGE, RegionList.aRegions[1]) + cbFilename);
410 if (pThis)
411 {
412 pThis->hIsoFile = NIL_RTVFSFILE;
413 pThis->cbImage = 0;
414 pThis->fOpenFlags = fOpenFlags;
415 pThis->pszFilename = (char *)memcpy(&pThis->RegionList.aRegions[1], pszFilename, cbFilename);
416 pThis->pIfIo = pIfIo;
417 pThis->pIfError = pIfError;
418
419 pThis->RegionList.fFlags = 0;
420 pThis->RegionList.cRegions = 1;
421 pThis->RegionList.aRegions[0].offRegion = 0;
422 pThis->RegionList.aRegions[0].cRegionBlocksOrBytes = 0;
423 pThis->RegionList.aRegions[0].cbBlock = 2048;
424 pThis->RegionList.aRegions[0].enmDataForm = VDREGIONDATAFORM_RAW;
425 pThis->RegionList.aRegions[0].enmMetadataForm = VDREGIONMETADATAFORM_NONE;
426 pThis->RegionList.aRegions[0].cbData = 2048;
427 pThis->RegionList.aRegions[0].cbMetadata = 0;
428
429 /*
430 * Only go all the way if this isn't an info query. Re-mastering an ISO
431 * can potentially be a lot of work and we don't want to go thru with it
432 * just because the GUI wants to display the image size.
433 */
434 if (!(fOpenFlags & VD_OPEN_FLAGS_INFO))
435 rc = visoOpenWorker(pThis);
436 else
437 rc = visoProbeWorker(pThis->pszFilename, pThis->pIfIo, &pThis->Uuid);
438 if (RT_SUCCESS(rc))
439 {
440 *ppBackendData = pThis;
441 LogFlowFunc(("returns VINF_SUCCESS (UUID=%RTuuid, pszFilename=%s)\n", &pThis->Uuid, pThis->pszFilename));
442 return VINF_SUCCESS;
443 }
444
445 RTMemFree(pThis);
446 }
447 else
448 rc = VERR_NO_MEMORY;
449 LogFlowFunc(("returns %Rrc\n", rc));
450 return rc;
451}
452
453
454/**
455 * @interface_method_impl{VDIMAGEBACKEND,pfnClose}
456 */
457static DECLCALLBACK(int) visoClose(void *pBackendData, bool fDelete)
458{
459 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
460 LogFlowFunc(("pThis=%p fDelete=%RTbool\n", pThis, fDelete));
461
462 if (pThis)
463 {
464 if (fDelete)
465 vdIfIoIntFileDelete(pThis->pIfIo, pThis->pszFilename);
466
467 if (pThis->hIsoFile != NIL_RTVFSFILE)
468 {
469 RTVfsFileRelease(pThis->hIsoFile);
470 pThis->hIsoFile = NIL_RTVFSFILE;
471 }
472
473 RTMemFree(pThis);
474 }
475
476 LogFlowFunc(("returns VINF_SUCCESS\n"));
477 return VINF_SUCCESS;
478}
479
480/**
481 * @interface_method_impl{VDIMAGEBACKEND,pfnRead}
482 */
483static DECLCALLBACK(int) visoRead(void *pBackendData, uint64_t uOffset, size_t cbToRead, PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
484{
485 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
486 uint64_t off = uOffset;
487 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
488 AssertReturn(pThis->hIsoFile != NIL_RTVFSFILE, VERR_VD_NOT_OPENED);
489 LogFlowFunc(("pThis=%p off=%#RX64 cbToRead=%#zx pIoCtx=%p pcbActuallyRead=%p\n", pThis, off, cbToRead, pIoCtx, pcbActuallyRead));
490
491 /*
492 * Check request.
493 */
494 AssertReturn( off < pThis->cbImage
495 || (off == pThis->cbImage && cbToRead == 0), VERR_EOF);
496
497 uint64_t cbLeftInImage = pThis->cbImage - off;
498 if (cbToRead >= cbLeftInImage)
499 cbToRead = cbLeftInImage; /* ASSUMES the caller can deal with this, given the pcbActuallyRead parameter... */
500
501 /*
502 * Work the I/O context using vdIfIoIntIoCtxSegArrayCreate.
503 */
504 int rc = VINF_SUCCESS;
505 size_t cbActuallyRead = 0;
506 while (cbToRead > 0)
507 {
508 RTSGSEG Seg;
509 unsigned cSegs = 1;
510 size_t cbThisRead = vdIfIoIntIoCtxSegArrayCreate(pThis->pIfIo, pIoCtx, &Seg, &cSegs, cbToRead);
511 AssertBreakStmt(cbThisRead != 0, rc = VERR_INTERNAL_ERROR_2);
512 Assert(cbThisRead == Seg.cbSeg);
513
514 rc = RTVfsFileReadAt(pThis->hIsoFile, off, Seg.pvSeg, cbThisRead, NULL);
515 AssertRCBreak(rc);
516
517 /* advance. */
518 cbActuallyRead += cbThisRead;
519 off += cbThisRead;
520 cbToRead -= cbThisRead;
521 }
522
523 *pcbActuallyRead = cbActuallyRead;
524 return rc;
525}
526
527/**
528 * @interface_method_impl{VDIMAGEBACKEND,pfnWrite}
529 */
530static DECLCALLBACK(int) visoWrite(void *pBackendData, uint64_t uOffset, size_t cbToWrite,
531 PVDIOCTX pIoCtx, size_t *pcbWriteProcess, size_t *pcbPreRead,
532 size_t *pcbPostRead, unsigned fWrite)
533{
534 RT_NOREF(uOffset, cbToWrite, pIoCtx, pcbWriteProcess, pcbPreRead, pcbPostRead, fWrite);
535 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
536 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
537 AssertReturn(pThis->hIsoFile != NIL_RTVFSFILE, VERR_VD_NOT_OPENED);
538 LogFlowFunc(("pThis=%p off=%#RX64 pIoCtx=%p cbToWrite=%#zx pcbWriteProcess=%p pcbPreRead=%p pcbPostRead=%p -> VERR_VD_IMAGE_READ_ONLY\n",
539 pThis, uOffset, pIoCtx, cbToWrite, pcbWriteProcess, pcbPreRead, pcbPostRead));
540 return VERR_VD_IMAGE_READ_ONLY;
541}
542
543/**
544 * @interface_method_impl{VDIMAGEBACKEND,pfnFlush}
545 */
546static DECLCALLBACK(int) visoFlush(void *pBackendData, PVDIOCTX pIoCtx)
547{
548 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
549 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
550 AssertReturn(pThis->hIsoFile != NIL_RTVFSFILE, VERR_VD_NOT_OPENED);
551 RT_NOREF(pIoCtx);
552 return VINF_SUCCESS;
553}
554
555/**
556 * @interface_method_impl{VDIMAGEBACKEND,pfnGetVersion}
557 */
558static DECLCALLBACK(unsigned) visoGetVersion(void *pBackendData)
559{
560 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
561 AssertPtrReturn(pThis, 0);
562 LogFlowFunc(("pThis=%#p -> 1\n", pThis));
563 return 1;
564}
565
566/**
567 * @interface_method_impl{VDIMAGEBACKEND,pfnGetFileSize}
568 */
569static DECLCALLBACK(uint64_t) visoGetFileSize(void *pBackendData)
570{
571 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
572 AssertPtrReturn(pThis, 0);
573 LogFlowFunc(("pThis=%p -> %RX64 (%s)\n", pThis, pThis->cbImage, pThis->hIsoFile == NIL_RTVFSFILE ? "fake!" : "real"));
574 return pThis->cbImage;
575}
576
577/**
578 * @interface_method_impl{VDIMAGEBACKEND,pfnGetPCHSGeometry}
579 */
580static DECLCALLBACK(int) visoGetPCHSGeometry(void *pBackendData, PVDGEOMETRY pPCHSGeometry)
581{
582 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
583 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
584 LogFlowFunc(("pThis=%p pPCHSGeometry=%p -> VERR_NOT_SUPPORTED\n", pThis, pPCHSGeometry));
585 RT_NOREF(pPCHSGeometry);
586 return VERR_NOT_SUPPORTED;
587}
588
589/**
590 * @interface_method_impl{VDIMAGEBACKEND,pfnSetPCHSGeometry}
591 */
592static DECLCALLBACK(int) visoSetPCHSGeometry(void *pBackendData, PCVDGEOMETRY pPCHSGeometry)
593{
594 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
595 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
596 LogFlowFunc(("pThis=%p pPCHSGeometry=%p:{%u/%u/%u} -> VERR_VD_IMAGE_READ_ONLY\n",
597 pThis, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
598 RT_NOREF(pPCHSGeometry);
599 return VERR_VD_IMAGE_READ_ONLY;
600}
601
602/**
603 * @interface_method_impl{VDIMAGEBACKEND,pfnGetLCHSGeometry}
604 */
605static DECLCALLBACK(int) visoGetLCHSGeometry(void *pBackendData, PVDGEOMETRY pLCHSGeometry)
606{
607 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
608 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
609 LogFlowFunc(("pThis=%p pLCHSGeometry=%p -> VERR_NOT_SUPPORTED\n", pThis, pLCHSGeometry));
610 RT_NOREF(pLCHSGeometry);
611 return VERR_NOT_SUPPORTED;
612}
613
614/**
615 * @interface_method_impl{VDIMAGEBACKEND,pfnSetLCHSGeometry}
616 */
617static DECLCALLBACK(int) visoSetLCHSGeometry(void *pBackendData, PCVDGEOMETRY pLCHSGeometry)
618{
619 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
620 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
621 LogFlowFunc(("pThis=%p pLCHSGeometry=%p:{%u/%u/%u} -> VERR_VD_IMAGE_READ_ONLY\n",
622 pThis, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
623 RT_NOREF(pLCHSGeometry);
624 return VERR_VD_IMAGE_READ_ONLY;
625}
626
627/**
628 * @interface_method_impl{VDIMAGEBACKEND,pfnQueryRegions}
629 */
630static DECLCALLBACK(int) visoQueryRegions(void *pBackendData, PCVDREGIONLIST *ppRegionList)
631{
632 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
633 *ppRegionList = NULL;
634 AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
635
636 *ppRegionList = &pThis->RegionList;
637 LogFlowFunc(("returns VINF_SUCCESS (one region: 0 LB %RX64; pThis=%p)\n", pThis->RegionList.aRegions[0].cbData, pThis));
638 return VINF_SUCCESS;
639}
640
641/**
642 * @interface_method_impl{VDIMAGEBACKEND,pfnRegionListRelease}
643 */
644static DECLCALLBACK(void) visoRegionListRelease(void *pBackendData, PCVDREGIONLIST pRegionList)
645{
646 /* Nothing to do here. Just assert the input to avoid unused parameter warnings. */
647 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
648 LogFlowFunc(("pThis=%p pRegionList=%p\n", pThis, pRegionList));
649 AssertPtrReturnVoid(pThis);
650 AssertReturnVoid(pRegionList == &pThis->RegionList || pRegionList == 0);
651}
652
653/**
654 * @interface_method_impl{VDIMAGEBACKEND,pfnGetImageFlags}
655 */
656static DECLCALLBACK(unsigned) visoGetImageFlags(void *pBackendData)
657{
658 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
659 LogFlowFunc(("pThis=%p -> VD_IMAGE_FLAGS_NONE\n", pThis));
660 AssertPtrReturn(pThis, VD_IMAGE_FLAGS_NONE);
661 return VD_IMAGE_FLAGS_NONE;
662}
663
664/**
665 * @interface_method_impl{VDIMAGEBACKEND,pfnGetOpenFlags}
666 */
667static DECLCALLBACK(unsigned) visoGetOpenFlags(void *pBackendData)
668{
669 LogFlowFunc(("pBackendData=%#p\n", pBackendData));
670 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
671 AssertPtrReturn(pThis, 0);
672
673 LogFlowFunc(("returns %#x\n", pThis->fOpenFlags));
674 return pThis->fOpenFlags;
675}
676
677/**
678 * @interface_method_impl{VDIMAGEBACKEND,pfnSetOpenFlags}
679 */
680static DECLCALLBACK(int) visoSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
681{
682 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
683 LogFlowFunc(("pThis=%p fOpenFlags=%#x\n", pThis, uOpenFlags));
684
685 AssertPtrReturn(pThis, VERR_INVALID_POINTER);
686 uint32_t const fSupported = VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_INFO
687 | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE
688 | VD_OPEN_FLAGS_SEQUENTIAL | VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS;
689 AssertMsgReturn(!(uOpenFlags & ~fSupported), ("fOpenFlags=%#x\n", uOpenFlags), VERR_INVALID_FLAGS);
690
691 /*
692 * Only react if we switch from VD_OPEN_FLAGS_INFO to non-VD_OPEN_FLAGS_INFO mode,
693 * becuase that means we need to open the image.
694 */
695 if ( (pThis->fOpenFlags & VD_OPEN_FLAGS_INFO)
696 && !(uOpenFlags & VD_OPEN_FLAGS_INFO)
697 && pThis->hIsoFile == NIL_RTVFSFILE)
698 {
699 int rc = visoOpenWorker(pThis);
700 if (RT_FAILURE(rc))
701 {
702 LogFlowFunc(("returns %Rrc\n", rc));
703 return rc;
704 }
705 }
706
707 /*
708 * Update the flags.
709 */
710 pThis->fOpenFlags &= ~fSupported;
711 pThis->fOpenFlags |= fSupported & uOpenFlags;
712 pThis->fOpenFlags |= VD_OPEN_FLAGS_READONLY;
713 if (pThis->hIsoFile != NIL_RTVFSFILE)
714 pThis->fOpenFlags &= ~VD_OPEN_FLAGS_INFO;
715
716 return VINF_SUCCESS;
717}
718
719#define uOpenFlags fOpenFlags /* sigh */
720
721/**
722 * @interface_method_impl{VDIMAGEBACKEND,pfnGetComment}
723 */
724VD_BACKEND_CALLBACK_GET_COMMENT_DEF_NOT_SUPPORTED(visoGetComment);
725
726/**
727 * @interface_method_impl{VDIMAGEBACKEND,pfnSetComment}
728 */
729VD_BACKEND_CALLBACK_SET_COMMENT_DEF_NOT_SUPPORTED(visoSetComment, PVISOIMAGE);
730
731/**
732 * @interface_method_impl{VDIMAGEBACKEND,pfnGetUuid}
733 */
734static DECLCALLBACK(int) visoGetUuid(void *pBackendData, PRTUUID pUuid)
735{
736 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
737 *pUuid = pThis->Uuid;
738 LogFlowFunc(("returns VIF_SUCCESS (%RTuuid)\n", pUuid));
739 return VINF_SUCCESS;
740}
741
742/**
743 * @interface_method_impl{VDIMAGEBACKEND,pfnSetUuid}
744 */
745VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetUuid, PVISOIMAGE);
746
747/**
748 * @interface_method_impl{VDIMAGEBACKEND,pfnGetModificationUuid}
749 */
750VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(visoGetModificationUuid);
751
752/**
753 * @interface_method_impl{VDIMAGEBACKEND,pfnSetModificationUuid}
754 */
755VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetModificationUuid, PVISOIMAGE);
756
757/**
758 * @interface_method_impl{VDIMAGEBACKEND,pfnGetParentUuid}
759 */
760VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(visoGetParentUuid);
761
762/**
763 * @interface_method_impl{VDIMAGEBACKEND,pfnSetParentUuid}
764 */
765VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetParentUuid, PVISOIMAGE);
766
767/**
768 * @interface_method_impl{VDIMAGEBACKEND,pfnGetParentModificationUuid}
769 */
770VD_BACKEND_CALLBACK_GET_UUID_DEF_NOT_SUPPORTED(visoGetParentModificationUuid);
771
772/**
773 * @interface_method_impl{VDIMAGEBACKEND,pfnSetParentModificationUuid}
774 */
775VD_BACKEND_CALLBACK_SET_UUID_DEF_NOT_SUPPORTED(visoSetParentModificationUuid, PVISOIMAGE);
776
777#undef uOpenFlags
778
779/**
780 * @interface_method_impl{VDIMAGEBACKEND,pfnDump}
781 */
782static DECLCALLBACK(void) visoDump(void *pBackendData)
783{
784 PVISOIMAGE pThis = (PVISOIMAGE)pBackendData;
785 AssertPtrReturnVoid(pThis);
786
787 vdIfErrorMessage(pThis->pIfError, "Dumping CUE image '%s' fOpenFlags=%x cbImage=%#RX64\n",
788 pThis->pszFilename, pThis->fOpenFlags, pThis->cbImage);
789}
790
791
792
793/**
794 * VBox ISO maker backend.
795 */
796const VDIMAGEBACKEND g_VBoxIsoMakerBackend =
797{
798 /* u32Version */
799 VD_IMGBACKEND_VERSION,
800 /* pszBackendName */
801 "VBoxIsoMaker",
802 /* uBackendCaps */
803 VD_CAP_FILE,
804 /* paFileExtensions */
805 g_aVBoXIsoMakerFileExtensions,
806 /* paConfigInfo */
807 NULL,
808 /* pfnProbe */
809 visoProbe,
810 /* pfnOpen */
811 visoOpen,
812 /* pfnCreate */
813 NULL,
814 /* pfnRename */
815 NULL,
816 /* pfnClose */
817 visoClose,
818 /* pfnRead */
819 visoRead,
820 /* pfnWrite */
821 visoWrite,
822 /* pfnFlush */
823 visoFlush,
824 /* pfnDiscard */
825 NULL,
826 /* pfnGetVersion */
827 visoGetVersion,
828 /* pfnGetFileSize */
829 visoGetFileSize,
830 /* pfnGetPCHSGeometry */
831 visoGetPCHSGeometry,
832 /* pfnSetPCHSGeometry */
833 visoSetPCHSGeometry,
834 /* pfnGetLCHSGeometry */
835 visoGetLCHSGeometry,
836 /* pfnSetLCHSGeometry */
837 visoSetLCHSGeometry,
838 /* pfnQueryRegions */
839 visoQueryRegions,
840 /* pfnRegionListRelease */
841 visoRegionListRelease,
842 /* pfnGetImageFlags */
843 visoGetImageFlags,
844 /* pfnGetOpenFlags */
845 visoGetOpenFlags,
846 /* pfnSetOpenFlags */
847 visoSetOpenFlags,
848 /* pfnGetComment */
849 visoGetComment,
850 /* pfnSetComment */
851 visoSetComment,
852 /* pfnGetUuid */
853 visoGetUuid,
854 /* pfnSetUuid */
855 visoSetUuid,
856 /* pfnGetModificationUuid */
857 visoGetModificationUuid,
858 /* pfnSetModificationUuid */
859 visoSetModificationUuid,
860 /* pfnGetParentUuid */
861 visoGetParentUuid,
862 /* pfnSetParentUuid */
863 visoSetParentUuid,
864 /* pfnGetParentModificationUuid */
865 visoGetParentModificationUuid,
866 /* pfnSetParentModificationUuid */
867 visoSetParentModificationUuid,
868 /* pfnDump */
869 visoDump,
870 /* pfnGetTimestamp */
871 NULL,
872 /* pfnGetParentTimestamp */
873 NULL,
874 /* pfnSetParentTimestamp */
875 NULL,
876 /* pfnGetParentFilename */
877 NULL,
878 /* pfnSetParentFilename */
879 NULL,
880 /* pfnComposeLocation */
881 genericFileComposeLocation,
882 /* pfnComposeName */
883 genericFileComposeName,
884 /* pfnCompact */
885 NULL,
886 /* pfnResize */
887 NULL,
888 /* pfnRepair */
889 NULL,
890 /* pfnTraverseMetadata */
891 NULL,
892 /* u32VersionEnd */
893 VD_IMGBACKEND_VERSION
894};
895
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