1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 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 "gsimpleasyncresult.h"
39 * @short_description: Mount management
41 * @see also: GVolume, GUnixMount
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 #GAsyncReady
53 * and #GSimpleAsyncReady. To unmount a #GMount instance, first call
54 * g_mount_unmount() 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_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_finish()
61 * is called, then it will be filled with any error information.
64 static void g_mount_base_init (gpointer g_class);
65 static void g_mount_class_init (gpointer g_class,
69 g_mount_get_type (void)
71 static GType mount_type = 0;
75 static const GTypeInfo mount_info =
77 sizeof (GMountIface), /* class_size */
78 g_mount_base_init, /* base_init */
79 NULL, /* base_finalize */
81 NULL, /* class_finalize */
82 NULL, /* class_data */
89 g_type_register_static (G_TYPE_INTERFACE, I_("GMount"),
92 g_type_interface_add_prerequisite (mount_type, G_TYPE_OBJECT);
99 g_mount_class_init (gpointer g_class,
105 g_mount_base_init (gpointer g_class)
107 static gboolean initialized = FALSE;
114 * Emitted when the mount has been changed.
116 g_signal_new (I_("changed"),
119 G_STRUCT_OFFSET (GMountIface, changed),
121 g_cclosure_marshal_VOID__VOID,
127 * This signal is emitted when the #GMount have been
128 * unmounted. If the recipient is holding references to the
129 * object they should release them so the object can be
132 g_signal_new (I_("unmounted"),
135 G_STRUCT_OFFSET (GMountIface, unmounted),
137 g_cclosure_marshal_VOID__VOID,
148 * Gets the root directory on @mount.
153 g_mount_get_root (GMount *mount)
157 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
159 iface = G_MOUNT_GET_IFACE (mount);
161 return (* iface->get_root) (mount);
168 * Gets the name of @mount.
170 * Returns: the name for the given @mount. The returned string should
171 * be freed when no longer needed.
174 g_mount_get_name (GMount *mount)
178 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
180 iface = G_MOUNT_GET_IFACE (mount);
182 return (* iface->get_name) (mount);
189 * Gets the icon for @mount.
194 g_mount_get_icon (GMount *mount)
198 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
200 iface = G_MOUNT_GET_IFACE (mount);
202 return (* iface->get_icon) (mount);
209 * Gets the UUID for the @mount. The reference is typically based on
210 * the file system UUID for the mount in question and should be
211 * considered an opaque string. Returns %NULL if there is no UUID
214 * Returns: the UUID for @mount or %NULL if no UUID can be computed.
217 g_mount_get_uuid (GMount *mount)
221 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
223 iface = G_MOUNT_GET_IFACE (mount);
225 return (* iface->get_uuid) (mount);
229 * g_mount_get_volume:
232 * Gets the volume for the @mount.
234 * Returns: a #GVolume or %NULL if @mount is not associated with a volume.
237 g_mount_get_volume (GMount *mount)
241 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
243 iface = G_MOUNT_GET_IFACE (mount);
245 return (* iface->get_volume) (mount);
252 * Gets the drive for the @mount.
254 * This is a convenience method for getting the #GVolume and then
255 * using that object to get the #GDrive.
257 * Returns: a #GDrive or %NULL if @mount is not associated with a volume or a drive.
260 g_mount_get_drive (GMount *mount)
264 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
266 iface = G_MOUNT_GET_IFACE (mount);
268 return (* iface->get_drive) (mount);
272 * g_mount_can_unmount:
275 * Checks if @mount can be mounted.
277 * Returns: %TRUE if the @mount can be unmounted.
280 g_mount_can_unmount (GMount *mount)
284 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
286 iface = G_MOUNT_GET_IFACE (mount);
288 return (* iface->can_unmount) (mount);
295 * Checks if @mount can be eject.
297 * Returns: %TRUE if the @mount can be ejected.
300 g_mount_can_eject (GMount *mount)
304 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
306 iface = G_MOUNT_GET_IFACE (mount);
308 return (* iface->can_eject) (mount);
314 * @flags: flags affecting the operation
315 * @cancellable: optional #GCancellable object, %NULL to ignore.
316 * @callback: a #GAsyncReadyCallback, or %NULL.
317 * @user_data: user data passed to @callback.
319 * Unmounts a mount. This is an asynchronous operation, and is
320 * finished by calling g_mount_unmount_finish() with the @mount
321 * and #GAsyncResults data returned in the @callback.
324 g_mount_unmount (GMount *mount,
325 GMountUnmountFlags flags,
326 GCancellable *cancellable,
327 GAsyncReadyCallback callback,
332 g_return_if_fail (G_IS_MOUNT (mount));
334 iface = G_MOUNT_GET_IFACE (mount);
336 if (iface->unmount == NULL)
338 g_simple_async_report_error_in_idle (G_OBJECT (mount),
340 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
341 /* Translators: This is an error
342 * message for mount objects that
343 * don't implement unmount. */
344 _("mount doesn't implement unmount"));
349 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
353 * g_mount_unmount_finish:
355 * @result: a #GAsyncResult.
356 * @error: a #GError location to store the error occuring, or %NULL to
359 * Finishes unmounting a mount. If any errors occurred during the operation,
360 * @error will be set to contain the errors and %FALSE will be returned.
362 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
365 g_mount_unmount_finish (GMount *mount,
366 GAsyncResult *result,
371 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
372 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
374 if (G_IS_SIMPLE_ASYNC_RESULT (result))
376 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
377 if (g_simple_async_result_propagate_error (simple, error))
381 iface = G_MOUNT_GET_IFACE (mount);
382 return (* iface->unmount_finish) (mount, result, error);
389 * @flags: flags affecting the unmount if required for eject
390 * @cancellable: optional #GCancellable object, %NULL to ignore.
391 * @callback: a #GAsyncReadyCallback, or %NULL.
392 * @user_data: user data passed to @callback.
394 * Ejects a mount. This is an asynchronous operation, and is
395 * finished by calling g_mount_eject_finish() with the @mount
396 * and #GAsyncResults data returned in the @callback.
399 g_mount_eject (GMount *mount,
400 GMountUnmountFlags flags,
401 GCancellable *cancellable,
402 GAsyncReadyCallback callback,
407 g_return_if_fail (G_IS_MOUNT (mount));
409 iface = G_MOUNT_GET_IFACE (mount);
411 if (iface->eject == NULL)
413 g_simple_async_report_error_in_idle (G_OBJECT (mount),
415 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
416 /* Translators: This is an error
417 * message for mount objects that
418 * don't implement eject. */
419 _("mount doesn't implement eject"));
424 (* iface->eject) (mount, flags, cancellable, callback, user_data);
428 * g_mount_eject_finish:
430 * @result: a #GAsyncResult.
431 * @error: a #GError location to store the error occuring, or %NULL to
434 * Finishes ejecting a mount. If any errors occurred during the operation,
435 * @error will be set to contain the errors and %FALSE will be returned.
437 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
440 g_mount_eject_finish (GMount *mount,
441 GAsyncResult *result,
446 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
447 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
449 if (G_IS_SIMPLE_ASYNC_RESULT (result))
451 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
452 if (g_simple_async_result_propagate_error (simple, error))
456 iface = G_MOUNT_GET_IFACE (mount);
457 return (* iface->eject_finish) (mount, result, error);
463 * @flags: flags affecting the operation
464 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
465 * @cancellable: optional #GCancellable object, %NULL to ignore.
466 * @callback: a #GAsyncReadyCallback, or %NULL.
467 * @user_data: user data passed to @callback.
469 * Remounts a mount. This is an asynchronous operation, and is
470 * finished by calling g_mount_remount_finish() with the @mount
471 * and #GAsyncResults data returned in the @callback.
473 * Remounting is useful when some setting affecting the operation
474 * of the volume has been changed, as these may need a remount to
475 * take affect. While this is semantically equivalent with unmounting
476 * and then remounting not all backends might need to actually be
480 g_mount_remount (GMount *mount,
481 GMountMountFlags flags,
482 GMountOperation *mount_operation,
483 GCancellable *cancellable,
484 GAsyncReadyCallback callback,
489 g_return_if_fail (G_IS_MOUNT (mount));
491 iface = G_MOUNT_GET_IFACE (mount);
493 if (iface->remount == NULL)
495 g_simple_async_report_error_in_idle (G_OBJECT (mount),
497 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
498 /* Translators: This is an error
499 * message for mount objects that
500 * don't implement remount. */
501 _("mount doesn't implement remount"));
506 (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
510 * g_mount_remount_finish:
512 * @result: a #GAsyncResult.
513 * @error: a #GError location to store the error occuring, or %NULL to
516 * Finishes remounting a mount. If any errors occurred during the operation,
517 * @error will be set to contain the errors and %FALSE will be returned.
519 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
522 g_mount_remount_finish (GMount *mount,
523 GAsyncResult *result,
528 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
529 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
531 if (G_IS_SIMPLE_ASYNC_RESULT (result))
533 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
534 if (g_simple_async_result_propagate_error (simple, error))
538 iface = G_MOUNT_GET_IFACE (mount);
539 return (* iface->remount_finish) (mount, result, error);
543 #define __G_MOUNT_C__
544 #include "gioaliasdef.c"