PhysicalDisk (macOS): adds SMART failing status for ATA disks

Ref: #2726
This commit is contained in:
giovannilentini authored and Carter Li committed 2026-11-18 21:00:40 -06:00
1 parent 3bd01e5abc
commit d3c9178f11
2 files changed
+41 -3

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ Features:
* Added opt-in drive health detection for NVMe disks, via udisks2 on Linux (no root required), NVMe SMART on macOS and the NVMe health log on Windows. (#2726, PhysicalDisk, Linux / macOS / Windows)
* Enable it with `"health": true`. The default output appends `Health <100 - percentage used>%` and any critical warnings.
* New format args: `{health}`, `{percent-used}`, `{available-spare}` and `{critical-warning}`.
* On Linux and Windows, ATA disks report the SMART `failing` status as a critical warning.
* ATA disks report the SMART `failing` status as a critical warning.
Changes:
* Improved PCI GPU name resolution by checking udev's hardware database and the NVIDIA driver's procfs before falling back to pci.ids. (GPU, Linux)
@@ -8,18 +8,17 @@
#include <IOKit/storage/IOBlockStorageDriver.h>
#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
#include <IOKit/storage/IOStorageProtocolCharacteristics.h>
#include <IOKit/storage/ata/ATASMARTLib.h>
#ifdef MAC_OS_X_VERSION_10_15
#include <IOKit/storage/nvme/NVMeSMARTLibExternal.h>
#endif
#ifdef MAC_OS_X_VERSION_10_15
static inline void wrapIoDestroyPlugInInterface(IOCFPlugInInterface*** pluginInf) {
assert(pluginInf);
if (*pluginInf) {
IODestroyPlugInInterface(*pluginInf);
}
}
#endif
static const char* detectNvmeSmart(io_service_t entryPhysical, FFPhysicalDiskResult* device, FFPhysicalDiskOptions* options) {
#ifdef MAC_OS_X_VERSION_10_15
@@ -59,6 +58,38 @@ static const char* detectNvmeSmart(io_service_t entryPhysical, FFPhysicalDiskRes
#endif
}
static const char* detectAtaSmart(io_service_t entryPhysical, FFPhysicalDiskResult* device) {
[[gnu::cleanup(wrapIoDestroyPlugInInterface)]] IOCFPlugInInterface** pluginInf = nullptr;
int32_t score;
if (IOCreatePlugInInterfaceForService(entryPhysical, kIOATASMARTUserClientTypeID, kIOCFPlugInInterfaceID, &pluginInf, &score) != kIOReturnSuccess) {
FF_DEBUG("IOCreatePlugInInterfaceForService(kIOATASMARTUserClientTypeID) failed");
return "IOCreatePlugInInterfaceForService() failed";
}
IOATASMARTInterface** smartInf = nullptr;
if ((*pluginInf)->QueryInterface(pluginInf, CFUUIDGetUUIDBytes(kIOATASMARTInterfaceID), (LPVOID) &smartInf) != kIOReturnSuccess) {
FF_DEBUG("QueryInterface(kIOATASMARTInterfaceID) failed");
return "QueryInterface() failed";
}
Boolean exceeded = false;
const char* error = nullptr;
if ((*smartInf)->SMARTReturnStatus(smartInf, &exceeded) == kIOReturnSuccess) {
if (device->criticalWarning == FF_PHYSICALDISK_WARNING_UNSET) {
device->criticalWarning = FF_PHYSICALDISK_WARNING_NONE;
}
if (exceeded) {
device->criticalWarning |= FF_PHYSICALDISK_WARNING_FAILING;
}
} else {
FF_DEBUG("SMARTReturnStatus() failed");
error = "SMARTReturnStatus() failed";
}
(*pluginInf)->Release(smartInf);
return error;
}
const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) {
FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = 0;
if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching(kIOBlockStorageDriverClass), &iterator) != KERN_SUCCESS) {
@@ -200,6 +231,13 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
}
}
#endif
if (!(device->type & FF_PHYSICALDISK_TYPE_VIRTUAL) && options->health) {
FF_CFTYPE_AUTO_RELEASE CFBooleanRef ataSMARTCapable = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertySMARTCapableKey), nullptr, kNilOptions);
if (ataSMARTCapable && CFBooleanGetValue(ataSMARTCapable)) {
detectAtaSmart(entryPhysical, device);
}
}
}
return nullptr;