mmap() of a non-file

Tony Finch dot at dotat.at
Mon Apr 10 16:23:49 UTC 2006


If you try to mmap() an fd that isn't a normal file, FreeBSD returns
EINVAL whereas POSIX says it should return ENODEV - at least according
to my reading of
http://www.opengroup.org/onlinepubs/009695399/functions/mmap.html

Index: sys/vm/vm_mmap.c
===================================================================
RCS file: /work/FreeBSD/cvs/src/sys/vm/vm_mmap.c,v
retrieving revision 1.203
diff -u -r1.203 vm_mmap.c
--- sys/vm/vm_mmap.c    12 Oct 2005 06:56:00 -0000      1.203
+++ sys/vm/vm_mmap.c    10 Apr 2006 16:19:13 -0000
@@ -297,7 +297,7 @@
                if ((error = fget(td, uap->fd, &fp)) != 0)
                        goto done;
                if (fp->f_type != DTYPE_VNODE) {
-                       error = EINVAL;
+                       error = ENODEV;
                        goto done;
                }
                /*
Index: lib/libc/sys/mmap.2
===================================================================
RCS file: /work/FreeBSD/cvs/src/lib/libc/sys/mmap.2,v
retrieving revision 1.52
diff -u -r1.52 mmap.2
--- lib/libc/sys/mmap.2 17 Nov 2005 13:00:00 -0000      1.52
+++ lib/libc/sys/mmap.2 10 Apr 2006 16:20:21 -0000
@@ -312,11 +312,6 @@
 .Fa fd
 argument was not -1.
 .It Bq Er EINVAL
-.Dv MAP_ANON
-has not been specified and
-.Fa fd
-did not reference a regular or character special file.
-.It Bq Er EINVAL
 The
 .Fa offset
 argument
@@ -324,6 +319,11 @@
 (See
 .Sx BUGS
 below.)
+.It Bq Er ENODEV
+.Dv MAP_ANON
+has not been specified and
+.Fa fd
+did not reference a regular or character special file.
 .It Bq Er ENOMEM
 .Dv MAP_FIXED
 was specified and the

Tony.
-- 
f.a.n.finch  <dot at dotat.at>  http://dotat.at/
BERWICK ON TWEED TO WHITBY: WEST OR SOUTHWEST 5 OR 6, PERHAPS INCREASING 7
LATER IN NORTH. RAIN AT FIRST. MAINLY GOOD. SLIGHT OR MODERATE.


More information about the freebsd-standards mailing list