Re: How to lock an optical drive tray closed?

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

 



On 07-11-07 09:19, Steve R. Hastings wrote:

Hello.  I'm trying to figure out how to lock the tray of an optical
drive, so that the drive will not open the tray when the user presses
the hardware "eject" button on the drive.

This seems straightforward, because there is a well-documented list of
IOCTLs for optical drive control, and one of them is CDROM_LOCKDOOR.
(See Edward A. Falk's "cdrom.txt" doc file, and
also /usr/include/linux/cdrom.h.)

However, in my tests, the drive still ejects the disk even when I use
the CDROM_LOCKDOOR IOCTL to lock it.

Works for me on a pata/sr driven CD-ROM and DVD. The description sort of makes it sound like the ioctl is a toggle, so are you perhaps not passing the 1/0 lock/unlock argument?

Rene.

/* gcc - W -Wall -o lock lock.c */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

#include <linux/cdrom.h>

int main(int argc, char *argv[])
{
	int i, lock = 1;

	while ((i = getopt(argc, argv, "u")) != -1) {
	       if (i != 'u')
		       goto usage;
	       lock = 0;
	}
	if (optind >= argc) {
usage:		
		fprintf(stderr, "usage: %s [-u] <device>\n", argv[0]);
		return EXIT_FAILURE;
	}

	i = open(argv[optind], O_RDONLY);
	if (i < 0) {
		perror("open");
		return EXIT_FAILURE;
	}
	if (ioctl(i, CDROM_LOCKDOOR, lock) < 0) {
		perror("ioctl");
		return EXIT_FAILURE;
	}
	if (close(i) < 0) {
		perror("close");
		return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
}

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux