inline static gboolean automount_volume(GVolume* vol, gboolean silent) { GMount* mount; if(!g_volume_should_automount(vol) || !g_volume_can_mount(vol)) return FALSE; mount = g_volume_get_mount(vol); if(!mount) /* not mounted, automount is needed */ { g_debug("try automount"); if(!fm_mount_volume(NULL, vol, !silent)) return FALSE; if(silent) return TRUE; mount = g_volume_get_mount(vol); g_debug("mount = %p", mount); } if(mount) { if(!silent && app_config->autorun) /* show autorun dialog */ show_autorun_dlg(vol, mount); g_object_unref(mount); } return TRUE; }
static void list_volumes (GList *volumes, int indent, gboolean only_with_no_drive) { GList *l, *mounts; int c, i; GMount *mount; GVolume *volume; GDrive *drive; char *name; char *uuid; GFile *activation_root; char **ids; GIcon *icon; char *type_name; const gchar *sort_key; for (c = 0, l = volumes; l != NULL; l = l->next, c++) { volume = (GVolume *) l->data; if (only_with_no_drive) { drive = g_volume_get_drive (volume); if (drive != NULL) { g_object_unref (drive); continue; } } name = g_volume_get_name (volume); g_print ("%*sVolume(%d): %s\n", indent, "", c, name); g_free (name); type_name = get_type_name (volume); g_print ("%*sType: %s\n", indent+2, "", type_name); g_free (type_name); if (extra_detail) { ids = g_volume_enumerate_identifiers (volume); if (ids && ids[0] != NULL) { g_print ("%*sids:\n", indent+2, ""); for (i = 0; ids[i] != NULL; i++) { char *id = g_volume_get_identifier (volume, ids[i]); g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); g_free (id); } } g_strfreev (ids); uuid = g_volume_get_uuid (volume); if (uuid) g_print ("%*suuid=%s\n", indent + 2, "", uuid); activation_root = g_volume_get_activation_root (volume); if (activation_root) { char *uri; uri = g_file_get_uri (activation_root); g_print ("%*sactivation_root=%s\n", indent + 2, "", uri); g_free (uri); g_object_unref (activation_root); } icon = g_volume_get_icon (volume); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } g_print ("%*scan_mount=%d\n", indent + 2, "", g_volume_can_mount (volume)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_volume_can_eject (volume)); g_print ("%*sshould_automount=%d\n", indent + 2, "", g_volume_should_automount (volume)); sort_key = g_volume_get_sort_key (volume); if (sort_key != NULL) g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); g_free (uuid); } mount = g_volume_get_mount (volume); if (mount) { mounts = g_list_prepend (NULL, mount); list_mounts (mounts, indent + 2, FALSE); g_list_free (mounts); g_object_unref (mount); } } }
static void mount_add (TrackerStorage *storage, GMount *mount) { TrackerStoragePrivate *priv; GFile *root; GVolume *volume; gchar *mount_name, *mount_path, *uuid; gboolean is_optical = FALSE; gboolean is_removable = FALSE; /* Get mount name */ mount_name = g_mount_get_name (mount); /* Get root path of the mount */ root = g_mount_get_root (mount); mount_path = g_file_get_path (root); g_debug ("Found '%s' mounted on path '%s'", mount_name, mount_path); /* Do not process shadowed mounts! */ if (g_mount_is_shadowed (mount)) { g_debug (" Skipping shadowed mount '%s'", mount_name); g_object_unref (root); g_free (mount_path); g_free (mount_name); return; } priv = TRACKER_STORAGE_GET_PRIVATE (storage); /* fstab partitions may not have corresponding * GVolumes, so volume may be NULL */ volume = g_mount_get_volume (mount); if (volume) { /* GMount with GVolume */ /* Try to get UUID from the Volume. * Note that g_volume_get_uuid() is NOT equivalent */ uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID); if (!uuid) { gchar *content_type; gboolean is_multimedia; gboolean is_blank; /* Optical discs usually won't have UUID in the GVolume */ content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); is_removable = TRUE; /* We don't index content which is video, music or blank */ if (!is_multimedia && !is_blank) { uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, mount_name, -1); g_debug (" No UUID, generated:'%s' (based on mount name)", uuid); g_debug (" Assuming GVolume has removable media, if wrong report a bug! " "content type is '%s'", content_type); } else { g_debug (" Being ignored because mount with volume is music/video/blank " "(content type:%s, optical:%s, multimedia:%s, blank:%s)", content_type, is_optical ? "yes" : "no", is_multimedia ? "yes" : "no", is_blank ? "yes" : "no"); } g_free (content_type); } else { /* Any other removable media will have UUID in the * GVolume. Note that this also may include some * partitions in the machine which have GVolumes * associated to the GMounts. We also check a drive * exists to be sure the device is local. */ GDrive *drive; drive = g_volume_get_drive (volume); if (drive) { /* We can't mount/unmount system volumes, so tag * them as non removable. */ is_removable = g_volume_can_mount (volume); g_debug (" Found mount with volume and drive which %s be mounted: " "Assuming it's %s removable, if wrong report a bug!", is_removable ? "can" : "cannot", is_removable ? "" : "not"); g_object_unref (drive); } else { /* Note: not sure when this can happen... */ g_debug (" Mount with volume but no drive, " "assuming not a removable device, " "if wrong report a bug!"); is_removable = FALSE; } } g_object_unref (volume); } else { /* GMount without GVolume. * Note: Never found a case where this g_mount_get_uuid() returns * non-NULL... :-) */ uuid = g_mount_get_uuid (mount); if (!uuid) { if (mount_path) { gchar *content_type; gboolean is_multimedia; gboolean is_blank; content_type = mount_guess_content_type (mount, &is_optical, &is_multimedia, &is_blank); /* Note: for GMounts without GVolume, is_blank should NOT be considered, * as it may give unwanted results... */ if (!is_multimedia) { uuid = g_compute_checksum_for_string (G_CHECKSUM_MD5, mount_path, -1); g_debug (" No UUID, generated:'%s' (based on mount path)", uuid); } else { g_debug (" Being ignored because mount is music/video " "(content type:%s, optical:%s, multimedia:%s)", content_type, is_optical ? "yes" : "no", is_multimedia ? "yes" : "no"); } g_free (content_type); } else { g_debug (" Being ignored because mount has no GVolume (i.e. not user mountable) " "and has no mount root path available"); } } } /* If we got something to be used as UUID, then add the mount * to the TrackerStorage */ if (uuid && mount_path && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) { g_debug (" Adding mount point with UUID: '%s', removable: %s, optical: %s, path: '%s'", uuid, is_removable ? "yes" : "no", is_optical ? "yes" : "no", mount_path); mount_add_new (storage, uuid, mount_path, mount_name, is_removable, is_optical); } else { g_debug (" Skipping mount point with UUID: '%s', path: '%s', already managed: '%s'", uuid ? uuid : "none", mount_path ? mount_path : "none", (uuid && g_hash_table_lookup (priv->mounts_by_uuid, uuid)) ? "yes" : "no"); } g_free (mount_name); g_free (mount_path); g_free (uuid); g_object_unref (root); }
static VALUE rg_can_mount_p(VALUE self) { return CBOOL2RVAL(g_volume_can_mount(_SELF(self))); }
static gboolean xfdesktop_volume_icon_populate_context_menu(XfdesktopIcon *icon, GtkWidget *menu) { XfdesktopVolumeIcon *volume_icon = XFDESKTOP_VOLUME_ICON(icon); GVolume *volume = volume_icon->priv->volume; GtkWidget *mi, *img; GMount *mount; const gchar *icon_name, *icon_label; icon_name = GTK_STOCK_OPEN; img = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU); gtk_widget_show(img); mi = gtk_image_menu_item_new_with_mnemonic(_("_Open")); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img); gtk_widget_show(mi); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); g_signal_connect_swapped(G_OBJECT(mi), "activate", G_CALLBACK(xfdesktop_icon_activated), icon); mi = gtk_separator_menu_item_new(); gtk_widget_show(mi); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); mount = g_volume_get_mount(volume); if(mount && g_volume_can_eject(volume)) { icon_name = "media-eject"; icon_label = _("E_ject Volume"); xfdesktop_volume_icon_add_context_menu_option(icon, icon_name, icon_label, menu, G_CALLBACK(xfdesktop_volume_icon_menu_eject)); } if(mount && g_mount_can_unmount(mount)) { icon_name = NULL; icon_label = _("_Unmount Volume"); xfdesktop_volume_icon_add_context_menu_option(icon, icon_name, icon_label, menu, G_CALLBACK(xfdesktop_volume_icon_menu_unmount)); } if(!mount && g_volume_can_mount(volume)) { icon_name = NULL; icon_label = _("_Mount Volume"); xfdesktop_volume_icon_add_context_menu_option(icon, icon_name, icon_label, menu, G_CALLBACK(xfdesktop_volume_icon_menu_mount)); } if(mount) g_object_unref(mount); mi = gtk_separator_menu_item_new(); gtk_widget_show(mi); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); icon_name = GTK_STOCK_PROPERTIES; icon_label = _("P_roperties..."); if(!volume_icon->priv->file_info) xfdesktop_volume_icon_add_context_menu_option(icon, icon_name, icon_label, menu, NULL); else { xfdesktop_volume_icon_add_context_menu_option(icon, icon_name, icon_label, menu, G_CALLBACK(xfdesktop_volume_icon_menu_properties)); } return TRUE; }
gboolean brasero_gio_operation_mount (GVolume *gvolume, GtkWindow *parent_window, GCancellable *cancel, gboolean wait, GError **error) { GMount *mount; gboolean result; GMountOperation *operation = NULL; BRASERO_MEDIA_LOG ("Mounting"); if (!gvolume) { BRASERO_MEDIA_LOG ("No volume"); return FALSE; } if (!g_volume_can_mount (gvolume)) { BRASERO_MEDIA_LOG ("Volume can't be mounted"); return FALSE; } mount = g_volume_get_mount (gvolume); if (mount) { BRASERO_MEDIA_LOG ("Existing mount"); g_object_unref (mount); return TRUE; } if (parent_window && GTK_IS_WINDOW (parent_window)) operation = gtk_mount_operation_new (parent_window); if (wait) { BraseroGioOperation *op; op = g_new0 (BraseroGioOperation, 1); op->cancel = cancel; /* Ref gvolume as it could be unreffed * while we are in the loop */ g_object_ref (gvolume); g_volume_mount (gvolume, G_MOUNT_MOUNT_NONE, operation, /* authentification */ cancel, brasero_gio_operation_mount_finish, op); result = brasero_gio_operation_wait_for_operation_end (op, error); g_object_unref (gvolume); } else { g_volume_mount (gvolume, G_MOUNT_MOUNT_NONE, operation, /* authentification */ cancel, NULL, NULL); result = TRUE; } if (operation) g_object_unref (operation); BRASERO_MEDIA_LOG ("Mount result = %d", result); return result; }