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 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 * #GAsyncReady 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 #GAsyncReady 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),
81 g_cclosure_marshal_VOID__VOID,
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),
98 g_cclosure_marshal_VOID__VOID,
101 * GMount::pre-unmount:
102 * @mount: the object on which the signal is emitted
104 * This signal is emitted when the #GMount is about to be
109 g_signal_new (I_("pre-unmount"),
112 G_STRUCT_OFFSET (GMountIface, pre_unmount),
114 g_cclosure_marshal_VOID__VOID,
122 * Gets the root directory on @mount.
124 * Returns: (transfer full): a #GFile.
125 * The returned object should be unreffed with
126 * g_object_unref() when no longer needed.
129 g_mount_get_root (GMount *mount)
133 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
135 iface = G_MOUNT_GET_IFACE (mount);
137 return (* iface->get_root) (mount);
141 * g_mount_get_default_location:
144 * Gets the default location of @mount. The default location of the given
145 * @mount is a path that reflects the main entry point for the user (e.g.
146 * the home directory, or the root of the volume).
148 * Returns: (transfer full): a #GFile.
149 * The returned object should be unreffed with
150 * g_object_unref() when no longer needed.
153 g_mount_get_default_location (GMount *mount)
158 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
160 iface = G_MOUNT_GET_IFACE (mount);
162 /* Fallback to get_root when default_location () is not available */
163 if (iface->get_default_location)
164 file = (* iface->get_default_location) (mount);
166 file = (* iface->get_root) (mount);
175 * Gets the name of @mount.
177 * Returns: the name for the given @mount.
178 * The returned string should be freed with g_free()
179 * when no longer needed.
182 g_mount_get_name (GMount *mount)
186 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
188 iface = G_MOUNT_GET_IFACE (mount);
190 return (* iface->get_name) (mount);
197 * Gets the icon for @mount.
199 * Returns: (transfer full): a #GIcon.
200 * The returned object should be unreffed with
201 * g_object_unref() when no longer needed.
204 g_mount_get_icon (GMount *mount)
208 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
210 iface = G_MOUNT_GET_IFACE (mount);
212 return (* iface->get_icon) (mount);
217 * g_mount_get_symbolic_icon:
220 * Gets the symbolic icon for @mount.
222 * Returns: (transfer full): a #GIcon.
223 * The returned object should be unreffed with
224 * g_object_unref() when no longer needed.
229 g_mount_get_symbolic_icon (GMount *mount)
234 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
236 iface = G_MOUNT_GET_IFACE (mount);
238 if (iface->get_symbolic_icon != NULL)
239 ret = iface->get_symbolic_icon (mount);
241 ret = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic");
250 * Gets the UUID for the @mount. The reference is typically based on
251 * the file system UUID for the mount in question and should be
252 * considered an opaque string. Returns %NULL if there is no UUID
255 * Returns: the UUID for @mount or %NULL if no UUID can be computed.
256 * The returned string should be freed with g_free()
257 * when no longer needed.
260 g_mount_get_uuid (GMount *mount)
264 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
266 iface = G_MOUNT_GET_IFACE (mount);
268 return (* iface->get_uuid) (mount);
272 * g_mount_get_volume:
275 * Gets the volume for the @mount.
277 * Returns: (transfer full): a #GVolume or %NULL if @mount is not associated with a volume.
278 * The returned object should be unreffed with
279 * g_object_unref() when no longer needed.
282 g_mount_get_volume (GMount *mount)
286 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
288 iface = G_MOUNT_GET_IFACE (mount);
290 return (* iface->get_volume) (mount);
297 * Gets the drive for the @mount.
299 * This is a convenience method for getting the #GVolume and then
300 * using that object to get the #GDrive.
302 * Returns: (transfer full): a #GDrive or %NULL if @mount is not associated with a volume or a drive.
303 * The returned object should be unreffed with
304 * g_object_unref() when no longer needed.
307 g_mount_get_drive (GMount *mount)
311 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
313 iface = G_MOUNT_GET_IFACE (mount);
315 return (* iface->get_drive) (mount);
319 * g_mount_can_unmount:
322 * Checks if @mount can be mounted.
324 * Returns: %TRUE if the @mount can be unmounted.
327 g_mount_can_unmount (GMount *mount)
331 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
333 iface = G_MOUNT_GET_IFACE (mount);
335 return (* iface->can_unmount) (mount);
342 * Checks if @mount can be eject.
344 * Returns: %TRUE if the @mount can be ejected.
347 g_mount_can_eject (GMount *mount)
351 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
353 iface = G_MOUNT_GET_IFACE (mount);
355 return (* iface->can_eject) (mount);
361 * @flags: flags affecting the operation
362 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
363 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
364 * @user_data: user data passed to @callback.
366 * Unmounts a mount. This is an asynchronous operation, and is
367 * finished by calling g_mount_unmount_finish() with the @mount
368 * and #GAsyncResult data returned in the @callback.
370 * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead.
373 g_mount_unmount (GMount *mount,
374 GMountUnmountFlags flags,
375 GCancellable *cancellable,
376 GAsyncReadyCallback callback,
381 g_return_if_fail (G_IS_MOUNT (mount));
383 iface = G_MOUNT_GET_IFACE (mount);
385 if (iface->unmount == NULL)
387 g_task_report_new_error (mount, callback, user_data,
388 g_mount_unmount_with_operation,
389 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
390 /* Translators: This is an error
391 * message for mount objects that
392 * don't implement unmount. */
393 _("mount doesn't implement \"unmount\""));
397 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
401 * g_mount_unmount_finish:
403 * @result: a #GAsyncResult.
404 * @error: a #GError location to store the error occurring, or %NULL to
407 * Finishes unmounting a mount. If any errors occurred during the operation,
408 * @error will be set to contain the errors and %FALSE will be returned.
410 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
412 * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead.
415 g_mount_unmount_finish (GMount *mount,
416 GAsyncResult *result,
421 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
422 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
424 if (g_async_result_legacy_propagate_error (result, error))
426 else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
427 return g_task_propagate_boolean (G_TASK (result), error);
429 iface = G_MOUNT_GET_IFACE (mount);
430 return (* iface->unmount_finish) (mount, result, error);
437 * @flags: flags affecting the unmount if required for eject
438 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
439 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
440 * @user_data: user data passed to @callback.
442 * Ejects a mount. This is an asynchronous operation, and is
443 * finished by calling g_mount_eject_finish() with the @mount
444 * and #GAsyncResult data returned in the @callback.
446 * Deprecated: 2.22: Use g_mount_eject_with_operation() instead.
449 g_mount_eject (GMount *mount,
450 GMountUnmountFlags flags,
451 GCancellable *cancellable,
452 GAsyncReadyCallback callback,
457 g_return_if_fail (G_IS_MOUNT (mount));
459 iface = G_MOUNT_GET_IFACE (mount);
461 if (iface->eject == NULL)
463 g_task_report_new_error (mount, callback, user_data,
464 g_mount_eject_with_operation,
465 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
466 /* Translators: This is an error
467 * message for mount objects that
468 * don't implement eject. */
469 _("mount doesn't implement \"eject\""));
473 (* iface->eject) (mount, flags, cancellable, callback, user_data);
477 * g_mount_eject_finish:
479 * @result: a #GAsyncResult.
480 * @error: a #GError location to store the error occurring, or %NULL to
483 * Finishes ejecting a mount. If any errors occurred during the operation,
484 * @error will be set to contain the errors and %FALSE will be returned.
486 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
488 * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead.
491 g_mount_eject_finish (GMount *mount,
492 GAsyncResult *result,
497 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
498 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
500 if (g_async_result_legacy_propagate_error (result, error))
502 else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
503 return g_task_propagate_boolean (G_TASK (result), error);
505 iface = G_MOUNT_GET_IFACE (mount);
506 return (* iface->eject_finish) (mount, result, error);
510 * g_mount_unmount_with_operation:
512 * @flags: flags affecting the operation
513 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
515 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
516 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
517 * @user_data: user data passed to @callback.
519 * Unmounts a mount. This is an asynchronous operation, and is
520 * finished by calling g_mount_unmount_with_operation_finish() with the @mount
521 * and #GAsyncResult data returned in the @callback.
526 g_mount_unmount_with_operation (GMount *mount,
527 GMountUnmountFlags flags,
528 GMountOperation *mount_operation,
529 GCancellable *cancellable,
530 GAsyncReadyCallback callback,
535 g_return_if_fail (G_IS_MOUNT (mount));
537 iface = G_MOUNT_GET_IFACE (mount);
539 if (iface->unmount == NULL && iface->unmount_with_operation == NULL)
541 g_task_report_new_error (mount, callback, user_data,
542 g_mount_unmount_with_operation,
543 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
544 /* Translators: This is an error
545 * message for mount objects that
546 * don't implement any of unmount or unmount_with_operation. */
547 _("mount doesn't implement \"unmount\" or \"unmount_with_operation\""));
551 if (iface->unmount_with_operation != NULL)
552 (* iface->unmount_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
554 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
558 * g_mount_unmount_with_operation_finish:
560 * @result: a #GAsyncResult.
561 * @error: a #GError location to store the error occurring, or %NULL to
564 * Finishes unmounting a mount. If any errors occurred during the operation,
565 * @error will be set to contain the errors and %FALSE will be returned.
567 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
572 g_mount_unmount_with_operation_finish (GMount *mount,
573 GAsyncResult *result,
578 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
579 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
581 if (g_async_result_legacy_propagate_error (result, error))
583 else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation))
584 return g_task_propagate_boolean (G_TASK (result), error);
586 iface = G_MOUNT_GET_IFACE (mount);
587 if (iface->unmount_with_operation_finish != NULL)
588 return (* iface->unmount_with_operation_finish) (mount, result, error);
590 return (* iface->unmount_finish) (mount, result, error);
595 * g_mount_eject_with_operation:
597 * @flags: flags affecting the unmount if required for eject
598 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
600 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
601 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
602 * @user_data: user data passed to @callback.
604 * Ejects a mount. This is an asynchronous operation, and is
605 * finished by calling g_mount_eject_with_operation_finish() with the @mount
606 * and #GAsyncResult data returned in the @callback.
611 g_mount_eject_with_operation (GMount *mount,
612 GMountUnmountFlags flags,
613 GMountOperation *mount_operation,
614 GCancellable *cancellable,
615 GAsyncReadyCallback callback,
620 g_return_if_fail (G_IS_MOUNT (mount));
622 iface = G_MOUNT_GET_IFACE (mount);
624 if (iface->eject == NULL && iface->eject_with_operation == NULL)
626 g_task_report_new_error (mount, callback, user_data,
627 g_mount_eject_with_operation,
628 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
629 /* Translators: This is an error
630 * message for mount objects that
631 * don't implement any of eject or eject_with_operation. */
632 _("mount doesn't implement \"eject\" or \"eject_with_operation\""));
636 if (iface->eject_with_operation != NULL)
637 (* iface->eject_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
639 (* iface->eject) (mount, flags, cancellable, callback, user_data);
643 * g_mount_eject_with_operation_finish:
645 * @result: a #GAsyncResult.
646 * @error: a #GError location to store the error occurring, or %NULL to
649 * Finishes ejecting a mount. If any errors occurred during the operation,
650 * @error will be set to contain the errors and %FALSE will be returned.
652 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
657 g_mount_eject_with_operation_finish (GMount *mount,
658 GAsyncResult *result,
663 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
664 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
666 if (g_async_result_legacy_propagate_error (result, error))
668 else if (g_async_result_is_tagged (result, g_mount_eject_with_operation))
669 return g_task_propagate_boolean (G_TASK (result), error);
671 iface = G_MOUNT_GET_IFACE (mount);
672 if (iface->eject_with_operation_finish != NULL)
673 return (* iface->eject_with_operation_finish) (mount, result, error);
675 return (* iface->eject_finish) (mount, result, error);
681 * @flags: flags affecting the operation
682 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
684 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
685 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
686 * @user_data: user data passed to @callback.
688 * Remounts a mount. This is an asynchronous operation, and is
689 * finished by calling g_mount_remount_finish() with the @mount
690 * and #GAsyncResults data returned in the @callback.
692 * Remounting is useful when some setting affecting the operation
693 * of the volume has been changed, as these may need a remount to
694 * take affect. While this is semantically equivalent with unmounting
695 * and then remounting not all backends might need to actually be
699 g_mount_remount (GMount *mount,
700 GMountMountFlags flags,
701 GMountOperation *mount_operation,
702 GCancellable *cancellable,
703 GAsyncReadyCallback callback,
708 g_return_if_fail (G_IS_MOUNT (mount));
710 iface = G_MOUNT_GET_IFACE (mount);
712 if (iface->remount == NULL)
714 g_task_report_new_error (mount, callback, user_data,
716 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
717 /* Translators: This is an error
718 * message for mount objects that
719 * don't implement remount. */
720 _("mount doesn't implement \"remount\""));
724 (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
728 * g_mount_remount_finish:
730 * @result: a #GAsyncResult.
731 * @error: a #GError location to store the error occurring, or %NULL to
734 * Finishes remounting a mount. If any errors occurred during the operation,
735 * @error will be set to contain the errors and %FALSE will be returned.
737 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
740 g_mount_remount_finish (GMount *mount,
741 GAsyncResult *result,
746 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
747 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
749 if (g_async_result_legacy_propagate_error (result, error))
751 else if (g_async_result_is_tagged (result, g_mount_remount))
752 return g_task_propagate_boolean (G_TASK (result), error);
754 iface = G_MOUNT_GET_IFACE (mount);
755 return (* iface->remount_finish) (mount, result, error);
759 * g_mount_guess_content_type:
761 * @force_rescan: Whether to force a rescan of the content.
762 * Otherwise a cached result will be used if available
763 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
764 * @callback: a #GAsyncReadyCallback
765 * @user_data: user data passed to @callback
767 * Tries to guess the type of content stored on @mount. Returns one or
768 * more textual identifiers of well-known content types (typically
769 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
770 * memory cards. See the
771 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
772 * specification for more on x-content types.
774 * This is an asynchronous operation (see
775 * g_mount_guess_content_type_sync() for the synchronous version), and
776 * is finished by calling g_mount_guess_content_type_finish() with the
777 * @mount and #GAsyncResult data returned in the @callback.
782 g_mount_guess_content_type (GMount *mount,
783 gboolean force_rescan,
784 GCancellable *cancellable,
785 GAsyncReadyCallback callback,
790 g_return_if_fail (G_IS_MOUNT (mount));
792 iface = G_MOUNT_GET_IFACE (mount);
794 if (iface->guess_content_type == NULL)
796 g_task_report_new_error (mount, callback, user_data,
797 g_mount_guess_content_type,
798 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
799 /* Translators: This is an error
800 * message for mount objects that
801 * don't implement content type guessing. */
802 _("mount doesn't implement content type guessing"));
806 (* iface->guess_content_type) (mount, force_rescan, cancellable, callback, user_data);
810 * g_mount_guess_content_type_finish:
812 * @result: a #GAsyncResult
813 * @error: a #GError location to store the error occurring, or %NULL to
816 * Finishes guessing content types of @mount. If any errors occurred
817 * during the operation, @error will be set to contain the errors and
818 * %FALSE will be returned. In particular, you may get an
819 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content
822 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
823 * Caller should free this array with g_strfreev() when done with it.
828 g_mount_guess_content_type_finish (GMount *mount,
829 GAsyncResult *result,
834 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
835 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
837 if (g_async_result_legacy_propagate_error (result, error))
839 else if (g_async_result_is_tagged (result, g_mount_guess_content_type))
840 return g_task_propagate_pointer (G_TASK (result), error);
842 iface = G_MOUNT_GET_IFACE (mount);
843 return (* iface->guess_content_type_finish) (mount, result, error);
847 * g_mount_guess_content_type_sync:
849 * @force_rescan: Whether to force a rescan of the content.
850 * Otherwise a cached result will be used if available
851 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
852 * @error: a #GError location to store the error occurring, or %NULL to
855 * Tries to guess the type of content stored on @mount. Returns one or
856 * more textual identifiers of well-known content types (typically
857 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
858 * memory cards. See the
859 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
860 * specification for more on x-content types.
862 * This is an synchronous operation and as such may block doing IO;
863 * see g_mount_guess_content_type() for the asynchronous version.
865 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
866 * Caller should free this array with g_strfreev() when done with it.
871 g_mount_guess_content_type_sync (GMount *mount,
872 gboolean force_rescan,
873 GCancellable *cancellable,
878 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
880 iface = G_MOUNT_GET_IFACE (mount);
882 if (iface->guess_content_type_sync == NULL)
884 g_set_error_literal (error,
885 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
886 /* Translators: This is an error
887 * message for mount objects that
888 * don't implement content type guessing. */
889 _("mount doesn't implement synchronous content type guessing"));
894 return (* iface->guess_content_type_sync) (mount, force_rescan, cancellable, error);
897 G_LOCK_DEFINE_STATIC (priv_lock);
899 /* only access this structure when holding priv_lock */
902 gint shadow_ref_count;
906 free_private (GMountPrivate *private)
910 G_UNLOCK (priv_lock);
913 /* may only be called when holding priv_lock */
914 static GMountPrivate *
915 get_private (GMount *mount)
917 GMountPrivate *private;
919 private = g_object_get_data (G_OBJECT (mount), "g-mount-private");
920 if (G_LIKELY (private != NULL))
923 private = g_new0 (GMountPrivate, 1);
924 g_object_set_data_full (G_OBJECT (mount),
927 (GDestroyNotify) free_private);
934 * g_mount_is_shadowed:
937 * Determines if @mount is shadowed. Applications or libraries should
938 * avoid displaying @mount in the user interface if it is shadowed.
940 * A mount is said to be shadowed if there exists one or more user
941 * visible objects (currently #GMount objects) with a root that is
942 * inside the root of @mount.
944 * One application of shadow mounts is when exposing a single file
945 * system that is used to address several logical volumes. In this
946 * situation, a #GVolumeMonitor implementation would create two
947 * #GVolume objects (for example, one for the camera functionality of
948 * the device and one for a SD card reader on the device) with
949 * activation URIs `gphoto2://[usb:001,002]/store1/`
950 * and `gphoto2://[usb:001,002]/store2/`. When the
951 * underlying mount (with root
952 * `gphoto2://[usb:001,002]/`) is mounted, said
953 * #GVolumeMonitor implementation would create two #GMount objects
954 * (each with their root matching the corresponding volume activation
955 * root) that would shadow the original mount.
957 * The proxy monitor in GVfs 2.26 and later, automatically creates and
958 * manage shadow mounts (and shadows the underlying mount) if the
959 * activation root on a #GVolume is set.
961 * Returns: %TRUE if @mount is shadowed.
966 g_mount_is_shadowed (GMount *mount)
971 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
974 priv = get_private (mount);
975 ret = (priv->shadow_ref_count > 0);
976 G_UNLOCK (priv_lock);
985 * Increments the shadow count on @mount. Usually used by
986 * #GVolumeMonitor implementations when creating a shadow mount for
987 * @mount, see g_mount_is_shadowed() for more information. The caller
988 * will need to emit the #GMount::changed signal on @mount manually.
993 g_mount_shadow (GMount *mount)
997 g_return_if_fail (G_IS_MOUNT (mount));
1000 priv = get_private (mount);
1001 priv->shadow_ref_count += 1;
1002 G_UNLOCK (priv_lock);
1007 * @mount: A #GMount.
1009 * Decrements the shadow count on @mount. Usually used by
1010 * #GVolumeMonitor implementations when destroying a shadow mount for
1011 * @mount, see g_mount_is_shadowed() for more information. The caller
1012 * will need to emit the #GMount::changed signal on @mount manually.
1017 g_mount_unshadow (GMount *mount)
1019 GMountPrivate *priv;
1021 g_return_if_fail (G_IS_MOUNT (mount));
1024 priv = get_private (mount);
1025 priv->shadow_ref_count -= 1;
1026 if (priv->shadow_ref_count < 0)
1027 g_warning ("Shadow ref count on GMount is negative");
1028 G_UNLOCK (priv_lock);
1032 * g_mount_get_sort_key:
1033 * @mount: A #GMount.
1035 * Gets the sort key for @mount, if any.
1037 * Returns: Sorting key for @mount or %NULL if no such key is available.
1042 g_mount_get_sort_key (GMount *mount)
1044 const gchar *ret = NULL;
1047 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
1049 iface = G_MOUNT_GET_IFACE (mount);
1050 if (iface->get_sort_key != NULL)
1051 ret = iface->get_sort_key (mount);