Changeset 69840 in vbox for trunk/src/VBox/Storage/testcase
- Timestamp:
- Nov 27, 2017 3:19:30 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 119281
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/vbox-img.cpp
r69616 r69840 36 36 #include <iprt/assert.h> 37 37 #include <iprt/dvm.h> 38 #include <iprt/filesystem.h>39 38 #include <iprt/vfs.h> 40 39 … … 1360 1359 static int handleCompact(HandlerArg *a) 1361 1360 { 1362 int rc = VINF_SUCCESS;1363 1361 PVDISK pDisk = NULL; 1364 const char *pszFilename = NULL;1365 bool fFilesystemAware = false;1366 1362 VDINTERFACEQUERYRANGEUSE VDIfQueryRangeUse; 1367 1363 PVDINTERFACE pIfsCompact = NULL; … … 1372 1368 static const RTGETOPTDEF s_aOptions[] = 1373 1369 { 1374 { "--filename", 'f', RTGETOPT_REQ_STRING }, 1375 { "--filesystemaware", 'a', RTGETOPT_REQ_NOTHING } 1370 { "--filename", 'f', RTGETOPT_REQ_STRING }, 1371 { "--filesystemaware", 'a', RTGETOPT_REQ_NOTHING }, 1372 { "--file-system-aware", 'a', RTGETOPT_REQ_NOTHING }, 1376 1373 }; 1374 1375 const char *pszFilename = NULL; 1376 bool fFilesystemAware = false; 1377 bool fVerbose = true; 1378 1377 1379 int ch; 1378 1380 RTGETOPTUNION ValueUnion; … … 1405 1407 char *pszFormat = NULL; 1406 1408 VDTYPE enmType = VDTYPE_INVALID; 1407 rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType);1409 int rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType); 1408 1410 if (RT_FAILURE(rc)) 1409 1411 return errorSyntax("Format autodetect failed: %Rrc\n", rc); … … 1419 1421 return errorRuntime("Error while opening the image: %Rrf (%Rrc)\n", rc, rc); 1420 1422 1423 /* 1424 * If --file-system-aware, we first ask the disk volume manager (DVM) to 1425 * find the volumes on the disk. 1426 */ 1421 1427 if ( RT_SUCCESS(rc) 1422 1428 && fFilesystemAware) … … 1434 1440 && RTDvmMapGetValidVolumes(hDvm) > 0) 1435 1441 { 1436 /* Get all volumes and set the block query status callback. */ 1442 /* 1443 * Enumerate the volumes: Try finding a file system interpreter and 1444 * set the block query status callback to work with the FS. 1445 */ 1446 uint32_t iVol = 0; 1437 1447 RTDVMVOLUME hVol; 1438 1448 rc = RTDvmMapQueryFirstVolume(hDvm, &hVol); … … 1441 1451 while (RT_SUCCESS(rc)) 1442 1452 { 1453 if (fVerbose) 1454 { 1455 char *pszVolName; 1456 rc = RTDvmVolumeQueryName(hVol, &pszVolName); 1457 if (RT_FAILURE(rc)) 1458 pszVolName = NULL; 1459 RTMsgInfo("Vol%u: %Rhcb %u %s%s%s\n", iVol, RTDvmVolumeGetSize(hVol), 1460 RTDvmVolumeTypeGetDescr(RTDvmVolumeGetType(hVol)), 1461 pszVolName ? " " : "", pszVolName ? pszVolName : ""); 1462 RTStrFree(pszVolName); 1463 } 1464 1443 1465 RTVFSFILE hVfsFile; 1444 1466 rc = RTDvmVolumeCreateVfsFile(hVol, RTFILE_O_READWRITE, &hVfsFile); 1445 1467 if (RT_FAILURE(rc)) 1468 { 1469 errorRuntime("RTDvmVolumeCreateVfsFile failed: %Rrc\n"); 1446 1470 break; 1471 } 1447 1472 1448 1473 /* Try to detect the filesystem in this volume. */ 1474 RTERRINFOSTATIC ErrInfo; 1449 1475 RTVFS hVfs; 1450 rc = RTFilesystemVfsFromFile(hVfsFile, &hVfs); 1451 if (rc == VERR_NOT_SUPPORTED) 1452 { 1453 /* Release the file handle and continue.*/ 1454 RTVfsFileRelease(hVfsFile); 1455 } 1456 else if (RT_FAILURE(rc)) 1457 break; 1458 else 1476 rc = RTVfsMountVol(hVfsFile, RTVFSMNT_F_READ_ONLY | RTVFSMNT_F_FOR_RANGE_IN_USE, &hVfs, 1477 RTErrInfoInitStatic(&ErrInfo)); 1478 RTVfsFileRelease(hVfsFile); 1479 if (RT_SUCCESS(rc)) 1459 1480 { 1460 1481 PVBOXIMGVFS pVBoxImgVfs = (PVBOXIMGVFS)RTMemAllocZ(sizeof(VBOXIMGVFS)); 1461 1482 if (!pVBoxImgVfs) 1483 { 1484 RTVfsRelease(hVfs); 1462 1485 rc = VERR_NO_MEMORY; 1463 else 1464 { 1465 pVBoxImgVfs->hVfs = hVfs; 1466 pVBoxImgVfs->pNext = pVBoxImgVfsHead; 1467 pVBoxImgVfsHead = pVBoxImgVfs; 1468 RTDvmVolumeSetQueryBlockStatusCallback(hVol, vboximgQueryBlockStatus, hVfs); 1486 break; 1469 1487 } 1488 pVBoxImgVfs->hVfs = hVfs; 1489 pVBoxImgVfs->pNext = pVBoxImgVfsHead; 1490 pVBoxImgVfsHead = pVBoxImgVfs; 1491 RTDvmVolumeSetQueryBlockStatusCallback(hVol, vboximgQueryBlockStatus, hVfs); 1470 1492 } 1471 1493 else if (rc != VERR_NOT_SUPPORTED) 1494 { 1495 if (RTErrInfoIsSet(&ErrInfo.Core)) 1496 errorRuntime("RTVfsMountVol failed: %s\n", ErrInfo.Core.pszMsg); 1497 break; 1498 } 1499 else if (fVerbose && RTErrInfoIsSet(&ErrInfo.Core)) 1500 RTMsgInfo("Unsupported file system: %s", ErrInfo.Core.pszMsg); 1501 1502 /* 1503 * Advance. (Releasing hVol here is fine since RTDvmVolumeCreateVfsFile 1504 * retained a reference and the hVfs a reference of it again.) 1505 */ 1472 1506 RTDVMVOLUME hVolNext = NIL_RTDVMVOLUME; 1473 1507 if (RT_SUCCESS(rc)) 1474 1508 rc = RTDvmMapQueryNextVolume(hDvm, hVol, &hVolNext); 1475 1476 /*1477 * Release the volume handle, the file handle has a reference1478 * to keep it open.1479 */1480 1509 RTDvmVolumeRelease(hVol); 1481 1510 hVol = hVolNext; 1511 iVol++; 1482 1512 } 1483 1513 … … 1496 1526 else if (rc == VERR_NOT_FOUND) 1497 1527 { 1528 RTPrintf("No known volume format on disk found\n"); 1498 1529 rc = VINF_SUCCESS; 1499 RTPrintf("No known volume format on disk found\n");1500 1530 } 1501 1531 else
Note:
See TracChangeset
for help on using the changeset viewer.