diff --git a/include/cdio/mmc.h b/include/cdio/mmc.h index eca5793b..2f6a1f22 100644 --- a/include/cdio/mmc.h +++ b/include/cdio/mmc.h @@ -906,30 +906,6 @@ mmc_audio_read_subchannel (CdIo_t *p_cdio, driver_return_code_t mmc_set_drive_speed( const CdIo_t *p_cdio, int i_drive_speed ); - /** - Set the drive speed in K bytes per second. - - @param p_cdio CD structure set by cdio_open(). - @param i_Kbs_speed speed in K bytes per second. Note this is - not in standard CD-ROM speed units, e.g. - 1x, 4x, 16x as it is in cdio_set_speed. - To convert CD-ROM speed units to Kbs, - multiply the number by 176 (for raw data) - and by 150 (for filesystem data). - Also note that ATAPI specs say that a value - less than 176 will result in an error. - On many CD-ROM drives, - specifying a value too large will result in using - the fastest speed. - - @return the drive speed if greater than 0. -1 if we had an error. is -2 - returned if this is not implemented for the current driver. - - @see cdio_set_speed and mmc_set_drive_speed - */ - driver_return_code_t mmc_set_speed( const CdIo_t *p_cdio, - int i_Kbs_speed ); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/include/cdio/mmc_cmds.h b/include/cdio/mmc_cmds.h index cbc664b3..8fde0c98 100644 --- a/include/cdio/mmc_cmds.h +++ b/include/cdio/mmc_cmds.h @@ -194,6 +194,31 @@ extern "C" { uint8_t subchannel_selection, uint16_t i_blocksize, uint32_t i_blocks ); + /** + Set the drive speed in K bytes per second using SCSI-MMC SET SPEED. +. + + @param p_cdio CD structure set by cdio_open(). + @param i_Kbs_speed speed in K bytes per second. Note this is + not in standard CD-ROM speed units, e.g. + 1x, 4x, 16x as it is in cdio_set_speed. + To convert CD-ROM speed units to Kbs, + multiply the number by 176 (for raw data) + and by 150 (for filesystem data). + Also note that ATAPI specs say that a value + less than 176 will result in an error. + On many CD-ROM drives, + specifying a value too large will result in using + the fastest speed. + + @return the drive speed if greater than 0. -1 if we had an error. is -2 + returned if this is not implemented for the current driver. + + @see cdio_set_speed and mmc_set_drive_speed + */ + driver_return_code_t mmc_set_speed( const CdIo_t *p_cdio, + int i_Kbs_speed ); + /** Load or Unload media using a MMC START STOP UNIT command. diff --git a/lib/driver/mmc.c b/lib/driver/mmc.c index 8922ed9f..c0f08137 100644 --- a/lib/driver/mmc.c +++ b/lib/driver/mmc.c @@ -120,22 +120,22 @@ audio_read_subchannel_mmc ( void *p_user_data, cdio_subchannel_t *p_subchannel) */ const char *mmc_audio_state2str( uint8_t i_audio_state ) { - switch(i_audio_state) { - case CDIO_MMC_READ_SUB_ST_INVALID: - return "invalid"; - case CDIO_MMC_READ_SUB_ST_PLAY: - return "playing"; - case CDIO_MMC_READ_SUB_ST_PAUSED: - return "paused"; - case CDIO_MMC_READ_SUB_ST_COMPLETED: - return "completed"; - case CDIO_MMC_READ_SUB_ST_ERROR: - return "error"; - case CDIO_MMC_READ_SUB_ST_NO_STATUS: - return "no status"; - default: - return "unknown"; - } + switch(i_audio_state) { + case CDIO_MMC_READ_SUB_ST_INVALID: + return "invalid"; + case CDIO_MMC_READ_SUB_ST_PLAY: + return "playing"; + case CDIO_MMC_READ_SUB_ST_PAUSED: + return "paused"; + case CDIO_MMC_READ_SUB_ST_COMPLETED: + return "completed"; + case CDIO_MMC_READ_SUB_ST_ERROR: + return "error"; + case CDIO_MMC_READ_SUB_ST_NO_STATUS: + return "no status"; + default: + return "unknown"; + } } /** @@ -145,9 +145,9 @@ const char *mmc_audio_state2str( uint8_t i_audio_state ) int get_blocksize_mmc (void *p_user_data) { - generic_img_private_t *p_env = p_user_data; - if (!p_env) return DRIVER_OP_UNINIT; - return mmc_get_blocksize(p_env->cdio); + generic_img_private_t *p_env = p_user_data; + if (!p_env) return DRIVER_OP_UNINIT; + return mmc_get_blocksize(p_env->cdio); } /** @@ -156,9 +156,9 @@ get_blocksize_mmc (void *p_user_data) lsn_t get_disc_last_lsn_mmc (void *p_user_data) { - generic_img_private_t *p_env = p_user_data; - if (!p_env) return CDIO_INVALID_LSN; - return mmc_get_disc_last_lsn(p_env->cdio); + generic_img_private_t *p_env = p_user_data; + if (!p_env) return CDIO_INVALID_LSN; + return mmc_get_disc_last_lsn(p_env->cdio); } void @@ -195,8 +195,8 @@ get_mcn_mmc (const void *p_user_data) driver_return_code_t get_tray_status (const void *p_user_data) { - const generic_img_private_t *p_env = p_user_data; - return mmc_get_tray_status( p_env->cdio ); + const generic_img_private_t *p_env = p_user_data; + return mmc_get_tray_status( p_env->cdio ); } /*! Read sectors using SCSI-MMC GPCMD_READ_CD. @@ -207,8 +207,8 @@ read_data_sectors_mmc ( void *p_user_data, void *p_buf, lsn_t i_lsn, uint16_t i_blocksize, uint32_t i_blocks ) { - const generic_img_private_t *p_env = p_user_data; - return mmc_read_data_sectors( p_env->cdio, p_buf, i_lsn, i_blocksize, + const generic_img_private_t *p_env = p_user_data; + return mmc_read_data_sectors( p_env->cdio, p_buf, i_lsn, i_blocksize, i_blocks ); } @@ -218,9 +218,9 @@ read_data_sectors_mmc ( void *p_user_data, void *p_buf, driver_return_code_t set_blocksize_mmc (void *p_user_data, uint16_t i_blocksize) { - generic_img_private_t *p_env = p_user_data; - if (!p_env) return DRIVER_OP_UNINIT; - return mmc_set_blocksize(p_env->cdio, i_blocksize); + generic_img_private_t *p_env = p_user_data; + if (!p_env) return DRIVER_OP_UNINIT; + return mmc_set_blocksize(p_env->cdio, i_blocksize); } /** Set the drive speed Set the drive speed in K bytes per second. (via @@ -229,9 +229,9 @@ set_blocksize_mmc (void *p_user_data, uint16_t i_blocksize) driver_return_code_t set_speed_mmc (void *p_user_data, int i_speed) { - generic_img_private_t *p_env = p_user_data; - if (!p_env) return DRIVER_OP_UNINIT; - return mmc_set_speed( p_env->cdio, i_speed ); + generic_img_private_t *p_env = p_user_data; + if (!p_env) return DRIVER_OP_UNINIT; + return mmc_set_speed( p_env->cdio, i_speed ); } /** @@ -630,9 +630,8 @@ mmc_get_cmd_len(uint8_t scsi_cmd) @return true if the disc is detected as erasable (rewritable), false otherwise. */ -bool - mmc_get_disc_erasable( const CdIo_t *p_cdio, - driver_return_code_t *opt_i_status ) { +bool mmc_get_disc_erasable(const CdIo_t *p_cdio, + driver_return_code_t *opt_i_status) { mmc_cdb_t cdb = {{0, }}; uint8_t buf[42] = { 0, }; driver_return_code_t i_status; @@ -640,8 +639,8 @@ bool CDIO_MMC_SET_COMMAND (cdb.field, CDIO_MMC_GPCMD_READ_DISC_INFO); CDIO_MMC_SET_READ_LENGTH8 (cdb.field, sizeof(buf)); - i_status = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ, - sizeof(buf), &buf); + i_status = mmc_run_cmd(p_cdio, 0, &cdb, SCSI_MMC_DATA_READ, + sizeof(buf), &buf); if (opt_i_status != NULL) *opt_i_status = i_status; return (DRIVER_OP_SUCCESS == i_status) ? ((buf[2] & 0x10) ? true : false) @@ -967,20 +966,20 @@ int mmc_get_tray_status(const CdIo_t *p_cdio) bytes available, <0 in case of internal error. */ int -mmc_last_cmd_sense( const CdIo_t *p_cdio, mmc_request_sense_t **pp_sense) +mmc_last_cmd_sense(const CdIo_t *p_cdio, mmc_request_sense_t **pp_sense) { - generic_img_private_t *gen; - - if (!p_cdio) return DRIVER_OP_UNINIT; - gen = p_cdio->env; - *pp_sense = NULL; - if (gen->scsi_mmc_sense_valid <= 0) + generic_img_private_t *gen; + + if (!p_cdio) return DRIVER_OP_UNINIT; + gen = p_cdio->env; + *pp_sense = NULL; + if (gen->scsi_mmc_sense_valid <= 0) return 0; - *pp_sense = calloc(1, gen->scsi_mmc_sense_valid); - if (*pp_sense == NULL) - return DRIVER_OP_ERROR; - memcpy(*pp_sense, gen->scsi_mmc_sense, gen->scsi_mmc_sense_valid); - return gen->scsi_mmc_sense_valid; + *pp_sense = calloc(1, gen->scsi_mmc_sense_valid); + if (*pp_sense == NULL) + return DRIVER_OP_ERROR; + memcpy(*pp_sense, gen->scsi_mmc_sense, gen->scsi_mmc_sense_valid); + return gen->scsi_mmc_sense_valid; } /** @@ -1006,8 +1005,8 @@ mmc_run_cmd( const CdIo_t *p_cdio, unsigned int i_timeout_ms, if (!p_cdio) return DRIVER_OP_UNINIT; if (!p_cdio->op.run_mmc_cmd) return DRIVER_OP_UNSUPPORTED; return p_cdio->op.run_mmc_cmd(p_cdio->env, i_timeout_ms, - mmc_get_cmd_len(p_cdb->field[0]), - p_cdb, e_direction, i_buf, p_buf); + mmc_get_cmd_len(p_cdb->field[0]), + p_cdb, e_direction, i_buf, p_buf); } /* Added by SukkoPera to allow CDB length to be specified manually */ @@ -1371,7 +1370,7 @@ mmc_set_blocksize ( const CdIo_t *p_cdio, uint16_t i_blocksize) } -/*! +/** Set the drive speed in CD-ROM speed units. @param p_cdio CD structure set by cdio_open(). @@ -1395,38 +1394,6 @@ mmc_set_drive_speed( const CdIo_t *p_cdio, int i_drive_speed ) } -/*! - Set the drive speed in K bytes per second. - - @return the drive speed if greater than 0. -1 if we had an error. is -2 - returned if this is not implemented for the current driver. -*/ -int -mmc_set_speed( const CdIo_t *p_cdio, int i_Kbs_speed ) - -{ - uint8_t buf[14] = { 0, }; - mmc_cdb_t cdb; - - /* If the requested speed is less than 1x 176 kb/s this command - will return an error - it's part of the ATAPI specs. Therefore, - test and stop early. */ - - if ( i_Kbs_speed < 176 ) return -1; - - memset(&cdb, 0, sizeof(mmc_cdb_t)); - CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_SET_SPEED); - CDIO_MMC_SET_LEN16(cdb.field, 2, i_Kbs_speed); - /* Some drives like the Creative 24x CDRW require one to set a - nonzero write speed or else one gets an error back. Some - specifications have setting the value 0xfffff indicate setting to - the maximum allowable speed. - */ - CDIO_MMC_SET_LEN16(cdb.field, 4, 0xffff); - return mmc_run_cmd(p_cdio, 2000, &cdb, SCSI_MMC_DATA_WRITE, - sizeof(buf), buf); -} - /* * Local variables: diff --git a/lib/driver/mmc_cmds.c b/lib/driver/mmc_cmds.c index e7ebb05f..ad46a83d 100644 --- a/lib/driver/mmc_cmds.c +++ b/lib/driver/mmc_cmds.c @@ -83,22 +83,22 @@ driver_return_code_t mmc_get_event_status(const CdIo_t *p_cdio, uint8_t out_buf[2]) { - uint8_t buf[8] = { 0, }; - void *p_buf = &buf; - const unsigned int i_size = sizeof(buf); - driver_return_code_t i_status; - - MMC_CMD_SETUP_READ16(CDIO_MMC_GPCMD_GET_EVENT_STATUS); - - cdb.field[1] = 1; /* We poll for info */ - cdb.field[4] = 1 << 4; /* We want Media events */ - - i_status = MMC_RUN_CMD(SCSI_MMC_DATA_READ); - if (i_status == DRIVER_OP_SUCCESS) { - out_buf[0] = buf[4]; - out_buf[1] = buf[5]; - } - return i_status; + uint8_t buf[8] = { 0, }; + void *p_buf = &buf; + const unsigned int i_size = sizeof(buf); + driver_return_code_t i_status; + + MMC_CMD_SETUP_READ16(CDIO_MMC_GPCMD_GET_EVENT_STATUS); + + cdb.field[1] = 1; /* We poll for info */ + cdb.field[4] = 1 << 4; /* We want Media events */ + + i_status = MMC_RUN_CMD(SCSI_MMC_DATA_READ); + if (i_status == DRIVER_OP_SUCCESS) { + out_buf[0] = buf[4]; + out_buf[1] = buf[5]; + } + return i_status; } /** @@ -119,9 +119,9 @@ mmc_mode_sense( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size, we had an infinite recursion. So we can't use cdio_have_atapi() (until we put in better capability checks.) */ - if ( DRIVER_OP_SUCCESS == mmc_mode_sense_6(p_cdio, p_buf, i_size, page) ) - return DRIVER_OP_SUCCESS; - return mmc_mode_sense_10(p_cdio, p_buf, i_size, page); + if ( DRIVER_OP_SUCCESS == mmc_mode_sense_6(p_cdio, p_buf, i_size, page) ) + return DRIVER_OP_SUCCESS; + return mmc_mode_sense_10(p_cdio, p_buf, i_size, page); } /** @@ -274,50 +274,99 @@ mmc_read_cd(const CdIo_t *p_cdio, void *p_buf1, lsn_t i_lsn, uint8_t subchannel_selection, uint16_t i_blocksize, uint32_t i_blocks) { - void *p_buf = p_buf1; - uint8_t cdb9 = 0; - const unsigned int i_size = i_blocksize * i_blocks; - - MMC_CMD_SETUP(CDIO_MMC_GPCMD_READ_CD); - - CDIO_MMC_SET_READ_TYPE(cdb.field, read_sector_type); - if (b_digital_audio_play) cdb.field[1] |= 0x2; - - if (b_sync) cdb9 |= 128; - if (b_user_data) cdb9 |= 16; - if (b_edc_ecc) cdb9 |= 8; - cdb9 |= (header_codes & 3) << 5; - cdb9 |= (c2_error_information & 3) << 1; - cdb.field[9] = cdb9; - cdb.field[10] = (subchannel_selection & 7); - + void *p_buf = p_buf1; + uint8_t cdb9 = 0; + const unsigned int i_size = i_blocksize * i_blocks; + + MMC_CMD_SETUP(CDIO_MMC_GPCMD_READ_CD); + + CDIO_MMC_SET_READ_TYPE(cdb.field, read_sector_type); + if (b_digital_audio_play) cdb.field[1] |= 0x2; + + if (b_sync) cdb9 |= 128; + if (b_user_data) cdb9 |= 16; + if (b_edc_ecc) cdb9 |= 8; + cdb9 |= (header_codes & 3) << 5; + cdb9 |= (c2_error_information & 3) << 1; + cdb.field[9] = cdb9; + cdb.field[10] = (subchannel_selection & 7); + { - unsigned int j = 0; - int i_status = DRIVER_OP_SUCCESS; - - while (i_blocks > 0) { - const unsigned i_blocks2 = (i_blocks > MAX_CD_READ_BLOCKS) - ? MAX_CD_READ_BLOCKS : i_blocks; + unsigned int j = 0; + int i_status = DRIVER_OP_SUCCESS; - const unsigned int i_size = i_blocksize * i_blocks2; - - p_buf = ((char *)p_buf1 ) + (j * i_blocksize); - CDIO_MMC_SET_READ_LBA (cdb.field, (i_lsn+j)); - CDIO_MMC_SET_READ_LENGTH24(cdb.field, i_blocks2); - - i_status = MMC_RUN_CMD(SCSI_MMC_DATA_READ); - - if (i_status) return i_status; - - i_blocks -= i_blocks2; - j += i_blocks2; - } - return i_status; + while (i_blocks > 0) { + const unsigned i_blocks2 = (i_blocks > MAX_CD_READ_BLOCKS) + ? MAX_CD_READ_BLOCKS : i_blocks; + + const unsigned int i_size = i_blocksize * i_blocks2; + + p_buf = ((char *)p_buf1 ) + (j * i_blocksize); + CDIO_MMC_SET_READ_LBA (cdb.field, (i_lsn+j)); + CDIO_MMC_SET_READ_LENGTH24(cdb.field, i_blocks2); + + i_status = MMC_RUN_CMD(SCSI_MMC_DATA_READ); + + if (i_status) return i_status; + + i_blocks -= i_blocks2; + j += i_blocks2; + } + return i_status; } } /** - Load or Unload media using a MMC START STOP command. + Set the drive speed in K bytes per second using SCSI-MMC SET SPEED. + . + + @param p_cdio CD structure set by cdio_open(). + @param i_Kbs_speed speed in K bytes per second. Note this is + not in standard CD-ROM speed units, e.g. + 1x, 4x, 16x as it is in cdio_set_speed. + To convert CD-ROM speed units to Kbs, + multiply the number by 176 (for raw data) + and by 150 (for filesystem data). + Also note that ATAPI specs say that a value + less than 176 will result in an error. + On many CD-ROM drives, + specifying a value too large will result in using + the fastest speed. + + @return the drive speed if greater than 0. -1 if we had an + error. is -2 returned if this is not implemented for the current + driver. + + @see cdio_set_speed and mmc_set_drive_speed + */ +int +mmc_set_speed(const CdIo_t *p_cdio, int i_Kbs_speed) + +{ + uint8_t buf[14] = { 0, }; + void * p_buf = &buf; + const unsigned int i_size = sizeof(buf); + + MMC_CMD_SETUP(CDIO_MMC_GPCMD_SET_SPEED); + + /* If the requested speed is less than 1x 176 kb/s this command + will return an error - it's part of the ATAPI specs. Therefore, + test and stop early. */ + + if ( i_Kbs_speed < 176 ) return -1; + + CDIO_MMC_SET_LEN16(cdb.field, 2, i_Kbs_speed); + /* Some drives like the Creative 24x CDRW require one to set a + nonzero write speed or else one gets an error back. Some + specifications have setting the value 0xfffff indicate setting to + the maximum allowable speed. + */ + CDIO_MMC_SET_LEN16(cdb.field, 4, 0xffff); + return MMC_RUN_CMD(SCSI_MMC_DATA_WRITE); +} + +/** + Load or Unload media using a MMC START/STOP UNIT command. @param p_cdio the CD object to be acted upon. @param b_eject eject if true and close tray if false @@ -350,4 +399,3 @@ mmc_start_stop_unit(const CdIo_t *p_cdio, bool b_eject, bool b_immediate, return MMC_RUN_CMD(SCSI_MMC_DATA_WRITE); } -