Bypassing Disk Caching

S

sturnfie

Anyone know a way to bypass disk caching in Windows XP?

I am working on a C# program that needs to verify the integrity of
data that was copied to a removable drive. My approach is to read the
data back and compare it to the original data source. Problem is,
this process is happening way too quickly to be possible.

I used filemon to see what the file system is doing when I attempt to
copy back the file I just wrote to the removable drive, and although
there are tons of FASTIO_WRITE requests directing chucks of the data
to a local file (a file that holds a "copy" of the removable drive's
data), there is not a single request for any information from the
external drive.

My best guess is that the entire file is still in the local disk's
cache; this would explain the super speeds I am seeing.

So my question(s): Is there a way to force windows to not use the
disk cache? If not, is there a way to flush the disk cache? Is there
another workaround someone can suggest?

I am going to start trying to hack something together to fool it
(maybe renaming the file on the external drive will be enough to fool
it), but thanks in advance to anyone who knows a proper way to handle
this problem.
 
B

Barry Kelly

Anyone know a way to bypass disk caching in Windows XP?

Yes, use FILE_FLAG_NO_BUFFERING with CreateFile. That'll require
P/Invoke etc., and there are other restrictions, like working with
aligned buffers of specific sizes etc.
If not, is there a way to flush the disk cache?

FlushFileBuffers is the function to use, again with P/Invoke.

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top