/** * @file drive.h * @brief represent physical drive * @author hendrik schutter * @date 01.05.2020 */ #ifndef DRIVE_H_ #define DRIVE_H_ #include "reHDD.h" class Drive { public: enum class TaskState { NONE, SHRED_SELECTED, SHRED_ACTIVE, // shred iterations active CHECK_ACTIVE, // optional checking active CHECK_SUCCESSFUL, CHECK_FAILED, DELETE_SELECTED, DELETE_ACTIVE, FROZEN }; enum class ConnectionType { UNKNOWN, USB, SATA, NVME }; struct ShredSpeed { time_t u32ShredTimeDelta; std::chrono::time_point chronoShredTimestamp; unsigned long ulWrittenBytes; unsigned long ulSpeedMetricBytesWritten; }; std::atomic state; std::atomic connectionType; std::atomic sShredSpeed; bool bWasShredded = false; // all shred iterations done bool bWasShredStarted = false; // shred was atleast once started bool bWasChecked = false; // all shred iterations and optional checking done bool bWasDeleted = false; bool bIsOffline = false; uint32_t u32DriveChecksumAfterShredding = 0U; uint16_t u16DriveIndex = 0U; // Index of TUI list private: std::string sPath; time_t u32Timestamp = 0U; // unix timestamp for detecting a frozen drive double d32TaskPercentage = 0U; // in percent for Shred (1 to 100) time_t u32TimestampTaskStart = 0U; // unix timestamp for duration of an action time_t u32TaskDuration = 0U; // time needed to complete the task struct { std::string sModelFamily; std::string sModelName; std::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: void setTimestamp(); protected: public: // Copy constructor Drive(const Drive &other); // Copy assignment operator Drive &operator=(const Drive &other); // Move constructor Drive(Drive &&other) noexcept; // Move assignment operator Drive &operator=(Drive &&other) noexcept; Drive(std::string path) { this->sPath = path; } std::string getPath(void); std::string getModelFamily(void); std::string getModelName(void); std::string getSerial(void); uint64_t getCapacity(void); // in byte uint32_t getErrorCount(void); uint32_t getPowerOnHours(void); // in hours uint32_t getPowerCycles(void); uint32_t getTemperature(void); // in Fahrenheit, just kidding: degree Celsius void checkFrozenDrive(void); void setDriveSMARTData(std::string modelFamily, std::string modelName, std::string serial, uint64_t capacity, uint32_t errorCount, uint32_t powerOnHours, uint32_t powerCycles, uint32_t temperature); std::string sCapacityToText(); std::string sErrorCountToText(); std::string sPowerOnHoursToText(); std::string sPowerCyclesToText(); std::string sTemperatureToText(); void setTaskPercentage(double d32TaskPercentage); double getTaskPercentage(void); void setActionStartTimestamp(); time_t getActionStartTimestamp(); void calculateTaskDuration(); time_t getTaskDuration(); }; #endif // DRIVE_H_