Compare commits

...

2 Commits

Author SHA1 Message Date
Hendrik Schutter 8e15a537cf comments for better understanding 2022-08-22 09:47:06 +02:00
Hendrik Schutter 0d72829f61 display shred speed 2022-06-30 09:38:11 +02:00
9 changed files with 1245 additions and 34 deletions

View File

@ -1 +1,2 @@
4673974d
2cb3dea4

View File

@ -22,6 +22,14 @@ public:
FROZEN
} state;
struct
{
time_t u32ShredTimeDelta;
std::chrono::time_point<std::chrono::system_clock> chronoShredTimestamp;
unsigned long ulWrittenBytes;
} sShredSpeed;
bool bWasShredded = false;
bool bWasDeleteted = false;
bool bIsOffline = false;

View File

@ -29,7 +29,7 @@
#endif
// Logic
#define DRYRUN //don´t touch the drives
//#define DRYRUN //don´t touch the drives
#define FROZEN_ALERT //show alert if drive is frozen
//IPC pipes

View File

@ -93,6 +93,8 @@ private:
inline void tfng_encrypt_rawblk(TFNG_UNIT_TYPE *O, const TFNG_UNIT_TYPE *I, const TFNG_UNIT_TYPE *K);
inline void tfnge_emit(void *dst, size_t szdst, struct tfnge_stream *tfe);
void printRandomBufferChecksum(char* buf, size_t szdst);
};
#endif // SHRED_H_

View File

@ -56,7 +56,7 @@ private:
static WINDOW *createOverViewWindow( int iXSize, int iYSize);
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive);
static WINDOW *overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart);
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, bool bSelected);
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected);
static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart);
static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate);
static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB);
@ -65,6 +65,7 @@ private:
void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY);
string formatTimeDuration(time_t u32Duration);
string formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes);
};
#endif // TUI_H_

1144
reHDD_random.log Normal file

File diff suppressed because it is too large Load Diff

BIN
reHDD_speed_test.ods Normal file

Binary file not shown.

View File

