[xiph-commits] r15174 - in trunk/cdparanoia: . interface

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Aug 12 03:58:45 PDT 2008


Author: xiphmont
Date: 2008-08-12 03:58:44 -0700 (Tue, 12 Aug 2008)
New Revision: 15174

Modified:
   trunk/cdparanoia/interface/cdda_interface.h
   trunk/cdparanoia/interface/common_interface.c
   trunk/cdparanoia/interface/cooked_interface.c
   trunk/cdparanoia/interface/interface.c
   trunk/cdparanoia/interface/low_interface.h
   trunk/cdparanoia/interface/scan_devices.c
   trunk/cdparanoia/interface/scsi_interface.c
   trunk/cdparanoia/interface/test_interface.c
   trunk/cdparanoia/main.c
   trunk/cdparanoia/version.h
Log:
Work in progress.  This is not intended to be used, new code is 
spitting out diagnostics.



Modified: trunk/cdparanoia/interface/cdda_interface.h
===================================================================
--- trunk/cdparanoia/interface/cdda_interface.h	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/cdda_interface.h	2008-08-12 10:58:44 UTC (rev 15174)
@@ -42,6 +42,8 @@
 
 /* cdrom access function pointer */
 
+typedef struct cdda_private_data cdda_private_data_t;
+
 typedef struct cdrom_drive{
 
   int opened; /* This struct may just represent a candidate for opening */
@@ -82,14 +84,8 @@
   int is_atapi;
   int is_mmc;
 
-  /* SCSI command buffer and offset pointers */
-  /* this should have been private hidden data, but it isn't.  At
-     this point, sg and sg_buffer are treated internally as void *
-     pointing to internal private data, which is correct even if it is
-     semantically confusing.  This problem will be corrected in the
-     next major release increment. */
-  unsigned char *sg;
-  unsigned char *sg_buffer;
+  cdda_private_data_t *private;
+  void         *reserved;
   unsigned char inqbytes[4];
 
   /* Scsi parameters and state */
@@ -125,6 +121,7 @@
 
 /******** Drive oriented functions */
 
+extern int cdda_cache_sectors(cdrom_drive *d);
 extern int cdda_speed_set(cdrom_drive *d, int speed);
 extern void cdda_verbose_set(cdrom_drive *d,int err_action, int mes_action);
 extern char *cdda_messages(cdrom_drive *d);

Modified: trunk/cdparanoia/interface/common_interface.c
===================================================================
--- trunk/cdparanoia/interface/common_interface.c	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/common_interface.c	2008-08-12 10:58:44 UTC (rev 15174)
@@ -168,10 +168,122 @@
   }
 }
 
