[PATCH] ntdll: improve character device type detection on FreeBSD and macOS

Damjan Jovanovic damjan.jov at gmail.com
Sun Nov 8 11:41:09 CST 2020


configure and include/config.h.in need to be regenerated.
macOS wasn't tested.

Signed-off-by: Damjan Jovanovic <damjan.jov at gmail.com>
---
 configure.ac           |  2 +-
 dlls/ntdll/unix/file.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
-------------- next part --------------
diff --git a/configure.ac b/configure.ac
index 923d5e3b0f3..666219f5f36 100644
--- a/configure.ac
+++ b/configure.ac
@@ -540,7 +540,7 @@ AC_HEADER_STAT()
 
 dnl **** Checks for headers that depend on other ones ****
 
-AC_CHECK_HEADERS([sys/mount.h sys/statfs.h sys/user.h sys/vfs.h],,,
+AC_CHECK_HEADERS([sys/conf.h sys/mount.h sys/statfs.h sys/user.h sys/vfs.h],,,
     [#include <sys/types.h>
      #ifdef HAVE_SYS_PARAM_H
      # include <sys/param.h>
diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c
index d12a3ffb119..f039c3488a6 100644
--- a/dlls/ntdll/unix/file.c
+++ b/dlls/ntdll/unix/file.c
@@ -99,6 +99,9 @@
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
+#ifdef HAVE_SYS_CONF_H
+#include <sys/conf.h>
+#endif
 #ifdef HAVE_SYS_MOUNT_H
 #include <sys/mount.h>
 #endif
@@ -6048,6 +6051,10 @@ static NTSTATUS get_device_info( int fd, FILE_FS_DEVICE_INFORMATION *info )
     if (fstat( fd, &st ) < 0) return errno_to_status( errno );
     if (S_ISCHR( st.st_mode ))
     {
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+        int d_type;
+#endif
+
         info->DeviceType = FILE_DEVICE_UNKNOWN;
 #ifdef linux
         switch(major(st.st_rdev))
@@ -6065,6 +6072,28 @@ static NTSTATUS get_device_info( int fd, FILE_FS_DEVICE_INFORMATION *info )
             info->DeviceType = FILE_DEVICE_TAPE;
             break;
         }
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
+        if (ioctl(fd, FIODTYPE, &d_type) == 0)
+        {
+            switch(d_type)
+            {
+            case D_TAPE:
+                info->DeviceType = FILE_DEVICE_TAPE;
+                break;
+            case D_DISK:
+                info->DeviceType = FILE_DEVICE_DISK;
+                break;
+            case D_TTY:
+                info->DeviceType = FILE_DEVICE_SERIAL_PORT;
+                break;
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+            case D_MEM:
+                info->DeviceType = FILE_DEVICE_NULL;
+                break;
+#endif
+            }
+            /* no special d_type for parallel ports */
+        }
 #endif
     }
     else if (S_ISBLK( st.st_mode ))


More information about the wine-devel mailing list