From 068413c15d44be83bec4b4ad1234d3c907eb3e10 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 26 Jan 2022 13:52:21 +0100 Subject: [PATCH 1/4] log attached drives --- src/reHDD.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 32c5b7d..895745f 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -298,7 +298,7 @@ void reHDD::searchDrives(list * plistDrives) if (outputfileHwinfo == NULL) { - Logger::logThis()->error("Unable to scann attached drives"); + Logger::logThis()->error("Unable to scan attached drives"); exit(EXIT_FAILURE); } @@ -310,6 +310,7 @@ void reHDD::searchDrives(list * plistDrives) tmpDrive->state = Drive::NONE; tmpDrive->bIsOffline = false; plistDrives->push_back(*tmpDrive); + Logger::logThis()->info("search drives: " + tmpDrive->getPath()); } } fclose(outputfileHwinfo); From c942f36e492d41969b96a2a3726760fcfb27e0a8 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 26 Jan 2022 15:15:34 +0100 Subject: [PATCH 2/4] using lsblk for listing attached drives --- src/reHDD.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 895745f..5cc7443 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -294,7 +294,7 @@ void reHDD::searchDrives(list * plistDrives) char * cLine = NULL; size_t len = 0; - FILE* outputfileHwinfo = popen("ls -1 /dev/sd*", "r"); + FILE* outputfileHwinfo = popen("lsblk -I 8 -d -o NAME", "r"); if (outputfileHwinfo == NULL) { @@ -304,13 +304,13 @@ void reHDD::searchDrives(list * plistDrives) while ((getline(&cLine, &len, outputfileHwinfo)) != -1) { - if (string(cLine).length() == 9) + if (string(cLine).length() == 4) { - Drive* tmpDrive = new Drive(string(cLine).substr(0, 8)); + Drive* tmpDrive = new Drive("/dev/" + string(cLine).substr(0, 3)); tmpDrive->state = Drive::NONE; tmpDrive->bIsOffline = false; plistDrives->push_back(*tmpDrive); - Logger::logThis()->info("search drives: " + tmpDrive->getPath()); + Logger::logThis()->info("drive found: " + tmpDrive->getPath()); } } fclose(outputfileHwinfo); From f2db85aa33be4be41cbaa0b56592ad228b3f2df9 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 26 Jan 2022 15:44:32 +0100 Subject: [PATCH 3/4] pclose instead fclose --- .gitignore | 3 +++ include/reHDD.h | 4 ++-- src/delete.cpp | 2 +- src/reHDD.cpp | 7 +++---- src/smart.cpp | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index ee41a9d..9862cb4 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ reHDD reHDD.log + + +ignoreDrives.conf diff --git a/include/reHDD.h b/include/reHDD.h index 48c5733..755ce7a 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,7 +8,7 @@ #ifndef REHDD_H_ #define REHDD_H_ -#define REHDD_VERSION "bV0.2.0" +#define REHDD_VERSION "bV0.2.1" // Drive handling Settings #define WORSE_HOURS 19200 //mark drive if at this limit or beyond @@ -18,7 +18,7 @@ // Logger Settings #define LOG_PATH "./reHDD.log" -#define DESCRIPTION "reHDD - Copyright Hendrik Schutter 2020" +#define DESCRIPTION "reHDD - Copyright Hendrik Schutter 2022" #define DEVICE_ID "generic" #define SOFTWARE_VERSION "alpha" #define HARDWARE_VERSION "generic" diff --git a/src/delete.cpp b/src/delete.cpp index 68b2984..0d60b25 100644 --- a/src/delete.cpp +++ b/src/delete.cpp @@ -38,5 +38,5 @@ void Delete::deleteDrive(Drive* drive) { //wipefs running } - fclose(deleteCmdOutput); + pclose(deleteCmdOutput); } diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 5cc7443..9695079 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -289,7 +289,6 @@ void reHDD::filterNewDrives(list * plistOldDrives, list * plistNew */ void reHDD::searchDrives(list * plistDrives) { - // cout << "search drives ..." << endl; Logger::logThis()->info("--> search drives <--"); char * cLine = NULL; size_t len = 0; @@ -310,10 +309,10 @@ void reHDD::searchDrives(list * plistDrives) tmpDrive->state = Drive::NONE; tmpDrive->bIsOffline = false; plistDrives->push_back(*tmpDrive); - Logger::logThis()->info("drive found: " + tmpDrive->getPath()); + //Logger::logThis()->info("drive found: " + tmpDrive->getPath()); } } - fclose(outputfileHwinfo); + pclose(outputfileHwinfo); } /** @@ -378,7 +377,7 @@ void reHDD::filterIgnoredDrives(list * plistDrives) //cout << "blkid uuid:" << sUUID << endl; } } - fclose(outputfileBlkid); + pclose(outputfileBlkid); //cout << "blkid uuid:" << sUUID << endl; if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive diff --git a/src/smart.cpp b/src/smart.cpp index 815ef00..1a787af 100644 --- a/src/smart.cpp +++ b/src/smart.cpp @@ -51,7 +51,7 @@ void SMART::readSMARTData(Drive* drive) SMART::parsePowerOnHours(sLine); SMART::parsePowerCycle(sLine); } - fclose(outputfileSmart); + pclose(outputfileSmart); drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle); //wirte data in drive } From 84e42a430b5cfa14dea0856aa6667ab71e68deb8 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 26 Jan 2022 16:31:46 +0100 Subject: [PATCH 4/4] dis[play capacity as double --- src/drive.cpp | 22 +++++++++++----------- src/reHDD.cpp | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/drive.cpp b/src/drive.cpp index c7b4e45..87dd50a 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -48,17 +48,17 @@ uint32_t Drive::getPowerCycles(void) string Drive::sCapacityToText() { - if(getCapacity() <= (999*1000000000UL)) - { - // Less or even 999 GB --> GB - return to_string(getCapacity() / 1000000000UL) + " GB"; - } - else - { - // More 999 GB --> TB - return to_string(getCapacity() / 1000000000000UL) + " TB"; - } - return "ERROR"; + char acBuffer[16]; + double dSize = (double) getCapacity(); + uint16_t u16UnitIndex = 0; + const char* units[] = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; + while (dSize >= 1000) { //using the marketing capacity + dSize /= 1000; + u16UnitIndex++; + } + + sprintf(acBuffer, "%.*f %s", u16UnitIndex-3, dSize, units[u16UnitIndex]); + return acBuffer; } string Drive::sErrorCountToText() diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 9695079..38fb6ee 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -343,7 +343,7 @@ void reHDD::filterIgnoredDrives(list * plistDrives) sLine.erase(0, pos + sDelimiter.length()); sIgnoredDriveUUID = sLine; } //end while - vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ingnore file to vector + vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ignore file to vector } } //loop through found entries in ingnore file @@ -383,7 +383,7 @@ void reHDD::filterIgnoredDrives(list * plistDrives) if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive { cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl; - Logger::logThis()->error("[ERROR] different uuid found than in ignore file: " + it->getPath()); + Logger::logThis()->error("[ERROR] different uuid found than in ignore file: " + it->getPath() + " uuid from drive: " + sUUID); exit(EXIT_FAILURE); // exit to prevent accidentally shred a system drive } else