diff --git a/src/core/smartattributeparseddata.cpp b/src/core/smartattributeparseddata.cpp index 8c195cd..3de8344 100644 --- a/src/core/smartattributeparseddata.cpp +++ b/src/core/smartattributeparseddata.cpp @@ -33,6 +33,10 @@ static const QMap tableUnit(); static SmartAttributeParsedData::SmartQuirk getQuirk(QString model, QString firmware); +/** Creates a new SmartAttributeParsedData object. + @param disk the reference to the disk that this attribute is allocated to + @param jsonAttribute JSON attribute data +*/ SmartAttributeParsedData::SmartAttributeParsedData(SmartDiskInformation *disk, QJsonObject jsonAttribute) : m_Id(0), @@ -93,6 +97,8 @@ SmartAttributeParsedData::SmartAttributeParsedData(SmartDiskInformation *disk, } } +/** @param other SmartAttributeParsedData to copy +*/ SmartAttributeParsedData::SmartAttributeParsedData(const SmartAttributeParsedData &other) : m_Id(other.id()), m_CurrentValue(other.currentValue()), @@ -117,6 +123,7 @@ SmartAttributeParsedData::SmartAttributeParsedData(const SmartAttributeParsedDat } +/** Validate values from the current attribute */ void SmartAttributeParsedData::validateValues() { m_CurrentValueValid = m_CurrentValue >= 1 && m_CurrentValue <= 0xFD; @@ -137,6 +144,7 @@ void SmartAttributeParsedData::validateValues() m_Warn = (m_GoodNowValid && !m_GoodNow) || (m_GoodInThePastValid && !m_GoodInThePast); } +/** Make a pretty value from raw based on attribute's id */ void SmartAttributeParsedData::makePretty() { if (m_PrettyUnit == SMART_ATTRIBUTE_UNIT_UNKNOWN) @@ -206,6 +214,7 @@ void SmartAttributeParsedData::makePretty() } } +/** Verify attribute's unit */ void SmartAttributeParsedData::verifyAttribute() { if (id() == 3 || id() == 226) diff --git a/src/core/smartattributeparseddata.h b/src/core/smartattributeparseddata.h index 2868fb7..d11a6bb 100644 --- a/src/core/smartattributeparseddata.h +++ b/src/core/smartattributeparseddata.h @@ -23,9 +23,17 @@ class SmartDiskInformation; +/** A SMART parsed attribute. + + It receives the attribute data from JSON, retrieve its data and validates its values. + + @author Caio Carvalho +*/ class SmartAttributeParsedData { public: + + /** A unit for SMART attributes */ enum SmartAttributeUnit { SMART_ATTRIBUTE_UNIT_UNKNOWN, SMART_ATTRIBUTE_UNIT_NONE, @@ -38,6 +46,7 @@ public: _SMART_ATTRIBUTE_UNIT_MAX }; + /** SMART Quirk */ enum SmartQuirk { SMART_QUIRK_9_POWERONMINUTES = 0x000001, SMART_QUIRK_9_POWERONSECONDS = 0x000002, @@ -63,6 +72,7 @@ public: SMART_QUIRK_3_UNUSED = 0x200000 }; + /** SMART Quirk to some particular model and firmware */ struct SmartQuirkDataBase { const char *model; const char *firmware; @@ -77,92 +87,92 @@ public: public: quint32 id() const { - return m_Id; + return m_Id; /**< @return attribute id */ } qint32 currentValue() const { - return m_CurrentValue; + return m_CurrentValue; /**< @return attribute current value */ } qint32 worstValue() const { - return m_WorstValue; + return m_WorstValue; /**< @return attribute worst value */ } qint32 threshold() const { - return m_Threshold; + return m_Threshold; /**< @return attribute threshold value */ } bool prefailure() const { - return m_Prefailure; + return m_Prefailure; /**< @return attribute prefailure status */ } bool online() const { - return m_Online; + return m_Online; /**< @return attribute online status */ } quint64 raw() const { - return m_Raw; + return m_Raw; /**< @return attribute raw value */ } quint64 prettyValue() const { - return m_PrettyValue; + return m_PrettyValue; /**< @return attribute pretty value */ } SmartAttributeUnit prettyUnit() const { - return m_PrettyUnit; + return m_PrettyUnit; /**< @return pretty unit value */ } bool goodNowValid() const { - return m_GoodNowValid; + return m_GoodNowValid; /**< @return good now attribute status validation */ } bool goodNow() const { - return m_GoodNow; + return m_GoodNow; /**< @return good now attribute status */ } bool goodInThePastValid() const { - return m_GoodInThePastValid; + return m_GoodInThePastValid; /**< @return good in the past attribute status validation */ } bool goodInThePast() const { - return m_GoodInThePast; + return m_GoodInThePast; /**< @return good in the past attribute status */ } bool thresholdValid() const { - return m_ThresholdValid; + return m_ThresholdValid; /**< @return threshold value validation */ } bool currentValueValid() const { - return m_CurrentValueValid; + return m_CurrentValueValid; /**< @return current value validation */ } bool worstValueValid() const { - return m_WorstValueValid; + return m_WorstValueValid; /**< @return worst value validation */ } bool warn() const { - return m_Warn; + return m_Warn; /**< @return warn status */ } SmartDiskInformation *disk() const { - return m_Disk; + return m_Disk; /**< @return attribute's disk reference */ } protected: diff --git a/src/core/smartdiskinformation.cpp b/src/core/smartdiskinformation.cpp index b220279..f227692 100644 --- a/src/core/smartdiskinformation.cpp +++ b/src/core/smartdiskinformation.cpp @@ -20,6 +20,7 @@ static quint64 u64log2(quint64 n); +/** Creates a new SmartDiskInformationObject */ SmartDiskInformation::SmartDiskInformation() : m_ModelName(QString()), m_FirmwareVersion(QString()), @@ -38,6 +39,7 @@ SmartDiskInformation::SmartDiskInformation() : } +/** Update the number of bad sectors based on reallocated sector count and current pending sector attributes data */ void SmartDiskInformation::updateBadSectors() { SmartAttributeParsedData *reallocatedSectorCt; @@ -56,6 +58,7 @@ void SmartDiskInformation::updateBadSectors() m_BadSectors = currentPendingSector->prettyValue(); } +/** Update SMART overall data based on the quantity of bad sectors and the status of SMART attributes */ void SmartDiskInformation::updateOverall() { if (!smartStatus()) { @@ -91,6 +94,9 @@ void SmartDiskInformation::updateOverall() } +/** Update the temperature value based on SMART attributes + @return a boolean representing the status of the operation +*/ bool SmartDiskInformation::updateTemperature() { SmartAttributeParsedData *temperatureCelsius; @@ -118,6 +124,9 @@ bool SmartDiskInformation::updateTemperature() return false; } +/** Update the powered on value based on SMART attributes + @return a boolean representing the status of the operation +*/ bool SmartDiskInformation::updatePowerOn() { SmartAttributeParsedData *powerOnHours; @@ -138,6 +147,9 @@ bool SmartDiskInformation::updatePowerOn() return false; } +/** Update the power cycles value based on SMART attributes + @return a boolean representing the status of the operation +*/ bool SmartDiskInformation::updatePowerCycle() { SmartAttributeParsedData *powerCycleCount; @@ -152,6 +164,7 @@ bool SmartDiskInformation::updatePowerCycle() return false; } +/** Validate disk attributes status */ void SmartDiskInformation::validateBadAttributes() { for (const SmartAttributeParsedData &attribute : qAsConst(m_Attributes)) { @@ -164,6 +177,9 @@ void SmartDiskInformation::validateBadAttributes() } } +/** Search for a attribute based on its id number + @return a reference to the attribute +*/ SmartAttributeParsedData *SmartDiskInformation::findAttribute(quint32 id) { SmartAttributeParsedData *attr = nullptr; diff --git a/src/core/smartdiskinformation.h b/src/core/smartdiskinformation.h index 9c9ba4f..cc79cf0 100644 --- a/src/core/smartdiskinformation.h +++ b/src/core/smartdiskinformation.h @@ -23,9 +23,16 @@ class SmartAttributeParsedData; +/** Disk information retrieved by SMART. + + It includes a list with your SMART attributes. + + @author Caio Carvalho +*/ class SmartDiskInformation { public: + /** SMART self test execution state */ enum SmartSelfTestExecutionStatus { SMART_SELF_TEST_EXECUTION_STATUS_SUCCESS_OR_NEVER = 0, SMART_SELF_TEST_EXECUTION_STATUS_ABORTED = 1, @@ -40,6 +47,7 @@ public: _SMART_SELF_TEST_EXECUTION_STATUS_MAX }; + /** SMART overall state */ enum SmartOverall { SMART_OVERALL_GOOD, SMART_OVERALL_BAD_ATTRIBUTE_IN_THE_PAST, @@ -69,62 +77,62 @@ public: public: const QString model() const { - return m_ModelName; + return m_ModelName; /**< @return the disk model name */ } const QString firmware() const { - return m_FirmwareVersion; + return m_FirmwareVersion; /**< @return the disk firmware version */ } const QString serial() const { - return m_SerialNumber; + return m_SerialNumber; /**< @return the disk serial number */ } quint64 size() const { - return m_Size; + return m_Size; /**< @return disk size */ } bool smartStatus() const { - return m_SmartStatus; + return m_SmartStatus; /**< @return a boolean representing SMART status */ } SmartSelfTestExecutionStatus selfTestExecutionStatus() const { - return m_SelfTestExecutionStatus; + return m_SelfTestExecutionStatus; /**< @return SMART self execution status */ } SmartOverall overall() const { - return m_Overall; + return m_Overall; /**< @return SMART overall status */ } quint64 temperature() const { - return m_Temperature; + return m_Temperature; /**< @return disk temperature in kelvin */ } quint64 badSectors() const { - return m_BadSectors; + return m_BadSectors; /**< @return the number of bad sectors */ } quint64 poweredOn() const { - return m_PoweredOn; + return m_PoweredOn; /**< @return quantity of time that device is powered on */ } quint64 powerCycles() const { - return m_PowerCycles; + return m_PowerCycles; /**< @return quantity of power cycles */ } QList attributes() const { - return m_Attributes; + return m_Attributes; /**< @return a list that contains the disk SMART attributes */ } public: diff --git a/src/core/smartparser.cpp b/src/core/smartparser.cpp index cfe1f5f..5e4716a 100644 --- a/src/core/smartparser.cpp +++ b/src/core/smartparser.cpp @@ -28,6 +28,9 @@ #include #include +/** Creates a new SmartParser object + @param device_path device path that indicates the device that SMART must analyse +*/ SmartParser::SmartParser(const QString &device_path) : m_DevicePath(device_path), m_DiskInformation(nullptr) @@ -35,6 +38,7 @@ SmartParser::SmartParser(const QString &device_path) : } +/** Initialize SmartParser data, retrieve the information from SMART JSON and initialize the disk information data */ bool SmartParser::init() { loadSmartOutput(); @@ -107,6 +111,7 @@ bool SmartParser::init() return true; } +/** Run smartctl command and recover its output */ void SmartParser::loadSmartOutput() { if (m_SmartOutput.isEmpty()) { @@ -122,6 +127,7 @@ void SmartParser::loadSmartOutput() } } +/** Load SMART disk attributes from JSON data */ void SmartParser::loadAttributes() { loadSmartOutput(); diff --git a/src/core/smartparser.h b/src/core/smartparser.h index 7a199fa..6160492 100644 --- a/src/core/smartparser.h +++ b/src/core/smartparser.h @@ -23,6 +23,12 @@ class SmartDiskInformation; +/** A parser to SMART JSON output. + + Responsable to execute smartctl and parse its output. + + @author Caio Carvalho +*/ class SmartParser { public: @@ -34,12 +40,12 @@ public: public: const QString &devicePath() const { - return m_DevicePath; + return m_DevicePath; /**< @return the device path that SMART must analyse */ } SmartDiskInformation *diskInformation() const { - return m_DiskInformation; + return m_DiskInformation; /**< @return a reference to parsed disk information */ } protected: