Lay the groundwork for NVMe support

This commit is contained in:
spiros
2024-05-30 04:01:07 +03:00
parent b1348d61b7
commit 90c19c36ee
2 changed files with 75 additions and 37 deletions

79
.gitignore vendored
View File

@@ -1,32 +1,57 @@
# Prerequisites # C++ objects and libs
*.d
# Compiled Object files
*.slo *.slo
*.lo *.lo
*.o *.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a *.a
*.lib *.la
*.lai
*.so
*.so.*
*.dll
*.dylib
# Executables # Qt-es
*.exe object_script.*.Release
*.out object_script.*.Debug
*.app *_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.qm
*.prl
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
# QtCreator 4.8< compilation database
compile_commands.json
# QtCreator local machine specific files for imported projects
*creator.user*
*_qmlcache.qrc
# The entire build directory
build/

View File

@@ -69,6 +69,7 @@ void MainWindow::scanDevices()
QJsonObject localObj = localDoc.object(); QJsonObject localObj = localDoc.object();
QJsonArray attributes = localObj["ata_smart_attributes"].toObject()["table"].toArray(); QJsonArray attributes = localObj["ata_smart_attributes"].toObject()["table"].toArray();
QJsonArray nvmeLog = localObj["nvme_smart_health_information_log"].toArray();
QString temperature = "N/A"; QString temperature = "N/A";
bool healthPassed = localObj["smart_status"].toObject()["passed"].toBool(); bool healthPassed = localObj["smart_status"].toObject()["passed"].toBool();
bool caution = false; bool caution = false;
@@ -86,11 +87,13 @@ void MainWindow::scanDevices()
temperature = QString::number(temperatureInt) + " °C"; temperature = QString::number(temperatureInt) + " °C";
} }
for (const QJsonValue &attr : attributes) { if (!isNvme) {
QJsonObject attrObj = attr.toObject(); for (const QJsonValue &attr : attributes) {
if (!isNvme && (attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198) && (attrObj["raw"].toObject()["value"].toInt() != 0)) { QJsonObject attrObj = attr.toObject();
caution = true; if (!isNvme && (attrObj["id"] == 5 || attrObj["id"] == 197 || attrObj["id"] == 198) && (attrObj["raw"].toObject()["value"].toInt() != 0)) {
break; caution = true;
break;
}
} }
} }
@@ -121,9 +124,8 @@ void MainWindow::scanDevices()
globalObj = localObj; globalObj = localObj;
globalHealth = health; globalHealth = health;
button->setChecked(true); button->setChecked(true);
firstTime = false;
} }
firstTime = false;
} }
horizontalLayout->addStretch(); horizontalLayout->addStretch();
populateWindow(globalObj, globalHealth); populateWindow(globalObj, globalHealth);
@@ -132,6 +134,7 @@ void MainWindow::scanDevices()
void MainWindow::populateWindow(const QJsonObject &localObj, const QString &health) void MainWindow::populateWindow(const QJsonObject &localObj, const QString &health)
{ {
QJsonArray attributes = localObj["ata_smart_attributes"].toObject()["table"].toArray(); QJsonArray attributes = localObj["ata_smart_attributes"].toObject()["table"].toArray();
QJsonArray nvmeLog = localObj["nvme_smart_health_information_log"].toArray();
QString modelName = localObj["model_name"].toString(); QString modelName = localObj["model_name"].toString();
QString firmwareVersion = localObj["firmware_version"].toString(); QString firmwareVersion = localObj["firmware_version"].toString();
float userCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9; float userCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9;
@@ -195,9 +198,19 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal
for (const QJsonValue &attr : attributes) { //Need different logic for NVMe for (const QJsonValue &attr : attributes) { //Need different logic for NVMe
QJsonObject attrObj = attr.toObject(); QJsonObject attrObj = attr.toObject();
if (attrObj["id"] == 241 && !isNvme) { if (attrObj["id"] == 241 && !isNvme) {
totalWrites = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; if (attrObj["name"] == "Host_Writes_32MiB") {
totalWrites = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB";
} else if (attrObj["name"] == "Host_Writes_32MiB") {
double gibibytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9;
totalWrites = QString::number(static_cast<int>(gibibytes)) + " GB";
}
} else if (attrObj["id"] == 242 && !isNvme) { } else if (attrObj["id"] == 242 && !isNvme) {
totalReads = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB"; if (attrObj["name"] == "Total_Reads_GB") {
totalReads = QString::number(attrObj["raw"].toObject()["value"].toInt()) + " GB";
} else if (attrObj["name"] == "Host_Reads_32MiB") {
double gibibytes = (attrObj["raw"].toObject()["value"].toInt() * 32 * 1024.0 * 1024.0) / 1e9;
totalReads = QString::number(static_cast<int>(gibibytes)) + " GB";
}
} }
} }
@@ -323,7 +336,7 @@ QString MainWindow::getSmartctlOutput(const QStringList &arguments, bool root)
QProcess process; QProcess process;
QString command; QString command;
QStringList commandArgs; QStringList commandArgs;
if(root) { if (root) {
command = "pkexec"; command = "pkexec";
commandArgs = {"smartctl"}; commandArgs = {"smartctl"};
} else { } else {