[Wine-devel] kernel32: Create serial device entries in registry

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Чт Авг 14 17:17:15 MSD 2008


----------- следующая часть -----------
From 1100e7fbf217ef2213c7460c0822539c243aec76 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 13 Aug 2008 14:39:21 +0400
Subject: [PATCH] kernel32: Create serial device entries in registry

---
 dlls/kernel32/oldconfig.c |   68 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 67 insertions(+), 1 deletions(-)

diff --git a/dlls/kernel32/oldconfig.c b/dlls/kernel32/oldconfig.c
index 09e407b..717c2f4 100644
--- a/dlls/kernel32/oldconfig.c
+++ b/dlls/kernel32/oldconfig.c
@@ -28,6 +28,7 @@
 #include <sys/types.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <errno.h>
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
@@ -329,6 +330,45 @@ static int SCSI_getprocentry( FILE * procfile, struct LinuxProcScsiDevice * dev
 }
 
 
+/* create serial device entry in registry */
+static void create_serialcomm_entry( int dev_num )
+{
+    HANDLE serialKey;
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING nameW;
+    char buffer[40];
+    WCHAR dataW[20];
+    DWORD lenW;
+
+    attr.Length = sizeof(attr);
+    attr.RootDirectory = 0;
+    attr.ObjectName = &nameW;
+    attr.Attributes = 0;
+    attr.SecurityDescriptor = NULL;
+    attr.SecurityQualityOfService = NULL;
+
+    if (!RtlCreateUnicodeStringFromAsciiz( &nameW,
+        "Machine\\HARDWARE\\DEVICEMAP\\SERIALCOMM" ) ||
+        NtCreateKey( &serialKey, KEY_ALL_ACCESS, &attr, 0,
+                     NULL, REG_OPTION_VOLATILE, NULL ))
+    {
+        ERR( "Cannot create DEVICEMAP\\SERIALCOMM registry key\n" );
+        return;
+    }
+    RtlFreeUnicodeString( &nameW );
+
+    /* Names like \Device\Serial0 are used on WinXP/2003 */
+    snprintf( buffer, sizeof(buffer), "\\Device\\Serial%d", dev_num - 1 );
+    RtlCreateUnicodeStringFromAsciiz( &nameW, buffer );
+    snprintf( buffer, sizeof(buffer), "COM%d", dev_num );
+    RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &lenW, buffer, strlen(buffer) );
+    NtSetValueKey( serialKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW );
+    RtlFreeUnicodeString( &nameW );
+
+    NtClose( serialKey );
+}
+
+
 /* create the hardware registry branch */
 static void create_hardware_branch(void)
 {
@@ -337,15 +377,18 @@ static void create_hardware_branch(void)
     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";
+    const char *config_dir = wine_get_config_dir();
     DIR *idedir;
     struct dirent *dent = NULL;
     FILE *procfile = NULL;
     char cStr[40], cDevModel[40], cUnixDeviceName[40], read1[10] = "\0", read2[10] = "\0";
+    char *com;
     SCSI_ADDRESS scsi_addr;
     UINT nType;
     struct LinuxProcScsiDevice dev;
-    int result = 0, nSgNumber = 0;
+    int result = 0, nSgNumber = 0, dev_num = 1, fd;
     UCHAR uFirstSCSIPort = 0;
+    size_t len;
 
     /* Enumerate all ide devices first */
     idedir = opendir("/proc/ide");
@@ -449,6 +492,29 @@ static void create_hardware_branch(void)
     if( result != EOF )
         WARN("Incorrect %s format\n", procname_scsi);
     fclose( procfile );
+
+    /* Enumerate serial devices */
+    len = strlen( config_dir ) + sizeof("/dosdevices/com") + 20;
+    com = HeapAlloc( GetProcessHeap(), 0, len );
+    if (NULL == com)
+        return;
+    strcpy( com, config_dir );
+    strcat( com, "/dosdevices/com" );
+    len = strlen( com );
+    for (;;)
+    {
+        sprintf( cStr, "%d", dev_num );
+        strcat( com, cStr );
+        fd = open( com, 0 );
+        if (fd >= 0)
+            close( fd );
+        else
+            if (EACCES != errno)
+                break;
+        create_serialcomm_entry( dev_num++ );
+        com[len] = 0;
+    }
+    HeapFree( GetProcessHeap(), 0, com );
 }
 
 
-- 
1.5.4.5.GIT



Подробная информация о списке рассылки Wine-devel