able to find all devices in /dev/
This commit is contained in:
parent
bfc7b8ca5d
commit
20cfc44b51
|
@ -8,7 +8,7 @@
|
||||||
## planned Features:
|
## planned Features:
|
||||||
|
|
||||||
* search for new attached Hard Drives via USB
|
* 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
|
* Check S.M.A.R.T. values and make an 'passed' or 'not passed' decision
|
||||||
* If passed, wipe the data securely
|
* If passed, wipe the data securely
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,133 @@
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue