Merge branch 'master' into feature/shred-speedup

This commit is contained in:
2025-12-13 16:53:06 +01:00
2 changed files with 87 additions and 23 deletions

View File

@ -8,7 +8,7 @@
#ifndef REHDD_H_ #ifndef REHDD_H_
#define REHDD_H_ #define REHDD_H_
#define REHDD_VERSION "V1.2.1" #define REHDD_VERSION "V1.3.0"
// Drive handling Settings // Drive handling Settings
#define WORSE_HOURS 19200 // mark drive if at this limit or beyond #define WORSE_HOURS 19200 // mark drive if at this limit or beyond

View File

@ -418,8 +418,8 @@ void reHDD::searchDrives(std::list<Drive> *plistDrives)
} }
/** /**
* \brief filter out drives that are listed in "ignoreDrives.conf" * \brief filter out drives that are listed in "ignoreDrives.conf", loop devices, and optical drives
* \param pointer of list <Drive>* plistDrives * \param pointer of list <Drive>* plistDrives
* \return void * \return void
*/ */
void reHDD::filterIgnoredDrives(list<Drive> *plistDrives) void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
@ -428,9 +428,8 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
if (getSystemDrive(systemDrivePath)) if (getSystemDrive(systemDrivePath))
{ {
// Logger::logThis()->info("Found system drive: " + systemDrivePath); // Logger::logThis()->info("Found system drive: " + systemDrivePath);
list<Drive>::iterator it = plistDrives->begin();
list<Drive>::iterator it; while (it != plistDrives->end())
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{ {
string driveName = it->getPath(); string driveName = it->getPath();
// Remove /dev/ prefix // Remove /dev/ prefix
@ -438,6 +437,7 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
{ {
driveName = driveName.substr(5); // Skip "/dev/" driveName = driveName.substr(5); // Skip "/dev/"
} }
if (systemDrivePath.find(driveName) != std::string::npos) // compare found system drive and current drive if (systemDrivePath.find(driveName) != std::string::npos) // compare found system drive and current drive
{ {
// system drive found --> ignore this drive // system drive found --> ignore this drive
@ -446,59 +446,123 @@ void reHDD::filterIgnoredDrives(list<Drive> *plistDrives)
#endif #endif
it = plistDrives->erase(it); it = plistDrives->erase(it);
} }
else
{
++it;
}
} }
} }
list<tuple<string>> vtlIgnoredDevices; // store drives from ignore file // Filter out loop devices (loop0, loop1, etc.)
ifstream input("ignoreDrives.conf"); // read ignore file 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");
for (string sLine; getline(input, sLine);) for (string sLine; getline(input, sLine);)
{ {
// Logger::logThis()->info("read uuid: " + sLine); // Skip empty lines and comments
vtlIgnoredDevices.emplace_back(sLine); // add found path and uuid from ignore file to vector if (!sLine.empty() && sLine[0] != '#')
{
vtlIgnoredDevices.emplace_back(sLine);
}
} }
// loop through found entries in ignore file
// Loop through found entries in ignore file
for (auto row : vtlIgnoredDevices) for (auto row : vtlIgnoredDevices)
{ {
list<Drive>::iterator it; it = plistDrives->begin();
for (it = plistDrives->begin(); it != plistDrives->end(); ++it) while (it != plistDrives->end())
{ {
string sUUID; string sUUID;
char *cLine = NULL; char *cLine = NULL;
size_t len = 0; size_t len = 0;
string sCMD = "blkid "; string sCMD = "blkid ";
sCMD.append(it->getPath()); sCMD.append(it->getPath());
// cout << "cmd: " << sCMD << endl;
FILE *outputfileBlkid = popen(sCMD.c_str(), "r"); // get UUID from drive FILE *outputfileBlkid = popen(sCMD.c_str(), "r");
if (outputfileBlkid == NULL) if (outputfileBlkid == NULL)
{ {
exit(EXIT_FAILURE); Logger::logThis()->error("Failed to execute blkid for: " + it->getPath());
++it;
continue;
} }
while ((getline(&cLine, &len, outputfileBlkid)) != -1) // parse UUID from blkid while ((getline(&cLine, &len, outputfileBlkid)) != -1)
{ {
size_t ptuuidPos = string(cLine).find("PTUUID"); size_t ptuuidPos = string(cLine).find("PTUUID");
if (ptuuidPos != string::npos) if (ptuuidPos != string::npos)
{ {
string sBlkidOut = string(cLine); string sBlkidOut = string(cLine);
sBlkidOut.erase(0, ptuuidPos + 8); sBlkidOut.erase(0, ptuuidPos + 8);
sBlkidOut.erase(8, sBlkidOut.length()); if (sBlkidOut.length() >= 8)
{
sBlkidOut.erase(8, sBlkidOut.length());
}
sUUID = sBlkidOut; sUUID = sBlkidOut;
// cout << "blkid uuid:" << sUUID << endl;
} }
} }
free(cLine); free(cLine);
pclose(outputfileBlkid); pclose(outputfileBlkid);
// cout << "blkid uuid:" << sUUID << endl;
if (!get<0>(row).compare(sUUID)) // compare uuid from ignore file and uuid from drive if (!get<0>(row).compare(sUUID))
{ {
// same uuid found than in ignore file --> ignore this drive
#ifdef LOG_LEVEL_HIGH #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 in ignore file --> ignore this drive: " + it->getPath());
#endif #endif
it = plistDrives->erase(it); it = plistDrives->erase(it);
} }
else
{
++it;
}
} }
} }
} }