completed logger usage and changed shred task to non-static

This commit is contained in:
2020-09-08 13:01:09 +02:00
parent 730b1205f7
commit 938f267813
5 changed files with 80 additions and 44 deletions

View File

@ -22,9 +22,18 @@ struct tfnge_stream
static struct tfnge_stream tfnge;
static unsigned long blockcount = 0UL;
static long blockcount_max;
static double d32Percent;
Shred::Shred()
{
}
Shred::~Shred()
{
}
#endif
/**
* \brief shred drive with shred
@ -60,6 +69,10 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
blockcount_max = SHRED_ITERATIONS*(drive->getCapacity()/4096);
#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);
@ -80,13 +93,7 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
goto _return;
}
if (!blksz) blksz = (size_t)st.st_blksize;
/*
if (howmany != -1)
{
l = ll = howmany;
noround = 1;
}
*/
else l = ll = st.st_size;
if (l == 0 && !S_ISREG(st.st_mode)) special = 1;
memset(&st, 0, sizeof(struct stat));
@ -148,20 +155,27 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
// write block loop
while (1)
{
//usleep(10);
if(drive->state != Drive::SHRED_ACTIVE)
{
drive->setTaskPercentage(0);
d32Percent = 0.00;
blockcount = 0;
blockcount_max = 0;
Logger::logThis()->info("Aborted shred for: " + drive->getModelName() + "-" + drive->getSerial());
goto _return;
}
double d32TmpPercent = calcProgress();
if((d32TmpPercent-d32Percent) >= 0.09)
{
drive->setTaskPercentage(d32TmpPercent);
d32Percent = d32TmpPercent;
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Shred-Task: BlockCount: " + to_string(blockcount) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());
#endif
write(*ipSignalFd, "A",1);
}
@ -274,6 +288,7 @@ _return:
drive->bWasShredded = true;
drive->state= Drive::NONE;
drive->setTaskPercentage(0);
Logger::logThis()->info("Finished shred for: " + drive->getModelName() + "-" + drive->getSerial());
}
}
#ifndef DRYRUN