diff --git a/example/mmc1.c b/example/mmc1.c index 58771492..67adaace 100644 --- a/example/mmc1.c +++ b/example/mmc1.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2004, 2005, 2008, 2009 Rocky Bernstein + Copyright (C) 2004, 2005, 2008, 2009, 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 @@ -50,8 +50,8 @@ main(int argc, const char *argv[]) return 77; } else { int i_status; /* Result of MMC command */ - char buf[36] = { 0, }; /* Place to hold returned data */ mmc_cdb_t cdb = {{0, }}; /* Command Descriptor Buffer */ + char buf[36] = { 0, }; /* Place to hold returned data */ CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_INQUIRY); cdb.field[4] = sizeof(buf); @@ -59,26 +59,36 @@ main(int argc, const char *argv[]) i_status = mmc_run_cmd(p_cdio, DEFAULT_TIMEOUT_MS, &cdb, SCSI_MMC_DATA_READ, sizeof(buf), &buf); if (i_status == 0) { - char psz_vendor[CDIO_MMC_HW_VENDOR_LEN+1]; - char psz_model[CDIO_MMC_HW_MODEL_LEN+1]; - char psz_rev[CDIO_MMC_HW_REVISION_LEN+1]; - - memcpy(psz_vendor, buf + 8, sizeof(psz_vendor)-1); - psz_vendor[sizeof(psz_vendor)-1] = '\0'; - memcpy(psz_model, - buf + 8 + CDIO_MMC_HW_VENDOR_LEN, - sizeof(psz_model)-1); - psz_model[sizeof(psz_model)-1] = '\0'; - memcpy(psz_rev, - buf + 8 + CDIO_MMC_HW_VENDOR_LEN +CDIO_MMC_HW_MODEL_LEN, - sizeof(psz_rev)-1); - psz_rev[sizeof(psz_rev)-1] = '\0'; - - printf("Vendor: %s\nModel: %s\nRevision: %s\n", - psz_vendor, psz_model, psz_rev); + char psz_vendor[CDIO_MMC_HW_VENDOR_LEN+1]; + char psz_model[CDIO_MMC_HW_MODEL_LEN+1]; + char psz_rev[CDIO_MMC_HW_REVISION_LEN+1]; + + memcpy(psz_vendor, buf + 8, sizeof(psz_vendor)-1); + psz_vendor[sizeof(psz_vendor)-1] = '\0'; + memcpy(psz_model, + buf + 8 + CDIO_MMC_HW_VENDOR_LEN, + sizeof(psz_model)-1); + psz_model[sizeof(psz_model)-1] = '\0'; + memcpy(psz_rev, + buf + 8 + CDIO_MMC_HW_VENDOR_LEN +CDIO_MMC_HW_MODEL_LEN, + sizeof(psz_rev)-1); + psz_rev[sizeof(psz_rev)-1] = '\0'; + + printf("Vendor: %s\nModel: %s\nRevision: %s\n", + psz_vendor, psz_model, psz_rev); } else { printf("Couldn't get INQUIRY data (vendor, model, and revision).\n"); } + + { + driver_return_code_t drc; + bool b_erasable = mmc_get_disc_erasable(p_cdio, &drc); + if (DRIVER_OP_SUCCESS == drc) + printf("Disc is %serasable.\n", b_erasable ? "" : "not "); + else + printf("Can't determine if disc is erasable.\n"); + } + } cdio_destroy(p_cdio); diff --git a/include/cdio/mmc.h b/include/cdio/mmc.h index c1edfd0a..d20c1f44 100644 --- a/include/cdio/mmc.h +++ b/include/cdio/mmc.h @@ -557,11 +557,15 @@ mmc_audio_read_subchannel (CdIo_t *p_cdio, /** Detects if a disc (CD or DVD) is erasable or not. + @param p_user_data the CD object to be acted upon. - @param i_status on return will be set indicate whether the operation - was a success (DRIVER_OP_SUCCESS) or if not to some other value. - @return true if the disc is detected as erasable (rewritable), false - otherwise. + + @param i_status, if not NULL, on return will be set indicate + whether the operation was a success (DRIVER_OP_SUCCESS) or if not + to some other value. + + @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 *i_status ); diff --git a/lib/driver/mmc.c b/lib/driver/mmc.c index 3b8f351d..8c55becd 100644 --- a/lib/driver/mmc.c +++ b/lib/driver/mmc.c @@ -682,29 +682,32 @@ mmc_get_cmd_len(uint8_t scsi_cmd) /** Detects if a disc (CD or DVD) is erasable or not. + @param p_user_data the CD object to be acted upon. - @param i_status on return will be set indicate whether the operation - was a success (DRIVER_OP_SUCCESS) or if not to some other value. + + @param i_status, if not NULL, on return will be set indicate whether + the operation was a success (DRIVER_OP_SUCCESS) or if not to some + other value. + @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 *i_status ) { + 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; + 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, + i_status = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ, sizeof(buf), &buf); - if (*i_status == 0) { - if (buf[2] & 0x10) - return true; - else - return false; - } else - return false; + if (opt_i_status != NULL) *opt_i_status = i_status; + return (DRIVER_OP_SUCCESS == i_status) ? + ((buf[2] & 0x10) ? true : false) + : false; } /** diff --git a/test/driver/mmc.c b/test/driver/mmc.c index 172547c6..84c7fcfc 100644 --- a/test/driver/mmc.c +++ b/test/driver/mmc.c @@ -85,7 +85,10 @@ tmmc_get_disc_erasable(const CdIo_t *p_cdio, const char *psz_source, { driver_return_code_t drc; bool b_erasable = mmc_get_disc_erasable(p_cdio, &drc); - printf("disk is %serasable.\n", b_erasable ? "" : "not "); + if (verbose) + printf("Disc is %serasable.\n", b_erasable ? "" : "not "); + /* Try also with NULL. */ + b_erasable = mmc_get_disc_erasable(p_cdio, NULL); return drc; }