/* compile with: * gcc -o gvfs-list-drives gvfs-list-drives.c \ * `pkg-config --cflags --libs gnome-vfs-2.0` */ #include #include static const char *device_types[] = { "unknown", "audio-cd", "video-dvd", "harddrive", "cdrom", "floppy", "zip", "jaz", "nfs", "autofs", "camera", "memory-stick", "smb", "apple", "music-player", "windows", "loopback", "network" }; static const char *volume_types[] = { "mountpoint", "vfs-mount", "connected-server", }; static void print_volume_info(GnomeVFSVolume *volume) { char *tmp; printf(" Volume %lu:\n", gnome_vfs_volume_get_id(volume)); printf(" Volume type: %s\n", volume_types[gnome_vfs_volume_get_volume_type(volume)]); printf(" Device type: %s\n", device_types[gnome_vfs_volume_get_device_type(volume)]); tmp = gnome_vfs_volume_get_device_path(volume); printf(" Device path: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_volume_get_activation_uri(volume); printf(" Activation URI: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_volume_get_filesystem_type(volume); printf(" Filesystem type: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_volume_get_display_name(volume); printf(" Display name: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_volume_get_icon(volume); printf(" Icon: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_volume_get_hal_udi(volume); printf(" HAL UDI: %s\n", tmp ? tmp : "(null)"); g_free(tmp); printf(" User visible: %s\n", gnome_vfs_volume_is_user_visible(volume) ? "true" : "false"); printf(" Read only: %s\n", gnome_vfs_volume_is_read_only(volume) ? "true" : "false"); printf(" Mounted: %s\n", gnome_vfs_volume_is_mounted(volume) ? "true" : "false"); printf(" Handles trash: %s\n", gnome_vfs_volume_handles_trash(volume) ? "true" : "false"); printf("\n"); } static void print_drive_info (GnomeVFSDrive *drive) { char *tmp; GList *volumes, *v; printf("Drive %lu:\n", gnome_vfs_drive_get_id(drive)); printf(" Device type: %s\n", device_types[gnome_vfs_drive_get_device_type(drive)]); tmp = gnome_vfs_drive_get_device_path(drive); printf(" Device path: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_drive_get_activation_uri(drive); printf(" Activation URI: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_drive_get_display_name(drive); printf(" Display name: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_drive_get_icon(drive); printf(" Icon: %s\n", tmp ? tmp : "(null)"); g_free(tmp); tmp = gnome_vfs_drive_get_hal_udi(drive); printf(" HAL UDI: %s\n", tmp ? tmp : "(null)"); g_free(tmp); printf(" User visible: %s\n", gnome_vfs_drive_is_user_visible(drive) ? "true" : "false"); printf(" Connected: %s\n", gnome_vfs_drive_is_connected(drive) ? "true" : "false"); printf(" Mounted: %s\n", gnome_vfs_drive_is_mounted(drive) ? "true" : "false"); printf("\n"); volumes = gnome_vfs_drive_get_mounted_volumes(drive); for (v = volumes; v != NULL; v = v->next) { GnomeVFSVolume *volume = v->data; print_volume_info(volume); gnome_vfs_volume_unref(volume); } g_list_free(volumes); } int main(int argc, char **argv) { GnomeVFSVolumeMonitor *monitor; GList *drives, *volumes, *tmp; GnomeVFSDrive *drive; GnomeVFSVolume *volume; if (!gnome_vfs_init()) { fprintf(stderr, "Could not initialise gnome-vfs.\n"); return 1; } monitor = gnome_vfs_get_volume_monitor(); drives = gnome_vfs_volume_monitor_get_connected_drives(monitor); for (tmp = drives; tmp != NULL; tmp = tmp->next) { drive = tmp->data; print_drive_info(drive); gnome_vfs_drive_unref(drive); } g_list_free(drives); printf("Drive-less volumes:\n"); volumes = gnome_vfs_volume_monitor_get_mounted_volumes(monitor); for (tmp = volumes; tmp != NULL; tmp = tmp->next) { volume = tmp->data; drive = gnome_vfs_volume_get_drive(volume); if (drive != NULL) { gnome_vfs_drive_unref(drive); } else { print_volume_info(volume); } gnome_vfs_volume_unref(volume); } g_list_free(volumes); return 0; }