diff options
author | David Zeuthen <davidz@redhat.com> | 2012-05-15 12:49:44 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2012-05-15 12:49:44 -0400 |
commit | d44ebed4590fc19b41e88d00fe7c598b9eaac832 (patch) | |
tree | d716790a802ab724e8c35e154176f609019b601a /programs/gvfs-mount.c | |
parent | 817d82da698910b45f2809175653d671190b939f (diff) | |
download | gvfs-d44ebed4590fc19b41e88d00fe7c598b9eaac832.tar.gz |
gvfs-mount: add new -e option to eject a mount
Like the rest of gvfs-mount(1), this is mostly useful for debugging.
Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'programs/gvfs-mount.c')
-rw-r--r-- | programs/gvfs-mount.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c index d6ccc9c3..c815294f 100644 --- a/programs/gvfs-mount.c +++ b/programs/gvfs-mount.c @@ -43,6 +43,7 @@ static GMainLoop *main_loop; static gboolean mount_mountable = FALSE; static gboolean mount_unmount = FALSE; +static gboolean mount_eject = FALSE; static gboolean mount_list = FALSE; static gboolean extra_detail = FALSE; static gboolean mount_monitor = FALSE; @@ -54,6 +55,7 @@ static const GOptionEntry entries[] = { "mountable", 'm', 0, G_OPTION_ARG_NONE, &mount_mountable, N_("Mount as mountable"), NULL }, { "device", 'd', 0, G_OPTION_ARG_STRING, &mount_device_file, N_("Mount volume with device file"), NULL}, { "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, N_("Unmount"), NULL}, + { "eject", 'e', 0, G_OPTION_ARG_NONE, &mount_eject, N_("Eject"), NULL}, { "unmount-scheme", 's', 0, G_OPTION_ARG_STRING, &unmount_scheme, N_("Unmount all mounts with the given scheme"), NULL}, /* Translator: List here is a verb as in 'List all mounts' */ { "list", 'l', 0, G_OPTION_ARG_NONE, &mount_list, N_("List"), NULL}, @@ -271,6 +273,51 @@ unmount (GFile *file) outstanding_mounts++; } +static void +eject_done_cb (GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + gboolean succeeded; + GError *error = NULL; + + succeeded = g_mount_eject_with_operation_finish (G_MOUNT (object), res, &error); + + g_object_unref (G_MOUNT (object)); + + if (!succeeded) + g_printerr (_("Error ejecting mount: %s\n"), error->message); + + outstanding_mounts--; + + if (outstanding_mounts == 0) + g_main_loop_quit (main_loop); +} + +static void +eject (GFile *file) +{ + GMount *mount; + GError *error = NULL; + GMountOperation *mount_op; + + if (file == NULL) + return; + + mount = g_file_find_enclosing_mount (file, NULL, &error); + if (mount == NULL) + { + g_printerr (_("Error finding enclosing mount: %s\n"), error->message); + return; + } + + mount_op = new_mount_op (); + g_mount_eject_with_operation (mount, 0, mount_op, NULL, eject_done_cb, NULL); + g_object_unref (mount_op); + + outstanding_mounts++; +} + /* =============== list mounts ================== */ static gboolean @@ -978,6 +1025,8 @@ main (int argc, char *argv[]) file = g_file_new_for_commandline_arg (argv[i]); if (mount_unmount) unmount (file); + else if (mount_eject) + eject (file); else mount (file); g_object_unref (file); |