From a0c842d90d1528d1152c92a8c8a171f34c3ed4db Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 15 Jun 2025 22:16:34 +0200 Subject: [PATCH 1/3] add terminate action --- include/reHDD.h | 7 ++++--- include/tui.h | 1 + src/reHDD.cpp | 34 ++++++++++++++++++++++++++++++++++ src/tui.cpp | 7 +++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index 9f02846..602d057 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,7 +8,7 @@ #ifndef REHDD_H_ #define REHDD_H_ -#define REHDD_VERSION "V1.1.3" +#define REHDD_VERSION "V1.2.0" // Drive handling Settings #define WORSE_HOURS 19200 // mark drive if at this limit or beyond @@ -25,13 +25,13 @@ #define SOFTWARE_VERSION REHDD_VERSION #define HARDWARE_VERSION "generic" -// #define LOG_LEVEL_HIGH //log everything, like drive scan thread +#define LOG_LEVEL_HIGH // log everything, like drive scan thread #ifndef LOG_LEVEL_HIGH #define LOG_LEVEL_LOW // log only user actions and tasks #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 @@ -86,6 +86,7 @@ private: static void searchDrives(list *plistDrives); static void printDrives(list *plistDrives); static void startShredAllDrives(list *plistDrives); + static void stopShredAllDrives(list *plistDrives); static void updateShredMetrics(list *plistDrives); static void filterIgnoredDrives(list *plistDrives); static void filterInvalidDrives(list *plistDrives); diff --git a/include/tui.h b/include/tui.h index df7cd8d..4ae017a 100644 --- a/include/tui.h +++ b/include/tui.h @@ -31,6 +31,7 @@ public: Delete, Enter, ESC, + Terminate, Undefined }; struct MenuState diff --git a/src/reHDD.cpp b/src/reHDD.cpp index a98b2c8..7ab8f03 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -197,6 +197,12 @@ void reHDD::ThreadUserInput() handleESC(); ui->updateTUI(&listDrives, u8SelectedEntry); break; + case TUI::UserInput::Terminate: + cout << "Terminate" << endl; + stopShredAllDrives(&listDrives); + sleep(5); // sleep 5 sec + std::exit(1); // Terminates main, doesn't wait for threads + break; default: break; } @@ -464,6 +470,34 @@ void reHDD::startShredAllDrives(list *plistDrives) mxDrives.unlock(); } +/** + * \brief stop shred for all drives + * \param pointer of list * plistDrives + * \return void + */ +void reHDD::stopShredAllDrives(list *plistDrives) +{ + list::iterator it; + mxDrives.lock(); + for (it = plistDrives->begin(); it != plistDrives->end(); ++it) + { + + if (it->state == Drive::SHRED_ACTIVE || it->state == Drive::DELETE_ACTIVE) + { + it->state = Drive::NONE; + Logger::logThis()->info("Abort-Shred-Signal for: " + it->getModelName() + "-" + it->getSerial()); + // task for drive is running --> remove selection + } + +#ifdef LOG_LEVEL_HIGH + ostringstream address; + address << (void const *)&(*it); + Logger::logThis()->info("Started shred (all) for: " + it->getModelName() + "-" + it->getSerial() + " @" + address.str()); +#endif + } + mxDrives.unlock(); +} + /** * \brief print drives with all information * \param pointer of list * plistDrives diff --git a/src/tui.cpp b/src/tui.cpp index 9078b11..edb3532 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -237,6 +237,9 @@ enum TUI::UserInput TUI::readUserInput() case 'S': return TUI::UserInput::ShredAll; break; + case 'T': + return TUI::UserInput::Terminate; + break; default: return TUI::UserInput::Undefined; break; @@ -482,8 +485,12 @@ WINDOW *TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st { string sLineTmp = "Press d for Delete"; mvwaddstr(newWindow, u16Line++, (iXSize / 2) - (sLineTmp.size() / 2), sLineTmp.c_str()); + u16Line++; } + string sLineTmp = "Press T for terminating reHDD"; + mvwaddstr(newWindow, u16Line++, (iXSize / 2) - (sLineTmp.size() / 2), sLineTmp.c_str()); + return newWindow; } From 1ec4a2c79370e98761c7c78abbde0ab9fff96ace Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 21 Jun 2025 11:46:45 +0200 Subject: [PATCH 2/3] fix shred.cpp --- src/shred.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shred.cpp b/src/shred.cpp index d6b53c9..2255310 100644 --- a/src/shred.cpp +++ b/src/shred.cpp @@ -187,7 +187,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd) Logger::logThis()->info("Check-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str()); drive->u32DriveChecksumAfterShredding = uiCalcChecksum(driveFileDiscr, drive, ipSignalFd); #ifdef LOG_LEVEL_HIGH - if (drive->u32DriveChecksumAferShredding != 0) + if (drive->u32DriveChecksumAfterShredding != 0) { Logger::logThis()->info("Shred-Task: Checksum not zero: " + to_string(drive->u32DriveChecksumAfterShredding) + " - Drive: " + drive->getSerial()); } From 20d0dd8e90d1bf57a53153482f4e822450aa30b3 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 21 Jun 2025 11:49:49 +0200 Subject: [PATCH 3/3] reset build settings --- include/reHDD.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index 602d057..519a4ce 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -25,13 +25,13 @@ #define SOFTWARE_VERSION REHDD_VERSION #define HARDWARE_VERSION "generic" -#define LOG_LEVEL_HIGH // log everything, like drive scan thread +// #define LOG_LEVEL_HIGH // log everything, like drive scan thread #ifndef LOG_LEVEL_HIGH #define LOG_LEVEL_LOW // log only user actions and tasks #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