handover drive data to printer class

This commit is contained in:
Hendrik Schutter 2022-11-24 20:04:06 +01:00
parent b1cc2ac13d
commit e7c8ee2423
9 changed files with 43 additions and 43 deletions

View File

@ -33,9 +33,9 @@ public:
bool bWasShredded = false; //all shred iterations done
bool bWasChecked = false; //all shred iterations and optional checking done
bool bWasDeleteted = false;
bool bWasDeleted = false;
bool bIsOffline = false;
uint32_t u32DriveChecksumAferShredding = 0U;
uint32_t u32DriveChecksumAfterShredding = 0U;
private:
string sPath;

View File

@ -26,7 +26,7 @@ typedef struct
char caDriveShredDuration[STR_BUFFER_SIZE];
char caDriveCapacity[STR_BUFFER_SIZE];
char caDriveState[STR_BUFFER_SIZE];
char caDriveModelFamiliy[STR_BUFFER_SIZE];
char caDriveModelFamily[STR_BUFFER_SIZE];
char caDriveModelName[STR_BUFFER_SIZE];
char caDriveSerialnumber[STR_BUFFER_SIZE];
char caDriveReHddVersion[STR_BUFFER_SIZE];
@ -46,7 +46,7 @@ protected:
public:
static Printer* getPrinter();
void print();
void print(Drive* drive);
private:
static bool instanceFlag;

View File

@ -91,7 +91,7 @@ private:
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 ThreadScanDevices();
static void ThreadUserInput();
static void ThreadShred(Drive* const pDrive);
static void ThreadDelete();

View File

@ -21,9 +21,9 @@
#define CHUNK_SIZE 1024*1024*32 //amount of bytes that are overwritten at once --> 32MB
#define TFNG_DATA_SIZE CHUNK_SIZE //amount of bytes used by tfng
#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 5*1024*1024*1024L // 5GB
#define DEMO_DRIVE_SIZE 5*1024*1024*1024L // 5GB
//#define DEMO_DRIVE_SIZE 1024*1024*1024*10L // 10GB
typedef int fileDescriptor;

View File

@ -182,7 +182,7 @@ void Drive::checkFrozenDrive(void)
if((u32localtime - this->u32Timestamp) >= (FROZEN_TIMEOUT*60) && (this->u32Timestamp > 0) && (this->getTaskPercentage() < 100.0))
{
Logger::logThis()->warning("Drive Frozen: " + this->getModelName() + " " + this->getSerial());
this->bWasDeleteted = false;
this->bWasDeleted = false;
this->bWasShredded = false;
this->state = Drive::FROZEN;
}

View File

