From b271f7955a862b7588e6638271655fbfeefb44b4 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 28 Aug 2020 15:28:57 +0200 Subject: [PATCH] percent are now two digit precision --- include/drive.h | 6 +++--- include/reHDD.h | 6 +----- include/shred/shred.h | 2 +- src/drive.cpp | 10 +++++----- src/shred/shred.cpp | 23 +++++++++++++++-------- src/tui.cpp | 19 +++++++++++-------- 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/include/drive.h b/include/drive.h index efe38fc..33cd10d 100644 --- a/include/drive.h +++ b/include/drive.h @@ -34,7 +34,7 @@ private: uint32_t u32PowerOnHours = 0U; //in hours uint32_t u32PowerCycles = 0U; - uint8_t u8TaskPercentage = 0U; //in percent for Shred (1 to 100) + double d32TaskPercentage = 0U; //in percent for Shred (1 to 100) protected: @@ -66,8 +66,8 @@ public: string sPowerOnHoursToText(); string sPowerCyclesToText(); - void setTaskPercentage(uint8_t u8TaskPercentage); - uint8_t getTaskPercentage(void); + void setTaskPercentage(double d32TaskPercentage); + double getTaskPercentage(void); }; diff --git a/include/reHDD.h b/include/reHDD.h index 79e6f5a..44c260d 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -8,17 +8,13 @@ #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 #define SHRED_ITERATIONS 1 - - - - #define READ 0 #define WRITE 1 diff --git a/include/shred/shred.h b/include/shred/shred.h index b1efaa1..c1d1b22 100644 --- a/include/shred/shred.h +++ b/include/shred/shred.h @@ -80,7 +80,7 @@ public: private: Shred(void); - static inline uint8_t calcProgress(); + static inline double 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); diff --git a/src/drive.cpp b/src/drive.cpp index ebea0e8..18441ff 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -86,16 +86,16 @@ string Drive::sPowerCyclesToText() return to_string(getPowerCycles()); } -void Drive::setTaskPercentage(uint8_t u8TaskPercentage) +void Drive::setTaskPercentage(double d32TaskPercentage) { - if(u8TaskPercentage <= 100) + if(d32TaskPercentage <= 100) { - this->u8TaskPercentage = u8TaskPercentage; + this->d32TaskPercentage = d32TaskPercentage; } } -uint8_t Drive::getTaskPercentage(void) +double Drive::getTaskPercentage(void) { - return this->u8TaskPercentage; + return this->d32TaskPercentage; } diff --git a/src/shred/shred.cpp b/src/shred/shred.cpp index 605f2a3..d896f43 100644 --- a/src/shred/shred.cpp +++ b/src/shred/shred.cpp @@ -24,7 +24,7 @@ static struct tfnge_stream tfnge; static unsigned long blockcount = 0UL; static long blockcount_max; -static uint8_t u8Percent; +static double d32Percent; #endif /** * \brief shred drive with shred @@ -60,7 +60,7 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd) blockcount_max = SHRED_ITERATIONS*(drive->getCapacity()/4096); - u8Percent = 0U; + d32Percent = 0U; rsf = open(randsrc, O_RDONLY | O_LARGEFILE); if (rsf == -1) @@ -148,19 +148,19 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd) // write block loop while (1) { - usleep(10); + //usleep(10); if(drive->state != Drive::SHRED_ACTIVE) { goto _return; } - uint8_t u8TmpPercent = calcProgress(); + double d32TmpPercent = calcProgress(); - if(u8Percent != u8TmpPercent) + if((d32TmpPercent-d32Percent) >= 0.09) { - drive->setTaskPercentage(u8TmpPercent); - u8Percent = u8TmpPercent; + drive->setTaskPercentage(d32TmpPercent); + d32Percent = d32TmpPercent; write(*ipSignalFd, "A",1); } @@ -267,11 +267,18 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd) _return: optind++; close(rsf); + + if(drive->state == Drive::SHRED_ACTIVE) + { + drive->bWasShredded = true; + } + + #endif } #ifndef DRYRUN -uint8_t Shred::calcProgress() +double Shred::calcProgress() { blockcount++; return ((((double)blockcount/(double)blockcount_max))*100); diff --git a/src/tui.cpp b/src/tui.cpp index ff2fcc9..4dd0c29 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -85,11 +85,14 @@ void TUI::updateTUI(vector * pvecDrives, uint8_t u8SelectedEntry) displaySelectedDrive(pvecDrives->at(u8SelectedEntry), stdscrX, stdscrY); } + stringstream stream; switch (it->state) { case Drive::SHRED_ACTIVE: - sState = "Shredding: " + to_string(it->getTaskPercentage()) + "%"; + + stream << fixed << setprecision(2) << (it->getTaskPercentage()); + sState = "Shredding: " + stream.str() + "%"; break; case Drive::DELETE_ACTIVE: @@ -190,7 +193,7 @@ WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize) centerTitle(newWindow, "Detected Drives"); - keypad(newWindow, TRUE); + //keypad(newWindow, TRUE); return newWindow; } @@ -256,7 +259,7 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive mvwaddstr(newWindow,u16Line++, 3, sErrorCount.c_str()); } - keypad(newWindow, TRUE); + //keypad(newWindow, TRUE); return newWindow; } @@ -290,7 +293,7 @@ WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart) attroff(COLOR_PAIR(COLOR_AREA_DETAIL)); - keypad(newWindow, TRUE); + //keypad(newWindow, TRUE); return newWindow; } @@ -320,7 +323,7 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, mvwaddstr(newWindow,2, iXSize-sState.length()-5, sState.c_str()); - keypad(newWindow, TRUE); + //keypad(newWindow, TRUE); return newWindow; } @@ -346,7 +349,7 @@ WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iYStart) mvwaddstr(newWindow,2, 2, time.c_str()); - keypad(newWindow, TRUE); + //keypad(newWindow, TRUE); return newWindow; } @@ -375,7 +378,7 @@ WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st { mvwaddstr(newWindow,u16Line++, 3, "Press D for Delete"); } - keypad(newWindow, TRUE); + //keypad(newWindow, TRUE); return newWindow; } @@ -393,7 +396,7 @@ WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, stri mvwaddstr(newWindow,u16Line++, 3, optionA.c_str()); mvwaddstr(newWindow,u16Line++, 3, optionB.c_str()); - keypad(newWindow, TRUE); + //keypad(newWindow, TRUE); return newWindow; }