+/* we can ask most drives what their various caches' sizes are, but no
+   drive will tell if it caches redbook data.  None should, many do,
+   and there's no way in (eg) MMAC/ATAPI to tell a drive not to.  SCSI
+   drives have a FUA facility, but it's not clear how many ignore it.
+   For that reason, we need to empirically determine cache size used
+   for reads */
+
+int cdda_cache_sectors(cdrom_drive *d){
+  /* let's assume the (physically) fastest drives are 100x.  Although
+     the physical disc itself can't spin at faster than 50x or so,
+     many drives use multiple read heads and interleave access. */
+  float ms_per_sector = 1./75./100.;
+  int i;
+  int lo = 75;
+  int current = lo;
+  int max = 75*256;
+  int firstsector=-1;
+  int lastsector=-1;
+  int firsttest=-1;
+  int lasttest=-1;
+  int under=1;
+
+  cdmessage(d,"\nChecking CDROM drive cache behavior...\n");
+
+
+  /* find the longest stretch of available audio data */
+
+  for(i=0;i<d->tracks;i++){
+    if(cdda_track_audiop(d,i+1)==1){
+      if(firsttest == -1)
+	firsttest=cdda_track_firstsector(d,i+1);
+      lasttest=cdda_track_lastsector(d,i+1);
+      if(lasttest-firsttest > lastsector-firstsector){
+	firstsector=firsttest;
+	lastsector=lasttest;
+      }
+    }else{
+      firsttest=-1;
+      lasttest=-1;
+    }
+  }
+
+  if(firstsector==-1){
+    cdmessage(d,"\n\tNo audio on disc; Cannot determine audio caching behavior.\n");
+    return -1;
+  }
+
+  while(current <= max && under){
+    int offset = (lastsector - firstsector - current)/2; 
+    int i,j;
+    under=0;
+
+    {
+      char buffer[80];
+      snprintf(buffer,80,"\tTesting reads for caching (%d sectors):\n\t",current);
+      cdmessage(d,buffer);
+    }
+
+    for(i=0;i<10;i++){
+      int sofar=0;
+      int fulltime=0;
+      
+      while(sofar<current){
+	for(j=0;;j++){
+	  
+	  int readsectors = d->read_audio(d,NULL,offset+sofar,current-sofar);
+	  if(readsectors<=0){
+	    if(j==2){
+	      d->enable_cdda(d,0);
+	      cdmessage(d,"\n\tRead error while performing drive cache checks; aborting test.\n");
+	      return(-1);
+	    }
+	  }else{
+	    sofar+=readsectors;
+	    if(d->private->last_milliseconds==-1){
+	      if(j==2){
+		d->enable_cdda(d,0);
+		cdmessage(d,"\n\tTiming error while performing drive cache checks; aborting test.\n");
+		return(-1);
+	      }
+	    }else{
+	      fulltime += d->private->last_milliseconds;
+	      break;
+	    }
+	  }
+	}
+      }
+      {
+	char buffer[80];
+	snprintf(buffer,80," %d:%fms/sec",i,(float)fulltime/current);
+	cdmessage(d,buffer);
+      }
+      if(fulltime/current < ms_per_sector) under=1;
+    }
+    cdmessage(d,"\n");
+
+    current*=2;
+  } 
+#if 0
+  if(current > max){
+    cdmessage(d,"\nGiving up; drive cache is too large to defeat using overflow.\n");
+    cdmessage(d,"\n(Drives should not cache redbook reads, this drive does anyway."
+	        "\n Worse, the cache is too large to have any hope of defeating."
+	        "\n Cdparanoia has no chance of catching errors from this drive.\n");
+
+    return INT_MAX;
+  }
+
+#endif
+  return 0;
+}
+
 /************************************************************************/
 /* 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. */
+   knows the leadout/leadin size. */
 
 int FixupTOC(cdrom_drive *d,int tracks){
   struct cdrom_multisession ms_str;

Modified: trunk/cdparanoia/interface/cooked_interface.c
===================================================================
--- trunk/cdparanoia/interface/cooked_interface.c	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/cooked_interface.c	2008-08-12 10:58:44 UTC (rev 15174)
@@ -10,6 +10,19 @@
 #include "common_interface.h"
 #include "utils.h"
 
+static int timed_ioctl(cdrom_drive *d, int fd, int command, void *arg){
+  struct timeval tv1;
+  struct timeval tv2;
+  int ret1=gettimeofday(&tv1,NULL);
+  int ret2=ioctl(fd, command,arg);
+  int ret3=gettimeofday(&tv2,NULL);
+  if(ret1<0 || ret3<0){
+    d->private->last_milliseconds=-1;
+  }else{
+    d->private->last_milliseconds = (tv2.tv_sec-tv1.tv_sec)*1000 + (tv2.tv_usec-tv1.tv_usec)/1000;
+  }
+}
+
 static int cooked_readtoc (cdrom_drive *d){
   int i;
   int tracks;
@@ -72,12 +85,13 @@
  */
 
 static long cooked_read (cdrom_drive *d, void *p, long begin, long sectors){
-  int retry_count,err;
+  int retry_count,err,ret=0;
   struct cdrom_read_audio arg;
   char *buffer=(char *)p;
 
   /* read d->nsectors at a time, max. */
   sectors=(sectors>d->nsectors?d->nsectors:sectors);
+  if(p==NULL)buffer = malloc(sectors*CD_FRAMESIZE_RAW);
 
   arg.addr.lba = begin;
   arg.addr_format = CDROM_LBA;
@@ -87,14 +101,18 @@
 
   do {
     if((err=ioctl(d->ioctl_fd, CDROMREADAUDIO, &arg))){
-      if(!d->error_retry)return(-7);
+      if(!d->error_retry){
+	ret=-7;
+	goto done;
+      }
       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);  
+	  ret=-300;
+	  goto done;
 	}
       default:
 	if(sectors==1){
@@ -108,8 +126,8 @@
 	    sprintf(b,"010: Unable to access sector %ld: skipping...\n",
 		    begin);
 	    cderror(d,b);
-	    return(-10);
-	    
+	    ret=-10;
+	    goto done;
 	  }
 	  break;
 	}
@@ -120,13 +138,18 @@
       retry_count++;
       if(retry_count>MAX_RETRIES){
 	cderror(d,"007: Unknown, unrecoverable error reading data\n");
-	return(-7);
+	ret=-7;
+	goto done;
       }
     }else
       break;
   } while (err);
   
