/*_____________________________________________________________________________ | | | File name: cftcd.c | | | | Program name: Completely Fill The Current Directory | | | | Version: 2.1 | | | | Description: Fills the directory it's located in entriely with 1's, i.e. | | 0xFF. It does so effeciently by making as large of write as possible and | | halving the size each time. It also compensates for possible file size limits| | by filling a file until the file system won't allow. Quits when writes are no| | longer possible. Capable of continuing where it left off. Can be used to wipe| | free space because it writes on all freespace. Then, the files can simply be | | deleted. 0xFF is chosen becuase it does not show up as a displayable | | character. The files are .txt, so it looks like a giant empty notepad file. | | This is intentional to be possibly confusing. | | | | Author: Thaddeus Joseph "T.J." Jancewicz | | | | Creation date: Tuesday 13 January 2009 | | | | Update date: Friday 24 August 2010: Realized fwrite() doesn't output | | that makes sense to compare to the write size. | |____________________________________________________________________________*/ #include #include #include #include // nope, we don't EVER need to return anything. ever. void main(void) { FILE *file = NULL; /* the following array sizes won't overflow unless you're trying to fill NASA... and are running a 128-bit computer AND rewrite this code for 128 bit ints */ char file_name[30], number_to_append[26], nothing = 0xFF; #ifdef LLONG_MAX #define WRITE_SIZE_LIMIT ULLONG_MAX /* these lines are here if we're running on a 64-bit computer. the hilarious part is that no system on Earth can even store 2^64-1 bytes. well, in 10 years*/ unsigned long long file_number = 0, write_size, check_value = 0; #else #define WRITE_SIZE_LIMIT ULONG_MAX unsigned long file_number = 0, write_size, check_value = 0; #endif for( ; ; file_number++ ) { sprintf(number_to_append, "%u", file_number); /* itoa() can give negatives */ file_name[0] = 0; // blanks the string strcat( strcat( file_name, "blank"), strcat( number_to_append, ".txt") ); if( !( file = fopen(file_name, "ab" ) ) ) { // quit if we can't make anymore files return; // exit unforunately takes an argument. we return nothing } setbuf(file, NULL); // disable buffering for increased performance for( write_size = WRITE_SIZE_LIMIT ; ; ) { // check_value holds the bytes written for comparison // also, don't change the 1. you'll read random bytes check_value = fwrite(¬hing, 1, write_size, file); if( !check_value ) { // we work backwards by exponents. byte by byte is SLOW write_size /= 2; } if( !write_size || feof(file) ) { // go make another file if we hit the file size limit /* some file systems work wierd, so we include ALL of the above checks. the checks are arranged performance stealing backwards. */ break; } } fclose(file); } }