| 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 |
#ifdef HAVE_CONFIG_H |
|---|
| 33 |
# include "config.h" |
|---|
| 34 |
#endif |
|---|
| 35 |
|
|---|
| 36 |
#include <vlc_common.h> |
|---|
| 37 |
|
|---|
| 38 |
#ifdef HAVE_UNISTD_H |
|---|
| 39 |
# include <unistd.h> |
|---|
| 40 |
#endif |
|---|
| 41 |
|
|---|
| 42 |
#ifdef HAVE_FCNTL_H |
|---|
| 43 |
# include <fcntl.h> |
|---|
| 44 |
#endif |
|---|
| 45 |
|
|---|
| 46 |
#ifdef HAVE_DVD_H |
|---|
| 47 |
# include <dvd.h> |
|---|
| 48 |
#endif |
|---|
| 49 |
|
|---|
| 50 |
#if defined(__linux__) && defined(HAVE_LINUX_VERSION_H) |
|---|
| 51 |
# include <linux/version.h> |
|---|
| 52 |
|
|---|
| 53 |
# ifndef KERNEL_VERSION |
|---|
| 54 |
# define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) |
|---|
| 55 |
# endif |
|---|
| 56 |
|
|---|
| 57 |
# include <sys/types.h> |
|---|
| 58 |
# include <sys/stat.h> |
|---|
| 59 |
# include <sys/ioctl.h> |
|---|
| 60 |
|
|---|
| 61 |
# include <sys/ioctl.h> |
|---|
| 62 |
# include <sys/mount.h> |
|---|
| 63 |
|
|---|
| 64 |
# include <linux/cdrom.h> |
|---|
| 65 |
# if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) |
|---|
| 66 |
# include <linux/ucdrom.h> |
|---|
| 67 |
# endif |
|---|
| 68 |
|
|---|
| 69 |
# include <scsi/scsi.h> |
|---|
| 70 |
# include <scsi/sg.h> |
|---|
| 71 |
# include <scsi/scsi_ioctl.h> |
|---|
| 72 |
#endif |
|---|
| 73 |
|
|---|
| 74 |
#if defined( WIN32 ) && !defined( UNDER_CE ) |
|---|
| 75 |
# include <mmsystem.h> |
|---|
| 76 |
#endif |
|---|
| 77 |
|
|---|
| 78 |
#include <vlc_interface.h> |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
#if defined(__linux__) && defined(HAVE_LINUX_VERSION_H) |
|---|
| 84 |
static int EjectSCSI ( int i_fd ); |
|---|
| 85 |
#endif |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
int __intf_Eject( vlc_object_t *p_this, const char *psz_device ) |
|---|
| 102 |
{ |
|---|
| 103 |
VLC_UNUSED(p_this); |
|---|
| 104 |
int i_ret = VLC_SUCCESS; |
|---|
| 105 |
|
|---|
| 106 |
#ifdef __APPLE__ |
|---|
| 107 |
FILE *p_eject; |
|---|
| 108 |
char *psz_disk; |
|---|
| 109 |
char sz_cmd[32]; |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
if( ( psz_disk = (char *)strstr( psz_device, "disk" ) ) != NULL && |
|---|
| 119 |
strlen( psz_disk ) > 4 ) |
|---|
| 120 |
{ |
|---|
| 121 |
#define EJECT_CMD "/usr/sbin/disktool -e %s 0" |
|---|
| 122 |
snprintf( sz_cmd, sizeof(sz_cmd), EJECT_CMD, psz_disk ); |
|---|
| 123 |
#undef EJECT_CMD |
|---|
| 124 |
|
|---|
| 125 |
if( ( p_eject = popen( sz_cmd, "r" ) ) != NULL ) |
|---|
| 126 |
{ |
|---|
| 127 |
char psz_result[0x200]; |
|---|
| 128 |
i_ret = fread( psz_result, 1, sizeof(psz_result) - 1, p_eject ); |
|---|
| 129 |
|
|---|
| 130 |
if( i_ret == 0 && ferror( p_eject ) != 0 ) |
|---|
| 131 |
{ |
|---|
| 132 |
pclose( p_eject ); |
|---|
| 133 |
return VLC_EGENERIC; |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
pclose( p_eject ); |
|---|
| 137 |
|
|---|
| 138 |
psz_result[ i_ret ] = 0; |
|---|
| 139 |
|
|---|
| 140 |
if( strstr( psz_result, "Disk Ejected" ) != NULL ) |
|---|
| 141 |
{ |
|---|
| 142 |
return VLC_SUCCESS; |
|---|
| 143 |
} |
|---|
| 144 |
} |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
return VLC_EGENERIC; |
|---|
| 148 |
|
|---|
| 149 |
#elif defined(UNDER_CE) |
|---|
| 150 |
msg_Warn( p_this, "CD-Rom ejection unsupported on this platform" ); |
|---|
| 151 |
return i_ret; |
|---|
| 152 |
|
|---|
| 153 |
#elif defined(WIN32) |
|---|
| 154 |
MCI_OPEN_PARMS op; |
|---|
| 155 |
MCI_STATUS_PARMS st; |
|---|
| 156 |
DWORD i_flags; |
|---|
| 157 |
char psz_drive[4]; |
|---|
| 158 |
|
|---|
| 159 |
memset( &op, 0, sizeof(MCI_OPEN_PARMS) ); |
|---|
| 160 |
op.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO; |
|---|
| 161 |
|
|---|
| 162 |
strcpy( psz_drive, "X:" ); |
|---|
| 163 |
psz_drive[0] = psz_device[0]; |
|---|
| 164 |
op.lpstrElementName = psz_drive; |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
i_flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | |
|---|
| 168 |
MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE; |
|---|
| 169 |
|
|---|
| 170 |
if( !mciSendCommand( 0, MCI_OPEN, i_flags, (unsigned long)&op ) ) |
|---|
| 171 |
{ |
|---|
| 172 |
st.dwItem = MCI_STATUS_READY; |
|---|
| 173 |
|
|---|
| 174 |
i_ret = mciSendCommand( op.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0 ); |
|---|
| 175 |
|
|---|
| 176 |
mciSendCommand( op.wDeviceID, MCI_CLOSE, MCI_WAIT, 0 ); |
|---|
| 177 |
} |
|---|
| 178 |
else i_ret = VLC_EGENERIC; |
|---|
| 179 |
|
|---|
| 180 |
return i_ret; |
|---|
| 181 |
#else |
|---|
| 182 |
|
|---|
| 183 |
int i_fd; |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
i_fd = open( psz_device, O_RDONLY | O_NONBLOCK ); |
|---|
| 188 |
|
|---|
| 189 |
if( i_fd == -1 ) |
|---|
| 190 |
{ |
|---|
| 191 |
msg_Err( p_this, "could not open device %s", psz_device ); |
|---|
| 192 |
return VLC_EGENERIC; |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
#if defined(__linux__) && defined(HAVE_LINUX_VERSION_H) |
|---|
| 196 |
|
|---|
| 197 |
i_ret = ioctl( i_fd, CDROMEJECT, 0 ); |
|---|
| 198 |
|
|---|
| 199 |
if( i_ret != 0 ) |
|---|
| 200 |
{ |
|---|
| 201 |
i_ret = EjectSCSI( i_fd ); |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
if( i_ret != 0 ) |
|---|
| 205 |
{ |
|---|
| 206 |
msg_Err( p_this, "could not eject %s", psz_device ); |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
#elif defined (HAVE_DVD_H) |
|---|
| 210 |
i_ret = ioctl( i_fd, CDROMEJECT, 0 ); |
|---|
| 211 |
|
|---|
| 212 |
#else |
|---|
| 213 |
msg_Warn( p_this, "CD-ROM ejection unsupported on this platform" ); |
|---|
| 214 |
i_ret = -1; |
|---|
| 215 |
|
|---|
| 216 |
#endif |
|---|
| 217 |
close( i_fd ); |
|---|
| 218 |
|
|---|
| 219 |
return i_ret; |
|---|
| 220 |
#endif |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
#if defined(__linux__) && defined(HAVE_LINUX_VERSION_H) |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
static int EjectSCSI( int i_fd ) |
|---|
| 237 |
{ |
|---|
| 238 |
int i_status; |
|---|
| 239 |
|
|---|
| 240 |
struct sdata |
|---|
| 241 |
{ |
|---|
| 242 |
int inlen; |
|---|
| 243 |
int outlen; |
|---|
| 244 |
char cmd[256]; |
|---|
| 245 |
} scsi_cmd; |
|---|
| 246 |
|
|---|
| 247 |
scsi_cmd.inlen = 0; |
|---|
| 248 |
scsi_cmd.outlen = 0; |
|---|
| 249 |
scsi_cmd.cmd[0] = ALLOW_MEDIUM_REMOVAL; |
|---|
| 250 |
scsi_cmd.cmd[1] = 0; |
|---|
| 251 |
scsi_cmd.cmd[2] = 0; |
|---|
| 252 |
scsi_cmd.cmd[3] = 0; |
|---|
| 253 |
scsi_cmd.cmd[4] = 0; |
|---|
| 254 |
scsi_cmd.cmd[5] = 0; |
|---|
| 255 |
i_status = ioctl( i_fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd ); |
|---|
| 256 |
if( i_status != 0 ) |
|---|
| 257 |
{ |
|---|
| 258 |
return VLC_EGENERIC; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
scsi_cmd.inlen = 0; |
|---|
| 262 |
scsi_cmd.outlen = 0; |
|---|
| 263 |
scsi_cmd.cmd[0] = START_STOP; |
|---|
| 264 |
scsi_cmd.cmd[1] = 0; |
|---|
| 265 |
scsi_cmd.cmd[2] = 0; |
|---|
| 266 |
scsi_cmd.cmd[3] = 0; |
|---|
| 267 |
scsi_cmd.cmd[4] = 1; |
|---|
| 268 |
scsi_cmd.cmd[5] = 0; |
|---|
| 269 |
i_status = ioctl( i_fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd ); |
|---|
| 270 |
if( i_status != 0 ) |
|---|
| 271 |
{ |
|---|
| 272 |
return VLC_EGENERIC; |
|---|
| 273 |
} |
|---|
| 274 |
|
|---|
| 275 |
scsi_cmd.inlen = 0; |
|---|
| 276 |
scsi_cmd.outlen = 0; |
|---|
| 277 |
scsi_cmd.cmd[0] = START_STOP; |
|---|
| 278 |
scsi_cmd.cmd[1] = 0; |
|---|
| 279 |
scsi_cmd.cmd[2] = 0; |
|---|
| 280 |
scsi_cmd.cmd[3] = 0; |
|---|
| 281 |
scsi_cmd.cmd[4] = 2; |
|---|
| 282 |
scsi_cmd.cmd[5] = 0; |
|---|
| 283 |
i_status = ioctl( i_fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd ); |
|---|
| 284 |
if( i_status != 0 ) |
|---|
| 285 |
{ |
|---|
| 286 |
return VLC_EGENERIC; |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
i_status = ioctl( i_fd, BLKRRPART ); |
|---|
| 291 |
|
|---|
| 292 |
return i_status; |
|---|
| 293 |
} |
|---|
| 294 |
#endif |
|---|
| 295 |
|
|---|