1 /*****************************************************************************
2 * eject.c: CD/DVD-ROM ejection handling functions
3 *****************************************************************************
4 * Copyright (C) 2001-2011 the VideoLAN team
6 * Authors: Julien Blache <jb@technologeek.org> for the Linux part
7 * with code taken from the Linux "eject" command
8 * Jon Lech Johansen <jon-vl@nanocrew.net> for Darwin
9 * Gildas Bazin <gbazin@netcourrier.com> for Win32
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * This file contain functions to eject CD and DVD drives
31 /*#ifdef HAVE_CONFIG_H
35 #include <vlc_common.h>
37 #include <vlc_charset.h>
40 # include <mmsystem.h>
41 #elif defined(__linux__)
42 # include <sys/types.h>
45 # include <sys/ioctl.h>
46 # include <sys/mount.h>
48 # include <linux/cdrom.h>
50 # include <scsi/scsi.h>
52 # include <scsi/scsi_ioctl.h>
53 #elif defined (HAVE_DVD_H)
59 #if defined(__linux__)
61 * \brief Ejects the CD /DVD using SCSI commands
62 * \ingroup vlc_interface
63 * This function is local
64 * \param i_fd a device nummber
65 * \return 0 on success, VLC_EGENERIC on failure
67 static int EjectSCSI( int i_fd
)
78 scsi_cmd
.cmd
[0] = ALLOW_MEDIUM_REMOVAL
;
84 if( ioctl( i_fd
, SCSI_IOCTL_SEND_COMMAND
, (void *)&scsi_cmd
) < 0 )
89 scsi_cmd
.cmd
[0] = START_STOP
;
95 if( ioctl( i_fd
, SCSI_IOCTL_SEND_COMMAND
, (void *)&scsi_cmd
) < 0 )
100 scsi_cmd
.cmd
[0] = START_STOP
;
106 if( ioctl( i_fd
, SCSI_IOCTL_SEND_COMMAND
, (void *)&scsi_cmd
) < 0 )
109 /* Force kernel to reread partition table when new disc inserted */
110 ioctl( i_fd
, BLKRRPART
);
117 * Ejects the optical disc in a device
118 * \param p_this the calling vlc_object_t
119 * \param psz_device the CD/DVD to eject
120 * \return VLC_SUCCESS or VLC_EGENERIC
122 static int intf_Eject( vlc_object_t
*p_this
, const char *psz_device
)
131 memset( &op
, 0, sizeof(MCI_OPEN_PARMS
) );
132 op
.lpstrDeviceType
= (LPCTSTR
)MCI_DEVTYPE_CD_AUDIO
;
134 _tcscpy( psz_drive
, TEXT("X:") );
135 psz_drive
[0] = psz_device
[0];
136 op
.lpstrElementName
= psz_drive
;
138 /* Set the flags for the device type */
139 i_flags
= MCI_OPEN_TYPE
| MCI_OPEN_TYPE_ID
|
140 MCI_OPEN_ELEMENT
| MCI_OPEN_SHAREABLE
;
142 if( mciSendCommand( 0, MCI_OPEN
, i_flags
, (uintptr_t)&op
) )
146 mciSendCommand( op
.wDeviceID
, MCI_SET
, MCI_SET_DOOR_OPEN
, 0 );
147 /* Release access to the device */
148 mciSendCommand( op
.wDeviceID
, MCI_CLOSE
, MCI_WAIT
, 0 );
152 #elif defined (__linux__) || defined (HAVE_DVD_H)
153 /* This code could be extended to support CD/DVD-ROM chargers */
154 int fd
= vlc_open( psz_device
, O_RDONLY
| O_NONBLOCK
);
157 msg_Err( p_this
, "could not open device %s", psz_device
);
161 # if defined(__linux__)
162 /* Try a simple ATAPI eject */
163 if( ioctl( fd
, CDROMEJECT
, 0 ) < 0
166 if( ioctl( fd
, CDROMEJECT
, 0 ) < 0 )
169 msg_Err( p_this
, "could not eject %s", psz_device
);
177 VLC_UNUSED( psz_device
);
178 msg_Warn( p_this
, "CD-Rom ejection unsupported on this platform" );
183 #define intf_Eject(o, p) intf_Eject(VLC_OBJECT(o), p)