/* 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 ); }