From b0cf3abe9569c5172ec75bcba5596b65205434c2 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 20 Dec 2011 11:04:18 +0100 Subject: [eter-2.0.0 03/10] mountmgr: Rename hal.c to dbus.c. Conflicts: dlls/mountmgr.sys/Makefile.in dlls/mountmgr.sys/mountmgr.c --- dlls/mountmgr.sys/Makefile.in | 2 +- dlls/mountmgr.sys/dbus.c | 384 +++++++++++++++++++++++++++++++++++++++++ dlls/mountmgr.sys/hal.c | 382 ---------------------------------------- dlls/mountmgr.sys/mountmgr.c | 2 +- dlls/mountmgr.sys/mountmgr.h | 2 +- 5 files changed, 387 insertions(+), 385 deletions(-) create mode 100644 dlls/mountmgr.sys/dbus.c delete mode 100644 dlls/mountmgr.sys/hal.c diff --git a/dlls/mountmgr.sys/Makefile.in b/dlls/mountmgr.sys/Makefile.in index 14b033f..38d9ccf 100644 --- a/dlls/mountmgr.sys/Makefile.in +++ b/dlls/mountmgr.sys/Makefile.in @@ -7,9 +7,9 @@ EXTRAINCL = @USBINCL@ EXTRALIBS = @DISKARBITRATIONLIB@ @USBLIBS@ @IEEE1284LIBS@ C_SRCS = \ + dbus.c \ device.c \ diskarb.c \ - hal.c \ mountmgr.c \ parport.c \ usbhub.c diff --git a/dlls/mountmgr.sys/dbus.c b/dlls/mountmgr.sys/dbus.c new file mode 100644 index 0000000..7d514ca --- /dev/null +++ b/dlls/mountmgr.sys/dbus.c @@ -0,0 +1,384 @@ +/* + * DBus devices support + * + * Copyright 2006 Alexandre Julliard + * + * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" +#include "wine/port.h" + +#include +#include +#include +#include +#include +#include +#ifdef SONAME_LIBDBUS_1 +# include +#endif +#ifdef SONAME_LIBHAL +# include +#endif + +#include "mountmgr.h" +#include "winnls.h" +#include "excpt.h" + +#include "wine/library.h" +#include "wine/exception.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(mountmgr); + +#ifdef SONAME_LIBHAL + +#define DBUS_FUNCS \ + DO_FUNC(dbus_bus_get); \ + DO_FUNC(dbus_connection_close); \ + DO_FUNC(dbus_connection_read_write_dispatch); \ + DO_FUNC(dbus_error_init); \ + DO_FUNC(dbus_error_free); \ + DO_FUNC(dbus_error_is_set) + +#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 +DBUS_FUNCS; +HAL_FUNCS; +#undef DO_FUNC + +static BOOL load_functions(void) +{ + void *hal_handle; + char error[128]; + + /* 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. */ + + 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 + 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 + + return TRUE; + +failed: + WARN( "failed to load HAL support: %s\n", error ); + return FALSE; +} + +static LONG WINAPI assert_fault(EXCEPTION_POINTERS *eptr) +{ + if (eptr->ExceptionRecord->ExceptionCode == EXCEPTION_WINE_ASSERTION) + return EXCEPTION_EXECUTE_HANDLER; + return EXCEPTION_CONTINUE_SEARCH; +} + +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; +} + +static int automount_disabled(void) +{ + static int disabled = -1; + + if (disabled < 0) + { + char *automount = getenv( "WINEAUTOMOUNT" ); + disabled = (automount && !strcmp( automount, "no" )); + } + return disabled; +} + +static int get_num_from_file( const char *path, const char *filename ) +{ + char *fullpath, str[16]; + int fd, num = 0; + + fullpath = RtlAllocateHeap( GetProcessHeap(), 0, + strlen(path) + strlen(filename) + 2 ); + if (!fullpath) return 0; + strcpy( fullpath, path ); + strcat( fullpath, "/" ); + strcat( fullpath, filename ); + if ((fd = open( fullpath, O_RDONLY )) >= 0) + { + if ((num = read( fd, str, sizeof(str) - 1 )) > 0) + { + str[num] = 0; + num = atoi( str ); + } + close( fd ); + } + RtlFreeHeap( GetProcessHeap(), 0, fullpath ); + return num; +} + +/* HAL callback for new device */ +static void hal_new_device( LibHalContext *ctx, const char *udi ) +{ + DBusError error; + char *subsys = NULL; + char *parent = NULL; + char *mount_point = NULL; + char *device = NULL; + char *type = NULL; + char *bus = NULL; + char *vendor = NULL; + char *product = NULL; + char *revision = NULL; + char *current = NULL; + char *prev = NULL; + char *serial = NULL; + char *sysfs_path; + char *uuid_str = NULL; + GUID guid, *guid_ptr = NULL; + enum device_type drive_type; + STORAGE_BUS_TYPE bus_type; + int usb_bus = 0, usb_addr = 0; + + p_dbus_error_init( &error ); + + if ((subsys = p_libhal_device_get_property_string( ctx, udi, "info.subsystem", NULL )) && + !strcmp( subsys, "usb_device" )) + add_usb_devices(); + + if (automount_disabled()) + goto done; + + 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 ); + + bus = p_libhal_device_get_property_string( ctx, parent, "storage.bus", NULL ); + if (bus && !strcmp( bus, "usb" )) bus_type = BusTypeUsb; + else bus_type = BusTypeUnknown; + + type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", NULL ); + if (type && !strcmp( type, "cdrom" )) drive_type = DEVICE_CDROM; + else if (type && !strcmp( type, "floppy" )) drive_type = DEVICE_FLOPPY; + else if (type && !strcmp( type, "disk" )) drive_type = DEVICE_HARDDISK; + else drive_type = DEVICE_UNKNOWN; + + vendor = p_libhal_device_get_property_string( ctx, parent, "info.vendor", NULL ); + product = p_libhal_device_get_property_string( ctx, parent, "info.product", NULL ); + revision = p_libhal_device_get_property_string( ctx, parent, "storage.firmware_version", NULL ); + + if (!(current = p_libhal_device_get_property_string( ctx, udi, "info.parent", NULL ))) + goto done; + do { + prev = p_libhal_device_get_property_string( ctx, current, "info.parent", NULL ); + if (prev) + { + serial = p_libhal_device_get_property_string( ctx, prev, "usb_device.serial", NULL ); + } + if (serial) + { + sysfs_path = p_libhal_device_get_property_string( ctx, prev, "linux.sysfs_path", NULL ); + if (sysfs_path) + { + usb_bus = get_num_from_file( sysfs_path, "busnum" ); + usb_addr = get_num_from_file( sysfs_path, "devnum" ); + p_libhal_free_string( sysfs_path ); + } + } + p_libhal_free_string( current ); + current = prev; + prev = NULL; + } while (current && !serial); + + if (p_libhal_device_get_property_bool( ctx, parent, "storage.removable", &error )) + { + add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr, + bus_type, vendor, product, revision, serial, usb_bus, usb_addr ); + /* 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 (subsys) p_libhal_free_string( subsys ); + 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 ); + if (bus) p_libhal_free_string( bus ); + if (vendor) p_libhal_free_string( vendor ); + if (product) p_libhal_free_string( product ); + if (revision) p_libhal_free_string( revision ); + if (current) p_libhal_free_string( current ); + if (serial) p_libhal_free_string( serial ); + p_dbus_error_free( &error ); +} + +/* HAL callback for removed device */ +static void hal_removed_device( LibHalContext *ctx, const char *udi ) +{ + DBusError error; + + TRACE( "removed %s\n", wine_dbgstr_a(udi) ); + + remove_usb_devices(); + if (!remove_dos_device( -1, udi )) + { + p_dbus_error_init( &error ); + p_libhal_device_remove_property_watch( ctx, udi, &error ); + p_dbus_error_free( &error ); + } + else remove_volume( udi ); +} + +/* HAL callback for property changes */ +static void hal_property_modified (LibHalContext *ctx, const char *udi, + const char *key, dbus_bool_t is_removed, dbus_bool_t is_added) +{ + TRACE( "udi %s key %s %s\n", wine_dbgstr_a(udi), wine_dbgstr_a(key), + is_added ? "added" : is_removed ? "removed" : "modified" ); + + if (!strcmp( key, "volume.mount_point" )) hal_new_device( ctx, udi ); +} + + +static DWORD WINAPI dbus_thread( void *arg ) +{ + DBusError error; + DBusConnection *dbc; + LibHalContext *ctx; + int i, num; + char **list; + + if (!(ctx = p_libhal_ctx_new())) return 1; + + p_dbus_error_init( &error ); + if (!(dbc = 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; + } + + p_libhal_ctx_set_dbus_connection( ctx, dbc ); + 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 ); + + if (!p_libhal_ctx_init( ctx, &error )) + { + WARN( "HAL context init failed: %s\n", error.message ); + p_dbus_error_free( &error ); + return 1; + } + + /* retrieve all existing devices */ + if (!(list = p_libhal_get_all_devices( ctx, &num, &error ))) p_dbus_error_free( &error ); + else + { + for (i = 0; i < num; i++) hal_new_device( ctx, list[i] ); + p_libhal_free_string_array( list ); + } + + __TRY + { + while (p_dbus_connection_read_write_dispatch( dbc, -1 )) /* nothing */ ; + } + __EXCEPT( assert_fault ) + { + WARN( "dbus assertion failure, disabling HAL support\n" ); + return 1; + } + __ENDTRY; + + p_libhal_ctx_shutdown( ctx, &error ); + p_dbus_error_free( &error ); /* just in case */ + p_dbus_connection_close( dbc ); + p_libhal_ctx_free( ctx ); + return 0; +} + +void initialize_dbus(void) +{ + HANDLE handle; + + if (!load_functions()) return; + if (!(handle = CreateThread( NULL, 0, dbus_thread, NULL, 0, NULL ))) return; + CloseHandle( handle ); +} + +#else /* SONAME_LIBHAL */ + +void initialize_dbus(void) +{ + TRACE( "Skipping, DBUS support not compiled in\n" ); +} + +#endif /* SONAME_LIBHAL */ diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c deleted file mode 100644 index 95970c5..0000000 --- a/dlls/mountmgr.sys/hal.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * HAL devices support - * - * Copyright 2006 Alexandre Julliard - * - * 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 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#include -#include -#include -#include -#ifdef SONAME_LIBHAL -# include -# include -#endif - -#include "mountmgr.h" -#include "winnls.h" -#include "excpt.h" - -#include "wine/library.h" -#include "wine/exception.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(mountmgr); - -#ifdef SONAME_LIBHAL - -#define DBUS_FUNCS \ - DO_FUNC(dbus_bus_get); \ - DO_FUNC(dbus_connection_close); \ - DO_FUNC(dbus_connection_read_write_dispatch); \ - DO_FUNC(dbus_error_init); \ - DO_FUNC(dbus_error_free); \ - DO_FUNC(dbus_error_is_set) - -#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 -DBUS_FUNCS; -HAL_FUNCS; -#undef DO_FUNC - -static BOOL load_functions(void) -{ - void *hal_handle; - char error[128]; - - /* 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. */ - - 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 - 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 - - return TRUE; - -failed: - WARN( "failed to load HAL support: %s\n", error ); - return FALSE; -} - -static LONG WINAPI assert_fault(EXCEPTION_POINTERS *eptr) -{ - if (eptr->ExceptionRecord->ExceptionCode == EXCEPTION_WINE_ASSERTION) - return EXCEPTION_EXECUTE_HANDLER; - return EXCEPTION_CONTINUE_SEARCH; -} - -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; -} - -static int automount_disabled(void) -{ - static int disabled = -1; - - if (disabled < 0) - { - char *automount = getenv( "WINEAUTOMOUNT" ); - disabled = (automount && !strcmp( automount, "no" )); - } - return disabled; -} - -static int get_num_from_file( const char *path, const char *filename ) -{ - char *fullpath, str[16]; - int fd, num = 0; - - fullpath = RtlAllocateHeap( GetProcessHeap(), 0, - strlen(path) + strlen(filename) + 2 ); - if (!fullpath) return 0; - strcpy( fullpath, path ); - strcat( fullpath, "/" ); - strcat( fullpath, filename ); - if ((fd = open( fullpath, O_RDONLY )) >= 0) - { - if ((num = read( fd, str, sizeof(str) - 1 )) > 0) - { - str[num] = 0; - num = atoi( str ); - } - close( fd ); - } - RtlFreeHeap( GetProcessHeap(), 0, fullpath ); - return num; -} - -/* HAL callback for new device */ -static void new_device( LibHalContext *ctx, const char *udi ) -{ - DBusError error; - char *subsys = NULL; - char *parent = NULL; - char *mount_point = NULL; - char *device = NULL; - char *type = NULL; - char *bus = NULL; - char *vendor = NULL; - char *product = NULL; - char *revision = NULL; - char *current = NULL; - char *prev = NULL; - char *serial = NULL; - char *sysfs_path; - char *uuid_str = NULL; - GUID guid, *guid_ptr = NULL; - enum device_type drive_type; - STORAGE_BUS_TYPE bus_type; - int usb_bus = 0, usb_addr = 0; - - p_dbus_error_init( &error ); - - if ((subsys = p_libhal_device_get_property_string( ctx, udi, "info.subsystem", NULL )) && - !strcmp( subsys, "usb_device" )) - add_usb_devices(); - - if (automount_disabled()) - goto done; - - 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 ); - - bus = p_libhal_device_get_property_string( ctx, parent, "storage.bus", NULL ); - if (bus && !strcmp( bus, "usb" )) bus_type = BusTypeUsb; - else bus_type = BusTypeUnknown; - - type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", NULL ); - if (type && !strcmp( type, "cdrom" )) drive_type = DEVICE_CDROM; - else if (type && !strcmp( type, "floppy" )) drive_type = DEVICE_FLOPPY; - else if (type && !strcmp( type, "disk" )) drive_type = DEVICE_HARDDISK; - else drive_type = DEVICE_UNKNOWN; - - vendor = p_libhal_device_get_property_string( ctx, parent, "info.vendor", NULL ); - product = p_libhal_device_get_property_string( ctx, parent, "info.product", NULL ); - revision = p_libhal_device_get_property_string( ctx, parent, "storage.firmware_version", NULL ); - - if (!(current = p_libhal_device_get_property_string( ctx, udi, "info.parent", NULL ))) - goto done; - do { - prev = p_libhal_device_get_property_string( ctx, current, "info.parent", NULL ); - if (prev) - { - serial = p_libhal_device_get_property_string( ctx, prev, "usb_device.serial", NULL ); - } - if (serial) - { - sysfs_path = p_libhal_device_get_property_string( ctx, prev, "linux.sysfs_path", NULL ); - if (sysfs_path) - { - usb_bus = get_num_from_file( sysfs_path, "busnum" ); - usb_addr = get_num_from_file( sysfs_path, "devnum" ); - p_libhal_free_string( sysfs_path ); - } - } - p_libhal_free_string( current ); - current = prev; - prev = NULL; - } while (current && !serial); - - if (p_libhal_device_get_property_bool( ctx, parent, "storage.removable", &error )) - { - add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr, - bus_type, vendor, product, revision, serial, usb_bus, usb_addr ); - /* 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 (subsys) p_libhal_free_string( subsys ); - 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 ); - if (bus) p_libhal_free_string( bus ); - if (vendor) p_libhal_free_string( vendor ); - if (product) p_libhal_free_string( product ); - if (revision) p_libhal_free_string( revision ); - if (current) p_libhal_free_string( current ); - if (serial) p_libhal_free_string( serial ); - p_dbus_error_free( &error ); -} - -/* HAL callback for removed device */ -static void removed_device( LibHalContext *ctx, const char *udi ) -{ - DBusError error; - - TRACE( "removed %s\n", wine_dbgstr_a(udi) ); - - remove_usb_devices(); - if (!remove_dos_device( -1, udi )) - { - p_dbus_error_init( &error ); - p_libhal_device_remove_property_watch( ctx, udi, &error ); - p_dbus_error_free( &error ); - } - else remove_volume( udi ); -} - -/* HAL callback for property changes */ -static void property_modified (LibHalContext *ctx, const char *udi, - const char *key, dbus_bool_t is_removed, dbus_bool_t is_added) -{ - TRACE( "udi %s key %s %s\n", wine_dbgstr_a(udi), wine_dbgstr_a(key), - is_added ? "added" : is_removed ? "removed" : "modified" ); - - if (!strcmp( key, "volume.mount_point" )) new_device( ctx, udi ); -} - - -static DWORD WINAPI hal_thread( void *arg ) -{ - DBusError error; - DBusConnection *dbc; - LibHalContext *ctx; - int i, num; - char **list; - - if (!(ctx = p_libhal_ctx_new())) return 1; - - p_dbus_error_init( &error ); - if (!(dbc = 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; - } - - p_libhal_ctx_set_dbus_connection( ctx, dbc ); - p_libhal_ctx_set_device_added( ctx, new_device ); - p_libhal_ctx_set_device_removed( ctx, removed_device ); - p_libhal_ctx_set_device_property_modified( ctx, property_modified ); - - if (!p_libhal_ctx_init( ctx, &error )) - { - WARN( "HAL context init failed: %s\n", error.message ); - p_dbus_error_free( &error ); - return 1; - } - - /* retrieve all existing devices */ - if (!(list = p_libhal_get_all_devices( ctx, &num, &error ))) p_dbus_error_free( &error ); - else - { - for (i = 0; i < num; i++) new_device( ctx, list[i] ); - p_libhal_free_string_array( list ); - } - - __TRY - { - while (p_dbus_connection_read_write_dispatch( dbc, -1 )) /* nothing */ ; - } - __EXCEPT( assert_fault ) - { - WARN( "dbus assertion failure, disabling HAL support\n" ); - return 1; - } - __ENDTRY; - - p_libhal_ctx_shutdown( ctx, &error ); - p_dbus_error_free( &error ); /* just in case */ - p_dbus_connection_close( dbc ); - p_libhal_ctx_free( ctx ); - return 0; -} - -void initialize_hal(void) -{ - HANDLE handle; - - if (!load_functions()) return; - if (!(handle = CreateThread( NULL, 0, hal_thread, NULL, 0, NULL ))) return; - CloseHandle( handle ); -} - -#else /* SONAME_LIBHAL */ - -void initialize_hal(void) -{ - TRACE( "Skipping, HAL support not compiled in\n" ); -} - -#endif /* SONAME_LIBHAL */ diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c index 224fda2..05615cc 100644 --- a/dlls/mountmgr.sys/mountmgr.c +++ b/dlls/mountmgr.sys/mountmgr.c @@ -472,7 +472,7 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) RtlInitUnicodeString( &nameW, usbhubW ); status = IoCreateDriver( &nameW, usbhub_driver_entry ); - initialize_hal(); + initialize_dbus(); initialize_diskarbitration(); return status; diff --git a/dlls/mountmgr.sys/mountmgr.h b/dlls/mountmgr.sys/mountmgr.h index 32558bc..3b1f5a1 100644 --- a/dlls/mountmgr.sys/mountmgr.h +++ b/dlls/mountmgr.sys/mountmgr.h @@ -36,7 +36,7 @@ #include "ddk/wdm.h" #include "ddk/mountmgr.h" -extern void initialize_hal(void) DECLSPEC_HIDDEN; +extern void initialize_dbus(void) DECLSPEC_HIDDEN; extern void initialize_diskarbitration(void) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI usbhub_driver_entry( DRIVER_OBJECT *driver, -- 1.7.9.7