Force flush of unwritten data to USB stick?
-
Hello! When writing to an USB stick, Windows caches all writes. We are therefore required to safely eject the USB stick in Windows before removing it. Unfortunately it frequently happens that users remove USB sticks without ejecting it first. I would now like to force Windows to flush a file immediately when it's closed programmatically, i.e. I'm looking for an API function that allows such flushing. I am not looking for a way to completely disable the caching. The file is written using CreateFile/WriteFile. Is there such an API or way to achieve flushing? Thanks and best regards Dominik
Too many passwords to remember? Try KeePass Password Safe!
-
Hello! When writing to an USB stick, Windows caches all writes. We are therefore required to safely eject the USB stick in Windows before removing it. Unfortunately it frequently happens that users remove USB sticks without ejecting it first. I would now like to force Windows to flush a file immediately when it's closed programmatically, i.e. I'm looking for an API function that allows such flushing. I am not looking for a way to completely disable the caching. The file is written using CreateFile/WriteFile. Is there such an API or way to achieve flushing? Thanks and best regards Dominik
Too many passwords to remember? Try KeePass Password Safe!
I've done that before. IIRC, you have to delve into DeviceIoControl().
-
I've done that before. IIRC, you have to delve into DeviceIoControl().
Do you remember the control code you used? I've only found
IOCTL_STORAGE_EJECT_MEDIA
and such things, but no code to only flush write buffers. Thanks for your reply, best regards Dominik
Too many passwords to remember? Try KeePass Password Safe!
-
Do you remember the control code you used? I've only found
IOCTL_STORAGE_EJECT_MEDIA
and such things, but no code to only flush write buffers. Thanks for your reply, best regards Dominik
Too many passwords to remember? Try KeePass Password Safe!
Look at "FSCTL_LOCK_VOLUME". MSDN Library has this to say about it: "The system flushes all cached data to the volume before locking it. For example, any data held in a lazy-write cache is written to the volume."
-
Look at "FSCTL_LOCK_VOLUME". MSDN Library has this to say about it: "The system flushes all cached data to the volume before locking it. For example, any data held in a lazy-write cache is written to the volume."
-
Hello! When writing to an USB stick, Windows caches all writes. We are therefore required to safely eject the USB stick in Windows before removing it. Unfortunately it frequently happens that users remove USB sticks without ejecting it first. I would now like to force Windows to flush a file immediately when it's closed programmatically, i.e. I'm looking for an API function that allows such flushing. I am not looking for a way to completely disable the caching. The file is written using CreateFile/WriteFile. Is there such an API or way to achieve flushing? Thanks and best regards Dominik
Too many passwords to remember? Try KeePass Password Safe!