diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index dadc78d405..adecfde5ff 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -5,6 +5,8 @@ #include "ThemeManager.h" #include "PrefsManager.h" #include "RageLog.h" +#include "RageFileManager.h" +#include "RageFileDriver.h" #include "ScreenManager.h" #include "ProfileManager.h" #include "Foreach.h" @@ -12,6 +14,19 @@ MemoryCardManager* MEMCARDMAN = NULL; // global and accessable from anywhere in our program +const CString MEM_CARD_MOUNT_POINT[NUM_PLAYERS] = +{ + /* @ is importast; see RageFileManager LoadedDriver::GetPath */ + "@mc1/", + "@mc2/", +}; + +static const CString MEM_CARD_MOUNT_POINT_INTERNAL[NUM_PLAYERS] = +{ + /* @ is importast; see RageFileManager LoadedDriver::GetPath */ + "@mc1int/", + "@mc2int/", +}; MemoryCardManager::MemoryCardManager() { @@ -32,6 +47,12 @@ MemoryCardManager::MemoryCardManager() MemoryCardManager::~MemoryCardManager() { delete m_pDriver; + + FOREACH_PlayerNumber( pn ) + { + FILEMAN->Unmount( "", "", MEM_CARD_MOUNT_POINT[pn] ); + FILEMAN->Unmount( "", "", MEM_CARD_MOUNT_POINT_INTERNAL[pn] ); + } } void MemoryCardManager::Update( float fDelta ) @@ -265,13 +286,35 @@ void MemoryCardManager::UnmountAllUsedCards() void MemoryCardManager::MountCard( PlayerNumber pn ) { ASSERT( !m_Device[pn].IsBlank() ); - m_pDriver->MountAndTestWrite(&m_Device[pn], MEM_CARD_MOUNT_POINT[pn]); + + if( !m_pDriver->MountAndTestWrite(&m_Device[pn]) ) + return; + + /* If this is the first time we're mounting the device, mount the VFS drivers. + * Simply mounting our VFS on a directory doesn't actually touch the directory, + * so this isn't a timeout risk. (This is important for other reasons; for example, + * if we mount a CDROM, we should not spin up the disc simply by mounting it.) */ + RageFileDriver *pDriver = FILEMAN->GetFileDriver( MEM_CARD_MOUNT_POINT_INTERNAL[pn] ); + if( pDriver == NULL ) + { + FILEMAN->Mount( "dir", m_Device[pn].sOsMountDir, MEM_CARD_MOUNT_POINT_INTERNAL[pn] ); + FILEMAN->Mount( "timeout", MEM_CARD_MOUNT_POINT_INTERNAL[pn], MEM_CARD_MOUNT_POINT[pn] ); + } + else + { + /* It's already mounted. We don't want to unmount the timeout FS. Instead, just + * move the target. */ + pDriver->Remount( m_Device[pn].sOsMountDir ); + FILEMAN->ReleaseFileDriver( pDriver ); + } } void MemoryCardManager::UnmountCard( PlayerNumber pn ) { ASSERT( !m_Device[pn].IsBlank() ); - m_pDriver->Unmount(&m_Device[pn], MEM_CARD_MOUNT_POINT[pn]); + + /* Leave our own filesystem drivers mounted. */ + m_pDriver->Unmount( &m_Device[pn] ); } void MemoryCardManager::FlushAndReset() diff --git a/stepmania/src/MemoryCardManager.h b/stepmania/src/MemoryCardManager.h index 9586f9b964..e9012ab4d3 100644 --- a/stepmania/src/MemoryCardManager.h +++ b/stepmania/src/MemoryCardManager.h @@ -7,12 +7,7 @@ #include "arch/MemoryCard/MemoryCardDriver.h" -const CString MEM_CARD_MOUNT_POINT[NUM_PLAYERS] = -{ - /* @ is importast; see RageFileManager LoadedDriver::GetPath */ - "@mc1/", - "@mc2/", -}; +extern const CString MEM_CARD_MOUNT_POINT[NUM_PLAYERS]; class MemoryCardManager { diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h index e597af974b..3dae7b33b8 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h @@ -53,8 +53,8 @@ public: virtual ~MemoryCardDriver() {}; virtual bool StorageDevicesChanged() = 0; virtual void GetStorageDevices( vector& vStorageDevicesOut ) = 0; - virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint ) = 0; // return false if mount or write fails - virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0; + virtual bool MountAndTestWrite( UsbStorageDevice* pDevice ) = 0; // return false if mount or write fails + virtual void Unmount( UsbStorageDevice* pDevice ) = 0; virtual void Flush( UsbStorageDevice* pDevice ) = 0; virtual void ResetUsbStorage() = 0; enum MountThreadState diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp index 15194671f1..adf5fbd439 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp @@ -119,7 +119,7 @@ void MemoryCardDriverThreaded::GetStorageDevices( vector& vDev vDevicesOut.push_back( m_vStorageDevices[i] ); } -bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint ) +bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice ) { LockMut( m_mutexStorageDevices ); vector::const_iterator iter = find( m_vStorageDevices.begin(), m_vStorageDevices.end(), *pDevice ); @@ -132,10 +132,7 @@ bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice, CSt if( !iter->bWriteTestSucceeded ) return false; - /* Move the VFS mount to the destination. This is safe to do in the main thread. */ - FILEMAN->Remount( sMountPoint, pDevice->sOsMountDir ); - - this->Mount( pDevice, sMountPoint ); + this->Mount( pDevice ); return pDevice->bWriteTestSucceeded; } diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h index 156081618a..b058740030 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h @@ -12,7 +12,7 @@ public: virtual bool StorageDevicesChanged(); virtual void GetStorageDevices( vector& vStorageDevicesOut ); - virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint ); + virtual bool MountAndTestWrite( UsbStorageDevice* pDevice ); virtual void SetMountThreadState( MountThreadState mts ); private: @@ -34,7 +34,7 @@ protected: void StopThread(); // call this in the derived desstructor to stop the mounting thread virtual void MountThreadDoOneUpdate() = 0; // this will get called as fast as possible virtual bool MountThreadWaitForUpdate(); - virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0; + virtual void Mount( UsbStorageDevice* pDevice ) = 0; bool ShouldDoOsMount() { return m_MountThreadState==detect_and_mount; } vector m_vStorageDevices; diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index 7d2f073be4..381cf793c6 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -518,13 +518,10 @@ void GetNewStorageDevices( vector& vDevicesOut ) } -void MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice, CString sMountPoint ) +void MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice ) { ASSERT( !pDevice->sOsMountDir.empty() ); - FILEMAN->Mount( "dir", pDevice->sOsMountDir, sMountPoint.c_str() ); - LOG->Trace( "FILEMAN->Mount %s %s", pDevice->sOsMountDir.c_str(), sMountPoint.c_str() ); - // HACK: Do OS mount for m_bMemoryCardsMountOnlyWhenNecessary CString sCommand = "mount " + pDevice->sOsMountDir; LOG->Trace( "hack mount (%s)", sCommand.c_str() ); @@ -535,7 +532,7 @@ void MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice, CString s LOG->Trace( "WriteTest: %s, Name: %s", pDevice->bWriteTestSucceeded ? "succeeded" : "failed", pDevice->sName.c_str() ); } -void MemoryCardDriverThreaded_Linux::Unmount( UsbStorageDevice* pDevice, CString sMountPoint ) +void MemoryCardDriverThreaded_Linux::Unmount( UsbStorageDevice* pDevice ) { if( pDevice->sOsMountDir.empty() ) return; diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h index ca657ff8b0..336314764b 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h @@ -9,10 +9,10 @@ public: MemoryCardDriverThreaded_Linux(); virtual ~MemoryCardDriverThreaded_Linux(); - virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ); + virtual void Unmount( UsbStorageDevice* pDevice ); virtual void Flush( UsbStorageDevice* pDevice ); protected: - virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ); + virtual void Mount( UsbStorageDevice* pDevice ); virtual void ResetUsbStorage(); virtual void MountThreadDoOneUpdate(); virtual bool MountThreadWaitForUpdate(); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp index cece3923e0..68539ba1fa 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp @@ -106,7 +106,7 @@ void MemoryCardDriverThreaded_Windows::MountThreadDoOneUpdate() usbd.bWriteTestSucceeded = TestWrite( sDrive ); // read name - this->Mount( &usbd, TEMP_MOUNT_POINT ); + this->Mount( &usbd ); FILEMAN->Mount( "dir", usbd.sOsMountDir, TEMP_MOUNT_POINT_INTERNAL ); FILEMAN->Mount( "timeout", TEMP_MOUNT_POINT_INTERNAL, TEMP_MOUNT_POINT ); @@ -134,19 +134,14 @@ void MemoryCardDriverThreaded_Windows::MountThreadDoOneUpdate() } } -void MemoryCardDriverThreaded_Windows::Mount( UsbStorageDevice* pDevice, CString sMountPoint ) +void MemoryCardDriverThreaded_Windows::Mount( UsbStorageDevice* pDevice ) { - ASSERT( !pDevice->sOsMountDir.empty() ); - - LOG->Trace( "FILEMAN->Mount %s %s", pDevice->sOsMountDir.c_str(), sMountPoint.c_str() ); - // nothing to do here... } -void MemoryCardDriverThreaded_Windows::Unmount( UsbStorageDevice* pDevice, CString sMountPoint ) +void MemoryCardDriverThreaded_Windows::Unmount( UsbStorageDevice* pDevice ) { - - // nothing to do here... + // nothing to do here... } void MemoryCardDriverThreaded_Windows::Flush( UsbStorageDevice* pDevice ) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h index 0ec66ac540..b0d87bf92f 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h @@ -10,10 +10,10 @@ public: MemoryCardDriverThreaded_Windows(); virtual ~MemoryCardDriverThreaded_Windows(); - virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ); + virtual void Unmount( UsbStorageDevice* pDevice ); virtual void Flush( UsbStorageDevice* pDevice ); protected: - virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ); + virtual void Mount( UsbStorageDevice* pDevice ); virtual void ResetUsbStorage(); virtual void MountThreadDoOneUpdate(); virtual bool MountThreadWaitForUpdate(); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver_Null.h b/stepmania/src/arch/MemoryCard/MemoryCardDriver_Null.h index 17e0ec1692..5b9cc88cb4 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver_Null.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver_Null.h @@ -9,8 +9,8 @@ public: MemoryCardDriver_Null() {} virtual bool StorageDevicesChanged() { return false; } virtual void GetStorageDevices( vector& vStorageDevicesOut ) {} - virtual bool MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint ) { return false; } - virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ) {} + virtual bool MountAndTestWrite( UsbStorageDevice* pDevice ) { return false; } + virtual void Unmount( UsbStorageDevice* pDevice ) {} virtual void Flush( UsbStorageDevice* pDevice ) {} virtual void ResetUsbStorage() {} virtual void PauseMountingThread() {}