-  return(sectors);
+  ret=sectors;
+
+ done:
+  if(p==NULL && buffer)free(buffer);
+  return ret;
 }
 
 /* hook */

Modified: trunk/cdparanoia/interface/interface.c
===================================================================
--- trunk/cdparanoia/interface/interface.c	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/interface.c	2008-08-12 10:58:44 UTC (rev 15174)
@@ -34,8 +34,11 @@
     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);
-    
+    if(d->private){
+      if(d->private->sg_hd)free(d->private->sg_hd);
+      free(d->private);
+    }
+
     free(d);
   }
   return(0);
@@ -72,7 +75,7 @@
   
   /* Some drives happily return a TOC even if there is no disc... */
   {
-    int i;
+     int i;
     for(i=0;i<d->tracks;i++)
       if(d->disc_toc[i].dwStartSector<0 ||
 	 d->disc_toc[i+1].dwStartSector==0){

Modified: trunk/cdparanoia/interface/low_interface.h
===================================================================
--- trunk/cdparanoia/interface/low_interface.h	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/low_interface.h	2008-08-12 10:58:44 UTC (rev 15174)
@@ -96,6 +96,13 @@
 
 #endif
 
+struct cdda_private_data {
+  struct sg_header *sg_hd;
+  unsigned char *sg_buffer; /* points into sg_hd */
+
+  int last_milliseconds;
+};
+
 #define MAX_RETRIES 8
 #define MAX_BIG_BUFF_SIZE 65536
 #define MIN_BIG_BUFF_SIZE 4096

Modified: trunk/cdparanoia/interface/scan_devices.c
===================================================================
--- trunk/cdparanoia/interface/scan_devices.c	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/scan_devices.c	2008-08-12 10:58:44 UTC (rev 15174)
@@ -263,6 +263,7 @@
   d->interface=COOKED_IOCTL;
   d->bigendianp=-1; /* We don't know yet... */
   d->nsectors=-1;
+  d->private=calloc(1,sizeof(*d->private));
   idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description);
   
   return(d);
@@ -668,10 +669,10 @@
   d->bigendianp=-1; /* We don't know yet... */
   d->nsectors=-1;
   d->messagedest = messagedest;
-
+  d->private=calloc(1,sizeof(*d->private));
   if(use_sgio){
     d->interface=SGIO_SCSI;
-    d->sg_buffer=d->sg=malloc(MAX_BIG_BUFF_SIZE);
+    d->private->sg_buffer=(unsigned char *)(d->private->sg_hd=malloc(MAX_BIG_BUFF_SIZE));
     g_fd=d->cdda_fd=dup(d->ioctl_fd);
   }else{
     version=verify_SG_version(d,messagedest,messages);
@@ -685,8 +686,8 @@
     }
 
     /* malloc our big buffer for scsi commands */
-    d->sg=malloc(MAX_BIG_BUFF_SIZE);
-    d->sg_buffer=d->sg+SG_OFF;
+    d->private->sg_hd=malloc(MAX_BIG_BUFF_SIZE);
+    d->private->sg_buffer=((unsigned char *)d->private->sg_hd)+SG_OFF;
   }
 
   {
@@ -763,7 +764,10 @@
   if(i_fd!=-1)close(i_fd);
   if(g_fd!=-1)close(g_fd);
   if(d){
-    if(d->sg)free(d->sg);
+    if(d->private){
+      if(d->private->sg_hd)free(d->private->sg_hd);
+      free(d->private);
+    }
     free(d);
   }
   return(NULL);
@@ -809,6 +813,7 @@
   d->interface=TEST_INTERFACE;
   d->bigendianp=-1; /* We don't know yet... */
   d->nsectors=-1;
+  d->private=calloc(1,sizeof(*d->private));
   d->drive_model=copystring("File based test interface");
   idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",d->drive_model);
   

Modified: trunk/cdparanoia/interface/scsi_interface.c
===================================================================
--- trunk/cdparanoia/interface/scsi_interface.c	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/scsi_interface.c	2008-08-12 10:58:44 UTC (rev 15174)
@@ -76,7 +76,7 @@
 static void clear_garbage(cdrom_drive *d){
   fd_set fdset;
   struct timeval tv;
-  struct sg_header *sg_hd=(struct sg_header *)d->sg;
+  struct sg_header *sg_hd=d->private->sg_hd;
   int flag=0;
 
   /* clear out any possibly preexisting garbage */
@@ -158,9 +158,11 @@
 			       unsigned char bytefill,
 			       int bytecheck,
 			       unsigned char *sense_buffer){
-  
+  struct timeval tv1;
+  struct timeval tv2;
+  int tret1,tret2;
   int status = 0;
-  struct sg_header *sg_hd=(struct sg_header *)d->sg;
+  struct sg_header *sg_hd=d->private->sg_hd;
   long writebytes=SG_OFF+cmd_len+in_size;
 
   /* generic scsi device services */
@@ -170,7 +172,7 @@
 
   memset(sg_hd,0,sizeof(sg_hd)); 
   memset(sense_buffer,0,SG_MAX_SENSE); 
-  memcpy(d->sg_buffer,cmd,cmd_len);
+  memcpy(d->private->sg_buffer,cmd,cmd_len);
   sg_hd->twelve_byte = cmd_len == 12;
   sg_hd->result = 0;
   sg_hd->reply_len = SG_OFF + out_size;
@@ -184,7 +186,7 @@
      tell if the command failed.  Scared yet? */
 
   if(bytecheck && out_size>in_size){
-    memset(d->sg_buffer+cmd_len+in_size,bytefill,out_size-in_size); 
+    memset(d->private->sg_buffer+cmd_len+in_size,bytefill,out_size-in_size); 
     /* the size does not remove cmd_len due to the way the kernel
        driver copies buffers */
     writebytes+=(out_size-in_size);
@@ -192,8 +194,8 @@
 
   {
     /* Select on write with a 5 second timeout.  This is a hack until
-       a better error reporting layer is in place in alpha 10; right
-       now, always print a message. */
+       a better error reporting layer is in place; right now, always
+       print a message. */
 
     fd_set fdset;
     struct timeval tv;
@@ -218,6 +220,7 @@
   }
 
   sigprocmask (SIG_BLOCK, &(d->sigset), NULL );
+  tret1=gettimeofday(&tv1,NULL);  
   errno=0;
   status = write(d->cdda_fd, sg_hd, writebytes );
 
@@ -226,11 +229,12 @@
     if(errno==0)errno=EIO;
     return(TR_EWRITE);
   }
+
   
   {
     /* Select on read (and write; this signals an error) with a 5
        second timeout.  This is a hack until a better error reporting
-       layer is in place in alpha 10; right now, always print a
+       layer is in place; right now, always print a
        message. */
 
     fd_set rset;
@@ -262,6 +266,7 @@
     }
   }
 
+  tret2=gettimeofday(&tv2,NULL);  
   errno=0;
   status = read(d->cdda_fd, sg_hd, SG_OFF + out_size);
   sigprocmask ( SIG_UNBLOCK, &(d->sigset), NULL );
@@ -285,7 +290,7 @@
   if(bytecheck && in_size+cmd_len<out_size){
     long i,flag=0;
     for(i=in_size;i<out_size;i++)
-      if(d->sg_buffer[i]!=bytefill){
+      if(d->private->sg_buffer[i]!=bytefill){
 	flag=1;
 	break;
       }
@@ -297,6 +302,11 @@
   }
 
   errno=0;
+  if(tret1<0 || tret2<0){
+    d->private->last_milliseconds=-1;
+  }else{
+    d->private->last_milliseconds = (tv2.tv_sec-tv1.tv_sec)*1000 + (tv2.tv_usec-tv1.tv_usec)/1000;
+  }
   return(0);
 }
 
@@ -321,7 +331,7 @@
   hdr.mx_sb_len = SG_MAX_SENSE;
   hdr.timeout = 50000;
   hdr.interface_id = 'S';
-  hdr.dxferp =  d->sg_buffer;
+  hdr.dxferp =  d->private->sg_buffer;
   hdr.flags = SG_FLAG_DIRECT_IO;  /* direct IO if we can get it */
 
   /* scary buffer fill hack */
@@ -363,7 +373,7 @@
   if(bytecheck && in_size<out_size){
     long i,flag=0;
     for(i=in_size;i<out_size;i++)
-      if(d->sg_buffer[i]!=bytefill){
+      if(d->private->sg_buffer[i]!=bytefill){
 	flag=1;
 	break;
       }
@@ -374,6 +384,7 @@
     }
   }
   
+  d->private->last_milliseconds = hdr.duration;
   errno = 0;
   return 0;
 }
