diff --git a/stepmania/src/MemoryCardManager.cpp b/stepmania/src/MemoryCardManager.cpp index 2e285448bd..2e1ce7d085 100644 --- a/stepmania/src/MemoryCardManager.cpp +++ b/stepmania/src/MemoryCardManager.cpp @@ -7,6 +7,7 @@ #include "RageLog.h" #include "ScreenManager.h" #include "ProfileManager.h" +#include "Foreach.h" MemoryCardManager* MEMCARDMAN = NULL; // global and accessable from anywhere in our program @@ -18,18 +19,12 @@ MemoryCardManager::MemoryCardManager() FOREACH_PlayerNumber( p ) { m_bTooLate[p] = false; - m_bWriteError[p] = false; } - m_pDriver->GetStorageDevices( m_vStorageDevices ); - - m_bDontPlaySoundsOnce = false; m_soundReady.Load( THEME->GetPathToS("MemoryCardManager ready") ); m_soundError.Load( THEME->GetPathToS("MemoryCardManager error") ); m_soundTooLate.Load( THEME->GetPathToS("MemoryCardManager too late") ); m_soundDisconnect.Load( THEME->GetPathToS("MemoryCardManager disconnect") ); - - UpdateUnassignedCards(); } MemoryCardManager::~MemoryCardManager() @@ -49,64 +44,168 @@ void MemoryCardManager::Update( float fDelta ) // check for disconnects - { - for( unsigned i=0; iIdsMatch(*newd) ) { - const UsbStorageDevice &old = vOld[i]; - if( find(vNew.begin(),vNew.end(),old) == vNew.end() ) // didn't find - { - LOG->Trace( ssprintf("Disconnected bus %d port %d device %d path %s", old.iBus, old.iPort, old.iLevel, old.sOsMountDir.c_str()) ); - vDisconnects.push_back( old ); - } + bFoundMatch = true; + break; } - } + } + if( !bFoundMatch ) + { + LOG->Trace( "Disconnected bus %d port %d device %d path %s", old->iBus, old->iPort, old->iLevel, old->sOsMountDir.c_str() ); + vDisconnects.push_back( *old ); + } + } // check for connects - { - for( unsigned i=0; iTrace( ssprintf("Connected bus %d port %d device %d path %s", newd.iBus, newd.iPort, newd.iLevel, newd.sOsMountDir.c_str()) ); - vConnects.push_back( newd ); - } - } - } + FOREACH( UsbStorageDevice, vNew, newd ) + { + bool bFoundMatch = false; + FOREACH( UsbStorageDevice, vOld, old ) + { + if( old->IdsMatch(*newd) ) + { + bFoundMatch = true; + break; + } + } + if( !bFoundMatch ) + { + LOG->Trace( "Connected bus %d port %d device %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() ); + vDisconnects.push_back( *newd ); + } + } // unassign cards that were disconnected - { - FOREACH_PlayerNumber( p ) - { - if( m_Device[p].IsBlank() ) // not assigned a card - continue; - - if( find(vDisconnects.begin(),vDisconnects.end(),m_Device[p]) != vDisconnects.end() ) // assigned card was disconnected - { - m_pDriver->Unmount(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); + FOREACH_PlayerNumber( p ) + { + UsbStorageDevice &assigned_device = m_Device[p]; + if( assigned_device.IsBlank() ) // not assigned a card + continue; + + FOREACH( UsbStorageDevice, vDisconnects, disconnect ) + { + if( disconnect->IdsMatch(assigned_device) ) + { + m_pDriver->Unmount(&assigned_device, MEM_CARD_MOUNT_POINT[p]); + + assigned_device.MakeBlank(); + m_soundDisconnect.Play(); + + if( PROFILEMAN->ProfileWasLoadedFromMemoryCard(p) ) + PROFILEMAN->UnloadProfile( p ); + } + } + } - m_Device[p].MakeBlank(); - m_soundDisconnect.Play(); + // Update the status of already-assigned cards. It may contain updated info + // like WriteTest results and a new sName. + FOREACH_PlayerNumber( p ) + { + UsbStorageDevice &assigned_device = m_Device[p]; + if( assigned_device.IsBlank() ) // no card assigned to this player + continue; - if( PROFILEMAN->ProfileWasLoadedFromMemoryCard((PlayerNumber)p) ) - PROFILEMAN->UnloadProfile( (PlayerNumber)p ); - } - } - } + FOREACH( UsbStorageDevice, m_vStorageDevices, d ) + { + if( d->IdsMatch(assigned_device) ) + { + // play write test error sound if write test failed since we last checked + if( assigned_device.bNeedsWriteTest && !d->bNeedsWriteTest && !d->bWriteTestSucceeded ) + m_soundError.Play(); + assigned_device = *d; + } + } + } - UpdateUnassignedCards(); + // make a list of unassigned + vector vUnassignedDevices = m_vStorageDevices; // copy + + // remove cards that are already assigned + FOREACH_PlayerNumber( p ) + { + UsbStorageDevice &assigned_device = m_Device[p]; + if( assigned_device.IsBlank() ) // no card assigned to this player + continue; + FOREACH( UsbStorageDevice, vUnassignedDevices, d ) + { + if( d->IdsMatch(assigned_device) ) + { + vUnassignedDevices.erase( d ); + break; + } + } + } + + // try to assign each device to a player + FOREACH_PlayerNumber( p ) + { + LOG->Trace( "Looking for a card for Player %d", p+1 ); + + UsbStorageDevice &assigned_device = m_Device[p]; + if( !assigned_device.IsBlank() ) // they already have an assigned card + { + LOG->Trace( "Player %d already has a card: '%s'", p+1, assigned_device.sOsMountDir.c_str() ); + continue; // skip + } + + FOREACH( UsbStorageDevice, vUnassignedDevices, d ) + { + // search for card dir match + if( !PREFSMAN->m_sMemoryCardOsMountPoint[p].empty() && + d->sOsMountDir.CompareNoCase(PREFSMAN->m_sMemoryCardOsMountPoint[p]) ) + continue; // not a match + + // search for USB bus match + if( PREFSMAN->m_iMemoryCardUsbBus[p] != -1 && + PREFSMAN->m_iMemoryCardUsbBus[p] != d->iBus ) + continue; // not a match + + if( PREFSMAN->m_iMemoryCardUsbPort[p] != -1 && + PREFSMAN->m_iMemoryCardUsbPort[p] != d->iPort ) + continue; // not a match + + if( PREFSMAN->m_iMemoryCardUsbLevel[p] != -1 && + PREFSMAN->m_iMemoryCardUsbLevel[p] != d->iLevel ) + continue; // not a match + + LOG->Trace( "device match: iScsiIndex: %d, iBus: %d, iLevel: %d, iPort: %d, sOsMountDir: %s", + d->iScsiIndex, d->iBus, d->iLevel, d->iPort, d->sOsMountDir.c_str() ); + + assigned_device = *d; // save a copy + vUnassignedDevices.erase( d ); // remove the device so we don't match it for another player + m_bTooLate[p] = m_bCardsLocked; // the device is too late if inserted when cards were locked + + // play sound + if( m_bTooLate[p] ) + m_soundTooLate.Play(); + else if( !d->bNeedsWriteTest && !d->bWriteTestSucceeded ) + m_soundError.Play(); + else + m_soundReady.Play(); + + break; + } + } + SCREENMAN->RefreshCreditsMessages(); } } MemoryCardState MemoryCardManager::GetCardState( PlayerNumber pn ) { - if( m_Device[pn].IsBlank() ) + UsbStorageDevice &d = m_Device[pn]; + if( d.IsBlank() ) return MEMORY_CARD_STATE_NO_CARD; else if( m_bTooLate[pn] ) return MEMORY_CARD_STATE_TOO_LATE; - else if( m_bWriteError[pn] ) + else if( !d.bNeedsWriteTest && !d.bWriteTestSucceeded ) return MEMORY_CARD_STATE_WRITE_ERROR; else return MEMORY_CARD_STATE_READY; @@ -133,10 +232,7 @@ void MemoryCardManager::LockCards( bool bLock ) if( m_Device[p].IsBlank() ) // they don't have an assigned card continue; - if( !m_pDriver->MountAndTestWrite(&m_Device[p], MEM_CARD_MOUNT_POINT[p]) ) - { - m_bWriteError[p] = true; - } + m_pDriver->MountAndTestWrite(&m_Device[p], MEM_CARD_MOUNT_POINT[p]); } } @@ -147,123 +243,19 @@ void MemoryCardManager::LockCards( bool bLock ) m_pDriver->SetMountThreadState( MemoryCardDriver::detect_and_mount ); } -void MemoryCardManager::UpdateUnassignedCards() -{ - LOG->Trace( "UpdateUnassignedCards" ); - - // make a list of unassigned - vector vUnassignedDevices = m_vStorageDevices; // copy - - // remove cards that are already assigned - { - FOREACH_PlayerNumber( p ) - { - if( m_Device[p].IsBlank() ) // no card assigned to this player - continue; - - vector::iterator it = find(vUnassignedDevices.begin(),vUnassignedDevices.end(),m_Device[p]); - if( it != vUnassignedDevices.end() ) - { - // TRICKY: Update m_Device with the latest info we received from the - // driver. It may contain updated info like WriteTest results and a - // sName. - m_Device[p] = *it; - - vUnassignedDevices.erase( it ); - } - } - } - - // try to assign each device to a player - { - FOREACH_PlayerNumber( p ) - { - LOG->Trace( "Looking for a card for Player %d", p+1 ); - - if( !m_Device[p].IsBlank() ) // they already have an assigned card - { - LOG->Trace( "Player %d already has a card: '%s'", p+1, m_Device[p].sOsMountDir.c_str() ); - continue; // skip - } - - unsigned i; - - // search for card dir match - if( !PREFSMAN->m_sMemoryCardOsMountPoint[p].empty() ) - { - for( i=0; im_sMemoryCardOsMountPoint[p]) == 0 ) // match - { - LOG->Trace( "dir match: iScsiIndex: %d, iBus: %d, iLevel: %d, iPort: %d", - usbd.iScsiIndex, usbd.iBus, usbd.iLevel, usbd.iPort ); - goto match; - } - } - } - - // search for USB bus match - for( i=0; im_iMemoryCardUsbBus[p] != -1 && - PREFSMAN->m_iMemoryCardUsbBus[p] != usbd.iBus ) - continue; // not a match - - if( PREFSMAN->m_iMemoryCardUsbPort[p] != -1 && - PREFSMAN->m_iMemoryCardUsbPort[p] != usbd.iPort ) - continue; // not a match - - if( PREFSMAN->m_iMemoryCardUsbLevel[p] != -1 && - PREFSMAN->m_iMemoryCardUsbLevel[p] != usbd.iLevel ) - continue; // not a match - - LOG->Trace( "bus/port match: iScsiIndex: %d, iBus: %d, iLevel: %d, iPort: %d", - usbd.iScsiIndex, usbd.iBus, usbd.iLevel, usbd.iPort ); - goto match; - } - - LOG->Trace( "Player %d memory card: none", p+1 ); - continue; // no matches -match: - m_Device[p] = vUnassignedDevices[i]; // save a copy - LOG->Trace( "Player %d memory card: '%s'", p+1, m_Device[p].sOsMountDir.c_str() ); - vUnassignedDevices.erase( vUnassignedDevices.begin()+i ); // remove the device so we don't match it for another player - m_bTooLate[p] = m_bCardsLocked; - m_bWriteError[p] = false; - - if( !m_bDontPlaySoundsOnce ) - { - // play sound - if( m_bWriteError[p] ) - m_soundError.Play(); - else if( m_bTooLate[p] ) - m_soundTooLate.Play(); - else - m_soundReady.Play(); - } - } - } - - m_bDontPlaySoundsOnce = false; -} - void MemoryCardManager::FlushAndReset() { FOREACH_PlayerNumber( p ) { - if( m_Device[p].IsBlank() ) // no card assigned + UsbStorageDevice &d = m_Device[p]; + if( d.IsBlank() ) // no card assigned continue; // skip - if( m_bWriteError[p] || m_bTooLate[p] ) + if( (!d.bNeedsWriteTest && !d.bWriteTestSucceeded) || m_bTooLate[p] ) continue; // skip m_pDriver->Flush(&m_Device[p]); } m_pDriver->ResetUsbStorage(); // forces cards to be re-detected - - m_bDontPlaySoundsOnce = true; } bool MemoryCardManager::PathIsMemCard( CString sDir ) const diff --git a/stepmania/src/MemoryCardManager.h b/stepmania/src/MemoryCardManager.h index 0a8eefe0a8..0fd92289cb 100644 --- a/stepmania/src/MemoryCardManager.h +++ b/stepmania/src/MemoryCardManager.h @@ -46,12 +46,8 @@ protected: bool m_bCardsLocked; bool m_bTooLate[NUM_PLAYERS]; // card was inserted after lock - bool m_bWriteError[NUM_PLAYERS]; // couldn't write to the card UsbStorageDevice m_Device[NUM_PLAYERS]; // device in the memory card slot, NULL if none - // don't play sounds on the first assign after resetting the driver - bool m_bDontPlaySoundsOnce; - RageSound m_soundReady; RageSound m_soundError; RageSound m_soundTooLate; diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp index 7eb23e4ab2..0fa5c37921 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver.cpp @@ -4,7 +4,7 @@ #include "arch/arch_platform.h" -bool UsbStorageDevice::operator==(const UsbStorageDevice& other) const +bool UsbStorageDevice::IdsMatch(const UsbStorageDevice& other) const { // LOG->Trace( "Comparing %d %d %d %s %s to %d %d %d %s %s", // iBus, iPort, iLevel, sName.c_str(), sOsMountDir.c_str(), diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h index cab1d1ab90..917c024ec9 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriver.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriver.h @@ -15,6 +15,8 @@ struct UsbStorageDevice sScsiDevice = ""; sSerial = ""; sOsMountDir = ""; + bNeedsWriteTest = true; + bWriteTestSucceeded = false; sName = ""; }; int iBus; @@ -24,16 +26,30 @@ struct UsbStorageDevice int iScsiIndex; CString sScsiDevice; CString sOsMountDir; // WITHOUT trailing slash - CString sName; // Name in the profile on the memory card. - // This is passed here because it's read in the mounting thread. - + bool bNeedsWriteTest; + bool bWriteTestSucceeded; // only valid if bNeedsWriteTest == false + CString sName; // Name in the profile on the memory card. + bool IsBlank() { return sOsMountDir.empty(); } - - bool operator==(const UsbStorageDevice& other) const; - bool operator!=(const UsbStorageDevice& other) const - { - return !operator==(other); - } + + bool operator==(const UsbStorageDevice& other) const + { +#define COMPARE(x) if( x != other.x ) return false; + COMPARE( iBus ); + COMPARE( iPort ); + COMPARE( iLevel ); + COMPARE( sSerial ); + COMPARE( iScsiIndex ); + COMPARE( sScsiDevice ); + COMPARE( sOsMountDir ); + COMPARE( sName ); + COMPARE( bNeedsWriteTest ); + COMPARE( bWriteTestSucceeded ); + COMPARE( sOsMountDir ); +#undef COMPARE + return true; + } + bool IdsMatch(const UsbStorageDevice& other) const; }; class MemoryCardDriver diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp index d17ca2691b..fd5392f82d 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp @@ -25,7 +25,6 @@ MemoryCardDriverThreaded::MemoryCardDriverThreaded() : m_mutexStorageDevices("StorageDevices") { m_bShutdownNextUpdate = false; - m_bForceRedetectNextUpdate = true; m_bStorageDevicesChanged = false; m_MountThreadState = detect_and_mount; } @@ -65,13 +64,6 @@ void MemoryCardDriverThreaded::SetMountThreadState( MountThreadState mts ) if( old == paused && mts != paused ) m_mutexPause.Unlock(); - if( old == detect_and_dont_mount && mts == detect_and_mount ) - { - m_bForceRedetectNextUpdate = true; - LockMut( m_mutexStorageDevices ); - m_vStorageDevices.clear(); - } - m_MountThreadState = mts; } @@ -121,7 +113,7 @@ void MemoryCardDriverThreaded::GetStorageDevices( vector& vDev bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice, CString sMountPoint ) { LockMut( m_mutexStorageDevices ); - vector::const_iterator iter = find( m_vStorageDevices.begin(), m_vStorageDevices.end(), *pDevice ); + vector::const_iterator iter = find( m_vStorageDevices.begin(), m_vStorageDevices.end(), *pDevice ); if( iter == m_vStorageDevices.end() ) { LOG->Warn( "Trying to mount a memory card that is no longer connected. bus %d port %d device %d path %s", pDevice->iBus, pDevice->iPort, pDevice->iLevel, pDevice->sOsMountDir.c_str() ); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h index 290f72ec3a..dad7b6a2b6 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h @@ -4,19 +4,6 @@ #include "MemoryCardDriver.h" #include "RageThreads.h" -struct UsbStorageDeviceEx : public UsbStorageDevice -{ - UsbStorageDeviceEx() { MakeBlank(); } - - void MakeBlank() - { - UsbStorageDevice::MakeBlank(); - bWriteTestSucceeded = false; - } - - bool bWriteTestSucceeded; -}; - class MemoryCardDriverThreaded : public MemoryCardDriver { public: @@ -49,11 +36,9 @@ protected: virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0; bool ShouldDoOsMount() { return m_MountThreadState==detect_and_mount; } - vector m_vStorageDevices; + vector m_vStorageDevices; bool m_bStorageDevicesChanged; RageMutex m_mutexStorageDevices; // protects the above two - bool m_bForceRedetectNextUpdate; // on the next update, redetect from scratch report new devices found - // placed here for use by derivitives to eliminate duplicate code void UnmountMountPoint( const CString &sMountPoint ); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index 2a367c3121..dd2d5f97ea 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -5,6 +5,7 @@ #include "RageFileManager.h" #include "Profile.h" #include "PrefsManager.h" +#include "Foreach.h" #include #include @@ -22,7 +23,7 @@ const CString TEMP_MOUNT_POINT = "@mctemp/"; static const char *USB_DEVICE_LIST_FILE = "/proc/bus/usb/devices"; static const char *ETC_MTAB = "/etc/mtab"; -void GetNewStorageDevices( vector& vDevicesOut ); +void GetNewStorageDevices( vector& vDevicesOut ); static int RunProgram( const char *path, char *const args[], CString &out ) { @@ -147,23 +148,22 @@ void MemoryCardDriverThreaded_Linux::ResetUsbStorage() // if usb-storage gets in a bad state, resetting usb-storage will sometimes fix it. // - LockMut( m_mutexStorageDevices ); - // unmount all devices before trying to remove the module - for( unsigned i=0; iTrace( "reset unmount %i/%i (%s)", i, m_vStorageDevices.size(), sCommand.c_str() ); + CString sCommand = "umount " + d->sOsMountDir; + LOG->Trace( "reset unmount (%s)", sCommand.c_str() ); ExecuteCommand( sCommand ); - LOG->Trace( "reset unmount %i/%i done", i, m_vStorageDevices.size() ); + LOG->Trace( "reset unmount done" ); + + // force a remount the next time cards aren't locked + d->bNeedsWriteTest = true; + d->bWriteTestSucceeded = false; } ExecuteCommand( "rmmod usb-storage" ); ExecuteCommand( "modprobe usb-storage" ); - m_bForceRedetectNextUpdate = true; - MountThreadDoOneUpdate(); } @@ -174,31 +174,40 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate() usleep( 50000 ); return; } - - if( m_bForceRedetectNextUpdate ) - { - m_vDevicesLastSeen.clear(); - m_bForceRedetectNextUpdate = false; - // fall through - } + + bool bNeedToDoAnyMounts = false; + for( unsigned i=0; iWarn( "Error polling: %s", strerror(errno) ); - return; - } - } - + { + pollfd pfd = { m_fd, POLLIN, 0 }; + int ret = poll( &pfd, 1, 100 ); + switch( ret ) + { + case 1: + // file changed. Fall through. + break; + case 0: // no change. Poll again. + return; + case -1: + if( errno != EINTR ) + LOG->Warn( "Error polling: %s", strerror(errno) ); + return; + } + } + // TRICKY: We're waiting for a change in the USB device list, but // the usb-storage descriptors take a bit longer to update. It's more convenient to wait // on the USB device list because the usb-storage descriptors are separate files per @@ -206,52 +215,89 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate() // usb-storage a chance to initialize. usleep(1000*300); - vector vDevicesNow; - GetNewStorageDevices( vDevicesNow ); - - vector &vNew = vDevicesNow; - vector &vOld = m_vDevicesLastSeen; + vector vNew; + GetNewStorageDevices( vNew ); + vector vOld = m_vDevicesLastSeen; // copy // check for disconnects - vector vDisconnects; - for( unsigned i=0; i vDisconnects; + FOREACH( UsbStorageDevice, vOld, old ) { - UsbStorageDeviceEx &old = vOld[i]; - if( find(vNew.begin(),vNew.end(),old) == vNew.end() )// didn't find + bool bMatch = false; + FOREACH( UsbStorageDevice, vNew, newd ) + { + if( old->IdsMatch(*newd) ) { - 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 ); + bMatch = true; + break; } + } + + if( !bMatch ) // 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 ); + + FOREACH( UsbStorageDevice, m_vDevicesLastSeen, d ) + { + if( old->IdsMatch(*d) ) + { + m_vDevicesLastSeen.erase( d ); + break; + } + } + } } + // check for connects - vector vConnects; - for( unsigned i=0; iTrace( "Connected bus %d port %d level %d path %s", newd.iBus, newd.iPort, newd.iLevel, newd.sOsMountDir.c_str() ); - vConnects.push_back( &newd ); - } - } - + vector vConnects; + FOREACH( UsbStorageDevice, vNew, newd ) + { + bool bMatch = false; + FOREACH( UsbStorageDevice, vOld, old ) + { + if( old->IdsMatch(*newd) ) + { + bMatch = true; + break; + } + } + + if( !bMatch ) // didn't find + { + LOG->Trace( "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; iTrace( "unmount disconnects %i/%i (%s)", i, vDisconnects.size(), sCommand.c_str() ); ExecuteCommand( sCommand ); LOG->Trace( "unmount disconnects %i/%i done", i, vDisconnects.size() ); } - // mount all connects - for( unsigned i=0; iTrace( "write test %s", d.bWriteTestSucceeded ? "succeeded" : "failed" ); + LOG->Trace( "WriteTest: %s, Name: %s", d.bWriteTestSucceeded ? "succeeded" : "failed", d.sName.c_str() ); } } - if( !vDisconnects.empty() || !vConnects.empty() ) + if( bDidAnyMounts || !vDisconnects.empty() || !vConnects.empty() ) { LockMut( m_mutexStorageDevices ); m_bStorageDevicesChanged = true; - m_vStorageDevices = vDevicesNow; - for( unsigned i=0; iTrace( "index %d, bWriteTestSucceeded %d", i, d.bWriteTestSucceeded ); - } + m_vStorageDevices = m_vDevicesLastSeen; } - m_vDevicesLastSeen = vDevicesNow; - CHECKPOINT; } -bool ReadUsbStorageDescriptor( CString fn, int iScsiIndex, vector& vDevicesOut ) +bool ReadUsbStorageDescriptor( CString fn, int iScsiIndex, vector& vDevicesOut ) { LOG->Trace( "ReadUsbStorageDescriptor %s", fn.c_str() ); @@ -348,7 +387,7 @@ bool ReadUsbStorageDescriptor( CString fn, int iScsiIndex, vector& vDevicesOut ) +void GetNewStorageDevices( vector& vDevicesOut ) { LOG->Trace( "GetNewStorageDevices" ); @@ -432,7 +471,7 @@ void GetNewStorageDevices( vector& vDevicesOut ) CStringArray vsLines; split( sOutput, "\n", vsLines ); - UsbStorageDeviceEx usbd; + UsbStorageDevice usbd; for( unsigned i=0; i m_vDevicesLastSeen; + vector m_vDevicesLastSeen; }; #endif