add memory card level matching to disallow deep USB devices
This commit is contained in:
@@ -9,15 +9,15 @@ struct UsbStorageDevice
|
|||||||
{
|
{
|
||||||
// -1 means "don't know"
|
// -1 means "don't know"
|
||||||
iBus = -1;
|
iBus = -1;
|
||||||
iDeviceOnBus = -1;
|
iPort = -1;
|
||||||
iPortOnHub = -1;
|
iLevel = -1;
|
||||||
iUsbStorageIndex = -1;
|
iUsbStorageIndex = -1;
|
||||||
sSerial = "";
|
sSerial = "";
|
||||||
sOsMountDir = "";
|
sOsMountDir = "";
|
||||||
};
|
};
|
||||||
int iBus;
|
int iBus;
|
||||||
int iDeviceOnBus;
|
int iPort;
|
||||||
int iPortOnHub;
|
int iLevel;
|
||||||
CString sSerial;
|
CString sSerial;
|
||||||
int iUsbStorageIndex;
|
int iUsbStorageIndex;
|
||||||
CString sOsMountDir; // WITHOUT trailing slash
|
CString sOsMountDir; // WITHOUT trailing slash
|
||||||
@@ -28,7 +28,9 @@ struct UsbStorageDevice
|
|||||||
{
|
{
|
||||||
if( (iBus!=-1 || other.iBus!=-1) && iBus != other.iBus )
|
if( (iBus!=-1 || other.iBus!=-1) && iBus != other.iBus )
|
||||||
return false;
|
return false;
|
||||||
if( (iDeviceOnBus!=-1 || other.iDeviceOnBus!=-1) && iDeviceOnBus != other.iDeviceOnBus )
|
if( (iPort!=-1 || other.iPort!=-1) && iPort != other.iPort )
|
||||||
|
return false;
|
||||||
|
if( (iLevel!=-1 || other.iLevel!=-1) && iBus != other.iLevel )
|
||||||
return false;
|
return false;
|
||||||
return sOsMountDir==other.sOsMountDir; // every time a device is plugged in, it gets a unique device number
|
return sOsMountDir==other.sOsMountDir; // every time a device is plugged in, it gets a unique device number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ void MemoryCardDriverThreaded_Linux::MountThreadMain()
|
|||||||
UsbStorageDeviceEx &old = vOld[i];
|
UsbStorageDeviceEx &old = vOld[i];
|
||||||
if( find(vNew.begin(),vNew.end(),old) == vNew.end() )// didn't find
|
if( find(vNew.begin(),vNew.end(),old) == vNew.end() )// didn't find
|
||||||
{
|
{
|
||||||
LOG->Trace( ssprintf("Disconnected bus %d port %d device %d path %s", old.iBus, old.iPortOnHub, old.iDeviceOnBus, old.sOsMountDir.c_str()) );
|
LOG->Trace( ssprintf("Disconnected bus %d port %d device %d path %s", old.iBus, old.iPort, old.iLevel, old.sOsMountDir.c_str()) );
|
||||||
vDisconnects.push_back( &old );
|
vDisconnects.push_back( &old );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ void MemoryCardDriverThreaded_Linux::MountThreadMain()
|
|||||||
UsbStorageDeviceEx &newd = vNew[i];
|
UsbStorageDeviceEx &newd = vNew[i];
|
||||||
if( find(vOld.begin(),vOld.end(),newd) == vOld.end() )// didn't find
|
if( find(vOld.begin(),vOld.end(),newd) == vOld.end() )// didn't find
|
||||||
{
|
{
|
||||||
LOG->Trace( ssprintf("Connected bus %d port %d device %d path %s", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus, newd.sOsMountDir.c_str()) );
|
LOG->Trace( ssprintf("Connected bus %d port %d device %d path %s", newd.iBus, newd.iPort, newd.iLevel, newd.sOsMountDir.c_str()) );
|
||||||
vConnects.push_back( &newd );
|
vConnects.push_back( &newd );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,13 +214,13 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
int iRet, iThrowAway;
|
int iRet, iThrowAway;
|
||||||
|
|
||||||
// T: Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
|
// T: Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
|
||||||
int iBus, iPort, iDevice;
|
int iBus, iLevel, iPort, iDevice;
|
||||||
iRet = sscanf( sLine.c_str(), "T: Bus=%d Lev=%d Prnt=%d Port=%d Cnt=%d Dev#=%d Spd=%d MxCh=%d", &iBus, &iThrowAway, &iThrowAway, &iPort, &iThrowAway, &iDevice, &iThrowAway, &iThrowAway );
|
iRet = sscanf( sLine.c_str(), "T: Bus=%d Lev=%d Prnt=%d Port=%d Cnt=%d Dev#=%d Spd=%d MxCh=%d", &iBus, &iLevel, &iThrowAway, &iPort, &iThrowAway, &iDevice, &iThrowAway, &iThrowAway );
|
||||||
if( iRet == 8 )
|
if( iRet == 8 )
|
||||||
{
|
{
|
||||||
usbd.iBus = iBus;
|
usbd.iBus = iBus;
|
||||||
usbd.iDeviceOnBus = iDevice;
|
usbd.iPort = iPort;
|
||||||
usbd.iPortOnHub = iPort;
|
usbd.iLevel = iLevel;
|
||||||
continue; // stop processing this line
|
continue; // stop processing this line
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +241,8 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
if( iClass == 8 ) // storage class
|
if( iClass == 8 ) // storage class
|
||||||
{
|
{
|
||||||
vDevicesOut.push_back( usbd );
|
vDevicesOut.push_back( usbd );
|
||||||
LOG->Trace( "iUsbStorageIndex: %d, iBus: %d, iDeviceOnBus: %d, iPortOnHub: %d",
|
LOG->Trace( "iUsbStorageIndex: %d, iBus: %d, iLevel: %d, iPort: %d",
|
||||||
usbd.iUsbStorageIndex, usbd.iBus, usbd.iDeviceOnBus, usbd.iPortOnHub );
|
usbd.iUsbStorageIndex, usbd.iBus, usbd.iLevel, usbd.iPort );
|
||||||
}
|
}
|
||||||
continue; // stop processing this line
|
continue; // stop processing this line
|
||||||
}
|
}
|
||||||
@@ -286,8 +286,8 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
if( usbd.sSerial == szSerial )
|
if( usbd.sSerial == szSerial )
|
||||||
{
|
{
|
||||||
usbd.iUsbStorageIndex = i;
|
usbd.iUsbStorageIndex = i;
|
||||||
LOG->Trace( "iUsbStorageIndex: %d, iBus: %d, iDeviceOnBus: %d, iPortOnHub: %d, sSerial: %s",
|
LOG->Trace( "iUsbStorageIndex: %d, iBus: %d, iLevel: %d, iPort: %d, sSerial: %s",
|
||||||
usbd.iUsbStorageIndex, usbd.iBus, usbd.iDeviceOnBus, usbd.iPortOnHub, usbd.sSerial.c_str() );
|
usbd.iUsbStorageIndex, usbd.iBus, usbd.iLevel, usbd.iPort, usbd.sSerial.c_str() );
|
||||||
break; // done looking for the corresponding device.
|
break; // done looking for the corresponding device.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,8 +335,8 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
{
|
{
|
||||||
usbd.sOsMountDir = sMountPoint;
|
usbd.sOsMountDir = sMountPoint;
|
||||||
|
|
||||||
LOG->Trace( "iUsbStorageIndex: %d, iBus: %d, iDeviceOnBus: %d, iPortOnHub: %d, sOsMountDir: %s",
|
LOG->Trace( "iUsbStorageIndex: %d, iBus: %d, iLevel: %d, iPort: %d, sOsMountDir: %s",
|
||||||
usbd.iUsbStorageIndex, usbd.iBus, usbd.iDeviceOnBus, usbd.iPortOnHub, usbd.sOsMountDir.c_str() );
|
usbd.iUsbStorageIndex, usbd.iBus, usbd.iLevel, usbd.iPort, usbd.sOsMountDir.c_str() );
|
||||||
|
|
||||||
break; // stop looking for a match
|
break; // stop looking for a match
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user