From owner-freebsd-hackers Thu Oct 31 10:37:24 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E2FD637B401 for ; Thu, 31 Oct 2002 10:37:21 -0800 (PST) Received: from gicco.homeip.net (dclient80-218-72-234.hispeed.ch [80.218.72.234]) by mx1.FreeBSD.org (Postfix) with ESMTP id 48A2143E7B for ; Thu, 31 Oct 2002 10:37:20 -0800 (PST) (envelope-from hampi@rootshell.be) Received: (from hampi@localhost) by gicco.homeip.net (8.11.6/8.11.6) id g9VIbJH00982 for freebsd-hackers@FreeBSD.ORG; Thu, 31 Oct 2002 19:37:19 +0100 (CET) (envelope-from hampi@rootshell.be) Date: Thu, 31 Oct 2002 19:37:19 +0100 From: Hanspeter Roth To: freebsd-hackers@FreeBSD.ORG Subject: Patch to prevent write-protected floppy from being mounted writable Message-ID: <20021031193719.A940@gicco.homeip.net> Reply-To: freebsd-hackers@FreeBSD.ORG Mail-Followup-To: freebsd-hackers@FreeBSD.ORG References: <20021029182712.A1479@gicco.homeip.net> <94460.1035912876@critter.freebsd.dk> <20021031145952.A457@mezcal.tue.le> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20021031145952.A457@mezcal.tue.le>; from thz@Lennartz-electronic.de on Thu, Oct 31, 2002 at 02:59:52PM +0100 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Oct 31 at 14:59, Thomas Zenker spoke: > On Tue, Oct 29, 2002 at 06:34:36PM +0100, Poul-Henning Kamp wrote: > > 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 Hey, exactly! Thank you! Could the core team consider this patch to get merged into 4.8? -Hanspeter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message