fix for compatibility with 2.4
This commit is contained in:
@@ -118,6 +118,7 @@ static bool ExecuteCommand( CCStringRef sCommand )
|
|||||||
{
|
{
|
||||||
LOG->Trace( "executing '%s'", sCommand.c_str() );
|
LOG->Trace( "executing '%s'", sCommand.c_str() );
|
||||||
int ret = system(sCommand);
|
int ret = system(sCommand);
|
||||||
|
LOG->Trace( "done executing '%s'", sCommand.c_str() );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
LOG->Warn( "failed to execute '%s' with error %d.", sCommand.c_str(), ret );
|
LOG->Warn( "failed to execute '%s' with error %d.", sCommand.c_str(), ret );
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
@@ -248,8 +249,57 @@ MemoryCardDriverThreaded_Linux::MemoryCardDriverThreaded_Linux()
|
|||||||
this->StartThread();
|
this->StartThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ReadUsbStorageDescriptor( CString fn, int iScsiIndex, vector<UsbStorageDeviceEx>& vDevicesOut )
|
||||||
|
{
|
||||||
|
LOG->Trace( "ReadUsbStorageDescriptor %s", fn.c_str() );
|
||||||
|
|
||||||
|
// Read the usb-storage descriptor. It looks like:
|
||||||
|
|
||||||
|
// Host scsi0: usb-storage
|
||||||
|
// Vendor: KINGSTON
|
||||||
|
// Product: USB DRIVE
|
||||||
|
// Serial Number: 1125198948886
|
||||||
|
// Protocol: Transparent SCSI
|
||||||
|
// Transport: Bulk
|
||||||
|
// GUID: 04e801000001125198948886
|
||||||
|
// Attached: Yes
|
||||||
|
|
||||||
|
ifstream f;
|
||||||
|
f.open(fn);
|
||||||
|
if( !f.is_open() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CString sLine;
|
||||||
|
while( getline(f, sLine) )
|
||||||
|
{
|
||||||
|
// Serial Number: 1125198948886
|
||||||
|
char szSerial[1024];
|
||||||
|
int iRet = sscanf( sLine.c_str(), "Serial Number: %[^\n]", szSerial );
|
||||||
|
if( iRet == 1 ) // we found our line
|
||||||
|
{
|
||||||
|
// Search for the device corresponding to this serial number.
|
||||||
|
for( unsigned j=0; j<vDevicesOut.size(); j++ )
|
||||||
|
{
|
||||||
|
UsbStorageDevice& usbd = vDevicesOut[j];
|
||||||
|
|
||||||
|
if( usbd.sSerial == szSerial )
|
||||||
|
{
|
||||||
|
usbd.iScsiIndex = iScsiIndex;
|
||||||
|
LOG->Trace( "iScsiIndex: %d, iBus: %d, iLevel: %d, iPort: %d, sSerial: %s",
|
||||||
|
usbd.iScsiIndex, usbd.iBus, usbd.iLevel, usbd.iPort, usbd.sSerial.c_str() );
|
||||||
|
break; // done looking for the corresponding device.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break; // we already found the line we care about
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
||||||
{
|
{
|
||||||
|
LOG->Trace( "GetNewStorageDevices" );
|
||||||
|
|
||||||
vDevicesOut.clear();
|
vDevicesOut.clear();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -277,6 +327,7 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
|
|
||||||
ifstream f;
|
ifstream f;
|
||||||
CString fn = "/proc/bus/usb/devices";
|
CString fn = "/proc/bus/usb/devices";
|
||||||
|
LOG->Trace( fn );
|
||||||
f.open(fn);
|
f.open(fn);
|
||||||
if( !f.is_open() )
|
if( !f.is_open() )
|
||||||
{
|
{
|
||||||
@@ -328,8 +379,14 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
|
|
||||||
{
|
{
|
||||||
// Find the usb-storage device index for all storage class devices.
|
// Find the usb-storage device index for all storage class devices.
|
||||||
|
|
||||||
const CString sDir = "/proc/scsi/usb-storage/";
|
const CString sDir = "/proc/scsi/usb-storage/";
|
||||||
|
LOG->Trace( sDir );
|
||||||
DIR *dirp = opendir( sDir );
|
DIR *dirp = opendir( sDir );
|
||||||
|
if( dirp )
|
||||||
|
{
|
||||||
|
// 2.6 kernel style
|
||||||
|
|
||||||
struct dirent *direntp;
|
struct dirent *direntp;
|
||||||
while ( (direntp = readdir( dirp )) != NULL )
|
while ( (direntp = readdir( dirp )) != NULL )
|
||||||
{
|
{
|
||||||
@@ -339,52 +396,12 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
int iScsiIndex = atoi( direntp->d_name );
|
int iScsiIndex = atoi( direntp->d_name );
|
||||||
CString fn = sDir + direntp->d_name;
|
CString fn = sDir + direntp->d_name;
|
||||||
|
|
||||||
// Read the usb-storage descriptor. It looks like:
|
ReadUsbStorageDescriptor( fn, iScsiIndex, vDevicesOut );
|
||||||
|
|
||||||
// Host scsi0: usb-storage
|
|
||||||
// Vendor: KINGSTON
|
|
||||||
// Product: USB DRIVE
|
|
||||||
// Serial Number: 1125198948886
|
|
||||||
// Protocol: Transparent SCSI
|
|
||||||
// Transport: Bulk
|
|
||||||
// GUID: 04e801000001125198948886
|
|
||||||
// Attached: Yes
|
|
||||||
|
|
||||||
ifstream f;
|
|
||||||
f.open(fn);
|
|
||||||
if( !f.is_open() )
|
|
||||||
break;
|
|
||||||
|
|
||||||
CString sLine;
|
|
||||||
while( getline(f, sLine) )
|
|
||||||
{
|
|
||||||
// Serial Number: 1125198948886
|
|
||||||
char szSerial[1024];
|
|
||||||
int iRet = sscanf( sLine.c_str(), "Serial Number: %[^\n]", szSerial );
|
|
||||||
if( iRet == 1 ) // we found our line
|
|
||||||
{
|
|
||||||
// Search for the device corresponding to this serial number.
|
|
||||||
for( unsigned j=0; j<vDevicesOut.size(); j++ )
|
|
||||||
{
|
|
||||||
UsbStorageDevice& usbd = vDevicesOut[j];
|
|
||||||
|
|
||||||
if( usbd.sSerial == szSerial )
|
|
||||||
{
|
|
||||||
usbd.iScsiIndex = iScsiIndex;
|
|
||||||
LOG->Trace( "iScsiIndex: %d, iBus: %d, iLevel: %d, iPort: %d, sSerial: %s",
|
|
||||||
usbd.iScsiIndex, usbd.iBus, usbd.iLevel, usbd.iPort, usbd.sSerial.c_str() );
|
|
||||||
break; // done looking for the corresponding device.
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break; // we already found the line we care about
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir( dirp );
|
closedir( dirp );
|
||||||
}
|
dirp = NULL;
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
// Get the mapping from Scsi device number to Scsi file device. Requires "sg-utils".
|
// Get the mapping from Scsi device number to Scsi file device. Requires "sg-utils".
|
||||||
// sg_scan. It looks like:
|
// sg_scan. It looks like:
|
||||||
|
|
||||||
@@ -392,7 +409,9 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
// /dev/sg1: scsi46 channel=0 id=0 lun=0 [em] type=0
|
// /dev/sg1: scsi46 channel=0 id=0 lun=0 [em] type=0
|
||||||
|
|
||||||
CString sOutput;
|
CString sOutput;
|
||||||
RunProgram( "/usr/bin/sg_scan", NULL, sOutput );
|
CString sCommand = "/usr/bin/sg_scan";
|
||||||
|
LOG->Trace( sCommand );
|
||||||
|
RunProgram( sCommand, NULL, sOutput );
|
||||||
|
|
||||||
CStringArray vsLines;
|
CStringArray vsLines;
|
||||||
split( sOutput, "\n", vsLines );
|
split( sOutput, "\n", vsLines );
|
||||||
@@ -424,9 +443,25 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done_mapping:
|
else
|
||||||
int blah = 0; // hack around "label must be followed by statement"
|
{
|
||||||
|
// 2.4 kernel style
|
||||||
|
|
||||||
|
// Find the usb-storage device index for all storage class devices.
|
||||||
|
for( unsigned i=0; true; i++ )
|
||||||
|
{
|
||||||
|
CString fn = ssprintf( "/proc/scsi/usb-storage-%d/%d", i, i );
|
||||||
|
if( !ReadUsbStorageDescriptor( fn, i, vDevicesOut ) )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( unsigned i=0; i<vDevicesOut.size(); i++ )
|
||||||
|
{
|
||||||
|
UsbStorageDevice& usbd = vDevicesOut[i];
|
||||||
|
usbd.sScsiDevice = ssprintf("/dev/sd%c",'a'+(char)usbd.iScsiIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Find where each device is mounted. Output looks like:
|
// Find where each device is mounted. Output looks like:
|
||||||
@@ -436,6 +471,7 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
// /dev/sdc1 /mnt/flash3 auto noauto,owner 0 0
|
// /dev/sdc1 /mnt/flash3 auto noauto,owner 0 0
|
||||||
|
|
||||||
CString fn = "/etc/fstab";
|
CString fn = "/etc/fstab";
|
||||||
|
LOG->Trace( fn );
|
||||||
RageFile f;
|
RageFile f;
|
||||||
if( !f.Open(fn) )
|
if( !f.Open(fn) )
|
||||||
{
|
{
|
||||||
@@ -482,6 +518,8 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leave:
|
||||||
|
|
||||||
/* Remove any devices that we couldn't find a mountpoint for. */
|
/* Remove any devices that we couldn't find a mountpoint for. */
|
||||||
for( unsigned i=0; i<vDevicesOut.size(); i++ )
|
for( unsigned i=0; i<vDevicesOut.size(); i++ )
|
||||||
{
|
{
|
||||||
@@ -493,8 +531,10 @@ void GetNewStorageDevices( vector<UsbStorageDeviceEx>& vDevicesOut )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG->Trace( "Done with GetNewStorageDevices" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice, CString sMountPoint )
|
void MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice, CString sMountPoint )
|
||||||
{
|
{
|
||||||
ASSERT( !pDevice->sOsMountDir.empty() );
|
ASSERT( !pDevice->sOsMountDir.empty() );
|
||||||
|
|||||||
Reference in New Issue
Block a user