support smartctl usb contoller options
This commit is contained in:
parent
aa7ddf8b36
commit
0ad7de4352
@ -20,6 +20,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
SMART(void);
|
SMART(void);
|
||||||
|
|
||||||
|
static uint8_t parseExitStatus(string sLine);
|
||||||
static void parseModelFamily(string sLine);
|
static void parseModelFamily(string sLine);
|
||||||
static void parseModelName(string sLine);
|
static void parseModelName(string sLine);
|
||||||
static void parseSerial(string sLine);
|
static void parseSerial(string sLine);
|
||||||
|
@ -32,19 +32,25 @@ void SMART::readSMARTData(Drive* drive)
|
|||||||
powerCycle = 0U;
|
powerCycle = 0U;
|
||||||
temperature = 0U;
|
temperature = 0U;
|
||||||
|
|
||||||
size_t len = 0; //lenght of found line
|
string sSmartctlCommands[] = {" --json -a ", " --json -d sntjmicron -a ", " --json -d sntasmedia -a ", " --json -d sntrealtek -a "};
|
||||||
char* cLine = NULL; //found line
|
|
||||||
|
|
||||||
string sCMD = ("smartctl --json -a ");
|
for (string sSmartctlCommand : sSmartctlCommands)
|
||||||
|
{
|
||||||
|
string sCMD = ("smartctl");
|
||||||
|
sCMD.append(sSmartctlCommand);
|
||||||
sCMD.append(drive->getPath());
|
sCMD.append(drive->getPath());
|
||||||
const char *cpComand = sCMD.c_str();
|
const char *cpComand = sCMD.c_str();
|
||||||
|
|
||||||
FILE *outputfileSmart = popen(cpComand, "r");
|
FILE *outputfileSmart = popen(cpComand, "r");
|
||||||
|
size_t len = 0; // length of found line
|
||||||
|
char *cLine = NULL; // found line
|
||||||
|
uint8_t status = 255;
|
||||||
|
|
||||||
while ((getline(&cLine, &len, outputfileSmart)) != -1)
|
while ((getline(&cLine, &len, outputfileSmart)) != -1)
|
||||||
{
|
{
|
||||||
string sLine = string(cLine);
|
string sLine = string(cLine);
|
||||||
|
|
||||||
|
status = SMART::parseExitStatus(sLine);
|
||||||
SMART::parseModelFamily(sLine);
|
SMART::parseModelFamily(sLine);
|
||||||
SMART::parseModelName(sLine);
|
SMART::parseModelName(sLine);
|
||||||
SMART::parseSerial(sLine);
|
SMART::parseSerial(sLine);
|
||||||
@ -54,10 +60,37 @@ void SMART::readSMARTData(Drive* drive)
|
|||||||
SMART::parsePowerCycle(sLine);
|
SMART::parsePowerCycle(sLine);
|
||||||
SMART::parseTemperature(sLine);
|
SMART::parseTemperature(sLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
pclose(outputfileSmart);
|
pclose(outputfileSmart);
|
||||||
|
|
||||||
|
if (status == 0U)
|
||||||
|
{
|
||||||
|
//Found S.M.A.R.T. data with this command
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle, temperature); // wirte data in drive
|
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle, temperature); // wirte data in drive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse ExitStatus
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return uint_8 exit status
|
||||||
|
*/
|
||||||
|
uint8_t SMART::parseExitStatus(string sLine)
|
||||||
|
{
|
||||||
|
uint8_t exitStatus = -1;
|
||||||
|
string search("\"exit_status\": ");
|
||||||
|
size_t found = sLine.find(search);
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
sLine.erase(0, sLine.find(": ") + 1);
|
||||||
|
exitStatus = stol(sLine);
|
||||||
|
}
|
||||||
|
return exitStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief parse ModelFamiliy
|
* \brief parse ModelFamiliy
|
||||||
* \param string output line of smartctl
|
* \param string output line of smartctl
|
||||||
@ -157,7 +190,6 @@ void SMART::parsePowerOnHours(string sLine)
|
|||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length() - 1, 1);
|
sLine.erase(sLine.length() - 1, 1);
|
||||||
powerOnHours = stol(sLine);
|
powerOnHours = stol(sLine);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +207,6 @@ void SMART::parsePowerCycle(string sLine)
|
|||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length() - 2, 2);
|
sLine.erase(sLine.length() - 2, 2);
|
||||||
powerCycle = stol(sLine);
|
powerCycle = stol(sLine);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +225,7 @@ void SMART::parseTemperature(string sLine)
|
|||||||
sLine.erase(sLine.length() - 1, 2);
|
sLine.erase(sLine.length() - 1, 2);
|
||||||
if (sLine == "{")
|
if (sLine == "{")
|
||||||
{
|
{
|
||||||
temperature = 0U; // this drive doesn't support temperatur
|
temperature = 0U; // this drive doesn't support temperature
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user