From a665f8638edbc5aa1e6346a2ff814a4b97490c5a Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 2 Jun 2024 09:31:55 +0200 Subject: [PATCH 1/3] find system drive --- include/reHDD.h | 3 ++- src/reHDD.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ src/smart.cpp | 4 ++-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index 7bd1e90..d8a98c1 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -31,7 +31,7 @@ #endif // Logic -//#define DRYRUN //don´t touch the drives +#define DRYRUN //don´t touch the drives #define FROZEN_ALERT // show alert if drive is frozen #define ZERO_CHECK // check drive after shred if all bytes are zero, show alert if this fails @@ -101,6 +101,7 @@ private: static void handleESC(); static void handleAbort(); static Drive *getSelectedDrive(); + static bool getSystemDrive(string &systemDrive); }; #endif // REHDD_H_ diff --git a/src/reHDD.cpp b/src/reHDD.cpp index bc4f5e3..4946859 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -346,6 +346,12 @@ void reHDD::filterIgnoredDrives(list *plistDrives) { list> vtlIgnoredDevices; // store drives from ignore file ifstream input("ignoreDrives.conf"); // read ignore file + string systemDrivePath; + + if (getSystemDrive(systemDrivePath)) + { + Logger::logThis()->info("Found system drive: " + systemDrivePath); + } for (string sLine; getline(input, sLine);) { @@ -605,3 +611,52 @@ void reHDD::handleAbort() } } } + +bool reHDD::getSystemDrive(string &systemDrive) +{ + Logger::logThis()->info("--> search system drive <--"); + char *cLine = NULL; + size_t len = 0; + bool systemDriveFound = false; + + FILE *outputfileHwinfo = popen("lsblk -e 11 -o NAME,MOUNTPOINT", "r"); + + if (outputfileHwinfo == NULL) + { + Logger::logThis()->error("Unable to scan attached drives for system drive"); + exit(EXIT_FAILURE); + } + + while ((getline(&cLine, &len, outputfileHwinfo)) != -1) + { + string currentLine = cLine; + + if (currentLine.find("NAME") != std::string::npos) + { + continue; + } + + // Logger::logThis()->info(currentLine); + + if ((cLine[0U] != '|') && (cLine[0U] != '`')) + { + systemDrive = currentLine; + // Logger::logThis()->info("Drive found: " + systemDrive); + } + + if (currentLine.ends_with(" /boot/efi\n"s)) + { + systemDriveFound = true; + break; + } + + if (currentLine.ends_with(" /\n"s)) + { + systemDriveFound = true; + break; + } + } + pclose(outputfileHwinfo); + + return systemDriveFound; +} \ No newline at end of file diff --git a/src/smart.cpp b/src/smart.cpp index 339d94f..68df376 100644 --- a/src/smart.cpp +++ b/src/smart.cpp @@ -36,7 +36,7 @@ void SMART::readSMARTData(Drive *drive) sCMD.append(drive->getPath()); const char *cpComand = sCMD.c_str(); - // Logger::logThis()->info(cpComand); + //Logger::logThis()->info(cpComand); FILE *outputfileSmart = popen(cpComand, "r"); size_t len = 0U; // length of found line @@ -63,7 +63,7 @@ void SMART::readSMARTData(Drive *drive) if (status == 0U) { // Found S.M.A.R.T. data with this command - // Logger::logThis()->info("Found S.M.A.R.T. data with this command"); + //Logger::logThis()->info("Found S.M.A.R.T. data with this command"); break; } } From 77b322d47dfada9f3a089892d2ceb76363849b1b Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 2 Jun 2024 09:51:22 +0200 Subject: [PATCH 2/3] ignore system drive --- src/reHDD.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 4946859..a273166 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -344,15 +344,29 @@ void reHDD::searchDrives(list *plistDrives) */ void reHDD::filterIgnoredDrives(list *plistDrives) { - list> vtlIgnoredDevices; // store drives from ignore file - ifstream input("ignoreDrives.conf"); // read ignore file string systemDrivePath; - if (getSystemDrive(systemDrivePath)) { Logger::logThis()->info("Found system drive: " + systemDrivePath); + + list::iterator it; + for (it = plistDrives->begin(); it != plistDrives->end(); ++it) + { + if (it->getPath().find(systemDrivePath) != std::string::npos) // compare found system drive and current drive + { + // system drive found --> ignore this drive +#ifdef LOG_LEVEL_HIGH + Logger::logThis()->info("system drive found --> ignore this drive: " + it->getPath()); +#endif + it = plistDrives->erase(it); + it--; + } + } } + list> vtlIgnoredDevices; // store drives from ignore file + ifstream input("ignoreDrives.conf"); // read ignore file + for (string sLine; getline(input, sLine);) { // Logger::logThis()->info("read uuid: " + sLine); @@ -614,7 +628,6 @@ void reHDD::handleAbort() bool reHDD::getSystemDrive(string &systemDrive) { - Logger::logThis()->info("--> search system drive <--"); char *cLine = NULL; size_t len = 0; bool systemDriveFound = false; @@ -641,6 +654,8 @@ bool reHDD::getSystemDrive(string &systemDrive) if ((cLine[0U] != '|') && (cLine[0U] != '`')) { systemDrive = currentLine; + systemDrive.erase(std::remove(systemDrive.begin(), systemDrive.end(), '\n'), systemDrive.end()); // remove newline + systemDrive.erase(std::remove(systemDrive.begin(), systemDrive.end(), ' '), systemDrive.end()); // remove spaces // Logger::logThis()->info("Drive found: " + systemDrive); } From b1b9870150f6a52a2f7e62eb3e9795a4062ed14b Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 2 Jun 2024 09:57:12 +0200 Subject: [PATCH 3/3] remove dryrun --- include/reHDD.h | 2 +- src/reHDD.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index d8a98c1..9ffa69f 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -31,7 +31,7 @@ #endif // Logic -#define DRYRUN //don´t touch the drives +//#define DRYRUN // don't touch the drives #define FROZEN_ALERT // show alert if drive is frozen #define ZERO_CHECK // check drive after shred if all bytes are zero, show alert if this fails diff --git a/src/reHDD.cpp b/src/reHDD.cpp index a273166..9338242 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -347,7 +347,7 @@ void reHDD::filterIgnoredDrives(list *plistDrives) string systemDrivePath; if (getSystemDrive(systemDrivePath)) { - Logger::logThis()->info("Found system drive: " + systemDrivePath); + // Logger::logThis()->info("Found system drive: " + systemDrivePath); list::iterator it; for (it = plistDrives->begin(); it != plistDrives->end(); ++it)