From nobody@FreeBSD.org  Tue Aug 30 14:31:35 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id DF2EF16A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 30 Aug 2005 14:31:35 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 79B2B43D53
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 30 Aug 2005 14:31:35 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j7UEVZxQ031352
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 30 Aug 2005 14:31:35 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j7UEVZBi031335;
	Tue, 30 Aug 2005 14:31:35 GMT
	(envelope-from nobody)
Message-Id: <200508301431.j7UEVZBi031335@www.freebsd.org>
Date: Tue, 30 Aug 2005 14:31:35 GMT
From: Lev Levinson <llevinson@inbox.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: reading from fd0 when floppy disk is write-protected
X-Send-Pr-Version: www-2.3

>Number:         85481
>Category:       kern
>Synopsis:       [patch] error reading certain number of blocks from fd0 when disk is write-protected
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 30 14:40:18 GMT 2005
>Closed-Date:    Fri Sep 02 00:40:14 GMT 2005
>Last-Modified:  Fri Sep 02 00:40:14 GMT 2005
>Originator:     Lev Levinson
>Release:        5.4-RELEASE
>Organization:
>Environment:
FreeBSD  5.4-RELEASE FreeBSD 5.4-RELEASE #0: Sun May  8 10:21:06 UTC 2005     root@harlow.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
Reading n x 512 byte blocks from /dev/fd0 result in "Input/output error"
when n IS NOT DIVISOR of 36 and floppy disk is write-protected. 
for example, 
dd if=/dev/fd0 of=/dev/null bs=512 
dd if=/dev/fd0 of=/dev/null bs=1024 # 2x512 
dd if=/dev/fd0 of=/dev/null bs=1536 # 3x512 
dd if=/dev/fd0 of=/dev/null bs=2048 # 4x512
dd if=/dev/fd0 of=/dev/null bs=3072 # 6x512
dd if=/dev/fd0 of=/dev/null bs=4608 # 9x512
works well, but
dd if=/dev/fd0 of=/dev/null bs=2560 # 5x512
dd if=/dev/fd0 of=/dev/null bs=3584 # 7x512
dd if=/dev/fd0 of=/dev/null bs=4096 # 8x512
dd if=/dev/fd0 of=/dev/null bs=5120 # 10x512
reports input-output error.

tar reads file with 20 x 512 byte blocks, and 
tar -xzf /dev/fd0 
no works if disk is write-protected.
but 
tar -xzf /dev/fd0 -b 36
works.



 





>How-To-Repeat:
1 Boot and login as root
2 Insert write protected floppy disk.
3 dd if=/dev/fd0 of=/dev/null bs=4096
  (or bs = n x 512, where n is not divisor of 36 - number of sectors per floppy track)
>Fix:
In function fdc_worker (src/sys/dev/fdc/fdc.c:746) i found this line:

if (bp != NULL &&
    (fdc->retry >= retries || (fd->flags & FDOPT_NORETRY))) {

In this line, option (BUT NOT FLAG!!!) FDOPT_NORETRY AND-ed against
field fd->flags (BUT NOT fd->options). 
Option FDOPT_NORETRY has same value as a flag FD_WP (write protected).
Thus, instead "need more reads" we have "Disk is write-protected" in condition.
For fix this bug, code mast be like this:

if (bp != NULL &&
    (fdc->retry >= retries || (fd->options & FDOPT_NORETRY))) {





>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: rodrigc 
State-Changed-When: Fri Sep 2 00:39:40 GMT 2005 
State-Changed-Why:  
Committed to -CURRET, RELENG_6, RELENG_5. 
Thanks! 

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