[1562] in linux-scsi channel archive

home help back first fref pref prev next nref lref last post

CDROMCLOSETRAY for SCSI broken in 2.1.x

daemon@ATHENA.MIT.EDU (Gerd Knorr)
Fri Mar 14 17:07:40 1997

Date: 	Fri, 14 Mar 1997 22:39:33 +0100
From: Gerd Knorr <kraxel@cs.tu-berlin.de>
To: linux-scsi@vger.rutgers.edu
In-Reply-To: <199703141356.AA11687@rasty.anu.edu.au>


>but now things are borken in that if the drive is open, you can't get a
>file descriptor to issue the CDROMCLOSETRAY ioctl() over, which is a
>bit of a catch-22, as seen below.
>

You can get one if you open the device with O_NONBLOCK. The small program
attached below does the trick.

This is handled by the generic cdrom driver, not the SCSI cdrom driver.

  Gerd

------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <linux/cdrom.h>
#include <linux/ucdrom.h>
#include <sys/ioctl.h>

char *devname = "/dev/cdrom";
int  filehandle;
int  eject = 1;

int
main(int argc, char *argv[])
{
    if (argc > 1) devname = argv[1];

    if (strstr(argv[0],"close"))
	eject = 0;

    filehandle = open(devname,O_RDONLY | O_NONBLOCK);
    if (filehandle == -1) {
	perror("open");
	exit(1);
    }
    if (eject) {
	if (0 != ioctl(filehandle,CDROMEJECT,0)) {
	    perror("ioctl eject");
	    exit(1);
	}
    } else {
	if (0 != ioctl(filehandle,CDROMCLOSETRAY,0)) {
	    perror("ioctl close");
	    exit(1);
	}
    }
    exit(0);
}

home help back first fref pref prev next nref lref last post