completed logger usage and changed shred task to non-static
This commit is contained in:
parent
730b1205f7
commit
938f267813
@ -8,7 +8,7 @@
|
|||||||
#ifndef REHDD_H_
|
#ifndef REHDD_H_
|
||||||
#define REHDD_H_
|
#define REHDD_H_
|
||||||
|
|
||||||
#define DRYRUN
|
//#define DRYRUN
|
||||||
|
|
||||||
#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
|
||||||
@ -25,6 +25,11 @@
|
|||||||
#define SOFTWARE_VERSION "alpha"
|
#define SOFTWARE_VERSION "alpha"
|
||||||
#define HARDWARE_VERSION "generic"
|
#define HARDWARE_VERSION "generic"
|
||||||
|
|
||||||
|
#define LOG_LEVEL_HIGH //log everything, like drive scann thread
|
||||||
|
#ifndef LOG_LEVEL_HIGH
|
||||||
|
#define LOG_LEVEL_LOW //log only user actions and tasks
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -76,16 +76,22 @@ class Shred
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void shredDrive(Drive* drive, int* ipSignalFd);
|
|
||||||
|
Shred();
|
||||||
|
~Shred();
|
||||||
|
void shredDrive(Drive* drive, int* ipSignalFd);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Shred(void);
|
|
||||||
static inline double calcProgress();
|
|
||||||
static inline void tfnge_init_iv(struct tfnge_stream *tfe, const void *key, const void *iv);
|
|
||||||
static inline void tfnge_init(struct tfnge_stream *tfe, const void *key);
|
|
||||||
static inline void tfng_encrypt_rawblk(TFNG_UNIT_TYPE *O, const TFNG_UNIT_TYPE *I, const TFNG_UNIT_TYPE *K);
|
|
||||||
static inline void tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe);
|
|
||||||
|
|
||||||
|
unsigned long blockcount = 0UL;
|
||||||
|
long blockcount_max;
|
||||||
|
double d32Percent;
|
||||||
|
|
||||||
|
inline double calcProgress();
|
||||||
|
inline void tfnge_init_iv(struct tfnge_stream *tfe, const void *key, const void *iv);
|
||||||
|
inline void tfnge_init(struct tfnge_stream *tfe, const void *key);
|
||||||
|
inline void tfng_encrypt_rawblk(TFNG_UNIT_TYPE *O, const TFNG_UNIT_TYPE *I, const TFNG_UNIT_TYPE *K);
|
||||||
|
inline void tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ void reHDD::ThreadScannDevices()
|
|||||||
addSMARTData(&vecNewDrives); //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);
|
||||||
|
printDrives(&vecNewDrives);
|
||||||
sleep(5); //sleep 5 sec
|
sleep(5); //sleep 5 sec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,8 +178,9 @@ void reHDD::ThreadShred()
|
|||||||
{
|
{
|
||||||
if (getSelectedDrive() != nullptr)
|
if (getSelectedDrive() != nullptr)
|
||||||
{
|
{
|
||||||
Shred::shredDrive(getSelectedDrive(), &fdShredInformPipe[1]);
|
Shred* pShredTask = new Shred(); //create new shred task
|
||||||
Logger::logThis()->info("Finished shred for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
pShredTask->shredDrive(getSelectedDrive(), &fdShredInformPipe[1]); //start new shred task
|
||||||
|
delete pShredTask; //delete shred task
|
||||||
ui->updateTUI(&vecDrives, u8SelectedEntry);
|
ui->updateTUI(&vecDrives, u8SelectedEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,7 +218,6 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
|
|||||||
for (long unsigned int i=0; i<pvecNewDrives->size(); i++)
|
for (long unsigned int i=0; i<pvecNewDrives->size(); i++)
|
||||||
{
|
{
|
||||||
pvecOldDrives->push_back((*pvecNewDrives)[i]);
|
pvecOldDrives->push_back((*pvecNewDrives)[i]);
|
||||||
Logger::logThis()->info("Attached drive: " + i + string("-") + pvecNewDrives->at(i).getPath());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,6 +229,7 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
|
|||||||
void reHDD::searchDrives(vector <Drive>* pvecDrives)
|
void reHDD::searchDrives(vector <Drive>* pvecDrives)
|
||||||
{
|
{
|
||||||
// cout << "search drives ..." << endl;
|
// cout << "search drives ..." << endl;
|
||||||
|
Logger::logThis()->info("--> search drives <--");
|
||||||
char * cLine = NULL;
|
char * cLine = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
@ -324,7 +326,9 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// same uuid found than in ignore file --> ignore this 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());
|
Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath());
|
||||||
|
#endif
|
||||||
it = pvecDrives->erase(it);
|
it = pvecDrives->erase(it);
|
||||||
it--;
|
it--;
|
||||||
}
|
}
|
||||||
@ -340,10 +344,13 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
|||||||
*/
|
*/
|
||||||
void reHDD::printDrives(vector <Drive>* pvecDrives)
|
void reHDD::printDrives(vector <Drive>* pvecDrives)
|
||||||
{
|
{
|
||||||
cout << "------------DRIVES---------------" << endl;
|
#ifdef LOG_LEVEL_HIGH
|
||||||
|
Logger::logThis()->info("------------DRIVES---------------");
|
||||||
|
//cout << "------------DRIVES---------------" << endl;
|
||||||
vector <Drive>::iterator it;
|
vector <Drive>::iterator it;
|
||||||
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
cout << " Drive: " << distance(pvecDrives->begin(), it) << endl;
|
cout << " Drive: " << distance(pvecDrives->begin(), it) << endl;
|
||||||
cout << "Path: " << it->getPath() << endl;
|
cout << "Path: " << it->getPath() << endl;
|
||||||
cout << "ModelFamily: " << it->getModelFamily() << endl;
|
cout << "ModelFamily: " << it->getModelFamily() << endl;
|
||||||
@ -353,9 +360,12 @@ void reHDD::printDrives(vector <Drive>* pvecDrives)
|
|||||||
cout << "PowerOnHours: " << it->getPowerOnHours() << endl;
|
cout << "PowerOnHours: " << it->getPowerOnHours() << endl;
|
||||||
cout << "PowerCycle: " << it->getPowerCycles() << endl;
|
cout << "PowerCycle: " << it->getPowerCycles() << endl;
|
||||||
cout << "ErrorCount: " << it->getErrorCount() << endl;
|
cout << "ErrorCount: " << it->getErrorCount() << endl;
|
||||||
cout << endl;
|
cout << endl;*/
|
||||||
|
Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial());
|
||||||
}
|
}
|
||||||
cout << "---------------------------------" << endl;
|
Logger::logThis()->info("---------------------------------");
|
||||||
|
//cout << "---------------------------------" << endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,9 +22,18 @@ struct tfnge_stream
|
|||||||
|
|
||||||
static struct tfnge_stream tfnge;
|
static struct tfnge_stream tfnge;
|
||||||
|
|
||||||
static unsigned long blockcount = 0UL;
|
Shred::Shred()
|
||||||
static long blockcount_max;
|
{
|
||||||
static double d32Percent;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Shred::~Shred()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* \brief shred drive with shred
|
* \brief shred drive with shred
|
||||||
@ -60,6 +69,10 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
|||||||
|
|
||||||
blockcount_max = SHRED_ITERATIONS*(drive->getCapacity()/4096);
|
blockcount_max = SHRED_ITERATIONS*(drive->getCapacity()/4096);
|
||||||
|
|
||||||
|
#ifdef LOG_LEVEL_HIGH
|
||||||
|
Logger::logThis()->info("Shred-Task: Max-BlockCount: " + to_string(blockcount_max) + " - Drive: " + drive->getSerial());
|
||||||
|
#endif
|
||||||
|
|
||||||
d32Percent = 0U;
|
d32Percent = 0U;
|
||||||
|
|
||||||
rsf = open(randsrc, O_RDONLY | O_LARGEFILE);
|
rsf = open(randsrc, O_RDONLY | O_LARGEFILE);
|
||||||
@ -80,13 +93,7 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
|||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
if (!blksz) blksz = (size_t)st.st_blksize;
|
if (!blksz) blksz = (size_t)st.st_blksize;
|
||||||
/*
|
|
||||||
if (howmany != -1)
|
|
||||||
{
|
|
||||||
l = ll = howmany;
|
|
||||||
noround = 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
else l = ll = st.st_size;
|
else l = ll = st.st_size;
|
||||||
if (l == 0 && !S_ISREG(st.st_mode)) special = 1;
|
if (l == 0 && !S_ISREG(st.st_mode)) special = 1;
|
||||||
memset(&st, 0, sizeof(struct stat));
|
memset(&st, 0, sizeof(struct stat));
|
||||||
@ -148,20 +155,27 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
|||||||
// write block loop
|
// write block loop
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
//usleep(10);
|
|
||||||
|
|
||||||
if(drive->state != Drive::SHRED_ACTIVE)
|
if(drive->state != Drive::SHRED_ACTIVE)
|
||||||
{
|
{
|
||||||
drive->setTaskPercentage(0);
|
drive->setTaskPercentage(0);
|
||||||
|
d32Percent = 0.00;
|
||||||
|
blockcount = 0;
|
||||||
|
blockcount_max = 0;
|
||||||
|
Logger::logThis()->info("Aborted shred for: " + drive->getModelName() + "-" + drive->getSerial());
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double d32TmpPercent = calcProgress();
|
double d32TmpPercent = calcProgress();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if((d32TmpPercent-d32Percent) >= 0.09)
|
if((d32TmpPercent-d32Percent) >= 0.09)
|
||||||
{
|
{
|
||||||
drive->setTaskPercentage(d32TmpPercent);
|
drive->setTaskPercentage(d32TmpPercent);
|
||||||
d32Percent = d32TmpPercent;
|
d32Percent = d32TmpPercent;
|
||||||
|
#ifdef LOG_LEVEL_HIGH
|
||||||
|
Logger::logThis()->info("Shred-Task: BlockCount: " + to_string(blockcount) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());
|
||||||
|
#endif
|
||||||
write(*ipSignalFd, "A",1);
|
write(*ipSignalFd, "A",1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +288,7 @@ _return:
|
|||||||
drive->bWasShredded = true;
|
drive->bWasShredded = true;
|
||||||
drive->state= Drive::NONE;
|
drive->state= Drive::NONE;
|
||||||
drive->setTaskPercentage(0);
|
drive->setTaskPercentage(0);
|
||||||
|
Logger::logThis()->info("Finished shred for: " + drive->getModelName() + "-" + drive->getSerial());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef DRYRUN
|
#ifndef DRYRUN
|
||||||
|
Loading…
Reference in New Issue
Block a user