Fix ntdll-Serial_Port_Detection patchset

This commit is contained in:
Alistair Leslie-Hughes 2021-11-30 12:33:31 +11:00
parent 65ca056d29
commit 2056903cdf

View File

@ -1,4 +1,4 @@
From e5652dcb913e0bf956c5ed4b0d1e1755c58714c5 Mon Sep 17 00:00:00 2001
From 57842b80ce2211e1ec909062b381ccd099ad5fb4 Mon Sep 17 00:00:00 2001
From: Alex Henrie <alexhenrie24@gmail.com>
Date: Tue, 29 Dec 2015 00:48:02 -0700
Subject: [PATCH] mountmgr.sys: Do a device check before returning a default
@ -6,48 +6,51 @@ Subject: [PATCH] mountmgr.sys: Do a device check before returning a default
Fixes https://bugs.winehq.org/show_bug.cgi?id=39793
---
dlls/mountmgr.sys/device.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
dlls/mountmgr.sys/device.c | 2 +-
dlls/mountmgr.sys/unixlib.c | 24 ++++++++++++++++++++++++
dlls/mountmgr.sys/unixlib.h | 1 +
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/dlls/mountmgr.sys/device.c b/dlls/mountmgr.sys/device.c
index 332f390550d..666bdb12e6b 100644
index 332f390550d..6343807e14d 100644
--- a/dlls/mountmgr.sys/device.c
+++ b/dlls/mountmgr.sys/device.c
@@ -23,6 +23,11 @@
#include <stdarg.h>
#include <stdio.h>
@@ -1916,7 +1916,7 @@ static BOOL create_port_device( DRIVER_OBJECT *driver, int n, const char *unix_p
UNICODE_STRING nt_name, symlink_name, default_name;
DEVICE_OBJECT *dev_obj;
NTSTATUS status;
- struct set_dosdev_symlink_params params = { dosdevices_path, unix_path };
+ struct set_dosdev_symlink_params params = { dosdevices_path, unix_path, driver == serial_driver };
/* create DOS device */
if (MOUNTMGR_CALL( set_dosdev_symlink, &params )) return FALSE;
diff --git a/dlls/mountmgr.sys/unixlib.c b/dlls/mountmgr.sys/unixlib.c
index 52a3fce66d6..de1e0445a5c 100644
--- a/dlls/mountmgr.sys/unixlib.c
+++ b/dlls/mountmgr.sys/unixlib.c
@@ -31,6 +31,9 @@
#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <sys/stat.h>
#include <unistd.h>
+#ifdef HAVE_TERMIOS_H
+# include <termios.h>
+#endif
#ifdef HAVE_SYS_STATFS_H
# include <sys/statfs.h>
#endif
@@ -1918,9 +1923,6 @@ static BOOL create_port_device( DRIVER_OBJECT *driver, int n, const char *unix_p
NTSTATUS status;
struct set_dosdev_symlink_params params = { dosdevices_path, unix_path };
- /* create DOS device */
- if (MOUNTMGR_CALL( set_dosdev_symlink, &params )) return FALSE;
-
if (driver == serial_driver)
{
dos_name_format = L"COM%u";
@@ -1940,6 +1942,30 @@ static BOOL create_port_device( DRIVER_OBJECT *driver, int n, const char *unix_p
#include "unixlib.h"
swprintf( dos_name, ARRAY_SIZE(dos_name), dos_name_format, n );
@@ -253,6 +256,27 @@ static NTSTATUS set_dosdev_symlink( void *args )
char *path;
NTSTATUS status = STATUS_SUCCESS;
+#ifdef linux
+ /* Serial port device files almost always exist on Linux even if the corresponding serial
+ * ports don't exist. Do a basic functionality check before advertising a serial port. */
+ if (driver == serial_driver)
+ if (params->serial)
+ {
+ struct termios tios;
+ int fd;
+
+ if ((fd = open( unix_path, O_RDONLY )) == -1)
+ if ((fd = open( params->dest, O_RDONLY )) == -1)
+ return FALSE;
+
+ if (tcgetattr( fd, &tios ) == -1)
@ -60,12 +63,21 @@ index 332f390550d..666bdb12e6b 100644
+ }
+#endif
+
+ /* create DOS device */
+ if (MOUNTMGR_CALL( set_dosdev_symlink, &params )) return FALSE;
+
/* create NT device */
swprintf( nt_buffer, ARRAY_SIZE(nt_buffer), nt_name_format, n - 1 );
RtlInitUnicodeString( &nt_name, nt_buffer );
if (!(path = get_dosdevices_path( params->dev ))) return STATUS_NO_MEMORY;
if (params->dest && params->dest[0])
diff --git a/dlls/mountmgr.sys/unixlib.h b/dlls/mountmgr.sys/unixlib.h
index e7846a764da..72f60f200b8 100644
--- a/dlls/mountmgr.sys/unixlib.h
+++ b/dlls/mountmgr.sys/unixlib.h
@@ -75,6 +75,7 @@ struct set_dosdev_symlink_params
{
const char *dev;
const char *dest;
+ BOOL serial;
};
struct get_volume_dos_devices_params
--
2.33.0