Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
useful:encryption:randfs [2009/01/05 15:05] – chemist | useful:encryption:randfs [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | if you are the author of this script please let me know (I forgot to link you down) | ||
- | **randfs /mnt/file** | ||
- | <code perl> | ||
- | # | ||
- | |||
- | use strict; | ||
- | use warnings; | ||
- | use IO::File; | ||
- | |||
- | $|=1; | ||
- | |||
- | my $file; | ||
- | |||
- | sub randomString(){ | ||
- | my $fetch=(int(rand(512))+512)*20480; | ||
- | my $data=''; | ||
- | my $packet; | ||
- | my $fh=new IO:: | ||
- | || die(" | ||
- | binmode($fh); | ||
- | while(length($data) < $fetch){ | ||
- | printf(" | ||
- | read($fh, | ||
- | $data.=$packet; | ||
- | } | ||
- | $fh-> | ||
- | printf(" | ||
- | return($data); | ||
- | } | ||
- | |||
- | sub fillDisk($){ | ||
- | my $string=shift; | ||
- | my $written=0; | ||
- | my $size=length($string); | ||
- | my $started=time; | ||
- | my $mbytes; | ||
- | $SIG{TERM}=$SIG{INT}=sub{ | ||
- | print(" | ||
- | removeFile(); | ||
- | exit(1); | ||
- | }; | ||
- | my $fh=new IO:: | ||
- | || die(" | ||
- | binmode($fh); | ||
- | while(print($fh $string)){ | ||
- | $written+=$size; | ||
- | $mbytes=$written/ | ||
- | printf(" | ||
- | } | ||
- | $fh-> | ||
- | print(" | ||
- | } | ||
- | |||
- | sub syncDisk(){ | ||
- | print(' | ||
- | system('/ | ||
- | print(" | ||
- | } | ||
- | |||
- | sub removeFile(){ | ||
- | print(' | ||
- | unlink($file); | ||
- | system('/ | ||
- | print(" | ||
- | } | ||
- | |||
- | sub showUsage(){ | ||
- | print(<< | ||
- | This programm will generate a urandom string of 10 to 20 MBytes, | ||
- | repeatedly write this into the given file until writing becomes impossible | ||
- | and remove the file from disk. | ||
- | |||
- | The given file must NOT exist! | ||
- | |||
- | Usage: $0 < | ||
- | |||
- | __EOF | ||
- | exit(1); | ||
- | } | ||
- | |||
- | sub main(){ | ||
- | $file=$ARGV[0]; | ||
- | print(" | ||
- | unless(defined($file) && $file=~/ | ||
- | showUsage(); | ||
- | } | ||
- | fillDisk(randomString()); | ||
- | syncDisk(); | ||
- | removeFile(); | ||
- | exit(0); | ||
- | } | ||
- | |||
- | main(); | ||
- | 1;</ |
Last modified: le 2009/01/05 15:05