mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 07:26:15 +01:00
gio-tool: Add support for stopping drives
There is not currently an option for stopping drives, however it would be really useful for testing. Let's add that possibility for "gio mount".
This commit is contained in:
parent
66187c4c3e
commit
fe9c6192c4
@ -50,6 +50,7 @@ static gboolean extra_detail = FALSE;
|
|||||||
static gboolean mount_monitor = FALSE;
|
static gboolean mount_monitor = FALSE;
|
||||||
static const char *unmount_scheme = NULL;
|
static const char *unmount_scheme = NULL;
|
||||||
static const char *mount_device_file = NULL;
|
static const char *mount_device_file = NULL;
|
||||||
|
static const char *stop_device_file = NULL;
|
||||||
static gboolean success = TRUE;
|
static gboolean success = TRUE;
|
||||||
|
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ static const GOptionEntry entries[] =
|
|||||||
{ "device", 'd', 0, G_OPTION_ARG_STRING, &mount_device_file, N_("Mount volume with device file"), N_("DEVICE") },
|
{ "device", 'd', 0, G_OPTION_ARG_STRING, &mount_device_file, N_("Mount volume with device file"), N_("DEVICE") },
|
||||||
{ "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, N_("Unmount"), 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},
|
{ "eject", 'e', 0, G_OPTION_ARG_NONE, &mount_eject, N_("Eject"), NULL},
|
||||||
|
{ "stop", 't', 0, G_OPTION_ARG_STRING, &stop_device_file, N_("Stop drive with device file"), N_("DEVICE") },
|
||||||
{ "unmount-scheme", 's', 0, G_OPTION_ARG_STRING, &unmount_scheme, N_("Unmount all mounts with the given scheme"), N_("SCHEME") },
|
{ "unmount-scheme", 's', 0, G_OPTION_ARG_STRING, &unmount_scheme, N_("Unmount all mounts with the given scheme"), N_("SCHEME") },
|
||||||
{ "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore outstanding file operations when unmounting or ejecting"), NULL },
|
{ "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore outstanding file operations when unmounting or ejecting"), NULL },
|
||||||
{ "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, N_("Use an anonymous user when authenticating"), NULL },
|
{ "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, N_("Use an anonymous user when authenticating"), NULL },
|
||||||
@ -436,6 +438,76 @@ eject (GFile *file)
|
|||||||
outstanding_mounts++;
|
outstanding_mounts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stop_with_device_file_cb (GObject *object,
|
||||||
|
GAsyncResult *res,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
gchar *device_path = user_data;
|
||||||
|
|
||||||
|
if (!g_drive_stop_finish (G_DRIVE (object), res, &error))
|
||||||
|
{
|
||||||
|
print_error ("%s: %s", device_path, error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
success = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (device_path);
|
||||||
|
|
||||||
|
outstanding_mounts--;
|
||||||
|
|
||||||
|
if (outstanding_mounts == 0)
|
||||||
|
g_main_loop_quit (main_loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stop_with_device_file (const char *device_file)
|
||||||
|
{
|
||||||
|
GVolumeMonitor *volume_monitor;
|
||||||
|
GList *drives;
|
||||||
|
GList *l;
|
||||||
|
|
||||||
|
volume_monitor = g_volume_monitor_get ();
|
||||||
|
|
||||||
|
drives = g_volume_monitor_get_connected_drives (volume_monitor);
|
||||||
|
for (l = drives; l != NULL; l = l->next)
|
||||||
|
{
|
||||||
|
GDrive *drive = G_DRIVE (l->data);
|
||||||
|
gchar *id;
|
||||||
|
|
||||||
|
id = g_drive_get_identifier (drive, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
||||||
|
if (g_strcmp0 (id, device_file) == 0)
|
||||||
|
{
|
||||||
|
GMountOperation *op;
|
||||||
|
GMountUnmountFlags flags;
|
||||||
|
|
||||||
|
op = new_mount_op ();
|
||||||
|
flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE;
|
||||||
|
g_drive_stop (drive,
|
||||||
|
flags,
|
||||||
|
op,
|
||||||
|
NULL,
|
||||||
|
stop_with_device_file_cb,
|
||||||
|
g_steal_pointer (&id));
|
||||||
|
g_object_unref (op);
|
||||||
|
|
||||||
|
outstanding_mounts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (id);
|
||||||
|
}
|
||||||
|
g_list_free_full (drives, g_object_unref);
|
||||||
|
|
||||||
|
if (outstanding_mounts == 0)
|
||||||
|
{
|
||||||
|
print_error ("%s: %s", device_file, _("No drive for device file"));
|
||||||
|
success = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (volume_monitor);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
iterate_gmain_timeout_function (gpointer data)
|
iterate_gmain_timeout_function (gpointer data)
|
||||||
{
|
{
|
||||||
@ -1168,6 +1240,8 @@ handle_mount (int argc, char *argv[], gboolean do_help)
|
|||||||
list_monitor_items ();
|
list_monitor_items ();
|
||||||
else if (mount_device_file != NULL)
|
else if (mount_device_file != NULL)
|
||||||
mount_with_device_file (mount_device_file);
|
mount_with_device_file (mount_device_file);
|
||||||
|
else if (stop_device_file)
|
||||||
|
stop_with_device_file (stop_device_file);
|
||||||
else if (unmount_scheme != NULL)
|
else if (unmount_scheme != NULL)
|
||||||
unmount_all_with_scheme (unmount_scheme);
|
unmount_all_with_scheme (unmount_scheme);
|
||||||
else if (mount_monitor)
|
else if (mount_monitor)
|
||||||
|
Loading…
Reference in New Issue
Block a user