Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Oct 1998 17:19:20 -0600 (MDT)
From:      "Kenneth D. Merry" <ken@plutotech.com>
To:        nathan@rtfm.net (Nathan Dorfman)
Cc:        freebsd-current@FreeBSD.ORG
Subject:   Re: 3.0-R, CAM, and audio tracks (more info)
Message-ID:  <199810192319.RAA26289@panzer.plutotech.com>
In-Reply-To: <19981019185216.B10530@rtfm.net> from Nathan Dorfman at "Oct 19, 98 06:52:17 pm"

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Nathan Dorfman wrote...
> On Mon, Oct 19, 1998 at 12:17:41AM -0600, Kenneth D. Merry wrote:
> > Nathan Dorfman wrote...
> >
> > Your CDROM drive didn't like the command that tosha sent.
> 
> Sounds fishy to me, because it likes the same commands just fine
> when the track isn't an audio track (significantly reducing tosha's
> usefulness, however). However, you're Mr. CAM, so if you say it's
> my drive and not CAM, I guess I'll have to believe you :-)

It's actually tosha's interaction with your drive.  I'm sure that given the
correct commands, it would probably work.

The difference between audio and data tracks is probably the density code
and sector size you have to set before issuing the read command.

> > > Is CAM preventing tosha from reading audio data via passthrough?
> > 
> > Yes.  Justin and I were paid by the RIAA to make sure that FreeBSD users
> > can't copy audio CDs.  The FBI will contact you shortly to discuss whether
> > or not your use of your CDs constitutes "fair use".
> 
> Haha :) that's *not* what I meant. Actually, I want to create a CD,
> for my personal use, that contains my favorite tracks from other
> discs that I own. Is this "fair use"? No one seemed to mind when
> everyone did it with tapes.

Yes, that's fair use.  If you own the CDs in question, I think you can copy
them for your own personal use.

> > It looks like your drive doesn't like it when you try to read audio tracks
> > that way.  You may want to talk to Oliver Fromme about it, and see if he's
> > heard any other bug reports about Yamaha drives not working.  IIRC, Daniel
> > O'Conner had a similar problem with a Yamaha drive.  I think he was able to
> > get it to work with cdda2wav, but he ran into another problem with cdda2wav
> > that looks like a vm problem related to shared memory.
> > 
> > I'm not exactly sure what the problem is, but it's most likely related to
> > tosha's interaction with your drive.
> 
> I e-mailed Oliver and am still waiting for a response. Meanwhile, is there
> any way to force the drive to reset to a sane state without rebooting so I
> can at least use it?

Try replacing tosha/patches/patch-ab with the attached patch.  It should
theoretically re-set the density code and sector size to their original
values before it exits.  I say "theoretically", since tosha works just fine
with my Plextor drives, and therefore doesn't exit abnormally.

Ken
-- 
Kenneth Merry
ken@plutotech.com

