[PATCH] mountmgr: Create registry entries for serial ports.

Alex Henrie alexhenrie24 at gmail.com
Mon Apr 3 00:08:43 CDT 2017


Cc: André Hentschel <nerv at dawncrow.de>

Fixes https://bugs.winehq.org/show_bug.cgi?id=11811

This patch uses CreateFile to figure out whether or not the serial port
exists. This avoids duplicating the logic in the ntdll functions
get_dos_device and get_default_com_device.

I thought about creating registry entries for 256 serial ports
regardless of whether they exist, but TI Connect crashes if the computer
has more than 20 serial ports.

Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
 dlls/mountmgr.sys/mountmgr.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/dlls/mountmgr.sys/mountmgr.c b/dlls/mountmgr.sys/mountmgr.c
index 10286dc2de..da0b962c86 100644
--- a/dlls/mountmgr.sys/mountmgr.c
+++ b/dlls/mountmgr.sys/mountmgr.c
@@ -422,11 +422,14 @@ 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 comW[] = {'\\','\\','.','\\','C','O','M','%','d',0};
 
     UNICODE_STRING nameW, linkW;
     DEVICE_OBJECT *device;
     NTSTATUS status;
     HKEY hkey, devicemap_key;
+    WCHAR pathW[16];
+    int i;
 
     TRACE( "%s\n", debugstr_w(path->Buffer) );
 
@@ -453,7 +456,21 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
             RegCloseKey( hkey );
         if (!RegCreateKeyExW( devicemap_key, serialW, 0, NULL, REG_OPTION_VOLATILE,
                               KEY_ALL_ACCESS, NULL, &hkey, NULL ))
+        {
+            /* create a registry entry for each serial port */
+            for (i = 1; i <= 256; i++)
+            {
+                sprintfW( pathW, comW, i );
+                device = CreateFileW( pathW, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
+                if (device == INVALID_HANDLE_VALUE)
+                    break;
+
+                CloseHandle( device );
+                RegSetValueExW( hkey, pathW + 4, 0, REG_SZ, (BYTE *)(pathW + 4),
+                                (strlenW( pathW + 4 ) + 1) * sizeof(WCHAR) );
+            }
             RegCloseKey( hkey );
+        }
         RegCloseKey( devicemap_key );
     }
 
-- 
2.12.0




More information about the wine-patches mailing list