|
|
|
|
@ -218,16 +218,18 @@ void reHDD::ThreadUserInput()
|
|
|
|
|
break;
|
|
|
|
|
case TUI::UserInput::Print:
|
|
|
|
|
// cout << "Print" << endl;
|
|
|
|
|
Logger::logThis()->info("User print single");
|
|
|
|
|
if (tmpSelectedDrive != nullptr)
|
|
|
|
|
{
|
|
|
|
|
printDrive(tmpSelectedDrive);
|
|
|
|
|
// printDrive(tmpSelectedDrive);
|
|
|
|
|
}
|
|
|
|
|
ui->updateTUI(&listDrives, u16SelectedEntry);
|
|
|
|
|
// ui->updateTUI(&listDrives, u16SelectedEntry);
|
|
|
|
|
break;
|
|
|
|
|
case TUI::UserInput::PrintAll:
|
|
|
|
|
// cout << "PrintAll" << endl;
|
|
|
|
|
printAllDrives(&listDrives);
|
|
|
|
|
ui->updateTUI(&listDrives, u16SelectedEntry);
|
|
|
|
|
Logger::logThis()->info("User print all");
|
|
|
|
|
// printAllDrives(&listDrives);
|
|
|
|
|
// ui->updateTUI(&listDrives, u16SelectedEntry);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
@ -236,7 +238,7 @@ void reHDD::ThreadUserInput()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief print all shredded drives
|
|
|
|
|
* \brief start shred for all drives
|
|
|
|
|
* \param pointer of list <Drive>* plistDrives
|
|
|
|
|
* \return void
|
|
|
|
|
*/
|
|
|
|
|
@ -252,11 +254,6 @@ void reHDD::printAllDrives(list<Drive> *plistDrives)
|
|
|
|
|
mxDrives.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief print a shredded drives
|
|
|
|
|
* \param pointer of a drive
|
|
|
|
|
* \return void
|
|
|
|
|
*/
|
|
|
|
|
void reHDD::printDrive(Drive *const pDrive)
|
|
|
|
|
{
|
|
|
|
|
if (pDrive->bWasShredded)
|
|
|
|
|
@ -268,7 +265,7 @@ void reHDD::printDrive(Drive *const pDrive)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
Logger::logThis()->info("User print for: " + pDrive->getModelName() + "-" + pDrive->getSerial());
|
|
|
|
|
Printer::getPrinter()->print(pDrive);
|
|
|
|
|
// TODO: Trigger printer for this drive
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -284,16 +281,16 @@ void reHDD::ThreadShred(Drive *const pDrive)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reHDD::ThreadDelete(Drive *const pDrive)
|
|
|
|
|
void reHDD::ThreadDelete()
|
|
|
|
|
{
|
|
|
|
|
if (pDrive != nullptr)
|
|
|
|
|
Drive *tmpSelectedDrive = getSelectedDrive();
|
|
|
|
|
if (tmpSelectedDrive != nullptr)
|
|
|
|
|
{
|
|
|
|
|
pDrive->state = Drive::TaskState::DELETE_ACTIVE;
|
|
|
|
|
pDrive->setActionStartTimestamp(); // save timestamp at start of deleting
|
|
|
|
|
Delete::deleteDrive(pDrive); // blocking, no thread
|
|
|
|
|
pDrive->state = Drive::TaskState::NONE; // delete finished
|
|
|
|
|
pDrive->bWasDeleted = true;
|
|
|
|
|
Logger::logThis()->info("Finished delete for: " + pDrive->getModelName() + "-" + pDrive->getSerial());
|
|
|
|
|
tmpSelectedDrive->setActionStartTimestamp(); // save timestamp at start of deleting
|
|
|
|
|
Delete::deleteDrive(tmpSelectedDrive); // blocking, no thread
|
|
|
|
|
tmpSelectedDrive->state = Drive::TaskState::NONE; // delete finished
|
|
|
|
|
tmpSelectedDrive->bWasDeleted = true;
|
|
|
|
|
Logger::logThis()->info("Finished delete for: " + tmpSelectedDrive->getModelName() + "-" + tmpSelectedDrive->getSerial());
|
|
|
|
|
ui->updateTUI(&listDrives, u16SelectedEntry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -418,7 +415,7 @@ void reHDD::searchDrives(std::list<Drive> *plistDrives)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief filter out drives that are listed in "ignoreDrives.conf", loop devices, and optical drives
|
|
|
|
|
* \brief filter out drives that are listed in "ignoreDrives.conf"
|
|
|
|
|
* \param pointer of list <Drive>* plistDrives
|
|
|
|
|
* \return void
|
|
|
|
|
*/
|
|
|
|
|
@ -428,8 +425,9 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
|
|
|
|
|
if (getSystemDrive(systemDrivePath))
|
|
|
|
|
{
|
|
|
|
|
// Logger::logThis()->info("Found system drive: " + systemDrivePath);
|
|
|
|
|
list<Drive>::iterator it = plistDrives->begin();
|
|
|
|
|
while (it != plistDrives->end())
|
|
|
|
|
|
|
|
|
|
list<Drive>::iterator it;
|
|
|
|
|
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
string driveName = it->getPath();
|
|
|
|
|
// Remove /dev/ prefix
|
|
|
|
|
@ -437,7 +435,6 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
|
|
|
|
|
{
|
|
|
|
|
driveName = driveName.substr(5); // Skip "/dev/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (systemDrivePath.find(driveName) != std::string::npos) // compare found system drive and current drive
|
|
|
|
|
{
|
|
|
|
|
// system drive found --> ignore this drive
|
|
|
|
|
@ -446,123 +443,59 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
|
|
|
|
|
#endif
|
|
|
|
|
it = plistDrives->erase(it);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter out loop devices (loop0, loop1, etc.)
|
|
|
|
|
list<Drive>::iterator it = plistDrives->begin();
|
|
|
|
|
while (it != plistDrives->end())
|
|
|
|
|
{
|
|
|
|
|
string driveName = it->getPath();
|
|
|
|
|
if (driveName.find("/dev/") == 0)
|
|
|
|
|
{
|
|
|
|
|
driveName = driveName.substr(5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (driveName.find("loop") == 0)
|
|
|
|
|
{
|
|
|
|
|
#ifdef LOG_LEVEL_HIGH
|
|
|
|
|
Logger::logThis()->info("loop device found --> ignore this drive: " + it->getPath());
|
|
|
|
|
#endif
|
|
|
|
|
it = plistDrives->erase(it);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter out optical drives (sr0, sr1, cdrom, dvd, etc.)
|
|
|
|
|
it = plistDrives->begin();
|
|
|
|
|
while (it != plistDrives->end())
|
|
|
|
|
{
|
|
|
|
|
string driveName = it->getPath();
|
|
|
|
|
if (driveName.find("/dev/") == 0)
|
|
|
|
|
{
|
|
|
|
|
driveName = driveName.substr(5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (driveName.find("sr") == 0 ||
|
|
|
|
|
driveName.find("cdrom") == 0 ||
|
|
|
|
|
driveName.find("dvd") == 0 ||
|
|
|
|
|
driveName.find("cdrw") == 0)
|
|
|
|
|
{
|
|
|
|
|
#ifdef LOG_LEVEL_HIGH
|
|
|
|
|
Logger::logThis()->info("optical drive found --> ignore this drive: " + it->getPath());
|
|
|
|
|
#endif
|
|
|
|
|
it = plistDrives->erase(it);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read ignored drives from config file
|
|
|
|
|
list<tuple<string>> vtlIgnoredDevices;
|
|
|
|
|
ifstream input("ignoreDrives.conf");
|
|
|
|
|
list<tuple<string>> vtlIgnoredDevices; // store drives from ignore file
|
|
|
|
|
ifstream input("ignoreDrives.conf"); // read ignore file
|
|
|
|
|
|
|
|
|
|
for (string sLine; getline(input, sLine);)
|
|
|
|
|
{
|
|
|
|
|
// Skip empty lines and comments
|
|
|
|
|
if (!sLine.empty() && sLine[0] != '#')
|
|
|
|
|
{
|
|
|
|
|
vtlIgnoredDevices.emplace_back(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 ignore file
|
|
|
|
|
// loop through found entries in ignore file
|
|
|
|
|
for (auto row : vtlIgnoredDevices)
|
|
|
|
|
{
|
|
|
|
|
it = plistDrives->begin();
|
|
|
|
|
while (it != plistDrives->end())
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
FILE *outputfileBlkid = popen(sCMD.c_str(), "r");
|
|
|
|
|
// cout << "cmd: " << sCMD << endl;
|
|
|
|
|
FILE *outputfileBlkid = popen(sCMD.c_str(), "r"); // get UUID from drive
|
|
|
|
|
if (outputfileBlkid == NULL)
|
|
|
|
|
{
|
|
|
|
|
Logger::logThis()->error("Failed to execute blkid for: " + it->getPath());
|
|
|
|
|
++it;
|
|
|
|
|
continue;
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((getline(&cLine, &len, outputfileBlkid)) != -1)
|
|
|
|
|
while ((getline(&cLine, &len, outputfileBlkid)) != -1) // parse UUID from blkid
|
|
|
|
|
{
|
|
|
|
|
size_t ptuuidPos = string(cLine).find("PTUUID");
|
|
|
|
|
if (ptuuidPos != string::npos)
|
|
|
|
|
{
|
|
|
|
|
string sBlkidOut = string(cLine);
|
|
|
|
|
sBlkidOut.erase(0, ptuuidPos + 8);
|
|
|
|
|
if (sBlkidOut.length() >= 8)
|
|
|
|
|
{
|
|
|
|
|
sBlkidOut.erase(8, sBlkidOut.length());
|
|
|
|
|
}
|
|
|
|
|
sUUID = sBlkidOut;
|
|
|
|
|
// cout << "blkid uuid:" << sUUID << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(cLine);
|
|
|
|
|
pclose(outputfileBlkid);
|
|
|
|
|
// cout << "blkid uuid:" << sUUID << endl;
|
|
|
|
|
|
|
|
|
|
if (!get<0>(row).compare(sUUID))
|
|
|
|
|
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 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 = plistDrives->erase(it);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -606,6 +539,7 @@ void reHDD::startShredAllDrives(list<Drive> *plistDrives)
|
|
|
|
|
address << (void const *)&(*pTmpDrive);
|
|
|
|
|
Logger::logThis()->info("Started shred (all) for: " + pTmpDrive->getModelName() + "-" + pTmpDrive->getSerial() + " @" + address.str());
|
|
|
|
|
#endif
|
|
|
|
|
pTmpDrive->state = Drive::TaskState::SHRED_ACTIVE;
|
|
|
|
|
thread(ThreadShred, pTmpDrive).detach();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -757,13 +691,17 @@ void reHDD::handleEnter()
|
|
|
|
|
if (tmpSelectedDrive->state == Drive::TaskState::SHRED_SELECTED)
|
|
|
|
|
{
|
|
|
|
|
Logger::logThis()->info("Started shred/check for: " + tmpSelectedDrive->getModelName() + "-" + tmpSelectedDrive->getSerial());
|
|
|
|
|
tmpSelectedDrive->state = Drive::TaskState::SHRED_ACTIVE;
|
|
|
|
|
// task for drive is running --> don't show more task option
|
|
|
|
|
thread(ThreadShred, tmpSelectedDrive).detach();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tmpSelectedDrive->state == Drive::TaskState::DELETE_SELECTED)
|
|
|
|
|
{
|
|
|
|
|
Logger::logThis()->info("Started delete for: " + tmpSelectedDrive->getModelName() + "-" + tmpSelectedDrive->getSerial());
|
|
|
|
|
thread(ThreadDelete, tmpSelectedDrive).detach();
|
|
|
|
|
tmpSelectedDrive->state = Drive::TaskState::DELETE_ACTIVE;
|
|
|
|
|
// task for drive is running --> don't show more task options
|
|
|
|
|
thread(ThreadDelete).detach();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|