Changeset 86134 in vbox for trunk/src/VBox
- Timestamp:
- Sep 16, 2020 3:39:09 PM (4 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r85929 r86134 1602 1602 { 1603 1603 ComPtr<IHostDrive> pHostDrive = apHostDrives[i]; 1604 1604 /* 1605 * The drive path and the model are obtained using different way 1606 * outside of the IHostDrive object, therefore, they are defined 1607 * even if another info is not available. 1608 */ 1605 1609 com::Bstr bstrDrivePath; 1606 1610 CHECK_ERROR(pHostDrive,COMGETTER(DrivePath)(bstrDrivePath.asOutParam())); … … 1608 1612 1609 1613 com::Bstr bstrModel; 1614 CHECK_ERROR(pHostDrive,COMGETTER(Model)(bstrModel.asOutParam())); 1615 if (bstrModel.isNotEmpty()) 1616 RTPrintf("Model: %ls\n", bstrModel.raw()); 1617 else 1618 RTPrintf("Model: Unknown\n"); 1619 1610 1620 com::Bstr bstrUuidDisk; 1611 1621 ULONG cbSectorSize = 0; … … 1613 1623 PartitioningType_T partitioningType; 1614 1624 HRESULT hrc; 1615 if ( SUCCEEDED(hrc = pHostDrive->COMGETTER(Model)(bstrModel.asOutParam())) 1616 && SUCCEEDED(hrc = pHostDrive->COMGETTER(Uuid)(bstrUuidDisk.asOutParam())) 1625 if ( SUCCEEDED(hrc = pHostDrive->COMGETTER(Uuid)(bstrUuidDisk.asOutParam())) 1617 1626 && SUCCEEDED(hrc = pHostDrive->COMGETTER(SectorSize)(&cbSectorSize)) 1618 1627 && SUCCEEDED(hrc = pHostDrive->COMGETTER(Size)(&cbSize)) 1619 1628 && SUCCEEDED(hrc = pHostDrive->COMGETTER(PartitioningType)(&partitioningType))) 1620 1629 { 1621 if (bstrModel.isNotEmpty())1622 RTPrintf("Model: %ls\n", bstrModel.raw());1623 else1624 RTPrintf("Model: Unknown\n");1625 1626 1630 if (partitioningType == PartitioningType_GPT || com::Guid(bstrUuidDisk).isZero()) 1627 1631 RTPrintf("UUID: %ls\n", bstrUuidDisk.raw()); -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r86069 r86134 10650 10650 </attribute> 10651 10651 10652 <attribute name="model" type="wstring" readonly="yes" >10652 <attribute name="model" type="wstring" readonly="yes" wrap-hint-server="limitedcaller"> 10653 10653 <desc> 10654 10654 The model string of the drive if available. -
trunk/src/VBox/Main/src-server/linux/HostHardwareLinux.cpp
r85932 r86134 38 38 #include <linux/fd.h> 39 39 #include <linux/major.h> 40 41 #include <linux/version.h> 42 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) 43 # include <linux/nvme_ioctl.h> 44 #else 45 # include <linux/nvme.h> 46 #endif 40 47 #include <scsi/scsi.h> 41 48 … … 349 356 AssertReturnVoid(!pszUdi || cbUdi > 0); 350 357 351 size_t cchVendor = strLenStripped(pcszVendor);352 358 size_t cchModel = strLenStripped(pcszModel); 359 /* 360 * Vendor and Model strings can contain trailing spaces. 361 * Create trimmed copy of them because we should not modify 362 * original strings. 363 */ 364 char* pszStartTrimmed = RTStrStripL(pcszVendor); 365 char* pszVendor = RTStrDup(pszStartTrimmed); 366 RTStrStripR(pszVendor); 367 pszStartTrimmed = RTStrStripL(pcszModel); 368 char* pszModel = RTStrDup(pszStartTrimmed); 369 RTStrStripR(pszModel); 370 371 size_t cbVendor = strlen(pszVendor); 353 372 354 373 /* Create a cleaned version of the model string for the UDI string. */ … … 365 384 if (pszDesc) 366 385 { 367 if (c chVendor > 0)368 { 369 RTStrPrintf(pszDesc, cbDesc, "%.*s %s", c chVendor, pcszVendor, cchModel > 0 ? pcszModel : "(unknown drive model)");386 if (cbVendor > 0) 387 { 388 RTStrPrintf(pszDesc, cbDesc, "%.*s %s", cbVendor, pszVendor, strlen(pszModel) > 0 ? pszModel : "(unknown drive model)"); 370 389 RTStrPurgeEncoding(pszDesc); 371 390 } 372 391 else 373 RTStrCopy(pszDesc, cbDesc, p cszModel);392 RTStrCopy(pszDesc, cbDesc, pszModel); 374 393 } 375 394 /* Construct the UDI string */ … … 383 402 } 384 403 404 /** 405 * Check whether the device is the NVME device. 406 * @returns true on success, false if the name was not available (i.e. the 407 * device was not readable, or the file name wasn't a NVME device) 408 * @param pcszNode the path to the device node for the device 409 */ 410 static bool probeNVME(const char *pcszNode) RT_NOTHROW_DEF 411 { 412 AssertPtrReturn(pcszNode, false); 413 RTFILE File; 414 int rc = RTFileOpen(&File, pcszNode, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_NON_BLOCK); 415 if (RT_SUCCESS(rc)) 416 { 417 int rcIoCtl; 418 rc = RTFileIoCtl(File, NVME_IOCTL_ID, NULL, 0, &rcIoCtl); 419 RTFileClose(File); 420 if (RT_SUCCESS(rc) && rcIoCtl >= 0) 421 return true; 422 } 423 return false; 424 } 385 425 386 426 /** … … 736 776 int64_t type = 0; 737 777 int rc = RTLinuxSysFsReadIntFile(10, &type, "block/%s/device/type", mpcszName); 738 if (RT_SUCCESS(rc) && type != TYPE_DISK) 739 return; 778 if (!RT_SUCCESS(rc) || type != TYPE_DISK) 779 { 780 if (noProbe() || !probeNVME(mszNode)) 781 { 782 char szDriver[16]; 783 rc = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver), NULL, "block/%s/%s", 784 mpcszName, "device/device/driver"); 785 if (RT_FAILURE(rc) || RTStrCmp(szDriver, "nvme")) 786 return; 787 } 788 } 740 789 char szVendor[128]; 741 rc = RTLinuxSysFsReadStrFile(szVendor, sizeof(szVendor), NULL, "block/%s/device/vendor", mpcszName); 790 char szModel[128]; 791 size_t cbRead = 0; 792 rc = RTLinuxSysFsReadStrFile(szVendor, sizeof(szVendor), &cbRead, "block/%s/device/vendor", mpcszName); 793 szVendor[cbRead] = '\0'; 794 /* Assume the model is always present. Vendor is not present for NVME disks */ 795 cbRead = 0; 796 rc = RTLinuxSysFsReadStrFile(szModel, sizeof(szModel), &cbRead, "block/%s/device/model", mpcszName); 797 szModel[cbRead] = '\0'; 742 798 if (RT_SUCCESS(rc)) 743 799 { 744 char szModel[128]; 745 rc = RTLinuxSysFsReadStrFile(szModel, sizeof(szModel), NULL, "block/%s/device/model", mpcszName); 746 if (RT_SUCCESS(rc)) 747 { 748 misValid = true; 749 dvdCreateDeviceStrings(szVendor, szModel, mszDesc, sizeof(mszDesc), mszUdi, sizeof(mszUdi)); 750 return; 751 } 800 misValid = true; 801 dvdCreateDeviceStrings(szVendor, szModel, mszDesc, sizeof(mszDesc), mszUdi, sizeof(mszUdi)); 752 802 } 753 803 }
Note:
See TracChangeset
for help on using the changeset viewer.