Index: sys/kern/vfs_vnops.c =================================================================== RCS file: /cvsroot/src/sys/kern/vfs_vnops.c,v retrieving revision 1.195 diff -u -u -r1.195 vfs_vnops.c --- sys/kern/vfs_vnops.c 30 Mar 2017 09:13:37 -0000 1.195 +++ sys/kern/vfs_vnops.c 9 Nov 2017 18:13:46 -0000 @@ -299,6 +299,9 @@ if ((fflags & O_DIRECTORY) != 0 && vp->v_type != VDIR) return ENOTDIR; + if ((fflags & O_REGULAR) != 0 && vp->v_type != VREG) + return EFTYPE; + if ((fflags & FREAD) != 0) { permbits = VREAD; } Index: sys/sys/fcntl.h =================================================================== RCS file: /cvsroot/src/sys/sys/fcntl.h,v retrieving revision 1.48 diff -u -u -r1.48 fcntl.h --- sys/sys/fcntl.h 10 Jan 2017 23:08:13 -0000 1.48 +++ sys/sys/fcntl.h 9 Nov 2017 18:13:46 -0000 @@ -121,6 +121,7 @@ #if defined(_NETBSD_SOURCE) #define O_NOSIGPIPE 0x01000000 /* don't deliver sigpipe */ #endif +#define O_REGULAR 0x02000000 /* fail if not a regular file */ #ifdef _KERNEL /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ @@ -131,7 +132,7 @@ #define O_MASK (O_ACCMODE|O_NONBLOCK|O_APPEND|O_SHLOCK|O_EXLOCK|\ O_ASYNC|O_SYNC|O_CREAT|O_TRUNC|O_EXCL|O_DSYNC|\ O_RSYNC|O_NOCTTY|O_ALT_IO|O_NOFOLLOW|O_DIRECT|\ - O_DIRECTORY|O_CLOEXEC|O_NOSIGPIPE) + O_DIRECTORY|O_CLOEXEC|O_NOSIGPIPE|O_REGULAR) #define FMARK 0x00001000 /* mark during gc() */ #define FDEFER 0x00002000 /* defer for next gc pass */ Index: lib/libc/stdio/fdopen.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fdopen.c,v retrieving revision 1.17 diff -u -u -r1.17 fdopen.c --- lib/libc/stdio/fdopen.c 10 Jan 2017 17:00:58 -0000 1.17 +++ lib/libc/stdio/fdopen.c 9 Nov 2017 18:13:51 -0000 @@ -92,7 +92,7 @@ return NULL; } - if (oflags & O_NONBLOCK) { + if (oflags & O_REGULAR) { struct stat st; if (fstat(fd, &st) == -1) { return NULL; Index: lib/libc/stdio/flags.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/flags.c,v retrieving revision 1.18 diff -u -u -r1.18 flags.c --- lib/libc/stdio/flags.c 4 Nov 2017 02:49:55 -0000 1.18 +++ lib/libc/stdio/flags.c 9 Nov 2017 18:13:51 -0000 @@ -105,7 +105,7 @@ o |= O_CLOEXEC; break; case 'f': - o |= O_NONBLOCK; + o |= O_REGULAR; break; case 'l': o |= O_NOFOLLOW; Index: lib/libc/stdio/fopen.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/fopen.c,v retrieving revision 1.16 diff -u -u -r1.16 fopen.c --- lib/libc/stdio/fopen.c 4 Nov 2017 07:26:35 -0000 1.16 +++ lib/libc/stdio/fopen.c 9 Nov 2017 18:13:51 -0000 @@ -66,20 +66,6 @@ return NULL; if ((f = open(file, oflags, DEFFILEMODE)) < 0) goto release; - if (oflags & O_NONBLOCK) { - struct stat st; - if (fstat(f, &st) == -1) { - int sverrno = errno; - (void)close(f); - errno = sverrno; - goto release; - } - if (!S_ISREG(st.st_mode)) { - (void)close(f); - errno = EFTYPE; - goto release; - } - } /* * File descriptors are a full int, but _file is only a short. * If we get a valid file descriptor that is greater or equal to Index: lib/libc/stdio/freopen.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdio/freopen.c,v retrieving revision 1.19 diff -u -u -r1.19 freopen.c --- lib/libc/stdio/freopen.c 27 Mar 2012 15:05:42 -0000 1.19 +++ lib/libc/stdio/freopen.c 9 Nov 2017 18:13:51 -0000 @@ -141,21 +141,6 @@ return NULL; } - if (oflags & O_NONBLOCK) { - struct stat st; - if (fstat(f, &st) == -1) { - sverrno = errno; - (void)close(f); - errno = sverrno; - return NULL; - } - if (!S_ISREG(st.st_mode)) { - (void)close(f); - errno = EFTYPE; - return NULL; - } - } - /* * If reopening something that was open before on a real file, try * to maintain the descriptor. Various C library routines (perror) Index: lib/libc/sys/open.2 =================================================================== RCS file: /cvsroot/src/lib/libc/sys/open.2,v retrieving revision 1.57 diff -u -u -r1.57 open.2 --- lib/libc/sys/open.2 14 May 2017 12:30:37 -0000 1.57 +++ lib/libc/sys/open.2 9 Nov 2017 18:13:52 -0000 @@ -29,7 +29,7 @@ .\" .\" @(#)open.2 8.2 (Berkeley) 11/16/93 .\" -.Dd July 29, 2013 +.Dd November 9, 2017 .Dt OPEN 2 .Os .Sh NAME @@ -188,6 +188,8 @@ element of the request must meet the above alignment constraints. .It Dv O_DIRECTORY Fail if the file is not a directory. +.It Dv O_REGULAR +Fail if the path does not refer to a regular file. .It Dv O_ASYNC Enable the .Dv SIGIO