From 807f5ee9a09d02e7f6ab44395a40b0acaf40ac80 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Sat, 8 Mar 2008 12:35:31 -0800 Subject: [PATCH] mountmgr.sys: Query hal for extended device information --- dlls/mountmgr.sys/hal.c | 90 ++++++++++++++++++++++++++++++++++++----- dlls/mountmgr.sys/mountmgr.c | 12 +++++- dlls/mountmgr.sys/mountmgr.h | 3 + 3 files changed, 93 insertions(+), 12 deletions(-) diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c index 5a04ae5..2ea3048 100644 --- a/dlls/mountmgr.sys/hal.c +++ b/dlls/mountmgr.sys/hal.c @@ -2,6 +2,7 @@ * HAL devices support * * Copyright 2006 Alexandre Julliard + * Copyright 2008 Maarten Lankhorst * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -124,12 +125,11 @@ static LONG WINAPI assert_fault(EXCEPTION_POINTERS *eptr) static void new_device( LibHalContext *ctx, const char *udi ) { DBusError error; - char *parent = NULL; - char *mount_point = NULL; - char *device = NULL; - char *type = NULL; - char *filesystem = NULL; - char *parent_block = NULL; + char *parent = NULL, *mount_point = NULL, *device = NULL, *type = NULL, *filesystem = NULL, *product = NULL; + char *parent_block = NULL, *serial = NULL, *vendor = NULL, *grandparent = NULL, *fw_version = NULL; + const char *settype; + + BOOL got_extended = 0; p_dbus_error_init( &error ); @@ -152,23 +152,91 @@ static void new_device( LibHalContext *ctx, const char *udi ) if ((!type || strcasecmp(type, "cdrom")) && (!filesystem || !filesystem[0])) goto done; + if (!type || !strcmp(type, "disk")) + settype = "hd"; + else settype = type; + + /* Check if not mounted */ + if (!mount_point[0]) + goto out; + + TRACE("Mount point: %s\n", mount_point); + + if (!(parent_block = p_libhal_device_get_property_string( ctx, parent, "block.device", NULL ))) + goto out; + TRACE("Parent block device: %s\n", parent_block); + +#ifdef linux + if (!strncmp(parent_block, "/dev/ub", 7)) + FIXME("You're using the ub driver instead of usb-storage, adding extended info won't work\n"); +#endif + + /* Try the extended version, which adds usbstor keys! (removable = 1 at this point) */ + if (!(vendor = p_libhal_device_get_property_string( ctx, parent, "info.vendor", NULL ))) + goto out; + + TRACE("Vendor: %s\n", vendor); + + if (!(product = p_libhal_device_get_property_string( ctx, parent, "info.product", NULL ))) + goto out; + + TRACE("Product: %s\n", product); + + if (!(fw_version = p_libhal_device_get_property_string( ctx, parent, "storage.firmware_version", NULL ))) + goto out; + + TRACE("Firmware version: %s\n", fw_version); + + grandparent = p_libhal_device_get_property_string( ctx, parent, "info.parent", NULL ); + if (!grandparent) + goto out; + TRACE("Grandparent: %s\n", grandparent); + + while (!serial) { + char *ancestor = p_libhal_device_get_property_string( ctx, grandparent, "info.parent", NULL ); + if (ancestor) + { + p_libhal_free_string( grandparent ); + grandparent = ancestor; + serial = p_libhal_device_get_property_string( ctx, grandparent, "usb_device.serial", NULL ); + } + else break; + } + if (!serial) + goto out; + TRACE("Serial: %s\n", serial); + + got_extended = 1; + add_extended_dos_device( udi, device, parent_block, mount_point, settype, vendor, product, fw_version, serial ); + +out: if (mount_point[0]) { - parent_block = p_libhal_device_get_property_string( ctx, parent, "block.device", NULL ); - add_dos_device( udi, parent_block, device, mount_point, type ); - if (parent_block) p_libhal_free_string( parent_block ); + if (!got_extended) + { + TRACE("Extended usbstor failed, back to normal mode\n"); + add_dos_device( udi, parent_block, device, mount_point, settype ); + } } - else remove_dos_device( udi ); + else + remove_dos_device( udi ); /* add property watch for mount point */ p_libhal_device_add_property_watch( ctx, udi, &error ); + if (serial) p_libhal_free_string( serial ); + if (grandparent) p_libhal_free_string( grandparent ); + if (fw_version) p_libhal_free_string( fw_version ); + if (product) p_libhal_free_string( product ); + if (vendor) p_libhal_free_string( vendor ); + if (parent_block) p_libhal_free_string( parent_block ); + done: if (filesystem) p_libhal_free_string( filesystem ); if (type) p_libhal_free_string( type ); if (parent) p_libhal_free_string( parent ); - if (device) p_libhal_free_string( device ); if (mount_point) p_libhal_free_string( mount_point ); + if (device) p_libhal_free_string( device ); p_dbus_error_free( &error ); } diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c index ebba481..0092069 100644 --- a/dlls/mountmgr.sys/mountmgr.c +++ b/dlls/mountmgr.sys/mountmgr.c @@ -750,6 +750,16 @@ static DEVICE_OBJECT *find_parent_device(const char *parent_device) return devobj; } +BOOL add_extended_dos_device( const char *udi, const char *device, const char *parent_device, + const char *mount_point, const char *type, const char *vendor, + const char *product, const char *fw_version, const char *serial ) +{ + BOOL ret; + ret = add_dos_device( udi, parent_device, device, mount_point, type ); + FIXME("stub!\n"); + return ret; +} + BOOL add_dos_device( const char *udi, const char *parent_device, const char *device, const char *mount_point, const char *type ) { @@ -766,7 +776,7 @@ BOOL add_dos_device( const char *udi, const char *parent_device, const char *dev if (mount_points[drive * 2].device) { - ERR("Already added %s!\n", device); + TRACE("Already added %s!\n", device); return FALSE; } diff --git a/dlls/mountmgr.sys/mountmgr.h b/dlls/mountmgr.sys/mountmgr.h index d0cb5ad..88ab9b2 100644 --- a/dlls/mountmgr.sys/mountmgr.h +++ b/dlls/mountmgr.sys/mountmgr.h @@ -22,5 +22,8 @@ void initialize_hal(void); void initialize_diskarbitration(void); BOOL add_dos_device( const char *udi, const char *device, const char *parent_device, const char *mount_point, const char *type ); +BOOL add_extended_dos_device( const char *udi, const char *device, const char *parent_device, + const char *mount_point, const char *type, const char *vendor, + const char *product, const char *fw_version, const char *serial ); BOOL remove_dos_device( const char *udi ); -- 1.5.4.1