Blame gio/gvolume.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 * 
Packit ae235b
 * Copyright (C) 2006-2007 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Alexander Larsson <alexl@redhat.com>
Packit ae235b
 *         David Zeuthen <davidz@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
#include "gmount.h"
Packit ae235b
#include "gvolume.h"
Packit ae235b
#include "gthemedicon.h"
Packit ae235b
#include "gasyncresult.h"
Packit ae235b
#include "gtask.h"
Packit ae235b
#include "gioerror.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gvolume
Packit ae235b
 * @short_description: Volume management
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 * 
Packit ae235b
 * The #GVolume interface represents user-visible objects that can be
Packit ae235b
 * mounted. Note, when porting from GnomeVFS, #GVolume is the moral
Packit ae235b
 * equivalent of #GnomeVFSDrive.
Packit ae235b
 *
Packit ae235b
 * Mounting a #GVolume instance is an asynchronous operation. For more
Packit ae235b
 * information about asynchronous operations, see #GAsyncResult and
Packit ae235b
 * #GTask. To mount a #GVolume, first call g_volume_mount() with (at
Packit ae235b
 * least) the #GVolume instance, optionally a #GMountOperation object
Packit ae235b
 * and a #GAsyncReadyCallback.
Packit ae235b
 *
Packit ae235b
 * Typically, one will only want to pass %NULL for the
Packit ae235b
 * #GMountOperation if automounting all volumes when a desktop session
Packit ae235b
 * starts since it's not desirable to put up a lot of dialogs asking
Packit ae235b
 * for credentials.
Packit ae235b
 *
Packit ae235b
 * The callback will be fired when the operation has resolved (either
Packit ae235b
 * with success or failure), and a #GAsyncReady structure will be
Packit ae235b
 * passed to the callback.  That callback should then call
Packit ae235b
 * g_volume_mount_finish() with the #GVolume instance and the
Packit ae235b
 * #GAsyncReady data to see if the operation was completed
Packit ae235b
 * successfully.  If an @error is present when g_volume_mount_finish()
Packit ae235b
 * is called, then it will be filled with any error information.
Packit ae235b
 *
Packit ae235b
 * ## Volume Identifiers # {#volume-identifier}
Packit ae235b
 *
Packit ae235b
 * It is sometimes necessary to directly access the underlying
Packit ae235b
 * operating system object behind a volume (e.g. for passing a volume
Packit ae235b
 * to an application via the commandline). For this purpose, GIO
Packit ae235b
 * allows to obtain an 'identifier' for the volume. There can be
Packit ae235b
 * different kinds of identifiers, such as Hal UDIs, filesystem labels,
Packit ae235b
 * traditional Unix devices (e.g. `/dev/sda2`), UUIDs. GIO uses predefined
Packit ae235b
 * strings as names for the different kinds of identifiers:
Packit ae235b
 * #G_VOLUME_IDENTIFIER_KIND_HAL_UDI, #G_VOLUME_IDENTIFIER_KIND_LABEL, etc.
Packit ae235b
 * Use g_volume_get_identifier() to obtain an identifier for a volume.
Packit ae235b
 *
Packit ae235b
 *
Packit ae235b
 * Note that #G_VOLUME_IDENTIFIER_KIND_HAL_UDI will only be available
Packit ae235b
 * when the gvfs hal volume monitor is in use. Other volume monitors
Packit ae235b
 * will generally be able to provide the #G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE
Packit ae235b
 * identifier, which can be used to obtain a hal device by means of
Packit ae235b
 * libhal_manager_find_device_string_match().
Packit ae235b
 */
