copy newer S.M.A.R.T. values to existing drive

This commit is contained in:
Hendrik Schutter 2022-08-24 16:11:36 +02:00
parent 2df5ceb0c8
commit 69fd10207d
3 changed files with 30 additions and 25 deletions

View File

@ -37,19 +37,22 @@ public:
private: private:
string sPath; string sPath;
string sModelFamily;
string sModelName;
string sSerial;
uint64_t u64Capacity = 0U; //in byte
uint32_t u32ErrorCount = 0U;
uint32_t u32PowerOnHours = 0U; //in hours
uint32_t u32PowerCycles = 0U;
uint32_t u32Temperature = 0U; //in Fahrenheit, just kidding: degree Celsius
time_t u32Timestamp = 0U; //unix timestamp for detecting a frozen drive time_t u32Timestamp = 0U; //unix timestamp for detecting a frozen drive
double d32TaskPercentage = 0U; //in percent for Shred (1 to 100) double d32TaskPercentage = 0U; //in percent for Shred (1 to 100)
time_t u32TimestampTaskStart = 0U; //unix timestamp for duration of an action time_t u32TimestampTaskStart = 0U; //unix timestamp for duration of an action
time_t u32TaskDuration = 0U; //time needed to complete the task time_t u32TaskDuration = 0U; //time needed to complete the task
struct
{
string sModelFamily;
string sModelName;
string sSerial;
uint64_t u64Capacity = 0U; //in byte
uint32_t u32ErrorCount = 0U;
uint32_t u32PowerOnHours = 0U; //in hours
uint32_t u32PowerCycles = 0U;
uint32_t u32Temperature = 0U; //in Fahrenheit, just kidding: degree Celsius
} sSmartData;
private: private:
void setTimestamp(); void setTimestamp();

View File

@ -14,41 +14,41 @@ string Drive::getPath(void)
string Drive::getModelFamily(void) string Drive::getModelFamily(void)
{ {
return sModelFamily; return sSmartData.sModelFamily;
} }
string Drive::getModelName(void) string Drive::getModelName(void)
{ {
return sModelName; return sSmartData.sModelName;
} }
string Drive::getSerial(void) string Drive::getSerial(void)
{ {
return sSerial; return sSmartData.sSerial;
} }
uint64_t Drive::getCapacity(void) uint64_t Drive::getCapacity(void)
{ {
return u64Capacity; return sSmartData.u64Capacity;
} }
uint32_t Drive::getErrorCount(void) uint32_t Drive::getErrorCount(void)
{ {
return u32ErrorCount; return sSmartData.u32ErrorCount;
} }
uint32_t Drive::getPowerOnHours(void) uint32_t Drive::getPowerOnHours(void)
{ {
return u32PowerOnHours; return sSmartData.u32PowerOnHours;
} }
uint32_t Drive::getPowerCycles(void) uint32_t Drive::getPowerCycles(void)
{ {
return u32PowerCycles; return sSmartData.u32PowerCycles;
} }
uint32_t Drive::getTemperature(void) uint32_t Drive::getTemperature(void)
{ {
return u32Temperature; return sSmartData.u32Temperature;
} }
string Drive::sCapacityToText() string Drive::sCapacityToText()
@ -124,6 +124,7 @@ double Drive::getTaskPercentage(void)
* \param uint32_t errorCount * \param uint32_t errorCount
* \param uint32_t powerOnHours * \param uint32_t powerOnHours
* \param uint32_t powerCycle * \param uint32_t powerCycle
* \param uint32_t temperature
* \return void * \return void
*/ */
void Drive::setDriveSMARTData( string modelFamily, void Drive::setDriveSMARTData( string modelFamily,
@ -135,15 +136,14 @@ void Drive::setDriveSMARTData( string modelFamily,
uint32_t powerCycle, uint32_t powerCycle,
uint32_t temperature) uint32_t temperature)
{ {
this->sModelFamily = modelFamily; this->sSmartData.sModelFamily = modelFamily;
sModelName = modelName; this->sSmartData.sModelName = modelName;
sSerial = serial; this->sSmartData.sSerial = serial;
u64Capacity = capacity; this->sSmartData.u64Capacity = capacity;
u32ErrorCount = errorCount; this->sSmartData.u32ErrorCount = errorCount;
u32PowerOnHours = powerOnHours; this->sSmartData.u32PowerOnHours = powerOnHours;
u32PowerCycles = powerCycle; this->sSmartData.u32PowerCycles = powerCycle;
u32Temperature = temperature; this->sSmartData.u32Temperature = temperature;
} }
void Drive::setTimestamp() void Drive::setTimestamp()

View File

@ -264,6 +264,8 @@ void reHDD::filterNewDrives(list <Drive>* plistOldDrives, list <Drive>* plistNew
if((itOld->getSerial() == itNew->getSerial()) || (itOld->getPath() == itNew->getPath())) if((itOld->getSerial() == itNew->getSerial()) || (itOld->getPath() == itNew->getPath()))
{ {
itOld->bIsOffline = false; //drive is still attached itOld->bIsOffline = false; //drive is still attached
//copy new smart data to existing drive
itOld->setDriveSMARTData(itNew->getModelFamily(), itNew->getModelName(), itNew->getSerial(), itNew->getCapacity(), itNew->getErrorCount(), itNew->getPowerOnHours(), itNew->getPowerCycles(), itNew->getTemperature());
#ifdef LOG_LEVEL_HIGH #ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName()); Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName());
#endif #endif