From 02ce5551711f50b0e1c49efa23d2cf733cd7769f Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 13 Mar 2005 04:42:38 +0000 Subject: [PATCH] A hacky OSX close drive routine. It doesn't handle the actual drive paramater because we don't really know how to pass that to druti. --- lib/driver/cdio_private.h | 11 +++--- lib/driver/osx.c | 76 ++++++++++++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/lib/driver/cdio_private.h b/lib/driver/cdio_private.h index df08bdb4..777168b1 100644 --- a/lib/driver/cdio_private.h +++ b/lib/driver/cdio_private.h @@ -1,5 +1,5 @@ /* - $Id: cdio_private.h,v 1.26 2005/03/11 02:08:05 rocky Exp $ + $Id: cdio_private.h,v 1.27 2005/03/13 04:42:38 rocky Exp $ Copyright (C) 2003, 2004, 2005 Rocky Bernstein @@ -473,10 +473,11 @@ extern "C" { void cdio_add_device_list(char **device_list[], const char *psz_drive, unsigned int *i_drives); - driver_return_code_t close_tray_freebsd (const char *psz_device); - driver_return_code_t close_tray_linux (const char *psz_device); - driver_return_code_t close_tray_solaris(const char *psz_device); - driver_return_code_t close_tray_win32 (const char *psz_win32_drive); + driver_return_code_t close_tray_freebsd (const char *psz_drive); + driver_return_code_t close_tray_linux (const char *psz_drive); + driver_return_code_t close_tray_osx (const char *psz_drive); + driver_return_code_t close_tray_solaris (const char *psz_drive); + driver_return_code_t close_tray_win32 (const char *psz_drive); #ifdef __cplusplus diff --git a/lib/driver/osx.c b/lib/driver/osx.c index a5b677a5..d5e516df 100644 --- a/lib/driver/osx.c +++ b/lib/driver/osx.c @@ -1,5 +1,5 @@ /* - $Id: osx.c,v 1.1 2005/03/05 09:26:52 rocky Exp $ + $Id: osx.c,v 1.2 2005/03/13 04:42:38 rocky Exp $ Copyright (C) 2003, 2004, 2005 Rocky Bernstein from vcdimager code: @@ -34,7 +34,7 @@ #include "config.h" #endif -static const char _rcsid[] = "$Id: osx.c,v 1.1 2005/03/05 09:26:52 rocky Exp $"; +static const char _rcsid[] = "$Id: osx.c,v 1.2 2005/03/13 04:42:38 rocky Exp $"; #include #include @@ -1324,29 +1324,29 @@ _eject_media_osx (void *user_data) { _img_private_t *p_env = user_data; - FILE *p_eject; - char *psz_disk; + FILE *p_file; + char *psz_drive; char sz_cmd[32]; - if( ( psz_disk = (char *)strstr( p_env->gen.source_name, "disk" ) ) != NULL && - strlen( psz_disk ) > 4 ) + if( ( psz_drive = (char *)strstr( p_env->gen.source_name, "disk" ) ) != NULL && + strlen( psz_drive ) > 4 ) { #define EJECT_CMD "/usr/sbin/hdiutil eject %s" - snprintf( sz_cmd, sizeof(sz_cmd), EJECT_CMD, psz_disk ); + snprintf( sz_cmd, sizeof(sz_cmd), EJECT_CMD, psz_drive ); #undef EJECT_CMD - if( ( p_eject = popen( sz_cmd, "r" ) ) != NULL ) + if( ( p_file = popen( sz_cmd, "r" ) ) != NULL ) { char psz_result[0x200]; - int i_ret = fread( psz_result, 1, sizeof(psz_result) - 1, p_eject ); + int i_ret = fread( psz_result, 1, sizeof(psz_result) - 1, p_file ); - if( i_ret == 0 && ferror( p_eject ) != 0 ) + if( i_ret == 0 && ferror( p_file ) != 0 ) { - pclose( p_eject ); + pclose( p_file ); return DRIVER_OP_ERROR; } - pclose( p_eject ); + pclose( p_file ); psz_result[ i_ret ] = 0; @@ -1508,6 +1508,58 @@ set_speed_osx (void *p_user_data, int i_speed) #endif /* HAVE_DARWIN_CDROM */ +/*! + Close tray on CD-ROM. + + @param psz_drive the CD-ROM drive to be closed. + +*/ + +/* FIXME: We don't use the device name because we don't how + to. + */ +#define CLOSE_TRAY_CMD "/usr/sbin/drutil tray close" +driver_return_code_t +close_tray_osx (const char *psz_drive) +{ +#ifdef HAVE_DARWIN_CDROM + FILE *p_file; + char sz_cmd[80]; + + if ( !psz_drive) return DRIVER_OP_UNINIT; + + /* Right now we really aren't making use of snprintf, but + possibly someday we will. + */ + snprintf( sz_cmd, sizeof(sz_cmd), CLOSE_TRAY_CMD ); + + if( ( p_file = popen( sz_cmd, "r" ) ) != NULL ) + { + char psz_result[0x200]; + int i_ret = fread( psz_result, 1, sizeof(psz_result) - 1, p_file ); + + if( i_ret == 0 && ferror( p_file ) != 0 ) + { + pclose( p_file ); + return DRIVER_OP_ERROR; + } + + pclose( p_file ); + + psz_result[ i_ret ] = 0; + + if( 0 == i_ret ) + { + return DRIVER_OP_SUCCESS; + } + } + + return DRIVER_OP_ERROR; +#else + return DRIVER_OP_NO_DRIVER; +#endif /*HAVE_DARWIN_CDROM*/ +} + /*! Return a string containing the default CD device if none is specified. */