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, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
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 * #GAsyncReady 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 #GAsyncReady 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
),
83 g_cclosure_marshal_VOID__VOID
,
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
),
100 g_cclosure_marshal_VOID__VOID
,
103 * GMount::pre-unmount:
104 * @mount: the object on which the signal is emitted
106 * This signal is emitted when the #GMount is about to be
111 g_signal_new (I_("pre-unmount"),
114 G_STRUCT_OFFSET (GMountIface
, pre_unmount
),
116 g_cclosure_marshal_VOID__VOID
,
124 * Gets the root directory on @mount.
126 * Returns: (transfer full): a #GFile.
127 * The returned object should be unreffed with
128 * g_object_unref() when no longer needed.
131 g_mount_get_root (GMount
*mount
)
135 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
137 iface
= G_MOUNT_GET_IFACE (mount
);
139 return (* iface
->get_root
) (mount
);
143 * g_mount_get_default_location:
146 * Gets the default location of @mount. The default location of the given
147 * @mount is a path that reflects the main entry point for the user (e.g.
148 * the home directory, or the root of the volume).
150 * Returns: (transfer full): a #GFile.
151 * The returned object should be unreffed with
152 * g_object_unref() when no longer needed.
155 g_mount_get_default_location (GMount
*mount
)
160 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
162 iface
= G_MOUNT_GET_IFACE (mount
);
164 /* Fallback to get_root when default_location () is not available */
165 if (iface
->get_default_location
)
166 file
= (* iface
->get_default_location
) (mount
);
168 file
= (* iface
->get_root
) (mount
);
177 * Gets the name of @mount.
179 * Returns: the name for the given @mount.
180 * The returned string should be freed with g_free()
181 * when no longer needed.
184 g_mount_get_name (GMount
*mount
)
188 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
190 iface
= G_MOUNT_GET_IFACE (mount
);
192 return (* iface
->get_name
) (mount
);
199 * Gets the icon for @mount.
201 * Returns: (transfer full): a #GIcon.
202 * The returned object should be unreffed with
203 * g_object_unref() when no longer needed.
206 g_mount_get_icon (GMount
*mount
)
210 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
212 iface
= G_MOUNT_GET_IFACE (mount
);
214 return (* iface
->get_icon
) (mount
);
219 * g_mount_get_symbolic_icon:
222 * Gets the symbolic icon for @mount.
224 * Returns: (transfer full): a #GIcon.
225 * The returned object should be unreffed with
226 * g_object_unref() when no longer needed.
231 g_mount_get_symbolic_icon (GMount
*mount
)
236 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
238 iface
= G_MOUNT_GET_IFACE (mount
);
240 if (iface
->get_symbolic_icon
!= NULL
)
241 ret
= iface
->get_symbolic_icon (mount
);
243 ret
= g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic");
252 * Gets the UUID for the @mount. The reference is typically based on
253 * the file system UUID for the mount in question and should be
254 * considered an opaque string. Returns %NULL if there is no UUID
257 * Returns: the UUID for @mount or %NULL if no UUID can be computed.
258 * The returned string should be freed with g_free()
259 * when no longer needed.
262 g_mount_get_uuid (GMount
*mount
)
266 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
268 iface
= G_MOUNT_GET_IFACE (mount
);
270 return (* iface
->get_uuid
) (mount
);
274 * g_mount_get_volume:
277 * Gets the volume for the @mount.
279 * Returns: (transfer full): a #GVolume or %NULL if @mount is not associated with a volume.
280 * The returned object should be unreffed with
281 * g_object_unref() when no longer needed.
284 g_mount_get_volume (GMount
*mount
)
288 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
290 iface
= G_MOUNT_GET_IFACE (mount
);
292 return (* iface
->get_volume
) (mount
);
299 * Gets the drive for the @mount.
301 * This is a convenience method for getting the #GVolume and then
302 * using that object to get the #GDrive.
304 * Returns: (transfer full): a #GDrive or %NULL if @mount is not associated with a volume or a drive.
305 * The returned object should be unreffed with
306 * g_object_unref() when no longer needed.
309 g_mount_get_drive (GMount
*mount
)
313 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
315 iface
= G_MOUNT_GET_IFACE (mount
);
317 return (* iface
->get_drive
) (mount
);
321 * g_mount_can_unmount:
324 * Checks if @mount can be mounted.
326 * Returns: %TRUE if the @mount can be unmounted.
329 g_mount_can_unmount (GMount
*mount
)
333 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
335 iface
= G_MOUNT_GET_IFACE (mount
);
337 return (* iface
->can_unmount
) (mount
);
344 * Checks if @mount can be eject.
346 * Returns: %TRUE if the @mount can be ejected.
349 g_mount_can_eject (GMount
*mount
)
353 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
355 iface
= G_MOUNT_GET_IFACE (mount
);
357 return (* iface
->can_eject
) (mount
);
363 * @flags: flags affecting the operation
364 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
365 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
366 * @user_data: user data passed to @callback.
368 * Unmounts a mount. This is an asynchronous operation, and is
369 * finished by calling g_mount_unmount_finish() with the @mount
370 * and #GAsyncResult data returned in the @callback.
372 * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead.
375 g_mount_unmount (GMount
*mount
,
376 GMountUnmountFlags flags
,
377 GCancellable
*cancellable
,
378 GAsyncReadyCallback callback
,
383 g_return_if_fail (G_IS_MOUNT (mount
));
385 iface
= G_MOUNT_GET_IFACE (mount
);
387 if (iface
->unmount
== NULL
)
389 g_task_report_new_error (mount
, callback
, user_data
,
390 g_mount_unmount_with_operation
,
391 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
392 /* Translators: This is an error
393 * message for mount objects that
394 * don't implement unmount. */
395 _("mount doesn't implement \"unmount\""));
399 (* iface
->unmount
) (mount
, flags
, cancellable
, callback
, user_data
);
403 * g_mount_unmount_finish:
405 * @result: a #GAsyncResult.
406 * @error: a #GError location to store the error occurring, or %NULL to
409 * Finishes unmounting a mount. If any errors occurred during the operation,
410 * @error will be set to contain the errors and %FALSE will be returned.
412 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
414 * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead.
417 g_mount_unmount_finish (GMount
*mount
,
418 GAsyncResult
*result
,
423 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
424 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
426 if (g_async_result_legacy_propagate_error (result
, error
))
428 else if (g_async_result_is_tagged (result
, g_mount_unmount_with_operation
))
429 return g_task_propagate_boolean (G_TASK (result
), error
);
431 iface
= G_MOUNT_GET_IFACE (mount
);
432 return (* iface
->unmount_finish
) (mount
, result
, error
);
439 * @flags: flags affecting the unmount if required for eject
440 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
441 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
442 * @user_data: user data passed to @callback.
444 * Ejects a mount. This is an asynchronous operation, and is
445 * finished by calling g_mount_eject_finish() with the @mount
446 * and #GAsyncResult data returned in the @callback.
448 * Deprecated: 2.22: Use g_mount_eject_with_operation() instead.
451 g_mount_eject (GMount
*mount
,
452 GMountUnmountFlags flags
,
453 GCancellable
*cancellable
,
454 GAsyncReadyCallback callback
,
459 g_return_if_fail (G_IS_MOUNT (mount
));
461 iface
= G_MOUNT_GET_IFACE (mount
);
463 if (iface
->eject
== NULL
)
465 g_task_report_new_error (mount
, callback
, user_data
,
466 g_mount_eject_with_operation
,
467 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
468 /* Translators: This is an error
469 * message for mount objects that
470 * don't implement eject. */
471 _("mount doesn't implement \"eject\""));
475 (* iface
->eject
) (mount
, flags
, cancellable
, callback
, user_data
);
479 * g_mount_eject_finish:
481 * @result: a #GAsyncResult.
482 * @error: a #GError location to store the error occurring, or %NULL to
485 * Finishes ejecting a mount. If any errors occurred during the operation,
486 * @error will be set to contain the errors and %FALSE will be returned.
488 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
490 * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead.
493 g_mount_eject_finish (GMount
*mount
,
494 GAsyncResult
*result
,
499 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
500 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
502 if (g_async_result_legacy_propagate_error (result
, error
))
504 else if (g_async_result_is_tagged (result
, g_mount_eject_with_operation
))
505 return g_task_propagate_boolean (G_TASK (result
), error
);
507 iface
= G_MOUNT_GET_IFACE (mount
);
508 return (* iface
->eject_finish
) (mount
, result
, error
);
512 * g_mount_unmount_with_operation:
514 * @flags: flags affecting the operation
515 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
517 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
518 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
519 * @user_data: user data passed to @callback.
521 * Unmounts a mount. This is an asynchronous operation, and is
522 * finished by calling g_mount_unmount_with_operation_finish() with the @mount
523 * and #GAsyncResult data returned in the @callback.
528 g_mount_unmount_with_operation (GMount
*mount
,
529 GMountUnmountFlags flags
,
530 GMountOperation
*mount_operation
,
531 GCancellable
*cancellable
,
532 GAsyncReadyCallback callback
,
537 g_return_if_fail (G_IS_MOUNT (mount
));
539 iface
= G_MOUNT_GET_IFACE (mount
);
541 if (iface
->unmount
== NULL
&& iface
->unmount_with_operation
== NULL
)
543 g_task_report_new_error (mount
, callback
, user_data
,
544 g_mount_unmount_with_operation
,
545 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
546 /* Translators: This is an error
547 * message for mount objects that
548 * don't implement any of unmount or unmount_with_operation. */
549 _("mount doesn't implement \"unmount\" or \"unmount_with_operation\""));
553 if (iface
->unmount_with_operation
!= NULL
)
554 (* iface
->unmount_with_operation
) (mount
, flags
, mount_operation
, cancellable
, callback
, user_data
);
556 (* iface
->unmount
) (mount
, flags
, cancellable
, callback
, user_data
);
560 * g_mount_unmount_with_operation_finish:
562 * @result: a #GAsyncResult.
563 * @error: a #GError location to store the error occurring, or %NULL to
566 * Finishes unmounting a mount. If any errors occurred during the operation,
567 * @error will be set to contain the errors and %FALSE will be returned.
569 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
574 g_mount_unmount_with_operation_finish (GMount
*mount
,
575 GAsyncResult
*result
,
580 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
581 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
583 if (g_async_result_legacy_propagate_error (result
, error
))
585 else if (g_async_result_is_tagged (result
, g_mount_unmount_with_operation
))
586 return g_task_propagate_boolean (G_TASK (result
), error
);
588 iface
= G_MOUNT_GET_IFACE (mount
);
589 if (iface
->unmount_with_operation_finish
!= NULL
)
590 return (* iface
->unmount_with_operation_finish
) (mount
, result
, error
);
592 return (* iface
->unmount_finish
) (mount
, result
, error
);
597 * g_mount_eject_with_operation:
599 * @flags: flags affecting the unmount if required for eject
600 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
602 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
603 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
604 * @user_data: user data passed to @callback.
606 * Ejects a mount. This is an asynchronous operation, and is
607 * finished by calling g_mount_eject_with_operation_finish() with the @mount
608 * and #GAsyncResult data returned in the @callback.
613 g_mount_eject_with_operation (GMount
*mount
,
614 GMountUnmountFlags flags
,
615 GMountOperation
*mount_operation
,
616 GCancellable
*cancellable
,
617 GAsyncReadyCallback callback
,
622 g_return_if_fail (G_IS_MOUNT (mount
));
624 iface
= G_MOUNT_GET_IFACE (mount
);
626 if (iface
->eject
== NULL
&& iface
->eject_with_operation
== NULL
)
628 g_task_report_new_error (mount
, callback
, user_data
,
629 g_mount_eject_with_operation
,
630 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
631 /* Translators: This is an error
632 * message for mount objects that
633 * don't implement any of eject or eject_with_operation. */
634 _("mount doesn't implement \"eject\" or \"eject_with_operation\""));
638 if (iface
->eject_with_operation
!= NULL
)
639 (* iface
->eject_with_operation
) (mount
, flags
, mount_operation
, cancellable
, callback
, user_data
);
641 (* iface
->eject
) (mount
, flags
, cancellable
, callback
, user_data
);
645 * g_mount_eject_with_operation_finish:
647 * @result: a #GAsyncResult.
648 * @error: a #GError location to store the error occurring, or %NULL to
651 * Finishes ejecting a mount. If any errors occurred during the operation,
652 * @error will be set to contain the errors and %FALSE will be returned.
654 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
659 g_mount_eject_with_operation_finish (GMount
*mount
,
660 GAsyncResult
*result
,
665 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
666 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
668 if (g_async_result_legacy_propagate_error (result
, error
))
670 else if (g_async_result_is_tagged (result
, g_mount_eject_with_operation
))
671 return g_task_propagate_boolean (G_TASK (result
), error
);
673 iface
= G_MOUNT_GET_IFACE (mount
);
674 if (iface
->eject_with_operation_finish
!= NULL
)
675 return (* iface
->eject_with_operation_finish
) (mount
, result
, error
);
677 return (* iface
->eject_finish
) (mount
, result
, error
);
683 * @flags: flags affecting the operation
684 * @mount_operation: (allow-none): a #GMountOperation or %NULL to avoid
686 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
687 * @callback: (allow-none): a #GAsyncReadyCallback, or %NULL.
688 * @user_data: user data passed to @callback.
690 * Remounts a mount. This is an asynchronous operation, and is
691 * finished by calling g_mount_remount_finish() with the @mount
692 * and #GAsyncResults data returned in the @callback.
694 * Remounting is useful when some setting affecting the operation
695 * of the volume has been changed, as these may need a remount to
696 * take affect. While this is semantically equivalent with unmounting
697 * and then remounting not all backends might need to actually be
701 g_mount_remount (GMount
*mount
,
702 GMountMountFlags flags
,
703 GMountOperation
*mount_operation
,
704 GCancellable
*cancellable
,
705 GAsyncReadyCallback callback
,
710 g_return_if_fail (G_IS_MOUNT (mount
));
712 iface
= G_MOUNT_GET_IFACE (mount
);
714 if (iface
->remount
== NULL
)
716 g_task_report_new_error (mount
, callback
, user_data
,
718 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
719 /* Translators: This is an error
720 * message for mount objects that
721 * don't implement remount. */
722 _("mount doesn't implement \"remount\""));
726 (* iface
->remount
) (mount
, flags
, mount_operation
, cancellable
, callback
, user_data
);
730 * g_mount_remount_finish:
732 * @result: a #GAsyncResult.
733 * @error: a #GError location to store the error occurring, or %NULL to
736 * Finishes remounting a mount. If any errors occurred during the operation,
737 * @error will be set to contain the errors and %FALSE will be returned.
739 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
742 g_mount_remount_finish (GMount
*mount
,
743 GAsyncResult
*result
,
748 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
749 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
751 if (g_async_result_legacy_propagate_error (result
, error
))
753 else if (g_async_result_is_tagged (result
, g_mount_remount
))
754 return g_task_propagate_boolean (G_TASK (result
), error
);
756 iface
= G_MOUNT_GET_IFACE (mount
);
757 return (* iface
->remount_finish
) (mount
, result
, error
);
761 * g_mount_guess_content_type:
763 * @force_rescan: Whether to force a rescan of the content.
764 * Otherwise a cached result will be used if available
765 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
766 * @callback: a #GAsyncReadyCallback
767 * @user_data: user data passed to @callback
769 * Tries to guess the type of content stored on @mount. Returns one or
770 * more textual identifiers of well-known content types (typically
771 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
772 * memory cards. See the <ulink url="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</ulink>
773 * specification for more on x-content types.
775 * This is an asynchronous operation (see
776 * g_mount_guess_content_type_sync() for the synchronous version), and
777 * is finished by calling g_mount_guess_content_type_finish() with the
778 * @mount and #GAsyncResult data returned in the @callback.
783 g_mount_guess_content_type (GMount
*mount
,
784 gboolean force_rescan
,
785 GCancellable
*cancellable
,
786 GAsyncReadyCallback callback
,
791 g_return_if_fail (G_IS_MOUNT (mount
));
793 iface
= G_MOUNT_GET_IFACE (mount
);
795 if (iface
->guess_content_type
== NULL
)
797 g_task_report_new_error (mount
, callback
, user_data
,
798 g_mount_guess_content_type
,
799 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
800 /* Translators: This is an error
801 * message for mount objects that
802 * don't implement content type guessing. */
803 _("mount doesn't implement content type guessing"));
807 (* iface
->guess_content_type
) (mount
, force_rescan
, cancellable
, callback
, user_data
);
811 * g_mount_guess_content_type_finish:
813 * @result: a #GAsyncResult
814 * @error: a #GError location to store the error occurring, or %NULL to
817 * Finishes guessing content types of @mount. If any errors occurred
818 * during the operation, @error will be set to contain the errors and
819 * %FALSE will be returned. In particular, you may get an
820 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content
823 * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error.
824 * Caller should free this array with g_strfreev() when done with it.
829 g_mount_guess_content_type_finish (GMount
*mount
,
830 GAsyncResult
*result
,
835 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
836 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), NULL
);
838 if (g_async_result_legacy_propagate_error (result
, error
))
840 else if (g_async_result_is_tagged (result
, g_mount_guess_content_type
))
841 return g_task_propagate_pointer (G_TASK (result
), error
);
843 iface
= G_MOUNT_GET_IFACE (mount
);
844 return (* iface
->guess_content_type_finish
) (mount
, result
, error
);
848 * g_mount_guess_content_type_sync:
850 * @force_rescan: Whether to force a rescan of the content.
851 * Otherwise a cached result will be used if available
852 * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
853 * @error: a #GError location to store the error occurring, or %NULL to
856 * Tries to guess the type of content stored on @mount. Returns one or
857 * more textual identifiers of well-known content types (typically
858 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
859 * memory cards. See the <ulink url="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</ulink>
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 <literal>gphoto2://[usb:001,002]/store1/</literal>
950 * and <literal>gphoto2://[usb:001,002]/store2/</literal>. When the
951 * underlying mount (with root
952 * <literal>gphoto2://[usb:001,002]/</literal>) 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
);