Solved Xfce 4.16 - Mount/Unmount USB drives with Thunar (bsdisks/gvfs)

Hi everyone,

my system is FreeBSD 13.1 Release, Xfce 4.16, Thunar 4.16.11 and bsdisks 0.27. Mounting and unmounting UFS or FAT formatted USB sticks with Thunar works fine (as non-root).
But as soon as I use NTFS or exFAT formatted sticks, unmounting is impossible as non-root. Thunar says: "Operation not permitted."
And in this case Thunar shows always two entries in locations, one for /dev/da1 and one for /dev/da1p1.

My workaround so far: open a terminal, become root and unmount the file system... not very comfortable :'‑(

I think the reason for this behavior is the usage of fusefs, but I'm not sure.
Just to clarify, mounting and unmounting as non-root works fine in a terminal, so my basic setup (vfs.usermount=1 etc.) should be fine.

What is your experience with bsdisks under Xfce?
Any solutions for unmounting fusefs file systems as non-root?
 
I thought you meant dsbmc/dsbmd (client/daemon), I had to search to identify the acronyms. I have used it in the past with no problems.

Or you may want to continue checking system logs or requested output for udisks bugs. Maybe you need to add something extra to mount_msdosfs_flags in /usr/local/etc/bsdisks.conf?
  • the output of 'udisksctl dump'
  • the output of 'udevadm info --export-db' (as root)
  • the output of 'cat /proc/self/mountinfo'
...and more.
Unprivileged mounts, UID and GID passing
Also a mount option is added automatically to indicate the umount command to use UDisks again for unmounting when called by an unprivileged user. uhelper=udisks2

Related?
Then the problem is that udisks is trying to use the kernel ntfs driver, which does not understand this (default) mount option. For this to work the optional dependency NTFS-3G must be installed.

On my machine running 13.1-STABLE, exFAT is now properly handled: mounting and unmounting from PCManFM-Qt or Thunar works as expected and gvfs-udisks2-volume-monitor isn't causing any trouble anymore. Nice!
On another machine running 13.1-RELEASE, the problem is now different: the file manager can mount an exFAT-formatted disk but can't unmount it ("operation not permitted"). Still not really convenient, but less annoying then having to kill a process eating the CPU.
The main problem is gone and the fully functional stack will land in RELEASE sooner or later, so I consider this solved. Thank you!
Unmounting the mountpoint doesn't work but the device name does.
 
Last edited:
Many thanks for your hints.
I think PR 259033 is related to my problem. Unfortunately, there was no mention of whether a successful unmount was performed as root or as a normal user.

Maybe I should create a new bug report...
 
I'm following your bug. Xfce definitely doesn't work well on FreeBSD and it's a well rated desktop by users.

I didn't know that KDE used bsdisks. KDE worked out of the box on 13.x-release-amd64, mounts and unmounts USB with no issues. I'm not sure about my NTFS drive, it's a drive I use very occasionally, but at least it didn't cause the issues of the past in Xfce for me.

Could Xfce need /proc?

Must read:
 
Xfce definitely doesn't work well on FreeBSD
I would say, not in general, it depends on your use case. For me Xfce works pretty well on FreeBSD, except for the unmount problem of fuse file systems.

I know the thread you quoted, a lot of problems have been solved in the meantime.
bsdisks is doomed to succeed ;)
 
Short update: I filed a bug report (PR 268320) and it turned out that bsdisks works fine.
The problem is more likely to be Xfce, Thunar or some internal libraries.

To narrow that down I have created a clean VM with FreeBSD and Mate (Caja) - and I could observe exactly the same behavior.

Maybe it's gvfs?
 
I did some more research on the internet and found what I was looking for. The unmount process is carried out by gvfs, more precisely by gvfs-udisks2-volume-monitor.

