From owner-freebsd-hackers Tue Jun 3 18:34:12 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id SAA08251 for hackers-outgoing; Tue, 3 Jun 1997 18:34:12 -0700 (PDT) Received: from riverside.mr.net (root@Riverside.MR.Net [137.192.2.5]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id SAA08243 for ; Tue, 3 Jun 1997 18:34:06 -0700 (PDT) Received: from data.mr.net (root@data.MR.Net [137.192.192.27]) by riverside.mr.net (8.8.5/) with ESMTP id UAA11959 for ; Tue, 3 Jun 1997 20:33:24 -0500 (CDT) Received: from data (fritchie@data.MR.Net [137.192.192.27]) by data.mr.net (8.8.5/8.7.2) with ESMTP id UAA14543 for ; Tue, 3 Jun 1997 20:33:23 -0500 (CDT) Message-Id: <199706040133.UAA14543@data.mr.net> To: freebsd-hackers@freebsd.org Subject: mmap() incapable of mapping block special files? Date: Tue, 03 Jun 1997 20:33:22 -0500 From: Scott Lystig Fritchie Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk [Originally posted to comp.unix.bsd.freebsd.misc, ] 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