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 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Author: Alexander Larsson <alexl@redhat.com>
21 * David Zeuthen <davidz@redhat.com>
29 #include "gmountprivate.h"
30 #include "gthemedicon.h"
31 #include "gasyncresult.h"
39 * @short_description: Mount management
41 * @see_also: GVolume, GUnixMountEntry, GUnixMountPoint
43 * The #GMount interface represents user-visible mounts. Note, when
44 * porting from GnomeVFS, #GMount is the moral equivalent of #GnomeVFSVolume.
46 * #GMount is a "mounted" filesystem that you can access. Mounted is in
47 * quotes because it's not the same as a unix mount, it might be a gvfs
48 * mount, but you can still access the files on it if you use GIO. Might or
49 * might not be related to a volume object.
51 * Unmounting a #GMount instance is an asynchronous operation. For
52 * more information about asynchronous operations, see #GAsyncResult
53 * and #GTask. To unmount a #GMount instance, first call
54 * g_mount_unmount_with_operation() with (at least) the #GMount instance and a
55 * #GAsyncReadyCallback. The callback will be fired when the
56 * operation has resolved (either with success or failure), and a
57 * #GAsyncResult structure will be passed to the callback. That
58 * callback should then call g_mount_unmount_with_operation_finish() with the #GMount
59 * and the #GAsyncResult data to see if the operation was completed
60 * successfully. If an @error is present when g_mount_unmount_with_operation_finish()
61 * is called, then it will be filled with any error information.
64 typedef GMountIface GMountInterface;
65 G_DEFINE_INTERFACE (GMount, g_mount, G_TYPE_OBJECT)
68 g_mount_default_init (GMountInterface *iface)
72 * @mount: the object on which the signal is emitted
74 * Emitted when the mount has been changed.
76 g_signal_new (I_("changed"),
79 G_STRUCT_OFFSET (GMountIface, changed),
86 * @mount: the object on which the signal is emitted
88 * This signal is emitted when the #GMount have been
89 * unmounted. If the recipient is holding references to the
90 * object they should release them so the object can be
93 g_signal_new (I_("unmounted"),
96 G_STRUCT_OFFSET (GMountIface, unmounted),
101 * GMount::pre-unmount:
102 * @mount: the object on which the signal is emitted
104 * This signal may be emitted when the #GMount is about to be
107 * This signal depends on the backend and is only emitted if
108 * GIO was used to unmount.
112 g_signal_new (I_("pre-unmount"),
115 G_STRUCT_OFFSET (GMountIface, pre_unmount),
125 * Gets the root directory on @mount.
127 * Returns: (transfer full): a #GFile.
128 * The returned object should be unreffed with
129 * g_object_unref() when no longer needed.
132 g_mount_get_root (GMount *mount)
136 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
138 iface = G_MOUNT_GET_IFACE (mount);
140 return (* iface->get_root) (mount);
144 * g_mount_get_default_location:
147 * Gets the default location of @mount. The default location of the given
148 * @mount is a path that reflects the main entry point for the user (e.g.
149 * the home directory, or the root of the volume).
151 * Returns: (transfer full): a #GFile.
152 * The returned object should be unreffed with
153 * g_object_unref() when no longer needed.
156 g_mount_get_default_location (GMount *mount)
161 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
163 iface = G_MOUNT_GET_IFACE (mount);
165 /* Fallback to get_root when default_location () is not available */
166 if (iface->get_default_location)
167 file = (* iface->get_default_location) (mount);
169 file = (* iface->get_root) (mount);
178 * Gets the name of @mount.
180 * Returns: the name for the given @mount.
181 * The returned string should be freed with g_free()
182 * when no longer needed.
185 g_mount_get_name (GMount *mount)
189 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
191 iface = G_MOUNT_GET_IFACE (mount);
193 return (* iface->get_name) (mount);
200 * Gets the icon for @mount.
202 * Returns: (transfer full): a #GIcon.
203 * The returned object should be unreffed with
204 * g_object_unref() when no longer needed.
207 g_mount_get_icon (GMount *mount)
211 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
213 iface = G_MOUNT_GET_IFACE (mount);
215 return (* iface->get_icon) (mount);
220 * g_mount_get_symbolic_icon:
223 * Gets the symbolic icon for @mount.
225 * Returns: (transfer full): a #GIcon.
226 * The returned object should be unreffed with
227 * g_object_unref() when no longer needed.
232 g_mount_get_symbolic_icon (GMount *mount)
237 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
239 iface = G_MOUNT_GET_IFACE (mount);
241 if (iface->get_symbolic_icon != NULL)
242 ret = iface->get_symbolic_icon (mount);
244 ret = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic");
253 * Gets the UUID for the @mount. The reference is typically based on
254 * the file system UUID for the mount in question and should be
255 * considered an opaque string. Returns %NULL if there is no UUID
258 * Returns: (nullable) (transfer full): the UUID for @mount or %NULL if no UUID
260 * The returned string should be freed with g_free()
261 * when no longer needed.
264 g_mount_get_uuid (GMount *mount)
268 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
270 iface = G_MOUNT_GET_IFACE (mount);
272 return (* iface->get_uuid) (mount);
276 * g_mount_get_volume:
279 * Gets the volume for the @mount.
281 * Returns: (transfer full) (nullable): a #GVolume or %NULL if @mount is not
282 * associated with a volume.
283 * The returned object should be unreffed with
284 * g_object_unref() when no longer needed.
287 g_mount_get_volume (GMount *mount)
291 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
293 iface = G_MOUNT_GET_IFACE (mount);
295 return (* iface->get_volume) (mount);
302 * Gets the drive for the @mount.
304 * This is a convenience method for getting the #GVolume and then
305 * using that object to get the #GDrive.
307 * Returns: (transfer full) (nullable): a #GDrive or %NULL if @mount is not
308 * associated with a volume or a drive.
309 * The returned object should be unreffed with
310 * g_object_unref() when no longer needed.
313 g_mount_get_drive (GMount *mount)
317 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
319 iface = G_MOUNT_GET_IFACE (mount);
321 return (* iface->get_drive) (mount);
325 * g_mount_can_unmount:
328 * Checks if @mount can be unmounted.
330 * Returns: %TRUE if the @mount can be unmounted.
333 g_mount_can_unmount (GMount *mount)
337 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
339 iface = G_MOUNT_GET_IFACE (mount);
341 return (* iface->can_unmount) (mount);
348 * Checks if @mount can be ejected.
350 * Returns: %TRUE if the @mount can be ejected.
353 g_mount_can_eject (GMount *mount)
357 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
359 iface = G_MOUNT_GET_IFACE (mount);
361 return (* iface->can_eject) (mount);
367 * @flags: flags affecting the operation
368 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
369 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
370 * @user_data: user data passed to @callback.
372 * Unmounts a mount. This is an asynchronous operation, and is
373 * finished by calling g_mount_unmount_finish() with the @mount
374 * and #GAsyncResult data returned in the @callback.
376 * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead.
379 g_mount_unmount (GMount *mount,
380 GMountUnmountFlags flags,
381 GCancellable *cancellable,
382 GAsyncReadyCallback callback,
387 g_return_if_fail (G_IS_MOUNT (mount));
389 iface = G_MOUNT_GET_IFACE (mount);
391 if (iface->unmount == NULL)
393 g_task_report_new_error (mount, callback, user_data,
394 g_mount_unmount_with_operation,
395 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
396 /* Translators: This is an error
397 * message for mount objects that
398 * don't implement unmount. */
399 _("mount doesn’t implement “unmount”"));
403 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
407 * g_mount_unmount_finish:
409 * @result: a #GAsyncResult.
410 * @error: a #GError location to store the error occurring, or %NULL to
413 * Finishes unmounting a mount. If any errors occurred during the operation,
414 * @error will be set to contain the errors and %FALSE will be returned.
416 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
418 * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead.
421 g_mount_unmount_finish (GMount *mount,
422 GAsyncResult *result,
427 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
428 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
430 if (g_async_result_legacy_propagate_error (result, error))
432 else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
433 return g_task_propagate_boolean (G_TASK (result), error);
435 iface = G_MOUNT_GET_IFACE (mount);
436 return (* iface->unmount_finish) (mount, result, error);
443 * @flags: flags affecting the unmount if required for eject
444 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
445 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
446 * @user_data: user data passed to @callback.
448 * Ejects a mount. This is an asynchronous operation, and is
449 * finished by calling g_mount_eject_finish() with the @mount
450 * and #GAsyncResult data returned in the @callback.
452 * Deprecated: 2.22: Use g_mount_eject_with_operation() instead.
455 g_mount_eject (GMount *mount,
456 GMountUnmountFlags flags,
457 GCancellable *cancellable,
458 GAsyncReadyCallback callback,
463 g_return_if_fail (G_IS_MOUNT (mount));
465 iface = G_MOUNT_GET_IFACE (mount);
467 if (iface->eject == NULL)
469 g_task_report_new_error (mount, callback, user_data,
470 g_mount_eject_with_operation,
471 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
472 /* Translators: This is an error
473 * message for mount objects that
474 * don't implement eject. */
475 _("mount doesn’t implement “eject”"));
479 (* iface->eject) (mount, flags, cancellable, callback, user_data);
483 * g_mount_eject_finish:
485 * @result: a #GAsyncResult.
486 * @error: a #GError location to store the error occurring, or %NULL to
489 * Finishes ejecting a mount. If any errors occurred during the operation,
490 * @error will be set to contain the errors and %FALSE will be returned.
492 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
494 * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead.
497 g_mount_eject_finish (GMount *mount,
498 GAsyncResult *result,
503 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
504 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
506 if (g_async_result_legacy_propagate_error (result, error))
508 else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
509 return g_task_propagate_boolean (G_TASK (result), error);
511 iface = G_MOUNT_GET_IFACE (mount);
512 return (* iface->eject_finish) (mount, result, error);
516 * g_mount_unmount_with_operation:
518 * @flags: flags affecting the operation
519 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
521 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
522 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
523 * @user_data: user data passed to @callback.
525 * Unmounts a mount. This is an asynchronous operation, and is
526 * finished by calling g_mount_unmount_with_operation_finish() with the @mount
527 * and #GAsyncResult data returned in the @callback.
532 g_mount_unmount_with_operation (GMount *mount,
533 GMountUnmountFlags flags,
534 GMountOperation *mount_operation,
535 GCancellable *cancellable,
536 GAsyncReadyCallback callback,
541 g_return_if_fail (G_IS_MOUNT (mount));
543 iface = G_MOUNT_GET_IFACE (mount);
545 if (iface->unmount == NULL && iface->unmount_with_operation == NULL)
547 g_task_report_new_error (mount, callback, user_data,
548 g_mount_unmount_with_operation,
549 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
550 /* Translators: This is an error
551 * message for mount objects that
552 * don't implement any of unmount or unmount_with_operation. */
553 _("mount doesn’t implement “unmount” or “unmount_with_operation”"));
557 if (iface->unmount_with_operation != NULL)
558 (* iface->unmount_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
560 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
564 * g_mount_unmount_with_operation_finish:
566 * @result: a #GAsyncResult.
567 * @error: a #GError location to store the error occurring, or %NULL to
570 * Finishes unmounting a mount. If any errors occurred during the operation,
571 * @error will be set to contain the errors and %FALSE will be returned.
573 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
578 g_mount_unmount_with_operation_finish (GMount *mount,
579 GAsyncResult *result,
584 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
585 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
587 if (g_async_result_legacy_propagate_error (result, error))
589 else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
590 return g_task_propagate_boolean (G_TASK (result), error);
592 iface = G_MOUNT_GET_IFACE (mount);
593 if (iface->unmount_with_operation_finish != NULL)
594 return (* iface->unmount_with_operation_finish) (mount, result, error);
596 return (* iface->unmount_finish) (mount, result, error);
601 * g_mount_eject_with_operation:
603 * @flags: flags affecting the unmount if required for eject
604 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
606 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
607 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
608 * @user_data: user data passed to @callback.
610 * Ejects a mount. This is an asynchronous operation, and is
611 * finished by calling g_mount_eject_with_operation_finish() with the @mount
612 * and #GAsyncResult data returned in the @callback.
617 g_mount_eject_with_operation (GMount *mount,
618 GMountUnmountFlags flags,
619 GMountOperation *mount_operation,
620 GCancellable *cancellable,
621 GAsyncReadyCallback callback,
626 g_return_if_fail (G_IS_MOUNT (mount));
628 iface = G_MOUNT_GET_IFACE (mount);
630 if (iface->eject == NULL && iface->eject_with_operation == NULL)
632 g_task_report_new_error (mount, callback, user_data,
633 g_mount_eject_with_operation,
634 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
635 /* Translators: This is an error
636 * message for mount objects that
637 * don't implement any of eject or eject_with_operation. */
638 _("mount doesn’t implement “eject” or “eject_with_operation”"));
642 if (iface->eject_with_operation != NULL)
643 (* iface->eject_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
645 (* iface->eject) (mount, flags, cancellable, callback, user_data);
649 * g_mount_eject_with_operation_finish:
651 * @result: a #GAsyncResult.
652 * @error: a #GError location to store the error occurring, or %NULL to
655 * Finishes ejecting a mount. If any errors occurred during the operation,
656 * @error will be set to contain the errors and %FALSE will be returned.
658 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
663 g_mount_eject_with_operation_finish (GMount *mount,
664 GAsyncResult *result,
669 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
670 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
672 if (g_async_result_legacy_propagate_error (result, error))
674 else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
675 return g_task_propagate_boolean (G_TASK (result), error);
677 iface = G_MOUNT_GET_IFACE (mount);
678 if (iface->eject_with_operation_finish != NULL)
679 return (* iface->eject_with_operation_finish) (mount, result, error);
681 return (* iface->eject_finish) (mount, result, error);
687 * @flags: flags affecting the operation
688 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
690 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
691 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
692 * @user_data: user data passed to @callback.
694 * Remounts a mount. This is an asynchronous operation, and is
695 * finished by calling g_mount_remount_finish() with the @mount
696 * and #GAsyncResults data returned in the @callback.
698 * Remounting is useful when some setting affecting the operation
699 * of the volume has been changed, as these may need a remount to
700 * take affect. While this is semantically equivalent with unmounting
701 * and then remounting not all backends might need to actually be
705 g_mount_remount (GMount *mount,
706 GMountMountFlags flags,
707 GMountOperation *mount_operation,
708 GCancellable *cancellable,
709 GAsyncReadyCallback callback,
714 g_return_if_fail (G_IS_MOUNT (mount));
716 iface = G_MOUNT_GET_IFACE (mount);
718 if (iface->remount == NULL)
720 g_task_report_new_error (mount, callback, user_data,
722 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
723 /* Translators: This is an error
724 * message for mount objects that
725 * don't implement remount. */
726 _("mount doesn’t implement “remount”"));
730 (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
734 * g_mount_remount_finish:
736 * @result: a #GAsyncResult.
737 * @error: a #GError location to store the error occurring, or %NULL to
740 * Finishes remounting a mount. If any errors occurred during the operation,
741 * @error will be set to contain the errors and %FALSE will be returned.
743 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
746 g_mount_remount_finish (GMount *mount,
747 GAsyncResult *result,
752 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
753 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
755 if (g_async_result_legacy_propagate_error (result, error))
757 else if (g_async_result_is_tagged (result, g_mount_remount))
758 return g_task_propagate_boolean (G_TASK (result), error);
760 iface = G_MOUNT_GET_IFACE (mount);
761 return (* iface->remount_finish) (mount, result, error);
765 * g_mount_guess_content_type:
767 * @force_rescan: Whether to force a rescan of the content.
768 * Otherwise a cached result will be used if available
769 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
770 * @callback: a #GAsyncReadyCallback
771 * @user_data: user data passed to @callback
773 * Tries to guess the type of content stored on @mount. Returns one or
774 * more textual identifiers of well-known content types (typically
775 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
776 * memory cards. See the
777 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
778 * specification for more on x-content types.
780 * This is an asynchronous operation (see
781 * g_mount_guess_content_type_sync() for the synchronous version), and
782 * is finished by calling g_mount_guess_content_type_finish() with the
783 * @mount and #GAsyncResult data returned in the @callback.
788 g_mount_guess_content_type (GMount *mount,
789 gboolean force_rescan,
790 GCancellable *cancellable,
791 GAsyncReadyCallback callback,
796 g_return_if_fail (G_IS_MOUNT (mount));
798 iface = G_MOUNT_GET_IFACE (mount);
800 if (iface->guess_content_type == NULL)
802 g_task_report_new_error (mount, callback, user_data,
803 g_mount_guess_content_type,
804 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
805 /* Translators: This is an error
806 * message for mount objects that
807 * don't implement content type guessing. */
808 _("mount doesn’t implement content type guessing"));
812 (* iface->guess_content_type) (mount, force_rescan, cancellable, callback, user_data);
816 * g_mount_guess_content_type_finish:
818 * @result: a #GAsyncResult
819 * @error: a #GError location to store the error occurring, or %NULL to
822 * Finishes guessing content types of @mount. If any errors occurred
823 * during the operation, @error will be set to contain the errors and
824 * %FALSE will be returned. In particular, you may get an
825 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content
828 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
829 * Caller should free this array with g_strfreev() when done with it.
834 g_mount_guess_content_type_finish (GMount *mount,
835 GAsyncResult *result,
840 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
841 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
843 if (g_async_result_legacy_propagate_error (result, error))
845 else if (g_async_result_is_tagged (result, g_mount_guess_content_type))
846 return g_task_propagate_pointer (G_TASK (result), error);
848 iface = G_MOUNT_GET_IFACE (mount);
849 return (* iface->guess_content_type_finish) (mount, result, error);
853 * g_mount_guess_content_type_sync:
855 * @force_rescan: Whether to force a rescan of the content.
856 * Otherwise a cached result will be used if available
857 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
858 * @error: a #GError location to store the error occurring, or %NULL to
861 * Tries to guess the type of content stored on @mount. Returns one or
862 * more textual identifiers of well-known content types (typically
863 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
864 * memory cards. See the
865 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
866 * specification for more on x-content types.
868 * This is a synchronous operation and as such may block doing IO;
869 * see g_mount_guess_content_type() for the asynchronous version.
871 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
872 * Caller should free this array with g_strfreev() when done with it.
877 g_mount_guess_content_type_sync (GMount *mount,
878 gboolean force_rescan,
879 GCancellable *cancellable,
884 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
886 iface = G_MOUNT_GET_IFACE (mount);
888 if (iface->guess_content_type_sync == NULL)
890 g_set_error_literal (error,
891 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
892 /* Translators: This is an error
893 * message for mount objects that
894 * don't implement content type guessing. */
895 _("mount doesn’t implement synchronous content type guessing"));
900 return (* iface->guess_content_type_sync) (mount, force_rescan, cancellable, error);
903 G_LOCK_DEFINE_STATIC (priv_lock);
905 /* only access this structure when holding priv_lock */
908 gint shadow_ref_count;
912 free_private (GMountPrivate *private)
916 G_UNLOCK (priv_lock);
919 /* may only be called when holding priv_lock */
920 static GMountPrivate *
921 get_private (GMount *mount)
923 GMountPrivate *private;
925 private = g_object_get_data (G_OBJECT (mount), "g-mount-private");
926 if (G_LIKELY (private != NULL))
929 private = g_new0 (GMountPrivate, 1);
930 g_object_set_data_full (G_OBJECT (mount),
933 (GDestroyNotify) free_private);
940 * g_mount_is_shadowed:
943 * Determines if @mount is shadowed. Applications or libraries should
944 * avoid displaying @mount in the user interface if it is shadowed.
946 * A mount is said to be shadowed if there exists one or more user
947 * visible objects (currently #GMount objects) with a root that is
948 * inside the root of @mount.
950 * One application of shadow mounts is when exposing a single file
951 * system that is used to address several logical volumes. In this
952 * situation, a #GVolumeMonitor implementation would create two
953 * #GVolume objects (for example, one for the camera functionality of
954 * the device and one for a SD card reader on the device) with
955 * activation URIs `gphoto2://[usb:001,002]/store1/`
956 * and `gphoto2://[usb:001,002]/store2/`. When the
957 * underlying mount (with root
958 * `gphoto2://[usb:001,002]/`) is mounted, said
959 * #GVolumeMonitor implementation would create two #GMount objects
960 * (each with their root matching the corresponding volume activation
961 * root) that would shadow the original mount.
963 * The proxy monitor in GVfs 2.26 and later, automatically creates and
964 * manage shadow mounts (and shadows the underlying mount) if the
965 * activation root on a #GVolume is set.
967 * Returns: %TRUE if @mount is shadowed.
972 g_mount_is_shadowed (GMount *mount)
977 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
980 priv = get_private (mount);
981 ret = (priv->shadow_ref_count > 0);
982 G_UNLOCK (priv_lock);
991 * Increments the shadow count on @mount. Usually used by
992 * #GVolumeMonitor implementations when creating a shadow mount for
993 * @mount, see g_mount_is_shadowed() for more information. The caller
994 * will need to emit the #GMount::changed signal on @mount manually.
999 g_mount_shadow (GMount *mount)
1001 GMountPrivate *priv;
1003 g_return_if_fail (G_IS_MOUNT (mount));
1006 priv = get_private (mount);
1007 priv->shadow_ref_count += 1;
1008 G_UNLOCK (priv_lock);
1013 * @mount: A #GMount.
1015 * Decrements the shadow count on @mount. Usually used by
1016 * #GVolumeMonitor implementations when destroying a shadow mount for
1017 * @mount, see g_mount_is_shadowed() for more information. The caller
1018 * will need to emit the #GMount::changed signal on @mount manually.
1023 g_mount_unshadow (GMount *mount)
1025 GMountPrivate *priv;
1027 g_return_if_fail (G_IS_MOUNT (mount));
1030 priv = get_private (mount);
1031 priv->shadow_ref_count -= 1;
1032 if (priv->shadow_ref_count < 0)
1033 g_warning ("Shadow ref count on GMount is negative");
1034 G_UNLOCK (priv_lock);
1038 * g_mount_get_sort_key:
1039 * @mount: A #GMount.
1041 * Gets the sort key for @mount, if any.
1043 * Returns: (nullable): Sorting key for @mount or %NULL if no such key is available.
1048 g_mount_get_sort_key (GMount *mount)
1050 const gchar *ret = NULL;
1053 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
1055 iface = G_MOUNT_GET_IFACE (mount);
1056 if (iface->get_sort_key != NULL)
1057 ret = iface->get_sort_key (mount);