Blame gio/gmount.c

Packit ae235b
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
Packit ae235b
Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 * 
Packit ae235b
 * Copyright (C) 2006-2008 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
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include "gmount.h"
Packit ae235b
#include "gmountprivate.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:gmount
Packit ae235b
 * @short_description: Mount management
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 * @see_also: GVolume, GUnixMountEntry, GUnixMountPoint
Packit ae235b
 *
Packit ae235b
 * The #GMount interface represents user-visible mounts. Note, when 
Packit ae235b
 * porting from GnomeVFS, #GMount is the moral equivalent of #GnomeVFSVolume.
Packit ae235b
 *
Packit ae235b
 * #GMount is a "mounted" filesystem that you can access. Mounted is in
Packit ae235b
 * quotes because it's not the same as a unix mount, it might be a gvfs
Packit ae235b
 * mount, but you can still access the files on it if you use GIO. Might or
Packit ae235b
 * might not be related to a volume object.
Packit ae235b
 * 
Packit ae235b
 * Unmounting a #GMount instance is an asynchronous operation. For
Packit ae235b
 * more information about asynchronous operations, see #GAsyncResult
Packit ae235b
 * and #GTask. To unmount a #GMount instance, first call
Packit ae235b
 * g_mount_unmount_with_operation() with (at least) the #GMount instance and a
Packit ae235b
 * #GAsyncReadyCallback.  The callback will be fired when the
Packit ae235b
 * operation has resolved (either with success or failure), and a
Packit ae235b
 * #GAsyncResult structure will be passed to the callback.  That
Packit ae235b
 * callback should then call g_mount_unmount_with_operation_finish() with the #GMount
Packit ae235b
 * and the #GAsyncResult data to see if the operation was completed
Packit ae235b
 * successfully.  If an @error is present when g_mount_unmount_with_operation_finish() 
Packit ae235b
 * is called, then it will be filled with any error information.
Packit ae235b
 **/
