mmc.h: Big endian bytes is not the same as big_endian bitfield

mmc.c: more pervasive use of cdio's mmc definitions.
This commit is contained in:
R. Bernstein
2010-02-04 04:24:43 -05:00
parent e3a5e16cbb
commit 34bc1ec0b4
3 changed files with 27 additions and 29 deletions

View File

@@ -35,6 +35,11 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* On GNU/Linux see <linux/byteorder/big_endian.h> */
#ifndef __BIG_ENDIAN_BITFIELD
#define __MMC_BIG_ENDIAN_BITFIELD
#endif
/** /**
Structure of a SCSI/MMC sense reply. Structure of a SCSI/MMC sense reply.
@@ -44,7 +49,7 @@ extern "C" {
SPC 4.5.3, Table 26. SPC 4.5.3, Table 26.
*/ */
typedef struct mmc_request_sense { typedef struct mmc_request_sense {
#if defined(WORDS_BIGENDIAN) #if defined(__MMC_BIG_ENDIAN_BITFIELD)
uint8_t valid : 1; /**< valid bit is 1 if info is valid */ uint8_t valid : 1; /**< valid bit is 1 if info is valid */
uint8_t error_code : 7; uint8_t error_code : 7;
#else #else
@@ -52,7 +57,7 @@ extern "C" {
uint8_t valid : 1; /**< valid bit is 1 if info is valid */ uint8_t valid : 1; /**< valid bit is 1 if info is valid */
#endif #endif
uint8_t segment_number; uint8_t segment_number;
#if defined(WORDS_BIGENDIAN) #if defined(__MMC_BIG_ENDIAN_BITFIELD)
uint8_t filemark : 1; /**< manditory in sequential uint8_t filemark : 1; /**< manditory in sequential
* access devices */ * access devices */
uint8_t eom : 1; /**< end of medium. manditory in uint8_t eom : 1; /**< end of medium. manditory in

View File

@@ -423,7 +423,7 @@ mmc_mode_sense_6( CdIo_t *p_cdio, void *p_buf, int i_size, int page)
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_MODE_SENSE_6); CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_MODE_SENSE_6);
cdb.field[2] = 0x3F & page; cdb.field[2] = CDIO_MMC_ALL_PAGES & page;
cdb.field[4] = i_size; cdb.field[4] = i_size;
return p_cdio->op.run_mmc_cmd (p_cdio->env, return p_cdio->op.run_mmc_cmd (p_cdio->env,
@@ -455,7 +455,7 @@ mmc_mode_sense_10( CdIo_t *p_cdio, void *p_buf, int i_size, int page)
CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_MODE_SENSE_10); CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_MODE_SENSE_10);
CDIO_MMC_SET_READ_LENGTH16(cdb.field, i_size); CDIO_MMC_SET_READ_LENGTH16(cdb.field, i_size);
cdb.field[2] = 0x3F & page; cdb.field[2] = CDIO_MMC_ALL_PAGES & page;
return p_cdio->op.run_mmc_cmd (p_cdio->env, return p_cdio->op.run_mmc_cmd (p_cdio->env,
mmc_timeout_ms, mmc_timeout_ms,
@@ -1095,13 +1095,13 @@ mmc_last_cmd_sense( const CdIo_t *p_cdio, unsigned char **sense)
*/ */
driver_return_code_t driver_return_code_t
mmc_run_cmd( const CdIo_t *p_cdio, unsigned int i_timeout_ms, mmc_run_cmd( const CdIo_t *p_cdio, unsigned int i_timeout_ms,
const mmc_cdb_t *p_cdb, const mmc_cdb_t *p_cdb,
cdio_mmc_direction_t e_direction, unsigned int i_buf, cdio_mmc_direction_t e_direction, unsigned int i_buf,
/*in/out*/ void *p_buf ) /*in/out*/ void *p_buf )
{ {
if (!p_cdio) return DRIVER_OP_UNINIT; if (!p_cdio) return DRIVER_OP_UNINIT;
if (!p_cdio->op.run_mmc_cmd) return DRIVER_OP_UNSUPPORTED; if (!p_cdio->op.run_mmc_cmd) return DRIVER_OP_UNSUPPORTED;
return p_cdio->op.run_mmc_cmd(p_cdio->env, i_timeout_ms, return p_cdio->op.run_mmc_cmd(p_cdio->env, i_timeout_ms,
mmc_get_cmd_len(p_cdb->field[0]), mmc_get_cmd_len(p_cdb->field[0]),
p_cdb, e_direction, i_buf, p_buf); p_cdb, e_direction, i_buf, p_buf);
} }

View File

@@ -208,30 +208,25 @@ tmmc_load_eject(CdIo_t *p_cdio, int *sense_avail,
@return return value of mmc_run_cmd(), @return return value of mmc_run_cmd(),
or other driver_return_code_t or other driver_return_code_t
*/ */
static int static driver_return_code_t
tmmc_mode_sense(CdIo_t *p_cdio, int *sense_avail,unsigned char sense_reply[18], tmmc_mode_sense(CdIo_t *p_cdio, int *sense_avail,unsigned char sense_reply[18],
int page_code, int subpage_code, int alloc_len, int page_code, int subpage_code, int alloc_len,
unsigned char *buf, int *buf_fill, int flag) unsigned char *buf, int *buf_fill, int flag)
{ {
int i_status; driver_return_code_t i_status;
mmc_cdb_t cdb = {{0, }}; mmc_cdb_t cdb = {{0, }};
if (alloc_len < 10) if (alloc_len < 10)
return DRIVER_OP_BAD_PARAMETER; return DRIVER_OP_BAD_PARAMETER;
memset(cdb.field, 0, 10); mmc_mode_sense_10(p_cdio, buf, alloc_len, page_code);
cdb.field[0] = 0x5a; /* MODE SENSE(10), SPC-3 6.10 */
cdb.field[2] = page_code & 0x3f; /* PC=0 : Current values */
cdb.field[3] = subpage_code & 0xff;
cdb.field[7] = (alloc_len >> 8) & 0xff;
cdb.field[8] = alloc_len & 0xff;
if (flag & 1) if (flag & 1)
fprintf(stderr, "tmmc_mode_sense(0x%X, %X, %d) ... ", fprintf(stderr, "tmmc_mode_sense(0x%X, %X, %d) ... ",
(unsigned int) page_code, (unsigned int) subpage_code, alloc_len); (unsigned int) page_code, (unsigned int) subpage_code, alloc_len);
i_status = mmc_run_cmd(p_cdio, 10000, &cdb, SCSI_MMC_DATA_READ, i_status = mmc_run_cmd(p_cdio, 10000, &cdb, SCSI_MMC_DATA_READ,
alloc_len, buf); alloc_len, buf);
tmmc_handle_outcome(p_cdio, i_status, sense_avail, sense_reply, flag & 1); tmmc_handle_outcome(p_cdio, i_status, sense_avail, sense_reply, flag & 1);
if (i_status != 0) if (DRIVER_OP_SUCCESS != i_status)
return i_status; return i_status;
if (flag & 2) if (flag & 2)
*buf_fill = buf[9] + 10; /* MMC-5 7.2.3 */ *buf_fill = buf[9] + 10; /* MMC-5 7.2.3 */
@@ -276,11 +271,9 @@ tmmc_mode_select(CdIo_t *p_cdio,
printf("\n"); printf("\n");
} }
memset(cdb.field, 0, 10); CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_MODE_SELECT_10); /* SPC-3 6.8 */
cdb.field[0] = 0x55; /* MODE SELECT(10), SPC-3 6.8 */
cdb.field[1] = 0x10; /* PF = 1 : official SCSI mode page */ cdb.field[1] = 0x10; /* PF = 1 : official SCSI mode page */
cdb.field[7] = (buf_fill >> 8) & 0xff; CDIO_MMC_SET_READ_LENGTH16(cdb.field, buf_fill);
cdb.field[8] = buf_fill & 0xff;
if (flag & 1) if (flag & 1)
fprintf(stderr, "tmmc_mode_select(0x%X, %d, %d) ... ", fprintf(stderr, "tmmc_mode_select(0x%X, %d, %d) ... ",
(unsigned int) buf[8], (unsigned int) buf[9], buf_fill); (unsigned int) buf[8], (unsigned int) buf[9], buf_fill);
@@ -305,6 +298,7 @@ tmmc_wait_for_drive(CdIo_t *p_cdio, int max_tries, int flag)
{ {
int ret, i, sense_avail; int ret, i, sense_avail;
unsigned char sense_reply[18]; unsigned char sense_reply[18];
mmc_request_sense_t *p_sense_reply = (mmc_request_sense_t *) sense_reply;
for (i = 0; i < max_tries; i++) { for (i = 0; i < max_tries; i++) {
ret = tmmc_test_unit_ready(p_cdio, &sense_avail, sense_reply, flag & 1); ret = tmmc_test_unit_ready(p_cdio, &sense_avail, sense_reply, flag & 1);
@@ -312,23 +306,22 @@ tmmc_wait_for_drive(CdIo_t *p_cdio, int max_tries, int flag)
return 1; return 1;
if (sense_avail < 18) if (sense_avail < 18)
return -1; return -1;
sense_reply[2] &= 0xf; if (p_sense_reply->sense_key == 2 && sense_reply[12] == 0x04) {
if (sense_reply[2] == 2 && sense_reply[12] == 0x04) {
/* Not ready */; /* Not ready */;
} else if (sense_reply[2] == 6 && sense_reply[12] == 0x28 } else if (p_sense_reply->sense_key == 6 && sense_reply[12] == 0x28
&& sense_reply[13] == 0x00) { && sense_reply[13] == 0x00) {
/* Media change notice = try again */; /* Media change notice = try again */;
} else if (sense_reply[2] == 2 && sense_reply[12] == 0x3a) { } else if (p_sense_reply->sense_key == 2 && sense_reply[12] == 0x3a) {
/* Medium not present */; /* Medium not present */;
if (!(flag & 2)) if (!(flag & 2))
return 1; return 1;
} else if (sense_reply[2] == 0 && sense_reply[12] == 0) { } else if (p_sense_reply->sense_key == 0 && sense_reply[12] == 0) {
/* Error with no sense */; /* Error with no sense */;