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.
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.