1 eject.1 | 13 +++++++++++--
2 eject.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 2 files changed, 63 insertions(+), 4 deletions(-)
5 diff --git a/eject.1 b/eject.1
6 index 3c388c6..315dc6d 100644
9 @@ -17,6 +17,8 @@ eject [\-vn] \-a on|off|1|0 [<name>]
11 eject [\-vn] \-c slot [<name>]
13 +eject [\-vn] \-i on|off|1|0 [<name>]
15 eject [\-vn] \-t [<name>]
17 eject [\-vn] \-T [<name>]
18 @@ -83,6 +85,13 @@ for a change request to work. Please also note that the first slot of
19 the changer is referred to as 0, not 1.
23 +This option controls locking of the hardware eject button. When
24 +enabled, the drive will not be ejected when the button is pressed.
25 +This is useful when you are carrying a laptop in a bag or case and
26 +don't want it to eject if the button is inadvertently pressed.
30 With this option the drive is given a CD-ROM tray close command. Not
31 all devices support this command.
32 @@ -121,8 +130,8 @@ performed.
34 This option specifies that the drive should be ejected using a
40 This option specifies that the drive should be ejected using
42 @@ -145,7 +154,7 @@ also passes the \-n option to umount(1).
45 This option allows eject to work with device drivers which automatically
46 -mount removable media and therefore must be always mount()ed.
47 +mount removable media and therefore must be always mount(1)ed.
48 The option tells eject to not try to unmount the given device,
49 even if it is mounted according to /etc/mtab or /proc/mounts.
51 diff --git a/eject.c b/eject.c
52 index f7b2a2e..4175756 100644
55 @@ -116,6 +116,7 @@ int d_option = 0;
63 @@ -129,6 +130,7 @@ int m_option = 0;
68 static char *programName; /* used in error messages */
71 @@ -163,6 +165,7 @@ static void usage()
72 " eject [-vn] -c <slot> [<name>] -- switch discs on a CD-ROM changer\n"
73 " eject [-vn] -t [<name>] -- close tray\n"
74 " eject [-vn] -T [<name>] -- toggle tray\n"
75 +" eject [-vn] -i on|off|1|0 [<name>] -- toggle manual eject protection on/off\n"
76 " eject [-vn] -x <speed> [<name>] -- set CD-ROM max speed\n"
77 " eject [-vn] -X [<name>] -- list CD-ROM available speeds\n"
79 @@ -200,7 +203,7 @@ static void usage()
82 " -n --noop -V --version\n"
83 -" -p --proc -m --no-unmount -T --traytoggle\n"));
84 +" -p --proc -m --no-unmount -T --traytoggle -i --manualeject\n"));
85 #endif /* GETOPTLONG */
87 "Parameter <name> can be a device file or a mount point.\n"
88 @@ -214,7 +217,7 @@ static void usage()
89 /* Handle command line options. */
90 static void parse_args(int argc, char **argv, char **device)
92 - const char *flags = "a:c:x:dfhnqrstTXvVpm";
93 + const char *flags = "a:c:x:i:dfhnqrstTXvVpm";
95 static struct option long_options[] =
97 @@ -223,6 +226,7 @@ static void parse_args(int argc, char **argv, char **device)
98 {"default", no_argument, NULL, 'd'},
99 {"auto", required_argument, NULL, 'a'},
100 {"changerslot", required_argument, NULL, 'c'},
101 + {"manualeject", required_argument, NULL, 'i'},
102 {"trayclose", no_argument, NULL, 't'},
103 {"traytoggle", no_argument, NULL, 'T'},
104 {"cdspeed", required_argument, NULL, 'x'},
105 @@ -297,6 +301,21 @@ static void parse_args(int argc, char **argv, char **device)
111 + if (!strcmp(optarg, "0"))
113 + else if (!strcmp(optarg, "off"))
115 + else if (!strcmp(optarg, "1"))
117 + else if (!strcmp(optarg, "on"))
120 + fprintf(stderr, _("%s: invalid argument to -i option\n"), programName);
127 @@ -482,6 +501,30 @@ static char *FindDevice(const char *name)
132 + * Stops CDROM from opening on manual eject pressing the button.
133 + * This can be useful when you carry your laptop
134 + * in your bag while it's on and no CD inserted in it's drive.
135 + * Implemented as found in Documentation/ioctl/cdrom.txt
137 + * TODO: Maybe we should check this also:
138 + * EDRIVE_CANT_DO_THIS Door lock function not supported.
139 + * EBUSY Attempt to unlock when multiple users
140 + * have the drive open and not CAP_SYS_ADMIN
142 +static void ManualEject(int fd, int onOff)
144 + if (ioctl(fd, CDROM_LOCKDOOR, onOff) < 0) {
145 + perror("ioctl on CDROM_LOCKDOOR");
148 + printf("CD-Drive may NOT be ejected with device button\n");
150 + printf("CD-Drive may be ejected with device button\n");
155 /* Set or clear auto-eject mode. */
156 static void AutoEject(int fd, int onOff)
158 @@ -1233,6 +1276,13 @@ int main(int argc, char **argv)
162 + /* handle -i option */
164 + fd = OpenDevice(deviceName);
165 + ManualEject(fd, i_arg);
169 /* handle -a option */