@@ -63,6 +63,14 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
6363 continue ;
6464 }
6565
66+ uint64_t size = 0 ;
67+ {
68+ FF_CFTYPE_AUTO_RELEASE CFNumberRef mediaSize = IORegistryEntryCreateCFProperty (entryMedia , CFSTR (kIOMediaSizeKey ), kCFAllocatorDefault , kNilOptions );
69+ if (mediaSize ) {
70+ ffCfNumGetInt64 (mediaSize , (int64_t * ) & size );
71+ }
72+ }
73+
6674 FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryPhysical = 0 ;
6775 if (IORegistryEntryGetParentEntry (entryDriver , kIOServicePlane , & entryPhysical ) != KERN_SUCCESS ) {
6876 continue ;
@@ -78,12 +86,12 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
7886 }
7987
8088 FF_STRBUF_AUTO_DESTROY interconnect = ffStrbufCreate ();
81- FFPhysicalDiskType diskType = FF_PHYSICALDISK_TYPE_NONE ;
89+ bool isVirtual = false ;
8290 FF_CFTYPE_AUTO_RELEASE CFDictionaryRef protocolCharacteristics = IORegistryEntryCreateCFProperty (entryPhysical , CFSTR (kIOPropertyProtocolCharacteristicsKey ), kCFAllocatorDefault , kNilOptions );
8391 if (protocolCharacteristics ) {
8492 if (ffCfDictGetString (protocolCharacteristics , CFSTR (kIOPropertyPhysicalInterconnectTypeKey ), & interconnect ) == NULL ) {
8593 if (ffStrbufEqualS (& interconnect , kIOPropertyPhysicalInterconnectTypeVirtual )) {
86- diskType |= FF_PHYSICALDISK_TYPE_VIRTUAL ;
94+ isVirtual = true ;
8795 FF_STRBUF_AUTO_DESTROY location = ffStrbufCreate ();
8896 if (ffCfDictGetString (protocolCharacteristics , CFSTR (kIOPropertyPhysicalInterconnectLocationKey ), & location ) == NULL ) {
8997 ffStrbufAppendS (& interconnect , " - " );
@@ -99,8 +107,9 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
99107 ffStrbufInitS (& device -> name , deviceName );
100108 ffStrbufInit (& device -> devPath );
101109 ffStrbufInitMove (& device -> interconnect , & interconnect );
102- device -> type = diskType ;
103- device -> size = 0 ;
110+ device -> type = (isVirtual ? FF_PHYSICALDISK_TYPE_VIRTUAL : FF_PHYSICALDISK_TYPE_NONE ) |
111+ (size > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_UNKNOWN );
112+ device -> size = size ;
104113 device -> temperature = FF_PHYSICALDISK_TEMP_UNSET ;
105114
106115 FF_CFTYPE_AUTO_RELEASE CFBooleanRef removable = IORegistryEntryCreateCFProperty (entryMedia , CFSTR (kIOMediaRemovableKey ), kCFAllocatorDefault , kNilOptions );
@@ -119,13 +128,6 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
119128 ffStrbufPrependS (& device -> devPath , "/dev/" );
120129 }
121130
122- FF_CFTYPE_AUTO_RELEASE CFNumberRef mediaSize = IORegistryEntryCreateCFProperty (entryMedia , CFSTR (kIOMediaSizeKey ), kCFAllocatorDefault , kNilOptions );
123- if (mediaSize ) {
124- ffCfNumGetInt64 (mediaSize , (int64_t * ) & device -> size );
125- } else {
126- device -> size = 0 ;
127- }
128-
129131 FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty (entryPhysical , CFSTR (kIOPropertyDeviceCharacteristicsKey ), kCFAllocatorDefault , kNilOptions );
130132 if (deviceCharacteristics ) {
131133 ffCfDictGetString (deviceCharacteristics , CFSTR (kIOPropertyProductSerialNumberKey ), & device -> serial );
0 commit comments