Skip to content

Commit 9979515

Browse files
committed
PhysicalDisk (macOS): adds type unknown detection
1 parent 6cf403d commit 9979515

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/detection/physicaldisk/physicaldisk_apple.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/modules/physicaldisk/option.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ typedef enum __attribute__((__packed__)) FFPhysicalDiskType {
1616
FF_PHYSICALDISK_TYPE_READWRITE = 1 << 5,
1717
FF_PHYSICALDISK_TYPE_READONLY = 1 << 6,
1818

19+
FF_PHYSICALDISK_TYPE_UNKNOWN = 1 << 7,
20+
1921
FF_PHYSICALDISK_TYPE_FORCE_UNSIGNED = UINT8_MAX,
2022
} FFPhysicalDiskType;
2123
static_assert(sizeof(FFPhysicalDiskType) == sizeof(uint8_t), "");

0 commit comments

Comments
 (0)