Re: CDROM: Hardware tray movement detection

Gerd Knorr (kraxel@goldbach.isdn.cs.tu-berlin.de)
Wed, 27 Aug 1997 10:04:07 +0200


In article <199708270037.UAA02250@defiant.interpath.net>, you wrote:
>Letting the chips fall where they may, I quote Tim P. Gerla:
>>My question:
>>
>>Is there any way to detect *hardware* tray movement, and afterward, detect
>>a disk change?
>
>I'm sure there the drive will generate any async event to notify you of a
>disk being inserted -- well, some SCSI drives might.

No. SCSI does'nt send async events. You'll get back a "error" and
UNIT ATTENTION as sense code if there was a disk change since the last
scsi command. The scsi error code looks like this:

if ((SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
scsi_CDs[DEVICE_NR(SCpnt->request.rq_dev)].device->changed = 1;

IDE cdrom drives probably work the same way, ATAPI and SCSI are not
very different (you even can drive the IDE cdrom with the SCSI cdrom
driver if you disable the IDE-CD driver and enable the IDE SCSI emulation
support - requires pre7 / 2.1.x).

>Once auto media change detection is available, all sorts of things become
>possible. I, for one, have a drive that closes the tray when polled, so
>workman is constantly closing the drive while I'm change the CD -- not good.

Probably is'nt the drive, but linux. Most drivers close the tray if you
open the device. But I don't know how workman polls (could do with open
or ioctl).

Gerd