[PATCH 1/2] mountmgr: Populate HKLM\HARDWARE\DEVICEMAP\Scsi here instead of in kernel32. (try 4)

Charles Davis cdavis at mymail.mines.edu
Wed May 4 11:00:48 CDT 2011


Try 4: Fix unused variable warning.
Try 3: Add support for IDE drives.
Try 2: Don't depend on the SCSI-generic driver on Linux.

---
 dlls/kernel32/Makefile.in    |    1 -
 dlls/kernel32/oldconfig.c    |  404 ------------------------------------------
 dlls/kernel32/process.c      |    3 -
 dlls/mountmgr.sys/hal.c      |  165 +++++++++++++++++
 dlls/mountmgr.sys/mountmgr.c |  169 ++++++++++++++++++
 dlls/mountmgr.sys/mountmgr.h |    4 +
 6 files changed, 338 insertions(+), 408 deletions(-)
 delete mode 100644 dlls/kernel32/oldconfig.c

diff --git a/dlls/kernel32/Makefile.in b/dlls/kernel32/Makefile.in
index 6c60623..e5b3ac6 100644
--- a/dlls/kernel32/Makefile.in
+++ b/dlls/kernel32/Makefile.in
@@ -26,7 +26,6 @@ C_SRCS = \
 	locale.c \
 	lzexpand.c \
 	module.c \
-	oldconfig.c \
 	path.c \
 	powermgnt.c \
 	process.c \
