/*cdrom.c*/ #include <sys/ioctl.h> #include <linux/cdrom.h> #include <fcntl.h> #define CDROM "/dev/cdrom" /* In all functions 'device' means name of CD-ROM device, * for example /dev/cdrom */ /* Close CD-ROM tray */ int cdclose(char *device) { int fd = open(device, O_RDONLY|O_NONBLOCK); if (fd == -1) return -1; if (ioctl(fd, CDROMCLOSETRAY) == -1) return -1; close(fd); return 0; } /* Eject CD-ROM tray */ int cdeject(char *device) { int fd = open(device, O_RDONLY|O_NONBLOCK); if (fd == -1) return -1; if (ioctl(fd, CDROMEJECT) == -1) return -1; close(fd); return 0; } /* Lock (if lock==1) or unlock (if lock==0) CD-ROM tray */ int cdlock(char *device, int lock) { int fd; fd = open(device, O_RDONLY|O_NONBLOCK); if (fd == -1) return -1; if (ioctl(fd, CDROM_LOCKDOOR, lock) == -1) return -1; close(fd); return 0; } /**********************************************************/ /**********************************************************/ /**********************************************************/ /* Cdrom.i */ %module Cdrom %{ /* Put header files here (optional) */ %} extern int cdclose(char *device); extern int cdeject(char *device); extern int cdlock(char *device, int lock); /**********************************************************/ /**********************************************************/ /**********************************************************/ #cdrom.pl ########################################### #!/usr/bin/perl use Cdrom; #cdclose($device); #cdeject($device); #cdlock($device,$lock); #lock=1 to lock #lock=0 to unlock #cdlock($device,1) $cdrom= '/dev/cdrom'; #$cdrom = '/dev/hdc'; cdeject($cdrom) or die $!; sleep(5); cdclose($cdrom) or die $!; exit (0); ############################################

In reply to cdrom tray control with swig by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.