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
),
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 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
),
117 g_cclosure_marshal_VOID__VOID
,
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: the UUID for @mount or %NULL if no UUID can be computed.
259 * The returned string should be freed with g_free()
260 * when no longer needed.
263 g_mount_get_uuid (GMount
*mount
)
267 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
269 iface
= G_MOUNT_GET_IFACE (mount
);
271 return (* iface
->get_uuid
) (mount
);
275 * g_mount_get_volume:
278 * Gets the volume for the @mount.
280 * Returns: (transfer full): a #GVolume or %NULL if @mount is not associated with a volume.
281 * The returned object should be unreffed with
282 * g_object_unref() when no longer needed.
285 g_mount_get_volume (GMount
*mount
)
289 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
291 iface
= G_MOUNT_GET_IFACE (mount
);
293 return (* iface
->get_volume
) (mount
);
300 * Gets the drive for the @mount.
302 * This is a convenience method for getting the #GVolume and then
303 * using that object to get the #GDrive.
305 * Returns: (transfer full): a #GDrive or %NULL if @mount is not associated with a volume or a drive.
306 * The returned object should be unreffed with
307 * g_object_unref() when no longer needed.
310 g_mount_get_drive (GMount
*mount
)
314 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
316 iface
= G_MOUNT_GET_IFACE (mount
);
318 return (* iface
->get_drive
) (mount
);
322 * g_mount_can_unmount:
325 * Checks if @mount can be unmounted.
327 * Returns: %TRUE if the @mount can be unmounted.
330 g_mount_can_unmount (GMount
*mount
)
334 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
336 iface
= G_MOUNT_GET_IFACE (mount
);
338 return (* iface
->can_unmount
) (mount
);
345 * Checks if @mount can be ejected.
347 * Returns: %TRUE if the @mount can be ejected.
350 g_mount_can_eject (GMount
*mount
)
354 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
356 iface
= G_MOUNT_GET_IFACE (mount
);
358 return (* iface
->can_eject
) (mount
);
364 * @flags: flags affecting the operation
365 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
366 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
367 * @user_data: user data passed to @callback.
369 * Unmounts a mount. This is an asynchronous operation, and is
370 * finished by calling g_mount_unmount_finish() with the @mount
371 * and #GAsyncResult data returned in the @callback.
373 * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead.
376 g_mount_unmount (GMount
*mount
,
377 GMountUnmountFlags flags
,
378 GCancellable
*cancellable
,
379 GAsyncReadyCallback callback
,
384 g_return_if_fail (G_IS_MOUNT (mount
));
386 iface
= G_MOUNT_GET_IFACE (mount
);
388 if (iface
->unmount
== NULL
)
390 g_task_report_new_error (mount
, callback
, user_data
,
391 g_mount_unmount_with_operation
,
392 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
393 /* Translators: This is an error
394 * message for mount objects that
395 * don't implement unmount. */
396 _("mount doesn’t implement “unmount”"));
400 (* iface
->unmount
) (mount
, flags
, cancellable
, callback
, user_data
);
404 * g_mount_unmount_finish:
406 * @result: a #GAsyncResult.
407 * @error: a #GError location to store the error occurring, or %NULL to
410 * Finishes unmounting a mount. If any errors occurred during the operation,
411 * @error will be set to contain the errors and %FALSE will be returned.
413 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
415 * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead.
418 g_mount_unmount_finish (GMount
*mount
,
419 GAsyncResult
*result
,
424 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
425 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
427 if (g_async_result_legacy_propagate_error (result
, error
))
429 else if (g_async_result_is_tagged (result
, g_mount_unmount_with_operation
))
430 return g_task_propagate_boolean (G_TASK (result
), error
);
432 iface
= G_MOUNT_GET_IFACE (mount
);
433 return (* iface
->unmount_finish
) (mount
, result
, error
);
440 * @flags: flags affecting the unmount if required for eject
441 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
442 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
443 * @user_data: user data passed to @callback.
445 * Ejects a mount. This is an asynchronous operation, and is
446 * finished by calling g_mount_eject_finish() with the @mount
447 * and #GAsyncResult data returned in the @callback.
449 * Deprecated: 2.22: Use g_mount_eject_with_operation() instead.
452 g_mount_eject (GMount
*mount
,
453 GMountUnmountFlags flags
,
454 GCancellable
*cancellable
,
455 GAsyncReadyCallback callback
,
460 g_return_if_fail (G_IS_MOUNT (mount
));
462 iface
= G_MOUNT_GET_IFACE (mount
);
464 if (iface
->eject
== NULL
)
466 g_task_report_new_error (mount
, callback
, user_data
,
467 g_mount_eject_with_operation
,
468 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
469 /* Translators: This is an error
470 * message for mount objects that
471 * don't implement eject. */
472 _("mount doesn’t implement “eject”"));
476 (* iface
->eject
) (mount
, flags
, cancellable
, callback
, user_data
);
480 * g_mount_eject_finish:
482 * @result: a #GAsyncResult.
483 * @error: a #GError location to store the error occurring, or %NULL to
486 * Finishes ejecting a mount. If any errors occurred during the operation,
487 * @error will be set to contain the errors and %FALSE will be returned.
489 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
491 * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead.
494 g_mount_eject_finish (GMount
*mount
,
495 GAsyncResult
*result
,
500 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
501 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
503 if (g_async_result_legacy_propagate_error (result
, error
))
505 else if (g_async_result_is_tagged (result
, g_mount_eject_with_operation
))
506 return g_task_propagate_boolean (G_TASK (result
), error
);
508 iface
= G_MOUNT_GET_IFACE (mount
);
509 return (* iface
->eject_finish
) (mount
, result
, error
);
513 * g_mount_unmount_with_operation:
515 * @flags: flags affecting the operation
516 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
518 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
519 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
520 * @user_data: user data passed to @callback.
522 * Unmounts a mount. This is an asynchronous operation, and is
523 * finished by calling g_mount_unmount_with_operation_finish() with the @mount
524 * and #GAsyncResult data returned in the @callback.
529 g_mount_unmount_with_operation (GMount
*mount
,
530 GMountUnmountFlags flags
,
531 GMountOperation
*mount_operation
,
532 GCancellable
*cancellable
,
533 GAsyncReadyCallback callback
,
538 g_return_if_fail (G_IS_MOUNT (mount
));
540 iface
= G_MOUNT_GET_IFACE (mount
);
542 if (iface
->unmount
== NULL
&& iface
->unmount_with_operation
== NULL
)
544 g_task_report_new_error (mount
, callback
, user_data
,
545 g_mount_unmount_with_operation
,
546 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
547 /* Translators: This is an error
548 * message for mount objects that
549 * don't implement any of unmount or unmount_with_operation. */
550 _("mount doesn’t implement “unmount” or “unmount_with_operation”"));
554 if (iface
->unmount_with_operation
!= NULL
)
555 (* iface
->unmount_with_operation
) (mount
, flags
, mount_operation
, cancellable
, callback
, user_data
);
557 (* iface
->unmount
) (mount
, flags
, cancellable
, callback
, user_data
);
561 * g_mount_unmount_with_operation_finish:
563 * @result: a #GAsyncResult.
564 * @error: a #GError location to store the error occurring, or %NULL to
567 * Finishes unmounting a mount. If any errors occurred during the operation,
568 * @error will be set to contain the errors and %FALSE will be returned.
570 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
575 g_mount_unmount_with_operation_finish (GMount
*mount
,
576 GAsyncResult
*result
,
581 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
582 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
584 if (g_async_result_legacy_propagate_error (result
, error
))
586 else if (g_async_result_is_tagged (result
, g_mount_unmount_with_operation
))
587 return g_task_propagate_boolean (G_TASK (result
), error
);
589 iface
= G_MOUNT_GET_IFACE (mount
);
590 if (iface
->unmount_with_operation_finish
!= NULL
)
591 return (* iface
->unmount_with_operation_finish
) (mount
, result
, error
);
593 return (* iface
->unmount_finish
) (mount
, result
, error
);
598 * g_mount_eject_with_operation:
600 * @flags: flags affecting the unmount if required for eject
601 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
603 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
604 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
605 * @user_data: user data passed to @callback.
607 * Ejects a mount. This is an asynchronous operation, and is
608 * finished by calling g_mount_eject_with_operation_finish() with the @mount
609 * and #GAsyncResult data returned in the @callback.
614 g_mount_eject_with_operation (GMount
*mount
,
615 GMountUnmountFlags flags
,
616 GMountOperation
*mount_operation
,
617 GCancellable
*cancellable
,
618 GAsyncReadyCallback callback
,
623 g_return_if_fail (G_IS_MOUNT (mount
));
625 iface
= G_MOUNT_GET_IFACE (mount
);
627 if (iface
->eject
== NULL
&& iface
->eject_with_operation
== NULL
)
629 g_task_report_new_error (mount
, callback
, user_data
,
630 g_mount_eject_with_operation
,
631 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
632 /* Translators: This is an error
633 * message for mount objects that
634 * don't implement any of eject or eject_with_operation. */
635 _("mount doesn’t implement “eject” or “eject_with_operation”"));
639 if (iface
->eject_with_operation
!= NULL
)
640 (* iface
->eject_with_operation
) (mount
, flags
, mount_operation
, cancellable
, callback
, user_data
);
642 (* iface
->eject
) (mount
, flags
, cancellable
, callback
, user_data
);
646 * g_mount_eject_with_operation_finish:
648 * @result: a #GAsyncResult.
649 * @error: a #GError location to store the error occurring, or %NULL to
652 * Finishes ejecting a mount. If any errors occurred during the operation,
653 * @error will be set to contain the errors and %FALSE will be returned.
655 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
660 g_mount_eject_with_operation_finish (GMount
*mount
,
661 GAsyncResult
*result
,
666 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
667 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
669 if (g_async_result_legacy_propagate_error (result
, error
))
671 else if (g_async_result_is_tagged (result
, g_mount_eject_with_operation
))
672 return g_task_propagate_boolean (G_TASK (result
), error
);
674 iface
= G_MOUNT_GET_IFACE (mount
);
675 if (iface
->eject_with_operation_finish
!= NULL
)
676 return (* iface
->eject_with_operation_finish
) (mount
, result
, error
);
678 return (* iface
->eject_finish
) (mount
, result
, error
);
684 * @flags: flags affecting the operation
685 * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid
687 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
688 * @callback: (nullable): a #GAsyncReadyCallback, or %NULL.
689 * @user_data: user data passed to @callback.
691 * Remounts a mount. This is an asynchronous operation, and is
692 * finished by calling g_mount_remount_finish() with the @mount
693 * and #GAsyncResults data returned in the @callback.
695 * Remounting is useful when some setting affecting the operation
696 * of the volume has been changed, as these may need a remount to
697 * take affect. While this is semantically equivalent with unmounting
698 * and then remounting not all backends might need to actually be
702 g_mount_remount (GMount
*mount
,
703 GMountMountFlags flags
,
704 GMountOperation
*mount_operation
,
705 GCancellable
*cancellable
,
706 GAsyncReadyCallback callback
,
711 g_return_if_fail (G_IS_MOUNT (mount
));
713 iface
= G_MOUNT_GET_IFACE (mount
);
715 if (iface
->remount
== NULL
)
717 g_task_report_new_error (mount
, callback
, user_data
,
719 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
720 /* Translators: This is an error
721 * message for mount objects that
722 * don't implement remount. */
723 _("mount doesn’t implement “remount”"));
727 (* iface
->remount
) (mount
, flags
, mount_operation
, cancellable
, callback
, user_data
);
731 * g_mount_remount_finish:
733 * @result: a #GAsyncResult.
734 * @error: a #GError location to store the error occurring, or %NULL to
737 * Finishes remounting a mount. If any errors occurred during the operation,
738 * @error will be set to contain the errors and %FALSE will be returned.
740 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
743 g_mount_remount_finish (GMount
*mount
,
744 GAsyncResult
*result
,
749 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
750 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
752 if (g_async_result_legacy_propagate_error (result
, error
))
754 else if (g_async_result_is_tagged (result
, g_mount_remount
))
755 return g_task_propagate_boolean (G_TASK (result
), error
);
757 iface
= G_MOUNT_GET_IFACE (mount
);
758 return (* iface
->remount_finish
) (mount
, result
, error
);
762 * g_mount_guess_content_type:
764 * @force_rescan: Whether to force a rescan of the content.
765 * Otherwise a cached result will be used if available
766 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
767 * @callback: a #GAsyncReadyCallback
768 * @user_data: user data passed to @callback
770 * Tries to guess the type of content stored on @mount. Returns one or
771 * more textual identifiers of well-known content types (typically
772 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
773 * memory cards. See the
774 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
775 * specification for more on x-content types.
777 * This is an asynchronous operation (see
778 * g_mount_guess_content_type_sync() for the synchronous version), and
779 * is finished by calling g_mount_guess_content_type_finish() with the
780 * @mount and #GAsyncResult data returned in the @callback.
785 g_mount_guess_content_type (GMount
*mount
,
786 gboolean force_rescan
,
787 GCancellable
*cancellable
,
788 GAsyncReadyCallback callback
,
793 g_return_if_fail (G_IS_MOUNT (mount
));
795 iface
= G_MOUNT_GET_IFACE (mount
);
797 if (iface
->guess_content_type
== NULL
)
799 g_task_report_new_error (mount
, callback
, user_data
,
800 g_mount_guess_content_type
,
801 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
802 /* Translators: This is an error
803 * message for mount objects that
804 * don't implement content type guessing. */
805 _("mount doesn’t implement content type guessing"));
809 (* iface
->guess_content_type
) (mount
, force_rescan
, cancellable
, callback
, user_data
);
813 * g_mount_guess_content_type_finish:
815 * @result: a #GAsyncResult
816 * @error: a #GError location to store the error occurring, or %NULL to
819 * Finishes guessing content types of @mount. If any errors occurred
820 * during the operation, @error will be set to contain the errors and
821 * %FALSE will be returned. In particular, you may get an
822 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content
825 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
826 * Caller should free this array with g_strfreev() when done with it.
831 g_mount_guess_content_type_finish (GMount
*mount
,
832 GAsyncResult
*result
,
837 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
838 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), NULL
);
840 if (g_async_result_legacy_propagate_error (result
, error
))
842 else if (g_async_result_is_tagged (result
, g_mount_guess_content_type
))
843 return g_task_propagate_pointer (G_TASK (result
), error
);
845 iface
= G_MOUNT_GET_IFACE (mount
);
846 return (* iface
->guess_content_type_finish
) (mount
, result
, error
);
850 * g_mount_guess_content_type_sync:
852 * @force_rescan: Whether to force a rescan of the content.
853 * Otherwise a cached result will be used if available
854 * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore
855 * @error: a #GError location to store the error occurring, or %NULL to
858 * Tries to guess the type of content stored on @mount. Returns one or
859 * more textual identifiers of well-known content types (typically
860 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
861 * memory cards. See the
862 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
863 * specification for more on x-content types.
865 * This is an synchronous operation and as such may block doing IO;
866 * see g_mount_guess_content_type() for the asynchronous version.
868 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
869 * Caller should free this array with g_strfreev() when done with it.
874 g_mount_guess_content_type_sync (GMount
*mount
,
875 gboolean force_rescan
,
876 GCancellable
*cancellable
,
881 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
883 iface
= G_MOUNT_GET_IFACE (mount
);
885 if (iface
->guess_content_type_sync
== NULL
)
887 g_set_error_literal (error
,
888 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
889 /* Translators: This is an error
890 * message for mount objects that
891 * don't implement content type guessing. */
892 _("mount doesn’t implement synchronous content type guessing"));
897 return (* iface
->guess_content_type_sync
) (mount
, force_rescan
, cancellable
, error
);
900 G_LOCK_DEFINE_STATIC (priv_lock
);
902 /* only access this structure when holding priv_lock */
905 gint shadow_ref_count
;
909 free_private (GMountPrivate
*private)
913 G_UNLOCK (priv_lock
);
916 /* may only be called when holding priv_lock */
917 static GMountPrivate
*
918 get_private (GMount
*mount
)
920 GMountPrivate
*private;
922 private = g_object_get_data (G_OBJECT (mount
), "g-mount-private");
923 if (G_LIKELY (private != NULL
))
926 private = g_new0 (GMountPrivate
, 1);
927 g_object_set_data_full (G_OBJECT (mount
),
930 (GDestroyNotify
) free_private
);
937 * g_mount_is_shadowed:
940 * Determines if @mount is shadowed. Applications or libraries should
941 * avoid displaying @mount in the user interface if it is shadowed.
943 * A mount is said to be shadowed if there exists one or more user
944 * visible objects (currently #GMount objects) with a root that is
945 * inside the root of @mount.
947 * One application of shadow mounts is when exposing a single file
948 * system that is used to address several logical volumes. In this
949 * situation, a #GVolumeMonitor implementation would create two
950 * #GVolume objects (for example, one for the camera functionality of
951 * the device and one for a SD card reader on the device) with
952 * activation URIs `gphoto2://[usb:001,002]/store1/`
953 * and `gphoto2://[usb:001,002]/store2/`. When the
954 * underlying mount (with root
955 * `gphoto2://[usb:001,002]/`) is mounted, said
956 * #GVolumeMonitor implementation would create two #GMount objects
957 * (each with their root matching the corresponding volume activation
958 * root) that would shadow the original mount.
960 * The proxy monitor in GVfs 2.26 and later, automatically creates and
961 * manage shadow mounts (and shadows the underlying mount) if the
962 * activation root on a #GVolume is set.
964 * Returns: %TRUE if @mount is shadowed.
969 g_mount_is_shadowed (GMount
*mount
)
974 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
977 priv
= get_private (mount
);
978 ret
= (priv
->shadow_ref_count
> 0);
979 G_UNLOCK (priv_lock
);
988 * Increments the shadow count on @mount. Usually used by
989 * #GVolumeMonitor implementations when creating a shadow mount for
990 * @mount, see g_mount_is_shadowed() for more information. The caller
991 * will need to emit the #GMount::changed signal on @mount manually.
996 g_mount_shadow (GMount
*mount
)
1000 g_return_if_fail (G_IS_MOUNT (mount
));
1003 priv
= get_private (mount
);
1004 priv
->shadow_ref_count
+= 1;
1005 G_UNLOCK (priv_lock
);
1010 * @mount: A #GMount.
1012 * Decrements the shadow count on @mount. Usually used by
1013 * #GVolumeMonitor implementations when destroying a shadow mount for
1014 * @mount, see g_mount_is_shadowed() for more information. The caller
1015 * will need to emit the #GMount::changed signal on @mount manually.
1020 g_mount_unshadow (GMount
*mount
)
1022 GMountPrivate
*priv
;
1024 g_return_if_fail (G_IS_MOUNT (mount
));
1027 priv
= get_private (mount
);
1028 priv
->shadow_ref_count
-= 1;
1029 if (priv
->shadow_ref_count
< 0)
1030 g_warning ("Shadow ref count on GMount is negative");
1031 G_UNLOCK (priv_lock
);
1035 * g_mount_get_sort_key:
1036 * @mount: A #GMount.
1038 * Gets the sort key for @mount, if any.
1040 * Returns: Sorting key for @mount or %NULL if no such key is available.
1045 g_mount_get_sort_key (GMount
*mount
)
1047 const gchar
*ret
= NULL
;
1050 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
1052 iface
= G_MOUNT_GET_IFACE (mount
);
1053 if (iface
->get_sort_key
!= NULL
)
1054 ret
= iface
->get_sort_key (mount
);