/* finish initializing the drive! */ int cdio_cddap_open(cdrom_drive_t *d) { int ret; if(d->opened)return(0); #if HAVE_SCSI_HANDLING switch(d->interface){ case GENERIC_SCSI: if((ret=scsi_init_drive(d))) return(ret); break; case COOKED_IOCTL: if((ret=cooked_init_drive(d))) return(ret); break; default: cderror(d, "100: Interface not supported\n"); return(-100); } #else d->cdpinterface = COOKED_IOCTL; if ( (ret=cooked_init_drive(d)) ) return(ret); #endif /* Check TOC, enable for CDDA */ /* Some drives happily return a TOC even if there is no disc... */ { int i; for(i=0; i<d->tracks; i++) if(d->disc_toc[i].dwStartSector<0 || d->disc_toc[i+1].dwStartSector==0){ d->opened=0; cderror(d,"009: CDROM reporting illegal table of contents\n"); return(-9); } } if((ret=d->enable_cdda(d,1))) return(ret); /* d->select_speed(d,d->maxspeed); most drives are full speed by default */ if (d->bigendianp==-1) d->bigendianp=data_bigendianp(d); return(0); }
long cdda_read(cdrom_drive *d, void *buffer, long beginsector, long sectors){ if(d->opened){ if(sectors>0){ sectors=d->read_audio(d,buffer,beginsector,sectors); if(sectors!=-1){ /* byteswap? */ if(d->bigendianp==-1) /* not determined yet */ d->bigendianp=data_bigendianp(d); if(d->bigendianp!=bigendianp()){ int i; u_int16_t *p=(u_int16_t *)buffer; long els=sectors*CD_FRAMESIZE_RAW/2; for(i=0;i<els;i++)p[i]=swap16(p[i]); } } } return(sectors); } cderror(d,"400: Device not open\n"); return(-400); }
/* finish initializing the drive! */ int cdio_cddap_open(cdrom_drive_t *d) { int ret; if(d->opened)return(0); if ( (ret=cddap_init_drive(d)) ) return(ret); /* Check TOC, enable for CDDA */ /* Some drives happily return a TOC even if there is no disc... */ { int i; for(i=0; i<d->tracks; i++) if(d->disc_toc[i].dwStartSector<0 || d->disc_toc[i+1].dwStartSector==0){ d->opened=0; cderror(d,"009: CDROM reporting illegal table of contents\n"); return(-9); } } if((ret=d->enable_cdda(d,1))) return(ret); /* d->select_speed(d,d->maxspeed); most drives are full speed by default */ if ( -1 == d->bigendianp ) { d->bigendianp = data_bigendianp(d); } return(0); }
static long int read_blocks (cdrom_drive_t *d, void *p, lsn_t begin, long i_sectors) { int retry_count = 0; int err; char *buffer=(char *)p; do { err = cdio_read_audio_sectors( d->p_cdio, buffer, begin, i_sectors); if ( 0 != err ) { if (!d->error_retry) return -7; if (i_sectors==1) { /* *Could* be I/O or media error. I think. If we're at 30 retries, we better skip this unhappy little sector. */ if (retry_count>MAX_RETRIES-1) { char b[256]; snprintf(b, sizeof(b), "010: Unable to access sector %ld: skipping...\n", (long int) begin); cderror(d, b); return -10; } break; } if(retry_count>4) if(i_sectors>1) i_sectors=i_sectors*3/4; retry_count++; if (retry_count>MAX_RETRIES) { cderror(d,"007: Unknown, unrecoverable error reading data\n"); return(-7); } } else break; } while (err); return(i_sectors); }
long cdio_cddap_read(cdrom_drive_t *d, void *buffer, lsn_t beginsector, long sectors) { if (d->opened) { if (sectors>0) { sectors=d->read_audio(d, buffer, beginsector, sectors); if (sectors > 0) { /* byteswap? */ if ( d->bigendianp == -1 ) /* not determined yet */ d->bigendianp = data_bigendianp(d); if ( d->b_swap_bytes && d->bigendianp != bigendianp() ) { int i; uint16_t *p=(uint16_t *)buffer; long els=sectors*CDIO_CD_FRAMESIZE_RAW/2; /* Note: Something perhaps in the original cdparanoia code might cause the code to access outside of the allocated range of buffer. This comment is just to serve as a marker for the loop where the data got clobbered. I don't think this code however is wrong. See the comment in i_read_c_block of paranioa.c */ for(i=0;i<els;i++) p[i]=UINT16_SWAP_LE_BE_C(p[i]); } } } return(sectors); } cderror(d,"400: Device not open\n"); return(-400); }
static long int read_blocks (cdrom_drive_t *d, void *p, lsn_t begin, long i_sectors) { int retry_count = 0; int err; int ret = 0; char *buffer=(char *)p; if(p==NULL)buffer = malloc(i_sectors*CD_FRAMESIZE_RAW); do { struct timespec tv1; struct timespec tv2; int ret1,ret2; ret1 = gettime(&tv1); err = cdio_read_audio_sectors( d->p_cdio, buffer, begin, i_sectors); ret2 = gettime(&tv2); if(ret1<0 || ret2<0) { d->last_milliseconds=-1; } else { d->last_milliseconds = (tv2.tv_sec-tv1.tv_sec)*1000. + (tv2.tv_nsec-tv1.tv_nsec)/1000000.; } if ( DRIVER_OP_SUCCESS != err ) { if (!d->error_retry) { ret=-7; goto done; } if (i_sectors==1) { /* *Could* be I/O or media error. I think. If we're at 30 retries, we better skip this unhappy little sector. */ if (retry_count>MAX_RETRIES-1) { char b[256]; snprintf(b, sizeof(b), "010: Unable to access sector %ld: skipping...\n", (long int) begin); cderror(d, b); ret=-10; goto done; } } if(retry_count>4) if(i_sectors>1) i_sectors=i_sectors*3/4; retry_count++; if (retry_count>MAX_RETRIES) { cderror(d,"007: Unknown, unrecoverable error reading data\n"); ret=-7; goto done; } } else break; } while (err); ret=i_sectors; done: if(p==NULL && buffer)free(buffer); return ret; }