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

Richard Neill linux-thinkpad@linux-thinkpad.org
Sun, 29 Jan 2006 18:03:00 +0000


Matt Graham wrote:
> 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 CD-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 the
> "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 do 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,
> 

Thanks. That's extremely helpful. I'm slightly surprised that there 
isn't a way to get this info out of /proc though. After all, everything 
else is in there!

Best wishes,

Richard






> 
> 

-- 
rn214@hermes.cam.ac.uk  **  http://www.richardneill.org
Richard Neill, Trinity College, Cambridge, CB21TQ, U.K.