Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!metro!munnari.OZ.AU!news.ecn.uoknor.edu!news.wildstar.net!news.ececs.uc.edu!newsrelay.netins.net!mr.net!news.mr.net!news
From: Scott Fritchie <fritchie@mr.net>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: mmap() incapable of mapping block special files
Date: 01 Jun 1997 01:12:07 -0500
Organization: Minnesota Regional Network
Lines: 36
Sender: fritchie@data
Message-ID: <ytlraemlumg.fsf@mr.net>
NNTP-Posting-Host: data.mr.net
X-Newsreader: Gnus v5.3/Emacs 19.34
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:42011
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