mount and unmount FILEMAN mountpoints in MemoryCardManager,

not drivers; use timeout FS; don't pass mountpoints to drivers since
they never need to know them
This commit is contained in:
Glenn Maynard
2005-01-27 19:23:54 +00:00
parent 7efbea62aa
commit 39604143f6
10 changed files with 64 additions and 37 deletions
+45 -2
View File
@@ -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()
+1 -6
View File
@@ -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
{
@@ -53,8 +53,8 @@ public:
virtual ~MemoryCardDriver() {};
virtual bool StorageDevicesChanged() = 0;
virtual void GetStorageDevices( vector<UsbStorageDevice>& 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
@@ -119,7 +119,7 @@ void MemoryCardDriverThreaded::GetStorageDevices( vector<UsbStorageDevice>& vDev
vDevicesOut.push_back( m_vStorageDevices[i] );
}
bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint )
bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice )
{
LockMut( m_mutexStorageDevices );
vector<UsbStorageDevice>::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;
}
@@ -12,7 +12,7 @@ public:
virtual bool StorageDevicesChanged();
virtual void GetStorageDevices( vector<UsbStorageDevice>& 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<UsbStorageDevice> m_vStorageDevices;
@@ -518,13 +518,10 @@ void GetNewStorageDevices( vector<UsbStorageDevice>& 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;
@@ -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();
@@ -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 )
@@ -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();
@@ -9,8 +9,8 @@ public:
MemoryCardDriver_Null() {}
virtual bool StorageDevicesChanged() { return false; }
virtual void GetStorageDevices( vector<UsbStorageDevice>& 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() {}