[gvfs] udisks2: don't show drives from other seats and special-case seat "all"



commit c241b86cc74ce8ca13d9ee2b8d0b7cf15850cf71
Author: David Zeuthen <davidz redhat com>
Date:   Sun Apr 22 11:48:19 2012 -0400

    udisks2: don't show drives from other seats and special-case seat "all"
    
    If Drive:seat is "all" it means the drive is available on all seats.
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 monitor/udisks2/gvfsudisks2utils.c         |   83 ++++++++++++++++++++++++++++
 monitor/udisks2/gvfsudisks2utils.h         |    2 +
 monitor/udisks2/gvfsudisks2volume.c        |   74 +------------------------
 monitor/udisks2/gvfsudisks2volumemonitor.c |   47 ++++++++++++---
 4 files changed, 123 insertions(+), 83 deletions(-)
---
diff --git a/monitor/udisks2/gvfsudisks2utils.c b/monitor/udisks2/gvfsudisks2utils.c
index 0dc8abe..43d583a 100644
--- a/monitor/udisks2/gvfsudisks2utils.c
+++ b/monitor/udisks2/gvfsudisks2utils.c
@@ -511,3 +511,86 @@ gvfs_udisks2_utils_spawn_finish (GAsyncResult   *res,
   return ret;
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+#if defined(HAVE_LIBSYSTEMD_LOGIN)
+#include <systemd/sd-login.h>
+
+static const gchar *
+get_seat (void)
+{
+  static gsize once = 0;
+  static char *seat = NULL;
+
+  if (g_once_init_enter (&once))
+    {
+      char *session = NULL;
+      if (sd_pid_get_session (getpid (), &session) == 0)
+        {
+          sd_session_get_seat (session, &seat);
+          free (session);
+          /* we intentionally leak seat here... */
+        }
+      g_once_init_leave (&once, (gsize) 1);
+    }
+  return seat;
+}
+
+#else
+
+static const gchar *
+get_seat (void)
+{
+  return NULL;
+}
+
+#endif
+
+gboolean
+gvfs_udisks2_utils_is_drive_on_our_seat (UDisksDrive *drive)
+{
+  gboolean ret = FALSE;
+  const gchar *seat;
+  const gchar *drive_seat = NULL;
+
+  /* assume our own seat if we don't have seat-support or it doesn't work */
+  seat = get_seat ();
+  if (seat == NULL)
+    {
+      ret = TRUE;
+      goto out;
+    }
+
+  /* If the device is not tagged, assume that udisks does not have
+   * working seat-support... so just assume it's available at our
+   * seat.
+   *
+   * Note that seat support was added in udisks 1.95.0 (and so was the
+   * UDISKS_CHECK_VERSION macro) - for now, be compatible with older
+   * versions instead of bumping requirement in configure.ac
+   */
+#ifdef UDISKS_CHECK_VERSION
+# if UDISKS_CHECK_VERSION(1,95,0)
+  drive_seat = udisks_drive_get_seat (drive);
+# endif
+#endif
+  if (drive_seat == NULL || strlen (drive_seat) == 0)
+    {
+      ret = TRUE;
+      goto out;
+    }
+
+  /* "all" is special, it means the device is available on any seat */
+  if (g_strcmp0 (drive_seat, "all") == 0)
+    {
+      ret = TRUE;
+      goto out;
+    }
+
+  /* Otherwise, check if it's on our seat */
+  if (g_strcmp0 (seat, drive_seat) == 0)
+    ret = TRUE;
+
+ out:
+  return ret;
+}
diff --git a/monitor/udisks2/gvfsudisks2utils.h b/monitor/udisks2/gvfsudisks2utils.h
index 2b6dc3c..1965883 100644
--- a/monitor/udisks2/gvfsudisks2utils.h
+++ b/monitor/udisks2/gvfsudisks2utils.h
@@ -50,6 +50,8 @@ gboolean gvfs_udisks2_utils_spawn_finish (GAsyncResult   *res,
                                           gchar         **out_standard_error,
                                           GError        **error);
 
+gboolean gvfs_udisks2_utils_is_drive_on_our_seat (UDisksDrive *drive);
+
 
 G_END_DECLS
 
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index 243dc14..a1c7fa4 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -36,41 +36,6 @@
 #include "gvfsudisks2mount.h"
 #include "gvfsudisks2utils.h"
 
-
-#if defined(HAVE_LIBSYSTEMD_LOGIN)
-#include <systemd/sd-login.h>
-
-static const gchar *
-get_seat (void)
-{
-  static gsize once = 0;
-  static char *seat = NULL;
-
-  if (g_once_init_enter (&once))
-    {
-      char *session = NULL;
-      if (sd_pid_get_session (getpid (), &session) == 0)
-        {
-          sd_session_get_seat (session, &seat);
-          /* we intentionally leak seat here... */
-        }
-      g_once_init_leave (&once, (gsize) 1);
-    }
-  return seat;
-}
-
-#else
-
-static const gchar *
-get_seat (void)
-{
-  return NULL;
-}
-
-#endif
-
-
-
 typedef struct _GVfsUDisks2VolumeClass GVfsUDisks2VolumeClass;
 
 struct _GVfsUDisks2VolumeClass
@@ -213,43 +178,6 @@ apply_options_from_fstab (GVfsUDisks2Volume *volume,
 }
 
 static gboolean
-drive_is_on_our_seat (UDisksDrive *drive)
-{
-  gboolean ret = FALSE;
-  const gchar *seat;
-  const gchar *drive_seat = NULL;
-
-  /* assume our own seat if we don't have seat-support or it doesn't work */
-  seat = get_seat ();
-  if (seat == NULL)
-    {
-      ret = TRUE;
-      goto out;
-    }
-
-  /* Assume seat0 if a) device is not tagged; or b) udisks does not
-   * have seat-support.
-   *
-   * Note that seat support was added in udisks 1.95.0 (and so was the
-   * UDISKS_CHECK_VERSION macro) - for now, be compatible with older
-   * versions instead of bumping requirement in configure.ac
-   */
-#ifdef UDISKS_CHECK_VERSION
-# if UDISKS_CHECK_VERSION(1,95,0)
-  drive_seat = udisks_drive_get_seat (drive);
-# endif
-#endif
-  if (drive_seat == NULL || strlen (drive_seat) == 0)
-    drive_seat = "seat0";
-
-  if (g_strcmp0 (seat, drive_seat) == 0)
-    ret = TRUE;
-
- out:
-  return ret;
-}
-
-static gboolean
 update_volume (GVfsUDisks2Volume *volume)
 {
   gboolean changed;
@@ -387,7 +315,7 @@ update_volume (GVfsUDisks2Volume *volume)
             g_object_unref (media_icon);
 
           /* Only automount drives attached to the same seat as we're running on */
-          if (drive_is_on_our_seat (udisks_drive))
+          if (gvfs_udisks2_utils_is_drive_on_our_seat (udisks_drive))
             {
               /* Only automount filesystems from drives of known types/interconnects:
                *
diff --git a/monitor/udisks2/gvfsudisks2volumemonitor.c b/monitor/udisks2/gvfsudisks2volumemonitor.c
index 1ea86b2..2826164 100644
--- a/monitor/udisks2/gvfsudisks2volumemonitor.c
+++ b/monitor/udisks2/gvfsudisks2volumemonitor.c
@@ -805,6 +805,9 @@ should_include_volume_check_configuration (GVfsUDisks2VolumeMonitor *monitor,
   return ret;
 }
 
+static gboolean should_include_drive (GVfsUDisks2VolumeMonitor *monitor,
+                                      UDisksDrive              *drive);
+
 static gboolean
 should_include_volume (GVfsUDisks2VolumeMonitor *monitor,
                        UDisksBlock              *block,
@@ -813,12 +816,23 @@ should_include_volume (GVfsUDisks2VolumeMonitor *monitor,
   gboolean ret = FALSE;
   GDBusObject *object;
   UDisksFilesystem *filesystem;
+  UDisksDrive *udisks_drive = NULL;
   const gchar* const *mount_points;
 
   /* Block:Ignore trumps everything */
   if (udisks_block_get_hint_ignore (block))
     goto out;
 
+  /* ignore the volume if the drive is ignored */
+  udisks_drive = udisks_client_get_drive_for_block (monitor->client, block);
+  if (udisks_drive != NULL)
+    {
+      if (!should_include_drive (monitor, udisks_drive))
+        {
+          goto out;
+        }
+    }
+
   /* show encrypted volumes... */
   if (g_strcmp0 (udisks_block_get_id_type (block), "crypto_LUKS") == 0)
     {
@@ -879,6 +893,7 @@ should_include_volume (GVfsUDisks2VolumeMonitor *monitor,
   ret = TRUE;
 
  out:
+  g_clear_object (&udisks_drive);
   return ret;
 }
 
@@ -888,17 +903,26 @@ static gboolean
 should_include_drive (GVfsUDisks2VolumeMonitor *monitor,
                       UDisksDrive              *drive)
 {
-  /* NOTE: For now, we just include all detected drives. This is
-   * probably wrong - non-removable drives without anything visible
-   * (such RAID components) should probably not be shown. Then again,
-   * the GNOME 3 user interface doesn't really show GDrive instances
-   * except for in the computer:/// location in Nautilus.
-   *
-   * Therefore, if device is non-removable, maybe only show it, if it
-   * has more visible devices... this is the gdu volume monitor
-   * behavior.
+  gboolean ret = TRUE;
+
+  /* Don't include drives on other seats */
+  if (!gvfs_udisks2_utils_is_drive_on_our_seat (drive))
+    {
+      ret = FALSE;
+      goto out;
+    }
+
+  /* NOTE: For now, we just include a drive no matter its
+   * content. This may be wrong ... for example non-removable drives
+   * without anything visible (such RAID components) should probably
+   * not be shown. Then again, the GNOME 3 user interface doesn't
+   * really show GDrive instances except for in the computer:///
+   * location in Nautilus....
    */
-  return TRUE;
+
+ out:
+
+  return ret;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -1743,6 +1767,9 @@ update_discs (GVfsUDisks2VolumeMonitor  *monitor,
       if (udisks_drive == NULL)
         continue;
 
+      if (!should_include_drive (monitor, udisks_drive))
+        continue;
+
       /* only consider blank and audio discs */
       if (!(udisks_drive_get_optical_blank (udisks_drive) ||
             udisks_drive_get_optical_num_audio_tracks (udisks_drive) > 0))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]