From tamrin@shinzan.kuee.kyoto-u.ac.jp  Wed Oct 14 08:24:02 1998
Received: from shinzan.kuee.kyoto-u.ac.jp (shinzan.kuee.kyoto-u.ac.jp [130.54.28.246])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA06256
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 14 Oct 1998 08:24:01 -0700 (PDT)
          (envelope-from tamrin@shinzan.kuee.kyoto-u.ac.jp)
Received: (from tamrin@localhost)
	by shinzan.kuee.kyoto-u.ac.jp (8.8.8/8.8.8) id AAA12060;
	Thu, 15 Oct 1998 00:23:40 +0900 (JST)
	(envelope-from tamrin)
Message-Id: <199810141523.AAA12060@shinzan.kuee.kyoto-u.ac.jp>
Date: Thu, 15 Oct 1998 00:23:40 +0900 (JST)
From: tamrin@kuee.kyoto-u.ac.jp
Reply-To: tamrin@shinzan.kuee.kyoto-u.ac.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject: [ATAPI CD-ROM] open() doesn't return -1 when no CDs in drive.
X-Send-Pr-Version: 3.2

>Number:         8316
>Category:       kern
>Synopsis:       [ATAPI CD-ROM] open() doesn't return -1 when no CDs in drive.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 14 08:30:01 PDT 1998
>Closed-Date:    Sun Dec 13 15:27:37 PST 1998
>Last-Modified:  Sun Dec 13 15:30:31 PST 1998
>Originator:     Masatoshi TAMURA
>Release:        FreeBSD 2.2.7-RELEASE i386
>Organization:
Kyoto Univ.
>Environment:

OS Version:    2.2.7-RELEASE
ATAPI CD-ROM:  TEAC CD-524EA (Secondary Master)
M/B:           GigaByte GA-586ATX3

: wdc1 at 0x170-0x177 irq 15 on isa
: wdc1: unit 0 (atapi): <CD-524EA/3.0A>, removable, accel, ovlap, dma, iordis
: wcd0: 4134Kb/sec, 128Kb cache, audio play, 16 volume levels, ejectable tray
: wcd0: no disc inside, unlocked

>Description:

  I think, for SCSI CD driver compatible, open() system call for 
"/dev/[r]wcd0c" should return -1 if no CD is in the drive.
But open("/dev/rwcd0c",..) return a positive number such case.
Open() seems to success, but no ioctl() request is accepted by
returned file descriptor.

>How-To-Repeat:

  Run the next program with no CD in drive.
  You will see "open success(fd=3)", and kernel message 
"wcd0: cannot read audio disc" in cosole.

-----
#include <stdio.h>
#include <fcntl.h>

main()
{
    int fd;

    if ((fd = open("/dev/rwcd0c", O_RDONLY)) < 0)
	printf("open fail\n");
    else
	printf("open success(fd=%d)\n", fd);

    return 0;
}
-----

>Fix:

patch for /sys/i386/isa/wcd.c

function wcd_read_toc() will return only 0 or EIO(this is defined to 5).
So "wcd_read_toc (t) < 0" is always FALSE.
	
--- /sys/i386/isa/wcd.c.original	Tue Jul  7 14:23:28 1998
+++ /sys/i386/isa/wcd.c	Fri Oct  9 14:11:30 1998
@@ -420,7 +420,7 @@
 	/* On the first open, read the table of contents. */
 	if (! (t->flags & F_BOPEN) && ! t->refcnt) {
 		/* Read table of contents. */
-		if (wcd_read_toc (t) < 0)
+		if (wcd_read_toc (t) != 0)
 			return (EIO);
 
 		/* Lock the media. */
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: steve 
State-Changed-When: Sun Dec 13 15:27:37 PST 1998 
State-Changed-Why:  
Patch committed, thanks! 
>Unformatted:
