From 60a89b8cf42d7c79e8314e6fa0a11d0ecbe921a3 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 29 Mar 2004 09:01:56 +0000 Subject: [PATCH] possibly fix stale card data used due to failed umount --- .../MemoryCard/MemoryCardDriver_Linux.cpp | 120 ++++++++++++------ 1 file changed, 80 insertions(+), 40 deletions(-) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriver_Linux.cpp index dba4dc5824..55c6c9d972 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver_Linux.cpp @@ -22,6 +22,21 @@ int MemoryCardDriver_Linux::MountThread_Start( void *p ) return 0; } +template +bool VectorsAreEqual( const T &a, const T &b ) +{ + if( a.size() != b.size() ) + return false; + + for( unsigned i=0; i vDevicesNow; this->GetStorageDevices( vDevicesNow ); - bool bDevicesChanged = false; - if( vDevicesLastSeen.size() != vDevicesNow.size() ) + vector &vNew = vDevicesNow; + vector &vOld = vDevicesLastSeen; + + // check for disconnects + vector vDisconnects; + for( unsigned i=0; iTrace( ssprintf("Disconnected bus %d port %d device %d path %s", old.iBus, old.iPortOnHub, old.iDeviceOnBus, old.sOsMountDir.c_str()) ); + vDisconnects.push_back( old ); } } - if( bDevicesChanged ) + // check for connects + vector vConnects; + for( unsigned i=0; iTrace( "executing '%s'", sCommand.c_str() ); - if( system(sCommand) == -1 ) - LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); - } - - for( unsigned i=0; iTrace( "executing '%s'", sCommand.c_str() ); - if( system(sCommand) == -1 ) - LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); + const UsbStorageDevice newd = vNew[i]; + 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()) ); + vConnects.push_back( newd ); } - - { - LockMut( m_StorageDevicesChangedMutex ); - m_bStorageDevicesChanged = true; - } } + + // unmount all disconnects + for( unsigned i=0; iTrace( "executing '%s'", sCommand.c_str() ); + if( system(sCommand) == -1 ) + LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); + } + + // mount all connects + for( unsigned i=0; iTrace( "executing '%s'", sCommand.c_str() ); + if( system(sCommand) == -1 ) + LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); + + sCommand = "mount " + d.sOsMountDir; + LOG->Trace( "executing '%s'", sCommand.c_str() ); + if( system(sCommand) == -1 ) + LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); + } + + if( !vDisconnects.empty() || !vConnects.empty() ) + { + LockMut( m_StorageDevicesChangedMutex ); + m_bStorageDevicesChanged = true; + } + vDevicesLastSeen = vDevicesNow; } usleep( 1000*100 ); // 100 ms @@ -384,13 +417,20 @@ void MemoryCardDriver_Linux::Flush( UsbStorageDevice* pDevice ) // very slow.) -glenn CString sCommand = "mount -o remount " + pDevice->sOsMountDir; LOG->Trace( "executing '%s'", sCommand.c_str() ); - system( sCommand ); + if( system(sCommand) == -1 ) + LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); + } void MemoryCardDriver_Linux::ResetUsbStorage() { - system( "rmmod usb-storage" ); - system( "modprobe usb-storage" ); + CString sCommand; + sCommand = "rmmod usb-storage"; + if( system(sCommand) == -1 ) + LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); + sCommand = "modprobe usb-storage"; + if( system(sCommand) == -1 ) + LOG->Warn( "failed to execute '%s'", sCommand.c_str() ); }