Find the base mount point of a partition that has bind mounts
With bind mounts on Linux, UDisks returns a 'MountPoints' property that could include several paths, try to get the actual mount point of the partition and ignore bind mounts. Inspired by the approach used by GNOME's gio, use libmount to parse "/proc/self/mountinfo" and check the path returned by mnt_fs_get_root(), for the base partition this should return "/", for bind mounts it returns a dir e.g. /mnt/dirA/. This fixes a bug where clicking a Device icon in the Places panel could open the path of one of the bind mounts instead of the actual/base partition mount point, which is confusing to say the least. For more details: frameworks/solid!37 https://gitlab.gnome.org/GNOME/glib/-/issues/1271#note_352412 https://gitlab.gnome.org/GNOME/glib/-/commit/e1fa5ffb91e74376394fe17612015d44fec82366 https://github.com/storaged-project/udisks/issues/478 BUG: 349617 FIXED-IN: 5.84
-
-
Hello Ahmad. This change resulted in crashes of Dolphin and Plasmashell for some users of Slackware-current. Slackware doesn't use systemd, and /var/run is a bind mount of /run.
The crash occurs because
mnt_fs_get_root(fs)
in line 97 ofsolid/devices/backends/udisks2/udisksstorageaccess.cpp
returns NULL under some as of yet unknown circumstances (doesn't affect all Slackware-current users trying to mount removable media or other partitions).Someone made this patch that seems to correct the issue. Do you think the patch is reasonable?
diff -urN solid-5.84.0.orig/src/solid/devices/backends/udisks2/udisksstorageaccess.cpp solid-5.84.0/src/solid/devices/backends/udisks2/udisksstorageaccess.cpp --- solid-5.84.0.orig/src/solid/devices/backends/udisks2/udisksstorageaccess.cpp 2021-07-03 15:21:37.000000000 +0300 +++ solid-5.84.0/src/solid/devices/backends/udisks2/udisksstorageaccess.cpp 2021-07-20 18:21:03.578070205 +0300 @@ -80,6 +80,8 @@ QString mountPoint; #if HAVE_LIBMOUNT + const char *root = NULL; + // UDisks "MountPoints" property contains multiple paths, this happens with // devices with bind mounts; try finding the "base" mount point if (struct libmnt_table *table = mnt_new_table()) { @@ -93,8 +95,10 @@ while (mnt_table_next_fs(table, itr, &fs) == 0) { if (mnt_fs_get_srcpath(fs) == devicePath + // Ensure that is get a valid string for root + && (root = mnt_fs_get_root(fs)) // Base mount point will have "/" as root fs - && (strcmp(mnt_fs_get_root(fs), "/") == 0)) { + && (strcmp(root, "/") == 0)) { mountPoint = QFile::decodeName(mnt_fs_get_target(fs)); break; }
Here' the link to the discussion in the Slackware support forum if you want more context, though there's a lot of stabbing in the dark.
Thanks for reading!
-
Thanks for the report and sorry for the trouble :)
Reading the libmount docs again, it indeed says that mnt_fs_get_root() can return NULL, so I've replaced strcmp with qstrcmp; could you please test !48 (merged) ?
-
-
mentioned in commit e5964d13
-
mentioned in merge request !48 (merged)