summaryrefslogtreecommitdiff
path: root/extra/eject/eject-2.1.5-unlock.patch
blob: d554f9bdfae4a22ecfa3a69c8d4ed55b93d2ca65 (plain)
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
diff -pur eject-orig/eject.c eject/eject.c
--- eject-orig/eject.c	2006-02-11 04:54:38.000000000 +0300
+++ eject/eject.c	2011-08-11 13:12:16.568112725 +0400
@@ -527,6 +527,25 @@ static void CloseTray(int fd)
 }
 
 /*
+ * Unlock tray using CDROM_LOCKDOOR ioctl.
+	* New kernels doesn't automatically unlock tray before ejecting,
+	* and the new udev automatically locks it.
+ */
+static int UnlockCdrom(int fd)
+{
+	int status = -1;
+
+	if (v_option)
+		printf(_("%s: unlocking tray using CDROM_LOCKDOOR ioctl\n"), programName);
+
+	status = ioctl(fd, CDROM_LOCKDOOR, 0);
+	if (v_option && status != 0)
+		printf(_("%s: CDROM_LOCKDOOR ioctl failed\n"), programName);
+
+	return (status == 0);
+}
+
+/*
  * Toggle tray.
  *
  * Written by Benjamin Schwenk <benjaminschwenk@yahoo.de> and
@@ -543,6 +562,8 @@ static void ToggleTray(int fd)
 
 #ifdef CDROMCLOSETRAY
 
+	UnlockCdrom(fd);
+
 	/* Try to open the CDROM tray and measure the time therefor
 	 * needed.  In my experience the function needs less than 0.05
 	 * seconds if the tray was already open, and at least 1.5 seconds
@@ -566,7 +587,11 @@ static void ToggleTray(int fd)
 	 * was already open. In this case, close it now. Else the tray was
 	 * closed before. This would mean that we are done.  */
 	if (time_elapsed < TRAY_WAS_ALREADY_OPEN_USECS)
+	{
+		if (v_option)
+			printf(_("%s: CD-ROM tray was already open, closing it\n"), programName);
 		CloseTray(fd);
+	}
 
 #else
     fprintf(stderr, _("%s: CD-ROM tray toggle command not supported by this kernel\n"), programName);
@@ -681,7 +706,7 @@ static void ListSpeedCdrom(const char *f
 static int EjectCdrom(int fd)
 {
 	int status = -1;
-
+	UnlockCdrom(fd);
 #if defined(CDROMEJECT)
 	status = ioctl(fd, CDROMEJECT);
 #elif defined(CDIOCEJECT)