?
Solved

cd TOC access

Posted on 1997-06-19
5
Medium Priority
?
283 Views
Last Modified: 2013-12-26
I have a SCSI CD-Rom drive with ID=3.  I am trying to access the TOC on the drive and continually get and error of -21 (badUnitErr).  I have downloaded samples from Apple, but i cannot get those to work either.  
I am using the PBControl call (this returns with -21) but fill in the paramblock with what i beleive are the correct values.

If you could send me some code that reads off theTOC from the disk (using the mode 4 which gives the starting address of all tracks), it would be very helpful.

thanks
kevin
0
Comment
Question by:meyerkl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Paul B earned 400 total points
ID: 1291510
Here is a short program I wrote to show how to do this.
Apples example is screwed up.
If this does not work please tell me whos driver software you are using. It could be a driver bug!

The code is heavily commented
Notes:
You MUST know the drive number of the CD!
The drive MUST support mode 4 Read Toc
The CD MUST be in the drive

Paul Baxter
pbaxter@assistivetech.com

#include <string.h>
#include <stdio.h>

#define kREADTOC            100                              // Read Toc command
#define kGETALL                  4                              // mode of read toc
#define kWHOISTHERE            97                              // test to see if CD drive

#define kBADRESULT            0xDEAD                        // error code
#define kBUFSIZE            512                              // buffer size to read TOC into


/* Prototypes */
void ReadTocALL(void);
OSErr ReadToc(short driveNum, Ptr buffer);
Boolean IsCDDrive(short driveNum);
short GetDriverRefNum(short driveNum);
void ReadTocALL(void);

char gBuffer[kBUFSIZE];

void main(void)
{
      ReadTocALL();
}

// Read TOC for ALL CD Drives
void ReadTocALL(void)
{
       QHdrPtr                  drvQHdr;
      DrvQEl                  *CurrDrvPtr;
      short                  driveNum, count;
      OSErr                  err;

      count = 0;                                                // number of CD drives found
       drvQHdr = GetDrvQHdr();                              // get the drive que head
      CurrDrvPtr = (DrvQEl *)drvQHdr->qHead;      // set current entry
      while (CurrDrvPtr) {                              // loop until out of range
            driveNum = CurrDrvPtr->dQDrive;            // get drive number
                                                                  // Is this a CD drive
            if (IsCDDrive(driveNum)) {
                  count++;                                    // count number of CD drives
                                                                  // Read TOC for this drive
                  err = ReadToc(driveNum, gBuffer);
                  if (!err) {
                        // Success!!!!!!!!!!!!!!!!!!
                        // TOC data is in gBuffer
                  }
                  printf("drive %d Read TOC  result %d\n", driveNum, err);
            }

            CurrDrvPtr = (DrvQEl *)CurrDrvPtr->qLink;
      }
      if (count == 0)      printf("NO CD drive found!!\nMake sure CD is in drive\n");
}


// Read TOC mode 4 into a buffer
// buffer MUST be pre allocated
// driveNum == drive number of the CD (not SCSI ID)
OSErr ReadToc(short driveNum, Ptr buffer)
{
       CntrlParam ctlPB;                                    // param block
       OSErr      err;                                          // result
       
      memset(&ctlPB, 0, sizeof(CntrlParam));      // Clear param block
                                                                  // get the driver
      ctlPB.ioCRefNum = GetDriverRefNum(driveNum);
                                                                  // check for error
      if (ctlPB.ioCRefNum == kBADRESULT)      return badUnitErr;
      ctlPB.csCode = kREADTOC;                        // set Read TOC Command
       ctlPB.ioVRefNum = driveNum;                        // Drive number (NOT volume number)
       ctlPB.csParam[0] = kGETALL;                        // set mode
                                                                   // set buffer
      ctlPB.csParam[1] = HiWord((long)buffer);
      ctlPB.csParam[2] = LoWord((long)buffer);
                                                                  // call the driver
      err = PBControlSync((ParmBlkPtr) &ctlPB);
      if (err == noErr) err = ctlPB.ioResult;      // check ioResult field
      return err;                                                // return the result
}

// get the driver refnum given a drive number
short GetDriverRefNum(short driveNum)
{
       QHdrPtr                  drvQHdr;
      DrvQEl                  *CurrDrvPtr;

       drvQHdr = GetDrvQHdr();                              // get the drive que head
      CurrDrvPtr = (DrvQEl *)drvQHdr->qHead;      // set current entry
      while (CurrDrvPtr) {                              // loop until out of range
                                                                  // is this the right drive?
            if (CurrDrvPtr->dQDrive == driveNum) {      
                  return(CurrDrvPtr->dQRefNum);      // set return value
            }
            else {                                                // goto next element
                  CurrDrvPtr = (DrvQEl *)CurrDrvPtr->qLink;
            }
      }
      return kBADRESULT;                                    // return
}

// return true if the drive is a CD drive
Boolean IsCDDrive(short driveNum)
{
      short refnum;
      
       CntrlParam ctlPB;                                    // param block
       OSErr      err;                                          // result
       
      memset(&ctlPB, 0, sizeof(CntrlParam));      // Clear param block
                                                                  // get the driver
      ctlPB.ioCRefNum = GetDriverRefNum(driveNum);
                                                                  // check for error
      if (ctlPB.ioCRefNum == kBADRESULT)      return false;
      
      ctlPB.csCode = kWHOISTHERE;                        // id the a CD?
      err = PBStatusSync((ParmBlkPtr) &ctlPB);// call the drivr
      if (err == noErr) err = ctlPB.ioResult;      // check ioResult field
      return err == noErr;
}

0
 

Author Comment

by:meyerkl
ID: 1291511
just a quick comment:
  I also want to be able to read the Q-subcode on different tracks.  I know that there is a different value you place in csCode but i was wondering if i could just use your functions to place the call with the different value.  ie: I know that Apple has some samples that do not work, just wondering how general your code is...

thanks alot!!!!!
0
 
LVL 1

Expert Comment

by:Paul B
ID: 1291512
To ReadQ it is pretty much the same once you know the drive number.
ReadQ will return the data in csParams 0..8 so you should copy the data to somewhere else

This function will copy the data to the buffer passed

#define kREADQ                        101
#define kREADQSIZE 9

OSErr ReadQ(short driveNum, Ptr buffer)
{
       CntrlParam ctlPB;                                    // param block
       OSErr      err;                                                // result
       
      memset(&ctlPB, 0, sizeof(CntrlParam));      // Clear param block
                                                                  // get the driver
      ctlPB.ioCRefNum = GetDriverRefNum(driveNum);
                                                                  // check for error
      if (ctlPB.ioCRefNum == kBADRESULT)      return badUnitErr;
      ctlPB.csCode = kREADQ;                              // set Read TOC Command
       ctlPB.ioVRefNum = driveNum;                        // Drive number (NOT volume number)
       err = PBControlSync((ParmBlkPtr) &ctlPB);
      if (err == noErr) err = ctlPB.ioResult;      // check ioResult field
 if (err == noErr) {
          BlockMovedata(&ctlPB.csParam[0], buffer, kREADQSIZE);
 }
      return err;                                                // return the result
}
0
 
LVL 1

Expert Comment

by:Paul B
ID: 1291513
ooops...BlockMovedata should be BlockMoveData :/


0
 

Author Comment

by:meyerkl
ID: 1291514
Paul,
      I noticed on your Customer Infomation page here that you have written some software for CD-ROM mastering.  I am trying to write something like that but for my own use.  I was wondering if you have an e-mail address I could ask you questions and stuff.

thanks.
meyerkl@crux.rose-hulman.edu
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question