2006-04-18 16:48:13 +02:00
|
|
|
/*
|
2011-12-20 11:04:18 +01:00
|
|
|
* DBus devices support
|
2006-04-18 16:48:13 +02:00
|
|
|
*
|
2011-12-20 11:42:45 +01:00
|
|
|
* Copyright 2006, 2011 Alexandre Julliard
|
2006-04-18 16:48:13 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-04-18 16:48:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
2006-04-18 21:12:43 +02:00
|
|
|
#include <stdio.h>
|
2006-04-18 16:48:13 +02:00
|
|
|
#include <sys/time.h>
|
2011-12-20 11:04:18 +01:00
|
|
|
#ifdef SONAME_LIBDBUS_1
|
2011-09-06 12:11:41 +02:00
|
|
|
# include <dbus/dbus.h>
|
2011-12-20 11:04:18 +01:00
|
|
|
#endif
|
|
|
|
#ifdef SONAME_LIBHAL
|
2011-09-06 12:11:41 +02:00
|
|
|
# include <hal/libhal.h>
|
|
|
|
#endif
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2008-10-21 15:01:52 +02:00
|
|
|
#include "mountmgr.h"
|
2009-07-20 16:11:17 +02:00
|
|
|
#include "winnls.h"
|
2006-04-18 16:48:13 +02:00
|
|
|
#include "excpt.h"
|
|
|
|
|
|
|
|
#include "wine/library.h"
|
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2008-03-04 07:58:32 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
#ifdef SONAME_LIBDBUS_1
|
2006-04-18 21:12:43 +02:00
|
|
|
|
2006-04-18 16:48:13 +02:00
|
|
|
#define DBUS_FUNCS \
|
2011-12-20 11:42:45 +01:00
|
|
|
DO_FUNC(dbus_bus_add_match); \
|
2006-04-18 16:48:13 +02:00
|
|
|
DO_FUNC(dbus_bus_get); \
|
2011-12-20 11:42:45 +01:00
|
|
|
DO_FUNC(dbus_bus_remove_match); \
|
|
|
|
DO_FUNC(dbus_connection_add_filter); \
|
2006-04-18 16:48:13 +02:00
|
|
|
DO_FUNC(dbus_connection_close); \
|
|
|
|
DO_FUNC(dbus_connection_read_write_dispatch); \
|
2011-12-20 11:42:45 +01:00
|
|
|
DO_FUNC(dbus_connection_remove_filter); \
|
|
|
|
DO_FUNC(dbus_connection_send_with_reply_and_block); \
|
2006-04-18 16:48:13 +02:00
|
|
|
DO_FUNC(dbus_error_free); \
|
2011-12-20 11:42:45 +01:00
|
|
|
DO_FUNC(dbus_error_init); \
|
|
|
|
DO_FUNC(dbus_error_is_set); \
|
|
|
|
DO_FUNC(dbus_free_string_array); \
|
|
|
|
DO_FUNC(dbus_message_get_args); \
|
|
|
|
DO_FUNC(dbus_message_get_interface); \
|
|
|
|
DO_FUNC(dbus_message_get_member); \
|
|
|
|
DO_FUNC(dbus_message_get_path); \
|
|
|
|
DO_FUNC(dbus_message_get_type); \
|
|
|
|
DO_FUNC(dbus_message_is_signal); \
|
|
|
|
DO_FUNC(dbus_message_iter_append_basic); \
|
|
|
|
DO_FUNC(dbus_message_iter_get_arg_type); \
|
|
|
|
DO_FUNC(dbus_message_iter_get_basic); \
|
|
|
|
DO_FUNC(dbus_message_iter_init); \
|
|
|
|
DO_FUNC(dbus_message_iter_init_append); \
|
|
|
|
DO_FUNC(dbus_message_iter_next); \
|
|
|
|
DO_FUNC(dbus_message_iter_recurse); \
|
|
|
|
DO_FUNC(dbus_message_new_method_call); \
|
|
|
|
DO_FUNC(dbus_message_unref);
|
|
|
|
|
|
|
|
#define DO_FUNC(f) static typeof(f) * p_##f
|
|
|
|
DBUS_FUNCS;
|
|
|
|
#undef DO_FUNC
|
|
|
|
|
|
|
|
static int udisks_timeout = -1;
|
|
|
|
static DBusConnection *connection;
|
|
|
|
|
|
|
|
#ifdef SONAME_LIBHAL
|
2006-04-18 16:48:13 +02:00
|
|
|
|
|
|
|
#define HAL_FUNCS \
|
|
|
|
DO_FUNC(libhal_ctx_free); \
|
|
|
|
DO_FUNC(libhal_ctx_init); \
|
|
|
|
DO_FUNC(libhal_ctx_new); \
|
|
|
|
DO_FUNC(libhal_ctx_set_dbus_connection); \
|
|
|
|
DO_FUNC(libhal_ctx_set_device_added); \
|
|
|
|
DO_FUNC(libhal_ctx_set_device_property_modified); \
|
|
|
|
DO_FUNC(libhal_ctx_set_device_removed); \
|
|
|
|
DO_FUNC(libhal_ctx_shutdown); \
|
|
|
|
DO_FUNC(libhal_device_get_property_bool); \
|
|
|
|
DO_FUNC(libhal_device_get_property_string); \
|
|
|
|
DO_FUNC(libhal_device_add_property_watch); \
|
|
|
|
DO_FUNC(libhal_device_remove_property_watch); \
|
|
|
|
DO_FUNC(libhal_free_string); \
|
|
|
|
DO_FUNC(libhal_free_string_array); \
|
|
|
|
DO_FUNC(libhal_get_all_devices)
|
|
|
|
|
|
|
|
#define DO_FUNC(f) static typeof(f) * p_##f
|
|
|
|
HAL_FUNCS;
|
|
|
|
#undef DO_FUNC
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
static BOOL load_hal_functions(void)
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
2006-09-26 20:29:15 +02:00
|
|
|
void *hal_handle;
|
2006-04-18 16:48:13 +02:00
|
|
|
char error[128];
|
|
|
|
|
2006-09-26 20:29:15 +02:00
|
|
|
/* Load libhal with RTLD_GLOBAL so that the dbus symbols are available.
|
|
|
|
* We can't load libdbus directly since libhal may have been built against a
|
|
|
|
* different version but with the same soname. Binary compatibility is for wimps. */
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2006-09-26 20:29:15 +02:00
|
|
|
if (!(hal_handle = wine_dlopen(SONAME_LIBHAL, RTLD_NOW|RTLD_GLOBAL, error, sizeof(error))))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
#define DO_FUNC(f) if (!(p_##f = wine_dlsym( RTLD_DEFAULT, #f, error, sizeof(error) ))) goto failed
|
2006-04-18 16:48:13 +02:00
|
|
|
DBUS_FUNCS;
|
|
|
|
#undef DO_FUNC
|
|
|
|
|
|
|
|
#define DO_FUNC(f) if (!(p_##f = wine_dlsym( hal_handle, #f, error, sizeof(error) ))) goto failed
|
|
|
|
HAL_FUNCS;
|
|
|
|
#undef DO_FUNC
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
udisks_timeout = 3000; /* don't try for too long if we can fall back to HAL */
|
2006-04-18 16:48:13 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failed:
|
2008-03-04 07:58:32 +01:00
|
|
|
WARN( "failed to load HAL support: %s\n", error );
|
2006-04-18 16:48:13 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
#endif /* SONAME_LIBHAL */
|
|
|
|
|
2008-02-15 16:19:29 +01:00
|
|
|
static LONG WINAPI assert_fault(EXCEPTION_POINTERS *eptr)
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
2008-02-15 16:19:29 +01:00
|
|
|
if (eptr->ExceptionRecord->ExceptionCode == EXCEPTION_WINE_ASSERTION)
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
2006-04-18 16:48:13 +02:00
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
2009-07-20 16:11:17 +02:00
|
|
|
static GUID *parse_uuid( GUID *guid, const char *str )
|
|
|
|
{
|
|
|
|
/* standard uuid format */
|
|
|
|
if (strlen(str) == 36)
|
|
|
|
{
|
|
|
|
UNICODE_STRING strW;
|
|
|
|
WCHAR buffer[39];
|
|
|
|
|
|
|
|
if (MultiByteToWideChar( CP_UNIXCP, 0, str, 36, buffer + 1, 36 ))
|
|
|
|
{
|
|
|
|
buffer[0] = '{';
|
|
|
|
buffer[37] = '}';
|
|
|
|
buffer[38] = 0;
|
|
|
|
RtlInitUnicodeString( &strW, buffer );
|
|
|
|
if (!RtlGUIDFromString( &strW, guid )) return guid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for xxxx-xxxx format (FAT serial number) */
|
|
|
|
if (strlen(str) == 9 && str[4] == '-')
|
|
|
|
{
|
|
|
|
memset( guid, 0, sizeof(*guid) );
|
|
|
|
if (sscanf( str, "%hx-%hx", &guid->Data2, &guid->Data3 ) == 2) return guid;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
static BOOL load_dbus_functions(void)
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
char error[128];
|
|
|
|
|
|
|
|
if (!(handle = wine_dlopen(SONAME_LIBDBUS_1, RTLD_NOW, error, sizeof(error))))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
#define DO_FUNC(f) if (!(p_##f = wine_dlsym( handle, #f, error, sizeof(error) ))) goto failed
|
|
|
|
DBUS_FUNCS;
|
|
|
|
#undef DO_FUNC
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
WARN( "failed to load DBUS support: %s\n", error );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *udisks_next_dict_entry( DBusMessageIter *iter, DBusMessageIter *variant )
|
|
|
|
{
|
|
|
|
DBusMessageIter sub;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (p_dbus_message_iter_get_arg_type( iter ) != DBUS_TYPE_DICT_ENTRY) return NULL;
|
|
|
|
p_dbus_message_iter_recurse( iter, &sub );
|
|
|
|
p_dbus_message_iter_next( iter );
|
|
|
|
p_dbus_message_iter_get_basic( &sub, &name );
|
|
|
|
p_dbus_message_iter_next( &sub );
|
|
|
|
p_dbus_message_iter_recurse( &sub, variant );
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2011-12-28 10:36:29 +01:00
|
|
|
WARN( "failed: %s\n", error.message );
|
2011-12-20 11:42:45 +01:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UDisks callback for removed device */
|
|
|
|
static void udisks_removed_device( const char *udi )
|
|
|
|
{
|
|
|
|
TRACE( "removed %s\n", wine_dbgstr_a(udi) );
|
|
|
|
|
|
|
|
if (!remove_dos_device( -1, udi )) remove_volume( udi );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UDisks callback for changed device */
|
|
|
|
static void udisks_changed_device( const char *udi )
|
|
|
|
{
|
|
|
|
udisks_new_device( udi );
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL udisks_enumerate_devices(void)
|
|
|
|
{
|
|
|
|
DBusMessage *request, *reply;
|
|
|
|
DBusError error;
|
|
|
|
char **paths;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
request = p_dbus_message_new_method_call( "org.freedesktop.UDisks", "/org/freedesktop/UDisks",
|
|
|
|
"org.freedesktop.UDisks", "EnumerateDevices" );
|
|
|
|
if (!request) return FALSE;
|
|
|
|
|
|
|
|
p_dbus_error_init( &error );
|
|
|
|
reply = p_dbus_connection_send_with_reply_and_block( connection, request, udisks_timeout, &error );
|
|
|
|
p_dbus_message_unref( request );
|
|
|
|
if (!reply)
|
|
|
|
{
|
|
|
|
WARN( "failed: %s\n", error.message );
|
|
|
|
p_dbus_error_free( &error );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
p_dbus_error_free( &error );
|
|
|
|
|
|
|
|
if (p_dbus_message_get_args( reply, &error, DBUS_TYPE_ARRAY,
|
|
|
|
DBUS_TYPE_OBJECT_PATH, &paths, &count, DBUS_TYPE_INVALID ))
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++) udisks_new_device( paths[i] );
|
|
|
|
p_dbus_free_string_array( paths );
|
|
|
|
}
|
|
|
|
else WARN( "unexpected args in EnumerateDevices reply\n" );
|
|
|
|
|
|
|
|
p_dbus_message_unref( reply );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DBusHandlerResult udisks_filter( DBusConnection *ctx, DBusMessage *msg, void *user_data )
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
p_dbus_error_init( &error );
|
|
|
|
|
|
|
|
if (p_dbus_message_is_signal( msg, "org.freedesktop.UDisks", "DeviceAdded" ) &&
|
|
|
|
p_dbus_message_get_args( msg, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID ))
|
|
|
|
{
|
|
|
|
udisks_new_device( path );
|
|
|
|
}
|
|
|
|
else if (p_dbus_message_is_signal( msg, "org.freedesktop.UDisks", "DeviceRemoved" ) &&
|
|
|
|
p_dbus_message_get_args( msg, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID ))
|
|
|
|
{
|
|
|
|
udisks_removed_device( path );
|
|
|
|
}
|
|
|
|
else if (p_dbus_message_is_signal( msg, "org.freedesktop.UDisks", "DeviceChanged" ) &&
|
|
|
|
p_dbus_message_get_args( msg, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID ))
|
|
|
|
{
|
|
|
|
udisks_changed_device( path );
|
|
|
|
}
|
|
|
|
else TRACE( "ignoring message type=%d path=%s interface=%s method=%s\n",
|
|
|
|
p_dbus_message_get_type( msg ), p_dbus_message_get_path( msg ),
|
|
|
|
p_dbus_message_get_interface( msg ), p_dbus_message_get_member( msg ) );
|
|
|
|
|
|
|
|
p_dbus_error_free( &error );
|
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SONAME_LIBHAL
|
|
|
|
|
2006-04-18 16:48:13 +02:00
|
|
|
/* HAL callback for new device */
|
2011-12-20 11:04:18 +01:00
|
|
|
static void hal_new_device( LibHalContext *ctx, const char *udi )
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
|
|
|
DBusError error;
|
2007-12-27 11:01:13 +01:00
|
|
|
char *parent = NULL;
|
|
|
|
char *mount_point = NULL;
|
|
|
|
char *device = NULL;
|
|
|
|
char *type = NULL;
|
2009-07-20 16:11:17 +02:00
|
|
|
char *uuid_str = NULL;
|
|
|
|
GUID guid, *guid_ptr = NULL;
|
2008-11-12 10:47:49 +01:00
|
|
|
enum device_type drive_type;
|
2006-04-18 16:48:13 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-07-20 16:11:17 +02:00
|
|
|
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 );
|
|
|
|
|
2006-04-18 16:48:13 +02:00
|
|
|
if (!(type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", &error )))
|
|
|
|
p_dbus_error_free( &error ); /* ignore error */
|
|
|
|
|
2008-11-12 10:47:49 +01:00
|
|
|
if (type && !strcmp( type, "cdrom" )) drive_type = DEVICE_CDROM;
|
|
|
|
else if (type && !strcmp( type, "floppy" )) drive_type = DEVICE_FLOPPY;
|
|
|
|
else drive_type = DEVICE_UNKNOWN;
|
2008-10-15 20:12:27 +02:00
|
|
|
|
2009-07-21 20:33:17 +02:00
|
|
|
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 );
|
2006-04-18 16:48:13 +02:00
|
|
|
|
|
|
|
done:
|
2007-12-27 11:01:13 +01:00
|
|
|
if (type) p_libhal_free_string( type );
|
|
|
|
if (parent) p_libhal_free_string( parent );
|
|
|
|
if (device) p_libhal_free_string( device );
|
2009-07-20 16:11:17 +02:00
|
|
|
if (uuid_str) p_libhal_free_string( uuid_str );
|
2007-12-27 11:01:13 +01:00
|
|
|
if (mount_point) p_libhal_free_string( mount_point );
|
2006-04-18 16:48:13 +02:00
|
|
|
p_dbus_error_free( &error );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HAL callback for removed device */
|
2011-12-20 11:04:18 +01:00
|
|
|
static void hal_removed_device( LibHalContext *ctx, const char *udi )
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
|
|
|
DBusError error;
|
|
|
|
|
2008-03-04 07:58:32 +01:00
|
|
|
TRACE( "removed %s\n", wine_dbgstr_a(udi) );
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2008-10-23 15:44:18 +02:00
|
|
|
if (!remove_dos_device( -1, udi ))
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
|
|
|
p_dbus_error_init( &error );
|
|
|
|
p_libhal_device_remove_property_watch( ctx, udi, &error );
|
|
|
|
p_dbus_error_free( &error );
|
|
|
|
}
|
2009-07-21 20:33:17 +02:00
|
|
|
else remove_volume( udi );
|
2006-04-18 16:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* HAL callback for property changes */
|
2011-12-20 11:04:18 +01:00
|
|
|
static void hal_property_modified (LibHalContext *ctx, const char *udi,
|
|
|
|
const char *key, dbus_bool_t is_removed, dbus_bool_t is_added)
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
2008-03-04 07:58:32 +01:00
|
|
|
TRACE( "udi %s key %s %s\n", wine_dbgstr_a(udi), wine_dbgstr_a(key),
|
2011-12-20 11:04:18 +01:00
|
|
|
is_added ? "added" : is_removed ? "removed" : "modified" );
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2011-12-20 11:04:18 +01:00
|
|
|
if (!strcmp( key, "volume.mount_point" )) hal_new_device( ctx, udi );
|
2006-04-18 16:48:13 +02:00
|
|
|
}
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
static BOOL hal_enumerate_devices(void)
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
|
|
|
LibHalContext *ctx;
|
2011-12-20 11:42:45 +01:00
|
|
|
DBusError error;
|
2006-04-18 16:48:13 +02:00
|
|
|
int i, num;
|
|
|
|
char **list;
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
if (!p_libhal_ctx_new) return FALSE;
|
|
|
|
if (!(ctx = p_libhal_ctx_new())) return FALSE;
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
p_libhal_ctx_set_dbus_connection( ctx, connection );
|
2011-12-20 11:04:18 +01:00
|
|
|
p_libhal_ctx_set_device_added( ctx, hal_new_device );
|
|
|
|
p_libhal_ctx_set_device_removed( ctx, hal_removed_device );
|
|
|
|
p_libhal_ctx_set_device_property_modified( ctx, hal_property_modified );
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
p_dbus_error_init( &error );
|
2006-04-18 16:48:13 +02:00
|
|
|
if (!p_libhal_ctx_init( ctx, &error ))
|
|
|
|
{
|
2008-03-04 07:58:32 +01:00
|
|
|
WARN( "HAL context init failed: %s\n", error.message );
|
2006-04-18 16:48:13 +02:00
|
|
|
p_dbus_error_free( &error );
|
2011-12-20 11:42:45 +01:00
|
|
|
return FALSE;
|
2006-04-18 16:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve all existing devices */
|
|
|
|
if (!(list = p_libhal_get_all_devices( ctx, &num, &error ))) p_dbus_error_free( &error );
|
|
|
|
else
|
|
|
|
{
|
2011-12-20 11:04:18 +01:00
|
|
|
for (i = 0; i < num; i++) hal_new_device( ctx, list[i] );
|
2006-04-18 16:48:13 +02:00
|
|
|
p_libhal_free_string_array( list );
|
|
|
|
}
|
2011-12-20 11:42:45 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SONAME_LIBHAL */
|
|
|
|
|
|
|
|
static DWORD WINAPI dbus_thread( void *arg )
|
|
|
|
{
|
|
|
|
static const char udisks_match[] = "type='signal',"
|
|
|
|
"interface='org.freedesktop.UDisks',"
|
|
|
|
"sender='org.freedesktop.UDisks'";
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
|
|
|
p_dbus_error_init( &error );
|
|
|
|
if (!(connection = p_dbus_bus_get( DBUS_BUS_SYSTEM, &error )))
|
|
|
|
{
|
|
|
|
WARN( "failed to get system dbus connection: %s\n", error.message );
|
|
|
|
p_dbus_error_free( &error );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_dbus_connection_add_filter( connection, udisks_filter, NULL, NULL ))
|
|
|
|
p_dbus_bus_add_match( connection, udisks_match, &error );
|
|
|
|
|
|
|
|
if (!udisks_enumerate_devices())
|
|
|
|
{
|
|
|
|
p_dbus_bus_remove_match( connection, udisks_match, &error );
|
|
|
|
p_dbus_connection_remove_filter( connection, udisks_filter, NULL );
|
|
|
|
|
|
|
|
#ifdef SONAME_LIBHAL
|
|
|
|
if (!hal_enumerate_devices())
|
|
|
|
{
|
|
|
|
p_dbus_connection_close( connection );
|
|
|
|
p_dbus_error_free( &error );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2006-04-18 16:48:13 +02:00
|
|
|
|
|
|
|
__TRY
|
|
|
|
{
|
2011-12-20 11:42:45 +01:00
|
|
|
while (p_dbus_connection_read_write_dispatch( connection, -1 )) /* nothing */ ;
|
2006-04-18 16:48:13 +02:00
|
|
|
}
|
|
|
|
__EXCEPT( assert_fault )
|
|
|
|
{
|
2011-12-20 11:42:45 +01:00
|
|
|
WARN( "dbus assertion failure, disabling support\n" );
|
2006-04-18 16:48:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__ENDTRY;
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
p_dbus_connection_close( connection );
|
2006-04-18 16:48:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-20 11:04:18 +01:00
|
|
|
void initialize_dbus(void)
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
#ifdef SONAME_LIBHAL
|
|
|
|
if (!load_hal_functions())
|
|
|
|
#endif
|
|
|
|
if (!load_dbus_functions()) return;
|
2011-12-20 11:04:18 +01:00
|
|
|
if (!(handle = CreateThread( NULL, 0, dbus_thread, NULL, 0, NULL ))) return;
|
2006-04-18 16:48:13 +02:00
|
|
|
CloseHandle( handle );
|
|
|
|
}
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
#else /* SONAME_LIBDBUS_1 */
|
2006-04-18 16:48:13 +02:00
|
|
|
|
2011-12-20 11:04:18 +01:00
|
|
|
void initialize_dbus(void)
|
2006-04-18 16:48:13 +02:00
|
|
|
{
|
2011-12-20 11:04:18 +01:00
|
|
|
TRACE( "Skipping, DBUS support not compiled in\n" );
|
2006-04-18 16:48:13 +02:00
|
|
|
}
|
|
|
|
|
2011-12-20 11:42:45 +01:00
|
|
|
#endif /* SONAME_LIBDBUS_1 */
|