/** 
 * gnome_vfs_volume_unmount:
 * @volume: the #GnomeVFSVolume that should be unmounted.
 * @callback: the #GnomeVFSVolumeOpCallback that should be invoked after unmounting @volume.
 * @user_data: the user data to pass to @callback.
 *
 * Note that gnome_vfs_volume_unmount() may also invoke gnome_vfs_volume_eject(),
 * if the @volume signals that it should be ejected when it is unmounted.
 * This may be true for CD-ROMs, USB sticks and other devices, depending on the
 * backend providing the @volume.
 *
 * Since: 2.6
 */
void
gnome_vfs_volume_unmount (GnomeVFSVolume *volume,
			  GnomeVFSVolumeOpCallback  callback,
			  gpointer                   user_data)
{
	char *mount_path, *device_path;
	char *uri;
	GnomeVFSVolumeType type;

	if (volume->priv->drive != NULL) {
		if (volume->priv->drive->priv->must_eject_at_unmount) {
			gnome_vfs_volume_eject (volume, callback, user_data);
			return;
		}
	}

	emit_pre_unmount (volume);

	type = gnome_vfs_volume_get_volume_type (volume);
	if (type == GNOME_VFS_VOLUME_TYPE_MOUNTPOINT) {
		char *hal_udi;

		uri = gnome_vfs_volume_get_activation_uri (volume);
		mount_path = gnome_vfs_get_local_path_from_uri (uri);
		g_free (uri);
		device_path = gnome_vfs_volume_get_device_path (volume);
		hal_udi = gnome_vfs_volume_get_hal_udi (volume);

		/* Volumes from drives that are not polled may not
		 * have a hal_udi.. take the one from HAL to get
		 * gnome-mount working */
		if (hal_udi == NULL) {
			GnomeVFSDrive *drive;
			drive = gnome_vfs_volume_get_drive (volume);
			if (drive != NULL) {
				hal_udi = gnome_vfs_drive_get_hal_udi (drive);
				gnome_vfs_drive_unref (drive);
			}
		}

		mount_unmount_operation (mount_path,
					 device_path,
					 hal_udi,
					 gnome_vfs_volume_get_device_type (volume),
					 FALSE, TRUE, FALSE,
					 callback, user_data);
		g_free (mount_path);
		g_free (device_path);
		g_free (hal_udi);
	} else if (type == GNOME_VFS_VOLUME_TYPE_VFS_MOUNT) {
		/* left intentionally blank as these cannot be mounted and thus not unmounted */
	} else if (type == GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER) {
		unmount_connected_server (volume, callback, user_data);
	}
}
Example #2
0
void _fillin_connected(GnomeVFSDrive * drive, GSList ** p)
{

  Menu_list_item * item;
  GSList *sublist = *p;
  char * dev_path;

  item = g_malloc(sizeof(Menu_list_item));

  item->item_type = MENU_ITEM_DRIVE;
  item->name = g_strdup(gnome_vfs_drive_get_display_name(drive));
  item->icon = g_strdup(gnome_vfs_drive_get_icon(drive));
  item->drive = drive;
  /* FIXME gnome_vfs_drive_get_mounted_volume is deprecated.*/



  if (gnome_vfs_drive_get_mounted_volume(drive))
  {

    GnomeVFSVolume* volume;
    volume = gnome_vfs_drive_get_mounted_volume(drive);
    item->mount_point = gnome_vfs_volume_get_activation_uri(volume);
    item->drive_prep = NULL;
    gnome_vfs_volume_unref(volume) ;
  }
  else
  {
    item->mount_point = g_strdup("Unmounted");
    item->drive_prep = _mount_connected;
  }

  dev_path = gnome_vfs_drive_get_device_path(drive);

  item->comment = g_strdup_printf("%s\n%s\n%s", item->name, item->mount_point, dev_path) ;
  item->desktop = g_strdup("");
  sublist = g_slist_append(sublist, item);
  g_free(dev_path);

  *p = sublist;
}
/** 
 * gnome_vfs_volume_eject:
 * @volume: the #GnomeVFSVolume that should be ejected.
 * @callback: the #GnomeVFSVolumeOpCallback that should be invoked after ejecting of @volume.
 * @user_data: the user data to pass to @callback.
 *
 * Requests ejection of a #GnomeVFSVolume.
 *
 * Before the unmount operation is executed, the
 * #GnomeVFSVolume::pre-unmount signal is emitted.
 *
 * If the @volume is a mount point (its type is
 * #GNOME_VFS_VOLUME_TYPE_MOUNTPOINT), it is unmounted,
 * and if it refers to a disc, it is also ejected.
 *
 * If the @volume is a special VFS mount, i.e.
 * its type is #GNOME_VFS_VOLUME_TYPE_VFS_MOUNT, it
 * is ejected.
 *
 * If the @volume is a connected server, it
 * is removed from the list of connected servers.
 *
 * Otherwise, no further action is done.
 *
 * Since: 2.6
 */
void
gnome_vfs_volume_eject (GnomeVFSVolume *volume,
			GnomeVFSVolumeOpCallback  callback,
			gpointer                   user_data)
{
	char *mount_path, *device_path;
	char *uri;
	char *hal_udi;
	GnomeVFSVolumeType type;
	
	emit_pre_unmount (volume);

	type = gnome_vfs_volume_get_volume_type (volume);
	if (type == GNOME_VFS_VOLUME_TYPE_MOUNTPOINT) {
		uri = gnome_vfs_volume_get_activation_uri (volume);
		mount_path = gnome_vfs_get_local_path_from_uri (uri);
		g_free (uri);
		device_path = gnome_vfs_volume_get_device_path (volume);
		hal_udi = gnome_vfs_volume_get_hal_udi (volume);

		/* Volumes from drives that are not polled may not
		 * have a hal_udi.. take the one from HAL to get
		 * gnome-mount working */
		if (hal_udi == NULL) {
			GnomeVFSDrive *drive;
			drive = gnome_vfs_volume_get_drive (volume);
			if (drive != NULL) {
				hal_udi = gnome_vfs_drive_get_hal_udi (drive);
				gnome_vfs_drive_unref (drive);
			}
		}

		mount_unmount_operation (mount_path,
					 device_path,
					 hal_udi,
					 gnome_vfs_volume_get_device_type (volume),
					 FALSE, TRUE, TRUE,
					 callback, user_data);
		g_free (mount_path);
		g_free (device_path);
		g_free (hal_udi);
	} else if (type == GNOME_VFS_VOLUME_TYPE_VFS_MOUNT) {
		hal_udi = gnome_vfs_volume_get_hal_udi (volume);
		uri = gnome_vfs_volume_get_activation_uri (volume);
		device_path = gnome_vfs_volume_get_device_path (volume);

		/* special handling for optical disc VFS_MOUNT created by the hal backend */
		if (hal_udi != NULL &&
		    (g_str_has_prefix (uri, "cdda://") || g_str_has_prefix (uri, "burn:///"))) {
			device_path = gnome_vfs_volume_get_device_path (volume);
			mount_unmount_operation (NULL,
						 device_path,
						 hal_udi,
						 gnome_vfs_volume_get_device_type (volume),
						 FALSE, FALSE, TRUE,
						 callback, user_data);
			g_free (device_path);
		    }
		g_free (uri);
		g_free (hal_udi);
	} else if (type == GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER) {
		unmount_connected_server (volume, callback, user_data);
	}
}