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

Charles Davis cdavis at mymail.mines.edu
Sat Jun 11 20:59:52 CDT 2011


Try 8: Gut UnixDeviceName support. N.B. This will break WinASPI.
Try 7: Fix getting the device name for IDE devices.
Try 6: Fix some problems noticed by Vitaliy Margolen.
Try 5: Get the value of "DeviceName" from mountmgr instead of making one up.
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/device.c   |  156 ++++++++++++++++-
 dlls/mountmgr.sys/diskarb.c  |    2 +-
 dlls/mountmgr.sys/hal.c      |  181 +++++++++++++++++++-
 dlls/mountmgr.sys/mountmgr.c |    6 +-
 dlls/mountmgr.sys/mountmgr.h |   36 ++++-
 8 files changed, 376 insertions(+), 413 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 6b8ff99..6916958 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -1158,9 +1158,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/device.c b/dlls/mountmgr.sys/device.c
index 8b91be6..0a98053 100644
--- a/dlls/mountmgr.sys/device.c
+++ b/dlls/mountmgr.sys/device.c
@@ -25,7 +25,14 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <fcntl.h>
 #include <sys/time.h>
+#ifdef HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
+#ifdef HAVE_LINUX_HDREG_H
+# include <linux/hdreg.h>
+#endif
 
 #include "mountmgr.h"
 #include "winreg.h"
@@ -54,6 +61,12 @@ static const WCHAR drive_types[][8] =
 
 static const WCHAR drives_keyW[] = {'S','o','f','t','w','a','r','e','\\',
                                     'W','i','n','e','\\','D','r','i','v','e','s',0};