@@ -405,9 +416,9 @@
 
   handle_scsi_cmd(d, cmd, 6, 0, 56, 0,0, sense);
 
-  key = d->sg_buffer[2] & 0xf;
-  ASC = d->sg_buffer[12];
-  ASCQ = d->sg_buffer[13];
+  key = d->private->sg_buffer[2] & 0xf;
+  ASC = d->private->sg_buffer[12];
+  ASCQ = d->private->sg_buffer[13];
   
   if(key == 2 && ASC == 4 && ASCQ == 1) return 0;
   return 1;
@@ -452,7 +463,7 @@
   if (handle_scsi_cmd (d, cmd, 10, 0, size+4,'\377',1,sense)) return(1);
 
   {
-    unsigned char *b=d->sg_buffer;
+    unsigned char *b=d->private->sg_buffer;
     if(b[0])return(1); /* Handles only up to 256 bytes */
     if(b[6])return(1); /* Handles only up to 256 bytes */
 
@@ -563,8 +574,8 @@
 static unsigned int get_orig_sectorsize(cdrom_drive *d){
   if(mode_sense(d,12,0x01))return(-1);
 
-  d->orgdens = d->sg_buffer[4];
-  return(d->orgsize = ((int)(d->sg_buffer[10])<<8)+d->sg_buffer[11]);
+  d->orgdens = d->private->sg_buffer[4];
+  return(d->orgsize = ((int)(d->private->sg_buffer[10])<<8)+d->private->sg_buffer[11]);
 }
 
 /* switch CDROM scsi drives to given sector size  */
@@ -623,8 +634,8 @@
     return(-4);
   }
 
