Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Oct 2002 13:23:38 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Patch to allow a driver to report unrecoverable write errors to the  buf layer
Message-ID:  <3DBEFC5A.5468CADD@mindspring.com>
References:  <20021029182712.A1479@gicco.homeip.net> <94460.1035912876@critter.freebsd.dk> <20021029184724.A1682@gicco.homeip.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Hanspeter Roth wrote:
>   On Oct 29 at 18:34, Poul-Henning Kamp spoke:
> > 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.
> 
> Isn't there a means to determine the state of the protection before
> the mount is attempted?


You can write 0x04ss (sense drive status on standard parameter
for drive and head select 'ss') to port 0x03F5; then read disk
status register 3 for one byte:

	bit	meaning
	---	------------
	7	No drive fault
	6	Write protected (1 = protected)
	5	Drive ready (1 = ready)
	4	Head is on track zero (1 = on track 0)
	3	Two sided (1 = two sided, 0 = one sided)
	2	Head select (0 = side 0, 1 = side 1)
	1 |
	0 |	bit 1	bit 0	meaning
		-----	-----	------------
		0	0	drive 0 selected
		0	1	drive 1 selected
		1	0	drive 2 selected
		1	1	drive 3 selected

You can detect "disk change" by selecting a sidk, and then reading
0x03F7 (this works on all PC hardware on or after the IBM PC AT).
The byte you read is only interesting for bit 7, unless you can
verify that specific controller being used.  If bit 7 is zero, then
there is a disk present, and it has not been changed.  If bit 7 is
set, then there is no diskette present, or the disk has not been
changed.  Therefore, by repeating this operation twice, and seeing
a 1 -> 0 transition for bit 7, you can tell a disk is present, or
seeing a 1 -> 1 persistance, you can tell there is no disk present
(e.g. you will need to save "one behind" on status for this to be
useful in detecting both changes and missing disks).

Note that this works on 3.5" disks, but only works on 5.25" disks
that are 1.2M or larger.  In addition, many systems fail to wire
up the "disk change" or "disk present" lines from the floppy drive
to the controller, hard wiring the disk as being present and
unchanged at all times.  So "disk change" is unreliable.

"If all else fails, read the documentation..."

-- Terry

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?3DBEFC5A.5468CADD>