Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Checking if a CD is in a drive and it is blank?

by ghenry (Vicar)
on Feb 02, 2006 at 13:27 UTC ( [id://527325]=perlquestion: print w/replies, xml ) Need Help??

ghenry has asked for the wisdom of the Perl Monks concerning the following question:

Update: Sorry, no context what so ever.

This is on Linux and I am just after an example.

Just a quickie guys...

Can this be done in Perl or via system?

I am stumped.

Gavin.

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!

Replies are listed 'Best First'.
Re: Checking if a Cd is in a drive and is blank?
by Fletch (Bishop) on Feb 02, 2006 at 13:50 UTC

    Yes.

    But then again given the correct command to run via system that's true for pretty much anything. Of course since you've given zero context as to platform and OS no one's going to be able to give you anything more than vague hints (possibly involving cdrecord for Linux and BSDen).

Re: Checking if a CD is in a drive and it is blank?
by zentara (Archbishop) on Feb 02, 2006 at 16:10 UTC
    Here is something using Inline::C to use ioctl. cdromp You probably can access directly with sysopen
    #!/usr/bin/perl # read man ioctl_list for hex codes # read /usr/include/linux/cdrom.h for cd codes use Fcntl; sysopen my $f, "/dev/sr0", O_RDONLY|O_NONBLOCK or die "open $?"; ioctl $f, 0x5329, 0 or die "ioctl $!"; # 0 unlocks 1 locks door ioctl $f, 0x5309, 0 or die "ioctl $!"; # open tray ioctl $f, 0x5319, 0 or die "ioctl $!"; #close tray

    You can detect whether there is a cd in the tray, and try to mount it, and see if it contains any data. The thing is, it can be formatted a variety of ways, a cd dosn't have to be iso9660.

    Also see in the perlfaq, "perldoc -q ioctl".

    8.21: Where do I get the include files to do ioctl() or syscall()?

    Running cdrecord with some options may tell you if the cd is blank.


    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://527325]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found