diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index f9b80104ae..c95e817f7e 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -145,52 +145,37 @@ static bool BlockDevicesChanged() LOG->Trace( "Change in USB storage devices detected." ); return bChanged; } -#if 0 -bool MemoryCardDriverThreaded_Linux::MountThreadWaitForUpdate() + +bool MemoryCardDriverThreaded_Linux::NeedUpdate( bool bMount ) const { - /* Check if any devices need a write test. */ - for( unsigned i=0; i& vStorageDevicesOut ) { - if( !BlockDevicesChanged() ) + if( !NeedUpdate(bMount) ) return false; - vector vNew; - GetNewStorageDevices( vNew ); vector vOld = m_vDevicesLastSeen; // copy - - // check for disconnects - vector vDisconnects; - FOREACH( UsbStorageDevice, vOld, old ) - { - vector::iterator iter = find( vNew.begin(), vNew.end(), *old ); - if( iter == vNew.end() ) // 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 ); - - vector::iterator iter = find( m_vDevicesLastSeen.begin(), m_vDevicesLastSeen.end(), *old ); - ASSERT( iter != m_vDevicesLastSeen.end() ); - m_vDevicesLastSeen.erase( iter ); - } - } - + GetNewStorageDevices( vStorageDevicesOut ); + vector &vNew = vStorageDevicesOut; // check for connects vector vConnects; @@ -201,82 +186,71 @@ bool MemoryCardDriverThreaded_Linux::DoOneUpdate( bool bMount, vectorTrace( "Connected bus %d port %d level %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() ); vConnects.push_back( *newd ); - - m_vDevicesLastSeen.push_back( *newd ); } } - bool bDidAnyMounts = false; - - // unmount all disconnects - //if( ShouldDoOsMount() ) - for( unsigned i=0; i::iterator iter = find( vOld.begin(), vOld.end(), d ); + if( iter == vOld.end() ) // didn't find { - UsbStorageDevice &d = vDisconnects[i]; - CString sCommand = "umount " + d.sOsMountDir; - LOG->Trace( "unmount disconnects %i/%i (%s)", i, vDisconnects.size(), sCommand.c_str() ); - ExecuteCommand( sCommand ); - LOG->Trace( "unmount disconnects %i/%i done", i, vDisconnects.size() ); + d.m_State = UsbStorageDevice::STATE_CHECKING; + continue; } - - // mount all devices that need a write test - for( unsigned i=0; iTrace( "unmount old connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() ); - ExecuteCommand( sCommand ); // don't care if this fails - LOG->Trace( "unmount old connect %i/%i done", i, vConnects.size() ); - - sCommand = "mount " + d.sOsMountDir; - LOG->Trace( "mount new connect %i/%i (%s)", i, vConnects.size(), sCommand.c_str() ); + + /* If the device already existed, and was set to CHECKING, check the device + * now if we're allowed to. */ + if( iter->m_State == UsbStorageDevice::STATE_CHECKING ) + { + if( !bMount ) + { + /* We can't check it now. Keep the checking state and check it when + * we can. */ + d.m_State = UsbStorageDevice::STATE_CHECKING; + continue; + } + + CString sCommand = "mount " + d.sOsMountDir; bool bMountedSuccessfully = ExecuteCommand( sCommand ); - LOG->Trace( "mount new connect %i/%i done", i, vConnects.size() ); if( bMountedSuccessfully && TestWrite( d.sOsMountDir ) ) + { + /* We've successfully mounted and tested the device. Read the + * profile name (by mounting a temporary, private mountpoint), + * and then unmount it until Mount() is called. */ d.m_State = UsbStorageDevice::STATE_READY; + + FILEMAN->Mount( "dir", d.sOsMountDir, TEMP_MOUNT_POINT ); + + Profile profile; + CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/'; + profile.LoadEditableDataFromDir( sProfileDir ); + d.sName = profile.GetDisplayName(); + + FILEMAN->Unmount( "dir", d.sOsMountDir, TEMP_MOUNT_POINT ); + + CString sCommand = "umount " + d.sOsMountDir; + ExecuteCommand( sCommand ); + } else d.m_State = UsbStorageDevice::STATE_WRITE_ERROR; - - // read name - this->Mount( &d ); - FILEMAN->FlushDirCache( TEMP_MOUNT_POINT ); - - Profile profile; - CString sProfileDir = TEMP_MOUNT_POINT + PREFSMAN->m_sMemoryCardProfileSubdir + '/'; - profile.LoadEditableDataFromDir( sProfileDir ); - d.sName = profile.GetDisplayName(); LOG->Trace( "WriteTest: %s, Name: %s", d.m_State == UsbStorageDevice::STATE_WRITE_ERROR? "failed":"succeeded", d.sName.c_str() ); } } - if( bDidAnyMounts || !vDisconnects.empty() || !vConnects.empty() ) - { - vStorageDevicesOut = m_vDevicesLastSeen; - return true; - } + m_vDevicesLastSeen = vNew; CHECKPOINT; - return false; + return true; } struct WhiteListEntry @@ -523,10 +497,6 @@ bool MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice ) LOG->Trace( "hack mount (%s)", sCommand.c_str() ); bool bMountedSuccessfully = ExecuteCommand( sCommand ); -// pDevice->bWriteTestSucceeded = bMountedSuccessfully && TestWrite( pDevice->sOsMountDir ); -// -// LOG->Trace( "WriteTest: %s, Name: %s", pDevice->bWriteTestSucceeded ? "succeeded" : "failed", pDevice->sName.c_str() ); - return bMountedSuccessfully; } diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h index a657363dbf..7ab6c8be73 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h @@ -16,6 +16,8 @@ public: virtual void Reset(); protected: + bool NeedUpdate( bool bMount ) const; + vector m_vDevicesLastSeen; };