From 3bd01e5abce237c3915eb1e128e9ba4645ad2bf8 Mon Sep 17 00:00:00 2001 From: giovannilentini Date: Wed, 18 Nov 2026 12:38:54 +0100 Subject: [PATCH] PhysicalDisk (Windows): adds SMART failing status for ATA disks Ref: #2726 --- CHANGELOG.md | 2 +- .../physicaldisk/physicaldisk_windows.c | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faeb3c02b..7f71e08bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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, ATA disks report the SMART `failing` status as a critical warning. + * On Linux and Windows, 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) diff --git a/src/detection/physicaldisk/physicaldisk_windows.c b/src/detection/physicaldisk/physicaldisk_windows.c index 64b048232..440ea382f 100644 --- a/src/detection/physicaldisk/physicaldisk_windows.c +++ b/src/detection/physicaldisk/physicaldisk_windows.c @@ -340,6 +340,32 @@ static const char* detectPhysicalDisk(const char* physicalType, const wchar_t* s } } + if (options->health && sdd && !(device->type & FF_PHYSICALDISK_TYPE_VIRTUAL) && (sdd->BusType == BusTypeAta || sdd->BusType == BusTypeSata)) { + STORAGE_PREDICT_FAILURE spf = {}; + if (DeviceIoControl( + hDevice, + IOCTL_STORAGE_PREDICT_FAILURE, + nullptr, + 0, + &spf, + sizeof(spf), + &retSize, + nullptr)) { + if (retSize >= sizeof(spf)) { + if (device->criticalWarning == FF_PHYSICALDISK_WARNING_UNSET) { + device->criticalWarning = FF_PHYSICALDISK_WARNING_NONE; + } + if (spf.PredictFailure) { + device->criticalWarning |= FF_PHYSICALDISK_WARNING_FAILING; + } + } else { + FF_DEBUG("ATA failure prediction reply too short: %u bytes", (unsigned) retSize); + } + } else { + FF_DEBUG("Failed to query ATA failure prediction: %s", ffDebugWin32Error(GetLastError())); + } + } + return nullptr; }