Fix the build
[glib.git] / gio / gmount.c
blob172ad3bee90ee8f689d6a86979a363cdae2b0276
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
4 *
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>
26 #include "config.h"
28 #include <string.h>
30 #include "gmount.h"
31 #include "gmountprivate.h"
32 #include "gasyncresult.h"
33 #include "gsimpleasyncresult.h"
34 #include "gioerror.h"
35 #include "glibintl.h"
37 #include "gioalias.h"
39 /**
40 * SECTION:gmount
41 * @short_description: Mount management
42 * @include: gio/gio.h
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.
64 **/
66 static void g_mount_base_init (gpointer g_class);
67 static void g_mount_class_init (gpointer g_class,
68 gpointer class_data);
70 GType
71 g_mount_get_type (void)
73 static GType mount_type = 0;
75 if (! mount_type)
77 static const GTypeInfo mount_info =
79 sizeof (GMountIface), /* class_size */
80 g_mount_base_init, /* base_init */
81 NULL, /* base_finalize */
82 g_mount_class_init,
83 NULL, /* class_finalize */
84 NULL, /* class_data */
86 0, /* n_preallocs */
87 NULL
90 mount_type =
91 g_type_register_static (G_TYPE_INTERFACE, I_("GMount"),
92 &mount_info, 0);
94 g_type_interface_add_prerequisite (mount_type, G_TYPE_OBJECT);
97 return mount_type;
100 static void
101 g_mount_class_init (gpointer g_class,
102 gpointer class_data)
106 static void
107 g_mount_base_init (gpointer g_class)
109 static gboolean initialized = FALSE;
111 if (! initialized)
114 * GMount::changed:
116 * Emitted when the mount has been changed.
118 g_signal_new (I_("changed"),
119 G_TYPE_MOUNT,
120 G_SIGNAL_RUN_LAST,
121 G_STRUCT_OFFSET (GMountIface, changed),
122 NULL, NULL,
123 g_cclosure_marshal_VOID__VOID,
124 G_TYPE_NONE, 0);
127 * GMount::unmounted:
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
132 * finalized.
134 g_signal_new (I_("unmounted"),
135 G_TYPE_MOUNT,
136 G_SIGNAL_RUN_LAST,
137 G_STRUCT_OFFSET (GMountIface, unmounted),
138 NULL, NULL,
139 g_cclosure_marshal_VOID__VOID,
140 G_TYPE_NONE, 0);
142 initialized = TRUE;
147 * g_mount_get_root:
148 * @mount: a #GMount.
150 * Gets the root directory on @mount.
152 * Returns: a #GFile.
154 GFile *
155 g_mount_get_root (GMount *mount)
157 GMountIface *iface;
159 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
161 iface = G_MOUNT_GET_IFACE (mount);
163 return (* iface->get_root) (mount);
167 * g_mount_get_name:
168 * @mount: a #GMount.
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.
175 char *
176 g_mount_get_name (GMount *mount)
178 GMountIface *iface;
180 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
182 iface = G_MOUNT_GET_IFACE (mount);
184 return (* iface->get_name) (mount);
188 * g_mount_get_icon:
189 * @mount: a #GMount.
191 * Gets the icon for @mount.
193 * Returns: a #GIcon.
195 GIcon *
196 g_mount_get_icon (GMount *mount)
198 GMountIface *iface;
200 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
202 iface = G_MOUNT_GET_IFACE (mount);
204 return (* iface->get_icon) (mount);
208 * g_mount_get_uuid:
209 * @mount: a #GMount.
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
214 * available.
216 * Returns: the UUID for @mount or %NULL if no UUID can be computed.
218 char *
219 g_mount_get_uuid (GMount *mount)
221 GMountIface *iface;
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:
232 * @mount: a #GMount.
234 * Gets the volume for the @mount.
236 * Returns: a #GVolume or %NULL if @mount is not associated with a volume.
238 GVolume *
239 g_mount_get_volume (GMount *mount)
241 GMountIface *iface;
243 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
245 iface = G_MOUNT_GET_IFACE (mount);
247 return (* iface->get_volume) (mount);
251 * g_mount_get_drive:
252 * @mount: a #GMount.
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.
261 GDrive *
262 g_mount_get_drive (GMount *mount)
264 GMountIface *iface;
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:
275 * @mount: a #GMount.
277 * Checks if @mount can be mounted.
279 * Returns: %TRUE if the @mount can be unmounted.
281 gboolean
282 g_mount_can_unmount (GMount *mount)
284 GMountIface *iface;
286 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
288 iface = G_MOUNT_GET_IFACE (mount);
290 return (* iface->can_unmount) (mount);
294 * g_mount_can_eject:
295 * @mount: a #GMount.
297 * Checks if @mount can be eject.
299 * Returns: %TRUE if the @mount can be ejected.
301 gboolean
302 g_mount_can_eject (GMount *mount)
304 GMountIface *iface;
306 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
308 iface = G_MOUNT_GET_IFACE (mount);
310 return (* iface->can_eject) (mount);
314 * g_mount_unmount:
315 * @mount: a #GMount.
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.
325 void
326 g_mount_unmount (GMount *mount,
327 GMountUnmountFlags flags,
328 GCancellable *cancellable,
329 GAsyncReadyCallback callback,
330 gpointer user_data)
332 GMountIface *iface;
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),
341 callback, user_data,
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"));
348 return;
351 (* iface->unmount) (mount, flags, cancellable, callback, user_data);
355 * g_mount_unmount_finish:
356 * @mount: a #GMount.
357 * @result: a #GAsyncResult.
358 * @error: a #GError location to store the error occuring, or %NULL to
359 * ignore.
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.
366 gboolean
367 g_mount_unmount_finish (GMount *mount,
368 GAsyncResult *result,
369 GError **error)
371 GMountIface *iface;
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))
380 return FALSE;
383 iface = G_MOUNT_GET_IFACE (mount);
384 return (* iface->unmount_finish) (mount, result, error);
389 * g_mount_eject:
390 * @mount: a #GMount.
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.
400 void
401 g_mount_eject (GMount *mount,
402 GMountUnmountFlags flags,
403 GCancellable *cancellable,
404 GAsyncReadyCallback callback,
405 gpointer user_data)
407 GMountIface *iface;
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),
416 callback, user_data,
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"));
423 return;
426 (* iface->eject) (mount, flags, cancellable, callback, user_data);
430 * g_mount_eject_finish:
431 * @mount: a #GMount.
432 * @result: a #GAsyncResult.
433 * @error: a #GError location to store the error occuring, or %NULL to
434 * ignore.
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.
441 gboolean
442 g_mount_eject_finish (GMount *mount,
443 GAsyncResult *result,
444 GError **error)
446 GMountIface *iface;
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))
455 return FALSE;
458 iface = G_MOUNT_GET_IFACE (mount);
459 return (* iface->eject_finish) (mount, result, error);
463 * g_mount_remount:
464 * @mount: a #GMount.
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
479 * unmounted.
481 void
482 g_mount_remount (GMount *mount,
483 GMountMountFlags flags,
484 GMountOperation *mount_operation,
485 GCancellable *cancellable,
486 GAsyncReadyCallback callback,
487 gpointer user_data)
489 GMountIface *iface;
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),
498 callback, user_data,
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"));
505 return;
508 (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data);
512 * g_mount_remount_finish:
513 * @mount: a #GMount.
514 * @result: a #GAsyncResult.
515 * @error: a #GError location to store the error occuring, or %NULL to
516 * ignore.
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.
523 gboolean
524 g_mount_remount_finish (GMount *mount,
525 GAsyncResult *result,
526 GError **error)
528 GMountIface *iface;
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))
537 return FALSE;
540 iface = G_MOUNT_GET_IFACE (mount);
541 return (* iface->remount_finish) (mount, result, error);
545 #define __G_MOUNT_C__
546 #include "gioaliasdef.c"