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 "gasyncresult.h"
33 #include "gsimpleasyncresult.h"
41 * @short_description: Mount management
43 * @see also: GVolume, GUnixMount
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 #GAsyncReady
55 * and #GSimpleAsyncReady. To unmount a #GMount instance, first call
56 * g_mount_unmount() 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_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_finish()
63 * is called, then it will be filled with any error information.
66 static void g_mount_base_init (gpointer g_class);
67 static void g_mount_class_init (gpointer g_class,
71 g_mount_get_type (void)
73 static GType mount_type = 0;
77 static const GTypeInfo mount_info =
79 sizeof (GMountIface), /* class_size */
80 g_mount_base_init, /* base_init */
81 NULL, /* base_finalize */
83 NULL, /* class_finalize */
84 NULL, /* class_data */
91 g_type_register_static (G_TYPE_INTERFACE, I_("GMount"),
94 g_type_interface_add_prerequisite (mount_type, G_TYPE_OBJECT);
101 g_mount_class_init (gpointer g_class,
107 g_mount_base_init (gpointer g_class)
109 static gboolean initialized = FALSE;
116 * Emitted when the mount has been changed.
118 g_signal_new (I_("changed"),
121 G_STRUCT_OFFSET (GMountIface, changed),
123 g_cclosure_marshal_VOID__VOID,
129 * This signal is emitted when the #GMount have been
130 * unmounted. If the recipient is holding references to the
131 * object they should release them so the object can be
134 g_signal_new (I_("unmounted"),
137 G_STRUCT_OFFSET (GMountIface, unmounted),
139 g_cclosure_marshal_VOID__VOID,
150 * Gets the root directory on @mount.
153 * The returned object should be unreffed with
154 * g_object_unref() when no longer needed.
157 g_mount_get_root (GMount *mount)
161 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
163 iface = G_MOUNT_GET_IFACE (mount);
165 return (* iface->get_root) (mount);
172 * Gets the name of @mount.
174 * Returns: the name for the given @mount.
175 * The returned string should be freed with g_free()
176 * when no longer needed.
179 g_mount_get_name (GMount *mount)
183 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
185 iface = G_MOUNT_GET_IFACE (mount);
187 return (* iface->get_name) (mount);
194 * Gets the icon for @mount.
197 * The returned object should be unreffed with
198 * g_object_unref() when no longer needed.
201 g_mount_get_icon (GMount *mount)
205 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
207 iface = G_MOUNT_GET_IFACE (mount);
209 return (* iface->get_icon) (mount);
216 * Gets the UUID for the @mount. The reference is typically based on
217 * the file system UUID for the mount in question and should be
218 * considered an opaque string. Returns %NULL if there is no UUID
221 * Returns: the UUID for @mount or %NULL if no UUID can be computed.
222 * The returned string should be freed with g_free()
223 * when no longer needed.
226 g_mount_get_uuid (GMount *mount)
230 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
232 iface = G_MOUNT_GET_IFACE (mount);
234 return (* iface->get_uuid) (mount);
238 * g_mount_get_volume:
241 * Gets the volume for the @mount.
243 * Returns: a #GVolume or %NULL if @mount is not associated with a volume.
244 * The returned object should be unreffed with
245 * g_object_unref() when no longer needed.
248 g_mount_get_volume (GMount *mount)
252 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
254 iface = G_MOUNT_GET_IFACE (mount);
256 return (* iface->get_volume) (mount);
263 * Gets the drive for the @mount.
265 * This is a convenience method for getting the #GVolume and then
266 * using that object to get the #GDrive.
268 * Returns: a #GDrive or %NULL if @mount is not associated with a volume or a drive.
269 * The returned object should be unreffed with
270 * g_object_unref() when no longer needed.
273 g_mount_get_drive (GMount *mount)
277 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
279 iface = G_MOUNT_GET_IFACE (mount);
281 return (* iface->get_drive) (mount);
285 * g_mount_can_unmount:
288 * Checks if @mount can be mounted.
290 * Returns: %TRUE if the @mount can be unmounted.
293 g_mount_can_unmount (GMount *mount)
297 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
299 iface = G_MOUNT_GET_IFACE (mount);
301 return (* iface->can_unmount) (mount);
308 * Checks if @mount can be eject.
310 * Returns: %TRUE if the @mount can be ejected.
313 g_mount_can_eject (GMount *mount)
317 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
319 iface = G_MOUNT_GET_IFACE (mount);
321 return (* iface->can_eject) (mount);
327 * @flags: flags affecting the operation
328 * @cancellable: optional #GCancellable object, %NULL to ignore.
329 * @callback: a #GAsyncReadyCallback, or %NULL.
330 * @user_data: user data passed to @callback.
332 * Unmounts a mount. This is an asynchronous operation, and is
333 * finished by calling g_mount_unmount_finish() with the @mount
334 * and #GAsyncResult data returned in the @callback.
337 g_mount_unmount (GMount *mount,
338 GMountUnmountFlags flags,
339 GCancellable *cancellable,
340 GAsyncReadyCallback callback,
345 g_return_if_fail (G_IS_MOUNT (mount));
347 iface = G_MOUNT_GET_IFACE (mount);
349 if (iface->unmount == NULL)
351 g_simple_async_report_error_in_idle (G_OBJECT (mount),
353 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
354 /* Translators: This is an error
355 * message for mount objects that
356 * don't implement unmount. */
357 _("mount doesn't implement unmount"));
362 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
366 * g_mount_unmount_finish:
368 * @result: a #GAsyncResult.
369 * @error: a #GError location to store the error occuring, or %NULL to
372 * Finishes unmounting a mount. If any errors occurred during the operation,
373 * @error will be set to contain the errors and %FALSE will be returned.
375 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
378 g_mount_unmount_finish (GMount *mount,
379 GAsyncResult *result,
384 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
385 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
387 if (G_IS_SIMPLE_ASYNC_RESULT (result))
389 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
390 if (g_simple_async_result_propagate_error (simple, error))
394 iface = G_MOUNT_GET_IFACE (mount);
395 return (* iface->unmount_finish) (mount, result, error);
402 * @flags: flags affecting the unmount if required for eject
403 * @cancellable: optional #GCancellable object, %NULL to ignore.
404 * @callback: a #GAsyncReadyCallback, or %NULL.
405 * @user_data: user data passed to @callback.
407 * Ejects a mount. This is an asynchronous operation, and is
408 * finished by calling g_mount_eject_finish() with the @mount
409 * and #GAsyncResult data returned in the @callback.
412 g_mount_eject (GMount *mount,
413 GMountUnmountFlags flags,
414 GCancellable *cancellable,
415 GAsyncReadyCallback callback,
420 g_return_if_fail (G_IS_MOUNT (mount));
422 iface = G_MOUNT_GET_IFACE (mount);
424 if (iface->eject == NULL)
426 g_simple_async_report_error_in_idle (G_OBJECT (mount),
428 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
429 /* Translators: This is an error
430 * message for mount objects that
431 * don't implement eject. */
432 _("mount doesn't implement eject"));
437 (* iface->eject) (mount, flags, cancellable, callback, user_data);
441 * g_mount_eject_finish:
443 * @result: a #GAsyncResult.
444 * @error: a #GError location to store the error occuring, or %NULL to
447 * Finishes ejecting a mount. If any errors occurred during the operation,
448 * @error will be set to contain the errors and %FALSE will be returned.
450 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
453 g_mount_eject_finish (GMount *mount,
454 GAsyncResult *result,
459 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
460 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
462 if (G_IS_SIMPLE_ASYNC_RESULT (result))
464 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
465 if (g_simple_async_result_propagate_error (simple, error))
469 iface = G_MOUNT_GET_IFACE (mount);
470 return (* iface->eject_finish) (mount, result, error);
476 * @flags: flags affecting the operation
477 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
478 * @cancellable: optional #GCancellable object, %NULL to ignore.
479 * @callback: a #GAsyncReadyCallback, or %NULL.
480 * @user_data: user data passed to @callback.
482 * Remounts a mount. This is an asynchronous operation, and is
483 * finished by calling g_mount_remount_finish() with the @mount
484 * and #GAsyncResults data returned in the @callback.
486 * Remounting is useful when some setting affecting the operation
487 * of the volume has been changed, as these may need a remount to
488 * take affect. While this is semantically equivalent with unmounting
489 * and then remounting not all backends might need to actually be
493 g_mount_remount (GMount *mount,
494 GMountMountFlags flags,
495 GMountOperation *mount_operation,
496 GCancellable *cancellable,
497 GAsyncReadyCallback callback,
502 g_return_if_fail (G_IS_MOUNT (mount));
504 iface = G_MOUNT_GET_IFACE (mount);
506 if (iface->remount == NULL)
508 g_simple_async_report_error_in_idle (G_OBJECT (mount),
510 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
511 /* Translators: This is an error
512 * message for mount objects that
513 * don't implement remount. */
514 _("mount doesn't implement remount"));
519 (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
523 * g_mount_remount_finish:
525 * @result: a #GAsyncResult.
526 * @error: a #GError location to store the error occuring, or %NULL to
529 * Finishes remounting a mount. If any errors occurred during the operation,
530 * @error will be set to contain the errors and %FALSE will be returned.
532 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
535 g_mount_remount_finish (GMount *mount,
536 GAsyncResult *result,
541 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
542 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
544 if (G_IS_SIMPLE_ASYNC_RESULT (result))
546 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
547 if (g_simple_async_result_propagate_error (simple, error))
551 iface = G_MOUNT_GET_IFACE (mount);
552 return (* iface->remount_finish) (mount, result, error);
556 * g_mount_guess_content_type:
558 * @force_rescan: Whether to force a rescan of the content.
559 * Otherwise a cached result will be used if available
560 * @cancellable: optional #GCancellable object, %NULL to ignore
561 * @callback: a #GAsyncReadyCallback
562 * @user_data: user data passed to @callback
564 * Tries to guess the type of content stored on @mount. Returns one or
565 * more textual identifiers of well-known content types (typically
566 * prefixed with "x-content/"), e.g. x-content/image-dcf for camera
567 * memory cards. See the <ulink url="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</ulink>
568 * specification for more on x-content types.
570 * This is an asynchronous operation, and is finished by calling
571 * g_mount_guess_content_type_finish() with the @mount and #GAsyncResult
572 * data returned in the @callback.
577 g_mount_guess_content_type (GMount *mount,
578 gboolean force_rescan,
579 GCancellable *cancellable,
580 GAsyncReadyCallback callback,
585 g_return_if_fail (G_IS_MOUNT (mount));
587 iface = G_MOUNT_GET_IFACE (mount);
589 if (iface->guess_content_type == NULL)
591 g_simple_async_report_error_in_idle (G_OBJECT (mount),
593 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
594 /* Translators: This is an error
595 * message for mount objects that
596 * don't implement content type guessing. */
597 _("mount doesn't implement content type guessing"));
602 (* iface->guess_content_type) (mount, force_rescan, cancellable, callback, user_data);
606 * g_mount_guess_content_type_finish:
608 * @result: a #GAsyncResult
609 * @error: a #GError location to store the error occuring, or %NULL to
612 * Finishes guessing content types of @mount. If any errors occured
613 * during the operation, @error will be set to contain the errors and
614 * %FALSE will be returned. In particular, you may get an
615 * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content
618 * Returns: a %NULL-terminated array of content types or %NULL on error.
619 * Caller should free this array with g_strfreev() when done with it.
624 g_mount_guess_content_type_finish (GMount *mount,
625 GAsyncResult *result,
630 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
631 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
633 if (G_IS_SIMPLE_ASYNC_RESULT (result))
635 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
636 if (g_simple_async_result_propagate_error (simple, error))
640 iface = G_MOUNT_GET_IFACE (mount);
641 return (* iface->guess_content_type_finish) (mount, result, error);
645 #define __G_MOUNT_C__
646 #include "gioaliasdef.c"