dryrun and set states for new drives

This commit is contained in:
Hendrik Schutter 2020-08-26 15:07:53 +02:00
parent f39fbfbd54
commit 424218bb23
4 changed files with 37 additions and 22 deletions

View File

@ -8,7 +8,7 @@
#ifndef REHDD_H_ #ifndef REHDD_H_
#define REHDD_H_ #define REHDD_H_
//#define DRYRUN #define DRYRUN
#define WORSE_HOURS 19200 //mark drive if at this limit or beyond #define WORSE_HOURS 19200 //mark drive if at this limit or beyond
#define WORSE_POWERUP 4000 //mark drive if at this limit or beyond #define WORSE_POWERUP 4000 //mark drive if at this limit or beyond

View File

@ -80,11 +80,11 @@ public:
private: private:
Shred(void); Shred(void);
static inline uint8_t calcProgress(); static inline uint8_t calcProgress();
static inline void tfnge_init_iv(struct tfnge_stream *tfe, const void *key, const void *iv); static inline void tfnge_init_iv(struct tfnge_stream *tfe, const void *key, const void *iv);
static inline void tfnge_init(struct tfnge_stream *tfe, const void *key); static inline void tfnge_init(struct tfnge_stream *tfe, const void *key);
static inline void tfng_encrypt_rawblk(TFNG_UNIT_TYPE *O, const TFNG_UNIT_TYPE *I, const TFNG_UNIT_TYPE *K); static inline void tfng_encrypt_rawblk(TFNG_UNIT_TYPE *O, const TFNG_UNIT_TYPE *I, const TFNG_UNIT_TYPE *K);
static inline void tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe); static inline void tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe);
}; };

View File

@ -223,6 +223,7 @@ void reHDD::searchDrives(vector <Drive>* pvecDrives)
if (string(cLine).find("/dev/sd") != string::npos) if (string(cLine).find("/dev/sd") != string::npos)
{ {
Drive* tmpDrive = new Drive(string(cLine).substr (2,8)); Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
tmpDrive->state = Drive::NONE;
pvecDrives->push_back(*tmpDrive); pvecDrives->push_back(*tmpDrive);
} }
} }

View File

@ -6,7 +6,7 @@
*/ */
#include "../../include/reHDD.h" #include "../../include/reHDD.h"
#ifndef DRYRUN
static char *randsrc = (char*) "/dev/urandom"; static char *randsrc = (char*) "/dev/urandom";
static int force = 0, rmf = 0, zrf = 0, noround = 0, verbose = 0, syncio = 0, alwaysrand = 0, reqrand = 0; static int force = 0, rmf = 0, zrf = 0, noround = 0, verbose = 0, syncio = 0, alwaysrand = 0, reqrand = 0;
@ -25,7 +25,7 @@ static struct tfnge_stream tfnge;
static unsigned long blockcount = 0UL; static unsigned long blockcount = 0UL;
static long blockcount_max; static long blockcount_max;
static uint8_t u8Percent; static uint8_t u8Percent;
#endif
/** /**
* \brief shred drive with shred * \brief shred drive with shred
* \param pointer of Drive instance * \param pointer of Drive instance
@ -33,9 +33,18 @@ static uint8_t u8Percent;
*/ */
void Shred::shredDrive(Drive* drive, int* ipSignalFd) void Shred::shredDrive(Drive* drive, int* ipSignalFd)
{ {
#ifdef DRYRUN #ifdef DRYRUN
//TODO for(int i = 0; i<=10; i++)
{
if(drive->state != Drive::SHRED_ACTIVE)
{
return;
}
drive->setTaskPercentage(i*10);
write(*ipSignalFd, "A",1);
sleep(2);
}
#endif #endif
#ifndef DRYRUN #ifndef DRYRUN
@ -139,18 +148,21 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
// write block loop // write block loop
while (1) while (1)
{ {
usleep(10);
if(drive->state != Drive::SHRED_ACTIVE){ if(drive->state != Drive::SHRED_ACTIVE)
goto _return; {
} goto _return;
}
uint8_t u8TmpPercent = calcProgress(); uint8_t u8TmpPercent = calcProgress();
if(u8Percent != u8TmpPercent){ if(u8Percent != u8TmpPercent)
drive->setTaskPercentage(u8TmpPercent); {
u8Percent = u8TmpPercent; drive->setTaskPercentage(u8TmpPercent);
write(*ipSignalFd, "A",1); u8Percent = u8TmpPercent;
} write(*ipSignalFd, "A",1);
}
if (!pat) if (!pat)
{ {
@ -257,10 +269,11 @@ _return:
close(rsf); close(rsf);
#endif #endif
} }
#ifndef DRYRUN
uint8_t Shred::calcProgress()
uint8_t Shred::calcProgress(){ {
blockcount++; blockcount++;
return ((((double)blockcount/(double)blockcount_max))*100); return ((((double)blockcount/(double)blockcount_max))*100);
} }
@ -365,4 +378,5 @@ void Shred::tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe)
tfe->carry_bytes = TFNG_BLOCK_SIZE-sz; tfe->carry_bytes = TFNG_BLOCK_SIZE-sz;
memcpy(tfe->carry_block, udst+sz, tfe->carry_bytes); memcpy(tfe->carry_block, udst+sz, tfe->carry_bytes);
} }
} }
#endif