Delayed Write

I have a named device (“\Device\MyDevice”) created using IoCreateDeviceSecure that takes MJ_IRP_READ and MJ_IRP_WRITE and read/writes the buffer from/to a virtual partition file (opened with FILE_WRITE_THROUGH flag) on a a physical disk.

I can format the device using the FormatEx API and I can access the device using the Win32 API file functions (CreateFile, CopyFile, etc) by passing a "\.\MyDevice" prefix to file names.

The following code…

CopyFile(L"C:\Windows\Explorer.exe", L"\\.\MyDevice\Explorer.exe", FALSE);

works fine, but if I stop the driver (NET STOP MYDRIVER) after the copy has finished, I sometimes get a “Delayed Write Failure” referencing “\MyDevice\$Mft” and my virtual partition file gets corrupted.

As I have not assigned a drive letter to my device, how can I stop the file system from caching my device?

> works fine, but if I stop the driver (NET STOP MYDRIVER) after the copy has finished, I sometimes

get a “Delayed Write Failure” referencing “\MyDevice\$Mft” and my virtual partition file gets
corrupted.
As I have not assigned a drive letter to my device, how can I stop the file system from caching my
device?

The Real And Proper Way is to make your driver PnP and emulate surprise removal of the virtual drives you need to stop.

If you don’t care XP (a good habit BTW), then you can write a StorPort virtual miniport for this.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com