diff options
-rw-r--r-- | include/netnuke.h | 2 | ||||
-rw-r--r-- | src/misc.c | 2 | ||||
-rw-r--r-- | src/netnuke.c | 7 | ||||
-rw-r--r-- | src/nukectl.c | 17 |
4 files changed, 16 insertions, 12 deletions
diff --git a/include/netnuke.h b/include/netnuke.h index b24af74..ee39a13 100644 --- a/include/netnuke.h +++ b/include/netnuke.h @@ -53,7 +53,7 @@ int nnlogcleanup(); int COM(const char* func, char *format, ...); void* wipe(void* device); pthread_t nnthread(nndevice_t* device); -int nnwrite(FILE* fp, int bsize); +int nnwrite(int fd, int bsize); void nnrandinit(); void nnrandfree(); unsigned int nngetseed(); @@ -33,3 +33,5 @@ int strind(const char* str, const char ch) } return index; } + + diff --git a/src/netnuke.c b/src/netnuke.c index 16f902e..7ff94bc 100644 --- a/src/netnuke.c +++ b/src/netnuke.c @@ -138,13 +138,14 @@ void usage(const char* progname) int main(int argc, char* argv[]) { +/* Re-enable this later... jesus testing is getting annoying. uid_t uid=getuid(), euid=geteuid(); - if (uid < 0 || uid != euid) + if (uid != 0 || uid != euid) { COM(self, "Need root... exiting\n"); exit(1); } - +*/ if((nnlogcleanup()) != 0) { fprintf(stderr, "Failed to cleanup %s: %s\n", NNLOGFILE, strerror(errno)); @@ -299,7 +300,7 @@ int main(int argc, char* argv[]) for( i = 0; device[i] != NULL ; i++ ) { thread[i] = (pthread_t)nnthread(device[i]); - COM(self, "thread id: %ld\n", thread[i]); + COM(self, "thread id: %8X %8X\n", thread[i]); } /* Catch up */ usleep(10000); diff --git a/src/nukectl.c b/src/nukectl.c index 8b8c7ff..d2853cb 100644 --- a/src/nukectl.c +++ b/src/nukectl.c @@ -24,11 +24,12 @@ #include <errno.h> #include <unistd.h> #include <pthread.h> +#include <fcntl.h> #include "netnuke.h" FILE* randfp; unsigned int randseed; -unsigned long long total_written_bytes; +unsigned long long total_written_bytes = 0; extern unsigned int blksz_override; extern int verbose_flag; extern int safety_flag; @@ -76,8 +77,8 @@ void* wipe(void* device) d->blks = d->blksz * d->blks; } - FILE* fp = fopen(d->path, "w+t"); - if(fp == NULL) + int fd = open(d->path, O_WRONLY | O_SYNC); + if(fd < 0) { COM(self, "Unable to open %s: %s\n", d->path, strerror(errno)); return (int*)1; @@ -93,7 +94,7 @@ void* wipe(void* device) printf("%s: %llu of %llu (%0.2Lf%%)\n", d->path, bytes_written, d->sz, percent); } - bytes_written += nnwrite(fp, d->blksz); + bytes_written += nnwrite(fd, d->blksz); } COM(self, "%s complete\n", d->path); pthread_exit(NULL); @@ -113,11 +114,11 @@ pthread_t nnthread(nndevice_t* device) return thread; } -int nnwrite(FILE* fp, int bsize) +int nnwrite(int fd, 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 */ @@ -126,11 +127,11 @@ int nnwrite(FILE* fp, int bsize) else { /* destructive */ - //bytes_written = fwrite(buffer, sizeof(char), bsize, fp); + //bytes_written = write(fd, buffer, bsize); bytes_written += bsize; } - total_written_bytes += bytes_written; + //total_written_bytes += bytes_written; pthread_mutex_unlock(&lock_write); free(buffer); |