17 #if defined(SYS_LINUX) && defined(HAVE_LINUX_VERSION_H)
18 # include <linux/version.h>
19 /* handy macro found in 2.1 kernels, but not in older ones */
20 # ifndef KERNEL_VERSION
21 # define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
24 # include <sys/types.h>
25 # include <sys/stat.h>
26 # include <sys/ioctl.h>
28 # include <sys/ioctl.h>
29 # include <sys/mount.h>
31 # include <linux/cdrom.h>
32 # if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)
33 include <linux/ucdrom.h>
36 # include <scsi/scsi.h>
38 # include <scsi/scsi_ioctl.h>
41 #if defined( WIN32 ) && !defined( UNDER_CE )
42 # include <mmsystem.h>
45 #include <vlc_interface.h>
47 /*****************************************************************************
49 *****************************************************************************/
50 #if defined(SYS_LINUX) && defined(HAVE_LINUX_VERSION_H)
51 static int EjectSCSI ( int i_fd );
54 /*****************************************************************************
55 * intf_Eject: eject the CDRom
56 *****************************************************************************
57 * returns 0 on success
58 * returns 1 on failure
59 * returns -1 if not implemented
60 *****************************************************************************/
62 * \brief Ejects the CD /DVD
63 * \ingroup vlc_interface
64 * \param p_this the calling vlc_object_t
65 * \param psz_device the CD/DVD to eject
66 * \return 0 on success, 1 on failure, -1 if not implemented
68 int __intf_Eject( vlc_object_t *p_this, const char *psz_device )
70 int i_ret = VLC_SUCCESS;
78 * The only way to cleanly unmount the disc under MacOS X
79 * is to use the 'disktool' command line utility. It uses
80 * the non-public Disk Arbitration API, which can not be
81 * used by Cocoa or Carbon applications.
84 if( ( psz_disk = (char *)strstr( psz_device, "disk" ) ) != NULL &&
85 strlen( psz_disk ) > 4 )
87 #define EJECT_CMD "/usr/sbin/disktool -e %s 0"
88 snprintf( sz_cmd, sizeof(sz_cmd), EJECT_CMD, psz_disk );
91 if( ( p_eject = popen( sz_cmd, "r" ) ) != NULL )
93 char psz_result[0x200];
94 i_ret = fread( psz_result, 1, sizeof(psz_result) - 1, p_eject );
96 if( i_ret == 0 && ferror( p_eject ) != 0 )
104 psz_result[ i_ret ] = 0;
106 if( strstr( psz_result, "Disk Ejected" ) != NULL )
115 #elif defined(UNDER_CE)
116 msg_Warn( p_this, "CD-Rom ejection unsupported on this platform" );
125 memset( &op, 0, sizeof(MCI_OPEN_PARMS) );
126 op.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO;
128 strcpy( psz_drive, "X:" );
129 psz_drive[0] = psz_device[0];
130 op.lpstrElementName = psz_drive;
132 /* Set the flags for the device type */
133 i_flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID |
134 MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE;
136 if( !mciSendCommand( 0, MCI_OPEN, i_flags, (unsigned long)&op ) )
138 st.dwItem = MCI_STATUS_READY;
140 i_ret = mciSendCommand( op.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0 );
141 /* Release access to the device */
142 mciSendCommand( op.wDeviceID, MCI_CLOSE, MCI_WAIT, 0 );
144 else i_ret = VLC_EGENERIC;
151 /* This code could be extended to support CD/DVD-ROM chargers */
153 i_fd = open( psz_device, O_RDONLY | O_NONBLOCK );
157 msg_Err( p_this, "could not open device %s", psz_device );
161 #if defined(SYS_LINUX) && defined(HAVE_LINUX_VERSION_H)
162 /* Try a simple ATAPI eject */
163 i_ret = ioctl( i_fd, CDROMEJECT, 0 );
167 i_ret = EjectSCSI( i_fd );
172 msg_Err( p_this, "could not eject %s", psz_device );
175 #elif defined (HAVE_DVD_H)
176 i_ret = ioctl( i_fd, CDROMEJECT, 0 );
179 msg_Warn( p_this, "CD-ROM ejection unsupported on this platform" );
189 /* The following functions are local */
191 #if defined(SYS_LINUX) && defined(HAVE_LINUX_VERSION_H)
192 /*****************************************************************************
193 * Eject using SCSI commands. Return 0 if successful
194 *****************************************************************************/
196 * \brief Ejects the CD /DVD using SCSI commands
197 * \ingroup vlc_interface
198 * This function is local
199 * \param i_fd a device nummber
200 * \return 0 on success, VLC_EGENERIC on failure
202 static int EjectSCSI( int i_fd )
215 scsi_cmd.cmd[0] = ALLOW_MEDIUM_REMOVAL;
221 i_status = ioctl( i_fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd );
229 scsi_cmd.cmd[0] = START_STOP;
235 i_status = ioctl( i_fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd );
243 scsi_cmd.cmd[0] = START_STOP;
249 i_status = ioctl( i_fd, SCSI_IOCTL_SEND_COMMAND, (void *)&scsi_cmd );
255 /* Force kernel to reread partition table when new disc inserted */
256 i_status = ioctl( i_fd, BLKRRPART );