From rfg@monkeys.com Wed Oct 27 16:54:14 1999
Return-Path: <rfg@monkeys.com>
Received: from monkeys.com (i180.value.net [206.14.136.180])
	by hub.freebsd.org (Postfix) with ESMTP id 24E0C14E2D
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 27 Oct 1999 16:52:36 -0700 (PDT)
	(envelope-from rfg@monkeys.com)
Received: (from rfg@localhost)
	by monkeys.com (8.9.3/8.9.3) id QAA63935;
	Wed, 27 Oct 1999 16:52:28 -0700 (PDT)
Message-Id: <199910272352.QAA63935@monkeys.com>
Date: Wed, 27 Oct 1999 16:52:28 -0700 (PDT)
From: "Ronald F. Guilmette" <rfg@monkeys.com>
Reply-To: rfg@monkeys.com (Ronald F. Guilmette)
To: FreeBSD-gnats-submit@freebsd.org
Subject: ioctl (fd, CDIOCEJECT, (void*) 0) doesn't work, even on SCSI CD drives
X-Send-Pr-Version: 3.2

>Number:         14561
>Category:       kern
>Synopsis:       ioctl (fd, CDIOCEJECT, (void*) 0) doesn't work
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ken
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 27 17:00:01 PDT 1999
>Closed-Date:    Wed Oct 05 06:22:28 GMT 2005
>Last-Modified:  Wed Oct 05 06:22:28 GMT 2005
>Originator:     Ronald F. Guilmette
>Release:        FreeBSD 3.3-RELEASE i386
>Organization:
E-Scrub Technologies, Inc.
>Environment:

>Description:

	Calling ioctl (fd, CDIOCEJECT, (void*) 0) from within a C program
	for an `fd' value which is an open file descriptor for a SCSI CDROM
	drive that *does* have eject capabilities and that *does* currently
	contain a loaded CD fails to cause the drive to perform the eject
	operation, and the call returns with a negative (-1?) result and
	with ERRNO set to the mysterious and uninformative value of `EIO'
	(``Input/output error'').

>How-To-Repeat:

	Compile and run the following trivial program giving it "/dev/cd0c"
	as its one and only command line argument.  Execute the program
	_only_ on a system with a SCSI CDROM drive that has programmed
	ejection capability, and only when there is already a CD loaded
	in the drive.  (I also tried specifying "/dev/rcd0c" and also
	"/dev/cd0a" and even "/dev/rcd0a" and none of these worked any
	better.)

	--------------------------------------------------------------------
	/* eject.c - program for FreeBSD to eject a CD */
	/* Usage:
		eject [device]
	*/
	/* Copyright (c) 1999 Ronald F. Guilmette; all rights reserved. */
	
	#include <stdio.h>
	#include <errno.h>
	#include <string.h>
	#include <fcntl.h>
	#include <unistd.h>
	#include <sys/cdio.h>
	
	static char const *pname;
	
	int
	main (register int const argc, register char const **argv)
	{
	  register int ifd;
	  register char const *filename;
	
	  pname = strrchr (argv[0], '/');
	  pname = pname ? pname + 1 : argv[0];
	
	  filename = argv[1];
	
	  if ((ifd = open (filename, O_RDONLY)) == -1)
	    {
	      fprintf (stderr, "%s: Error opening `%s': %s\n",
		       pname, filename, strerror (errno));
	      return 1;
	    }
	  if (ioctl (ifd, CDIOCEJECT, (void*) 0) == -1)
	    {
	      fprintf (stderr, "%s: Error opening `%s': %s\n",
		       pname, filename, strerror (errno));
	      return 1;
	    }
	  close (ifd);
	  return 0;
	}
	--------------------------------------------------------------------

>Fix:

	Manually eject the CD.  (Difficult, if you are not physically adjacent
	to it.)


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: ken 
State-Changed-When: Wed Oct 27 17:09:28 PDT 1999 
State-Changed-Why:  
This is a known problem, we're working on a fix.  Yes, it is more complicated than it appears.   
Until we get a fix, try using 'camcontrol eject cd0' to eject your CD. 


Responsible-Changed-From-To: freebsd-bugs->ken 
Responsible-Changed-By: ken 
Responsible-Changed-When: Wed Oct 27 17:09:28 PDT 1999 
Responsible-Changed-Why:  
My driver. 
State-Changed-From-To: analyzed->feedback 
State-Changed-By: ken 
State-Changed-When: Mon Mar 3 11:08:02 PST 2003 
State-Changed-Why:  
The program in question should issue the CDIOCALLOW ioctl before issuing 
the CDIOCEJECT ioctl.  CDs are locked in the drive on open(), so you need 
to allow removal before you can eject them. 

If you do that, things should work okay. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=14561 
State-Changed-From-To: feedback->closed 
State-Changed-By: rodrigc 
State-Changed-When: Wed Oct 5 06:22:12 GMT 2005 
State-Changed-Why:  
Feedback timeout 

http://www.freebsd.org/cgi/query-pr.cgi?pr=14561 
>Unformatted:
