neil / rpms / udisks2

Forked from rpms/udisks2 a year ago
Clone
5137f5
From 95929aea77992077ea8725c54c4d861f08edbd46 Mon Sep 17 00:00:00 2001
5137f5
From: Tomas Bzatek <tbzatek@redhat.com>
5137f5
Date: Thu, 16 Jan 2014 17:37:27 +0100
5137f5
Subject: [PATCH] Check if cdrom drive has media on cleanup
5137f5
5137f5
When cleanup is run, it is supposed to remove lingering mounts.
5137f5
That probably works fine for card readers etc. since there's
5137f5
a partition exposed for the drive but fails for optical media.
5137f5
As a result, when mounted and user presses the drive eject
5137f5
button, tray is ejected but mounts lives on.
5137f5
5137f5
This patch adds a special check for CDROM drives and looks for
5137f5
active media.
5137f5
5137f5
https://bugs.freedesktop.org/show_bug.cgi?id=72206
5137f5
---
5137f5
 src/udisksstate.c | 19 ++++++++++++++++++-
5137f5
 1 file changed, 18 insertions(+), 1 deletion(-)
5137f5
5137f5
diff --git a/src/udisksstate.c b/src/udisksstate.c
5137f5
index e7b549a..73aba4f 100644
5137f5
--- a/src/udisksstate.c
5137f5
+++ b/src/udisksstate.c
5137f5
@@ -541,6 +541,7 @@ udisks_state_check_mounted_fs_entry (UDisksState  *state,
5137f5
   gboolean device_exists;
5137f5
   gboolean device_to_be_cleaned;
5137f5
   gboolean attempt_no_cleanup;
5137f5
+  gboolean empty_cd_drive;
5137f5
   UDisksMountMonitor *monitor;
5137f5
   GUdevClient *udev_client;
5137f5
   GUdevDevice *udev_device;
5137f5
@@ -552,6 +553,7 @@ udisks_state_check_mounted_fs_entry (UDisksState  *state,
5137f5
   device_exists = FALSE;
5137f5
   device_to_be_cleaned = FALSE;
5137f5
   attempt_no_cleanup = FALSE;
5137f5
+  empty_cd_drive = FALSE;
5137f5
   block_device_value = NULL;
5137f5
   fstab_mount_value = NULL;
5137f5
   fstab_mount = FALSE;
5137f5
@@ -651,6 +653,16 @@ udisks_state_check_mounted_fs_entry (UDisksState  *state,
5137f5
                   g_object_unref (udev_device_disk);
5137f5
                 }
5137f5
             }
5137f5
+          /* for disk, check if it's a cd-rom drive and has media */
5137f5
+          else if (g_strcmp0 (g_udev_device_get_devtype (udev_device), "disk") == 0)
5137f5
+            {
5137f5
+              device_exists = TRUE;
5137f5
+
5137f5
+              /* taken from udisks_daemon_util_block_get_size() */
5137f5
+              if (g_udev_device_get_property_as_boolean (udev_device, "ID_CDROM") &&
5137f5
+                 !g_udev_device_get_property_as_boolean (udev_device, "ID_CDROM_MEDIA"))
5137f5
+                empty_cd_drive = TRUE;
5137f5
+            }
5137f5
           else
5137f5
             {
5137f5
               device_exists = TRUE;
5137f5
@@ -670,7 +682,7 @@ udisks_state_check_mounted_fs_entry (UDisksState  *state,
5137f5
         }
5137f5
     }
5137f5
 
5137f5
-  if (is_mounted && device_exists && !device_to_be_cleaned)
5137f5
+  if (is_mounted && device_exists && !device_to_be_cleaned && !empty_cd_drive)
5137f5
     keep = TRUE;
5137f5
 
5137f5
  out:
5137f5
@@ -679,6 +691,11 @@ udisks_state_check_mounted_fs_entry (UDisksState  *state,
5137f5
     {
5137f5
       if (!device_exists)
5137f5
         {
5137f5
+          udisks_notice ("Cleaning up mount point %s (device %d:%d is CDROM and has no media)",
5137f5
+                         mount_point, major (block_device), minor (block_device));
5137f5
+        }
5137f5
+      else if (!device_exists)
5137f5
+        {
5137f5
           udisks_notice ("Cleaning up mount point %s (device %d:%d no longer exist)",
5137f5
                          mount_point, major (block_device), minor (block_device));
5137f5
         }
5137f5
-- 
5137f5
1.8.1.5
5137f5