libcdio-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libcdio-devel] Re: Submission of new mmc function for libcdio


From: Frank Endres
Subject: Re: [Libcdio-devel] Re: Submission of new mmc function for libcdio
Date: Sun, 31 Jan 2010 11:07:02 -0100

Hi !

I propose a little modification for "mmc_get_disc erasable" allowing
transmitting "NULL" for the "i_status" parameter (for a programmer who
doesn't need to get status information):
/**
  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.
 */
bool
mmc_get_disc_erasable( const CdIo_t *p_cdio, driver_return_code_t *i_status
) {
    mmc_cdb_t cdb = {{0, }};
    uint8_t buf[42] = { 0, };
    driver_return_code_t status_i = !0;

    CDIO_MMC_SET_COMMAND (cdb.field, CDIO_MMC_GPCMD_READ_DISC_INFO);
    CDIO_MMC_SET_READ_LENGTH8 (cdb.field, sizeof(buf));

    if (i_status == NULL)
        status_i = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ,
                                                    sizeof(buf), &buf);
    else
        *i_status = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ,
                                                    sizeof(buf), &buf);
    if (i_status != NULL && *i_status == 0 || status_i == 0) {
        if (buf[2] & 0x10)
            return true;
        else
            return false;
    } else
        return false;
}


Then I propose two new functions, that I will probably use in
"mmc_get_disc_information":
/**
  Detects if a disc (CD or DVD) is empy 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 empty, false otherwise.
 */
bool
_mmc_get_disc_empty ( const CdIo_t *p_cdio, driver_return_code_t *i_status )
{
    mmc_cdb_t cdb = {{0, }};
    uint8_t buf[42] = { 0, };
    driver_return_code_t status_i = !0;

    CDIO_MMC_SET_COMMAND (cdb.field, CDIO_MMC_GPCMD_READ_DISC_INFO);
    CDIO_MMC_SET_READ_LENGTH8 (cdb.field, sizeof(buf));

    if (i_status == NULL)
        status_i = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ,
                                                    sizeof(buf), &buf);
    else
        *i_status = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ,
                                                    sizeof(buf), &buf);
    if (i_status != NULL && *i_status == 0 || status_i == 0) {
      if (buf[2] & 0x03 == 0x00)
        return true;
      else
        return false;
    } else
       return false;
}


//WARNING INCOMPLETE FUNCTION:
#define CDIO_MMC_GPCMD_READ_FORMAT_CAPACITIES 0x23
/**
  Detects a disc (CD or DVD) ccapacity.
  @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 the detected disc capacity, or 0 (no media present, unknown
  capacity or operation failure); for non writable discs, capacity is equal
to size.
 */
guint32
_mmc_get_disc_capacity ( const CdIo_t *p_cdio, driver_return_code_t
*i_status ) {
    int capacity;
    mmc_cdb_t cdb = {{0, }};
    uint8_t buf[268] = { 0, };
    uint8_t descriptor_type;
    uint8_t *p;
    driver_return_code_t status_i = !0;

    CDIO_MMC_SET_COMMAND (cdb.field, CDIO_MMC_GPCMD_READ_FORMAT_CAPACITIES);
    CDIO_MMC_SET_READ_LENGTH8 (cdb.field, sizeof(buf));

    if (i_status == NULL)
        status_i = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ,
                                                    sizeof(buf), &buf);
    else
        *i_status = mmc_run_cmd (p_cdio, 0, &cdb, SCSI_MMC_DATA_READ,
                                                    sizeof(buf), &buf);
    if (i_status != NULL && *i_status == 0 || status_i == 0) {
        descriptor_type = buf[8] & 0x03;
        if (descriptor_type == 0x03) //no media present or unknown capacity
            capacity =  0;
        else {
            p = buf + 4;
            capacity = CDIO_MMC_GET_LEN32 (p);
            capacity = capacity * 2;
        }
    } else {
        capacity =  0;
    }

    return capacity;
}

What do You think about them ? I am not sure it is a good idea to add too
many functions, but I think it is better to have the much simpler code
possible for "mmc_get_disc_information". If You want to add them, tell me
and I will write the associated tests: do You prefer a patch for
"test/driver/mmc.c" (based on git version) or that I send the code in a
message ? Warning "mmc_get_media_capacity" is just a draft (it doesn't work
with all medias types - is there a simpler way to get capacity ?).

I also have a question: is there a function that gives the size of an
iso9660 formatted media - like the isosize command ("cdio_get_disc_last_lsn"
seems to give incorrect results for DVDs). If not (I haven't found one), I
intend to add a "cdio_get_isosize" function.

I have the same question for UDF formatted media; If You have suggestions on
how to do this, tell me...

Best regards !

Frank


reply via email to

[Prev in Thread] Current Thread [Next in Thread]