diff options
author | David Zeuthen <davidz@redhat.com> | 2007-12-17 09:31:08 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2007-12-17 09:31:08 +0000 |
commit | f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8 (patch) | |
tree | 7b3dd83e827af09ff5750c0d90ac540cf9dd487c /gio/gunixmount.c | |
parent | 96a0e238e5f8854ff0f4207e51bc0beed52d6c2f (diff) | |
download | glib-f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8.tar.gz |
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
Diffstat (limited to 'gio/gunixmount.c')
-rw-r--r-- | gio/gunixmount.c | 102 |
1 files changed, 80 insertions, 22 deletions
diff --git a/gio/gunixmount.c b/gio/gunixmount.c index 6246357a5..6061f8263 100644 --- a/gio/gunixmount.c +++ b/gio/gunixmount.c @@ -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); @@ -168,6 +172,12 @@ g_unix_mount_get_icon (GMount *mount) } static char * +g_unix_mount_get_uuid (GMount *mount) +{ + return NULL; +} + +static char * g_unix_mount_get_name (GMount *mount) { GUnixMount *unix_mount = G_UNIX_MOUNT (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 @@ -335,14 +364,43 @@ g_unix_mount_unmount_finish (GMount *mount, } 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; } |