[-- Attachment #2 --]
diff -c ../tosha-0.05/Makefile ./Makefile
*** ../tosha-0.05/Makefile	Tue May 20 17:57:17 1997
--- ./Makefile	Mon Jul  6 16:26:50 1998
***************
*** 19,24 ****
--- 19,31 ----
  CFLAGS=-O2 -Wall -ansi
  # CFLAGS=-g -Wall -ansi -pedantic
  
+ .if (exists(/usr/include/camlib.h))
+ CFLAGS+=-DCAM
+ LDFLAGS=-lcam
+ .else
+ LDFLAGS=-lscsi
+ .endif
+ 
  all:	tosha pcmplay pcmfade
  
  utils.o:	utils.c utils.h
***************
*** 28,34 ****
  pcmfade.o:	pcmfade.c utils.h
  
  tosha:	tosha.o utils.o getlopt.o
! 	$(CC) $(CFLAGS) -o tosha -lscsi tosha.o utils.o getlopt.o
  
  pcmplay:	pcmplay.o utils.o getlopt.o
  	$(CC) $(CFLAGS) -o pcmplay pcmplay.o utils.o getlopt.o
--- 35,41 ----
  pcmfade.o:	pcmfade.c utils.h
  
  tosha:	tosha.o utils.o getlopt.o
! 	$(CC) $(CFLAGS) -o tosha $(LDFLAGS) tosha.o utils.o getlopt.o
  
  pcmplay:	pcmplay.o utils.o getlopt.o
  	$(CC) $(CFLAGS) -o pcmplay pcmplay.o utils.o getlopt.o
diff -c ../tosha-0.05/tosha.c ./tosha.c
*** ../tosha-0.05/tosha.c	Tue May 20 18:11:49 1997
--- ./tosha.c	Mon Oct 19 17:10:41 1998
***************
*** 47,55 ****
  #include <fcntl.h>
  #include <sys/types.h>
  #include <sys/uio.h>
- #include <sys/scsiio.h>
  #include <unistd.h>
  #include <scsi.h>
  extern int errno;
  
  /*
--- 47,65 ----
  #include <fcntl.h>
  #include <sys/types.h>
  #include <sys/uio.h>
  #include <unistd.h>
+ #ifdef CAM
+ #include <cam/cam.h>
+ #include <cam/cam_ccb.h>
+ #include <cam/scsi/scsi_all.h>
+ #include <cam/scsi/scsi_da.h>
+ #include <cam/scsi/scsi_pass.h>
+ #include <cam/scsi/scsi_message.h>
+ #include <camlib.h>
+ #else /* !CAM */
+ #include <sys/scsiio.h>
  #include <scsi.h>
+ #endif /* !CAM  */
  extern int errno;
  
  /*
***************
*** 74,79 ****
--- 84,90 ----
   *   wasn't able to find a better solution.
   */
  
+ #ifndef CAM
  #undef SCSIREQ_ERROR
  #define SCSIREQ_ERROR(SR) (\
  0 \
***************
*** 81,86 ****
--- 92,98 ----
  || SR->retsts      	/* SCSI transfer status */ \
  || SR->error       	/* copy of errno */ \
  )
+ #endif
  
  /*
   *   Uncommenting this define will cause a LOT of output.
***************
*** 95,102 ****
--- 107,119 ----
  typedef unsigned char byte;
  typedef unsigned long ulong;
  
+ #ifdef CAM
+ union ccb *ccb;
+ struct cam_device *cam_dev;
+ #else /* !CAM */
  struct scsireq *sreq;	/* SCSI device request structure */
  int scsifd;		/* SCSI device file descriptor */
+ #endif /* !CAM */
  int readcmd = 0x28;	/* read command to use for DA reading */
  int byteswap = FALSE;	/* do we have to swap byte order? */
  
***************
*** 126,131 ****
--- 143,176 ----
  {
  	int result;
  
+ #ifdef CAM
+ 	bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio));
+ 	csio_build(&ccb->csio,
+ 		   /* data_ptr */ (u_int8_t *)buf,
+ 		   /* dxfer_len */ size,
+ 		   /* flags */ flags,
+ 		   /* retry_count */ 1,
+ 		   /* timeout */ 10000,
+ 		   /* cmd_spec */ cmd);
+ 
+ 	if ((result = cam_send_ccb(cam_dev, ccb)) < 0) {
+ 		perror("error sending SCSI command");
+ 		cam_freeccb(ccb);
+ 		cam_close_device(cam_dev);
+ 		exit(1);
+ 	}
+ 	if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+ 		fprintf(stderr, "error returned from SCSI command:\n");
+ 		if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
+ 		     CAM_SCSI_STATUS_ERROR)
+ 			scsi_sense_print(cam_dev, &ccb->csio, stderr);
+ 		else
+ 			fprintf(stderr, "ccb->ccb_h.status == %d\n",
+ 				ccb->ccb_h.status);
+ 
+ 		exit(1);
+ 	}
+ #else /* !CAM */
  	scsireq_reset (sreq);
  	sreq->timeout = 10000;
  	scsireq_build (sreq, size, (char *) buf, flags, cmd);
***************
*** 134,139 ****
--- 179,185 ----
  	if (SCSIREQ_ERROR (sreq))
  #endif
  		scsi_debug (stderr, result, sreq);
+ #endif /* !CAM */
  	return (result);
  }
  
