Separate Dokan instance creation and Mount
Ideally even if it is not an user requirement but only a discussion (https://github.com/dokan-dev/dokany/issues/50#issuecomment-170402742), we should be able to assign several mount point to the same file system / volume. This means Dokan instance creation and mount should be separated .
I think this issue should be done for 1.0.0 to fix stability issue when Antivirus (or else) are contacting dokan driver for the new mounted device even if dokan has not finished to create it and this create BSOD.
Message from @marinkobabic
I have installed Windows 7 x64 and I have been able to reproduce lot of various BSODs running your code. Then I tried to fix each of them. After a lot of time I have realized what is there going on and that it makes definitely no sense to fix the BSODs at this point. Before fixing any of the BSODs the driver must be redesigned the following way:
When usermode is doing a mount, the code should not return until the mount is really finished. Actually the device is created, mounting is in progress and during this process the device is deleted which causes a lot of problems
When usermode is doing an unmount and the mounting is still in progress, the STATUS_DEVICE_IN_NOT_READY should be returned or the code should wait until the mounting is finished.
Then we can start to fix the remaining BSODs, if any still there. An device can also be unmounted by the timer automatically and there is the same code executed like we are doing the unmount manually.
I thing those changes should be done here #136 and one of the tests should be your code above.
AV Issue reported https://groups.google.com/forum/#!msg/dokan/7ahNxJ7XNOI/52bTIV-HEQAJ
You are right. I actually don't even think that the separation would solve the problem. In generally we have the the problem that we are for example checking for drive availability or antivirus and if at this time the device is removed, we can get a BSOD because of some running Irp. The DeviceObject will become invalid and if the Irp is completed we will get an BSOD. A much better locking mechanism is needed like RemoveLock.
This is also the reason we get BSOD during drive availability check. It has been also reported. It's just timing. The check sends some requests and while those are processed the drive is removed.