From hampi@rootshell.be  Thu May 20 12:33:47 2004
Return-Path: <hampi@rootshell.be>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 6E33316A4D0
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 20 May 2004 12:33:47 -0700 (PDT)
Received: from smtp.hispeed.ch (mxout.hispeed.ch [62.2.95.247])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 82A7343D31
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 20 May 2004 12:33:46 -0700 (PDT)
	(envelope-from hampi@rootshell.be)
Received: from gicco.homeip.net (80-218-73-163.dclient.hispeed.ch [80.218.73.163])
	by smtp.hispeed.ch (8.12.6/8.12.6/tornado-1.0) with ESMTP id i4KJXSWZ002038
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO);
	Thu, 20 May 2004 21:33:28 +0200
Received: from localhost.here (idefix@gicco.homeip.net [127.0.0.1])
	by gicco.homeip.net (8.12.8p2/8.12.8) with ESMTP id i4KJXRYA000227;
	Thu, 20 May 2004 21:33:27 +0200 (CEST)
	(envelope-from idefix@gicco.homeip.net)
Received: (from idefix@localhost)
	by localhost.here (8.12.8p2/8.12.8/Submit) id i4KJXQYF000226;
	Thu, 20 May 2004 21:33:26 +0200 (CEST)
Message-Id: <200405201933.i4KJXQYF000226@localhost.here>
Date: Thu, 20 May 2004 21:33:26 +0200 (CEST)
From: Hanspeter Roth <hampi@rootshell.be>
Reply-To: hampi@rootshell.be
To: FreeBSD-gnats-submit@freebsd.org
Cc: hampi@rootshell.be
Subject: filesystems not unmounted during reboot due to floppy
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         66960
>Category:       kern
>Synopsis:       [fdc] [patch] filesystems not unmounted during reboot due to write-protected floppy
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 20 12:40:17 PDT 2004
>Closed-Date:    Sat May 11 14:05:45 UTC 2013
>Last-Modified:  Sat May 11 14:05:45 UTC 2013
>Originator:     Idefix
>Release:        FreeBSD 4.10-RC3 i386
>Organization:
>Environment:
System: FreeBSD snoopy.here 4.10-RC3 FreeBSD 4.10-RC3 #1: Thu May 20 20:54:31 CEST 2004 idefix@snoopy.here:/usr/src/sys/compile/C3 i386


	
>Description:
	This has been discussed in October 2002.
	http://docs.freebsd.org/cgi/getmsg.cgi?fetch=350780+0+archive/2002/freebsd-hackers/20021103.freebsd-hackers
	If one forgets to mount a floppy readonly that is write-protected the 
	filesystems of the harddisk can't be unmounted and must be checked
	after reboot.
	The patch from Thomas Zenker prevents a write-protected floppy to
	be mounted writable. The floppy will be allowed to be mounted
	only readonly.
>How-To-Repeat:
	Set the floppy to write-protected and mount it writable and then reboot
	the system.
>Fix:

Index: sys/isa/fd.c
===================================================================
RCS file: /usr/cvs/FreeBSD/src/sys/isa/fd.c,v
retrieving revision 1.176.2.8
diff -u -r1.176.2.8 fd.c
--- sys/isa/fd.c	15 May 2002 21:56:14 -0000	1.176.2.8
+++ sys/isa/fd.c	31 Oct 2002 13:06:05 -0000
@@ -1448,6 +1448,21 @@
 		}
 	}
 	fd->ft = fd_types + type - 1;
+	if (flags & FWRITE) {	/* check for write protection */
+		int r, s, st3;
+	        s = splbio();
+		set_motor(fdc, fd->fdsu, TURNON); /* select drive */
+		r = fd_sense_drive_status(fdc, &st3);
+		set_motor(fdc, fd->fdsu, TURNOFF);
+		fdc->state = RESETCTLR;
+		splx(s);
+		if(r != 0)
+			return(ENXIO);
+		if (st3 & NE7_ST3_WP) {
+			device_printf(fd->dev, "write protected\n");
+			return(EPERM);
+		}
+	}
 	fd->flags |= FD_OPEN;
 	/*
 	 * Clearing the DMA overrun counter at open time is a bit messy.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: eadler 
State-Changed-When: Sat May 11 14:05:43 UTC 2013 
State-Changed-Why:  
the 'fd' driver has been replaced with the 'fdc' driver.  A quick check 
seems to indicate that this functionality exists in the fdc driver.  I'm 
sorry that no one had a chance to look at your PR :( 

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