/** * @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; }