home *** CD-ROM | disk | FTP | other *** search
/ ftp.cdrom.com/pub/cdrom/ / cdrom.tar / cdrom / sun_toshiba / rcb.c < prev    next >
C/C++ Source or Header  |  1993-07-05  |  2KB  |  89 lines

  1. /* rcb.c  --  Read CD-DA Blocks.
  2.  *
  3.  * Send a raw SCSI message via the USCSI facility of the CDROM device driver
  4.  * to read raw (CD-DA audio) frames from a Toshiba XM3401xx drive. Print the
  5.  * binary samples to the standard output. If you want to read CD-DA frames,
  6.  * the drive should be in density 0x82 mode (e.g. via the set_raw program).
  7.  * Note: SunOS can't handle large SCSI transfers, so limit the number of
  8.  * frames you want to read (or do it in a loop).
  9.  *
  10.  * Author: Adrie Koolen (adrie@ica.philips.nl)
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <sys/types.h>
  15. #include <scsi/scsi_types.h>
  16. #include <scsi/impl/uscsi.h>
  17.  
  18. u_char scsibuf[] = {
  19.     0x28,    /* READ */
  20.     0x08,    /* LUN */
  21.     0x00,
  22.     0x00,
  23.     0x00,
  24.     0x00,
  25.     0x00,
  26.     0x00,    /* nr of blocks. */
  27.     0x01,    /* 1 block */
  28.     0x00
  29. };
  30.  
  31. u_char *databuf;
  32.  
  33. struct uscsi_cmd usc = {
  34.     (caddr_t) scsibuf,
  35.     sizeof(scsibuf),
  36.     0,
  37.     0,
  38.     0,
  39.     (USCSI_DIAGNOSE | USCSI_ISOLATE | USCSI_READ)
  40. };
  41.  
  42. char *program;
  43.  
  44.  
  45. main(argc, argv)
  46. int argc;
  47. char *argv[];
  48. {
  49.     int fd;
  50.     int len;
  51.     int i;
  52.     int bnr, nrbl;        /* Block Number, Number of Blocks to read. */
  53.  
  54.     program = argv[0];
  55.  
  56.     bnr = (argc > 1) ? atoi(argv[1]) : 0;
  57.     scsibuf[3] = (bnr >> 16) & 0xFF;
  58.     scsibuf[4] = (bnr >> 8) & 0xFF;
  59.     scsibuf[5] = bnr & 0xFF;
  60.  
  61.     nrbl = (argc > 2) ? atoi(argv[2]) : 1;
  62.     scsibuf[7] = nrbl / 256;
  63.     scsibuf[8] = nrbl % 256;
  64.  
  65.     databuf = (u_char *)malloc(2352 * nrbl);
  66.     if (databuf < 0)
  67.         pfatal("malloc");
  68.  
  69.     usc.uscsi_bufaddr = (caddr_t) databuf;
  70.     usc.uscsi_buflen = 2352 * nrbl;
  71.  
  72.     if ((fd = open("/dev/rsr0", 0)) < 0) 
  73.         pfatal("open");
  74.  
  75.     if (ioctl(fd, USCSICMD, usc) < 0)
  76.         pfatal("ioctl");
  77.  
  78.     write(1, databuf, usc.uscsi_buflen);
  79. }
  80.  
  81. pfatal(s)
  82. char *s;
  83. {
  84.     fprintf(stderr, "%s: ", program);
  85.     perror(s);
  86.     fprintf(stderr, "\n");
  87.     exit(1);
  88. }
  89.