static void eject (GFile *file) { GMount *mount; GError *error = NULL; GMountOperation *mount_op; GMountUnmountFlags flags; if (file == NULL) return; mount = g_file_find_enclosing_mount (file, NULL, &error); if (mount == NULL) { print_file_error (file, error->message); success = FALSE; g_error_free (error); return; } mount_op = new_mount_op (); flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE; g_mount_eject_with_operation (mount, flags, mount_op, NULL, eject_done_cb, g_object_ref (file)); g_object_unref (mount_op); outstanding_mounts++; }
void GioLister::UnmountDevice(const QString &id) { QMutexLocker l(&mutex_); if (!devices_.contains(id)) return; const DeviceInfo& info = devices_[id]; if (!info.mount) return; if (info.volume) { if (g_volume_can_eject(info.volume)) { g_volume_eject_with_operation( info.volume, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) VolumeEjectFinished, NULL); g_object_unref(info.volume); return; } } if (g_mount_can_eject(info.mount)) { g_mount_eject_with_operation( info.mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) MountEjectFinished, NULL); } else if (g_mount_can_unmount(info.mount)) { g_mount_unmount_with_operation( info.mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) MountUnmountFinished, NULL); } }
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++; }
static void do_unmount (GMount *mount, gboolean should_eject, GtkWindow *window) { GMountOperation *mount_op; mount_op = gtk_mount_operation_new (window); if (should_eject) { g_mount_eject_with_operation (mount, 0, mount_op, NULL, unmount_mount_callback, (gpointer) 1); } else { g_mount_unmount_with_operation (mount, 0, mount_op, NULL, unmount_mount_callback, (gpointer) 0); } g_object_unref (mount_op); }
static void default_eject (RBDeviceSource *source) { GVolume *volume = NULL; GMount *mount = NULL; if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "volume")) { g_object_get (source, "volume", &volume, NULL); } if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "mount")) { g_object_get (source, "mount", &mount, NULL); } /* try ejecting based on volume first, then based on the mount, * and finally try unmounting. */ if (volume != NULL) { if (g_volume_can_eject (volume)) { rb_debug ("ejecting volume"); g_volume_eject_with_operation (volume, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) eject_cb, NULL); } else { /* this should never happen; the eject command will be * insensitive if the selected source cannot be ejected. */ rb_debug ("don't know what to do with this volume"); } } else if (mount != NULL) { if (g_mount_can_eject (mount)) { rb_debug ("ejecting mount"); g_mount_eject_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) eject_cb, NULL); } else if (g_mount_can_unmount (mount)) { rb_debug ("unmounting mount"); g_mount_unmount_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) unmount_cb, NULL); } else { /* this should never happen; the eject command will be * insensitive if the selected source cannot be ejected. */ rb_debug ("don't know what to do with this mount"); } } if (volume != NULL) { g_object_unref (volume); } if (mount != NULL) { g_object_unref (mount); } }
// -------------------------------------------------------------------------------- // void guGIO_Mount::Unmount( void ) { g_mount_eject_with_operation( m_Mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, GAsyncReadyCallback( Unmounted_Device ), this ); }
static gboolean fm_do_mount(GtkWindow* parent, GObject* obj, MountAction action, gboolean interactive) { gboolean ret; struct MountData* data = g_new0(struct MountData, 1); /* bug #3615234: it seems GtkMountOperations is buggy and sometimes leaves parent window reference intact while destroys itself so it leads to severe memory corruption, therefore we pass here NULL as parent window to gtk_mount_operation_new() to not bind it to anything as a workaround */ GMountOperation* op = interactive ? gtk_mount_operation_new(NULL) : NULL; GCancellable* cancellable = g_cancellable_new(); data->loop = g_main_loop_new (NULL, TRUE); data->action = action; switch(data->action) { case MOUNT_VOLUME: g_volume_mount(G_VOLUME(obj), 0, op, cancellable, on_mount_action_finished, data); break; case MOUNT_GFILE: g_file_mount_enclosing_volume(G_FILE(obj), 0, op, cancellable, on_mount_action_finished, data); break; case UMOUNT_MOUNT: prepare_unmount(G_MOUNT(obj)); g_mount_unmount_with_operation(G_MOUNT(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data); break; case EJECT_MOUNT: prepare_unmount(G_MOUNT(obj)); g_mount_eject_with_operation(G_MOUNT(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data); break; case EJECT_VOLUME: { GMount* mnt = g_volume_get_mount(G_VOLUME(obj)); if (mnt) /* it might be unmounted already */ { prepare_unmount(mnt); g_object_unref(mnt); } g_volume_eject_with_operation(G_VOLUME(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data); } break; } /* FIXME: create progress window with busy cursor */ if (g_main_loop_is_running(data->loop)) { GDK_THREADS_LEAVE(); g_main_loop_run(data->loop); GDK_THREADS_ENTER(); } g_main_loop_unref(data->loop); ret = data->ret; if(data->err) { if(interactive) { if(data->err->domain == G_IO_ERROR) { if(data->err->code == G_IO_ERROR_FAILED) { /* Generate a more human-readable error message instead of using a gvfs one. */ /* The original error message is something like: * Error unmounting: umount exited with exit code 1: * helper failed with: umount: only root can unmount * UUID=18cbf00c-e65f-445a-bccc-11964bdea05d from /media/sda4 */ /* Why they pass this back to us? * This is not human-readable for the users at all. */ if(strstr(data->err->message, "only root can ")) { g_debug("%s", data->err->message); g_free(data->err->message); data->err->message = g_strdup(_("Only system administrators have the permission to do this.")); } } else if(data->err->code == G_IO_ERROR_FAILED_HANDLED) interactive = FALSE; } if(interactive) fm_show_error(parent, NULL, data->err->message); } g_error_free(data->err); } g_free(data); g_object_unref(cancellable); if(op) g_object_unref(op); return ret; }
static void _tile_eject_cb (MpdStorageDeviceTile *tile, MpdDevicesTile *self) { MpdDevicesTilePrivate *priv = GET_PRIVATE (self); char const *uri; GList *mounts; GList *iter; uri = mpd_storage_device_tile_get_mount_point (tile); mounts = g_volume_monitor_get_mounts (priv->monitor); iter = g_list_find_custom (mounts, uri, (GCompareFunc) _find_mount_cb); if (iter) { GMount *mount = G_MOUNT (iter->data); GDrive *drive; GVolume *vol; gboolean ejected = TRUE; drive = g_mount_get_drive (mount); vol = g_mount_get_volume (mount); if (drive && g_drive_can_eject (drive)) { g_debug ("%s() ejecting drive %s", __FUNCTION__, uri); g_drive_eject_with_operation (drive, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback)_drive_eject_cb, tile); } else if (vol && g_volume_can_eject (vol)) { g_debug ("%s() ejecting volume %s", __FUNCTION__, uri); g_volume_eject_with_operation (vol, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback)_vol_eject_cb, tile); } else if (g_mount_can_eject (mount)) { g_debug ("%s() ejecting mount %s", __FUNCTION__, uri); g_mount_eject_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) _mount_eject_cb, tile); } else if (g_mount_can_unmount (mount)) { g_debug ("%s() unmounting mount %s", __FUNCTION__, uri); g_mount_unmount_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, (GAsyncReadyCallback) _mount_unmount_cb, tile); } else { ejected = FALSE; g_warning ("Eject or unmount not possible"); } mx_widget_set_disabled (MX_WIDGET (tile), ejected); /* TODO: inform user of ejection with text inside the tile: * For that (and other reasons) this code really should be inside * MpdStorageDeviceTile */ /* TODO: we want to start a 2s timeout here, and if not done sync'ing when * expired show the message "Ejecting ..." */ if (drive) { g_object_unref (drive); } if (vol) { g_object_unref (vol); } } g_list_foreach (mounts, (GFunc) g_object_unref, NULL); g_list_free (mounts); }