From 9fd1ac07667914eb8f82c24ac63c32ab858e8809 Mon Sep 17 00:00:00 2001 From: Johnny Silverman Date: Sat, 8 Nov 2025 16:12:51 +0200 Subject: [PATCH] Parse through "ata_device_statistics" for devices which report incorrect reads/writes or don't report them at all in legacy attributes. --- src/mainwindow.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d2dac04..2deda9f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -672,6 +672,42 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal } } } + + // Some devices don't report or report incorrect reads/writes in legacy + // attributes, so we look for that data in ata_device_statistics. + // We do this after parsing through the legacy attributes + // to override possibly incorrect calculations. + QJsonObject ata_device_statistics = localObj["ata_device_statistics"].toObject(); + if (!ata_device_statistics.empty()) + { + QJsonArray pages = ata_device_statistics["pages"].toArray(); + for (const QJsonValue &pageval : std::as_const(pages)) + { + QJsonObject page = pageval.toObject(); + if (page["name"] == "General Statistics") + { + QJsonArray general_statistics = page["table"].toArray(); + for (const QJsonValue &stat : std::as_const(general_statistics)) + { + QJsonObject statObj = stat.toObject(); + QString key = statObj["name"].toString(); + QJsonValue value = statObj["value"]; + + if (key == "Logical Sectors Read") { + double logicalSectorsRead = value.toDouble(); + double megabytes = logicalSectorsRead * logicalBlockSize / 1e6; + totalMbReadsI64 = static_cast(megabytes); + } else if (key == "Logical Sectors Written") { + double logicalSectorsWritten = value.toDouble(); + double megabytes = logicalSectorsWritten * logicalBlockSize / 1e6; + totalMbWritesI64 = static_cast(megabytes); + } + } + break; // no need looking into other pages + } + } + } + if (percentage.isEmpty() && rotationRate == "---- (SSD)") { // Workaround for some drives which have this and another attribute for (const QJsonValue &attr : std::as_const(attributes)) { QJsonObject attrObj = attr.toObject();