[gnome-multi-writer] Unmount all partitions when a device is inserted
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-multi-writer] Unmount all partitions when a device is inserted
- Date: Thu, 15 Jan 2015 13:27:16 +0000 (UTC)
commit eb81ee1230514cd4868976bb8d86735d94b76386
Author: Richard Hughes <richard hughsie com>
Date: Thu Jan 15 13:26:06 2015 +0000
Unmount all partitions when a device is inserted
LiveUSB devices typically have one partition, but very occasionaly more.
src/gmw-main.c | 51 ++++++++++++++++++++++++++++++---------------------
1 files changed, 30 insertions(+), 21 deletions(-)
---
diff --git a/src/gmw-main.c b/src/gmw-main.c
index 5ba27c0..0142d71 100644
--- a/src/gmw-main.c
+++ b/src/gmw-main.c
@@ -869,28 +869,37 @@ gmw_udisks_unmount_cb (GObject *source_object,
static UDisksFilesystem *
gmw_udisks_get_filesystem_for_device (GmwPrivate *priv, GmwDevice *device)
{
- UDisksFilesystem *udisks_fs = NULL;
- _cleanup_error_free_ GError *error = NULL;
- _cleanup_free_ gchar *object_path_child = NULL;
- _cleanup_object_unref_ UDisksBlock *udisks_block = NULL;
- _cleanup_object_unref_ UDisksObject *udisks_object = NULL;
- _cleanup_strv_free_ gchar **mtab = NULL;
-
- object_path_child = g_strdup_printf ("%s1", gmw_device_get_object_path (device));
- udisks_object = udisks_client_get_object (priv->udisks_client,
- object_path_child);
- if (udisks_object == NULL)
- return NULL;
- udisks_fs = udisks_object_get_filesystem (udisks_object);
- if (udisks_fs == NULL)
- return NULL;
- mtab = udisks_filesystem_dup_mount_points (udisks_fs);
- if (mtab == NULL || mtab[0] == NULL) {
- g_debug ("%s not mounted", object_path_child);
- return NULL;
+ guint i;
+
+ /* this is crude, but fast -- LiveUSB devices will only typically have
+ * one partition, but very occasionaly two or more */
+ for (i = 1; i <= 4; i++) {
+ UDisksFilesystem *udisks_fs = NULL;
+ _cleanup_error_free_ GError *error = NULL;
+ _cleanup_free_ gchar *object_path = NULL;
+ _cleanup_object_unref_ UDisksBlock *udisks_block = NULL;
+ _cleanup_object_unref_ UDisksObject *udisks_object = NULL;
+ _cleanup_strv_free_ gchar **mtab = NULL;
+
+ object_path = g_strdup_printf ("%s%i",
+ gmw_device_get_object_path (device),
+ i);
+ udisks_object = udisks_client_get_object (priv->udisks_client,
+ object_path);
+ if (udisks_object == NULL)
+ continue;
+ udisks_fs = udisks_object_get_filesystem (udisks_object);
+ if (udisks_fs == NULL)
+ continue;
+ mtab = udisks_filesystem_dup_mount_points (udisks_fs);
+ if (mtab == NULL || mtab[0] == NULL) {
+ g_debug ("%s not mounted", object_path);
+ continue;
+ }
+ g_debug ("found filesystem %s from %s", mtab[0], object_path);
+ return udisks_fs;
}
- g_debug ("found filesystem %s from %s", mtab[0], object_path_child);
- return udisks_fs;
+ return NULL;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]