More device error return codes. More detailed errors when CDROM_SEND_PACKET

fails.
This commit is contained in:
rocky
2005-02-28 02:00:20 +00:00
parent 602be8e5c6
commit 306f8bc498
2 changed files with 123 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/* -*- c -*- /* -*- c -*-
$Id: device.h,v 1.14 2005/02/12 15:27:22 rocky Exp $ $Id: device.h,v 1.15 2005/02/28 02:00:20 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -114,20 +114,26 @@ extern "C" {
integer. C seems to tolerate this. integer. C seems to tolerate this.
*/ */
typedef enum { typedef enum {
DRIVER_OP_UNINIT = -3, /**< returned when a particular driver DRIVER_OP_SUCCESS = 0, /**< in cases where an int is returned,
hasn't been initialized or a null like cdio_set_speed, more the negative
pointer has been passed. return codes are for errors and the
*/ positive ones for success. */
DRIVER_OP_UNSUPPORTED = -2, /**< returned when a particular driver DRIVER_OP_ERROR = -1, /**< operation returned an error */
doesn't support a particular operation. DRIVER_OP_UNSUPPORTED = -2, /**< returned when a particular driver
For example an image driver which doesn't doesn't support a particular operation.
really "eject" a CD. For example an image driver which doesn't
*/ really "eject" a CD.
DRIVER_OP_ERROR = -1, /**< operation returned an error */ */
DRIVER_OP_SUCCESS = 0, /**< in cases where an int is returned, DRIVER_OP_UNINIT = -3, /**< returned when a particular driver
like cdio_set_speed, more the negative hasn't been initialized or a null
return codes are for errors and the pointer has been passed.
positive ones for success. */ */
DRIVER_OP_NOT_PERMITTED = -4, /**< Operation not permitted.
For example might be a permission
problem.
*/
DRIVER_OP_BAD_PARAMETER = -5, /**< Bad parameter passed */
DRIVER_OP_BAD_POINTER = -6, /**< Bad pointer to memory area */
} driver_return_code_t; } driver_return_code_t;
/*! /*!
@@ -794,4 +800,4 @@ extern "C" {
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __CDIO_TRACK_H__ */ #endif /* __CDIO_DEVICE_H__ */

View File

@@ -1,5 +1,5 @@
/* /*
$Id: _cdio_linux.c,v 1.26 2005/02/17 07:03:37 rocky Exp $ $Id: _cdio_linux.c,v 1.27 2005/02/28 02:00:20 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2002, 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2002, 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -27,7 +27,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: _cdio_linux.c,v 1.26 2005/02/17 07:03:37 rocky Exp $"; static const char _rcsid[] = "$Id: _cdio_linux.c,v 1.27 2005/02/28 02:00:20 rocky Exp $";
#include <string.h> #include <string.h>
@@ -193,6 +193,71 @@ check_mounts_linux(const char *mtab)
return NULL; return NULL;
} }
/*!
Pause playing CD through analog output
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_pause_linux (void *p_user_data) {
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMPAUSE);
}
/*!
Pause playing CD through analog output
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_play_msf_linux (void *p_user_data, msf_t *p_msf) {
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMPLAYMSF, p_msf);
}
/*!
Playing CD through analog output at the desired track and index
@param p_cdio the CD object to be acted upon.
@param p_track_index location to start/end.
*/
static driver_return_code_t
audio_play_track_index_linux (void *p_user_data,
cdio_track_index_t *p_track_index) {
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMPLAYTRKIND, p_track_index);
}
/*!
Resume playing an audio CD.
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_resume_linux (void *p_user_data) {
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMRESUME, 0);
}
/*!
Resume playing an audio CD.
@param p_cdio the CD object to be acted upon.
*/
static driver_return_code_t
audio_set_volume_linux (void *p_user_data,
const cdio_audio_volume_t *p_volume) {
const _img_private_t *p_env = p_user_data;
return ioctl(p_env->gen.fd, CDROMVOLCTRL, p_volume);
}
/*! /*!
Return the value associated with the key "arg". Return the value associated with the key "arg".
*/ */
@@ -926,10 +991,10 @@ read_toc_linux (void *p_user_data)
*/ */
static driver_return_code_t static driver_return_code_t
run_mmc_cmd_linux( void *p_user_data, run_mmc_cmd_linux( void *p_user_data,
unsigned int i_timeout_ms, unsigned int i_timeout_ms,
unsigned int i_cdb, const scsi_mmc_cdb_t *p_cdb, unsigned int i_cdb, const scsi_mmc_cdb_t *p_cdb,
scsi_mmc_direction_t e_direction, scsi_mmc_direction_t e_direction,
unsigned int i_buf, /*in/out*/ void *p_buf ) unsigned int i_buf, /*in/out*/ void *p_buf )
{ {
const _img_private_t *p_env = p_user_data; const _img_private_t *p_env = p_user_data;
struct cdrom_generic_command cgc; struct cdrom_generic_command cgc;
@@ -944,7 +1009,29 @@ run_mmc_cmd_linux( void *p_user_data,
cgc.timeout = i_timeout_ms; cgc.timeout = i_timeout_ms;
#endif #endif
return ioctl (p_env->gen.fd, CDROM_SEND_PACKET, &cgc); {
int i_rc = ioctl (p_env->gen.fd, CDROM_SEND_PACKET, &cgc);
if (0 == i_rc) return DRIVER_OP_SUCCESS;
if (-1 == i_rc) {
cdio_warn ("ioctl CDROM_SEND_PACKET failed: %s\n", strerror(errno));
switch (errno) {
case EPERM:
return DRIVER_OP_NOT_PERMITTED;
break;
case EINVAL:
return DRIVER_OP_BAD_PARAMETER;
break;
case EFAULT:
return DRIVER_OP_BAD_POINTER;
break;
case EIO:
default:
return DRIVER_OP_ERROR;
break;
}
}
return DRIVER_OP_ERROR;
}
} }
/*! /*!
@@ -963,7 +1050,7 @@ get_disc_last_lsn_linux (void *p_user_data)
tocent.cdte_format = CDROM_LBA; tocent.cdte_format = CDROM_LBA;
if (ioctl (p_env->gen.fd, CDROMREADTOCENTRY, &tocent) == -1) if (ioctl (p_env->gen.fd, CDROMREADTOCENTRY, &tocent) == -1)
{ {
perror ("ioctl(CDROMREADTOCENTRY)"); cdio_warn ("ioctl CDROMREADTOCENTRY failed: %s\n", strerror(errno));
return CDIO_INVALID_LSN; return CDIO_INVALID_LSN;
} }
@@ -1160,6 +1247,12 @@ cdio_open_am_linux (const char *psz_orig_source, const char *access_mode)
char *psz_source; char *psz_source;
cdio_funcs_t _funcs = { cdio_funcs_t _funcs = {
// .audio_get_volume = audio_get_volume_linux,
.audio_pause = audio_pause_linux,
.audio_play_msf = audio_play_msf_linux,
.audio_play_track_index= audio_play_track_index_linux,
.audio_resume = audio_resume_linux,
.audio_set_volume = audio_set_volume_linux,
.eject_media = eject_media_linux, .eject_media = eject_media_linux,
.free = cdio_generic_free, .free = cdio_generic_free,
.get_arg = get_arg_linux, .get_arg = get_arg_linux,