/*! Reads a single mode1 form1 or form2 sector from cd device into data starting from lsn. Returns 0 if no error. */ int cdio_read_mode1_sector (const CdIo *cdio, void *data, lsn_t lsn, bool is_form2) { uint32_t size = is_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE ; char buf[M2RAW_SECTOR_SIZE] = { 0, }; int ret; cdio_assert (cdio != NULL); cdio_assert (data != NULL); if (cdio->op.lseek && cdio->op.read) { if (0 > cdio_lseek(cdio, CDIO_CD_FRAMESIZE*lsn, SEEK_SET)) return -1; if (0 > cdio_read(cdio, buf, CDIO_CD_FRAMESIZE)) return -1; memcpy (data, buf, size); return 0; } else { ret = cdio_read_mode2_sector(cdio, data, lsn, is_form2); if (ret == 0) memcpy (data, buf+CDIO_CD_SUBHEADER_SIZE, size); } return ret; }
/*! Reads a single mode1 form1 or form2 sector from cd device into data starting from lsn. Returns DRIVER_OP_SUCCESS if no error. */ driver_return_code_t cdio_read_mode1_sector (const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn, bool b_form2) { uint32_t size = b_form2 ? M2RAW_SECTOR_SIZE : CDIO_CD_FRAMESIZE ; check_lsn(i_lsn); if (p_cdio->op.read_mode1_sector) { return p_cdio->op.read_mode1_sector(p_cdio->env, p_buf, i_lsn, b_form2); } else if (p_cdio->op.lseek && p_cdio->op.read) { char buf[M2RAW_SECTOR_SIZE] = { 0, }; if (0 > cdio_lseek(p_cdio, CDIO_CD_FRAMESIZE*i_lsn, SEEK_SET)) return -1; if (0 > cdio_read(p_cdio, buf, CDIO_CD_FRAMESIZE)) return -1; memcpy (p_buf, buf, size); return DRIVER_OP_SUCCESS; } return DRIVER_OP_UNSUPPORTED; }
/*! Reads into buf the next size bytes. Similar to (if not the same as) libc's read() @param p_buf place to read data into. The caller should make sure this location can store at least i_size bytes. @param i_size number of bytes to read @return (ssize_t) -1 on error. */ ssize_t read(void *p_buf, size_t i_size) { return cdio_read(p_cdio, p_buf, i_size); }