Esempio n. 1
0
static void
unmount (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_unmount_with_operation (mount, flags, mount_op, NULL, unmount_done_cb, g_object_ref (file));
  g_object_unref (mount_op);

  outstanding_mounts++;
}
static void
xfdesktop_volume_icon_menu_unmount(GtkWidget *widget, gpointer user_data)
{
    XfdesktopVolumeIcon *icon = XFDESKTOP_VOLUME_ICON(user_data);
    GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon));
    GtkWidget *toplevel = gtk_widget_get_toplevel(icon_view);
    GVolume *volume;
    GMount *mount;
    GMountOperation *operation;

    volume = xfdesktop_volume_icon_peek_volume(icon);
    mount = g_volume_get_mount(volume);

    if(!mount)
        return;

#ifdef HAVE_LIBNOTIFY
    xfdesktop_notify_unmount(mount);
#endif

    operation = gtk_mount_operation_new(toplevel ? GTK_WINDOW(toplevel) : NULL);
    gtk_mount_operation_set_screen(GTK_MOUNT_OPERATION(operation),
                                   icon->priv->gscreen);

    g_mount_unmount_with_operation(mount,
                                   G_MOUNT_UNMOUNT_NONE,
                                   operation,
                                   NULL,
                                   xfdesktop_volume_icon_unmount_finish,
                                   g_object_ref(icon));

    g_object_unref(mount);
    g_object_unref(operation);
}
Esempio n. 3
0
static gboolean
ensure_loaded (RBMtpSource *source)
{
	RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (source);
#if defined(HAVE_GUDEV)
	GMount *mount;
#endif
	if (priv->tried_open) {
		RBSourceLoadStatus status;
		g_object_get (source, "load-status", &status, NULL);
		return (status == RB_SOURCE_LOAD_STATUS_LOADED);
	}
	priv->tried_open = TRUE;

	/* try to open the device.  if gvfs has mounted it, unmount it first */
#if defined(HAVE_GUDEV)
	mount = find_mount_for_device (priv->udev_device);
	if (mount != NULL) {
		rb_debug ("device is already mounted, waiting until activated");
		g_mount_unmount_with_operation (mount,
						G_MOUNT_UNMOUNT_NONE,
						NULL,
						NULL,
						unmount_done_cb,
						g_object_ref (source));
		/* mount gets unreffed in callback */
	} else {
		rb_debug ("device isn't mounted");
		open_device (source);
	}
#else
	open_device (source);
#endif
	return FALSE;
}
Esempio n. 4
0
static void unmount_before_eject(EjectData* data)
{
    GMount* mnt = G_MOUNT(data->mounts->data);
    data->mounts = g_list_delete_link(data->mounts, data->mounts);
    /* pop the first GMount in the list. */
    g_mount_unmount_with_operation(mnt, data->flags, data->op,
                                 data->cancellable,
                                 on_unmounted, data);
    /* FIXME: Notify volume monitor!! */
    g_object_unref(mnt);
}
Esempio n. 5
0
static void unmountVolume (ASVolume *v)
{
	SHOW_CHECKPOINT;
	if (ASVolume_isVolume (v) 
	    && !ASVolume_isRequestPending(v)
			&& ASVolume_isMounted(v)){
		GMount *mount = g_volume_get_mount (v->gVolume);
		LOCAL_DEBUG_OUT ("Unmounting volume %s", v == NULL ? "(none)": v->name);
		if (mount) {
			set_flags (v->flags, ASVolume_UnmountRequested);
			ASVolume_refreshDisplay (v);
			g_mount_unmount_with_operation (mount, G_MOUNT_UNMOUNT_NONE, NULL, NULL, unmountVolumeAsyncCallback, v->gVolume);
  	  /* g_object_unref (mount) will be called in AsyncResult function above */
		}
	}		
}
Esempio n. 6
0
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);
  }
}
Esempio n. 7
0
static void
unmount (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_unmount_with_operation (mount, 0, mount_op, NULL, unmount_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);
}
int
main (int argc, char *argv[])
{
        int ret;
        GError *error;
        MduPool *pool;
        MduDevice *device;
        MduDevice *device_to_unmount;
        MduDevice *device_to_mount;
        MduPresentable *volume;
        gchar *volume_name;
        gchar *confirmation_secondary;
        GtkWidget *dialog;
        gint response;
        gchar *fs_type;
        gchar *fs_label;
        gboolean encrypt;
        gchar *passphrase;
        gboolean save_passphrase_in_keyring;
        gboolean save_passphrase_in_keyring_session;
        GMainLoop *loop;
        GVolumeMonitor *gvolume_monitor;
        GList *l;
        GList *gvolumes;
        GVolume *gvolume;
        GMount *gmount;
        gboolean take_ownership;
        FormatData *format_data;
        MduPresentable *toplevel;
        gchar *drive_name;
        gchar *format_desc;
        gchar *formatting_desc;
        gchar *size_str;
        gint grace_timeout_id;

        ret = 1;
        pool = NULL;
        device = NULL;
        device_to_unmount = NULL;
        device_to_mount = NULL;
        volume = NULL;
        volume_name = NULL;
        confirmation_secondary = NULL;
        dialog = NULL;
        fs_type = NULL;
        fs_label = NULL;
        passphrase = NULL;
        loop = NULL;
        volume = NULL;
        gmount = NULL;
        gvolume_monitor = NULL;
        gvolumes = NULL;
        gvolume = NULL;
        gmount = NULL;
        format_data = NULL;
        toplevel = NULL;
        drive_name = NULL;
        format_desc = NULL;
        formatting_desc = NULL;
        size_str = NULL;

#if !GLIB_CHECK_VERSION (2, 32, 0)
        g_thread_init (NULL);
#endif

        /* Initialize gettext support */
        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

        /*  Initialize gtk  */
        error = NULL;
        if (! gtk_init_with_args (&argc, &argv, NULL, entries, GETTEXT_PACKAGE, &error)) {
                g_printerr ("Could not parse arguments: %s\n", error->message);
                g_error_free (error);
                goto out;
        }

        loop = g_main_loop_new (NULL, FALSE);

        g_set_prgname ("mdu-format-tool");
        g_set_application_name (_("Mate Disk Utility formatting tool"));

        if (device_file == NULL) {
                g_printerr ("Incorrect usage. Try --help.\n");
                goto out;
        }

        pool = mdu_pool_new ();
        if (pool == NULL) {
                g_warning ("Unable to get device pool");
                goto out;
        }

        device = mdu_pool_get_by_device_file (pool, device_file);
        if (device == NULL) {
                g_printerr ("No device for %s\n", device_file);
                goto out;
        }

        /* if the user specified a luks device, find the slave backing device */
        if (mdu_device_is_luks_cleartext (device)) {
                const gchar *slave;
                slave = mdu_device_luks_cleartext_get_slave (device);
                g_object_ref (device);
                device = mdu_pool_get_by_object_path (pool, slave);
                /* don't support LUKS in LUKS... */
                g_assert (!mdu_device_is_luks_cleartext (device));
        }

        volume = mdu_pool_get_volume_by_device (pool, device);
        if (volume == NULL) {
                g_printerr ("%s is not a volume\n", device_file);
                goto out;
        }
        volume_name = mdu_presentable_get_name (volume);

        toplevel = mdu_presentable_get_toplevel (MDU_PRESENTABLE (volume));
        if (toplevel != NULL && MDU_IS_DRIVE (toplevel)) {
                drive_name = mdu_presentable_get_name (toplevel);
        }
        size_str = mdu_util_get_size_for_display (mdu_device_get_size (device),
                                                  FALSE,
                                                  FALSE);

        if (drive_name != NULL) {
                if (mdu_device_is_partition (device)) {
                        /* Translators: First argument is the partition number, second argument is the drive name,
                         * third argument is the size (e.g. 10 GB)
                         */
                        format_desc = g_strdup_printf (_("Format partition %d of %s (%s)"),
                                                       mdu_device_partition_get_number (device),
                                                       drive_name,
                                                       size_str);
                        /* Translators: First argument is the partition number, second argument is the drive name,
                         * third argument is the size (e.g. 10 GB)
                         */
                        formatting_desc = g_strdup_printf (_("Formatting partition %d of %s (%s)"),
                                                           mdu_device_partition_get_number (device),
                                                           drive_name,
                                                           size_str);
                } else {
                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
                        format_desc = g_strdup_printf (_("Format %s (%s)"),
                                                       drive_name,
                                                       size_str);
                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
                        formatting_desc = g_strdup_printf (_("Formatting %s (%s)"),
                                                           drive_name,
                                                           size_str);
                }
        } else {
                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
                format_desc = g_strdup_printf (_("Format %s Volume (%s)"),
                                               size_str,
                                               mdu_device_get_device_file (device));
                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
                formatting_desc = g_strdup_printf (_("Formatting %s Volume (%s)"),
                                                   size_str,
                                                   mdu_device_get_device_file (device));
        }

        dialog = mdu_format_dialog_new (NULL, /* no parent window */
                                        volume,
                                        MDU_FORMAT_DIALOG_FLAGS_SIMPLE |
                                        MDU_FORMAT_DIALOG_FLAGS_DISK_UTILITY_BUTTON);
        gtk_window_set_title (GTK_WINDOW (dialog), format_desc);
        gtk_window_set_icon_name (GTK_WINDOW (dialog), "caja-mdu");
        gtk_widget_show_all (dialog);

        response = gtk_dialog_run (GTK_DIALOG (dialog));

        switch (response) {
        case GTK_RESPONSE_OK:
                break;

        case GTK_RESPONSE_ACCEPT:
                gtk_widget_destroy (dialog);
                dialog = NULL;
                launch_mate_disk (device_file);
                goto out;

        default: /* explicit fallthrough */
        case GTK_RESPONSE_CANCEL:
                goto out;
        }

        fs_type = mdu_format_dialog_get_fs_type (MDU_FORMAT_DIALOG (dialog));
        fs_label = mdu_format_dialog_get_fs_label (MDU_FORMAT_DIALOG (dialog));
        encrypt = mdu_format_dialog_get_encrypt (MDU_FORMAT_DIALOG (dialog));
        gtk_widget_destroy (dialog);
        dialog = NULL;

        /* Ask for passphrase if needed */
        passphrase = NULL;
        save_passphrase_in_keyring = FALSE;
        save_passphrase_in_keyring_session = FALSE;
        if (encrypt) {
                passphrase = mdu_util_dialog_ask_for_new_secret (NULL,
                                                                 &save_passphrase_in_keyring,
                                                                 &save_passphrase_in_keyring_session);
                if (passphrase == NULL)
                        goto out;
        }

        take_ownership = (g_strcmp0 (fs_type, "vfat") != 0);

        format_data = g_new0 (FormatData, 1);
        format_data->loop = loop;
        format_data->error = NULL;

        dialog = mdu_format_progress_dialog_new (NULL,
                                                 device,
                                                 _("Preparing..."));
        gtk_window_set_title (GTK_WINDOW (dialog), formatting_desc);
        gtk_widget_show_all (dialog);
        g_signal_connect (dialog, "response", G_CALLBACK (on_progress_dialog_response), format_data);

        /* first a small 2.5 sec window to allow the user to cancel before initiating */
        grace_timeout_id = g_timeout_add (2500, on_grace_timeout, format_data);
        g_main_loop_run (loop);
        g_source_remove (grace_timeout_id);
        if (format_data->error != NULL &&
            format_data->error->domain == G_IO_ERROR &&
            format_data->error->code == G_IO_ERROR_CANCELLED) {
                /* cancelled already, we are done */
                goto out;
        }

        /* then unmount the mount if needed; we use GIO for this to handle tearing
         * down LUKS; first determine the device to unmount
         */
        if (mdu_device_is_luks (device)) {
                const gchar *holder;
                holder = mdu_device_luks_get_holder (device);
                device_to_unmount = mdu_pool_get_by_object_path (pool, holder);
        } else {
                device_to_unmount = g_object_ref (device);
        }
        g_assert (device_to_unmount != NULL);
        gvolume_monitor = g_volume_monitor_get ();
        gvolumes = g_volume_monitor_get_volumes (gvolume_monitor);
        for (l = gvolumes; l != NULL; l = l->next) {
                GVolume *v = G_VOLUME (l->data);
                if (g_strcmp0 (g_volume_get_identifier (v, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
                               mdu_device_get_device_file (device_to_unmount)) == 0) {
                        gvolume = g_object_ref (v);
                        break;
                }
        }
        if (gvolume != NULL) {
                gmount = g_volume_get_mount (gvolume);
                if (gmount != NULL) {
                        GMountOperation *mount_op;

                        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                                             _("Unmounting..."));

                        mount_op = gtk_mount_operation_new (GTK_WINDOW (dialog));
                        g_mount_unmount_with_operation (gmount,
                                                        G_MOUNT_UNMOUNT_NONE,
                                                        mount_op,
                                                        NULL,
                                                        unmount_cb,
                                                        format_data);
                        g_object_unref (mount_op);
                        g_main_loop_run (format_data->loop);

                        if (format_data->error != NULL) {

                                if (!(format_data->error->domain == G_IO_ERROR &&
                                      format_data->error->code == G_IO_ERROR_FAILED_HANDLED)) {
                                        gchar *primary;

                                        primary = g_strdup_printf (_("Unable to format '%s'"), volume_name);
                                        show_error_dialog (NULL,
                                                           primary,
                                                           format_data->error->message);

                                        g_free (primary);
                                }
                                g_error_free (format_data->error);
                                goto out;
                        }
                }
        }

        /* and now, kick off the operation */
        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                             _("Formatting..."));
        mdu_device_op_filesystem_create (device,
                                         fs_type,
                                         fs_label,
                                         passphrase,
                                         take_ownership,
                                         fs_create_cb,
                                         format_data);
 again:
        g_main_loop_run (loop);
        if (format_data->error != NULL) {
                gtk_widget_destroy (dialog);
                dialog = NULL;

                if (format_data->error->domain == G_IO_ERROR &&
                    format_data->error->code == G_IO_ERROR_CANCELLED) {
                        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                                             _("Cancelling..."));

                        /* cancel the job; no callback since op_filesystem_create will return an error */
                        mdu_device_op_cancel_job (device,
                                                  NULL,
                                                  NULL);
                        goto again;

                } else {
                        show_error_dialog (NULL,
                                           _("Error formatting volume"),
                                           format_data->error->message);
                        g_error_free (format_data->error);
                }
                goto out;
        }

        /* ugh, DeviceKit-disks bug - spin around in the mainloop for some time to ensure we
         * have gotten all changes
         */
        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                             _("Mounting volume..."));
        g_timeout_add (1500, on_hack_timeout, loop);
        g_main_loop_run (loop);

        /* OK, peachy, now mount the volume and open a window */
        if (passphrase != NULL) {
                const gchar *cleartext_objpath;

                g_assert (mdu_device_is_luks (device));
                cleartext_objpath = mdu_device_luks_get_holder (device);
                device_to_mount = mdu_pool_get_by_object_path (pool, cleartext_objpath);
        } else {
                device_to_mount = g_object_ref (device);
        }

        mdu_device_op_filesystem_mount (device_to_mount,
                                        NULL,
                                        fs_mount_cb,
                                        format_data);
        g_main_loop_run (loop);
        gtk_widget_destroy (dialog);
        dialog = NULL;
        if (format_data->error != NULL) {
                show_error_dialog (NULL,
                                   _("Error mounting device"),
                                   format_data->error->message);
                g_error_free (format_data->error);
                goto out;
        }

        /* open file manager */
        launch_file_manager (format_data->mount_point);

        g_free (format_data->mount_point);

        /* save passphrase in keyring if requested */
        if (passphrase != NULL && (save_passphrase_in_keyring || save_passphrase_in_keyring_session)) {
                if (!mdu_util_save_secret (device,
                                           passphrase,
                                           save_passphrase_in_keyring_session)) {
                        show_error_dialog (NULL,
                                           _("Error storing passphrase in keyring"),
                                           "");
                        goto out;
                }
        }

        ret = 0;

 out:
        if (toplevel != NULL)
                g_object_unref (toplevel);
        g_free (drive_name);
        g_free (size_str);
        g_free (format_desc);
        g_free (formatting_desc);
        if (gmount != NULL)
                g_object_unref (gmount);
        if (gvolume != NULL)
                g_object_unref (gvolume);
        g_list_foreach (gvolumes, (GFunc) g_object_unref, NULL);
        if (gvolume_monitor != NULL)
                g_object_unref (gvolume_monitor);
        g_free (confirmation_secondary);
        g_free (volume_name);
        g_free (passphrase);
        g_free (fs_type);
        g_free (fs_label);
        g_free (device_file);
        if (loop != NULL)
                g_main_loop_unref (loop);
        if (dialog != NULL)
                gtk_widget_destroy (dialog);
        if (volume != NULL)
                g_object_unref (volume);
        if (device != NULL)
                g_object_unref (device);
        if (device_to_unmount != NULL)
                g_object_unref (device_to_unmount);
        if (device_to_mount != NULL)
                g_object_unref (device_to_mount);
        if (pool != NULL)
                g_object_unref (pool);
        if (format_data != NULL)
                g_free (format_data);
        return ret;
}
Esempio n. 10
0
static void
rb_mtp_source_constructed (GObject *object)
{
	RBMtpSource *source;
	RBMtpSourcePrivate *priv;
	RBEntryView *tracks;
	RBShell *shell;
	RBShellPlayer *shell_player;
	GObject *player_backend;
	GtkIconTheme *theme;
	GdkPixbuf *pixbuf;
#if defined(HAVE_GUDEV)
	GMount *mount;
#endif
	gint size;

	RB_CHAIN_GOBJECT_METHOD (rb_mtp_source_parent_class, constructed, object);
	source = RB_MTP_SOURCE (object);
	priv = MTP_SOURCE_GET_PRIVATE (source);

	/* try to open the device.  if gvfs has mounted it, unmount it first */
#if defined(HAVE_GUDEV)
	mount = find_mount_for_device (priv->udev_device);
	if (mount != NULL) {
		rb_debug ("device is already mounted, waiting until activated");
		g_mount_unmount_with_operation (mount,
						G_MOUNT_UNMOUNT_NONE,
						NULL,
						NULL,
						unmount_done_cb,
						g_object_ref (source));
		/* mount gets unreffed in callback */
	} else
#endif
	open_device (source);

	tracks = rb_source_get_entry_view (RB_SOURCE (source));
	rb_entry_view_append_column (tracks, RB_ENTRY_VIEW_COL_RATING, FALSE);
	rb_entry_view_append_column (tracks, RB_ENTRY_VIEW_COL_LAST_PLAYED, FALSE);

	/* the source element needs our cooperation */
	g_object_get (source, "shell", &shell, NULL);
	shell_player = RB_SHELL_PLAYER (rb_shell_get_player (shell));
	g_object_get (shell_player, "player", &player_backend, NULL);

	g_signal_connect_object (player_backend,
				 "prepare-source",
				 G_CALLBACK (prepare_player_source_cb),
				 source, 0);

	g_object_unref (player_backend);
	g_object_unref (shell);

	g_signal_connect_object (rb_encoder_factory_get (),
				 "prepare-source",
				 G_CALLBACK (prepare_encoder_source_cb),
				 source, 0);
	g_signal_connect_object (rb_encoder_factory_get (),
				 "prepare-sink",
				 G_CALLBACK (prepare_encoder_sink_cb),
				 source, 0);

	/* icon */
	theme = gtk_icon_theme_get_default ();
	gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &size, NULL);
	pixbuf = gtk_icon_theme_load_icon (theme, "multimedia-player", size, 0, NULL);

	rb_source_set_pixbuf (RB_SOURCE (source), pixbuf);
	g_object_unref (pixbuf);

	if (priv->album_art_supported) {
		RhythmDB *db;

		db = get_db_for_source (source);
		g_signal_connect_object (db, "entry-extra-metadata-notify::rb:coverArt",
					 G_CALLBACK (artwork_notify_cb), source, 0);
		g_object_unref (db);
	}
}
Esempio n. 11
0
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);
	}
}
Esempio n. 12
0
gboolean
brasero_gio_operation_umount (GVolume *gvolume,
			      GCancellable *cancel,
			      gboolean wait,
			      GError **error)
{
	GMount *mount;
	gboolean result;

	BRASERO_MEDIA_LOG ("Unmounting volume");

	if (!gvolume) {
		BRASERO_MEDIA_LOG ("No volume");
		return TRUE;
	}

	mount = g_volume_get_mount (gvolume);
	if (!mount) {
		BRASERO_MEDIA_LOG ("No mount");
		return TRUE;
	}

	if (!g_mount_can_unmount (mount)) {
		/* NOTE: that can happen when for example a blank medium is 
		 * mounted on burn:// */
		BRASERO_MEDIA_LOG ("Mount can't unmount");
		return FALSE;
	}

	if (wait) {
		gulong umount_sig;
		BraseroGioOperation *op;

		op = g_new0 (BraseroGioOperation, 1);
		op->cancel = cancel;

		umount_sig = g_signal_connect_after (mount,
						     "unmounted",
						     G_CALLBACK (brasero_gio_operation_umounted_cb),
						     op);

		/* NOTE: we own a reference to mount
		 * object so no need to ref it even more */
		g_mount_unmount_with_operation (mount,
				 		G_MOUNT_UNMOUNT_NONE,
						NULL,
				 		cancel,
				 		brasero_gio_operation_umount_finish,
				 		op);
		result = brasero_gio_operation_wait_for_operation_end (op, error);
		brasero_gio_operation_destroy (op);
		g_signal_handler_disconnect (mount, umount_sig);
	}
	else {
		g_mount_unmount_with_operation (mount,
				 		G_MOUNT_UNMOUNT_NONE,
						NULL,
				 		cancel,
				 		NULL,					/* callback */
				 		NULL);
		result = TRUE;
	}
	g_object_unref (mount);

	BRASERO_MEDIA_LOG ("Unmount result = %d", result);
	return result;
}
Esempio n. 13
0
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);
}