Exemplo n.º 1
0
/* Packet driver to read mode2 sectors. 
   Can read only up to 25 blocks.
*/
static int
_cdio_mmc_read_sectors (int fd, void *buf, lba_t lba, int sector_type, 
			unsigned int nblocks)
{
  typedef struct cdrom_generic_command cgc_t;
  cgc_t cgc;

  memset (&cgc, 0, sizeof (cgc_t));

  cgc.cmd[0] = CDIO_MMC_GPCMD_READ_CD;
  CDIO_MMC_SET_READ_TYPE  (cgc.cmd, sector_type);
  CDIO_MMC_SET_READ_LBA   (cgc.cmd, lba);
  CDIO_MMC_SET_READ_LENGTH(cgc.cmd, nblocks);
  CDIO_MMC_SET_MAIN_CHANNEL_SELECTION_BITS(cgc.cmd, CDIO_MMC_MCSB_ALL_HEADERS);

  cgc.buflen = CDIO_CD_FRAMESIZE_RAW * nblocks; 
  cgc.buffer = buf;

#ifdef HAVE_LINUX_CDROM_TIMEOUT
  cgc.timeout = 500;
#endif
  cgc.data_direction = CGC_DATA_READ;

  return ioctl (fd, CDROM_SEND_PACKET, &cgc);

  return 0;
}
Exemplo n.º 2
0
/**
   Issue a MMC READ_CD command.
   
   @param p_cdio  object to read from 
   
   @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 
   
   @param expected_sector_type restricts reading to a specific CD
   sector type.  Only 3 bits with values 1-5 are used:
   0 all sector types
   1 CD-DA sectors only 
   2 Mode 1 sectors only
   3 Mode 2 formless sectors only. Note in contrast to all other
   values an MMC CD-ROM is not required to support this mode.
   4 Mode 2 Form 1 sectors only
   5 Mode 2 Form 2 sectors only
   
   @param b_digital_audio_play Control error concealment when the
   data being read is CD-DA.  If the data being read is not CD-DA,
   this parameter is ignored.  If the data being read is CD-DA and
   DAP is false zero, then the user data returned should not be
   modified by flaw obscuring mechanisms such as audio data mute and
   interpolate.  If the data being read is CD-DA and DAP is true,
   then the user data returned should be modified by flaw obscuring
   mechanisms such as audio data mute and interpolate.  
   
   b_sync_header return the sync header (which will probably have
   the same value as CDIO_SECTOR_SYNC_HEADER of size
   CDIO_CD_SYNC_SIZE).
   
   @param header_codes Header Codes refer to the sector header and
   the sub-header that is present in mode 2 formed sectors: 
   
   0 No header information is returned.  
   1 The 4-byte sector header of data sectors is be returned, 
   2 The 8-byte sector sub-header of mode 2 formed sectors is
   returned.  
   3 Both sector header and sub-header (12 bytes) is returned.  
   The Header preceeds the rest of the bytes (e.g. user-data bytes) 
   that might get returned.
   
   @param b_user_data  Return user data if true. 
   
   For CD-DA, the User Data is CDIO_CD_FRAMESIZE_RAW bytes.
   
   For Mode 1, The User Data is ISO_BLOCKSIZE bytes beginning at
   offset CDIO_CD_HEADER_SIZE+CDIO_CD_SUBHEADER_SIZE.
   
   For Mode 2 formless, The User Data is M2RAW_SECTOR_SIZE bytes
   beginning at offset CDIO_CD_HEADER_SIZE+CDIO_CD_SUBHEADER_SIZE.
   
   For data Mode 2, form 1, User Data is ISO_BLOCKSIZE bytes beginning at
   offset CDIO_CD_XA_SYNC_HEADER.
   
   For data Mode 2, form 2, User Data is 2 324 bytes beginning at
   offset CDIO_CD_XA_SYNC_HEADER.
   
   @param b_sync 
   
   @param b_edc_ecc true if we return EDC/ECC error detection/correction bits.
   
   The presence and size of EDC redundancy or ECC parity is defined
   according to sector type: 
   
   CD-DA sectors have neither EDC redundancy nor ECC parity.  
   
   Data Mode 1 sectors have 288 bytes of EDC redundancy, Pad, and
   ECC parity beginning at offset 2064.
   
   Data Mode 2 formless sectors have neither EDC redundancy nor ECC
   parity
   
   Data Mode 2 form 1 sectors have 280 bytes of EDC redundancy and
   ECC parity beginning at offset 2072
   
   Data Mode 2 form 2 sectors optionally have 4 bytes of EDC
   redundancy beginning at offset 2348.
   
   @param c2_error_information If true associate a bit with each
   sector for C2 error The resulting bit field is ordered exactly as
   the main channel bytes.  Each 8-bit boundary defines a byte of
   flag bits.
   
   @param subchannel_selection subchannel-selection bits
   
   0  No Sub-channel data shall be returned.  (0 bytes)
   1  RAW P-W Sub-channel data shall be returned.  (96 byte)
   2  Formatted Q sub-channel data shall be transferred (16 bytes)
   3  Reserved     
   4  Corrected and de-interleaved R-W sub-channel (96 bytes)
   5-7  Reserved
   
   @param i_blocksize size of the a block expected to be returned
   
   @param i_blocks number of blocks expected to be returned.

   @return DRIVER_OP_SUCCESS if we ran the command ok.
*/
driver_return_code_t
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)
{
    void *p_buf = p_buf1;
    uint8_t cdb9 = 0;
    const unsigned int i_timeout = mmc_timeout_ms * (MAX_CD_READ_BLOCKS/2);

    MMC_CMD_SETUP(CDIO_MMC_GPCMD_READ_CD);

    /* Catch what may be a common bug. */
    if (NULL == p_buf) return DRIVER_OP_BAD_POINTER;

    CDIO_MMC_SET_READ_TYPE(cdb.field, read_sector_type);
    if (b_digital_audio_play) cdb.field[1] |= 0x2;
    
    if (b_sync)      cdb9 |= 128;
    if (b_user_data) cdb9 |=  16;
    if (b_edc_ecc)   cdb9 |=   8;
    cdb9 |= (header_codes & 3)         << 5;
    cdb9 |= (c2_error_information & 3) << 1;
    cdb.field[9]  = cdb9;
    cdb.field[10] = (subchannel_selection & 7);
    
  {
      unsigned int j = 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;
          
          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_status = MMC_RUN_CMD(SCSI_MMC_DATA_READ, i_timeout);
          
          if (i_status) return i_status;
          
          i_blocks -= i_blocks2;
          j += i_blocks2;
      }
      return i_status;
  }
}
Exemplo n.º 3
0
/* Packet driver to read mode2 sectors. 
   Can read only up to 25 blocks.
*/
static int
__read_packet_mode2_sectors (int fd, void *buf, lba_t lba, 
			     unsigned int nblocks, bool use_read_10)
{
  struct cdrom_generic_command cgc;

  memset (&cgc, 0, sizeof (struct cdrom_generic_command));

  cgc.cmd[0] = use_read_10 ? GPCMD_READ_10 : CDIO_MMC_GPCMD_READ_CD;

  CDIO_MMC_SET_READ_LBA(cgc.cmd, lba);
  CDIO_MMC_SET_READ_LENGTH(cgc.cmd, nblocks);

  if (!use_read_10)
    {
      cgc.cmd[1] = 0; /* sector size mode2 */

      cgc.cmd[9] = 0x58; /* 2336 mode2 */
    }

  cgc.buflen = 2336 * nblocks;
  cgc.buffer = buf;

#ifdef HAVE_LINUX_CDROM_TIMEOUT
  cgc.timeout = 500;
#endif
  cgc.data_direction = CGC_DATA_READ;

  if (use_read_10)
    {
      int retval;

      if ((retval = _set_bsize (fd, 2336)))
	return retval;

      if ((retval = ioctl (fd, CDROM_SEND_PACKET, &cgc)))
	{
	  _set_bsize (fd, 2048);
	  return retval;
	}

      if ((retval = _set_bsize (fd, 2048)))
	return retval;
    }
  else
    return ioctl (fd, CDROM_SEND_PACKET, &cgc);

  return 0;
}
Exemplo n.º 4
0
/*!
   Reads a single raw sector using the DeviceIoControl method into
   data starting from lsn. Returns 0 if no error.
 */
