Wipe Free space on hard disk drive using C#

Crash893 picture Crash893 · Jan 14, 2010 · Viewed 7.4k times · Source

I have been tasked to overwrite all the free space on a few laptops 3 times. I know there are some alternatives but I like to know how things work and if I can to do it myself with C#.

1) yes, I know there are plenty of freeware applications that will do this

2) no, we don't need to conform to any specific government standard

Where do I look for ideas on how to start this?

Thanks if you can point me in the right direction.

Can it be achieved using C#? If so, how?

Answer

Paul Sasik picture Paul Sasik · Jan 14, 2010

Simple algorithm:

  • Create a large text file full of arbitrary text (best to use a pre-created file instead of regenerating random for performance reasons. Test it out.)
  • Create a clever folder and file naming scheme so as to be able to track the files. You should also track the files with your app but if it crashes, especially near the end of a first few test runs, you'll want to be able to easily find and clean up your handy work.
  • Write it to the HDD until it's full
  • Delete the files you created
  • Repeat above steps two more times

Update: More advanced consideration on wiping per subsequent discussion:

  • On first pass write files of 0x0000 values (all bits off)
  • On second pass write all bits as 0xFFFF (all bits on)
  • On last pass repeat with 0x0000

The above ignores a few ideas such as what is the best size of the file, depends on your file system anyway. You might also get different behaviors from the OS as you near a filled HDD...