Closed shujaat-github closed 2 years ago
Hi @shujaat-github ,
What is exactly the situation ? You would like to know whether files are open and if it is safe for you to ask Dokan for unmounting the drive ?
Hi @shujaat-github ,
What is exactly the situation ? You would like to know whether files are open and if it is safe for you to ask Dokan for unmounting the drive ?
Yes, that's exactly what I want to know whether files are open and if it's safe for me to ask Doken to unmount the drive.
Unfortunately, the library does not keep an Open / Close count but luckily that's something that possible to implement by the userland filesystem by increasing a counter on Open and decreasing on Close. You might want to ignore some Open that are kept long by the system to be aware if the target has changed like folders.
@Liryna Probably you are talking about the following two functions for Close and Open respectively: https://github.com/dokan-dev/dokany/blob/1c9c20d1d874c1756cfb7d2ebf61e746054196df/samples/dokan_mirror/mirror.c#L1738 https://github.com/dokan-dev/dokany/blob/1c9c20d1d874c1756cfb7d2ebf61e746054196df/samples/dokan_mirror/mirror.c#L1739
But I observed that MirrorCloseFile is called more than MirrorReadFile for the SAME FILE, so when I use a signed integer counter and decrease that counter on MirrorCloseFile for the SAME FILE then the counter becomes negative while the file remains open in my Notepad/Word Application.
There is one Close for each CreateFile for one context. You can have multiple CreateFile on the same file at the same time. That's why you will have the same number of close. The number of readfile is not linked. You can have no readfile during a life time of a context.
@shujaat-github Let me know if you need further information otherwise can I close this issue ?
I have come across a need to prevent Dokany from unmounting drive if there are some opened files. I wonder if there is any built-in feature in Dokany to achieve this or there is any workaround.