Commit f4add8f0 authored by David Zeuthen's avatar David Zeuthen Committed by Alexander Larsson

Provide eject() on both GMount and GVolume and utility functions to guess

2007-12-14  David Zeuthen  <davidz@redhat.com>

	* Makefile.am:
	* gio.symbols:
	* gmount.c: (g_mount_get_uuid), (g_mount_can_eject),
	(g_mount_eject), (g_mount_eject_finish):
	* gmount.h:
	* gunionvolumemonitor.c: (g_union_volume_monitor_finalize),
	(get_volume_for_uuid), (get_mount_for_uuid),
	(g_union_volume_monitor_class_init),
	(get_default_native_type_with_exclude), (get_default_native_type),
	(get_native_type), (update_native_type),
	(g_union_volume_monitor_init), (_g_mount_get_for_mount_path):
	* gunixmount.c: (_g_unix_mount_new), (g_unix_mount_get_uuid),
	(g_unix_mount_can_eject), (eject_unmount_cb),
	(eject_unmount_read_error), (eject_unmount_do),
	(g_unix_mount_unmount), (g_unix_mount_eject),
	(g_unix_mount_eject_finish), (g_unix_mount_mount_iface_init):
	* gunixmounts.c: (g_unix_mount_guess_can_eject),
	(g_unix_mount_point_guess_can_eject):
	* gunixmounts.h:
	* gunixvolume.c: (_g_unix_volume_new), (g_unix_volume_get_uuid),
	(g_unix_volume_can_eject), (g_unix_volume_get_drive),
	(eject_mount_cb), (eject_mount_read_error), (eject_mount_do),
	(g_unix_volume_mount), (g_unix_volume_eject),
	(g_unix_volume_eject_finish), (g_unix_volume_volume_iface_init):
	* gunixvolumemonitor.c: (get_volume_for_uuid),
	(get_mount_for_uuid), (g_unix_volume_monitor_class_init),
	(update_mounts):
	* gvolume.c: (g_volume_get_uuid), (g_volume_can_eject),
	(g_volume_eject), (g_volume_eject_finish):
	* gvolume.h:
	* gvolumemonitor.c: (g_volume_monitor_get_volume_for_uuid),
	(g_volume_monitor_get_mount_for_uuid):
	* gvolumemonitor.h:

	Provide eject() on both GMount and GVolume and utility functions
	to guess whether a GUnixMountPoint or GUnixMountEntry should be
	ejected. Introduce the concept of UUID's and wire it into GVolume
	and GMount and provide API on GVolumeMonitor to find such
	instances. Also handle the case where an external
	GNativeVolumeMonitor fails to initialize. Lock around the
	_g_get_mount_for_mount_path() function such that volume monitor
	implementations won't have to do locking themselves.



