0

I'm looking for a good way of calculating a checksum of an entire flash drive's contents.

Not a particular file, or a group of files, but the entire volume which is read only so it never changes.

Does anyone know of any C, C++, or C# code that can open a flash drive volume and read it byte for byte efficiently so I can feed this to say an MD5 or SHA1 hash algorithm?

I see lots of code for now to read files but I'd like to read the entire physical drive from beginning to end.

user1090205
  • 91
  • 1
  • 2
  • 5
  • 1
    This is probably not a good idea. Flash memory has limited life (in terms of number of reads/writes); you don't want to do a frequent heavy IO operation like this. What are you trying to accomplish? – ashes999 Feb 23 '12 at 21:26
  • 1
    @ashes999: Only writes wear flash memory. The potential number of reads is practically unlimited. – Ben Voigt Feb 23 '12 at 21:27
  • @BenVoigt are you sure? I guess I'm mistaken then; that's good to know. – ashes999 Feb 23 '12 at 21:28
  • Any particular reason you did not find answers to your original question useful? possible duplicate of [How to read the contents of an entire disk bit by bit](http://stackoverflow.com/questions/9417557/how-to-read-the-contents-of-an-entire-disk-bit-by-bit) – Alexei Levenkov Feb 23 '12 at 21:43

2 Answers2

2

You can open a whole volume using the OS-level file APIs (C# suggests Windows, where the function is CreateFile).

You should probably unmount the filesystem first, however, lest some other process change your data while you're using it. Also, a checksum of the entire volume is not likely to be useful, since it'll change whenever the "last accessed time" field gets updated.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

Perhaps look at the source code for dd and the SHA-1 functions in OpenSSL.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345