#!/usr/bin/env python """ wipefreespace.py This program is a simple, one-pass disk overwrite utility. It overwrites all the unused space on the disk volume you specify in 'filepath' with the bit pattern you specify in 'pattern1', 'pattern2', 'pattern3', and 'pattern4'. It overwrites the disk's free space; it does nothing for the disk space used by virtual memory. To wipe the free space for other than the volume of the current directory, change "filepath" below. You may also change the bit patterns written by altering the four pattern variables. It would be a simple exercise to mod for multiple passes with different or randomly varying bit patterns. The time required depends on the amount of free space to be wiped and drive speed. On my PowerBook... 15MB/sec. YMMV. NB: This program in NO WAY conforms to any of the MIL-SPECs for wiping drives. Larry Bugbee August 2003 """ import os, struct, time # '.' = current directory filepath = '.' # '/' '/mnt/hdb2/' 'D:/' <---<< pattern1 = 0xf3 # 0x00 0xc3 0x3c 0xff etc. <---<< pattern2 = 0x81 # 0x00 0xc3 0x3c 0xff etc. <---<< pattern3 = 0x82 # 0x00 0xc3 0x3c 0xff etc. <---<< pattern4 = 0x03 # 0x00 0xc3 0x3c 0xff etc. <---<< t0 = time.time() filename = filepath+'___wiped___' # the *4 /4 is to get around word alignment issues (64 bit? *8 /8) chunksize = 1024*128 # assures easy divisibility by 4 (or 8?) data = struct.pack('4B', pattern1, pattern2, pattern3, pattern4) data *= (chunksize/4) mb = 0 # megabytes written try: f = open(filename, 'wb') try: while 1: # repeat until disk full exception f.write(data) mb += 1 except: f.close() mb *= float(chunksize)/(1024*1024) t1 = time.time() t = t1-t0 print ' elapsed time of %5.2f seconds for %5.1f MB' % (t, mb) print ' rate: %5.1f MB per sec' % (mb/t) # comment out the next line only if you want to see the file and # are willing to delete it manually os.remove(filename) except Exception, e: print e