From owner-freebsd-bugs@FreeBSD.ORG Sat May 17 00:20:18 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9E62E37B439 for ; Sat, 17 May 2003 00:20:17 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4FB3743F3F for ; Sat, 17 May 2003 00:20:15 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h4H7KEUp047383 for ; Sat, 17 May 2003 00:20:14 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h4H7KELq047382; Sat, 17 May 2003 00:20:14 -0700 (PDT) Date: Sat, 17 May 2003 00:20:14 -0700 (PDT) Message-Id: <200305170720.h4H7KELq047382@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Subject: Re: kern/52338: fd(4) floppy disk driver & non-blocking I/O X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 May 2003 07:20:18 -0000 The following reply was made to PR kern/52338; it has been noted by GNATS. From: Bruce Evans To: Yar Tikhiy Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org Subject: Re: kern/52338: fd(4) floppy disk driver & non-blocking I/O Date: Sat, 17 May 2003 17:18:57 +1000 (EST) 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