[ltp] Detecting CDs (is there a disc in the cdrom drive ?)

Matt Graham linux-thinkpad@linux-thinkpad.org
Sun, 29 Jan 2006 12:51:13 -0500


From: Richard Neill <rn214@hermes.cam.ac.uk>
> I'm trying to write an acpi script for an X22 ultrabase.
> I need to know whether there is a CD or DVD in the drive at the time.
> Is there any easy way to find out?

Sure, but you can't really do it via the shell.  You have to open() the C=
D-R*
device with O_NONBLOCK and perform an ioctl() on it.  This is easily done=
 with
a short C program or a Perl script.  Go to
http://groups.google.com/advanced_group_search and put the string
slrncqvbdd.79u.danSPANceswitTRAPhcrows@samantha.crow202.dyndns.org into t=
he
"find messages with this Message-ID" field, then push "lookup message".  =
Read
the whole thread; the message shows how to do it in C, but you can also d=
o it
in Perl without much effort.  The code written returns messages to stdout=
,
while you probably will want to modify it so that it returns status codes=
 and
doesn't print anything.  HTH,



-- =

Matt G / Dances With Crows
There is no Darkness in Eternity/But only Light too dim for us to see
"I backed up my brain to tape, but tar says the tape contains no data....=
"