diff --git a/.gitignore b/.gitignore
index e257658..5af8f1b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,6 @@
*.out
*.app
+# Astyle
+*.orig
+
diff --git a/Docu/refurbishingHddTool.drawio b/Docu/refurbishingHddTool.drawio
new file mode 100644
index 0000000..3667556
--- /dev/null
+++ b/Docu/refurbishingHddTool.drawio
@@ -0,0 +1 @@
+7VttU+o4FP41zOx+kGnTF+CjgKh3vczdxV31050Ioc1aGkyDiL9+kzalL6mXqlOCrDMONqdpSM85zzlPTkLLGiyezylc+t/JDAUtYMyeW9awBYBpA9ASf8Zsk0jcrpUIPIpnslMmmOAXJIWGlK7wDEWFjoyQgOFlUTglYYimrCCDlJJ1sducBMVvXUIPKYLJFAaq9AbPmJ9Iu6CTyS8Q9vz0m023l9xZwLSzfJPIhzOyzomss5Y1oISw5GrxPECBUF6ql5vLzU1w9eCef/szeoR/9/+4Hv9zkgw2essj21egKGTvHtpe/bx9PJsPfl6ML+l4fHUz8V5O5LtGbJPqC824+mSTUOYTj4QwOMukfUpW4QyJUQ3eyvpcEbLkQpML/0WMbaQvwBUjXOSzRSDv8regm1vxfNtJm3dyuLgxfC60NrKVzFVMsGTaHXqR/SKyolP0C2VIOzNIPcR+0c/aGp+jBpEF4pPkz1EUQIafipOD0n29bb/MRPxCWukNFpOTfILBSn7TD0o8ChcRnzdTzRkEHGnCbGsfMzRZwlgFaw72olHksIgy9PwO9arqkKNYHelj6wx9piHfws8hzzUa0phpqlr5/zq5VdPJTaParPvxckvx8hDxK+AGfM79e8qvPBZry4UL4cnhfST+XQyHYjoL/vFj0LJGVU+UfIH6ZHG/inYjZBv/hZnmJGQjuMCBsNsFCp4Qw1Mob0inMLn++jDAXsgbU24+RMUwjJKHbS6KB+ZfiUOPt9ysdR372Ym9D2huSrDcBdVeY1B1dUC1aciZdROL6ejEnKmmlnEMOiNBlYfmQtGhiqCtAczdKCrjwwtgFEnbVUAjj7nGcOAWcQDMjooDUIEDuzEc2MeIg7qpR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m6aodD2XU3+q6bz2QWPaV73+GzxO3dtOiR701J+RVB3jfIfueTP73XESoLJfb1tn/wE=
\ No newline at end of file
diff --git a/Docu/refurbishingHddTool.pdf b/Docu/refurbishingHddTool.pdf
new file mode 100644
index 0000000..6989d9c
Binary files /dev/null and b/Docu/refurbishingHddTool.pdf differ
diff --git a/src/app.cpp b/src/app.cpp
new file mode 100644
index 0000000..fd3ff36
--- /dev/null
+++ b/src/app.cpp
@@ -0,0 +1,174 @@
+/**
+ * @file app.cpp
+ * @brief app logic
+ * @author hendrik schutter
+ * @date 01.05.2020
+ */
+
+#include "app.h"
+
+/**
+ * \brief app constructor
+ * \param void
+ * \return instance of App
+ */
+App::App(void) {
+ cout << "created app" << endl;
+}
+
+/**
+ * \brief app logic
+ * \param void
+ * \return void
+ */
+void App::app_logic(void)
+{
+ cout << "app logic" << endl;
+
+ searchDrives(&listDrives); //search for new drives and store them in list
+ filterIgnoredDrives(&listDrives); //filter out ignored drives
+ printDrives(&listDrives); //print currently attached drives
+}
+
+/**
+ * \brief search attached drives on /dev/sd*
+ * \param pointer of list *listDrives
+ * \return void
+ */
+void App::searchDrives(list *listDrives)
+{
+ cout << "search drives ..." << endl;
+ char * cLine = NULL;
+ size_t len = 0;
+
+ FILE* outputfileHwinfo = popen("./hwinfo --short --disk", "r");
+
+ if (outputfileHwinfo == NULL)
+ {
+ exit(EXIT_FAILURE);
+ }
+
+ while ((getline(&cLine, &len, outputfileHwinfo)) != -1)
+ {
+ if (string(cLine).find("/dev/sd") != string::npos)
+ {
+ struct drive tmpDrive;
+ tmpDrive.u32ErrorCount = 0U;
+ tmpDrive.u32PowerOnHours = 0U;
+ tmpDrive.u32SpinUpCount = 0U;
+ tmpDrive.sPath = string(cLine).substr (2,8);
+ listDrives->push_back(tmpDrive);
+ }
+ }
+ fclose(outputfileHwinfo);
+}
+
+/**
+ * \brief filter out drives that are listed in "ignoreDrives.conf"
+ * \param pointer of list *listDrives
+ * \return void
+ */
+void App::filterIgnoredDrives(list *listDrives)
+{
+ string sDelimiter = ":";
+ string sIgnoredDrivePath;
+ string sIgnoredDriveUUID;
+
+ vector> vtlIgnoredDevices; //store drives from ingnore file
+
+ ifstream input( "ignoreDrives.conf" ); //read ingnore file
+
+ for(string sLine; getline( input, sLine );)
+ {
+ if (string(sLine).find("/dev/sd") != string::npos)
+ {
+ size_t pos = 0;
+ string token;
+ while ((pos = sLine.find(sDelimiter)) != string::npos)
+ {
+ token = sLine.substr(0, pos);
+ sIgnoredDrivePath = token;
+ sLine.erase(0, pos + sDelimiter.length());
+ sIgnoredDriveUUID = sLine;
+ } //end while
+ //cout << "Path: " << sIgnoredDrivePath << std::endl;
+ //cout << "UUID: " << sIgnoredDriveUUID << std::endl;
+ vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ingnore file to vector
+ }
+ }
+
+ //loop through found entries in ingnore file
+ for(auto row : vtlIgnoredDevices)
+ {
+ //cout << get<0>(row) << " is " << get<1>(row) << endl;
+ list ::iterator it;
+ // loop through found drives
+ for (it = listDrives->begin(); it != listDrives->end(); ++it)
+ {
+ string sUUID;
+ if (!get<0>(row).compare(it->sPath)) //find same drive based on path
+ {
+ // cout << "Same drive path found" << endl;
+ char * cLine = NULL;
+ size_t len = 0;
+ string sCMD = "./blkid ";
+ sCMD.append(it->sPath);
+ // cout << "cmd: " << sCMD << endl;
+ FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
+ if (outputfileBlkid == NULL)
+ {
+ exit(EXIT_FAILURE);
+ }
+
+ while ((getline(&cLine, &len, outputfileBlkid)) != -1) //parse UUID from blkid
+ {
+ if (string(cLine).find("PTUUID") != string::npos)
+ {
+ string sBlkidOut = string(cLine);
+ sBlkidOut.erase(0, 18);
+ sBlkidOut.erase(36, sBlkidOut.length() - 36);
+ sUUID = sBlkidOut;
+ //cout << "blkid uuid:" << sUUID << endl;
+ }
+ }
+ fclose(outputfileBlkid);
+ //cout << "blkid uuid:" << sUUID << endl;
+
+ if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
+ {
+ cout << "[ERROR] different uuid found than in ignore file:" << it->sPath << endl;
+ exit(EXIT_FAILURE); // exit to prevent accidentally shred a system drive
+ }
+ else
+ {
+ // same uuid found than in ignore file --> ignore this drive
+ it = listDrives->erase(it);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * \brief print drives with all information
+ * \param pointer of list *listDrives
+ * \return void
+ */
+void App::printDrives(list *listDrives)
+{
+ cout << "------------DRIVES---------------" << endl;
+ list ::iterator it;
+ for (it = listDrives->begin(); it != listDrives->end(); ++it)
+ {
+ cout << "Path: " << it->sPath << endl;
+ cout << "Model: " << it->sModel << endl;
+ cout << "Manufacturer: " << it->sManufacturer << endl;
+ cout << "Capacity: " << it->sCapacity << endl;
+ cout << "Serial: " << it->sSerial << endl;
+ cout << "PowerOnHours: " << it->u32PowerOnHours << endl;
+ cout << "SpinUpCount: " << it->u32SpinUpCount << endl;
+ cout << "ErrorCount: " << it->u32ErrorCount << endl;
+ cout << endl;
+ }
+ cout << "---------------------------------" << endl;
+}
diff --git a/src/app.h b/src/app.h
new file mode 100644
index 0000000..062ce73
--- /dev/null
+++ b/src/app.h
@@ -0,0 +1,34 @@
+/**
+ * @file app.h
+ * @brief app logic
+ * @author hendrik schutter
+ * @date 01.05.2020
+ */
+
+#ifndef APP_H_
+#define APP_H_
+
+#include "refurbishingHddTool.h"
+#include "drive.h"
+
+class App {
+protected:
+
+
+public:
+ App(void);
+ void app_logic();
+
+private:
+
+ list listDrives; //stores all drive data
+
+ void searchDrives(list *listDrives);
+ void printDrives(list *listDrives);
+ void filterIgnoredDrives(list *listDrives);
+};
+
+
+
+
+#endif // APP_H_
\ No newline at end of file
diff --git a/src/blkid b/src/blkid
new file mode 100755
index 0000000..ba5906d
Binary files /dev/null and b/src/blkid differ
diff --git a/src/drive.cpp b/src/drive.cpp
new file mode 100644
index 0000000..95bd3d2
--- /dev/null
+++ b/src/drive.cpp
@@ -0,0 +1,13 @@
+/**
+ * @file drive.cpp
+ * @brief
+ * @author hendrik schutter
+ * @date
+ */
+
+#include "drive.h"
+
+Drive::Drive(void) {
+ cout << "created drive" << endl;
+}
+
diff --git a/src/drive.h b/src/drive.h
new file mode 100644
index 0000000..65bd343
--- /dev/null
+++ b/src/drive.h
@@ -0,0 +1,40 @@
+/**
+ * @file drive.h
+ * @brief represent
+ * @author hendrik schutter
+ * @date 16.12.2017
+ */
+
+#ifndef DRIVE_H_
+#define DRIVE_H_
+
+#include "refurbishingHddTool.h"
+
+
+struct drive
+{
+ string sPath;
+ string sManufacturer;
+ string sModel;
+ string sSerial;
+ string sCapacity;
+ uint32_t u32ErrorCount;
+ uint32_t u32PowerOnHours;
+ uint32_t u32SpinUpCount;
+};
+
+
+class Drive {
+protected:
+
+
+public:
+ Drive(void);
+
+};
+
+
+
+
+
+#endif // DRIVE_H_
\ No newline at end of file
diff --git a/src/drives.cpp b/src/drives.cpp
deleted file mode 100644
index e69de29..0000000
diff --git a/src/hwinfo b/src/hwinfo
new file mode 100755
index 0000000..a509a53
Binary files /dev/null and b/src/hwinfo differ
diff --git a/src/ignoreDrives.conf b/src/ignoreDrives.conf
new file mode 100644
index 0000000..aef73e8
--- /dev/null
+++ b/src/ignoreDrives.conf
@@ -0,0 +1,3 @@
+/dev/sda:508ef27d-5039-4e8b-9e2c-22d7528b7149
+/dev/sdb:07f4ad14-c4b6-46e7-9cdf-3cfa9841d53d
+/dev/sdc:4673974d-1af2-44fd-996b-a2d8e4c43d9a
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..35e4398
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,25 @@
+/**
+ * @file main.cpp
+ * @brief app entry point
+ * @author hendrik schutter
+ * @date 01.05.2020
+ */
+
+#include "refurbishingHddTool.h"
+#include "app.h"
+
+
+/**
+ * \brief app entry point
+ * \param void
+ * \return Status-Code
+ */
+int main(void)
+{
+ cout << "refurbishingHddTool" << endl;
+
+ App* app = new App();
+ app->app_logic();
+
+ return EXIT_SUCCESS;
+}
\ No newline at end of file
diff --git a/src/mainTest.cpp b/src/mainTest.cpp
index ce80899..330705e 100644
--- a/src/mainTest.cpp
+++ b/src/mainTest.cpp
@@ -1,110 +1,49 @@
-
-#include
-#include
-#include
-#include
-
-using namespace std;
-
-struct deviceData{
- string model;
- string manufacturer;
- short rotationRate; //in rpm
- short capacity; //in Gigabytes
-};
-
-
-
-string removeLastNewLine(string s);
-deviceData getDeviceData(string path);
-
-
-
/*
- *
- * clear && g++ -Wall -o test mainTest.cpp
- *
- */
-int main(void)
-{
- cout << "Hello World!\n";
-
-
- char * cLine = NULL;
- string path;
- size_t len = 0;
-
- int loop = 0;
-
- int devicesSize = 0;
-
- string devices[5];
-
-
- FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r");
-
- if (outputfileHwinfo == NULL) {
- exit(EXIT_FAILURE);
- }
-
- while ((getline(&cLine, &len, outputfileHwinfo)) != -1) {
-
- if(loop > 0) {
-
- string line = string(cLine);
-
- path = line.substr (2,8);
-
- devices[devicesSize] = path;
-
- devicesSize++;
- }
-
- loop++;
- }
-
- fclose(outputfileHwinfo);
-
-
-
- cout << "Model: " << getDeviceData(devices[0]) << endl;
-
-
-
- return 0;
-}
deviceData getDeviceData(string path) {
+
+
+ struct deviceData hdd;
+
+
+
size_t len = 0; //lenght of found line
char * cLine = NULL; //found line
- string comand = ("smartctl -a " + path);
+ string comand = ("./smartctl -a " + path);
const char *cComand = comand.c_str();
-
+
FILE* outputfileSmart = popen(cComand, "r");
+
+
while ((getline(&cLine, &len, outputfileSmart)) != -1) {
+
+
string line = string(cLine);
+
+ cout << line << "XYZ\n";
+
string search ("Device Model:");
-
+
size_t found = line.find(search);
-
+
if (found!=string::npos) {
-
+
int lenght = line.length(); //lenght of line
string str3 (":");
found = line.find(str3);
- //cout << "Found1: " << found << endl;
+ cout << "Found1: " << found << endl;
for(int i = (found+1); i < lenght; i++) {
if(line[i] != ' ') {
- // cout << i << endl;
+ cout << i << endl;
found = i;
break;
}
@@ -117,17 +56,17 @@ deviceData getDeviceData(string path) {
model = removeLastNewLine(model);
- // cout << model << endl;
+ cout << model << endl;
- return model;
+ return hdd;
}
}
-
+
fclose(outputfileSmart);
- return "error";
+ return hdd;
}
@@ -139,3 +78,4 @@ string removeLastNewLine(string s) {
}
return s;
}
+*/
\ No newline at end of file
diff --git a/src/mainTest.cpp.orig b/src/mainTest.cpp.orig
deleted file mode 100644
index 3d3f0d4..0000000
--- a/src/mainTest.cpp.orig
+++ /dev/null
@@ -1,133 +0,0 @@
-
-#include
-#include
-#include
-#include
-
-using namespace std;
-
-
-string removeLastNewLine(string s);
-string getModel(string path);
-
-/*
- *
- * g++ -Wall -o cctv_radar cctv_radar.cpp mcp3008Spi.cpp logger.cpp libftpclient.a -lcurl -lwiringPi -pthread
- *
- */
-int main(void)
-{
- cout << "Hello World!\n";
-
-
- char * cLine = NULL;
- string path;
- size_t len = 0;
-
- int loop = 0;
-
- int devicesSize = 0;
-
- string devices[5];
-
-
- FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r");
-
- if (outputfileHwinfo == NULL) {
- exit(EXIT_FAILURE);
- }
-
- while ((getline(&cLine, &len, outputfileHwinfo)) != -1) {
-
- if(loop > 0) {
-
- string line = string(cLine);
-
- path = line.substr (2,8);
-
- devices[devicesSize] = path;
-
- devicesSize++;
- }
-
- loop++;
- }
-
- fclose(outputfileHwinfo);
-
-
-
-cout << "Model: " << getModel(devices[0]) << endl;
-
-
-
- return 0;
-}
-
-string getModel(string path){
-
- size_t len = 0;
-
- char * cLine = NULL;
-
- string comand = ("smartctl -a " + path);
- const char *cComand = comand.c_str();
-
- FILE* outputfileSmart = popen(cComand, "r");
-
- while ((getline(&cLine, &len, outputfileSmart)) != -1) {
-
- string line = string(cLine);
-
- //cout << line << endl;
-
- string str2 ("Device Model:");
- size_t found = line.find(str2);
- if (found!=string::npos) {
- // cout << "Device Model: at: " << found << '\n';
- // cout << line << endl;
-
- int size = line.length();
-
-
- string str3 (":");
- found = line.find(str3);
-
- //cout << "Found1: " << found << endl;
-
- for(int i = (found+1); i < size; i++) {
-
- if(line[i] != ' ') {
- // cout << i << endl;
- found = i;
- break;
- }
-
- }
-
-
-
- string model = line.substr (found, size);
-
- model = removeLastNewLine(model);
-
- // cout << model << endl;
-
- return model;
-
- }
-
- }
-
- return "error";
-
-}
-
-
-
-string removeLastNewLine(string s) {
- if (!s.empty() && s[s.length()-1] == '\n') {
- s.erase(s.length()-1);
- }
- return s;
-}
diff --git a/src/makefile b/src/makefile
new file mode 100644
index 0000000..8e669ea
--- /dev/null
+++ b/src/makefile
@@ -0,0 +1,14 @@
+refurbishingHddTool: main.o app.o drive.o
+ g++ -Wall -o refurbishingHddTool main.o app.o drive.o
+
+main.o: main.cpp
+ g++ -c main.cpp
+
+app.o: app.cpp
+ g++ -c app.cpp
+
+drive.o: drive.cpp
+ g++ -c drive.cpp
+
+clean :
+ rm refurbishingHddTool main.o app.o drive.o
diff --git a/src/refurbishingHddTool b/src/refurbishingHddTool
new file mode 100755
index 0000000..f328664
Binary files /dev/null and b/src/refurbishingHddTool differ
diff --git a/src/refurbishingHddTool.h b/src/refurbishingHddTool.h
index e69de29..246dd1c 100644
--- a/src/refurbishingHddTool.h
+++ b/src/refurbishingHddTool.h
@@ -0,0 +1,21 @@
+/**
+ * @file refurbishingHddTool.h
+ * @brief represent
+ * @author hendrik schutter
+ * @date 01.05.2020
+ */
+
+#ifndef REFURBISHING_HDD_TOOL_H_
+#define REFURBISHING_HDD_TOOL_H_
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+
+#endif // REFURBISHING_HDD_TOOL_H_
\ No newline at end of file
diff --git a/src/smartctl b/src/smartctl
new file mode 100755
index 0000000..f1bac60
Binary files /dev/null and b/src/smartctl differ
diff --git a/src/test b/src/test
deleted file mode 100755
index 172a8e6..0000000
Binary files a/src/test and /dev/null differ
diff --git a/vcCodium.code-workspace b/vcCodium.code-workspace
new file mode 100644
index 0000000..876a149
--- /dev/null
+++ b/vcCodium.code-workspace
@@ -0,0 +1,8 @@
+{
+ "folders": [
+ {
+ "path": "."
+ }
+ ],
+ "settings": {}
+}
\ No newline at end of file