mountmgr: Populate HKLM\HARDWARE\DEVICEMAP\Scsi here instead of in kernel32.

Signed-off-by: Chip Davis <cdavis@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Chip Davis 2019-11-25 11:40:34 -06:00 committed by Alexandre Julliard
parent 8388ea840f
commit 19549d11a7
8 changed files with 377 additions and 416 deletions

View file

@ -24,7 +24,6 @@ C_SRCS = \
lzexpand.c \
module.c \
nameprep.c \
oldconfig.c \
path.c \
powermgnt.c \
process.c \

View file

@ -1,407 +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
#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, "\\Registry\\Machine\\HARDWARE\\DEVICEMAP", &scsiKey, &disp )) return;
NtClose( scsiKey );
/* Ensure there is Scsi key */
if (create_key( 0, "\\Registry\\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)
{
if (snprintf(cStr, sizeof(cStr), procname_ide_media, dent->d_name) >= sizeof(cStr))
continue;
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 (_strnicmp(cStr, "disk", 4) == 0) nType = DRIVE_FIXED;
if (_strnicmp(cStr, "cdrom", 5) == 0) nType = DRIVE_CDROM;
if (nType == DRIVE_UNKNOWN) continue;
}
if (snprintf(cStr, sizeof(cStr), procname_ide_model, dent->d_name) >= sizeof(cStr))
continue;
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;
}
if (snprintf(cUnixDeviceName, sizeof(cUnixDeviceName), "/dev/%s", dent->d_name) >= sizeof(cUnixDeviceName))
continue;
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 if (strncmp(dev.type, "Scanner", 7) == 0) nType = DRIVE_NO_ROOT_DIR;
else if (strncmp(dev.type, "Printer", 7) == 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, "\\Registry\\Machine\\HARDWARE", &key, &disp )) return;
NtClose( key );
if (disp != REG_OPENED_EXISTING_KEY) create_hardware_branch();
}

View file

@ -214,7 +214,6 @@ void * CDECL __wine_kernel_init(void)
RtlSetUnhandledExceptionFilter( UnhandledExceptionFilter );
LOCALE_Init();
convert_old_config();
set_library_argv( __wine_main_wargv );
if (!params->CurrentDirectory.Handle) chdir("/"); /* avoid locking removable devices */

View file

@ -101,6 +101,7 @@ static DBusConnection *connection;
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); \
@ -318,7 +319,7 @@ static void udisks_new_device( const char *udi )
if (device)
{
if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr );
if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr, NULL );
else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );
}
@ -484,7 +485,7 @@ static void udisks2_add_device( const char *udi, DBusMessageIter *dict, DBusMess
}
if (device)
{
if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr );
if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr, NULL );
else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );
}
}
@ -582,6 +583,178 @@ static DBusHandlerResult udisks_filter( DBusConnection *ctx, DBusMessage *msg, v
#ifdef SONAME_LIBHAL
static BOOL hal_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;
BOOL ret = FALSE;
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 = TRUE;
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 BOOL hal_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;
BOOL ret = FALSE;
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 = TRUE;
scsi_addr->PortNumber = host;
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 hal_new_ide_device( LibHalContext *ctx, const char *udi )
{
SCSI_ADDRESS scsi_addr;
UCHAR devtype;
char ident[40];
if (!hal_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 hal_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 (!hal_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 (!hal_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 hal_new_scsi_device( LibHalContext *ctx, const char *udi )
{
SCSI_ADDRESS scsi_addr;
UCHAR devtype;
char ident[40];
if (!hal_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 hal_new_device( LibHalContext *ctx, const char *udi )
{
@ -596,6 +769,9 @@ static void hal_new_device( LibHalContext *ctx, const char *udi )
p_dbus_error_init( &error );
hal_new_scsi_device( ctx, udi );
hal_new_ide_device( ctx, udi );
if (!(device = p_libhal_device_get_property_string( ctx, udi, "block.device", &error )))
goto done;
@ -619,7 +795,10 @@ static void hal_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 );
hal_set_device_name( ctx, parent, &devname );
/* add property watch for mount point */
p_libhal_device_add_property_watch( ctx, udi, &error );
}

View file

@ -25,7 +25,11 @@
#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
#define NONAMELESSUNION
@ -60,6 +64,12 @@ 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 ports_keyW[] = {'S','o','f','t','w','a','r','e','\\',
'W','i','n','e','\\','P','o','r','t','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
{
@ -686,6 +696,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 )
@ -736,7 +884,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;
@ -812,6 +961,8 @@ found:
if (udi) notify = drive->drive;
if (devname) *devname = volume->device->name;
done:
if (volume) release_volume( volume );
LeaveCriticalSection( &device_section );

View file

@ -89,7 +89,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 );

View file

@ -268,7 +268,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
{
@ -461,6 +461,7 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
static const WCHAR harddiskW[] = {'\\','D','r','i','v','e','r','\\','H','a','r','d','d','i','s','k',0};
static const WCHAR driver_serialW[] = {'\\','D','r','i','v','e','r','\\','S','e','r','i','a','l',0};
static const WCHAR driver_parallelW[] = {'\\','D','r','i','v','e','r','\\','P','a','r','a','l','l','e','l',0};
static const WCHAR devicemapW[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0};
#ifdef _WIN64
static const WCHAR qualified_ports_keyW[] = {'\\','R','E','G','I','S','T','R','Y','\\',
@ -475,6 +476,7 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
UNICODE_STRING nameW, linkW;
DEVICE_OBJECT *device;
HKEY devicemap_key;
NTSTATUS status;
TRACE( "%s\n", debugstr_w(path->Buffer) );
@ -494,6 +496,10 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
RegCreateKeyExW( HKEY_LOCAL_MACHINE, mounted_devicesW, 0, NULL,
REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &mount_key, NULL );
if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE, devicemapW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &devicemap_key, NULL ))
RegCloseKey( devicemap_key );
RtlInitUnicodeString( &nameW, harddiskW );
status = IoCreateDriver( &nameW, harddisk_driver_entry );

View file

@ -27,6 +27,7 @@
#include "winternl.h"
#include "winioctl.h"
#include "ntddstor.h"
#include "ntddscsi.h"
#include "ntddcdrm.h"
#include "ddk/wdm.h"
#define WINE_MOUNTMGR_EXTENSIONS
@ -53,13 +54,46 @@ 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;
extern NTSTATUS WINAPI serial_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *path ) DECLSPEC_HIDDEN;
extern NTSTATUS WINAPI parallel_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 ) DECLSPEC_HIDDEN;
extern void set_scsi_device_name( SCSI_ADDRESS *scsi_addr, const UNICODE_STRING *devname ) DECLSPEC_HIDDEN;
/* mount point functions */
struct mount_point;