diff --git a/dlls/kernel32/oldconfig.c b/dlls/kernel32/oldconfig.c
deleted file mode 100644
index 02dac06..0000000
--- a/dlls/kernel32/oldconfig.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/*
- * Support for converting from old configuration format
- *
- * Copyright 2005 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
- *
- * NOTES
- *   This file should be removed after a suitable transition period.
- */
-
-#include "config.h"
-#include "wine/port.h"
-
-#include <stdarg.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#include <fcntl.h>
-#ifdef HAVE_DIRENT_H
-# include <dirent.h>
-#endif
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-#ifdef HAVE_LINUX_HDREG_H
-# include <linux/hdreg.h>
-#endif
-
-#define NONAMELESSUNION
-#define NONAMELESSSTRUCT
-#include "windef.h"
-#include "winbase.h"
-#include "winternl.h"
-#include "ntddscsi.h"
-#include "wine/library.h"
-#include "wine/unicode.h"
-#include "wine/debug.h"
-#include "kernel_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(reg);
-
-static NTSTATUS create_key( HANDLE root, const char *name, HANDLE *key, DWORD *disp )
-{
-    OBJECT_ATTRIBUTES attr;
-    UNICODE_STRING nameW;
-    NTSTATUS status;
-
-    attr.Length = sizeof(attr);
-    attr.RootDirectory = root;
-    attr.ObjectName = &nameW;
-    attr.Attributes = 0;
-    attr.SecurityDescriptor = NULL;
-    attr.SecurityQualityOfService = NULL;
-
-    if (!RtlCreateUnicodeStringFromAsciiz( &nameW, name )) return STATUS_NO_MEMORY;
-    status = NtCreateKey( key, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, disp );
-    if (status) ERR("Cannot create %s registry key\n", name );
-    RtlFreeUnicodeString( &nameW );
-    return status;
-}
-
-/******************************************************************
- *		create_scsi_entry
- *
- * Initializes registry to contain scsi info about the cdrom in NT.
- * All devices (even not real scsi ones) have this info in NT.
- * NOTE: programs usually read these registry entries after sending the
- *       IOCTL_SCSI_GET_ADDRESS ioctl to the cdrom
- */
-static void create_scsi_entry( PSCSI_ADDRESS scsi_addr, LPCSTR lpDriver, UINT uDriveType,
-    LPSTR lpDriveName, LPSTR lpUnixDeviceName )
-{
-    static UCHAR uCdromNumber = 0;
-    static UCHAR uTapeNumber = 0;
-
-    UNICODE_STRING nameW;
-    WCHAR dataW[50];
-    DWORD sizeW;
-    char buffer[40];
-    DWORD value;
-    const char *data;
-    HANDLE scsiKey;
-    HANDLE portKey;
-    HANDLE busKey;
-    HANDLE targetKey;
-    HANDLE lunKey;
-    DWORD disp;
-
-    if (create_key( 0, "Machine\\HARDWARE\\DEVICEMAP", &scsiKey, &disp )) return;
-    NtClose( scsiKey );
-
-    /* Ensure there is Scsi key */
-    if (create_key( 0, "Machine\\HARDWARE\\DEVICEMAP\\Scsi", &scsiKey, &disp )) return;
-
-    snprintf(buffer,sizeof(buffer),"Scsi Port %d",scsi_addr->PortNumber);
-    if (create_key( scsiKey, buffer, &portKey, &disp )) return;
-
-    RtlCreateUnicodeStringFromAsciiz( &nameW, "Driver" );
-    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, lpDriver, strlen(lpDriver)+1);
-    NtSetValueKey( portKey, &nameW, 0, REG_SZ, dataW, sizeW );
-    RtlFreeUnicodeString( &nameW );
-    value = 10;
-    RtlCreateUnicodeStringFromAsciiz( &nameW, "FirstBusTimeScanInMs" );
-    NtSetValueKey( portKey,&nameW, 0, REG_DWORD, &value, sizeof(DWORD) );
-    RtlFreeUnicodeString( &nameW );
-
-    value = 0;
-    if (strcmp(lpDriver, "atapi") == 0)
-    {
-#ifdef HDIO_GET_DMA
-        int fd, dma;
-        
-        fd = open(lpUnixDeviceName, O_RDONLY|O_NONBLOCK);
-        if (fd != -1)
-        {
-            if (ioctl(fd, HDIO_GET_DMA, &dma) != -1) value = dma;
-            close(fd);
-        }
-#endif
-        RtlCreateUnicodeStringFromAsciiz( &nameW, "DMAEnabled" );
-        NtSetValueKey( portKey,&nameW, 0, REG_DWORD, &value, sizeof(DWORD) );
-        RtlFreeUnicodeString( &nameW );
-    }
-
-    snprintf(buffer, sizeof(buffer),"Scsi Bus %d", scsi_addr->PathId);
-    if (create_key( portKey, buffer, &busKey, &disp )) return;
-
-    /* FIXME: get real controller Id for SCSI */
-    if (create_key( busKey, buffer, &targetKey, &disp )) return;
-    NtClose( targetKey );
-
-    snprintf(buffer, sizeof(buffer),"Target Id %d", scsi_addr->TargetId);
-    if (create_key( busKey, buffer, &targetKey, &disp )) return;
-
-    snprintf(buffer, sizeof(buffer),"Logical Unit Id %d", scsi_addr->Lun);
-    if (create_key( targetKey, buffer, &lunKey, &disp )) return;
-
-    switch (uDriveType)
-    {
-        case DRIVE_NO_ROOT_DIR:
-        default:
-            data = "OtherPeripheral"; break;
-        case DRIVE_FIXED:
-            data = "DiskPeripheral"; break;
-        case DRIVE_REMOVABLE:
-            data = "TapePeripheral";
-            snprintf(buffer, sizeof(buffer), "Tape%d", uTapeNumber++);
-            break;
-        case DRIVE_CDROM:
-            data = "CdRomPeripheral";
-            snprintf(buffer, sizeof(buffer), "Cdrom%d", uCdromNumber++);
-            break;
-    }
-    RtlCreateUnicodeStringFromAsciiz( &nameW, "Type" );
-    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, data, strlen(data)+1);
-    NtSetValueKey( lunKey, &nameW, 0, REG_SZ, dataW, sizeW );
-    RtlFreeUnicodeString( &nameW );
-
-    RtlCreateUnicodeStringFromAsciiz( &nameW, "Identifier" );
-    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, lpDriveName, strlen(lpDriveName)+1);
-    NtSetValueKey( lunKey, &nameW, 0, REG_SZ, dataW, sizeW );
-    RtlFreeUnicodeString( &nameW );
-
-    if (uDriveType == DRIVE_CDROM || uDriveType == DRIVE_REMOVABLE)
-    {
-        RtlCreateUnicodeStringFromAsciiz( &nameW, "DeviceName" );
-        RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, buffer, strlen(buffer)+1);
-        NtSetValueKey( lunKey, &nameW, 0, REG_SZ, dataW, sizeW );
-        RtlFreeUnicodeString( &nameW );
-    }
-
-    RtlCreateUnicodeStringFromAsciiz( &nameW, "UnixDeviceName" );
-    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, lpUnixDeviceName, strlen(lpUnixDeviceName)+1);
-    NtSetValueKey( lunKey, &nameW, 0, REG_SZ, dataW, sizeW );
-    RtlFreeUnicodeString( &nameW );
-
-    NtClose( lunKey );
-    NtClose( targetKey );
-    NtClose( busKey );
-    NtClose( portKey );
-    NtClose( scsiKey );
-}
-
-struct LinuxProcScsiDevice
-{
-    int host;
-    int channel;
-    int target;
-    int lun;
-    char vendor[9];
-    char model[17];
-    char rev[5];
-    char type[33];
-    int ansirev;
-};
-
-/*
- * we need to declare white spaces explicitly via %*1[ ],
- * as there are very dainbread CD-ROM devices out there
- * which have their manufacturer name blanked out via spaces,
- * which confuses fscanf's parsing (skips all blank spaces)
- */
-static int SCSI_getprocentry( FILE * procfile, struct LinuxProcScsiDevice * dev )
-{
-    int result;
-
-    result = fscanf( procfile,
-        "Host:%*1[ ]scsi%d%*1[ ]Channel:%*1[ ]%d%*1[ ]Id:%*1[ ]%d%*1[ ]Lun:%*1[ ]%d\n",
-	&dev->host,
-	&dev->channel,
-	&dev->target,
-	&dev->lun );
-    if( result == EOF )
-    {
-        /* "end of entries" return, so no TRACE() here */
-        return EOF;
-    }
-    if( result != 4 )
-    {
-        ERR("bus id line scan count error (fscanf returns %d, expected 4)\n", result);
-        return 0;
-    }
-    result = fscanf( procfile,
-        "  Vendor:%*1[ ]%8c%*1[ ]Model:%*1[ ]%16c%*1[ ]Rev:%*1[ ]%4c\n",
-        dev->vendor,
-        dev->model,
-        dev->rev );
-    if( result != 3 )
-    {
-        ERR("model line scan count error (fscanf returns %d, expected 3)\n", result);
-        return 0;
-    }
-
-    result = fscanf( procfile,
-        "  Type:%*3[ ]%32c%*1[ ]ANSI SCSI%*1[ ]revision:%*1[ ]%x\n",
-        dev->type,
-        &dev->ansirev );
-    if( result != 2 )
-    {
-        ERR("SCSI type line scan count error (fscanf returns %d, expected 2)\n", result);
-        return 0;
-    }
-    /* Since we fscanf with %XXc instead of %s.. put a NULL at end */
-    dev->vendor[8] = 0;
-    dev->model[16] = 0;
-    dev->rev[4] = 0;
-    dev->type[32] = 0;
-
-    return 1;
-}
-
-
-/* create the hardware registry branch */
-static void create_hardware_branch(void)
-{
-    /* The following mostly will work on Linux, but should not cause
-     * problems on other systems. */
-    static const char procname_ide_media[] = "/proc/ide/%s/media";
-    static const char procname_ide_model[] = "/proc/ide/%s/model";
-    static const char procname_scsi[] = "/proc/scsi/scsi";
-    DIR *idedir;
-    struct dirent *dent = NULL;
-    FILE *procfile = NULL;
-    char cStr[40], cDevModel[40], cUnixDeviceName[40], read1[10] = "\0", read2[10] = "\0";
-    SCSI_ADDRESS scsi_addr;
-    UINT nType;
-    struct LinuxProcScsiDevice dev;
-    int result = 0, nSgNumber = 0;
-    UCHAR uFirstSCSIPort = 0;
-
-    /* Enumerate all ide devices first */
-    idedir = opendir("/proc/ide");
-    if (idedir)
-    {
-        while ((dent = readdir(idedir)))
-        {
-            if (strncmp(dent->d_name, "hd", 2) == 0)
-            {
-                sprintf(cStr, procname_ide_media, dent->d_name);
-                procfile = fopen(cStr, "r");
-                if (!procfile)
-                {
-                    ERR("Could not open %s\n", cStr);
-                    continue;
-                } else {
-                    fgets(cStr, sizeof(cStr), procfile);
-                    fclose(procfile);
-                    nType = DRIVE_UNKNOWN;
-                    if (strncasecmp(cStr, "disk", 4)  == 0) nType = DRIVE_FIXED;
-                    if (strncasecmp(cStr, "cdrom", 5) == 0) nType = DRIVE_CDROM;
-
-                    if (nType == DRIVE_UNKNOWN) continue;
-                }
-
-                sprintf(cStr, procname_ide_model, dent->d_name);
-                procfile = fopen(cStr, "r");
-                if (!procfile)
-                {
-                    ERR("Could not open %s\n", cStr);
-                    switch (nType)
-                    {
-                    case DRIVE_FIXED: strcpy(cDevModel, "Wine harddisk"); break;
-                    case DRIVE_CDROM: strcpy(cDevModel, "Wine CDROM"); break;
-                    }
-                } else {
-                    fgets(cDevModel, sizeof(cDevModel), procfile);
-                    fclose(procfile);
-                    cDevModel[strlen(cDevModel) - 1] = 0;
-                }
-
-                sprintf(cUnixDeviceName, "/dev/%s", dent->d_name);
-                scsi_addr.PortNumber = (dent->d_name[2] - 'a') / 2;
-                scsi_addr.PathId = 0;
-                scsi_addr.TargetId = (dent->d_name[2] - 'a') % 2;
-                scsi_addr.Lun = 0;
-                if (scsi_addr.PortNumber + 1 > uFirstSCSIPort)
-                    uFirstSCSIPort = scsi_addr.PortNumber + 1;
-
-                create_scsi_entry(&scsi_addr, "atapi", nType, cDevModel, cUnixDeviceName);
-            }
-        }
-        closedir(idedir);
-    }
-
-    /* Now goes SCSI */
-    procfile = fopen(procname_scsi, "r");
-    if (!procfile)
-    {
-        TRACE("Could not open %s\n", procname_scsi);
-        return;
-    }
-    fgets(cStr, 40, procfile);
-    sscanf(cStr, "Attached %9s %9s", read1, read2);
-
-    if (strcmp(read1, "devices:") != 0)
-    {
-        WARN("Incorrect %s format\n", procname_scsi);
-        fclose( procfile );
-        return;
-    }
-    if (strcmp(read2, "none") == 0)
-    {
-        TRACE("No SCSI devices found in %s.\n", procname_scsi);
-        fclose( procfile );
-        return;
-    }
-
-    /* Read info for one device */
-    while ((result = SCSI_getprocentry(procfile, &dev)) > 0)
-    {
-        scsi_addr.PortNumber = dev.host;
-        scsi_addr.PathId = dev.channel;
-        scsi_addr.TargetId = dev.target;
-        scsi_addr.Lun = dev.lun;
-
-        scsi_addr.PortNumber += uFirstSCSIPort;
-        if (strncmp(dev.type, "Direct-Access", 13) == 0) nType = DRIVE_FIXED;
-        else if (strncmp(dev.type, "Sequential-Access", 17) == 0) nType = DRIVE_REMOVABLE;
-        else if (strncmp(dev.type, "CD-ROM", 6) == 0) nType = DRIVE_CDROM;
-        else if (strncmp(dev.type, "Processor", 9) == 0) nType = DRIVE_NO_ROOT_DIR;
-        else continue;
-
-        strcpy(cDevModel, dev.vendor);
-        strcat(cDevModel, dev.model);
-        strcat(cDevModel, dev.rev);
-        sprintf(cUnixDeviceName, "/dev/sg%d", nSgNumber++);
-        /* FIXME: get real driver name */
-        create_scsi_entry(&scsi_addr, "WINE SCSI", nType, cDevModel, cUnixDeviceName);
-    }
-    if( result != EOF )
-        WARN("Incorrect %s format\n", procname_scsi);
-    fclose( procfile );
-}
-
-
-/***********************************************************************
- *              convert_old_config
- */
-void convert_old_config(void)
-{
-    HANDLE key;
-    DWORD disp;
-
-    /* create some hardware keys (FIXME: should not be done here) */
-    if (create_key( 0, "Machine\\HARDWARE", &key, &disp )) return;
-    NtClose( key );
-    if (disp != REG_OPENED_EXISTING_KEY) create_hardware_branch();
-}
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index d1d6a3b..34dadb3 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -1157,9 +1157,6 @@ void CDECL __wine_kernel_init(void)
         /* Copy the parent environment */
         if (!build_initial_environment()) exit(1);
 
