From matthias.andree@gmx.de  Mon Oct 24 22:54:54 2005
Return-Path: <matthias.andree@gmx.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id BDB1C16A420
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 24 Oct 2005 22:54:54 +0000 (GMT)
	(envelope-from matthias.andree@gmx.de)
Received: from mail.dt.e-technik.uni-dortmund.de (krusty.dt.E-Technik.uni-dortmund.de [129.217.163.1])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2504643D79
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 24 Oct 2005 22:54:41 +0000 (GMT)
	(envelope-from matthias.andree@gmx.de)
Received: from localhost (localhost [127.0.0.1])
	by mail.dt.e-technik.uni-dortmund.de (Postfix) with ESMTP id 3A77944547;
	Tue, 25 Oct 2005 00:54:39 +0200 (CEST)
Received: from mail.dt.e-technik.uni-dortmund.de ([127.0.0.1])
 by localhost (krusty [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
 id 31826-03; Tue, 25 Oct 2005 00:54:37 +0200 (CEST)
Received: from m2a2.dyndns.org (p509101DF.dip0.t-ipconnect.de [80.145.1.223])
	by mail.dt.e-technik.uni-dortmund.de (Postfix) with ESMTP id 8744044380;
	Tue, 25 Oct 2005 00:54:37 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
	by merlin.emma.line.org (Postfix) with ESMTP id AA5212015F4;
	Tue, 25 Oct 2005 00:54:36 +0200 (CEST)
Received: from m2a2.dyndns.org ([127.0.0.1])
 by localhost (m2a2.dyndns.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 19915-14; Tue, 25 Oct 2005 00:54:36 +0200 (CEST)
Received: by merlin.emma.line.org (Postfix, from userid 500)
	id 959762015F6; Tue, 25 Oct 2005 00:54:36 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
	by merlin.emma.line.org (Postfix) with ESMTP id B9A0E2015F2;
	Tue, 25 Oct 2005 00:52:59 +0200 (CEST)
Received: from m2a2.dyndns.org ([127.0.0.1])
 by localhost (m2a2.dyndns.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 20313-11; Tue, 25 Oct 2005 00:52:58 +0200 (CEST)
Received: from rho.emma.line.org (rho.emma.line.org [192.168.0.3])
	by merlin.emma.line.org (Postfix) with ESMTP id ABAA12007B1;
	Tue, 25 Oct 2005 00:52:58 +0200 (CEST)
Received: by rho.emma.line.org (Postfix, from userid 0)
	id 7BE0E5C36; Tue, 25 Oct 2005 00:52:58 +0200 (CEST)
Message-Id: <20051024225258.7BE0E5C36@rho.emma.line.org>
Date: Tue, 25 Oct 2005 00:52:58 +0200 (CEST)
From: Matthias Andree <matthias.andree@gmx.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Martin Cracauer <cracauer@cons.org>
Subject: ext2fs: no cp(1) possible, mmap returns EINVAL
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         87959
>Category:       kern
>Synopsis:       [ext2fs] no cp(1) possible, mmap returns EINVAL
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    cracauer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 24 23:00:26 GMT 2005
>Closed-Date:    Thu Dec 29 16:38:09 EST 2005
>Last-Modified:  Thu Dec 29 16:38:09 EST 2005
>Originator:     Bourne-again Superuser
>Release:        FreeBSD 6.0-RC1 i386
>Organization:
>Environment:
System: FreeBSD rho.emma.line.org 6.0-RC1 FreeBSD 6.0-RC1 #7: Mon Oct 24 18:20:44 CEST 2005 toor@rho.emma.line.org:/usr/obj/usr/src/sys/SIGMA i386


	
>Description:
Taken from http://docs.freebsd.org/cgi/mid.cgi?m37je55eb8.fsf
-------------------------------------------------------------
I mounted a Linux ext3 as ext2fs, which worked fine. However, trying to cvsupd
or cp data out of the partition was refused, tracing the processes revealed
that mmap() returned EINVAL.

rsync(1) (from ports) worked though.

Additional information (not in the original report on current@)
----------------------
The problem was originally reported against FreeBSD 6.0-BETA3 bug persists in
6.0-RC1 (i386) that was CVSupped on the UTC afternoon of 2005-10-24, fresh
kernel + world builds were WITHOUT -DNOCLEAN and with default optimization
options but with CPUTYPE?= athlon-xp.

Excerpt from truss cp:

break(0x805f000)                                 = 0 (0x0)
break(0x8060000)                                 = 0 (0x0)
stat("/linux/.bash_history",0x805f148)           = 0 (0x0)
stat("/tmp/.bash_history",0xbfbfebb0)            = 0 (0x0)
open("/linux/.bash_history",0x0,00)              = 3 (0x3)
open("/tmp/.bash_history",0x401,00)              = 4 (0x4)
mmap(0x0,199,(0x1)PROT_READ,(0x1)MAP_SHARED,3,0x0) ERR#22 'Invalid argument'
cp: write(2,0xbfbfe4c0,4)                                = 4 (0x4)
/linux/.bash_historywrite(2,0xbfbfe4e0,20)                               = 20 (0x14)
: write(2,0x281423ec,2)                          = 2 (0x2)
Invalid argument
write(2,0xbfbfe4c0,17)                           = 17 (0x11)

	
>How-To-Repeat:
	
1. (if needed) create an ext2fs
2. mount pre-existing ext2fs, perhaps writing some files to it
3. try to "cp" a regular file from ext2fs to some other filesystem, for instance:
   cp /linux/.bash_history /tmp/
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->cracauer 
Responsible-Changed-By: cracauer 
Responsible-Changed-When: Mon Oct 24 21:39:53 EDT 2005 
Responsible-Changed-Why:  
Assigning to myself, I want this done for 6.0 

http://www.freebsd.org/cgi/query-pr.cgi?pr=87959 

From: "Loren M. Lang" <lorenl@alzatex.com>
To: bug-followup@FreeBSD.org, matthias.andree@gmx.de
Cc:  
Subject: Re: kern/87959: [ext2fs] no cp(1) possible, mmap returns EINVAL
Date: Tue, 27 Dec 2005 00:45:30 -0800

 --b5gNqxB1S1yM7hjW
 Content-Type: multipart/mixed; boundary="G4iJoqBmSsgzjUCe"
 Content-Disposition: inline
 
 
 --G4iJoqBmSsgzjUCe
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Here is a patch that has been tested and appears to solve the problem.
 It falls back to the write() system call when mmap() fails.
 --=20
 I sense much NT in you.
 NT leads to Bluescreen.
 Bluescreen leads to downtime.
 Downtime leads to suffering.
 NT is the path to the darkside.
 Powerful Unix is.
 
 Public Key: ftp://ftp.tallye.com/pub/lorenl_pubkey.asc
 Fingerprint: CEE1 AAE2 F66C 59B5 34CA  C415 6D35 E847 0118 A3D2
 =20
 
 --G4iJoqBmSsgzjUCe
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="cp.patch"
 Content-Transfer-Encoding: quoted-printable
 
 --- src/bin/cp/utils.c.orig	Tue Dec 27 00:35:05 2005
 +++ src/bin/cp/utils.c	Tue Dec 27 00:35:40 2005
 @@ -130,38 +130,38 @@
  	 * wins some CPU back.
  	 */
  #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
 +	/*
 +	 * Some filesystems like ext2fs do not support mmap() under FreeBSD
 +	 * so fall back to write() instead
 +	 */
  	if (S_ISREG(fs->st_mode) && fs->st_size > 0 &&
 -	    fs->st_size <=3D 8 * 1048576) {
 -		if ((p =3D mmap(NULL, (size_t)fs->st_size, PROT_READ,
 -		    MAP_SHARED, from_fd, (off_t)0)) =3D=3D MAP_FAILED) {
 +	    fs->st_size <=3D 8 * 1048576 &&
 +	    (p =3D mmap(NULL, (size_t)fs->st_size, PROT_READ,
 +	     MAP_SHARED, from_fd, (off_t)0)) !=3D MAP_FAILED) {
 +		wtotal =3D 0;
 +		for (bufp =3D p, wresid =3D fs->st_size; ;
 +		    bufp +=3D wcount, wresid -=3D (size_t)wcount) {
 +			wcount =3D write(to_fd, bufp, wresid);
 +			wtotal +=3D wcount;
 +			if (info) {
 +				info =3D 0;
 +				(void)fprintf(stderr,
 +					"%s -> %s %3d%%\n",
 +					entp->fts_path, to.p_path,
 +					cp_pct(wtotal, fs->st_size));
 +				=09
 +			}
 +			if (wcount >=3D (ssize_t)wresid || wcount <=3D 0)
 +				break;
 +		}
 +		if (wcount !=3D (ssize_t)wresid) {
 +			warn("%s", to.p_path);
 +			rval =3D 1;
 +		}
 +		/* Some systems don't unmap on close(2). */
 +		if (munmap(p, fs->st_size) < 0) {
  			warn("%s", entp->fts_path);
  			rval =3D 1;
 -		} else {
 -			wtotal =3D 0;
 -			for (bufp =3D p, wresid =3D fs->st_size; ;
 -			    bufp +=3D wcount, wresid -=3D (size_t)wcount) {
 -				wcount =3D write(to_fd, bufp, wresid);
 -				wtotal +=3D wcount;
 -				if (info) {
 -					info =3D 0;
 -					(void)fprintf(stderr,
 -						"%s -> %s %3d%%\n",
 -						entp->fts_path, to.p_path,
 -						cp_pct(wtotal, fs->st_size));
 -					=09
 -				}
 -				if (wcount >=3D (ssize_t)wresid || wcount <=3D 0)
 -					break;
 -			}
 -			if (wcount !=3D (ssize_t)wresid) {
 -				warn("%s", to.p_path);
 -				rval =3D 1;
 -			}
 -			/* Some systems don't unmap on close(2). */
 -			if (munmap(p, fs->st_size) < 0) {
 -				warn("%s", entp->fts_path);
 -				rval =3D 1;
 -			}
  		}
  	} else
  #endif
 
 --G4iJoqBmSsgzjUCe--
 
 --b5gNqxB1S1yM7hjW
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.1 (GNU/Linux)
 
 iD8DBQFDsP8qbTXoRwEYo9IRAvffAJ43jfIFwZp5DzCz41pdiC4Cw0iCygCfUNIc
 UsT5KSIWUww5fAVaW7fHna0=
 =JrVE
 -----END PGP SIGNATURE-----
 
 --b5gNqxB1S1yM7hjW--

From: Matthias Andree <matthias.andree@gmx.de>
To: "Loren M. Lang" <lorenl@alzatex.com>, bug-followup@freebsd.org
Cc:  
Subject: Re: kern/87959: [ext2fs] no cp(1) possible, mmap returns EINVAL
Date: Tue, 27 Dec 2005 11:49:32 +0100

 On Tue, 27 Dec 2005, Loren M. Lang wrote:
 
 > Here is a patch that has been tested and appears to solve the problem.
 > It falls back to the write() system call when mmap() fails.
 
 Thanks a lot, but isn't it better to fix the filesystem to support
 mmap()? Else we'll be fixing applications to no end. That's why I filed
 it as kern/ bug, not bin/ bug.
 
 cvsupd is the next to require mmap() and not work on ext2fs...
 
 -- 
 Matthias Andree
State-Changed-From-To: open->closed 
State-Changed-By: cracauer 
State-Changed-When: Thu Dec 29 16:37:05 EST 2005 
State-Changed-Why:  
I had fixed that right before 6.0 but forgot to commit a style-fixe 
and to close the PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=87959 
>Unformatted:
