What's the preferred way to unmount?

392 views
Skip to first unread message

Alejandro Exojo

unread,
Jun 22, 2015, 10:49:29 AM6/22/15
to osxfus...@googlegroups.com
Hello.

Now a question easier than my previous one. How do you unmount a
(OSXFUSE) filesystem from code? Do you launch a new process with the
`umount` program, or you do it making calls to FUSE functions? I've
attempted several combinations of the latter, with no luck.

I mount more or less like this:

// (...) Setup options, operations, etc.
// Save some return values for later in member variables of a class.
m_channel = fuse_mount(mountpoint, &arguments);
m_filesystem = fuse_new(m_channel, &arguments, &operations,
sizeof(operations), 0);
int result = fuse_loop(m_filesystem);
fuse_unmount(mountpoint, m_channel);
fuse_destroy(m_filesystem);

This is more or less what fuse_main does, but I don't launch the file
system from a console, so the UNIX signal handlers are not useful to me
to interrupt the file system. I try to unmount it the same way it's done
by those signal handlers that fuse_main installs, which is:

fuse_session_exit(fuse_get_session(m_filesystem));

I call that from a different thread instead of a signal handler.

This works with one important issue: it unmounts the file system cleanly
after some access to the file system, and after about 60 seconds (the
FUSE_DEFAULT_DAEMON_TIMEOUT, I assume). On Linux the behaviour is the
same, but there is no delay. This matches this known behaviour:

http://stackoverflow.com/questions/8903448/libfuse-exiting-fuse-session-loop/

On Linux the following works unmounting immediately without noticeable
problems, but Valgrind reports some memory issues (and on OSXFUSE it
crashes the application):

fuse_unmount(mountpoint, m_channel);
// And then NOT calling fuse_unmount again after fuse_loop.

Calling umount (or unmounting through Finder) seems to work always, and
I do wonder if that's the only supported way.

Thank you.
Regards.

Alejandro Exojo

unread,
Jul 21, 2015, 3:32:36 PM7/21/15
to osxfus...@googlegroups.com
On 22 June 2015 at 16:49, Alejandro Exojo <al...@vikingsoft.eu> wrote:
> Now a question easier than my previous one. How do you unmount a
> (OSXFUSE) filesystem from code? Do you launch a new process with the
> `umount` program, or you do it making calls to FUSE functions? I've
> attempted several combinations of the latter, with no luck.

Hi.

Sorry to insist on this, but, anyone has a hint? I've attempted all
the combinations I can think of through code, and launching "umount"
in a new process has been unreliable in my experience.

Thank you.

Sam Moffatt

unread,
Jul 22, 2015, 1:02:36 AM7/22/15
to osxfus...@googlegroups.com
IMHO I'm not sure it makes sense for a file system to unmount itself except in an error state. Generally the user should elect to unmount the file system. It could be that spawning unmount is unreliable because something is holding onto a file handle. Perhaps look into trying hdiutil to see if it can work a little better.

What is the reason for the file system driving the unmount?

Cheers,

Sam

--
Sam Moffatt
http://pasamio.id.au
Note: I'm not at my desk, responses may be delayed
> --
> You received this message because you are subscribed to the Google Groups "OSXFUSE" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to osxfuse-grou...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Alejandro Exojo

unread,
Jul 22, 2015, 4:56:30 AM7/22/15
to osxfus...@googlegroups.com
On 22 July 2015 at 07:02, Sam Moffatt <pas...@gmail.com> wrote:
> IMHO I'm not sure it makes sense for a file system to unmount itself except in an error state. Generally the user should elect to unmount the file system. It could be that spawning unmount is unreliable because something is holding onto a file handle. Perhaps look into trying hdiutil to see if it can work a little better.

Being blocked because the file system is busy is something I
considered, too, but in the console, it worked. I will look into
hdiutil, thank you.

> What is the reason for the file system driving the unmount?

I'm doing a GUI app that on start creates the file system. From the
GUI, the user should be able to choose the directory of the mount
point. I could force the user to unmount through Finder and restart
the application after changing the mount point, but just restarting
the application has been useful to me while developing the application
itself. On Linux, the call to fusermount -u has been reliable enough.

There might be other cases that I can or can't think of, like having
the file system and application running and the system shutting down,
etc.

Thank you for your help.
Reply all
Reply to author
Forward
0 new messages