diff --git a/README.md b/README.md index 3c43fa4..0da769b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## planned Features: * search for new attached Hard Drives via USB -* display Hard Drive Manufacturer, Model, Spin Speed and Capacity +* display Hard Drive Manufacturer, Model, Rotation Rate and Capacity * Check S.M.A.R.T. values and make an 'passed' or 'not passed' decision * If passed, wipe the data securely diff --git a/src/drives.cpp b/src/drives.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/mainTest.cpp b/src/mainTest.cpp new file mode 100644 index 0000000..ce80899 --- /dev/null +++ b/src/mainTest.cpp @@ -0,0 +1,141 @@ + +#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) { + + size_t len = 0; //lenght of found line + char * cLine = NULL; //found line + + 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); + 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; + + for(int i = (found+1); i < lenght; i++) { + + if(line[i] != ' ') { + // cout << i << endl; + found = i; + break; + } + + } + + + + string model = line.substr (found, lenght); + + model = removeLastNewLine(model); + + // cout << model << endl; + + return model; + + } + + } + + fclose(outputfileSmart); + + 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/mainTest.cpp.orig b/src/mainTest.cpp.orig new file mode 100644 index 0000000..3d3f0d4 --- /dev/null +++ b/src/mainTest.cpp.orig @@ -0,0 +1,133 @@ + +#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/refurbishingHddTool.h b/src/refurbishingHddTool.h new file mode 100644 index 0000000..e69de29 diff --git a/src/smart.cpp b/src/smart.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/test b/src/test new file mode 100755 index 0000000..172a8e6 Binary files /dev/null and b/src/test differ diff --git a/src/wipe.cpp b/src/wipe.cpp new file mode 100644 index 0000000..e69de29