[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: (Child) Locking the CD tray in software



On Wednesday 16 Feb 2005 18:01, Nazri Ramliy wrote:
> Hi list.
>
> My 15 months old amuses himself by opening and closing the CDROM tray
> on my box by pressing the eject button, waits for the tray to come
> out, then  pushes it back in.  He does this over and over.
>>cut
>
> Anybody know of any cd tools to keep the tray closed, i.e.  ignoring
> the signal from the eject button?

This little bit of code sends the right ioctl to lock the tray of /dev/cdrom. 

To compile save into a file "blah.c" and run gcc -o lock blah.c

#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/cdrom.h>

int main()
{
        int fd = open("/dev/cdrom", O_RDONLY|O_NONBLOCK);
        if (fd == -1) { return -1; }

 int lock = 1;   # change to 1 to unlock       

        if (ioctl(fd, CDROM_LOCKDOOR, lock) == -1) { return -1; }
        close(fd);
        return 0;

}


Regards 
Rob

-- 
Robert Wood <rob@rnwood.co.uk>
http://www.rnwood.co.uk/

 "If you can't make something good,
  make something look good." - Bill Gates



Reply to: