From das@HAL9000.wox.org  Sat Apr 13 04:17:42 2002
Return-Path: <das@HAL9000.wox.org>
Received: from HAL9000.wox.org (12-232-222-90.client.attbi.com [12.232.222.90])
	by hub.freebsd.org (Postfix) with ESMTP id 9B17D37B404
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 13 Apr 2002 04:17:41 -0700 (PDT)
Received: (from das@localhost)
	by HAL9000.wox.org (8.11.6/8.11.6) id g3DBHkR21118;
	Sat, 13 Apr 2002 04:17:46 -0700 (PDT)
	(envelope-from das)
Message-Id: <200204131117.g3DBHkR21118@HAL9000.wox.org>
Date: Sat, 13 Apr 2002 04:17:46 -0700 (PDT)
From: David Schultz <dschultz@uclink.Berkeley.EDU>
Reply-To: David Schultz <dschultz@uclink.Berkeley.EDU>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] msdosfs_readdir() freezes after failed write
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         37035
>Category:       kern
>Synopsis:       [PATCH] msdosfs_readdir() freezes after failed write
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    trhodes
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 13 04:20:01 PDT 2002
>Closed-Date:    Wed Jul 09 11:41:03 PDT 2003
>Last-Modified:  Wed Jul 09 11:41:03 PDT 2003
>Originator:     David Schultz
>Release:        FreeBSD 4.5-RELEASE-p2 i386
>Organization:
>Environment:
Problem affects all versions of FreeBSD from at least 4.0-RELEASE.
to 5.0-CURRENT
>Description:
After an attempt to write a buffer to a write-protected or otherwise
bad floppy, attempts to bread() the same block return success, but the
resulting buffer has b_count == b_resid.  Unlike the UFS code, which
correctly handles this situation, msdosfs_readdir() goes into an
infinite loop.
>How-To-Repeat:
Mount a write-protected DOS floppy, then...
/flp# cat > foo
(error)
/flp# ls
(lockup)
>Fix:
This patch causes msdosfs_readdir() to give up in the case where it would
otherwise spin forever.  There is still room for improvement; for example,
the buffer cache ought to give up when the floppy is forcibly unmounted.
However, this solves the actual lockup that many people complain about.

Index: msdosfs_vnops.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/msdosfs/msdosfs_vnops.c,v
retrieving revision 1.119
diff -u -r1.119 msdosfs_vnops.c
--- msdosfs_vnops.c	2002/04/05 14:01:04	1.119
+++ msdosfs_vnops.c	2002/04/12 23:12:27
@@ -1603,7 +1603,16 @@
 			brelse(bp);
 			return (error);
 		}
+
+		/*
+		 * If a short read occurred, the buffer may contain
+		 * less valid data than expected.
+		 */
 		n = min(n, blsize - bp->b_resid);
+		if (n == 0) {
+			brelse(bp);
+			break;
+		}
 
 		/*
 		 * Convert from dos directory entries to fs-independent
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: trhodes 
State-Changed-When: Fri Sep 13 19:49:37 PDT 2002 
State-Changed-Why:  
I'll review this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37035 
State-Changed-From-To: closed->open 
State-Changed-By: trhodes 
State-Changed-When: Sat Sep 14 13:19:32 PDT 2002 
State-Changed-Why:  
Change this to me, instead of closed.  My original intent. 


Responsible-Changed-From-To: freebsd-bugs->trhodes 
Responsible-Changed-By: trhodes 
Responsible-Changed-When: Sat Sep 14 13:19:32 PDT 2002 
Responsible-Changed-Why:  
Change this to me, instead of closed.  My original intent. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37035 
State-Changed-From-To: open->closed 
State-Changed-By: trhodes 
State-Changed-When: Wed Jul 9 11:40:40 PDT 2003 
State-Changed-Why:  
Applied!  Thanks for the submission das! 

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