/* HAL callback for new device */ static void new_device( LibHalContext *ctx, const char *udi ) { DBusError error; char *parent, *mount_point, *device, *type; p_dbus_error_init( &error ); if (!(device = p_libhal_device_get_property_string( ctx, udi, "block.device", &error ))) goto done; if (!(mount_point = p_libhal_device_get_property_string( ctx, udi, "volume.mount_point", &error ))) goto done; if (!(parent = p_libhal_device_get_property_string( ctx, udi, "info.parent", &error ))) goto done; if (!p_libhal_device_get_property_bool( ctx, parent, "storage.removable", &error )) goto done; if (!(type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", &error ))) p_dbus_error_free( &error ); /* ignore error */ add_dos_device( udi, device, mount_point, type ); if (type) p_libhal_free_string( type ); p_libhal_free_string( parent ); p_libhal_free_string( device ); p_libhal_free_string( mount_point ); /* add property watch for mount point */ p_libhal_device_add_property_watch( ctx, udi, &error ); done: p_dbus_error_free( &error ); }
/* HAL callback for new device */ static void hal_new_device( LibHalContext *ctx, const char *udi ) { DBusError error; char *parent = NULL; char *mount_point = NULL; char *device = NULL; char *type = NULL; char *uuid_str = NULL; GUID guid, *guid_ptr = NULL; enum device_type drive_type; p_dbus_error_init( &error ); if (!(device = p_libhal_device_get_property_string( ctx, udi, "block.device", &error ))) goto done; if (!(mount_point = p_libhal_device_get_property_string( ctx, udi, "volume.mount_point", &error ))) goto done; if (!(parent = p_libhal_device_get_property_string( ctx, udi, "info.parent", &error ))) goto done; if (!(uuid_str = p_libhal_device_get_property_string( ctx, udi, "volume.uuid", &error ))) p_dbus_error_free( &error ); /* ignore error */ else guid_ptr = parse_uuid( &guid, uuid_str ); if (!(type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", &error ))) p_dbus_error_free( &error ); /* ignore error */ if (type && !strcmp( type, "cdrom" )) drive_type = DEVICE_CDROM; else if (type && !strcmp( type, "floppy" )) drive_type = DEVICE_FLOPPY; else drive_type = DEVICE_UNKNOWN; if (p_libhal_device_get_property_bool( ctx, parent, "storage.removable", &error )) { add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr ); /* add property watch for mount point */ p_libhal_device_add_property_watch( ctx, udi, &error ); } else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr ); done: if (type) p_libhal_free_string( type ); if (parent) p_libhal_free_string( parent ); if (device) p_libhal_free_string( device ); if (uuid_str) p_libhal_free_string( uuid_str ); if (mount_point) p_libhal_free_string( mount_point ); p_dbus_error_free( &error ); }
/* UDisks callback for new device */ static void udisks_new_device( const char *udi ) { static const char *dev_name = "org.freedesktop.UDisks.Device"; DBusMessage *request, *reply; DBusMessageIter iter, variant; DBusError error; const char *device = NULL; const char *mount_point = NULL; const char *type = NULL; GUID guid, *guid_ptr = NULL; int removable = FALSE; enum device_type drive_type = DEVICE_UNKNOWN; request = p_dbus_message_new_method_call( "org.freedesktop.UDisks", udi, "org.freedesktop.DBus.Properties", "GetAll" ); if (!request) return; p_dbus_message_iter_init_append( request, &iter ); p_dbus_message_iter_append_basic( &iter, DBUS_TYPE_STRING, &dev_name ); p_dbus_error_init( &error ); reply = p_dbus_connection_send_with_reply_and_block( connection, request, -1, &error ); p_dbus_message_unref( request ); if (!reply) { WARN( "failed: %s\n", error.message ); p_dbus_error_free( &error ); return; } p_dbus_error_free( &error ); p_dbus_message_iter_init( reply, &iter ); if (p_dbus_message_iter_get_arg_type( &iter ) == DBUS_TYPE_ARRAY) { const char *name; p_dbus_message_iter_recurse( &iter, &iter ); while ((name = udisks_next_dict_entry( &iter, &variant ))) { if (!strcmp( name, "DeviceFile" )) p_dbus_message_iter_get_basic( &variant, &device ); else if (!strcmp( name, "DeviceIsRemovable" )) p_dbus_message_iter_get_basic( &variant, &removable ); else if (!strcmp( name, "IdType" )) p_dbus_message_iter_get_basic( &variant, &type ); else if (!strcmp( name, "DriveMediaCompatibility" )) { DBusMessageIter media; p_dbus_message_iter_recurse( &variant, &media ); while (p_dbus_message_iter_get_arg_type( &media ) == DBUS_TYPE_STRING) { const char *media_type; p_dbus_message_iter_get_basic( &media, &media_type ); if (!strncmp( media_type, "optical_dvd", 11 )) drive_type = DEVICE_DVD; if (!strncmp( media_type, "floppy", 6 )) drive_type = DEVICE_FLOPPY; else if (!strncmp( media_type, "optical_", 8 ) && drive_type == DEVICE_UNKNOWN) drive_type = DEVICE_CDROM; p_dbus_message_iter_next( &media ); } } else if (!strcmp( name, "DeviceMountPaths" )) { DBusMessageIter paths; p_dbus_message_iter_recurse( &variant, &paths ); if (p_dbus_message_iter_get_arg_type( &paths ) == DBUS_TYPE_STRING) p_dbus_message_iter_get_basic( &paths, &mount_point ); } else if (!strcmp( name, "IdUuid" )) { char *uuid_str; p_dbus_message_iter_get_basic( &variant, &uuid_str ); guid_ptr = parse_uuid( &guid, uuid_str ); } } } TRACE( "udi %s device %s mount point %s uuid %s type %s removable %u\n", debugstr_a(udi), debugstr_a(device), debugstr_a(mount_point), debugstr_guid(guid_ptr), debugstr_a(type), removable ); if (type) { if (!strcmp( type, "iso9660" )) { removable = TRUE; drive_type = DEVICE_CDROM; } else if (!strcmp( type, "udf" )) { removable = TRUE; drive_type = DEVICE_DVD; } } if (device) { if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr ); else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr ); } p_dbus_message_unref( reply ); }
static void udisks2_add_device( const char *udi, DBusMessageIter *dict, DBusMessageIter *block ) { DBusMessageIter iter, variant, paths, string; const char *device = NULL; const char *mount_point = NULL; const char *type = NULL; const char *drive = NULL; GUID guid, *guid_ptr = NULL; const char *iface, *name; int removable = FALSE; enum device_type drive_type = DEVICE_UNKNOWN; while ((iface = udisks_next_dict_entry( block, &iter ))) { if (!strcmp( iface, "org.freedesktop.UDisks2.Filesystem" )) { while ((name = udisks_next_dict_entry( &iter, &variant ))) { if (!strcmp( name, "MountPoints" )) { p_dbus_message_iter_recurse( &variant, &paths ); if (p_dbus_message_iter_get_arg_type( &paths ) == DBUS_TYPE_ARRAY) { p_dbus_message_iter_recurse( &variant, &string ); mount_point = udisks2_string_from_array( &string ); } } } } if (!strcmp( iface, "org.freedesktop.UDisks2.Block" )) { while ((name = udisks_next_dict_entry( &iter, &variant ))) { if (!strcmp( name, "Device" )) device = udisks2_string_from_array( &variant ); else if (!strcmp( name, "IdType" )) p_dbus_message_iter_get_basic( &variant, &type ); else if (!strcmp( name, "Drive" )) { p_dbus_message_iter_get_basic( &variant, &drive ); udisks2_get_drive_info( drive, dict, &drive_type, &removable ); } else if (!strcmp( name, "IdUUID" )) { const char *uuid_str; if (p_dbus_message_iter_get_arg_type( &variant ) == DBUS_TYPE_ARRAY) uuid_str = udisks2_string_from_array( &variant ); else p_dbus_message_iter_get_basic( &variant, &uuid_str ); guid_ptr = parse_uuid( &guid, uuid_str ); } } } } TRACE( "udi %s device %s mount point %s uuid %s type %s removable %u\n", debugstr_a(udi), debugstr_a(device), debugstr_a(mount_point), debugstr_guid(guid_ptr), debugstr_a(type), removable ); if (type) { if (!strcmp( type, "iso9660" )) { removable = TRUE; drive_type = DEVICE_CDROM; } else if (!strcmp( type, "udf" )) { removable = TRUE; drive_type = DEVICE_DVD; } } if (device) { if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr ); else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr ); } }