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 _("mount doesn't implement unmount"));
346 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
350 * g_mount_unmount_finish:
352 * @result: a #GAsyncResult.
353 * @error: a #GError location to store the error occuring, or %NULL to
356 * Finishes unmounting a mount. If any errors occurred during the operation,
357 * @error will be set to contain the errors and %FALSE will be returned.
359 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
362 g_mount_unmount_finish (GMount *mount,
363 GAsyncResult *result,
368 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
369 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
371 if (G_IS_SIMPLE_ASYNC_RESULT (result))
373 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
374 if (g_simple_async_result_propagate_error (simple, error))
378 iface = G_MOUNT_GET_IFACE (mount);
379 return (* iface->unmount_finish) (mount, result, error);
386 * @flags: flags affecting the unmount if required for eject
387 * @cancellable: optional #GCancellable object, %NULL to ignore.
388 * @callback: a #GAsyncReadyCallback, or %NULL.
389 * @user_data: user data passed to @callback.
391 * Ejects a mount. This is an asynchronous operation, and is
392 * finished by calling g_mount_eject_finish() with the @mount
393 * and #GAsyncResults data returned in the @callback.
396 g_mount_eject (GMount *mount,
397 GMountUnmountFlags flags,
398 GCancellable *cancellable,
399 GAsyncReadyCallback callback,
404 g_return_if_fail (G_IS_MOUNT (mount));
406 iface = G_MOUNT_GET_IFACE (mount);
408 if (iface->eject == NULL)
410 g_simple_async_report_error_in_idle (G_OBJECT (mount),
412 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
413 _("mount doesn't implement eject"));
418 (* iface->eject) (mount, flags, cancellable, callback, user_data);
422 * g_mount_eject_finish:
424 * @result: a #GAsyncResult.
425 * @error: a #GError location to store the error occuring, or %NULL to
428 * Finishes ejecting a mount. If any errors occurred during the operation,
429 * @error will be set to contain the errors and %FALSE will be returned.
431 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
434 g_mount_eject_finish (GMount *mount,
435 GAsyncResult *result,
440 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
441 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
443 if (G_IS_SIMPLE_ASYNC_RESULT (result))
445 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
446 if (g_simple_async_result_propagate_error (simple, error))
450 iface = G_MOUNT_GET_IFACE (mount);
451 return (* iface->eject_finish) (mount, result, error);
457 * @flags: flags affecting the operation
458 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
459 * @cancellable: optional #GCancellable object, %NULL to ignore.
460 * @callback: a #GAsyncReadyCallback, or %NULL.
461 * @user_data: user data passed to @callback.
463 * Remounts a mount. This is an asynchronous operation, and is
464 * finished by calling g_mount_remount_finish() with the @mount
465 * and #GAsyncResults data returned in the @callback.
467 * Remounting is useful when some setting affecting the operation
468 * of the volume has been changed, as these may need a remount to
469 * take affect. While this is semantically equivalent with unmounting
470 * and then remounting not all backends might need to actually be
474 g_mount_remount (GMount *mount,
475 GMountMountFlags flags,
476 GMountOperation *mount_operation,
477 GCancellable *cancellable,
478 GAsyncReadyCallback callback,
483 g_return_if_fail (G_IS_MOUNT (mount));
485 iface = G_MOUNT_GET_IFACE (mount);
487 if (iface->remount == NULL)
489 g_simple_async_report_error_in_idle (G_OBJECT (mount),
491 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
492 _("mount doesn't implement remount"));
497 (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
501 * g_mount_remount_finish:
503 * @result: a #GAsyncResult.
504 * @error: a #GError location to store the error occuring, or %NULL to
507 * Finishes remounting a mount. If any errors occurred during the operation,
508 * @error will be set to contain the errors and %FALSE will be returned.
510 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
513 g_mount_remount_finish (GMount *mount,
514 GAsyncResult *result,
519 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
520 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
522 if (G_IS_SIMPLE_ASYNC_RESULT (result))
524 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
525 if (g_simple_async_result_propagate_error (simple, error))
529 iface = G_MOUNT_GET_IFACE (mount);
530 return (* iface->remount_finish) (mount, result, error);
534 #define __G_MOUNT_C__
535 #include "gioaliasdef.c"