ignore usb-storage descriptors marked "not attached"

This commit is contained in:
Chris Danford
2004-02-26 09:37:04 +00:00
parent e5793ab28a
commit d2c8684449
@@ -133,10 +133,11 @@ void MemoryCardDriver_Linux::GetStorageDevices( vector<UsbStorageDevice>& vDevic
} }
{ {
// Find the usb-storage device index for all storage class devices. // Read all usb-storage descriptors and map from our array to usb-storage device index.
for( unsigned i=0; i<vDevicesOut.size(); i++ ) int iConnectedDeviceIndex = 0;
for( iUsbStorageIndex = 0; true; iUsbStorageIndex++; )
{ {
UsbStorageDevice& usbd = vDevicesOut[i]; UsbStorageDevice& usbd = vDevicesOut[iConnectedDeviceIndex];
// Output looks like: // Output looks like:
// Host scsi0: usb-storage // Host scsi0: usb-storage
@@ -148,29 +149,35 @@ void MemoryCardDriver_Linux::GetStorageDevices( vector<UsbStorageDevice>& vDevic
// GUID: 04e801000001125198948886 // GUID: 04e801000001125198948886
// Attached: Yes // Attached: Yes
CString fn = ssprintf( "/proc/scsi/usb-storage-%d/%d", i, i ); CString fn = ssprintf( "/proc/scsi/usb-storage-%d/%d", iUsbStorageIndex, iUsbStorageIndex );
ifstream f; ifstream f;
f.open(fn); f.open(fn);
if( !f.is_open() ) if( !f.is_open() )
{ break;
LOG->Warn( "can't open '%s'", fn.c_str() );
return; char szTemp[1024];
}
CString sLine; CString sLine;
while( getline(f, sLine) ) while( getline(f, sLine) )
{ {
// Serial Number: 1125198948886 // Attached: Yes
char szSerial[1024]; int iRet = sscanf( sLine.c_str(), " Attached: %s", szTemp );
int iRet = sscanf( sLine.c_str(), "Serial Number: %[^\n]", szSerial );
if( iRet == 1 ) // we found our line if( iRet == 1 ) // we found our line
{ {
usbd.iUsbStorageIndex = i; if( strcmp(szTemp,"Yes")==0 )
{
LOG->Trace( "iUsbStorageIndex: %d, iBus: %d, iDeviceOnBus: %d, iPortOnHub: %d", usbd.iUsbStorageIndex = iUsbStorageIndex;
usbd.iUsbStorageIndex, usbd.iBus, usbd.iDeviceOnBus, usbd.iPortOnHub ); iConnectedDeviceIndex++;
}
break; // stop looking else if( strcmp(szTemp,"No")==0 )
{
break; // this device isn't attached. Ignore it.
}
else
{
LOG->Warn( "Invalid value for Attached: '%s'", szTemp );
break;
}
} }
} }
} }