added drive wipe
This commit is contained in:
parent
eccd7b0a8b
commit
36e8f5b62c
|
@ -8,17 +8,19 @@
|
||||||
#ifndef REHDD_H_
|
#ifndef REHDD_H_
|
||||||
#define REHDD_H_
|
#define REHDD_H_
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <time.h>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "drive.h"
|
#include "drive.h"
|
||||||
#include "smart.h"
|
#include "smart.h"
|
||||||
|
#include "wipe.h"
|
||||||
|
|
||||||
template <typename T, typename I> T* iterator_to_pointer(I i)
|
template <typename T, typename I> T* iterator_to_pointer(I i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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_
|
|
@ -30,6 +30,18 @@ void reHDD::app_logic(void)
|
||||||
filterIgnoredDrives(&vecDrives); //filter out ignored drives
|
filterIgnoredDrives(&vecDrives); //filter out ignored drives
|
||||||
addSMARTData(&vecDrives); //add S.M.A.R.T. Data to the drives
|
addSMARTData(&vecDrives); //add S.M.A.R.T. Data to the drives
|
||||||
printDrives(&vecDrives); //print currently attached 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 <Drive>* pvecDrives)
|
||||||
vector <Drive>::iterator it;
|
vector <Drive>::iterator it;
|
||||||
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
||||||
{
|
{
|
||||||
|
cout << " Drive: " << distance(pvecDrives->begin(), it) << endl;
|
||||||
cout << "Path: " << it->getPath() << endl;
|
cout << "Path: " << it->getPath() << endl;
|
||||||
cout << "ModelFamily: " << it->getModelFamily() << endl;
|
cout << "ModelFamily: " << it->getModelFamily() << endl;
|
||||||
cout << "ModelName: " << it->getModelName() << endl;
|
cout << "ModelName: " << it->getModelName() << endl;
|
||||||
|
|
72
src/wipe.cpp
72
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<double, std::milli>(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;
|
||||||
|
}
|
|
@ -11,7 +11,8 @@
|
||||||
"string": "cpp",
|
"string": "cpp",
|
||||||
"unordered_map": "cpp",
|
"unordered_map": "cpp",
|
||||||
"string_view": "cpp",
|
"string_view": "cpp",
|
||||||
"ostream": "cpp"
|
"ostream": "cpp",
|
||||||
|
"chrono": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue