SerCeMan / jnr-fuse

FUSE implementation in Java using Java Native Runtime (JNR)
MIT License
370 stars 88 forks source link

Unmounting on Windows (WinFsp) #28

Closed PhilLehmann closed 7 years ago

PhilLehmann commented 7 years ago

Thanks for this great library. I just couldn't believe how quick one could get started! :-)

I am not sure whether this is a usage question or a bug report, so let's go:

When mounting, AbstractFuseFSuses the correct path to WinFsp to initialize communication with it:

https://github.com/SerCeMan/jnr-fuse/blob/4b97249333ef360335ed7fe2e7cf46a37f34cfcd/src/main/java/ru/serce/jnrfuse/AbstractFuseFS.java#L63

For unmounting, it simply calls MountUtils which does not seem to be aware of WinFsp:

https://github.com/SerCeMan/jnr-fuse/blob/561d140f9bf6e1ecb66327abaee91d16554af582/src/main/java/ru/serce/jnrfuse/utils/MountUtils.java#L16-L20

So unmounting fails and the device stays forever. Am I doing something wrong or does WinFsp not support unmounting? Thanks!

webfolderio commented 7 years ago

You shoudn't call the MountUtils.unmout() for WinFsp, but its required by fuse. WinFsp listen Ctrl+C break event to unmount the path.

PhilLehmann commented 7 years ago

Well I just call AbstractFuseFS.umount as I would on any other OS, which then calls MountUtils.umount.

https://github.com/SerCeMan/jnr-fuse/blob/4b97249333ef360335ed7fe2e7cf46a37f34cfcd/src/main/java/ru/serce/jnrfuse/AbstractFuseFS.java#L294-L300

That method seems to have code for Linux and macOS, but not Windows.

As WinFsp is handed over to LibraryLoader<LibFuse>, maybe that can be used to send the CTRL + C to it. Studying the code, I could not find a way... maybe there is a non obvious solution? We should implement this solution within AbstractFuseFS.umount, so that it behaves the same for all three OS. The mount command of it does, too.

PhilLehmann commented 7 years ago

We might be able to use the windows command taskkill /pid <pid> to terminate the WinFsp process in question. Would that be feasible?

webfolderio commented 7 years ago

Unfortunately, taskkill does not send Ctrl+C event to console application.

SerCeMan commented 7 years ago

Hi, @philrykoff!

As mentioned before, I don't see any feasible way to implement unmounting for reasons described in https://github.com/billziss-gh/winfsp/issues/47. It might make sense to throw a reasonable exception though instead of calling linux/macos tools.

PhilLehmann commented 7 years ago

That would be better than the status quo...

This guy managed to send CTRL C from Java, but only via yet another native dependancy (SendMessage.exe) - https://stackoverflow.com/a/10336831/284364

So while that way would offer a solution, it would be a truly ugly one. I'll ask the WinFsp guys about the possibility to add an invokable api.

billziss-gh commented 7 years ago

Under WinFsp-FUSE fuse_exit is able to cleanly exit and unmount the file system.

For example, here is how I handle FUSE unmount in cgofuse:

https://github.com/billziss-gh/cgofuse/blob/v1.0.3/fuse/host.go#L459-L492

SerCeMan commented 7 years ago

@billziss-gh Thanks for the info! Then it's actually very easy to implement.

SerCeMan commented 7 years ago

Hey, @philrykoff!

I added the fuse_exit method on master. Can you check that it solves the problem?

PhilLehmann commented 7 years ago

Unmounting works like a charm - thanks so much! 😄

billziss-gh commented 7 years ago

Good work @SerCeMan :)

SerCeMan commented 7 years ago

I published 0.5.1 with the fix included.