***************
*** 144,150 ****
--- 190,202 ----
  
  void get_density (int *density, int *secsize)
  {
+ #ifdef CAM
+ 	simple_request (12, CAM_DIR_IN |
+ 			    CAM_DEV_QFRZDIS |
+ 			    CAM_PASS_ERR_RECOVER, "1A 0 1 0 C 0");
+ #else /* !CAM */
  	simple_request (12, SCCMD_READ, "1A 0 1 0 C 0");
+ #endif /* !CAM */
  	*density = buf[4];
  	*secsize = buf[10] << 8 | buf[11];
  }
***************
*** 161,167 ****
--- 213,225 ----
  	buf[4] = density;
  	buf[10] = secsize >> 8;
  	buf[11] = secsize & 0xff;
+ #ifdef CAM
+ 	simple_request (12, CAM_DIR_OUT |
+ 			    CAM_DEV_QFRZDIS |
+ 			    CAM_PASS_ERR_RECOVER, "15 10 0 0 C 0");
+ #else /* !CAM */
  	simple_request (12, SCCMD_WRITE, "15 10 0 0 C 0");
+ #endif /* !CAM */
  }
  
  /*
***************
*** 386,391 ****
--- 444,489 ----
  	for (sec = start; sec < endpp; sec += secread) {
  		if ((secread = framesperbuf) > endpp - sec)
  			secread = endpp - sec;
+ 
+ #ifdef CAM
+ 		if (readcmd == 0xd8)
+ 			csio_build(&ccb->csio,
+ 				   /* data_ptr */ (u_int8_t *)buf,
+ 				   /* dxfer_len */ FRAMESIZE * secread,
+ 				   /* flags */ CAM_DIR_IN,
+ 				   /* retries */ 1,
+ 				   /* timeout */ 10000,
+ 				   /* cmd_spec */ "v 0 0 v:i3 0 0 0 v 0 0",
+ 				   readcmd, sec, secread);
+ 		else
+ 			csio_build(&ccb->csio,
+ 				   /* data_ptr */ (u_int8_t *)buf,
+ 				   /* dxfer_len */ FRAMESIZE * secread,
+ 				   /* flags */ CAM_DIR_IN,
+ 				   /* retries */ 1,
+ 				   /* timeout */ 10000,
+ 				   /* cmd_spec */ "v 0 0 v:i3 0 0 v 0",
+ 				   readcmd, sec, secread );
+ 
+ 		if ((result = cam_send_ccb(cam_dev, ccb)) < 0) {
+ 			perror("error sending CD-DA read command");
+ 			return(FALSE);
+ 		}
+ 
+ 		if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+ 			fprintf(stderr, "error returned from CD-DA"
+ 				" read command:\n");
+ 			if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
+ 			     CAM_SCSI_STATUS_ERROR)
+ 				scsi_sense_print(cam_dev, &ccb->csio, stderr);
+ 			else
+ 				fprintf(stderr, "ccb->ccb_h.status == %d\n",
+ 					ccb->ccb_h.status);
+ 
+ 			return(FALSE);
+ 		}
+ #else /* !CAM */
+ 
  		scsireq_reset (sreq);
  		sreq->timeout = 10000;
  		if (readcmd == 0xd8)
***************
*** 403,408 ****
--- 501,507 ----
  		if (SCSIREQ_ERROR (sreq))
  #endif
  			scsi_debug (stderr, result, sreq);
