Blame gio/gdrive.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 "gdrive.h"
Packit ae235b
#include "gtask.h"
Packit ae235b
#include "gthemedicon.h"
Packit ae235b
#include "gasyncresult.h"
Packit ae235b
#include "gioerror.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gdrive
Packit ae235b
 * @short_description: Drive management
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * #GDrive - this represent a piece of hardware connected to the machine.
Packit ae235b
 * It's generally only created for removable hardware or hardware with
Packit ae235b
 * removable media.
Packit ae235b
 *
Packit ae235b
 * #GDrive is a container class for #GVolume objects that stem from
Packit ae235b
 * the same piece of media. As such, #GDrive abstracts a drive with
Packit ae235b
 * (or without) removable media and provides operations for querying
Packit ae235b
 * whether media is available, determining whether media change is
Packit ae235b
 * automatically detected and ejecting the media.
Packit ae235b
 *
Packit ae235b
 * If the #GDrive reports that media isn't automatically detected, one
Packit ae235b
 * can poll for media; typically one should not do this periodically
Packit ae235b
 * as a poll for media operation is potententially expensive and may
Packit ae235b
 * spin up the drive creating noise.
Packit ae235b
 *
Packit ae235b
 * #GDrive supports starting and stopping drives with authentication
Packit ae235b
 * support for the former. This can be used to support a diverse set
Packit ae235b
 * of use cases including connecting/disconnecting iSCSI devices,
Packit ae235b
 * powering down external disk enclosures and starting/stopping
Packit ae235b
 * multi-disk devices such as RAID devices. Note that the actual
Packit ae235b
 * semantics and side-effects of starting/stopping a #GDrive may vary
Packit ae235b
 * according to implementation. To choose the correct verbs in e.g. a
Packit ae235b
 * file manager, use g_drive_get_start_stop_type().
Packit ae235b
 *
Packit ae235b
 * For porting from GnomeVFS note that there is no equivalent of
Packit ae235b
 * #GDrive in that API.
Packit ae235b
 **/