-        /* convert old configuration to new format */
-        convert_old_config();
-
         got_environment = set_registry_environment( FALSE );
         set_additional_environment();
     }
diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c
index 82a70e9..ebfd1a2 100644
--- a/dlls/mountmgr.sys/hal.c
+++ b/dlls/mountmgr.sys/hal.c
@@ -59,7 +59,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
     DO_FUNC(libhal_ctx_set_device_property_modified); \
     DO_FUNC(libhal_ctx_set_device_removed); \
     DO_FUNC(libhal_ctx_shutdown); \
+    DO_FUNC(libhal_device_property_exists); \
     DO_FUNC(libhal_device_get_property_bool); \
+    DO_FUNC(libhal_device_get_property_int); \
     DO_FUNC(libhal_device_get_property_string); \
     DO_FUNC(libhal_device_add_property_watch); \
     DO_FUNC(libhal_device_remove_property_watch); \
@@ -133,6 +135,163 @@ static GUID *parse_uuid( GUID *guid, const char *str )
     return NULL;
 }
 
+static int get_scsi_parameters( LibHalContext *ctx, const char *udi, SCSI_ADDRESS *scsi_addr, UCHAR *devtype, char *ident, size_t ident_size )
+{
+    DBusError error;
+    char *type = NULL;
+    char *vendor = NULL;
+    char *model = NULL;
+    int host, bus, target, lun;
+    int ret = 0;
+
+    p_dbus_error_init( &error );
+
+    if ((host = p_libhal_device_get_property_int( ctx, udi, "scsi.host", &error )) < 0)
+        goto done;
+    if ((bus = p_libhal_device_get_property_int( ctx, udi, "scsi.bus", &error )) < 0)
+        goto done;
+    if ((target = p_libhal_device_get_property_int( ctx, udi, "scsi.target", &error )) < 0)
+        goto done;
+    if ((lun = p_libhal_device_get_property_int( ctx, udi, "scsi.lun", &error )) < 0)
+        goto done;
+
+    ret = 1;
+    scsi_addr->PortNumber = host + 2;
+    scsi_addr->PathId = bus;
+    scsi_addr->TargetId = target;
+    scsi_addr->Lun = lun;
+
+    if (ident)
+    {
+        if (!(vendor = p_libhal_device_get_property_string( ctx, udi, "scsi.vendor", &error )))
+            p_dbus_error_free( &error );  /* ignore error */
+        if (!(model = p_libhal_device_get_property_string( ctx, udi, "scsi.model", &error )))
+            p_dbus_error_free( &error );  /* ignore error */
+        snprintf( ident, ident_size, "%s %s", vendor ? vendor : "WINE", model ? model : "SCSI" );
+    }
+
+    if (devtype)
+    {
+        if (!(type = p_libhal_device_get_property_string( ctx, udi, "scsi.type", &error )))
+        {
+            *devtype = ~0;
+            goto done;
+        }
+        if (!strcmp( type, "disk" ))
+            *devtype = 0x00;
+        else if (!strcmp( type, "tape" ))
+            *devtype = 0x01;
+        else if (!strcmp( type, "printer" ))
+            *devtype = 0x02;
+        else if (!strcmp( type, "processor" ))
+            *devtype = 0x03;
+        else if (!strcmp( type, "cdrom" ))
+            *devtype = 0x05;
+        else if (!strcmp( type, "scanner" ))
+            *devtype = 0x06;
+        else if (!strcmp( type, "medium_changer" ))
+            *devtype = 0x08;
+        else if (!strcmp( type, "comm" ))
+            *devtype = 0x09;
+        else if (!strcmp( type, "raid" ))
+            *devtype = 0x0C;
+        else
+            *devtype = ~0;
+    }
+
+done:
+    if (type) p_libhal_free_string( type );
+    if (vendor) p_libhal_free_string( vendor );
+    if (model) p_libhal_free_string( model );
+    p_dbus_error_free( &error );
+    return ret;
+}
+
+static void new_ide_device( LibHalContext *ctx, const char *udi )
+{
+    DBusError error;
+    char *parent = NULL;
+    char *type = NULL;
+    char *model = NULL;
+    int host, chan;
+    SCSI_ADDRESS scsi_addr;
+    UCHAR devtype;
+
+    p_dbus_error_init( &error );
+
+    if (!(parent = p_libhal_device_get_property_string( ctx, udi, "info.parent", &error )))
+        goto done;
+    if ((host = p_libhal_device_get_property_int( ctx, parent, "ide.host", &error )) < 0)
+        goto done;
+    if ((chan = p_libhal_device_get_property_int( ctx, parent, "ide.channel", &error )) < 0)
+        goto done;
+
+    if (!(type = p_libhal_device_get_property_string( ctx, udi, "storage.drive_type", &error )))
+        devtype = ~0;
+    else if (!strcmp( type, "disk" ) || !strcmp( type, "floppy" ))
+        devtype = 0x00;
+    else if (!strcmp( type, "tape" ))
+        devtype = 0x01;
+    else if (!strcmp( type, "cdrom" ))
+        devtype = 0x05;
+    else if (!strcmp( type, "raid" ))
+        devtype = 0x0C;
+    else
+        devtype = ~0;
+
+    if (!(model = p_libhal_device_get_property_string( ctx, udi, "storage.model", &error )))
+        p_dbus_error_free( &error );  /* ignore error */
+
+    scsi_addr.PortNumber = host;
+    scsi_addr.PathId = 0;
+    scsi_addr.TargetId = chan;
+    scsi_addr.Lun = 0;
+
+    /* FIXME: Get device filename? WinASPI expects it to be an SG device */
+    create_scsi_entry( &scsi_addr, 255, devtype == 0x05 ? "atapi" : "WINE SCSI", devtype, model, NULL );
+
+done:
+    if (model) p_libhal_free_string( model );
+    if (type) p_libhal_free_string( type );
+    if (parent) p_libhal_free_string( parent );
+    p_dbus_error_free( &error );
+}
+
+#ifdef __linux__
+static void new_sg_device( LibHalContext *ctx, const char *udi )
+{
+    DBusError error;
+    SCSI_ADDRESS scsi_addr;
+    char *unixdev = NULL;
+    char *parent = NULL;
+
+    p_dbus_error_init( &error );
+
+    if (!(unixdev = p_libhal_device_get_property_string( ctx, udi, "scsi_generic.device", &error )))
+        goto done;
+    if (!(parent = p_libhal_device_get_property_string( ctx, udi, "info.parent", &error )))
+        goto done;
+    if (!get_scsi_parameters( ctx, parent, &scsi_addr, NULL, NULL, 0 ))
+        goto done;
+    set_scsi_unix_device_name( &scsi_addr, unixdev );
+
+done:
+    if (unixdev) p_libhal_free_string( unixdev );
+    if (parent) p_libhal_free_string( parent );
+    p_dbus_error_free( &error );
+}
+#endif
+static void new_scsi_device( LibHalContext *ctx, const char *udi )
+{
+    SCSI_ADDRESS scsi_addr;
+    UCHAR devtype;
+    char ident[40];
+
+    if (!get_scsi_parameters( ctx, udi, &scsi_addr, &devtype, ident, sizeof(ident) )) return;
+    /* FIXME: get real controller Id for SCSI */
+    create_scsi_entry( &scsi_addr, 255, "WINE SCSI", devtype, ident, NULL );
+}
+
 /* HAL callback for new device */
 static void new_device( LibHalContext *ctx, const char *udi )
 {
@@ -147,6 +306,12 @@ static void new_device( LibHalContext *ctx, const char *udi )
 
     p_dbus_error_init( &error );
 
+#ifdef __linux__
+    new_sg_device( ctx, udi );
+#endif
+    new_scsi_device( ctx, udi );
+    new_ide_device( ctx, udi );
+
     if (!(device = p_libhal_device_get_property_string( ctx, udi, "block.device", &error )))
         goto done;
 
diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c
index 4e9900f..5e34341 100644
--- a/dlls/mountmgr.sys/mountmgr.c
+++ b/dlls/mountmgr.sys/mountmgr.c
@@ -18,8 +18,16 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <stdio.h>
 #include <stdarg.h>
 #include <unistd.h>
+#include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
+#ifdef HAVE_LINUX_HDREG_H
+# include <linux/hdreg.h>
+#endif
 
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
@@ -33,6 +41,163 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
 
+static const WCHAR scsiW[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0};
+static const WCHAR scsi_portW[] = {'S','c','s','i',' ','P','o','r','t',' ','%','d',0};
+static const WCHAR scsi_busW[] = {'S','c','s','i',' ','B','u','s',' ','%','d',0};
+static const WCHAR target_idW[] = {'T','a','r','g','e','t',' ','I','d',' ','%','d',0};
+static const WCHAR lunW[] = {'L','o','g','i','c','a','l',' ','U','n','i','t',' ','I','d',' ','%','d',0};
+static const WCHAR unixdev_nameW[] = {'U','n','i','x','D','e','v','i','c','e','N','a','m','e',0};
+
+void create_scsi_entry( SCSI_ADDRESS *scsi_addr, UINT init_id, const char *driver, UINT type, const char *model, const char *unixdev )
+{
+    static UCHAR cdrom_no = 0;
+    static UCHAR tape_no = 0;
+    static const WCHAR init_idW[] = {'I','n','i','t','i','a','t','o','r',' ','I','d',' ','%','d',0};
+    static const WCHAR driverW[] = {'D','r','i','v','e','r',0};
+    static const WCHAR bus_scan_timeW[] = {'F','i','r','s','t','B','u','s','S','c','a','n','T','i','m','e','I','n','M','s',0};
+    static const WCHAR typeW[] = {'T','y','p','e',0};
+    static const WCHAR identW[] = {'I','d','e','n','t','i','f','i','e','r',0};
+
+    WCHAR dataW[50];
+    DWORD sizeW;
+    char buffer[40];
+    DWORD value;
+    const char *data;
+    HKEY scsi_key;
+    HKEY port_key;
+    HKEY bus_key;
+    HKEY target_key;
+    HKEY lun_key;
+
+    if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, scsiW, 0, KEY_READ|KEY_WRITE, &scsi_key )) return;
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_portW, scsi_addr->PortNumber );
+    if (RegCreateKeyExW( scsi_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &port_key, NULL )) return;
+
+    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, driver, strlen(driver)+1);
+    RegSetValueExW( port_key, driverW, 0, REG_SZ, (CONST BYTE *)dataW, sizeW );
+    value = 10;
+    RegSetValueExW( port_key, bus_scan_timeW, 0, REG_DWORD, (CONST BYTE *)&value, sizeof(value));
+
+    value = 0;
+    if (strcmp(driver, "atapi") == 0 && unixdev)
+    {
+        static const WCHAR dmaW[] = {'D','M','A','E','n','a','b','l','e','d',0};
+#ifdef HDIO_GET_DMA
+        int fd, dma;
+        
+        fd = open( unixdev, O_RDONLY|O_NONBLOCK );
+        if (fd != -1)
+        {
+            if (ioctl( fd, HDIO_GET_DMA, &dma ) != -1) value = dma;
+            close( fd );
+        }
+#endif
+        RegSetValueExW( port_key, dmaW, 0, REG_DWORD, (CONST BYTE *)&value, sizeof(value) );
+    }
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_busW, scsi_addr->PathId );
+    if (RegCreateKeyExW( port_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &bus_key, NULL )) return;
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), init_idW, init_id );
+    if (RegCreateKeyExW( bus_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &target_key, NULL )) return;
+    RegCloseKey( target_key );
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), target_idW, scsi_addr->TargetId );
+    if (RegCreateKeyExW( bus_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &target_key, NULL )) return;
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), lunW, scsi_addr->Lun );
+    if (RegCreateKeyExW( target_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &lun_key, NULL )) return;
+
+    switch (type)
+    {
+    case 0x00: data = "DiskPeripheral"; break;
+    case 0x01:
+        data = "TapePeripheral";
+        snprintf(buffer, sizeof(buffer), "Tape%d", tape_no++);
+        break;
+    case 0x02: data = "PrinterPeripheral"; break;
+    case 0x04: data = "WormPeripheral"; break;
+    case 0x05:
+        data = "CdRomPeripheral";
+        snprintf(buffer, sizeof(buffer), "Cdrom%d", cdrom_no++);
+        break;
+    case 0x06: data = "ScannerPeripheral"; break;
+    case 0x07: data = "OpticalDiskPeripheral"; break;
+    case 0x08: data = "MediumChangerPeripheral"; break;
+    case 0x09: data = "CommunicationsPeripheral"; break;
+    case 0x0A:
+    case 0x0B: data = "ASCPrePressGraphicsPeripheral"; break;
+    case 0x0C: data = "ArrayPeripheral"; break;
+    case 0x0D: data = "EnclosurePeripheral"; break;
+    case 0x0E: data = "RBCPeripheral"; break;
+    case 0x0F: data = "CardReaderPeripheral"; break;
+    case 0x10: data = "BridgePeripheral"; break;
+    case 0x11:  /* Object-based storage devices */
+    case 0x12:  /* Automation/drive controllers */
+    case 0x15:  /* Reduced-commands MM devices */
+    case 0x03:  /* Processor devices (considered to be "Other" by Windows) */
+    default: data = "OtherPeripheral"; break;
+    }
+    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, data, strlen(data)+1);
+    RegSetValueExW( lun_key, typeW, 0, REG_SZ, (CONST BYTE *)dataW, sizeW );
+
+    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, model, strlen(model)+1);
+    RegSetValueExW( lun_key, identW, 0, REG_SZ, (CONST BYTE *)dataW, sizeW );
+
+    if (type == 0x01 || type == 0x05)
+    {
+        static const WCHAR devnameW[] = {'D','e','v','i','c','e','N','a','m','e',0};
+        RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, buffer, strlen(buffer)+1);
+        RegSetValueExW( lun_key, devnameW, 0, REG_SZ, (CONST BYTE *)dataW, sizeW );
+    }
+
+    if (unixdev)
+    {
+        RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, unixdev, strlen(unixdev)+1);
+        RegSetValueExW( lun_key, unixdev_nameW, 0, REG_SZ, (CONST BYTE *)dataW, sizeW );
+    }
+
+    RegCloseKey( lun_key );
+    RegCloseKey( target_key );
+    RegCloseKey( bus_key );
+    RegCloseKey( port_key );
+    RegCloseKey( scsi_key );
+}
+
+void set_scsi_unix_device_name( SCSI_ADDRESS *scsi_addr, const char *unixdev )
+{
+    WCHAR dataW[50];
+    DWORD sizeW;
+    HKEY scsi_key;
+    HKEY port_key;
+    HKEY bus_key;
+    HKEY target_key;
+    HKEY lun_key;
+
+    if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, scsiW, 0, KEY_READ|KEY_WRITE, &scsi_key )) return;
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_portW, scsi_addr->PortNumber );
+    if (RegCreateKeyExW( scsi_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &port_key, NULL )) return;
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_busW, scsi_addr->PathId );
+    if (RegCreateKeyExW( port_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &bus_key, NULL )) return;
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), target_idW, scsi_addr->TargetId );
+    if (RegCreateKeyExW( bus_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &target_key, NULL )) return;
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), lunW, scsi_addr->Lun );
+    if (RegCreateKeyExW( target_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &lun_key, NULL )) return;
+
+    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &sizeW, unixdev, strlen(unixdev)+1);
+    RegSetValueExW( lun_key, unixdev_nameW, 0, REG_SZ, (CONST BYTE *)dataW, sizeW );
+
+    RegCloseKey( lun_key );
+    RegCloseKey( target_key );
+    RegCloseKey( bus_key );
+    RegCloseKey( port_key );
+    RegCloseKey( scsi_key );
+}
+
+/* mount point functions */
+
 #define MIN_ID_LEN     4
 
 struct mount_point
