clean up formatting

This commit is contained in:
Chris Danford
2004-08-17 06:16:49 +00:00
parent be7b0bf85a
commit 925c349d26
@@ -149,7 +149,7 @@ void MemoryCardDriverThreaded_Linux::ResetUsbStorage()
// //
// unmount all devices before trying to remove the module // unmount all devices before trying to remove the module
FOREACH( UsbStorageDevice, m_vDevicesLastSeen, d ) FOREACH( UsbStorageDevice, m_vDevicesLastSeen, d )
{ {
CString sCommand = "umount " + d->sOsMountDir; CString sCommand = "umount " + d->sOsMountDir;
LOG->Trace( "reset unmount (%s)", sCommand.c_str() ); LOG->Trace( "reset unmount (%s)", sCommand.c_str() );
@@ -177,36 +177,36 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
bool bNeedToDoAnyMounts = false; bool bNeedToDoAnyMounts = false;
for( unsigned i=0; i<m_vDevicesLastSeen.size(); i++ ) for( unsigned i=0; i<m_vDevicesLastSeen.size(); i++ )
{ {
UsbStorageDevice &d = m_vDevicesLastSeen[i]; UsbStorageDevice &d = m_vDevicesLastSeen[i];
if( d.bNeedsWriteTest ) if( d.bNeedsWriteTest )
{ {
bNeedToDoAnyMounts = true; bNeedToDoAnyMounts = true;
break; break;
} }
} }
if( bNeedToDoAnyMounts ) if( bNeedToDoAnyMounts )
{ {
// fall through // fall through
} }
else else
{ {
pollfd pfd = { m_fd, POLLIN, 0 }; pollfd pfd = { m_fd, POLLIN, 0 };
int ret = poll( &pfd, 1, 100 ); int ret = poll( &pfd, 1, 100 );
switch( ret ) switch( ret )
{ {
case 1: case 1:
// file changed. Fall through. // file changed. Fall through.
break; break;
case 0: // no change. Poll again. case 0: // no change. Poll again.
return; return;
case -1: case -1:
if( errno != EINTR ) if( errno != EINTR )
LOG->Warn( "Error polling: %s", strerror(errno) ); LOG->Warn( "Error polling: %s", strerror(errno) );
return; return;
} }
} }
// TRICKY: We're waiting for a change in the USB device list, but // TRICKY: We're waiting for a change in the USB device list, but
// the usb-storage descriptors take a bit longer to update. It's more convenient to wait // the usb-storage descriptors take a bit longer to update. It's more convenient to wait
@@ -223,110 +223,110 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
vector<UsbStorageDevice> vDisconnects; vector<UsbStorageDevice> vDisconnects;
FOREACH( UsbStorageDevice, vOld, old ) FOREACH( UsbStorageDevice, vOld, old )
{ {
bool bMatch = false; bool bMatch = false;
FOREACH( UsbStorageDevice, vNew, newd ) FOREACH( UsbStorageDevice, vNew, newd )
{
if( old->IdsMatch(*newd) )
{ {
bMatch = true; if( old->IdsMatch(*newd) )
break; {
bMatch = true;
break;
}
} }
}
if( !bMatch ) // didn't find if( !bMatch ) // didn't find
{
LOG->Trace( "Disconnected bus %d port %d level %d path %s", old->iBus, old->iPort, old->iLevel, old->sOsMountDir.c_str() );
vDisconnects.push_back( *old );
FOREACH( UsbStorageDevice, m_vDevicesLastSeen, d )
{ {
if( old->IdsMatch(*d) ) LOG->Trace( "Disconnected bus %d port %d level %d path %s", old->iBus, old->iPort, old->iLevel, old->sOsMountDir.c_str() );
{ vDisconnects.push_back( *old );
m_vDevicesLastSeen.erase( d );
break; FOREACH( UsbStorageDevice, m_vDevicesLastSeen, d )
} {
if( old->IdsMatch(*d) )
{
m_vDevicesLastSeen.erase( d );
break;
}
}
} }
}
} }
// check for connects // check for connects
vector<UsbStorageDevice> vConnects; vector<UsbStorageDevice> vConnects;
FOREACH( UsbStorageDevice, vNew, newd ) FOREACH( UsbStorageDevice, vNew, newd )
{ {
bool bMatch = false; bool bMatch = false;
FOREACH( UsbStorageDevice, vOld, old ) FOREACH( UsbStorageDevice, vOld, old )
{ {
if( old->IdsMatch(*newd) ) if( old->IdsMatch(*newd) )
{ {
bMatch = true; bMatch = true;
break; break;
} }
} }
if( !bMatch ) // didn't find if( !bMatch ) // didn't find
{ {
LOG->Trace( "Connected bus %d port %d level %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() ); LOG->Trace( "Connected bus %d port %d level %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() );
vConnects.push_back( *newd ); vConnects.push_back( *newd );
m_vDevicesLastSeen.push_back( *newd ); m_vDevicesLastSeen.push_back( *newd );
} }
} }
bool bDidAnyMounts = false; bool bDidAnyMounts = false;
// unmount all disconnects // unmount all disconnects
if( ShouldDoOsMount() ) if( ShouldDoOsMount() )
{ {
for( unsigned i=0; i<vDisconnects.size(); i++ ) for( unsigned i=0; i<vDisconnects.size(); i++ )
{ {
UsbStorageDevice &d = vDisconnects[i]; UsbStorageDevice &d = vDisconnects[i];
CString sCommand = "umount " + d.sOsMountDir; CString sCommand = "umount " + d.sOsMountDir;
LOG->Trace( "unmount disconnects %i/%i (%s)", i, vDisconnects.size(), sCommand.c_str() ); LOG->Trace( "unmount disconnects %i/%i (%s)", i, vDisconnects.size(), sCommand.c_str() );
ExecuteCommand( sCommand ); ExecuteCommand( sCommand );
LOG->Trace( "unmount disconnects %i/%i done", i, vDisconnects.size() ); LOG->Trace( "unmount disconnects %i/%i done", i, vDisconnects.size() );
} }
// mount all devices that need a write test // mount all devices that need a write test
for( unsigned i=0; i<m_vDevicesLastSeen.size(); i++ ) for( unsigned i=0; i<m_vDevicesLastSeen.size(); i++ )
{ {
UsbStorageDevice &d = m_vDevicesLastSeen[i]; UsbStorageDevice &d = m_vDevicesLastSeen[i];
if( !d.bNeedsWriteTest ) if( !d.bNeedsWriteTest )
continue; // skip continue; // skip
bDidAnyMounts = true; bDidAnyMounts = true;
d.bNeedsWriteTest = false; d.bNeedsWriteTest = false;
CString sCommand; CString sCommand;
// unmount this device before trying to mount it. If this device // unmount this device before trying to mount it. If this device
// wasn't unmounted before, then our mount call will fail and the // wasn't unmounted before, then our mount call will fail and the
// mount may contain an out-of-date view of the files on the device. // mount may contain an out-of-date view of the files on the device.
sCommand = "umount " + d.sOsMountDir; sCommand = "umount " + d.sOsMountDir;
LOG->Trace( "unmount old connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() ); LOG->Trace( "unmount old connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() );
ExecuteCommand( sCommand ); // don't care if this fails ExecuteCommand( sCommand ); // don't care if this fails
LOG->Trace( "unmount old connect %i/%i done", i, vConnects.size() ); LOG->Trace( "unmount old connect %i/%i done", i, vConnects.size() );
sCommand = "mount " + d.sOsMountDir; sCommand = "mount " + d.sOsMountDir;
LOG->Trace( "mount new connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() ); LOG->Trace( "mount new connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() );
bool bMountedSuccessfully = ExecuteCommand( sCommand ); bool bMountedSuccessfully = ExecuteCommand( sCommand );
LOG->Trace( "mount new connect %i/%i done", i, vConnects.size() ); LOG->Trace( "mount new connect %i/%i done", i, vConnects.size() );
d.bWriteTestSucceeded = bMountedSuccessfully && TestWrite( d.sOsMountDir ); d.bWriteTestSucceeded = bMountedSuccessfully && TestWrite( d.sOsMountDir );
// read name // read name
this->Mount( &d, TEMP_MOUNT_POINT ); this->Mount( &d, TEMP_MOUNT_POINT );
FILEMAN->FlushDirCache( TEMP_MOUNT_POINT ); FILEMAN->FlushDirCache( TEMP_MOUNT_POINT );
Profile profile; Profile profile;
CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/'; CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/';
profile.LoadEditableDataFromDir( sProfileDir ); profile.LoadEditableDataFromDir( sProfileDir );
d.sName = profile.GetDisplayName(); d.sName = profile.GetDisplayName();
UnmountMountPoint( TEMP_MOUNT_POINT ); UnmountMountPoint( TEMP_MOUNT_POINT );
LOG->Trace( "WriteTest: %s, Name: %s", d.bWriteTestSucceeded ? "succeeded" : "failed", d.sName.c_str() ); LOG->Trace( "WriteTest: %s, Name: %s", d.bWriteTestSucceeded ? "succeeded" : "failed", d.sName.c_str() );
} }
} }
if( bDidAnyMounts || !vDisconnects.empty() || !vConnects.empty() ) if( bDidAnyMounts || !vDisconnects.empty() || !vConnects.empty() )
{ {
@@ -457,12 +457,12 @@ void GetNewStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
{ {
// Bus 002 Device 001: ID 0000:0000 // Bus 002 Device 001: ID 0000:0000
// Port 4 // Port 4
// iSerial 3 1125198948886 // iSerial 3 1125198948886
// bInterfaceClass 8 Mass Storage // bInterfaceClass 8 Mass Storage
// Don't include a path. The usbutils installer script installs // Don't include a path. The usbutils installer script installs
// to /usr/local/sbin and the Debian package installs to /usr/sbin/. // to /usr/local/sbin and the Debian package installs to /usr/sbin/.
CString sCommand = "lsusb"; CString sCommand = "lsusb";
char *szParams[] = { "lsusb", "-v", NULL }; char *szParams[] = { "lsusb", "-v", NULL };
CString sOutput; CString sOutput;
@@ -487,13 +487,13 @@ void GetNewStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
continue; // stop processing this line continue; // stop processing this line
} }
// Port 4 // Port 4
int iPort; int iPort;
iRet = sscanf( sLine.c_str(), "Port %d", &iPort ); iRet = sscanf( sLine.c_str(), "Port %d", &iPort );
if( iRet == 1 ) if( iRet == 1 )
{ {
usbd.iPort = iPort; usbd.iPort = iPort;
continue; // stop processing this line continue; // stop processing this line
} }
// iSerial 3 1125198948886 // iSerial 3 1125198948886