diff --git a/include/reHDD.h b/include/reHDD.h index 746f62b..40f93e4 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,7 +8,7 @@ #ifndef REHDD_H_ #define REHDD_H_ -#define REHDD_VERSION "V1.2.1" +#define REHDD_VERSION "V1.3.0" // Drive handling Settings #define WORSE_HOURS 19200 // mark drive if at this limit or beyond diff --git a/src/reHDD.cpp b/src/reHDD.cpp index ab00ef5..e7b0a98 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -418,8 +418,8 @@ void reHDD::searchDrives(std::list *plistDrives) } /** - * \brief filter out drives that are listed in "ignoreDrives.conf" - * \param pointer of list * plistDrives + * \brief filter out drives that are listed in "ignoreDrives.conf", loop devices, and optical drives + * \param pointer of list * plistDrives * \return void */ void reHDD::filterIgnoredDrives(list *plistDrives) @@ -428,9 +428,8 @@ void reHDD::filterIgnoredDrives(list *plistDrives) if (getSystemDrive(systemDrivePath)) { // Logger::logThis()->info("Found system drive: " + systemDrivePath); - - list::iterator it; - for (it = plistDrives->begin(); it != plistDrives->end(); ++it) + list::iterator it = plistDrives->begin(); + while (it != plistDrives->end()) { string driveName = it->getPath(); // Remove /dev/ prefix @@ -438,6 +437,7 @@ void reHDD::filterIgnoredDrives(list *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,59 +446,123 @@ void reHDD::filterIgnoredDrives(list *plistDrives) #endif it = plistDrives->erase(it); } + else + { + ++it; + } } } - list> vtlIgnoredDevices; // store drives from ignore file - ifstream input("ignoreDrives.conf"); // read ignore file + // Filter out loop devices (loop0, loop1, etc.) + list::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> vtlIgnoredDevices; + ifstream input("ignoreDrives.conf"); 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 + // Skip empty lines and comments + 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) { - list::iterator it; - for (it = plistDrives->begin(); it != plistDrives->end(); ++it) + it = plistDrives->begin(); + while (it != plistDrives->end()) { string sUUID; char *cLine = NULL; size_t len = 0; string sCMD = "blkid "; 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) { - 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"); if (ptuuidPos != string::npos) { string sBlkidOut = string(cLine); sBlkidOut.erase(0, ptuuidPos + 8); - sBlkidOut.erase(8, sBlkidOut.length()); + 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)) // 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 - 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 it = plistDrives->erase(it); } + else + { + ++it; + } } } }