Changeset 85929 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Aug 28, 2020 2:40:55 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 140122
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r82968 r85929 29 29 30 30 #include <iprt/asm.h> 31 #include <iprt/base64.h> 31 32 #include <iprt/file.h> 32 33 #include <iprt/path.h> … … 38 39 #include <VBox/log.h> 39 40 #include <VBox/vd.h> 41 42 #include <list> 40 43 41 44 #include "VBoxManage.h" … … 96 99 else if (!RTStrNICmp(psz, "formatted", len)) 97 100 uMediumVariant |= MediumVariant_Formatted; 101 else if ( !RTStrNICmp(psz, "raw", len) 102 || !RTStrNICmp(psz, "rawdisk", len)) 103 uMediumVariant |= MediumVariant_VmdkRawDisk; 98 104 else 99 105 rc = VERR_PARSE_ERROR; … … 244 250 { "--variant", 'm', RTGETOPT_REQ_STRING }, 245 251 { "-variant", 'm', RTGETOPT_REQ_STRING }, // deprecated 246 { "--property", 'p', RTGETOPT_REQ_STRING } 252 { "--property", 'p', RTGETOPT_REQ_STRING }, 253 { "--property-file",'P', RTGETOPT_REQ_STRING }, 247 254 }; 248 255 249 256 RTEXITCODE handleCreateMedium(HandlerArg *a) 250 257 { 258 class MediumProperty 259 { 260 public: 261 const char *m_pszKey; 262 const char *m_pszValue; /**< Can be binary too. */ 263 size_t m_cbValue; 264 char *m_pszFreeValue; 265 MediumProperty() : m_pszKey(NULL), m_pszValue(NULL), m_cbValue(0), m_pszFreeValue(NULL) { } 266 MediumProperty(MediumProperty const &a_rThat) 267 : m_pszKey(a_rThat.m_pszKey) 268 , m_pszValue(a_rThat.m_pszValue) 269 , m_cbValue(a_rThat.m_cbValue) 270 , m_pszFreeValue(NULL) 271 { 272 Assert(a_rThat.m_pszFreeValue == NULL); /* not expected here! */ 273 } 274 ~MediumProperty() 275 { 276 RTMemFree(m_pszFreeValue); 277 m_pszFreeValue = NULL; 278 } 279 280 private: 281 MediumProperty &operator=(MediumProperty const &a_rThat) 282 { 283 m_pszKey = a_rThat.m_pszKey; 284 m_pszValue = a_rThat.m_pszValue; 285 m_cbValue = a_rThat.m_cbValue; 286 m_pszFreeValue = a_rThat.m_pszFreeValue; 287 if (a_rThat.m_pszFreeValue != NULL) 288 { 289 m_pszFreeValue = (char *)RTMemAlloc(m_cbValue + 1); 290 if (m_pszFreeValue) 291 { 292 memcpy(m_pszFreeValue, m_pszValue, m_cbValue + 1); 293 m_pszValue = m_pszFreeValue; 294 } 295 else 296 RTMsgError("Out of memory copying '%s'", m_pszValue); 297 } 298 return *this; 299 } 300 }; 301 std::list<MediumProperty> lstProperties; 302 251 303 HRESULT rc; 252 304 int vrc; … … 254 306 const char *diffparent = NULL; 255 307 uint64_t size = 0; 256 typedef struct MEDIUMPROPERTY_LIST257 {258 struct MEDIUMPROPERTY_LIST *next;259 const char *key;260 const char *value;261 } MEDIUMPROPERTY, *PMEDIUMPROPERTY;262 PMEDIUMPROPERTY pMediumProps = NULL;263 308 enum 264 309 { … … 322 367 323 368 case 'p': // --property 369 case 'P': // --property-file 324 370 { 325 371 /* allocate property kvp, parse, and append to end of singly linked list */ 326 # define PROP_MAXLEN 256 327 PMEDIUMPROPERTY pNewProp = (PMEDIUMPROPERTY)RTMemAlloc(sizeof(MEDIUMPROPERTY)); 328 if (!pNewProp) 329 return errorArgument("Can't allocate memory for property '%s'", ValueUnion.psz); 330 size_t cchKvp = RTStrNLen(ValueUnion.psz, PROP_MAXLEN); 331 char *pszEqual = (char *)memchr(ValueUnion.psz, '=', cchKvp); 332 if (pszEqual) 372 char *pszValue = (char *)strchr(ValueUnion.psz, '='); 373 if (!pszValue) 374 return RTMsgErrorExitFailure("Invalid key value pair: No '='."); 375 376 lstProperties.push_back(MediumProperty()); 377 MediumProperty &rNewProp = lstProperties.back(); 378 *pszValue++ = '\0'; /* Warning! Modifies argument string. */ 379 rNewProp.m_pszKey = ValueUnion.psz; 380 if (c == 'p') 333 381 { 334 *pszEqual = '\0'; /* Warning! Modifies argument string. */ 335 pNewProp->next = NULL; 336 pNewProp->key = (char *)ValueUnion.psz; 337 pNewProp->value = pszEqual + 1; 382 rNewProp.m_pszValue = pszValue; 383 rNewProp.m_cbValue = strlen(pszValue); 338 384 } 339 if (pMediumProps)385 else // 'P' 340 386 { 341 PMEDIUMPROPERTY pProp; 342 for (pProp = pMediumProps; pProp->next; pProp = pProp->next) 343 continue; 344 pProp->next = pNewProp; 387 RTFILE hValueFile = NIL_RTFILE; 388 vrc = RTFileOpen(&hValueFile, pszValue, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 389 if (RT_FAILURE(vrc)) 390 return RTMsgErrorExitFailure("Cannot open replacement value file '%s': %Rrc", pszValue, vrc); 391 392 uint64_t cbValue = 0; 393 vrc = RTFileQuerySize(hValueFile, &cbValue); 394 if (RT_SUCCESS(vrc)) 395 { 396 if (cbValue <= _16M) 397 { 398 rNewProp.m_cbValue = (size_t)cbValue; 399 rNewProp.m_pszValue = rNewProp.m_pszFreeValue = (char *)RTMemAlloc(rNewProp.m_cbValue + 1); 400 if (rNewProp.m_pszFreeValue) 401 { 402 vrc = RTFileReadAt(hValueFile, 0, rNewProp.m_pszFreeValue, cbValue, NULL); 403 if (RT_SUCCESS(vrc)) 404 rNewProp.m_pszFreeValue[rNewProp.m_cbValue] = '\0'; 405 else 406 RTMsgError("Error reading replacement MBR file '%s': %Rrc", pszValue, vrc); 407 } 408 else 409 vrc = RTMsgErrorRc(VERR_NO_MEMORY, "Out of memory reading '%s': %Rrc", pszValue, vrc); 410 } 411 else 412 vrc = RTMsgErrorRc(VERR_OUT_OF_RANGE, "Replacement value file '%s' is to big: %Rhcb, max 16MiB", pszValue, cbValue); 413 } 414 else 415 RTMsgError("Cannot get the size of the value file '%s': %Rrc", pszValue, vrc); 416 RTFileClose(hValueFile); 417 if (RT_FAILURE(vrc)) 418 return RTEXITCODE_FAILURE; 345 419 } 346 else347 pMediumProps = pNewProp;348 420 break; 349 421 } … … 389 461 if (fBase) 390 462 { 391 if ( !filename392 || !*filename393 ||size == 0)394 return errorSyntax(USAGE_CREATEMEDIUM, "Parameters -- filename and --size arerequired");463 if (!filename || !*filename) 464 return errorSyntax(USAGE_CREATEMEDIUM, "Parameters --filename is required"); 465 if ((enmMediumVariant & MediumVariant_VmdkRawDisk) == 0 && size == 0) 466 return errorSyntax(USAGE_CREATEMEDIUM, "Parameters --size is required"); 395 467 if (!format || !*format) 396 468 { … … 482 554 if (SUCCEEDED(rc) && pMedium) 483 555 { 484 if (pMediumProps) 485 for (PMEDIUMPROPERTY pProp = pMediumProps; pProp;) 556 if (lstProperties.size() > 0) 557 { 558 ComPtr<IMediumFormat> pMediumFormat; 559 CHECK_ERROR2I_RET(pMedium, COMGETTER(MediumFormat)(pMediumFormat.asOutParam()), RTEXITCODE_FAILURE); 560 com::SafeArray<BSTR> propertyNames; 561 com::SafeArray<BSTR> propertyDescriptions; 562 com::SafeArray<DataType_T> propertyTypes; 563 com::SafeArray<ULONG> propertyFlags; 564 com::SafeArray<BSTR> propertyDefaults; 565 CHECK_ERROR2I_RET(pMediumFormat, 566 DescribeProperties(ComSafeArrayAsOutParam(propertyNames), 567 ComSafeArrayAsOutParam(propertyDescriptions), 568 ComSafeArrayAsOutParam(propertyTypes), 569 ComSafeArrayAsOutParam(propertyFlags), 570 ComSafeArrayAsOutParam(propertyDefaults)), 571 RTEXITCODE_FAILURE); 572 573 for (std::list<MediumProperty>::iterator it = lstProperties.begin(); 574 it != lstProperties.end(); 575 ++it) 486 576 { 487 CHECK_ERROR(pMedium, SetProperty(Bstr(pProp->key).raw(), Bstr(pProp->value).raw())); 488 PMEDIUMPROPERTY next = pProp->next; 489 RTMemFree(pProp); 490 pProp = next; 577 const char * const pszKey = it->m_pszKey; 578 bool fBinary = true; 579 for (size_t i = 0; i < propertyNames.size(); ++i) 580 if (RTUtf16CmpUtf8(propertyNames[i], pszKey) == 0) 581 { 582 fBinary = propertyTypes[i] == DataType_Int8; 583 break; 584 } 585 if (!fBinary) 586 CHECK_ERROR2I_RET(pMedium, SetProperty(Bstr(pszKey).raw(), Bstr(it->m_pszValue).raw()), 587 RTEXITCODE_FAILURE); 588 else 589 { 590 com::Bstr bstrBase64Value; 591 HRESULT hrc = bstrBase64Value.base64Encode(it->m_pszValue, it->m_cbValue); 592 if (FAILED(hrc)) 593 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Base64 encoding of the property %s failed. (%Rhrc)", 594 pszKey, hrc); 595 CHECK_ERROR2I_RET(pMedium, SetProperty(Bstr(pszKey).raw(), bstrBase64Value.raw()), RTEXITCODE_FAILURE); 596 } 491 597 } 598 } 492 599 493 600 ComPtr<IProgress> pProgress; -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r85778 r85929 480 480 " groups|webcams|screenshotformats|cloudproviders|\n" 481 481 #if defined(VBOX_WITH_CLOUD_NET) 482 " cloudprofiles|cloudnets|cpu-profiles \n"482 " cloudprofiles|cloudnets|cpu-profiles|hostdrives\n" 483 483 #else 484 " cloudprofiles|cpu-profiles \n"484 " cloudprofiles|cpu-profiles|hostdrives\n" 485 485 #endif 486 486 "\n", SEP); … … 1011 1011 " [--format VDI|VMDK|VHD] (default: VDI)]\n" 1012 1012 " [--variant Standard,Fixed,Split2G,Stream,ESX,\n" 1013 " Formatted]\n" 1014 " [[--property <name>=<value>] --property <name>=<value]...\n" 1013 " Formatted,RawDisk]\n" 1014 " [[--property <name>=<value>] --property <name>=<value>\n" 1015 " --property-file <name>=</path/to/file/with/value>]...\n" 1015 1016 "\n", SEP); 1016 1017 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r85769 r85929 1415 1415 1416 1416 /** 1417 * Translates PartitionType_T to a string if possible. 1418 * @returns read-only string if known value, @a pszUnknown if not. 1419 */ 1420 static const char *PartitionTypeToString(PartitionType_T enmType, const char *pszUnknown) 1421 { 1422 #define MY_CASE_STR(a_Type) case RT_CONCAT(PartitionType_,a_Type): return #a_Type 1423 switch (enmType) 1424 { 1425 MY_CASE_STR(Empty); 1426 MY_CASE_STR(FAT12); 1427 MY_CASE_STR(FAT16); 1428 MY_CASE_STR(FAT); 1429 MY_CASE_STR(IFS); 1430 MY_CASE_STR(FAT32CHS); 1431 MY_CASE_STR(FAT32LBA); 1432 MY_CASE_STR(FAT16B); 1433 MY_CASE_STR(Extended); 1434 MY_CASE_STR(WindowsRE); 1435 MY_CASE_STR(LinuxSwapOld); 1436 MY_CASE_STR(LinuxOld); 1437 MY_CASE_STR(DragonFlyBSDSlice); 1438 MY_CASE_STR(LinuxSwap); 1439 MY_CASE_STR(Linux); 1440 MY_CASE_STR(LinuxExtended); 1441 MY_CASE_STR(LinuxLVM); 1442 MY_CASE_STR(BSDSlice); 1443 MY_CASE_STR(AppleUFS); 1444 MY_CASE_STR(AppleHFS); 1445 MY_CASE_STR(Solaris); 1446 MY_CASE_STR(GPT); 1447 MY_CASE_STR(EFI); 1448 MY_CASE_STR(Unknown); 1449 MY_CASE_STR(MBR); 1450 MY_CASE_STR(iFFS); 1451 MY_CASE_STR(SonyBoot); 1452 MY_CASE_STR(LenovoBoot); 1453 MY_CASE_STR(WindowsMSR); 1454 MY_CASE_STR(WindowsBasicData); 1455 MY_CASE_STR(WindowsLDMMeta); 1456 MY_CASE_STR(WindowsLDMData); 1457 MY_CASE_STR(WindowsRecovery); 1458 MY_CASE_STR(WindowsStorageSpaces); 1459 MY_CASE_STR(WindowsStorageReplica); 1460 MY_CASE_STR(IBMGPFS); 1461 MY_CASE_STR(LinuxData); 1462 MY_CASE_STR(LinuxRAID); 1463 MY_CASE_STR(LinuxRootX86); 1464 MY_CASE_STR(LinuxRootAMD64); 1465 MY_CASE_STR(LinuxRootARM32); 1466 MY_CASE_STR(LinuxRootARM64); 1467 MY_CASE_STR(LinuxHome); 1468 MY_CASE_STR(LinuxSrv); 1469 MY_CASE_STR(LinuxPlainDmCrypt); 1470 MY_CASE_STR(LinuxLUKS); 1471 MY_CASE_STR(LinuxReserved); 1472 MY_CASE_STR(FreeBSDBoot); 1473 MY_CASE_STR(FreeBSDData); 1474 MY_CASE_STR(FreeBSDSwap); 1475 MY_CASE_STR(FreeBSDUFS); 1476 MY_CASE_STR(FreeBSDVinum); 1477 MY_CASE_STR(FreeBSDZFS); 1478 MY_CASE_STR(FreeBSDUnknown); 1479 MY_CASE_STR(AppleHFSPlus); 1480 MY_CASE_STR(AppleAPFS); 1481 MY_CASE_STR(AppleRAID); 1482 MY_CASE_STR(AppleRAIDOffline); 1483 MY_CASE_STR(AppleBoot); 1484 MY_CASE_STR(AppleLabel); 1485 MY_CASE_STR(AppleTvRecovery); 1486 MY_CASE_STR(AppleCoreStorage); 1487 MY_CASE_STR(SoftRAIDStatus); 1488 MY_CASE_STR(SoftRAIDScratch); 1489 MY_CASE_STR(SoftRAIDVolume); 1490 MY_CASE_STR(SoftRAIDCache); 1491 MY_CASE_STR(AppleUnknown); 1492 MY_CASE_STR(SolarisBoot); 1493 MY_CASE_STR(SolarisRoot); 1494 MY_CASE_STR(SolarisSwap); 1495 MY_CASE_STR(SolarisBackup); 1496 MY_CASE_STR(SolarisUsr); 1497 MY_CASE_STR(SolarisVar); 1498 MY_CASE_STR(SolarisHome); 1499 MY_CASE_STR(SolarisAltSector); 1500 MY_CASE_STR(SolarisReserved); 1501 MY_CASE_STR(SolarisUnknown); 1502 MY_CASE_STR(NetBSDSwap); 1503 MY_CASE_STR(NetBSDFFS); 1504 MY_CASE_STR(NetBSDLFS); 1505 MY_CASE_STR(NetBSDRAID); 1506 MY_CASE_STR(NetBSDConcatenated); 1507 MY_CASE_STR(NetBSDEncrypted); 1508 MY_CASE_STR(NetBSDUnknown); 1509 MY_CASE_STR(ChromeOSKernel); 1510 MY_CASE_STR(ChromeOSRootFS); 1511 MY_CASE_STR(ChromeOSFuture); 1512 MY_CASE_STR(ContLnxUsr); 1513 MY_CASE_STR(ContLnxRoot); 1514 MY_CASE_STR(ContLnxReserved); 1515 MY_CASE_STR(ContLnxRootRAID); 1516 MY_CASE_STR(HaikuBFS); 1517 MY_CASE_STR(MidntBSDBoot); 1518 MY_CASE_STR(MidntBSDData); 1519 MY_CASE_STR(MidntBSDSwap); 1520 MY_CASE_STR(MidntBSDUFS); 1521 MY_CASE_STR(MidntBSDVium); 1522 MY_CASE_STR(MidntBSDZFS); 1523 MY_CASE_STR(MidntBSDUnknown); 1524 MY_CASE_STR(OpenBSDData); 1525 MY_CASE_STR(QNXPowerSafeFS); 1526 MY_CASE_STR(Plan9); 1527 MY_CASE_STR(VMWareVMKCore); 1528 MY_CASE_STR(VMWareVMFS); 1529 MY_CASE_STR(VMWareReserved); 1530 MY_CASE_STR(VMWareUnknown); 1531 MY_CASE_STR(AndroidX86Bootloader); 1532 MY_CASE_STR(AndroidX86Bootloader2); 1533 MY_CASE_STR(AndroidX86Boot); 1534 MY_CASE_STR(AndroidX86Recovery); 1535 MY_CASE_STR(AndroidX86Misc); 1536 MY_CASE_STR(AndroidX86Metadata); 1537 MY_CASE_STR(AndroidX86System); 1538 MY_CASE_STR(AndroidX86Cache); 1539 MY_CASE_STR(AndroidX86Data); 1540 MY_CASE_STR(AndroidX86Persistent); 1541 MY_CASE_STR(AndroidX86Vendor); 1542 MY_CASE_STR(AndroidX86Config); 1543 MY_CASE_STR(AndroidX86Factory); 1544 MY_CASE_STR(AndroidX86FactoryAlt); 1545 MY_CASE_STR(AndroidX86Fastboot); 1546 MY_CASE_STR(AndroidX86OEM); 1547 MY_CASE_STR(AndroidARMMeta); 1548 MY_CASE_STR(AndroidARMExt); 1549 MY_CASE_STR(ONIEBoot); 1550 MY_CASE_STR(ONIEConfig); 1551 MY_CASE_STR(PowerPCPrep); 1552 MY_CASE_STR(XDGShrBootConfig); 1553 MY_CASE_STR(CephBlock); 1554 MY_CASE_STR(CephBlockDB); 1555 MY_CASE_STR(CephBlockDBDmc); 1556 MY_CASE_STR(CephBlockDBDmcLUKS); 1557 MY_CASE_STR(CephBlockDmc); 1558 MY_CASE_STR(CephBlockDmcLUKS); 1559 MY_CASE_STR(CephBlockWALog); 1560 MY_CASE_STR(CephBlockWALogDmc); 1561 MY_CASE_STR(CephBlockWALogDmcLUKS); 1562 MY_CASE_STR(CephDisk); 1563 MY_CASE_STR(CephDiskDmc); 1564 MY_CASE_STR(CephJournal); 1565 MY_CASE_STR(CephJournalDmc); 1566 MY_CASE_STR(CephJournalDmcLUKS); 1567 MY_CASE_STR(CephLockbox); 1568 MY_CASE_STR(CephMultipathBlock1); 1569 MY_CASE_STR(CephMultipathBlock2); 1570 MY_CASE_STR(CephMultipathBlockDB); 1571 MY_CASE_STR(CephMultipathBLockWALog); 1572 MY_CASE_STR(CephMultipathJournal); 1573 MY_CASE_STR(CephMultipathOSD); 1574 MY_CASE_STR(CephOSD); 1575 MY_CASE_STR(CephOSDDmc); 1576 MY_CASE_STR(CephOSDDmcLUKS); 1577 #ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK 1578 case PartitionType_32BitHack: break; 1579 #endif 1580 /* no default! */ 1581 } 1582 #undef MY_CASE_STR 1583 return pszUnknown; 1584 } 1585 1586 1587 /** 1588 * List all available host drives with their partitions. 1589 * 1590 * @returns See produceList. 1591 * @param pVirtualBox Reference to the IVirtualBox pointer. 1592 * @param fOptLong Long listing or human readable. 1593 */ 1594 static HRESULT listHostDrives(const ComPtr<IVirtualBox> pVirtualBox, bool fOptLong) 1595 { 1596 HRESULT rc = S_OK; 1597 ComPtr<IHost> pHost; 1598 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(Host)(pHost.asOutParam()), hrcCheck); 1599 com::SafeIfaceArray<IHostDrive> apHostDrives; 1600 CHECK_ERROR2I_RET(pHost, COMGETTER(HostDrives)(ComSafeArrayAsOutParam(apHostDrives)), hrcCheck); 1601 for (size_t i = 0; i < apHostDrives.size(); ++i) 1602 { 1603 ComPtr<IHostDrive> pHostDrive = apHostDrives[i]; 1604 1605 com::Bstr bstrDrivePath; 1606 CHECK_ERROR(pHostDrive,COMGETTER(DrivePath)(bstrDrivePath.asOutParam())); 1607 RTPrintf("%sDrive: %ls\n", i > 0 ? "\n" : "", bstrDrivePath.raw()); 1608 1609 com::Bstr bstrModel; 1610 com::Bstr bstrUuidDisk; 1611 ULONG cbSectorSize = 0; 1612 LONG64 cbSize = 0; 1613 PartitioningType_T partitioningType; 1614 HRESULT hrc; 1615 if ( SUCCEEDED(hrc = pHostDrive->COMGETTER(Model)(bstrModel.asOutParam())) 1616 && SUCCEEDED(hrc = pHostDrive->COMGETTER(Uuid)(bstrUuidDisk.asOutParam())) 1617 && SUCCEEDED(hrc = pHostDrive->COMGETTER(SectorSize)(&cbSectorSize)) 1618 && SUCCEEDED(hrc = pHostDrive->COMGETTER(Size)(&cbSize)) 1619 && SUCCEEDED(hrc = pHostDrive->COMGETTER(PartitioningType)(&partitioningType))) 1620 { 1621 if (bstrModel.isNotEmpty()) 1622 RTPrintf("Model: %ls\n", bstrModel.raw()); 1623 else 1624 RTPrintf("Model: Unknown\n"); 1625 1626 if (partitioningType == PartitioningType_GPT || com::Guid(bstrUuidDisk).isZero()) 1627 RTPrintf("UUID: %ls\n", bstrUuidDisk.raw()); 1628 if (fOptLong) 1629 RTPrintf("Size: %llu bytes (%Rhcb)\n", cbSize, cbSize); 1630 else 1631 RTPrintf("Size: %Rhcb\n", cbSize); 1632 RTPrintf("Sector Size: %u bytes\n", cbSectorSize); 1633 RTPrintf("Scheme: %s\n", partitioningType == PartitioningType_MBR ? "MBR" : "GPT"); 1634 1635 com::SafeIfaceArray<IHostDrivePartition> apHostDrivesPartitions; 1636 CHECK_ERROR(pHostDrive, COMGETTER(Partitions)(ComSafeArrayAsOutParam(apHostDrivesPartitions))); 1637 1638 if (partitioningType == PartitioningType_MBR) 1639 { 1640 if (fOptLong) 1641 RTPrintf("Partitions: First Last\n" 1642 "## Type Byte Size Byte Offset Cyl/Head/Sec Cyl/Head/Sec Active\n"); 1643 else 1644 RTPrintf("Partitions: First Last\n" 1645 "## Type Size Start Cyl/Head/Sec Cyl/Head/Sec Active\n"); 1646 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j) 1647 { 1648 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j]; 1649 1650 ULONG idx = 0; 1651 CHECK_ERROR(pHostDrivePartition, COMGETTER(Number)(&idx)); 1652 ULONG uType = 0; 1653 CHECK_ERROR(pHostDrivePartition, COMGETTER(TypeMBR)(&uType)); 1654 ULONG uStartCylinder = 0; 1655 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartCylinder)(&uStartCylinder)); 1656 ULONG uStartHead = 0; 1657 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartHead)(&uStartHead)); 1658 ULONG uStartSector = 0; 1659 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartSector)(&uStartSector)); 1660 ULONG uEndCylinder = 0; 1661 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndCylinder)(&uEndCylinder)); 1662 ULONG uEndHead = 0; 1663 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndHead)(&uEndHead)); 1664 ULONG uEndSector = 0; 1665 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndSector)(&uEndSector)); 1666 cbSize = 0; 1667 CHECK_ERROR(pHostDrivePartition, COMGETTER(Size)(&cbSize)); 1668 LONG64 offStart = 0; 1669 CHECK_ERROR(pHostDrivePartition, COMGETTER(Start)(&offStart)); 1670 BOOL fActive = 0; 1671 CHECK_ERROR(pHostDrivePartition, COMGETTER(Active)(&fActive)); 1672 PartitionType_T enmType = PartitionType_Unknown; 1673 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType)); 1674 1675 /* Max size & offset here is around 16TiB with 4KiB sectors. */ 1676 if (fOptLong) /* cb/off: max 16TiB; idx: max 64. */ 1677 RTPrintf("%2u %02x %14llu %14llu %4u/%3u/%2u %4u/%3u/%2u %s %s\n", 1678 idx, uType, cbSize, offStart, 1679 uStartCylinder, uStartHead, uStartSector, uEndCylinder, uEndHead, uEndSector, 1680 fActive ? "yes" : "no", PartitionTypeToString(enmType, "")); 1681 else 1682 RTPrintf("%2u %02x %8Rhcb %8Rhcb %4u/%3u/%2u %4u/%3u/%2u %s %s\n", 1683 idx, uType, (uint64_t)cbSize, (uint64_t)offStart, 1684 uStartCylinder, uStartHead, uStartSector, uEndCylinder, uEndHead, uEndSector, 1685 fActive ? "yes" : "no", PartitionTypeToString(enmType, "")); 1686 } 1687 } 1688 else /* GPT */ 1689 { 1690 /* Determin the max partition type length to try reduce the table width: */ 1691 size_t cchMaxType = 0; 1692 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j) 1693 { 1694 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j]; 1695 PartitionType_T enmType = PartitionType_Unknown; 1696 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType)); 1697 size_t const cchTypeNm = strlen(PartitionTypeToString(enmType, "e530bf6d-2754-4e9d-b260-60a5d0b80457")); 1698 cchMaxType = RT_MAX(cchTypeNm, cchMaxType); 1699 } 1700 cchMaxType = RT_MIN(cchMaxType, RTUUID_STR_LENGTH); 1701 1702 if (fOptLong) 1703 RTPrintf("Partitions:\n" 1704 "## %-*s Uuid Byte Size Byte Offset Active Name\n", 1705 (int)cchMaxType, "Type"); 1706 else 1707 RTPrintf("Partitions:\n" 1708 "## %-*s Uuid Size Start Active Name\n", 1709 (int)cchMaxType, "Type"); 1710 1711 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j) 1712 { 1713 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j]; 1714 1715 ULONG idx = 0; 1716 CHECK_ERROR(pHostDrivePartition, COMGETTER(Number)(&idx)); 1717 com::Bstr bstrUuidType; 1718 CHECK_ERROR(pHostDrivePartition, COMGETTER(TypeUuid)(bstrUuidType.asOutParam())); 1719 com::Bstr bstrUuidPartition; 1720 CHECK_ERROR(pHostDrivePartition, COMGETTER(Uuid)(bstrUuidPartition.asOutParam())); 1721 cbSize = 0; 1722 CHECK_ERROR(pHostDrivePartition, COMGETTER(Size)(&cbSize)); 1723 LONG64 offStart = 0; 1724 CHECK_ERROR(pHostDrivePartition, COMGETTER(Start)(&offStart)); 1725 BOOL fActive = 0; 1726 CHECK_ERROR(pHostDrivePartition, COMGETTER(Active)(&fActive)); 1727 com::Bstr bstrName; 1728 CHECK_ERROR(pHostDrivePartition, COMGETTER(Name)(bstrName.asOutParam())); 1729 1730 PartitionType_T enmType = PartitionType_Unknown; 1731 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType)); 1732 1733 Utf8Str strTypeConv; 1734 const char *pszTypeNm = PartitionTypeToString(enmType, NULL); 1735 if (!pszTypeNm) 1736 pszTypeNm = (strTypeConv = bstrUuidType).c_str(); 1737 else if (strlen(pszTypeNm) >= RTUUID_STR_LENGTH /* includes '\0' */) 1738 pszTypeNm -= RTUUID_STR_LENGTH - 1 - strlen(pszTypeNm); 1739 1740 if (fOptLong) 1741 RTPrintf("%2u %-*s %36ls %19llu %19llu %-3s %ls\n", idx, cchMaxType, pszTypeNm, 1742 bstrUuidPartition.raw(), cbSize, offStart, fActive ? "on" : "off", bstrName.raw()); 1743 else 1744 RTPrintf("%2u %-*s %36ls %8Rhcb %8Rhcb %-3s %ls\n", idx, cchMaxType, pszTypeNm, 1745 bstrUuidPartition.raw(), cbSize, offStart, fActive ? "on" : "off", bstrName.raw()); 1746 } 1747 } 1748 } 1749 else 1750 RTPrintf("Partitions and disk info for the drive %ls are not available. Error %Rhrc (%#RX32)\n", 1751 bstrDrivePath.raw(), hrc, hrc); 1752 } 1753 return rc; 1754 } 1755 1756 1757 /** 1417 1758 * The type of lists we can produce. 1418 1759 */ … … 1450 1791 kListCloudProviders, 1451 1792 kListCloudProfiles, 1452 kListCPUProfiles 1793 kListCPUProfiles, 1794 kListHostDrives 1453 1795 }; 1454 1796 … … 1807 2149 break; 1808 2150 2151 case kListHostDrives: 2152 rc = listHostDrives(pVirtualBox, fOptLong); 2153 break; 1809 2154 /* No default here, want gcc warnings. */ 1810 2155 … … 1865 2210 { "cloudprofiles", kListCloudProfiles, RTGETOPT_REQ_NOTHING }, 1866 2211 { "cpu-profiles", kListCPUProfiles, RTGETOPT_REQ_NOTHING }, 2212 { "hostdrives", kListHostDrives, RTGETOPT_REQ_NOTHING }, 1867 2213 }; 1868 2214 … … 1922 2268 case kListCloudProfiles: 1923 2269 case kListCPUProfiles: 2270 case kListHostDrives: 1924 2271 enmOptCommand = (enum ListType_T)ch; 1925 2272 if (fOptMultiple)
Note:
See TracChangeset
for help on using the changeset viewer.