2020-05-01 18:31:02 +02:00
/**
2020-05-02 22:06:47 +02:00
* @ file reHDD . h
2020-09-21 21:56:26 +02:00
* @ brief app logic header
2020-05-02 22:06:47 +02:00
* @ author hendrik schutter
* @ date 01.05 .2020
2020-05-01 18:31:02 +02:00
*/
2020-05-02 22:06:47 +02:00
# ifndef REHDD_H_
# define REHDD_H_
2022-11-24 20:45:24 +01:00
# define REHDD_VERSION "bV1.1.0"
2020-09-15 13:39:45 +02:00
2020-09-11 17:18:53 +02:00
// Drive handling Settings
2020-08-07 16:17:45 +02:00
# define WORSE_HOURS 19200 //mark drive if at this limit or beyond
2020-08-31 09:40:31 +02:00
# define WORSE_POWERUP 10000 //mark drive if at this limit or beyond
2022-08-24 16:27:51 +02:00
# define WORSE_TEMPERATURE 55 //mark drive if at this limit or beyond
2022-08-25 09:18:12 +02:00
# define SHRED_ITERATIONS 3U
2022-08-24 16:27:51 +02:00
# define FROZEN_TIMEOUT 20 //After this timeout (minutes) the drive will be marked as frozen, if no progress
2022-08-22 23:09:41 +02:00
# define METRIC_THRESHOLD 3L*1000L*1000L*1000L //calc shred speed with this minimum of time delta
2020-08-26 00:12:39 +02:00
2020-09-07 17:23:15 +02:00
// Logger Settings
# define LOG_PATH ". / reHDD.log"
2022-01-26 15:44:32 +01:00
# define DESCRIPTION "reHDD - Copyright Hendrik Schutter 2022"
2020-09-08 13:01:09 +02:00
# define DEVICE_ID "generic"
# define SOFTWARE_VERSION "alpha"
# define HARDWARE_VERSION "generic"
2022-05-15 15:17:49 +02:00
//#define LOG_LEVEL_HIGH //log everything, like drive scan thread
2020-09-08 13:01:09 +02:00
# ifndef LOG_LEVEL_HIGH
# define LOG_LEVEL_LOW //log only user actions and tasks
# endif
2020-09-07 17:23:15 +02:00
2020-09-21 21:56:26 +02:00
// Logic
2022-06-30 00:32:13 +02:00
//#define DRYRUN //don´ t touch the drives
2020-09-21 21:56:26 +02:00
# define FROZEN_ALERT //show alert if drive is frozen
2022-09-27 21:58:59 +02:00
# define ZERO_CHECK //check drive after shred if all bytes are zero, show alert if this fails
2020-09-21 21:56:26 +02:00
2020-09-11 17:18:53 +02:00
//IPC pipes
# define READ 0
# define WRITE 1
2020-05-02 22:06:47 +02:00
# include <iostream>
# include <string>
# include <fstream>
# include <tuple>
2020-09-16 15:13:32 +02:00
# include <list>
2020-05-03 17:17:20 +02:00
# include <time.h>
# include <chrono>
2020-08-03 22:40:07 +02:00
# include <curses.h>
2020-08-04 17:18:32 +02:00
# include <thread>
2020-08-03 22:40:07 +02:00
# include <unistd.h>
2020-08-04 11:59:45 +02:00
# include <mutex>
# include <sys/select.h>
2020-08-26 00:12:39 +02:00
# include <algorithm>
2020-08-04 22:35:29 +02:00
# include <cstring>
2020-08-07 13:17:52 +02:00
# include <sstream>
# include <iomanip>
2020-08-26 00:12:39 +02:00
# include <signal.h>
2020-08-04 11:59:45 +02:00
2020-05-02 22:06:47 +02:00
using namespace std ;
2020-05-01 18:31:02 +02:00
# include "drive.h"
2020-05-02 00:49:11 +02:00
# include "smart.h"
2022-05-14 14:06:16 +02:00
# include "shred.h"
2020-08-23 11:04:10 +02:00
# include "delete.h"
2020-08-04 22:35:29 +02:00
# include "tui.h"
2022-11-24 20:41:23 +01:00
# include "printer.h"
2020-09-07 17:23:15 +02:00
# include "logger/logger.h"
2020-08-04 22:35:29 +02:00
2020-09-07 17:23:15 +02:00
extern Logger * logging ;
2020-05-01 18:31:02 +02:00
2020-05-02 22:06:47 +02:00
template < typename T , typename I > T * iterator_to_pointer ( I i )
2020-05-02 17:15:55 +02:00
{
return ( & ( * i ) ) ;
}
2020-05-02 22:06:47 +02:00
class reHDD
2020-05-02 17:15:55 +02:00
{
2020-05-01 18:31:02 +02:00
protected :
public :
2020-05-02 22:06:47 +02:00
reHDD ( void ) ;
2020-09-07 17:23:15 +02:00
static void app_logic ( ) ;
2020-05-01 18:31:02 +02:00
private :
2020-09-16 15:13:32 +02:00
static void searchDrives ( list < Drive > * plistDrives ) ;
static void printDrives ( list < Drive > * plistDrives ) ;
2022-08-20 16:09:40 +02:00
static void startShredAllDrives ( list < Drive > * plistDrives ) ;
2022-08-22 18:35:27 +02:00
static void updateShredMetrics ( list < Drive > * plistDrives ) ;
2022-08-20 16:09:40 +02:00
static void filterIgnoredDrives ( list < Drive > * plistDrives ) ;
2020-09-16 15:13:32 +02:00
static void filterNewDrives ( list < Drive > * plistOldDrives , list < Drive > * plistNewDrives ) ;
static void addSMARTData ( list < Drive > * plistDrives ) ;
2022-11-24 20:41:23 +01:00
static void ThreadScanDevices ( ) ;
2020-08-07 12:07:29 +02:00
static void ThreadUserInput ( ) ;
2022-08-20 16:09:40 +02:00
static void ThreadShred ( Drive * const pDrive ) ;
2020-09-21 16:50:33 +02:00
static void ThreadDelete ( ) ;
2020-09-11 17:18:53 +02:00
static void ThreadCheckFrozenDrives ( ) ;
2020-08-23 09:26:32 +02:00
static void handleArrowKey ( TUI : : UserInput userInput ) ;
2020-08-09 21:41:28 +02:00
static void handleEnter ( ) ;
static void handleESC ( ) ;
static void handleAbort ( ) ;
2020-08-26 18:38:39 +02:00
static Drive * getSelectedDrive ( ) ;
2020-05-01 18:31:02 +02:00
} ;
2020-09-07 17:23:15 +02:00
# endif // REHDD_H_