From: David Zeuthen Date: Wed, 28 Sep 2011 18:32:34 +0000 (-0400) Subject: Introduce DeviceBusy error and use it in Filesystem.Unmount() X-Git-Tag: upstream/2.1.2~472 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc50a85542719d4726db5abe836e2d52bc9869c3;p=platform%2Fupstream%2Fudisks2.git Introduce DeviceBusy error and use it in Filesystem.Unmount() Signed-off-by: David Zeuthen --- diff --git a/data/org.freedesktop.UDisks2.xml b/data/org.freedesktop.UDisks2.xml index 2c99f84..1a4dd95 100644 --- a/data/org.freedesktop.UDisks2.xml +++ b/data/org.freedesktop.UDisks2.xml @@ -813,8 +813,9 @@ Unmount a mounted device. - If the filesystem is busy, this operation fails unless the - option force is given. + If the filesystem is busy, this operation fails with the error + org.freedesktop.UDisks.Error.DeviceBusy + unless the option force is used. If the device in question is referenced in a system-wide configuration file (such as the /etc/fstab file) @@ -828,7 +829,7 @@ umount8 command is invoked as root. --> - + diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c index cd13214..833c469 100644 --- a/src/udiskslinuxfilesystem.c +++ b/src/udiskslinuxfilesystem.c @@ -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); diff --git a/udisks/udisksenums.h b/udisks/udisksenums.h index d9afe60..1784474 100644 --- a/udisks/udisksenums.h +++ b/udisks/udisksenums.h @@ -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 diff --git a/udisks/udiskserror.c b/udisks/udiskserror.c index 27e81bd..9d2df57 100644 --- a/udisks/udiskserror.c +++ b/udisks/udiskserror.c @@ -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