3

I've written some simple filesystems with Python-fuse, but now I'm wanting to do something that I can't find in the pydoc nor in the sample scripts I've found: when the filesystem is unmounted with fusermount -u, I want to trap that action, perform the umount, and then rmdir the mount directory created by my program's initialization script. If it is even possible, what's the magic incantation to trap the umount action?

I can see how that could easily turn into an endless loop, but I can hopefully figure out how to disable the umount trap the first time it's hit.


Update: I found destroy at http://omake.metaprl.org/prerelease/omake-dll-fuse.html#htoc582 and added the method, but it doesn't seem to be called.
jcomeau_ictx
  • 35,098
  • 6
  • 89
  • 99

2 Answers2

0

Another solution, though not specific and not tested under Python, is prevent FUSE from "daemonizing" with the -f switch.

In this case, the fuse_main method will block until the filesystem in unmounted, and you will get the control back afterwards.

If you do need the deamon behavior, you can reimplement it yourself before mounting.

Kevin
  • 4,355
  • 2
  • 34
  • 58
0

found it! it's fsdestroy() in Python-fuse. located it by:

jcomeau@intrepid:/usr/src/google-desktop/api$ cat /usr/lib/python2.6/dist-packages/fuseparts/* | strings | grep destroy
fsdestroy

What I used was:

def fsdestroy(self, data = None):
  syslog.syslog(syslog.LOG_INFO, 'destroy %s: %s' % (self.mountpoint, data))
  os.rmdir(self.mountpoint)

Don't know if the data parameter is necessary or not, but doesn't hurt. And apparently, it's called after the umount, so I didn't have to worry about handling that.

jcomeau_ictx
  • 35,098
  • 6
  • 89
  • 99
  • Doesn't work for me. If I override this method, when `fusermount -u` is called the contents of the method never run (the `os.rmdir` doesn't have any effect and prints don't output anything even though they do work in other methods), and the script hangs. I have to kill it manually with `kill -KILL`. I have `fuse.fuse_python_api = (0, 2)` – Suzanne Soy May 17 '12 at 21:25