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 "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.
155 g_mount_get_root (GMount
*mount
)
159 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
161 iface
= G_MOUNT_GET_IFACE (mount
);
163 return (* iface
->get_root
) (mount
);
170 * Gets the name of @mount.
172 * Returns: the name for the given @mount. The returned string should
173 * be freed when no longer needed.
176 g_mount_get_name (GMount
*mount
)
180 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
182 iface
= G_MOUNT_GET_IFACE (mount
);
184 return (* iface
->get_name
) (mount
);
191 * Gets the icon for @mount.
196 g_mount_get_icon (GMount
*mount
)
200 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
202 iface
= G_MOUNT_GET_IFACE (mount
);
204 return (* iface
->get_icon
) (mount
);
211 * Gets the UUID for the @mount. The reference is typically based on
212 * the file system UUID for the mount in question and should be
213 * considered an opaque string. Returns %NULL if there is no UUID
216 * Returns: the UUID for @mount or %NULL if no UUID can be computed.
219 g_mount_get_uuid (GMount
*mount
)
223 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
225 iface
= G_MOUNT_GET_IFACE (mount
);
227 return (* iface
->get_uuid
) (mount
);
231 * g_mount_get_volume:
234 * Gets the volume for the @mount.
236 * Returns: a #GVolume or %NULL if @mount is not associated with a volume.
239 g_mount_get_volume (GMount
*mount
)
243 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
245 iface
= G_MOUNT_GET_IFACE (mount
);
247 return (* iface
->get_volume
) (mount
);
254 * Gets the drive for the @mount.
256 * This is a convenience method for getting the #GVolume and then
257 * using that object to get the #GDrive.
259 * Returns: a #GDrive or %NULL if @mount is not associated with a volume or a drive.
262 g_mount_get_drive (GMount
*mount
)
266 g_return_val_if_fail (G_IS_MOUNT (mount
), NULL
);
268 iface
= G_MOUNT_GET_IFACE (mount
);
270 return (* iface
->get_drive
) (mount
);
274 * g_mount_can_unmount:
277 * Checks if @mount can be mounted.
279 * Returns: %TRUE if the @mount can be unmounted.
282 g_mount_can_unmount (GMount
*mount
)
286 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
288 iface
= G_MOUNT_GET_IFACE (mount
);
290 return (* iface
->can_unmount
) (mount
);
297 * Checks if @mount can be eject.
299 * Returns: %TRUE if the @mount can be ejected.
302 g_mount_can_eject (GMount
*mount
)
306 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
308 iface
= G_MOUNT_GET_IFACE (mount
);
310 return (* iface
->can_eject
) (mount
);
316 * @flags: flags affecting the operation
317 * @cancellable: optional #GCancellable object, %NULL to ignore.
318 * @callback: a #GAsyncReadyCallback, or %NULL.
319 * @user_data: user data passed to @callback.
321 * Unmounts a mount. This is an asynchronous operation, and is
322 * finished by calling g_mount_unmount_finish() with the @mount
323 * and #GAsyncResults data returned in the @callback.
326 g_mount_unmount (GMount
*mount
,
327 GMountUnmountFlags flags
,
328 GCancellable
*cancellable
,
329 GAsyncReadyCallback callback
,
334 g_return_if_fail (G_IS_MOUNT (mount
));
336 iface
= G_MOUNT_GET_IFACE (mount
);
338 if (iface
->unmount
== NULL
)
340 g_simple_async_report_error_in_idle (G_OBJECT (mount
),
342 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
343 /* Translators: This is an error
344 * message for mount objects that
345 * don't implement unmount. */
346 _("mount doesn't implement unmount"));
351 (* iface
->unmount
) (mount
, flags
, cancellable
, callback
, user_data
);
355 * g_mount_unmount_finish:
357 * @result: a #GAsyncResult.
358 * @error: a #GError location to store the error occuring, or %NULL to
361 * Finishes unmounting a mount. If any errors occurred during the operation,
362 * @error will be set to contain the errors and %FALSE will be returned.
364 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
367 g_mount_unmount_finish (GMount
*mount
,
368 GAsyncResult
*result
,
373 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
374 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
376 if (G_IS_SIMPLE_ASYNC_RESULT (result
))
378 GSimpleAsyncResult
*simple
= G_SIMPLE_ASYNC_RESULT (result
);
379 if (g_simple_async_result_propagate_error (simple
, error
))
383 iface
= G_MOUNT_GET_IFACE (mount
);
384 return (* iface
->unmount_finish
) (mount
, result
, error
);
391 * @flags: flags affecting the unmount if required for eject
392 * @cancellable: optional #GCancellable object, %NULL to ignore.
393 * @callback: a #GAsyncReadyCallback, or %NULL.
394 * @user_data: user data passed to @callback.
396 * Ejects a mount. This is an asynchronous operation, and is
397 * finished by calling g_mount_eject_finish() with the @mount
398 * and #GAsyncResults data returned in the @callback.
401 g_mount_eject (GMount
*mount
,
402 GMountUnmountFlags flags
,
403 GCancellable
*cancellable
,
404 GAsyncReadyCallback callback
,
409 g_return_if_fail (G_IS_MOUNT (mount
));
411 iface
= G_MOUNT_GET_IFACE (mount
);
413 if (iface
->eject
== NULL
)
415 g_simple_async_report_error_in_idle (G_OBJECT (mount
),
417 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
418 /* Translators: This is an error
419 * message for mount objects that
420 * don't implement eject. */
421 _("mount doesn't implement eject"));
426 (* iface
->eject
) (mount
, flags
, cancellable
, callback
, user_data
);
430 * g_mount_eject_finish:
432 * @result: a #GAsyncResult.
433 * @error: a #GError location to store the error occuring, or %NULL to
436 * Finishes ejecting a mount. If any errors occurred during the operation,
437 * @error will be set to contain the errors and %FALSE will be returned.
439 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
442 g_mount_eject_finish (GMount
*mount
,
443 GAsyncResult
*result
,
448 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
449 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
451 if (G_IS_SIMPLE_ASYNC_RESULT (result
))
453 GSimpleAsyncResult
*simple
= G_SIMPLE_ASYNC_RESULT (result
);
454 if (g_simple_async_result_propagate_error (simple
, error
))
458 iface
= G_MOUNT_GET_IFACE (mount
);
459 return (* iface
->eject_finish
) (mount
, result
, error
);
465 * @flags: flags affecting the operation
466 * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
467 * @cancellable: optional #GCancellable object, %NULL to ignore.
468 * @callback: a #GAsyncReadyCallback, or %NULL.
469 * @user_data: user data passed to @callback.
471 * Remounts a mount. This is an asynchronous operation, and is
472 * finished by calling g_mount_remount_finish() with the @mount
473 * and #GAsyncResults data returned in the @callback.
475 * Remounting is useful when some setting affecting the operation
476 * of the volume has been changed, as these may need a remount to
477 * take affect. While this is semantically equivalent with unmounting
478 * and then remounting not all backends might need to actually be
482 g_mount_remount (GMount
*mount
,
483 GMountMountFlags flags
,
484 GMountOperation
*mount_operation
,
485 GCancellable
*cancellable
,
486 GAsyncReadyCallback callback
,
491 g_return_if_fail (G_IS_MOUNT (mount
));
493 iface
= G_MOUNT_GET_IFACE (mount
);
495 if (iface
->remount
== NULL
)
497 g_simple_async_report_error_in_idle (G_OBJECT (mount
),
499 G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
500 /* Translators: This is an error
501 * message for mount objects that
502 * don't implement remount. */
503 _("mount doesn't implement remount"));
508 (* iface
->remount
) (mount
, flags
, mount_operation
, cancellable
, callback
, user_data
);
512 * g_mount_remount_finish:
514 * @result: a #GAsyncResult.
515 * @error: a #GError location to store the error occuring, or %NULL to
518 * Finishes remounting a mount. If any errors occurred during the operation,
519 * @error will be set to contain the errors and %FALSE will be returned.
521 * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise.
524 g_mount_remount_finish (GMount
*mount
,
525 GAsyncResult
*result
,
530 g_return_val_if_fail (G_IS_MOUNT (mount
), FALSE
);
531 g_return_val_if_fail (G_IS_ASYNC_RESULT (result
), FALSE
);
533 if (G_IS_SIMPLE_ASYNC_RESULT (result
))
535 GSimpleAsyncResult
*simple
= G_SIMPLE_ASYNC_RESULT (result
);
536 if (g_simple_async_result_propagate_error (simple
, error
))
540 iface
= G_MOUNT_GET_IFACE (mount
);
541 return (* iface
->remount_finish
) (mount
, result
, error
);
545 #define __G_MOUNT_C__
546 #include "gioaliasdef.c"