@ -60,8 +60,8 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
#ifndef DRYRUN
struct stat st;
char *buf, *s, *d, rc = 0;
int f, rsf;
char *bufRandomData, *s, *d, rc = 0;
int filehandleDrive, filehandleRandom;
int xret = 0, pat = 0, last = 0, special = 0, iIteration = 0;
size_t blksz = 0, x, y;
size_t l, ll = NOSIZE;
@ -70,14 +70,17 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
blockcount_max = SHRED_ITERATIONS*(drive->getCapacity()/4096);
drive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();; //set inital timestamp for speed metric
unsigned long ulSpeedMetricBytesWritten = 0U; //uses to calculate speed metric
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Shred-Task: Max-BlockCount: " + to_string(blockcount_max) + " - Drive: " + drive->getSerial());
#endif
d32Percent = 0U;
rsf = open(randsrc, O_RDONLY | O_LARGEFILE);
if (rsf == -1)
filehandleRandom = open(randsrc, O_RDONLY | O_LARGEFILE);
if (filehandleRandom == -1)
{
perror(randsrc);
exit(1);
@ -85,7 +88,10 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
special = pat = 0;
iIteration = SHRED_ITERATIONS;
if (verbose) fprintf(stderr, "destroying %s ...\n", cpDrivePath);
if (verbose)
{
fprintf(stderr, "destroying %s ...\n", cpDrivePath);
}
if (stat(cpDrivePath, &st) == -1)
{
@ -93,10 +99,20 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
XRET(1);
goto _return;
}
if (!blksz) blksz = (size_t)st.st_blksize;
if (!blksz)
{
blksz = (size_t)st.st_blksize;
Logger::logThis()->info("Optimal block size for I/O: " + to_string(blksz));
}
else l = ll = st.st_size;
if (l == 0 && !S_ISREG(st.st_mode)) special = 1;
else
{
l = ll = st.st_size;
}
if (l == 0 && !S_ISREG(st.st_mode))
{
special = 1;
}
memset(&st, 0, sizeof(struct stat));
if (force) if (chmod(cpDrivePath, S_IRUSR|S_IWUSR) == -1)
@ -104,35 +120,36 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
perror(cpDrivePath);
XRET(1);
}
f = open(cpDrivePath, O_WRONLY | O_LARGEFILE | O_NOCTTY | syncio);
if (f == -1)
filehandleDrive = open(cpDrivePath, O_WRONLY | O_LARGEFILE | O_NOCTTY | syncio);
if (filehandleDrive == -1)
{
XRET(1);
perror(cpDrivePath);
goto _return;
}
buf = (char*) malloc(blksz);
if (!buf)
bufRandomData = (char*) malloc(blksz);
if (!bufRandomData)
{
perror("malloc");
XRET(2);
fprintf(stderr, "Continuing with fixed buffer (%zu bytes long)\n", sizeof(sfbuf));
buf = sfbuf;
bufRandomData = sfbuf;
blksz = sizeof(sfbuf);
}
memset(buf, 0, blksz);
memset(bufRandomData, 0, blksz);
if (read(rsf, buf, blksz) <= 0) fprintf(stderr, "%s: read 0 bytes (wanted %zu)\n", randsrc, blksz);
tfnge_init(&tfnge, buf);
if (read(filehandleRandom, bufRandomData, blksz) <= 0) fprintf(stderr, "%s: read 0 bytes (wanted %zu)\n", randsrc, blksz);
tfnge_init(&tfnge, bufRandomData);
//iteration loop
while (iIteration)
{
lseek(f, 0L, SEEK_SET);
lseek(filehandleDrive, 0L, SEEK_SET);
if (iIteration <= 1 && zrf)
{
Logger::logThis()->info("pat=1");
pat = 1;
rc = 0;
}
@ -142,9 +159,10 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
}
else if (!alwaysrand)
{
if (read(rsf, &rc, 1) <= 0) fprintf(stderr, "%s: read 0 bytes (wanted 1)\n", randsrc);
if (read(filehandleRandom, &rc, 1) <= 0) fprintf(stderr, "%s: read 0 bytes (wanted 1)\n", randsrc);
pat = rc%2;
if (read(rsf, &rc, 1) <= 0) fprintf(stderr, "%s: read 0 bytes (wanted 1)\n", randsrc);
if (read(filehandleRandom, &rc, 1) <= 0) fprintf(stderr, "%s: read 0 bytes (wanted 1)\n", randsrc);
}
else pat = 0;
@ -177,16 +195,25 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Shred-Task: BlockCount: " + to_string(blockcount) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());
#endif
//set metrics for calculating shred speed
std::chrono::time_point<std::chrono::system_clock> chronoCurrentTimestamp = std::chrono::system_clock::now();
drive->sShredSpeed.u32ShredTimeDelta = (chronoCurrentTimestamp - drive->sShredSpeed.chronoShredTimestamp).count();
drive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();
drive->sShredSpeed.ulWrittenBytes = ulSpeedMetricBytesWritten;
ulSpeedMetricBytesWritten = 0U;
write(*ipSignalFd, "A",1);
}
if (!pat)
{
tfnge_emit(buf, blksz, &tfnge);
// Logger::logThis()->info("tfnge_emit");
//tfnge_emit(bufRandomData, blksz, &tfnge);
}
else
{
memset(buf, rc, blksz);
memset(bufRandomData, rc, blksz);
}
if (l <= blksz && !special)
@ -194,7 +221,12 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
last = 1;
}
errno = 0;
l -= write(f, buf, (noround && last) ? l : blksz);
printRandomBufferChecksum(bufRandomData, (noround && last) ? l : blksz);
size_t write_return = write(filehandleDrive, bufRandomData, (noround && last) ? l : blksz);
ulSpeedMetricBytesWritten += write_return;
l -= write_return;
if (errno)
{
perror(cpDrivePath);
@ -210,14 +242,14 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
}
// write block loop end
l = ll;
fdatasync(f);
fdatasync(filehandleDrive);
iIteration--;
} //iteration loop end
if (rmf)
{
close(f);
f = open(cpDrivePath, O_WRONLY | O_TRUNC | O_LARGEFILE | O_NOCTTY | syncio);
close(filehandleDrive);
filehandleDrive = open(cpDrivePath, O_WRONLY | O_TRUNC | O_LARGEFILE | O_NOCTTY | syncio);
if (verbose) fprintf(stderr, "removing %s ...\n", cpDrivePath);
x = strnlen(cpDrivePath, sizeof(sfbuf)/2);
s = sfbuf+(sizeof(sfbuf)/2);
@ -277,12 +309,12 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
}
tfnge_emit(NULL, 0, &tfnge);
if (buf && buf != sfbuf) free(buf);
if (f != -1) close(f);
if (bufRandomData && bufRandomData != sfbuf) free(bufRandomData);
if (filehandleDrive != -1) close(filehandleDrive);
_return:
optind++;
close(rsf);
close(filehandleRandom);
#endif
if(drive->state == Drive::SHRED_ACTIVE)
{
@ -300,6 +332,16 @@ double Shred::calcProgress()
return ((((double)blockcount/(double)blockcount_max))*100);
}
void Shred::printRandomBufferChecksum(char* buf, size_t szdst)
{
uint8_t u8Checksum = 0U;
for (size_t i = 0; i < szdst; i++)
{
u8Checksum += buf[i];
}
Logger::logThis()->info("random: " + to_string(u8Checksum));
}
void Shred::tfnge_init_iv(struct tfnge_stream *tfe, const void *key, const void *iv)
{

View File

@ -78,7 +78,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
string sCapacity = it->sCapacityToText();
string sState = " ";
string sTime = " ";
string sSpeed = " ";
bool bSelectedEntry = false;
@ -107,6 +107,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
it->calculateTaskDuration();
sTime = this->formatTimeDuration(it->getTaskDuration());
sSpeed = this->formatSpeed(it->sShredSpeed.u32ShredTimeDelta, it->sShredSpeed.ulWrittenBytes);
break;
case Drive::DELETE_ACTIVE:
sState = "Deleting ...";
@ -142,7 +143,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
break;
}
WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, sTime, bSelectedEntry);
WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, sTime, sSpeed, bSelectedEntry);
wrefresh(tmp);
u8Index++;
}//end loop though drives
@ -296,7 +297,7 @@ WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart)
return newWindow;
}
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, bool bSelected)
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
@ -320,8 +321,9 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,
mvwaddstr(newWindow,2, 1, sModelName.c_str());
mvwaddstr(newWindow,3, 1, sCapacity.c_str());
mvwaddstr(newWindow,1, iXSize-sSpeed.length()-5, sSpeed.c_str());
mvwaddstr(newWindow,2, iXSize-sState.length()-5, sState.c_str());
mvwaddstr(newWindow,3, iXSize-sState.length()-5, sTime.c_str());
mvwaddstr(newWindow,3, iXSize-sTime.length()-5, sTime.c_str());
return newWindow;
}
@ -461,6 +463,17 @@ string TUI::formatTimeDuration(time_t u32Duration)
return out.str();
}
string TUI::formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes)
{
std::ostringstream out;
double dDeltaSec = ((double)((u32ShredTimeDelta)/1000000000.0)); //convert nano in sec
double speed = ((ulWrittenBytes/1000000.0)/dDeltaSec);
char s[25];
sprintf(s, "%0.2lf MB/s", speed);
out << s;
return out.str();
}
void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
{
struct MenuState menustate;