Compare commits
7 Commits
b0.2.2
...
45dac1a4a7
Author | SHA1 | Date | |
---|---|---|---|
45dac1a4a7 | |||
e7a1cb1887 | |||
42668e54d2 | |||
9863c5591e | |||
c61859ed4e | |||
8de45505e4 | |||
f8ba9c6732 |
@ -22,6 +22,13 @@ public:
|
||||
FROZEN
|
||||
} state;
|
||||
|
||||
struct
|
||||
{
|
||||
time_t u32ShredTimeDelta;
|
||||
std::chrono::time_point<std::chrono::system_clock> chronoShredTimestamp;
|
||||
unsigned long ulWrittenBytes;
|
||||
} sShredSpeed;
|
||||
|
||||
bool bWasShredded = false;
|
||||
bool bWasDeleteted = false;
|
||||
bool bIsOffline = false;
|
||||
|
@ -13,7 +13,7 @@
|
||||
// Drive handling Settings
|
||||
#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 SHRED_ITERATIONS 3U
|
||||
#define SHRED_ITERATIONS 1U
|
||||
#define FROZEN_TIMEOUT 10 //After this timeout (minutes) the drive will be marked as frozen
|
||||
|
||||
// Logger Settings
|
||||
|
@ -56,7 +56,7 @@ private:
|
||||
static WINDOW *createOverViewWindow( int iXSize, int iYSize);
|
||||
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive);
|
||||
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, string sTime, bool bSelected);
|
||||
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected);
|
||||
static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart);
|
||||
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);
|
||||
@ -66,6 +66,7 @@ private:
|
||||
|
||||
void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY);
|
||||
string formatTimeDuration(time_t u32Duration);
|
||||
string formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes);
|
||||
|
||||
};
|
||||
#endif // TUI_H_
|
6
makefile
6
makefile
@ -1,6 +1,6 @@
|
||||
#### PROJECT SETTINGS ####
|
||||
# The name of the executable to be created
|
||||
BIN_NAME := reHDD
|
||||
BIN_NAME := shredTest
|
||||
# Compiler used
|
||||
CXX ?= g++
|
||||
# Extension of source files used in the project
|
||||
@ -12,7 +12,7 @@ LIBS =
|
||||
# General compiler flags
|
||||
COMPILE_FLAGS = -std=c++17 -Wall -Wextra -g
|
||||
# Additional release-specific flags
|
||||
RCOMPILE_FLAGS = -D NDEBUG
|
||||
RCOMPILE_FLAGS = -D NDEBUG -O3
|
||||
# Additional debug-specific flags
|
||||
DCOMPILE_FLAGS = -D DEBUG
|
||||
# Add additional include paths
|
||||
@ -51,7 +51,7 @@ ifeq ($(V),true)
|
||||
endif
|
||||
|
||||
# Combine compiler and linker flags
|
||||
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS)
|
||||
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS)
|
||||
release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS)
|
||||
debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS)
|
||||
debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS)
|
||||
|
1
reHDDShred
Symbolic link
1
reHDDShred
Symbolic link
@ -0,0 +1 @@
|
||||
bin/release/reHDDShred
|
1108
reHDD_memset.log
Normal file
1108
reHDD_memset.log
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,15 +2,17 @@
|
||||
|
||||
echo starting update
|
||||
|
||||
systemctl stop /lib/systemd/system/getty@tty1.service.d
|
||||
|
||||
cd /root/reHDD/
|
||||
|
||||
FILE=./ignoreDrives.conf
|
||||
if test -f "$FILE"; then
|
||||
echo backup exits
|
||||
else
|
||||
cp reHDD/ignoreDrives.conf ./ignoreDrives.conf
|
||||
cp /root/reHDD/ignoreDrives.conf /root/ignoreDrives.conf
|
||||
fi
|
||||
|
||||
cd reHDD
|
||||
|
||||
git reset
|
||||
|
||||
git stash force
|
||||
@ -23,4 +25,6 @@ git pull
|
||||
|
||||
make release
|
||||
|
||||
cp ../ignoreDrives.conf ./
|
||||
cp /root/ignoreDrives.conf /root/reHDD/ignoreDrives.conf
|
||||
|
||||
systemctl start /lib/systemd/system/getty@tty1.service.d
|
463
src/reHDD.cpp
463
src/reHDD.cpp
@ -11,13 +11,7 @@ static int fdNewDrivesInformPipe[2];//File descriptor for pipe that informs if n
|
||||
|
||||
static int fdShredInformPipe[2];//File descriptor for pipe that informs if a wipe thread signals
|
||||
|
||||
static std::mutex mxScannDrives;
|
||||
|
||||
list <Drive> listNewDrives; //store found drives that are updated every 5sec
|
||||
|
||||
static list <Drive> listDrives; //stores all drive data from scann thread
|
||||
|
||||
TUI *ui;
|
||||
static Drive* pDummyDrive;
|
||||
|
||||
static uint8_t u8SelectedEntry;
|
||||
|
||||
@ -40,15 +34,15 @@ reHDD::reHDD(void)
|
||||
*/
|
||||
void reHDD::app_logic(void)
|
||||
{
|
||||
ui = new TUI();
|
||||
ui->initTUI();
|
||||
pDummyDrive = new Drive("/dev/sdc");
|
||||
pDummyDrive->state = Drive::NONE;
|
||||
pDummyDrive->bIsOffline = false;
|
||||
|
||||
pipe(fdNewDrivesInformPipe);
|
||||
pipe(fdShredInformPipe);
|
||||
|
||||
thread thDevices(ThreadScannDevices); //start thread that scanns for drives
|
||||
thread thUserInput(ThreadUserInput); //start thread that reads user input
|
||||
thread thCheckFrozenDrives(ThreadCheckFrozenDrives); //start thread that checks timeout for drives
|
||||
getSelectedDrive()->state = Drive::TaskState::SHRED_ACTIVE;
|
||||
thread(ThreadShred).detach();
|
||||
|
||||
while(1)
|
||||
{
|
||||
@ -58,457 +52,40 @@ void reHDD::app_logic(void)
|
||||
|
||||
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
|
||||
|
||||
if(FD_ISSET(fdNewDrivesInformPipe[0], &selectSet))
|
||||
{
|
||||
mxScannDrives.lock();
|
||||
char dummy;
|
||||
read (fdNewDrivesInformPipe[0],&dummy,1);
|
||||
filterNewDrives(&listDrives, &listNewDrives); //filter and copy to app logic vector
|
||||
printDrives(&listDrives);
|
||||
mxScannDrives.unlock();
|
||||
}
|
||||
if(FD_ISSET(fdShredInformPipe[0], &selectSet))
|
||||
{
|
||||
char dummy;
|
||||
read (fdShredInformPipe[0],&dummy,1);
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("got progress signal from a shred task");
|
||||
#endif
|
||||
|
||||
stringstream stream;
|
||||
stream << fixed << setprecision(3) << (getSelectedDrive()->getTaskPercentage());
|
||||
string sState = "Shredding: " + stream.str() + "%";
|
||||
|
||||
std::ostringstream out;
|
||||
double dDeltaSec = ((double)((getSelectedDrive()->sShredSpeed.u32ShredTimeDelta)/1000000000.0)); //convert nano in sec
|
||||
double speed = ((getSelectedDrive()->sShredSpeed.ulWrittenBytes/1000000.0)/dDeltaSec);
|
||||
char s[25];
|
||||
sprintf(s, "%0.2lf MB/s", speed);
|
||||
out << s;
|
||||
Logger::logThis()->info(sState + " - " + out.str());
|
||||
}
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
} //endless loop
|
||||
thDevices.join();
|
||||
thUserInput.join();
|
||||
thCheckFrozenDrives.join();
|
||||
}
|
||||
|
||||
Drive* reHDD::getSelectedDrive()
|
||||
{
|
||||
if(u8SelectedEntry < listDrives.size() )
|
||||
{
|
||||
list<Drive>::iterator it = listDrives.begin();
|
||||
advance(it, u8SelectedEntry);
|
||||
return &(*it);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::logThis()->warning("selected drive not present");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void reHDD::ThreadScannDevices()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
mxScannDrives.lock();
|
||||
listNewDrives.clear();
|
||||
searchDrives(&listNewDrives); //search for new drives and store them in list
|
||||
filterIgnoredDrives(&listNewDrives); //filter out ignored drives
|
||||
addSMARTData(&listNewDrives); //add S.M.A.R.T. Data to the drives
|
||||
mxScannDrives.unlock();
|
||||
write(fdNewDrivesInformPipe[1], "A",1);
|
||||
sleep(5); //sleep 5 sec
|
||||
}
|
||||
}
|
||||
|
||||
void reHDD::ThreadCheckFrozenDrives()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
mxScannDrives.lock();
|
||||
for(auto it = begin(listDrives); it != end(listDrives); ++it)
|
||||
{
|
||||
if(it->state == Drive::SHRED_ACTIVE)
|
||||
{
|
||||
it->checkFrozenDrive();
|
||||
}
|
||||
}
|
||||
mxScannDrives.unlock();
|
||||
sleep(13); //sleep 13 sec
|
||||
}
|
||||
}
|
||||
|
||||
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(&listDrives, u8SelectedEntry);
|
||||
break;
|
||||
case TUI::UserInput::UpKey:
|
||||
//cout << "Up" << endl;
|
||||
handleArrowKey(TUI::UserInput::UpKey);
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
break;
|
||||
case TUI::UserInput::Undefined:
|
||||
//cout << "Undefined" << endl;
|
||||
break;
|
||||
case TUI::UserInput::Abort:
|
||||
//cout << "Abort" << endl;
|
||||
handleAbort();
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
break;
|
||||
case TUI::UserInput::Delete:
|
||||
//cout << "Delete" << endl;
|
||||
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
if(getSelectedDrive()->state == Drive::NONE)
|
||||
{
|
||||
getSelectedDrive()->state = Drive::DELETE_SELECTED;
|
||||
}
|
||||
}
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
break;
|
||||
case TUI::UserInput::Shred:
|
||||
//cout << "Shred" << endl;
|
||||
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
if(getSelectedDrive()->state == Drive::NONE)
|
||||
{
|
||||
getSelectedDrive()->state = Drive::SHRED_SELECTED;
|
||||
}
|
||||
}
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
break;
|
||||
case TUI::UserInput::Enter:
|
||||
//cout << "Enter" << endl;
|
||||
handleEnter();
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
break;
|
||||
case TUI::UserInput::ESC:
|
||||
//cout << "ESC" << endl;
|
||||
handleESC();
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pDummyDrive;
|
||||
}
|
||||
|
||||
void reHDD::ThreadShred()
|
||||
{
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
Logger::logThis()->info("Starting Shred Thread");
|
||||
getSelectedDrive()->setActionStartTimestamp(); //save timestamp at start of shredding
|
||||
Shred* pShredTask = new Shred(); //create new shred task
|
||||
pShredTask->shredDrive(getSelectedDrive(), &fdShredInformPipe[1]); //start new shred task
|
||||
delete pShredTask; //delete shred task
|
||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||
}
|
||||
}
|
||||
|
||||
void reHDD::ThreadDelete()
|
||||
{
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
getSelectedDrive()->setActionStartTimestamp(); //save timestamp at start of deleting
|
||||
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
|
||||
for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end();)
|
||||
{
|
||||
if(itOld->bIsOffline == true)
|
||||
{
|
||||
Logger::logThis()->warning("Offline drive found: " + itOld->getPath());
|
||||
itOld = plistOldDrives->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
|
||||
u8SelectedEntry = 0U;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
++itOld;
|
||||
}
|
||||
}
|
||||
|
||||
//search offline drives and mark them
|
||||
for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end(); ++itOld)
|
||||
{
|
||||
itOld->bIsOffline = true; //set offline befor seachring in the new list
|
||||
for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end();)
|
||||
{
|
||||
if((itOld->getSerial() == itNew->getSerial()) || (itOld->getPath() == itNew->getPath()))
|
||||
{
|
||||
itOld->bIsOffline = false; //drive is still attached
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName());
|
||||
#endif
|
||||
itNew = plistNewDrives->erase(itNew); //This drive is allready attached, remove from new list
|
||||
}
|
||||
else
|
||||
{
|
||||
++itNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//mark offline old drives
|
||||
for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end(); ++itOld)
|
||||
{
|
||||
if(itOld->bIsOffline == true)
|
||||
{
|
||||
//cout << "offline drive found: " << itOld->getPath() << endl;
|
||||
Logger::logThis()->warning("Mark offline drive found: " + itOld->getPath());
|
||||
itOld->state = Drive::NONE; //clear state --> shred task will terminate
|
||||
}
|
||||
}
|
||||
|
||||
//add new drives to drive list
|
||||
for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end(); ++itNew)
|
||||
{
|
||||
plistOldDrives->push_back(*itNew);
|
||||
Logger::logThis()->info("Add new drive: " + itNew->getModelName());
|
||||
}
|
||||
plistNewDrives->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief search attached drives on /dev/sd*
|
||||
* \param pointer of list <Drive>* plistDrives
|
||||
* \return void
|
||||
*/
|
||||
void reHDD::searchDrives(list <Drive>* plistDrives)
|
||||
{
|
||||
Logger::logThis()->info("--> search drives <--");
|
||||
char * cLine = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
FILE* outputfileHwinfo = popen("lsblk -I 8 -d -o NAME", "r");
|
||||
|
||||
if (outputfileHwinfo == NULL)
|
||||
{
|
||||
Logger::logThis()->error("Unable to scan attached drives");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while ((getline(&cLine, &len, outputfileHwinfo)) != -1)
|
||||
{
|
||||
if (string(cLine).length() == 4)
|
||||
{
|
||||
Drive* tmpDrive = new Drive("/dev/" + string(cLine).substr(0, 3));
|
||||
tmpDrive->state = Drive::NONE;
|
||||
tmpDrive->bIsOffline = false;
|
||||
plistDrives->push_back(*tmpDrive);
|
||||
//Logger::logThis()->info("drive found: " + tmpDrive->getPath());
|
||||
}
|
||||
}
|
||||
pclose(outputfileHwinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief filter out drives that are listed in "ignoreDrives.conf"
|
||||
* \param pointer of list <Drive>* plistDrives
|
||||
* \return void
|
||||
*/
|
||||
void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
|
||||
{
|
||||
list<tuple<string>> vtlIgnoredDevices; //store drives from ingnore file
|
||||
ifstream input( "ignoreDrives.conf" ); //read ingnore file
|
||||
|
||||
for(string sLine; getline( input, sLine );)
|
||||
{
|
||||
Logger::logThis()->info("read uuid: " + sLine);
|
||||
vtlIgnoredDevices.emplace_back(sLine); //add found path and uuid from ignore file to vector
|
||||
}
|
||||
//loop through found entries in ingnore file
|
||||
for(auto row : vtlIgnoredDevices)
|
||||
{
|
||||
list <Drive>::iterator it;
|
||||
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
||||
{
|
||||
string sUUID;
|
||||
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(8, sBlkidOut.length());
|
||||
sUUID = sBlkidOut;
|
||||
//cout << "blkid uuid:" << sUUID << endl;
|
||||
}
|
||||
}
|
||||
pclose(outputfileBlkid);
|
||||
//cout << "blkid uuid:" << sUUID << endl;
|
||||
|
||||
if (!get<0>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
|
||||
{
|
||||
// same uuid found than in ignore file --> ignore this drive
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath());
|
||||
#endif
|
||||
it = plistDrives->erase(it);
|
||||
it--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief print drives with all information
|
||||
* \param pointer of list <Drive>* plistDrives
|
||||
* \return void
|
||||
*/
|
||||
void reHDD::printDrives(list <Drive>* plistDrives)
|
||||
{
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("------------DRIVES START------------");
|
||||
//cout << "------------DRIVES---------------" << endl;
|
||||
list <Drive>::iterator it;
|
||||
uint8_t u8Index = 0;
|
||||
for (it = plistDrives->begin(); it != plistDrives->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;*/
|
||||
|
||||
ostringstream address;
|
||||
address << (void const *)&(*it);
|
||||
Logger::logThis()->info(to_string(u8Index++) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str());
|
||||
}
|
||||
Logger::logThis()->info("------------DRIVES END--------------");
|
||||
//cout << "---------------------------------" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief add S.M.A.R.T data from SMART
|
||||
* \param pointer of list <Drive>* plistDrives
|
||||
* \return void
|
||||
*/
|
||||
void reHDD::addSMARTData(list <Drive>* plistDrives)
|
||||
{
|
||||
list <Drive>::iterator it;
|
||||
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
||||
{
|
||||
Drive* pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator > (it);
|
||||
SMART::readSMARTData(pTmpDrive);
|
||||
}
|
||||
}
|
||||
|
||||
void reHDD::handleArrowKey(TUI::UserInput userInput)
|
||||
{
|
||||
int8_t u8EntrySize = (int8_t) listDrives.size();
|
||||
switch (userInput)
|
||||
{
|
||||
case TUI::UserInput::DownKey:
|
||||
u8SelectedEntry++;
|
||||
if(u8SelectedEntry >= u8EntrySize)
|
||||
{
|
||||
u8SelectedEntry = 0;
|
||||
}
|
||||
break;
|
||||
case TUI::UserInput::UpKey:
|
||||
if(u8SelectedEntry == 0)
|
||||
{
|
||||
u8SelectedEntry = (u8EntrySize-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
u8SelectedEntry--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
u8SelectedEntry = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
Logger::logThis()->info("ArrowKey - selected drive: " + to_string(u8SelectedEntry));
|
||||
}
|
||||
|
||||
void reHDD::handleEnter()
|
||||
{
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
if(getSelectedDrive()->state == Drive::TaskState::SHRED_SELECTED)
|
||||
{
|
||||
Logger::logThis()->info("Started shred for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
||||
getSelectedDrive()->state = Drive::TaskState::SHRED_ACTIVE;
|
||||
//task for drive is running --> don´t show more task options
|
||||
thread(ThreadShred).detach();
|
||||
}
|
||||
|
||||
if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED)
|
||||
{
|
||||
Logger::logThis()->info("Started delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
||||
getSelectedDrive()->state = Drive::TaskState::DELETE_ACTIVE;
|
||||
//task for drive is running --> don´t show more task options
|
||||
thread(ThreadDelete).detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reHDD::handleESC()
|
||||
{
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
if(getSelectedDrive()->state == Drive::TaskState::SHRED_SELECTED)
|
||||
{
|
||||
getSelectedDrive()->state = Drive::TaskState::NONE;
|
||||
//task for drive is selected --> remove selection
|
||||
}
|
||||
|
||||
if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED)
|
||||
{
|
||||
getSelectedDrive()->state = Drive::TaskState::NONE;
|
||||
//task for drive is selected --> remove selection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reHDD::handleAbort()
|
||||
{
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
if(getSelectedDrive()->state == Drive::SHRED_ACTIVE || getSelectedDrive()->state == Drive::DELETE_ACTIVE )
|
||||
{
|
||||
getSelectedDrive()->state = Drive::NONE;
|
||||
Logger::logThis()->info("Abort-Shred-Signal for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
||||
//task for drive is running --> remove selection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -64,6 +64,8 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
||||
}
|
||||
|
||||
this->ulDriveByteSize = getDriveSizeInBytes(driveFileDiscr);
|
||||
drive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();; //set inital timestamp for speed metric
|
||||
unsigned long ulSpeedMetricBytesWritten = 0U; //uses to calculate speed metric
|
||||
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("Shred-Task: Bytes-Size of Drive: " + to_string(this->ulDriveByteSize) + " - Drive: " + drive->getSerial());
|
||||
@ -74,17 +76,19 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
||||
unsigned long ulDriveByteCounter = 0U; //used for one shred-iteration to keep track of the current drive position
|
||||
uint32_t u32ChunkDimensionIndex = 0U;
|
||||
|
||||
/*
|
||||
if(uiShredIterationCounter == (SHRED_ITERATIONS-1))
|
||||
{
|
||||
//last shred iteration --> overwrite with zeros instead with random data
|
||||
memset(caChunk, 0U, CHUNK_DIMENSION*CHUNK_SIZE);
|
||||
}
|
||||
*/
|
||||
|
||||
while (ulDriveByteCounter < ulDriveByteSize)
|
||||
{
|
||||
int iBytesToShred = 0; //Bytes that will be overwritten in this chunk-iteration
|
||||
|
||||
if((u32ChunkDimensionIndex == 0U) && (uiShredIterationCounter != (SHRED_ITERATIONS-1)))
|
||||
if((u32ChunkDimensionIndex == 0U))
|
||||
{
|
||||
//read new chunks from random source if needed and this is NOT the last shred iteration
|
||||
unsigned long ulBytesInChunkBuffer = 0U;
|
||||
@ -136,14 +140,25 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
||||
ulDriveByteCounter += iByteShredded;
|
||||
ulDriveByteOverallCount += iByteShredded;
|
||||
d32Percent = this->calcProgress();
|
||||
ulSpeedMetricBytesWritten += iByteShredded;
|
||||
|
||||
#ifdef LOG_LEVEL_HIGH
|
||||
Logger::logThis()->info("Shred-Task: ByteCount: " + to_string(ulDriveByteCounter) + " - iteration: " + to_string((uiShredIterationCounter+1)) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());
|
||||
#endif
|
||||
if((d32Percent-d32TmpPercent) >= 0.01)
|
||||
{
|
||||
//set shred percantage
|
||||
drive->setTaskPercentage(d32TmpPercent);
|
||||
d32TmpPercent = d32Percent;
|
||||
|
||||
//set metrics for calculating shred speed
|
||||
std::chrono::time_point<std::chrono::system_clock> chronoCurrentTimestamp = std::chrono::system_clock::now();
|
||||
drive->sShredSpeed.u32ShredTimeDelta = (chronoCurrentTimestamp - drive->sShredSpeed.chronoShredTimestamp).count();
|
||||
drive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();
|
||||
drive->sShredSpeed.ulWrittenBytes = ulSpeedMetricBytesWritten;
|
||||
ulSpeedMetricBytesWritten = 0U;
|
||||
|
||||
//signal process in shreding
|
||||
write(*ipSignalFd, "A",1);
|
||||
}
|
||||
|
||||
|
21
src/tui.cpp
21
src/tui.cpp
@ -77,9 +77,9 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
||||
string sModelName = it->getModelName();
|
||||
string sCapacity = it->sCapacityToText();
|
||||
string sState = " ";
|
||||
string sSpeed = " ";
|
||||
string sTime = " ";
|
||||
|
||||
|
||||
bool bSelectedEntry = false;
|
||||
|
||||
if(u8SelectedEntry == u8Index)
|
||||
@ -107,6 +107,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
||||
|
||||
it->calculateTaskDuration();
|
||||
sTime = this->formatTimeDuration(it->getTaskDuration());
|
||||
sSpeed = this->formatSpeed(it->sShredSpeed.u32ShredTimeDelta, it->sShredSpeed.ulWrittenBytes);
|
||||
break;
|
||||
case Drive::DELETE_ACTIVE:
|
||||
sState = "Deleting ...";
|
||||
@ -151,7 +152,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
||||
break;
|
||||
}
|
||||
|
||||
WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, sTime, bSelectedEntry);
|
||||
WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, sTime, sSpeed, bSelectedEntry);
|
||||
wrefresh(tmp);
|
||||
u8Index++;
|
||||
}//end loop though drives
|
||||
@ -305,7 +306,7 @@ WINDOW* TUI::overwriteDetailViewWindow( 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, string sState, string sTime, bool bSelected)
|
||||
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected)
|
||||
{
|
||||
WINDOW *newWindow;
|
||||
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
|
||||
@ -329,8 +330,9 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,
|
||||
mvwaddstr(newWindow,2, 1, sModelName.c_str());
|
||||
mvwaddstr(newWindow,3, 1, sCapacity.c_str());
|
||||
|
||||
mvwaddstr(newWindow,1, iXSize-sSpeed.length()-5, sSpeed.c_str());
|
||||
mvwaddstr(newWindow,2, iXSize-sState.length()-5, sState.c_str());
|
||||
mvwaddstr(newWindow,3, iXSize-sState.length()-5, sTime.c_str());
|
||||
mvwaddstr(newWindow,3, iXSize-sTime.length()-5, sTime.c_str());
|
||||
|
||||
return newWindow;
|
||||
}
|
||||
@ -506,6 +508,17 @@ string TUI::formatTimeDuration(time_t u32Duration)
|
||||
return out.str();
|
||||
}
|
||||
|
||||
string TUI::formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes)
|
||||
{
|
||||
std::ostringstream out;
|
||||
double dDeltaSec = ((double)((u32ShredTimeDelta)/1000000000.0)); //convert nano in sec
|
||||
double speed = ((ulWrittenBytes/1000000.0)/dDeltaSec);
|
||||
char s[25];
|
||||
sprintf(s, "%0.2lf MB/s", speed);
|
||||
out << s;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
|
||||
{
|
||||
struct MenuState menustate;
|
||||
|
Reference in New Issue
Block a user