+ #endif /* !CAM */
  		if (byteswap) {
  			int j, num = FRAMESIZE * secread;
  			byte t;
***************
*** 460,465 ****
--- 559,565 ----
  	char *vendor, *product, *versid;
  	char *ofname;	/* output file name */
  	int density, sectorsize;
+ 	int exit_val = 0;
  	int index;
  	int singlefile = FALSE;
  	int modechange = TRUE, denschange = 0;
***************
*** 497,514 ****
  	 *   Open SCSI device and initialize SCSI request structure.
  	 */
  
  	if ((scsifd = scsi_open(device, O_RDWR)) == -1)
  		die (device);
  	if (!(sreq = scsireq_new())) {
  		fprintf (stderr, "%s: scsireq_new(): Out of memory.\n", me);
  		exit (1);
  	}
! 
  	/*
  	 *   Get vendor & product IDs.
  	 */
  
  	simple_request (64, SCCMD_READ, "12 0 0 0 40 0");
  	vendor = justify(strndup((char *) buf+8, 8));
  	product = justify(strndup((char *) buf+16, 16));
  	versid = justify(strndup((char *) buf+32, 4));
--- 597,630 ----
  	 *   Open SCSI device and initialize SCSI request structure.
  	 */
  
+ #ifdef CAM
+ 	if ((cam_dev = cam_open_device(device, O_RDWR)) == NULL) {
+ 		fprintf(stderr, "%s: %s\n", me, cam_errbuf);
+ 		exit(1);
+ 	}
+ 	if ((ccb = cam_getccb(cam_dev)) == NULL) {
+ 		fprintf(stderr, "%s: couldn't allocate CCB\n", me);
+ 		exit(1);
+ 	}
+ #else /* !CAM */
  	if ((scsifd = scsi_open(device, O_RDWR)) == -1)
  		die (device);
  	if (!(sreq = scsireq_new())) {
  		fprintf (stderr, "%s: scsireq_new(): Out of memory.\n", me);
  		exit (1);
  	}
! #endif /* !CAM */
  	/*
  	 *   Get vendor & product IDs.
  	 */
  
+ #ifdef CAM
+ 	simple_request(64, CAM_DIR_IN |
+ 			   CAM_DEV_QFRZDIS |
+ 			   CAM_PASS_ERR_RECOVER, "12 0 0 0 40 0");
+ #else /* !CAM */
  	simple_request (64, SCCMD_READ, "12 0 0 0 40 0");
+ #endif /* !CAM */
  	vendor = justify(strndup((char *) buf+8, 8));
  	product = justify(strndup((char *) buf+16, 16));
  	versid = justify(strndup((char *) buf+32, 4));
***************
*** 571,577 ****
--- 687,700 ----
  	 *   Get table of contents.
  	 */
  
+ #ifdef CAM
+ 	if (simple_request (2048, CAM_DIR_IN |
+ 				  CAM_DEV_QFRZDIS |
+ 				  CAM_PASS_ERR_RECOVER,
+ 			    "43 0 0 0 0 0 1 8 0 0")) {
+ #else /* !CAM */
  	if (simple_request (2048, SCCMD_READ, "43 0 0 0 0 0 1 8 0 0")) {
+ #endif /* !CAM */
  		fprintf (stderr, "%s: Can't read table of contents.\n", me);
  		exit (1);
  	}
***************
*** 631,638 ****
  			print_trackinfo (-1, 1, startsec, endsec);
  			fprintf (stderr, "  Reading ...\r");
  		}
! 		if (!indexonly)
! 			readsectors (startsec, endsec, pcmfd);
  	}
  	else {
  		for (index = 0; index < tracklistsize; index++) {
--- 754,765 ----
  			print_trackinfo (-1, 1, startsec, endsec);
  			fprintf (stderr, "  Reading ...\r");
  		}
! 		if (!indexonly) {
! 			if (readsectors(startsec, endsec, pcmfd) == FALSE) {
! 				exit_val = 1;
! 				goto error_exit;
! 			}
! 		}
  	}
  	else {
  		for (index = 0; index < tracklistsize; index++) {
***************
*** 657,663 ****
  						O_TRUNC, 0644)) < 0)
  					die ("open(output file)");
  			}
! 			readsectors (trackstart[i], trackstart[i + 1], pcmfd);
  			if (!singlefile)
  				close (pcmfd);
  		}
--- 784,794 ----
  						O_TRUNC, 0644)) < 0)
  					die ("open(output file)");
  			}
! 			if (readsectors(trackstart[i],
! 					trackstart[i + 1], pcmfd) == FALSE) {
! 				exit_val = FALSE;
! 				goto error_exit;
! 			}
  			if (!singlefile)
  				close (pcmfd);
  		}
***************
*** 687,697 ****
  	/*
  	 *   Set original density code and sector size.
  	 */
  
  	set_density (density, sectorsize);
  
  	close (scsifd);
! 	exit (0);
  }
  
  /* EOF */
--- 818,835 ----
  	/*
  	 *   Set original density code and sector size.
  	 */
+ error_exit:
  
  	set_density (density, sectorsize);
  
+ #ifdef CAM 
+ 	cam_freeccb(ccb);
+ 
+ 	cam_close_device(cam_dev);
+ #else /* !CAM */
  	close (scsifd);
! #endif /* !CAM */
! 	exit (exit_val);
  }
  
  /* EOF */

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810192319.RAA26289>