[ale] really really deleting files....

Christopher Fowler cfowler at outpostsentinel.com
Tue Jun 24 13:43:05 EDT 2003


Here is one:

---- Cut Here --- Cut Here ---

/* gcc -o wipe ./wipe.c */
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

static char
getRandomByte(void) {
    static int fd = -1;
    char byte;

    if(fd == -1) {
        if((fd = open("/dev/urandom", O_RDONLY)) == -1) {
            perror("open urandom");
            exit(2);
        }
    }

    if(read(fd, &byte, 1) != 1) {
        perror("read");
        exit(1);
    }

    return byte;
}


int
main(int argc, char **argv) {
    struct stat finfo;
    char byte;
    int fd;
    int x;
    int y;

    if(argc != 2) {
        fprintf(stderr, "wipe <filename>\n");
        exit(0);
    }

    if((fd = open(argv[1], O_WRONLY)) == -1) {
        perror("open");
        exit(1);
    }

    if(fstat(fd, &finfo) == -1) {
        perror("get file size");
        exit(1);
    }

    for(y = 0; y != 1024; y++) {
        printf("\rPass %d", y);
        fflush(stdout);
        lseek(fd, SEEK_SET, 0);
        for(x = 0; x != finfo.st_size; x++) {
            byte = getRandomByte();
            write(fd, &byte, 1);
        }

	sync();
    }

    unlink(argv[0]);
}

/* vi: set ts=4 sw=4:*/

---- Cut Here --- Cut Here ---

I think that should get it.  

_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list