svn path=/trunk/; revision=6140
parent 96a0e238
2007-12-14 David Zeuthen <davidz@redhat.com>
* Makefile.am:
* gio.symbols:
* gmount.c: (g_mount_get_uuid), (g_mount_can_eject),
(g_mount_eject), (g_mount_eject_finish):
* gmount.h:
* gunionvolumemonitor.c: (g_union_volume_monitor_finalize),
(get_volume_for_uuid), (get_mount_for_uuid),
(g_union_volume_monitor_class_init),
(get_default_native_type_with_exclude), (get_default_native_type),
(get_native_type), (update_native_type),
(g_union_volume_monitor_init), (_g_mount_get_for_mount_path):
* gunixmount.c: (_g_unix_mount_new), (g_unix_mount_get_uuid),
(g_unix_mount_can_eject), (eject_unmount_cb),
(eject_unmount_read_error), (eject_unmount_do),
(g_unix_mount_unmount), (g_unix_mount_eject),
(g_unix_mount_eject_finish), (g_unix_mount_mount_iface_init):
* gunixmounts.c: (g_unix_mount_guess_can_eject),
(g_unix_mount_point_guess_can_eject):
* gunixmounts.h:
* gunixvolume.c: (_g_unix_volume_new), (g_unix_volume_get_uuid),
(g_unix_volume_can_eject), (g_unix_volume_get_drive),
(eject_mount_cb), (eject_mount_read_error), (eject_mount_do),
(g_unix_volume_mount), (g_unix_volume_eject),
(g_unix_volume_eject_finish), (g_unix_volume_volume_iface_init):
* gunixvolumemonitor.c: (get_volume_for_uuid),
(get_mount_for_uuid), (g_unix_volume_monitor_class_init),
(update_mounts):
* gvolume.c: (g_volume_get_uuid), (g_volume_can_eject),
(g_volume_eject), (g_volume_eject_finish):
* gvolume.h:
* gvolumemonitor.c: (g_volume_monitor_get_volume_for_uuid),
(g_volume_monitor_get_mount_for_uuid):
* gvolumemonitor.h:
Provide eject() on both GMount and GVolume and utility functions
to guess whether a GUnixMountPoint or GUnixMountEntry should be
ejected. Introduce the concept of UUID's and wire it into GVolume
and GMount and provide API on GVolumeMonitor to find such
instances. Also handle the case where an external
GNativeVolumeMonitor fails to initialize. Lock around the
_g_get_mount_for_mount_path() function such that volume monitor
implementations won't have to do locking themselves.
2007-12-17 Matthias Clasen <mclasen@redhat.com>
* gdesktopappinfo.c:
......
......@@ -235,6 +235,7 @@ gio_headers = \
gmemoryinputstream.h \
gmemoryoutputstream.h \
gmountoperation.h \
gnativevolumemonitor.h \
goutputstream.h \
gseekable.h \
gsimpleasyncresult.h \
......
......@@ -50,6 +50,7 @@
#include <gio/gmemoryoutputstream.h>
#include <gio/gsimpleasyncresult.h>
#include <gio/gioenumtypes.h>
#include <gio/gnativevolumemonitor.h>
#undef __GIO_GIO_H_INSIDE__
......
......@@ -681,11 +681,15 @@ g_mount_get_type G_GNUC_CONST
g_mount_get_root
g_mount_get_name
g_mount_get_icon
g_mount_get_uuid
g_mount_get_volume
g_mount_get_drive
g_mount_can_unmount
g_mount_can_eject
g_mount_unmount
g_mount_unmount_finish
g_mount_eject
g_mount_eject_finish
#endif
#endif
......@@ -694,11 +698,15 @@ g_mount_unmount_finish
g_volume_get_type G_GNUC_CONST
g_volume_get_name
g_volume_get_icon
g_volume_get_uuid
g_volume_get_drive
g_volume_get_mount
g_volume_can_mount
g_volume_can_eject
g_volume_mount
g_volume_mount_finish
g_volume_eject
g_volume_eject_finish
#endif
#endif
......@@ -708,6 +716,7 @@ g_volume_monitor_get_type G_GNUC_CONST
g_volume_monitor_get_connected_drives
g_volume_monitor_get_volumes
g_volume_monitor_get_mounts
g_volume_monitor_get_mount_for_uuid
#endif
#if IN_FILE(__G_UNION_VOLUME_MONITOR_C__)
g_volume_monitor_get
......
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* GIO - GLib Input, Output and Streaming Library
*
* Copyright (C) 2006-2007 Red Hat, Inc.
......@@ -22,6 +24,9 @@
*/
#include <config.h>
#include <string.h>
#include "gmount.h"
#include "gmountprivate.h"
#include "gsimpleasyncresult.h"
......@@ -175,7 +180,30 @@ g_mount_get_icon (GMount *mount)
return (* iface->get_icon) (mount);
}
/**
* g_mount_get_uuid:
* @mount: a #GMount.
*
* Gets the UUID for the @mount. The reference is typically based on
* the file system UUID for the mount in question and should be
* considered an opaque string. Returns %NULL if there is no UUID
* available.
*
* Returns: the UUID for @mount or %NULL if no UUID can be computed.
**/
char *
g_mount_get_uuid (GMount *mount)
{
GMountIface *iface;
g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
iface = G_MOUNT_GET_IFACE (mount);
return (* iface->get_uuid) (mount);
}
/**
* g_mount_get_volume:
* @mount: a #GMount.
......@@ -239,6 +267,26 @@ g_mount_can_unmount (GMount *mount)
return (* iface->can_unmount) (mount);
}
/**
* g_mount_can_eject:
* @mount: a #GMount.
*
* Checks if @mount can be eject.
*
* Returns: %TRUE if the @mount can be ejected.
**/
gboolean
g_mount_can_eject (GMount *mount)
{
GMountIface *iface;
g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
iface = G_MOUNT_GET_IFACE (mount);
return (* iface->can_eject) (mount);
}
/**
* g_mount_unmount:
* @mount: a #GMount.
......@@ -308,5 +356,75 @@ g_mount_unmount_finish (GMount *mount,
return (* iface->unmount_finish) (mount, result, error);
}
/**
* g_mount_eject:
* @mount: a #GMount.
* @cancellable: optional #GCancellable object, %NULL to ignore.
* @callback: a #GAsyncReadyCallback.
* @user_data: user data passed to @callback.
*
* Ejects a mount. This is an asynchronous operation, and is
* finished by calling g_mount_eject_finish() with the @mount
* and #GAsyncResults data returned in the @callback.
**/
void
g_mount_eject (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GMountIface *iface;
g_return_if_fail (G_IS_MOUNT (mount));
iface = G_MOUNT_GET_IFACE (mount);
if (iface->eject == NULL)
{
g_simple_async_report_error_in_idle (G_OBJECT (mount),
callback, user_data,
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
_("mount doesn't implement eject"));
return;
}
(* iface->eject) (mount, cancellable, callback, user_data);
}
/**
* g_mount_eject_finish:
* @mount: a #GMount.
* @result: a #GAsyncResult.
* @error: a #GError location to store the error occuring, or %NULL to
* ignore.
*
* Finishes ejecting a mount. If any errors occured during the operation,
* @error will be set to contain the errors and %FALSE will be returned.
*
* Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
**/
gboolean
g_mount_eject_finish (GMount *mount,
GAsyncResult *result,
GError **error)
{
GMountIface *iface;
g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
if (G_IS_SIMPLE_ASYNC_RESULT (result))
{
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
}
iface = G_MOUNT_GET_IFACE (mount);
return (* iface->eject_finish) (mount, result, error);
}
#define __G_MOUNT_C__
#include "gioaliasdef.c"
......@@ -62,11 +62,15 @@ typedef struct _GMountIface GMountIface;
* @get_root: Gets a #GFile to the root directory of the #GMount.
* @get_name: Gets a string containing the name of the #GMount.
* @get_icon: Gets a #GIcon for the #GMount.
* @get_uuid: Gets the UUID for the #GMount. The reference is typically based on the file system UUID for the mount in question and should be considered an opaque string. Returns %NULL if there is no UUID available.
* @get_volume: Gets a #GVolume the mount is located on. Returns %NULL if the #GMount is not associated with a #GVolume.
* @get_drive: Gets a #GDrive the volume of the mount is located on. Returns %NULL if the #GMount is not associated with a #GDrive or a #GVolume. This is convenience method for getting the #GVolume and using that to get the #GDrive.
* @can_unmount: Checks if a #GMount can be unmounted.
* @can_eject: Checks if a #GMount can be ejected.
* @unmount: Starts unmounting a #GMount.
* @unmount_finish: Finishes an unmounting operation.
* @eject: Starts ejecting a #GMount.
* @eject_finish: Finishes an eject operation.
*
* Interface for implementing operations for mounts.
**/
......@@ -83,9 +87,11 @@ struct _GMountIface
GFile * (*get_root) (GMount *mount);
char * (*get_name) (GMount *mount);
GIcon * (*get_icon) (GMount *mount);
char * (*get_uuid) (GMount *mount);
GVolume * (*get_volume) (GMount *mount);
GDrive * (*get_drive) (GMount *mount);
gboolean (*can_unmount) (GMount *mount);
gboolean (*can_eject) (GMount *mount);
void (*unmount) (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -93,6 +99,13 @@ struct _GMountIface
gboolean (*unmount_finish) (GMount *mount,
GAsyncResult *result,
GError **error);
void (*eject) (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*eject_finish) (GMount *mount,
GAsyncResult *result,
GError **error);
};
GType g_mount_get_type (void) G_GNUC_CONST;
......@@ -100,16 +113,25 @@ GType g_mount_get_type (void) G_GNUC_CONST;
GFile * g_mount_get_root (GMount *mount);
char * g_mount_get_name (GMount *mount);
GIcon * g_mount_get_icon (GMount *mount);
char * g_mount_get_uuid (GMount *mount);
GVolume * g_mount_get_volume (GMount *mount);
GDrive * g_mount_get_drive (GMount *mount);
gboolean g_mount_can_unmount (GMount *mount);
gboolean g_mount_can_eject (GMount *mount);
void g_mount_unmount (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean g_mount_unmount_finish (GMount *mount,
GAsyncResult *result,
GError **error);
GAsyncResult *result,
GError **error);
void g_mount_eject (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean g_mount_eject_finish (GMount *mount,
GAsyncResult *result,
GError **error);
G_END_DECLS
......
......@@ -59,12 +59,17 @@ static void
g_union_volume_monitor_finalize (GObject *object)
{
GUnionVolumeMonitor *monitor;
GVolumeMonitor *child_monitor;
monitor = G_UNION_VOLUME_MONITOR (object);
while (monitor->monitors != NULL)
g_union_volume_monitor_remove_monitor (monitor,
monitor->monitors->data);
while (monitor->monitors != NULL) {
child_monitor = monitor->monitors->data;
g_union_volume_monitor_remove_monitor (monitor,
child_monitor);
g_object_unref (child_monitor);
}
if (G_OBJECT_CLASS (g_union_volume_monitor_parent_class)->finalize)
(*G_OBJECT_CLASS (g_union_volume_monitor_parent_class)->finalize) (object);
......@@ -163,6 +168,64 @@ get_connected_drives (GVolumeMonitor *volume_monitor)
return res;
}
static GVolume *
get_volume_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid)
{
GUnionVolumeMonitor *monitor;
GVolumeMonitor *child_monitor;
GVolume *volume;
GList *l;
monitor = G_UNION_VOLUME_MONITOR (volume_monitor);
volume = NULL;
G_LOCK (the_volume_monitor);
for (l = monitor->monitors; l != NULL; l = l->next)
{
child_monitor = l->data;
volume = g_volume_monitor_get_volume_for_uuid (child_monitor, uuid);
if (volume != NULL)
break;
}
G_UNLOCK (the_volume_monitor);
return volume;
}
static GMount *
get_mount_for_uuid (GVolumeMonitor *volume_monitor, const char *uuid)
{
GUnionVolumeMonitor *monitor;
GVolumeMonitor *child_monitor;
GMount *mount;
GList *l;
monitor = G_UNION_VOLUME_MONITOR (volume_monitor);
mount = NULL;
G_LOCK (the_volume_monitor);
for (l = monitor->monitors; l != NULL; l = l->next)
{
child_monitor = l->data;
mount = g_volume_monitor_get_mount_for_uuid (child_monitor, uuid);
if (mount != NULL)
break;
}
G_UNLOCK (the_volume_monitor);
return mount;
}
static void
g_union_volume_monitor_class_init (GUnionVolumeMonitorClass *klass)
{
......@@ -175,6 +238,8 @@ g_union_volume_monitor_class_init (GUnionVolumeMonitorClass *klass)
monitor_class->get_connected_drives = get_connected_drives;
monitor_class->get_volumes = get_volumes;
monitor_class->get_mounts = get_mounts;
monitor_class->get_volume_for_uuid = get_volume_for_uuid;
monitor_class->get_mount_for_uuid = get_mount_for_uuid;
}
static void
......@@ -325,14 +390,13 @@ g_union_volume_monitor_remove_monitor (GUnionVolumeMonitor *union_monitor,
g_signal_handlers_disconnect_by_func (child_monitor, child_drive_changed, union_monitor);
}
static gpointer
get_default_native_type (gpointer data)
static GType
get_default_native_type_with_exclude (GType type_to_exclude)
{
GNativeVolumeMonitorClass *klass;
GType *monitors;
guint n_monitors;
GType native_type;
GType *ret = (GType *) data;
int native_prio;
int i;
......@@ -347,39 +411,57 @@ get_default_native_type (gpointer data)
/* Ensure vfs in modules loaded */
_g_io_modules_ensure_loaded ();
monitors = g_type_children (G_TYPE_NATIVE_VOLUME_MONITOR, &n_monitors);
native_type = 0;
native_prio = -1;
for (i = 0; i < n_monitors; i++)
{
klass = G_NATIVE_VOLUME_MONITOR_CLASS (g_type_class_ref (monitors[i]));
if (klass->priority > native_prio)
if (monitors[i] != type_to_exclude)
{
native_prio = klass->priority;
native_type = monitors[i];
}
klass = G_NATIVE_VOLUME_MONITOR_CLASS (g_type_class_ref (monitors[i]));
if (klass->priority > native_prio)
{
native_prio = klass->priority;
native_type = monitors[i];
}
g_type_class_unref (klass);
g_type_class_unref (klass);
}
}
g_free (monitors);
*ret = native_type;
return native_type;
}
static gpointer
get_default_native_type (gpointer data)
{
GType *ret = (GType *) data;
*ret = get_default_native_type_with_exclude (G_TYPE_INVALID);
return NULL;
}
static GOnce _once_init = G_ONCE_INIT;
static GType _type = G_TYPE_INVALID;
static GType
get_native_type (void)
get_native_type ()
{
static GOnce once_init = G_ONCE_INIT;
static GType type = G_TYPE_INVALID;
g_once (&once_init, get_default_native_type, &type);
g_once (&_once_init, get_default_native_type, &_type);
return type;
return _type;
}
static void
update_native_type (GType type)
{
_type = type;
}
static void
......@@ -396,8 +478,22 @@ g_union_volume_monitor_init (GUnionVolumeMonitor *union_monitor)
if (native_type != G_TYPE_INVALID)
{
monitor = g_object_new (native_type, NULL);
g_union_volume_monitor_add_monitor (union_monitor, monitor);
g_object_unref (monitor);
/* A native file monitor (the hal one if hald isn't running for
* example) may very well fail so handle falling back to the
* native one shipped with gio (e.g. GUnixVolumeMonitor)
*/
if (monitor == NULL)
{
native_type = get_default_native_type_with_exclude (native_type);
monitor = g_object_new (native_type, NULL);
}
if (monitor != NULL)
{
g_union_volume_monitor_add_monitor (union_monitor, monitor);
g_object_unref (monitor);
update_native_type (native_type);
}
}
monitors = g_type_children (G_TYPE_VOLUME_MONITOR, &n_monitors);
......@@ -474,10 +570,22 @@ _g_mount_get_for_mount_path (const char *mount_path)
return NULL;
mount = NULL;
klass = G_NATIVE_VOLUME_MONITOR_CLASS (g_type_class_ref (native_type));
if (klass->get_mount_for_mount_path)
mount = klass->get_mount_for_mount_path (mount_path);
{
G_LOCK (the_volume_monitor);
mount = klass->get_mount_for_mount_path (mount_path);
G_UNLOCK (the_volume_monitor);
}
/* TODO: How do we know this succeeded? Keep in mind that the native
* volume monitor may fail (e.g. not being able to connect to
* hald). Is the get_mount_for_mount_path() method allowed to
* return NULL? Seems like it is ... probably the method needs
* to take a boolean and write if it succeeds or not.. Messy.
* Very messy.
*/
g_type_class_unref (klass);
......
......@@ -52,6 +52,8 @@ struct _GUnixMount {
GIcon *icon;
char *device_path;
char *mount_path;
gboolean can_eject;
};
static void g_unix_mount_mount_iface_init (GMountIface *iface);
......@@ -99,9 +101,9 @@ g_unix_mount_init (GUnixMount *unix_mount)
}
GUnixMount *
_g_unix_mount_new (GVolumeMonitor *volume_monitor,
GUnixMountEntry *mount_entry,
GUnixVolume *volume)
_g_unix_mount_new (GVolumeMonitor *volume_monitor,
GUnixMountEntry *mount_entry,
GUnixVolume *volume)
{
GUnixMount *mount;
......@@ -113,6 +115,8 @@ _g_unix_mount_new (GVolumeMonitor *volume_monitor,
mount->volume_monitor = volume_monitor != NULL ? g_object_ref (volume_monitor) : NULL;
mount->device_path = g_strdup (g_unix_mount_get_device_path (mount_entry));
mount->mount_path = g_strdup (g_unix_mount_get_mount_path (mount_entry));
mount->can_eject = g_unix_mount_guess_can_eject (mount_entry);
mount->name = g_unix_mount_guess_name (mount_entry);
mount->icon = g_unix_mount_guess_icon (mount_entry);
......@@ -167,6 +171,12 @@ g_unix_mount_get_icon (GMount *mount)
return g_object_ref (unix_mount->icon);
}
static char *
g_unix_mount_get_uuid (GMount *mount)
{
return NULL;
}
static char *
g_unix_mount_get_name (GMount *mount)
{
......@@ -210,6 +220,13 @@ g_unix_mount_can_unmount (GMount *mount)
return TRUE;
}
static gboolean
g_unix_mount_can_eject (GMount *mount)
{
GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
return unix_mount->can_eject;
}
typedef struct {
GUnixMount *unix_mount;
......@@ -220,12 +237,12 @@ typedef struct {
GIOChannel *error_channel;
guint error_channel_source_id;
GString *error_string;
} UnmountOp;
} UnmountEjectOp;
static void
unmount_cb (GPid pid, gint status, gpointer user_data)
eject_unmount_cb (GPid pid, gint status, gpointer user_data)
{
UnmountOp *data = user_data;
UnmountEjectOp *data = user_data;
GSimpleAsyncResult *simple;
if (WEXITSTATUS (status) != 0)
......@@ -260,13 +277,13 @@ unmount_cb (GPid pid, gint status, gpointer user_data)
}
static gboolean
unmount_read_error (GIOChannel *channel,
eject_unmount_read_error (GIOChannel *channel,
GIOCondition condition,
gpointer user_data)
{
char *str;
gsize str_len;
UnmountOp *data = user_data;
UnmountEjectOp *data = user_data;
g_io_channel_read_to_end (channel, &str, &str_len, NULL);
g_string_append (data->error_string, str);
......@@ -275,23 +292,18 @@ unmount_read_error (GIOChannel *channel,
}
static void
g_unix_mount_unmount (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
eject_unmount_do (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
char **argv)
{
GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
UnmountOp *data;
UnmountEjectOp *data;
GPid child_pid;
GError *error;
char *argv[] = {"umount", NULL, NULL};
if (unix_mount->mount_path != NULL)
argv[1] = unix_mount->mount_path;
else
argv[1] = unix_mount->device_path;
data = g_new0 (UnmountOp, 1);
data = g_new0 (UnmountEjectOp, 1);
data->unix_mount = unix_mount;
data->callback = callback;
data->user_data = user_data;
......@@ -322,8 +334,25 @@ g_unix_mount_unmount (GMount *mount,
}
data->error_string = g_string_new ("");
data->error_channel = g_io_channel_unix_new (data->error_fd);
data->error_channel_source_id = g_io_add_watch (data->error_channel, G_IO_IN, unmount_read_error, data);
g_child_watch_add (child_pid, unmount_cb, data);
data->error_channel_source_id = g_io_add_watch (data->error_channel, G_IO_IN, eject_unmount_read_error, data);
g_child_watch_add (child_pid, eject_unmount_cb, data);
}
static void
g_unix_mount_unmount (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
char *argv[] = {"umount", NULL, NULL};
if (unix_mount->mount_path != NULL)
argv[1] = unix_mount->mount_path;
else
argv[1] = unix_mount->device_path;
return eject_unmount_do (mount, cancellable, callback, user_data, argv);
}
static gboolean
......@@ -334,15 +363,44 @@ g_unix_mount_unmount_finish (GMount *mount,
return TRUE;
}
static void
g_unix_mount_eject (GMount *mount,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
char *argv[] = {"eject", NULL, NULL};
if (unix_mount->mount_path != NULL)
argv[1] = unix_mount->mount_path;
else
argv[1] = unix_mount->device_path;
return eject_unmount_do (mount, cancellable, callback, user_data, argv);
}
static gboolean
g_unix_mount_eject_finish (GMount *mount,
GAsyncResult *result,
GError **error)
{
return TRUE;
}
static void
g_unix_mount_mount_iface_init (GMountIface *iface)
{
iface->get_root = g_unix_mount_get_root;
iface->get_name = g_unix_mount_get_name;
iface->get_icon = g_unix_mount_get_icon;
iface->get_uuid = g_unix_mount_get_uuid;
iface->get_drive = g_unix_mount_get_drive;
iface->get_volume = g_unix_mount_get_volume;
iface->can_unmount = g_unix_mount_can_unmount;
iface->can_eject = g_unix_mount_can_eject;
iface->unmount = g_unix_mount_unmount;
iface->unmount_finish = g_unix_mount_unmount_finish;
iface->eject = g_unix_mount_eject;
iface->eject_finish = g_unix_mount_eject_finish;
}
......@@ -1807,6 +1807,32 @@ g_unix_mount_point_guess_icon (GUnixMountPoint *mount_point)
return g_themed_icon_new (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE));
}
gboolean
g_unix_mount_guess_can_eject (GUnixMountEntry *mount_entry)
{
GUnixMountType guessed_type;