2 * Copyright 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Matthias Clasen <mclasen@redhat.com>
32 #define STDIN_FILENO 0
40 static int outstanding_mounts = 0;
41 static GMainLoop *main_loop;
43 static gboolean mount_mountable = FALSE;
44 static gboolean mount_unmount = FALSE;
45 static gboolean mount_eject = FALSE;
46 static gboolean force = FALSE;
47 static gboolean anonymous = FALSE;
48 static gboolean mount_list = FALSE;
49 static gboolean extra_detail = FALSE;
50 static gboolean mount_monitor = FALSE;
51 static const char *unmount_scheme = NULL;
52 static const char *mount_device_file = NULL;
53 static gboolean success = TRUE;
56 static const GOptionEntry entries[] =
58 { "mountable", 'm', 0, G_OPTION_ARG_NONE, &mount_mountable, N_("Mount as mountable"), NULL },
59 { "device", 'd', 0, G_OPTION_ARG_STRING, &mount_device_file, N_("Mount volume with device file"), N_("DEVICE") },
60 { "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, N_("Unmount"), NULL},
61 { "eject", 'e', 0, G_OPTION_ARG_NONE, &mount_eject, N_("Eject"), NULL},
62 { "unmount-scheme", 's', 0, G_OPTION_ARG_STRING, &unmount_scheme, N_("Unmount all mounts with the given scheme"), N_("SCHEME") },
63 { "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore outstanding file operations when unmounting or ejecting"), NULL },
64 { "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, N_("Use an anonymous user when authenticating"), NULL },
65 /* Translator: List here is a verb as in 'List all mounts' */
66 { "list", 'l', 0, G_OPTION_ARG_NONE, &mount_list, N_("List"), NULL},
67 { "monitor", 'o', 0, G_OPTION_ARG_NONE, &mount_monitor, N_("Monitor events"), NULL},
68 { "detail", 'i', 0, G_OPTION_ARG_NONE, &extra_detail, N_("Show extra information"), NULL},
73 prompt_for (const char *prompt, const char *default_value, gboolean echo)
76 struct termios term_attr;
78 gboolean restore_flags;
83 if (default_value && *default_value != 0)
84 g_print ("%s [%s]: ", prompt, default_value);
86 g_print ("%s: ", prompt);
91 restore_flags = FALSE;
92 if (!echo && tcgetattr (STDIN_FILENO, &term_attr) == 0)
94 old_flags = term_attr.c_lflag;
95 term_attr.c_lflag &= ~ECHO;
98 if (tcsetattr (STDIN_FILENO, TCSAFLUSH, &term_attr) != 0)
99 g_print ("Warning! Password will be echoed");
104 fgets(data, sizeof (data), stdin);
106 #ifdef HAVE_TERMIOS_H
109 term_attr.c_lflag = old_flags;
110 tcsetattr (STDIN_FILENO, TCSAFLUSH, &term_attr);
120 if (data[len-1] == '\n')
126 if (*data == 0 && default_value)
127 return g_strdup (default_value);
128 return g_strdup (data);
132 ask_password_cb (GMountOperation *op,
134 const char *default_user,
135 const char *default_domain,
136 GAskPasswordFlags flags)
138 if ((flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED) && anonymous)
140 g_mount_operation_set_anonymous (op, TRUE);
145 g_print ("%s\n", message);
147 if (flags & G_ASK_PASSWORD_NEED_USERNAME)
149 s = prompt_for ("User", default_user, TRUE);
152 g_mount_operation_set_username (op, s);
156 if (flags & G_ASK_PASSWORD_NEED_DOMAIN)
158 s = prompt_for ("Domain", default_domain, TRUE);
161 g_mount_operation_set_domain (op, s);
165 if (flags & G_ASK_PASSWORD_NEED_PASSWORD)
167 s = prompt_for ("Password", NULL, FALSE);
170 g_mount_operation_set_password (op, s);
175 /* Only try anonymous access once. */
177 GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ASKED)
179 g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ABORTED));
180 g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
184 g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ASKED));
185 g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
191 g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
195 ask_question_cb (GMountOperation *op,
200 char **ptr = choices;
204 g_print ("%s\n", message);
209 g_print ("[%d] %s\n", i, *ptr++);
213 s = prompt_for ("Choice", NULL, TRUE);
218 if (choice > 0 && choice < i)
220 g_mount_operation_set_choice (op, choice - 1);
221 g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
228 g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
232 mount_mountable_done_cb (GObject *object,
237 GError *error = NULL;
238 GMountOperation *op = user_data;
240 target = g_file_mount_mountable_finish (G_FILE (object), res, &error);
245 if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED)
246 g_printerr (_("Error mounting location: Anonymous access denied\n"));
247 else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
248 g_printerr (_("Error mounting location: %s\n"), error->message);
250 g_error_free (error);
253 g_object_unref (target);
255 outstanding_mounts--;
257 if (outstanding_mounts == 0)
258 g_main_loop_quit (main_loop);
262 mount_done_cb (GObject *object,
267 GError *error = NULL;
268 GMountOperation *op = user_data;
270 succeeded = g_file_mount_enclosing_volume_finish (G_FILE (object), res, &error);
275 if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED)
276 g_printerr (_("Error mounting location: Anonymous access denied\n"));
277 else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
278 g_printerr (_("Error mounting location: %s\n"), error->message);
280 g_error_free (error);
283 outstanding_mounts--;
285 if (outstanding_mounts == 0)
286 g_main_loop_quit (main_loop);
289 static GMountOperation *
294 op = g_mount_operation_new ();
296 g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_NONE));
298 g_signal_connect (op, "ask_password", G_CALLBACK (ask_password_cb), NULL);
299 g_signal_connect (op, "ask_question", G_CALLBACK (ask_question_cb), NULL);
301 /* TODO: we *should* also connect to the "aborted" signal but since the
302 * main thread is blocked handling input we won't get that signal anyway...
317 op = new_mount_op ();
320 g_file_mount_mountable (file, 0, op, NULL, mount_mountable_done_cb, op);
322 g_file_mount_enclosing_volume (file, 0, op, NULL, mount_done_cb, op);
324 outstanding_mounts++;
328 unmount_done_cb (GObject *object,
333 GError *error = NULL;
335 succeeded = g_mount_unmount_with_operation_finish (G_MOUNT (object), res, &error);
337 g_object_unref (G_MOUNT (object));
341 g_printerr (_("Error unmounting mount: %s\n"), error->message);
343 g_error_free (error);
346 outstanding_mounts--;
348 if (outstanding_mounts == 0)
349 g_main_loop_quit (main_loop);
353 unmount (GFile *file)
356 GError *error = NULL;
357 GMountOperation *mount_op;
358 GMountUnmountFlags flags;
363 mount = g_file_find_enclosing_mount (file, NULL, &error);
366 g_printerr (_("Error finding enclosing mount: %s\n"), error->message);
368 g_error_free (error);
372 mount_op = new_mount_op ();
373 flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE;
374 g_mount_unmount_with_operation (mount, flags, mount_op, NULL, unmount_done_cb, NULL);
375 g_object_unref (mount_op);
377 outstanding_mounts++;
381 eject_done_cb (GObject *object,
386 GError *error = NULL;
388 succeeded = g_mount_eject_with_operation_finish (G_MOUNT (object), res, &error);
390 g_object_unref (G_MOUNT (object));
394 g_printerr (_("Error ejecting mount: %s\n"), error->message);
396 g_error_free (error);
399 outstanding_mounts--;
401 if (outstanding_mounts == 0)
402 g_main_loop_quit (main_loop);
409 GError *error = NULL;
410 GMountOperation *mount_op;
411 GMountUnmountFlags flags;
416 mount = g_file_find_enclosing_mount (file, NULL, &error);
419 g_printerr (_("Error finding enclosing mount: %s\n"), error->message);
421 g_error_free (error);
425 mount_op = new_mount_op ();
426 flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE;
427 g_mount_eject_with_operation (mount, flags, mount_op, NULL, eject_done_cb, NULL);
428 g_object_unref (mount_op);
430 outstanding_mounts++;
434 iterate_gmain_timeout_function (gpointer data)
436 g_main_loop_quit (main_loop);
443 g_timeout_add (500, iterate_gmain_timeout_function, NULL);
444 g_main_loop_run (main_loop);
448 show_themed_icon_names (GThemedIcon *icon, gboolean symbolic, int indent)
453 g_print ("%*s%sthemed icons:", indent, " ", symbolic ? "symbolic " : "");
457 g_object_get (icon, "names", &names, NULL);
459 for (iter = names; *iter; iter++)
460 g_print (" [%s]", *iter);
466 /* don't copy-paste this code */
468 get_type_name (gpointer object)
470 const char *type_name;
473 type_name = g_type_name (G_TYPE_FROM_INSTANCE (object));
474 if (strcmp ("GProxyDrive", type_name) == 0)
476 ret = g_strdup_printf ("%s (%s)",
478 (const char *) g_object_get_data (G_OBJECT (object),
479 "g-proxy-drive-volume-monitor-name"));
481 else if (strcmp ("GProxyVolume", type_name) == 0)
483 ret = g_strdup_printf ("%s (%s)",
485 (const char *) g_object_get_data (G_OBJECT (object),
486 "g-proxy-volume-volume-monitor-name"));
488 else if (strcmp ("GProxyMount", type_name) == 0)
490 ret = g_strdup_printf ("%s (%s)",
492 (const char *) g_object_get_data (G_OBJECT (object),
493 "g-proxy-mount-volume-monitor-name"));
495 else if (strcmp ("GProxyShadowMount", type_name) == 0)
497 ret = g_strdup_printf ("%s (%s)",
499 (const char *) g_object_get_data (G_OBJECT (object),
500 "g-proxy-shadow-mount-volume-monitor-name"));
504 ret = g_strdup (type_name);
511 list_mounts (GList *mounts,
513 gboolean only_with_no_volume)
519 char *name, *uuid, *uri;
520 GFile *root, *default_location;
522 char **x_content_types;
524 const gchar *sort_key;
526 for (c = 0, l = mounts; l != NULL; l = l->next, c++)
528 mount = (GMount *) l->data;
530 if (only_with_no_volume)
532 volume = g_mount_get_volume (mount);
535 g_object_unref (volume);
540 name = g_mount_get_name (mount);
541 root = g_mount_get_root (mount);
542 uri = g_file_get_uri (root);
544 g_print ("%*sMount(%d): %s -> %s\n", indent, "", c, name, uri);
546 type_name = get_type_name (mount);
547 g_print ("%*sType: %s\n", indent+2, "", type_name);
552 uuid = g_mount_get_uuid (mount);
554 g_print ("%*suuid=%s\n", indent + 2, "", uuid);
556 default_location = g_mount_get_default_location (mount);
557 if (default_location)
559 char *loc_uri = g_file_get_uri (default_location);
560 g_print ("%*sdefault_location=%s\n", indent + 2, "", loc_uri);
562 g_object_unref (default_location);
565 icon = g_mount_get_icon (mount);
568 if (G_IS_THEMED_ICON (icon))
569 show_themed_icon_names (G_THEMED_ICON (icon), FALSE, indent + 2);
571 g_object_unref (icon);
574 icon = g_mount_get_symbolic_icon (mount);
577 if (G_IS_THEMED_ICON (icon))
578 show_themed_icon_names (G_THEMED_ICON (icon), TRUE, indent + 2);
580 g_object_unref (icon);
583 x_content_types = g_mount_guess_content_type_sync (mount, FALSE, NULL, NULL);
584 if (x_content_types != NULL && g_strv_length (x_content_types) > 0)
587 g_print ("%*sx_content_types:", indent + 2, "");
588 for (n = 0; x_content_types[n] != NULL; n++)
589 g_print (" %s", x_content_types[n]);
592 g_strfreev (x_content_types);
594 g_print ("%*scan_unmount=%d\n", indent + 2, "", g_mount_can_unmount (mount));
595 g_print ("%*scan_eject=%d\n", indent + 2, "", g_mount_can_eject (mount));
596 g_print ("%*sis_shadowed=%d\n", indent + 2, "", g_mount_is_shadowed (mount));
597 sort_key = g_mount_get_sort_key (mount);
598 if (sort_key != NULL)
599 g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key);
603 g_object_unref (root);
610 list_volumes (GList *volumes,
612 gboolean only_with_no_drive)
621 GFile *activation_root;
625 const gchar *sort_key;
627 for (c = 0, l = volumes; l != NULL; l = l->next, c++)
629 volume = (GVolume *) l->data;
631 if (only_with_no_drive)
633 drive = g_volume_get_drive (volume);
636 g_object_unref (drive);
641 name = g_volume_get_name (volume);
643 g_print ("%*sVolume(%d): %s\n", indent, "", c, name);
646 type_name = get_type_name (volume);
647 g_print ("%*sType: %s\n", indent+2, "", type_name);
652 ids = g_volume_enumerate_identifiers (volume);
653 if (ids && ids[0] != NULL)
655 g_print ("%*sids:\n", indent+2, "");
656 for (i = 0; ids[i] != NULL; i++)
658 char *id = g_volume_get_identifier (volume,
660 g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id);
666 uuid = g_volume_get_uuid (volume);
668 g_print ("%*suuid=%s\n", indent + 2, "", uuid);
669 activation_root = g_volume_get_activation_root (volume);
673 uri = g_file_get_uri (activation_root);
674 g_print ("%*sactivation_root=%s\n", indent + 2, "", uri);
676 g_object_unref (activation_root);
678 icon = g_volume_get_icon (volume);
681 if (G_IS_THEMED_ICON (icon))
682 show_themed_icon_names (G_THEMED_ICON (icon), FALSE, indent + 2);
684 g_object_unref (icon);
687 icon = g_volume_get_symbolic_icon (volume);
690 if (G_IS_THEMED_ICON (icon))
691 show_themed_icon_names (G_THEMED_ICON (icon), TRUE, indent + 2);
693 g_object_unref (icon);
696 g_print ("%*scan_mount=%d\n", indent + 2, "", g_volume_can_mount (volume));
697 g_print ("%*scan_eject=%d\n", indent + 2, "", g_volume_can_eject (volume));
698 g_print ("%*sshould_automount=%d\n", indent + 2, "", g_volume_should_automount (volume));
699 sort_key = g_volume_get_sort_key (volume);
700 if (sort_key != NULL)
701 g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key);
705 mount = g_volume_get_mount (volume);
708 mounts = g_list_prepend (NULL, mount);
709 list_mounts (mounts, indent + 2, FALSE);
710 g_list_free (mounts);
711 g_object_unref (mount);
717 list_drives (GList *drives,
727 const gchar *sort_key;
729 for (c = 0, l = drives; l != NULL; l = l->next, c++)
731 drive = (GDrive *) l->data;
732 name = g_drive_get_name (drive);
734 g_print ("%*sDrive(%d): %s\n", indent, "", c, name);
737 type_name = get_type_name (drive);
738 g_print ("%*sType: %s\n", indent+2, "", type_name);
743 GEnumValue *enum_value;
746 ids = g_drive_enumerate_identifiers (drive);
747 if (ids && ids[0] != NULL)
749 g_print ("%*sids:\n", indent+2, "");
750 for (i = 0; ids[i] != NULL; i++)
752 char *id = g_drive_get_identifier (drive,
754 g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id);
760 icon = g_drive_get_icon (drive);
763 if (G_IS_THEMED_ICON (icon))
764 show_themed_icon_names (G_THEMED_ICON (icon), FALSE, indent + 2);
765 g_object_unref (icon);
768 icon = g_drive_get_symbolic_icon (drive);
771 if (G_IS_THEMED_ICON (icon))
772 show_themed_icon_names (G_THEMED_ICON (icon), TRUE, indent + 2);
774 g_object_unref (icon);
777 g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive));
778 g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive));
779 g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive));
780 g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive));
781 g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive));
782 g_print ("%*scan_start=%d\n", indent + 2, "", g_drive_can_start (drive));
783 g_print ("%*scan_stop=%d\n", indent + 2, "", g_drive_can_stop (drive));
786 klass = g_type_class_ref (G_TYPE_DRIVE_START_STOP_TYPE);
789 enum_value = g_enum_get_value (klass, g_drive_get_start_stop_type (drive));
790 g_print ("%*sstart_stop_type=%s\n", indent + 2, "",
791 enum_value != NULL ? enum_value->value_nick : "UNKNOWN");
792 g_type_class_unref (klass);
795 sort_key = g_drive_get_sort_key (drive);
796 if (sort_key != NULL)
797 g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key);
799 volumes = g_drive_get_volumes (drive);
800 list_volumes (volumes, indent + 2, FALSE);
801 g_list_free_full (volumes, g_object_unref);
807 list_monitor_items (void)
809 GVolumeMonitor *volume_monitor;
810 GList *drives, *volumes, *mounts;
812 volume_monitor = g_volume_monitor_get();
814 /* populate gvfs network mounts */
817 drives = g_volume_monitor_get_connected_drives (volume_monitor);
818 list_drives (drives, 0);
819 g_list_free_full (drives, g_object_unref);
821 volumes = g_volume_monitor_get_volumes (volume_monitor);
822 list_volumes (volumes, 0, TRUE);
823 g_list_free_full (volumes, g_object_unref);
825 mounts = g_volume_monitor_get_mounts (volume_monitor);
826 list_mounts (mounts, 0, TRUE);
827 g_list_free_full (mounts, g_object_unref);
829 g_object_unref (volume_monitor);
833 unmount_all_with_scheme (const char *scheme)
835 GVolumeMonitor *volume_monitor;
839 volume_monitor = g_volume_monitor_get();
841 /* populate gvfs network mounts */
844 mounts = g_volume_monitor_get_mounts (volume_monitor);
845 for (l = mounts; l != NULL; l = l->next) {
846 GMount *mount = G_MOUNT (l->data);
849 root = g_mount_get_root (mount);
850 if (g_file_has_uri_scheme (root, scheme)) {
853 g_object_unref (root);
855 g_list_free_full (mounts, g_object_unref);
857 g_object_unref (volume_monitor);
861 mount_with_device_file_cb (GObject *object,
867 GError *error = NULL;
869 volume = G_VOLUME (object);
871 succeeded = g_volume_mount_finish (volume, res, &error);
875 g_printerr (_("Error mounting %s: %s\n"),
876 g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
878 g_error_free (error);
887 mount = g_volume_get_mount (volume);
888 root = g_mount_get_root (mount);
889 mount_path = g_file_get_path (root);
891 g_print (_("Mounted %s at %s\n"),
892 g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
895 g_object_unref (mount);
896 g_object_unref (root);
900 outstanding_mounts--;
902 if (outstanding_mounts == 0)
903 g_main_loop_quit (main_loop);
907 mount_with_device_file (const char *device_file)
909 GVolumeMonitor *volume_monitor;
913 volume_monitor = g_volume_monitor_get();
915 volumes = g_volume_monitor_get_volumes (volume_monitor);
916 for (l = volumes; l != NULL; l = l->next)
918 GVolume *volume = G_VOLUME (l->data);
920 if (g_strcmp0 (g_volume_get_identifier (volume,
921 G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE), device_file) == 0)
925 op = new_mount_op ();
927 g_volume_mount (volume,
931 mount_with_device_file_cb,
934 outstanding_mounts++;
937 g_list_free_full (volumes, g_object_unref);
939 if (outstanding_mounts == 0)
941 g_print (_("No volume for device file %s\n"), device_file);
945 g_object_unref (volume_monitor);
949 monitor_print_mount (GMount *mount)
954 l = g_list_prepend (NULL, mount);
955 list_mounts (l, 2, FALSE);
962 monitor_print_volume (GVolume *volume)
967 l = g_list_prepend (NULL, volume);
968 list_volumes (l, 2, FALSE);
975 monitor_print_drive (GDrive *drive)
980 l = g_list_prepend (NULL, drive);
988 monitor_mount_added (GVolumeMonitor *volume_monitor, GMount *mount)
991 name = g_mount_get_name (mount);
992 g_print ("Mount added: '%s'\n", name);
994 monitor_print_mount (mount);
998 monitor_mount_removed (GVolumeMonitor *volume_monitor, GMount *mount)
1001 name = g_mount_get_name (mount);
1002 g_print ("Mount removed: '%s'\n", name);
1004 monitor_print_mount (mount);
1008 monitor_mount_changed (GVolumeMonitor *volume_monitor, GMount *mount)
1011 name = g_mount_get_name (mount);
1012 g_print ("Mount changed: '%s'\n", name);
1014 monitor_print_mount (mount);
1018 monitor_mount_pre_unmount (GVolumeMonitor *volume_monitor, GMount *mount)
1021 name = g_mount_get_name (mount);
1022 g_print ("Mount pre-unmount: '%s'\n", name);
1024 monitor_print_mount (mount);
1028 monitor_volume_added (GVolumeMonitor *volume_monitor, GVolume *volume)
1031 name = g_volume_get_name (volume);
1032 g_print ("Volume added: '%s'\n", name);
1034 monitor_print_volume (volume);
1038 monitor_volume_removed (GVolumeMonitor *volume_monitor, GVolume *volume)
1041 name = g_volume_get_name (volume);
1042 g_print ("Volume removed: '%s'\n", name);
1044 monitor_print_volume (volume);
1048 monitor_volume_changed (GVolumeMonitor *volume_monitor, GVolume *volume)
1051 name = g_volume_get_name (volume);
1052 g_print ("Volume changed: '%s'\n", name);
1054 monitor_print_volume (volume);
1058 monitor_drive_connected (GVolumeMonitor *volume_monitor, GDrive *drive)
1061 name = g_drive_get_name (drive);
1062 g_print ("Drive connected: '%s'\n", name);
1064 monitor_print_drive (drive);
1068 monitor_drive_disconnected (GVolumeMonitor *volume_monitor, GDrive *drive)
1071 name = g_drive_get_name (drive);
1072 g_print ("Drive disconnected: '%s'\n", name);
1074 monitor_print_drive (drive);
1078 monitor_drive_changed (GVolumeMonitor *volume_monitor, GDrive *drive)
1081 name = g_drive_get_name (drive);
1082 g_print ("Drive changed: '%s'\n", name);
1084 monitor_print_drive (drive);
1088 monitor_drive_eject_button (GVolumeMonitor *volume_monitor, GDrive *drive)
1091 name = g_drive_get_name (drive);
1092 g_print ("Drive eject button: '%s'\n", name);
1099 GVolumeMonitor *volume_monitor;
1101 volume_monitor = g_volume_monitor_get ();
1103 g_signal_connect (volume_monitor, "mount-added", (GCallback) monitor_mount_added, NULL);
1104 g_signal_connect (volume_monitor, "mount-removed", (GCallback) monitor_mount_removed, NULL);
1105 g_signal_connect (volume_monitor, "mount-changed", (GCallback) monitor_mount_changed, NULL);
1106 g_signal_connect (volume_monitor, "mount-pre-unmount", (GCallback) monitor_mount_pre_unmount, NULL);
1107 g_signal_connect (volume_monitor, "volume-added", (GCallback) monitor_volume_added, NULL);
1108 g_signal_connect (volume_monitor, "volume-removed", (GCallback) monitor_volume_removed, NULL);
1109 g_signal_connect (volume_monitor, "volume-changed", (GCallback) monitor_volume_changed, NULL);
1110 g_signal_connect (volume_monitor, "drive-connected", (GCallback) monitor_drive_connected, NULL);
1111 g_signal_connect (volume_monitor, "drive-disconnected", (GCallback) monitor_drive_disconnected, NULL);
1112 g_signal_connect (volume_monitor, "drive-changed", (GCallback) monitor_drive_changed, NULL);
1113 g_signal_connect (volume_monitor, "drive-eject-button", (GCallback) monitor_drive_eject_button, NULL);
1115 g_print ("Monitoring events. Press Ctrl+C to quit.\n");
1117 g_main_loop_run (main_loop);
1121 handle_mount (int argc, char *argv[], gboolean do_help)
1123 GOptionContext *context;
1125 GError *error = NULL;
1129 g_set_prgname ("gio mount");
1131 /* Translators: commandline placeholder */
1132 param = g_strdup_printf ("[%s...]", _("LOCATION"));
1133 context = g_option_context_new (param);
1135 g_option_context_set_help_enabled (context, FALSE);
1136 g_option_context_set_summary (context, _("Mount or unmount the locations."));
1137 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
1141 show_help (context, NULL);
1145 if (!g_option_context_parse (context, &argc, &argv, &error))
1147 show_help (context, error->message);
1148 g_error_free (error);
1152 g_option_context_free (context);
1154 main_loop = g_main_loop_new (NULL, FALSE);
1157 list_monitor_items ();
1158 else if (mount_device_file != NULL)
1159 mount_with_device_file (mount_device_file);
1160 else if (unmount_scheme != NULL)
1161 unmount_all_with_scheme (unmount_scheme);
1162 else if (mount_monitor)
1166 for (i = 1; i < argc; i++)
1168 file = g_file_new_for_commandline_arg (argv[i]);
1171 else if (mount_eject)
1175 g_object_unref (file);
1179 if (outstanding_mounts > 0)
1180 g_main_loop_run (main_loop);
1182 return success ? 0 : 2;