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

bool K3bDevice::Device::readFormatCapacity ( int  wantedFormat,
K3b::Msf result,
K3b::Msf currentMax = 0,
int *  currentMaxFormat = 0 
) const

Refers to MMC command READ FORMAT CAPACITY

Parameters:
wantedFormat The requested format type.
result If true is returned this contains the requested value.
currentMax If not 0 this will be filled with the Current/Maximum Descriptor value.
currentMax If not 0 this will be filled with the Current/Maximum Format Type.

Definition at line 694 of file k3bdevice_mmc.cpp.

References blockDeviceName(), and K3b::Msf::lba().

Referenced by diskInfo().

{
  bool success = false;

  // the maximal length as stated in MMC4
  static const unsigned int maxLen = 4 + (8*31);

  unsigned char buffer[maxLen];
  ::memset( buffer, 0, maxLen );

  ScsiCommand cmd( this );
  cmd[0] = MMC_READ_FORMAT_CAPACITIES;
  cmd[7] = maxLen >> 8;
  cmd[8] = maxLen & 0xFF;
  if( cmd.transport( TR_DIR_READ, buffer, maxLen ) == 0 ) {

    int realLength = buffer[3] + 4;

    kdDebug() << "(K3bDevice::Device) " << blockDeviceName() << " READ FORMAT CAPACITY: Current/Max "
            << (int)(buffer[8]&0x3) << " " << from4Byte( &buffer[4] ) << endl;

    if( currentMax )
      *currentMax = from4Byte( &buffer[4] );
    if( currentMaxFormat )
      *currentMaxFormat = (int)(buffer[8]&0x3);

    //
    // Descriptor Type:
    // 0 - reserved
    // 1 - unformatted :)
    // 2 - formatted. Here we get the used capacity (lead-in to last lead-out/border-out)
    // 3 - No media present
    //
    for( int i = 12; i < realLength-4; i+=8 ) {
      int format = (int)((buffer[i+4]>>2)&0x3f);
      kdDebug() << "(K3bDevice::Device) " << blockDeviceName() << " READ FORMAT CAPACITY: "
            << format << " " << from4Byte( &buffer[i] )
            << " " << (int)( buffer[i+5] << 16 & 0xFF0000 |
                         buffer[i+6] << 8  & 0xFF00 |
                         buffer[i+7]       & 0xFF ) << endl;

      if( format == wantedFormat ) {
      // found the descriptor
      r = QMAX( (int)from4Byte( &buffer[i] ), r.lba() );
      success = true;
      }
    }
  }

  return success;
}


Generated by  Doxygen 1.6.0   Back to index