added feature to start shredding for all drives

This commit is contained in:
Hendrik Schutter 2022-08-20 16:09:40 +02:00
parent 9863c5591e
commit e3aefb24ee
7 changed files with 55 additions and 21 deletions

View File

@ -22,12 +22,13 @@ public:
FROZEN
} state;
struct {
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;

View File

@ -64,6 +64,8 @@ using namespace std;
#include "tui.h"
#include "logger/logger.h"
#include "chunk.h"
extern Logger* logging;
template <typename T, typename I> T* iterator_to_pointer(I i)
@ -83,12 +85,13 @@ private:
static void searchDrives(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 addSMARTData(list <Drive>* plistDrives);
static void ThreadScannDevices();
static void ThreadUserInput();
static void ThreadShred();
static void ThreadShred(Drive* const pDrive);
static void ThreadDelete();
static void ThreadCheckFrozenDrives();
static void handleArrowKey(TUI::UserInput userInput);

View File

@ -22,7 +22,7 @@
//#define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB
//#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;

View File

@ -22,7 +22,7 @@ protected:
public:
enum UserInput { UpKey, DownKey, Abort, Shred, Delete, Enter, ESC, Undefined};
enum UserInput { UpKey, DownKey, Abort, Shred, ShredAll, Delete, Enter, ESC, Undefined};
struct MenuState
{
bool bAbort;

View File

@ -178,6 +178,11 @@ void reHDD::ThreadUserInput()
}
ui->updateTUI(&listDrives, u8SelectedEntry);
break;
case TUI::UserInput::ShredAll:
cout << "ShredAll" << endl;
startShredAllDrives(&listDrives);
ui->updateTUI(&listDrives, u8SelectedEntry);
break;
case TUI::UserInput::Enter:
//cout << "Enter" << endl;
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
pShredTask->shredDrive(getSelectedDrive(), &fdShredInformPipe[1]); //start new shred task
pShredTask->shredDrive(pDrive, &fdShredInformPipe[1]); //start new shred task
delete pShredTask; //delete shred task
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)
{
plistOldDrives->push_back(*itNew);
Logger::logThis()->info("Add new drive: " + itNew->getModelName());
//Logger::logThis()->info("Add new drive: " + itNew->getModelName());
}
plistNewDrives->clear();
}
@ -291,7 +296,7 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
*/
void reHDD::searchDrives(list <Drive>* plistDrives)
{
Logger::logThis()->info("--> search drives <--");
//Logger::logThis()->info("--> search drives <--");
char * cLine = NULL;
size_t len = 0;
@ -329,7 +334,7 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
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
}
//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
* \param pointer of list <Drive>* plistDrives
@ -454,7 +479,7 @@ void reHDD::handleArrowKey(TUI::UserInput userInput)
break;
}
Logger::logThis()->info("ArrowKey - selected drive: " + to_string(u8SelectedEntry));
//Logger::logThis()->info("ArrowKey - selected drive: " + to_string(u8SelectedEntry));
}
void reHDD::handleEnter()
@ -466,7 +491,8 @@ void reHDD::handleEnter()
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();
Drive* pTmpDrive = getSelectedDrive();
thread(ThreadShred, std::ref(pTmpDrive)).detach();
}
if(getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED)

View File

@ -26,6 +26,7 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
{
#ifdef DRYRUN
Logger::logThis()->info("Shred-Task started - Drive: " + drive->getSerial());
for(int i = 0; i<=500; i++)
{
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
uint32_t u32ChunkDimensionIndex = 0U;
if(uiShredIterationCounter == (SHRED_ITERATIONS-1))
{

View File

@ -97,7 +97,6 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
stringstream stream;
switch (it->state)
{
case Drive::SHRED_ACTIVE:
@ -204,6 +203,9 @@ enum TUI::UserInput TUI::readUserInput()
case 's':
return TUI::UserInput::Shred;
break;
case 'S':
return TUI::UserInput::ShredAll;
break;
default:
return TUI::UserInput::Undefined;
break;
@ -386,19 +388,19 @@ WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st
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());
u16Line++;
}
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());
u16Line++;
}
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());
}
@ -508,7 +510,8 @@ string TUI::formatTimeDuration(time_t u32Duration)
return out.str();
}
string TUI::formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes){
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);