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?