Packit ae235b
Packit ae235b
typedef GDriveIface GDriveInterface;
Packit ae235b
G_DEFINE_INTERFACE(GDrive, g_drive, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_drive_default_init (GDriveInterface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GDrive::changed:
Packit ae235b
   * @drive: a #GDrive.
Packit ae235b
   *
Packit ae235b
   * Emitted when the drive's state has changed.
Packit ae235b
   **/
Packit ae235b
  g_signal_new (I_("changed"),
Packit ae235b
		G_TYPE_DRIVE,
Packit ae235b
		G_SIGNAL_RUN_LAST,
Packit ae235b
		G_STRUCT_OFFSET (GDriveIface, changed),
Packit ae235b
		NULL, NULL,
Packit ae235b
		g_cclosure_marshal_VOID__VOID,
Packit ae235b
		G_TYPE_NONE, 0);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDrive::disconnected:
Packit ae235b
   * @drive: a #GDrive.
Packit ae235b
   *
Packit ae235b
   * This signal is emitted when the #GDrive have been
Packit ae235b
   * disconnected. If the recipient is holding references to the
Packit ae235b
   * object they should release them so the object can be
Packit ae235b
   * finalized.
Packit ae235b
   **/
Packit ae235b
  g_signal_new (I_("disconnected"),
Packit ae235b
		G_TYPE_DRIVE,
Packit ae235b
		G_SIGNAL_RUN_LAST,
Packit ae235b
		G_STRUCT_OFFSET (GDriveIface, disconnected),
Packit ae235b
		NULL, NULL,
Packit ae235b
		g_cclosure_marshal_VOID__VOID,
Packit ae235b
		G_TYPE_NONE, 0);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDrive::eject-button:
Packit ae235b
   * @drive: a #GDrive.
Packit ae235b
   *
Packit ae235b
   * Emitted when the physical eject button (if any) of a drive has
Packit ae235b
   * been pressed.
Packit ae235b
   **/
Packit ae235b
  g_signal_new (I_("eject-button"),
Packit ae235b
		G_TYPE_DRIVE,
Packit ae235b
		G_SIGNAL_RUN_LAST,
Packit ae235b
		G_STRUCT_OFFSET (GDriveIface, eject_button),
Packit ae235b
		NULL, NULL,
Packit ae235b
		g_cclosure_marshal_VOID__VOID,
Packit ae235b
		G_TYPE_NONE, 0);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GDrive::stop-button:
Packit ae235b
   * @drive: a #GDrive.
Packit ae235b
   *
Packit ae235b
   * Emitted when the physical stop button (if any) of a drive has
Packit ae235b
   * been pressed.
Packit ae235b
   *
Packit ae235b
   * Since: 2.22
Packit ae235b
   **/
Packit ae235b
  g_signal_new (I_("stop-button"),
Packit ae235b
		G_TYPE_DRIVE,
Packit ae235b
		G_SIGNAL_RUN_LAST,
Packit ae235b
		G_STRUCT_OFFSET (GDriveIface, stop_button),
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_drive_get_name:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Gets the name of @drive.
Packit ae235b
 *
Packit ae235b
 * Returns: a string containing @drive's name. The returned 
Packit ae235b
 *     string should be freed when no longer needed.
Packit ae235b
 **/
Packit ae235b
char *
Packit ae235b
g_drive_get_name (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->get_name) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_get_icon:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Gets the icon for @drive.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): #GIcon for the @drive.
Packit ae235b
 *    Free the returned object with g_object_unref().
Packit ae235b
 **/
Packit ae235b
GIcon *
Packit ae235b
g_drive_get_icon (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->get_icon) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_get_symbolic_icon:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Gets the icon for @drive.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): symbolic #GIcon for the @drive.
Packit ae235b
 *    Free the returned object with g_object_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.34
Packit ae235b
 **/
Packit ae235b
GIcon *
Packit ae235b
g_drive_get_symbolic_icon (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
  GIcon *ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->get_symbolic_icon != NULL)
Packit ae235b
    ret = iface->get_symbolic_icon (drive);
Packit ae235b
  else
Packit ae235b
    ret = g_themed_icon_new_with_default_fallbacks ("drive-removable-media-symbolic");
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_has_volumes:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Check if @drive has any mountable volumes.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @drive contains volumes, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_has_volumes (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->has_volumes) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_get_volumes:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Get a list of mountable volumes for @drive.
Packit ae235b
 *
Packit ae235b
 * The returned list should be freed with g_list_free(), after
Packit ae235b
 * its elements have been unreffed with g_object_unref().
Packit ae235b
 * 
Packit ae235b
 * Returns: (element-type GVolume) (transfer full): #GList containing any #GVolume objects on the given @drive.
Packit ae235b
 **/
Packit ae235b
GList *
Packit ae235b
g_drive_get_volumes (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->get_volumes) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_is_media_check_automatic:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Checks if @drive is capabable of automatically detecting media changes.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @drive is capabable of automatically detecting 
Packit ae235b
 *     media changes, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_is_media_check_automatic (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->is_media_check_automatic) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_is_removable:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 *
Packit ae235b
 * Checks if the #GDrive and/or its media is considered removable by the user.
Packit ae235b
 * See g_drive_is_media_removable().
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @drive and/or its media is considered removable, %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.50
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_is_removable (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
  if (iface->is_removable != NULL)
Packit ae235b
    return iface->is_removable (drive);
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_is_media_removable:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Checks if the @drive supports removable media.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @drive supports removable media, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_is_media_removable (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->is_media_removable) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_has_media:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Checks if the @drive has media. Note that the OS may not be polling
Packit ae235b
 * the drive for media changes; see g_drive_is_media_check_automatic()
Packit ae235b
 * for more details.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @drive has media, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_has_media (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->has_media) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_can_eject:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Checks if a drive can be ejected.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @drive can be ejected, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_can_eject (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->can_eject == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->can_eject) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_can_poll_for_media:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Checks if a drive can be polled for media changes.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @drive can be polled for media changes,
Packit ae235b
 *     %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_can_poll_for_media (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->poll_for_media == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->can_poll_for_media) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_eject:
Packit ae235b
 * @drive: a #GDrive.
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 to pass to @callback
Packit ae235b
 * 
Packit ae235b
 * Asynchronously ejects a drive.
Packit ae235b
 *
Packit ae235b
 * When the operation is finished, @callback will be called.
Packit ae235b
 * You can then call g_drive_eject_finish() to obtain the
Packit ae235b
 * result of the operation.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_drive_eject_with_operation() instead.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_drive_eject (GDrive              *drive,
Packit ae235b
	       GMountUnmountFlags   flags,
Packit ae235b
	       GCancellable        *cancellable,
Packit ae235b
	       GAsyncReadyCallback  callback,
Packit ae235b
	       gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DRIVE (drive));
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->eject == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (drive, callback, user_data,
Packit ae235b
                               g_drive_eject_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               _("drive doesn’t implement eject"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->eject) (drive, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_eject_finish:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @result: a #GAsyncResult.
Packit ae235b
 * @error: a #GError, or %NULL
Packit ae235b
 * 
Packit ae235b
 * Finishes ejecting a drive.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the drive has been ejected successfully,
Packit ae235b
 *     %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_drive_eject_with_operation_finish() instead.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_eject_finish (GDrive        *drive,
Packit ae235b
		      GAsyncResult  *result,
Packit ae235b
		      GError       **error)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), 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_drive_eject_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
  
Packit ae235b
  return (* iface->eject_finish) (drive, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_eject_with_operation:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @flags: flags affecting the unmount if required for eject
Packit ae235b
 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
Packit ae235b
 *     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 drive. This is an asynchronous operation, and is
Packit ae235b
 * finished by calling g_drive_eject_with_operation_finish() with the @drive
Packit ae235b
 * and #GAsyncResult data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_drive_eject_with_operation (GDrive              *drive,
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
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DRIVE (drive));
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->eject == NULL && iface->eject_with_operation == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (drive, callback, user_data,
Packit ae235b
                               g_drive_eject_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for drive objects that
Packit ae235b
                                * don't implement any of eject or eject_with_operation. */
Packit ae235b
                               _("drive 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) (drive, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
  else
Packit ae235b
    (* iface->eject) (drive, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_eject_with_operation_finish:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @result: a #GAsyncResult.
Packit ae235b
 * @error: a #GError location to store the error occurring, or %NULL to
Packit ae235b
 *     ignore.
Packit ae235b
 *
Packit ae235b
 * Finishes ejecting a drive. 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 drive was successfully ejected. %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_eject_with_operation_finish (GDrive        *drive,
Packit ae235b
                                     GAsyncResult  *result,
Packit ae235b
                                     GError       **error)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), 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_drive_eject_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
  if (iface->eject_with_operation_finish != NULL)
Packit ae235b
    return (* iface->eject_with_operation_finish) (drive, result, error);
Packit ae235b
  else
Packit ae235b
    return (* iface->eject_finish) (drive, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_poll_for_media:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
Packit ae235b
 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
Packit ae235b
 * @user_data: user data to pass to @callback
Packit ae235b
 * 
Packit ae235b
 * Asynchronously polls @drive to see if media has been inserted or removed.
Packit ae235b
 * 
Packit ae235b
 * When the operation is finished, @callback will be called.
Packit ae235b
 * You can then call g_drive_poll_for_media_finish() to obtain the
Packit ae235b
 * result of the operation.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_drive_poll_for_media (GDrive              *drive,
Packit ae235b
                        GCancellable        *cancellable,
Packit ae235b
                        GAsyncReadyCallback  callback,
Packit ae235b
                        gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DRIVE (drive));
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->poll_for_media == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (drive, callback, user_data,
Packit ae235b
                               g_drive_poll_for_media,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               _("drive doesn’t implement polling for media"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->poll_for_media) (drive, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_poll_for_media_finish:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @result: a #GAsyncResult.
Packit ae235b
 * @error: a #GError, or %NULL
Packit ae235b
 * 
Packit ae235b
 * Finishes an operation started with g_drive_poll_for_media() on a drive.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the drive has been poll_for_mediaed successfully,
Packit ae235b
 *     %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_drive_poll_for_media_finish (GDrive        *drive,
Packit ae235b
                               GAsyncResult  *result,
Packit ae235b
                               GError       **error)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), 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_drive_poll_for_media))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
  
Packit ae235b
  return (* iface->poll_for_media_finish) (drive, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_get_identifier:
Packit ae235b
 * @drive: a #GDrive
Packit ae235b
 * @kind: the kind of identifier to return
Packit ae235b
 *
Packit ae235b
 * Gets the identifier of the given kind for @drive.
Packit ae235b
 *
Packit ae235b
 * Returns: a newly allocated string containing the
Packit ae235b
 *     requested identfier, or %NULL if the #GDrive
Packit ae235b
 *     doesn't have this kind of identifier.
Packit ae235b
 */
Packit ae235b
char *
Packit ae235b
g_drive_get_identifier (GDrive     *drive,
Packit ae235b
			const char *kind)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
Packit ae235b
  g_return_val_if_fail (kind != NULL, NULL);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->get_identifier == NULL)
Packit ae235b
    return NULL;
Packit ae235b
  
Packit ae235b
  return (* iface->get_identifier) (drive, kind);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_enumerate_identifiers:
Packit ae235b
 * @drive: a #GDrive
Packit ae235b
 *
Packit ae235b
 * Gets the kinds of identifiers that @drive has. 
Packit ae235b
 * Use g_drive_get_identifier() to obtain the identifiers
Packit ae235b
 * themselves.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (array zero-terminated=1): a %NULL-terminated
Packit ae235b
 *     array of strings containing kinds of identifiers. Use g_strfreev()
Packit ae235b
 *     to free.
Packit ae235b
 */
Packit ae235b
char **
Packit ae235b
g_drive_enumerate_identifiers (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->enumerate_identifiers == NULL)
Packit ae235b
    return NULL;
Packit ae235b
  
Packit ae235b
  return (* iface->enumerate_identifiers) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_get_start_stop_type:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 *
Packit ae235b
 * Gets a hint about how a drive can be started/stopped.
Packit ae235b
 *
Packit ae235b
 * Returns: A value from the #GDriveStartStopType enumeration.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
GDriveStartStopType
Packit ae235b
g_drive_get_start_stop_type (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->get_start_stop_type == NULL)
Packit ae235b
    return G_DRIVE_START_STOP_TYPE_UNKNOWN;
Packit ae235b
Packit ae235b
  return (* iface->get_start_stop_type) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_can_start:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 *
Packit ae235b
 * Checks if a drive can be started.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the @drive can be started, %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_drive_can_start (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->can_start == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->can_start) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_can_start_degraded:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 *
Packit ae235b
 * Checks if a drive can be started degraded.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the @drive can be started degraded, %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_drive_can_start_degraded (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->can_start_degraded == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->can_start_degraded) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_start:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @flags: flags affecting the start operation.
Packit ae235b
 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
Packit ae235b
 *     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 to pass to @callback
Packit ae235b
 *
Packit ae235b
 * Asynchronously starts a drive.
Packit ae235b
 *
Packit ae235b
 * When the operation is finished, @callback will be called.
Packit ae235b
 * You can then call g_drive_start_finish() to obtain the
Packit ae235b
 * result of the operation.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_drive_start (GDrive              *drive,
Packit ae235b
               GDriveStartFlags     flags,
Packit ae235b
               GMountOperation     *mount_operation,
Packit ae235b
               GCancellable        *cancellable,
Packit ae235b
               GAsyncReadyCallback  callback,
Packit ae235b
               gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DRIVE (drive));
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->start == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (drive, callback, user_data,
Packit ae235b
                               g_drive_start,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               _("drive doesn’t implement start"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  (* iface->start) (drive, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_start_finish:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @result: a #GAsyncResult.
Packit ae235b
 * @error: a #GError, or %NULL
Packit ae235b
 *
Packit ae235b
 * Finishes starting a drive.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the drive has been started successfully,
Packit ae235b
 *     %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_drive_start_finish (GDrive         *drive,
Packit ae235b
                      GAsyncResult   *result,
Packit ae235b
                      GError        **error)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), 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_drive_start))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->start_finish) (drive, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_can_stop:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 *
Packit ae235b
 * Checks if a drive can be stopped.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the @drive can be stopped, %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_drive_can_stop (GDrive *drive)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->can_stop == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  return (* iface->can_stop) (drive);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_stop:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @flags: flags affecting the unmount if required for stopping.
Packit ae235b
 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
Packit ae235b
 *     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 to pass to @callback
Packit ae235b
 *
Packit ae235b
 * Asynchronously stops a drive.
Packit ae235b
 *
Packit ae235b
 * When the operation is finished, @callback will be called.
Packit ae235b
 * You can then call g_drive_stop_finish() to obtain the
Packit ae235b
 * result of the operation.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_drive_stop (GDrive               *drive,
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
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_DRIVE (drive));
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  if (iface->stop == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (drive, callback, user_data,
Packit ae235b
                               g_drive_start,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               _("drive doesn’t implement stop"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  (* iface->stop) (drive, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_stop_finish:
Packit ae235b
 * @drive: a #GDrive.
Packit ae235b
 * @result: a #GAsyncResult.
Packit ae235b
 * @error: a #GError, or %NULL
Packit ae235b
 *
Packit ae235b
 * Finishes stopping a drive.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the drive has been stopped successfully,
Packit ae235b
 *     %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_drive_stop_finish (GDrive        *drive,
Packit ae235b
                     GAsyncResult  *result,
Packit ae235b
                     GError       **error)
Packit ae235b
{
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), 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_drive_start))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
Packit ae235b
  return (* iface->stop_finish) (drive, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_drive_get_sort_key:
Packit ae235b
 * @drive: A #GDrive.
Packit ae235b
 *
Packit ae235b
 * Gets the sort key for @drive, if any.
Packit ae235b
 *
Packit ae235b
 * Returns: Sorting key for @drive or %NULL if no such key is available.
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_drive_get_sort_key (GDrive  *drive)
Packit ae235b
{
Packit ae235b
  const gchar *ret = NULL;
Packit ae235b
  GDriveIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
Packit ae235b
Packit ae235b
  iface = G_DRIVE_GET_IFACE (drive);
Packit ae235b
  if (iface->get_sort_key != NULL)
Packit ae235b
    ret = iface->get_sort_key (drive);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}