@@ -405,6 +570,7 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
     static const WCHAR devicemapW[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P',0};
     static const WCHAR parallelW[] = {'P','A','R','A','L','L','E','L',' ','P','O','R','T','S',0};
     static const WCHAR serialW[] = {'S','E','R','I','A','L','C','O','M','M',0};
+    static const WCHAR scsiW[] = {'S','c','s','i',0};
 
     UNICODE_STRING nameW, linkW;
     DEVICE_OBJECT *device;
@@ -437,6 +603,9 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
         if (!RegCreateKeyExW( devicemap_key, serialW, 0, NULL, REG_OPTION_VOLATILE,
                               KEY_ALL_ACCESS, NULL, &hkey, NULL ))
             RegCloseKey( hkey );
+        if (!RegCreateKeyExW( devicemap_key, scsiW, 0, NULL, REG_OPTION_VOLATILE,
+                              KEY_ALL_ACCESS, NULL, &hkey, NULL ))
+            RegCloseKey( hkey );
         RegCloseKey( devicemap_key );
     }
 
diff --git a/dlls/mountmgr.sys/mountmgr.h b/dlls/mountmgr.sys/mountmgr.h
index da1312c..6e4fcfa 100644
--- a/dlls/mountmgr.sys/mountmgr.h
+++ b/dlls/mountmgr.sys/mountmgr.h
@@ -30,6 +30,7 @@
 #include "winternl.h"
 #include "winioctl.h"
 #include "ntddstor.h"
+#include "ntddscsi.h"
 #include "ntddcdrm.h"
 #include "ddk/wdm.h"
 #define WINE_MOUNTMGR_EXTENSIONS
@@ -38,6 +39,9 @@
 extern void initialize_hal(void);
 extern void initialize_diskarbitration(void);
 
+extern void create_scsi_entry( SCSI_ADDRESS *scsi_addr, UINT init_id, const char *driver, UINT type, const char *drive, const char *unixdev );
+extern void set_scsi_unix_device_name( SCSI_ADDRESS *scsi_addr, const char *unixdev );
+
 /* device functions */
 
 enum device_type
-- 
1.7.3.4




More information about the wine-patches mailing list