Add udisks --eject option
authorMatt Zimmerman <mdz@ubuntu.com>
Mon, 28 Jun 2010 09:05:58 +0000 (11:05 +0200)
committerMartin Pitt <martin.pitt@ubuntu.com>
Mon, 28 Jun 2010 09:05:58 +0000 (11:05 +0200)
As a companion to --mount, --unmount, and --detach, it's useful for testing and
provides a policykit-authenticated alternative to eject(1).

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
doc/man/udisks.xml
tools/udisks-bash-completion.sh
tools/udisks.c

index cd50639..9340a04 100644 (file)
 
       <varlistentry>
         <term>
+          <option>--eject</option>
+          <arg choice="plain"><replaceable>device_file</replaceable></arg>
+          <arg><option>--eject-options</option><arg choice="plain"><replaceable>options</replaceable></arg></arg>
+        </term>
+        <listitem>
+          <para>
+            Ejects media from the device represented
+            by <replaceable>device_file</replaceable> using a
+            comma-separated list
+            of <replaceable>options</replaceable>.
+          </para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>
           <option>--ata-smart-refresh</option>
           <arg choice="plain"><replaceable>device_file</replaceable></arg>
           <arg><option>--ata-smart-wakeup</option></arg>
index 30f1ee2..79d1d81 100644 (file)
@@ -18,6 +18,8 @@ __udisks() {
         COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur))
     elif [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--detach" ] ; then
         COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur))
+    elif [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--eject" ] ; then
+        COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur))
     elif [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--ata-smart-refresh" ] ; then
         COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur))
     elif [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--ata-smart-simulate" ] ; then
@@ -27,7 +29,7 @@ __udisks() {
     elif [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--poll-for-media" ] ; then
         COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur))
     else
-        COMPREPLY=($(IFS=: compgen -W "--dump:--inhibit-polling:--inhibit-all-polling:--enumerate:--enumerate-device-files:--monitor:--monitor-detail:--show-info:--help:--mount:--mount-fstype:--mount-options:--unmount:--unmount-options:--detach:--detach-options:--ata-smart-refresh:--ata-smart-wakeup:--ata-smart-simulate:--set-spindown:--set-spindown-all:--spindown-timeout:--poll-for-media" -- $cur))
+        COMPREPLY=($(IFS=: compgen -W "--dump:--inhibit-polling:--inhibit-all-polling:--enumerate:--enumerate-device-files:--monitor:--monitor-detail:--show-info:--help:--mount:--mount-fstype:--mount-options:--unmount:--unmount-options:--detach:--detach-options:--eject:--eject-options:--ata-smart-refresh:--ata-smart-wakeup:--ata-smart-simulate:--set-spindown:--set-spindown-all:--spindown-timeout:--poll-for-media" -- $cur))
     fi
 }
 
index f2202a0..6481efb 100644 (file)
@@ -73,6 +73,8 @@ static char *opt_unmount = NULL;
 static char *opt_unmount_options = NULL;
 static char *opt_detach = NULL;
 static char *opt_detach_options = NULL;
+static char *opt_eject = NULL;
+static char *opt_eject_options = NULL;
 static char *opt_ata_smart_refresh = NULL;
 static gboolean opt_ata_smart_wakeup = FALSE;
 static char *opt_ata_smart_simulate = NULL;
@@ -194,6 +196,30 @@ do_detach (const char *object_path,
 }
 
 static void
+do_eject (const char *object_path,
+           const char *options)
+{
+  DBusGProxy *proxy;
+  GError *error;
+  char **eject_options;
+
+  eject_options = NULL;
+  if (options != NULL)
+    eject_options = g_strsplit (options, ",", 0);
+
+  proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.UDisks", object_path, "org.freedesktop.UDisks.Device");
+
+  error = NULL;
+  if (!org_freedesktop_UDisks_Device_drive_eject (proxy, (const char **) options, &error))
+    {
+      g_print ("Eject failed: %s\n", error->message);
+      g_error_free (error);
+    }
+
+  g_strfreev (eject_options);
+}
+
+static void
 device_added_signal_handler (DBusGProxy *proxy,
                              const char *object_path,
                              gpointer user_data)
@@ -1959,6 +1985,8 @@ main (int argc,
       { "detach", 0, 0, G_OPTION_ARG_STRING, &opt_detach, "Detach the given device", NULL },
       { "detach-options", 0, 0, G_OPTION_ARG_STRING, &opt_detach_options, "Detach options separated by comma",
         NULL },
+      { "eject", 0, 0, G_OPTION_ARG_STRING, &opt_eject, "Eject the given device", NULL },
+      { "eject-options", 0, 0, G_OPTION_ARG_STRING, &opt_eject_options, "Eject options separated by comma", NULL },
       { "ata-smart-refresh", 0, 0, G_OPTION_ARG_STRING, &opt_ata_smart_refresh, "Refresh ATA SMART data", NULL },
       { "ata-smart-wakeup", 0, 0, G_OPTION_ARG_NONE, &opt_ata_smart_wakeup,
         "Wake up the disk if it is not awake", NULL },
@@ -2140,6 +2168,13 @@ main (int argc,
         goto out;
       do_detach (device_file, opt_detach_options);
     }
+  else if (opt_eject != NULL)
+    {
+      device_file = device_file_to_object_path (opt_eject);
+      if (device_file == NULL)
+        goto out;
+      do_eject (device_file, opt_eject_options);
+    }
   else if (opt_ata_smart_refresh != NULL)
     {
       device_file = device_file_to_object_path (opt_ata_smart_refresh);