Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 May 2003 17:18:57 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Yar Tikhiy <yar@comp.chem.msu.su>
Cc:        FreeBSD-gnats-submit@freebsd.org
Subject:   Re: kern/52338: fd(4) floppy disk driver & non-blocking I/O
Message-ID:  <20030517165718.B15076@gamplex.bde.org>
In-Reply-To: <200305161646.h4GGkdDS000677@stylish.chem.msu.su>
References:  <200305161646.h4GGkdDS000677@stylish.chem.msu.su>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 16 May 2003, Yar Tikhiy wrote:

> >Description:
>
> 	If /dev/fdX has been opened in non-blocking mode, the
> 	inserted floppy type will never be autoselected.  So trying
> 	to get its parameters through DIOCGSECTORSIZE or DIOCGMEDIASIZE
> 	will cause panic on dereferencing the NULL fd->ft pointer.
> 	And reading from or writing to its descriptor will result
> 	in the ENXIO (Device not configured) error.

I made the obvious quick for for the null pointer panics when they were
implemented:

%%%
Index: fd.c
===================================================================
RCS file: /home/ncvs/src/sys/isa/fd.c,v
retrieving revision 1.244
diff -u -2 -r1.244 fd.c
--- fd.c	11 Jan 2003 20:10:41 -0000	1.244
+++ fd.c	11 Jan 2003 21:02:32 -0000
@@ -2623,12 +2788,22 @@
 	 * FD_NONBLOCK still being set.
 	 */
-	switch (cmd) {
+#ifdef TEST_LABELLING
+	/* XXX only some slice ioctls are non-blocking. */
+	error = dsioctl(dev, cmd, addr, flag, &fd->slices);
+	if (error != ENOIOCTL)
+		return (error);
+#endif

+	switch (cmd) {
 	case DIOCGMEDIASIZE:
-		*(off_t *)addr = (128 << (fd->ft->secsize)) * fd->ft->size;
+		if (fd->ft == 0)
+			return (ENXIO);
+		*(off_t *)addr = (128 << fd->ft->secsize) * fd->ft->size;
 		return (0);

 	case DIOCGSECTORSIZE:
-		*(u_int *)addr = 128 << (fd->ft->secsize);
+		if (fd->ft == 0)
+			return (ENXIO);
+		*(u_int *)addr = 128 << fd->ft->secsize;
 		return (0);

%%%

Other changes in this patch:
- local code (TEST_LABELLING).
- fix 2 style bugs (excessive parentheses).

Style bugs in this patch:
- '0' is used for a null pointer constant to give bug for bug compatibility
  with other checks for fd->ft being a null pointer.

Not autoselecting for the O_NONBLOCK case seems to be a feature.
Autoselecting requires even more blocking than does starting the motor,
and it would be just bogus to autoselect for an open whose purpose is
to set the type.

fd->ft may be NULL for other reasons, so the null pointer checks are
needed no matter how O_NONBLOCK is handled.

Bruce



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