diff --git a/src/detection/physicaldisk/physicaldisk_apple.c b/src/detection/physicaldisk/physicaldisk_apple.c index b48d857d4..69cc4ca13 100644 --- a/src/detection/physicaldisk/physicaldisk_apple.c +++ b/src/detection/physicaldisk/physicaldisk_apple.c @@ -63,6 +63,14 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) continue; } + uint64_t size = 0; + { + FF_CFTYPE_AUTO_RELEASE CFNumberRef mediaSize = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaSizeKey), kCFAllocatorDefault, kNilOptions); + if (mediaSize) { + ffCfNumGetInt64(mediaSize, (int64_t*) &size); + } + } + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryPhysical = 0; if (IORegistryEntryGetParentEntry(entryDriver, kIOServicePlane, &entryPhysical) != KERN_SUCCESS) { continue; @@ -78,12 +86,12 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) } FF_STRBUF_AUTO_DESTROY interconnect = ffStrbufCreate(); - FFPhysicalDiskType diskType = FF_PHYSICALDISK_TYPE_NONE; + bool isVirtual = false; FF_CFTYPE_AUTO_RELEASE CFDictionaryRef protocolCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyProtocolCharacteristicsKey), kCFAllocatorDefault, kNilOptions); if (protocolCharacteristics) { if (ffCfDictGetString(protocolCharacteristics, CFSTR(kIOPropertyPhysicalInterconnectTypeKey), &interconnect) == NULL) { if (ffStrbufEqualS(&interconnect, kIOPropertyPhysicalInterconnectTypeVirtual)) { - diskType |= FF_PHYSICALDISK_TYPE_VIRTUAL; + isVirtual = true; FF_STRBUF_AUTO_DESTROY location = ffStrbufCreate(); if (ffCfDictGetString(protocolCharacteristics, CFSTR(kIOPropertyPhysicalInterconnectLocationKey), &location) == NULL) { ffStrbufAppendS(&interconnect, " - "); @@ -99,8 +107,9 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) ffStrbufInitS(&device->name, deviceName); ffStrbufInit(&device->devPath); ffStrbufInitMove(&device->interconnect, &interconnect); - device->type = diskType; - device->size = 0; + device->type = (isVirtual ? FF_PHYSICALDISK_TYPE_VIRTUAL : FF_PHYSICALDISK_TYPE_NONE) | + (size > 0 ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_UNKNOWN); + device->size = size; device->temperature = FF_PHYSICALDISK_TEMP_UNSET; FF_CFTYPE_AUTO_RELEASE CFBooleanRef removable = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaRemovableKey), kCFAllocatorDefault, kNilOptions); @@ -119,13 +128,6 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) ffStrbufPrependS(&device->devPath, "/dev/"); } - FF_CFTYPE_AUTO_RELEASE CFNumberRef mediaSize = IORegistryEntryCreateCFProperty(entryMedia, CFSTR(kIOMediaSizeKey), kCFAllocatorDefault, kNilOptions); - if (mediaSize) { - ffCfNumGetInt64(mediaSize, (int64_t*) &device->size); - } else { - device->size = 0; - } - FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, kNilOptions); if (deviceCharacteristics) { ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyProductSerialNumberKey), &device->serial); diff --git a/src/modules/physicaldisk/option.h b/src/modules/physicaldisk/option.h index 2bd032da8..e0ff899b2 100644 --- a/src/modules/physicaldisk/option.h +++ b/src/modules/physicaldisk/option.h @@ -16,6 +16,8 @@ typedef enum __attribute__((__packed__)) FFPhysicalDiskType { FF_PHYSICALDISK_TYPE_READWRITE = 1 << 5, FF_PHYSICALDISK_TYPE_READONLY = 1 << 6, + FF_PHYSICALDISK_TYPE_UNKNOWN = 1 << 7, + FF_PHYSICALDISK_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFPhysicalDiskType; static_assert(sizeof(FFPhysicalDiskType) == sizeof(uint8_t), "");