After I figured that out, I looked at the source code at gvfs\monitor\udisks2\gvfsudisks2mount.c and found this section:
C:
  /* Use the umount(8) command if there is no block device / filesystem */
  if (data->filesystem == NULL)
    {
      gchar *escaped_mount_path;
      escaped_mount_path = g_strescape (mount->mount_path, NULL);
      gvfs_udisks2_utils_spawn (10, /* timeout in seconds */
                                g_task_get_cancellable (task),
                                umount_command_cb,
                                task,
                                "umount %s \"%s\"",
                                force ? "-l " : "",
                                escaped_mount_path);
      g_free (escaped_mount_path);
      goto out;
    }

This explains my observations, assuming that data->filesystem is equal NULL in the case of fuse filesystems on FreeBSD (respectively Thunar, Caja, ...):
  1. unmounting fuse filesystems works as root (because the umount command is used)
  2. unmounting fuse filesystems doesn't work as user (operation not permitted, insufficient rights for the mount point)
  3. in the case of fuse filesystems I see no call of the Unmount method in dbus-monitor
As a cross-check, I commented out the lines and re-compiled the devel/gvfs port. After that, unmounting fuse filesystems no longer worked - even as root.

Unfortunately my programming skills are not sufficient to write a patch or to carry out more detailed analyses. I'm not even sure if this is a bug to be fixed upstream or if it needs to be patched in the ports of FreeBSD?

Hopefully someone who is more familiar with such things is reading here :)
 
Short update:
I've been using the following workaround for some time, and it works quite good:
now I use DSBMD + DSBMC for mounting and unmounting external drives. To avoid conflicts between DSBMC and gvfs-udisks2-volume-monitor, I deleted the file udisks2.monitor in /usr/local/share/gvfs/remote-volume-monitors. This prevents gvfsd from starting the gvfs-udisks2-volume-monitor service, see gvfs(7).

Nice side effect: now it's possible to unmount external USB drives (even with FUSE file systems) via Thunar as a regular user.
 
This was indeed a problem on 13.1-RELEASE but should work properly now with 13.2-RELEASE.

fbsd470 Could you please try on 13.2 without any workaround and report back how it behaves?
 
I think that it may be to the rest of the users on this thread if the original poster provided us with configuration files such as their doas.conf for instance.
 
bsduck, thanks for the tip. I have tested it with FreeBSD 13.2 RELEASE, Xfce 4.18 and no workarounds!

Mounting and unmounting now actually works as a regular user. Thunar's sidebar no longer shows two drives (1 x device, 1 x partition) as seen before.

I have tested USB drives with NTFS, FAT and UFS2 partitions. It worked for all. Great!
In dbus-monitor I could see the umount method being called, so gvfs and bsdisks seem to work well together now.

:D
 
...but...

...sometimes the folder content is not updated. FAT volumes are definitely affected :'‑(

It's easy to reproduce, simply copy a file per drag & drop to the mounted volume and you see ...nothing.
Only an F5 key stroke reveals the copied content.
 
New findings, .xsession-errors shows:
Code:
(Thunar:1517): GLib-GIO-WARNING **: 10:05:24.354: Excluding /media/Kingston_DataTraveler_3.0_4CEDFB790E84F541783D01D2_s1 from kernel notification, falling back to poll

(Thunar:1517): GLib-GIO-WARNING **: 10:06:36.135: Excluding /media/CT480BX5_00SSD1_987654321029_p2 from kernel notification, falling back to poll

First drive is FAT formatted, folder content is not updated when copying or deleting files, second ist NTFS and gets updated. Strange things are happening :-/
 
sometimes the folder content is not updated. FAT volumes are definitely affected
Yes, I noticed this too. I didn't really think of it as a bug since I have seen the same behaviour a lot in various contexts with Microsoft Windows and I'm used to press F5 after moving something... I didn't pay attention whether it works the same when interacting with FAT volumes on Windows, though.
 
I think it has something to do with the folder /media. As far as I know/understand this folder is under "special observation" by Thunar and/or gvfs.

When mounting a FAT volume to /mnt manually, everything works as expected - no issues with the update of the folder contents when copying or deleting files.

So I kept my workaround: disable gvfs-udisks2-volume-monitor, use DSBMC instead, /mnt as default mount-point.

Not absolutely necessary, but fortunately we have the freedom of choice 🥰
 
Back
Top