The first all libcdio cdda_interface. There are some gaps could be

filled.

cdda_inteface.h renamed to cdda.h

cdio_destroy moved from cdio.h to device.h
This commit is contained in:
rocky
2005-01-05 04:16:11 +00:00
parent 2c20dfb2ef
commit 7a2a44a814
17 changed files with 254 additions and 722 deletions

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.18 2005/01/04 10:58:03 rocky Exp $ # $Id: Makefile.am,v 1.19 2005/01/05 04:16:11 rocky Exp $
# #
# Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> # Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
# #
@@ -26,7 +26,7 @@ libcdioinclude_HEADERS = \
bytesex.h \ bytesex.h \
bytesex_asm.h \ bytesex_asm.h \
paranoia.h \ paranoia.h \
cdda_interface.h \ cdda.h \
cdio.h \ cdio.h \
cdtext.h \ cdtext.h \
cdtext.h \ cdtext.h \

View File

@@ -1,7 +1,7 @@
/* /*
$Id: cdda_interface.h,v 1.3 2004/12/30 11:13:49 rocky Exp $ $Id: cdda.h,v 1.1 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2001 Xiph.org Copyright (C) 2001 Xiph.org
and Heiko Eissfeldt heiko@escape.colossus.de and Heiko Eissfeldt heiko@escape.colossus.de
@@ -27,8 +27,8 @@
#ifndef _CDDA_INTERFACE_H_ #ifndef _CDDA_INTERFACE_H_
#define _CDDA_INTERFACE_H_ #define _CDDA_INTERFACE_H_
#include <cdio/cdio.h>
#include <cdio/paranoia.h> #include <cdio/paranoia.h>
#include <cdio/types.h>
#define CD_FRAMESAMPLES (CDIO_CD_FRAMESIZE_RAW / 4) #define CD_FRAMESAMPLES (CDIO_CD_FRAMESIZE_RAW / 4)
@@ -41,7 +41,6 @@
#define MAXTRK (CDIO_CD_MAX_TRACKS+1) #define MAXTRK (CDIO_CD_MAX_TRACKS+1)
typedef struct TOC { /* structure of table of contents */ typedef struct TOC { /* structure of table of contents */
unsigned char bFlags;
unsigned char bTrack; unsigned char bTrack;
int32_t dwStartSector; int32_t dwStartSector;
} TOC_t; } TOC_t;
@@ -62,25 +61,21 @@ typedef struct TOC { /* structure of table of contents */
struct cdrom_drive_s { struct cdrom_drive_s {
CdIo_t *p_cdio;
int opened; /* This struct may just represent a candidate for opening */ int opened; /* This struct may just represent a candidate for opening */
char *cdda_device_name; char *cdda_device_name;
char *ioctl_device_name;
int cdda_fd;
int ioctl_fd;
char *drive_model; char *drive_model;
int drive_type;
int interface; int interface;
int bigendianp; int bigendianp;
int nsectors; int nsectors;
int cd_extra; int cd_extra;
int tracks; track_t tracks;
TOC_t disc_toc[MAXTRK]; TOC_t disc_toc[MAXTRK];
long audio_first_sector; lsn_t audio_first_sector;
long audio_last_sector; lsn_t audio_last_sector;
int errordest; int errordest;
int messagedest; int messagedest;
@@ -91,7 +86,7 @@ struct cdrom_drive_s {
int (*enable_cdda) (cdrom_drive_t *d, int onoff); int (*enable_cdda) (cdrom_drive_t *d, int onoff);
int (*read_toc) (cdrom_drive_t *d); int (*read_toc) (cdrom_drive_t *d);
long (*read_audio) (cdrom_drive_t *d, void *p, long begin, long (*read_audio) (cdrom_drive_t *d, void *p, lsn_t begin,
long sectors); long sectors);
int (*set_speed) (cdrom_drive_t *d, int speed); int (*set_speed) (cdrom_drive_t *d, int speed);
int error_retry; int error_retry;
@@ -138,26 +133,45 @@ extern cdrom_drive_t *cdda_identify_test(const char *filename,
/** oriented functions */ /** oriented functions */
extern int cdda_speed_set(cdrom_drive_t *d, int speed); extern int cdda_speed_set(cdrom_drive_t *d, int speed);
extern void cdda_verbose_set(cdrom_drive_t *d,int err_action, int mes_action); extern void cdda_verbose_set(cdrom_drive_t *d, int err_action,
extern char *cdda_messages(cdrom_drive_t *d); int mes_action);
extern char *cdda_errors(cdrom_drive_t *d); extern char *cdda_messages(cdrom_drive_t *d);
extern char *cdda_errors(cdrom_drive_t *d);
extern int cdda_close(cdrom_drive_t *d); extern int cdda_close(cdrom_drive_t *d);
extern int cdda_open(cdrom_drive_t *d); extern int cdda_open(cdrom_drive_t *d);
extern long cdda_read(cdrom_drive_t *d, void *buffer, extern long cdda_read(cdrom_drive_t *d, void *p_buffer,
long int beginsector, long int sectors); lsn_t beginsector, long sectors);
extern long cdda_track_firstsector(cdrom_drive_t *d,int track); /*! Return the lsn for the start of track i_track */
extern long cdda_track_lastsector(cdrom_drive_t *d,int track); extern lsn_t cdda_track_firstsector(cdrom_drive_t *d, track_t i_track);
extern long cdda_tracks(cdrom_drive_t *d);
extern int cdda_sector_gettrack(cdrom_drive_t *d,long sector); /*! Get last lsn of the track. This generally one less than the start
extern int cdda_track_channels(cdrom_drive_t *d,int track); of the next track. -1 is returned on error. */
extern int cdda_track_audiop(cdrom_drive_t *d,int track); extern lsn_t cdda_track_lastsector(cdrom_drive_t *d, track_t i_track);
extern int cdda_track_copyp(cdrom_drive_t *d,int track); extern track_t cdda_tracks(cdrom_drive_t *d);
extern int cdda_track_preemp(cdrom_drive_t *d,int track); extern int cdda_sector_gettrack(cdrom_drive_t *d, lsn_t lsn);
extern long cdda_disc_firstsector(cdrom_drive_t *d); extern int cdda_track_channels(cdrom_drive_t *d, track_t i_track);
extern long cdda_disc_lastsector(cdrom_drive_t *d);
/*! Return 1 is track is an audio track, 0 otherwise. */
extern int cdda_track_audiop(cdrom_drive_t *d, track_t i_track);
/*! Return 1 is track has copy permit set, 0 otherwise. */
extern int cdda_track_copyp(cdrom_drive_t *d, track_t i_track);
/*! Return 1 is audio track has linear preemphasis set, 0 otherwise.
Only makes sense for audio tracks.
*/
extern int cdda_track_preemp(cdrom_drive_t *d, track_t i_track);
/*! Get first lsn of the first audio track. -1 is returned on error. */
extern lsn_t cdda_disc_firstsector(cdrom_drive_t *d);
/*! Get last lsn of the last audio track. The last lssn generally one
less than the start of the next track after the audio track. -1 is
returned on error. */
extern lsn_t cdda_disc_lastsector(cdrom_drive_t *d);
/** transport errors: */ /** transport errors: */

View File

@@ -1,5 +1,5 @@
/* -*- c -*- /* -*- c -*-
$Id: cdio.h,v 1.73 2005/01/04 10:58:03 rocky Exp $ $Id: cdio.h,v 1.74 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -57,14 +57,6 @@ extern "C" {
/** This is an opaque structure for the CD-Text object. */ /** This is an opaque structure for the CD-Text object. */
typedef struct cdtext cdtext_t; typedef struct cdtext cdtext_t;
/*!
Free any resources associated with p_cdio. Call this when done using p_cdio
and using CD reading/control operations.
@param p_cdio the CD object to eliminated.
*/
void cdio_destroy (CdIo_t *p_cdio);
/*! /*!
Get the value associatied with key. Get the value associatied with key.

View File

@@ -1,5 +1,5 @@
/* -*- c -*- /* -*- c -*-
$Id: device.h,v 1.1 2005/01/04 10:58:03 rocky Exp $ $Id: device.h,v 1.2 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -279,6 +279,14 @@ extern "C" {
/*! Like cdio_have_xxx but uses an enumeration instead. */ /*! Like cdio_have_xxx but uses an enumeration instead. */
bool cdio_have_driver (driver_id_t driver_id); bool cdio_have_driver (driver_id_t driver_id);
/*!
Free any resources associated with p_cdio. Call this when done using p_cdio
and using CD reading/control operations.
@param p_cdio the CD object to eliminated.
*/
void cdio_destroy (CdIo_t *p_cdio);
/*! /*!
Get a string decribing driver_id. Get a string decribing driver_id.

View File

@@ -1,7 +1,7 @@
/* /*
$Id: scsi_mmc.h,v 1.36 2004/12/18 17:29:32 rocky Exp $ $Id: scsi_mmc.h,v 1.37 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -395,7 +395,7 @@ discmode_t scsi_mmc_get_dvd_struct_physical ( const CdIo *p_cdio,
Get the CD-ROM hardware info via a SCSI MMC INQUIRY command. Get the CD-ROM hardware info via a SCSI MMC INQUIRY command.
False is returned if we had an error getting the information. False is returned if we had an error getting the information.
*/ */
bool scsi_mmc_get_hwinfo ( const CdIo *p_cdio, bool scsi_mmc_get_hwinfo ( const CdIo_t *p_cdio,
/* out*/ cdio_hwinfo_t *p_hw_info ); /* out*/ cdio_hwinfo_t *p_hw_info );

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.1 2004/12/18 17:29:32 rocky Exp $ # $Id: Makefile.am,v 1.2 2005/01/05 04:16:11 rocky Exp $
# #
# Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> # Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
# #
@@ -51,7 +51,7 @@ noinst_HEADERS = common_interface.h drive_exceptions.h low_interface.h \
smallft.h utils.h smallft.h utils.h
libcdio_cdda_sources = common_interface.c cooked_interface.c interface.c \ libcdio_cdda_sources = common_interface.c cooked_interface.c interface.c \
scan_devices.c scsi_interface.c smallft.c test_interface.c \ scan_devices.c smallft.c test_interface.c \
toc.c utils.c toc.c utils.c
lib_LTLIBRARIES = libcdio_cdda.la lib_LTLIBRARIES = libcdio_cdda.la

View File

@@ -1,5 +1,5 @@
/* /*
$Id: common_interface.c,v 1.2 2004/12/19 01:43:38 rocky Exp $ $Id: common_interface.c,v 1.3 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998, 2002 Monty monty@xiph.org Copyright (C) 1998, 2002 Monty monty@xiph.org
@@ -205,19 +205,18 @@ data_bigendianp(cdrom_drive_t *d)
int int
FixupTOC(cdrom_drive_t *d, track_t i_tracks) FixupTOC(cdrom_drive_t *d, track_t i_tracks)
{ {
struct cdrom_multisession ms_str;
int j; int j;
/* First off, make sure the 'starting sector' is >=0 */ /* First off, make sure the 'starting sector' is >=0 */
for(j=0;j<i_tracks;j++){ for( j=0; j<i_tracks; j++){
if(d->disc_toc[j].dwStartSector<0){ if (d->disc_toc[j].dwStartSector<0 ) {
cdmessage(d,"\n\tTOC entry claims a negative start offset: massaging" cdmessage(d,"\n\tTOC entry claims a negative start offset: massaging"
".\n"); ".\n");
d->disc_toc[j].dwStartSector=0; d->disc_toc[j].dwStartSector=0;
} }
if(j<i_tracks-1 && d->disc_toc[j].dwStartSector> if( j<i_tracks-1 && d->disc_toc[j].dwStartSector>
d->disc_toc[j+1].dwStartSector){ d->disc_toc[j+1].dwStartSector ) {
cdmessage(d,"\n\tTOC entry claims an overly large start offset: massaging" cdmessage(d,"\n\tTOC entry claims an overly large start offset: massaging"
".\n"); ".\n");
d->disc_toc[j].dwStartSector=0; d->disc_toc[j].dwStartSector=0;
@@ -227,9 +226,9 @@ FixupTOC(cdrom_drive_t *d, track_t i_tracks)
/* Make sure the listed 'starting sectors' are actually increasing. /* Make sure the listed 'starting sectors' are actually increasing.
Flag things that are blatant/stupid/wrong */ Flag things that are blatant/stupid/wrong */
{ {
long last=d->disc_toc[0].dwStartSector; lsn_t last=d->disc_toc[0].dwStartSector;
for(j=1;j<i_tracks;j++){ for ( j=1; j<i_tracks; j++){
if(d->disc_toc[j].dwStartSector<last){ if ( d->disc_toc[j].dwStartSector<last ) {
cdmessage(d,"\n\tTOC entries claim non-increasing offsets: massaging" cdmessage(d,"\n\tTOC entries claim non-increasing offsets: massaging"
".\n"); ".\n");
d->disc_toc[j].dwStartSector=last; d->disc_toc[j].dwStartSector=last;
@@ -239,10 +238,12 @@ FixupTOC(cdrom_drive_t *d, track_t i_tracks)
} }
} }
#if LOOKED_OVER
/* For a scsi device, the ioctl must go to the specialized SCSI /* For a scsi device, the ioctl must go to the specialized SCSI
CDROM device, not the generic device. */ CDROM device, not the generic device. */
if (d->ioctl_fd != -1) { if (d->ioctl_fd != -1) {
struct cdrom_multisession ms_str;
int result; int result;
ms_str.addr_format = CDROM_LBA; ms_str.addr_format = CDROM_LBA;
@@ -266,6 +267,8 @@ FixupTOC(cdrom_drive_t *d, track_t i_tracks)
return 1; return 1;
} }
} }
#endif
return 0; return 0;
} }

View File

@@ -1,7 +1,7 @@
/* /*
$Id: cooked_interface.c,v 1.2 2004/12/19 01:43:38 rocky Exp $ $Id: cooked_interface.c,v 1.3 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Original interface.c Copyright (C) 1994-1997 Original interface.c Copyright (C) 1994-1997
Eissfeldt heiko@colossus.escape.de Eissfeldt heiko@colossus.escape.de
Current blenderization Copyright (C) 1998-1999 Monty xiphmont@mit.edu Current blenderization Copyright (C) 1998-1999 Monty xiphmont@mit.edu
@@ -35,48 +35,24 @@ static int
cooked_readtoc (cdrom_drive_t *d) cooked_readtoc (cdrom_drive_t *d)
{ {
int i; int i;
track_t i_tracks; track_t i_track;
struct cdrom_tochdr hdr;
struct cdrom_tocentry entry;
/* get TocHeader to find out how many entries there are */ /* Save TOC Entries */
if(ioctl(d->ioctl_fd, CDROMREADTOCHDR, &hdr )) d->tracks = cdio_get_num_tracks(d->p_cdio) ;
switch(errno){ i_track = cdio_get_first_track_num(d->p_cdio);
case EPERM:
cderror(d,"102: Permision denied on cdrom (ioctl) device\n");
return(-102);
default:
cderror(d,"004: Unable to read table of contents header\n");
return(-4);
}
/* get all TocEntries */ for ( i=0; i < d->tracks; i++) {
for(i=0;i<hdr.cdth_trk1;i++){ d->disc_toc[i].bTrack = i_track;
entry.cdte_track= i+1; d->disc_toc[i].dwStartSector = cdio_get_track_lsn(d->p_cdio, i_track);
entry.cdte_format = CDROM_LBA; i_track++;
if(ioctl(d->ioctl_fd,CDROMREADTOCENTRY,&entry)){
cderror(d,"005: Unable to read table of contents entry\n");
return(-5);
}
d->disc_toc[i].bFlags = (entry.cdte_adr << 4) | (entry.cdte_ctrl & 0x0f);
d->disc_toc[i].bTrack = i+1;
d->disc_toc[i].dwStartSector = entry.cdte_addr.lba;
} }
entry.cdte_track = CDIO_CDROM_LEADOUT_TRACK; d->disc_toc[i].bTrack = i_track;
entry.cdte_format = CDROM_LBA; d->disc_toc[i].dwStartSector = cdio_get_track_lsn(d->p_cdio,
if(ioctl(d->ioctl_fd, CDROMREADTOCENTRY, &entry)){ CDIO_CDROM_LEADOUT_TRACK);
cderror(d,"005: Unable to read table of contents entry\n");
return(-5);
}
d->disc_toc[i].bFlags = (entry.cdte_adr << 4) | (entry.cdte_ctrl & 0x0f);
d->disc_toc[i].bTrack = entry.cdte_track;
d->disc_toc[i].dwStartSector = entry.cdte_addr.lba;
i_tracks=hdr.cdth_trk1+1; d->cd_extra=FixupTOC(d, i_track);
d->cd_extra=FixupTOC(d,i_tracks); return --i_track; /* without lead-out */
return(--i_tracks); /* without lead-out */
} }
@@ -84,9 +60,11 @@ cooked_readtoc (cdrom_drive_t *d)
static int static int
cooked_setspeed(cdrom_drive_t *d, int speed) cooked_setspeed(cdrom_drive_t *d, int speed)
{ {
#if SET_SPEED_FIXED
if(d->ioctl_fd!=-1) if(d->ioctl_fd!=-1)
return ioctl(d->ioctl_fd, CDROM_SELECT_SPEED, speed); return ioctl(d->ioctl_fd, CDROM_SELECT_SPEED, speed);
else else
#endif
return 0; return 0;
} }
@@ -96,14 +74,14 @@ cooked_setspeed(cdrom_drive_t *d, int speed)
*/ */
static long int static long int
cooked_read (cdrom_drive_t *d, void *p, long begin, long sectors) cooked_read (cdrom_drive_t *d, void *p, lsn_t begin, long sectors)
{ {
int retry_count,err; int retry_count,err;
struct cdrom_read_audio arg; struct cdrom_read_audio arg;
char *buffer=(char *)p; char *buffer=(char *)p;
/* read d->nsectors at a time, max. */ /* read d->nsectors at a time, max. */
sectors=(sectors>d->nsectors?d->nsectors:sectors); sectors=( sectors > d->nsectors ? d->nsectors : sectors);
arg.addr.lba = begin; arg.addr.lba = begin;
arg.addr_format = CDROM_LBA; arg.addr_format = CDROM_LBA;
@@ -112,43 +90,35 @@ cooked_read (cdrom_drive_t *d, void *p, long begin, long sectors)
retry_count=0; retry_count=0;
do { do {
if((err=ioctl(d->ioctl_fd, CDROMREADAUDIO, &arg))){ err = cdio_read_audio_sectors( d->p_cdio, buffer, begin, sectors);
if(!d->error_retry)return(-7);
switch(errno){ if ( 0 != err ) {
case ENOMEM: if (!d->error_retry) return -7;
/* D'oh. Possible kernel error. Keep limping */
if(sectors==1){ if (sectors==1) {
/* Nope, can't continue */ /* *Could* be I/O or media error. I think. If we're at
cderror(d,"300: Kernel memory error\n"); 30 retries, we better skip this unhappy little
return(-300); sector. */
} if (retry_count>MAX_RETRIES-1) {
default: char b[256];
if(sectors==1){ snprintf(b, sizeof(b),
"010: Unable to access sector %ld: skipping...\n",
(long int) begin);
/* *Could* be I/O or media error. I think. If we're at cderror(d, b);
30 retries, we better skip this unhappy little return -10;
sector. */
if(retry_count>MAX_RETRIES-1){
char b[256];
sprintf(b,"010: Unable to access sector %ld: skipping...\n",
begin);
cderror(d,b);
return(-10);
}
break;
} }
break;
} }
if(retry_count>4) if(retry_count>4)
if(sectors>1) if(sectors>1)
sectors=sectors*3/4; sectors=sectors*3/4;
retry_count++; retry_count++;
if(retry_count>MAX_RETRIES){ if (retry_count>MAX_RETRIES) {
cderror(d,"007: Unknown, unrecoverable error reading data\n"); cderror(d,"007: Unknown, unrecoverable error reading data\n");
return(-7); return(-7);
} }
}else } else
break; break;
} while (err); } while (err);
@@ -206,6 +176,7 @@ verify_read_command(cdrom_drive_t *d)
#include "drive_exceptions.h" #include "drive_exceptions.h"
#if CHECK_EXCEPTIONS_FIXED
static void static void
check_exceptions(cdrom_drive_t *d, const exception_t *list) check_exceptions(cdrom_drive_t *d, const exception_t *list)
{ {
@@ -219,12 +190,14 @@ check_exceptions(cdrom_drive_t *d, const exception_t *list)
i++; i++;
} }
} }
#endif
/* set function pointers to use the ioctl routines */ /* set function pointers to use the ioctl routines */
int int
cooked_init_drive (cdrom_drive_t *d){ cooked_init_drive (cdrom_drive_t *d){
int ret; int ret;
#if BUFSIZE_DETERMINATION_FIXED
switch(d->drive_type){ switch(d->drive_type){
case MATSUSHITA_CDROM_MAJOR: /* sbpcd 1 */ case MATSUSHITA_CDROM_MAJOR: /* sbpcd 1 */
case MATSUSHITA_CDROM2_MAJOR: /* sbpcd 2 */ case MATSUSHITA_CDROM2_MAJOR: /* sbpcd 2 */
@@ -240,7 +213,7 @@ cooked_init_drive (cdrom_drive_t *d){
/* this ioctl returns zero on error; exactly wrong, but that's /* this ioctl returns zero on error; exactly wrong, but that's
what it does. */ what it does. */
if(ioctl(d->ioctl_fd, CDROMAUDIOBUFSIZ, d->nsectors)==0){ if (ioctl(d->ioctl_fd, CDROMAUDIOBUFSIZ, d->nsectors)==0) {
d->nsectors>>=1; d->nsectors>>=1;
if(d->nsectors==0){ if(d->nsectors==0){
char buffer[256]; char buffer[256];
@@ -250,7 +223,7 @@ cooked_init_drive (cdrom_drive_t *d){
cdmessage(d,buffer); cdmessage(d,buffer);
break; /* Oh, well. Try to read anyway.*/ break; /* Oh, well. Try to read anyway.*/
} }
}else{ } else {
char buffer[256]; char buffer[256];
sprintf(buffer,"\tSetting read block size at %d sectors (%ld bytes).\n", sprintf(buffer,"\tSetting read block size at %d sectors (%ld bytes).\n",
d->nsectors,(long)d->nsectors*CD_FRAMESIZE_RAW); d->nsectors,(long)d->nsectors*CD_FRAMESIZE_RAW);
@@ -275,6 +248,17 @@ cooked_init_drive (cdrom_drive_t *d){
default: default:
d->nsectors=40; d->nsectors=40;
} }
#else
{
char buffer[256];
d->nsectors=8;
sprintf(buffer,"\tSetting read block size at %d sectors (%ld bytes).\n",
d->nsectors,(long)d->nsectors*CD_FRAMESIZE_RAW);
cdmessage(d,buffer);
}
#endif
d->enable_cdda = Dummy; d->enable_cdda = Dummy;
d->read_audio = cooked_read; d->read_audio = cooked_read;
d->set_speed = cooked_setspeed; d->set_speed = cooked_setspeed;

View File

@@ -1,5 +1,5 @@
/* /*
$Id: drive_exceptions.h,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: drive_exceptions.h,v 1.2 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -39,6 +39,7 @@ typedef struct exception {
/* specific to general */ /* specific to general */
#ifdef FINISHED_DRIVE_EXCEPTIONS
/* list of drives that affect autosensing in ATAPI specific portions of code /* list of drives that affect autosensing in ATAPI specific portions of code
(force drives to detect as ATAPI or SCSI, force ATAPI read command */ (force drives to detect as ATAPI or SCSI, force ATAPI read command */
@@ -48,6 +49,7 @@ static exception_t atapi_list[]={
{"SONY CD-ROM CDU-561", 0, 0, Dummy, NULL,0}, {"SONY CD-ROM CDU-561", 0, 0, Dummy, NULL,0},
{"Chinon CD-ROM CDS-525", 0, 0, Dummy, NULL,0}, {"Chinon CD-ROM CDS-525", 0, 0, Dummy, NULL,0},
{NULL,0,0,NULL,NULL,0}}; {NULL,0,0,NULL,NULL,0}};
#endif /*FINISHED_DRIVE_EXCEPTIONS*/
/* list of drives that affect MMC default settings */ /* list of drives that affect MMC default settings */

View File

@@ -32,13 +32,11 @@ cdda_close(cdrom_drive_t *d)
if(d->opened) if(d->opened)
d->enable_cdda(d,0); d->enable_cdda(d,0);
cdio_destroy (d->p_cdio);
_clean_messages(d); _clean_messages(d);
if(d->cdda_device_name)free(d->cdda_device_name); if (d->cdda_device_name) free(d->cdda_device_name);
if(d->ioctl_device_name)free(d->ioctl_device_name); if (d->drive_model) free(d->drive_model);
if(d->drive_model)free(d->drive_model); if (d->sg) free(d->sg);
if(d->cdda_fd!=-1)close(d->cdda_fd);
if(d->ioctl_fd!=-1 && d->ioctl_fd!=d->cdda_fd)close(d->ioctl_fd);
if(d->sg)free(d->sg);
free(d); free(d);
} }
@@ -52,6 +50,7 @@ cdda_open(cdrom_drive_t *d)
int ret; int ret;
if(d->opened)return(0); if(d->opened)return(0);
#if HAVE_SCSI_HANDLING
switch(d->interface){ switch(d->interface){
case GENERIC_SCSI: case GENERIC_SCSI:
if((ret=scsi_init_drive(d))) if((ret=scsi_init_drive(d)))
@@ -71,6 +70,11 @@ cdda_open(cdrom_drive_t *d)
cderror(d,"100: Interface not supported\n"); cderror(d,"100: Interface not supported\n");
return(-100); return(-100);
} }
#else
d->interface = COOKED_IOCTL;
if ( (ret=cooked_init_drive(d)) )
return(ret);
#endif
/* Check TOC, enable for CDDA */ /* Check TOC, enable for CDDA */
@@ -100,7 +104,7 @@ cdda_speed_set(cdrom_drive_t *d, int speed)
return d->set_speed ? d->set_speed(d, speed) : 0; return d->set_speed ? d->set_speed(d, speed) : 0;
} }
long cdda_read(cdrom_drive_t *d, void *buffer, long beginsector, long sectors) long cdda_read(cdrom_drive_t *d, void *buffer, lsn_t beginsector, long sectors)
{ {
if(d->opened){ if(d->opened){
if(sectors>0){ if(sectors>0){

View File

@@ -1,7 +1,7 @@
/* /*
$Id: low_interface.h,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: low_interface.h,v 1.2 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@@ -41,7 +41,7 @@
#include <linux/major.h> #include <linux/major.h>
#include <linux/version.h> #include <linux/version.h>
#include <cdio/paranoia.h> #include <cdio/paranoia.h>
#include <cdio/cdda_interface.h> #include <cdio/cdda.h>
/* some include file locations have changed with newer kernels */ /* some include file locations have changed with newer kernels */

View File

@@ -1,5 +1,5 @@
/* /*
$Id: scan_devices.c,v 1.2 2004/12/19 01:43:38 rocky Exp $ $Id: scan_devices.c,v 1.3 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
@@ -36,6 +36,7 @@
#include "low_interface.h" #include "low_interface.h"
#include "common_interface.h" #include "common_interface.h"
#include "utils.h" #include "utils.h"
#include "cdio/scsi_mmc.h"
#define MAX_DEV_LEN 20 /* Safe because strings only come from below */ #define MAX_DEV_LEN 20 /* Safe because strings only come from below */
/* must be absolute paths! */ /* must be absolute paths! */
@@ -139,7 +140,6 @@ cdda_identify(const char *device, int messagedest,char **messages)
#endif #endif
d=cdda_identify_cooked(device,messagedest,messages); d=cdda_identify_cooked(device,messagedest,messages);
if(!d)d=cdda_identify_scsi(device,NULL,messagedest,messages);
#ifdef CDDA_TEST #ifdef CDDA_TEST
if(!d)d=cdda_identify_test(device,messagedest,messages); if(!d)d=cdda_identify_test(device,messagedest,messages);
@@ -166,135 +166,44 @@ test_resolve_symlink(const char *file,int messagedest,char **messages)
} }
cdrom_drive_t * cdrom_drive_t *
cdda_identify_cooked(const char *dev, int messagedest, cdda_identify_cooked(const char *dev, int messagedest, char **messages)
char **messages)
{ {
cdrom_drive_t *d=NULL; cdrom_drive_t *d=NULL;
struct stat st;
int fd=-1;
int type;
char *description=NULL;
char *device; char *device;
CdIo_t *p_cdio = NULL;
idmessage(messagedest,messages,"\tTesting %s for cooked ioctl() interface",dev); device = test_resolve_symlink(dev,messagedest,messages);
if ( !device ) return NULL;
device=test_resolve_symlink(dev,messagedest,messages); p_cdio = cdio_open(device, DRIVER_UNKNOWN);
if(device==NULL)return(NULL);
if(stat(device,&st)){ if (!p_cdio) {
idperror(messagedest,messages,"\t\tCould not stat %s",device); idperror(messagedest,messages,"\t\tUnable to open %s", dev);
free(device); free(device);
return(NULL); return NULL;
}
if (!S_ISCHR(st.st_mode) &&
!S_ISBLK(st.st_mode)){
idmessage(messagedest,messages,"\t\t%s is not a block or character device",device);
free(device);
return(NULL);
}
type=(int)(st.st_rdev>>8);
switch (type) {
case IDE0_MAJOR:
case IDE1_MAJOR:
case IDE2_MAJOR:
case IDE3_MAJOR:
/* Yay, ATAPI... */
/* Ping for CDROM-ness */
fd=open(device,O_RDONLY|O_NONBLOCK);
if(fd==-1){
idperror(messagedest,messages,"\t\tUnable to open %s",device);
free(device);
return(NULL);
}
if(ioctl_ping_cdrom(fd)){
idmessage(messagedest,messages,"\t\tDevice %s is not a CDROM",device);
close(fd);
free(device);
return(NULL);
}
{
char *temp=atapi_drive_info(fd);
description=catstring(NULL,"ATAPI compatible ");
description=catstring(description,temp);
free(temp);
}
break;
case CDU31A_CDROM_MAJOR:
/* major indicates this is a cdrom; no ping necessary. */
description=strdup("Sony CDU31A or compatible");
break;
case CDU535_CDROM_MAJOR:
/* major indicates this is a cdrom; no ping necessary. */
description=strdup("Sony CDU535 or compatible");
break;
case MATSUSHITA_CDROM_MAJOR:
case MATSUSHITA_CDROM2_MAJOR:
case MATSUSHITA_CDROM3_MAJOR:
case MATSUSHITA_CDROM4_MAJOR:
/* major indicates this is a cdrom; no ping necessary. */
description=strdup("non-ATAPI IDE-style Matsushita/Panasonic CR-5xx or compatible");
break;
case SANYO_CDROM_MAJOR:
description=strdup("Sanyo proprietary or compatible: NOT CDDA CAPABLE");
break;
case MITSUMI_CDROM_MAJOR:
case MITSUMI_X_CDROM_MAJOR:
description=strdup("Mitsumi proprietary or compatible: NOT CDDA CAPABLE");
break;
case OPTICS_CDROM_MAJOR:
description=strdup("Optics Dolphin or compatible: NOT CDDA CAPABLE");
break;
case AZTECH_CDROM_MAJOR:
description=strdup("Aztech proprietary or compatible: NOT CDDA CAPABLE");
break;
case GOLDSTAR_CDROM_MAJOR:
description=strdup("Goldstar proprietary: NOT CDDA CAPABLE");
break;
case CM206_CDROM_MAJOR:
description=strdup("Philips/LMS CM206 proprietary: NOT CDDA CAPABLE");
break;
case SCSI_CDROM_MAJOR:
case SCSI_GENERIC_MAJOR:
/* Nope nope nope */
idmessage(messagedest,messages,"\t\t%s is not a cooked ioctl CDROM.",device);
free(device);
return(NULL);
default:
/* What the hell is this? */
idmessage(messagedest,messages,"\t\t%s is not a cooked ioctl CDROM.",device);
free(device);
return(NULL);
}
if(fd==-1)fd=open(device,O_RDONLY|O_NONBLOCK);
if(fd==-1){
idperror(messagedest,messages,"\t\tUnable to open %s",device);
free(device);
if(description)free(description);
return(NULL);
} }
/* Minimum init */ /* Minimum init */
d=calloc(1,sizeof(cdrom_drive_t)); d=calloc(1,sizeof(cdrom_drive_t));
d->cdda_device_name=device; d->p_cdio = p_cdio;
d->ioctl_device_name=strdup(device); d->cdda_device_name = device;
d->drive_model=description; d->interface = COOKED_IOCTL;
d->drive_type=type; d->bigendianp = -1; /* We don't know yet... */
d->cdda_fd=fd; d->nsectors = -1;
d->ioctl_fd=fd;
d->interface=COOKED_IOCTL; {
d->bigendianp=-1; /* We don't know yet... */ cdio_hwinfo_t hw_info;
d->nsectors=-1;
idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description); if ( scsi_mmc_get_hwinfo( p_cdio, &hw_info ) ) {
d->drive_model=calloc(38,1);
snprintf(d->drive_model, 38, "%s %s %s",
hw_info.psz_vendor, hw_info.psz_model, hw_info.psz_revision );
idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",
d->drive_model);
}
}
return(d); return(d);
} }
@@ -310,379 +219,6 @@ typedef struct scsiid{
int lun; int lun;
} scsiid; } scsiid;
/* Even *this* isn't as simple as it bloody well should be :-P */
/* SG has an easy interface, but SCSI overall does not */
static int get_scsi_id(int fd, scsiid *id){
struct sg_id argid;
int busarg;
/* get the host/id/lun */
if(fd==-1)return(-1);
if(ioctl(fd,SCSI_IOCTL_GET_IDLUN,&argid))return(-1);
id->bus=argid.l2; /* for now */
id->id=argid.l1&0xff;
id->lun=(argid.l1>>8)&0xff;
if(ioctl(fd,SCSI_IOCTL_GET_BUS_NUMBER,&busarg)==0)
id->bus=busarg;
return(0);
}
/* slightly wasteful, but a clean abstraction */
static char *scsi_match(const char *device, const char **prefixes,
const char *devfs_test,
const char *devfs_other,
const char *prompt,
int messagedest,char **messages)
{
int dev=open(device,O_RDONLY|O_NONBLOCK);
scsiid a,b;
int i,j;
char buffer[200];
/* if we're running under /devfs, build the device name from the
device we already have */
if(!strncmp(device,devfs_test,strlen(devfs_test))){
char *pos;
strcpy(buffer,device);
pos=strrchr(buffer,'/');
if(pos){
int matchf;
sprintf(pos,"/%s",devfs_other);
matchf=open(buffer,O_RDONLY|O_NONBLOCK);
if(matchf!=-1){
close(matchf);
close(dev);
return(strdup(buffer));
}
}
}
/* get the host/id/lun */
if(dev==-1){
idperror(messagedest,messages,"\t\tCould not access device %s",
device);
goto matchfail;
}
if(get_scsi_id(dev,&a)){
idperror(messagedest,messages,"\t\tDevice %s could not perform ioctl()",
device);
goto matchfail;
}
/* go through most likely /dev nodes for a match */
for(i=0;i<25;i++){
for(j=0;j<2;j++){
int pattern=0;
int matchf;
while(prefixes[pattern]!=NULL){
switch(j){
case 0:
/* number */
sprintf(buffer,"%s%d",prefixes[pattern],i);
break;
case 1:
/* number */
sprintf(buffer,"%s%c",prefixes[pattern],i+'a');
break;
}
matchf=open(buffer,O_RDONLY|O_NONBLOCK);
if(matchf!=-1){
if(get_scsi_id(matchf,&b)==0){
if(a.bus==b.bus && a.id==b.id && a.lun==b.lun){
close(matchf);
close(dev);
return(strdup(buffer));
}
}
close(matchf);
}
pattern++;
}
}
}
idmessage(messagedest,messages,prompt,device);
matchfail:
if(dev!=-1)close(dev);
return(NULL);
}
static void
strscat(char *a,char *b,int n)
{
int i;
for(i=n;i>0;i--)
if(b[i-1]>' ')break;
strncat(a,b,i);
strcat(a," ");
}
/* At this point, we're going to punt compatability before SG2, and
allow only SG2 and SG3 */
static int verify_SG_version(cdrom_drive_t *d,int messagedest,
char **messages){
/* are we using the new SG driver by Doug Gilbert? If not, punt */
int version,major,minor;
char buffer[256];
idmessage(messagedest,messages,
"\nFound an accessible SCSI CDROM drive."
"\nLooking at revision of the SG interface in use...","");
if(ioctl(d->cdda_fd,SG_GET_VERSION_NUM,&version)){
/* Up, guess not. */
idmessage(messagedest,messages,
"\tOOPS! Old 2.0/early 2.1/early 2.2.x (non-ac patch) style "
"SG.\n\tCdparanoia no longer supports the old interface.\n","");
return(0);
}
major=version/10000;
version-=major*10000;
minor=version/100;
version-=minor*100;
sprintf(buffer,"\tSG interface version %d.%d.%d; OK.",
major,minor,version);
idmessage(messagedest,messages,buffer,"");
return(major);
}
cdrom_drive_t *
cdda_identify_scsi(const char *generic_device,
const char *ioctl_device, int messagedest,
char **messages)
{
cdrom_drive_t *d=NULL;
struct stat i_st;
struct stat g_st;
int i_fd=-1;
int g_fd=-1;
int version;
int type=-1;
char *p;
if(generic_device)
idmessage(messagedest,messages,"\tTesting %s for SCSI interface",
generic_device);
else
if(ioctl_device)
idmessage(messagedest,messages,"\tTesting %s for SCSI interface",
ioctl_device);
/* Do this first; it's wasteful, but the messages make more sense */
if(generic_device){
if(stat(generic_device,&g_st)){
idperror(messagedest,messages,"\t\tCould not access device %s",
generic_device);
return(NULL);
}
if((int)(g_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){
if((int)(g_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){
idmessage(messagedest,messages,"\t\t%s is not a SCSI device",
generic_device);
return(NULL);
}else{
char *temp=(char *)generic_device;
generic_device=ioctl_device;
ioctl_device=temp;
}
}
}
if(ioctl_device){
if(stat(ioctl_device,&i_st)){
idperror(messagedest,messages,"\t\tCould not access device %s",
ioctl_device);
return(NULL);
}
if((int)(i_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){
if((int)(i_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){
idmessage(messagedest,messages,"\t\t%s is not a SCSI device",
ioctl_device);
return(NULL);
}else{
char *temp=(char *)generic_device;
generic_device=ioctl_device;
ioctl_device=temp;
}
}
}
/* we need to resolve any symlinks for the lookup code to work */
if(generic_device){
generic_device=test_resolve_symlink(generic_device,messagedest,messages);
if(generic_device==NULL)goto cdda_identify_scsi_fail;
}
if(ioctl_device){
ioctl_device=test_resolve_symlink(ioctl_device,messagedest,messages);
if(ioctl_device==NULL)goto cdda_identify_scsi_fail;
}
if(!generic_device || !ioctl_device){
if(generic_device){
ioctl_device=
scsi_match(generic_device, scsi_cdrom_prefixes,
devfs_scsi_test, devfs_scsi_cd,
"\t\tNo cdrom device found to match generic device %s",
messagedest, messages);
}else{
generic_device=
scsi_match(ioctl_device,scsi_generic_prefixes,
devfs_scsi_test,devfs_scsi_generic,
"\t\tNo generic SCSI device found to match CDROM device %s",
messagedest,messages);
if(!generic_device)
goto cdda_identify_scsi_fail;
}
}
idmessage(messagedest,messages,"\t\tgeneric device: %s",generic_device);
idmessage(messagedest,messages,"\t\tioctl device: %s",(ioctl_device?
ioctl_device:
"not found"));
if(stat(generic_device,&g_st)){
idperror(messagedest,messages,"\t\tCould not access generic SCSI device "
"%s",generic_device);
goto cdda_identify_scsi_fail;
}
if(ioctl_device)i_fd=open(ioctl_device,O_RDONLY|O_NONBLOCK);
g_fd=open(generic_device,O_RDWR);
if(ioctl_device && i_fd==-1)
idperror(messagedest,messages,"\t\tCould not open SCSI cdrom device "
"%s (continuing)",ioctl_device);
if(g_fd==-1){
idperror(messagedest,messages,"\t\tCould not open generic SCSI device "
"%s",generic_device);
goto cdda_identify_scsi_fail;
}
if(i_fd!=-1){
if(stat(ioctl_device,&i_st)){
idperror(messagedest,messages,"\t\tCould not access SCSI cdrom device "
"%s",ioctl_device);
goto cdda_identify_scsi_fail;
}
type=(int)(i_st.st_rdev>>8);
if(type==SCSI_CDROM_MAJOR){
if (!S_ISBLK(i_st.st_mode)) {
idmessage(messagedest,messages,"\t\tSCSI CDROM device %s not a "
"block device",ioctl_device);
goto cdda_identify_scsi_fail;
}
}else{
idmessage(messagedest,messages,"\t\tSCSI CDROM device %s has wrong "
"major number",ioctl_device);
goto cdda_identify_scsi_fail;
}
}
if((int)(g_st.st_rdev>>8)==SCSI_GENERIC_MAJOR){
if (!S_ISCHR(g_st.st_mode)) {
idmessage(messagedest,messages,"\t\tGeneric SCSI device %s not a "
"char device",generic_device);
goto cdda_identify_scsi_fail;
}
}else{
idmessage(messagedest,messages,"\t\tGeneric SCSI device %s has wrong "
"major number",generic_device);
goto cdda_identify_scsi_fail;
}
d=calloc(1,sizeof(cdrom_drive_t));
d->drive_type=type;
d->cdda_fd=g_fd;
d->ioctl_fd=i_fd;
d->bigendianp=-1; /* We don't know yet... */
d->nsectors=-1;
version=verify_SG_version(d,messagedest,messages);
switch(version){
case -1:case 0:case 1:
d->interface=GENERIC_SCSI;
goto cdda_identify_scsi_fail;
case 2:case 3:
d->interface=GENERIC_SCSI;
break;
}
/* malloc our big buffer for scsi commands */
d->sg=malloc(MAX_BIG_BUFF_SIZE);
d->sg_buffer=d->sg+SG_OFF;
{
/* get the lun */
scsiid lun;
if(get_scsi_id(i_fd,&lun))
d->lun=0; /* a reasonable guess on a failed ioctl */
else
d->lun=lun.lun;
}
p = scsi_inquiry(d);
/* It would seem some TOSHIBA CDROMs gets things wrong */
if (!strncmp (p + 8, "TOSHIBA", 7) &&
!strncmp (p + 16, "CD-ROM", 6) &&
p[0] == TYPE_DISK) {
p[0] = TYPE_ROM;
p[1] |= 0x80; /* removable */
}
if (!p || (*p != TYPE_ROM && *p != TYPE_WORM)) {
idmessage(messagedest,messages,
"\t\tDrive is neither a CDROM nor a WORM device\n",NULL);
free(d->sg);
free(d);
goto cdda_identify_scsi_fail;
}
d->drive_model=calloc(36,1);
memcpy(d->inqbytes,p,4);
d->cdda_device_name=strdup(generic_device);
d->ioctl_device_name=strdup(ioctl_device);
d->drive_model=calloc(36,1);
strscat(d->drive_model,p+8,8);
strscat(d->drive_model,p+16,16);
strscat(d->drive_model,p+32,4);
idmessage(messagedest,messages,"\nCDROM model sensed sensed: %s",d->drive_model);
return(d);
cdda_identify_scsi_fail:
if(generic_device)free((char *)generic_device);
if(ioctl_device)free((char *)ioctl_device);
if(i_fd!=-1)close(i_fd);
if(g_fd!=-1)close(g_fd);
return(NULL);
}
#ifdef CDDA_TEST #ifdef CDDA_TEST
cdrom_drive_t *cdda_identify_test(const char *filename, int messagedest, cdrom_drive_t *cdda_identify_test(const char *filename, int messagedest,

View File

@@ -1,6 +1,7 @@
/* /*
$Id: toc.c,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: toc.c,v 1.2 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
derived from code (C) 1994-1996 Heiko Eissfeldt derived from code (C) 1994-1996 Heiko Eissfeldt
@@ -25,17 +26,18 @@
#include "low_interface.h" #include "low_interface.h"
#include "utils.h" #include "utils.h"
long /*! Return the lsn for the start of track i_track */
cdda_track_firstsector(cdrom_drive_t *d,int track) lsn_t
cdda_track_firstsector(cdrom_drive_t *d, track_t i_track)
{ {
if(!d->opened){ if(!d->opened){
cderror(d,"400: Device not open\n"); cderror(d,"400: Device not open\n");
return(-1); return(-1);
} }
if (track == 0) { if (i_track == 0) {
if (d->disc_toc[0].dwStartSector == 0) { if (d->disc_toc[0].dwStartSector == 0) {
/* first track starts at lba 0 -> no pre-gap */ /* first track starts at lsn 0 -> no pre-gap */
cderror(d,"401: Invalid track number\n"); cderror(d,"401: Invalid track number\n");
return(-1); return(-1);
} }
@@ -44,14 +46,15 @@ cdda_track_firstsector(cdrom_drive_t *d,int track)
} }
} }
if(track<0 || track>d->tracks){ if( i_track>d->tracks) {
cderror(d,"401: Invalid track number\n"); cderror(d,"401: Invalid track number\n");
return(-1); return(-1);
} }
return(d->disc_toc[track-1].dwStartSector); return(d->disc_toc[i_track-1].dwStartSector);
} }
long /*! Get first lsn of the first audio track. -1 is returned on error. */
lsn_t
cdda_disc_firstsector(cdrom_drive_t *d) cdda_disc_firstsector(cdrom_drive_t *d)
{ {
int i; int i;
@@ -61,27 +64,29 @@ cdda_disc_firstsector(cdrom_drive_t *d)
} }
/* look for an audio track */ /* look for an audio track */
for(i=0;i<d->tracks;i++) for ( i=0; i<d->tracks; i++ )
if(cdda_track_audiop(d,i+1)==1) { if( cdda_track_audiop(d, i+1)==1 ) {
if (i == 0) /* disc starts at lba 0 if first track is an audio track */ if (i == 0) /* disc starts at lba 0 if first track is an audio track */
return 0; return 0;
else else
return(cdda_track_firstsector(d,i+1)); return cdda_track_firstsector(d, i+1);
} }
cderror(d,"403: No audio tracks on disc\n"); cderror(d,"403: No audio tracks on disc\n");
return(-1); return(-1);
} }
long /*! Get last lsn of the track. The lsn is generally one less than the
cdda_track_lastsector(cdrom_drive_t *d,int track) start of the next track. -1 is returned on error. */
lsn_t
cdda_track_lastsector(cdrom_drive_t *d, track_t i_track)
{ {
if(!d->opened){ if (!d->opened) {
cderror(d,"400: Device not open\n"); cderror(d,"400: Device not open\n");
return(-1); return -1;
} }
if (track == 0) { if (i_track == 0) {
if (d->disc_toc[0].dwStartSector == 0) { if (d->disc_toc[0].dwStartSector == 0) {
/* first track starts at lba 0 -> no pre-gap */ /* first track starts at lba 0 -> no pre-gap */
cderror(d,"401: Invalid track number\n"); cderror(d,"401: Invalid track number\n");
@@ -92,108 +97,92 @@ cdda_track_lastsector(cdrom_drive_t *d,int track)
} }
} }
if(track<1 || track>d->tracks){ if ( i_track<1 || i_track>d->tracks ) {
cderror(d,"401: Invalid track number\n"); cderror(d,"401: Invalid track number\n");
return(-1); return -1;
} }
/* Safe, we've always the leadout at disc_toc[tracks] */ /* Safe, we've always the leadout at disc_toc[tracks] */
return(d->disc_toc[track].dwStartSector-1); return(d->disc_toc[i_track].dwStartSector-1);
} }
long /*! Get last lsn of the last audio track. The last lssn generally one
less than the start of the next track after the audio track. -1 is
returned on error. */
lsn_t
cdda_disc_lastsector(cdrom_drive_t *d) cdda_disc_lastsector(cdrom_drive_t *d)
{ {
int i; int i;
if(!d->opened){ if (!d->opened) {
cderror(d,"400: Device not open\n"); cderror(d,"400: Device not open\n");
return(-1); return -1;
} }
/* look for an audio track */ /* look for an audio track */
for(i=d->tracks-1;i>=0;i--) for ( i=d->tracks-1; i>=0; i-- )
if(cdda_track_audiop(d,i+1)==1) if ( cdda_track_audiop(d,i+1) == 1 )
return(cdda_track_lastsector(d,i+1)); return (cdda_track_lastsector(d,i+1));
cderror(d,"403: No audio tracks on disc\n"); cderror(d,"403: No audio tracks on disc\n");
return(-1); return -1;
} }
long track_t
cdda_tracks(cdrom_drive_t *d) cdda_tracks(cdrom_drive_t *d)
{ {
if(!d->opened){ if (!d->opened){
cderror(d,"400: Device not open\n"); cderror(d,"400: Device not open\n");
return(-1); return -1;
} }
return(d->tracks); return(d->tracks);
} }
int int
cdda_sector_gettrack(cdrom_drive_t *d,long sector) cdda_sector_gettrack(cdrom_drive_t *d, lsn_t lsn)
{ {
if(!d->opened){ if (!d->opened) {
cderror(d,"400: Device not open\n"); cderror(d,"400: Device not open\n");
return(-1); return -1;
}else{ } else {
int i; if (lsn < d->disc_toc[0].dwStartSector)
if (sector < d->disc_toc[0].dwStartSector)
return 0; /* We're in the pre-gap of first track */ return 0; /* We're in the pre-gap of first track */
for(i=0;i<d->tracks;i++){ return cdio_get_track(d->p_cdio, lsn);
if(d->disc_toc[i].dwStartSector<=sector &&
d->disc_toc[i+1].dwStartSector>sector)
return (i+1);
}
cderror(d,"401: Invalid track number\n");
return -1;
} }
} }
static int /*! Return number of channels in track: 2 or 4; -2 if not
cdda_track_bitmap(cdrom_drive_t *d,int track,int bit,int set,int clear) implemented or -1 for error.
{ Not meaningful if track is not an audio track.
if(!d->opened){ */
cderror(d,"400: Device not open\n");
return(-1);
}
if (track == 0)
track = 1; /* map to first track number */
if(track<1 || track>d->tracks){
cderror(d,"401: Invalid track number\n");
return(-1);
}
if ((d->disc_toc[track-1].bFlags & bit))
return(set);
else
return(clear);
}
int int
cdda_track_channels(cdrom_drive_t *d,int track) cdda_track_channels(cdrom_drive_t *d, track_t i_track)
{ {
return(cdda_track_bitmap(d,track,8,4,2)); return(cdio_get_track_channels(d->p_cdio, i_track));
} }
/*! Return 1 is track is an audio track, 0 otherwise. */
int int
cdda_track_audiop(cdrom_drive_t *d,int track) cdda_track_audiop(cdrom_drive_t *d, track_t i_track)
{ {
return(cdda_track_bitmap(d,track,4,0,1)); track_format_t track_format = cdio_get_track_format(d->p_cdio, i_track);
return TRACK_FORMAT_AUDIO == track_format ? 1 : 0;
} }
/*! Return 1 is track is an audio track, 0 otherwise. */
int int
cdda_track_copyp(cdrom_drive_t *d,int track) cdda_track_copyp(cdrom_drive_t *d, track_t i_track)
{ {
return(cdda_track_bitmap(d,track,2,1,0)); track_flag_t track_flag = cdio_get_track_copy_permit(d->p_cdio, i_track);
return CDIO_TRACK_FLAG_TRUE == track_flag ? 1 : 0;
} }
/*! Return 1 is audio track has linear preemphasis set, 0 otherwise.
Only makes sense for audio tracks.
*/
int int
cdda_track_preemp(cdrom_drive_t *d, int track) cdda_track_preemp(cdrom_drive_t *d, track_t i_track)
{ {
return(cdda_track_bitmap(d,track,1,1,0)); track_flag_t track_flag = cdio_get_track_preemphasis(d->p_cdio, i_track);
return CDIO_TRACK_FLAG_TRUE == track_flag ? 1 : 0;
} }

View File

@@ -1,5 +1,5 @@
/* /*
$Id: track.c,v 1.1 2005/01/04 04:33:36 rocky Exp $ $Id: track.c,v 1.2 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org> Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
@@ -160,13 +160,13 @@ cdio_get_track(const CdIo_t *p_cdio, lsn_t lsn)
do { do {
const track_t i_mid = (i_low_track + i_high_track) / 2; const track_t i_mid = (i_low_track + i_high_track) / 2;
if (lsn <= cdio_get_track_lsn(p_cdio, i_mid)) const lsn_t i_mid_lsn = cdio_get_track_lsn(p_cdio, i_mid);
i_high_track = i_mid; if (lsn <= i_mid_lsn) i_high_track = i_mid - 1;
else if (lsn >= i_mid_lsn) i_low_track = i_mid + 1;
i_low_track = i_mid + 1; } while ( i_low_track <= i_high_track );
} while ( i_low_track < i_high_track );
return i_high_track; return (i_low_track > i_high_track + 1)
? i_high_track + 1 : i_high_track;
} }
} }

View File

@@ -1,7 +1,7 @@
/* /*
$Id: p_block.c,v 1.2 2004/12/22 09:41:58 rocky Exp $ $Id: p_block.c,v 1.3 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@@ -32,7 +32,7 @@
#endif #endif
#include <limits.h> #include <limits.h>
#include "p_block.h" #include "p_block.h"
#include <cdio/cdda_interface.h> #include <cdio/cdda.h>
#include <cdio/paranoia.h> #include <cdio/paranoia.h>
linked_list *new_list(void *(*newp)(void),void (*freep)(void *)) linked_list *new_list(void *(*newp)(void),void (*freep)(void *))

View File

@@ -1,7 +1,7 @@
/* /*
$Id: p_block.h,v 1.1 2004/12/18 17:29:32 rocky Exp $ $Id: p_block.h,v 1.2 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) by Monty (xiphmont@mit.edu) Copyright (C) by Monty (xiphmont@mit.edu)
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@@ -23,7 +23,7 @@
#define _P_BLOCK_H_ #define _P_BLOCK_H_
#include <cdio/paranoia.h> #include <cdio/paranoia.h>
#include <cdio/cdda_interface.h> #include <cdio/cdda.h>
#define MIN_WORDS_OVERLAP 64 /* 16 bit words */ #define MIN_WORDS_OVERLAP 64 /* 16 bit words */
#define MIN_WORDS_SEARCH 64 /* 16 bit words */ #define MIN_WORDS_SEARCH 64 /* 16 bit words */

View File

@@ -1,7 +1,7 @@
/* /*
$Id: paranoia.c,v 1.2 2004/12/22 09:41:58 rocky Exp $ $Id: paranoia.c,v 1.3 2005/01/05 04:16:11 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com> Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998 Monty xiphmont@mit.edu Copyright (C) 1998 Monty xiphmont@mit.edu
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@@ -76,7 +76,7 @@
#include <string.h> #include <string.h>
#endif #endif
#include <math.h> #include <math.h>
#include <cdio/cdda_interface.h> #include <cdio/cdda.h>
#include "../cdda_interface/smallft.h" #include "../cdda_interface/smallft.h"
#include "p_block.h" #include "p_block.h"
#include <cdio/paranoia.h> #include <cdio/paranoia.h>