Implement pmount support for memory cards not found in fstab
authorMikko Rasa <tdb@tdb.fi>
Wed, 2 Nov 2011 15:47:40 +0000 (17:47 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 2 Nov 2011 15:47:40 +0000 (17:47 +0200)
src/MemoryCardManager.cpp
src/MemoryCardManager.h
src/arch/MemoryCard/MemoryCardDriver.h
src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp

index dbc4ed2..46edfc3 100755 (executable)
@@ -42,6 +42,8 @@ Preference<int> MemoryCardManager::m_iMemoryCardUsbLevel[NUM_PLAYERS] =
        Preference<int>("MemoryCardUsbLevelP2", -1)
 };
 
+Preference<bool> MemoryCardManager::m_bUsePmount( "UsePmount", false );
+
 Preference<CString>    MemoryCardManager::m_sEditorMemoryCardOsMountPoint( "EditorMemoryCardOsMountPoint",     "" );
 
 const CString MEM_CARD_MOUNT_POINT[NUM_PLAYERS] =
@@ -385,7 +387,10 @@ void MemoryCardManager::UpdateAssignments()
                        if( m_iMemoryCardUsbLevel[p] != -1 &&
                                m_iMemoryCardUsbLevel[p] != d->iLevel )
                                continue;       // not a match
-                       
+
+                       if( !m_bUsePmount && d->bUsePmount )
+                               continue;       // pmount disabled
+
                        LOG->Trace( "Player %i: matched %s", p+1, d->sDevice.c_str() );
 
                        assigned_device = *d;    // save a copy
index 526657a..c216028 100755 (executable)
@@ -47,6 +47,7 @@ public:
        static Preference<int>          m_iMemoryCardUsbBus[NUM_PLAYERS];
        static Preference<int>          m_iMemoryCardUsbPort[NUM_PLAYERS];
        static Preference<int>          m_iMemoryCardUsbLevel[NUM_PLAYERS];
+       static Preference<bool>         m_bUsePmount;
 
        static Preference<CString>      m_sEditorMemoryCardOsMountPoint;        
 
index da57d30..fd6fc68 100755 (executable)
@@ -14,6 +14,8 @@ struct UsbStorageDevice
                sDevice = "";
                sSerial = "<none>"; // be different than a card with no serial
                sOsMountDir = "";
+               bUsePmount = false;
+               sPmountLabel = "";
                m_State = STATE_NONE;
                bIsNameAvailable = false;
                sName = "";
@@ -30,6 +32,8 @@ struct UsbStorageDevice
        CString sSerial;
        CString sDevice;
        CString sOsMountDir;    // WITHOUT trailing slash
+       bool bUsePmount;
+       CString sPmountLabel;
        CString sSysPath;   // Linux: /sys/block name
        enum State
        {
index 59b5aa4..4e80fec 100755 (executable)
@@ -267,6 +267,8 @@ void MemoryCardDriverThreaded_Linux::GetUSBStorageDevices( vector<UsbStorageDevi
                                }
                        }
 
+                       usbd.sPmountLabel = "openitg-"+sDevice;
+
                        vDevicesOut.push_back( usbd );
                }
        }
@@ -320,14 +322,6 @@ void MemoryCardDriverThreaded_Linux::GetUSBStorageDevices( vector<UsbStorageDevi
                        }
                }
        }
-
-       for( unsigned i=0; i<vDevicesOut.size(); i++ )
-       {
-               UsbStorageDevice& usbd = vDevicesOut[i];
-               LOG->Trace( "    sDevice: %s, iBus: %d, iLevel: %d, iPort: %d, id: %04X:%04X, Vendor: '%s', Product: '%s', sSerial: \"%s\", sOsMountDir: %s",
-                               usbd.sDevice.c_str(), usbd.iBus, usbd.iLevel, usbd.iPort, usbd.idVendor, usbd.idProduct, usbd.sVendor.c_str(),
-                               usbd.sProduct.c_str(), usbd.sSerial.c_str(), usbd.sOsMountDir.c_str() );
-       }
        
        /* Remove any devices that we couldn't find a mountpoint for. */
        for( unsigned i=0; i<vDevicesOut.size(); i++ )
@@ -335,12 +329,30 @@ void MemoryCardDriverThreaded_Linux::GetUSBStorageDevices( vector<UsbStorageDevi
                UsbStorageDevice& usbd = vDevicesOut[i];
                if( usbd.sOsMountDir.empty() )
                {
-                       LOG->Trace( "Ignoring %s (couldn't find in /etc/fstab)", usbd.sDevice.c_str() );
-                       
-                       vDevicesOut.erase( vDevicesOut.begin()+i );
-                       --i;
+                       if( usbd.iBus != -1 )
+                       {
+                               LOG->Trace( "Using pmount for USB device %s", usbd.sDevice.c_str() );
+
+                               usbd.bUsePmount = true;
+                               usbd.sOsMountDir = "/media/"+usbd.sPmountLabel;
+                       }
+                       else
+                       {
+                               LOG->Trace( "Ignoring %s (couldn't find in /etc/fstab)", usbd.sDevice.c_str() );
+
+                               vDevicesOut.erase( vDevicesOut.begin()+i );
+                               --i;
+                       }
                }
        }
+
+       for( unsigned i=0; i<vDevicesOut.size(); i++ )
+       {
+               UsbStorageDevice& usbd = vDevicesOut[i];
+               LOG->Trace( "    sDevice: %s, iBus: %d, iLevel: %d, iPort: %d, id: %04X:%04X, Vendor: '%s', Product: '%s', sSerial: \"%s\", sOsMountDir: %s, bUsePmount: %d",
+                               usbd.sDevice.c_str(), usbd.iBus, usbd.iLevel, usbd.iPort, usbd.idVendor, usbd.idProduct, usbd.sVendor.c_str(),
+                               usbd.sProduct.c_str(), usbd.sSerial.c_str(), usbd.sOsMountDir.c_str(), usbd.bUsePmount );
+       }
        
        LOG->Trace( "Done with GetUSBStorageDevices" );
 }
@@ -350,8 +362,12 @@ bool MemoryCardDriverThreaded_Linux::Mount( UsbStorageDevice* pDevice )
 {
        ASSERT( !pDevice->sDevice.empty() );
        
-        CString sCommand = "mount " + pDevice->sDevice;
-        bool bMountedSuccessfully = ExecuteCommand( sCommand );
+       CString sCommand;
+       if( pDevice->bUsePmount )
+               sCommand = "pmount " + pDevice->sDevice + " " + pDevice->sPmountLabel;
+       else
+               sCommand = "mount " + pDevice->sDevice;
+       bool bMountedSuccessfully = ExecuteCommand( sCommand );
 
        return bMountedSuccessfully;
 }
@@ -366,7 +382,11 @@ void MemoryCardDriverThreaded_Linux::Unmount( UsbStorageDevice* pDevice )
         * by new devices until those are closed.  Without this, if something
         * causes the device to not unmount here, we'll never unmount it; that
         * causes a device name leak, eventually running us out of mountpoints. */
-       CString sCommand = "sync; umount -l \"" + pDevice->sDevice + "\"";
+       CString sCommand = "sync; ";
+       if( pDevice->bUsePmount )
+               sCommand += "pumount \"" + pDevice->sDevice + "\"";
+       else
+               sCommand += "umount -l \"" + pDevice->sDevice + "\"";
        ExecuteCommand( sCommand );
 }