From 1055ef57ee37f255f65ae27a1ee61918d7ae8963 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 16 Aug 2024 10:26:49 +0200 Subject: [PATCH] Disable delete after shred was once started. (#69) documented here: https://git.mosad.xyz/localhorst/reHDD/issues/65 Reviewed-on: https://git.mosad.xyz/localhorst/reHDD/pulls/69 Co-authored-by: localhorst Co-committed-by: localhorst --- include/drive.h | 1 + src/delete.cpp | 14 +++++++++----- src/shred.cpp | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/drive.h b/include/drive.h index f1e28ab..71b2d1d 100644 --- a/include/drive.h +++ b/include/drive.h @@ -34,6 +34,7 @@ public: } sShredSpeed; bool bWasShredded = false; // all shred iterations done + bool bWasShredStarted = false; // shred was atleast once started bool bWasChecked = false; // all shred iterations and optional checking done bool bWasDeleted = false; bool bIsOffline = false; diff --git a/src/delete.cpp b/src/delete.cpp index b7ca4bd..94560ab 100644 --- a/src/delete.cpp +++ b/src/delete.cpp @@ -32,11 +32,15 @@ void Delete::deleteDrive(Drive *drive) const char *cpComand = sCMD.c_str(); // cout << "delete: " << cpComand << endl; - FILE *deleteCmdOutput = popen(cpComand, "r"); - - while ((getline(&cLine, &len, deleteCmdOutput)) != -1) + if (drive->bWasShredStarted == false) { - // wipefs running + //only start delete if the drive was not shredded before + FILE *deleteCmdOutput = popen(cpComand, "r"); + + while ((getline(&cLine, &len, deleteCmdOutput)) != -1) + { + // wipefs running + } + pclose(deleteCmdOutput); } - pclose(deleteCmdOutput); } diff --git a/src/shred.cpp b/src/shred.cpp index 3cb9c48..d6b53c9 100644 --- a/src/shred.cpp +++ b/src/shred.cpp @@ -36,6 +36,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd) ostringstream address; address << (void const *)&(*drive); Logger::logThis()->info("Shred-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str()); + drive->bWasShredStarted = true; //Mark drive as partly shredded #ifdef DRYRUN for (int i = 0; i <= 500; i++) @@ -48,6 +49,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd) write(*ipSignalFd, "A", 1); usleep(20000); } + drive->bWasShredded = true; #endif #ifndef DRYRUN