cd status

Discussion in 'Perl Misc' started by Richard Neuboeck, Apr 2, 2004.

  1. 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.
    Richard Neuboeck, Apr 2, 2004
    #1
    1. Advertising

  2. Richard Neuboeck <> writes:

    > 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\\
    Brian McCauley, Apr 2, 2004
    #2
    1. Advertising

  3. Brian McCauley wrote:
    > Perhaps you should try a sysopen() with that mode.


    Thanks a lot!
    sysopen(CD, /dev/cdrom, O_RDONLY | O_NONBLOCK) solved my problems.
    Richard Neuboeck, Apr 2, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. saha
    Replies:
    0
    Views:
    4,036
  2. Shug
    Replies:
    13
    Views:
    888
    Philipp
    Dec 15, 2006
  3. Shug
    Replies:
    13
    Views:
    942
    Philipp
    Dec 15, 2006
  4. harryos
    Replies:
    0
    Views:
    372
    harryos
    Oct 13, 2010
  5. Sven S.

    status info like rc.status

    Sven S., Dec 9, 2008, in forum: Ruby
    Replies:
    2
    Views:
    168
    Sven S.
    Dec 11, 2008
Loading...

Share This Page