Introduce DeviceBusy error and use it in Filesystem.Unmount()
authorDavid Zeuthen <davidz@redhat.com>
Wed, 28 Sep 2011 18:32:34 +0000 (14:32 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 28 Sep 2011 18:32:34 +0000 (14:32 -0400)
Signed-off-by: David Zeuthen <davidz@redhat.com>
data/org.freedesktop.UDisks2.xml
src/udiskslinuxfilesystem.c
udisks/udisksenums.h
udisks/udiskserror.c

index 2c99f84..1a4dd95 100644 (file)
 
         Unmount a mounted device.
 
-        If the filesystem is busy, this operation fails unless the
-        option <parameter>force</parameter> is given.
+        If the filesystem is busy, this operation fails with the error
+        <link linkend="UDISKS-ERROR-DEVICE-BUSY:CAPS"><constant>org.freedesktop.UDisks.Error.DeviceBusy</constant></link>
+        unless the option <parameter>force</parameter> is used.
 
         If the device in question is referenced in a system-wide
         configuration file (such as the <filename>/etc/fstab</filename> file)
         <citerefentry><refentrytitle>umount</refentrytitle><manvolnum>8</manvolnum></citerefentry>
         command is invoked as root.
     -->
-    <method name="Unmount">
+<method name="Unmount">
       <arg name="options" direction="in" type="a{sv}"/>
     </method>
   </interface>
index cd13214..833c469 100644 (file)
@@ -1119,6 +1119,16 @@ handle_mount (UDisksFilesystem       *filesystem,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static guint
+get_error_code_for_umount (gint         exit_status,
+                           const gchar *error_message)
+{
+  if (strstr (error_message, "device is busy") != NULL)
+    return UDISKS_ERROR_DEVICE_BUSY;
+  else
+    return UDISKS_ERROR_FAILED;
+}
+
 /* runs in thread dedicated to handling @invocation */
 static gboolean
 handle_unmount (UDisksFilesystem       *filesystem,
@@ -1134,6 +1144,7 @@ handle_unmount (UDisksFilesystem       *filesystem,
   GError *error;
   uid_t mounted_by_uid;
   uid_t caller_uid;
+  gint status;
   gchar *error_message;
   const gchar *const *mount_points;
   gboolean opt_force;
@@ -1190,7 +1201,6 @@ handle_unmount (UDisksFilesystem       *filesystem,
    */
   if (system_managed)
     {
-      gint status;
       gboolean unmount_fstab_as_root;
 
       unmount_fstab_as_root = FALSE;
@@ -1228,7 +1238,7 @@ handle_unmount (UDisksFilesystem       *filesystem,
 
           g_dbus_method_invocation_return_error (invocation,
                                                  UDISKS_ERROR,
-                                                 UDISKS_ERROR_FAILED,
+                                                 get_error_code_for_umount (status, error_message),
                                                  "Error unmounting system-managed device %s: %s",
                                                  udisks_block_get_device (block),
                                                  error_message);
@@ -1312,7 +1322,7 @@ handle_unmount (UDisksFilesystem       *filesystem,
                                                   NULL, /* GCancellable */
                                                   0,    /* uid_t run_as_uid */
                                                   0,    /* uid_t run_as_euid */
-                                                  NULL, /* gint *out_status */
+                                                  &status,
                                                   &error_message,
                                                   NULL,  /* input_string */
                                                   "umount %s \"%s\"",
@@ -1324,7 +1334,7 @@ handle_unmount (UDisksFilesystem       *filesystem,
     {
       g_dbus_method_invocation_return_error (invocation,
                                              UDISKS_ERROR,
-                                             UDISKS_ERROR_FAILED,
+                                             get_error_code_for_umount (status, error_message),
                                              "Error unmounting %s: %s",
                                              udisks_block_get_device (block),
                                              error_message);
index d9afe60..1784474 100644 (file)
@@ -45,6 +45,7 @@ G_BEGIN_DECLS
  * @UDISKS_ERROR_NOT_SUPPORTED: The operation is not supported due to missing driver/tool support.
  * @UDISKS_ERROR_TIMED_OUT: The operation timed out.
  * @UDISKS_ERROR_WOULD_WAKEUP: The operation would wake up a disk that is in a deep-sleep state.
+ * @UDISKS_ERROR_DEVICE_BUSY: Attempting to unmount a device that is busy.
  *
  * Error codes for the #UDISKS_ERROR error domain and the
  * corresponding D-Bus error names.
@@ -65,9 +66,10 @@ typedef enum
   UDISKS_ERROR_NOT_SUPPORTED,              /* org.freedesktop.UDisks.Error.NotSupported */
   UDISKS_ERROR_TIMED_OUT,                  /* org.freedesktop.UDisks.Error.Timedout */
   UDISKS_ERROR_WOULD_WAKEUP,               /* org.freedesktop.UDisks.Error.WouldWakeup */
+  UDISKS_ERROR_DEVICE_BUSY                 /* org.freedesktop.UDisks.Error.DeviceBusy */
 } UDisksError;
 
-#define UDISKS_ERROR_NUM_ENTRIES  (UDISKS_ERROR_WOULD_WAKEUP + 1)
+#define UDISKS_ERROR_NUM_ENTRIES  (UDISKS_ERROR_DEVICE_BUSY + 1)
 
 G_END_DECLS
 
index 27e81bd..9d2df57 100644 (file)
@@ -47,6 +47,7 @@ static const GDBusErrorEntry dbus_error_entries[] =
   {UDISKS_ERROR_NOT_SUPPORTED,                "org.freedesktop.UDisks.Error.NotSupported"},
   {UDISKS_ERROR_TIMED_OUT,                    "org.freedesktop.UDisks.Error.Timedout"},
   {UDISKS_ERROR_WOULD_WAKEUP,                 "org.freedesktop.UDisks.Error.WouldWakeup"},
+  {UDISKS_ERROR_DEVICE_BUSY,                  "org.freedesktop.UDisks.Error.DeviceBusy"},
 };
 
 GQuark