1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
eject.1 | 13 +++++++++++--
eject.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 63 insertions(+), 4 deletions(-)
diff --git a/eject.1 b/eject.1
index 3c388c6..315dc6d 100644
--- a/eject.1
+++ b/eject.1
@@ -17,6 +17,8 @@ eject [\-vn] \-a on|off|1|0 [<name>]
.br
eject [\-vn] \-c slot [<name>]
.br
+eject [\-vn] \-i on|off|1|0 [<name>]
+.br
eject [\-vn] \-t [<name>]
.br
eject [\-vn] \-T [<name>]
@@ -83,6 +85,13 @@ for a change request to work. Please also note that the first slot of
the changer is referred to as 0, not 1.
.TP 0.5i
+.B \-i on|1|off|0
+This option controls locking of the hardware eject button. When
+enabled, the drive will not be ejected when the button is pressed.
+This is useful when you are carrying a laptop in a bag or case and
+don't want it to eject if the button is inadvertently pressed.
+
+.TP 0.5i
.B \-t
With this option the drive is given a CD-ROM tray close command. Not
all devices support this command.
@@ -121,8 +130,8 @@ performed.
.B \-r
This option specifies that the drive should be ejected using a
CDROM eject command.
-.TP 0.5i
+.TP 0.5i
.B \-s
This option specifies that the drive should be ejected using
SCSI commands.
@@ -145,7 +154,7 @@ also passes the \-n option to umount(1).
.TP 0.5i
.B \-m
This option allows eject to work with device drivers which automatically
-mount removable media and therefore must be always mount()ed.
+mount removable media and therefore must be always mount(1)ed.
The option tells eject to not try to unmount the given device,
even if it is mounted according to /etc/mtab or /proc/mounts.
diff --git a/eject.c b/eject.c
index f7b2a2e..4175756 100644
--- a/eject.c
+++ b/eject.c
@@ -116,6 +116,7 @@ int d_option = 0;
int f_option = 0;
int h_option = 0;
int n_option = 0;
+int i_option = 0;
int q_option = 0;
int r_option = 0;
int s_option = 0;
@@ -129,6 +130,7 @@ int m_option = 0;
int a_arg = 0;
int c_arg = 0;
int x_arg = 0;
+int i_arg = 0;
static char *programName; /* used in error messages */
/*
@@ -163,6 +165,7 @@ static void usage()
" eject [-vn] -c <slot> [<name>] -- switch discs on a CD-ROM changer\n"
" eject [-vn] -t [<name>] -- close tray\n"
" eject [-vn] -T [<name>] -- toggle tray\n"
+" eject [-vn] -i on|off|1|0 [<name>] -- toggle manual eject protection on/off\n"
" eject [-vn] -x <speed> [<name>] -- set CD-ROM max speed\n"
" eject [-vn] -X [<name>] -- list CD-ROM available speeds\n"
"Options:\n"
@@ -200,7 +203,7 @@ static void usage()
#endif
"\n"
" -n --noop -V --version\n"
-" -p --proc -m --no-unmount -T --traytoggle\n"));
+" -p --proc -m --no-unmount -T --traytoggle -i --manualeject\n"));
#endif /* GETOPTLONG */
fprintf(stderr,_(
"Parameter <name> can be a device file or a mount point.\n"
@@ -214,7 +217,7 @@ static void usage()
/* Handle command line options. */
static void parse_args(int argc, char **argv, char **device)
{
- const char *flags = "a:c:x:dfhnqrstTXvVpm";
+ const char *flags = "a:c:x:i:dfhnqrstTXvVpm";
#ifdef GETOPTLONG
static struct option long_options[] =
{
@@ -223,6 +226,7 @@ static void parse_args(int argc, char **argv, char **device)
{"default", no_argument, NULL, 'd'},
{"auto", required_argument, NULL, 'a'},
{"changerslot", required_argument, NULL, 'c'},
+ {"manualeject", required_argument, NULL, 'i'},
{"trayclose", no_argument, NULL, 't'},
{"traytoggle", no_argument, NULL, 'T'},
{"cdspeed", required_argument, NULL, 'x'},
@@ -297,6 +301,21 @@ static void parse_args(int argc, char **argv, char **device)
usage();
exit(0);
break;
+ case 'i':
+ i_option = 1;
+ if (!strcmp(optarg, "0"))
+ i_arg = 0;
+ else if (!strcmp(optarg, "off"))
+ i_arg = 0;
+ else if (!strcmp(optarg, "1"))
+ i_arg = 1;
+ else if (!strcmp(optarg, "on"))
+ i_arg = 1;
+ else {
+ fprintf(stderr, _("%s: invalid argument to -i option\n"), programName);
+ exit(1);
+ }
+ break;
case 'm':
m_option = 1;
break;
@@ -482,6 +501,30 @@ static char *FindDevice(const char *name)
}
+/*
+ * Stops CDROM from opening on manual eject pressing the button.
+ * This can be useful when you carry your laptop
+ * in your bag while it's on and no CD inserted in it's drive.
+ * Implemented as found in Documentation/ioctl/cdrom.txt
+ *
+ * TODO: Maybe we should check this also:
+ * EDRIVE_CANT_DO_THIS Door lock function not supported.
+ * EBUSY Attempt to unlock when multiple users
+ * have the drive open and not CAP_SYS_ADMIN
+ */
+static void ManualEject(int fd, int onOff)
+{
+ if (ioctl(fd, CDROM_LOCKDOOR, onOff) < 0) {
+ perror("ioctl on CDROM_LOCKDOOR");
+ } else {
+ if (onOff)
+ printf("CD-Drive may NOT be ejected with device button\n");
+ else
+ printf("CD-Drive may be ejected with device button\n");
+ }
+}
+
+
/* Set or clear auto-eject mode. */
static void AutoEject(int fd, int onOff)
{
@@ -1233,6 +1276,13 @@ int main(int argc, char **argv)
exit(0);
}
+ /* handle -i option */
+ if (i_option) {
+ fd = OpenDevice(deviceName);
+ ManualEject(fd, i_arg);
+ exit(0);
+ }
+
/* handle -a option */
if (a_option) {
if (v_option) {
|