-  first=d->sg_buffer[2];
-  last=d->sg_buffer[3];
+  first=d->private->sg_buffer[2];
+  last=d->private->sg_buffer[3];
   tracks=last-first+1;
 
   if (last > MAXTRK || first > MAXTRK || last<0 || first<0) {
@@ -642,7 +653,7 @@
       return(-5);
     }
     {
-      scsi_TOC *toc=(scsi_TOC *)(d->sg_buffer+4);
+      scsi_TOC *toc=(scsi_TOC *)(d->private->sg_buffer+4);
 
       d->disc_toc[i-first].bFlags=toc->bFlags;
       d->disc_toc[i-first].bTrack=i;
@@ -663,7 +674,7 @@
     return(-2);
   }
   {
-    scsi_TOC *toc=(scsi_TOC *)(d->sg_buffer+4);
+    scsi_TOC *toc=(scsi_TOC *)(d->private->sg_buffer+4);
     
     d->disc_toc[i-first].bFlags=toc->bFlags;
     d->disc_toc[i-first].bTrack=0xAA;
@@ -697,7 +708,7 @@
   }
 
   /* copy to our structure and convert start sector */
-  tracks = d->sg_buffer[1];
+  tracks = d->private->sg_buffer[1];
   if (tracks > MAXTRK) {
     cderror(d,"003: CDROM reporting illegal number of tracks\n");
     return(-3);
@@ -713,33 +724,33 @@
       return(-5);
     }
     
