added filter algo for existing drives
This commit is contained in:
parent
a61d4321f6
commit
27b48de32a
@ -1,3 +1,3 @@
|
|||||||
|
/dev/sdc:4673974d-1af2-44fd-996b-a2d8e4c43d9a
|
||||||
/dev/sda:508ef27d-5039-4e8b-9e2c-22d7528b7149
|
/dev/sda:508ef27d-5039-4e8b-9e2c-22d7528b7149
|
||||||
/dev/sdb:07f4ad14-c4b6-46e7-9cdf-3cfa9841d53d
|
/dev/sdb:07f4ad14-c4b6-46e7-9cdf-3cfa9841d53d
|
||||||
/dev/sdc:4673974d-1af2-44fd-996b-a2d8e4c43d9a
|
|
||||||
|
@ -48,8 +48,8 @@ private:
|
|||||||
uint32_t u32PowerCycles = 0U;
|
uint32_t u32PowerCycles = 0U;
|
||||||
uint32_t u32ShredPercentage = 0U; //in percent
|
uint32_t u32ShredPercentage = 0U; //in percent
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include<algorithm>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -49,12 +50,12 @@ private:
|
|||||||
|
|
||||||
vector <Drive> vecDrives; //stores all drive data
|
vector <Drive> vecDrives; //stores all drive data
|
||||||
|
|
||||||
static void searchDrives(vector <Drive>* pvecDrives);
|
static void searchDrives(vector <Drive>* pvecDrives);
|
||||||
|
|
||||||
static void printDrives(vector <Drive>* pvecDrives);
|
static void printDrives(vector <Drive>* pvecDrives);
|
||||||
|
|
||||||
|
|
||||||
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
||||||
|
|
||||||
|
|
||||||
static void addSMARTData(vector <Drive>* pvecDrives);
|
static void addSMARTData(vector <Drive>* pvecDrives);
|
||||||
@ -62,11 +63,11 @@ private:
|
|||||||
static void ThreadScannDevices();
|
static void ThreadScannDevices();
|
||||||
|
|
||||||
|
|
||||||
|
void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,17 +22,17 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TUI(void);
|
TUI(void);
|
||||||
|
|
||||||
void initTUI();
|
void initTUI();
|
||||||
|
|
||||||
void updateTUI(TUI_DATA data);
|
void updateTUI(TUI_DATA data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void centerTitle(WINDOW *pwin, const char * title);
|
void centerTitle(WINDOW *pwin, const char * title);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,22 +23,22 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TUI_DATA(vector <Drive>* pvecDrives);
|
TUI_DATA(vector <Drive>* pvecDrives);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string sCpuUsage;
|
|
||||||
string sRamUsage;
|
|
||||||
string sLocalTime;
|
string sCpuUsage;
|
||||||
|
string sRamUsage;
|
||||||
|
string sLocalTime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
TUI_DATA::TUI_DATA(vector <Drive>* pvecDrives)
|
TUI_DATA::TUI_DATA(vector <Drive>* pvecDrives)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// cout << "refurbishingHddTool" << endl;
|
// cout << "refurbishingHddTool" << endl;
|
||||||
|
|
||||||
reHDD* app = new reHDD();
|
reHDD* app = new reHDD();
|
||||||
app->app_logic();
|
app->app_logic();
|
||||||
|
142
src/reHDD.cpp
142
src/reHDD.cpp
@ -39,123 +39,106 @@ void reHDD::app_logic(void)
|
|||||||
cout << "app logic" << endl;
|
cout << "app logic" << endl;
|
||||||
|
|
||||||
|
|
||||||
int result = pipe(fdSearchDrives);
|
pipe(fdSearchDrives);
|
||||||
|
|
||||||
FD_ZERO(&selectSet);
|
FD_ZERO(&selectSet);
|
||||||
FD_SET(fdSearchDrives[0], &selectSet);
|
FD_SET(fdSearchDrives[0], &selectSet);
|
||||||
|
|
||||||
thread thDevices(ThreadScannDevices);
|
thread thDevices(ThreadScannDevices); //start thread that scanns for drives
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
|
||||||
while(1){
|
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
|
||||||
|
|
||||||
int iSelectReturn = select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
|
if( FD_ISSET(fdSearchDrives[0], &selectSet)) {
|
||||||
|
char dummy;
|
||||||
|
read (fdSearchDrives[0],&dummy,1);
|
||||||
|
mxScannDrives.lock();
|
||||||
|
printDrives(&vecNewDrives);
|
||||||
|
//replace with old list
|
||||||
|
// action if needed
|
||||||
|
|
||||||
|
|
||||||
if( FD_ISSET(fdSearchDrives[0], &selectSet)) {
|
|
||||||
|
|
||||||
|
filterNewDrives(&vecDrives, &vecDrives);
|
||||||
char ch;
|
|
||||||
|
|
||||||
|
|
||||||
result = read (fdSearchDrives[0],&ch,1);
|
|
||||||
|
|
||||||
if (result != 1) {
|
|
||||||
perror("read");
|
|
||||||
exit(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf ("From Main Thread: %c\n", ch);
|
|
||||||
|
|
||||||
mxScannDrives.lock();
|
|
||||||
printDrives(&vecNewDrives);
|
|
||||||
//replace with old list
|
|
||||||
// action if needed
|
|
||||||
mxScannDrives.unlock();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mxScannDrives.unlock();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
thDevices.join();
|
thDevices.join();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t u64SelectedDriveIndex = 0U;
|
size_t u64SelectedDriveIndex = 0U;
|
||||||
size_t u64DriveVecSize = (vecDrives.size());
|
size_t u64DriveVecSize = (vecDrives.size());
|
||||||
|
|
||||||
cout << "Select drive to wipe:" << endl;
|
cout << "Select drive to wipe:" << endl;
|
||||||
cin >> u64SelectedDriveIndex;
|
cin >> u64SelectedDriveIndex;
|
||||||
cout << "Selected drive index: " << u64SelectedDriveIndex << endl;
|
cout << "Selected drive index: " << u64SelectedDriveIndex << endl;
|
||||||
|
|
||||||
if(u64SelectedDriveIndex < (u64DriveVecSize)) {
|
if(u64SelectedDriveIndex < (u64DriveVecSize)) {
|
||||||
// Wipe::wipeDrive(&vecDrives[u64SelectedDriveIndex]);
|
// Wipe::wipeDrive(&vecDrives[u64SelectedDriveIndex]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void reHDD::ThreadScannDevices() {
|
||||||
|
while(true) {
|
||||||
|
cout << "Thread" << endl;
|
||||||
|
mxScannDrives.lock();
|
||||||
|
vecNewDrives.clear();
|
||||||
|
searchDrives(&vecNewDrives); //search for new drives and store them in list
|
||||||
|
filterIgnoredDrives(&vecNewDrives); //filter out ignored drives
|
||||||
|
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
|
||||||
|
mxScannDrives.unlock();
|
||||||
|
write (fdSearchDrives[1], "A",1);
|
||||||
|
sleep(5); //sleep 5 sec
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void reHDD::ThreadScannDevices(){
|
void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives){
|
||||||
|
|
||||||
|
|
||||||
|
vector <Drive>::iterator itOld; //Iterator for current (old) drive list
|
||||||
|
vector <Drive>::iterator itNew; //Iterator for new drive list that was created from to scann thread
|
||||||
|
|
||||||
while(true){
|
vector <Drive> vecOfflineDrives; //TODO
|
||||||
|
|
||||||
cout << "Thread" << endl;
|
for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld)
|
||||||
|
{
|
||||||
|
for (itNew = pvecOldDrives->begin(); itNew != pvecOldDrives->end(); ++itNew)
|
||||||
mxScannDrives.lock();
|
{
|
||||||
vecNewDrives.clear();
|
if(itOld->getSerial() == itNew->getSerial()){
|
||||||
|
//drive exists already --> remove it from old list
|
||||||
|
pvecOldDrives->erase(itOld);
|
||||||
searchDrives(&vecNewDrives); //search for new drives and store them in list
|
}
|
||||||
filterIgnoredDrives(&vecNewDrives); //filter out ignored drives
|
}
|
||||||
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
|
}
|
||||||
|
|
||||||
mxScannDrives.unlock();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int result = write (fdSearchDrives[1], "A",1);
|
|
||||||
//cout << result << endl;
|
|
||||||
if (result != 1){
|
|
||||||
perror ("write error");
|
|
||||||
// exit (2);
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep(5); //sleep 5 sec
|
|
||||||
}
|
|
||||||
|
|
||||||
|
copy(pvecOldDrives->begin(), pvecOldDrives->end(), back_inserter(vecOfflineDrives));
|
||||||
|
|
||||||
|
cout << "start offline" << endl;
|
||||||
|
printDrives(&vecOfflineDrives);
|
||||||
|
cout << "end offline" << endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief search attached drives on /dev/sd*
|
* \brief search attached drives on /dev/sd*
|
||||||
* \param pointer of vector <Drive>* pvecDrives
|
* \param pointer of vector <Drive>* pvecDrives
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
void reHDD::searchDrives(vector <Drive>* pvecDrives)
|
void reHDD::searchDrives(vector <Drive>* pvecDrives)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cout << "search drives ..." << endl;
|
cout << "search drives ..." << endl;
|
||||||
char * cLine = NULL;
|
char * cLine = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
@ -176,8 +159,6 @@ cout << "Thread" << endl;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(outputfileHwinfo);
|
fclose(outputfileHwinfo);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -213,10 +194,11 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
|||||||
vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ingnore file to vector
|
vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ingnore file to vector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//loop through found entries in ingnore file
|
//loop through found entries in ingnore file
|
||||||
for(auto row : vtlIgnoredDevices)
|
for(auto row : vtlIgnoredDevices)
|
||||||
{
|
{
|
||||||
|
cout << "file drive path found: " << get<0>(row) << endl;
|
||||||
|
|
||||||
auto it = pvecDrives->begin();
|
auto it = pvecDrives->begin();
|
||||||
while (it != pvecDrives->end())
|
while (it != pvecDrives->end())
|
||||||
{
|
{
|
||||||
@ -224,12 +206,12 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
|||||||
string sUUID;
|
string sUUID;
|
||||||
if (!get<0>(row).compare(it->getPath())) //find same drive based on path
|
if (!get<0>(row).compare(it->getPath())) //find same drive based on path
|
||||||
{
|
{
|
||||||
// cout << "Same drive path found" << endl;
|
cout << "Same drive path found: " << it->getPath() << endl;
|
||||||
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;
|
cout << "cmd: " << sCMD << endl;
|
||||||
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
|
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
|
||||||
if (outputfileBlkid == NULL)
|
if (outputfileBlkid == NULL)
|
||||||
{
|
{
|
||||||
@ -248,7 +230,7 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(outputfileBlkid);
|
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
|
if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
|
||||||
{
|
{
|
||||||
@ -259,6 +241,8 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
|||||||
{
|
{
|
||||||
// same uuid found than in ignore file --> ignore this drive
|
// same uuid found than in ignore file --> ignore this drive
|
||||||
it = pvecDrives->erase(it);
|
it = pvecDrives->erase(it);
|
||||||
|
cout << "same uuid found than in ignore file --> ignore this drive:" << it->getPath() << endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,19 +50,19 @@ void Wipe::wipeDrive(Drive* drive)
|
|||||||
uint64_t u64minutes = 0U;
|
uint64_t u64minutes = 0U;
|
||||||
uint64_t u64seconds = 0U;
|
uint64_t u64seconds = 0U;
|
||||||
|
|
||||||
while(u64TimeMS >= 1000)
|
while(u64TimeMS >= 1000)
|
||||||
{
|
{
|
||||||
u64seconds++;
|
u64seconds++;
|
||||||
u64TimeMS = u64TimeMS - 1000;
|
u64TimeMS = u64TimeMS - 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(u64seconds >= 60)
|
while(u64seconds >= 60)
|
||||||
{
|
{
|
||||||
u64minutes++;
|
u64minutes++;
|
||||||
u64seconds = u64seconds - 60;
|
u64seconds = u64seconds - 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(u64minutes >= 60)
|
while(u64minutes >= 60)
|
||||||
{
|
{
|
||||||
u64hours++;
|
u64hours++;
|
||||||
u64minutes = u64minutes - 60;
|
u64minutes = u64minutes - 60;
|
||||||
|
Loading…
Reference in New Issue
Block a user