aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2010-12-02 11:41:00 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2010-12-02 11:41:00 -0500
commit6785e4c29f76db8e9d410492bf88397757367567 (patch)
treefe21e1aa0a8302fd479bee6ac0cd5182a19dc185 /src
parentcbf44952901131c5c2df11080c76659616ddb2f4 (diff)
downloadNetNuke2-6785e4c29f76db8e9d410492bf88397757367567.tar.gz
Added user defined block size.
Fixed the error with the wipe() while loop not counting the correct variable.
Diffstat (limited to 'src')
-rw-r--r--src/nukectl.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/nukectl.c b/src/nukectl.c
index 8ea266e..2505ecc 100644
--- a/src/nukectl.c
+++ b/src/nukectl.c
@@ -29,6 +29,7 @@
FILE* randfp;
unsigned int randseed;
unsigned long long total_written_bytes;
+extern unsigned int blksz_override;
extern int safety_flag;
extern pthread_mutex_t lock_global;
extern pthread_mutex_t lock_write;
@@ -37,10 +38,24 @@ void* wipe(void* device)
{
nndevice_t* d = (nndevice_t*)device;
int output_progress = 0;
- unsigned long int blocks = d->blksz * d->blks;
+ unsigned long int blocks = 0;
unsigned long long blocks_written = 0;
long double percent = 0.0L;
+ if(blksz_override > 0)
+ {
+ pthread_mutex_lock(&lock_global);
+ d->blksz = blksz_override;
+ pthread_mutex_unlock(&lock_global);
+ d->blks = (d->blks / d->blksz);
+ // = d->blksz * d->blks;
+ COM(self, "Writing %llu records\n", blocks);
+ }
+ else
+ {
+ blocks = d->blksz * d->blks;
+ }
+
FILE* fp = fopen(d->path, "w+t");
if(fp == NULL)
{
@@ -50,16 +65,19 @@ void* wipe(void* device)
COM(self, "%s, block size %d, blocks %llu, total bytes %llu\n", d->path, d->blksz, d->blks, d->sz);
srand(nngetseed());
- while(blocks_written < blocks)
+ while(blocks_written < d->sz)
{
pthread_mutex_lock(&lock_global);
blocks_written += nnwrite(fp, d->blksz);
pthread_mutex_unlock(&lock_global);
- if(output_progress >= 102400)
+ //printf("output_progress = %d\n", output_progress);
+ if(output_progress >= 512)
{
+ pthread_mutex_lock(&lock_global);
percent = (long double)((blocks_written / (long double)d->sz) * 100);
printf("%s: %llu of %llu (%0.2Lf%%)\n", d->path, blocks_written, d->sz, percent);
+ pthread_mutex_unlock(&lock_global);
output_progress = 0;
}
++output_progress;