From dgl@kirk.sector14.net  Thu Nov  1 07:47:16 2001
Return-Path: <dgl@kirk.sector14.net>
Received: from kirk.sector14.net (66-61-170-163.mtc2.cox.rr.com [66.61.170.163])
	by hub.freebsd.org (Postfix) with ESMTP id A4A3937B401
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  1 Nov 2001 07:47:15 -0800 (PST)
Received: (from dgl@localhost)
	by kirk.sector14.net (8.11.3/8.11.3) id fA1Fl8Q19863;
	Thu, 1 Nov 2001 10:47:08 -0500 (EST)
	(envelope-from dgl)
Message-Id: <200111011547.fA1Fl8Q19863@kirk.sector14.net>
Date: Thu, 1 Nov 2001 10:47:08 -0500 (EST)
From: Doug Lee <dgl@visi.com>
Reply-To: Doug Lee <dgl@visi.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: 2872-or-less-byte ftp binary transfer from smbfs share produces garbage
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         31692
>Category:       bin
>Synopsis:       2872-or-less-byte ftp binary transfer from smbfs share produces garbage
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 01 07:50:00 PST 2001
>Closed-Date:    Sat Feb 14 23:08:11 PST 2004
>Last-Modified:  Sat Feb 14 23:08:11 PST 2004
>Originator:     Doug Lee
>Release:        FreeBSD 4.3-STABLE i386
>Organization:
Bartimaeus Group, McLean, Virginia
>Environment:
System: FreeBSD kirk.sector14.net 4.3-STABLE FreeBSD 4.3-STABLE #5: Mon May 28 01:57:16 EDT 2001 dgl@kirk.sector14.net:/usr/obj/usr/src/sys/CUSTOM i386

Using smbfs-1.4.1
Using standard ftpd; problem does not occur when using wu-ftpd-2.6.1.

>Description:
Trying to ftp a short file from a mounted smbfs share using binary
mode will produce garbage in the garbage file instead of a copy of
the file being transferred.  The garbage varies from one attempt
to the next.  This occurs even when using "ftp localhost."  It does
not occur when transferring from a UFS mount or when transferring
in ASCII mode, or when the file is larger than 2872 bytes.  The
problem does not occur when accessing the smbfs-mounted file by
other means (e.g., ex/vi, cp, or even copying to a Windows box via
a Samba share).  tcpdump during the corrupted ftp shows that data
moves correctly from smbfs-mounted machine to FreeBSD but is
incorrect by the time it leaves FreeBSD (via ftpd) for its final
destination.  Reproduced on two machines running different 4.3-STABLE
snapshots.  Transfers using wu-ftpd-2.6.1 work properly.
>How-To-Repeat:
Mount a Windows share via smbfs, ftp localhost on the FreeBSD box,
log in and change to binary mode, and get a file of2872 bytes
or less from somewhere under the smbfs mount point.  Compare original
and transferred files.
>Fix:
Workaround: Copy the needed file via means other than ftp to a UFS
mount before getting it with FTP, or use a different ftpd.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: sheldonh 
State-Changed-When: Thu Dec 27 04:45:13 PST 2001 
State-Changed-Why:  
First, try a recent RELENG_4 and confirm that the problem persists. 

Then, my guess would be sendfile() ickiness.  We can prove this by 
forcing the use of the old method instead of sendfile(). 

In ftpd.c, in send_data(), find the first occurrence of 

if (isreg) { 

and insert 

goto oldway; 

immediately before it.  This will skip the sendfile() method.  If that 
solves the problem, we know it's odd sendfile() interaction with 
smbfs (or possibly all remote filesystem types).  If so, it'd 
be interesting to see whether the same behaviour is observed with 
NFS instead of smbfs. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=31692 

From: Sheldon Hearn <sheldonh@starjuice.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/31692: ntfs and sendfile problem (corrupted data) 
Date: Sun, 30 Dec 2001 16:56:22 +0200

 Followup confirming that the problem is sendfile(2)-specific.
 
 Ciao,
 Sheldon.
 
 ----- Original Message -----
 
 Date:  Sun, 30 Dec 2001 15:47:45 +0100 (CET)
 From:  Michal Mertl <mime@traveller.cz>
 To:  Sheldon Hearn <sheldonh@starjuice.net>
 cc:  current@freebsd.org
 Subject:  Re: ntfs and sendfile problem (corrupted data) 
 
 
 > On Sun, 30 Dec 2001, Sheldon Hearn wrote:
 > 
 > >
 > >
 > > On Sun, 30 Dec 2001 01:53:08 +0100, Michal Mertl wrote:
 > >
 > > > I have ntfs partition mounted ro on current. I can read from it without
 > > > problems. But I noticed I get corrupted data (the corrupted file has
 > > > right size but contains mostly zeros) when using ftpd to read them.
 > > >
 > > > I'm pretty sure the problem is thus in sendfile(2) and/or ntfs fs support.
 > >
 > > See also PR bin/31692, which reports simmilar problems using ftpd and
 > > smbfs.  See my request for feedback, which ought to help verify that
 > > it's sendfile(2) causing the problem.
 > >
 > 
 > I did use the "goto oldway;" and the problem went away. I tried to look at
 > /sys/kern/uipc_syscalls.c sendfile implementation but it is too complex
 > for me :-(. I tried ktrace on ftpd but only saw the call to sendfile(2).
 > If you give me some guidance I can try to look into problem deeper. I
 > don't have any experience in kernel debugging but would like to learn it.
 > 
 > 
 > 
 > > Ciao,
 > > Sheldon.
 > >
 > 
 > -- 
 > Michal Mertl
 > mime@traveller.cz
 
 > 
 
State-Changed-From-To: feedback->open 
State-Changed-By: ceri 
State-Changed-When: Sun Jun 8 10:57:23 PDT 2003 
State-Changed-Why:  
Feedback has been requested and received; throw this PR back open. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=31692 
State-Changed-From-To: open->closed 
State-Changed-By: tjr 
State-Changed-When: Sat Feb 14 23:06:32 PST 2004 
State-Changed-Why:  
Same as kern/36038; closing this one as a duplicate because the 
newer PR has a more useful audit trail 

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