static void do_volume_tests (GDrive *drive, GVolume *volume) { GDrive *d; gchar *name; GMount *mount; gchar *uuid; name = g_volume_get_name (volume); g_assert (name != NULL); g_free (name); d = g_volume_get_drive (volume); g_assert (d == drive); if (d != NULL) g_object_unref (d); mount = g_volume_get_mount (volume); if (mount != NULL) { do_mount_tests (drive, volume, mount); g_object_unref (mount); } uuid = g_volume_get_uuid (volume); if (uuid) { GVolume *v; v = g_volume_monitor_get_volume_for_uuid (monitor, uuid); g_assert (v == volume); g_object_unref (v); g_free (uuid); } }
static gboolean ignore_volume (GVolume *volume) { gboolean ret = TRUE; char *path; GDrive *drive; /* Ignore drive? */ drive = g_volume_get_drive (volume); if (drive != NULL && ignore_drive (drive)) { g_object_unref (drive); return TRUE; } g_clear_object (&drive); path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); if (path != NULL) { ret = FALSE; g_free (path); } else { GRL_DEBUG ("%s: Not adding volume %s as it has no identifier", __FUNCTION__, g_volume_get_name (volume)); } return ret; }
static void test_volumes (void) { GList *volumes, *l; volumes = g_volume_monitor_get_volumes (monitor); for (l = volumes; l; l = l->next) { GVolume *volume = l->data; GDrive *drive; drive = g_volume_get_drive (volume); do_volume_tests (drive, volume); if (drive != NULL) g_object_unref (drive); } g_list_free_full (volumes, g_object_unref); }
static void test_volumes (void) { GList *volumes, *l; volumes = g_volume_monitor_get_volumes (monitor); for (l = volumes; l; l = l->next) { GVolume *volume = l->data; GDrive *drive; drive = g_volume_get_drive (volume); do_volume_tests (drive, volume); g_object_unref (drive); } g_list_foreach (volumes, (GFunc)g_object_unref, NULL); g_list_free (volumes); }
void GioLister::VolumeAdded(GVolume* volume) { g_object_ref(volume); DeviceInfo info; info.ReadVolumeInfo(volume); #ifdef HAVE_AUDIOCD if (info.volume_root_uri.startsWith("cdda")) // Audio CD devices are already handled by CDDA lister return; #endif info.ReadDriveInfo(g_volume_get_drive(volume)); info.ReadMountInfo(g_volume_get_mount(volume)); if (!info.is_suitable()) return; { QMutexLocker l(&mutex_); devices_[info.unique_id()] = info; } emit DeviceAdded(info.unique_id()); }
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); } } }
/* this is loosely based on update_places() from caja-places-sidebar.c */ static void panel_place_menu_item_append_local_gio (PanelPlaceMenuItem *place_item, GtkWidget *menu) { GList *l; GList *ll; GList *drives; GDrive *drive; GList *volumes; GVolume *volume; GList *mounts; GMount *mount; GSList *items; GSList *sl; PanelGioItem *item; GtkWidget *add_menu; items = NULL; /* first go through all connected drives */ drives = g_volume_monitor_get_connected_drives (place_item->priv->volume_monitor); for (l = drives; l != NULL; l = l->next) { drive = l->data; volumes = g_drive_get_volumes (drive); if (volumes != NULL) { for (ll = volumes; ll != NULL; ll = ll->next) { volume = ll->data; mount = g_volume_get_mount (volume); item = g_slice_new (PanelGioItem); if (mount != NULL) { item->type = PANEL_GIO_MOUNT; item->u.mount = mount; } else { /* Do show the unmounted volumes; this * is so the user can mount it (in case * automounting is off). * * Also, even if automounting is * enabled, this gives a visual cue * that the user should remember to * yank out the media if he just * unmounted it. */ item->type = PANEL_GIO_VOLUME; item->u.volume = g_object_ref (volume); } items = g_slist_prepend (items, item); g_object_unref (volume); } g_list_free (volumes); } else { if (g_drive_is_media_removable (drive) && !g_drive_is_media_check_automatic (drive)) { /* If the drive has no mountable volumes and we * cannot detect media change.. we display the * drive so the user can manually poll the * drive by clicking on it..." * * This is mainly for drives like floppies * where media detection doesn't work.. but * it's also for human beings who like to turn * off media detection in the OS to save * battery juice. */ item = g_slice_new (PanelGioItem); item->type = PANEL_GIO_DRIVE; item->u.drive = g_object_ref (drive); items = g_slist_prepend (items, item); } } g_object_unref (drive); } g_list_free (drives); /* add all volumes that is not associated with a drive */ volumes = g_volume_monitor_get_volumes (place_item->priv->volume_monitor); for (l = volumes; l != NULL; l = l->next) { volume = l->data; drive = g_volume_get_drive (volume); if (drive != NULL) { g_object_unref (volume); g_object_unref (drive); continue; } mount = g_volume_get_mount (volume); item = g_slice_new (PanelGioItem); if (mount != NULL) { item->type = PANEL_GIO_MOUNT; item->u.mount = mount; } else { /* see comment above in why we add an icon for an * unmounted mountable volume */ item->type = PANEL_GIO_VOLUME; item->u.volume = g_object_ref (volume); } items = g_slist_prepend (items, item); g_object_unref (volume); } g_list_free (volumes); /* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */ mounts = g_volume_monitor_get_mounts (place_item->priv->volume_monitor); for (l = mounts; l != NULL; l = l->next) { GFile *root; mount = l->data; if (g_mount_is_shadowed (mount)) { g_object_unref (mount); continue; } volume = g_mount_get_volume (mount); if (volume != NULL) { g_object_unref (volume); g_object_unref (mount); continue; } root = g_mount_get_root (mount); if (!g_file_is_native (root)) { g_object_unref (root); g_object_unref (mount); continue; } g_object_unref (root); item = g_slice_new (PanelGioItem); item->type = PANEL_GIO_MOUNT; item->u.mount = mount; items = g_slist_prepend (items, item); } g_list_free (mounts); /* now that we have everything, add the items inline or in a submenu */ items = g_slist_reverse (items); if (g_slist_length (items) <= MAX_ITEMS_OR_SUBMENU) { add_menu = menu; } else { GtkWidget *item; item = gtk_image_menu_item_new (); setup_menu_item_with_icon (item, panel_menu_icon_get_size (), PANEL_ICON_REMOVABLE_MEDIA, NULL, NULL, _("Removable Media")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); add_menu = create_empty_menu (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), add_menu); } for (sl = items; sl; sl = sl->next) { item = sl->data; switch (item->type) { case PANEL_GIO_DRIVE: panel_menu_item_append_drive (add_menu, item->u.drive); g_object_unref (item->u.drive); break; case PANEL_GIO_VOLUME: panel_menu_item_append_volume (add_menu, item->u.volume); g_object_unref (item->u.volume); break; case PANEL_GIO_MOUNT: panel_menu_item_append_mount (add_menu, item->u.mount); g_object_unref (item->u.mount); break; default: g_assert_not_reached (); } g_slice_free (PanelGioItem, item); } g_slist_free (items); }
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_drive(VALUE self) { return GOBJ2RVAL_UNREF(g_volume_get_drive(_SELF(self))); }
static GDrive* g_udisks_mount_get_drive (GMount* base) { GUDisksMount* mnt = G_UDISKS_MOUNT(base); return mnt->vol ? g_volume_get_drive(G_VOLUME(mnt->vol)) : NULL; }
GList *vfs_backend_list_volumes (void) { GVolumeMonitor *pVolumeMonitor = g_volume_monitor_get (); GList *pIconsList = NULL; Icon *pNewIcon; //\___________________ On chope les disques connectes (lecteur de CD/disquette/etc) et on liste leurs volumes. GList *pDrivesList = g_volume_monitor_get_connected_drives (pVolumeMonitor); GList *pAssociatedVolumes; GList *dl, *av; GDrive *pDrive; GVolume *pVolume; for (dl = pDrivesList; dl != NULL; dl = dl->next) { pDrive = dl->data; cd_message ("drive '%s'", g_drive_get_name (pDrive)); pAssociatedVolumes = g_drive_get_volumes (pDrive); if (pAssociatedVolumes != NULL) { for (av = pAssociatedVolumes; av != NULL; av = av->next) { pVolume = av->data; cd_message (" + volume '%s'", g_volume_get_name (pVolume)); pNewIcon = _cd_get_icon_for_volume (pVolume, NULL); if (pNewIcon != NULL) pIconsList = g_list_prepend (pIconsList, pNewIcon); //g_object_unref (pVolume); } g_list_free (pAssociatedVolumes); } else // le disque n'a aucun volume montable { cd_message (" le disque n'a aucun volume montable"); /*if (g_drive_is_media_removable (pDrive) && ! g_drive_is_media_check_automatic (pDrive)) { g_drive_get_icon (pDrive); g_drive_get_name (pDrive); }*/ } //g_object_unref (pDrive); } g_list_free (pDrivesList); //\___________________ On chope les volumes qui ne sont pas associes a un disque. GList *pVolumesList = g_volume_monitor_get_volumes (pVolumeMonitor); GList *v; for (v = pVolumesList; v != NULL; v = v->next) { pVolume = v->data; cd_message ("volume '%s'", g_volume_get_name (pVolume)); pDrive = g_volume_get_drive (pVolume); if (pDrive != NULL) // on l'a deja liste dans la 1ere boucle. { cd_message (" drive '%s' est deja liste", g_drive_get_name (pDrive)); //g_object_unref (pDrive); } else { cd_message (" + volume '%s'\n", g_volume_get_name (pVolume)); if (pNewIcon != NULL) pNewIcon = _cd_get_icon_for_volume (pVolume, NULL); pIconsList = g_list_prepend (pIconsList, pNewIcon); } //g_object_unref (pVolume); } g_list_free (pVolumesList); //\___________________ On chope les points de montage qui n'ont pas de volumes. (montage de mtab, ftp, etc) GList *pMountsList = g_volume_monitor_get_mounts (pVolumeMonitor); GMount *pMount; GList *m; for (m = pMountsList; m != NULL; m = m->next) { pMount = m->data; cd_message ("mount '%s'", g_mount_get_name (pMount)); pVolume = g_mount_get_volume (pMount); if (pVolume != NULL) // on l'a deja liste precedemment. { cd_message ("volume '%s' est deja liste", g_volume_get_name (pVolume)); //g_object_unref (pVolume); } else { cd_message ("+ volume '%s'", g_volume_get_name (pVolume)); if (pNewIcon != NULL) pNewIcon = _cd_get_icon_for_volume (NULL, pMount); pIconsList = g_list_prepend (pIconsList, pNewIcon); } //g_object_unref (pMount); } g_list_free (pMountsList); return pIconsList; }
static GList * nautilus_disc_burn_get_file_items (NautilusMenuProvider *provider, GtkWidget *window, GList *selection) { GList *items = NULL; NautilusMenuItem *item; NautilusFileInfo *file_info; GFile *file; GMount *mount; GVolume *volume; GDrive *drive; char *mime_type; gboolean is_iso; DEBUG_PRINT ("Getting file items\n"); if (!selection || selection->next != NULL) { return NULL; } file_info = NAUTILUS_FILE_INFO (selection->data); if (nautilus_file_info_is_gone (file_info)) { return NULL; } file = nautilus_file_info_get_location (file_info); if (file == NULL) { DEBUG_PRINT ("No file found\n"); return NULL; } mime_type = nautilus_file_info_get_mime_type (file_info); DEBUG_PRINT ("Mime type: %s\n", mime_type); if (! mime_type) { g_object_unref (file); return NULL; } is_iso = (strcmp (mime_type, "application/x-iso-image") == 0) || (strcmp (mime_type, "application/x-cd-image") == 0) || (strcmp (mime_type, "application/x-cue") == 0) || (strcmp (mime_type, "application/x-toc") == 0) || (strcmp (mime_type, "application/x-cdrdao-toc") == 0); if (is_iso) { /* Whether or not this file is local is not a problem */ item = nautilus_menu_item_new ("NautilusDiscBurn::write_iso", _("_Write to Disc…"), _("Write disc image to a CD or DVD"), "media-optical-data-new"); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_signal_connect (item, "activate", G_CALLBACK (write_iso_activate_cb), window); items = g_list_append (items, item); } /* * We handle two cases here. The selection is: * A) a volume * B) a drive * * This is because there is very little distinction between * the two for CD/DVD media */ drive = NULL; volume = NULL; mount = nautilus_file_info_get_mount (file_info); if (mount != NULL) { drive = g_mount_get_drive (mount); volume = g_mount_get_volume (mount); } else { char *uri = g_file_get_uri (file); DEBUG_PRINT ("Mount not found: %s\n", uri); g_free (uri); } if (drive == NULL && volume != NULL) { /* case A */ drive = g_volume_get_drive (volume); } else if (volume == NULL && drive != NULL) { /* case B */ volume = drive_get_first_volume (drive); if (volume == NULL) { DEBUG_PRINT ("Volume not found\n"); } } if (drive != NULL && volume != NULL && drive_is_cd_device (drive) && ! volume_is_blank (volume)) { char *device_path; BraseroMediumMonitor *monitor; BraseroDrive *bdrive; BraseroMedium *medium; BraseroMedia media; BraseroTrackType *type; /* Reminder: the following is not needed since it is already * called in drive_is_cd_device (). * ensure_initialized(); */ device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); monitor = brasero_medium_monitor_get_default (); bdrive = brasero_medium_monitor_get_drive (monitor, device_path); g_object_unref (monitor); medium = brasero_drive_get_medium (bdrive); media = brasero_medium_get_status (medium); g_object_unref (bdrive); type = brasero_track_type_new (); brasero_track_type_set_has_medium (type); brasero_track_type_set_medium_type (type, media); if (brasero_burn_library_input_supported (type) == BRASERO_BURN_OK) { /* user may want to copy it ... */ item = nautilus_menu_item_new ("NautilusDiscBurn::copy_disc", _("_Copy Disc…"), _("Create a copy of this CD or DVD"), "media-optical-copy"); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free); g_signal_connect (item, "activate", G_CALLBACK (copy_disc_activate_cb), window); items = g_list_append (items, item); } brasero_track_type_free (type); if (brasero_burn_library_get_media_capabilities (media) & BRASERO_MEDIUM_REWRITABLE) { /* ... or if it's a rewritable medium to blank it ... */ item = nautilus_menu_item_new ("NautilusDiscBurn::blank_disc", _("_Blank Disc…"), _("Blank this CD or DVD"), "media-optical-blank"); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free); g_signal_connect (item, "activate", G_CALLBACK (blank_disc_activate_cb), window); items = g_list_append (items, item); } /* - library should be able to checksum * - disc must have a data session */ if (brasero_burn_library_can_checksum () && (media & BRASERO_MEDIUM_HAS_DATA)) { /* ... or verify medium. */ item = nautilus_menu_item_new ("NautilusDiscBurn::check_disc", _("_Check Disc…"), _("Check the data integrity on this CD or DVD"), NULL); g_object_set_data (G_OBJECT (item), "file_info", file_info); g_object_set_data (G_OBJECT (item), "window", window); g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free); g_signal_connect (item, "activate", G_CALLBACK (check_disc_activate_cb), window); items = g_list_append (items, item); } g_free (device_path); } g_object_unref (file); if (drive != NULL) { g_object_unref (drive); } if (volume != NULL) { g_object_unref (volume); } g_free (mime_type); DEBUG_PRINT ("Items returned\n"); return items; }