Skip to content

PhysicalDisk (Linux): adds drive health detection via udisks2 - #2728

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

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

Conversation

@giovannilentini

@giovannilentini giovannilentini commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in drive health to the PhysicalDisk module, as discussed in #2726. This PR covers the shared part and Linux (NVMe via udisks2, no root needed). macOS, Windows and ATA can follow as separate PRs.

{ "type": "physicaldisk", "health": true }

Related issue (required for new logos for new distros)

Ref #2726

Changes

  • PhysicalDisk: adds health option and result fields
    • new health option (default false) and percent color thresholds (default like Battery: green ≥ 50, red < 20)
    • result fields percentUsed, availableSpare, criticalWarning; criticalWarning bits 0-5 match the NVMe Critical Warning field
    • default output honours percent.type (number and/or bar), like Battery and Disk
    • default output appends Health <100 - percent used>%, and the warnings only if there are any
    • format args {health}, {percent-used}, {available-spare}, {critical-warning}; JSON schema updated
  • DBus: supports calling methods with an empty a{sv} argument
    • SmartGetAttributes takes an a{sv} options argument, which dbus_message_append_args can't build. Loads dbus_message_iter_init_append / open_container / close_container and adds ffDBusGetMethodReplyEmptyDict()
  • PhysicalDisk (Linux): adds health detection via udisks2
    • only runs when health is enabled
    • checks NameHasOwner first, so udisksd is never auto-started by fastfetch
    • per NVMe disk: Block.Drive → NVMe.Controller.SmartUpdated (skipped if udisks has no SMART data yet) → SmartCriticalWarning → SmartGetAttributes (percent_used, avail_spare)
    • without D-Bus / udisks (or udisks < 2.10) the fields stay empty, no error is printed

Performance (-s physicaldisk, median of 31 runs, 2 NVMe disks):

time
health: false (default) 0.145 ms
health: true 1.288 ms

There's no cost unless health is enabled. The extra ~1 ms is the D-Bus connection plus 4 calls per NVMe disk.

Screenshots

Physical Disk (Lexar SSD NM620 256GB): 238.47 GiB [SSD, Fixed] - 34.9°C - Health 97%
Physical Disk (SHPP41-1000GM): 931.51 GiB [SSD, Fixed] - 39.9°C - Health 100%
Physical Disk (zram0): 8.00 GiB [Virtual, Fixed]
{
  "name": "Lexar SSD NM620 256GB",
  "interconnect": "NVMe",
  "kind": "SSD",
  "temperature": 34.85,
  "percentUsed": 3,
  "availableSpare": 100,
  "criticalWarning": []
}

The values match busctl --system call org.freedesktop.UDisks2 <drive> org.freedesktop.UDisks2.NVMe.Controller SmartGetAttributes 'a{sv}' 0 and GNOME Disks.

Checklist

  • I have tested my changes locally.
    • Fedora, udisks2 2.11.2, 2 NVMe disks; ctest 21/21, presets/all.jsonc, --format json, --gen-config (full)
    • builds with -DENABLE_DBUS=OFF
    • no system bus and no udisks on the bus both fall back cleanly

Should macOS / Windows / ATA go into this PR or into follow-ups?

FFPhysicalDiskWarning criticalWarning;
} FFPhysicalDiskResult;

static inline void ffPhysicalDiskInitHealth(FFPhysicalDiskResult* device) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use ffModuleInitXxx. This may change in the future, but for now please follow the common pattern.

Comment thread src/modules/physicaldisk/physicaldisk.c Outdated
if (dev->availableSpare != FF_PHYSICALDISK_PERCENT_UNSET) {
ffStrbufAppendF(&spareStr, "%u%%", (unsigned) dev->availableSpare);
}
FF_STRBUF_AUTO_DESTROY warningStr = ffStrbufCreate();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ffList with FFstrbuf, which is more friendly with lua script.

@giovannilentini

Copy link
Copy Markdown
Contributor Author

Done, fixed both.

@CarterLi
CarterLi merged commit 3c4793c into fastfetch-cli:dev Nov 17, 2026
24 of 26 checks passed
@giovannilentini
giovannilentini deleted the physicaldisk-health branch November 17, 2026 07:26
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.

2 participants