From 644a966bb1d5f65336cb357efb4d490d2a8de6be Mon Sep 17 00:00:00 2001 From: segfault Date: Sun, 10 Dec 2017 09:56:26 +0100 Subject: [PATCH] gtkplacessidebar: Add loop and device-mapper devices Loop and device-mapper devices were not included in the places sidebar, but those are often interesting to the user, for example mapped encrypted volumes stored in the filesystem. --- gtk/gtkplacessidebar.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index 4347c2a6643..54c122d9325 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -1352,6 +1352,67 @@ update_places (GtkPlacesSidebar *sidebar) } g_list_free (volumes); + /* add loop and device-mapper devices*/ + volumes = g_volume_monitor_get_volumes (sidebar->volume_monitor); + for (l = volumes; l != NULL; l = l->next) + { + volume = l->data; + + drive = g_volume_get_drive (volume); + if (drive != NULL) + { + g_object_unref (volume); + g_object_unref (drive); + continue; + } + + identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + + if (identifier == NULL || + (!g_str_has_prefix (identifier, "/dev/loop") && + !g_str_has_prefix (identifier, "/dev/dm"))) + { + g_free (identifier); + continue; + } + g_free (identifier); + + mount = g_volume_get_mount (volume); + if (mount != NULL) + { + char *mount_uri; + start_icon = g_mount_get_symbolic_icon (mount); + root = g_mount_get_default_location (mount); + mount_uri = g_file_get_uri (root); + tooltip = g_file_get_parse_name (root); + name = g_mount_get_name (mount); + add_place (sidebar, PLACES_MOUNTED_VOLUME, + SECTION_MOUNTS, + name, start_icon, NULL, mount_uri, + NULL, volume, mount, NULL, 0, tooltip); + g_object_unref (mount); + g_object_unref (root); + g_object_unref (start_icon); + g_free (name); + g_free (tooltip); + g_free (mount_uri); + } + else + { + /* see comment above in why we add an icon for an unmounted mountable volume */ + start_icon = g_volume_get_symbolic_icon (volume); + name = g_volume_get_name (volume); + add_place (sidebar, PLACES_MOUNTED_VOLUME, + SECTION_MOUNTS, + name, start_icon, NULL, NULL, + NULL, volume, NULL, NULL, 0, name); + g_object_unref (start_icon); + g_free (name); + } + g_object_unref (volume); + } + g_list_free (volumes); + /* file system root */ if (!sidebar->show_other_locations) { -- GitLab