Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Oct 2002 14:59:52 +0100
From:      Thomas Zenker <thz@Lennartz-electronic.de>
To:        Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Patch to allow a driver to report unrecoverable write errors to the buf layer
Message-ID:  <20021031145952.A457@mezcal.tue.le>
In-Reply-To: <94460.1035912876@critter.freebsd.dk>; from phk@critter.freebsd.dk on Tue, Oct 29, 2002 at 06:34:36PM %2B0100
References:  <20021029182712.A1479@gicco.homeip.net> <94460.1035912876@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Oct 29, 2002 at 06:34:36PM +0100, Poul-Henning Kamp wrote:
> In message <20021029182712.A1479@gicco.homeip.net>, Hanspeter Roth writes:
> >  On Oct 18 at 20:45, Maxim Sobolev spoke:
> >
> >> again, then again ad infinitum. The same effect if you'll mount
> >> write-protected floppy in read/write mode. 
> 
> This is just lame, but I'm not willing to to take a shouting match
> with the person who committed this brain-damage.
> 
> >As of a write-protected floppy, why is it allowd to be mounted as
> >writeable?
> >The mount should be degraded to readonly or rejected.
> 
> That's a slightly more involved issue because you would have to
> actually try to write to it before you find out that you can't.

for stable I have a patch, which checks during open for write
protection of the floppy if FWRITE bit is set and fails with EPERM
if this is the case. This works reliably for me. The reason I haven't
sent this patch in is, there is a possible conflict with accesses
to a second floppy disk drive at the same time. Anyway, better than
panic'ing the machine...

Actually all accesses to the controller hardware are serialized
thru a state machine "fdstate". The Bad Thing is, that this state
machine is bound too tight to the strategy (i.e. you get some job
done via a buffer or nothing). Best example is the interfacing of
formatting via the B_FORMAT/B_XXX kludge.  The Right Thing would
be to redesign  the interface to the state machine to get jobs done
from any source (with or without buffer) and maintaining state of
write protection.

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.


Cheers,

-- Thomas Zenker
   c/o Lennartz electronic GmbH
   Bismarckstrasse 136, D-72072 Tuebingen, Germany
   Phone:  +49-(0)7071-93550
   Email:  thz@lennartz-electronic.de

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021031145952.A457>