Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Jun 1997 20:33:22 -0500
From:      Scott Lystig Fritchie <fritchie@MR.Net>
To:        freebsd-hackers@freebsd.org
Subject:   mmap() incapable of mapping block special files?
Message-ID:  <199706040133.UAA14543@data.mr.net>

next in thread | raw e-mail | index | archive | help
[Originally posted to comp.unix.bsd.freebsd.misc, <ytlraemlumg.fsf@mr.net>]

I was puzzled for quite a while trying to figure out why a mmap() call
was failing with EINVAL.  None of the reasons for EINVAL in the mmap()
man page matched my situation.
 
I finally resorted to looking at the kernel source code.  (I should've
thought of it sooner, but I've got too much Solaris in my blood.  :-)
In /usr/src/sys/vm/vm_mmap.c (2.2.1-RELEASE) at about line 211 I
found:
 
                /*
                 * Mapping file, get fp for validation. Obtain vnode and make
                 * sure it is of appropriate type.
                 */
                if (((unsigned) uap->fd) >= fdp->fd_nfiles ||
                    (fp = fdp->fd_ofiles[uap->fd]) == NULL)
                        return (EBADF);
                if (fp->f_type != DTYPE_VNODE)
                        return (EINVAL);
                vp = (struct vnode *) fp->f_data;
                if (vp->v_type != VREG && vp->v_type != VCHR)
                        return (EINVAL);
 
Doh!  The file in question is a block special file, not a character
special or plain-old regular file.
 
I'm tempted to add an additional "&&" to the file type test to include
for VBLK ... but I wouldn't wanna do it if it will cause unknown (to
me) mischief down the road.  Is there a particular reason why VBLK
isn't included?
 
-Scott
---
Scott Lystig Fritchie, Network Engineer          MRNet Internet Services, Inc.
fritchie@mr.net, PGP key #152B8725               Minnesota Regional Network
v: 612/362.5820, p: 612/637.9547                 2829 University Ave SE
http://www.mr.net/~fritchie/                     Minneapolis, MN  55414



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199706040133.UAA14543>