updated on Sun Jan 15 16:02:00 UTC 2012
[aur-mirror.git] / eject-unlock / eject-2.1.5-lock.patch
blob25f84651ea85d2e5c01a61b360b83520f42da7d8
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
7 --- a/eject.1
8 +++ b/eject.1
9 @@ -17,6 +17,8 @@ eject [\-vn] \-a on|off|1|0 [<name>]
10 .br
11 eject [\-vn] \-c slot [<name>]
12 .br
13 +eject [\-vn] \-i on|off|1|0 [<name>]
14 +.br
15 eject [\-vn] \-t [<name>]
16 .br
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.
21 .TP 0.5i
22 +.B \-i on|1|off|0
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.
28 +.TP 0.5i
29 .B \-t
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.
33 .B \-r
34 This option specifies that the drive should be ejected using a
35 CDROM eject command.
36 -.TP 0.5i
38 +.TP 0.5i
39 .B \-s
40 This option specifies that the drive should be ejected using
41 SCSI commands.
42 @@ -145,7 +154,7 @@ also passes the \-n option to umount(1).
43 .TP 0.5i
44 .B \-m
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
53 --- a/eject.c
54 +++ b/eject.c
55 @@ -116,6 +116,7 @@ int d_option = 0;
56 int f_option = 0;
57 int h_option = 0;
58 int n_option = 0;
59 +int i_option = 0;
60 int q_option = 0;
61 int r_option = 0;
62 int s_option = 0;
63 @@ -129,6 +130,7 @@ int m_option = 0;
64 int a_arg = 0;
65 int c_arg = 0;
66 int x_arg = 0;
67 +int i_arg = 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"
78 "Options:\n"
79 @@ -200,7 +203,7 @@ static void usage()
80 #endif
81 "\n"
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 */
86 fprintf(stderr,_(
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";
94 #ifdef GETOPTLONG
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)
106 usage();
107 exit(0);
108 break;
109 + case 'i':
110 + i_option = 1;
111 + if (!strcmp(optarg, "0"))
112 + i_arg = 0;
113 + else if (!strcmp(optarg, "off"))
114 + i_arg = 0;
115 + else if (!strcmp(optarg, "1"))
116 + i_arg = 1;
117 + else if (!strcmp(optarg, "on"))
118 + i_arg = 1;
119 + else {
120 + fprintf(stderr, _("%s: invalid argument to -i option\n"), programName);
121 + exit(1);
123 + break;
124 case 'm':
125 m_option = 1;
126 break;
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
141 + */
142 +static void ManualEject(int fd, int onOff)
144 + if (ioctl(fd, CDROM_LOCKDOOR, onOff) < 0) {
145 + perror("ioctl on CDROM_LOCKDOOR");
146 + } else {
147 + if (onOff)
148 + printf("CD-Drive may NOT be ejected with device button\n");
149 + else
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)
159 exit(0);
162 + /* handle -i option */
163 + if (i_option) {
164 + fd = OpenDevice(deviceName);
165 + ManualEject(fd, i_arg);
166 + exit(0);
169 /* handle -a option */
170 if (a_option) {
171 if (v_option) {