Skip to content

PhysicalDisk: adds SMART failing status for ATA disks - #2733

Merged
CarterLi merged 3 commits into
fastfetch-cli:devfrom
giovannilentini:physicaldisk-health-ata
Nov 19, 2026
Merged

CarterLi merged 3 commits into
fastfetch-cli:devfrom
giovannilentini:physicaldisk-health-ata

Conversation

@giovannilentini

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2728 and #2731: with "health": true, ATA/SATA disks (SSDs and HDDs) now report the drive's own SMART verdict on Linux, Windows and macOS, as discussed in #2726.

SATA has no standard wear percentage, so there is no Health xx% for these disks. The drive's overall SMART status is reported as a new critical warning, failing:

SMART status criticalWarning (JSON) {critical-warning} default line
OK [] empty unchanged
failing ["failing"] failing - Warning: failing
unknown / not supported null empty unchanged

failing is the same status smartctl -H shows as FAILED!: the drive sets it itself when a pre-fail attribute crosses its vendor threshold. It doesn't depend on the vendor and works for SSDs and HDDs alike. NVMe behaviour is unchanged.

Related issue

Closes #2726

Changes

  • PhysicalDisk (Linux): adds SMART failing status for ATA disks
    • adds FF_PHYSICALDISK_WARNING_FAILING (bit 6; bits 0-5 stay the NVMe Critical Warning bits) and the failing warning name
    • udisks2 org.freedesktop.UDisks2.Drive.Ata: one GetAll per non-NVMe disk, using SmartEnabled, SmartUpdated and SmartFailing (all readable without root)
    • stays unknown when SMART is off or udisks hasn't polled the drive yet (SmartUpdated == 0), same rule as NVMe
    • the Block → Drive lookup is shared by the NVMe and ATA paths; virtual disks (zram etc.) are skipped before any D-Bus call
  • PhysicalDisk (Windows): adds SMART failing status for ATA disks
    • IOCTL_STORAGE_PREDICT_FAILURE on the existing FILE_READ_ATTRIBUTES handle, only for BusTypeAta / BusTypeSata (HDDs included)
    • no admin needed (tested, see below)
    • on failure the field stays unknown, with only an FF_DEBUG line
  • PhysicalDisk (macOS): adds SMART failing status for ATA disks
    • IOATASMARTInterface::SMARTReturnStatus() via kIOATASMARTUserClientTypeID, structured like the existing NVMe SMART code
    • only for disks whose physical entry has SMART Capable = true (kIOPropertySMARTCapableKey)
  • CHANGELOG: one more sub-bullet under the existing health entry

Screenshots

Windows 11 Pro (build 26300) in a QEMU VM, with the system disk on an emulated SATA (AHCI) controller, run as a normal user:

Physical Disk (QEMU HARDDISK): 64.00 GiB [Fixed]
"name": "QEMU HARDDISK",
"interconnect": "SATA",
"percentUsed": null,
"availableSpare": null,
"criticalWarning": []

The raw IOCTL returns PredictFailure = 0 both as a normal user and as admin. WMI MSStorageDriver_FailurePredictStatus (admin) agrees: PredictFailure False.

Linux (Fedora 45 VM, udisks2 2.11.2, emulated SATA disk): criticalWarning: [], and the default line is unchanged. With SmartFailing temporarily forced to true (not in this PR), the line ends with - Warning: failing, {critical-warning} is failing, and JSON is ["failing"]. Virtio disks, DVD drives and zram stay null.

Performance (-s physicaldisk with health: true, median of 31 runs): no measurable change on NVMe-only machines (Linux 1.215 → 1.223 ms, Windows 16.2 → 16.5 ms, both within noise). An ATA disk adds one D-Bus call on Linux, one IOCTL on Windows, and one SMART status call on macOS.

Checklist

  • I have tested my changes locally.
    • Linux: emulated SATA disk in a Fedora VM (healthy, before udisks' first poll, and forced failing); real NVMe machine unchanged; no build warnings
    • Windows: emulated SATA disk in a Windows 11 VM (normal user + admin); real Windows 11 PC (2 NVMe, MSYS2 CLANG64) builds with 0 warnings, ctest 22/22, NVMe output unchanged
    • macOS: real Intel/T2 Mac (NVMe only, macOS 15.7.9) builds with 0 warnings, ctest 21/21, NVMe output unchanged (the SATA path isn't triggered there because nothing has SMART Capable)

Not tested: real SATA hardware on any platform, a drive that actually reports failing, and the macOS SATA path at runtime (I don't have a SATA Mac).

@CarterLi

Copy link
Copy Markdown
Member

This is out of my knowledge, and I don't have SATA drives to test. I asked AI to review your change. Please address the concerns.


PR #2733 review — PhysicalDisk: SMART failing status for ATA disks

Thanks for the follow-up. I read through all three platform paths and checked the
external facts (udisks2 property contract, the Windows IOCTL definition, the
warning-bit layout). The overall shape is right and it is close to mergeable; the
items below are ordered by how much they would change my confidence in the change.


What I verified, so you do not have to re-check it

  • org.freedesktop.UDisks2.Drive.Ata really does expose SmartSupported b,
    SmartEnabled b, SmartUpdated t, SmartFailing b, all readable and all
    available without root. The property names in physicaldisk_linux.c are correct,
    and SmartFailing is documented as "read from the disk itself and does not
    include any interpretation", i.e. the same verdict smartctl -H prints.
  • IOCTL_STORAGE_PREDICT_FAILURE is CTL_CODE(IOCTL_STORAGE_BASE, 0x0440, METHOD_BUFFERED, FILE_ANY_ACCESS), so the existing FILE_READ_ATTRIBUTES
    handle is enough and "no admin needed" is correct. STORAGE_PREDICT_FAILURE is
    present in the MinGW headers as well, so the Windows build does not depend on a
    new SDK.
  • warningNames[] has exactly 7 entries in bit order, so 1 << 6 lands on
    "failing", and the NVMe path's & 0x3F mask cannot collide with the new bit.
  • Moving wrapIoDestroyPlugInInterface() out of #ifdef MAC_OS_X_VERSION_10_15
    is required, otherwise the ATA path is an unused static function on older SDKs.
    Good catch.

Blocking

1. The performance numbers do not measure the new code

Both machines used for the timing are NVMe-only, and every added call is behind a
non-NVMe branch (BusTypeAta || BusTypeSata on Windows, the else branch of the
/dev/nvme test on Linux). So on those two machines the new code never executes
and the deltas you report are noise by construction, not evidence.

To make the claim you need at least one ATA disk attached and a number of the form
"one extra D-Bus round trip / one extra IOCTL per ATA disk". On Linux that also
matters for machines with many disks, because the Block -> Drive lookup is now
performed for every non-virtual disk, not just NVMe ones.

2. The Windows corroboration is not independent

IOCTL_STORAGE_PREDICT_FAILURE returning PredictFailure = 0 and
MSStorageDriver_FailurePredictStatus saying False are the same observation:
the storage WMI provider reads the same PredictFailure data path. Agreeing with
itself does not prove the value is real.

Either drop that sentence, or corroborate with an independent source on the same
drive (for example smartctl -H on the same hardware from a Linux live
environment). As it stands the Windows side has no evidence that this path ever
returns TRUE on real hardware.

For what it is worth, on my Windows 11 machine (one NVMe disk and one USB
enclosure, no SATA disk) the IOCTL returns ERROR_INVALID_FUNCTION (1) for both
disks, so I could not reproduce the success case either — that is exactly the gap
that needs closing before this is trusted.

3. SmartEnabled is a redundant gate and can hide a real failure

physicaldisk_linux.c:171:

if (!smartEnabled || smartUpdated == 0) { ... }

The udisks documentation states the rule in terms of one condition only:
SmartUpdated is "the point in time that the SMART status was updated or 0 if
never updated. The value of the other properties related to SMART are not
meaningful if this property is 0." So smartUpdated == 0 is the necessary and
sufficient guard, and it matches the NVMe path.

SmartEnabled comes from the IDENTIFY DEVICE SMART-enabled bit as parsed by
libatasmart, which is frequently unreliable behind SATA-to-USB bridges. As
written, a drive that udisks did read SMART from, but whose enabled bit reads
back as false, is downgraded from failing to unknown. I would drop the
smartEnabled term; if you keep it, please add a comment explaining why the
documented SmartUpdated rule is not enough here.

Smaller things

  • physicaldisk_windows.c:343 is outside the !(VIRTUAL) guard. Releasing
    HDDs from that if is correct, but the new block is not filtered for virtual
    disks, unlike the macOS and Linux paths. BusType makes it harmless today; add
    && !(device->type & FF_PHYSICALDISK_TYPE_VIRTUAL) for consistency.
  • Two distinct reasons collapsed into one debug line
    (physicaldisk_linux.c:172). "SMART is disabled on the drive" and "udisks has
    not polled it yet" are diagnosed completely differently, and the NVMe code keeps
    them as two separate messages. Please split it the same way.
  • Duplicated a{sv} walk. The dictionary traversal in detectAtaHealth()
    (:143-168) is line-for-line the loop in parseSmartAttributes()
    (:73-104), except that one uses break and the other uses return. Either
    factor out a small property-iterator helper or make the two look identical.
  • retSize check in physicaldisk_windows.c:354. retSize >= sizeof(spf.PredictFailure) is always true on success, so its only effect is to
    let a short-but-successful reply fall into the failure branch and print a stale
    GetLastError(). Use retSize >= sizeof(STORAGE_PREDICT_FAILURE) and treat a
    short reply as "unknown" rather than as an error.
  • = failing ? FAILING : NONE overwrites instead of OR-ing, on all three
    platforms. Today each platform has a single writer so nothing breaks, but the
    Windows NVMe branch lives in the same function and the macOS NVMe branch in the
    same loop, so the first additional verdict (SCSI/SAS) will silently clear the
    other. if (unset) NONE; else |= FAILING would be future-proof.

Scope and documentation

  • SAS and RAID disks stay unknown. Linux has no Drive.Ata for them and on
    Windows they report BusTypeSas / BusTypeRAID. The title says "ATA disks",
    which is accurate, but the CHANGELOG sub-bullet reads as if every SATA/HDD is
    covered. Half a sentence ("ATA only; SAS and RAID disks keep reporting
    unknown") would save a bug report later.
  • USB disks behave differently per platform, which is worth documenting.
    A drive inside a USB enclosure is a SATA/NVMe drive, but the platform decides
    from the transport: Windows sees BusTypeUsb and skips it, macOS needs
    kIOPropertySMARTCapableKey which USB bridges do not publish, while udisks
    builds Drive.Ata from the ID_ATA udev property that ata_id sets through
    ATA pass-through, so the same disk can report failing on Linux and unknown
    on Windows. That is acceptable, but it should be stated.
  • {critical-warning} description now covers more than NVMe. The format arg
    is still documented as "Critical warnings (none if healthy)" while it now also
    carries the ATA SMART verdict. If you change the description, remember that
    physicaldiskFormat in doc/json_schema.json is generated by
    fastfetch -h format-json and has to be regenerated in the same commit.
    Modules/PhysicalDisk.md in the wiki has no health section at all yet; that
    is true for PhysicalDisk (Linux): adds drive health detection via udisks2 #2728 and PhysicalDisk (macOS / Windows): adds drive health detection #2731 as well and would be cheaper to write once, for all
    three.

One question

On Linux this reads cached udisks properties, so it never talks to the drive.
On Windows and macOS the new code issues a live ATA command (SMART RETURN STATUS) on every run. Could that wake a sleeping HDD or keep it from spinning
down? udisks has an explicit nowakeup option for its SMART methods, which
suggests the command does spin the platters up. If that is the case, a short note
in the health option description (or a way to opt out) would be worth having,
because fastfetch runs in shell prompts.

@giovannilentini

giovannilentini commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

You're right, sorry. I was too vague in the PR description about how I tested this. I don't have any SATA hardware, so the SATA path was only tested in QEMU, on an emulated AHCI disk. On macOS it was only compiled; I couldn't run it on a SATA disk. So it has never run on a real SATA drive, and none of the drives I tested ever reported "failing". The performance numbers in the description came from my NVMe-only machines, so they didn't measure the new code either. I'll fix the description: the WMI check isn't independent, so I'll drop it, and I'll use the QEMU numbers instead.

About waking up sleeping HDDs: I think yes, on Windows and macOS the check sends a real command to the disk. On Windows I could check the power state first and skip sleeping disks. On macOS, after some research I found that it doesn't have ATA pass-through: the only interface is IOATASMARTInterface, which supports only IDENTIFY and SMART commands, so CHECK POWER MODE can't be sent and there's no reliable way to know if the disk is asleep. smartctl has the same limitation (-n standby isn't supported on macOS). Do you prefer the power-state check on Windows plus a note in the health description for macOS, or just a note for both?

@CarterLi
CarterLi merged commit d3c9178 into fastfetch-cli:dev Nov 19, 2026
17 of 25 checks passed
@giovannilentini
giovannilentini deleted the physicaldisk-health-ata branch November 19, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] PhysicalDisk: opt-in drive health (NVMe wear / available spare / SMART critical warning)

2 participants