Packit ae235b
Packit ae235b
typedef GVolumeIface GVolumeInterface;
Packit ae235b
G_DEFINE_INTERFACE(GVolume, g_volume, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_volume_default_init (GVolumeInterface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GVolume::changed:
Packit ae235b
   * 
Packit ae235b
   * Emitted when the volume has been changed.
Packit ae235b
   */
Packit ae235b
  g_signal_new (I_("changed"),
Packit ae235b
		G_TYPE_VOLUME,
Packit ae235b
		G_SIGNAL_RUN_LAST,
Packit ae235b
		G_STRUCT_OFFSET (GVolumeIface, changed),
Packit ae235b
		NULL, NULL,
Packit ae235b
		g_cclosure_marshal_VOID__VOID,
Packit ae235b
		G_TYPE_NONE, 0);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GVolume::removed:
Packit ae235b
   * 
Packit ae235b
   * This signal is emitted when the #GVolume have been removed. If
Packit ae235b
   * the recipient is holding references to the object they should
Packit ae235b
   * release them so the object can be finalized.
Packit ae235b
   */
Packit ae235b
  g_signal_new (I_("removed"),
Packit ae235b
		G_TYPE_VOLUME,
Packit ae235b
		G_SIGNAL_RUN_LAST,
Packit ae235b
		G_STRUCT_OFFSET (GVolumeIface, removed),
Packit ae235b
		NULL, NULL,
Packit ae235b
		g_cclosure_marshal_VOID__VOID,
Packit ae235b
		G_TYPE_NONE, 0);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_name:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Gets the name of @volume.
Packit ae235b
 * 
Packit ae235b
 * Returns: the name for the given @volume. The returned string should 
Packit ae235b
 *     be freed with g_free() when no longer needed.
Packit ae235b
 */
Packit ae235b
char *
Packit ae235b
g_volume_get_name (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  return (* iface->get_name) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_icon:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Gets the icon for @volume.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GIcon.
Packit ae235b
 *     The returned object should be unreffed with g_object_unref()
Packit ae235b
 *     when no longer needed.
Packit ae235b
 */
Packit ae235b
GIcon *
Packit ae235b
g_volume_get_icon (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  return (* iface->get_icon) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_symbolic_icon:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Gets the symbolic icon for @volume.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GIcon.
Packit ae235b
 *     The returned object should be unreffed with g_object_unref()
Packit ae235b
 *     when no longer needed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.34
Packit ae235b
 */
Packit ae235b
GIcon *
Packit ae235b
g_volume_get_symbolic_icon (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
  GIcon *ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->get_symbolic_icon != NULL)
Packit ae235b
    ret = iface->get_symbolic_icon (volume);
Packit ae235b
  else
Packit ae235b
    ret = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic");
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_uuid:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Gets the UUID for the @volume. The reference is typically based on
Packit ae235b
 * the file system UUID for the volume in question and should be
Packit ae235b
 * considered an opaque string. Returns %NULL if there is no UUID
Packit ae235b
 * available.
Packit ae235b
 * 
Packit ae235b
 * Returns: the UUID for @volume or %NULL if no UUID can be computed.
Packit ae235b
 *     The returned string should be freed with g_free() 
Packit ae235b
 *     when no longer needed.
Packit ae235b
 */
Packit ae235b
char *
Packit ae235b
g_volume_get_uuid (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  return (* iface->get_uuid) (volume);
Packit ae235b
}
Packit ae235b
  
Packit ae235b
/**
Packit ae235b
 * g_volume_get_drive:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Gets the drive for the @volume.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GDrive or %NULL if @volume is not
Packit ae235b
 *     associated with a drive. The returned object should be unreffed
Packit ae235b
 *     with g_object_unref() when no longer needed.
Packit ae235b
 */
Packit ae235b
GDrive *
Packit ae235b
g_volume_get_drive (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  return (* iface->get_drive) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_mount:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Gets the mount for the @volume.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GMount or %NULL if @volume isn't mounted.
Packit ae235b
 *     The returned object should be unreffed with g_object_unref()
Packit ae235b
 *     when no longer needed.
Packit ae235b
 */
Packit ae235b
GMount *
Packit ae235b
g_volume_get_mount (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  return (* iface->get_mount) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_can_mount:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Checks if a volume can be mounted.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @volume can be mounted. %FALSE otherwise
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_volume_can_mount (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->can_mount == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->can_mount) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_can_eject:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Checks if a volume can be ejected.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @volume can be ejected. %FALSE otherwise
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_volume_can_eject (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->can_eject == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->can_eject) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_should_automount:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 *
Packit ae235b
 * Returns whether the volume should be automatically mounted.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the volume should be automatically mounted
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_volume_should_automount (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->should_automount == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->should_automount) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_mount:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * @flags: flags affecting the operation
Packit ae235b
 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid user interaction
Packit ae235b
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
Packit ae235b
 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL
Packit ae235b
 * @user_data: user data that gets passed to @callback
Packit ae235b
 * 
Packit ae235b
 * Mounts a volume. This is an asynchronous operation, and is
Packit ae235b
 * finished by calling g_volume_mount_finish() with the @volume
Packit ae235b
 * and #GAsyncResult returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Virtual: mount_fn
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_volume_mount (GVolume             *volume,
Packit ae235b
		GMountMountFlags     flags,
Packit ae235b
                GMountOperation     *mount_operation,
Packit ae235b
                GCancellable        *cancellable,
Packit ae235b
                GAsyncReadyCallback  callback,
Packit ae235b
                gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_VOLUME (volume));
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->mount_fn == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (volume, callback, user_data,
Packit ae235b
                               g_volume_mount,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               _("volume doesn’t implement mount"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->mount_fn) (volume, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_mount_finish:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * @result: a #GAsyncResult
Packit ae235b
 * @error: a #GError location to store an error, or %NULL to ignore
Packit ae235b
 * 
Packit ae235b
 * Finishes mounting a volume. If any errors occurred during the operation,
Packit ae235b
 * @error will be set to contain the errors and %FALSE will be returned.
Packit ae235b
 *
Packit ae235b
 * If the mount operation succeeded, g_volume_get_mount() on @volume
Packit ae235b
 * is guaranteed to return the mount right after calling this
Packit ae235b
 * function; there's no need to listen for the 'mount-added' signal on
Packit ae235b
 * #GVolumeMonitor.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE, %FALSE if operation failed
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_volume_mount_finish (GVolume       *volume,
Packit ae235b
                       GAsyncResult  *result,
Packit ae235b
                       GError       **error)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
Packit ae235b
Packit ae235b
  if (g_async_result_legacy_propagate_error (result, error))
Packit ae235b
    return FALSE;
Packit ae235b
  else if (g_async_result_is_tagged (result, g_volume_mount))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
  
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
  return (* iface->mount_finish) (volume, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_eject:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * @flags: flags affecting the unmount if required for eject
Packit ae235b
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
Packit ae235b
 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL
Packit ae235b
 * @user_data: user data that gets passed to @callback
Packit ae235b
 * 
Packit ae235b
 * Ejects a volume. This is an asynchronous operation, and is
Packit ae235b
 * finished by calling g_volume_eject_finish() with the @volume
Packit ae235b
 * and #GAsyncResult returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_volume_eject_with_operation() instead.
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_volume_eject (GVolume             *volume,
Packit ae235b
		GMountUnmountFlags   flags,
Packit ae235b
                GCancellable        *cancellable,
Packit ae235b
                GAsyncReadyCallback  callback,
Packit ae235b
                gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_VOLUME (volume));
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->eject == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (volume, callback, user_data,
Packit ae235b
                               g_volume_eject_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               _("volume doesn’t implement eject"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->eject) (volume, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_eject_finish:
Packit ae235b
 * @volume: pointer to a #GVolume
Packit ae235b
 * @result: a #GAsyncResult
Packit ae235b
 * @error: a #GError location to store an error, or %NULL to ignore
Packit ae235b
 * 
Packit ae235b
 * Finishes ejecting a volume. If any errors occurred during the operation,
Packit ae235b
 * @error will be set to contain the errors and %FALSE will be returned.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE, %FALSE if operation failed
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_volume_eject_with_operation_finish() instead.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_volume_eject_finish (GVolume       *volume,
Packit ae235b
                       GAsyncResult  *result,
Packit ae235b
                       GError       **error)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
Packit ae235b
Packit ae235b
  if (g_async_result_legacy_propagate_error (result, error))
Packit ae235b
    return FALSE;
Packit ae235b
  if (g_async_result_is_tagged (result, g_volume_eject_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
  
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
  return (* iface->eject_finish) (volume, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_eject_with_operation:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * @flags: flags affecting the unmount if required for eject
Packit ae235b
 * @mount_operation: (nullable): a #GMountOperation or %NULL to
Packit ae235b
 *     avoid user interaction
Packit ae235b
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
Packit ae235b
 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL
Packit ae235b
 * @user_data: user data passed to @callback
Packit ae235b
 *
Packit ae235b
 * Ejects a volume. This is an asynchronous operation, and is
Packit ae235b
 * finished by calling g_volume_eject_with_operation_finish() with the @volume
Packit ae235b
 * and #GAsyncResult data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_volume_eject_with_operation (GVolume              *volume,
Packit ae235b
                               GMountUnmountFlags   flags,
Packit ae235b
                               GMountOperation     *mount_operation,
Packit ae235b
                               GCancellable        *cancellable,
Packit ae235b
                               GAsyncReadyCallback  callback,
Packit ae235b
                               gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_VOLUME (volume));
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->eject == NULL && iface->eject_with_operation == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (volume, callback, user_data,
Packit ae235b
                               g_volume_eject_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for volume objects that
Packit ae235b
                                * don't implement any of eject or eject_with_operation. */
Packit ae235b
                               _("volume doesn’t implement eject or eject_with_operation"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (iface->eject_with_operation != NULL)
Packit ae235b
    (* iface->eject_with_operation) (volume, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
  else
Packit ae235b
    (* iface->eject) (volume, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_eject_with_operation_finish:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * @result: a #GAsyncResult
Packit ae235b
 * @error: a #GError location to store the error occurring, or %NULL
Packit ae235b
 *
Packit ae235b
 * Finishes ejecting a volume. If any errors occurred during the operation,
Packit ae235b
 * @error will be set to contain the errors and %FALSE will be returned.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the volume was successfully ejected. %FALSE otherwise
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_volume_eject_with_operation_finish (GVolume        *volume,
Packit ae235b
                                      GAsyncResult  *result,
Packit ae235b
                                      GError       **error)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
Packit ae235b
Packit ae235b
  if (g_async_result_legacy_propagate_error (result, error))
Packit ae235b
    return FALSE;
Packit ae235b
  else if (g_async_result_is_tagged (result, g_volume_eject_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
  if (iface->eject_with_operation_finish != NULL)
Packit ae235b
    return (* iface->eject_with_operation_finish) (volume, result, error);
Packit ae235b
  else
Packit ae235b
    return (* iface->eject_finish) (volume, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_identifier:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * @kind: the kind of identifier to return
Packit ae235b
 *
Packit ae235b
 * Gets the identifier of the given kind for @volume. 
Packit ae235b
 * See the [introduction][volume-identifier] for more
Packit ae235b
 * information about volume identifiers.
Packit ae235b
 *
Packit ae235b
 * Returns: a newly allocated string containing the
Packit ae235b
 *     requested identfier, or %NULL if the #GVolume
Packit ae235b
 *     doesn't have this kind of identifier
Packit ae235b
 */
Packit ae235b
char *
Packit ae235b
g_volume_get_identifier (GVolume    *volume,
Packit ae235b
			 const char *kind)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
  g_return_val_if_fail (kind != NULL, NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->get_identifier == NULL)
Packit ae235b
    return NULL;
Packit ae235b
  
Packit ae235b
  return (* iface->get_identifier) (volume, kind);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_enumerate_identifiers:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 * 
Packit ae235b
 * Gets the kinds of [identifiers][volume-identifier] that @volume has.
Packit ae235b
 * Use g_volume_get_identifier() to obtain the identifiers themselves.
Packit ae235b
 *
Packit ae235b
 * Returns: (array zero-terminated=1) (transfer full): a %NULL-terminated array
Packit ae235b
 *   of strings containing kinds of identifiers. Use g_strfreev() to free.
Packit ae235b
 */
Packit ae235b
char **
Packit ae235b
g_volume_enumerate_identifiers (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->enumerate_identifiers == NULL)
Packit ae235b
    return NULL;
Packit ae235b
  
Packit ae235b
  return (* iface->enumerate_identifiers) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_activation_root:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 *
Packit ae235b
 * Gets the activation root for a #GVolume if it is known ahead of
Packit ae235b
 * mount time. Returns %NULL otherwise. If not %NULL and if @volume
Packit ae235b
 * is mounted, then the result of g_mount_get_root() on the
Packit ae235b
 * #GMount object obtained from g_volume_get_mount() will always
Packit ae235b
 * either be equal or a prefix of what this function returns. In
Packit ae235b
 * other words, in code
Packit ae235b
 *
Packit ae235b
 * |[
Packit ae235b
 *   GMount *mount;
Packit ae235b
 *   GFile *mount_root
Packit ae235b
 *   GFile *volume_activation_root;
Packit ae235b
 *
Packit ae235b
 *   mount = g_volume_get_mount (volume); // mounted, so never NULL
Packit ae235b
 *   mount_root = g_mount_get_root (mount);
Packit ae235b
 *   volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL
Packit ae235b
 * ]|
Packit ae235b
 * then the expression
Packit ae235b
 * |[
Packit ae235b
 *   (g_file_has_prefix (volume_activation_root, mount_root) ||
Packit ae235b
 *    g_file_equal (volume_activation_root, mount_root))
Packit ae235b
 * ]|
Packit ae235b
 * will always be %TRUE.
Packit ae235b
 *
Packit ae235b
 * Activation roots are typically used in #GVolumeMonitor
Packit ae235b
 * implementations to find the underlying mount to shadow, see
Packit ae235b
 * g_mount_is_shadowed() for more details.
Packit ae235b
 *
Packit ae235b
 * Returns: (nullable) (transfer full): the activation root of @volume
Packit ae235b
 *     or %NULL. Use g_object_unref() to free.
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 */
Packit ae235b
GFile *
Packit ae235b
g_volume_get_activation_root (GVolume *volume)
Packit ae235b
{
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
Packit ae235b
  if (iface->get_activation_root == NULL)
Packit ae235b
    return NULL;
Packit ae235b
Packit ae235b
  return (* iface->get_activation_root) (volume);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_volume_get_sort_key:
Packit ae235b
 * @volume: a #GVolume
Packit ae235b
 *
Packit ae235b
 * Gets the sort key for @volume, if any.
Packit ae235b
 *
Packit ae235b
 * Returns: Sorting key for @volume or %NULL if no such key is available
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_volume_get_sort_key (GVolume *volume)
Packit ae235b
{
Packit ae235b
  const gchar *ret = NULL;
Packit ae235b
  GVolumeIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
Packit ae235b
Packit ae235b
  iface = G_VOLUME_GET_IFACE (volume);
Packit ae235b
  if (iface->get_sort_key != NULL)
Packit ae235b
    ret = iface->get_sort_key (volume);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}