1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2008 Red Hat, Inc.
7 * SPDX-License-Identifier: LGPL-2.1-or-later
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General
20 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 * Author: Alexander Larsson <alexl@redhat.com>
23 * David Zeuthen <davidz@redhat.com>
31 #include "gmountprivate.h"
32 #include "gthemedicon.h"
33 #include "gasyncresult.h"
41 * @short_description: Mount management
43 * @see_also: GVolume, GUnixMountEntry, GUnixMountPoint
45 * The #GMount interface represents user-visible mounts. Note, when
46 * porting from GnomeVFS, #GMount is the moral equivalent of #GnomeVFSVolume.
48 * #GMount is a "mounted" filesystem that you can access. Mounted is in
49 * quotes because it's not the same as a unix mount, it might be a gvfs
50 * mount, but you can still access the files on it if you use GIO. Might or
51 * might not be related to a volume object.
53 * Unmounting a #GMount instance is an asynchronous operation. For
54 * more information about asynchronous operations, see #GAsyncResult
55 * and #GTask. To unmount a #GMount instance, first call
56 * g_mount_unmount_with_operation() with (at least) the #GMount instance and a
57 * #GAsyncReadyCallback. The callback will be fired when the
58 * operation has resolved (either with success or failure), and a
59 * #GAsyncResult structure will be passed to the callback. That
60 * callback should then call g_mount_unmount_with_operation_finish() with the #GMount
61 * and the #GAsyncResult data to see if the operation was completed
62 * successfully. If an @error is present when g_mount_unmount_with_operation_finish()
63 * is called, then it will be filled with any error information.
66 typedef GMountIface GMountInterface;
67 G_DEFINE_INTERFACE (GMount, g_mount, G_TYPE_OBJECT)
70 g_mount_default_init (GMountInterface *iface)
74 * @mount: the object on which the signal is emitted
76 * Emitted when the mount has been changed.
78 g_signal_new (I_("changed"),
81 G_STRUCT_OFFSET (GMountIface, changed),
88 * @mount: the object on which the signal is emitted
90 * This signal is emitted when the #GMount have been
91 * unmounted. If the recipient is holding references to the
92 * object they should release them so the object can be
95 g_signal_new (I_("unmounted"),
98 G_STRUCT_OFFSET (GMountIface, unmounted),
103 * GMount::pre-unmount:
104 * @mount: the object on which the signal is emitted
106 * This signal may be emitted when the #GMount is about to be
109 * This signal depends on the backend and is only emitted if
110 * GIO was used to unmount.
114 g_signal_new (I_("pre-unmount"),
117 G_STRUCT_OFFSET (GMountIface, pre_unmount),
127 * Gets the root directory on @mount.
129 * Returns: (transfer full): a #GFile.
130 * The returned object should be unreffed with
131 * g_object_unref() when no longer needed.
134 g_mount_get_root (GMount *mount)
138 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
140 iface = G_MOUNT_GET_IFACE (mount);
142 return (* iface->get_root) (mount);
146 * g_mount_get_default_location:
149 * Gets the default location of @mount. The default location of the given
150 * @mount is a path that reflects the main entry point for the user (e.g.
151 * the home directory, or the root of the volume).
153 * Returns: (transfer full): a #GFile.
154 * The returned object should be unreffed with
155 * g_object_unref() when no longer needed.
158 g_mount_get_default_location (GMount *mount)
163 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
165 iface = G_MOUNT_GET_IFACE (mount);
167 /* Fallback to get_root when default_location () is not available */
168 if (iface->get_default_location)
169 file = (* iface->get_default_location) (mount);
171 file = (* iface->get_root) (mount);
180 * Gets the name of @mount.
182 * Returns: the name for the given @mount.
183 * The returned string should be freed with g_free()
184 * when no longer needed.
187 g_mount_get_name (GMount *mount)
191 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
193 iface = G_MOUNT_GET_IFACE (mount);
195 return (* iface->get_name) (mount);
202 * Gets the icon for @mount.
204 * Returns: (transfer full): a #GIcon.
205 * The returned object should be unreffed with
206 * g_object_unref() when no longer needed.
209 g_mount_get_icon (GMount *mount)
213 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
215 iface = G_MOUNT_GET_IFACE (mount);
217 return (* iface->get_icon) (mount);
222 * g_mount_get_symbolic_icon:
225 * Gets the symbolic icon for @mount.
227 * Returns: (transfer full): a #GIcon.
228 * The returned object should be unreffed with
229 * g_object_unref() when no longer needed.
234 g_mount_get_symbolic_icon (GMount *mount)
239 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
241 iface = G_MOUNT_GET_IFACE (mount);
243 if (iface->get_symbolic_icon != NULL)
244 ret = iface->get_symbolic_icon (mount);
246 ret = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic");
255 * Gets the UUID for the @mount. The reference is typically based on
256 * the file system UUID for the mount in question and should be
257 * considered an opaque string. Returns %NULL if there is no UUID
260 * Returns: (nullable) (transfer full): the UUID for @mount or %NULL if no UUID
262 * The returned string should be freed with g_free()
263 * when no longer needed.
266 g_mount_get_uuid (GMount *mount)
270 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
272 iface = G_MOUNT_GET_IFACE (mount);
274 return (* iface->get_uuid) (mount);
278 * g_mount_get_volume:
281 * Gets the volume for the @mount.
283 * Returns: (transfer full) (nullable): a #GVolume or %NULL if @mount is not
284 * associated with a volume.
285 * The returned object should be unreffed with
286 * g_object_unref() when no longer needed.
289 g_mount_get_volume (GMount *mount)
293 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
295 iface = G_MOUNT_GET_IFACE (mount);
297 return (* iface->get_volume) (mount);
304 * Gets the drive for the @mount.
306 * This is a convenience method for getting the #GVolume and then
307 * using that object to get the #GDrive.
309 * Returns: (transfer full) (nullable): a #GDrive or %NULL if @mount is not
310 * associated with a volume or a drive.
311 * The returned object should be unreffed with
312 * g_object_unref() when no longer needed.
315 g_mount_get_drive (GMount *mount)
319 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
321 iface = G_MOUNT_GET_IFACE (mount);
323 return (* iface->get_drive) (mount);
327 * g_mount_can_unmount:
330 * Checks if @mount can be unmounted.
332 * Returns: %TRUE if the @mount can be unmounted.
335 g_mount_can_unmount (GMount *mount)
339 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
341 iface = G_MOUNT_GET_IFACE (mount);
343 return (* iface->can_unmount) (mount);
350 * Checks if @mount can be ejected.
352 * Returns: %TRUE if the @mount can be ejected.
355 g_mount_can_eject (GMount *mount)
359 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
361 iface = G_MOUNT_GET_IFACE (mount);
363 return (* iface->can_eject) (mount);
369 * @flags: flags affecting the operation
370 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
371 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
372 * @user_data: user data passed to @callback.
374 * Unmounts a mount. This is an asynchronous operation, and is
375 * finished by calling g_mount_unmount_finish() with the @mount
376 * and #GAsyncResult data returned in the @callback.
378 * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead.
381 g_mount_unmount (GMount *mount,
382 GMountUnmountFlags flags,
383 GCancellable *cancellable,
384 GAsyncReadyCallback callback,
389 g_return_if_fail (G_IS_MOUNT (mount));
391 iface = G_MOUNT_GET_IFACE (mount);
393 if (iface->unmount == NULL)
395 g_task_report_new_error (mount, callback, user_data,
396 g_mount_unmount_with_operation,
397 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
398 /* Translators: This is an error
399 * message for mount objects that
400 * don't implement unmount. */
401 _("mount doesn’t implement “unmount”"));
405 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
409 * g_mount_unmount_finish:
411 * @result: a #GAsyncResult.
412 * @error: a #GError location to store the error occurring, or %NULL to
415 * Finishes unmounting a mount. If any errors occurred during the operation,
416 * @error will be set to contain the errors and %FALSE will be returned.
418 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
420 * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead.
423 g_mount_unmount_finish (GMount *mount,
424 GAsyncResult *result,
429 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
430 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
432 if (g_async_result_legacy_propagate_error (result, error))
434 else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
435 return g_task_propagate_boolean (G_TASK (result), error);
437 iface = G_MOUNT_GET_IFACE (mount);
438 return (* iface->unmount_finish) (mount, result, error);
445 * @flags: flags affecting the unmount if required for eject
446 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
447 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
448 * @user_data: user data passed to @callback.
450 * Ejects a mount. This is an asynchronous operation, and is
451 * finished by calling g_mount_eject_finish() with the @mount
452 * and #GAsyncResult data returned in the @callback.
454 * Deprecated: 2.22: Use g_mount_eject_with_operation() instead.
457 g_mount_eject (GMount *mount,
458 GMountUnmountFlags flags,
459 GCancellable *cancellable,
460 GAsyncReadyCallback callback,
465 g_return_if_fail (G_IS_MOUNT (mount));
467 iface = G_MOUNT_GET_IFACE (mount);
469 if (iface->eject == NULL)
471 g_task_report_new_error (mount, callback, user_data,
472 g_mount_eject_with_operation,
473 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
474 /* Translators: This is an error
475 * message for mount objects that
476 * don't implement eject. */
477 _("mount doesn’t implement “eject”"));
481 (* iface->eject) (mount, flags, cancellable, callback, user_data);
485 * g_mount_eject_finish:
487 * @result: a #GAsyncResult.
488 * @error: a #GError location to store the error occurring, or %NULL to
491 * Finishes ejecting a mount. If any errors occurred during the operation,
492 * @error will be set to contain the errors and %FALSE will be returned.
494 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
496 * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead.
499 g_mount_eject_finish (GMount *mount,
500 GAsyncResult *result,
505 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
506 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
508 if (g_async_result_legacy_propagate_error (result, error))
510 else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
511 return g_task_propagate_boolean (G_TASK (result), error);
513 iface = G_MOUNT_GET_IFACE (mount);
514 return (* iface->eject_finish) (mount, result, error);
518 * g_mount_unmount_with_operation:
520 * @flags: flags affecting the operation
521 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
523 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
524 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
525 * @user_data: user data passed to @callback.
527 * Unmounts a mount. This is an asynchronous operation, and is
528 * finished by calling g_mount_unmount_with_operation_finish() with the @mount
529 * and #GAsyncResult data returned in the @callback.
534 g_mount_unmount_with_operation (GMount *mount,
535 GMountUnmountFlags flags,
536 GMountOperation *mount_operation,
537 GCancellable *cancellable,
538 GAsyncReadyCallback callback,
543 g_return_if_fail (G_IS_MOUNT (mount));
545 iface = G_MOUNT_GET_IFACE (mount);
547 if (iface->unmount == NULL && iface->unmount_with_operation == NULL)
549 g_task_report_new_error (mount, callback, user_data,
550 g_mount_unmount_with_operation,
551 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
552 /* Translators: This is an error
553 * message for mount objects that
554 * don't implement any of unmount or unmount_with_operation. */
555 _("mount doesn’t implement “unmount” or “unmount_with_operation”"));
559 if (iface->unmount_with_operation != NULL)
560 (* iface->unmount_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
562 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
566 * g_mount_unmount_with_operation_finish:
568 * @result: a #GAsyncResult.
569 * @error: a #GError location to store the error occurring, or %NULL to
572 * Finishes unmounting a mount. If any errors occurred during the operation,
573 * @error will be set to contain the errors and %FALSE will be returned.
575 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
580 g_mount_unmount_with_operation_finish (GMount *mount,
581 GAsyncResult *result,
586 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
587 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
589 if (g_async_result_legacy_propagate_error (result, error))
591 else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
592 return g_task_propagate_boolean (G_TASK (result), error);
594 iface = G_MOUNT_GET_IFACE (mount);
595 if (iface->unmount_with_operation_finish != NULL)
596 return (* iface->unmount_with_operation_finish) (mount, result, error);
598 return (* iface->unmount_finish) (mount, result, error);
603 * g_mount_eject_with_operation:
605 * @flags: flags affecting the unmount if required for eject
606 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
608 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
609 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
610 * @user_data: user data passed to @callback.
612 * Ejects a mount. This is an asynchronous operation, and is
613 * finished by calling g_mount_eject_with_operation_finish() with the @mount
614 * and #GAsyncResult data returned in the @callback.
619 g_mount_eject_with_operation (GMount *mount,
620 GMountUnmountFlags flags,
621 GMountOperation *mount_operation,
622 GCancellable *cancellable,
623 GAsyncReadyCallback callback,
628 g_return_if_fail (G_IS_MOUNT (mount));
630 iface = G_MOUNT_GET_IFACE (mount);
632 if (iface->eject == NULL && iface->eject_with_operation == NULL)
634 g_task_report_new_error (mount, callback, user_data,
635 g_mount_eject_with_operation,
636 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
637 /* Translators: This is an error
638 * message for mount objects that
639 * don't implement any of eject or eject_with_operation. */
640 _("mount doesn’t implement “eject” or “eject_with_operation”"));
644 if (iface->eject_with_operation != NULL)
645 (* iface->eject_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
647 (* iface->eject) (mount, flags, cancellable, callback, user_data);
651 * g_mount_eject_with_operation_finish:
653 * @result: a #GAsyncResult.
654 * @error: a #GError location to store the error occurring, or %NULL to
657 * Finishes ejecting a mount. If any errors occurred during the operation,
658 * @error will be set to contain the errors and %FALSE will be returned.
660 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
665 g_mount_eject_with_operation_finish (GMount *mount,
666 GAsyncResult *result,
671 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
672 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
674 if (g_async_result_legacy_propagate_error (result, error))
676 else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
677 return g_task_propagate_boolean (G_TASK (result), error);
679 iface = G_MOUNT_GET_IFACE (mount);
680 if (iface->eject_with_operation_finish != NULL)
681 return (* iface->eject_with_operation_finish) (mount, result, error);
683 return (* iface->eject_finish) (mount, result, error);
689 * @flags: flags affecting the operation
690 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
692 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
693 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
694 * @user_data: user data passed to @callback.
696 * Remounts a mount. This is an asynchronous operation, and is
697 * finished by calling g_mount_remount_finish() with the @mount
698 * and #GAsyncResults data returned in the @callback.
700 * Remounting is useful when some setting affecting the operation
701 * of the volume has been changed, as these may need a remount to
702 * take affect. While this is semantically equivalent with unmounting
703 * and then remounting not all backends might need to actually be
707 g_mount_remount (GMount *mount,
708 GMountMountFlags flags,
709 GMountOperation *mount_operation,
710 GCancellable *cancellable,
711 GAsyncReadyCallback callback,
716 g_return_if_fail (G_IS_MOUNT (mount));
718 iface = G_MOUNT_GET_IFACE (mount);
720 if (iface->remount == NULL)
722 g_task_report_new_error (mount, callback, user_data,
724 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
725 /* Translators: This is an error
726 * message for mount objects that
727 * don't implement remount. */
728 _("mount doesn’t implement “remount”"));
732 (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
736 * g_mount_remount_finish:
738 * @result: a #GAsyncResult.
739 * @error: a #GError location to store the error occurring, or %NULL to
742 * Finishes remounting a mount. If any errors occurred during the operation,
743 * @error will be set to contain the errors and %FALSE will be returned.
745 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
748 g_mount_remount_finish (GMount *mount,
749 GAsyncResult *result,
754 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
755 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
757 if (g_async_result_legacy_propagate_error (result, error))
759 else if (g_async_result_is_tagged (result, g_mount_remount))
760 return g_task_propagate_boolean (G_TASK (result), error);
762 iface = G_MOUNT_GET_IFACE (mount);
763 return (* iface->remount_finish) (mount, result, error);
767 * g_mount_guess_content_type:
769 * @force_rescan: Whether to force a rescan of the content.
770 * Otherwise a cached result will be used if available
771 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
772 * @callback: a #GAsyncReadyCallback
773 * @user_data: user data passed to @callback
775 * Tries to guess the type of content stored on @mount. Returns one or
776 * more textual identifiers of well-known content types (typically
777 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
778 * memory cards. See the
779 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
780 * specification for more on x-content types.
782 * This is an asynchronous operation (see
783 * g_mount_guess_content_type_sync() for the synchronous version), and
784 * is finished by calling g_mount_guess_content_type_finish() with the
785 * @mount and #GAsyncResult data returned in the @callback.
790 g_mount_guess_content_type (GMount *mount,
791 gboolean force_rescan,
792 GCancellable *cancellable,
793 GAsyncReadyCallback callback,
798 g_return_if_fail (G_IS_MOUNT (mount));
800 iface = G_MOUNT_GET_IFACE (mount);
802 if (iface->guess_content_type == NULL)
804 g_task_report_new_error (mount, callback, user_data,
805 g_mount_guess_content_type,
806 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
807 /* Translators: This is an error
808 * message for mount objects that
809 * don't implement content type guessing. */
810 _("mount doesn’t implement content type guessing"));
814 (* iface->guess_content_type) (mount, force_rescan, cancellable, callback, user_data);
818 * g_mount_guess_content_type_finish:
820 * @result: a #GAsyncResult
821 * @error: a #GError location to store the error occurring, or %NULL to
824 * Finishes guessing content types of @mount. If any errors occurred
825 * during the operation, @error will be set to contain the errors and
826 * %FALSE will be returned. In particular, you may get an
827 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content
830 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
831 * Caller should free this array with g_strfreev() when done with it.
836 g_mount_guess_content_type_finish (GMount *mount,
837 GAsyncResult *result,
842 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
843 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
845 if (g_async_result_legacy_propagate_error (result, error))
847 else if (g_async_result_is_tagged (result, g_mount_guess_content_type))
848 return g_task_propagate_pointer (G_TASK (result), error);
850 iface = G_MOUNT_GET_IFACE (mount);
851 return (* iface->guess_content_type_finish) (mount, result, error);
855 * g_mount_guess_content_type_sync:
857 * @force_rescan: Whether to force a rescan of the content.
858 * Otherwise a cached result will be used if available
859 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
860 * @error: a #GError location to store the error occurring, or %NULL to
863 * Tries to guess the type of content stored on @mount. Returns one or
864 * more textual identifiers of well-known content types (typically
865 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
866 * memory cards. See the
867 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
868 * specification for more on x-content types.
870 * This is a synchronous operation and as such may block doing IO;
871 * see g_mount_guess_content_type() for the asynchronous version.
873 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
874 * Caller should free this array with g_strfreev() when done with it.
879 g_mount_guess_content_type_sync (GMount *mount,
880 gboolean force_rescan,
881 GCancellable *cancellable,
886 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
888 iface = G_MOUNT_GET_IFACE (mount);
890 if (iface->guess_content_type_sync == NULL)
892 g_set_error_literal (error,
893 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
894 /* Translators: This is an error
895 * message for mount objects that
896 * don't implement content type guessing. */
897 _("mount doesn’t implement synchronous content type guessing"));
902 return (* iface->guess_content_type_sync) (mount, force_rescan, cancellable, error);
905 G_LOCK_DEFINE_STATIC (priv_lock);
907 /* only access this structure when holding priv_lock */
910 gint shadow_ref_count;
914 free_private (GMountPrivate *private)
918 G_UNLOCK (priv_lock);
921 /* may only be called when holding priv_lock */
922 static GMountPrivate *
923 get_private (GMount *mount)
925 GMountPrivate *private;
927 private = g_object_get_data (G_OBJECT (mount), "g-mount-private");
928 if (G_LIKELY (private != NULL))
931 private = g_new0 (GMountPrivate, 1);
932 g_object_set_data_full (G_OBJECT (mount),
935 (GDestroyNotify) free_private);
942 * g_mount_is_shadowed:
945 * Determines if @mount is shadowed. Applications or libraries should
946 * avoid displaying @mount in the user interface if it is shadowed.
948 * A mount is said to be shadowed if there exists one or more user
949 * visible objects (currently #GMount objects) with a root that is
950 * inside the root of @mount.
952 * One application of shadow mounts is when exposing a single file
953 * system that is used to address several logical volumes. In this
954 * situation, a #GVolumeMonitor implementation would create two
955 * #GVolume objects (for example, one for the camera functionality of
956 * the device and one for a SD card reader on the device) with
957 * activation URIs `gphoto2://[usb:001,002]/store1/`
958 * and `gphoto2://[usb:001,002]/store2/`. When the
959 * underlying mount (with root
960 * `gphoto2://[usb:001,002]/`) is mounted, said
961 * #GVolumeMonitor implementation would create two #GMount objects
962 * (each with their root matching the corresponding volume activation
963 * root) that would shadow the original mount.
965 * The proxy monitor in GVfs 2.26 and later, automatically creates and
966 * manage shadow mounts (and shadows the underlying mount) if the
967 * activation root on a #GVolume is set.
969 * Returns: %TRUE if @mount is shadowed.
974 g_mount_is_shadowed (GMount *mount)
979 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
982 priv = get_private (mount);
983 ret = (priv->shadow_ref_count > 0);
984 G_UNLOCK (priv_lock);
993 * Increments the shadow count on @mount. Usually used by
994 * #GVolumeMonitor implementations when creating a shadow mount for
995 * @mount, see g_mount_is_shadowed() for more information. The caller
996 * will need to emit the #GMount::changed signal on @mount manually.
1001 g_mount_shadow (GMount *mount)
1003 GMountPrivate *priv;
1005 g_return_if_fail (G_IS_MOUNT (mount));
1008 priv = get_private (mount);
1009 priv->shadow_ref_count += 1;
1010 G_UNLOCK (priv_lock);
1015 * @mount: A #GMount.
1017 * Decrements the shadow count on @mount. Usually used by
1018 * #GVolumeMonitor implementations when destroying a shadow mount for
1019 * @mount, see g_mount_is_shadowed() for more information. The caller
1020 * will need to emit the #GMount::changed signal on @mount manually.
1025 g_mount_unshadow (GMount *mount)
1027 GMountPrivate *priv;
1029 g_return_if_fail (G_IS_MOUNT (mount));
1032 priv = get_private (mount);
1033 priv->shadow_ref_count -= 1;
1034 if (priv->shadow_ref_count < 0)
1035 g_warning ("Shadow ref count on GMount is negative");
1036 G_UNLOCK (priv_lock);
1040 * g_mount_get_sort_key:
1041 * @mount: A #GMount.
1043 * Gets the sort key for @mount, if any.
1045 * Returns: (nullable): Sorting key for @mount or %NULL if no such key is available.
1050 g_mount_get_sort_key (GMount *mount)
1052 const gchar *ret = NULL;
1055 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
1057 iface = G_MOUNT_GET_IFACE (mount);
1058 if (iface->get_sort_key != NULL)
1059 ret = iface->get_sort_key (mount);