added feature to start shredding for all drives
This commit is contained in:
parent
9863c5591e
commit
e3aefb24ee
|
@ -22,12 +22,13 @@ public:
|
||||||
FROZEN
|
FROZEN
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
time_t u32ShredTimeDelta;
|
time_t u32ShredTimeDelta;
|
||||||
std::chrono::time_point<std::chrono::system_clock> chronoShredTimestamp;
|
std::chrono::time_point<std::chrono::system_clock> chronoShredTimestamp;
|
||||||
unsigned long ulWrittenBytes;
|
unsigned long ulWrittenBytes;
|
||||||
} sShredSpeed;
|
} sShredSpeed;
|
||||||
|
|
||||||
bool bWasShredded = false;
|
bool bWasShredded = false;
|
||||||
bool bWasDeleteted = false;
|
bool bWasDeleteted = false;
|
||||||
bool bIsOffline = false;
|
bool bIsOffline = false;
|
||||||
|
|
|
@ -64,6 +64,8 @@ using namespace std;
|
||||||
#include "tui.h"
|
#include "tui.h"
|
||||||
#include "logger/logger.h"
|
#include "logger/logger.h"
|
||||||
|
|
||||||
|
#include "chunk.h"
|
||||||
|
|
||||||
extern Logger* logging;
|
extern Logger* logging;
|
||||||
|
|
||||||
template <typename T, typename I> T* iterator_to_pointer(I i)
|
template <typename T, typename I> T* iterator_to_pointer(I i)
|
||||||
|
@ -83,12 +85,13 @@ private:
|
||||||
|
|
||||||
static void searchDrives(list <Drive>* plistDrives);
|
static void searchDrives(list <Drive>* plistDrives);
|
||||||
static void printDrives(list <Drive>* plistDrives);
|
static void printDrives(list <Drive>* plistDrives);
|
||||||
static void filterIgnoredDrives(list <Drive>* plistDrives);
|
static void startShredAllDrives(list <Drive>* plistDrives);
|
||||||
|
static void filterIgnoredDrives(list <Drive>* plistDrives);
|
||||||
static void filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNewDrives);
|
static void filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNewDrives);
|
||||||
static void addSMARTData(list <Drive>* plistDrives);
|
static void addSMARTData(list <Drive>* plistDrives);
|
||||||
static void ThreadScannDevices();
|
static void ThreadScannDevices();
|
||||||
static void ThreadUserInput();
|
static void ThreadUserInput();
|
||||||
static void ThreadShred();
|
static void ThreadShred(Drive* const pDrive);
|
||||||
static void ThreadDelete();
|
static void ThreadDelete();
|
||||||
static void ThreadCheckFrozenDrives();
|
static void ThreadCheckFrozenDrives();
|
||||||
static void handleArrowKey(TUI::UserInput userInput);
|
static void handleArrowKey(TUI::UserInput userInput);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
//#define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB
|
//#define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB
|
||||||
//#define DEMO_DRIVE_SIZE 1024*1024*1024L // 1GB
|
//#define DEMO_DRIVE_SIZE 1024*1024*1024L // 1GB
|
||||||
//#define DEMO_DRIVE_SIZE 1024*1024*1024*10L // 10GB
|
#define DEMO_DRIVE_SIZE 1024*1024*1024*10L // 10GB
|
||||||
|
|
||||||
typedef int fileDescriptor;
|
typedef int fileDescriptor;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum UserInput { UpKey, DownKey, Abort, Shred, Delete, Enter, ESC, Undefined};
|
enum UserInput { UpKey, DownKey, Abort, Shred, ShredAll, Delete, Enter, ESC, Undefined};
|
||||||
struct MenuState
|
struct MenuState
|
||||||
{
|
{
|
||||||
bool bAbort;
|
bool bAbort;
|
||||||
|
|
|
@ -178,6 +178,11 @@ void reHDD::ThreadUserInput()
|
||||||
}
|
}
|
||||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||||
break;
|
break;
|
||||||
|
case TUI::UserInput::ShredAll:
|
||||||
|
cout << "ShredAll" << endl;
|
||||||
|
startShredAllDrives(&listDrives);
|
||||||
|
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||||
|
break;
|
||||||
case TUI::UserInput::Enter:
|
case TUI::UserInput::Enter:
|
||||||
//cout << "Enter" << endl;
|
//cout << "Enter" << endl;
|
||||||
handleEnter();
|
handleEnter();
|
||||||
|
@ -194,13 +199,13 @@ void reHDD::ThreadUserInput()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reHDD::ThreadShred()
|
void reHDD::ThreadShred(Drive* const pDrive)
|
||||||
{
|
{
|
||||||
if (getSelectedDrive() != nullptr)
|
if (pDrive != nullptr)
|
||||||
{
|
{
|
||||||
getSelectedDrive()->setActionStartTimestamp(); //save timestamp at start of shredding
|
pDrive->setActionStartTimestamp(); //save timestamp at start of shredding
|
||||||
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(pDrive, &fdShredInformPipe[1]); //start new shred task
|
||||||
delete pShredTask; //delete shred task
|
delete pShredTask; //delete shred task
|
||||||
ui->updateTUI(&listDrives, u8SelectedEntry);
|
ui->updateTUI(&listDrives, u8SelectedEntry);
|
||||||
}
|
}
|
||||||
|
@ -279,7 +284,7 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
|
||||||
for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end(); ++itNew)
|
for (itNew = plistNewDrives->begin(); itNew != plistNewDrives->end(); ++itNew)
|
||||||
{
|
{
|
||||||
plistOldDrives->push_back(*itNew);
|
plistOldDrives->push_back(*itNew);
|
||||||
Logger::logThis()->info("Add new drive: " + itNew->getModelName());
|
//Logger::logThis()->info("Add new drive: " + itNew->getModelName());
|
||||||
}
|
}
|
||||||
plistNewDrives->clear();
|
plistNewDrives->clear();
|
||||||
}
|
}
|
||||||
|
@ -291,7 +296,7 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
|
||||||
*/
|
*/
|
||||||
void reHDD::searchDrives(list <Drive>* plistDrives)
|
void reHDD::searchDrives(list <Drive>* plistDrives)
|
||||||
{
|
{
|
||||||
Logger::logThis()->info("--> search drives <--");
|
//Logger::logThis()->info("--> search drives <--");
|
||||||
char * cLine = NULL;
|
char * cLine = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
|
@ -329,7 +334,7 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
|
||||||
|
|
||||||
for(string sLine; getline( input, sLine );)
|
for(string sLine; getline( input, sLine );)
|
||||||
{
|
{
|
||||||
Logger::logThis()->info("read uuid: " + sLine);
|
//Logger::logThis()->info("read uuid: " + sLine);
|
||||||
vtlIgnoredDevices.emplace_back(sLine); //add found path and uuid from ignore file to vector
|
vtlIgnoredDevices.emplace_back(sLine); //add found path and uuid from ignore file to vector
|
||||||
}
|
}
|
||||||
//loop through found entries in ingnore file
|
//loop through found entries in ingnore file
|
||||||
|
@ -377,6 +382,26 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief start shred for all drives
|
||||||
|
* \param pointer of list <Drive>* plistDrives
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
|
void reHDD::startShredAllDrives(list <Drive>* plistDrives)
|
||||||
|
{
|
||||||
|
list <Drive>::iterator it;
|
||||||
|
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
||||||
|
{
|
||||||
|
if(it->state == Drive::NONE)
|
||||||
|
{
|
||||||
|
it->state = Drive::SHRED_ACTIVE;
|
||||||
|
Logger::logThis()->info("all start: " + it->getSerial());
|
||||||
|
Drive* pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator > (it);
|
||||||
|
thread(ThreadShred, std::ref(pTmpDrive)).detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief print drives with all information
|
* \brief print drives with all information
|
||||||
* \param pointer of list <Drive>* plistDrives
|
* \param pointer of list <Drive>* plistDrives
|
||||||
|
@ -454,7 +479,7 @@ void reHDD::handleArrowKey(TUI::UserInput userInput)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::logThis()->info("ArrowKey - selected drive: " + to_string(u8SelectedEntry));
|
//Logger::logThis()->info("ArrowKey - selected drive: " + to_string(u8SelectedEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
void reHDD::handleEnter()
|
void reHDD::handleEnter()
|
||||||
|
@ -466,7 +491,8 @@ void reHDD::handleEnter()
|
||||||
Logger::logThis()->info("Started shred for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
Logger::logThis()->info("Started shred for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
||||||
getSelectedDrive()->state = Drive::TaskState::SHRED_ACTIVE;
|
getSelectedDrive()->state = Drive::TaskState::SHRED_ACTIVE;
|
||||||
//task for drive is running --> don´t show more task options
|
//task for drive is running --> don´t show more task options
|
||||||
thread(ThreadShred).detach();
|
Drive* pTmpDrive = getSelectedDrive();
|
||||||
|
thread(ThreadShred, std::ref(pTmpDrive)).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED)
|
if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED)
|
||||||
|
|
|
@ -26,6 +26,7 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef DRYRUN
|
#ifdef DRYRUN
|
||||||
|
Logger::logThis()->info("Shred-Task started - Drive: " + drive->getSerial());
|
||||||
for(int i = 0; i<=500; i++)
|
for(int i = 0; i<=500; i++)
|
||||||
{
|
{
|
||||||
if(drive->state != Drive::SHRED_ACTIVE)
|
if(drive->state != Drive::SHRED_ACTIVE)
|
||||||
|
@ -75,7 +76,7 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
||||||
{
|
{
|
||||||
unsigned long ulDriveByteCounter = 0U; //used for one shred-iteration to keep track of the current drive position
|
unsigned long ulDriveByteCounter = 0U; //used for one shred-iteration to keep track of the current drive position
|
||||||
uint32_t u32ChunkDimensionIndex = 0U;
|
uint32_t u32ChunkDimensionIndex = 0U;
|
||||||
|
|
||||||
|
|
||||||
if(uiShredIterationCounter == (SHRED_ITERATIONS-1))
|
if(uiShredIterationCounter == (SHRED_ITERATIONS-1))
|
||||||
{
|
{
|
||||||
|
|
13
src/tui.cpp
13
src/tui.cpp
|
@ -97,7 +97,6 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
||||||
|
|
||||||
stringstream stream;
|
stringstream stream;
|
||||||
|
|
||||||
|
|
||||||
switch (it->state)
|
switch (it->state)
|
||||||
{
|
{
|
||||||
case Drive::SHRED_ACTIVE:
|
case Drive::SHRED_ACTIVE:
|
||||||
|
@ -204,6 +203,9 @@ enum TUI::UserInput TUI::readUserInput()
|
||||||
case 's':
|
case 's':
|
||||||
return TUI::UserInput::Shred;
|
return TUI::UserInput::Shred;
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
return TUI::UserInput::ShredAll;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return TUI::UserInput::Undefined;
|
return TUI::UserInput::Undefined;
|
||||||
break;
|
break;
|
||||||
|
@ -386,19 +388,19 @@ WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st
|
||||||
|
|
||||||
if(menustate.bAbort)
|
if(menustate.bAbort)
|
||||||
{
|
{
|
||||||
string sLineTmp = "Press A for Abort";
|
string sLineTmp = "Press a for Abort";
|
||||||
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
|
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
|
||||||
u16Line++;
|
u16Line++;
|
||||||
}
|
}
|
||||||
if(menustate.bShred)
|
if(menustate.bShred)
|
||||||
{
|
{
|
||||||
string sLineTmp = "Press S for Shred ";
|
string sLineTmp = "Press s for Shred (S for all drives)";
|
||||||
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
|
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
|
||||||
u16Line++;
|
u16Line++;
|
||||||
}
|
}
|
||||||
if(menustate.bDelete)
|
if(menustate.bDelete)
|
||||||
{
|
{
|
||||||
string sLineTmp = "Press D for Delete";
|
string sLineTmp = "Press d for Delete";
|
||||||
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
|
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLineTmp.size()/2), sLineTmp.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +510,8 @@ string TUI::formatTimeDuration(time_t u32Duration)
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
string TUI::formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes){
|
string TUI::formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes)
|
||||||
|
{
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
double dDeltaSec = ((double)((u32ShredTimeDelta)/1000000000.0)); //convert nano in sec
|
double dDeltaSec = ((double)((u32ShredTimeDelta)/1000000000.0)); //convert nano in sec
|
||||||
double speed = ((ulWrittenBytes/1000000.0)/dDeltaSec);
|
double speed = ((ulWrittenBytes/1000000.0)/dDeltaSec);
|
||||||
|
|
Loading…
Reference in New Issue