Initial commit
[platform/upstream/glib2.0.git] / gio / gdrive.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  *         David Zeuthen <davidz@redhat.com>
22  */
23
24 #include "config.h"
25 #include "gdrive.h"
26 #include "gsimpleasyncresult.h"
27 #include "gasyncresult.h"
28 #include "gioerror.h"
29 #include "glibintl.h"
30
31 #include "gioalias.h"
32
33 /**
34  * SECTION:gdrive
35  * @short_description: Drive management
36  * @include: gio/gio.h
37  *
38  * #GDrive - this represent a piece of hardware connected to the machine.
39  * It's generally only created for removable hardware or hardware with
40  * removable media.
41  *
42  * #GDrive is a container class for #GVolume objects that stem from
43  * the same piece of media. As such, #GDrive abstracts a drive with
44  * (or without) removable media and provides operations for querying
45  * whether media is available, determing whether media change is
46  * automatically detected and ejecting the media.
47  *
48  * If the #GDrive reports that media isn't automatically detected, one
49  * can poll for media; typically one should not do this periodically
50  * as a poll for media operation is potententially expensive and may
51  * spin up the drive creating noise.
52  *
53  * #GDrive supports starting and stopping drives with authentication
54  * support for the former. This can be used to support a diverse set
55  * of use cases including connecting/disconnecting iSCSI devices,
56  * powering down external disk enclosures and starting/stopping
57  * multi-disk devices such as RAID devices. Note that the actual
58  * semantics and side-effects of starting/stopping a #GDrive may vary
59  * according to implementation. To choose the correct verbs in e.g. a
60  * file manager, use g_drive_get_start_stop_type().
61  *
62  * For porting from GnomeVFS note that there is no equivalent of
63  * #GDrive in that API.
64  **/
65
66 typedef GDriveIface GDriveInterface;
67 G_DEFINE_INTERFACE(GDrive, g_drive, G_TYPE_OBJECT)
68
69 static void
70 g_drive_default_init (GDriveInterface *iface)
71 {
72   /**
73    * GDrive::changed:
74    * @drive: a #GDrive.
75    *
76    * Emitted when the drive's state has changed.
77    **/
78   g_signal_new (I_("changed"),
79                 G_TYPE_DRIVE,
80                 G_SIGNAL_RUN_LAST,
81                 G_STRUCT_OFFSET (GDriveIface, changed),
82                 NULL, NULL,
83                 g_cclosure_marshal_VOID__VOID,
84                 G_TYPE_NONE, 0);
85
86   /**
87    * GDrive::disconnected:
88    * @drive: a #GDrive.
89    *
90    * This signal is emitted when the #GDrive have been
91    * disconnected. If the recipient is holding references to the
92    * object they should release them so the object can be
93    * finalized.
94    **/
95   g_signal_new (I_("disconnected"),
96                 G_TYPE_DRIVE,
97                 G_SIGNAL_RUN_LAST,
98                 G_STRUCT_OFFSET (GDriveIface, disconnected),
99                 NULL, NULL,
100                 g_cclosure_marshal_VOID__VOID,
101                 G_TYPE_NONE, 0);
102
103   /**
104    * GDrive::eject-button:
105    * @drive: a #GDrive.
106    *
107    * Emitted when the physical eject button (if any) of a drive has
108    * been pressed.
109    **/
110   g_signal_new (I_("eject-button"),
111                 G_TYPE_DRIVE,
112                 G_SIGNAL_RUN_LAST,
113                 G_STRUCT_OFFSET (GDriveIface, eject_button),
114                 NULL, NULL,
115                 g_cclosure_marshal_VOID__VOID,
116                 G_TYPE_NONE, 0);
117
118   /**
119    * GDrive::stop-button:
120    * @drive: a #GDrive.
121    *
122    * Emitted when the physical stop button (if any) of a drive has
123    * been pressed.
124    *
125    * Since: 2.22
126    **/
127   g_signal_new (I_("stop-button"),
128                 G_TYPE_DRIVE,
129                 G_SIGNAL_RUN_LAST,
130                 G_STRUCT_OFFSET (GDriveIface, stop_button),
131                 NULL, NULL,
132                 g_cclosure_marshal_VOID__VOID,
133                 G_TYPE_NONE, 0);
134 }
135
136 /**
137  * g_drive_get_name:
138  * @drive: a #GDrive.
139  * 
140  * Gets the name of @drive.
141  *
142  * Returns: a string containing @drive's name. The returned 
143  *     string should be freed when no longer needed.
144  **/
145 char *
146 g_drive_get_name (GDrive *drive)
147 {
148   GDriveIface *iface;
149
150   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
151
152   iface = G_DRIVE_GET_IFACE (drive);
153
154   return (* iface->get_name) (drive);
155 }
156
157 /**
158  * g_drive_get_icon:
159  * @drive: a #GDrive.
160  * 
161  * Gets the icon for @drive.
162  * 
163  * Returns: #GIcon for the @drive.
164  *    Free the returned object with g_object_unref().
165  **/
166 GIcon *
167 g_drive_get_icon (GDrive *drive)
168 {
169   GDriveIface *iface;
170   
171   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
172
173   iface = G_DRIVE_GET_IFACE (drive);
174
175   return (* iface->get_icon) (drive);
176 }
177
178 /**
179  * g_drive_has_volumes:
180  * @drive: a #GDrive.
181  * 
182  * Check if @drive has any mountable volumes.
183  * 
184  * Returns: %TRUE if the @drive contains volumes, %FALSE otherwise.
185  **/
186 gboolean
187 g_drive_has_volumes (GDrive *drive)
188 {
189   GDriveIface *iface;
190
191   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
192
193   iface = G_DRIVE_GET_IFACE (drive);
194
195   return (* iface->has_volumes) (drive);
196 }
197
198 /**
199  * g_drive_get_volumes:
200  * @drive: a #GDrive.
201  * 
202  * Get a list of mountable volumes for @drive.
203  *
204  * The returned list should be freed with g_list_free(), after
205  * its elements have been unreffed with g_object_unref().
206  * 
207  * Returns: #GList containing any #GVolume objects on the given @drive.
208  **/
209 GList *
210 g_drive_get_volumes (GDrive *drive)
211 {
212   GDriveIface *iface;
213
214   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
215
216   iface = G_DRIVE_GET_IFACE (drive);
217
218   return (* iface->get_volumes) (drive);
219 }
220
221 /**
222  * g_drive_is_media_check_automatic:
223  * @drive: a #GDrive.
224  * 
225  * Checks if @drive is capabable of automatically detecting media changes.
226  * 
227  * Returns: %TRUE if the @drive is capabable of automatically detecting 
228  *     media changes, %FALSE otherwise.
229  **/
230 gboolean
231 g_drive_is_media_check_automatic (GDrive *drive)
232 {
233   GDriveIface *iface;
234
235   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
236
237   iface = G_DRIVE_GET_IFACE (drive);
238
239   return (* iface->is_media_check_automatic) (drive);
240 }
241
242 /**
243  * g_drive_is_media_removable:
244  * @drive: a #GDrive.
245  * 
246  * Checks if the @drive supports removable media.
247  * 
248  * Returns: %TRUE if @drive supports removable media, %FALSE otherwise.
249  **/
250 gboolean
251 g_drive_is_media_removable (GDrive *drive)
252 {
253   GDriveIface *iface;
254
255   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
256
257   iface = G_DRIVE_GET_IFACE (drive);
258
259   return (* iface->is_media_removable) (drive);
260 }
261
262 /**
263  * g_drive_has_media:
264  * @drive: a #GDrive.
265  * 
266  * Checks if the @drive has media. Note that the OS may not be polling
267  * the drive for media changes; see g_drive_is_media_check_automatic()
268  * for more details.
269  * 
270  * Returns: %TRUE if @drive has media, %FALSE otherwise.
271  **/
272 gboolean
273 g_drive_has_media (GDrive *drive)
274 {
275   GDriveIface *iface;
276
277   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
278
279   iface = G_DRIVE_GET_IFACE (drive);
280
281   return (* iface->has_media) (drive);
282 }
283
284 /**
285  * g_drive_can_eject:
286  * @drive: a #GDrive.
287  * 
288  * Checks if a drive can be ejected.
289  * 
290  * Returns: %TRUE if the @drive can be ejected, %FALSE otherwise.
291  **/
292 gboolean
293 g_drive_can_eject (GDrive *drive)
294 {
295   GDriveIface *iface;
296
297   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
298
299   iface = G_DRIVE_GET_IFACE (drive);
300
301   if (iface->can_eject == NULL)
302     return FALSE;
303
304   return (* iface->can_eject) (drive);
305 }
306
307 /**
308  * g_drive_can_poll_for_media:
309  * @drive: a #GDrive.
310  * 
311  * Checks if a drive can be polled for media changes.
312  * 
313  * Returns: %TRUE if the @drive can be polled for media changes,
314  *     %FALSE otherwise.
315  **/
316 gboolean
317 g_drive_can_poll_for_media (GDrive *drive)
318 {
319   GDriveIface *iface;
320
321   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
322
323   iface = G_DRIVE_GET_IFACE (drive);
324
325   if (iface->poll_for_media == NULL)
326     return FALSE;
327
328   return (* iface->can_poll_for_media) (drive);
329 }
330
331 /**
332  * g_drive_eject:
333  * @drive: a #GDrive.
334  * @flags: flags affecting the unmount if required for eject
335  * @cancellable: optional #GCancellable object, %NULL to ignore.
336  * @callback: a #GAsyncReadyCallback, or %NULL.
337  * @user_data: user data to pass to @callback
338  * 
339  * Asynchronously ejects a drive.
340  *
341  * When the operation is finished, @callback will be called.
342  * You can then call g_drive_eject_finish() to obtain the
343  * result of the operation.
344  *
345  * Deprecated: 2.22: Use g_drive_eject_with_operation() instead.
346  **/
347 void
348 g_drive_eject (GDrive              *drive,
349                GMountUnmountFlags   flags,
350                GCancellable        *cancellable,
351                GAsyncReadyCallback  callback,
352                gpointer             user_data)
353 {
354   GDriveIface *iface;
355
356   g_return_if_fail (G_IS_DRIVE (drive));
357
358   iface = G_DRIVE_GET_IFACE (drive);
359
360   if (iface->eject == NULL)
361     {
362       g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
363                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
364                                            _("drive doesn't implement eject"));
365       
366       return;
367     }
368   
369   (* iface->eject) (drive, flags, cancellable, callback, user_data);
370 }
371
372 /**
373  * g_drive_eject_finish:
374  * @drive: a #GDrive.
375  * @result: a #GAsyncResult.
376  * @error: a #GError, or %NULL
377  * 
378  * Finishes ejecting a drive.
379  * 
380  * Returns: %TRUE if the drive has been ejected successfully,
381  *     %FALSE otherwise.
382  *
383  * Deprecated: 2.22: Use g_drive_eject_with_operation_finish() instead.
384  **/
385 gboolean
386 g_drive_eject_finish (GDrive        *drive,
387                       GAsyncResult  *result,
388                       GError       **error)
389 {
390   GDriveIface *iface;
391
392   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
393   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
394
395   if (G_IS_SIMPLE_ASYNC_RESULT (result))
396     {
397       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
398       if (g_simple_async_result_propagate_error (simple, error))
399         return FALSE;
400     }
401   
402   iface = G_DRIVE_GET_IFACE (drive);
403   
404   return (* iface->eject_finish) (drive, result, error);
405 }
406
407 /**
408  * g_drive_eject_with_operation:
409  * @drive: a #GDrive.
410  * @flags: flags affecting the unmount if required for eject
411  * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
412  * @cancellable: optional #GCancellable object, %NULL to ignore.
413  * @callback: a #GAsyncReadyCallback, or %NULL.
414  * @user_data: user data passed to @callback.
415  *
416  * Ejects a drive. This is an asynchronous operation, and is
417  * finished by calling g_drive_eject_with_operation_finish() with the @drive
418  * and #GAsyncResult data returned in the @callback.
419  *
420  * Since: 2.22
421  **/
422 void
423 g_drive_eject_with_operation (GDrive              *drive,
424                               GMountUnmountFlags   flags,
425                               GMountOperation     *mount_operation,
426                               GCancellable        *cancellable,
427                               GAsyncReadyCallback  callback,
428                               gpointer             user_data)
429 {
430   GDriveIface *iface;
431
432   g_return_if_fail (G_IS_DRIVE (drive));
433
434   iface = G_DRIVE_GET_IFACE (drive);
435
436   if (iface->eject == NULL && iface->eject_with_operation == NULL)
437     {
438       g_simple_async_report_error_in_idle (G_OBJECT (drive),
439                                            callback, user_data,
440                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
441                                            /* Translators: This is an error
442                                             * message for drive objects that
443                                             * don't implement any of eject or eject_with_operation. */
444                                            _("drive doesn't implement eject or eject_with_operation"));
445       return;
446     }
447
448   if (iface->eject_with_operation != NULL)
449     (* iface->eject_with_operation) (drive, flags, mount_operation, cancellable, callback, user_data);
450   else
451     (* iface->eject) (drive, flags, cancellable, callback, user_data);
452 }
453
454 /**
455  * g_drive_eject_with_operation_finish:
456  * @drive: a #GDrive.
457  * @result: a #GAsyncResult.
458  * @error: a #GError location to store the error occuring, or %NULL to
459  *     ignore.
460  *
461  * Finishes ejecting a drive. If any errors occurred during the operation,
462  * @error will be set to contain the errors and %FALSE will be returned.
463  *
464  * Returns: %TRUE if the drive was successfully ejected. %FALSE otherwise.
465  *
466  * Since: 2.22
467  **/
468 gboolean
469 g_drive_eject_with_operation_finish (GDrive        *drive,
470                                      GAsyncResult  *result,
471                                      GError       **error)
472 {
473   GDriveIface *iface;
474
475   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
476   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
477
478   if (G_IS_SIMPLE_ASYNC_RESULT (result))
479     {
480       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
481       if (g_simple_async_result_propagate_error (simple, error))
482         return FALSE;
483     }
484
485   iface = G_DRIVE_GET_IFACE (drive);
486   if (iface->eject_with_operation_finish != NULL)
487     return (* iface->eject_with_operation_finish) (drive, result, error);
488   else
489     return (* iface->eject_finish) (drive, result, error);
490 }
491
492 /**
493  * g_drive_poll_for_media:
494  * @drive: a #GDrive.
495  * @cancellable: optional #GCancellable object, %NULL to ignore.
496  * @callback: a #GAsyncReadyCallback, or %NULL.
497  * @user_data: user data to pass to @callback
498  * 
499  * Asynchronously polls @drive to see if media has been inserted or removed.
500  * 
501  * When the operation is finished, @callback will be called.
502  * You can then call g_drive_poll_for_media_finish() to obtain the
503  * result of the operation.
504  **/
505 void
506 g_drive_poll_for_media (GDrive              *drive,
507                         GCancellable        *cancellable,
508                         GAsyncReadyCallback  callback,
509                         gpointer             user_data)
510 {
511   GDriveIface *iface;
512
513   g_return_if_fail (G_IS_DRIVE (drive));
514
515   iface = G_DRIVE_GET_IFACE (drive);
516
517   if (iface->poll_for_media == NULL)
518     {
519       g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
520                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
521                                            _("drive doesn't implement polling for media"));
522       
523       return;
524     }
525   
526   (* iface->poll_for_media) (drive, cancellable, callback, user_data);
527 }
528
529 /**
530  * g_drive_poll_for_media_finish:
531  * @drive: a #GDrive.
532  * @result: a #GAsyncResult.
533  * @error: a #GError, or %NULL
534  * 
535  * Finishes an operation started with g_drive_poll_for_media() on a drive.
536  * 
537  * Returns: %TRUE if the drive has been poll_for_mediaed successfully,
538  *     %FALSE otherwise.
539  **/
540 gboolean
541 g_drive_poll_for_media_finish (GDrive        *drive,
542                                GAsyncResult  *result,
543                                GError       **error)
544 {
545   GDriveIface *iface;
546
547   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
548   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
549
550   if (G_IS_SIMPLE_ASYNC_RESULT (result))
551     {
552       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
553       if (g_simple_async_result_propagate_error (simple, error))
554         return FALSE;
555     }
556   
557   iface = G_DRIVE_GET_IFACE (drive);
558   
559   return (* iface->poll_for_media_finish) (drive, result, error);
560 }
561
562 /**
563  * g_drive_get_identifier:
564  * @drive: a #GDrive
565  * @kind: the kind of identifier to return
566  *
567  * Gets the identifier of the given kind for @drive.
568  *
569  * Returns: a newly allocated string containing the
570  *     requested identfier, or %NULL if the #GDrive
571  *     doesn't have this kind of identifier.
572  */
573 char *
574 g_drive_get_identifier (GDrive     *drive,
575                         const char *kind)
576 {
577   GDriveIface *iface;
578
579   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
580   g_return_val_if_fail (kind != NULL, NULL);
581
582   iface = G_DRIVE_GET_IFACE (drive);
583
584   if (iface->get_identifier == NULL)
585     return NULL;
586   
587   return (* iface->get_identifier) (drive, kind);
588 }
589
590 /**
591  * g_drive_enumerate_identifiers:
592  * @drive: a #GDrive
593  *
594  * Gets the kinds of identifiers that @drive has. 
595  * Use g_drive_get_identifer() to obtain the identifiers
596  * themselves.
597  *
598  * Returns: a %NULL-terminated array of strings containing
599  *     kinds of identifiers. Use g_strfreev() to free.
600  */
601 char **
602 g_drive_enumerate_identifiers (GDrive *drive)
603 {
604   GDriveIface *iface;
605
606   g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
607   iface = G_DRIVE_GET_IFACE (drive);
608
609   if (iface->enumerate_identifiers == NULL)
610     return NULL;
611   
612   return (* iface->enumerate_identifiers) (drive);
613 }
614
615 /**
616  * g_drive_get_start_stop_type:
617  * @drive: a #GDrive.
618  *
619  * Gets a hint about how a drive can be started/stopped.
620  *
621  * Returns: A value from the #GDriveStartStopType enumeration.
622  *
623  * Since: 2.22
624  */
625 GDriveStartStopType
626 g_drive_get_start_stop_type (GDrive *drive)
627 {
628   GDriveIface *iface;
629
630   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
631
632   iface = G_DRIVE_GET_IFACE (drive);
633
634   if (iface->get_start_stop_type == NULL)
635     return G_DRIVE_START_STOP_TYPE_UNKNOWN;
636
637   return (* iface->get_start_stop_type) (drive);
638 }
639
640
641 /**
642  * g_drive_can_start:
643  * @drive: a #GDrive.
644  *
645  * Checks if a drive can be started.
646  *
647  * Returns: %TRUE if the @drive can be started, %FALSE otherwise.
648  *
649  * Since: 2.22
650  */
651 gboolean
652 g_drive_can_start (GDrive *drive)
653 {
654   GDriveIface *iface;
655
656   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
657
658   iface = G_DRIVE_GET_IFACE (drive);
659
660   if (iface->can_start == NULL)
661     return FALSE;
662
663   return (* iface->can_start) (drive);
664 }
665
666 /**
667  * g_drive_can_start_degraded:
668  * @drive: a #GDrive.
669  *
670  * Checks if a drive can be started degraded.
671  *
672  * Returns: %TRUE if the @drive can be started degraded, %FALSE otherwise.
673  *
674  * Since: 2.22
675  */
676 gboolean
677 g_drive_can_start_degraded (GDrive *drive)
678 {
679   GDriveIface *iface;
680
681   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
682
683   iface = G_DRIVE_GET_IFACE (drive);
684
685   if (iface->can_start_degraded == NULL)
686     return FALSE;
687
688   return (* iface->can_start_degraded) (drive);
689 }
690
691 /**
692  * g_drive_start:
693  * @drive: a #GDrive.
694  * @flags: flags affecting the start operation.
695  * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
696  * @cancellable: optional #GCancellable object, %NULL to ignore.
697  * @callback: a #GAsyncReadyCallback, or %NULL.
698  * @user_data: user data to pass to @callback
699  *
700  * Asynchronously starts a drive.
701  *
702  * When the operation is finished, @callback will be called.
703  * You can then call g_drive_start_finish() to obtain the
704  * result of the operation.
705  *
706  * Since: 2.22
707  */
708 void
709 g_drive_start (GDrive              *drive,
710                GDriveStartFlags     flags,
711                GMountOperation     *mount_operation,
712                GCancellable        *cancellable,
713                GAsyncReadyCallback  callback,
714                gpointer             user_data)
715 {
716   GDriveIface *iface;
717
718   g_return_if_fail (G_IS_DRIVE (drive));
719
720   iface = G_DRIVE_GET_IFACE (drive);
721
722   if (iface->start == NULL)
723     {
724       g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
725                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
726                                            _("drive doesn't implement start"));
727       return;
728     }
729
730   (* iface->start) (drive, flags, mount_operation, cancellable, callback, user_data);
731 }
732
733 /**
734  * g_drive_start_finish:
735  * @drive: a #GDrive.
736  * @result: a #GAsyncResult.
737  * @error: a #GError, or %NULL
738  *
739  * Finishes starting a drive.
740  *
741  * Returns: %TRUE if the drive has been started successfully,
742  *     %FALSE otherwise.
743  *
744  * Since: 2.22
745  */
746 gboolean
747 g_drive_start_finish (GDrive         *drive,
748                       GAsyncResult   *result,
749                       GError        **error)
750 {
751   GDriveIface *iface;
752
753   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
754   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
755
756   if (G_IS_SIMPLE_ASYNC_RESULT (result))
757     {
758       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
759       if (g_simple_async_result_propagate_error (simple, error))
760         return FALSE;
761     }
762
763   iface = G_DRIVE_GET_IFACE (drive);
764
765   return (* iface->start_finish) (drive, result, error);
766 }
767
768 /**
769  * g_drive_can_stop:
770  * @drive: a #GDrive.
771  *
772  * Checks if a drive can be stopped.
773  *
774  * Returns: %TRUE if the @drive can be stopped, %FALSE otherwise.
775  *
776  * Since: 2.22
777  */
778 gboolean
779 g_drive_can_stop (GDrive *drive)
780 {
781   GDriveIface *iface;
782
783   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
784
785   iface = G_DRIVE_GET_IFACE (drive);
786
787   if (iface->can_stop == NULL)
788     return FALSE;
789
790   return (* iface->can_stop) (drive);
791 }
792
793 /**
794  * g_drive_stop:
795  * @drive: a #GDrive.
796  * @flags: flags affecting the unmount if required for stopping.
797  * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
798  * @cancellable: optional #GCancellable object, %NULL to ignore.
799  * @callback: a #GAsyncReadyCallback, or %NULL.
800  * @user_data: user data to pass to @callback
801  *
802  * Asynchronously stops a drive.
803  *
804  * When the operation is finished, @callback will be called.
805  * You can then call g_drive_stop_finish() to obtain the
806  * result of the operation.
807  *
808  * Since: 2.22
809  */
810 void
811 g_drive_stop (GDrive               *drive,
812               GMountUnmountFlags    flags,
813               GMountOperation      *mount_operation,
814               GCancellable         *cancellable,
815               GAsyncReadyCallback   callback,
816               gpointer              user_data)
817 {
818   GDriveIface *iface;
819
820   g_return_if_fail (G_IS_DRIVE (drive));
821
822   iface = G_DRIVE_GET_IFACE (drive);
823
824   if (iface->stop == NULL)
825     {
826       g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
827                                            G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
828                                            _("drive doesn't implement stop"));
829       return;
830     }
831
832   (* iface->stop) (drive, flags, mount_operation, cancellable, callback, user_data);
833 }
834
835 /**
836  * g_drive_stop_finish:
837  * @drive: a #GDrive.
838  * @result: a #GAsyncResult.
839  * @error: a #GError, or %NULL
840  *
841  * Finishes stopping a drive.
842  *
843  * Returns: %TRUE if the drive has been stopped successfully,
844  *     %FALSE otherwise.
845  *
846  * Since: 2.22
847  */
848 gboolean
849 g_drive_stop_finish (GDrive        *drive,
850                      GAsyncResult  *result,
851                      GError       **error)
852 {
853   GDriveIface *iface;
854
855   g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
856   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
857
858   if (G_IS_SIMPLE_ASYNC_RESULT (result))
859     {
860       GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
861       if (g_simple_async_result_propagate_error (simple, error))
862         return FALSE;
863     }
864
865   iface = G_DRIVE_GET_IFACE (drive);
866
867   return (* iface->stop_finish) (drive, result, error);
868 }
869
870 #define __G_DRIVE_C__
871 #include "gioaliasdef.c"