October 2014
M T W T F S S
« Mar    
 12345
6789101112
13141516171819
20212223242526
2728293031  
137

Refs

Categories

Archives

profile for slm on Stack Exchange, a network of free, community-driven Q&A sites

[one-liner]: Locking the Eject Button on a CD/DVD Drive Under Fedora 14/CentOS 5 on a Laptop

Background

My kids are constantly trying to touch my laptop. They’ve especially become obsessed with the eject button on my CD/DVD drive. So I started looking for a way to enable/disable the button so that they would hopefully stop trying to eject it all the time.

Solution

You might want to try out cdctl. It’s available here. This switch, -oS, will accomplish the task of locking/unlocking the CD/DVD drive.

1
2
3
    -oS, --lockdoor=S
     Locks the eject button so the disc cannot be manually ejected.  Requires  kernel version 2.2.4 
     or newer.  Set S to 0 to unlock the drive, and to 1 to lock it.

I’ve used this for the last 10 years on Fedora, RHEL, CentOS but the package is available as a tarball and should be compilable on Ubuntu. NOTE: The package hasn’t been updated in a while but it works fine. There’s a patch available on Gentoo’s site that fixes a small issue so that it can be compiled with more recent kernels (>2.4+). The patch is available here on the Gentoo bug tracker site.

The patch, cdctl-0.15-cdc_ioctls.patch:

1
2
3
4
5
6
7
8
9
10
11
12
13
diff -Naurp cdctl-0.15-orig/cdctl.c cdctl-0.15/cdctl.c
--- cdctl-0.15-orig/cdctl.c	2006-08-08 23:18:44.000000000 +0200
+++ cdctl-0.15/cdctl.c	2006-08-08 23:19:33.000000000 +0200
@@ -337,7 +337,9 @@ int do_print_capabilities(int cdrom) {
 	printf("Can report media change: %i\n", (ret & CDC_MEDIA_CHANGED)?1:0);
 	printf("Can play audio discs   : %i\n", (ret & CDC_PLAY_AUDIO)?1:0);
 	printf("Can do a hard reset    : %i\n", (ret & CDC_RESET)?1:0);
+#ifdef CDC_IOCTLS
 	printf("Has non-standard ioctls: %i\n", (ret & CDC_IOCTLS)?1:0);
+#endif
 	printf("Can report drive status: %i\n", (ret & CDC_DRIVE_STATUS)?1:0);
 
 #ifdef CDROM_CHANGER_NSLOTS

Once you’ve compiled/installed it you can use these commands to lock & unlock the cd tray:

1
2
3
4
5
# locks the tray
% cdctl -o1
 
# unlocks the tray
% cdctl -o0

cdctl can do a whole lot more than just lock/unlock the CD/DVD drive. Here’s a list of all the switches it provides. They’re pretty self explanatory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-a     --pause         pAuse the cdrom currently playing
-bS    --speed=S       Ask the drive to spin the disc at speed S
-c     --close         Close the cd tray if possible
-dD    --disc=D        select Disc D for a cd-changer
-e     --eject         Eject the cd, cd tray, or cd cartridge
-g     --getstatus     Get and print type/status of the cd in the drive
-h     --help          print this Help message
-i     --iso-header    print interesting Iso 9660 header data
-k     --capabilities  Print out all the things your drive can do
-l     --list          List the entire table of contents
-m     --mcn           print MCN (or UPC) of the cd in the drive
-oA    --lockdoor=A    lOck or unlock the eject button
-pT    --play=T        Play track T
-r     --resume        Resume playing
-s     --stop          Stop playing
-tT    --tocentry=T    print the Table of contents entry for track T
-uA    --automount=A   set aUtomount bits to A
-vV    --volume=V      set Volume to V
-V     --version       print Version

For your convenience I’m also providing a Fedora 14 RPM along with the SRPM so that others can rebuild this package if they so desire.

Here are the same executables packaged for Debian/Ubuntu. I packaged these on Ubuntu 12.10.

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>