+static const WCHAR scsi_keyW[] = {'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_port_keyW[] = {'S','c','s','i',' ','P','o','r','t',' ','%','d',0};
+static const WCHAR scsi_bus_keyW[] = {'S','c','s','i',' ','B','u','s',' ','%','d',0};
+static const WCHAR target_id_keyW[] = {'T','a','r','g','e','t',' ','I','d',' ','%','d',0};
+static const WCHAR lun_keyW[] = {'L','o','g','i','c','a','l',' ','U','n','i','t',' ','I','d',' ','%','d',0};
+static const WCHAR devnameW[] = {'D','e','v','i','c','e','N','a','m','e',0};
 
 struct disk_device
 {
@@ -661,6 +674,144 @@ static void create_drive_devices(void)
     RtlFreeHeap( GetProcessHeap(), 0, path );
 }
 
+/* open the "Logical Unit" key for a given SCSI address */
+static HKEY get_scsi_device_lun_key( SCSI_ADDRESS *scsi_addr )
+{
+    WCHAR dataW[50];
+    HKEY scsi_key, port_key, bus_key, target_key, lun_key;
+
+    if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, scsi_keyW, 0, KEY_READ|KEY_WRITE, &scsi_key )) return NULL;
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_port_keyW, scsi_addr->PortNumber );
+    if (RegCreateKeyExW( scsi_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &port_key, NULL )) return NULL;
+    RegCloseKey( scsi_key );
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_bus_keyW, scsi_addr->PathId );
+    if (RegCreateKeyExW( port_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &bus_key, NULL )) return NULL;
+    RegCloseKey( port_key );
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), target_id_keyW, scsi_addr->TargetId );
+    if (RegCreateKeyExW( bus_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &target_key, NULL )) return NULL;
+    RegCloseKey( bus_key );
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), lun_keyW, scsi_addr->Lun );
+    if (RegCreateKeyExW( target_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &lun_key, NULL )) return NULL;
+    RegCloseKey( target_key );
+
+    return lun_key;
+}
+
+/* fill in the "Logical Unit" key for a given SCSI address */
+void create_scsi_entry( SCSI_ADDRESS *scsi_addr, UINT init_id, const char *driver, UINT type, const char *model, const UNICODE_STRING *dev )
+{
+    static UCHAR tape_no = 0;
+    static const WCHAR tapeW[] = {'T','a','p','e','%','d',0};
+    static const WCHAR init_id_keyW[] = {'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_time_scanW[] = {'F','i','r','s','t','B','u','s','T','i','m','e','S','c','a','n','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;
+    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, scsi_keyW, 0, KEY_READ|KEY_WRITE, &scsi_key )) return;
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_port_keyW, scsi_addr->PortNumber );
+    if (RegCreateKeyExW( scsi_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &port_key, NULL )) return;
+    RegCloseKey( scsi_key );
+
+    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_time_scanW, 0, REG_DWORD, (CONST BYTE *)&value, sizeof(value));
+
+    value = 0;
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), scsi_bus_keyW, scsi_addr->PathId );
+    if (RegCreateKeyExW( port_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &bus_key, NULL )) return;
+    RegCloseKey( port_key );
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), init_id_keyW, 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_id_keyW, scsi_addr->TargetId );
+    if (RegCreateKeyExW( bus_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &target_key, NULL )) return;
+    RegCloseKey( bus_key );
+
+    snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), lun_keyW, scsi_addr->Lun );
+    if (RegCreateKeyExW( target_key, dataW, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &lun_key, NULL )) return;
+    RegCloseKey( target_key );
+
+    switch (type)
+    {
+    case SCSI_DISK_PERIPHERAL:              data = "DiskPeripheral"; break;
+    case SCSI_TAPE_PERIPHERAL:              data = "TapePeripheral"; break;
+    case SCSI_PRINTER_PERIPHERAL:           data = "PrinterPeripheral"; break;
+    case SCSI_WORM_PERIPHERAL:              data = "WormPeripheral"; break;
+    case SCSI_CDROM_PERIPHERAL:             data = "CdRomPeripheral"; break;
+    case SCSI_SCANNER_PERIPHERAL:           data = "ScannerPeripheral"; break;
+    case SCSI_OPTICAL_DISK_PERIPHERAL:      data = "OpticalDiskPeripheral"; break;
+    case SCSI_MEDIUM_CHANGER_PERIPHERAL:    data = "MediumChangerPeripheral"; break;
+    case SCSI_COMMS_PERIPHERAL:             data = "CommunicationsPeripheral"; break;
+    case SCSI_ASC_GRAPHICS_PERIPHERAL:
+    case SCSI_ASC_GRAPHICS2_PERIPHERAL:     data = "ASCPrePressGraphicsPeripheral"; break;
+    case SCSI_ARRAY_PERIPHERAL:             data = "ArrayPeripheral"; break;
+    case SCSI_ENCLOSURE_PERIPHERAL:         data = "EnclosurePeripheral"; break;
+    case SCSI_REDUCED_DISK_PERIPHERAL:      data = "RBCPeripheral"; break;
+    case SCSI_CARD_READER_PERIPHERAL:       data = "CardReaderPeripheral"; break;
+    case SCSI_BRIDGE_PERIPHERAL:            data = "BridgePeripheral"; break;
+    case SCSI_OBJECT_STORAGE_PERIPHERAL:    /* Object-based storage devices */
+    case SCSI_DRIVE_CONTROLLER_PERIPHERAL:  /* Automation/drive controllers */
+    case SCSI_REDUCED_CDROM_PERIPHERAL:     /* Reduced-commands MM devices */
+    case SCSI_PROCESSOR_PERIPHERAL:         /* 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 (dev)
+    {
+        WCHAR *buffer = memchrW( dev->Buffer+1, '\\', dev->Length )+1;
+        ULONG length = dev->Length - (buffer - dev->Buffer)*sizeof(WCHAR);
+        RegSetValueExW( lun_key, devnameW, 0, REG_SZ, (CONST BYTE *)buffer, length );
+    }
+    else if (type == SCSI_TAPE_PERIPHERAL)
+    {
+        snprintfW( dataW, sizeof(dataW)/sizeof(*dataW), tapeW, tape_no++ );
+        RegSetValueExW( lun_key, devnameW, 0, REG_SZ, (CONST BYTE *)dataW, strlenW( dataW ) );
+    }
+
+    RegCloseKey( lun_key );
+}
+
+/* set the "DeviceName" for a given SCSI address */
+void set_scsi_device_name( SCSI_ADDRESS *scsi_addr, const UNICODE_STRING *dev )
+{
+    HKEY lun_key;
+    WCHAR *buffer;
+    ULONG length;
+
+    lun_key = get_scsi_device_lun_key( scsi_addr );
+    buffer = memchrW( dev->Buffer+1, '\\', dev->Length )+1;
+    length = dev->Length - (buffer - dev->Buffer)*sizeof(WCHAR);
+    RegSetValueExW( lun_key, devnameW, 0, REG_SZ, (CONST BYTE *)buffer, length );
+
+    RegCloseKey( lun_key );
+}
+
+
 /* create a new disk volume */
 NTSTATUS add_volume( const char *udi, const char *device, const char *mount_point,
                      enum device_type type, const GUID *guid )
@@ -711,7 +862,8 @@ NTSTATUS remove_volume( const char *udi )
 
 /* create a new dos drive */
 NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
-                         const char *mount_point, enum device_type type, const GUID *guid )
+                         const char *mount_point, enum device_type type, const GUID *guid,
+                         UNICODE_STRING *devname )
 {
     char *path, *p;
     HKEY hkey;
@@ -787,6 +939,8 @@ found:
 
     if (udi) notify = drive->drive;
 
+    if (devname) *devname = volume->device->name;
+
 done:
     if (volume) release_volume( volume );
     LeaveCriticalSection( &device_section );
diff --git a/dlls/mountmgr.sys/diskarb.c b/dlls/mountmgr.sys/diskarb.c
index d3912ca..9e3cd28 100644
--- a/dlls/mountmgr.sys/diskarb.c
+++ b/dlls/mountmgr.sys/diskarb.c
@@ -79,7 +79,7 @@ static void appeared_callback( DADiskRef disk, void *context )
            device, mount_point, wine_dbgstr_guid(guid_ptr) );
 
     if ((ref = CFDictionaryGetValue( dict, CFSTR("DAMediaRemovable") )) && CFBooleanGetValue( ref ))
-        add_dos_device( -1, device, device, mount_point, type, guid_ptr );
+        add_dos_device( -1, device, device, mount_point, type, guid_ptr, NULL );
     else
         if (guid_ptr) add_volume( device, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );
 
diff --git a/dlls/mountmgr.sys/hal.c b/dlls/mountmgr.sys/hal.c
index 82a70e9..9411199 100644
--- a/dlls/mountmgr.sys/hal.c
+++ b/dlls/mountmgr.sys/hal.c
@@ -60,6 +60,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
     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_int); \
     DO_FUNC(libhal_device_get_property_string); \
     DO_FUNC(libhal_device_add_property_watch); \
     DO_FUNC(libhal_device_remove_property_watch); \
@@ -133,6 +134,178 @@ static GUID *parse_uuid( GUID *guid, const char *str )
     return NULL;
 }
 
+static int get_ide_parameters( LibHalContext *ctx, const char *udi, SCSI_ADDRESS *scsi_addr, UCHAR *devtype, char *ident, size_t ident_size )
+{
+    DBusError error;
+    char *parent = NULL;
+    char *type = NULL;
+    char *model = NULL;
+    int host, chan;
+    int ret = 0;
+
+    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;
+
+    ret = 1;
+
+    if (devtype)
+    {
+        if (!(type = p_libhal_device_get_property_string( ctx, udi, "storage.drive_type", &error )))
+            *devtype = SCSI_UNKNOWN_PERIPHERAL;
+        else if (!strcmp( type, "disk" ) || !strcmp( type, "floppy" ))
+            *devtype = SCSI_DISK_PERIPHERAL;
+        else if (!strcmp( type, "tape" ))
+            *devtype = SCSI_TAPE_PERIPHERAL;
+        else if (!strcmp( type, "cdrom" ))
+            *devtype = SCSI_CDROM_PERIPHERAL;
+        else if (!strcmp( type, "raid" ))
+            *devtype = SCSI_ARRAY_PERIPHERAL;
+        else
+            *devtype = SCSI_UNKNOWN_PERIPHERAL;
+    }
+
+    if (ident)
+    {
+        if (!(model = p_libhal_device_get_property_string( ctx, udi, "storage.model", &error )))
+            p_dbus_error_free( &error );  /* ignore error */
+        else
+            lstrcpynA( ident, model, ident_size );
+    }
+
+    scsi_addr->PortNumber = host;
+    scsi_addr->PathId = 0;
+    scsi_addr->TargetId = chan;
+    scsi_addr->Lun = 0;
+
+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 );
+    return ret;
+}
+
+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, "%-8s%-16s", vendor ? vendor : "WINE", model ? model : "SCSI" );
+    }
+
+    if (devtype)
+    {
+        if (!(type = p_libhal_device_get_property_string( ctx, udi, "scsi.type", &error )))
+        {
+            *devtype = SCSI_UNKNOWN_PERIPHERAL;
+            goto done;
+        }
+        if (!strcmp( type, "disk" ))
+            *devtype = SCSI_DISK_PERIPHERAL;
+        else if (!strcmp( type, "tape" ))
+            *devtype = SCSI_TAPE_PERIPHERAL;
+        else if (!strcmp( type, "printer" ))
+            *devtype = SCSI_PRINTER_PERIPHERAL;
+        else if (!strcmp( type, "processor" ))
+            *devtype = SCSI_PROCESSOR_PERIPHERAL;
+        else if (!strcmp( type, "cdrom" ))
+            *devtype = SCSI_CDROM_PERIPHERAL;
+        else if (!strcmp( type, "scanner" ))
+            *devtype = SCSI_SCANNER_PERIPHERAL;
+        else if (!strcmp( type, "medium_changer" ))
+            *devtype = SCSI_MEDIUM_CHANGER_PERIPHERAL;
+        else if (!strcmp( type, "comm" ))
+            *devtype = SCSI_COMMS_PERIPHERAL;
+        else if (!strcmp( type, "raid" ))
+            *devtype = SCSI_ARRAY_PERIPHERAL;
+        else
+            *devtype = SCSI_UNKNOWN_PERIPHERAL;
+    }
+
+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 )
+{
+    SCSI_ADDRESS scsi_addr;
+    UCHAR devtype;
+    char ident[40];
+
+    if (!get_ide_parameters( ctx, udi, &scsi_addr, &devtype, ident, sizeof(ident) )) return;
+    create_scsi_entry( &scsi_addr, 255, devtype == SCSI_CDROM_PERIPHERAL ? "atapi" : "WINE SCSI", devtype, ident, NULL );
+}
+
+static void set_device_name( LibHalContext *ctx, const char *udi, const UNICODE_STRING *devname )
+{
+    DBusError error;
+    SCSI_ADDRESS scsi_addr;
+    char *parent = NULL;
+
+    p_dbus_error_init( &error );
+
+    if (!get_ide_parameters( ctx, udi, &scsi_addr, NULL, NULL, 0 ))
+    {
+        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_device_name( &scsi_addr, devname );
+
+done:
+    if (parent) p_libhal_free_string( parent );
+    p_dbus_error_free( &error );
+}
+
+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 +320,9 @@ static void new_device( LibHalContext *ctx, const char *udi )
 
     p_dbus_error_init( &error );
 
+    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;
 
@@ -170,7 +346,10 @@ static void new_device( LibHalContext *ctx, const char *udi )
 
     if (p_libhal_device_get_property_bool( ctx, parent, "storage.removable", &error ))
     {
-        add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr );
+        UNICODE_STRING devname;
+
+        add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr, &devname );
+        set_device_name( ctx, parent, &devname );
         /* add property watch for mount point */
         p_libhal_device_add_property_watch( ctx, udi, &error );
     }
diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c
index 4e9900f..c80e6f2 100644
--- a/dlls/mountmgr.sys/mountmgr.c
+++ b/dlls/mountmgr.sys/mountmgr.c
@@ -261,7 +261,7 @@ static NTSTATUS define_unix_drive( const void *in_buff, SIZE_T insize )
         case DRIVE_RAMDISK:   type = DEVICE_RAMDISK; break;
         case DRIVE_FIXED:     type = DEVICE_HARDDISK_VOL; break;
         }
-        return add_dos_device( letter - 'a', NULL, device, mount_point, type, NULL );
+        return add_dos_device( letter - 'a', NULL, device, mount_point, type, NULL, NULL );
     }
     else
     {
@@ -405,6 +405,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 +438,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 a47a3e3..9a2b7a4 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
@@ -56,11 +57,44 @@ extern NTSTATUS add_volume( const char *udi, const char *device, const char *mou
                             enum device_type type, const GUID *guid ) DECLSPEC_HIDDEN;
 extern NTSTATUS remove_volume( const char *udi ) DECLSPEC_HIDDEN;
 extern NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
-                                const char *mount_point, enum device_type type, const GUID *guid ) DECLSPEC_HIDDEN;
+                                const char *mount_point, enum device_type type, const GUID *guid,
+                                UNICODE_STRING *devname ) DECLSPEC_HIDDEN;
 extern NTSTATUS remove_dos_device( int letter, const char *udi ) DECLSPEC_HIDDEN;
 extern NTSTATUS query_dos_device( int letter, enum device_type *type, char **device, char **mount_point ) DECLSPEC_HIDDEN;
 extern NTSTATUS WINAPI harddisk_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) DECLSPEC_HIDDEN;
 
+/* SCSI entry functions */
+
+enum scsi_device_type
+{
+    SCSI_DISK_PERIPHERAL = 0x00,
+    SCSI_TAPE_PERIPHERAL = 0x01,
+    SCSI_PRINTER_PERIPHERAL = 0x02,
+    SCSI_PROCESSOR_PERIPHERAL = 0x03,
+    SCSI_WORM_PERIPHERAL = 0x04,
+    SCSI_CDROM_PERIPHERAL = 0x05,
+    SCSI_SCANNER_PERIPHERAL = 0x06,
+    SCSI_OPTICAL_DISK_PERIPHERAL = 0x07,
+    SCSI_MEDIUM_CHANGER_PERIPHERAL = 0x08,
+    SCSI_COMMS_PERIPHERAL = 0x09,
+    SCSI_ASC_GRAPHICS_PERIPHERAL = 0x0A,
+    SCSI_ASC_GRAPHICS2_PERIPHERAL = 0x0B,
+    SCSI_ARRAY_PERIPHERAL = 0x0C,
+    SCSI_ENCLOSURE_PERIPHERAL = 0x0D,
+    SCSI_REDUCED_DISK_PERIPHERAL = 0x0E,
+    SCSI_CARD_READER_PERIPHERAL = 0x0F,
+    SCSI_BRIDGE_PERIPHERAL = 0x10,
+    SCSI_OBJECT_STORAGE_PERIPHERAL = 0x11,
+    SCSI_DRIVE_CONTROLLER_PERIPHERAL = 0x12,
+    SCSI_REDUCED_CDROM_PERIPHERAL = 0x15,
+    SCSI_UNKNOWN_PERIPHERAL = ~0
+};
+
+extern void create_scsi_entry( SCSI_ADDRESS *scsi_addr, UINT init_id,
+                               const char *driver, UINT type, const char *drive,
+                               const UNICODE_STRING *devname );
+extern void set_scsi_device_name( SCSI_ADDRESS *scsi_addr, const UNICODE_STRING *devname );
+
 /* mount point functions */
 
 struct mount_point;
-- 
1.7.3.4




More information about the wine-patches mailing list