I have a big issue, that I sort of fixed after 2 days of tests, with my ProxyCrypt tool: when the system shuts down, the proxy is killed and so, the driver is waiting indefinitely, blocking this way the system.
I could ask Olof to add a timeout in the driver, but this will also add several other issues.
So, I need to unmount the volume myself, by checking the system shutdown. Here, the difficulties start...
Starting a process at the shutdown is really not recommanded. So I could call the functions of imdisk.cpl, but with all the notifications, this is too slow. So, I finally made my own dismount function, with only 2 calls to DeviceIoControl, with a handle opened to my volume: FSCTL_DISMOUNT_VOLUME and IOCTL_STORAGE_EJECT_MEDIA (strangely, without the second one, the dismount take more time).
I first tested this by defining an handler with SetConsoleCtrlHandler. I don't have tested on previous versions of Windows, but with 8.1, I simply get nothing at the shutdown. Or at least, I can do nothing, not even creating and closing an empty file. But this handler works for all other events, for an amount of time that not only depends of the event, but also strangely of what I am doing.
In all cases, this no longer reliable.
So, I tried to create a dummy window to check for the WM_QUERYENDSESSION message. It works, but if I create a thread to start something long and answer FALSE to this message, my process is killed about one second later. However, if I take that time directly while responding to the message, I get about 5 seconds.
In all cases, processing this message does no longer work to prevent the shutdown. I cannot even get the fullscreen message that says that an application is not responding.
Finally, I think to directly use WM_ENDSESSION. I doubt (and I don't hope) that Microsoft change its behavior before a long time.
It also seems that, at least at the shutdown of Windows 8.1, the FlushFileBuffers function is not necessary: even if start the shutdown just after a copy of large files, Windows flushes everything itself while several seconds, without FlushFileBuffers, and I have no data lost. That said, to be sure, maybe using it can be useful.
Anyhow, I wonder what we can do to fix this issue reliably.