Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wipe Free space on hard disk drive using C# [closed]

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?

like image 762
Crash893 Avatar asked Jan 14 '10 15:01

Crash893


2 Answers

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...

like image 188
Paul Sasik Avatar answered Sep 21 '22 10:09

Paul Sasik


This is really dangerous but..

You can use the Defrag APIs (here's a C# wrapper) to get hold of the drive 'map' and specifically target the freespace and write junk to those parts of the disk.

like image 40
JBRWilkinson Avatar answered Sep 17 '22 10:09

JBRWilkinson