From 424218bb23f5646bbec55d74f387a5a7b89f2a54 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 26 Aug 2020 15:07:53 +0200 Subject: [PATCH] dryrun and set states for new drives --- include/reHDD.h | 2 +- include/shred/shred.h | 10 +++++----- src/reHDD.cpp | 1 + src/shred/shred.cpp | 46 ++++++++++++++++++++++++++++--------------- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/include/reHDD.h b/include/reHDD.h index 7a7399e..c357efc 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,7 +8,7 @@ #ifndef REHDD_H_ #define REHDD_H_ -//#define DRYRUN +#define DRYRUN #define WORSE_HOURS 19200 //mark drive if at this limit or beyond #define WORSE_POWERUP 4000 //mark drive if at this limit or beyond diff --git a/include/shred/shred.h b/include/shred/shred.h index 12ccbfd..b1efaa1 100644 --- a/include/shred/shred.h +++ b/include/shred/shred.h @@ -80,11 +80,11 @@ public: private: Shred(void); - 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(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 tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe); + 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(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 tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe); }; diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 084ee5f..9406de5 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -223,6 +223,7 @@ void reHDD::searchDrives(vector * pvecDrives) if (string(cLine).find("/dev/sd") != string::npos) { Drive* tmpDrive = new Drive(string(cLine).substr (2,8)); + tmpDrive->state = Drive::NONE; pvecDrives->push_back(*tmpDrive); } } diff --git a/src/shred/shred.cpp b/src/shred/shred.cpp index 2f90949..605f2a3 100644 --- a/src/shred/shred.cpp +++ b/src/shred/shred.cpp @@ -6,7 +6,7 @@ */ #include "../../include/reHDD.h" - +#ifndef DRYRUN static char *randsrc = (char*) "/dev/urandom"; 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 long blockcount_max; static uint8_t u8Percent; - +#endif /** * \brief shred drive with shred * \param pointer of Drive instance @@ -33,9 +33,18 @@ static uint8_t u8Percent; */ void Shred::shredDrive(Drive* drive, int* ipSignalFd) { - #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 #ifndef DRYRUN @@ -139,18 +148,21 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd) // write block loop while (1) { + usleep(10); - if(drive->state != Drive::SHRED_ACTIVE){ - goto _return; - } + if(drive->state != Drive::SHRED_ACTIVE) + { + goto _return; + } uint8_t u8TmpPercent = calcProgress(); - if(u8Percent != u8TmpPercent){ - drive->setTaskPercentage(u8TmpPercent); - u8Percent = u8TmpPercent; - write(*ipSignalFd, "A",1); - } + if(u8Percent != u8TmpPercent) + { + drive->setTaskPercentage(u8TmpPercent); + u8Percent = u8TmpPercent; + write(*ipSignalFd, "A",1); + } if (!pat) { @@ -257,10 +269,11 @@ _return: close(rsf); #endif } +#ifndef DRYRUN - -uint8_t Shred::calcProgress(){ -blockcount++; +uint8_t Shred::calcProgress() +{ + blockcount++; 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; memcpy(tfe->carry_block, udst+sz, tfe->carry_bytes); } -} \ No newline at end of file +} +#endif \ No newline at end of file