1 Commits

Author SHA1 Message Date
fc83b60d85 Merge pull request 'create first beta release' (#23) from develop into master
Reviewed-on: #23
2020-09-15 13:47:06 +02:00
10 changed files with 153 additions and 272 deletions

View File

@ -1,24 +0,0 @@
#! /bin/bash
echo starting astyle for $PWD
astyle --style=gnu src/*.cpp
rm -f src/*.orig
astyle --style=gnu src/shred/*.cpp
rm -f src/shred/*.orig
astyle --style=gnu src/logger/*.cpp
rm -f src/logger/*.orig
astyle --style=gnu include/*.h
rm -f include//*.orig
astyle --style=gnu include//shred/*.h
rm -f include//shred/*.orig
astyle --style=gnu include//logger/*.h
rm -f include//logger/*.orig
echo finished astyle for $PWD

View File

@ -1,26 +0,0 @@
#! /usr/bin/bash
echo starting update
FILE=./ignoreDrives.conf
if test -f "$FILE"; then
echo backup exits
else
cp reHDD/ignoreDrives.conf ./ignoreDrives.conf
fi
cd reHDD
git reset
git stash force
git stash
git checkout master
git pull
make release
cp ../ignoreDrives.conf ./

View File

@ -1,3 +1 @@
/dev/sdc:4673974d-1af2-44fd-996b-a2d8e4c43d9a
/dev/sda:508ef27d-5039-4e8b-9e2c-22d7528b7149
/dev/sdb:32b66944-ffa0-40e9-817c-3f0c52eefaf4

View File

@ -10,6 +10,8 @@
#define REHDD_VERSION "bV0.1.0" #define REHDD_VERSION "bV0.1.0"
//#define DRYRUN
// Drive handling Settings // Drive handling Settings
#define WORSE_HOURS 19200 //mark drive if at this limit or beyond #define WORSE_HOURS 19200 //mark drive if at this limit or beyond
#define WORSE_POWERUP 10000 //mark drive if at this limit or beyond #define WORSE_POWERUP 10000 //mark drive if at this limit or beyond
@ -23,11 +25,6 @@
#define SOFTWARE_VERSION "alpha" #define SOFTWARE_VERSION "alpha"
#define HARDWARE_VERSION "generic" #define HARDWARE_VERSION "generic"
// Logic
//#define DRYRUN //don´t touch the drives
#define FROZEN_ALERT //show alert if drive is frozen
#define LOG_LEVEL_HIGH //log everything, like drive scann thread #define LOG_LEVEL_HIGH //log everything, like drive scann thread
#ifndef LOG_LEVEL_HIGH #ifndef LOG_LEVEL_HIGH
#define LOG_LEVEL_LOW //log only user actions and tasks #define LOG_LEVEL_LOW //log only user actions and tasks
@ -41,7 +38,7 @@
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <tuple> #include <tuple>
#include <list> #include <vector>
#include <time.h> #include <time.h>
#include <chrono> #include <chrono>
#include <curses.h> #include <curses.h>
@ -81,15 +78,14 @@ public:
private: private:
static void searchDrives(list <Drive>* plistDrives); static void searchDrives(vector <Drive>* pvecDrives);
static void printDrives(list <Drive>* plistDrives); static void printDrives(vector <Drive>* pvecDrives);
static void filterIgnoredDrives(list <Drive>* plistDrives); static void filterIgnoredDrives(vector <Drive>* pvecDrives);
static void filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNewDrives); static void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);
static void addSMARTData(list <Drive>* plistDrives); static void addSMARTData(vector <Drive>* pvecDrives);
static void ThreadScannDevices(); static void ThreadScannDevices();
static void ThreadUserInput(); static void ThreadUserInput();
static void ThreadShred(); static void ThreadShred();
static void ThreadDelete();
static void ThreadCheckFrozenDrives(); static void ThreadCheckFrozenDrives();
static void handleArrowKey(TUI::UserInput userInput); static void handleArrowKey(TUI::UserInput userInput);
static void handleEnter(); static void handleEnter();

View File

@ -36,7 +36,7 @@ public:
static void initTUI(); static void initTUI();
void updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry); void updateTUI(vector <Drive>* pvecDrives, uint8_t u8SelectedEntry);
static enum UserInput readUserInput(); static enum UserInput readUserInput();
@ -45,23 +45,22 @@ private:
static string sRamUsage; static string sRamUsage;
static string sLocalTime; static string sLocalTime;
WINDOW* overview; WINDOW* overview;
WINDOW* systemview; WINDOW* systemview;
WINDOW* detailview; WINDOW* detailview;
WINDOW* menuview; WINDOW* menuview;
WINDOW* dialog; WINDOW* dialog;
WINDOW* smartWarning;
static void centerTitle(WINDOW *pwin, const char * title); static void centerTitle(WINDOW *pwin, const char * title);
static WINDOW *createOverViewWindow( int iXSize, int iYSize); static WINDOW *createOverViewWindow( int iXSize, int iYSize);
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive); static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive);
static WINDOW *overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart); static WINDOW *overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart);
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, bool bSelected); static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, bool bSelected);
static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart); static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart);
static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate); static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate);
static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB); static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB);
static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress); static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial);
static WINDOW* createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount);
void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY); void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY);

View File

@ -167,7 +167,6 @@ clean:
@echo "Deleting directories" @echo "Deleting directories"
@$(RM) -r build @$(RM) -r build
@$(RM) -r bin @$(RM) -r bin
@$(RM) -f reHDD.log
# Main rule, checks the executable and symlinks to the output # Main rule, checks the executable and symlinks to the output
all: $(BIN_PATH)/$(BIN_NAME) all: $(BIN_PATH)/$(BIN_NAME)
@ -201,6 +200,5 @@ docs:
@$(RM) -r $(DOCDIR)/html @$(RM) -r $(DOCDIR)/html
@doxygen $(DOCDIR)/doxyfile @doxygen $(DOCDIR)/doxyfile
.PHONY: style
style:
@bash astyle.sh

View File

@ -21,7 +21,6 @@ void Delete::deleteDrive(Drive* drive)
#ifndef DRYRUN #ifndef DRYRUN
string sCMD = ("wipefs -af "); string sCMD = ("wipefs -af ");
sCMD.append(drive->getPath()); sCMD.append(drive->getPath());
sCMD.append("*");
#endif #endif
#ifdef DRYRUN #ifdef DRYRUN

View File

@ -69,19 +69,14 @@ string Drive::sErrorCountToText()
string Drive::sPowerOnHoursToText() string Drive::sPowerOnHoursToText()
{ {
double dDays = 0U;
double dYears = 0U; double dYears = 0U;
uint32_t u32Hours = getPowerOnHours(); uint32_t u32Hours = getPowerOnHours();
stringstream streamDays; stringstream stream;
stringstream streamYears;
dDays = (double) ((double)u32Hours/(double)24U);
dYears = (double) ((double)u32Hours/(double)8760U); dYears = (double) ((double)u32Hours/(double)8760U);
streamDays << fixed << setprecision(0) << dDays; stream << fixed << setprecision(2) << dYears;
streamYears << fixed << setprecision(1) << dYears; string sRet = to_string(getPowerOnHours()) + " hours or " + stream.str() + " years";
string sRet = to_string(getPowerOnHours()) + " hours or " + streamDays.str() + " days or " + streamYears.str() + " years";
return sRet; return sRet;
} }

View File

@ -13,9 +13,9 @@ static int fdShredInformPipe[2];//File descriptor for pipe that informs if a wip
static std::mutex mxScannDrives; static std::mutex mxScannDrives;
list <Drive> listNewDrives; //store found drives that are updated every 5sec vector <Drive> vecNewDrives; //store found drives that are updated every 5sec
static list <Drive> listDrives; //stores all drive data from scann thread static vector <Drive> vecDrives; //stores all drive data from scann thread
TUI *ui; TUI *ui;
@ -23,6 +23,8 @@ static uint8_t u8SelectedEntry;
static fd_set selectSet; static fd_set selectSet;
//static struct TUI::MenuState menustate;
/** /**
* \brief app constructor * \brief app constructor
* \param void * \param void
@ -31,6 +33,8 @@ static fd_set selectSet;
reHDD::reHDD(void) reHDD::reHDD(void)
{ {
u8SelectedEntry = 0U; u8SelectedEntry = 0U;
vecDrives.reserve(128);
} }
/** /**
@ -57,27 +61,23 @@ void reHDD::app_logic(void)
FD_SET(fdShredInformPipe[0], &selectSet); FD_SET(fdShredInformPipe[0], &selectSet);
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL); select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
if(FD_ISSET(fdNewDrivesInformPipe[0], &selectSet))
{
mxScannDrives.lock(); mxScannDrives.lock();
if( FD_ISSET(fdNewDrivesInformPipe[0], &selectSet))
{
char dummy; char dummy;
read (fdNewDrivesInformPipe[0],&dummy,1); read (fdNewDrivesInformPipe[0],&dummy,1);
filterNewDrives(&listDrives, &listNewDrives); //filter and copy to app logic vector filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector
printDrives(&listDrives); printDrives(&vecDrives);
mxScannDrives.unlock();
} }
if(FD_ISSET(fdShredInformPipe[0], &selectSet))
if (FD_ISSET(fdShredInformPipe[0], &selectSet))
{ {
char dummy; char dummy;
read (fdShredInformPipe[0],&dummy,1); read (fdShredInformPipe[0],&dummy,1);
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("got progress signal from a shred task");
#endif
} }
//mxScannDrives.lock(); ui->updateTUI(&vecDrives, u8SelectedEntry);
ui->updateTUI(&listDrives, u8SelectedEntry); mxScannDrives.unlock();
//mxScannDrives.unlock();
} //endless loop } //endless loop
thDevices.join(); thDevices.join();
thUserInput.join(); thUserInput.join();
@ -86,11 +86,9 @@ void reHDD::app_logic(void)
Drive* reHDD::getSelectedDrive() Drive* reHDD::getSelectedDrive()
{ {
if(u8SelectedEntry < listDrives.size() ) if(u8SelectedEntry < vecDrives.size() )
{ {
list<Drive>::iterator it = listDrives.begin(); return &(vecDrives.at(u8SelectedEntry));
advance(it, u8SelectedEntry);
return &(*it);
} }
else else
{ {
@ -104,22 +102,24 @@ void reHDD::ThreadScannDevices()
while(true) while(true)
{ {
mxScannDrives.lock(); mxScannDrives.lock();
listNewDrives.clear(); vecNewDrives.clear();
searchDrives(&listNewDrives); //search for new drives and store them in list searchDrives(&vecNewDrives); //search for new drives and store them in list
filterIgnoredDrives(&listNewDrives); //filter out ignored drives filterIgnoredDrives(&vecNewDrives); //filter out ignored drives
addSMARTData(&listNewDrives); //add S.M.A.R.T. Data to the drives addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
mxScannDrives.unlock(); mxScannDrives.unlock();
write(fdNewDrivesInformPipe[1], "A",1); write(fdNewDrivesInformPipe[1], "A",1);
sleep(5); //sleep 5 sec sleep(5); //sleep 5 sec
} }
} }
void reHDD::ThreadCheckFrozenDrives() void reHDD::ThreadCheckFrozenDrives()
{ {
while(true) while(true)
{ {
mxScannDrives.lock(); mxScannDrives.lock();
for(auto it = begin(listDrives); it != end(listDrives); ++it) for(auto it = begin(vecDrives); it != end(vecDrives); ++it)
{ {
if(it->state == Drive::SHRED_ACTIVE) if(it->state == Drive::SHRED_ACTIVE)
{ {
@ -127,7 +127,7 @@ void reHDD::ThreadCheckFrozenDrives()
} }
} }
mxScannDrives.unlock(); mxScannDrives.unlock();
sleep(13); //sleep 13 sec sleep(5); //sleep 5 sec
} }
} }
@ -141,12 +141,12 @@ void reHDD::ThreadUserInput()
case TUI::UserInput::DownKey: case TUI::UserInput::DownKey:
//cout << "Down" << endl; //cout << "Down" << endl;
handleArrowKey(TUI::UserInput::DownKey); handleArrowKey(TUI::UserInput::DownKey);
ui->updateTUI(&listDrives, u8SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::UpKey: case TUI::UserInput::UpKey:
//cout << "Up" << endl; //cout << "Up" << endl;
handleArrowKey(TUI::UserInput::UpKey); handleArrowKey(TUI::UserInput::UpKey);
ui->updateTUI(&listDrives, u8SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Undefined: case TUI::UserInput::Undefined:
//cout << "Undefined" << endl; //cout << "Undefined" << endl;
@ -154,7 +154,7 @@ void reHDD::ThreadUserInput()
case TUI::UserInput::Abort: case TUI::UserInput::Abort:
//cout << "Abort" << endl; //cout << "Abort" << endl;
handleAbort(); handleAbort();
ui->updateTUI(&listDrives, u8SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Delete: case TUI::UserInput::Delete:
//cout << "Delete" << endl; //cout << "Delete" << endl;
@ -166,7 +166,7 @@ void reHDD::ThreadUserInput()
getSelectedDrive()->state = Drive::DELETE_SELECTED; getSelectedDrive()->state = Drive::DELETE_SELECTED;
} }
} }
ui->updateTUI(&listDrives, u8SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Shred: case TUI::UserInput::Shred:
//cout << "Shred" << endl; //cout << "Shred" << endl;
@ -178,17 +178,17 @@ void reHDD::ThreadUserInput()
getSelectedDrive()->state = Drive::SHRED_SELECTED; getSelectedDrive()->state = Drive::SHRED_SELECTED;
} }
} }
ui->updateTUI(&listDrives, u8SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::Enter: case TUI::UserInput::Enter:
//cout << "Enter" << endl; //cout << "Enter" << endl;
handleEnter(); handleEnter();
ui->updateTUI(&listDrives, u8SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
case TUI::UserInput::ESC: case TUI::UserInput::ESC:
//cout << "ESC" << endl; //cout << "ESC" << endl;
handleESC(); handleESC();
ui->updateTUI(&listDrives, u8SelectedEntry); ui->updateTUI(&vecDrives, u8SelectedEntry);
break; break;
default: default:
break; break;
@ -203,36 +203,24 @@ void reHDD::ThreadShred()
Shred* pShredTask = new Shred(); //create new shred task Shred* pShredTask = new Shred(); //create new shred task
pShredTask->shredDrive(getSelectedDrive(), &fdShredInformPipe[1]); //start new shred task pShredTask->shredDrive(getSelectedDrive(), &fdShredInformPipe[1]); //start new shred task
delete pShredTask; //delete shred task delete pShredTask; //delete shred task
ui->updateTUI(&listDrives, u8SelectedEntry);; ui->updateTUI(&vecDrives, u8SelectedEntry);
} }
} }
void reHDD::ThreadDelete() void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives)
{ {
if (getSelectedDrive() != nullptr) 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
Delete::deleteDrive(getSelectedDrive()); //blocking, no thread
getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished
getSelectedDrive()->bWasDeleteted = true;
Logger::logThis()->info("Finished delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
ui->updateTUI(&listDrives, u8SelectedEntry);
}
}
void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNewDrives)
{
list <Drive>::iterator itOld; //Iterator for current (old) drive list
list <Drive>::iterator itNew; //Iterator for new drive list that was created from to scann thread
//remove offline old drives from previously run //remove offline old drives from previously run
for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end();) for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end();)
{ {
if(itOld->bIsOffline == true) if(itOld->bIsOffline == true)
{ {
Logger::logThis()->warning("Offline drive found: " + itOld->getPath()); Logger::logThis()->warning("Offline drive found: " + itOld->getPath());
itOld = plistOldDrives->erase(itOld); itOld = pvecOldDrives->erase(itOld);
/* /*
if(plistOldDrives->size() > 0){ //This can be a risk if the user starts a task for the selected drive and the selected drive changes if(pvecOldDrives->size() > 0){ //This can be a risk if the user starts a task for the selected drive and the selected drive changes
u8SelectedEntry = 0U; u8SelectedEntry = 0U;
} }
*/ */
@ -244,10 +232,10 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
} }
//search offline drives and mark them //search offline drives and mark them
for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end(); ++itOld) for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld)
{ {
itOld->bIsOffline = true; //set offline befor seachring in the new list itOld->bIsOffline = true; //set offline befor seachring in the new list
for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end();) for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end();)
{ {
if((itOld->getSerial() == itNew->getSerial()) || (itOld->getPath() == itNew->getPath())) if((itOld->getSerial() == itNew->getSerial()) || (itOld->getPath() == itNew->getPath()))
{ {
@ -255,7 +243,7 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
#ifdef LOG_LEVEL_HIGH #ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName()); Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName());
#endif #endif
itNew = plistNewDrives->erase(itNew); //This drive is allready attached, remove from new list itNew = pvecNewDrives->erase(itNew); //This drive is allready attached, remove from new list
} }
else else
{ {
@ -265,7 +253,7 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
} }
//mark offline old drives //mark offline old drives
for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end(); ++itOld) for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld)
{ {
if(itOld->bIsOffline == true) if(itOld->bIsOffline == true)
{ {
@ -276,12 +264,12 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
} }
//add new drives to drive list //add new drives to drive list
for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end(); ++itNew) for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew)
{ {
plistOldDrives->push_back(*itNew); pvecOldDrives->push_back(pvecNewDrives->at(itNew - pvecNewDrives->begin()));
Logger::logThis()->info("Add new drive: " + itNew->getModelName()); Logger::logThis()->info("Add new drive: " + itNew->getModelName());
} }
plistNewDrives->clear(); pvecNewDrives->clear();
} }
/** /**
@ -289,29 +277,28 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
* \param pointer of vector <Drive>* pvecDrives * \param pointer of vector <Drive>* pvecDrives
* \return void * \return void
*/ */
void reHDD::searchDrives(list <Drive>* plistDrives) void reHDD::searchDrives(vector <Drive>* pvecDrives)
{ {
// cout << "search drives ..." << endl; // cout << "search drives ..." << endl;
Logger::logThis()->info("--> search drives <--"); Logger::logThis()->info("--> search drives <--");
char * cLine = NULL; char * cLine = NULL;
size_t len = 0; size_t len = 0;
FILE* outputfileHwinfo = popen("ls -1 /dev/sd*", "r"); FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r");
if (outputfileHwinfo == NULL) if (outputfileHwinfo == NULL)
{ {
Logger::logThis()->error("Unable to scann attached drives");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while ((getline(&cLine, &len, outputfileHwinfo)) != -1) while ((getline(&cLine, &len, outputfileHwinfo)) != -1)
{ {
if (string(cLine).length() == 9) if (string(cLine).find("/dev/sd") != string::npos)
{ {
Drive* tmpDrive = new Drive(string(cLine).substr(0, 8)); Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
tmpDrive->state = Drive::NONE; tmpDrive->state = Drive::NONE;
tmpDrive->bIsOffline = false; tmpDrive->bIsOffline = false;
plistDrives->push_back(*tmpDrive); pvecDrives->push_back(*tmpDrive);
} }
} }
fclose(outputfileHwinfo); fclose(outputfileHwinfo);
@ -322,13 +309,13 @@ void reHDD::searchDrives(list <Drive>* plistDrives)
* \param pointer of vector <Drive>* pvecDrives * \param pointer of vector <Drive>* pvecDrives
* \return void * \return void
*/ */
void reHDD::filterIgnoredDrives(list <Drive>* plistDrives) void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
{ {
string sDelimiter = ":"; string sDelimiter = ":";
string sIgnoredDrivePath; string sIgnoredDrivePath;
string sIgnoredDriveUUID; string sIgnoredDriveUUID;
list<tuple<string, string>> vtlIgnoredDevices; //store drives from ingnore file vector<tuple<string, string>> vtlIgnoredDevices; //store drives from ingnore file
ifstream input( "ignoreDrives.conf" ); //read ingnore file ifstream input( "ignoreDrives.conf" ); //read ingnore file
@ -351,8 +338,8 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
//loop through found entries in ingnore file //loop through found entries in ingnore file
for(auto row : vtlIgnoredDevices) for(auto row : vtlIgnoredDevices)
{ {
list <Drive>::iterator it; vector <Drive>::iterator it;
for (it = plistDrives->begin(); it != plistDrives->end(); ++it) for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{ {
string sUUID; string sUUID;
if (!get<0>(row).compare(it->getPath())) //find same drive based on path if (!get<0>(row).compare(it->getPath())) //find same drive based on path
@ -394,7 +381,7 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
#ifdef LOG_LEVEL_HIGH #ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath()); Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath());
#endif #endif
it = plistDrives->erase(it); it = pvecDrives->erase(it);
it--; it--;
} }
} }
@ -407,14 +394,13 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
* \param pointer of vector <Drive>* pvecDrives * \param pointer of vector <Drive>* pvecDrives
* \return void * \return void
*/ */
void reHDD::printDrives(list <Drive>* plistDrives) void reHDD::printDrives(vector <Drive>* pvecDrives)
{ {
#ifdef LOG_LEVEL_HIGH #ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("------------DRIVES START------------"); Logger::logThis()->info("------------DRIVES---------------");
//cout << "------------DRIVES---------------" << endl; //cout << "------------DRIVES---------------" << endl;
list <Drive>::iterator it; vector <Drive>::iterator it;
uint8_t u8Index = 0; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{ {
/* /*
cout << " Drive: " << distance(pvecDrives->begin(), it) << endl; cout << " Drive: " << distance(pvecDrives->begin(), it) << endl;
@ -429,10 +415,12 @@ void reHDD::printDrives(list <Drive>* plistDrives)
cout << endl;*/ cout << endl;*/
ostringstream address; ostringstream address;
address << (void const *)&(*it); address << (void const *)&pvecDrives->at(it - pvecDrives->begin());
Logger::logThis()->info(to_string(u8Index++) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str());
Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str());
} }
Logger::logThis()->info("------------DRIVES END--------------"); Logger::logThis()->info("---------------------------------");
//cout << "---------------------------------" << endl; //cout << "---------------------------------" << endl;
#endif #endif
} }
@ -442,19 +430,19 @@ void reHDD::printDrives(list <Drive>* plistDrives)
* \param pointer of vector <Drive>* pvecDrives * \param pointer of vector <Drive>* pvecDrives
* \return void * \return void
*/ */
void reHDD::addSMARTData(list <Drive>* plistDrives) void reHDD::addSMARTData(vector <Drive>* pvecDrives)
{ {
list <Drive>::iterator it; vector <Drive>::iterator it;
for (it = plistDrives->begin(); it != plistDrives->end(); ++it) for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{ {
Drive* pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator > (it); Drive* pTmpDrive = iterator_to_pointer<Drive, std::vector<Drive>::iterator > (it);
SMART::readSMARTData(pTmpDrive); SMART::readSMARTData(pTmpDrive);
} }
} }
void reHDD::handleArrowKey(TUI::UserInput userInput) void reHDD::handleArrowKey(TUI::UserInput userInput)
{ {
int8_t u8EntrySize = (int8_t) listDrives.size(); int8_t u8EntrySize = (int8_t) vecDrives.size();
switch (userInput) switch (userInput)
{ {
case TUI::UserInput::DownKey: case TUI::UserInput::DownKey:
@ -499,7 +487,10 @@ void reHDD::handleEnter()
Logger::logThis()->info("Started delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); Logger::logThis()->info("Started delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
getSelectedDrive()->state = Drive::TaskState::DELETE_ACTIVE; getSelectedDrive()->state = Drive::TaskState::DELETE_ACTIVE;
//task for drive is running --> don´t show more task options //task for drive is running --> don´t show more task options
thread(ThreadDelete).detach(); Delete::deleteDrive(getSelectedDrive()); //blocking, no thread
getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished
getSelectedDrive()->bWasDeleteted = true;
Logger::logThis()->info("Finished delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
} }
} }
} }

View File

@ -50,28 +50,27 @@ void TUI::initTUI()
Logger::logThis()->info("UI successfully initialized"); Logger::logThis()->info("UI successfully initialized");
} }
void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry) void TUI::updateTUI(vector <Drive>* pvecDrives, uint8_t u8SelectedEntry)
{ {
mxUIrefresh.lock(); mxUIrefresh.lock();
uint16_t u16StdscrX, u16StdscrY; int stdscrX, stdscrY;
getmaxyx(stdscr, u16StdscrY, u16StdscrX); getmaxyx(stdscr, stdscrY, stdscrX);
init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE); init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE);
wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR)); wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR));
refresh(); refresh();
overview=createOverViewWindow((int)(u16StdscrX/3), (u16StdscrY-3)); overview=createOverViewWindow((int)(stdscrX/3), (stdscrY-15));
wrefresh(overview); wrefresh(overview);
systemview=createSystemStats((int)(u16StdscrX/3), 10, u16StdscrX-(int)(u16StdscrX/3)-2, (u16StdscrY-11 )); systemview=createSystemStats((int)(stdscrX/3), 10, (stdscrY-11));
wrefresh(systemview); wrefresh(systemview);
delwin(detailview); delwin(detailview);
list <Drive>::iterator it; vector <Drive>::iterator it;
uint8_t u8Index = 0U; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{ {
string sModelFamily = it->getModelFamily(); string sModelFamily = it->getModelFamily();
string sModelName = it->getModelName(); string sModelName = it->getModelName();
@ -80,17 +79,10 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
bool bSelectedEntry = false; bool bSelectedEntry = false;
if(u8SelectedEntry == u8Index) if(u8SelectedEntry == (it - pvecDrives->begin()))
{ {
bSelectedEntry = true; //mark this drive in entries list bSelectedEntry = true; //mark this drive in entries list
displaySelectedDrive(*it, u16StdscrX, u16StdscrY); displaySelectedDrive(pvecDrives->at(u8SelectedEntry), stdscrX, stdscrY);
if((it->getPowerOnHours() >= WORSE_HOURS) || (it->getPowerCycles() >= WORSE_POWERUP) || (it->getErrorCount() > 0))
{
// smart values are bad --> show warning
smartWarning=createSmartWarning(50, 10, ((u16StdscrX)-(int)(u16StdscrX/2)+35),(int)(u16StdscrY/2)-5, it->getPath(), it->getPowerOnHours(), it->getPowerCycles(), it->getErrorCount());
wrefresh(smartWarning);
}
} }
stringstream stream; stringstream stream;
@ -120,26 +112,18 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
} }
break; break;
case Drive::FROZEN: case Drive::FROZEN:
stream << fixed << setprecision(2) << (it->getTaskPercentage()); dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial());
#ifdef FROZEN_ALERT
if(bSelectedEntry)
{
dialog=createFrozenWarning(70, 16, ((u16StdscrX)-(int)(u16StdscrX/2)-20),(int)(u16StdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%");
wrefresh(dialog); wrefresh(dialog);
}
#endif
sState = "FROZEN " + stream.str() + "%"; //mark drive as frozen and reached progress
break; break;
default: default:
break; break;
} }
WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry); WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry);
wrefresh(tmp); wrefresh(tmp);
u8Index++;
}//end loop though drives }//end loop though drives
if(plistDrives->size() == 0) if(pvecDrives->size() == 0)
{ {
//no selected drive present //no selected drive present
Logger::logThis()->warning("no selected drive present"); Logger::logThis()->warning("no selected drive present");
@ -150,10 +134,10 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
menustate.bDelete = false; menustate.bDelete = false;
menustate.bShred = false; menustate.bShred = false;
menuview=createMenuView(((int)(u16StdscrX/3)-10 ), 10, (int)(u16StdscrX/3)+5,(u16StdscrY-11), menustate); menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate);
wrefresh(menuview); wrefresh(menuview);
detailview=overwriteDetailViewWindow(((u16StdscrX)-(int)(u16StdscrX/3)-7), (u16StdscrY-15), (int)(u16StdscrX/3)+5); detailview=overwriteDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5);
wrefresh(detailview); wrefresh(detailview);
} }
@ -248,9 +232,38 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive
attroff(COLOR_PAIR(COLOR_AREA_DETAIL)); attroff(COLOR_PAIR(COLOR_AREA_DETAIL));
if(drive.getPowerOnHours() >= WORSE_HOURS)
{
mvwaddstr(newWindow,u16Line++, 3, "------------> WARNING: OPERATING HOURS <-----------");
mvwaddstr(newWindow,u16Line++, 3, sPowerOnHours.c_str()); mvwaddstr(newWindow,u16Line++, 3, sPowerOnHours.c_str());
mvwaddstr(newWindow,u16Line++, 3, "---------------------------------------------------");
}
else
{
mvwaddstr(newWindow,u16Line++, 3, sPowerOnHours.c_str());
}
if(drive.getPowerCycles() >= WORSE_POWERUP)
{
mvwaddstr(newWindow,u16Line++, 3, "------------> WARNING: POWER-ON <------------------");
mvwaddstr(newWindow,u16Line++, 3, sPowerCycle.c_str()); mvwaddstr(newWindow,u16Line++, 3, sPowerCycle.c_str());
mvwaddstr(newWindow,u16Line++, 3, "---------------------------------------------------");
}
else
{
mvwaddstr(newWindow,u16Line++, 3, sPowerCycle.c_str());
}
if(drive.getErrorCount() > 0)
{
mvwaddstr(newWindow,u16Line++, 3, "------------> WARNING: S.M.A.R.T ERROR <-----------");
mvwaddstr(newWindow,u16Line++, 3, sErrorCount.c_str()); mvwaddstr(newWindow,u16Line++, 3, sErrorCount.c_str());
mvwaddstr(newWindow,u16Line++, 3, "---------------------------------------------------");
}
else
{
mvwaddstr(newWindow,u16Line++, 3, sErrorCount.c_str());
}
return newWindow; return newWindow;
} }
@ -317,10 +330,10 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,
return newWindow; return newWindow;
} }
WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart) WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iYStart)
{ {
WINDOW *newWindow; WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, iYStart, iXStart); newWindow = newwin(iYSize, iXSize, iYStart, 2);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW)); wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
box(newWindow, ACS_VLINE, ACS_HLINE); box(newWindow, ACS_VLINE, ACS_HLINE);
@ -335,19 +348,7 @@ WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart)
strftime(buffer,sizeof(buffer),"Date: %d-%m-%Y Time: %H:%M",timeinfo); strftime(buffer,sizeof(buffer),"Date: %d-%m-%Y Time: %H:%M",timeinfo);
string time(buffer); string time(buffer);
string sLine01 = "reHDD - hard drive refurbishing tool"; mvwaddstr(newWindow,2, 2, time.c_str());
string sLine02 = "Version: " + string(REHDD_VERSION);
string sLine03 = "Available under GPL 3.0";
string sLine04 = "https://git.mosad.xyz/localhorst/reHDD";
uint16_t u16Line = 2;
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine01.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine02.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine03.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine04.c_str());
u16Line++;
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), time.c_str());
return newWindow; return newWindow;
} }
@ -362,24 +363,20 @@ WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st
centerTitle(newWindow, "Controls"); centerTitle(newWindow, "Controls");
uint16_t u16Line = 2; uint16_t u16Line = 2;
if(menustate.bAbort) if(menustate.bAbort)
{ {
string sLineTmp = "Press A for Abort"; mvwaddstr(newWindow,u16Line++, 3, "Press A for Abort");
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
u16Line++;
} }
if(menustate.bShred) if(menustate.bShred)
{ {
string sLineTmp = "Press S for Shred "; mvwaddstr(newWindow,u16Line++, 3, "Press S for Shred");
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
u16Line++;
} }
if(menustate.bDelete) if(menustate.bDelete)
{ {
string sLineTmp = "Press D for Delete"; mvwaddstr(newWindow,u16Line++, 3, "Press D for Delete");
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
} }
return newWindow; return newWindow;
@ -395,15 +392,14 @@ WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, stri
centerTitle(newWindow, task.c_str()); centerTitle(newWindow, task.c_str());
uint16_t u16Line = 3; uint16_t u16Line = 2;
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(optionA.size()/2), optionA.c_str()); mvwaddstr(newWindow,u16Line++, 3, optionA.c_str());
u16Line++; mvwaddstr(newWindow,u16Line++, 3, optionB.c_str());
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(optionB.size()/2), optionB.c_str());
return newWindow; return newWindow;
} }
WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress) WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial)
{ {
WINDOW *newWindow; WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, iYStart, iXStart); newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
@ -413,7 +409,6 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar
string sHeader = "Drive " + sPath + " is frozen"; string sHeader = "Drive " + sPath + " is frozen";
string sLine01 = "Please detach this drive and check it manually:"; string sLine01 = "Please detach this drive and check it manually:";
string sShredState = "Shredding stopped after " + sProgress;
string sLinePath = "Path: " +sPath; string sLinePath = "Path: " +sPath;
string sLineModelFamlily = "ModelFamily: " + sModelFamily; string sLineModelFamlily = "ModelFamily: " + sModelFamily;
string sLineModelName = "ModelName: " + sModelName; string sLineModelName = "ModelName: " + sModelName;
@ -434,7 +429,6 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar
u16Line++; u16Line++;
mvwaddstr(newWindow,u16Line++, 3, sLine02.c_str()); mvwaddstr(newWindow,u16Line++, 3, sLine02.c_str());
mvwaddstr(newWindow,u16Line++, 3, sLine03.c_str()); mvwaddstr(newWindow,u16Line++, 3, sLine03.c_str());
mvwaddstr(newWindow,u16Line++, 3, sShredState.c_str());
return newWindow; return newWindow;
} }
@ -477,17 +471,17 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5, drive); detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5, drive);
wrefresh(detailview); wrefresh(detailview);
menuview=createMenuView(((int)(stdscrX/3)-10 ), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate); menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate);
wrefresh(menuview); wrefresh(menuview);
if(menustate.bConfirmShred == true) if(menustate.bConfirmShred == true)
{ {
dialog=createDialog(40, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm SHRED", "Press ENTER for SHRED", "Press ESC for cancel"); dialog=createDialog(70, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm SHRED", "Press ENTER for SHRED", "Press ESC for cancel");
wrefresh(dialog); wrefresh(dialog);
} }
else if(menustate.bConfirmDelete == true) else if(menustate.bConfirmDelete == true)
{ {
dialog=createDialog(40, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm DELETE", "Press ENTER for DELETE", "Press ESC for cancel"); dialog=createDialog(70, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm DELETE", "Press ENTER for DELETE", "Press ESC for cancel");
wrefresh(dialog); wrefresh(dialog);
} }
else else
@ -495,42 +489,3 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
delwin(dialog); delwin(dialog);
} }
} }
WINDOW* TUI::createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY_SELECTED));
box(newWindow, ACS_VLINE, ACS_HLINE);
string sHeader = "Drive " + sPath + " is suspicious";
string sLine01 = "Please evaluate this drive carefully.";
centerTitle(newWindow, sHeader.c_str());
uint16_t u16Line = 2;
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLine01.c_str());
u16Line++;
if(u32PowerOnHours > WORSE_HOURS)
{
string sLineTmp = "Operating hours exceeded " + to_string(WORSE_HOURS) + " hours: " + to_string(u32PowerOnHours);
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str());
u16Line++;
}
if(u32PowerCycles > WORSE_POWERUP)
{
string sLineTmp = "Power-on exceeded " + to_string(WORSE_POWERUP) + " cycles: " + to_string(u32PowerCycles);
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str());
u16Line++;
}
if(u32ErrorCount > 0)
{
string sLineTmp = "S.M.A.R.T. erros detected: " + to_string(u32ErrorCount);
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str());
}
return newWindow;
}