select drive based on arrow keys

This commit is contained in:
Hendrik Schutter 2020-08-07 11:38:00 +02:00
parent a92a9c2a2a
commit 1b0ea97ed1
7 changed files with 355 additions and 267 deletions

View File

@ -50,18 +50,19 @@ public:
private:
vector <Drive> vecDrives; //stores all drive data
static void searchDrives(vector <Drive>* pvecDrives);
static void printDrives(vector <Drive>* pvecDrives);
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
static void addSMARTData(vector <Drive>* pvecDrives);
static void ThreadScannDevices();
static void ThreadUserInput();
static void ThreadUserInput();
void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);
static void handleArrowKey(TUI::UserInput userInput);
static void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);
TUI *ui;

View File

@ -13,6 +13,7 @@
#define COLOR_AREA_STDSCR 1
#define COLOR_AREA_OVERVIEW 2
#define COLOR_AREA_ENTRY 3
#define COLOR_AREA_ENTRY_SELECTED 4
#define COLOR_GRAY 8
@ -28,7 +29,7 @@ public:
static void initTUI();
void updateTUI(vector <Drive>* pvecDrives);
void updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry);
static enum UserInput readUserInput();
@ -43,7 +44,7 @@ private:
static void centerTitle(WINDOW *pwin, const char * title);
static WINDOW *createOverViewWindow( int iXSize, int iYSize);
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart);
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity);
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity, bool bSelected);
};

View File

@ -8,7 +8,8 @@
#include "../../include/reHDD.h"
TUI::TUI(void) {
TUI::TUI(void)
{
@ -26,12 +27,15 @@ void TUI::initTUI()
initscr();
raw();
keypad(stdscr,TRUE);
if(has_colors() == TRUE) {
start_color();
} else {
printf("Your terminal does not support color\n");
exit(1);
}
if(has_colors() == TRUE)
{
start_color();
}
else
{
printf("Your terminal does not support color\n");
exit(1);
}
clear();
curs_set(0);
noecho();
@ -41,11 +45,18 @@ void TUI::initTUI()
init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE);
wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR));
init_pair(COLOR_AREA_ENTRY, COLOR_BLACK, COLOR_GRAY);
init_pair(COLOR_AREA_ENTRY_SELECTED, COLOR_BLACK, COLOR_WHITE);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 ");
}
void TUI::updateTUI(vector <Drive>* pvecDrives) {
void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry)
{
int stdscrX, stdscrY;
getmaxyx(stdscr, stdscrY, stdscrX);
@ -63,19 +74,27 @@ void TUI::updateTUI(vector <Drive>* pvecDrives) {
vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{
string sModelFamily = it->getModelFamily();
string sModelName = it->getModelName();
string sCapacity = it->sCapacityToText();
{
string sModelFamily = it->getModelFamily();
string sModelName = it->getModelName();
string sCapacity = it->sCapacityToText();
WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity);
wrefresh(tmp);
}
bool bSelectedEntry = false;
if(i32SelectedEntry == (it - pvecDrives->begin()))
{
bSelectedEntry = true;
}
WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, bSelectedEntry);
wrefresh(tmp);
}
}
enum TUI::UserInput TUI::readUserInput() {
int ch = wgetch(stdscr);
switch(ch)
enum TUI::UserInput TUI::readUserInput()
{
int ch = wgetch(stdscr);
switch(ch)
{
case KEY_UP:
return TUI::UserInput::UpKey;
@ -106,7 +125,8 @@ enum TUI::UserInput TUI::readUserInput() {
}
void TUI::centerTitle(WINDOW *pwin, const char * title) {
void TUI::centerTitle(WINDOW *pwin, const char * title)
{
int x, maxX, stringSize;
getmaxyx(pwin, maxX, maxX);
stringSize = 4 + strlen(title);
@ -118,10 +138,11 @@ void TUI::centerTitle(WINDOW *pwin, const char * title) {
waddch(pwin, ACS_LTEE);
}
WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize) {
WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, 2, 2);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
box(newWindow, ACS_VLINE, ACS_HLINE);
@ -142,10 +163,11 @@ WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize) {
return newWindow;
}
WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) {
WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, 2, iXStart);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
box(newWindow, ACS_VLINE, ACS_HLINE);
centerTitle(newWindow, "Selected Drive: xyz");
@ -154,14 +176,27 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) {
return newWindow;
}
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity) {
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, bool bSelected)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
init_pair(COLOR_AREA_ENTRY, COLOR_BLACK, COLOR_GRAY);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY));
box(newWindow, ACS_VLINE, ACS_HLINE);
attron(COLOR_PAIR(COLOR_AREA_ENTRY));
if(!bSelected)
{
// entry is NOT selected
attron(COLOR_PAIR(COLOR_AREA_ENTRY));
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY));
}
else
{
// entry IS selected
attron(COLOR_PAIR(COLOR_AREA_ENTRY));
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY_SELECTED));
}
box(newWindow, ACS_VLINE, ACS_HLINE);
mvwaddstr(newWindow,1, 1, sModelFamily.c_str());
mvwaddstr(newWindow,2, 1, sModelName.c_str());

