cd status

  • Thread starter Richard Neuboeck
  • Start date
R

Richard Neuboeck

Hi!

I'm trying to get some status information from my CDRW-drive and
CD-drive. In detail I would like to know whether a CD is inserted, what
kind of CD it is or if it's blank. I'm using perls ioctl function like this:

#!/usr/bin/perl
open (CD, "/dev/cdrom") || die "Can not access /dev/cdrom: $!";
$retval1 = ioctl(CD, 0x5326, 0); # CDROM_DRIVE_STATUS
$retval2 = ioctl(CD, 0x5327, 0); # CDROM_DISC_STATUS
$retval3=0;
$retval4 = ioctl(CD, 0x5305, \$retval3); # CDROMREADTOCHDR
close (CD);
#and some interpretation of the return values

This works fine with non blank CDs. If I insert a blank CD I can only
run this script once. Then I'm getting the following error message:
"Can not access /dev/cdrom: No medium found". At this point I can't even
use the tray-open script to eject the CD because the device can't be opened.

#!/usr/bin/perl
open (CD, "/dev/cdrom") || die "Can not access /dev/cdrom: $!";
ioctl(CD, 0x5309, 0);
close(CD);

Still working though is the eject C program which doesn't have a problem
opening the cdrom device. I still don't get it why perl is refusing to
open the device file more than once if a blank CD is inserted?
Am I doing something wrong?
Is there a better way to obtain some status information from the CD-drive?

Thanks in advance!
Richard

PS: By the way I tested the above scripts on RH9 (perl-5.8.0-88.3) with
an ATAPI CD-drive and on Debian/testing (perl-base 5.8.3-2) with a SCSI
CD-writer and SCSI CD-drive with the same results.
 
B

Brian McCauley

Richard Neuboeck said:
This works fine with non blank CDs. If I insert a blank CD I can only
run this script once. Then I'm getting the following error message:
"Can not access /dev/cdrom: No medium found". At this point I can't
even use the tray-open script to eject the CD because the device can't
be opened.

#!/usr/bin/perl
open (CD, "/dev/cdrom") || die "Can not access /dev/cdrom: $!";
ioctl(CD, 0x5309, 0);
close(CD);

Still working though is the eject C program which doesn't have a
problem opening the cdrom device. I still don't get it why perl is
refusing to open the device file more than once if a blank CD is
inserted?

Stracing the eject program reveals that it uses open mode
O_RDONLY|O_NONBLOCK.

Perhaps you should try a sysopen() with that mode.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
R

Richard Neuboeck

Brian said:
Perhaps you should try a sysopen() with that mode.

Thanks a lot!
sysopen(CD, /dev/cdrom, O_RDONLY | O_NONBLOCK) solved my problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top