From 67d5bfd6d559dcfa0306582e0968456ef60b324d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 27 Jan 2005 03:43:55 +0000 Subject: [PATCH] RageFileManager::Remount --- stepmania/src/RageFileDriver.h | 3 +++ stepmania/src/RageFileDriverDirect.cpp | 21 ++++++++++++++------- stepmania/src/RageFileDriverDirect.h | 1 + stepmania/src/RageFileManager.cpp | 16 ++++++++++++++++ stepmania/src/RageFileManager.h | 5 +++++ 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/stepmania/src/RageFileDriver.h b/stepmania/src/RageFileDriver.h index bb015762f5..9995a72ca6 100644 --- a/stepmania/src/RageFileDriver.h +++ b/stepmania/src/RageFileDriver.h @@ -23,6 +23,9 @@ public: virtual void FlushDirCache( const CString &sPath ); virtual bool Remove( const CString &sPath ) { return false; } + /* Optional: Move to a different place, as if reconstructed with a different path. */ + virtual bool Remount( const CString &sPath ) { return false; } + /* Possible error returns from Open, in addition to standard errno.h values: */ enum { ERROR_WRITING_NOT_SUPPORTED = -1 }; // protected: diff --git a/stepmania/src/RageFileDriverDirect.cpp b/stepmania/src/RageFileDriverDirect.cpp index a3445fff60..6db9f4fbd8 100644 --- a/stepmania/src/RageFileDriverDirect.cpp +++ b/stepmania/src/RageFileDriverDirect.cpp @@ -54,14 +54,9 @@ public: RageFileDriverDirect::RageFileDriverDirect( CString root_ ): - RageFileDriver( new DirectFilenameDB(root_) ), - root(root_) + RageFileDriver( new DirectFilenameDB(root_) ) { - if( root.Right(1) != "/" ) - root += '/'; - - /* If the root path doesn't exist, create it. */ - CreateDirectories( root ); + Remount( root_ ); } @@ -176,6 +171,18 @@ bool RageFileDriverDirect::Ready() return PathReady( root ); } +bool RageFileDriverDirect::Remount( const CString &sPath ) +{ + root = sPath; + if( root.Right(1) != "/" ) + root += '/'; + + /* If the root path doesn't exist, create it. */ + CreateDirectories( root ); + + return true; +} + static const unsigned int BUFSIZE = 1024*64; RageFileObjDirect::RageFileObjDirect( const CString &path_, int fd_, int mode_ ) { diff --git a/stepmania/src/RageFileDriverDirect.h b/stepmania/src/RageFileDriverDirect.h index 5b91a04d09..96b5fba3ea 100644 --- a/stepmania/src/RageFileDriverDirect.h +++ b/stepmania/src/RageFileDriverDirect.h @@ -11,6 +11,7 @@ public: RageFileBasic *Open( const CString &path, int mode, int &err ); bool Remove( const CString &sPath ); bool Ready(); + bool Remount( const CString &sPath ); private: CString root; diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index 4589a51aab..3fe37fc112 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -498,6 +498,22 @@ void RageFileManager::Unmount( CString Type, CString Root, CString MountPoint ) } } +void RageFileManager::Remount( CString sMountpoint, CString sPath ) +{ + RageFileDriver *pDriver = FILEMAN->GetFileDriver( sMountpoint ); + if( pDriver == NULL ) + { + LOG->Warn( "Remount(%s,%s): mountpoint not found", + sMountpoint.c_str(), sPath.c_str() ); + return; + } + + if( !pDriver->Remount(sPath) ) + LOG->Warn( "Remount(%s,%s): remount failed (does the driver support remounting?)" ); + + FILEMAN->ReleaseFileDriver( pDriver ); +} + bool RageFileManager::IsMounted( CString MountPoint ) { LockMut( *g_Mutex ); diff --git a/stepmania/src/RageFileManager.h b/stepmania/src/RageFileManager.h index fb4212573b..6b778299e6 100644 --- a/stepmania/src/RageFileManager.h +++ b/stepmania/src/RageFileManager.h @@ -34,6 +34,11 @@ public: void Mount( CString Type, CString RealPath, CString MountPoint ); void Unmount( CString Type, CString Root, CString MountPoint ); + + /* Change the root of a filesystem. Only a couple drivers support this; it's + * used to change memory card mountpoints without having to actually unmount + * the driver. */ + static void Remount( CString sMountpoint, CString sPath ); bool IsMounted( CString MountPoint ); bool MountpointIsReady( CString MountPoint ); struct DriverLocation