diff --git a/include/cdio++/mmc.hpp b/include/cdio++/mmc.hpp index 82af1b09..1e3ef320 100644 --- a/include/cdio++/mmc.hpp +++ b/include/cdio++/mmc.hpp @@ -1,7 +1,5 @@ /* - $Id: mmc.hpp,v 1.3 2008/03/25 15:59:10 karl Exp $ - - Copyright (C) 2005, 2006, 2008 Rocky Bernstein + Copyright (C) 2005, 2006, 2008, 2010 Rocky Bernstein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,12 +15,13 @@ along with this program. If not, see . */ -/** \file mmc.hpp +/** + * \file mmc.hpp * \brief methods relating to MMC (Multimedia Commands). This file * should not be #included directly. */ -/*! +/** Read Audio Subchannel information @param p_cdio the CD object to be acted upon. @@ -37,10 +36,10 @@ mmcAudioReadSubchannel (/*out*/ cdio_subchannel_t *p_subchannel) possible_throw_device_exception(drc); } -/*! +/** Eject using MMC commands. If CD-ROM is "locked" we'll unlock it. Command is not "immediate" -- we'll wait for the command to complete. - For a more general (and lower-level) routine, @see mmc_start_stop_media. + For a more general (and lower-level) routine, @see mmc_start_stop_unit. A DriverOpException is raised on error. */ @@ -50,7 +49,7 @@ void mmcEjectMedia() possible_throw_device_exception(drc); } -/*! +/** Get the lsn of the end of the CD @return the lsn. On error return CDIO_INVALID_LSN. @@ -60,7 +59,7 @@ lsn_t mmcGetDiscLastLsn() return mmc_get_disc_last_lsn( p_cdio ); } -/*! +/** Return the discmode as reported by the MMC Read (FULL) TOC command. @@ -74,7 +73,7 @@ discmode_t mmcGetDiscmode() return mmc_get_discmode( p_cdio ); } -/*! +/** Get drive capabilities for a device. @return the drive capabilities. */ @@ -85,7 +84,7 @@ void mmcGetDriveCap ( /*out*/ cdio_drive_read_cap_t *p_read_cap, mmc_get_drive_cap ( p_cdio, p_read_cap, p_write_cap, p_misc_cap); } -/*! +/** Get the MMC level supported by the device. */ cdio_mmc_level_t mmcGetDriveMmcCap() @@ -93,7 +92,7 @@ cdio_mmc_level_t mmcGetDriveMmcCap() return mmc_get_drive_mmc_cap(p_cdio); } -/*! +/** Get the DVD type associated with cd object. @return the DVD discmode. @@ -103,7 +102,7 @@ discmode_t mmcGetDvdStructPhysical (cdio_dvd_struct_t *s) return mmc_get_dvd_struct_physical (p_cdio, s); } -/*! +/** Get the CD-ROM hardware info via an MMC INQUIRY command. @return true if we were able to get hardware info, false if we had @@ -114,7 +113,7 @@ bool mmcGetHwinfo ( /* out*/ cdio_hwinfo_t *p_hw_info ) return mmc_get_hwinfo ( p_cdio, p_hw_info ); } -/*! +/** Find out if media has changed since the last call. @param p_cdio the CD object to be acted upon. @return 1 if media has changed since last call, 0 if not. Error @@ -125,7 +124,7 @@ int mmcGetMediaChanged() return mmc_get_media_changed(p_cdio); } -/*! +/** Get the media catalog number (MCN) from the CD via MMC. @return the media catalog number r NULL if there is none or we @@ -140,7 +139,8 @@ char * mmcGetMcn () return mmc_get_mcn ( p_cdio ); } -/** Get the output port volumes and port selections used on AUDIO PLAY +/** + Get the output port volumes and port selections used on AUDIO PLAY commands via a MMC MODE SENSE command using the CD Audio Control Page. @@ -152,7 +152,7 @@ void mmcAudioGetVolume (mmc_audio_volume_t *p_volume) possible_throw_device_exception(drc); } -/*! +/** Report if CD-ROM has a praticular kind of interface (ATAPI, SCSCI, ...) Is it possible for an interface to have serveral? If not this routine could probably return the single mmc_feature_interface_t. @@ -163,34 +163,38 @@ bool_3way_t mmcHaveInterface( cdio_mmc_feature_interface_t e_interface ) return mmc_have_interface( p_cdio, e_interface ); } -/*! Run a MODE_SENSE command (6- or 10-byte version) - and put the results in p_buf - @return DRIVER_OP_SUCCESS if we ran the command ok. +/** + Run a MODE_SENSE command (6- or 10-byte version) + and put the results in p_buf + @return DRIVER_OP_SUCCESS if we ran the command ok. */ int mmcModeSense( /*out*/ void *p_buf, int i_size, int page) { return mmc_mode_sense( p_cdio, /*out*/ p_buf, i_size, page); } -/*! Run a MODE_SENSE command (10-byte version) - and put the results in p_buf - @return DRIVER_OP_SUCCESS if we ran the command ok. +/** + Run a MODE_SENSE command (10-byte version) + and put the results in p_buf + @return DRIVER_OP_SUCCESS if we ran the command ok. */ int mmcModeSense10( /*out*/ void *p_buf, int i_size, int page) { return mmc_mode_sense_10( p_cdio, /*out*/ p_buf, i_size, page); } -/*! Run a MODE_SENSE command (6-byte version) - and put the results in p_buf - @return DRIVER_OP_SUCCESS if we ran the command ok. +/** + Run a MODE_SENSE command (6-byte version) + and put the results in p_buf + @return DRIVER_OP_SUCCESS if we ran the command ok. */ int mmcModeSense6( /*out*/ void *p_buf, int i_size, int page) { return mmc_mode_sense_6( p_cdio, /*out*/ p_buf, i_size, page); } -/*! Issue a MMC READ_CD command. +/** + Issue a MMC READ_CD command. @param p_cdio object to read from @@ -306,7 +310,9 @@ mmcReadCd ( void *p_buf, lsn_t i_lsn, int expected_sector_type, possible_throw_device_exception(drc); } -/*! Read just the user data part of some sort of data sector (via +/** + + Read just the user data part of some sort of data sector (via mmc_read_cd). @param p_cdio object to read from @@ -333,7 +339,8 @@ void mmcReadDataSectors ( void *p_buf, lsn_t i_lsn, uint16_t i_blocksize, } -/*! Read MMC read mode2 sectors +/** + Read MMC read mode2 sectors A DriverOpException is raised on error. */ @@ -345,7 +352,7 @@ void mmcReadSectors ( void *p_buf, lsn_t i_lsn, int read_sector_type, possible_throw_device_exception(drc); } -/*! +/** Run an MMC command. @param p_cdio CD structure set by cdio_open(). @@ -367,7 +374,7 @@ int mmcRunCmd( unsigned int i_timeout_ms, const mmc_cdb_t *p_cdb, return mmc_run_cmd( p_cdio, i_timeout_ms, p_cdb, e_direction, i_buf, p_buf ); } -/*! +/** Set the block size for subsequent read requests, via MMC. @param i_blocksize size to set for subsequent requests @@ -381,7 +388,7 @@ void mmcSetBlocksize ( uint16_t i_blocksize) } -/*! +/** Set the drive speed via MMC. @param i_speed speed to set drive to. @@ -394,7 +401,7 @@ void mmcSetSpeed( int i_speed ) possible_throw_device_exception(drc); } -/*! +/** Load or Unload media using a MMC START STOP command. @param p_cdio the CD object to be acted upon. @@ -411,7 +418,7 @@ void mmcStartStopMedia(bool b_eject, bool b_immediate, uint8_t power_condition) { driver_return_code_t drc = - mmc_start_stop_media(p_cdio, b_eject, b_immediate, power_condition); + mmc_start_stop_unit(p_cdio, b_eject, b_immediate, power_condition); possible_throw_device_exception(drc); } diff --git a/include/cdio/mmc.h b/include/cdio/mmc.h index 8a1bedaa..eca5793b 100644 --- a/include/cdio/mmc.h +++ b/include/cdio/mmc.h @@ -171,7 +171,7 @@ extern "C" { before MODE SELECT to get mode support or save current settings. (6 bytes). */ - CDIO_MMC_GPCMD_START_STOP = 0x1b, /**< Enable/disable Disc + CDIO_MMC_GPCMD_START_STOP_UNIT = 0x1b, /**< Enable/disable Disc operations. (6 bytes). */ CDIO_MMC_GPCMD_ALLOW_MEDIUM_REMOVAL = 0x1e, /**< Enable/disable Disc removal. (6 bytes). */ @@ -617,7 +617,7 @@ mmc_audio_read_subchannel (CdIo_t *p_cdio, /** Eject using MMC commands. If CD-ROM is "locked" we'll unlock it. Command is not "immediate" -- we'll wait for the command to complete. - For a more general (and lower-level) routine, @see mmc_start_stop_media. + For a more general (and lower-level) routine, @see mmc_start_stop_unit. @param p_cdio the CD object to be acted upon. @return DRIVER_OP_SUCCESS (0) if we got the status. @@ -674,7 +674,7 @@ mmc_audio_read_subchannel (CdIo_t *p_cdio, lsn_t mmc_get_disc_last_lsn( const CdIo_t *p_cdio ); /** - Close tray using a MMC START STOP command. + Close tray using a MMC START STOP UNIT command. @param p_cdio the CD object to be acted upon. @return DRIVER_OP_SUCCESS (0) if we got the status. return codes are the same as driver_return_code_t @@ -930,21 +930,6 @@ mmc_audio_read_subchannel (CdIo_t *p_cdio, 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 command. - - @param p_cdio the CD object to be acted upon. - @param b_eject eject if true and close tray if false - @param b_immediate wait or don't wait for operation to complete - @param power_condition Set CD-ROM to idle/standby/sleep. If nonzero, - eject/load is ignored, so set to 0 if you want to eject or load. - - @see mmc_eject_media or mmc_close_tray - */ - driver_return_code_t - mmc_start_stop_media(const CdIo_t *p_cdio, bool b_eject, bool b_immediate, - uint8_t power_condition); - #ifdef __cplusplus } #endif /* __cplusplus */ @@ -965,6 +950,10 @@ extern cdio_mmc_read_cd_type_t debug_cdio_mmc_read_cd_type; extern cdio_mmc_readtoc_t debug_cdio_mmc_readtoc; extern cdio_mmc_mode_page_t debug_cdio_mmc_mode_page; +#ifndef DO_NOT_WANT_OLD_MMC_COMPATIBILITY +#define CDIO_MMC_GPCMD_START_STOP CDIO_MMC_GPCMD_START_STOP_UNIT +#endif /*DO_NOT_WANT_PARANOIA_COMPATIBILITY*/ + #endif /* __MMC_H__ */ /* diff --git a/include/cdio/mmc_cmds.h b/include/cdio/mmc_cmds.h index 115d4769..cbc664b3 100644 --- a/include/cdio/mmc_cmds.h +++ b/include/cdio/mmc_cmds.h @@ -59,8 +59,8 @@ extern "C" { @param page which "page" of the mode sense command we are interested in @return DRIVER_OP_SUCCESS if we ran the command ok. */ - int mmc_mode_sense( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size, - int page); + driver_return_code_t mmc_mode_sense( CdIo_t *p_cdio, /*out*/ void *p_buf, + int i_size, int page); /** Run a MODE_SENSE command (10-byte version) @@ -71,8 +71,8 @@ extern "C" { @param page which "page" of the mode sense command we are interested in @return DRIVER_OP_SUCCESS if we ran the command ok. */ - int mmc_mode_sense_10( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size, - int page); + driver_return_code_t mmc_mode_sense_10( CdIo_t *p_cdio, /*out*/ void *p_buf, + int i_size, int page); /** Run a MODE_SENSE command (6-byte version) @@ -83,8 +83,8 @@ extern "C" { @param page which "page" of the mode sense command we are interested in @return DRIVER_OP_SUCCESS if we ran the command ok. */ - int mmc_mode_sense_6( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size, - int page); + driver_return_code_t mmc_mode_sense_6( CdIo_t *p_cdio, /*out*/ void *p_buf, + int i_size, int page); /** Issue a MMC READ_CD command. @@ -194,6 +194,25 @@ extern "C" { uint8_t subchannel_selection, uint16_t i_blocksize, uint32_t i_blocks ); + /** + 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 + @param b_immediate wait or don't wait for operation to complete + @param power_condition Set CD-ROM to idle/standby/sleep. If nonzero, + eject/load is ignored, so set to 0 if you want to eject or load. + + @see mmc_eject_media or mmc_close_tray + */ + driver_return_code_t + mmc_start_stop_unit(const CdIo_t *p_cdio, bool b_eject, bool b_immediate, + uint8_t power_condition); + +#ifndef DO_NOT_WANT_OLD_MMC_COMPATIBILITY +#define mmc_start_stop_media mmc_start_stop_unit +#endif /*DO_NOT_WANT_PARANOIA_COMPATIBILITY*/ + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lib/driver/mmc.c b/lib/driver/mmc.c index 3e86a36a..8922ed9f 100644 --- a/lib/driver/mmc.c +++ b/lib/driver/mmc.c @@ -1045,7 +1045,7 @@ mmc_run_cmd_len( const CdIo_t *p_cdio, unsigned int i_timeout_ms, } /** - Close tray using a MMC START STOP command. + Close tray using a MMC START STOP UNIT command. @param p_cdio the CD object to be acted upon. @return DRIVER_OP_SUCCESS (0) if we got the status. return codes are the same as driver_return_code_t @@ -1054,7 +1054,7 @@ driver_return_code_t mmc_close_tray( CdIo_t *p_cdio ) { if (p_cdio) { - return mmc_start_stop_media(p_cdio, false, false, 0); + return mmc_start_stop_unit(p_cdio, false, false, 0); } else { return DRIVER_OP_ERROR; } @@ -1086,7 +1086,7 @@ mmc_eject_media( const CdIo_t *p_cdio ) SCSI_MMC_DATA_WRITE, 0, &buf); if (0 != i_status) return i_status; - return mmc_start_stop_media(p_cdio, true, false, 0); + return mmc_start_stop_unit(p_cdio, true, false, 0); } diff --git a/lib/driver/mmc_cmds.c b/lib/driver/mmc_cmds.c index fa2871bb..e7ebb05f 100644 --- a/lib/driver/mmc_cmds.c +++ b/lib/driver/mmc_cmds.c @@ -30,6 +30,50 @@ #include #endif +/* Boilerplate initialization code to setup running MMC command. We + assume variables 'p_cdio', 'p_buf', and 'i_size' are previously + defined. It does the following: + + 1. Defines a cdb variable, + 2 Checks to see if we have a cdio object and can run an MMC command + 3. zeros the buffer (p_buf) using i_size. + 4. Sets up the command field of cdb to passed in value mmc_cmd. +*/ +#define MMC_CMD_SETUP(mmc_cmd) \ + mmc_cdb_t cdb = {{0, }}; \ + \ + if ( ! p_cdio ) return DRIVER_OP_UNINIT; \ + if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED; \ + \ + memset (p_buf, 0, i_size); \ + CDIO_MMC_SET_COMMAND(cdb.field, mmc_cmd) + +/* Boilerplate initialization code to setup running MMC read command + needs to set the cdb 16-bit length field. See above + comment for MMC_CMD_SETUP. +*/ +#define MMC_CMD_SETUP_READ16(mmc_cmd) \ + MMC_CMD_SETUP(mmc_cmd); \ + \ + /* Setup to read header, to get length of data */ \ + CDIO_MMC_SET_READ_LENGTH16(cdb.field, i_size) + +/* Boilerplate code to run a MMC command. + + We assume variables 'p_cdio', 'mmc_timeout_ms', 'cdb', 'i_size' and + 'p_buf' are defined previously. + + 'direction' is the SCSI direction (read, write, none) of the + command. +*/ +#define MMC_RUN_CMD(direction) \ + p_cdio->op.run_mmc_cmd(p_cdio->env, \ + mmc_timeout_ms, \ + mmc_get_cmd_len(cdb.field[0]), \ + &cdb, \ + direction, i_size, p_buf) + + /** Return results of media status @param p_cdio the CD object to be acted upon. @@ -39,26 +83,18 @@ driver_return_code_t mmc_get_event_status(const CdIo_t *p_cdio, uint8_t out_buf[2]) { - mmc_cdb_t cdb = {{0, }}; uint8_t buf[8] = { 0, }; - int i_status; - - if ( ! p_cdio ) return DRIVER_OP_UNINIT; - if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED; - - CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_GET_EVENT_STATUS); - - /* Setup to read header, to get length of data */ - CDIO_MMC_SET_READ_LENGTH16(cdb.field, sizeof(buf)); + 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 = p_cdio->op.run_mmc_cmd(p_cdio->env, mmc_timeout_ms, - mmc_get_cmd_len(cdb.field[0]), - &cdb, SCSI_MMC_DATA_READ, - sizeof(buf), buf); - if(i_status == DRIVER_OP_SUCCESS) { + 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]; } @@ -74,7 +110,7 @@ mmc_get_event_status(const CdIo_t *p_cdio, uint8_t out_buf[2]) @param page which "page" of the mode sense command we are interested in @return DRIVER_OP_SUCCESS if we ran the command ok. */ -int +driver_return_code_t mmc_mode_sense( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size, int page) { @@ -97,25 +133,12 @@ mmc_mode_sense( CdIo_t *p_cdio, /*out*/ void *p_buf, int i_size, @param page which "page" of the mode sense command we are interested in @return DRIVER_OP_SUCCESS if we ran the command ok. */ -int +driver_return_code_t mmc_mode_sense_10( CdIo_t *p_cdio, void *p_buf, int i_size, int page) { - mmc_cdb_t cdb = {{0, }}; - - if ( ! p_cdio ) return DRIVER_OP_UNINIT; - if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED; - - memset (p_buf, 0, i_size); - - CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_MODE_SENSE_10); - CDIO_MMC_SET_READ_LENGTH16(cdb.field, i_size); - - cdb.field[2] = CDIO_MMC_ALL_PAGES & page; - - return p_cdio->op.run_mmc_cmd (p_cdio->env, - mmc_timeout_ms, - mmc_get_cmd_len(cdb.field[0]), &cdb, - SCSI_MMC_DATA_READ, i_size, p_buf); + MMC_CMD_SETUP_READ16(CDIO_MMC_GPCMD_MODE_SENSE_10); + cdb.field[2] = CDIO_MMC_ALL_PAGES & page; + return MMC_RUN_CMD(SCSI_MMC_DATA_READ); } /** @@ -127,25 +150,15 @@ mmc_mode_sense_10( CdIo_t *p_cdio, void *p_buf, int i_size, int page) @param page which "page" of the mode sense command we are interested in @return DRIVER_OP_SUCCESS if we ran the command ok. */ -int +driver_return_code_t mmc_mode_sense_6( CdIo_t *p_cdio, void *p_buf, int i_size, int page) { - mmc_cdb_t cdb = {{0, }}; + MMC_CMD_SETUP(CDIO_MMC_GPCMD_MODE_SENSE_6); + cdb.field[4] = i_size; + + cdb.field[2] = CDIO_MMC_ALL_PAGES & page; - if ( ! p_cdio ) return DRIVER_OP_UNINIT; - if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED; - - memset (p_buf, 0, i_size); - - CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_MODE_SENSE_6); - - cdb.field[2] = CDIO_MMC_ALL_PAGES & page; - cdb.field[4] = i_size; - - return p_cdio->op.run_mmc_cmd (p_cdio->env, - mmc_timeout_ms, - mmc_get_cmd_len(cdb.field[0]), &cdb, - SCSI_MMC_DATA_READ, i_size, p_buf); + return MMC_RUN_CMD(SCSI_MMC_DATA_READ); } /* Maximum blocks to retrieve. Would be nice to customize this based on @@ -159,8 +172,8 @@ mmc_mode_sense_6( CdIo_t *p_cdio, void *p_buf, int i_size, int page) @param p_cdio object to read from - @param p_buf Place to store data. The caller should ensure that - p_buf can hold at least i_blocksize * i_blocks bytes. + @param p_buf1 Place to store data. The caller should ensure that + p_buf1 can hold at least i_blocksize * i_blocks bytes. @param i_lsn sector to read @@ -254,24 +267,19 @@ mmc_mode_sense_6( CdIo_t *p_cdio, void *p_buf, int i_size, int page) @param i_blocks number of blocks expected to be returned. */ driver_return_code_t -mmc_read_cd ( const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn, - int read_sector_type, bool b_digital_audio_play, - bool b_sync, uint8_t header_codes, bool b_user_data, - bool b_edc_ecc, uint8_t c2_error_information, - uint8_t subchannel_selection, uint16_t i_blocksize, - uint32_t i_blocks ) +mmc_read_cd(const CdIo_t *p_cdio, void *p_buf1, lsn_t i_lsn, + int read_sector_type, bool b_digital_audio_play, + bool b_sync, uint8_t header_codes, bool b_user_data, + bool b_edc_ecc, uint8_t c2_error_information, + uint8_t subchannel_selection, uint16_t i_blocksize, + uint32_t i_blocks) { - mmc_cdb_t cdb = {{0, }}; - - mmc_run_cmd_fn_t run_mmc_cmd; + 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); - if (!p_cdio) return DRIVER_OP_UNINIT; - if (!p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED; - - run_mmc_cmd = p_cdio->op.run_mmc_cmd; - - CDIO_MMC_SET_COMMAND (cdb.field, CDIO_MMC_GPCMD_READ_CD); CDIO_MMC_SET_READ_TYPE(cdb.field, read_sector_type); if (b_digital_audio_play) cdb.field[1] |= 0x2; @@ -285,29 +293,26 @@ mmc_read_cd ( const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn, { unsigned int j = 0; - int i_ret = DRIVER_OP_SUCCESS; - const uint8_t i_cdb = mmc_get_cmd_len(cdb.field[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; - void *p_buf2 = ((char *)p_buf ) + (j * i_blocksize); + 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_ret = run_mmc_cmd (p_cdio->env, CD_READ_TIMEOUT_MS, - i_cdb, &cdb, - SCSI_MMC_DATA_READ, - i_blocksize * i_blocks2, - p_buf2); + i_status = MMC_RUN_CMD(SCSI_MMC_DATA_READ); - if (i_ret) return i_ret; + if (i_status) return i_status; i_blocks -= i_blocks2; j += i_blocks2; } - return i_ret; + return i_status; } } @@ -323,16 +328,14 @@ mmc_read_cd ( const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn, @see mmc_eject_media or mmc_close_tray */ driver_return_code_t -mmc_start_stop_media(const CdIo_t *p_cdio, bool b_eject, bool b_immediate, - uint8_t power_condition) +mmc_start_stop_unit(const CdIo_t *p_cdio, bool b_eject, bool b_immediate, + uint8_t power_condition) { - mmc_cdb_t cdb = {{0, }}; uint8_t buf[1]; + void * p_buf = &buf; + const unsigned int i_size = 0; - if ( ! p_cdio ) return DRIVER_OP_UNINIT; - if ( ! p_cdio->op.run_mmc_cmd ) return DRIVER_OP_UNSUPPORTED; - - CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_START_STOP); + MMC_CMD_SETUP_READ16(CDIO_MMC_GPCMD_START_STOP_UNIT); if (b_immediate) cdb.field[1] |= 1; @@ -344,9 +347,7 @@ mmc_start_stop_media(const CdIo_t *p_cdio, bool b_eject, bool b_immediate, else cdb.field[4] = 3; /* close tray for tray-type */ } - - return p_cdio->op.run_mmc_cmd (p_cdio->env, mmc_timeout_ms, - mmc_get_cmd_len(cdb.field[0]), &cdb, - SCSI_MMC_DATA_WRITE, 0, &buf); + + return MMC_RUN_CMD(SCSI_MMC_DATA_WRITE); } diff --git a/src/mmc-tool.c b/src/mmc-tool.c index f0e9ec55..427e35e4 100644 --- a/src/mmc-tool.c +++ b/src/mmc-tool.c @@ -89,7 +89,7 @@ push_op(operation_t *p_op) } } -/* Parse a options. */ +/* Parse command-line options. */ static bool parse_options (int argc, char *argv[]) { @@ -488,7 +488,7 @@ main(int argc, char *argv[]) if (p_op->arg.psz) free(p_op->arg.psz); break; case OP_IDLE: - rc = mmc_start_stop_media(p_cdio, false, false, true); + rc = mmc_start_stop_unit(p_cdio, false, false, true); report(stdout, "%s (mmc_start_stop_media - powerdown): %s\n", program_name, cdio_driver_errmsg(rc)); break; @@ -519,7 +519,6 @@ main(int argc, char *argv[]) ; } } - free(source_name); cdio_destroy(p_cdio); diff --git a/test/driver/mmc.c b/test/driver/mmc.c index 58b0da9d..1a3b5791 100644 --- a/test/driver/mmc.c +++ b/test/driver/mmc.c @@ -177,7 +177,7 @@ tmmc_load_eject(CdIo_t *p_cdio, int *sense_avail, bool b_eject = !!(flag & 4); bool b_immediate = !!(flag & 2); - i_status = mmc_start_stop_media(p_cdio, b_eject, b_immediate, 0); + i_status = mmc_start_stop_unit(p_cdio, b_eject, b_immediate, 0); if (flag & 1) fprintf(stderr, "tmmc_load_eject(0x%X) ... ", (unsigned int) flag);