diff --git a/include/reHDD.h b/include/reHDD.h index e0ba8bd..a05e1ad 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,17 +8,19 @@ #ifndef REHDD_H_ #define REHDD_H_ -#include #include #include #include #include #include +#include +#include using namespace std; #include "drive.h" #include "smart.h" +#include "wipe.h" template T* iterator_to_pointer(I i) { diff --git a/include/wipe.h b/include/wipe.h new file mode 100644 index 0000000..21c8d5f --- /dev/null +++ b/include/wipe.h @@ -0,0 +1,25 @@ +/** + * @file wipe.h + * @brief wipe drive + * @author hendrik schutter + * @date 03.05.2020 + */ + +#ifndef WIPE_H_ +#define WIPE_H_ + +#include "reHDD.h" + +class Wipe +{ +protected: + +public: + static void wipeDrive(Drive* drive); + +private: + Wipe(void); + +}; + +#endif // WIPE_H_ \ No newline at end of file diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 756f95a..a123c19 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -30,6 +30,18 @@ void reHDD::app_logic(void) filterIgnoredDrives(&vecDrives); //filter out ignored drives addSMARTData(&vecDrives); //add S.M.A.R.T. Data to the drives printDrives(&vecDrives); //print currently attached drives + + size_t u64SelectedDriveIndex = 0U; + size_t u64DriveVecSize = (vecDrives.size()); + + cout << "Select drive to wipe:" << endl; + cin >> u64SelectedDriveIndex; + cout << "Selected drive index: " << u64SelectedDriveIndex << endl; + + if(u64SelectedDriveIndex < (u64DriveVecSize)) { + Wipe::wipeDrive(&vecDrives[u64SelectedDriveIndex]); + } + } /** @@ -158,6 +170,7 @@ void reHDD::printDrives(vector * pvecDrives) vector ::iterator it; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) { + cout << " Drive: " << distance(pvecDrives->begin(), it) << endl; cout << "Path: " << it->getPath() << endl; cout << "ModelFamily: " << it->getModelFamily() << endl; cout << "ModelName: " << it->getModelName() << endl; diff --git a/src/wipe.cpp b/src/wipe.cpp index e69de29..aac5c33 100644 --- a/src/wipe.cpp +++ b/src/wipe.cpp @@ -0,0 +1,72 @@ +/** + * @file wipe.cpp + * @brief wipe drive + * @author hendrik schutter + * @date 03.05.2020 + */ + +#include "../include/reHDD.h" + +//#define DRYRUN //if defined the drive will not be wiped, a ping cmd is attempted instead + +/** + * \brief wipe drive with shred + * \param pointer of Drive instance + * \return void + */ +void Wipe::wipeDrive(Drive* drive) +{ + size_t len = 0; //lenght of found line + char* cLine = NULL; //found line + +#ifndef DRYRUN + string sCMD = ("./bin_util/shred -v "); + sCMD.append(drive->getPath()); +#endif +#ifdef DRYRUN + cout << "dryrun for " << drive->getPath() << endl; + string sCMD = ("ping ::1 -c 5"); +#endif + const char* cpComand = sCMD.c_str(); + + cout << "wipe: " << cpComand << endl; + + auto t_start = chrono::high_resolution_clock::now(); + + FILE* outputfileSmart = popen(cpComand, "r"); + + while ((getline(&cLine, &len, outputfileSmart)) != -1) + { + string sLine = string(cLine); + cout << sLine; + } + fclose(outputfileSmart); + + auto t_end = chrono::high_resolution_clock::now(); + + uint64_t u64TimeMS = chrono::duration(t_end-t_start).count(); + + uint64_t u64hours = 0U; + uint64_t u64minutes = 0U; + uint64_t u64seconds = 0U; + + while(u64TimeMS >= 1000) + { + u64seconds++; + u64TimeMS = u64TimeMS - 1000; + } + + while(u64seconds >= 60) + { + u64minutes++; + u64seconds = u64seconds - 60; + } + + while(u64minutes >= 60) + { + u64hours++; + u64minutes = u64minutes - 60; + } + + cout << "Elapsed time: " << u64hours << " h - " << u64minutes << " min - " << u64seconds << " sec" << endl; +} diff --git a/vcCodium.code-workspace b/vcCodium.code-workspace index a924abd..6b6425d 100644 --- a/vcCodium.code-workspace +++ b/vcCodium.code-workspace @@ -11,7 +11,8 @@ "string": "cpp", "unordered_map": "cpp", "string_view": "cpp", - "ostream": "cpp" + "ostream": "cpp", + "chrono": "cpp" } } } \ No newline at end of file