diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 584c8b4..77cc332 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,49 +1,46 @@ set(CORE_SRC core/copysource.cpp core/copysourcedevice.cpp core/copysourcefile.cpp core/copysourceshred.cpp core/copytarget.cpp core/copytargetdevice.cpp core/copytargetfile.cpp core/device.cpp core/devicescanner.cpp core/diskdevice.cpp core/fstab.cpp core/lvmdevice.cpp core/operationrunner.cpp core/operationstack.cpp core/partition.cpp core/partitionalignment.cpp core/partitionnode.cpp core/partitionrole.cpp core/partitiontable.cpp core/smartstatus.cpp core/smartattribute.cpp core/smartparser.cpp core/smartattributeparseddata.cpp core/smartdiskinformation.cpp core/volumemanagerdevice.cpp ) set(CORE_LIB_HDRS core/device.h core/devicescanner.h core/diskdevice.h core/fstab.h core/lvmdevice.h core/operationrunner.h core/operationstack.h core/partition.h core/partitionalignment.h core/partitionnode.h core/partitionrole.h core/partitiontable.h core/smartattribute.h core/smartstatus.h - core/smartparser.h - core/smartattributeparseddata.h - core/smartdiskinformation.h core/volumemanagerdevice.h ) diff --git a/src/core/copysource.h b/src/core/copysource.h index f8f36b2..4e4f447 100644 --- a/src/core/copysource.h +++ b/src/core/copysource.h @@ -1,55 +1,53 @@ /************************************************************************* * Copyright (C) 2008 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(KPMCORE_COPYSOURCE_H) #define KPMCORE_COPYSOURCE_H #include class CopyTarget; class QString; /** Base class for something to copy from. Abstract base class for all copy sources. Used in combination with CopyTarget to implement moving, copying, backing up and restoring FileSystems. @see CopyTarget @author Volker Lanz */ class CopySource { Q_DISABLE_COPY(CopySource) protected: CopySource() {} virtual ~CopySource() {} public: virtual bool open() = 0; virtual QString path() const = 0; virtual qint64 length() const = 0; virtual bool overlaps(const CopyTarget& target) const = 0; virtual qint64 firstByte() const = 0; virtual qint64 lastByte() const = 0; - -private: }; #endif diff --git a/src/core/smartattribute.h b/src/core/smartattribute.h index d0d2e2a..08687d1 100644 --- a/src/core/smartattribute.h +++ b/src/core/smartattribute.h @@ -1,107 +1,105 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ -#if !defined(KPMCORE_SMARTATTRIBUTE_H) - +#ifndef KPMCORE_SMARTATTRIBUTE_H #define KPMCORE_SMARTATTRIBUTE_H #include "util/libpartitionmanagerexport.h" -#include "core/smartattributeparseddata.h" #include +class SmartAttributeParsedData; class LIBKPMCORE_EXPORT SmartAttribute { public: enum FailureType { PreFailure, OldAge }; enum UpdateType { Online, Offline }; enum Assessment { NotApplicable, Failing, HasFailed, Warning, Good }; public: SmartAttribute(const SmartAttributeParsedData& a); public: qint32 id() const { return m_Id; } const QString& name() const { return m_Name; } const QString& desc() const { return m_Desc; } FailureType failureType() const { return m_FailureType; } UpdateType updateType() const { return m_UpdateType; } qint32 current() const { return m_Current; } qint32 worst() const { return m_Worst; } qint32 threshold() const { return m_Threshold; } const QString& raw() const { return m_Raw; } Assessment assessment() const { return m_Assessment; } const QString& value() const { return m_Value; } QString assessmentToString() const { return assessmentToString(assessment()); } static QString assessmentToString(Assessment a); private: qint32 m_Id; QString m_Name; QString m_Desc; FailureType m_FailureType; UpdateType m_UpdateType; qint32 m_Current; qint32 m_Worst; qint32 m_Threshold; QString m_Raw; Assessment m_Assessment; QString m_Value; }; #endif - diff --git a/src/core/smartattributeparseddata.h b/src/core/smartattributeparseddata.h index ef3ed51..3f1a7fc 100644 --- a/src/core/smartattributeparseddata.h +++ b/src/core/smartattributeparseddata.h @@ -1,226 +1,226 @@ /************************************************************************* * Copyright (C) 2018 by Caio Carvalho * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ -#if !defined(KPMCORE_SMARTATTRIBUTEPARSEDDATA_H) +#ifndef KPMCORE_SMARTATTRIBUTEPARSEDDATA_H #define KPMCORE_SMARTATTRIBUTEPARSEDDATA_H #include #include 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, SMART_ATTRIBUTE_UNIT_MSECONDS, SMART_ATTRIBUTE_UNIT_SECTORS, SMART_ATTRIBUTE_UNIT_MKELVIN, SMART_ATTRIBUTE_UNIT_SMALL_PERCENT, SMART_ATTRIBUTE_UNIT_PERCENT, SMART_ATTRIBUTE_UNIT_MB, _SMART_ATTRIBUTE_UNIT_MAX }; /** SMART Quirk */ enum SmartQuirk { SMART_QUIRK_9_POWERONMINUTES = 0x000001, SMART_QUIRK_9_POWERONSECONDS = 0x000002, SMART_QUIRK_9_POWERONHALFMINUTES = 0x000004, SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT = 0x000008, SMART_QUIRK_193_LOADUNLOAD = 0x000010, SMART_QUIRK_194_10XCELSIUS = 0x000020, SMART_QUIRK_194_UNKNOWN = 0x000040, SMART_QUIRK_200_WRITEERRORCOUNT = 0x000080, SMART_QUIRK_201_DETECTEDTACOUNT = 0x000100, SMART_QUIRK_5_UNKNOWN = 0x000200, SMART_QUIRK_9_UNKNOWN = 0x000400, SMART_QUIRK_197_UNKNOWN = 0x000800, SMART_QUIRK_198_UNKNOWN = 0x001000, SMART_QUIRK_190_UNKNOWN = 0x002000, SMART_QUIRK_232_AVAILABLERESERVEDSPACE = 0x004000, SMART_QUIRK_233_MEDIAWEAROUTINDICATOR = 0x008000, SMART_QUIRK_225_TOTALLBASWRITTEN = 0x010000, SMART_QUIRK_4_UNUSED = 0x020000, SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR = 0x040000, SMART_QUIRK_227_TIMEWORKLOADHOSTREADS = 0x080000, SMART_QUIRK_228_WORKLOADTIMER = 0x100000, SMART_QUIRK_3_UNUSED = 0x200000 }; /** SMART Quirk to some particular model and firmware */ struct SmartQuirkDataBase { QString model; QString firmware; SmartAttributeParsedData::SmartQuirk quirk; SmartQuirkDataBase(const QString &m = QString(), const QString &f = QString(), SmartAttributeParsedData::SmartQuirk q = (SmartAttributeParsedData::SmartQuirk) 0) : model(m), firmware(f), quirk(q) { }; }; public: SmartAttributeParsedData(SmartDiskInformation *disk, QJsonObject jsonAttribute); SmartAttributeParsedData(const SmartAttributeParsedData &other); public: quint32 id() const { return m_Id; /**< @return attribute id */ } qint32 currentValue() const { return m_CurrentValue; /**< @return attribute current value */ } qint32 worstValue() const { return m_WorstValue; /**< @return attribute worst value */ } qint32 threshold() const { return m_Threshold; /**< @return attribute threshold value */ } bool prefailure() const { return m_Prefailure; /**< @return attribute prefailure status */ } bool online() const { return m_Online; /**< @return attribute online status */ } quint64 raw() const { return m_Raw; /**< @return attribute raw value */ } quint64 prettyValue() const { return m_PrettyValue; /**< @return attribute pretty value */ } SmartAttributeUnit prettyUnit() const { return m_PrettyUnit; /**< @return pretty unit value */ } bool goodNowValid() const { return m_GoodNowValid; /**< @return good now attribute status validation */ } bool goodNow() const { return m_GoodNow; /**< @return good now attribute status */ } bool goodInThePastValid() const { return m_GoodInThePastValid; /**< @return good in the past attribute status validation */ } bool goodInThePast() const { return m_GoodInThePast; /**< @return good in the past attribute status */ } bool thresholdValid() const { return m_ThresholdValid; /**< @return threshold value validation */ } bool currentValueValid() const { return m_CurrentValueValid; /**< @return current value validation */ } bool worstValueValid() const { return m_WorstValueValid; /**< @return worst value validation */ } bool warn() const { return m_Warn; /**< @return warn status */ } SmartDiskInformation *disk() const { return m_Disk; /**< @return attribute's disk reference */ } protected: void validateValues(); bool updateUnit(); void makePretty(); void verifyAttribute(); void verifyTemperature(); void verifyShortTime(); void verifyLongTime(); void verifySectors(); private: quint32 m_Id; qint32 m_CurrentValue; qint32 m_WorstValue; qint32 m_Threshold; quint64 m_Raw; quint64 m_PrettyValue; bool m_CurrentValueValid; bool m_WorstValueValid; bool m_ThresholdValid; bool m_Prefailure; bool m_Online; bool m_GoodNow; bool m_GoodNowValid; bool m_GoodInThePast; bool m_GoodInThePastValid; bool m_Warn; SmartAttributeUnit m_PrettyUnit; SmartDiskInformation *m_Disk; SmartQuirk m_Quirk; }; #endif // SMARTATTRIBUTEPARSEDDATA_H diff --git a/src/core/smartdiskinformation.h b/src/core/smartdiskinformation.h index 572168b..996c2fc 100644 --- a/src/core/smartdiskinformation.h +++ b/src/core/smartdiskinformation.h @@ -1,200 +1,200 @@ /************************************************************************* * Copyright (C) 2018 by Caio Carvalho * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ -#if !defined(KPMCORE_SMARTDISKINFORMATION_H) +#ifndef KPMCORE_SMARTDISKINFORMATION_H #define KPMCORE_SMARTDISKINFORMATION_H #include #include 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, SMART_SELF_TEST_EXECUTION_STATUS_INTERRUPTED = 2, SMART_SELF_TEST_EXECUTION_STATUS_FATAL = 3, SMART_SELF_TEST_EXECUTION_STATUS_ERROR_UNKNOWN = 4, SMART_SELF_TEST_EXECUTION_STATUS_ERROR_ELECTRICAL = 5, SMART_SELF_TEST_EXECUTION_STATUS_ERROR_SERVO = 6, SMART_SELF_TEST_EXECUTION_STATUS_ERROR_READ = 7, SMART_SELF_TEST_EXECUTION_STATUS_ERROR_HANDLING = 8, SMART_SELF_TEST_EXECUTION_STATUS_INPROGRESS = 15, _SMART_SELF_TEST_EXECUTION_STATUS_MAX }; /** SMART overall state */ enum SmartOverall { SMART_OVERALL_GOOD, SMART_OVERALL_BAD_ATTRIBUTE_IN_THE_PAST, SMART_OVERALL_BAD_SECTOR, SMART_OVERALL_BAD_ATTRIBUTE_NOW, SMART_OVERALL_BAD_SECTOR_MANY, SMART_OVERALL_BAD_STATUS, _SMART_OVERALL_MAX }; public: SmartDiskInformation(); public: void updateBadSectors(); void updateOverall(); bool updateTemperature(); bool updatePowerOn(); bool updatePowerCycle(); SmartAttributeParsedData *findAttribute(quint32 id); public: const QString model() const { return m_ModelName; /**< @return the disk model name */ } const QString firmware() const { return m_FirmwareVersion; /**< @return the disk firmware version */ } const QString serial() const { return m_SerialNumber; /**< @return the disk serial number */ } quint64 size() const { return m_Size; /**< @return disk size */ } bool smartStatus() const { return m_SmartStatus; /**< @return a boolean representing SMART status */ } SmartSelfTestExecutionStatus selfTestExecutionStatus() const { return m_SelfTestExecutionStatus; /**< @return SMART self execution status */ } SmartOverall overall() const { return m_Overall; /**< @return SMART overall status */ } quint64 temperature() const { return m_Temperature; /**< @return disk temperature in kelvin */ } quint64 badSectors() const { return m_BadSectors; /**< @return the number of bad sectors */ } quint64 poweredOn() const { return m_PoweredOn; /**< @return quantity of time that device is powered on */ } quint64 powerCycles() const { return m_PowerCycles; /**< @return quantity of power cycles */ } QList attributes() const { return m_Attributes; /**< @return a list that contains the disk SMART attributes */ } public: void setModel(QString modelName) { m_ModelName = modelName; } void setFirmware(QString firmware) { m_FirmwareVersion = firmware; } void setSerial(QString serial) { m_SerialNumber = serial; } void setSize(quint64 size) { m_Size = size; } void setPowerCycles(quint64 powerCycleCt) { m_PowerCycles = powerCycleCt; } void setSmartStatus(bool smartStatus) { m_SmartStatus = smartStatus; } void setSelfTestExecutionStatus(SmartSelfTestExecutionStatus status) { m_SelfTestExecutionStatus = status; } void addAttribute(SmartAttributeParsedData &attribute) { m_Attributes << attribute; } protected: void validateBadAttributes(); private: QString m_ModelName; QString m_FirmwareVersion; QString m_SerialNumber; quint64 m_Size; quint64 m_Temperature; quint64 m_BadSectors; quint64 m_PoweredOn; quint64 m_PowerCycles; bool m_SmartStatus; bool m_BadAttributeNow; bool m_BadAttributeInThePast; SmartSelfTestExecutionStatus m_SelfTestExecutionStatus; SmartOverall m_Overall; QList m_Attributes; }; #endif // SMARTDISKINFORMATION_H diff --git a/src/core/smartparser.h b/src/core/smartparser.h index 3438e8d..a48750c 100644 --- a/src/core/smartparser.h +++ b/src/core/smartparser.h @@ -1,63 +1,63 @@ /************************************************************************* * Copyright (C) 2018 by Caio Carvalho * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ -#if !defined(KPMCORE_SMARTPARSER_H) +#ifndef KPMCORE_SMARTPARSER_H #define KPMCORE_SMARTPARSER_H #include #include class SmartDiskInformation; /** A parser to SMART JSON output. Responsible to execute smartctl and parse its output. @author Caio Carvalho */ class SmartParser { public: SmartParser(const QString &device_path); public: bool init(); public: const QString &devicePath() const { return m_DevicePath; /**< @return the device path that SMART must analyse */ } SmartDiskInformation *diskInformation() const { return m_DiskInformation; /**< @return a reference to parsed disk information */ } protected: void loadSmartOutput(); void loadAttributes(); private: const QString m_DevicePath; QJsonDocument m_SmartOutput; SmartDiskInformation *m_DiskInformation; }; #endif // SMARTPARSER_H diff --git a/src/core/smartstatus.h b/src/core/smartstatus.h index 2983582..d064b7e 100644 --- a/src/core/smartstatus.h +++ b/src/core/smartstatus.h @@ -1,187 +1,186 @@ /************************************************************************* * Copyright (C) 2010 by Volker Lanz * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ -#if !defined(KPMCORE_SMARTSTATUS_H) - +#ifndef KPMCORE_SMARTSTATUS_H #define KPMCORE_SMARTSTATUS_H #include "util/libpartitionmanagerexport.h" #include "core/smartattribute.h" #include #include #include struct SkSmartAttributeParsedData; struct SkDisk; class LIBKPMCORE_EXPORT SmartStatus { public: enum Overall { Good, BadPast, BadSectors, BadNow, BadSectorsMany, Bad }; enum SelfTestStatus { Success, Aborted, Interrupted, Fatal, ErrorUnknown, ErrorEletrical, ErrorServo, ErrorRead, ErrorHandling, InProgress }; public: typedef QList Attributes; public: SmartStatus(const QString &device_path); public: void update(); const QString &devicePath() const { return m_DevicePath; } bool isValid() const { return m_InitSuccess; } bool status() const { return m_Status; } const QString &modelName() const { return m_ModelName; } const QString &serial() const { return m_Serial; } const QString &firmware() const { return m_Firmware; } quint64 temp() const { return m_Temp; } quint64 badSectors() const { return m_BadSectors; } quint64 powerCycles() const { return m_PowerCycles; } quint64 poweredOn() const { return m_PoweredOn; } const Attributes &attributes() const { return m_Attributes; } Overall overall() const { return m_Overall; } SelfTestStatus selfTestStatus() const { return m_SelfTestStatus; } void addAttributes(QList attr); static QString tempToString(quint64 mkelvin); static QString overallAssessmentToString(Overall o); static QString selfTestStatusToString(SmartStatus::SelfTestStatus s); protected: void setStatus(bool s) { m_Status = s; } void setModelName(const QString &name) { m_ModelName = name; } void setSerial(const QString &s) { m_Serial = s; } void setFirmware(const QString &f) { m_Firmware = f; } void setTemp(quint64 t) { m_Temp = t; } void setInitSuccess(bool b) { m_InitSuccess = b; } void setBadSectors(quint64 s) { m_BadSectors = s; } void setPowerCycles(quint64 p) { m_PowerCycles = p; } void setPoweredOn(quint64 t) { m_PoweredOn = t; } void setOverall(Overall o) { m_Overall = o; } void setSelfTestStatus(SelfTestStatus s) { m_SelfTestStatus = s; } private: const QString m_DevicePath; bool m_InitSuccess; bool m_Status; QString m_ModelName; QString m_Serial; QString m_Firmware; Overall m_Overall; SelfTestStatus m_SelfTestStatus; quint64 m_Temp; quint64 m_BadSectors; quint64 m_PowerCycles; quint64 m_PoweredOn; Attributes m_Attributes; }; #endif diff --git a/src/core/volumemanagerdevice.h b/src/core/volumemanagerdevice.h index db4272e..42c84c8 100644 --- a/src/core/volumemanagerdevice.h +++ b/src/core/volumemanagerdevice.h @@ -1,99 +1,99 @@ /************************************************************************* * Copyright (C) 2016 by Chantara Tith * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 3 of * * the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* *************************************************************************/ #if !defined(KPMCORE_VOLUMEMANAGERDEVICE_H) #define KPMCORE_VOLUMEMANAGERDEVICE_H #include "util/libpartitionmanagerexport.h" #include "core/device.h" #include #include #include #include /** A Volume Manager of physical devices represented as an abstract device. * * VolumeManagerDevice is an abstract device class for volume manager. e.g: LVM, SoftRAID. * example of physical device: /dev/sda, /dev/sdb1. * * Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions. * * @see Device, PartitionTable, Partition */ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device { Q_DISABLE_COPY(VolumeManagerDevice) public: VolumeManagerDevice(const QString& name, const QString& deviceNode, const qint64 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device); /** * @return list of physical device's path that makes up volumeManagerDevice.(e.g: /dev/sda, /dev/sdb1) */ virtual const QStringList deviceNodes() const = 0; /** * @return list of logical partition's path. */ virtual const QStringList partitionNodes() const = 0; /** * @return size of logical partition at the given path in bytes. */ virtual qint64 partitionSize(QString& partitionPath) const = 0; protected: /** Initialize device's partition table and partitions. * */ virtual void initPartitions() = 0; /** absolute sector as represented inside the device's partitionTable * * For VolumeMangerDevice to works with the rest of the codebase, partitions are stringed * one after another to create a representation of PartitionTable and partition just like * real disk device. * * @param partitionPath logical partition path * @sector sector value to be mapped (if 0, will return start sector of the partition) * @return absolute sector value as represented inside device's partitionTable */ virtual qint64 mappedSector(const QString& partitionPath, qint64 sector) const = 0; public: - /** string deviceNodes together into comma-sperated list + /** join deviceNodes together into comma-separated list * - * @return comma-seperated list of deviceNodes + * @return comma-separated list of deviceNodes */ virtual QString prettyDeviceNodeList() const; /** Resize device total number of logical sectors. * * @param n Number of sectors. */ void setTotalLogical(qint64 n) { Q_ASSERT(n > 0); m_TotalLogical = n; } }; #endif