View File

@ -46,15 +46,18 @@ uint32_t Drive::getPowerCycles(void)
return u32PowerCycles;
}
string Drive::sCapacityToText() {
if(getCapacity() <= (999*1000000000UL)) {
// Less or even 999 GB --> GB
return to_string(getCapacity() / 1000000000UL) + " GB";
}
else {
// More 999 GB --> TB
return to_string(getCapacity() / 1000000000000UL) + " TB";
}
string Drive::sCapacityToText()
{
if(getCapacity() <= (999*1000000000UL))
{
// Less or even 999 GB --> GB
return to_string(getCapacity() / 1000000000UL) + " GB";
}
else
{
// More 999 GB --> TB
return to_string(getCapacity() / 1000000000000UL) + " TB";
}
return "ERROR";
}

View File

@ -18,6 +18,11 @@ static std::mutex mxScannDrives;
static vector <Drive> vecNewDrives; //store found drives that are updated every 5sec
static vector <Drive> vecDrives; //stores all drive data from scann thread
TUI *ui;
static int32_t i32SelectedEntry;
static fd_set selectSet;
@ -29,8 +34,7 @@ static fd_set selectSet;
reHDD::reHDD(void)
{
cout << "created app" << endl;
i32SelectedEntry = 0;
}
/**
@ -41,9 +45,7 @@ reHDD::reHDD(void)
void reHDD::app_logic(void)
{
cout << "app logic" << endl;
ui = new TUI();
ui->initTUI();
pipe(fdSearchDrives);
@ -56,107 +58,124 @@ void reHDD::app_logic(void)
thread thDevices(ThreadScannDevices); //start thread that scanns for drives
thread thUserInput(ThreadUserInput); //start thread that reads user input
while(1) {
while(1)
{
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
if( FD_ISSET(fdSearchDrives[0], &selectSet)) {
char dummy;
read (fdSearchDrives[0],&dummy,1);
mxScannDrives.lock();
filterNewDrives(&vecDrives, &vecNewDrives);
//printDrives(&vecDrives);
//TODO update UI
if( FD_ISSET(fdSearchDrives[0], &selectSet))
{
char dummy;
read (fdSearchDrives[0],&dummy,1);
mxScannDrives.lock();
ui->updateTUI(&vecDrives);
filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector
mxScannDrives.unlock();
//printDrives(&vecDrives);
//TODO update UI
mxScannDrives.unlock();
}
else if (FD_ISSET(fdWhipe[0], &selectSet)) {
cout << "Whipe signal" << endl;
}
} //endless loop
ui->updateTUI(&vecDrives, i32SelectedEntry);
}
else if (FD_ISSET(fdWhipe[0], &selectSet))
{
cout << "Whipe signal" << endl;
//update percantage & state
//update ui
}
} //endless loop
thDevices.join();
thUserInput.join();
}
void reHDD::ThreadScannDevices() {
while(true) {
// cout << "Thread" << endl;
mxScannDrives.lock();
vecNewDrives.clear();
searchDrives(&vecNewDrives); //search for new drives and store them in list
filterIgnoredDrives(&vecNewDrives); //filter out ignored drives
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
mxScannDrives.unlock();
write (fdSearchDrives[1], "A",1);
sleep(5); //sleep 5 sec
}
}
void reHDD::ThreadUserInput() {
while(true) {
// cout << TUI::readUserInput() << endl;
switch (TUI::readUserInput())
void reHDD::ThreadScannDevices()
{
while(true)
{
case TUI::UserInput::DownKey:
/* code */
//cout << "Down" << endl;
break;
case TUI::UserInput::UpKey:
//cout << "Up" << endl;
break;
case TUI::UserInput::Undefined:
//cout << "Undefined" << endl;
break;
case TUI::UserInput::Abort:
//cout << "Abort" << endl;
break;
case TUI::UserInput::Delete:
//cout << "Delete" << endl;
break;
case TUI::UserInput::Shred:
//cout << "Shred" << endl;
break;
case TUI::UserInput::Enter:
//cout << "Enter" << endl;
break;
case TUI::UserInput::ESC:
//cout << "ESC" << endl;
break;
default:
break;
// cout << "Thread" << endl;
mxScannDrives.lock();
vecNewDrives.clear();
searchDrives(&vecNewDrives); //search for new drives and store them in list
filterIgnoredDrives(&vecNewDrives); //filter out ignored drives
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
mxScannDrives.unlock();
write (fdSearchDrives[1], "A",1);
sleep(5); //sleep 5 sec
}
}
}
void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives) {
void reHDD::ThreadUserInput()
{
while(true)
{
// cout << TUI::readUserInput() << endl;
switch (TUI::readUserInput())
{
case TUI::UserInput::DownKey:
//cout << "Down" << endl;
handleArrowKey(TUI::UserInput::DownKey);
ui->updateTUI(&vecDrives, i32SelectedEntry);
break;
case TUI::UserInput::UpKey:
//cout << "Up" << endl;
handleArrowKey(TUI::UserInput::UpKey);
ui->updateTUI(&vecDrives, i32SelectedEntry);
break;
case TUI::UserInput::Undefined:
//cout << "Undefined" << endl;
break;
case TUI::UserInput::Abort:
//cout << "Abort" << endl;
break;
case TUI::UserInput::Delete:
//cout << "Delete" << endl;
break;
case TUI::UserInput::Shred:
//cout << "Shred" << endl;
break;
case TUI::UserInput::Enter:
//cout << "Enter" << endl;
break;
case TUI::UserInput::ESC:
//cout << "ESC" << endl;
break;
default:
break;
}
}
}
void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives)
{
vector <Drive>::iterator itOld; //Iterator for current (old) drive list
vector <Drive>::iterator itNew; //Iterator for new drive list that was created from to scann thread
for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld)
{
bool bOldDriveIsOffline = true;
for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew)
{
if(itOld->getSerial() == itNew->getSerial()) {
bOldDriveIsOffline = false;
// cout << "already online drive found: " << itOld->getPath() << endl;
}
}
bool bOldDriveIsOffline = true;
for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew)
{
if(itOld->getSerial() == itNew->getSerial())
{
bOldDriveIsOffline = false;
// cout << "already online drive found: " << itOld->getPath() << endl;
}
}
if(bOldDriveIsOffline == true) {
//cout << "offline drive found: " << itOld->getPath() << endl;
//TODO kill wipe thread
if(bOldDriveIsOffline == true)
{
//cout << "offline drive found: " << itOld->getPath() << endl;
//TODO kill wipe thread
}
}
}
pvecOldDrives->clear();
for (long unsigned int i=0; i<pvecNewDrives->size(); i++) {
pvecOldDrives->push_back((*pvecNewDrives)[i]);
}
for (long unsigned int i=0; i<pvecNewDrives->size(); i++)
{
pvecOldDrives->push_back((*pvecNewDrives)[i]);
}
}
/**
@ -173,18 +192,18 @@ void reHDD::searchDrives(vector <Drive>* pvecDrives)
FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r");
if (outputfileHwinfo == NULL)
{
exit(EXIT_FAILURE);
}
{
exit(EXIT_FAILURE);
}
while ((getline(&cLine, &len, outputfileHwinfo)) != -1)
{
if (string(cLine).find("/dev/sd") != string::npos)
{
Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
pvecDrives->push_back(*tmpDrive);
if (string(cLine).find("/dev/sd") != string::npos)
{
Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
pvecDrives->push_back(*tmpDrive);
}
}
}
fclose(outputfileHwinfo);
}
@ -206,72 +225,72 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
ifstream input( "ignoreDrives.conf" ); //read ingnore file
for(string sLine; getline( input, sLine );)
{
if (string(sLine).find("/dev/sd") != string::npos)
{
size_t pos = 0;
string token;
while ((pos = sLine.find(sDelimiter)) != string::npos)
{
token = sLine.substr(0, pos);
sIgnoredDrivePath = token;
sLine.erase(0, pos + sDelimiter.length());
sIgnoredDriveUUID = sLine;
} //end while
//cout << "Path: " << sIgnoredDrivePath << std::endl;
//cout << "UUID: " << sIgnoredDriveUUID << std::endl;
vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ingnore file to vector
if (string(sLine).find("/dev/sd") != string::npos)
{
size_t pos = 0;
string token;
while ((pos = sLine.find(sDelimiter)) != string::npos)
{
token = sLine.substr(0, pos);
sIgnoredDrivePath = token;
sLine.erase(0, pos + sDelimiter.length());
sIgnoredDriveUUID = sLine;
} //end while
//cout << "Path: " << sIgnoredDrivePath << std::endl;
//cout << "UUID: " << sIgnoredDriveUUID << std::endl;
vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ingnore file to vector
}
}
}
//loop through found entries in ingnore file
for(auto row : vtlIgnoredDevices)
{
vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{
string sUUID;
if (!get<0>(row).compare(it->getPath())) //find same drive based on path
{
char * cLine = NULL;
size_t len = 0;
string sCMD = "blkid ";
sCMD.append(it->getPath());
//cout << "cmd: " << sCMD << endl;
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
if (outputfileBlkid == NULL)
vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{
exit(EXIT_FAILURE);
}
string sUUID;
if (!get<0>(row).compare(it->getPath())) //find same drive based on path
{
char * cLine = NULL;
size_t len = 0;
string sCMD = "blkid ";
sCMD.append(it->getPath());
//cout << "cmd: " << sCMD << endl;
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
if (outputfileBlkid == NULL)
{
exit(EXIT_FAILURE);
}
while ((getline(&cLine, &len, outputfileBlkid)) != -1) //parse UUID from blkid
{
if (string(cLine).find("PTUUID") != string::npos)
{
string sBlkidOut = string(cLine);
sBlkidOut.erase(0, 18);
sBlkidOut.erase(36, sBlkidOut.length() - 36);
sUUID = sBlkidOut;
//cout << "blkid uuid:" << sUUID << endl;
}
}
fclose(outputfileBlkid);
//cout << "blkid uuid:" << sUUID << endl;
while ((getline(&cLine, &len, outputfileBlkid)) != -1) //parse UUID from blkid
{
if (string(cLine).find("PTUUID") != string::npos)
{
string sBlkidOut = string(cLine);
sBlkidOut.erase(0, 18);
sBlkidOut.erase(36, sBlkidOut.length() - 36);
sUUID = sBlkidOut;
//cout << "blkid uuid:" << sUUID << endl;
}
}
fclose(outputfileBlkid);
//cout << "blkid uuid:" << sUUID << endl;
if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
{
cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl;
exit(EXIT_FAILURE); // exit to prevent accidentally shred a system drive
if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
{
cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl;
exit(EXIT_FAILURE); // exit to prevent accidentally shred a system drive
}
else
{
// same uuid found than in ignore file --> ignore this drive
it = pvecDrives->erase(it);
it--;
//cout << "same uuid found than in ignore file --> ignore this drive:" << it->getPath() << endl;
}
}
}
else
{
// same uuid found than in ignore file --> ignore this drive
it = pvecDrives->erase(it);
it--;
//cout << "same uuid found than in ignore file --> ignore this drive:" << it->getPath() << endl;
}
}
}
}
}
/**
@ -284,18 +303,18 @@ void reHDD::printDrives(vector <Drive>* pvecDrives)
cout << "------------DRIVES---------------" << endl;
vector <Drive>::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;
cout << "Capacity: " << it->getCapacity() << endl;
cout << "Serial: " << it->getSerial() << endl;
cout << "PowerOnHours: " << it->getPowerOnHours() << endl;
cout << "PowerCycle: " << it->getPowerCycles() << endl;
cout << "ErrorCount: " << it->getErrorCount() << endl;
cout << endl;
}
{
cout << " Drive: " << distance(pvecDrives->begin(), it) << endl;
cout << "Path: " << it->getPath() << endl;
cout << "ModelFamily: " << it->getModelFamily() << endl;
cout << "ModelName: " << it->getModelName() << endl;
cout << "Capacity: " << it->getCapacity() << endl;
cout << "Serial: " << it->getSerial() << endl;
cout << "PowerOnHours: " << it->getPowerOnHours() << endl;
cout << "PowerCycle: " << it->getPowerCycles() << endl;
cout << "ErrorCount: " << it->getErrorCount() << endl;
cout << endl;
}
cout << "---------------------------------" << endl;
}
@ -308,8 +327,33 @@ void reHDD::addSMARTData(vector <Drive>* pvecDrives)
{
vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{
Drive* pTmpDrive = iterator_to_pointer<Drive, std::vector<Drive>::iterator > (it);
SMART::readSMARTData(pTmpDrive);
}
{
Drive* pTmpDrive = iterator_to_pointer<Drive, std::vector<Drive>::iterator > (it);
SMART::readSMARTData(pTmpDrive);
}
}
void reHDD::handleArrowKey(TUI::UserInput userInput)
{
int32_t i32EntrySize = (int32_t) vecDrives.size();
switch (userInput)
{
case TUI::UserInput::DownKey:
i32SelectedEntry++;
if(i32SelectedEntry >= i32EntrySize)
{
i32SelectedEntry = 0;
}
break;
case TUI::UserInput::UpKey:
i32SelectedEntry--;
if(i32SelectedEntry < 0)
{
i32SelectedEntry = (i32EntrySize-1);
}
break;
default:
i32SelectedEntry = 0;
break;
}
}

View File

@ -40,17 +40,17 @@ void SMART::readSMARTData(Drive* drive)
FILE* outputfileSmart = popen(cpComand, "r");
while ((getline(&cLine, &len, outputfileSmart)) != -1)
{
string sLine = string(cLine);
{
string sLine = string(cLine);
SMART::parseModelFamily(sLine);
SMART::parseModelName(sLine);
SMART::parseSerial(sLine);
SMART::parseCapacity(sLine);
SMART::parseErrorCount(sLine);
SMART::parsePowerOnHours(sLine);
SMART::parsePowerCycle(sLine);
}
SMART::parseModelFamily(sLine);
SMART::parseModelName(sLine);
SMART::parseSerial(sLine);
SMART::parseCapacity(sLine);
SMART::parseErrorCount(sLine);
SMART::parsePowerOnHours(sLine);
SMART::parsePowerCycle(sLine);
}
fclose(outputfileSmart);
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle); //wirte data in drive
}
@ -64,11 +64,12 @@ void SMART::parseModelFamily(string sLine)
{
string search("\"model_family\": ");
size_t found = sLine.find(search);
if (found!=string::npos) {
sLine.erase(0, sLine.find(": ") + 3);
sLine.erase(sLine.length()-3, 3);
modelFamily = sLine;
}
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ") + 3);
sLine.erase(sLine.length()-3, 3);
modelFamily = sLine;
}
}
/**
@ -80,11 +81,12 @@ void SMART::parseModelName(string sLine)
{
string search("\"model_name\": ");
size_t found = sLine.find(search);
if (found!=string::npos) {
sLine.erase(0, sLine.find(": ") + 3);
sLine.erase(sLine.length()-3, 3);
modelName = sLine;
}
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ") + 3);
sLine.erase(sLine.length()-3, 3);
modelName = sLine;
}
}
/**
@ -96,11 +98,12 @@ void SMART::parseSerial(string sLine)
{
string search("\"serial_number\": ");
size_t found = sLine.find(search);
if (found!=string::npos) {
sLine.erase(0, sLine.find(": ") + 3);
sLine.erase(sLine.length()-3, 3);
serial = sLine;
}
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ") + 3);
sLine.erase(sLine.length()-3, 3);
serial = sLine;
}
}
/**
@ -112,11 +115,12 @@ void SMART::parseCapacity(string sLine)
{
string search("\"bytes\": ");
size_t found = sLine.find(search);
if (found!=string::npos) {
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length()-1, 1);
capacity = stol(sLine);
}
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length()-1, 1);
capacity = stol(sLine);
}
}
/**
@ -129,11 +133,11 @@ void SMART::parseErrorCount(string sLine)
string search("\"error_count_total\": ");
size_t found = sLine.find(search);
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ")+2);
sLine.erase(sLine.length()-2, 2);
errorCount = stol(sLine);
}
{
sLine.erase(0, sLine.find(": ")+2);
sLine.erase(sLine.length()-2, 2);
errorCount = stol(sLine);
}
}
/**
@ -146,12 +150,12 @@ void SMART::parsePowerOnHours(string sLine)
string search("\"hours\": ");
size_t found = sLine.find(search);
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length()-1, 1);
powerOnHours = stol(sLine);
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length()-1, 1);
powerOnHours = stol(sLine);
}
}
}
/**
@ -164,11 +168,11 @@ void SMART::parsePowerCycle(string sLine)
string search("\"power_cycle_count\": ");
size_t found = sLine.find(search);
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length()-2, 2);
powerCycle = stol(sLine);
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length()-2, 2);
powerCycle = stol(sLine);
}
}
}

View File

@ -36,10 +36,10 @@ void Wipe::wipeDrive(Drive* drive)
FILE* outputfileSmart = popen(cpComand, "r");
while ((getline(&cLine, &len, outputfileSmart)) != -1)
{
string sLine = string(cLine);
cout << sLine;
}
{
string sLine = string(cLine);
cout << sLine;
}
fclose(outputfileSmart);
auto t_end = chrono::high_resolution_clock::now();
@ -51,22 +51,22 @@ void Wipe::wipeDrive(Drive* drive)
uint64_t u64seconds = 0U;
while(u64TimeMS >= 1000)
{
u64seconds++;
u64TimeMS = u64TimeMS - 1000;
}
{
u64seconds++;
u64TimeMS = u64TimeMS - 1000;
}
while(u64seconds >= 60)
{
u64minutes++;
u64seconds = u64seconds - 60;
}
{
u64minutes++;
u64seconds = u64seconds - 60;
}
while(u64minutes >= 60)
{
u64hours++;
u64minutes = u64minutes - 60;
}
{
u64hours++;
u64minutes = u64minutes - 60;
}
cout << "Elapsed time: " << u64hours << " h - " << u64minutes << " min - " << u64seconds << " sec" << endl;
}