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
|
Add support for toggling the cdrom.
Patch by Patrik Kullman.
http://bugs.gentoo.org/62612
Note: this requires the no-umount.patch be applied first
or the 4th and 5th hunks will fail.
--- eject.c
+++ eject.c
@@ -51,6 +51,7 @@
#endif /* GETOPTLONG */
#include <errno.h>
#include <regex.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@@ -79,6 +80,7 @@
int r_option = 0;
int s_option = 0;
int t_option = 0;
+int T_option = 0;
int v_option = 0;
int x_option = 0;
int p_option = 0;
@@ -118,11 +120,13 @@
" eject [-vn] -a on|off|1|0 [<name>] -- turn auto-eject feature on or off\n"
" 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 status (EXPERIMENTAL)\n"
" eject [-vn] -x <speed> [<name>] -- set CD-ROM max speed\n"
"Options:\n"
" -v\t-- enable verbose output\n"
" -n\t-- don't eject, just show device found\n"
" -r\t-- eject CD-ROM\n"
+" -T\t-- toggle tray status (EXPERIMENTAL)"
" -s\t-- eject SCSI device\n"
" -f\t-- eject floppy\n"
" -q\t-- eject tape\n"
@@ -135,7 +139,7 @@
" -a --auto -c --changerslot -t --trayclose -x --cdspeed\n"
" -r --cdrom -s --scsi -f --floppy\n"
" -q --tape -n --noop -V --version\n"
-" -p --proc -m --no-unmount\n"));
+" -p --proc -m --no-unmount -T --toggletray\n"));
#endif /* GETOPTLONG */
fprintf(stderr,_(
"Parameter <name> can be a device file or a mount point.\n"
@@ -149,7 +153,7 @@
/* Handle command line options. */
static void parse_args(int argc, char **argv, char **device)
{
- const char *flags = "a:c:x:dfhnqrstvVpm";
+ const char *flags = "a:c:x:dfhnqrstTvVpm";
#ifdef GETOPTLONG
static struct option long_options[] =
{
@@ -159,6 +163,7 @@
{"auto", required_argument, NULL, 'a'},
{"changerslot", required_argument, NULL, 'c'},
{"trayclose", no_argument, NULL, 't'},
+ {"toggletray", no_argument, NULL, 'T'},
{"cdspeed", required_argument, NULL, 'x'},
{"noop", no_argument, NULL, 'n'},
{"cdrom", no_argument, NULL, 'r'},
@@ -247,6 +252,9 @@
case 't':
t_option = 1;
break;
+ case 'T':
+ T_option = 1;
+ break;
case 'v':
v_option = 1;
break;
@@ -909,6 +917,23 @@
exit(0);
}
+ /* handle -T option */
+ if (T_option) {
+ if (v_option)
+ printf(_("%s: trying to eject\n"), programName);
+ fd = OpenDevice(deviceName);
+ struct timeval tv, tv2;
+ gettimeofday(&tv, NULL);
+ EjectCdrom(fd);
+ gettimeofday(&tv2, NULL);
+ if ((tv2.tv_sec - tv.tv_sec) < 1) {
+ if (v_option)
+ printf(_("%s: tray seems open, trying to close\n"), programName);
+ CloseTray(fd);
+ HandleXOption(deviceName);
+ exit(0);
+ }
+ }
/* handle -t option */
if (t_option) {
if (v_option)
|