From 9565ef61abee7f799f459caf0b0f1b2384b54b8b Mon Sep 17 00:00:00 2001 From: Valerii Malov Date: Mon, 20 May 2019 22:22:01 +0300 Subject: [PATCH] Add support for smartmontools 7.0 user_capacity json output Summary: smartmontools 7.0 reports user capacity as an object that contains bytes and blocks value, instead of being an int that just contains bytes This should fix incorrect calculation of bad blocks threshold and incorrect display of "Overall" status Test Plan: run partitionmanager on a system that has smartmontools 7, open smart status overall status should be reported correctly Reviewers: stikonas Reviewed By: stikonas Differential Revision: https://phabricator.kde.org/D21311 --- src/core/smartparser.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/smartparser.cpp b/src/core/smartparser.cpp index 294691e..18d09bb 100644 --- a/src/core/smartparser.cpp +++ b/src/core/smartparser.cpp @@ -91,7 +91,15 @@ bool SmartParser::init() m_DiskInformation->setModel(smartJson[model_name].toString()); m_DiskInformation->setFirmware(smartJson[firmware].toString()); m_DiskInformation->setSerial(smartJson[serial_number].toString()); - m_DiskInformation->setSize(smartJson[user_capacity].toVariant().toULongLong()); + + if (smartJson[user_capacity].isObject()) { + // smartmontools 7.0+ + const auto user_capacity_object = smartJson[user_capacity].toObject(); + QString user_capacity_bytes = QStringLiteral("bytes"); + m_DiskInformation->setSize(user_capacity_object[user_capacity_bytes].toVariant().toULongLong()); + } else { + m_DiskInformation->setSize(smartJson[user_capacity].toVariant().toULongLong()); + } QJsonObject selfTest = smartJson[self_test].toObject(); QJsonObject selfTestStatus = selfTest[status].toObject();