From owner-freebsd-bugs Sat Apr 13 4:20:10 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 7874137B419 for ; Sat, 13 Apr 2002 04:20:02 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g3DBK2T55497; Sat, 13 Apr 2002 04:20:02 -0700 (PDT) (envelope-from gnats) 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 ; 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 Reply-To: David Schultz To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/37035: [PATCH] msdosfs_readdir() freezes after failed write Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 37035 >Category: kern >Synopsis: [PATCH] msdosfs_readdir() freezes after failed write >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Apr 13 04:20:01 PDT 2002 >Closed-Date: >Last-Modified: >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: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message