Changeset 70395 in vbox for trunk/src/VBox/Storage/VISO.cpp
- Timestamp:
- Jan 1, 2018 12:26:11 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/VISO.cpp
r67761 r70395 25 25 26 26 #include <VBox/log.h> 27 //#include <VBox/scsiinline.h>28 27 #include <iprt/assert.h> 29 28 #include <iprt/ctype.h> … … 31 30 #include <iprt/getopt.h> 32 31 #include <iprt/mem.h> 32 #include <iprt/path.h> 33 33 #include <iprt/string.h> 34 34 #include <iprt/uuid.h> … … 68 68 /** Open flags passed by VD layer. */ 69 69 uint32_t fOpenFlags; 70 /** Image name (for debug). 70 /** Image name. Allocation follows the region list, no need to free. */ 71 const char *pszFilename; 72 /** The parent director of pszFilename. 71 73 * Allocation follows the region list, no need to free. */ 72 const char *psz Filename;74 const char *pszCwd; 73 75 74 76 /** I/O interface. */ … … 312 314 { 313 315 /* 314 * Try instantiate the ISO image maker. 315 * Free the argument vector afterward to reduce memory pressure. 316 * Open the parent directory and use that as CWD for relative references. 316 317 */ 317 RTVFSFILE hVfsFile; 318 RTERRINFOSTATIC ErrInfo; 319 rc = RTFsIsoMakerCmdEx(cArgs, papszArgs, &hVfsFile, RTErrInfoInitStatic(&ErrInfo)); 320 321 RTGetOptArgvFreeEx(papszArgs, fGetOpt); 322 papszArgs = NULL; 323 318 RTVFSDIR hVfsCwd; 319 rc = RTVfsChainOpenDir(pThis->pszCwd, 0 /*fOpen*/, &hVfsCwd, NULL, NULL); 324 320 if (RT_SUCCESS(rc)) 325 321 { 326 uint64_t cbImage; 327 rc = RTVfsFileGetSize(hVfsFile, &cbImage); 322 /* 323 * Try instantiate the ISO image maker. 324 * Free the argument vector afterward to reduce memory pressure. 325 */ 326 RTVFSFILE hVfsFile; 327 RTERRINFOSTATIC ErrInfo; 328 rc = RTFsIsoMakerCmdEx(cArgs, papszArgs, hVfsCwd, pThis->pszCwd, 329 &hVfsFile, RTErrInfoInitStatic(&ErrInfo)); 330 331 RTVfsDirRelease(hVfsCwd); 332 333 RTGetOptArgvFreeEx(papszArgs, fGetOpt); 334 papszArgs = NULL; 335 328 336 if (RT_SUCCESS(rc)) 329 337 { 330 /* 331 * Update the state. 332 */ 333 pThis->cbImage = cbImage; 334 pThis->RegionList.aRegions[0].cRegionBlocksOrBytes = cbImage; 335 336 pThis->hIsoFile = hVfsFile; 337 hVfsFile = NIL_RTVFSFILE; 338 339 rc = VINF_SUCCESS; 340 LogRel(("VISO: %'RU64 bytes (%#RX64) - %s\n", cbImage, cbImage, pThis->pszFilename)); 338 uint64_t cbImage; 339 rc = RTVfsFileGetSize(hVfsFile, &cbImage); 340 if (RT_SUCCESS(rc)) 341 { 342 /* 343 * Update the state. 344 */ 345 pThis->cbImage = cbImage; 346 pThis->RegionList.aRegions[0].cRegionBlocksOrBytes = cbImage; 347 348 pThis->hIsoFile = hVfsFile; 349 hVfsFile = NIL_RTVFSFILE; 350 351 rc = VINF_SUCCESS; 352 LogRel(("VISO: %'RU64 bytes (%#RX64) - %s\n", cbImage, cbImage, pThis->pszFilename)); 353 } 354 355 RTVfsFileRelease(hVfsFile); 341 356 } 342 343 RTVfsFileRelease(hVfsFile); 344 } 345 else if (RTErrInfoIsSet(&ErrInfo.Core)) 346 { 347 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg)); 348 vdIfError(pThis->pIfError, rc, RT_SRC_POS, "VISO: %s", ErrInfo.Core.pszMsg); 357 else if (RTErrInfoIsSet(&ErrInfo.Core)) 358 { 359 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc - %s\n", rc, ErrInfo.Core.pszMsg)); 360 vdIfError(pThis->pIfError, rc, RT_SRC_POS, "VISO: %s", ErrInfo.Core.pszMsg); 361 } 362 else 363 { 364 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc\n", rc)); 365 vdIfError(pThis->pIfError, rc, RT_SRC_POS, "VISO: RTFsIsoMakerCmdEx failed: %Rrc", rc); 366 } 349 367 } 350 368 else 351 { 352 LogRel(("visoOpenWorker: RTFsIsoMakerCmdEx failed: %Rrc\n", rc)); 353 vdIfError(pThis->pIfError, rc, RT_SRC_POS, "VISO: RTFsIsoMakerCmdEx failed: %Rrc", rc); 354 } 369 vdIfError(pThis->pIfError, rc, RT_SRC_POS, 370 "VISO: Failed to open parent dir of: %s", pThis->pszFilename); 355 371 } 356 372 } … … 414 430 int rc; 415 431 size_t cbFilename = strlen(pszFilename) + 1; 416 PVISOIMAGE pThis = (PVISOIMAGE)RTMemAllocZ(RT_UOFFSETOF(VISOIMAGE, RegionList.aRegions[1]) + cbFilename );432 PVISOIMAGE pThis = (PVISOIMAGE)RTMemAllocZ(RT_UOFFSETOF(VISOIMAGE, RegionList.aRegions[1]) + cbFilename * 2); 417 433 if (pThis) 418 434 { … … 420 436 pThis->cbImage = 0; 421 437 pThis->fOpenFlags = fOpenFlags; 422 pThis->pszFilename = (char *)memcpy(&pThis->RegionList.aRegions[1], pszFilename, cbFilename);423 438 pThis->pIfIo = pIfIo; 424 439 pThis->pIfError = pIfError; … … 433 448 pThis->RegionList.aRegions[0].cbData = 2048; 434 449 pThis->RegionList.aRegions[0].cbMetadata = 0; 450 451 char *pszDst = (char *)&pThis->RegionList.aRegions[1]; 452 memcpy(pszDst, pszFilename, cbFilename); 453 pThis->pszFilename = pszDst; 454 pszDst[cbFilename - 1] = '\0'; 455 pszDst += cbFilename; 456 457 memcpy(pszDst, pszFilename, cbFilename); 458 pThis->pszCwd = pszDst; 459 pszDst[cbFilename - 1] = '\0'; 460 RTPathStripFilename(pszDst); 435 461 436 462 /*
Note:
See TracChangeset
for help on using the changeset viewer.