From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 26 08:25:28 2005 Return-Path: X-Original-To: freebsd-hackers@FreeBSD.org Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 161A416A41F for ; Wed, 26 Oct 2005 08:25:28 +0000 (GMT) (envelope-from delphij@frontfree.net) Received: from tarsier.geekcn.org (tarsier.geekcn.org [210.51.165.229]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6C93E43D53 for ; Wed, 26 Oct 2005 08:25:24 +0000 (GMT) (envelope-from delphij@frontfree.net) Received: from localhost (tarsier.geekcn.org [210.51.165.229]) by tarsier.geekcn.org (Postfix) with ESMTP id BC0A0EB101D; Wed, 26 Oct 2005 16:25:22 +0800 (CST) Received: from tarsier.geekcn.org ([210.51.165.229]) by localhost (mail.geekcn.org [210.51.165.229]) (amavisd-new, port 10024) with ESMTP id 64960-17; Wed, 26 Oct 2005 16:25:18 +0800 (CST) Received: from beastie.frontfree.net (unknown [211.71.95.7]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTP id 8D476EB1037; Wed, 26 Oct 2005 16:25:16 +0800 (CST) Received: from localhost (localhost.frontfree.net [127.0.0.1]) by beastie.frontfree.net (Postfix) with ESMTP id 41C22130FD9; Wed, 26 Oct 2005 16:25:10 +0800 (CST) Received: from beastie.frontfree.net ([127.0.0.1]) by localhost (beastie.frontfree.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 51035-12; Wed, 26 Oct 2005 16:25:09 +0800 (CST) Received: from [10.217.12.68] (sina152-194.staff.sina.com.cn [61.135.152.194]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by beastie.frontfree.net (Postfix) with ESMTP id C463A130C93; Wed, 26 Oct 2005 16:25:08 +0800 (CST) From: Xin LI To: freebsd-hackers@FreeBSD.org Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-d+sFaITjGw0SPWFkVk8H" Organization: The FreeBSD Simplified Chinese Project Date: Wed, 26 Oct 2005 16:25:01 +0800 Message-Id: <1130315101.810.5.camel@spirit> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 FreeBSD GNOME Team Port X-Virus-Scanned: amavisd-new at frontfree.net X-Virus-Scanned: amavisd-new at geekcn.org Cc: zhuyan@staff.sina.com.cn, LI Xin Subject: Is it possible to mmap() raw disk device? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2005 08:25:28 -0000 --=-d+sFaITjGw0SPWFkVk8H Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Dear folks, When we were trying to make a userland FS application we have encountered "Invalid Argument" when doing mmap() over an open descriptor to a disk device. The program goes here: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D #include #include #include /* mmap() */ #include #include #include int main(int argc, char *argv[]) { int fd; char *src, *dst; struct stat statbuf; dst =3D strdup("abcdefghijklmn"); if (dst =3D=3D NULL) { printf("Can not allocate memory\n"); exit(-1); } if ((fd =3D open("/dev/da2s1", O_RDWR | O_DIRECT)) < 0) printf("can't open for read/write"); if ((src =3D mmap(0, 10, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0)) =3D=3D (caddr_t) -1) { perror("mmap error for input"); return -1; } memcpy(dst, src, 10); /* does the file copy */ exit(0); } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D Do we need some special prerequisite before doing mmap()? According to the vm_mmap.c it seems that we should map a DTYPE_VNODE object, which looks somewhat confusing... Thanks in advance! Cheers, --=20 Xin LI http://www.delphij.net/ --=-d+sFaITjGw0SPWFkVk8H Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (FreeBSD) iD8DBQBDXz1d/cVsHxFZiIoRAuweAJ4lkRXRjkXNUEP3Zk8Fv5EW89ODAwCghEjf s5YomQWnRju+otn6BzuCBFY= =yNeR -----END PGP SIGNATURE----- --=-d+sFaITjGw0SPWFkVk8H--