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
|
/*
* Copyright (C) 2000-2003 the xine project,
*
* This file is part of xine, a free video player.
*
* xine is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* xine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
*/
/* Standard includes */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#ifndef WIN32
#include <sys/wait.h>
#include <sys/ioctl.h>
#endif
#include <unistd.h>
#include <string.h>
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
#include <sys/cdio.h> /* CDIOCALLOW etc... */
#elif defined(HAVE_LINUX_CDROM_H)
#include <linux/cdrom.h>
#elif defined(HAVE_SYS_CDIO_H)
#include <sys/cdio.h>
#elif WIN32
#else
#warning "This might not compile due to missing cdrom ioctls"
#endif
#include "media_helper.h"
#define LOG_MEDIA_EJECT
static int media_umount_media(const char *device)
{
#ifndef WIN32
int i;
pid_t pid;
int status;
pid=fork();
if (pid == 0) {
i= execl("/bin/umount", "umount", device, NULL);
exit(127);
}
do {
if(waitpid(pid, &status, 0) == -1) {
if (errno != EINTR)
return -1;
}
else {
return WEXITSTATUS(status);
}
} while(1);
return -1;
#else
return 0;
#endif /* WIN32 */
}
int media_eject_media (xine_t *xine, const char *device) {
#ifndef WIN32
int ret, status;
int fd;
#endif /* WIN32 */
/* printf("input_dvd: Eject Device %s current device %s opened=%d handle=%p trying...\n",device, this->current_dvd_device, this->opened, this->dvdnav); */
media_umount_media(device);
/**********
printf("input_dvd: umount result: %s\n",
strerror(errno));
***********/
#ifndef WIN32
if ((fd = open (device, O_RDONLY|O_NONBLOCK)) > -1) {
#if defined (__linux__)
if((status = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT)) > 0) {
switch(status) {
case CDS_TRAY_OPEN:
if((ret = ioctl(fd, CDROMCLOSETRAY)) != 0) {
#ifdef LOG_MEDIA_EJECT
printf("input_dvd: CDROMCLOSETRAY failed: %s\n",
strerror(errno));
#endif
}
break;
case CDS_DISC_OK:
if((ret = ioctl(fd, CDROMEJECT)) != 0) {
#ifdef LOG_MEDIA_EJECT
printf("input_dvd: CDROMEJECT failed: %s\n", strerror(errno));
#endif
}
break;
}
}
else {
#ifdef LOG_MEDIA_EJECT
printf("input_dvd: CDROM_DRIVE_STATUS failed: %s\n",
strerror(errno));
#endif
close(fd);
return 0;
}
#elif defined (__NetBSD__) || defined (__OpenBSD__) || defined (__FreeBSD__)
if (ioctl(fd, CDIOCALLOW) == -1) {
xprintf(xine, XINE_VERBOSITY_DEBUG, "ioctl(cdromallow): %s\n", strerror(errno));
} else {
if (ioctl(fd, CDIOCEJECT) == -1) {
xprintf(xine, XINE_VERBOSITY_DEBUG, "ioctl(cdromeject): %s\n", strerror(errno));
}
}
#endif
close(fd);
} else {
xprintf(xine, XINE_VERBOSITY_LOG,
_("input_dvd: Device %s failed to open during eject calls\n"), device);
}
return 1;
#else
return 0;
#endif /* WIN32 */
}
|