aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2010-12-02 17:06:23 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2010-12-02 17:06:23 -0500
commitd8394383b8ab15653ed02b82996081c8fe07cbd8 (patch)
tree1dd3c8d8f2712b1c9658de3b4c3ff3cc61b76c65
parent44a70fa1ee939fd17e46b4ad13cc90414ae7f678 (diff)
downloadNetNuke2-d8394383b8ab15653ed02b82996081c8fe07cbd8.tar.gz
Added --list argument to display devices then exit.
Implemented --ignore-first (probably a little buggy). For now, write messages only appear with --verbose set. Removed a few debug messages.
-rw-r--r--src/bus.c3
-rw-r--r--src/netnuke.c50
-rw-r--r--src/nukectl.c42
3 files changed, 61 insertions, 34 deletions
diff --git a/src/bus.c b/src/bus.c
index a551aa0..2515b0d 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -61,9 +61,8 @@ int scanbus(nndevice_t** device, int mask)
perror("device");
exit(1);
}
- COM(self, "device[%d] = %d\n", j, sizeof(nndevice_t));
- size = blocks * blocksize;
+ size = blocks * blocksize;
strncpy(device[j]->path, entries.gl_pathv[j], sizeof(device[j]->path));
device[j]->blks = blocks;
device[j]->sz = size;
diff --git a/src/netnuke.c b/src/netnuke.c
index 3920d7e..973f8b7 100644
--- a/src/netnuke.c
+++ b/src/netnuke.c
@@ -37,6 +37,8 @@ pthread_mutex_t lock_global = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t lock_write = PTHREAD_MUTEX_INITIALIZER;
extern unsigned long total_written_bytes;
unsigned int blksz_override = 0;
+int list_flag = 0;
+int ignore_flag = 0;
int safety_flag = 0;
int logging_flag = 0;
int verbose_flag = 0;
@@ -49,8 +51,9 @@ static struct option long_options[] =
{"help", no_argument, 0, 0},
{"verbose", no_argument, &verbose_flag, 1},
{"quiet", no_argument, &verbose_flag, 0},
+ {"list", no_argument, &list_flag, 1},
{"safety-off", no_argument, &safety_flag, 0},
- {"ignore-first", no_argument, 0, 'i'},
+ {"ignore-first", no_argument, &ignore_flag, 1},
{"logging", no_argument, &logging_flag, 1},
{"timeout", required_argument, 0, 't'},
{"scheme", required_argument, 0, 's'},
@@ -64,6 +67,7 @@ static char* long_options_help[] =
"\tThis message",
"More output",
"Suppress output",
+ "Print device list, then exit",
"Enable destructive write mode",
"Ignore first device",
"Log all output to netnuke.log",
@@ -147,7 +151,7 @@ int main(int argc, char* argv[])
int c;
int option_index = 0;
- while((c = getopt_long (argc, argv, "ib:s:d:t:", long_options, &option_index)) > 0)
+ while((c = getopt_long (argc, argv, "ib:s:d:t:", long_options, &option_index)) != -1)
{
switch (c)
{
@@ -194,11 +198,10 @@ int main(int argc, char* argv[])
}
break;
}
- case 'h':
- case ':':
+ //case 'h':
+ //case ':':
case '?':
usage(basename(argv[0]));
- break;
}
}
@@ -210,7 +213,7 @@ int main(int argc, char* argv[])
putchar ('\n');
}
- COM(self, "Safety is %s\n", safety_flag ? "ON" : "OFF");
+ COM(self, "Safety is %s\n", safety_flag ? "OFF" : "ON");
nndevice_t** device;
device = (nndevice_t**)malloc(MAXTHREAD * sizeof(nndevice_t));
@@ -219,9 +222,17 @@ int main(int argc, char* argv[])
perror("device list");
exit(1);
}
+
+ if(list_flag)
+ {
+ bus_mask = selectbus(bus_flags);
+ scanbus(device, bus_mask);
+ exit(0);
+ }
+
pthread_t thread[MAXTHREAD];
int thread_count = 0;
- int i;
+ int i = 0;
bus_mask = selectbus(bus_flags);
scanbus(device, bus_mask);
@@ -231,15 +242,36 @@ int main(int argc, char* argv[])
pthread_mutex_init(&lock_global, NULL);
COM(self, "Generating threads\n");
- for( i = 0 ; device[i] != NULL ; i++ )
+
+ if(ignore_flag)
+ {
+ int first = 0;
+ int last = 0;
+
+ while(device[i] != NULL)
+ {
+ i++;
+ }
+ last = i - 1;
+
+ COM(self, "IGNORING: %s\n", device[first]->path);
+ memmove(device[first], device[last], sizeof(nndevice_t));
+ memset(device[last], 0, sizeof(nndevice_t));
+ device[last] = NULL;
+ }
+
+
+ for( i = 0; device[i] != NULL ; i++ )
{
thread[i] = (pthread_t)nnthread(device[i]);
COM(self, "thread id: %ld\n", thread[i]);
}
+ usleep(10000);
thread_count = i;
COM(self, "Joining %d thread%c\n", thread_count, (thread_count > 1 || thread_count < 1) ? 's' : '\b');
- for( i = 0 ; i < thread_count ; i++ )
+
+ for( i = 0 ; i < thread_count ; i++)
{
pthread_join(thread[i], NULL);
}
diff --git a/src/nukectl.c b/src/nukectl.c
index 2505ecc..22e628e 100644
--- a/src/nukectl.c
+++ b/src/nukectl.c
@@ -30,6 +30,7 @@ FILE* randfp;
unsigned int randseed;
unsigned long long total_written_bytes;
extern unsigned int blksz_override;
+extern int verbose_flag;
extern int safety_flag;
extern pthread_mutex_t lock_global;
extern pthread_mutex_t lock_write;
@@ -37,23 +38,23 @@ extern pthread_mutex_t lock_write;
void* wipe(void* device)
{
nndevice_t* d = (nndevice_t*)device;
- int output_progress = 0;
- unsigned long int blocks = 0;
- unsigned long long blocks_written = 0;
+ unsigned long long bytes_written = 0;
long double percent = 0.0L;
+ if(d->path[0] == 0)
+ {
+ return NULL;
+ }
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);
+ pthread_mutex_unlock(&lock_global);
}
else
{
- blocks = d->blksz * d->blks;
+ d->blks = d->blksz * d->blks;
}
FILE* fp = fopen(d->path, "w+t");
@@ -65,22 +66,15 @@ 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 < d->sz)
+ while(bytes_written < d->sz)
{
- pthread_mutex_lock(&lock_global);
- blocks_written += nnwrite(fp, d->blksz);
- pthread_mutex_unlock(&lock_global);
-
- //printf("output_progress = %d\n", output_progress);
- if(output_progress >= 512)
+ if(verbose_flag)
{
- 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;
+ percent = (long double)((bytes_written / (long double)d->sz) * 100);
+ printf("%s: %llu of %llu (%0.2Lf%%)\n", d->path, bytes_written, d->sz, percent);
}
- ++output_progress;
+
+ bytes_written += nnwrite(fp, d->blksz);
}
COM(self, "%s complete\n", d->path);
pthread_exit(NULL);
@@ -104,7 +98,7 @@ int nnwrite(FILE* fp, int bsize)
{
unsigned int bytes_written = 0;
char* buffer = randstr(bsize);
- pthread_mutex_lock(&lock_write);
+ //pthread_mutex_lock(&lock_write);
if(safety_flag)
{
/* simulation */
@@ -146,12 +140,14 @@ unsigned int nngetseed()
{
if((fread(&randseed, 1, sizeof(int), randfp)) > 0)
{
- COM(self, "(urandom) Seed is %lu\n", randseed);
+ if(verbose_flag)
+ COM(self, "(urandom) Seed is %lu\n", randseed);
return randseed;
}
unsigned int t = time(NULL);
- COM(self, "(UNIX Epoch) Seed is %lu\n", t);
+ if(verbose_flag)
+ COM(self, "(UNIX Epoch) Seed is %lu\n", t);
return t;
}