BIG REORGANIZATION.
Reorganize directory structure for inclusion of cd-paranoia. Works for GNU/Linux. Other OS's may be broken. Regression test output needs to be adjusted too. Move: lib/driver (split off of lib) lib/iso9660 (split off of lib) Add from paranoia: lib/cdda_interface lib/paranoia src/paranoia Also made some small changes to capability indentification to show more reading capabilties and show that. cd-info now shows the total disc size.
This commit is contained in:
8
lib/cdda_interface/.cvsignore
Normal file
8
lib/cdda_interface/.cvsignore
Normal file
@@ -0,0 +1,8 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
*.la.ver
|
||||
76
lib/cdda_interface/Makefile.am
Normal file
76
lib/cdda_interface/Makefile.am
Normal file
@@ -0,0 +1,76 @@
|
||||
# $Id: Makefile.am,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
#
|
||||
# Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
#
|
||||
# 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
########################################################
|
||||
# Things to make the cdda_interface library
|
||||
########################################################
|
||||
|
||||
#
|
||||
# From libtool documentation amended with guidance from N. Boullis:
|
||||
#
|
||||
# 1. Start with version information of `0:0:0' for each libtool library.
|
||||
#
|
||||
# 2. It is probably not a good idea to update the version information
|
||||
# several times between public releases, but rather once per public
|
||||
# release. (This seems to be more an aesthetic consideration than
|
||||
# a hard technical one.)
|
||||
#
|
||||
# 3. If the library source code has changed at all since the last
|
||||
# update, then increment REVISION (`C:R:A' becomes `C:R+1:A').
|
||||
#
|
||||
# 4. If any interfaces have been added, removed, or changed since the
|
||||
# last update, increment CURRENT, and set REVISION to 0.
|
||||
#
|
||||
# 5. If any interfaces have been added since the last public release,
|
||||
# then increment AGE.
|
||||
#
|
||||
# 6. If any interfaces have been removed or changed since the last
|
||||
# public release, then set AGE to 0. A changed interface means an
|
||||
# incompatibility with previous versions.
|
||||
|
||||
libcdio_cdda_la_CURRENT := 0
|
||||
libcdio_cdda_la_REVISION := 0
|
||||
libcdio_cdda_la_AGE := 0
|
||||
|
||||
noinst_HEADERS = common_interface.h drive_exceptions.h low_interface.h \
|
||||
smallft.h utils.h
|
||||
|
||||
libcdio_cdda_sources = common_interface.c cooked_interface.c interface.c \
|
||||
scan_devices.c scsi_interface.c smallft.c test_interface.c \
|
||||
toc.c utils.c
|
||||
|
||||
lib_LTLIBRARIES = libcdio_cdda.la
|
||||
|
||||
libcdio_cdda_la_SOURCES = $(libcdio_cdda_sources)
|
||||
libcdio_cdda_la_ldflags = -version-info $(libcdio_cdda_la_CURRENT):$(libcdio_cdda_la_REVISION):$(libcdio_cdda_la_AGE)
|
||||
|
||||
libcdio_cdda_la_LDFLAGS = $(libcdio_cdda_la_ldflags)
|
||||
|
||||
INCLUDES = $(LIBCDIO_CFLAGS)
|
||||
|
||||
FLAGS=@LIBCDIO_CFLAGS@ @UCDROM_H@ @TYPESIZES@ @CFLAGS@
|
||||
|
||||
OPT=$(FLAGS)
|
||||
DEBUG=$(FLAGS) -DCDDA_TEST
|
||||
|
||||
## test:
|
||||
## $(MAKE) libcdio_cdda.a CFLAGS="$(DEBUG)"
|
||||
## $(CC) $(DEBUG) -c test_interface.c
|
||||
## $(LD) $(DEBUG) test_interface.o $(LDFLAGS) -o cdda_test $(LIBS) libcdio_cdda.a
|
||||
|
||||
LIBS = $(LIBCDIO_LIBS)
|
||||
262
lib/cdda_interface/common_interface.c
Normal file
262
lib/cdda_interface/common_interface.c
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
$Id: common_interface.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998, 2002 Monty monty@xiph.org
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/******************************************************************
|
||||
*
|
||||
* CDROM communication common to all interface methods is done here
|
||||
* (mostly ioctl stuff, but not ioctls specific to the 'cooked'
|
||||
* interface)
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include "common_interface.h"
|
||||
#include "utils.h"
|
||||
#include "smallft.h"
|
||||
|
||||
#include <linux/hdreg.h>
|
||||
|
||||
/* Test for presence of a cdrom by pinging with the 'CDROMVOLREAD' ioctl() */
|
||||
int
|
||||
ioctl_ping_cdrom(int fd)
|
||||
{
|
||||
struct cdrom_volctrl volctl;
|
||||
if (ioctl(fd, CDROMVOLREAD, &volctl))
|
||||
return(1); /* failure */
|
||||
|
||||
return(0);
|
||||
/* success! */
|
||||
}
|
||||
|
||||
|
||||
/* Use the ioctl thingy above ping the cdrom; this will get model info */
|
||||
char *atapi_drive_info(int fd){
|
||||
/* Work around the fact that the struct grew without warning in
|
||||
2.1/2.0.34 */
|
||||
|
||||
struct hd_driveid *id=malloc(512); /* the size in 2.0.34 */
|
||||
char *ret;
|
||||
|
||||
if (!(ioctl(fd, HDIO_GET_IDENTITY, id))) {
|
||||
|
||||
if(id->model==0 || id->model[0]==0)
|
||||
ret=copystring("Generic Unidentifiable ATAPI CDROM");
|
||||
else
|
||||
ret=copystring(id->model);
|
||||
}else
|
||||
ret=copystring("Generic Unidentifiable CDROM");
|
||||
|
||||
free(id);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
int
|
||||
data_bigendianp(cdrom_drive_t *d)
|
||||
{
|
||||
float lsb_votes=0;
|
||||
float msb_votes=0;
|
||||
int i,checked;
|
||||
int endiancache=d->bigendianp;
|
||||
float *a=calloc(1024,sizeof(float));
|
||||
float *b=calloc(1024,sizeof(float));
|
||||
long readsectors=5;
|
||||
int16_t *buff=malloc(readsectors*CDIO_CD_FRAMESIZE_RAW);
|
||||
|
||||
/* look at the starts of the audio tracks */
|
||||
/* if real silence, tool in until some static is found */
|
||||
|
||||
/* Force no swap for now */
|
||||
d->bigendianp=-1;
|
||||
|
||||
cdmessage(d,"\nAttempting to determine drive endianness from data...");
|
||||
d->enable_cdda(d,1);
|
||||
for(i=0,checked=0;i<d->tracks;i++){
|
||||
float lsb_energy=0;
|
||||
float msb_energy=0;
|
||||
if(cdda_track_audiop(d,i+1)==1){
|
||||
long firstsector=cdda_track_firstsector(d,i+1);
|
||||
long lastsector=cdda_track_lastsector(d,i+1);
|
||||
int zeroflag=-1;
|
||||
long beginsec=0;
|
||||
|
||||
/* find a block with nonzero data */
|
||||
|
||||
while(firstsector+readsectors<=lastsector){
|
||||
int j;
|
||||
|
||||
if(d->read_audio(d,buff,firstsector,readsectors)>0){
|
||||
|
||||
/* Avoid scanning through jitter at the edges */
|
||||
for(beginsec=0;beginsec<readsectors;beginsec++){
|
||||
int offset=beginsec*CDIO_CD_FRAMESIZE_RAW/2;
|
||||
/* Search *half* */
|
||||
for(j=460;j<128+460;j++)
|
||||
if(buff[offset+j]!=0){
|
||||
zeroflag=0;
|
||||
break;
|
||||
}
|
||||
if(!zeroflag)break;
|
||||
}
|
||||
if(!zeroflag)break;
|
||||
firstsector+=readsectors;
|
||||
}else{
|
||||
d->enable_cdda(d,0);
|
||||
free(a);
|
||||
free(b);
|
||||
free(buff);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
beginsec*=CDIO_CD_FRAMESIZE_RAW/2;
|
||||
|
||||
/* un-interleave for an fft */
|
||||
if(!zeroflag){
|
||||
int j;
|
||||
|
||||
for(j=0;j<128;j++)a[j]=le16_to_cpu(buff[j*2+beginsec+460]);
|
||||
for(j=0;j<128;j++)b[j]=le16_to_cpu(buff[j*2+beginsec+461]);
|
||||
fft_forward(128,a,NULL,NULL);
|
||||
fft_forward(128,b,NULL,NULL);
|
||||
for(j=0;j<128;j++)lsb_energy+=fabs(a[j])+fabs(b[j]);
|
||||
|
||||
for(j=0;j<128;j++)a[j]=be16_to_cpu(buff[j*2+beginsec+460]);
|
||||
for(j=0;j<128;j++)b[j]=be16_to_cpu(buff[j*2+beginsec+461]);
|
||||
fft_forward(128,a,NULL,NULL);
|
||||
fft_forward(128,b,NULL,NULL);
|
||||
for(j=0;j<128;j++)msb_energy+=fabs(a[j])+fabs(b[j]);
|
||||
}
|
||||
}
|
||||
if(lsb_energy<msb_energy){
|
||||
lsb_votes+=msb_energy/lsb_energy;
|
||||
checked++;
|
||||
}else
|
||||
if(lsb_energy>msb_energy){
|
||||
msb_votes+=lsb_energy/msb_energy;
|
||||
checked++;
|
||||
}
|
||||
|
||||
if(checked==5 && (lsb_votes==0 || msb_votes==0))break;
|
||||
cdmessage(d,".");
|
||||
}
|
||||
|
||||
free(buff);
|
||||
free(a);
|
||||
free(b);
|
||||
d->bigendianp=endiancache;
|
||||
d->enable_cdda(d,0);
|
||||
|
||||
/* How did we vote? Be potentially noisy */
|
||||
if(lsb_votes>msb_votes){
|
||||
char buffer[256];
|
||||
cdmessage(d,"\n\tData appears to be coming back little endian.\n");
|
||||
sprintf(buffer,"\tcertainty: %d%%\n",(int)
|
||||
(100.*lsb_votes/(lsb_votes+msb_votes)+.5));
|
||||
cdmessage(d,buffer);
|
||||
return(0);
|
||||
}else{
|
||||
if(msb_votes>lsb_votes){
|
||||
char buffer[256];
|
||||
cdmessage(d,"\n\tData appears to be coming back big endian.\n");
|
||||
sprintf(buffer,"\tcertainty: %d%%\n",(int)
|
||||
(100.*msb_votes/(lsb_votes+msb_votes)+.5));
|
||||
cdmessage(d,buffer);
|
||||
return(1);
|
||||
}
|
||||
|
||||
cdmessage(d,"\n\tCannot determine CDROM drive endianness.\n");
|
||||
return(bigendianp());
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* Here we fix up a couple of things that will never happen. yeah,
|
||||
right. The multisession stuff is from Hannu's code; it assumes it
|
||||
knows the leadoud/leadin size. */
|
||||
|
||||
int
|
||||
FixupTOC(cdrom_drive_t *d,int tracks)
|
||||
{
|
||||
struct cdrom_multisession ms_str;
|
||||
int j;
|
||||
|
||||
/* First off, make sure the 'starting sector' is >=0 */
|
||||
|
||||
for(j=0;j<tracks;j++){
|
||||
if(d->disc_toc[j].dwStartSector<0){
|
||||
cdmessage(d,"\n\tTOC entry claims a negative start offset: massaging"
|
||||
".\n");
|
||||
d->disc_toc[j].dwStartSector=0;
|
||||
}
|
||||
if(j<tracks-1 && d->disc_toc[j].dwStartSector>
|
||||
d->disc_toc[j+1].dwStartSector){
|
||||
cdmessage(d,"\n\tTOC entry claims an overly large start offset: massaging"
|
||||
".\n");
|
||||
d->disc_toc[j].dwStartSector=0;
|
||||
}
|
||||
|
||||
}
|
||||
/* Make sure the listed 'starting sectors' are actually increasing.
|
||||
Flag things that are blatant/stupid/wrong */
|
||||
{
|
||||
long last=d->disc_toc[0].dwStartSector;
|
||||
for(j=1;j<tracks;j++){
|
||||
if(d->disc_toc[j].dwStartSector<last){
|
||||
cdmessage(d,"\n\tTOC entries claim non-increasing offsets: massaging"
|
||||
".\n");
|
||||
d->disc_toc[j].dwStartSector=last;
|
||||
|
||||
}
|
||||
last=d->disc_toc[j].dwStartSector;
|
||||
}
|
||||
}
|
||||
|
||||
/* For a scsi device, the ioctl must go to the specialized SCSI
|
||||
CDROM device, not the generic device. */
|
||||
|
||||
if (d->ioctl_fd != -1) {
|
||||
int result;
|
||||
|
||||
ms_str.addr_format = CDROM_LBA;
|
||||
result = ioctl(d->ioctl_fd, CDROMMULTISESSION, &ms_str);
|
||||
if (result == -1) return -1;
|
||||
|
||||
if (ms_str.addr.lba > 100) {
|
||||
|
||||
/* This is an odd little piece of code --Monty */
|
||||
|
||||
/* believe the multisession offset :-) */
|
||||
/* adjust end of last audio track to be in the first session */
|
||||
for (j = tracks-1; j >= 0; j--) {
|
||||
if (j > 0 && !IS_AUDIO(d,j) && IS_AUDIO(d,j-1)) {
|
||||
if ((d->disc_toc[j].dwStartSector > ms_str.addr.lba - 11400) &&
|
||||
(ms_str.addr.lba - 11400 > d->disc_toc[j-1].dwStartSector))
|
||||
d->disc_toc[j].dwStartSector = ms_str.addr.lba - 11400;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
34
lib/cdda_interface/common_interface.h
Normal file
34
lib/cdda_interface/common_interface.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
$Id: common_interface.h,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _CDDA_COMMON_INTERFACE_H_
|
||||
#define _CDDA_COMMON_INTERFACE_H_
|
||||
|
||||
#include "low_interface.h"
|
||||
|
||||
/* Test for presence of a cdrom by pinging with the 'CDROMVOLREAD' ioctl() */
|
||||
extern int ioctl_ping_cdrom(int fd);
|
||||
|
||||
extern char *atapi_drive_info(int fd);
|
||||
extern int data_bigendianp(cdrom_drive_t *d);
|
||||
extern int FixupTOC(cdrom_drive_t *d,int tracks);
|
||||
|
||||
#endif /*_CDDA_COMMON_INTERFACE_H_*/
|
||||
291
lib/cdda_interface/cooked_interface.c
Normal file
291
lib/cdda_interface/cooked_interface.c
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
$Id: cooked_interface.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Original interface.c Copyright (C) 1994-1997
|
||||
Eissfeldt heiko@colossus.escape.de
|
||||
Current blenderization Copyright (C) 1998-1999 Monty xiphmont@mit.edu
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/******************************************************************
|
||||
*
|
||||
* CDROM code specific to the cooked ioctl interface
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "low_interface.h"
|
||||
#include "common_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
static int
|
||||
cooked_readtoc (cdrom_drive_t *d)
|
||||
{
|
||||
int i;
|
||||
int tracks;
|
||||
struct cdrom_tochdr hdr;
|
||||
struct cdrom_tocentry entry;
|
||||
|
||||
/* get TocHeader to find out how many entries there are */
|
||||
if(ioctl(d->ioctl_fd, CDROMREADTOCHDR, &hdr ))
|
||||
switch(errno){
|
||||
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<hdr.cdth_trk1;i++){
|
||||
entry.cdte_track= i+1;
|
||||
entry.cdte_format = CDROM_LBA;
|
||||
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;
|
||||
entry.cdte_format = CDROM_LBA;
|
||||
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 = entry.cdte_track;
|
||||
d->disc_toc[i].dwStartSector = entry.cdte_addr.lba;
|
||||
|
||||
tracks=hdr.cdth_trk1+1;
|
||||
d->cd_extra=FixupTOC(d,tracks);
|
||||
return(--tracks); /* without lead-out */
|
||||
}
|
||||
|
||||
|
||||
/* Set operating speed */
|
||||
static int
|
||||
cooked_setspeed(cdrom_drive_t *d, int speed)
|
||||
{
|
||||
if(d->ioctl_fd!=-1)
|
||||
return ioctl(d->ioctl_fd, CDROM_SELECT_SPEED, speed);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* read 'SectorBurst' adjacent sectors of audio sectors
|
||||
* to Buffer '*p' beginning at sector 'lSector'
|
||||
*/
|
||||
|
||||
static long int
|
||||
cooked_read (cdrom_drive_t *d, void *p, long begin, long sectors)
|
||||
{
|
||||
int retry_count,err;
|
||||
struct cdrom_read_audio arg;
|
||||
char *buffer=(char *)p;
|
||||
|
||||
/* read d->nsectors at a time, max. */
|
||||
sectors=(sectors>d->nsectors?d->nsectors:sectors);
|
||||
|
||||
arg.addr.lba = begin;
|
||||
arg.addr_format = CDROM_LBA;
|
||||
arg.nframes = sectors;
|
||||
arg.buf=buffer;
|
||||
retry_count=0;
|
||||
|
||||
do {
|
||||
if((err=ioctl(d->ioctl_fd, CDROMREADAUDIO, &arg))){
|
||||
if(!d->error_retry)return(-7);
|
||||
switch(errno){
|
||||
case ENOMEM:
|
||||
/* D'oh. Possible kernel error. Keep limping */
|
||||
if(sectors==1){
|
||||
/* Nope, can't continue */
|
||||
cderror(d,"300: Kernel memory error\n");
|
||||
return(-300);
|
||||
}
|
||||
default:
|
||||
if(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];
|
||||
sprintf(b,"010: Unable to access sector %ld: skipping...\n",
|
||||
begin);
|
||||
cderror(d,b);
|
||||
return(-10);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(retry_count>4)
|
||||
if(sectors>1)
|
||||
sectors=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(sectors);
|
||||
}
|
||||
|
||||
/* hook */
|
||||
static int Dummy (cdrom_drive_t *d,int Switch)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int
|
||||
verify_read_command(cdrom_drive_t *d)
|
||||
{
|
||||
int i;
|
||||
int16_t *buff=malloc(CD_FRAMESIZE_RAW);
|
||||
int audioflag=0;
|
||||
|
||||
cdmessage(d,"Verifying drive can read CDDA...\n");
|
||||
|
||||
d->enable_cdda(d,1);
|
||||
|
||||
for(i=1;i<=d->tracks;i++){
|
||||
if(cdda_track_audiop(d,i)==1){
|
||||
long firstsector=cdda_track_firstsector(d,i);
|
||||
long lastsector=cdda_track_lastsector(d,i);
|
||||
long sector=(firstsector+lastsector)>>1;
|
||||
audioflag=1;
|
||||
|
||||
if(d->read_audio(d,buff,sector,1)>0){
|
||||
cdmessage(d,"\tExpected command set reads OK.\n");
|
||||
d->enable_cdda(d,0);
|
||||
free(buff);
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d->enable_cdda(d,0);
|
||||
|
||||
if(!audioflag){
|
||||
cdmessage(d,"\tCould not find any audio tracks on this disk.\n");
|
||||
return(-403);
|
||||
}
|
||||
|
||||
cdmessage(d,"\n\tUnable to read any data; "
|
||||
"drive probably not CDDA capable.\n");
|
||||
|
||||
cderror(d,"006: Could not read any data from drive\n");
|
||||
|
||||
free(buff);
|
||||
return(-6);
|
||||
}
|
||||
|
||||
#include "drive_exceptions.h"
|
||||
|
||||
static void
|
||||
check_exceptions(cdrom_drive_t *d, const exception_t *list)
|
||||
{
|
||||
|
||||
int i=0;
|
||||
while(list[i].model){
|
||||
if(!strncmp(list[i].model,d->drive_model,strlen(list[i].model))){
|
||||
if(list[i].bigendianp!=-1)d->bigendianp=list[i].bigendianp;
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/* set function pointers to use the ioctl routines */
|
||||
int
|
||||
cooked_init_drive (cdrom_drive_t *d){
|
||||
int ret;
|
||||
|
||||
switch(d->drive_type){
|
||||
case MATSUSHITA_CDROM_MAJOR: /* sbpcd 1 */
|
||||
case MATSUSHITA_CDROM2_MAJOR: /* sbpcd 2 */
|
||||
case MATSUSHITA_CDROM3_MAJOR: /* sbpcd 3 */
|
||||
case MATSUSHITA_CDROM4_MAJOR: /* sbpcd 4 */
|
||||
/* don't make the buffer too big; this sucker don't preempt */
|
||||
|
||||
cdmessage(d,"Attempting to set sbpcd buffer size...\n");
|
||||
|
||||
d->nsectors=8;
|
||||
while(1){
|
||||
|
||||
/* this ioctl returns zero on error; exactly wrong, but that's
|
||||
what it does. */
|
||||
|
||||
if(ioctl(d->ioctl_fd, CDROMAUDIOBUFSIZ, d->nsectors)==0){
|
||||
d->nsectors>>=1;
|
||||
if(d->nsectors==0){
|
||||
char buffer[256];
|
||||
d->nsectors=8;
|
||||
sprintf(buffer,"\tTrouble setting buffer size. Defaulting to %d sectors.\n",
|
||||
d->nsectors);
|
||||
cdmessage(d,buffer);
|
||||
break; /* Oh, well. Try to read anyway.*/
|
||||
}
|
||||
}else{
|
||||
char buffer[256];
|
||||
sprintf(buffer,"\tSetting read block size at %d sectors (%ld bytes).\n",
|
||||
d->nsectors,(long)d->nsectors*CD_FRAMESIZE_RAW);
|
||||
cdmessage(d,buffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case IDE0_MAJOR:
|
||||
case IDE1_MAJOR:
|
||||
case IDE2_MAJOR:
|
||||
case IDE3_MAJOR:
|
||||
d->nsectors=8; /* it's a define in the linux kernel; we have no
|
||||
way of determining other than this guess tho */
|
||||
d->bigendianp=0;
|
||||
d->is_atapi=1;
|
||||
|
||||
check_exceptions(d, atapi_list);
|
||||
|
||||
break;
|
||||
default:
|
||||
d->nsectors=40;
|
||||
}
|
||||
d->enable_cdda = Dummy;
|
||||
d->read_audio = cooked_read;
|
||||
d->set_speed = cooked_setspeed;
|
||||
d->read_toc = cooked_readtoc;
|
||||
ret=d->tracks=d->read_toc(d);
|
||||
if(d->tracks<1)
|
||||
return(ret);
|
||||
|
||||
d->opened=1;
|
||||
if((ret=verify_read_command(d)))return(ret);
|
||||
d->error_retry=1;
|
||||
return(0);
|
||||
}
|
||||
|
||||
95
lib/cdda_interface/drive_exceptions.h
Normal file
95
lib/cdda_interface/drive_exceptions.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
$Id: drive_exceptions.h,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
extern int scsi_enable_cdda(cdrom_drive_t *d, int);
|
||||
extern long scsi_read_mmc(cdrom_drive_t *d, void *,long,long);
|
||||
extern long scsi_read_mmc2(cdrom_drive_t *d, void *,long,long);
|
||||
extern long scsi_read_D4_10(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_D4_12(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_D8(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_28(cdrom_drive_t *, void *,long,long);
|
||||
extern long scsi_read_A8(cdrom_drive_t *, void *,long,long);
|
||||
|
||||
typedef struct exception {
|
||||
const char *model;
|
||||
int atapi; /* If the ioctl doesn't work */
|
||||
unsigned char density;
|
||||
int (*enable)(cdrom_drive_t *,int);
|
||||
long (*read)(cdrom_drive_t *,void *, long, long);
|
||||
int bigendianp;
|
||||
} exception_t;
|
||||
|
||||
/* specific to general */
|
||||
|
||||
/* list of drives that affect autosensing in ATAPI specific portions of code
|
||||
(force drives to detect as ATAPI or SCSI, force ATAPI read command */
|
||||
|
||||
static exception_t atapi_list[]={
|
||||
{"SAMSUNG SCR-830 REV 2.09 2.09 ", 1, 0, Dummy,scsi_read_mmc2,0},
|
||||
{"Memorex CR-622", 1, 0, Dummy, NULL,0},
|
||||
{"SONY CD-ROM CDU-561", 0, 0, Dummy, NULL,0},
|
||||
{"Chinon CD-ROM CDS-525", 0, 0, Dummy, NULL,0},
|
||||
{NULL,0,0,NULL,NULL,0}};
|
||||
|
||||
/* list of drives that affect MMC default settings */
|
||||
|
||||
#ifdef NEED_MMC_LIST
|
||||
static exception_t mmc_list[]={
|
||||
{"SAMSUNG SCR-830 REV 2.09 2.09 ", 1, 0, Dummy,scsi_read_mmc2,0},
|
||||
{"Memorex CR-622", 1, 0, Dummy, NULL,0},
|
||||
{"SONY CD-ROM CDU-561", 0, 0, Dummy, NULL,0},
|
||||
{"Chinon CD-ROM CDS-525", 0, 0, Dummy, NULL,0},
|
||||
{"KENWOOD CD-ROM UCR", -1, 0, NULL,scsi_read_D8, 0},
|
||||
{NULL,0,0,NULL,NULL,0}};
|
||||
#endif /*NEED_MMC_LIST*/
|
||||
|
||||
/* list of drives that affect SCSI default settings */
|
||||
|
||||
#ifdef NEED_SCSI_LIST
|
||||
static exception_t scsi_list[]={
|
||||
{"TOSHIBA", -1,0x82,scsi_enable_cdda,scsi_read_28, 0},
|
||||
{"IBM", -1,0x82,scsi_enable_cdda,scsi_read_28, 0},
|
||||
{"DEC", -1,0x82,scsi_enable_cdda,scsi_read_28, 0},
|
||||
|
||||
{"IMS", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"KODAK", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"RICOH", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"HP", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"PHILIPS", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"PLASMON", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"GRUNDIG CDR100IPW", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"MITSUMI CD-R ", -1, 0,scsi_enable_cdda,scsi_read_28, 1},
|
||||
{"KENWOOD CD-ROM UCR", -1, 0, NULL,scsi_read_D8, 0},
|
||||
|
||||
{"YAMAHA", -1, 0,scsi_enable_cdda, NULL, 0},
|
||||
|
||||
{"PLEXTOR", -1, 0, NULL, NULL, 0},
|
||||
{"SONY", -1, 0, NULL, NULL, 0},
|
||||
|
||||
{"NEC", -1, 0, NULL,scsi_read_D4_10,0},
|
||||
|
||||
/* the 7501 locks up if hit with the 10 byte version from the
|
||||
autoprobe first */
|
||||
{"MATSHITA CD-R CW-7501", -1, 0, NULL,scsi_read_D4_12,-1},
|
||||
|
||||
{NULL,0,0,NULL,NULL,0}};
|
||||
|
||||
#endif /* NEED_SCSI_LIST*/
|
||||
149
lib/cdda_interface/interface.c
Normal file
149
lib/cdda_interface/interface.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/******************************************************************
|
||||
* CopyPolicy: GNU Public License 2 applies
|
||||
* Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
*
|
||||
* Top-level interface module for cdrom drive access. SCSI, ATAPI, etc
|
||||
* specific stuff are in other modules. Note that SCSI does use
|
||||
* specialized ioctls; these appear in common_interface.c where the
|
||||
* generic_scsi stuff is in scsi_interface.c.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include "low_interface.h"
|
||||
#include "common_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void _clean_messages(cdrom_drive_t *d)
|
||||
{
|
||||
if(d){
|
||||
if(d->messagebuf)free(d->messagebuf);
|
||||
if(d->errorbuf)free(d->errorbuf);
|
||||
d->messagebuf=NULL;
|
||||
d->errorbuf=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* doubles as "cdrom_drive_free()" */
|
||||
int
|
||||
cdda_close(cdrom_drive_t *d)
|
||||
{
|
||||
if(d){
|
||||
if(d->opened)
|
||||
d->enable_cdda(d,0);
|
||||
|
||||
_clean_messages(d);
|
||||
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->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);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* finish initializing the drive! */
|
||||
int
|
||||
cdda_open(cdrom_drive_t *d)
|
||||
{
|
||||
int ret;
|
||||
if(d->opened)return(0);
|
||||
|
||||
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;
|
||||
#ifdef CDDA_TEST
|
||||
case TEST_INTERFACE:
|
||||
if((ret=test_init_drive(d)))
|
||||
return(ret);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
cderror(d,"100: Interface not supported\n");
|
||||
return(-100);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
int
|
||||
cdda_speed_set(cdrom_drive_t *d, int speed)
|
||||
{
|
||||
return d->set_speed ? d->set_speed(d, speed) : 0;
|
||||
}
|
||||
|
||||
long cdda_read(cdrom_drive_t *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);
|
||||
}
|
||||
|
||||
void
|
||||
cdda_verbose_set(cdrom_drive_t *d,int err_action, int mes_action)
|
||||
{
|
||||
d->messagedest=mes_action;
|
||||
d->errordest=err_action;
|
||||
}
|
||||
|
||||
extern char *cdda_messages(cdrom_drive_t *d)
|
||||
{
|
||||
char *ret=d->messagebuf;
|
||||
d->messagebuf=NULL;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
extern char *cdda_errors(cdrom_drive_t *d)
|
||||
{
|
||||
char *ret=d->errorbuf;
|
||||
d->errorbuf=NULL;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
86
lib/cdda_interface/low_interface.h
Normal file
86
lib/cdda_interface/low_interface.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
$Id: low_interface.h,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/** internal include file for cdda interface kit for Linux */
|
||||
|
||||
#ifndef _CDDA_LOW_INTERFACE_
|
||||
#define _CDDA_LOW_INTERFACE_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <linux/major.h>
|
||||
#include <linux/version.h>
|
||||
#include <cdio/paranoia.h>
|
||||
#include <cdio/cdda_interface.h>
|
||||
|
||||
/* some include file locations have changed with newer kernels */
|
||||
|
||||
#ifdef SBPCD_H
|
||||
#include <linux/sbpcd.h>
|
||||
#endif
|
||||
|
||||
#ifdef UCDROM_H
|
||||
#include <linux/ucdrom.h>
|
||||
#endif
|
||||
|
||||
#ifndef CDROMAUDIOBUFSIZ
|
||||
#define CDROMAUDIOBUFSIZ 0x5382 /* set the audio buffer size */
|
||||
#endif
|
||||
|
||||
#include <scsi/sg.h>
|
||||
#include <scsi/scsi.h>
|
||||
|
||||
#include <linux/cdrom.h>
|
||||
#include <linux/major.h>
|
||||
|
||||
#define MAX_RETRIES 8
|
||||
#define MAX_BIG_BUFF_SIZE 65536
|
||||
#define MIN_BIG_BUFF_SIZE 4096
|
||||
#define SG_OFF sizeof(struct sg_header)
|
||||
|
||||
#ifndef SG_EMULATED_HOST
|
||||
/* old kernel version; the check for the ioctl is still runtime, this
|
||||
is just to build */
|
||||
#define SG_EMULATED_HOST 0x2203
|
||||
#define SG_SET_TRANSFORM 0x2204
|
||||
#define SG_GET_TRANSFORM 0x2205
|
||||
#endif
|
||||
|
||||
extern int cooked_init_drive (cdrom_drive_t *d);
|
||||
extern unsigned char *scsi_inquiry (cdrom_drive_t *d);
|
||||
extern int scsi_init_drive (cdrom_drive_t *d);
|
||||
#ifdef CDDA_TEST
|
||||
extern int test_init_drive (cdrom_drive_t *d);
|
||||
#endif
|
||||
#endif /*_CDDA_LOW_INTERFACE_*/
|
||||
|
||||
733
lib/cdda_interface/scan_devices.c
Normal file
733
lib/cdda_interface/scan_devices.c
Normal file
@@ -0,0 +1,733 @@
|
||||
/*
|
||||
$Id: scan_devices.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* Autoscan for or verify presence of a cdrom device
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "low_interface.h"
|
||||
#include "common_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_DEV_LEN 20 /* Safe because strings only come from below */
|
||||
/* must be absolute paths! */
|
||||
const char *scsi_cdrom_prefixes[]={
|
||||
"/dev/scd",
|
||||
"/dev/sr",
|
||||
NULL};
|
||||
const char *scsi_generic_prefixes[]={
|
||||
"/dev/sg",
|
||||
NULL};
|
||||
|
||||
const char *devfs_scsi_test="/dev/scsi/";
|
||||
const char *devfs_scsi_cd="cd";
|
||||
const char *devfs_scsi_generic="generic";
|
||||
|
||||
const char *cdrom_devices[]={
|
||||
"/dev/cdrom",
|
||||
"/dev/cdroms/cdrom?",
|
||||
"/dev/hd?",
|
||||
"/dev/sg?",
|
||||
"/dev/cdu31a",
|
||||
"/dev/cdu535",
|
||||
"/dev/sbpcd",
|
||||
"/dev/sbpcd?",
|
||||
"/dev/sonycd",
|
||||
"/dev/mcd",
|
||||
"/dev/sjcd",
|
||||
/* "/dev/aztcd", timeout is too long */
|
||||
"/dev/cm206cd",
|
||||
"/dev/gscd",
|
||||
"/dev/optcd",NULL};
|
||||
|
||||
/* Functions here look for a cdrom drive; full init of a drive type
|
||||
happens in interface.c */
|
||||
|
||||
cdrom_drive_t *
|
||||
cdda_find_a_cdrom(int messagedest, char **messages){
|
||||
/* Brute force... */
|
||||
|
||||
int i=0;
|
||||
cdrom_drive_t *d;
|
||||
|
||||
while(cdrom_devices[i]!=NULL){
|
||||
|
||||
/* is it a name or a pattern? */
|
||||
char *pos;
|
||||
if((pos=strchr(cdrom_devices[i],'?'))){
|
||||
int j;
|
||||
/* try first eight of each device */
|
||||
for(j=0;j<4;j++){
|
||||
char *buffer=copystring(cdrom_devices[i]);
|
||||
|
||||
/* number, then letter */
|
||||
|
||||
buffer[pos-(cdrom_devices[i])]=j+48;
|
||||
if((d=cdda_identify(buffer,messagedest,messages)))
|
||||
return(d);
|
||||
idmessage(messagedest,messages,"",NULL);
|
||||
buffer[pos-(cdrom_devices[i])]=j+97;
|
||||
if((d=cdda_identify(buffer,messagedest,messages)))
|
||||
return(d);
|
||||
idmessage(messagedest,messages,"",NULL);
|
||||
}
|
||||
}else{
|
||||
/* Name. Go for it. */
|
||||
if((d=cdda_identify(cdrom_devices[i],messagedest,messages)))
|
||||
return(d);
|
||||
|
||||
idmessage(messagedest,messages,"",NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
{
|
||||
struct passwd *temp;
|
||||
temp=getpwuid(geteuid());
|
||||
idmessage(messagedest,messages,
|
||||
"\n\nNo cdrom drives accessible to %s found.\n",
|
||||
temp->pw_name);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
cdrom_drive_t *
|
||||
cdda_identify(const char *device, int messagedest,char **messages)
|
||||
{
|
||||
struct stat st;
|
||||
cdrom_drive_t *d=NULL;
|
||||
idmessage(messagedest,messages,"Checking %s for cdrom...",device);
|
||||
|
||||
if(stat(device,&st)){
|
||||
idperror(messagedest,messages,"\tCould not stat %s",device);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#ifndef CDDA_TEST
|
||||
if (!S_ISCHR(st.st_mode) &&
|
||||
!S_ISBLK(st.st_mode)){
|
||||
idmessage(messagedest,messages,"\t%s is not a block or character device",device);
|
||||
return(NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
d=cdda_identify_cooked(device,messagedest,messages);
|
||||
if(!d)d=cdda_identify_scsi(device,NULL,messagedest,messages);
|
||||
|
||||
#ifdef CDDA_TEST
|
||||
if(!d)d=cdda_identify_test(device,messagedest,messages);
|
||||
#endif
|
||||
|
||||
return(d);
|
||||
}
|
||||
|
||||
static char *
|
||||
test_resolve_symlink(const char *file,int messagedest,char **messages)
|
||||
{
|
||||
char resolved[PATH_MAX];
|
||||
struct stat st;
|
||||
if(lstat(file,&st)){
|
||||
idperror(messagedest,messages,"\t\tCould not stat %s",file);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if(realpath(file,resolved))
|
||||
return(strdup(resolved));
|
||||
|
||||
idperror(messagedest,messages,"\t\tCould not resolve symlink %s",file);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
cdrom_drive_t *
|
||||
cdda_identify_cooked(const char *dev, int messagedest,
|
||||
char **messages)
|
||||
{
|
||||
|
||||
cdrom_drive_t *d=NULL;
|
||||
struct stat st;
|
||||
int fd=-1;
|
||||
int type;
|
||||
char *description=NULL;
|
||||
char *device;
|
||||
|
||||
idmessage(messagedest,messages,"\tTesting %s for cooked ioctl() interface",dev);
|
||||
|
||||
device=test_resolve_symlink(dev,messagedest,messages);
|
||||
if(device==NULL)return(NULL);
|
||||
|
||||
if(stat(device,&st)){
|
||||
idperror(messagedest,messages,"\t\tCould not stat %s",device);
|
||||
free(device);
|
||||
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=copystring("Sony CDU31A or compatible");
|
||||
break;
|
||||
case CDU535_CDROM_MAJOR:
|
||||
/* major indicates this is a cdrom; no ping necessary. */
|
||||
description=copystring("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=copystring("non-ATAPI IDE-style Matsushita/Panasonic CR-5xx or compatible");
|
||||
break;
|
||||
case SANYO_CDROM_MAJOR:
|
||||
description=copystring("Sanyo proprietary or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case MITSUMI_CDROM_MAJOR:
|
||||
case MITSUMI_X_CDROM_MAJOR:
|
||||
description=copystring("Mitsumi proprietary or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case OPTICS_CDROM_MAJOR:
|
||||
description=copystring("Optics Dolphin or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case AZTECH_CDROM_MAJOR:
|
||||
description=copystring("Aztech proprietary or compatible: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case GOLDSTAR_CDROM_MAJOR:
|
||||
description=copystring("Goldstar proprietary: NOT CDDA CAPABLE");
|
||||
break;
|
||||
case CM206_CDROM_MAJOR:
|
||||
description=copystring("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 */
|
||||
|
||||
d=calloc(1,sizeof(cdrom_drive_t));
|
||||
d->cdda_device_name=device;
|
||||
d->ioctl_device_name=copystring(device);
|
||||
d->drive_model=description;
|
||||
d->drive_type=type;
|
||||
d->cdda_fd=fd;
|
||||
d->ioctl_fd=fd;
|
||||
d->interface=COOKED_IOCTL;
|
||||
d->bigendianp=-1; /* We don't know yet... */
|
||||
d->nsectors=-1;
|
||||
idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description);
|
||||
|
||||
return(d);
|
||||
}
|
||||
|
||||
struct sg_id {
|
||||
long l1; /* target | lun << 8 | channel << 16 | low_ino << 24 */
|
||||
long l2; /* Unique id */
|
||||
} sg_id;
|
||||
|
||||
typedef struct scsiid{
|
||||
int bus;
|
||||
int id;
|
||||
int lun;
|
||||
} 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=copystring(generic_device);
|
||||
d->ioctl_device_name=copystring(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
|
||||
|
||||
cdrom_drive_t *cdda_identify_test(const char *filename, int messagedest,
|
||||
char **messages){
|
||||
|
||||
cdrom_drive_t *d=NULL;
|
||||
struct stat st;
|
||||
int fd=-1;
|
||||
|
||||
idmessage(messagedest,messages,"\tTesting %s for file/test interface",
|
||||
filename);
|
||||
|
||||
if(stat(filename,&st)){
|
||||
idperror(messagedest,messages,"\t\tCould not access file %s",
|
||||
filename);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if(!S_ISREG(st.st_mode)){
|
||||
idmessage(messagedest,messages,"\t\t%s is not a regular file",
|
||||
filename);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
fd=open(filename,O_RDONLY);
|
||||
|
||||
if(fd==-1){
|
||||
idperror(messagedest,messages,"\t\tCould not open file %s",filename);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
d=calloc(1,sizeof(cdrom_drive_t));
|
||||
|
||||
d->cdda_device_name=copystring(filename);
|
||||
d->ioctl_device_name=copystring(filename);
|
||||
d->drive_type=-1;
|
||||
d->cdda_fd=fd;
|
||||
d->ioctl_fd=fd;
|
||||
d->interface=TEST_INTERFACE;
|
||||
d->bigendianp=-1; /* We don't know yet... */
|
||||
d->nsectors=-1;
|
||||
d->drive_model=copystring("File based test interface");
|
||||
idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",d->drive_model);
|
||||
|
||||
return(d);
|
||||
}
|
||||
|
||||
#endif
|
||||
1580
lib/cdda_interface/scsi_interface.c
Normal file
1580
lib/cdda_interface/scsi_interface.c
Normal file
File diff suppressed because it is too large
Load Diff
547
lib/cdda_interface/smallft.c
Normal file
547
lib/cdda_interface/smallft.c
Normal file
@@ -0,0 +1,547 @@
|
||||
/******************************************************************
|
||||
* CopyPolicy: GNU Public License 2 applies
|
||||
* Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
*
|
||||
* FFT implementation from OggSquish, minus cosine transforms,
|
||||
* minus all but radix 2/4 case
|
||||
*
|
||||
* See OggSquish or NetLib for the version that can do other than just
|
||||
* power-of-two sized vectors.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "smallft.h"
|
||||
|
||||
static void drfti1(int n, float *wa, int *ifac){
|
||||
static int ntryh[4] = { 4,2,3,5 };
|
||||
static float tpi = 6.28318530717958647692528676655900577;
|
||||
float arg,argh,argld,fi;
|
||||
int ntry=0,i,j=-1;
|
||||
int k1, l1, l2, ib;
|
||||
int ld, ii, ip, is, nq, nr;
|
||||
int ido, ipm, nfm1;
|
||||
int nl=n;
|
||||
int nf=0;
|
||||
|
||||
L101:
|
||||
j++;
|
||||
if (j < 4)
|
||||
ntry=ntryh[j];
|
||||
else
|
||||
ntry+=2;
|
||||
|
||||
L104:
|
||||
nq=nl/ntry;
|
||||
nr=nl-ntry*nq;
|
||||
if (nr!=0) goto L101;
|
||||
|
||||
nf++;
|
||||
ifac[nf+1]=ntry;
|
||||
nl=nq;
|
||||
if(ntry!=2)goto L107;
|
||||
if(nf==1)goto L107;
|
||||
|
||||
for (i=1;i<nf;i++){
|
||||
ib=nf-i+1;
|
||||
ifac[ib+1]=ifac[ib];
|
||||
}
|
||||
ifac[2] = 2;
|
||||
|
||||
L107:
|
||||
if(nl!=1)goto L104;
|
||||
ifac[0]=n;
|
||||
ifac[1]=nf;
|
||||
argh=tpi/n;
|
||||
is=0;
|
||||
nfm1=nf-1;
|
||||
l1=1;
|
||||
|
||||
if(nfm1==0)return;
|
||||
|
||||
for (k1=0;k1<nfm1;k1++){
|
||||
ip=ifac[k1+2];
|
||||
ld=0;
|
||||
l2=l1*ip;
|
||||
ido=n/l2;
|
||||
ipm=ip-1;
|
||||
|
||||
for (j=0;j<ipm;j++){
|
||||
ld+=l1;
|
||||
i=is;
|
||||
argld=(float)ld*argh;
|
||||
fi=0.;
|
||||
for (ii=2;ii<ido;ii+=2){
|
||||
fi+=1.;
|
||||
arg=fi*argld;
|
||||
wa[i++]=cos(arg);
|
||||
wa[i++]=sin(arg);
|
||||
}
|
||||
is+=ido;
|
||||
}
|
||||
l1=l2;
|
||||
}
|
||||
}
|
||||
|
||||
static void fdrffti(int n, float *wsave, int *ifac){
|
||||
|
||||
if (n == 1) return;
|
||||
drfti1(n, wsave+n, ifac);
|
||||
}
|
||||
|
||||
static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
|
||||
int i,k;
|
||||
float ti2,tr2;
|
||||
int t0,t1,t2,t3,t4,t5,t6;
|
||||
|
||||
t1=0;
|
||||
t0=(t2=l1*ido);
|
||||
t3=ido<<1;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1<<1]=cc[t1]+cc[t2];
|
||||
ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
t1=0;
|
||||
t2=t0;
|
||||
for(k=0;k<l1;k++){
|
||||
t3=t2;
|
||||
t4=(t1<<1)+(ido<<1);
|
||||
t5=t1;
|
||||
t6=t1+t1;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t3+=2;
|
||||
t4-=2;
|
||||
t5+=2;
|
||||
t6+=2;
|
||||
tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
|
||||
ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
|
||||
ch[t6]=cc[t5]+ti2;
|
||||
ch[t4]=ti2-cc[t5];
|
||||
ch[t6-1]=cc[t5-1]+tr2;
|
||||
ch[t4-1]=cc[t5-1]-tr2;
|
||||
}
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
}
|
||||
|
||||
if(ido%2==1)return;
|
||||
|
||||
L105:
|
||||
t3=(t2=(t1=ido)-1);
|
||||
t2+=t0;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1]=-cc[t2];
|
||||
ch[t1-1]=cc[t3];
|
||||
t1+=ido<<1;
|
||||
t2+=ido;
|
||||
t3+=ido;
|
||||
}
|
||||
}
|
||||
|
||||
static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
|
||||
float *wa2,float *wa3){
|
||||
static float hsqt2 = .70710678118654752440084436210485;
|
||||
int i,k,t0,t1,t2,t3,t4,t5,t6;
|
||||
float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
|
||||
t0=l1*ido;
|
||||
|
||||
t1=t0;
|
||||
t4=t1<<1;
|
||||
t2=t1+(t1<<1);
|
||||
t3=0;
|
||||
|
||||
for(k=0;k<l1;k++){
|
||||
tr1=cc[t1]+cc[t2];
|
||||
tr2=cc[t3]+cc[t4];
|
||||
|
||||
ch[t5=t3<<2]=tr1+tr2;
|
||||
ch[(ido<<2)+t5-1]=tr2-tr1;
|
||||
ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
|
||||
ch[t5]=cc[t2]-cc[t1];
|
||||
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
t3+=ido;
|
||||
t4+=ido;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
|
||||
t1=0;
|
||||
for(k=0;k<l1;k++){
|
||||
t2=t1;
|
||||
t4=t1<<2;
|
||||
t5=(t6=ido<<1)+t4;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t3=(t2+=2);
|
||||
t4+=2;
|
||||
t5-=2;
|
||||
|
||||
t3+=t0;
|
||||
cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
|
||||
ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
|
||||
t3+=t0;
|
||||
cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
|
||||
ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
|
||||
t3+=t0;
|
||||
cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
|
||||
ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
|
||||
|
||||
tr1=cr2+cr4;
|
||||
tr4=cr4-cr2;
|
||||
ti1=ci2+ci4;
|
||||
ti4=ci2-ci4;
|
||||
|
||||
ti2=cc[t2]+ci3;
|
||||
ti3=cc[t2]-ci3;
|
||||
tr2=cc[t2-1]+cr3;
|
||||
tr3=cc[t2-1]-cr3;
|
||||
|
||||
ch[t4-1]=tr1+tr2;
|
||||
ch[t4]=ti1+ti2;
|
||||
|
||||
ch[t5-1]=tr3-ti4;
|
||||
ch[t5]=tr4-ti3;
|
||||
|
||||
ch[t4+t6-1]=ti4+tr3;
|
||||
ch[t4+t6]=tr4+ti3;
|
||||
|
||||
ch[t5+t6-1]=tr2-tr1;
|
||||
ch[t5+t6]=ti1-ti2;
|
||||
}
|
||||
t1+=ido;
|
||||
}
|
||||
if(ido&1)return;
|
||||
|
||||
L105:
|
||||
|
||||
t2=(t1=t0+ido-1)+(t0<<1);
|
||||
t3=ido<<2;
|
||||
t4=ido;
|
||||
t5=ido<<1;
|
||||
t6=ido;
|
||||
|
||||
for(k=0;k<l1;k++){
|
||||
ti1=-hsqt2*(cc[t1]+cc[t2]);
|
||||
tr1=hsqt2*(cc[t1]-cc[t2]);
|
||||
|
||||
ch[t4-1]=tr1+cc[t6-1];
|
||||
ch[t4+t5-1]=cc[t6-1]-tr1;
|
||||
|
||||
ch[t4]=ti1-cc[t1+t0];
|
||||
ch[t4+t5]=ti1+cc[t1+t0];
|
||||
|
||||
t1+=ido;
|
||||
t2+=ido;
|
||||
t4+=t3;
|
||||
t6+=ido;
|
||||
}
|
||||
}
|
||||
|
||||
static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
|
||||
int i,k1,l1,l2;
|
||||
int na,kh,nf;
|
||||
int ip,iw,ido,idl1,ix2,ix3;
|
||||
|
||||
nf=ifac[1];
|
||||
na=1;
|
||||
l2=n;
|
||||
iw=n;
|
||||
|
||||
for(k1=0;k1<nf;k1++){
|
||||
kh=nf-k1;
|
||||
ip=ifac[kh+1];
|
||||
l1=l2/ip;
|
||||
ido=n/l2;
|
||||
idl1=ido*l1;
|
||||
iw-=(ip-1)*ido;
|
||||
na=1-na;
|
||||
|
||||
if(ip!=4)goto L102;
|
||||
|
||||
ix2=iw+ido;
|
||||
ix3=ix2+ido;
|
||||
if(na!=0)
|
||||
dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
else
|
||||
dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
goto L110;
|
||||
|
||||
L102:
|
||||
if(ip!=2)goto L104;
|
||||
if(na!=0)goto L103;
|
||||
|
||||
dradf2(ido,l1,c,ch,wa+iw-1);
|
||||
goto L110;
|
||||
|
||||
L103:
|
||||
dradf2(ido,l1,ch,c,wa+iw-1);
|
||||
goto L110;
|
||||
|
||||
L104:
|
||||
return; /* We're restricted to powers of two. just fail */
|
||||
|
||||
L110:
|
||||
l2=l1;
|
||||
}
|
||||
|
||||
if(na==1)return;
|
||||
|
||||
for(i=0;i<n;i++)c[i]=ch[i];
|
||||
}
|
||||
|
||||
static void fdrfftf(int n,float *r,float *wsave,int *ifac){
|
||||
if(n==1)return;
|
||||
drftf1(n,r,wsave,wsave+n,ifac);
|
||||
}
|
||||
|
||||
static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
|
||||
int i,k,t0,t1,t2,t3,t4,t5,t6;
|
||||
float ti2,tr2;
|
||||
|
||||
t0=l1*ido;
|
||||
|
||||
t1=0;
|
||||
t2=0;
|
||||
t3=(ido<<1)-1;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1]=cc[t2]+cc[t3+t2];
|
||||
ch[t1+t0]=cc[t2]-cc[t3+t2];
|
||||
t2=(t1+=ido)<<1;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
t1=0;
|
||||
t2=0;
|
||||
for(k=0;k<l1;k++){
|
||||
t3=t1;
|
||||
t5=(t4=t2)+(ido<<1);
|
||||
t6=t0+t1;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t3+=2;
|
||||
t4+=2;
|
||||
t5-=2;
|
||||
t6+=2;
|
||||
ch[t3-1]=cc[t4-1]+cc[t5-1];
|
||||
tr2=cc[t4-1]-cc[t5-1];
|
||||
ch[t3]=cc[t4]-cc[t5];
|
||||
ti2=cc[t4]+cc[t5];
|
||||
ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
|
||||
ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
|
||||
}
|
||||
t2=(t1+=ido)<<1;
|
||||
}
|
||||
|
||||
if(ido%2==1)return;
|
||||
|
||||
L105:
|
||||
t1=ido-1;
|
||||
t2=ido-1;
|
||||
for(k=0;k<l1;k++){
|
||||
ch[t1]=cc[t2]+cc[t2];
|
||||
ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
|
||||
t1+=ido;
|
||||
t2+=ido<<1;
|
||||
}
|
||||
}
|
||||
|
||||
static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
|
||||
float *wa2,float *wa3){
|
||||
static float sqrt2=1.4142135623730950488016887242097;
|
||||
int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
|
||||
float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
|
||||
t0=l1*ido;
|
||||
|
||||
t1=0;
|
||||
t2=ido<<2;
|
||||
t3=0;
|
||||
t6=ido<<1;
|
||||
for(k=0;k<l1;k++){
|
||||
t4=t3+t6;
|
||||
t5=t1;
|
||||
tr3=cc[t4-1]+cc[t4-1];
|
||||
tr4=cc[t4]+cc[t4];
|
||||
tr1=cc[t3]-cc[(t4+=t6)-1];
|
||||
tr2=cc[t3]+cc[t4-1];
|
||||
ch[t5]=tr2+tr3;
|
||||
ch[t5+=t0]=tr1-tr4;
|
||||
ch[t5+=t0]=tr2-tr3;
|
||||
ch[t5+=t0]=tr1+tr4;
|
||||
t1+=ido;
|
||||
t3+=t2;
|
||||
}
|
||||
|
||||
if(ido<2)return;
|
||||
if(ido==2)goto L105;
|
||||
|
||||
t1=0;
|
||||
for(k=0;k<l1;k++){
|
||||
t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
|
||||
t7=t1;
|
||||
for(i=2;i<ido;i+=2){
|
||||
t2+=2;
|
||||
t3+=2;
|
||||
t4-=2;
|
||||
t5-=2;
|
||||
t7+=2;
|
||||
ti1=cc[t2]+cc[t5];
|
||||
ti2=cc[t2]-cc[t5];
|
||||
ti3=cc[t3]-cc[t4];
|
||||
tr4=cc[t3]+cc[t4];
|
||||
tr1=cc[t2-1]-cc[t5-1];
|
||||
tr2=cc[t2-1]+cc[t5-1];
|
||||
ti4=cc[t3-1]-cc[t4-1];
|
||||
tr3=cc[t3-1]+cc[t4-1];
|
||||
ch[t7-1]=tr2+tr3;
|
||||
cr3=tr2-tr3;
|
||||
ch[t7]=ti2+ti3;
|
||||
ci3=ti2-ti3;
|
||||
cr2=tr1-tr4;
|
||||
cr4=tr1+tr4;
|
||||
ci2=ti1+ti4;
|
||||
ci4=ti1-ti4;
|
||||
|
||||
ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
|
||||
ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
|
||||
ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
|
||||
ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
|
||||
ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
|
||||
ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
|
||||
}
|
||||
t1+=ido;
|
||||
}
|
||||
|
||||
if(ido%2 == 1)return;
|
||||
|
||||
L105:
|
||||
|
||||
t1=ido;
|
||||
t2=ido<<2;
|
||||
t3=ido-1;
|
||||
t4=ido+(ido<<1);
|
||||
for(k=0;k<l1;k++){
|
||||
t5=t3;
|
||||
ti1=cc[t1]+cc[t4];
|
||||
ti2=cc[t4]-cc[t1];
|
||||
tr1=cc[t1-1]-cc[t4-1];
|
||||
tr2=cc[t1-1]+cc[t4-1];
|
||||
ch[t5]=tr2+tr2;
|
||||
ch[t5+=t0]=sqrt2*(tr1-ti1);
|
||||
ch[t5+=t0]=ti2+ti2;
|
||||
ch[t5+=t0]=-sqrt2*(tr1+ti1);
|
||||
|
||||
t3+=ido;
|
||||
t1+=t2;
|
||||
t4+=t2;
|
||||
}
|
||||
}
|
||||
|
||||
static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
|
||||
int i,k1,l1,l2;
|
||||
int na;
|
||||
int nf,ip,iw,ix2,ix3,ido,idl1;
|
||||
|
||||
nf=ifac[1];
|
||||
na=0;
|
||||
l1=1;
|
||||
iw=1;
|
||||
|
||||
for(k1=0;k1<nf;k1++){
|
||||
ip=ifac[k1 + 2];
|
||||
l2=ip*l1;
|
||||
ido=n/l2;
|
||||
idl1=ido*l1;
|
||||
if(ip!=4)goto L103;
|
||||
ix2=iw+ido;
|
||||
ix3=ix2+ido;
|
||||
|
||||
if(na!=0)
|
||||
dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
else
|
||||
dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
|
||||
na=1-na;
|
||||
goto L115;
|
||||
|
||||
L103:
|
||||
if(ip!=2)goto L106;
|
||||
|
||||
if(na!=0)
|
||||
dradb2(ido,l1,ch,c,wa+iw-1);
|
||||
else
|
||||
dradb2(ido,l1,c,ch,wa+iw-1);
|
||||
na=1-na;
|
||||
goto L115;
|
||||
|
||||
L106:
|
||||
return; /* silently fail. we only do powers of two in this version */
|
||||
|
||||
L115:
|
||||
l1=l2;
|
||||
iw+=(ip-1)*ido;
|
||||
}
|
||||
|
||||
if(na==0)return;
|
||||
|
||||
for(i=0;i<n;i++)c[i]=ch[i];
|
||||
}
|
||||
|
||||
static void fdrfftb(int n, float *r, float *wsave, int *ifac){
|
||||
if (n == 1)return;
|
||||
drftb1(n, r, wsave, wsave+n, ifac);
|
||||
}
|
||||
|
||||
void fft_forward(int n, float *buf,float *trigcache,int *splitcache){
|
||||
int flag=0;
|
||||
|
||||
if(!trigcache || !splitcache){
|
||||
trigcache=calloc(3*n,sizeof(float));
|
||||
splitcache=calloc(32,sizeof(int));
|
||||
fdrffti(n, trigcache, splitcache);
|
||||
flag=1;
|
||||
}
|
||||
|
||||
fdrfftf(n, buf, trigcache, splitcache);
|
||||
|
||||
if(flag){
|
||||
free(trigcache);
|
||||
free(splitcache);
|
||||
}
|
||||
}
|
||||
|
||||
void fft_backward(int n, float *buf, float *trigcache,int *splitcache){
|
||||
int i;
|
||||
int flag=0;
|
||||
|
||||
if(!trigcache || !splitcache){
|
||||
trigcache=calloc(3*n,sizeof(float));
|
||||
splitcache=calloc(32,sizeof(int));
|
||||
fdrffti(n, trigcache, splitcache);
|
||||
flag=1;
|
||||
}
|
||||
|
||||
fdrfftb(n, buf, trigcache, splitcache);
|
||||
|
||||
for(i=0;i<n;i++)buf[i]/=n;
|
||||
|
||||
if(flag){
|
||||
free(trigcache);
|
||||
free(splitcache);
|
||||
}
|
||||
}
|
||||
|
||||
void fft_i(int n, float **trigcache, int **splitcache){
|
||||
*trigcache=calloc(3*n,sizeof(float));
|
||||
*splitcache=calloc(32,sizeof(int));
|
||||
fdrffti(n, *trigcache, *splitcache);
|
||||
}
|
||||
12
lib/cdda_interface/smallft.h
Normal file
12
lib/cdda_interface/smallft.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/******************************************************************
|
||||
* CopyPolicy: GNU Public License 2 applies
|
||||
* Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
*
|
||||
* FFT implementation from OggSquish, minus cosine transforms.
|
||||
* Only convenience functions exposed
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
extern void fft_forward(int n, float *buf, float *trigcache, int *sp);
|
||||
extern void fft_backward(int n, float *buf, float *trigcache, int *sp);
|
||||
extern void fft_i(int n, float **trigcache, int **splitcache);
|
||||
238
lib/cdda_interface/test_interface.c
Normal file
238
lib/cdda_interface/test_interface.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
$Id: test_interface.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/******************************************************************
|
||||
*
|
||||
* Fake interface backend for testing paranoia layer
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#ifdef CDDA_TEST
|
||||
#include "low_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
/* Build which test model? */
|
||||
#define CDDA_TEST_OK
|
||||
#undef CDDA_TEST_JITTER_SMALL
|
||||
#undef CDDA_TEST_JITTER_LARGE
|
||||
#undef CDDA_TEST_JITTER_MASSIVE
|
||||
#undef CDDA_TEST_FRAG_SMALL
|
||||
#undef CDDA_TEST_FRAG_LARGE
|
||||
#undef CDDA_TEST_FRAG_MASSIVE
|
||||
#undef CDDA_TEST_BOGUS_BYTES
|
||||
#undef CDDA_TEST_DROPDUPE_BYTES
|
||||
#undef CDDA_TEST_SCRATCH
|
||||
#undef CDDA_TEST_UNDERRUN
|
||||
|
||||
#undef CDDA_TEST_ALLJITTER
|
||||
#undef CDDA_TEST_SOMEJITTER
|
||||
#undef CDDA_TEST_SEEKJITTER
|
||||
|
||||
static int test_readtoc (cdrom_drive *d){
|
||||
int tracks=0;
|
||||
long bytes;
|
||||
long sectors;
|
||||
|
||||
/* only one track, as many sectors as the file */
|
||||
|
||||
bytes=lseek(d->cdda_fd,0,SEEK_END);
|
||||
lseek(d->cdda_fd,0,SEEK_SET);
|
||||
sectors=bytes/CDIO_CD_FRAMESIZE_RAW;
|
||||
|
||||
d->disc_toc[0].bFlags = 0;
|
||||
d->disc_toc[0].bTrack = 1;
|
||||
d->disc_toc[0].dwStartSector = 37;
|
||||
|
||||
d->disc_toc[1].bFlags = 0x4;
|
||||
d->disc_toc[1].bTrack = CDROM_LEADOUT;
|
||||
d->disc_toc[1].dwStartSector = sectors+37;
|
||||
|
||||
tracks=2;
|
||||
d->cd_extra=0;
|
||||
return(--tracks); /* without lead-out */
|
||||
}
|
||||
|
||||
/* we emulate jitter, scratches, atomic jitter and bogus bytes on
|
||||
boundaries, etc */
|
||||
|
||||
static long
|
||||
test_read(cdrom_drive *d, void *p, long begin, long sectors)
|
||||
{
|
||||
|
||||
#if defined(CDDA_TEST_SEEKJITTER) \
|
||||
|| defined(CDDA_TEST_ALLJITTER) \
|
||||
|| defined(CDDA_TEST_SOMEJITTER)
|
||||
int jitter_flag=0;
|
||||
#endif
|
||||
|
||||
int los_flag=0;
|
||||
static int jitter=0;
|
||||
int bytes_so_far=0;
|
||||
long bytestotal;
|
||||
static FILE *fd=NULL;
|
||||
static long lastread=0;
|
||||
|
||||
if(!fd)fd=fdopen(d->cdda_fd,"r");
|
||||
|
||||
#ifdef CDDA_TEST_UNDERRUN
|
||||
sectors-=1;
|
||||
#endif
|
||||
|
||||
#ifdef CDDA_TEST_SEEKJITTER
|
||||
if(lastread!=begin)jitter_flag=1;
|
||||
#else
|
||||
#ifdef CDDA_TEST_ALLJITTER
|
||||
jitter_flag=1;
|
||||
#else
|
||||
#ifdef CDDA_TEST_SOMEJITTER
|
||||
jitter_flag=(drand48()>.9?1:0);
|
||||
los_flag=(drand48()>.9?1:0);
|
||||
#else
|
||||
los_flag=1;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lastread=begin+sectors;
|
||||
bytestotal=sectors*CDIO_CD_FRAMESIZE_RAW;
|
||||
|
||||
begin*=CDIO_CD_FRAMESIZE_RAW;
|
||||
|
||||
while(bytes_so_far<bytestotal){
|
||||
int inner_bytes=bytestotal-bytes_so_far;
|
||||
char *inner_buf=(char *)p + bytes_so_far;
|
||||
long seeki;
|
||||
long rbytes;
|
||||
long this_bytes=inner_bytes;
|
||||
|
||||
#ifdef CDDA_TEST_OK
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_JITTER_SMALL
|
||||
if(jitter_flag)jitter=4*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_JITTER_LARGE
|
||||
if(jitter_flag)jitter=32*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_JITTER_MASSIVE
|
||||
if(jitter_flag)jitter=128*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_FRAG_SMALL
|
||||
if(los_flag)this_bytes=256*(int)(drand48()*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
if(jitter_flag)jitter=4*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_FRAG_LARGE
|
||||
if(los_flag)this_bytes=16*(int)(drand48()*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
if(jitter_flag)jitter=4*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_FRAG_MASSIVE
|
||||
if(los_flag)this_bytes=8*(int)(drand48()*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
if(jitter_flag)jitter=32*(int)((drand48()-.5)*CDIO_CD_FRAMESIZE_RAW/8);
|
||||
|
||||
#else
|
||||
#ifdef CDDA_TEST_DROPDUPE_BYTES
|
||||
if(los_flag)this_bytes=CDIO_CD_FRAMESIZE_RAW;
|
||||
if(jitter_flag)
|
||||
if (drand48()>.8)
|
||||
this_jitter=32;
|
||||
else
|
||||
this_jitter=0;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
if(this_bytes>inner_bytes)this_bytes=inner_bytes;
|
||||
if(begin+jitter+bytes_so_far<0)jitter=0;
|
||||
seeki=begin+bytes_so_far+jitter;
|
||||
|
||||
if(fseek(fd,seeki,SEEK_SET)<0){
|
||||
return(0);
|
||||
}
|
||||
rbytes=fread(inner_buf,1,this_bytes,fd);
|
||||
bytes_so_far+=rbytes;
|
||||
if(rbytes==0)break;
|
||||
|
||||
#ifdef CDDA_TEST_SEEKJITTER
|
||||
jitter_flag=0;
|
||||
los_flag=0;
|
||||
#else
|
||||
#ifdef CDDA_TEST_ALLJITTER
|
||||
jitter_flag=1;
|
||||
los_flag=0;
|
||||
#else
|
||||
#ifdef CDDA_TEST_SOMEJITTER
|
||||
jitter_flag=(drand48()>.9?1:0);
|
||||
los_flag=(drand48()>.9?1:0);
|
||||
#else
|
||||
los_flag=1;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifdef CDDA_TEST_SCRATCH
|
||||
{
|
||||
long location=300*CDIO_CD_FRAMESIZE_RAW+(drand48()*56)+512;
|
||||
|
||||
if(begin<=location && begin+bytestotal>location){
|
||||
memset(p+location-begin,(int)(drand48()*256),1100);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return(sectors);
|
||||
}
|
||||
|
||||
/* hook */
|
||||
static int Dummy (cdrom_drive *d,int Switch){
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* set function pointers to use the ioctl routines */
|
||||
int test_init_drive (cdrom_drive *d){
|
||||
|
||||
d->nsectors=13;
|
||||
d->enable_cdda = Dummy;
|
||||
d->read_audio = test_read;
|
||||
d->read_toc = test_readtoc;
|
||||
d->set_speed = Dummy;
|
||||
d->tracks=d->read_toc(d);
|
||||
if(d->tracks==-1)
|
||||
return(d->tracks);
|
||||
d->opened=1;
|
||||
srand48(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
199
lib/cdda_interface/toc.c
Normal file
199
lib/cdda_interface/toc.c
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
$Id: toc.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
derived from code (C) 1994-1996 Heiko Eissfeldt
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/******************************************************************
|
||||
* Table of contents convenience functions
|
||||
******************************************************************/
|
||||
|
||||
#include "low_interface.h"
|
||||
#include "utils.h"
|
||||
|
||||
long
|
||||
cdda_track_firstsector(cdrom_drive_t *d,int track)
|
||||
{
|
||||
if(!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (track == 0) {
|
||||
if (d->disc_toc[0].dwStartSector == 0) {
|
||||
/* first track starts at lba 0 -> no pre-gap */
|
||||
cderror(d,"401: Invalid track number\n");
|
||||
return(-1);
|
||||
}
|
||||
else {
|
||||
return 0; /* pre-gap of first track always starts at lba 0 */
|
||||
}
|
||||
}
|
||||
|
||||
if(track<0 || track>d->tracks){
|
||||
cderror(d,"401: Invalid track number\n");
|
||||
return(-1);
|
||||
}
|
||||
return(d->disc_toc[track-1].dwStartSector);
|
||||
}
|
||||
|
||||
long
|
||||
cdda_disc_firstsector(cdrom_drive_t *d)
|
||||
{
|
||||
int i;
|
||||
if(!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* look for an audio track */
|
||||
for(i=0;i<d->tracks;i++)
|
||||
if(cdda_track_audiop(d,i+1)==1) {
|
||||
if (i == 0) /* disc starts at lba 0 if first track is an audio track */
|
||||
return 0;
|
||||
else
|
||||
return(cdda_track_firstsector(d,i+1));
|
||||
}
|
||||
|
||||
cderror(d,"403: No audio tracks on disc\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
long
|
||||
cdda_track_lastsector(cdrom_drive_t *d,int track)
|
||||
{
|
||||
if(!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (track == 0) {
|
||||
if (d->disc_toc[0].dwStartSector == 0) {
|
||||
/* first track starts at lba 0 -> no pre-gap */
|
||||
cderror(d,"401: Invalid track number\n");
|
||||
return(-1);
|
||||
}
|
||||
else {
|
||||
return d->disc_toc[0].dwStartSector-1;
|
||||
}
|
||||
}
|
||||
|
||||
if(track<1 || track>d->tracks){
|
||||
cderror(d,"401: Invalid track number\n");
|
||||
return(-1);
|
||||
}
|
||||
/* Safe, we've always the leadout at disc_toc[tracks] */
|
||||
return(d->disc_toc[track].dwStartSector-1);
|
||||
}
|
||||
|
||||
long
|
||||
cdda_disc_lastsector(cdrom_drive_t *d)
|
||||
{
|
||||
int i;
|
||||
if(!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* look for an audio track */
|
||||
for(i=d->tracks-1;i>=0;i--)
|
||||
if(cdda_track_audiop(d,i+1)==1)
|
||||
return(cdda_track_lastsector(d,i+1));
|
||||
|
||||
cderror(d,"403: No audio tracks on disc\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
long
|
||||
cdda_tracks(cdrom_drive_t *d)
|
||||
{
|
||||
if(!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-1);
|
||||
}
|
||||
return(d->tracks);
|
||||
}
|
||||
|
||||
int
|
||||
cdda_sector_gettrack(cdrom_drive_t *d,long sector)
|
||||
{
|
||||
if(!d->opened){
|
||||
cderror(d,"400: Device not open\n");
|
||||
return(-1);
|
||||
}else{
|
||||
int i;
|
||||
|
||||
if (sector < d->disc_toc[0].dwStartSector)
|
||||
return 0; /* We're in the pre-gap of first track */
|
||||
|
||||
for(i=0;i<d->tracks;i++){
|
||||
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
|
||||
cdda_track_bitmap(cdrom_drive_t *d,int track,int bit,int set,int clear)
|
||||
{
|
||||
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
|
||||
cdda_track_channels(cdrom_drive_t *d,int track)
|
||||
{
|
||||
return(cdda_track_bitmap(d,track,8,4,2));
|
||||
}
|
||||
|
||||
int
|
||||
cdda_track_audiop(cdrom_drive_t *d,int track)
|
||||
{
|
||||
return(cdda_track_bitmap(d,track,4,0,1));
|
||||
}
|
||||
|
||||
int
|
||||
cdda_track_copyp(cdrom_drive_t *d,int track)
|
||||
{
|
||||
return(cdda_track_bitmap(d,track,2,1,0));
|
||||
}
|
||||
|
||||
int
|
||||
cdda_track_preemp(cdrom_drive_t *d, int track)
|
||||
{
|
||||
return(cdda_track_bitmap(d,track,1,1,0));
|
||||
}
|
||||
|
||||
138
lib/cdda_interface/utils.c
Normal file
138
lib/cdda_interface/utils.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
$Id: utils.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "common_interface.h"
|
||||
#include "utils.h"
|
||||
void
|
||||
cderror(cdrom_drive_t *d,const char *s)
|
||||
{
|
||||
if(s && d){
|
||||
switch(d->errordest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,s,strlen(s));
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
d->errorbuf=catstring(d->errorbuf,s);
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cdmessage(cdrom_drive_t *d, const char *s)
|
||||
{
|
||||
if(s && d){
|
||||
switch(d->messagedest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,s,strlen(s));
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
d->messagebuf=catstring(d->messagebuf,s);
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
idperror(int messagedest,char **messages,const char *f,
|
||||
const char *s)
|
||||
{
|
||||
|
||||
char *buffer;
|
||||
int malloced=0;
|
||||
if(!f)
|
||||
buffer=(char *)s;
|
||||
else
|
||||
if(!s)
|
||||
buffer=(char *)f;
|
||||
else{
|
||||
buffer=malloc(strlen(f)+strlen(s)+9);
|
||||
sprintf(buffer,f,s);
|
||||
malloced=1;
|
||||
}
|
||||
|
||||
if(buffer){
|
||||
switch(messagedest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,buffer,strlen(buffer));
|
||||
if(errno){
|
||||
write(STDERR_FILENO,": ",2);
|
||||
write(STDERR_FILENO,strerror(errno),strlen(strerror(errno)));
|
||||
write(STDERR_FILENO,"\n",1);
|
||||
}
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
if(messages){
|
||||
*messages=catstring(*messages,buffer);
|
||||
if(errno){
|
||||
*messages=catstring(*messages,": ");
|
||||
*messages=catstring(*messages,strerror(errno));
|
||||
*messages=catstring(*messages,"\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if(malloced)free(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
idmessage(int messagedest,char **messages,const char *f,
|
||||
const char *s)
|
||||
{
|
||||
char *buffer;
|
||||
int malloced=0;
|
||||
if(!f)
|
||||
buffer=(char *)s;
|
||||
else
|
||||
if(!s)
|
||||
buffer=(char *)f;
|
||||
else{
|
||||
buffer=malloc(strlen(f)+strlen(s)+10);
|
||||
sprintf(buffer,f,s);
|
||||
strcat(buffer,"\n");
|
||||
malloced=1;
|
||||
}
|
||||
|
||||
if(buffer){
|
||||
switch(messagedest){
|
||||
case CDDA_MESSAGE_PRINTIT:
|
||||
write(STDERR_FILENO,buffer,strlen(buffer));
|
||||
if(!malloced)write(STDERR_FILENO,"\n",1);
|
||||
break;
|
||||
case CDDA_MESSAGE_LOGIT:
|
||||
if(messages){
|
||||
*messages=catstring(*messages,buffer);
|
||||
if(!malloced)*messages=catstring(*messages,"\n");
|
||||
}
|
||||
break;
|
||||
case CDDA_MESSAGE_FORGETIT:
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if(malloced)free(buffer);
|
||||
}
|
||||
133
lib/cdda_interface/utils.h
Normal file
133
lib/cdda_interface/utils.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
$Id: utils.h,v 1.1 2004/12/18 17:29:32 rocky Exp $
|
||||
|
||||
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1998 Monty xiphmont@mit.edu
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <endian.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <cdio/types.h>
|
||||
|
||||
/* I wonder how many alignment issues this is gonna trip in the
|
||||
future... it shouldn't trip any... I guess we'll find out :) */
|
||||
|
||||
static inline int bigendianp(void){
|
||||
int test=1;
|
||||
char *hack=(char *)(&test);
|
||||
if(hack[0])return(0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
static inline int32_t swap32(int32_t x){
|
||||
return((((u_int32_t)x & 0x000000ffU) << 24) |
|
||||
(((u_int32_t)x & 0x0000ff00U) << 8) |
|
||||
(((u_int32_t)x & 0x00ff0000U) >> 8) |
|
||||
(((u_int32_t)x & 0xff000000U) >> 24));
|
||||
}
|
||||
|
||||
static inline int16_t swap16(int16_t x){
|
||||
return((((u_int16_t)x & 0x00ffU) << 8) |
|
||||
(((u_int16_t)x & 0xff00U) >> 8));
|
||||
}
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
|
||||
static inline int32_t be32_to_cpu(int32_t x){
|
||||
return(swap32(x));
|
||||
}
|
||||
|
||||
static inline int16_t be16_to_cpu(int16_t x){
|
||||
return(swap16(x));
|
||||
}
|
||||
|
||||
static inline int32_t le32_to_cpu(int32_t x){
|
||||
return(x);
|
||||
}
|
||||
|
||||
static inline int16_t le16_to_cpu(int16_t x){
|
||||
return(x);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline int32_t be32_to_cpu(int32_t x){
|
||||
return(x);
|
||||
}
|
||||
|
||||
static inline int16_t be16_to_cpu(int16_t x){
|
||||
return(x);
|
||||
}
|
||||
|
||||
static inline int32_t le32_to_cpu(int32_t x){
|
||||
return(swap32(x));
|
||||
}
|
||||
|
||||
static inline int16_t le16_to_cpu(int16_t x){
|
||||
return(swap16(x));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
static inline int32_t cpu_to_be32(int32_t x){
|
||||
return(be32_to_cpu(x));
|
||||
}
|
||||
|
||||
static inline int32_t cpu_to_le32(int32_t x){
|
||||
return(le32_to_cpu(x));
|
||||
}
|
||||
|
||||
static inline int16_t cpu_to_be16(int16_t x){
|
||||
return(be16_to_cpu(x));
|
||||
}
|
||||
|
||||
static inline int16_t cpu_to_le16(int16_t x){
|
||||
return(le16_to_cpu(x));
|
||||
}
|
||||
|
||||
static inline char *copystring(const char *s){
|
||||
if(s){
|
||||
char *ret=malloc((strlen(s)+9)*sizeof(char)); /* +9 to get around a linux
|
||||
libc 5 bug. below too */
|
||||
strcpy(ret,s);
|
||||
return(ret);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
static inline char *catstring(char *buff,const char *s){
|
||||
if(s){
|
||||
if(buff)
|
||||
buff=realloc(buff,strlen(buff)+strlen(s)+9);
|
||||
else
|
||||
buff=calloc(strlen(s)+9,1);
|
||||
strcat(buff,s);
|
||||
}
|
||||
return(buff);
|
||||
}
|
||||
|
||||
void cderror(cdrom_drive_t *d, const char *s);
|
||||
|
||||
void cdmessage(cdrom_drive_t *d,const char *s);
|
||||
|
||||
void idperror(int messagedest,char **messages,const char *f, const char *s);
|
||||
|
||||
void idmessage(int messagedest,char **messages,const char *f, const char *s);
|
||||
|
||||
Reference in New Issue
Block a user