@ -37,23 +37,23 @@ Printer::~Printer()
* \brief send data to msg queue
* \return void
*/
void Printer::print()
void Printer::print(Drive* drive)
{
t_msgQueueData msgQueueData;
msgQueueData.msg_queue_type = 1;
sprintf(msgQueueData.driveData.caDriveIndex, "%i",42);
sprintf(msgQueueData.driveData.caDriveIndex, "%i",42); //TODO: get from tui
sprintf(msgQueueData.driveData.caDriveState, "shredded");
sprintf(msgQueueData.driveData.caDriveModelFamiliy, "Toshiba 2.5\\ HDD MK..65GSSX");
sprintf(msgQueueData.driveData.caDriveModelName, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
sprintf(msgQueueData.driveData.caDriveCapacity, "%li",343597383680); //343597383680
sprintf(msgQueueData.driveData.caDriveSerialnumber, "YG6742U56UDRL123");
sprintf(msgQueueData.driveData.caDriveHours, "%i",7074);
sprintf(msgQueueData.driveData.caDriveCycles, "%i",4792);
sprintf(msgQueueData.driveData.caDriveErrors, "%i",1);
sprintf(msgQueueData.driveData.caDriveShredTimestamp, "%i",1647937421);
sprintf(msgQueueData.driveData.caDriveShredDuration, "%i",81718);
sprintf(msgQueueData.driveData.caDriveReHddVersion, "bV0.2.2");
strcpy(msgQueueData.driveData.caDriveModelFamily, drive->getModelFamily().c_str());
strcpy(msgQueueData.driveData.caDriveModelName, drive->getModelName().c_str());
sprintf(msgQueueData.driveData.caDriveCapacity, "%li", drive->getCapacity());
strcpy(msgQueueData.driveData.caDriveSerialnumber, drive->getSerial().c_str());
sprintf(msgQueueData.driveData.caDriveHours, "%i",drive->getPowerOnHours());
sprintf(msgQueueData.driveData.caDriveCycles, "%i",drive->getPowerCycles());
sprintf(msgQueueData.driveData.caDriveErrors, "%i",drive->getErrorCount());
sprintf(msgQueueData.driveData.caDriveShredTimestamp, "%li",drive->getActionStartTimestamp());
sprintf(msgQueueData.driveData.caDriveShredDuration, "%li",drive->getTaskDuration());
sprintf(msgQueueData.driveData.caDriveReHddVersion, REHDD_VERSION);
if (-1 == msgsnd(this->msqid, &msgQueueData, sizeof(t_msgQueueData) - sizeof(long), 0))
{

View File

@ -15,7 +15,7 @@ static std::mutex mxDrives;
list <Drive> listNewDrives; //store found drives that are updated every 5sec
static list <Drive> listDrives; //stores all drive data from scann thread
static list <Drive> listDrives; //stores all drive data from scan thread
TUI *ui;
@ -46,7 +46,7 @@ void reHDD::app_logic(void)
pipe(fdNewDrivesInformPipe);
pipe(fdShredInformPipe);
thread thDevices(ThreadScannDevices); //start thread that scanns for drives
thread thDevices(ThreadScanDevices); //start thread that scans for drives
thread thUserInput(ThreadUserInput); //start thread that reads user input
thread thCheckFrozenDrives(ThreadCheckFrozenDrives); //start thread that checks timeout for drives
@ -98,7 +98,7 @@ Drive* reHDD::getSelectedDrive()
}
}
void reHDD::ThreadScannDevices()
void reHDD::ThreadScanDevices()
{
while(true)
{
@ -221,7 +221,7 @@ void reHDD::ThreadDelete()
getSelectedDrive()->setActionStartTimestamp(); //save timestamp at start of deleting
Delete::deleteDrive(getSelectedDrive()); //blocking, no thread
getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished
getSelectedDrive()->bWasDeleteted = true;
getSelectedDrive()->bWasDeleted = true;
Logger::logThis()->info("Finished delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
ui->updateTUI(&listDrives, u8SelectedEntry);
}
@ -230,7 +230,7 @@ void reHDD::ThreadDelete()
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
list <Drive>::iterator itNew; //Iterator for new drive list that was created from to scan thread
//remove offline old drives from previously run
for (itOld = plistOldDrives->begin(); itOld != plistOldDrives->end();)
@ -263,9 +263,9 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
//copy new smart data to existing drive
itOld->setDriveSMARTData(itNew->getModelFamily(), itNew->getModelName(), itNew->getSerial(), itNew->getCapacity(), itNew->getErrorCount(), itNew->getPowerOnHours(), itNew->getPowerCycles(), itNew->getTemperature());
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName());
Logger::logThis()->info("Delete new drive, because already attached: " + itNew->getModelName());
#endif
itNew = plistNewDrives->erase(itNew); //This drive is allready attached, remove from new list
itNew = plistNewDrives->erase(itNew); //This drive is already attached, remove from new list
}
else
{
@ -334,15 +334,15 @@ void reHDD::searchDrives(list <Drive>* plistDrives)
*/
void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
{
list<tuple<string>> vtlIgnoredDevices; //store drives from ingnore file
ifstream input( "ignoreDrives.conf" ); //read ingnore file
list<tuple<string>> vtlIgnoredDevices; //store drives from ignore file
ifstream input( "ignoreDrives.conf" ); //read ignore 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
//loop through found entries in ignore file
for(auto row : vtlIgnoredDevices)
{
list <Drive>::iterator it;

View File

@ -182,15 +182,15 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
#ifdef ZERO_CHECK
drive->state=Drive::CHECK_ACTIVE;
Logger::logThis()->info("Check-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str());
drive->u32DriveChecksumAferShredding = uiCalcChecksum(driveFileDiscr, drive, ipSignalFd);
drive->u32DriveChecksumAfterShredding = uiCalcChecksum(driveFileDiscr, drive, ipSignalFd);
#ifdef LOG_LEVEL_HIGH
if (drive->u32DriveChecksumAferShredding != 0)
{
Logger::logThis()->info("Shred-Task: Checksum not zero: " + to_string(drive->u32DriveChecksumAferShredding) + " - Drive: " + drive->getSerial());
Logger::logThis()->info("Shred-Task: Checksum not zero: " + to_string(drive->u32DriveChecksumAfterShredding) + " - Drive: " + drive->getSerial());
}
else
{
Logger::logThis()->info("Shred-Task: Checksum zero: " + to_string(drive->u32DriveChecksumAferShredding) + " - Drive: " + drive->getSerial());
Logger::logThis()->info("Shred-Task: Checksum zero: " + to_string(drive->u32DriveChecksumAfterShredding) + " - Drive: " + drive->getSerial());
}
#endif
#endif
@ -202,7 +202,7 @@ int Shred::shredDrive(Drive* drive, int* ipSignalFd)
{
drive->state= Drive::NONE;
drive->setTaskPercentage(0.0);
Printer::getPrinter()->print();
Printer::getPrinter()->print(drive);
Logger::logThis()->info("Finished shred/check for: " + drive->getModelName() + "-" + drive->getSerial());
}
return 0;

View File

@ -128,7 +128,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
case Drive::NONE:
case Drive::SHRED_SELECTED:
case Drive::DELETE_SELECTED:
if (it->bWasDeleteted)
if (it->bWasDeleted)
{
sState = "DELETED"; //mark drive as deleted previously
}
@ -148,9 +148,9 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
}
#ifdef ZERO_CHECK
if(bSelectedEntry && it->bWasChecked && (it->u32DriveChecksumAferShredding != 0U))
if(bSelectedEntry && it->bWasChecked && (it->u32DriveChecksumAfterShredding != 0U))
{
dialog=createZeroChecksumWarning(70, 16, ((u16StdscrX)-(int)(u16StdscrX/2)-20),(int)(u16StdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), it->u32DriveChecksumAferShredding);
dialog=createZeroChecksumWarning(70, 16, ((u16StdscrX)-(int)(u16StdscrX/2)-20),(int)(u16StdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), it->u32DriveChecksumAfterShredding);
wrefresh(dialog);
}
#endif
@ -275,7 +275,7 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive
centerTitle(newWindow, title.c_str());
string sPath = "Path: " +drive.getPath();
string sModelFamlily = "ModelFamily: " + drive.getModelFamily();
string sModelFamily = "ModelFamily: " + drive.getModelFamily();
string sModelName = "ModelName: " + drive.getModelName();
string sCapacity = "Capacity: " + drive.sCapacityToText();
string sSerial = "Serial: " + drive.getSerial();
@ -286,7 +286,7 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive
uint16_t u16Line = 2;
mvwaddstr(newWindow,u16Line++, 3, sPath.c_str());
mvwaddstr(newWindow,u16Line++, 3, sModelFamlily.c_str());
mvwaddstr(newWindow,u16Line++, 3, sModelFamily.c_str());
mvwaddstr(newWindow,u16Line++, 3, sModelName.c_str());
mvwaddstr(newWindow,u16Line++, 3, sCapacity.c_str());
mvwaddstr(newWindow,u16Line++, 3, sSerial.c_str());
@ -315,7 +315,7 @@ WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart)
string sLine03 = "Available under GPL 3.0";
string sLine04 = "https://git.mosad.xyz/localhorst/reHDD";
string sLine05 = "Delete: Wipe format table - this is NOT secure";
string sLine06 = "Shred: Overwite drive " + to_string(SHRED_ITERATIONS) + " iterations - this is secure";
string sLine06 = "Shred: Overwrite drive " + to_string(SHRED_ITERATIONS) + " iterations - this is secure";
uint16_t u16Line = 5;
@ -544,7 +544,7 @@ WINDOW* TUI::createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int
string sLine01 = "Please detach this drive and check it manually:";
string sShredChecksum = "After shredding the checksum was: " + to_string(u32Checksum);
string sLinePath = "Path: " +sPath;
string sLineModelFamlily = "ModelFamily: " + sModelFamily;
string sLineModelFamily = "ModelFamily: " + sModelFamily;
string sLineModelName = "ModelName: " + sModelName;
string sLineSerial = "Serial: " + sSerial;
@ -557,7 +557,7 @@ WINDOW* TUI::createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int
mvwaddstr(newWindow,u16Line++, 3, sLine01.c_str());
u16Line++;
mvwaddstr(newWindow,u16Line++, 3, sLinePath.c_str());
mvwaddstr(newWindow,u16Line++, 3, sLineModelFamlily.c_str());
mvwaddstr(newWindow,u16Line++, 3, sLineModelFamily.c_str());
mvwaddstr(newWindow,u16Line++, 3, sLineModelName.c_str());
mvwaddstr(newWindow,u16Line++, 3, sLineSerial.c_str());
u16Line++;
@ -695,7 +695,7 @@ WINDOW* TUI::createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart
if(u32ErrorCount > 0)
{
string sLineTmp = "S.M.A.R.T. erros detected: " + to_string(u32ErrorCount);
string sLineTmp = "S.M.A.R.T. errors detected: " + to_string(u32ErrorCount);
mvwaddstr(newWindow,u16Line++, (iXSize/2)-(sLine01.size()/2), sLineTmp.c_str());
u16Line++;
}