static int
read_raw_sector (_img_private_t *p_env, void *p_buf, lsn_t lsn) 
{
  mmc_cdb_t cdb = {{0, }};

  /* ReadCD CDB12 command.  The values were taken from MMC1 draft paper. */
  CDIO_MMC_SET_COMMAND      (cdb.field, CDIO_MMC_GPCMD_READ_CD);
  CDIO_MMC_SET_READ_LBA     (cdb.field, lsn);
  CDIO_MMC_SET_READ_LENGTH24(cdb.field, 1);

  cdb.field[9]=0xF8;  /* Raw read, 2352 bytes per sector */
  
  return run_mmc_cmd_win32ioctl(p_env, OP_TIMEOUT_MS,
				mmc_get_cmd_len(cdb.field[0]), 
				&cdb, SCSI_MMC_DATA_READ, 
				CDIO_CD_FRAMESIZE_RAW, p_buf);
}
Exemplo n.º 5
0
/*!
   Reads nblocks of mode2 sectors from cd device into data starting
   from lsn.
   Returns 0 if no error. 
 */
int
read_mode2_sectors_freebsd_cam (_img_private_t *p_env, void *p_buf, 
				lsn_t lsn, unsigned int nblocks)
{
  mmc_cdb_t cdb = {{0, }};

  bool b_read_10 = false;

  CDIO_MMC_SET_READ_LBA(cdb.field, lsn);
  
  if (b_read_10) {
    int retval;
    
    CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_READ_10);
    CDIO_MMC_SET_READ_LENGTH16(cdb.field, nblocks);
    if ((retval = mmc_set_blocksize (p_env->gen.cdio, M2RAW_SECTOR_SIZE)))
      return retval;
    
    if ((retval = run_mmc_cmd_freebsd_cam (p_env, 0, 
					   mmc_get_cmd_len(cdb.field[0]),
					   &cdb, 
					   SCSI_MMC_DATA_READ,
					   M2RAW_SECTOR_SIZE * nblocks, 
					   p_buf)))
      {
	mmc_set_blocksize (p_env->gen.cdio, CDIO_CD_FRAMESIZE);
	return retval;
      }
    
    return mmc_set_blocksize (p_env->gen.cdio, CDIO_CD_FRAMESIZE);
  } else {
    CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_READ_CD);
    CDIO_MMC_SET_READ_LENGTH24(cdb.field, nblocks);
    cdb.field[1] = 0; /* sector size mode2 */
    cdb.field[9] = 0x58; /* 2336 mode2 */
    return run_mmc_cmd_freebsd_cam (p_env, 0, 
				    mmc_get_cmd_len(cdb.field[0]), 
				    &cdb, 
				    SCSI_MMC_DATA_READ,
				    M2RAW_SECTOR_SIZE * nblocks, p_buf);
    
  }
}