Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ |
2 | | |
3 | | /* GIO - GLib Input, Output and Streaming Library |
4 | | * |
5 | | * Copyright (C) 2006-2008 Red Hat, Inc. |
6 | | * |
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.1 of the License, or (at your option) any later version. |
11 | | * |
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. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General |
18 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 | | * |
20 | | * Author: Alexander Larsson <alexl@redhat.com> |
21 | | * David Zeuthen <davidz@redhat.com> |
22 | | */ |
23 | | |
24 | | #include "config.h" |
25 | | |
26 | | #include <string.h> |
27 | | |
28 | | #include "gmount.h" |
29 | | #include "gmountprivate.h" |
30 | | #include "gthemedicon.h" |
31 | | #include "gasyncresult.h" |
32 | | #include "gtask.h" |
33 | | #include "gioerror.h" |
34 | | #include "glibintl.h" |
35 | | |
36 | | |
37 | | /** |
38 | | * SECTION:gmount |
39 | | * @short_description: Mount management |
40 | | * @include: gio/gio.h |
41 | | * @see_also: GVolume, GUnixMountEntry, GUnixMountPoint |
42 | | * |
43 | | * The #GMount interface represents user-visible mounts. Note, when |
44 | | * porting from GnomeVFS, #GMount is the moral equivalent of #GnomeVFSVolume. |
45 | | * |
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. |
50 | | * |
51 | | * Unmounting a #GMount instance is an asynchronous operation. For |
52 | | * more information about asynchronous operations, see #GAsyncResult |
53 | | * and #GTask. To unmount a #GMount instance, first call |
54 | | * g_mount_unmount_with_operation() 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 | | * #GAsyncResult structure will be passed to the callback. That |
58 | | * callback should then call g_mount_unmount_with_operation_finish() with the #GMount |
59 | | * and the #GAsyncResult data to see if the operation was completed |
60 | | * successfully. If an @error is present when g_mount_unmount_with_operation_finish() |
61 | | * is called, then it will be filled with any error information. |
62 | | **/ |
63 | | |
64 | | typedef GMountIface GMountInterface; |
65 | | G_DEFINE_INTERFACE (GMount, g_mount, G_TYPE_OBJECT) |
66 | | |
67 | | static void |
68 | | g_mount_default_init (GMountInterface *iface) |
69 | 0 | { |
70 | | /** |
71 | | * GMount::changed: |
72 | | * @mount: the object on which the signal is emitted |
73 | | * |
74 | | * Emitted when the mount has been changed. |
75 | | **/ |
76 | 0 | g_signal_new (I_("changed"), |
77 | 0 | G_TYPE_MOUNT, |
78 | 0 | G_SIGNAL_RUN_LAST, |
79 | 0 | G_STRUCT_OFFSET (GMountIface, changed), |
80 | 0 | NULL, NULL, |
81 | 0 | NULL, |
82 | 0 | G_TYPE_NONE, 0); |
83 | | |
84 | | /** |
85 | | * GMount::unmounted: |
86 | | * @mount: the object on which the signal is emitted |
87 | | * |
88 | | * This signal is emitted when the #GMount have been |
89 | | * unmounted. If the recipient is holding references to the |
90 | | * object they should release them so the object can be |
91 | | * finalized. |
92 | | **/ |
93 | 0 | g_signal_new (I_("unmounted"), |
94 | 0 | G_TYPE_MOUNT, |
95 | 0 | G_SIGNAL_RUN_LAST, |
96 | 0 | G_STRUCT_OFFSET (GMountIface, unmounted), |
97 | 0 | NULL, NULL, |
98 | 0 | NULL, |
99 | 0 | G_TYPE_NONE, 0); |
100 | | /** |
101 | | * GMount::pre-unmount: |
102 | | * @mount: the object on which the signal is emitted |
103 | | * |
104 | | * This signal may be emitted when the #GMount is about to be |
105 | | * unmounted. |
106 | | * |
107 | | * This signal depends on the backend and is only emitted if |
108 | | * GIO was used to unmount. |
109 | | * |
110 | | * Since: 2.22 |
111 | | **/ |
112 | 0 | g_signal_new (I_("pre-unmount"), |
113 | 0 | G_TYPE_MOUNT, |
114 | 0 | G_SIGNAL_RUN_LAST, |
115 | 0 | G_STRUCT_OFFSET (GMountIface, pre_unmount), |
116 | 0 | NULL, NULL, |
117 | 0 | NULL, |
118 | 0 | G_TYPE_NONE, 0); |
119 | 0 | } |
120 | | |
121 | | /** |
122 | | * g_mount_get_root: |
123 | | * @mount: a #GMount. |
124 | | * |
125 | | * Gets the root directory on @mount. |
126 | | * |
127 | | * Returns: (transfer full): a #GFile. |
128 | | * The returned object should be unreffed with |
129 | | * g_object_unref() when no longer needed. |
130 | | **/ |
131 | | GFile * |
132 | | g_mount_get_root (GMount *mount) |
133 | 0 | { |
134 | 0 | GMountIface *iface; |
135 | |
|
136 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
137 | | |
138 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
139 | |
|
140 | 0 | return (* iface->get_root) (mount); |
141 | 0 | } |
142 | | |
143 | | /** |
144 | | * g_mount_get_default_location: |
145 | | * @mount: a #GMount. |
146 | | * |
147 | | * Gets the default location of @mount. The default location of the given |
148 | | * @mount is a path that reflects the main entry point for the user (e.g. |
149 | | * the home directory, or the root of the volume). |
150 | | * |
151 | | * Returns: (transfer full): a #GFile. |
152 | | * The returned object should be unreffed with |
153 | | * g_object_unref() when no longer needed. |
154 | | **/ |
155 | | GFile * |
156 | | g_mount_get_default_location (GMount *mount) |
157 | 0 | { |
158 | 0 | GMountIface *iface; |
159 | 0 | GFile *file; |
160 | |
|
161 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
162 | | |
163 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
164 | | |
165 | | /* Fallback to get_root when default_location () is not available */ |
166 | 0 | if (iface->get_default_location) |
167 | 0 | file = (* iface->get_default_location) (mount); |
168 | 0 | else |
169 | 0 | file = (* iface->get_root) (mount); |
170 | |
|
171 | 0 | return file; |
172 | 0 | } |
173 | | |
174 | | /** |
175 | | * g_mount_get_name: |
176 | | * @mount: a #GMount. |
177 | | * |
178 | | * Gets the name of @mount. |
179 | | * |
180 | | * Returns: the name for the given @mount. |
181 | | * The returned string should be freed with g_free() |
182 | | * when no longer needed. |
183 | | **/ |
184 | | char * |
185 | | g_mount_get_name (GMount *mount) |
186 | 0 | { |
187 | 0 | GMountIface *iface; |
188 | |
|
189 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
190 | | |
191 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
192 | |
|
193 | 0 | return (* iface->get_name) (mount); |
194 | 0 | } |
195 | | |
196 | | /** |
197 | | * g_mount_get_icon: |
198 | | * @mount: a #GMount. |
199 | | * |
200 | | * Gets the icon for @mount. |
201 | | * |
202 | | * Returns: (transfer full): a #GIcon. |
203 | | * The returned object should be unreffed with |
204 | | * g_object_unref() when no longer needed. |
205 | | **/ |
206 | | GIcon * |
207 | | g_mount_get_icon (GMount *mount) |
208 | 0 | { |
209 | 0 | GMountIface *iface; |
210 | |
|
211 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
212 | | |
213 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
214 | |
|
215 | 0 | return (* iface->get_icon) (mount); |
216 | 0 | } |
217 | | |
218 | | |
219 | | /** |
220 | | * g_mount_get_symbolic_icon: |
221 | | * @mount: a #GMount. |
222 | | * |
223 | | * Gets the symbolic icon for @mount. |
224 | | * |
225 | | * Returns: (transfer full): a #GIcon. |
226 | | * The returned object should be unreffed with |
227 | | * g_object_unref() when no longer needed. |
228 | | * |
229 | | * Since: 2.34 |
230 | | **/ |
231 | | GIcon * |
232 | | g_mount_get_symbolic_icon (GMount *mount) |
233 | 0 | { |
234 | 0 | GMountIface *iface; |
235 | 0 | GIcon *ret; |
236 | |
|
237 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
238 | | |
239 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
240 | |
|
241 | 0 | if (iface->get_symbolic_icon != NULL) |
242 | 0 | ret = iface->get_symbolic_icon (mount); |
243 | 0 | else |
244 | 0 | ret = g_themed_icon_new_with_default_fallbacks ("folder-remote-symbolic"); |
245 | |
|
246 | 0 | return ret; |
247 | 0 | } |
248 | | |
249 | | /** |
250 | | * g_mount_get_uuid: |
251 | | * @mount: a #GMount. |
252 | | * |
253 | | * Gets the UUID for the @mount. The reference is typically based on |
254 | | * the file system UUID for the mount in question and should be |
255 | | * considered an opaque string. Returns %NULL if there is no UUID |
256 | | * available. |
257 | | * |
258 | | * Returns: (nullable) (transfer full): the UUID for @mount or %NULL if no UUID |
259 | | * can be computed. |
260 | | * The returned string should be freed with g_free() |
261 | | * when no longer needed. |
262 | | **/ |
263 | | char * |
264 | | g_mount_get_uuid (GMount *mount) |
265 | 0 | { |
266 | 0 | GMountIface *iface; |
267 | |
|
268 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
269 | | |
270 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
271 | |
|
272 | 0 | return (* iface->get_uuid) (mount); |
273 | 0 | } |
274 | | |
275 | | /** |
276 | | * g_mount_get_volume: |
277 | | * @mount: a #GMount. |
278 | | * |
279 | | * Gets the volume for the @mount. |
280 | | * |
281 | | * Returns: (transfer full) (nullable): a #GVolume or %NULL if @mount is not |
282 | | * associated with a volume. |
283 | | * The returned object should be unreffed with |
284 | | * g_object_unref() when no longer needed. |
285 | | **/ |
286 | | GVolume * |
287 | | g_mount_get_volume (GMount *mount) |
288 | 0 | { |
289 | 0 | GMountIface *iface; |
290 | |
|
291 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
292 | | |
293 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
294 | |
|
295 | 0 | return (* iface->get_volume) (mount); |
296 | 0 | } |
297 | | |
298 | | /** |
299 | | * g_mount_get_drive: |
300 | | * @mount: a #GMount. |
301 | | * |
302 | | * Gets the drive for the @mount. |
303 | | * |
304 | | * This is a convenience method for getting the #GVolume and then |
305 | | * using that object to get the #GDrive. |
306 | | * |
307 | | * Returns: (transfer full) (nullable): a #GDrive or %NULL if @mount is not |
308 | | * associated with a volume or a drive. |
309 | | * The returned object should be unreffed with |
310 | | * g_object_unref() when no longer needed. |
311 | | **/ |
312 | | GDrive * |
313 | | g_mount_get_drive (GMount *mount) |
314 | 0 | { |
315 | 0 | GMountIface *iface; |
316 | |
|
317 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
318 | | |
319 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
320 | |
|
321 | 0 | return (* iface->get_drive) (mount); |
322 | 0 | } |
323 | | |
324 | | /** |
325 | | * g_mount_can_unmount: |
326 | | * @mount: a #GMount. |
327 | | * |
328 | | * Checks if @mount can be unmounted. |
329 | | * |
330 | | * Returns: %TRUE if the @mount can be unmounted. |
331 | | **/ |
332 | | gboolean |
333 | | g_mount_can_unmount (GMount *mount) |
334 | 0 | { |
335 | 0 | GMountIface *iface; |
336 | |
|
337 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
338 | | |
339 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
340 | |
|
341 | 0 | return (* iface->can_unmount) (mount); |
342 | 0 | } |
343 | | |
344 | | /** |
345 | | * g_mount_can_eject: |
346 | | * @mount: a #GMount. |
347 | | * |
348 | | * Checks if @mount can be ejected. |
349 | | * |
350 | | * Returns: %TRUE if the @mount can be ejected. |
351 | | **/ |
352 | | gboolean |
353 | | g_mount_can_eject (GMount *mount) |
354 | 0 | { |
355 | 0 | GMountIface *iface; |
356 | |
|
357 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
358 | | |
359 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
360 | |
|
361 | 0 | return (* iface->can_eject) (mount); |
362 | 0 | } |
363 | | |
364 | | /** |
365 | | * g_mount_unmount: |
366 | | * @mount: a #GMount. |
367 | | * @flags: flags affecting the operation |
368 | | * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore. |
369 | | * @callback: (nullable): a #GAsyncReadyCallback, or %NULL. |
370 | | * @user_data: user data passed to @callback. |
371 | | * |
372 | | * Unmounts a mount. This is an asynchronous operation, and is |
373 | | * finished by calling g_mount_unmount_finish() with the @mount |
374 | | * and #GAsyncResult data returned in the @callback. |
375 | | * |
376 | | * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead. |
377 | | **/ |
378 | | void |
379 | | g_mount_unmount (GMount *mount, |
380 | | GMountUnmountFlags flags, |
381 | | GCancellable *cancellable, |
382 | | GAsyncReadyCallback callback, |
383 | | gpointer user_data) |
384 | 0 | { |
385 | 0 | GMountIface *iface; |
386 | |
|
387 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
388 | | |
389 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
390 | |
|
391 | 0 | if (iface->unmount == NULL) |
392 | 0 | { |
393 | 0 | g_task_report_new_error (mount, callback, user_data, |
394 | 0 | g_mount_unmount_with_operation, |
395 | 0 | G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
396 | | /* Translators: This is an error |
397 | | * message for mount objects that |
398 | | * don't implement unmount. */ |
399 | 0 | _("mount doesn’t implement “unmount”")); |
400 | 0 | return; |
401 | 0 | } |
402 | | |
403 | 0 | (* iface->unmount) (mount, flags, cancellable, callback, user_data); |
404 | 0 | } |
405 | | |
406 | | /** |
407 | | * g_mount_unmount_finish: |
408 | | * @mount: a #GMount. |
409 | | * @result: a #GAsyncResult. |
410 | | * @error: a #GError location to store the error occurring, or %NULL to |
411 | | * ignore. |
412 | | * |
413 | | * Finishes unmounting a mount. If any errors occurred during the operation, |
414 | | * @error will be set to contain the errors and %FALSE will be returned. |
415 | | * |
416 | | * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise. |
417 | | * |
418 | | * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead. |
419 | | **/ |
420 | | gboolean |
421 | | g_mount_unmount_finish (GMount *mount, |
422 | | GAsyncResult *result, |
423 | | GError **error) |
424 | 0 | { |
425 | 0 | GMountIface *iface; |
426 | |
|
427 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
428 | 0 | g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); |
429 | | |
430 | 0 | if (g_async_result_legacy_propagate_error (result, error)) |
431 | 0 | return FALSE; |
432 | 0 | else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation)) |
433 | 0 | return g_task_propagate_boolean (G_TASK (result), error); |
434 | | |
435 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
436 | 0 | return (* iface->unmount_finish) (mount, result, error); |
437 | 0 | } |
438 | | |
439 | | |
440 | | /** |
441 | | * g_mount_eject: |
442 | | * @mount: a #GMount. |
443 | | * @flags: flags affecting the unmount if required for eject |
444 | | * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore. |
445 | | * @callback: (nullable): a #GAsyncReadyCallback, or %NULL. |
446 | | * @user_data: user data passed to @callback. |
447 | | * |
448 | | * Ejects a mount. This is an asynchronous operation, and is |
449 | | * finished by calling g_mount_eject_finish() with the @mount |
450 | | * and #GAsyncResult data returned in the @callback. |
451 | | * |
452 | | * Deprecated: 2.22: Use g_mount_eject_with_operation() instead. |
453 | | **/ |
454 | | void |
455 | | g_mount_eject (GMount *mount, |
456 | | GMountUnmountFlags flags, |
457 | | GCancellable *cancellable, |
458 | | GAsyncReadyCallback callback, |
459 | | gpointer user_data) |
460 | 0 | { |
461 | 0 | GMountIface *iface; |
462 | |
|
463 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
464 | | |
465 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
466 | |
|
467 | 0 | if (iface->eject == NULL) |
468 | 0 | { |
469 | 0 | g_task_report_new_error (mount, callback, user_data, |
470 | 0 | g_mount_eject_with_operation, |
471 | 0 | G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
472 | | /* Translators: This is an error |
473 | | * message for mount objects that |
474 | | * don't implement eject. */ |
475 | 0 | _("mount doesn’t implement “eject”")); |
476 | 0 | return; |
477 | 0 | } |
478 | | |
479 | 0 | (* iface->eject) (mount, flags, cancellable, callback, user_data); |
480 | 0 | } |
481 | | |
482 | | /** |
483 | | * g_mount_eject_finish: |
484 | | * @mount: a #GMount. |
485 | | * @result: a #GAsyncResult. |
486 | | * @error: a #GError location to store the error occurring, or %NULL to |
487 | | * ignore. |
488 | | * |
489 | | * Finishes ejecting a mount. If any errors occurred during the operation, |
490 | | * @error will be set to contain the errors and %FALSE will be returned. |
491 | | * |
492 | | * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise. |
493 | | * |
494 | | * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead. |
495 | | **/ |
496 | | gboolean |
497 | | g_mount_eject_finish (GMount *mount, |
498 | | GAsyncResult *result, |
499 | | GError **error) |
500 | 0 | { |
501 | 0 | GMountIface *iface; |
502 | |
|
503 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
504 | 0 | g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); |
505 | | |
506 | 0 | if (g_async_result_legacy_propagate_error (result, error)) |
507 | 0 | return FALSE; |
508 | 0 | else if (g_async_result_is_tagged (result, g_mount_eject_with_operation)) |
509 | 0 | return g_task_propagate_boolean (G_TASK (result), error); |
510 | | |
511 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
512 | 0 | return (* iface->eject_finish) (mount, result, error); |
513 | 0 | } |
514 | | |
515 | | /** |
516 | | * g_mount_unmount_with_operation: |
517 | | * @mount: a #GMount. |
518 | | * @flags: flags affecting the operation |
519 | | * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid |
520 | | * user interaction. |
521 | | * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore. |
522 | | * @callback: (nullable): a #GAsyncReadyCallback, or %NULL. |
523 | | * @user_data: user data passed to @callback. |
524 | | * |
525 | | * Unmounts a mount. This is an asynchronous operation, and is |
526 | | * finished by calling g_mount_unmount_with_operation_finish() with the @mount |
527 | | * and #GAsyncResult data returned in the @callback. |
528 | | * |
529 | | * Since: 2.22 |
530 | | **/ |
531 | | void |
532 | | g_mount_unmount_with_operation (GMount *mount, |
533 | | GMountUnmountFlags flags, |
534 | | GMountOperation *mount_operation, |
535 | | GCancellable *cancellable, |
536 | | GAsyncReadyCallback callback, |
537 | | gpointer user_data) |
538 | 0 | { |
539 | 0 | GMountIface *iface; |
540 | |
|
541 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
542 | | |
543 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
544 | |
|
545 | 0 | if (iface->unmount == NULL && iface->unmount_with_operation == NULL) |
546 | 0 | { |
547 | 0 | g_task_report_new_error (mount, callback, user_data, |
548 | 0 | g_mount_unmount_with_operation, |
549 | 0 | G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
550 | | /* Translators: This is an error |
551 | | * message for mount objects that |
552 | | * don't implement any of unmount or unmount_with_operation. */ |
553 | 0 | _("mount doesn’t implement “unmount” or “unmount_with_operation”")); |
554 | 0 | return; |
555 | 0 | } |
556 | | |
557 | 0 | if (iface->unmount_with_operation != NULL) |
558 | 0 | (* iface->unmount_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data); |
559 | 0 | else |
560 | 0 | (* iface->unmount) (mount, flags, cancellable, callback, user_data); |
561 | 0 | } |
562 | | |
563 | | /** |
564 | | * g_mount_unmount_with_operation_finish: |
565 | | * @mount: a #GMount. |
566 | | * @result: a #GAsyncResult. |
567 | | * @error: a #GError location to store the error occurring, or %NULL to |
568 | | * ignore. |
569 | | * |
570 | | * Finishes unmounting a mount. If any errors occurred during the operation, |
571 | | * @error will be set to contain the errors and %FALSE will be returned. |
572 | | * |
573 | | * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise. |
574 | | * |
575 | | * Since: 2.22 |
576 | | **/ |
577 | | gboolean |
578 | | g_mount_unmount_with_operation_finish (GMount *mount, |
579 | | GAsyncResult *result, |
580 | | GError **error) |
581 | 0 | { |
582 | 0 | GMountIface *iface; |
583 | |
|
584 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
585 | 0 | g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); |
586 | | |
587 | 0 | if (g_async_result_legacy_propagate_error (result, error)) |
588 | 0 | return FALSE; |
589 | 0 | else if (g_async_result_is_tagged (result, g_mount_unmount_with_operation)) |
590 | 0 | return g_task_propagate_boolean (G_TASK (result), error); |
591 | | |
592 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
593 | 0 | if (iface->unmount_with_operation_finish != NULL) |
594 | 0 | return (* iface->unmount_with_operation_finish) (mount, result, error); |
595 | 0 | else |
596 | 0 | return (* iface->unmount_finish) (mount, result, error); |
597 | 0 | } |
598 | | |
599 | | |
600 | | /** |
601 | | * g_mount_eject_with_operation: |
602 | | * @mount: a #GMount. |
603 | | * @flags: flags affecting the unmount if required for eject |
604 | | * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid |
605 | | * user interaction. |
606 | | * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore. |
607 | | * @callback: (nullable): a #GAsyncReadyCallback, or %NULL. |
608 | | * @user_data: user data passed to @callback. |
609 | | * |
610 | | * Ejects a mount. This is an asynchronous operation, and is |
611 | | * finished by calling g_mount_eject_with_operation_finish() with the @mount |
612 | | * and #GAsyncResult data returned in the @callback. |
613 | | * |
614 | | * Since: 2.22 |
615 | | **/ |
616 | | void |
617 | | g_mount_eject_with_operation (GMount *mount, |
618 | | GMountUnmountFlags flags, |
619 | | GMountOperation *mount_operation, |
620 | | GCancellable *cancellable, |
621 | | GAsyncReadyCallback callback, |
622 | | gpointer user_data) |
623 | 0 | { |
624 | 0 | GMountIface *iface; |
625 | |
|
626 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
627 | | |
628 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
629 | |
|
630 | 0 | if (iface->eject == NULL && iface->eject_with_operation == NULL) |
631 | 0 | { |
632 | 0 | g_task_report_new_error (mount, callback, user_data, |
633 | 0 | g_mount_eject_with_operation, |
634 | 0 | G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
635 | | /* Translators: This is an error |
636 | | * message for mount objects that |
637 | | * don't implement any of eject or eject_with_operation. */ |
638 | 0 | _("mount doesn’t implement “eject” or “eject_with_operation”")); |
639 | 0 | return; |
640 | 0 | } |
641 | | |
642 | 0 | if (iface->eject_with_operation != NULL) |
643 | 0 | (* iface->eject_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data); |
644 | 0 | else |
645 | 0 | (* iface->eject) (mount, flags, cancellable, callback, user_data); |
646 | 0 | } |
647 | | |
648 | | /** |
649 | | * g_mount_eject_with_operation_finish: |
650 | | * @mount: a #GMount. |
651 | | * @result: a #GAsyncResult. |
652 | | * @error: a #GError location to store the error occurring, or %NULL to |
653 | | * ignore. |
654 | | * |
655 | | * Finishes ejecting a mount. If any errors occurred during the operation, |
656 | | * @error will be set to contain the errors and %FALSE will be returned. |
657 | | * |
658 | | * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise. |
659 | | * |
660 | | * Since: 2.22 |
661 | | **/ |
662 | | gboolean |
663 | | g_mount_eject_with_operation_finish (GMount *mount, |
664 | | GAsyncResult *result, |
665 | | GError **error) |
666 | 0 | { |
667 | 0 | GMountIface *iface; |
668 | |
|
669 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
670 | 0 | g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); |
671 | | |
672 | 0 | if (g_async_result_legacy_propagate_error (result, error)) |
673 | 0 | return FALSE; |
674 | 0 | else if (g_async_result_is_tagged (result, g_mount_eject_with_operation)) |
675 | 0 | return g_task_propagate_boolean (G_TASK (result), error); |
676 | | |
677 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
678 | 0 | if (iface->eject_with_operation_finish != NULL) |
679 | 0 | return (* iface->eject_with_operation_finish) (mount, result, error); |
680 | 0 | else |
681 | 0 | return (* iface->eject_finish) (mount, result, error); |
682 | 0 | } |
683 | | |
684 | | /** |
685 | | * g_mount_remount: |
686 | | * @mount: a #GMount. |
687 | | * @flags: flags affecting the operation |
688 | | * @mount_operation: (nullable): a #GMountOperation or %NULL to avoid |
689 | | * user interaction. |
690 | | * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore. |
691 | | * @callback: (nullable): a #GAsyncReadyCallback, or %NULL. |
692 | | * @user_data: user data passed to @callback. |
693 | | * |
694 | | * Remounts a mount. This is an asynchronous operation, and is |
695 | | * finished by calling g_mount_remount_finish() with the @mount |
696 | | * and #GAsyncResults data returned in the @callback. |
697 | | * |
698 | | * Remounting is useful when some setting affecting the operation |
699 | | * of the volume has been changed, as these may need a remount to |
700 | | * take affect. While this is semantically equivalent with unmounting |
701 | | * and then remounting not all backends might need to actually be |
702 | | * unmounted. |
703 | | **/ |
704 | | void |
705 | | g_mount_remount (GMount *mount, |
706 | | GMountMountFlags flags, |
707 | | GMountOperation *mount_operation, |
708 | | GCancellable *cancellable, |
709 | | GAsyncReadyCallback callback, |
710 | | gpointer user_data) |
711 | 0 | { |
712 | 0 | GMountIface *iface; |
713 | |
|
714 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
715 | | |
716 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
717 | |
|
718 | 0 | if (iface->remount == NULL) |
719 | 0 | { |
720 | 0 | g_task_report_new_error (mount, callback, user_data, |
721 | 0 | g_mount_remount, |
722 | 0 | G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
723 | | /* Translators: This is an error |
724 | | * message for mount objects that |
725 | | * don't implement remount. */ |
726 | 0 | _("mount doesn’t implement “remount”")); |
727 | 0 | return; |
728 | 0 | } |
729 | | |
730 | 0 | (* iface->remount) (mount, flags, mount_operation, cancellable, callback, user_data); |
731 | 0 | } |
732 | | |
733 | | /** |
734 | | * g_mount_remount_finish: |
735 | | * @mount: a #GMount. |
736 | | * @result: a #GAsyncResult. |
737 | | * @error: a #GError location to store the error occurring, or %NULL to |
738 | | * ignore. |
739 | | * |
740 | | * Finishes remounting a mount. If any errors occurred during the operation, |
741 | | * @error will be set to contain the errors and %FALSE will be returned. |
742 | | * |
743 | | * Returns: %TRUE if the mount was successfully remounted. %FALSE otherwise. |
744 | | **/ |
745 | | gboolean |
746 | | g_mount_remount_finish (GMount *mount, |
747 | | GAsyncResult *result, |
748 | | GError **error) |
749 | 0 | { |
750 | 0 | GMountIface *iface; |
751 | |
|
752 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
753 | 0 | g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); |
754 | | |
755 | 0 | if (g_async_result_legacy_propagate_error (result, error)) |
756 | 0 | return FALSE; |
757 | 0 | else if (g_async_result_is_tagged (result, g_mount_remount)) |
758 | 0 | return g_task_propagate_boolean (G_TASK (result), error); |
759 | | |
760 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
761 | 0 | return (* iface->remount_finish) (mount, result, error); |
762 | 0 | } |
763 | | |
764 | | /** |
765 | | * g_mount_guess_content_type: |
766 | | * @mount: a #GMount |
767 | | * @force_rescan: Whether to force a rescan of the content. |
768 | | * Otherwise a cached result will be used if available |
769 | | * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore |
770 | | * @callback: a #GAsyncReadyCallback |
771 | | * @user_data: user data passed to @callback |
772 | | * |
773 | | * Tries to guess the type of content stored on @mount. Returns one or |
774 | | * more textual identifiers of well-known content types (typically |
775 | | * prefixed with "x-content/"), e.g. x-content/image-dcf for camera |
776 | | * memory cards. See the |
777 | | * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec) |
778 | | * specification for more on x-content types. |
779 | | * |
780 | | * This is an asynchronous operation (see |
781 | | * g_mount_guess_content_type_sync() for the synchronous version), and |
782 | | * is finished by calling g_mount_guess_content_type_finish() with the |
783 | | * @mount and #GAsyncResult data returned in the @callback. |
784 | | * |
785 | | * Since: 2.18 |
786 | | */ |
787 | | void |
788 | | g_mount_guess_content_type (GMount *mount, |
789 | | gboolean force_rescan, |
790 | | GCancellable *cancellable, |
791 | | GAsyncReadyCallback callback, |
792 | | gpointer user_data) |
793 | 0 | { |
794 | 0 | GMountIface *iface; |
795 | |
|
796 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
797 | | |
798 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
799 | |
|
800 | 0 | if (iface->guess_content_type == NULL) |
801 | 0 | { |
802 | 0 | g_task_report_new_error (mount, callback, user_data, |
803 | 0 | g_mount_guess_content_type, |
804 | 0 | G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
805 | | /* Translators: This is an error |
806 | | * message for mount objects that |
807 | | * don't implement content type guessing. */ |
808 | 0 | _("mount doesn’t implement content type guessing")); |
809 | 0 | return; |
810 | 0 | } |
811 | | |
812 | 0 | (* iface->guess_content_type) (mount, force_rescan, cancellable, callback, user_data); |
813 | 0 | } |
814 | | |
815 | | /** |
816 | | * g_mount_guess_content_type_finish: |
817 | | * @mount: a #GMount |
818 | | * @result: a #GAsyncResult |
819 | | * @error: a #GError location to store the error occurring, or %NULL to |
820 | | * ignore |
821 | | * |
822 | | * Finishes guessing content types of @mount. If any errors occurred |
823 | | * during the operation, @error will be set to contain the errors and |
824 | | * %FALSE will be returned. In particular, you may get an |
825 | | * %G_IO_ERROR_NOT_SUPPORTED if the mount does not support content |
826 | | * guessing. |
827 | | * |
828 | | * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error. |
829 | | * Caller should free this array with g_strfreev() when done with it. |
830 | | * |
831 | | * Since: 2.18 |
832 | | **/ |
833 | | gchar ** |
834 | | g_mount_guess_content_type_finish (GMount *mount, |
835 | | GAsyncResult *result, |
836 | | GError **error) |
837 | 0 | { |
838 | 0 | GMountIface *iface; |
839 | |
|
840 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
841 | 0 | g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL); |
842 | | |
843 | 0 | if (g_async_result_legacy_propagate_error (result, error)) |
844 | 0 | return NULL; |
845 | 0 | else if (g_async_result_is_tagged (result, g_mount_guess_content_type)) |
846 | 0 | return g_task_propagate_pointer (G_TASK (result), error); |
847 | | |
848 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
849 | 0 | return (* iface->guess_content_type_finish) (mount, result, error); |
850 | 0 | } |
851 | | |
852 | | /** |
853 | | * g_mount_guess_content_type_sync: |
854 | | * @mount: a #GMount |
855 | | * @force_rescan: Whether to force a rescan of the content. |
856 | | * Otherwise a cached result will be used if available |
857 | | * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore |
858 | | * @error: a #GError location to store the error occurring, or %NULL to |
859 | | * ignore |
860 | | * |
861 | | * Tries to guess the type of content stored on @mount. Returns one or |
862 | | * more textual identifiers of well-known content types (typically |
863 | | * prefixed with "x-content/"), e.g. x-content/image-dcf for camera |
864 | | * memory cards. See the |
865 | | * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec) |
866 | | * specification for more on x-content types. |
867 | | * |
868 | | * This is a synchronous operation and as such may block doing IO; |
869 | | * see g_mount_guess_content_type() for the asynchronous version. |
870 | | * |
871 | | * Returns: (transfer full) (element-type utf8): a %NULL-terminated array of content types or %NULL on error. |
872 | | * Caller should free this array with g_strfreev() when done with it. |
873 | | * |
874 | | * Since: 2.18 |
875 | | */ |
876 | | char ** |
877 | | g_mount_guess_content_type_sync (GMount *mount, |
878 | | gboolean force_rescan, |
879 | | GCancellable *cancellable, |
880 | | GError **error) |
881 | 0 | { |
882 | 0 | GMountIface *iface; |
883 | |
|
884 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
885 | | |
886 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
887 | |
|
888 | 0 | if (iface->guess_content_type_sync == NULL) |
889 | 0 | { |
890 | 0 | g_set_error_literal (error, |
891 | 0 | G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
892 | | /* Translators: This is an error |
893 | | * message for mount objects that |
894 | | * don't implement content type guessing. */ |
895 | 0 | _("mount doesn’t implement synchronous content type guessing")); |
896 | |
|
897 | 0 | return NULL; |
898 | 0 | } |
899 | | |
900 | 0 | return (* iface->guess_content_type_sync) (mount, force_rescan, cancellable, error); |
901 | 0 | } |
902 | | |
903 | | G_LOCK_DEFINE_STATIC (priv_lock); |
904 | | |
905 | | /* only access this structure when holding priv_lock */ |
906 | | typedef struct |
907 | | { |
908 | | gint shadow_ref_count; |
909 | | } GMountPrivate; |
910 | | |
911 | | static void |
912 | | free_private (GMountPrivate *private) |
913 | 0 | { |
914 | 0 | G_LOCK (priv_lock); |
915 | 0 | g_free (private); |
916 | 0 | G_UNLOCK (priv_lock); |
917 | 0 | } |
918 | | |
919 | | /* may only be called when holding priv_lock */ |
920 | | static GMountPrivate * |
921 | | get_private (GMount *mount) |
922 | 0 | { |
923 | 0 | GMountPrivate *private; |
924 | |
|
925 | 0 | private = g_object_get_data (G_OBJECT (mount), "g-mount-private"); |
926 | 0 | if (G_LIKELY (private != NULL)) |
927 | 0 | goto out; |
928 | | |
929 | 0 | private = g_new0 (GMountPrivate, 1); |
930 | 0 | g_object_set_data_full (G_OBJECT (mount), |
931 | 0 | "g-mount-private", |
932 | 0 | private, |
933 | 0 | (GDestroyNotify) free_private); |
934 | |
|
935 | 0 | out: |
936 | 0 | return private; |
937 | 0 | } |
938 | | |
939 | | /** |
940 | | * g_mount_is_shadowed: |
941 | | * @mount: A #GMount. |
942 | | * |
943 | | * Determines if @mount is shadowed. Applications or libraries should |
944 | | * avoid displaying @mount in the user interface if it is shadowed. |
945 | | * |
946 | | * A mount is said to be shadowed if there exists one or more user |
947 | | * visible objects (currently #GMount objects) with a root that is |
948 | | * inside the root of @mount. |
949 | | * |
950 | | * One application of shadow mounts is when exposing a single file |
951 | | * system that is used to address several logical volumes. In this |
952 | | * situation, a #GVolumeMonitor implementation would create two |
953 | | * #GVolume objects (for example, one for the camera functionality of |
954 | | * the device and one for a SD card reader on the device) with |
955 | | * activation URIs `gphoto2://[usb:001,002]/store1/` |
956 | | * and `gphoto2://[usb:001,002]/store2/`. When the |
957 | | * underlying mount (with root |
958 | | * `gphoto2://[usb:001,002]/`) is mounted, said |
959 | | * #GVolumeMonitor implementation would create two #GMount objects |
960 | | * (each with their root matching the corresponding volume activation |
961 | | * root) that would shadow the original mount. |
962 | | * |
963 | | * The proxy monitor in GVfs 2.26 and later, automatically creates and |
964 | | * manage shadow mounts (and shadows the underlying mount) if the |
965 | | * activation root on a #GVolume is set. |
966 | | * |
967 | | * Returns: %TRUE if @mount is shadowed. |
968 | | * |
969 | | * Since: 2.20 |
970 | | **/ |
971 | | gboolean |
972 | | g_mount_is_shadowed (GMount *mount) |
973 | 0 | { |
974 | 0 | GMountPrivate *priv; |
975 | 0 | gboolean ret; |
976 | |
|
977 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); |
978 | | |
979 | 0 | G_LOCK (priv_lock); |
980 | 0 | priv = get_private (mount); |
981 | 0 | ret = (priv->shadow_ref_count > 0); |
982 | 0 | G_UNLOCK (priv_lock); |
983 | |
|
984 | 0 | return ret; |
985 | 0 | } |
986 | | |
987 | | /** |
988 | | * g_mount_shadow: |
989 | | * @mount: A #GMount. |
990 | | * |
991 | | * Increments the shadow count on @mount. Usually used by |
992 | | * #GVolumeMonitor implementations when creating a shadow mount for |
993 | | * @mount, see g_mount_is_shadowed() for more information. The caller |
994 | | * will need to emit the #GMount::changed signal on @mount manually. |
995 | | * |
996 | | * Since: 2.20 |
997 | | **/ |
998 | | void |
999 | | g_mount_shadow (GMount *mount) |
1000 | 0 | { |
1001 | 0 | GMountPrivate *priv; |
1002 | |
|
1003 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
1004 | | |
1005 | 0 | G_LOCK (priv_lock); |
1006 | 0 | priv = get_private (mount); |
1007 | 0 | priv->shadow_ref_count += 1; |
1008 | 0 | G_UNLOCK (priv_lock); |
1009 | 0 | } |
1010 | | |
1011 | | /** |
1012 | | * g_mount_unshadow: |
1013 | | * @mount: A #GMount. |
1014 | | * |
1015 | | * Decrements the shadow count on @mount. Usually used by |
1016 | | * #GVolumeMonitor implementations when destroying a shadow mount for |
1017 | | * @mount, see g_mount_is_shadowed() for more information. The caller |
1018 | | * will need to emit the #GMount::changed signal on @mount manually. |
1019 | | * |
1020 | | * Since: 2.20 |
1021 | | **/ |
1022 | | void |
1023 | | g_mount_unshadow (GMount *mount) |
1024 | 0 | { |
1025 | 0 | GMountPrivate *priv; |
1026 | |
|
1027 | 0 | g_return_if_fail (G_IS_MOUNT (mount)); |
1028 | | |
1029 | 0 | G_LOCK (priv_lock); |
1030 | 0 | priv = get_private (mount); |
1031 | 0 | priv->shadow_ref_count -= 1; |
1032 | 0 | if (priv->shadow_ref_count < 0) |
1033 | 0 | g_warning ("Shadow ref count on GMount is negative"); |
1034 | 0 | G_UNLOCK (priv_lock); |
1035 | 0 | } |
1036 | | |
1037 | | /** |
1038 | | * g_mount_get_sort_key: |
1039 | | * @mount: A #GMount. |
1040 | | * |
1041 | | * Gets the sort key for @mount, if any. |
1042 | | * |
1043 | | * Returns: (nullable): Sorting key for @mount or %NULL if no such key is available. |
1044 | | * |
1045 | | * Since: 2.32 |
1046 | | */ |
1047 | | const gchar * |
1048 | | g_mount_get_sort_key (GMount *mount) |
1049 | 0 | { |
1050 | 0 | const gchar *ret = NULL; |
1051 | 0 | GMountIface *iface; |
1052 | |
|
1053 | 0 | g_return_val_if_fail (G_IS_MOUNT (mount), NULL); |
1054 | | |
1055 | 0 | iface = G_MOUNT_GET_IFACE (mount); |
1056 | 0 | if (iface->get_sort_key != NULL) |
1057 | 0 | ret = iface->get_sort_key (mount); |
1058 | |
|
1059 | 0 | return ret; |
1060 | 0 | } |