-    d->disc_toc[i].bFlags = d->sg_buffer[10];
+    d->disc_toc[i].bFlags = d->private->sg_buffer[10];
     d->disc_toc[i].bTrack = i + 1;
 
     d->disc_toc[i].dwStartSector= d->adjust_ssize * 
-	(((signed char)(d->sg_buffer[2])<<24) | 
-	 (d->sg_buffer[3]<<16)|
-	 (d->sg_buffer[4]<<8)|
-	 (d->sg_buffer[5]));
+	(((signed char)(d->private->sg_buffer[2])<<24) | 
+	 (d->private->sg_buffer[3]<<16)|
+	 (d->private->sg_buffer[4]<<8)|
+	 (d->private->sg_buffer[5]));
   }
 
   d->disc_toc[i].bFlags = 0;
   d->disc_toc[i].bTrack = i + 1;
-  memcpy (&foo, d->sg_buffer+2, 4);
-  memcpy (&bar, d->sg_buffer+6, 4);
+  memcpy (&foo, d->private->sg_buffer+2, 4);
+  memcpy (&bar, d->private->sg_buffer+6, 4);
   d->disc_toc[i].dwStartSector = d->adjust_ssize * (be32_to_cpu(foo) +
 						    be32_to_cpu(bar));
 
   d->disc_toc[i].dwStartSector= d->adjust_ssize * 
-    ((((signed char)(d->sg_buffer[2])<<24) | 
-      (d->sg_buffer[3]<<16)|
-      (d->sg_buffer[4]<<8)|
-      (d->sg_buffer[5]))+
+    ((((signed char)(d->private->sg_buffer[2])<<24) | 
+      (d->private->sg_buffer[3]<<16)|
+      (d->private->sg_buffer[4]<<8)|
+      (d->private->sg_buffer[5]))+
      
-     ((((signed char)(d->sg_buffer[6])<<24) | 
-       (d->sg_buffer[7]<<16)|
-       (d->sg_buffer[8]<<8)|
-       (d->sg_buffer[9]))));
+     ((((signed char)(d->private->sg_buffer[6])<<24) | 
+       (d->private->sg_buffer[7]<<16)|
+       (d->private->sg_buffer[8]<<8)|
+       (d->private->sg_buffer[9]))));
 
 
   d->cd_extra = FixupTOC(d,tracks+1);
@@ -763,7 +774,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,10,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -782,7 +793,7 @@
   cmd[9] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -800,7 +811,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,10,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -818,7 +829,7 @@
   cmd[9] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -836,7 +847,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,10,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -854,7 +865,7 @@
   cmd[9] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -868,7 +879,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -882,7 +893,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -896,7 +907,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -910,7 +921,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -924,7 +935,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -938,7 +949,7 @@
   cmd[8] = sectors;
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -972,7 +983,7 @@
 
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -985,7 +996,7 @@
 
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -998,7 +1009,7 @@
   
   if((ret=handle_scsi_cmd(d,cmd,12,0,sectors * CD_FRAMESIZE_RAW,'\177',1,sense)))
     return(ret);
-  if(p)memcpy(p,d->sg_buffer,sectors*CD_FRAMESIZE_RAW);
+  if(p)memcpy(p,d->private->sg_buffer,sectors*CD_FRAMESIZE_RAW);
   return(0);
 }
 
@@ -1214,7 +1225,7 @@
 static int count_2352_bytes(cdrom_drive *d){
   long i;
   for(i=2351;i>=0;i--)
-    if(d->sg_buffer[i]!=(unsigned char)'\177')
+    if(d->private->sg_buffer[i]!=(unsigned char)'\177')
       return(((i+3)>>2)<<2);
 
   return(0);
@@ -1223,7 +1234,7 @@
 static int verify_nonzero(cdrom_drive *d){
   long i,flag=0;
   for(i=0;i<2352;i++)
-    if(d->sg_buffer[i]!=0){
+    if(d->private->sg_buffer[i]!=0){
       flag=1;
       break;
     }
@@ -1565,7 +1576,7 @@
   d->is_mmc=0;
   if(mode_sense(d,22,0x2A)==0){
   
-    b=d->sg_buffer;
+    b=d->private->sg_buffer;
     b+=b[3]+4;
     
     if((b[0]&0x3F)==0x2A){
@@ -1613,7 +1624,7 @@
     cderror(d,"008: Unable to identify CDROM model\n");
     return(NULL);
   }
-  return (d->sg_buffer);
+  return (d->private->sg_buffer);
 }
 
 
@@ -1684,8 +1695,8 @@
   check_fua_bit(d);
 
   d->error_retry=1;
-  d->sg=realloc(d->sg,d->nsectors*CD_FRAMESIZE_RAW + SG_OFF + 128);
-  d->sg_buffer=d->sg+SG_OFF;
+  d->private->sg_hd=realloc(d->private->sg_hd,d->nsectors*CD_FRAMESIZE_RAW + SG_OFF + 128);
+  d->private->sg_buffer=((unsigned char *)d->private->sg_hd)+SG_OFF;
   d->report_all=1;
   return(0);
 }

Modified: trunk/cdparanoia/interface/test_interface.c
===================================================================
--- trunk/cdparanoia/interface/test_interface.c	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/interface/test_interface.c	2008-08-12 10:58:44 UTC (rev 15174)
@@ -91,7 +91,7 @@
 
   while(bytes_so_far<bytestotal){
     int inner_bytes=bytestotal-bytes_so_far;
-    char *inner_buf=p+bytes_so_far;
+    char *inner_buf=(p ? p+bytes_so_far : NULL);
     long seeki;
     long rbytes;
     long this_bytes=inner_bytes;
@@ -151,7 +151,15 @@
     if(fseek(fd,seeki,SEEK_SET)<0){
       return(0);
     }
-    rbytes=fread(inner_buf,1,this_bytes,fd);
+    if(!inner_buf){
+      char *temp = malloc(this_bytes);
+      rbytes=fread(temp,1,this_bytes,fd);
+      free(temp);
+    }else
+      rbytes=fread(inner_buf,1,this_bytes,fd);
+
+    d->private->last_milliseconds=this_bytes/2352./75./20.*1000.;
+
     bytes_so_far+=rbytes;
     if(rbytes==0)break;
 
@@ -179,7 +187,7 @@
     long location=300*CD_FRAMESIZE_RAW+(drand48()*56)+512;
 
     if(begin<=location && begin+bytestotal>location){
-      memset(p+location-begin,(int)(drand48()*256),1100);
+      if(p)memset(p+location-begin,(int)(drand48()*256),1100);
     }
   }
 #endif

Modified: trunk/cdparanoia/main.c
===================================================================
--- trunk/cdparanoia/main.c	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/main.c	2008-08-12 10:58:44 UTC (rev 15174)
@@ -928,6 +928,9 @@
     exit(1);
   }
 
+  /* Determine drive caching behavior */
+  cdda_cache_sectors(d);
+
   /* Dump the TOC */
   if(query_only || verbose)display_toc(d);
   if(query_only)exit(0);

Modified: trunk/cdparanoia/version.h
===================================================================
--- trunk/cdparanoia/version.h	2008-08-09 01:49:31 UTC (rev 15173)
+++ trunk/cdparanoia/version.h	2008-08-12 10:58:44 UTC (rev 15174)
@@ -1,10 +1,10 @@
 /******************************************************************
  * CopyPolicy: GNU Public License 2 applies
  * 
- * cdda_paranoia generation III release 10.1
+ * cdda_paranoia generation III release 10.2pre
  * Copyright (C) 2008 Monty monty at xiph.org
  *
  ******************************************************************/
 
 
-#define VERSION "cdparanoia III release 10.1 (August 6, 2008)\n"
+#define VERSION "cdparanoia III release 10.2pre (August 11, 2008)\n"



More information about the commits mailing list