From 89f900c970d506de79584ebded44e766b0a60c58 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 4 Aug 2020 19:51:34 +0200 Subject: [PATCH] detect offline drives --- ignoreDrives.conf | 2 +- include/reHDD.h | 2 ++ src/reHDD.cpp | 57 ++++++++++++++++++++++++----------------------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/ignoreDrives.conf b/ignoreDrives.conf index 0605f89..ed2b36a 100644 --- a/ignoreDrives.conf +++ b/ignoreDrives.conf @@ -1,3 +1,3 @@ /dev/sdc:4673974d-1af2-44fd-996b-a2d8e4c43d9a /dev/sda:508ef27d-5039-4e8b-9e2c-22d7528b7149 -/dev/sdb:07f4ad14-c4b6-46e7-9cdf-3cfa9841d53d +/dev/sdb:32b66944-ffa0-40e9-817c-3f0c52eefaf4 diff --git a/include/reHDD.h b/include/reHDD.h index 94a5a06..32390cd 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,6 +8,8 @@ #ifndef REHDD_H_ #define REHDD_H_ +#define DRYRUN + #include #include #include diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 4185445..6042f85 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -46,6 +46,7 @@ void reHDD::app_logic(void) thread thDevices(ThreadScannDevices); //start thread that scanns for drives + while(1) { select(FD_SETSIZE, &selectSet, NULL, NULL, NULL); @@ -54,16 +55,16 @@ void reHDD::app_logic(void) char dummy; read (fdSearchDrives[0],&dummy,1); mxScannDrives.lock(); - printDrives(&vecNewDrives); + //replace with old list // action if needed - filterNewDrives(&vecDrives, &vecDrives); - + filterNewDrives(&vecDrives, &vecNewDrives); + printDrives(&vecDrives); mxScannDrives.unlock(); } @@ -72,7 +73,7 @@ void reHDD::app_logic(void) - thDevices.join(); + // thDevices.join(); /* @@ -105,30 +106,33 @@ void reHDD::ThreadScannDevices() { } } -void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecNewDrives){ - +void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecNewDrives) { vector ::iterator itOld; //Iterator for current (old) drive list vector ::iterator itNew; //Iterator for new drive list that was created from to scann thread - vector vecOfflineDrives; //TODO - for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld) { - for (itNew = pvecOldDrives->begin(); itNew != pvecOldDrives->end(); ++itNew) + bool bOldDriveIsOffline = true; + for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew) { - if(itOld->getSerial() == itNew->getSerial()){ - //drive exists already --> remove it from old list - pvecOldDrives->erase(itOld); + if(itOld->getSerial() == itNew->getSerial()) { + bOldDriveIsOffline = false; + // cout << "already online drive found: " << itOld->getPath() << endl; } } - } - copy(pvecOldDrives->begin(), pvecOldDrives->end(), back_inserter(vecOfflineDrives)); + if(bOldDriveIsOffline == true) { + cout << "offline drive found: " << itOld->getPath() << endl; + //TODO kill wipe thread + } + } - cout << "start offline" << endl; - printDrives(&vecOfflineDrives); - cout << "end offline" << endl; + pvecOldDrives->clear(); + + for (long unsigned int i=0; isize(); i++) { + pvecOldDrives->push_back((*pvecNewDrives)[i]); + } } @@ -174,6 +178,8 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) vector> vtlIgnoredDevices; //store drives from ingnore file + //vector vecTmpDrives + ifstream input( "ignoreDrives.conf" ); //read ingnore file for(string sLine; getline( input, sLine );) @@ -197,21 +203,17 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) //loop through found entries in ingnore file for(auto row : vtlIgnoredDevices) { - cout << "file drive path found: " << get<0>(row) << endl; - - auto it = pvecDrives->begin(); - while (it != pvecDrives->end()) + vector ::iterator it; + for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) { - it++; string sUUID; if (!get<0>(row).compare(it->getPath())) //find same drive based on path { - cout << "Same drive path found: " << it->getPath() << endl; char * cLine = NULL; size_t len = 0; string sCMD = "blkid "; sCMD.append(it->getPath()); - cout << "cmd: " << sCMD << endl; + //cout << "cmd: " << sCMD << endl; FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive if (outputfileBlkid == NULL) { @@ -230,7 +232,7 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) } } fclose(outputfileBlkid); - cout << "blkid uuid:" << sUUID << endl; + //cout << "blkid uuid:" << sUUID << endl; if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive { @@ -241,10 +243,9 @@ void reHDD::filterIgnoredDrives(vector * pvecDrives) { // same uuid found than in ignore file --> ignore this drive it = pvecDrives->erase(it); - cout << "same uuid found than in ignore file --> ignore this drive:" << it->getPath() << endl; - + it--; + //cout << "same uuid found than in ignore file --> ignore this drive:" << it->getPath() << endl; } - } } }