Logo Search packages:      
Sourcecode: k9copy version File versions  Download package

int K3bDevice::Device::getIndex ( unsigned long  lba  )  const

Returns:
the index number on success -1 on general error and -2 if there is no index info in that frame

Definition at line 2865 of file k3bdevice.cpp.

References close(), isOpen(), open(), readCd(), readSubChannel(), and seek().

{
  // if the device is already opened we do not close it
  // to allow fast multible method calls in a row
  bool needToClose = !isOpen();

  if( !open() )
    return -1;

  int ret = -1;

  //
  // first try readCd
  //
  unsigned char readData[16];
  ::memset( readData, 0, 16 );

  //
  // The index is found in the Mode-1 Q which occupies at least 9 out of 10 successive CD frames
  // It can be indentified by ADR == 1
  //
  // So if the current sector does not provide Mode-1 Q subchannel we try the previous.
  //

  if( readCd( readData,
            16,
            1, // CD-DA
            0, // no DAP
            lba,
            1,
            false,
            false,
            false,
            false,
            false,
            0,
            2 // Q-Subchannel
            ) ) {
    // byte 0: 4 bits CONTROL (MSB) + 4 bits ADR (LSB)
    if( (readData[0]&0x0f) == 0x1 )
      ret = readData[2];

    // search previous sector for Mode1 Q Subchannel
    else if( readCd( readData,
            16,
            1, // CD-DA
            0, // no DAP
            lba-1,
            1,
            false,
            false,
            false,
            false,
            false,
            0,
            2 // Q-Subchannel
            ) ) {
      if( (readData[0]&0x0f) == 0x1 )
      ret = readData[2];
      else
      ret = -2;
    }
  }

  else {
    kdDebug() << "(K3bDevice::Device::getIndex) readCd failed. Trying seek." << endl;

    unsigned char* data = 0;
    int dataLen = 0;
    if( seek( lba ) && readSubChannel( &data, dataLen, 1, 0 ) ) {
      // byte 5: 4 bits ADR (MSB) + 4 bits CONTROL (LSB)
      if( dataLen > 7 && (data[5]>>4 & 0x0F) == 0x1 ) {
      ret = data[7];
      }
      else if( seek( lba-1 ) && readSubChannel( &data, dataLen, 1, 0 ) ) {
      if( dataLen > 7 && (data[5]>>4 & 0x0F) == 0x1 )
        ret = data[7];
      else
        ret = -2;
      }

      delete [] data;
    }
    else
      kdDebug() << "(K3bDevice::Device::getIndex) seek or readSubChannel failed." << endl;
  }

  if( needToClose )
    close();

  return ret;
}


Generated by  Doxygen 1.6.0   Back to index