Packit ae235b
Packit ae235b
typedef GMountIface GMountInterface;
Packit ae235b
G_DEFINE_INTERFACE (GMount, g_mount, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_mount_default_init (GMountInterface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GMount::changed:
Packit ae235b
   * @mount: the object on which the signal is emitted
Packit ae235b
   *
Packit ae235b
   * Emitted when the mount has been changed.
Packit ae235b
   **/
Packit ae235b
  g_signal_new (I_("changed"),
Packit ae235b
                G_TYPE_MOUNT,
Packit ae235b
                G_SIGNAL_RUN_LAST,
Packit ae235b
                G_STRUCT_OFFSET (GMountIface, changed),
Packit ae235b
                NULL, NULL,
Packit ae235b
                g_cclosure_marshal_VOID__VOID,
Packit ae235b
                G_TYPE_NONE, 0);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMount::unmounted:
Packit ae235b
   * @mount: the object on which the signal is emitted
Packit ae235b
   *
Packit ae235b
   * This signal is emitted when the #GMount have been
Packit ae235b
   * unmounted. 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_("unmounted"),
Packit ae235b
                G_TYPE_MOUNT,
Packit ae235b
                G_SIGNAL_RUN_LAST,
Packit ae235b
                G_STRUCT_OFFSET (GMountIface, unmounted),
Packit ae235b
                NULL, NULL,
Packit ae235b
                g_cclosure_marshal_VOID__VOID,
Packit ae235b
                G_TYPE_NONE, 0);
Packit ae235b
  /**
Packit ae235b
   * GMount::pre-unmount:
Packit ae235b
   * @mount: the object on which the signal is emitted
Packit ae235b
   *
Packit ae235b
   * This signal may be emitted when the #GMount is about to be
Packit ae235b
   * unmounted.
Packit ae235b
   *
Packit ae235b
   * This signal depends on the backend and is only emitted if
Packit ae235b
   * GIO was used to unmount.
Packit ae235b
   *
Packit ae235b
   * Since: 2.22
Packit ae235b
   **/
Packit ae235b
  g_signal_new (I_("pre-unmount"),
Packit ae235b
                G_TYPE_MOUNT,
Packit ae235b
                G_SIGNAL_RUN_LAST,
Packit ae235b
                G_STRUCT_OFFSET (GMountIface, pre_unmount),
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_mount_get_root:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Gets the root directory on @mount.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GFile. 
Packit ae235b
 *      The returned object should be unreffed with 
Packit ae235b
 *      g_object_unref() when no longer needed.
Packit ae235b
 **/
Packit ae235b
GFile *
Packit ae235b
g_mount_get_root (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->get_root) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_get_default_location:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 *
Packit ae235b
 * Gets the default location of @mount. The default location of the given
Packit ae235b
 * @mount is a path that reflects the main entry point for the user (e.g.
Packit ae235b
 * the home directory, or the root of the volume).
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): a #GFile.
Packit ae235b
 *      The returned object should be unreffed with
Packit ae235b
 *      g_object_unref() when no longer needed.
Packit ae235b
 **/
Packit ae235b
GFile *
Packit ae235b
g_mount_get_default_location (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
  GFile       *file;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  
Packit ae235b
  /* Fallback to get_root when default_location () is not available */
Packit ae235b
  if (iface->get_default_location)
Packit ae235b
    file = (* iface->get_default_location) (mount);
Packit ae235b
  else
Packit ae235b
    file = (* iface->get_root) (mount);
Packit ae235b
Packit ae235b
  return file;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_get_name:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Gets the name of @mount.
Packit ae235b
 * 
Packit ae235b
 * Returns: the name for the given @mount. 
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_mount_get_name (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->get_name) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_get_icon:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Gets the icon for @mount.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GIcon.
Packit ae235b
 *      The returned object should be unreffed with 
Packit ae235b
 *      g_object_unref() when no longer needed.
Packit ae235b
 **/
Packit ae235b
GIcon *
Packit ae235b
g_mount_get_icon (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->get_icon) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_get_symbolic_icon:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Gets the symbolic icon for @mount.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GIcon.
Packit ae235b
 *      The returned object should be unreffed with 
Packit ae235b
 *      g_object_unref() when no longer needed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.34
Packit ae235b
 **/
Packit ae235b
GIcon *
Packit ae235b
g_mount_get_symbolic_icon (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
  GIcon *ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->get_symbolic_icon != NULL)
Packit ae235b
    ret = iface->get_symbolic_icon (mount);
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
 * g_mount_get_uuid:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Gets the UUID for the @mount. The reference is typically based on
Packit ae235b
 * the file system UUID for the mount 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 @mount 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_mount_get_uuid (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->get_uuid) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_get_volume:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Gets the volume for the @mount.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GVolume or %NULL if @mount is not associated with a volume.
Packit ae235b
 *      The returned object should be unreffed with 
Packit ae235b
 *      g_object_unref() when no longer needed.
Packit ae235b
 **/
Packit ae235b
GVolume *
Packit ae235b
g_mount_get_volume (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->get_volume) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_get_drive:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Gets the drive for the @mount.
Packit ae235b
 *
Packit ae235b
 * This is a convenience method for getting the #GVolume and then
Packit ae235b
 * using that object to get the #GDrive.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full): a #GDrive or %NULL if @mount is not associated with a volume or a drive.
Packit ae235b
 *      The returned object should be unreffed with 
Packit ae235b
 *      g_object_unref() when no longer needed.
Packit ae235b
 **/
Packit ae235b
GDrive *
Packit ae235b
g_mount_get_drive (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->get_drive) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_can_unmount: 
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Checks if @mount can be unmounted.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @mount can be unmounted.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_can_unmount (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->can_unmount) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_can_eject: 
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * 
Packit ae235b
 * Checks if @mount can be ejected.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @mount can be ejected.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_can_eject (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  return (* iface->can_eject) (mount);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_unmount:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * @flags: flags affecting the operation
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
 * Unmounts a mount. This is an asynchronous operation, and is 
Packit ae235b
 * finished by calling g_mount_unmount_finish() with the @mount 
Packit ae235b
 * and #GAsyncResult data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_unmount (GMount              *mount,
Packit ae235b
                 GMountUnmountFlags   flags,
Packit ae235b
                 GCancellable        *cancellable,
Packit ae235b
                 GAsyncReadyCallback  callback,
Packit ae235b
                 gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
  
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->unmount == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (mount, callback, user_data,
Packit ae235b
                               g_mount_unmount_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for mount objects that
Packit ae235b
                                * don't implement unmount. */
Packit ae235b
                               _("mount doesn’t implement “unmount”"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->unmount) (mount, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_unmount_finish:
Packit ae235b
 * @mount: a #GMount.
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 unmounting a mount. 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 mount was successfully unmounted. %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_unmount_finish (GMount        *mount,
Packit ae235b
                        GAsyncResult  *result,
Packit ae235b
                        GError       **error)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), 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_mount_unmount_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
  
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  return (* iface->unmount_finish) (mount, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_eject:
Packit ae235b
 * @mount: a #GMount.
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 passed to @callback.
Packit ae235b
 * 
Packit ae235b
 * Ejects a mount. This is an asynchronous operation, and is 
Packit ae235b
 * finished by calling g_mount_eject_finish() with the @mount 
Packit ae235b
 * and #GAsyncResult data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_mount_eject_with_operation() instead.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_eject (GMount              *mount,
Packit ae235b
               GMountUnmountFlags   flags,
Packit ae235b
               GCancellable        *cancellable,
Packit ae235b
               GAsyncReadyCallback  callback,
Packit ae235b
               gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
  
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->eject == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (mount, callback, user_data,
Packit ae235b
                               g_mount_eject_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for mount objects that
Packit ae235b
                                * don't implement eject. */
Packit ae235b
                               _("mount doesn’t implement “eject”"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->eject) (mount, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_eject_finish:
Packit ae235b
 * @mount: a #GMount.
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 mount. 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 mount was successfully ejected. %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_eject_finish (GMount        *mount,
Packit ae235b
                      GAsyncResult  *result,
Packit ae235b
                      GError       **error)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), 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_mount_eject_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
  
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  return (* iface->eject_finish) (mount, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_unmount_with_operation:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * @flags: flags affecting the 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 passed to @callback.
Packit ae235b
 *
Packit ae235b
 * Unmounts a mount. This is an asynchronous operation, and is
Packit ae235b
 * finished by calling g_mount_unmount_with_operation_finish() with the @mount 
Packit ae235b
 * and #GAsyncResult data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_unmount_with_operation (GMount              *mount,
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
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->unmount == NULL && iface->unmount_with_operation == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (mount, callback, user_data,
Packit ae235b
                               g_mount_unmount_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for mount objects that
Packit ae235b
                                * don't implement any of unmount or unmount_with_operation. */
Packit ae235b
                               _("mount doesn’t implement “unmount” or “unmount_with_operation”"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (iface->unmount_with_operation != NULL)
Packit ae235b
    (* iface->unmount_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
  else
Packit ae235b
    (* iface->unmount) (mount, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_unmount_with_operation_finish:
Packit ae235b
 * @mount: a #GMount.
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 unmounting a mount. 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 mount was successfully unmounted. %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_unmount_with_operation_finish (GMount        *mount,
Packit ae235b
                                       GAsyncResult  *result,
Packit ae235b
                                       GError       **error)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), 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_mount_unmount_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  if (iface->unmount_with_operation_finish != NULL)
Packit ae235b
    return (* iface->unmount_with_operation_finish) (mount, result, error);
Packit ae235b
  else
Packit ae235b
    return (* iface->unmount_finish) (mount, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_eject_with_operation:
Packit ae235b
 * @mount: a #GMount.
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 mount. This is an asynchronous operation, and is
Packit ae235b
 * finished by calling g_mount_eject_with_operation_finish() with the @mount
Packit ae235b
 * and #GAsyncResult data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_eject_with_operation (GMount              *mount,
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
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->eject == NULL && iface->eject_with_operation == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (mount, callback, user_data,
Packit ae235b
                               g_mount_eject_with_operation,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for mount objects that
Packit ae235b
                                * don't implement any of eject or eject_with_operation. */
Packit ae235b
                               _("mount 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) (mount, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
  else
Packit ae235b
    (* iface->eject) (mount, flags, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_eject_with_operation_finish:
Packit ae235b
 * @mount: a #GMount.
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 mount. 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 mount was successfully ejected. %FALSE otherwise.
Packit ae235b
 *
Packit ae235b
 * Since: 2.22
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_eject_with_operation_finish (GMount        *mount,
Packit ae235b
                                     GAsyncResult  *result,
Packit ae235b
                                     GError       **error)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), 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_mount_eject_with_operation))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  if (iface->eject_with_operation_finish != NULL)
Packit ae235b
    return (* iface->eject_with_operation_finish) (mount, result, error);
Packit ae235b
  else
Packit ae235b
    return (* iface->eject_finish) (mount, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_remount:
Packit ae235b
 * @mount: a #GMount.
Packit ae235b
 * @flags: flags affecting the 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 passed to @callback.
Packit ae235b
 * 
Packit ae235b
 * Remounts a mount. This is an asynchronous operation, and is 
Packit ae235b
 * finished by calling g_mount_remount_finish() with the @mount 
Packit ae235b
 * and #GAsyncResults data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Remounting is useful when some setting affecting the operation
Packit ae235b
 * of the volume has been changed, as these may need a remount to
Packit ae235b
 * take affect. While this is semantically equivalent with unmounting
Packit ae235b
 * and then remounting not all backends might need to actually be
Packit ae235b
 * unmounted.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_remount (GMount              *mount,
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
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
  
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->remount == NULL)
Packit ae235b
    { 
Packit ae235b
      g_task_report_new_error (mount, callback, user_data,
Packit ae235b
                               g_mount_remount,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for mount objects that
Packit ae235b
                                * don't implement remount. */
Packit ae235b
                               _("mount doesn’t implement “remount”"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_remount_finish:
Packit ae235b
 * @mount: a #GMount.
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 remounting a mount. 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 mount was successfully remounted. %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_remount_finish (GMount        *mount,
Packit ae235b
                        GAsyncResult  *result,
Packit ae235b
                        GError       **error)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), 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_mount_remount))
Packit ae235b
    return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
  
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  return (* iface->remount_finish) (mount, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_guess_content_type:
Packit ae235b
 * @mount: a #GMount
Packit ae235b
 * @force_rescan: Whether to force a rescan of the content. 
Packit ae235b
 *     Otherwise a cached result will be used if available
Packit ae235b
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
Packit ae235b
 * @callback: a #GAsyncReadyCallback
Packit ae235b
 * @user_data: user data passed to @callback
Packit ae235b
 * 
Packit ae235b
 * Tries to guess the type of content stored on @mount. Returns one or
Packit ae235b
 * more textual identifiers of well-known content types (typically
Packit ae235b
 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera 
Packit ae235b
 * memory cards. See the 
Packit ae235b
 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
Packit ae235b
 * specification for more on x-content types.
Packit ae235b
 *
Packit ae235b
 * This is an asynchronous operation (see
Packit ae235b
 * g_mount_guess_content_type_sync() for the synchronous version), and
Packit ae235b
 * is finished by calling g_mount_guess_content_type_finish() with the
Packit ae235b
 * @mount and #GAsyncResult data returned in the @callback.
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_mount_guess_content_type (GMount              *mount,
Packit ae235b
                            gboolean             force_rescan,
Packit ae235b
                            GCancellable        *cancellable,
Packit ae235b
                            GAsyncReadyCallback  callback,
Packit ae235b
                            gpointer             user_data)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->guess_content_type == NULL)
Packit ae235b
    {
Packit ae235b
      g_task_report_new_error (mount, callback, user_data,
Packit ae235b
                               g_mount_guess_content_type,
Packit ae235b
                               G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                               /* Translators: This is an error
Packit ae235b
                                * message for mount objects that
Packit ae235b
                                * don't implement content type guessing. */
Packit ae235b
                               _("mount doesn’t implement content type guessing"));
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
  
Packit ae235b
  (* iface->guess_content_type) (mount, force_rescan, cancellable, callback, user_data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_guess_content_type_finish:
Packit ae235b
 * @mount: a #GMount
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 guessing content types of @mount. If any errors occurred
Packit ae235b
 * during the operation, @error will be set to contain the errors and
Packit ae235b
 * %FALSE will be returned. In particular, you may get an 
Packit ae235b
 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content 
Packit ae235b
 * guessing.
Packit ae235b
 * 
Packit ae235b
 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error. 
Packit ae235b
 *     Caller should free this array with g_strfreev() when done with it.
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 **/
Packit ae235b
gchar **
Packit ae235b
g_mount_guess_content_type_finish (GMount        *mount,
Packit ae235b
                                   GAsyncResult  *result,
Packit ae235b
                                   GError       **error)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
Packit ae235b
Packit ae235b
  if (g_async_result_legacy_propagate_error (result, error))
Packit ae235b
    return NULL;
Packit ae235b
  else if (g_async_result_is_tagged (result, g_mount_guess_content_type))
Packit ae235b
    return g_task_propagate_pointer (G_TASK (result), error);
Packit ae235b
  
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  return (* iface->guess_content_type_finish) (mount, result, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_guess_content_type_sync:
Packit ae235b
 * @mount: a #GMount
Packit ae235b
 * @force_rescan: Whether to force a rescan of the content.
Packit ae235b
 *     Otherwise a cached result will be used if available
Packit ae235b
 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
Packit ae235b
 * @error: a #GError location to store the error occurring, or %NULL to
Packit ae235b
 *     ignore
Packit ae235b
 *
Packit ae235b
 * Tries to guess the type of content stored on @mount. Returns one or
Packit ae235b
 * more textual identifiers of well-known content types (typically
Packit ae235b
 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera 
Packit ae235b
 * memory cards. See the 
Packit ae235b
 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
Packit ae235b
 * specification for more on x-content types.
Packit ae235b
 *
Packit ae235b
 * This is an synchronous operation and as such may block doing IO;
Packit ae235b
 * see g_mount_guess_content_type() for the asynchronous version.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
Packit ae235b
 *     Caller should free this array with g_strfreev() when done with it.
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 */
Packit ae235b
char **
Packit ae235b
g_mount_guess_content_type_sync (GMount              *mount,
Packit ae235b
                                 gboolean             force_rescan,
Packit ae235b
                                 GCancellable        *cancellable,
Packit ae235b
                                 GError             **error)
Packit ae235b
{
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
Packit ae235b
  if (iface->guess_content_type_sync == NULL)
Packit ae235b
    {
Packit ae235b
      g_set_error_literal (error,
Packit ae235b
                           G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                           /* Translators: This is an error
Packit ae235b
                            * message for mount objects that
Packit ae235b
                            * don't implement content type guessing. */
Packit ae235b
                           _("mount doesn’t implement synchronous content type guessing"));
Packit ae235b
Packit ae235b
      return NULL;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return (* iface->guess_content_type_sync) (mount, force_rescan, cancellable, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
G_LOCK_DEFINE_STATIC (priv_lock);
Packit ae235b
Packit ae235b
/* only access this structure when holding priv_lock */
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  gint shadow_ref_count;
Packit ae235b
} GMountPrivate;
Packit ae235b
Packit ae235b
static void
Packit ae235b
free_private (GMountPrivate *private)
Packit ae235b
{
Packit ae235b
  G_LOCK (priv_lock);
Packit ae235b
  g_free (private);
Packit ae235b
  G_UNLOCK (priv_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* may only be called when holding priv_lock */
Packit ae235b
static GMountPrivate *
Packit ae235b
get_private (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountPrivate *private;
Packit ae235b
Packit ae235b
  private = g_object_get_data (G_OBJECT (mount), "g-mount-private");
Packit ae235b
  if (G_LIKELY (private != NULL))
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  private = g_new0 (GMountPrivate, 1);
Packit ae235b
  g_object_set_data_full (G_OBJECT (mount),
Packit ae235b
                          "g-mount-private",
Packit ae235b
                          private,
Packit ae235b
                          (GDestroyNotify) free_private);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return private;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_is_shadowed:
Packit ae235b
 * @mount: A #GMount.
Packit ae235b
 *
Packit ae235b
 * Determines if @mount is shadowed. Applications or libraries should
Packit ae235b
 * avoid displaying @mount in the user interface if it is shadowed.
Packit ae235b
 *
Packit ae235b
 * A mount is said to be shadowed if there exists one or more user
Packit ae235b
 * visible objects (currently #GMount objects) with a root that is
Packit ae235b
 * inside the root of @mount.
Packit ae235b
 *
Packit ae235b
 * One application of shadow mounts is when exposing a single file
Packit ae235b
 * system that is used to address several logical volumes. In this
Packit ae235b
 * situation, a #GVolumeMonitor implementation would create two
Packit ae235b
 * #GVolume objects (for example, one for the camera functionality of
Packit ae235b
 * the device and one for a SD card reader on the device) with
Packit ae235b
 * activation URIs `gphoto2://[usb:001,002]/store1/`
Packit ae235b
 * and `gphoto2://[usb:001,002]/store2/`. When the
Packit ae235b
 * underlying mount (with root
Packit ae235b
 * `gphoto2://[usb:001,002]/`) is mounted, said
Packit ae235b
 * #GVolumeMonitor implementation would create two #GMount objects
Packit ae235b
 * (each with their root matching the corresponding volume activation
Packit ae235b
 * root) that would shadow the original mount.
Packit ae235b
 *
Packit ae235b
 * The proxy monitor in GVfs 2.26 and later, automatically creates and
Packit ae235b
 * manage shadow mounts (and shadows the underlying mount) if the
Packit ae235b
 * activation root on a #GVolume is set.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @mount is shadowed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_is_shadowed (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountPrivate *priv;
Packit ae235b
  gboolean ret;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
Packit ae235b
Packit ae235b
  G_LOCK (priv_lock);
Packit ae235b
  priv = get_private (mount);
Packit ae235b
  ret = (priv->shadow_ref_count > 0);
Packit ae235b
  G_UNLOCK (priv_lock);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_shadow:
Packit ae235b
 * @mount: A #GMount.
Packit ae235b
 *
Packit ae235b
 * Increments the shadow count on @mount. Usually used by
Packit ae235b
 * #GVolumeMonitor implementations when creating a shadow mount for
Packit ae235b
 * @mount, see g_mount_is_shadowed() for more information. The caller
Packit ae235b
 * will need to emit the #GMount::changed signal on @mount manually.
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_shadow (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountPrivate *priv;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
Packit ae235b
  G_LOCK (priv_lock);
Packit ae235b
  priv = get_private (mount);
Packit ae235b
  priv->shadow_ref_count += 1;
Packit ae235b
  G_UNLOCK (priv_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_unshadow:
Packit ae235b
 * @mount: A #GMount.
Packit ae235b
 *
Packit ae235b
 * Decrements the shadow count on @mount. Usually used by
Packit ae235b
 * #GVolumeMonitor implementations when destroying a shadow mount for
Packit ae235b
 * @mount, see g_mount_is_shadowed() for more information. The caller
Packit ae235b
 * will need to emit the #GMount::changed signal on @mount manually.
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_unshadow (GMount *mount)
Packit ae235b
{
Packit ae235b
  GMountPrivate *priv;
Packit ae235b
Packit ae235b
  g_return_if_fail (G_IS_MOUNT (mount));
Packit ae235b
Packit ae235b
  G_LOCK (priv_lock);
Packit ae235b
  priv = get_private (mount);
Packit ae235b
  priv->shadow_ref_count -= 1;
Packit ae235b
  if (priv->shadow_ref_count < 0)
Packit ae235b
    g_warning ("Shadow ref count on GMount is negative");
Packit ae235b
  G_UNLOCK (priv_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_get_sort_key:
Packit ae235b
 * @mount: A #GMount.
Packit ae235b
 *
Packit ae235b
 * Gets the sort key for @mount, if any.
Packit ae235b
 *
Packit ae235b
 * Returns: Sorting key for @mount or %NULL if no such key is available.
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_mount_get_sort_key (GMount  *mount)
Packit ae235b
{
Packit ae235b
  const gchar *ret = NULL;
Packit ae235b
  GMountIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
Packit ae235b
Packit ae235b
  iface = G_MOUNT_GET_IFACE (mount);
Packit ae235b
  if (iface->get_sort_key != NULL)
Packit ae235b
    ret = iface->get_sort_key (mount);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}