Revision: 201003 default
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 02 Feb 2010 00:24:33 +0200
changeset 2 b73a2e62868f
parent 1 acef663c1218
child 3 6752808b2036
Revision: 201003 Kit: 201005
clfwrapper/mediacollectionmanagersrc/mediacollectionmanagerimpl.cpp
harvester/client/inc/harvesterrequestactive.h
harvester/client/src/harvesterrequestqueue.cpp
harvester/common/inc/harvestercommon.h
harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp
harvester/monitorplugins/mdsfileserverplugin/src/mdsfileserverplugin.cpp
harvester/monitorplugins/mmcplugin/inc/mmcmounttaskao.h
harvester/monitorplugins/mmcplugin/inc/mmcscannerao.h
harvester/monitorplugins/mmcplugin/src/mmcfilelist.cpp
harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp
harvester/monitorplugins/mmcplugin/src/mmcmounttaskao.cpp
harvester/monitorplugins/mmcplugin/src/mmcscannerao.cpp
harvester/server/inc/harvesterao.h
harvester/server/src/harvesterao.cpp
harvester/server/src/harvesterqueue.cpp
inc/mdeharvestersession.h
inc/mdscommoninternal.h
locationmanager/locationtrail/inc/clocationrecord.h
locationmanager/locationtrail/inc/cpositioninfo.h
locationmanager/locationtrail/inc/ctracklog.h
mds_plat/location_manager_api/inc/locationdatatype.h
mds_plat/location_manager_api/inc/rlocationmanager.h
mds_plat/location_manager_api/inc/rlocationobjectmanipulator.h
mds_plat/location_manager_api/inc/rlocationtrail.h
mds_plat/location_manager_api/inc/rtracklog.h
metadataengine/client/bwincw/mdeclientu.def
metadataengine/client/eabi/mdeclientu.def
metadataengine/client/inc/mdeenginesession.h
metadataengine/client/inc/mdenotifierao.h
metadataengine/client/src/mdeenginesession.cpp
metadataengine/client/src/mdeharvestersession.cpp
metadataengine/client/src/mdesessionimpl.cpp
metadataengine/server/group/mdsserver.mmp
metadataengine/server/inc/mdsimportexport.h
metadataengine/server/inc/mdsmaintenanceengine.h
metadataengine/server/inc/mdsmanipulationengine.h
metadataengine/server/inc/mdsserversession.h
metadataengine/server/inc/mdssqlobjectmanipulate.h
metadataengine/server/src/mdsimportexport.cpp
metadataengine/server/src/mdsmaintenanceengine.cpp
metadataengine/server/src/mdsmanipulationengine.cpp
metadataengine/server/src/mdsnotifier.cpp
metadataengine/server/src/mdsnotifycomparator.cpp
metadataengine/server/src/mdsserver.cpp
metadataengine/server/src/mdsserversession.cpp
metadataengine/server/src/mdssqlobjectmanipulate.cpp
sis/mds/mds_stub.sis
sis/mds/package.pkg
sis/mds/package_separate.pkg
sis/mds/stub.pkg
--- a/clfwrapper/mediacollectionmanagersrc/mediacollectionmanagerimpl.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/clfwrapper/mediacollectionmanagersrc/mediacollectionmanagerimpl.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -84,6 +84,7 @@
     {
     User::Leave( KErrNotSupported );
 
+    // to stop compile warnings
     MMediaCollectionInfo* info = NULL;
     return info;
     }
@@ -99,6 +100,7 @@
     {
     User::Leave( KErrNotSupported );
 
+    // to stop compile warnings
     TInt collectionID( 0 );
     return collectionID;
     }
@@ -220,6 +222,7 @@
     {
     User::Leave( KErrNotSupported );
     
+    // to stop compile warnings
     const TInt drive( 0 );
     return drive;
     }
--- a/harvester/client/inc/harvesterrequestactive.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/client/inc/harvesterrequestactive.h	Tue Feb 02 00:24:33 2010 +0200
@@ -134,6 +134,8 @@
 private:
     // data
 
+    friend class CHarvesterRequestQueue;
+    
     /**
      * Session. Ref.
      */
@@ -157,7 +159,7 @@
     TBool iAddLocation;
     
     // not own
-    mutable CHarvesterRequestQueue* iRequestQueue;
+    CHarvesterRequestQueue* iRequestQueue;
     
     TPckg<TBool> iLocation;
     
--- a/harvester/client/src/harvesterrequestqueue.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/client/src/harvesterrequestqueue.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -125,7 +125,8 @@
         {
         CHarvesterRequestActive* selectedRequest = NULL;
     
-        for ( TInt i = 0; i < iRequests.Count(); i++ )
+        TInt endIndex( iRequests.Count() );
+        for ( TInt i = 0; i < endIndex; i++ )
             {
             CHarvesterRequestActive* request = iRequests[i];
         
@@ -139,10 +140,7 @@
             
                 // correct the index so that no tasks are skipped
                 i--;
-                if(i <= -1)
-                    {
-                    i = -1;
-                    }
+                endIndex--;
             
                 WRITELOG( "CHarvesterRequestQueue::RunL() - removing completed request");
                 }
@@ -233,6 +231,7 @@
         if( request )
             {
             request->Cancel();
+            request->iRequestQueue = NULL;
             }
         }
     }
--- a/harvester/common/inc/harvestercommon.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/common/inc/harvestercommon.h	Tue Feb 02 00:24:33 2010 +0200
@@ -91,7 +91,7 @@
 	};
 
 const TInt KHarvesterGetRootDirFlags = EDirsFirst;
-const TInt KHarvesterGetDirFlags = ESortByDate | EDescending | EDirsFirst;
+const TInt KHarvesterGetDirFlags = ESortByDate | EAscending | EDirsFirst;
 
 const TInt KOriginIgnored = 255;
 const TInt KOriginFastHarvest = 254;
@@ -101,6 +101,9 @@
 const CActive::TPriority KHarvesterPriorityComposerPlugin = CActive::EPriorityStandard;
 const CActive::TPriority KHarvesterPriorityHarvestingPlugin = CActive::EPriorityStandard;
 
+// Between Standard and UserInput to allow components to react to important events correctly
+const TInt KHarvesterCustomImportantPriority = 5;
+
 #endif
 
 
--- a/harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -441,27 +441,28 @@
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
                 *iPropDefs->iDatePropertyDef, &releaseDate, aIsAdd );
         }
-    
+
     if( iHarvestAlbumArt && iTNM && jpeg.Length() > 0 )
         {
-        HBufC8* jpegBuf = jpeg.AllocLC();
-        TBuf<KMimeLength> mimeType( KNullDesC );
+        HBufC8* jpegBuf = jpeg.AllocLC();  
+        _LIT( KAlbumArtMimeType, "image/jpeg" );
+        TBuf<KMimeLength> mimeType;
+        mimeType.Copy( KAlbumArtMimeType );
         CThumbnailObjectSource* tnmSource = CThumbnailObjectSource::NewL( jpegBuf, mimeType, uri );
+        // Ownership of buffer is transferred to Thumbnail Manager
         CleanupStack::Pop(); // jpegBuf
-        // Ownership of buffer is transferred to Thumbnail Manager
         iTNM->CreateThumbnails( *tnmSource );
         delete tnmSource;
         TBool thumbnailPresent( ETrue );
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
                           *iPropDefs->iThumbnailPropertyDef, &thumbnailPresent, aIsAdd );
         }
-    else if( iHarvestAlbumArt )
+    else if( iHarvestAlbumArt && iTNM )
         {
         TBool thumbnailNotPresent( EFalse );
         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
                           *iPropDefs->iThumbnailPropertyDef, &thumbnailNotPresent, aIsAdd );
         }
-       
     
     iAudioParser->ResetL();
     
--- a/harvester/monitorplugins/mdsfileserverplugin/src/mdsfileserverplugin.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/monitorplugins/mdsfileserverplugin/src/mdsfileserverplugin.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -391,9 +391,21 @@
             break;
 
 		case EFsFormatOpen:
+		    {
 			WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFormatOpen" );
 			// get the drive letter
-			err = iFsSession.Volume( volInfo, drvNumber );
+		    RFsPlugin fsplugin( aRequest ); 
+	        const TInt rfsPluginError( fsplugin.Connect() );
+	        if( rfsPluginError == KErrNone )
+	            {
+	            err = fsplugin.Volume( volInfo, drvNumber );
+	            }
+	        else
+	            {
+	            err = iFsSession.Volume( volInfo, drvNumber );
+	            }
+	        fsplugin.Close();
+	        
 			if( KErrNone == err )
 				{
 				iFormatOldMediaId = volInfo.iUniqueID;
@@ -406,6 +418,7 @@
 				iFormatDriveNumber = -1;
 				}
 			return KErrNone;
+		    }
 
 		case EFsFormatSubClose:
 			WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFormatSubClose" );
--- a/harvester/monitorplugins/mmcplugin/inc/mmcmounttaskao.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/monitorplugins/mmcplugin/inc/mmcmounttaskao.h	Tue Feb 02 00:24:33 2010 +0200
@@ -93,6 +93,7 @@
 		CMmcFileList* iMmcFileList;
 		CHarvesterEventManager* iHEM;
         TBool iCacheEvents;
+        RPointerArray<CHarvesterData> iHdArray;
 		
 	};
 
--- a/harvester/monitorplugins/mmcplugin/inc/mmcscannerao.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/monitorplugins/mmcplugin/inc/mmcscannerao.h	Tue Feb 02 00:24:33 2010 +0200
@@ -20,6 +20,7 @@
 #include <e32base.h>	// For CActive, link against: euser.lib
 
 #include <e32std.h>		// For RTimer, link against: euser.lib
+#include <harvesterdata.h>
 #include "mdeharvestersession.h"
 #include "mmcfilelist.h"
 
@@ -95,6 +96,8 @@
 	
 	// Not owned
 	MMonitorPluginObserver* iObserver;
+	
+	RPointerArray<CHarvesterData> iHdArray;
 	};
 
 #endif // CMMCSCANNERAO_H
--- a/harvester/monitorplugins/mmcplugin/src/mmcfilelist.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/monitorplugins/mmcplugin/src/mmcfilelist.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -87,7 +87,7 @@
 		RPointerArray<CPlaceholderData>& aEntryArray )
 	{
 	WRITELOG( "CMmcFileList::BuildFileListL - start" );
-	CDesCArrayFlat* path = new(ELeave) CDesCArrayFlat( 8 );
+	CDesCArrayFlat* path = new(ELeave) CDesCArrayFlat( 10 );
 	CleanupStack::PushL( path );
 	TFileName firstPath;
 	firstPath.Copy( aDrivePath );
@@ -191,14 +191,11 @@
 	WRITELOG( "CMmcFileList::HandleFileEntryL()" );
 	
 	// calculate batch size
-	TInt batchSize( 0 );
-	if ( aEntryArray.Count() >= KEntryBufferSize )
+	TInt batchSize( KEntryBufferSize );
+	const TInt count( aEntryArray.Count() );
+	if ( count < KEntryBufferSize )
 		{
-		batchSize = KEntryBufferSize;
-		}
-	else
-		{
-		batchSize = aEntryArray.Count();
+		batchSize = count;
 		}
 
 #ifdef _DEBUG
--- a/harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -24,8 +24,6 @@
 
 #include <e32cmn.h>
 
-const TInt KMassStorageScanCustomPriority = 5;
-
 _LIT( KColon, ":" );
 
 // construct/destruct
@@ -138,7 +136,7 @@
 			medias.Append( hdInfo );
 			
 			TRAP_IGNORE( iHddScanner = CMmcScannerAO::NewL( hdMediaId, iMdEClient, iObserver,
-			    				aHarvesterPluginFactory, KMassStorageScanCustomPriority, alreadyWaited ));
+			    				aHarvesterPluginFactory, KHarvesterCustomImportantPriority, alreadyWaited ));
 			}
 		}
 
--- a/harvester/monitorplugins/mmcplugin/src/mmcmounttaskao.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/monitorplugins/mmcplugin/src/mmcmounttaskao.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -29,8 +29,6 @@
 #include "harvesterplugininfo.h"
 #include "harvesterpluginfactory.h"
 
-const TInt KEntryBufferSize = 100;
-
 //-----------------------------------------------------------------------------
 // CMMCMountTaskAO
 //-----------------------------------------------------------------------------
@@ -58,7 +56,7 @@
 	}
 
 CMMCMountTaskAO::CMMCMountTaskAO() :
-		CActive( KHarvesterPriorityMonitorPlugin )
+		CActive( KHarvesterCustomImportantPriority )
 	{
 	WRITELOG( "CMMCMountTaskAO::CMMCMountTaskAO" );
 	}
@@ -81,6 +79,8 @@
 		}
 	
 	delete iMmcFileList;
+	iHdArray.ResetAndDestroy();
+	iHdArray.Close();
 	}
 	
 void CMMCMountTaskAO::SetMonitorObserver( MMonitorPluginObserver& aObserver )
@@ -156,6 +156,8 @@
 				iMountData = NULL;
 				}
 			
+			iHdArray.ResetAndDestroy();
+			
 			if( iMountDataQueue.Count() > 0 )
 				{
 				iMountData = iMountDataQueue[0];
@@ -279,7 +281,7 @@
 						}
 					Deinitialize();
 					SetNextRequest( ERequestStartTask );
-					break;
+					return;
 					}
 				
 	            if ( iEntryArray.Count() > 0 )
@@ -302,7 +304,6 @@
                 break;
 				}
 			}
-		break;
 		
 		case ERequestHandleReharvest:
 			{
@@ -318,13 +319,23 @@
 				{
 				HandleReharvestL( iHarvestEntryArray );
 				SetNextRequest( ERequestHandleReharvest );
+				break;
 				}
           	else
 				{
+                if ( iObserver )
+                    {
+                    if( iHdArray.Count() > 0)
+                        {
+                        iObserver->MonitorEvent( iHdArray );
+                        }
+                    }
+                iHdArray.Reset();
+                iHdArray.Compress();
 				SetNextRequest( ERequestHandleFileEntry );
+				break;
 				}
 			}
-		break;
 		
 		case ERequestCleanup:
 			{
@@ -394,22 +405,18 @@
 	{
 	WRITELOG("CMMCMountTaskAO::HandleReharvestL");
 	
-	TInt batchSize( 0 );
-	RPointerArray<CHarvesterData> hdArray;
-	CleanupClosePushL( hdArray );
-	
-	if ( aArray.Count() >= KEntryBufferSize )
+	const TInt count( aArray.Count() );
+	TInt batchSize( KMmcEntryBufferSize );
+	if ( count < KMmcEntryBufferSize )
 		{
-		batchSize = KEntryBufferSize;
+	    batchSize = count;
 		}
-	else
+
+	const TInt endIndex( count - batchSize );
+	
+	for ( TInt i = count; --i >= endIndex; )
 		{
-		batchSize = aArray.Count();
-		}
-			
-	for ( TInt i = 0; i < batchSize; i++ )
-		{
-		CPlaceholderData* ei = aArray[0];
+		CPlaceholderData* ei = aArray[i];
 		
 		HBufC* fileName = ei->Uri().AllocLC();
 		CHarvesterData* hd = CHarvesterData::NewL( fileName );
@@ -430,24 +437,14 @@
 			hd->SetClientData( ei );
 			}
 		
-		hdArray.Append( hd );
-		aArray.Remove( 0 );
+		iHdArray.Append( hd );
+		aArray.Remove( i );
 		}
 	
     if( aArray.Count() == 0 )
         {
         aArray.Compress();
         }
-			
-	if ( iObserver )
-		{
-		if( hdArray.Count() > 0)
-			{
-			iObserver->MonitorEvent( hdArray );
-			}
-		}
-	
-	CleanupStack::PopAndDestroy( &hdArray ); 
 	}
 	
 void CMMCMountTaskAO::RemoveNotPresentFromMDE()
--- a/harvester/monitorplugins/mmcplugin/src/mmcscannerao.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/monitorplugins/mmcplugin/src/mmcscannerao.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -17,13 +17,11 @@
 #include "mmcscannerao.h"
 #include "harvesterlog.h"
 #include "fsutil.h"
-#include <harvesterdata.h>
 #include <placeholderdata.h>
 #include <centralrepository.h>
 
 _LIT( KColon, ":" );
 
-const TInt KEntryBufferSize = 100;
 const TInt KDefaultDelay = 4;
 const TInt KMillion = 1000000;
 
@@ -95,6 +93,9 @@
 	iHarvestEntryArray.ResetAndDestroy();
 	iHarvestEntryArray.Close();
 	
+    iHdArray.ResetAndDestroy();
+	iHdArray.Close();
+	
 	iFs.Close();
 	}
 
@@ -165,6 +166,15 @@
 				}
 			else
 				{
+                if ( iObserver )
+                    {
+                    if( iHdArray.Count() > 0)
+                        {
+                        iObserver->MonitorEvent( iHdArray );
+                        }
+                    }
+                iHdArray.Reset();
+                iHdArray.Compress();
 				SetState( ERemoveNPFiles );
 				}
 			break;
@@ -181,6 +191,8 @@
 		case( EDone ):
 			{
 			iFs.Close();
+		    iHdArray.Reset();
+		    iHdArray.Compress();
 			iEntryArray.Compress();
 			iHarvestEntryArray.Compress();
 			break;
@@ -195,23 +207,19 @@
 void CMmcScannerAO::HandleReharvestL()
 	{
 	WRITELOG("CMMCMountTaskAO::HandleReharvestL");
-		
-	TInt batchSize( 0 );
-	RPointerArray<CHarvesterData> hdArray;
-	CleanupClosePushL( hdArray );
-	
-    if ( iHarvestEntryArray.Count() >= KEntryBufferSize )
+
+    const TInt count( iHarvestEntryArray.Count() );
+    TInt batchSize( KMmcEntryBufferSize );
+    if ( count < KMmcEntryBufferSize )
         {
-        batchSize = KEntryBufferSize;
+        batchSize = count;
         }
-    else
+
+    const TInt endIndex( count - batchSize );
+        
+    for ( TInt i = count; --i >= endIndex; )
         {
-        batchSize = iHarvestEntryArray.Count();
-        }
-        
-    for ( TInt i = 0; i < batchSize; i++ )
-        {
-        CPlaceholderData* ei = iHarvestEntryArray[0];
+        CPlaceholderData* ei = iHarvestEntryArray[i];
 
         HBufC* fileName = ei->Uri().AllocLC();
         CHarvesterData* hd = CHarvesterData::NewL( fileName );
@@ -231,28 +239,14 @@
 			hd->SetObjectType( EPlaceholder );
 			hd->SetClientData( ei );
 			}
-		hdArray.Append( hd );
-        iHarvestEntryArray.Remove( 0 );
+		iHdArray.Append( hd );
+        iHarvestEntryArray.Remove( i );
         }
 
     if( iHarvestEntryArray.Count() == 0 )
     	{
     	iHarvestEntryArray.Compress();
     	}
-    
-	if ( iObserver )
-		{
-		if( hdArray.Count() > 0)
-			{
-			iObserver->MonitorEvent( hdArray );
-			}
-		else
-			{
-			iObserver->MonitorEvent( hdArray[0] );
-			}
-		}
-	
-	CleanupStack::PopAndDestroy( &hdArray ); 
 	}
 	
 
--- a/harvester/server/inc/harvesterao.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/server/inc/harvesterao.h	Tue Feb 02 00:24:33 2010 +0200
@@ -534,6 +534,8 @@
         CHarvesterMediaIdUtil* iMediaIdUtil;
         
         CHarvesterAoPropertyDefs* iPropDefs;
+        
+        TBool iMassMemoryIdChecked;
 	};
 	
 #endif //__CHARVESTERAO_H__
--- a/harvester/server/src/harvesterao.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/server/src/harvesterao.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -17,6 +17,7 @@
 
 #include <e32svr.h>
 #include <caf/caf.h>
+#include <driveinfo.h>
 
 #include <rlocationobjectmanipulator.h>
 #include <placeholderdata.h>
@@ -47,8 +48,6 @@
 const TInt KContainerPlaceholderQueueSize = 10;
 const TInt KObjectDefStrSize = 20;
 
-const TInt KHarvesterAOCustomPriority = 5;
-
 _LIT( KTAGDaemonName, "ThumbAGDaemon" );
 _LIT( KTAGDaemonExe, "thumbagdaemon.exe" );
 
@@ -114,7 +113,7 @@
 // CHarvesterAO
 // ---------------------------------------------------------------------------
 //
-CHarvesterAO::CHarvesterAO() : CActive( KHarvesterAOCustomPriority)
+CHarvesterAO::CHarvesterAO() : CActive( KHarvesterCustomImportantPriority)
     {
     WRITELOG( "CHarvesterAO::CHarvesterAO() - begin" );
     
@@ -386,28 +385,46 @@
 	{
 	WRITELOG1( "CHarvesterAO::HandleUnmount(%d)", aMediaId );
 	
-    TUint32 mediaId(0);
-    TUint removed(0);
+    TUint32 mediaId( 0 );
+    TUint removed( 0 );
     CHarvesterData* hd = NULL;
-    
-#ifdef _DEBUG
-    WRITELOG1( "CHarvesterAO::HandleUnmount() iReadyPHArray.Count() = %d", iReadyPHArray.Count() );
-#endif
-	if( iReadyPHArray.Count() > 0 )
-		{
-		TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, iReadyPHArray.Count() ) );
-		TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, iReadyPHArray.Count()) );
-		iReadyPHArray.ResetAndDestroy();
-		}
 
     TInt err( KErrNone );
 	
 #ifdef _DEBUG
+	WRITELOG1( "CHarvesterAO::HandleUnmount() iReadyPHArray.Count() = %d", iReadyPHArray.Count() );
+#endif
+	TInt arrayCount( iReadyPHArray.Count() );
+	if( arrayCount > 0 )
+        {
+        for( TInt i=arrayCount-1; i>= 0; i--)
+            {
+            hd = iPHArray[i];
+            err = iMediaIdUtil->GetMediaId( hd->Uri(), mediaId );
+            
+            if( err == KErrNone && mediaId == aMediaId )
+                {
+                WRITELOG1( "CHarvesterAO::HandleUnmount() remove iReadyPHArray %d", i);
+                delete hd;
+                hd = NULL;
+                iReadyPHArray.Remove( i );
+                removed++;
+                arrayCount--;
+                }
+            }
+        WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iReadyPHArray %d", removed);
+        TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed) );
+        }
+   
+   removed = 0;
+	
+#ifdef _DEBUG
 	WRITELOG1( "CHarvesterAO::HandleUnmount() iPHArray.Count() = %d", iPHArray.Count() );
 #endif
-   if( iPHArray.Count() > 0 )
+	arrayCount = iPHArray.Count();
+   if( arrayCount > 0 )
         {
-        for( TInt i=iPHArray.Count()-1; i>= 0; i--)
+        for( TInt i=arrayCount-1; i>= 0; i--)
             {
             hd = iPHArray[i];
             err = iMediaIdUtil->GetMediaId( hd->Uri(), mediaId );
@@ -419,6 +436,7 @@
 				hd = NULL;
                 iPHArray.Remove( i );
                 removed++;
+                arrayCount--;
                 }
             }
         WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iPHArray %d", removed);
@@ -430,9 +448,10 @@
 #ifdef _DEBUG
    WRITELOG1( "CHarvesterAO::HandleUnmount() iContainerPHArray.Count() = %d", iContainerPHArray.Count() );
 #endif
-   if( iContainerPHArray.Count() > 0 )
+   arrayCount = iContainerPHArray.Count();
+   if( arrayCount > 0 )
         {
-        for( TInt i=iContainerPHArray.Count()-1; i>= 0; i--)
+        for( TInt i=arrayCount-1; i>= 0; i--)
             {
             hd = iContainerPHArray[i];
             err = iMediaIdUtil->GetMediaId( hd->Uri(), mediaId );
@@ -444,18 +463,21 @@
 				hd = NULL;
                 iContainerPHArray.Remove( i );
                 removed++;
+                arrayCount--;
                 }
             }
         WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iContainerPHArray %d", removed);
         TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed) );
         }
-	
-	TUint count = iQueue->ItemsInQueue();
+
+   removed = 0;
+   
+	const TUint count = iQueue->ItemsInQueue();
 	WRITELOG1( "CHarvesterAO::HandleUnmount() iQueue.Count() = %d", count );
 	if( count > 0 )
 	    {
 	    WRITELOG( "CHarvesterAO::HandleUnmount() remove iQueue" );
-	    TUint removed = iQueue->RemoveItems( aMediaId );
+	    removed = iQueue->RemoveItems( aMediaId );
 	    WRITELOG1( "CHarvesterAO::HandleUnmount() removed iQueue = %d", removed );
 	    TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed ) );
         TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, removed ) );
@@ -466,15 +488,15 @@
 	removed = 0;
 	
 	RPointerArray<CHarvesterPluginInfo>& hpiArray = iHarvesterPluginFactory->GetPluginInfos();
-	const TInt arrayCount( hpiArray.Count() );
-	if( arrayCount > 0 )
+	const TInt hpiArrayCount( hpiArray.Count() );
+	if( hpiArrayCount > 0 )
 		{
 		RArray<TItemId> placeholders;
 		
 		TUint32 mediaId( 0 );
 		TInt err( KErrNone );
 		
-		for( TInt i = arrayCount; --i >= 0; )
+		for( TInt i = hpiArrayCount; --i >= 0; )
 			{
 			CHarvesterPluginInfo* hpi = hpiArray[i];
 			for( TInt j = hpi->iQueue.Count(); --j >= 0; )
@@ -668,7 +690,8 @@
 	
 	TInt fastHarvestPlaceholderCount = 0;
 	
-	for (TInt i = iPHArray.Count() ; --i >= 0;)
+	TInt endindex( iPHArray.Count() );
+	for( TInt i = 0; i < endindex; i++ )
 		{
 		CHarvesterData* hd = iPHArray[i];
 		
@@ -676,6 +699,8 @@
 			{
 			iContainerPHArray.Append( hd );
 			iPHArray.Remove( i );
+            i--;
+            endindex--;
 			continue;
 			}
 		TBuf<KObjectDefStrSize> objDefStr;
@@ -690,6 +715,8 @@
 			delete hd;
 			hd = NULL;
 			iPHArray.Remove( i );
+            i--;
+            endindex--;
 			iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 );
 			continue;
 			}
@@ -717,6 +744,8 @@
 				delete hd;
 				hd = NULL;
 				iPHArray.Remove( i );
+	            i--;
+	            endindex--;
 				iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 );
 				CleanupStack::PopAndDestroy( entry );
 				CleanupStack::PopAndDestroy( phData );
@@ -743,6 +772,8 @@
 				delete hd;
 				hd = NULL;
 				iPHArray.Remove( i );
+	            i--;
+	            endindex--;
 				iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 );
 				continue;
 		    	}	
@@ -764,7 +795,7 @@
     	mdeObject->AddUint32PropertyL( *iPropDefs->iSizePropertyDef, phData->FileSize() );
 
 	    // set creation date
-    	TTime localModifiedDate = phData->Modified() + timeOffsetSeconds;
+    	const TTime localModifiedDate = phData->Modified() + timeOffsetSeconds;
     	mdeObject->AddTimePropertyL( *iPropDefs->iCreationDatePropertyDef, localModifiedDate );
 
 	    // set modification date
@@ -812,6 +843,8 @@
 		
 		iReadyPHArray.Append( hd );
 		iPHArray.Remove( i );
+        i--;
+        endindex--;
 		}
 	
 	const TInt objectCount = mdeObjectArray.Count();  
@@ -1219,6 +1252,28 @@
             }
         TRAP_IGNORE( BootPartialRestoreScanL() );
 #endif
+        
+        if( !iMassMemoryIdChecked )
+            {
+            TInt drive( -1 );
+            TInt massStorageError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) );
+            if( massStorageError == KErrNone )
+                {
+                TVolumeInfo massStorageVolumeInfo;
+                iFs.Volume( massStorageVolumeInfo, drive );
+                const TUint32 massStorageMediaId( massStorageVolumeInfo.iUniqueID );
+                massStorageError = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
+                if( massStorageError == KErrNone )
+                    {
+                    iFs.Volume( massStorageVolumeInfo, drive );
+                    // Update mass storage media id if the mass storage is not memory card
+                    if( massStorageVolumeInfo.iUniqueID != massStorageMediaId && massStorageMediaId != 0 )
+                        {
+                        iMdEHarvesterSession->CheckMassStorageMediaId( massStorageMediaId );
+                        }
+                    }
+                }
+            }
         }
     else
         {
@@ -1344,16 +1399,19 @@
 #ifdef _DEBUG
             		WRITELOG1("CHarvesterAO::RunL - items in ready pharray: %d", iReadyPHArray.Count() );
 #endif   		
-            		const TInt beginIndex( iReadyPHArray.Count() );
-            		TInt endIndex( beginIndex - KPlaceholderQueueSize );
-            		if( endIndex < 0 )
+            		const TInt arrayCount( iReadyPHArray.Count() );
+            		TInt endIndex( KPlaceholderQueueSize );
+            		if( arrayCount < KPlaceholderQueueSize )
             		    {
-            		    endIndex = 0;
+            		    endIndex = arrayCount;
             		    }
-            		for ( TInt i = beginIndex; --i >= endIndex; )
+            		for( TInt i = 0; i < endIndex; i++ )
             			{
                 		CheckFileExtensionAndHarvestL( iReadyPHArray[i] );
                 		iReadyPHArray.Remove( i );
+                        // correct the index so harvesting order remains ok
+                        i--;
+                        endIndex--;
             			}
             		if( iReadyPHArray.Count() )
             		    {
@@ -2255,6 +2313,26 @@
 	{
 	WRITELOG("CHarvesterAO::BootScanL() - begin");
 
+	
+    TInt drive( -1 );
+    TInt massStorageError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) );
+    if( massStorageError == KErrNone )
+        {
+        TVolumeInfo massStorageVolumeInfo;
+        iFs.Volume( massStorageVolumeInfo, drive );
+        const TUint32 massStorageMediaId( massStorageVolumeInfo.iUniqueID );
+        massStorageError = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
+        if( massStorageError == KErrNone )
+            {
+            iFs.Volume( massStorageVolumeInfo, drive );
+            // Update mass storage media id if the mass storage is not memory card
+            if( massStorageVolumeInfo.iUniqueID != massStorageMediaId && massStorageMediaId != 0 )
+                {
+                iMdEHarvesterSession->CheckMassStorageMediaId( massStorageMediaId );
+                }
+            }
+        }
+	
 	TVolumeInfo volumeInfo;
 	iFs.Volume( volumeInfo, EDriveC );
 
@@ -2268,6 +2346,7 @@
 	
 	RPointerArray<CHarvesterData> hdArray;
 	CleanupClosePushL( hdArray );
+	TBool rootDir( ETrue );
 	
 	while( aScanItems.Count() > 0 )
 		{
@@ -2275,8 +2354,17 @@
 		TUint32 preinstalled = aScanItems[0]->iPreinstalled;
 
 		CDir* directory = NULL;
-		TInt error = iFs.GetDir( folder->Des(), KEntryAttDir, KHarvesterGetDirFlags, directory );
-		
+		TInt error( KErrNone );
+        if( rootDir )
+            {
+            error = iFs.GetDir( folder->Des(), KEntryAttDir, KHarvesterGetRootDirFlags, directory );
+            rootDir = EFalse;
+            }
+        else
+            {
+            error = iFs.GetDir( folder->Des(), KEntryAttDir, KHarvesterGetDirFlags, directory );
+            }
+
 		if ( error == KErrNone )
 			{
 			CleanupStack::PushL( directory );
@@ -2407,6 +2495,8 @@
 
 	iMdEHarvesterSession->RemoveFilesNotPresent( volumeInfo.iUniqueID, ETrue );
 	
+	iMassMemoryIdChecked = ETrue;
+	
 	WRITELOG("CHarvesterAO::BootScanL() - end");
 	}
 
--- a/harvester/server/src/harvesterqueue.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/harvester/server/src/harvesterqueue.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -244,7 +244,8 @@
 void CHarvesterQueue::MonitorEvent(
         RPointerArray<CHarvesterData>& aHarvesterDataArray )
     {
-    for( TInt i = aHarvesterDataArray.Count(); --i >= 0; )
+    const TInt count( aHarvesterDataArray.Count() );
+    for( TInt i = 0; i < count; i++ )
     	{
     	MonitorEvent( aHarvesterDataArray[i] );
     	}
--- a/inc/mdeharvestersession.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/inc/mdeharvestersession.h	Tue Feb 02 00:24:33 2010 +0200
@@ -326,6 +326,11 @@
 	 */
 	IMPORT_C void ResetDBL();
 
+	/**
+	 * Update DB with current internal mass storage media id
+	 */
+    void CheckMassStorageMediaId( const TUint32 aMediaId );
+
 private:
 	CMdESessionImpl* iSession;
 
--- a/inc/mdscommoninternal.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/inc/mdscommoninternal.h	Tue Feb 02 00:24:33 2010 +0200
@@ -48,6 +48,9 @@
 _LIT( KSchemaChunkName, "MdSSchema" );
 
 _LIT( KCMediaIdKey, "CDriveMediaId" );
+_LIT( KMassStorageMediaIdKey, "MassStorageMediaId" );
+
+const TInt KMmcEntryBufferSize = 100;
 
 // The server version. A version must be specified when
 // creating a session with the server.
@@ -124,6 +127,7 @@
     EGetPending,			// Get objects with pending flag
     EResetDB,              	// Reset database (works only in DEBUG build)
     EChangeMediaId,			// Change C-drive media id and update objects
+    EChangeMassStorageMediaId,         // Change internal mass storage media id and update objects
     EUnknownMdEServRqst     // handle for unknown requests
     };
 
--- a/locationmanager/locationtrail/inc/clocationrecord.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/locationmanager/locationtrail/inc/clocationrecord.h	Tue Feb 02 00:24:33 2010 +0200
@@ -20,7 +20,7 @@
 
 #include <e32base.h>
 #include <e32property.h>
-#include <Lbs.h>
+#include <lbs.h>
 
 #include "rlocationtrail.h"
 #include "locationdatatype.h"
--- a/locationmanager/locationtrail/inc/cpositioninfo.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/locationmanager/locationtrail/inc/cpositioninfo.h	Tue Feb 02 00:24:33 2010 +0200
@@ -19,8 +19,8 @@
 #ifndef C_CPOSITIONINFO_H
 #define C_CPOSITIONINFO_H
 
-#include <Lbs.h>
-#include <LbsSatellite.h>
+#include <lbs.h>
+#include <lbssatellite.h>
 #include "rlocationtrail.h"
 
 /**
--- a/locationmanager/locationtrail/inc/ctracklog.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/locationmanager/locationtrail/inc/ctracklog.h	Tue Feb 02 00:24:33 2010 +0200
@@ -20,9 +20,9 @@
 #define CTRACKLOG_H_
 
 #include <f32file.h>
-#include <Lbs.h>
+#include <lbs.h>
 #include "clocationrecord.h"
-#include <LbsSatellite.h>
+#include <lbsSatellite.h>
 
 class MTrackLogObserver;
 class CGpxConverterAO;
--- a/mds_plat/location_manager_api/inc/locationdatatype.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/mds_plat/location_manager_api/inc/locationdatatype.h	Tue Feb 02 00:24:33 2010 +0200
@@ -17,7 +17,7 @@
 #ifndef LOCATIONDATATYPE_H_
 #define LOCATIONDATATYPE_H_
 
-#include <LbsPosition.h>
+#include <lbsposition.h>
 #include <etel3rdparty.h>
 
 /*
--- a/mds_plat/location_manager_api/inc/rlocationmanager.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/mds_plat/location_manager_api/inc/rlocationmanager.h	Tue Feb 02 00:24:33 2010 +0200
@@ -19,7 +19,7 @@
 #define R_RLOCATIONMANAGER_H
 
 #include <e32base.h>
-#include <LbsPosition.h>
+#include <lbsposition.h>
 #include <etel3rdparty.h>
 
 /**
--- a/mds_plat/location_manager_api/inc/rlocationobjectmanipulator.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/mds_plat/location_manager_api/inc/rlocationobjectmanipulator.h	Tue Feb 02 00:24:33 2010 +0200
@@ -21,7 +21,7 @@
 #include <locationdatatype.h>
 #include <etel3rdparty.h>
 #include <rlocationmanager.h>
-#include <LbsPosition.h> 
+#include <lbsposition.h> 
 
 #include "mdccommon.h"
 
--- a/mds_plat/location_manager_api/inc/rlocationtrail.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/mds_plat/location_manager_api/inc/rlocationtrail.h	Tue Feb 02 00:24:33 2010 +0200
@@ -20,7 +20,7 @@
 
 #include <e32base.h>
 #include <etel3rdparty.h>
-#include <LbsPosition.h>
+#include <lbsposition.h>
 #include <rlocationmanager.h>
 #include <locationdatatype.h>
 
--- a/mds_plat/location_manager_api/inc/rtracklog.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/mds_plat/location_manager_api/inc/rtracklog.h	Tue Feb 02 00:24:33 2010 +0200
@@ -18,7 +18,7 @@
 #ifndef RTRACKLOG_H_
 #define RTRACKLOG_H_
 
-#include <LbsSatellite.h> 
+#include <lbssatellite.h> 
 #include <rlocationmanager.h>
 #include <locationeventdef.h>
 
--- a/metadataengine/client/bwincw/mdeclientu.def	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/client/bwincw/mdeclientu.def	Tue Feb 02 00:24:33 2010 +0200
@@ -294,4 +294,5 @@
 	?SetPendingL@CMdEHarvesterSession@@QAEXABV?$RArray@K@@@Z @ 293 NONAME ; void CMdEHarvesterSession::SetPendingL(class RArray<unsigned long> const &)
 	?PlaceholderOnly@CMdEObjectCondition@@QBEHXZ @ 294 NONAME ; int CMdEObjectCondition::PlaceholderOnly(void) const
 	?SetPlaceholderOnly@CMdEObjectCondition@@QAEXH@Z @ 295 NONAME ; void CMdEObjectCondition::SetPlaceholderOnly(int)
+	?CheckMassStorageMediaId@CMdEHarvesterSession@@QAEXK@Z @ 296 NONAME ; void CMdEHarvesterSession::CheckMassStorageMediaId(unsigned long)
 
--- a/metadataengine/client/eabi/mdeclientu.def	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/client/eabi/mdeclientu.def	Tue Feb 02 00:24:33 2010 +0200
@@ -365,4 +365,5 @@
 	_ZN20CMdEHarvesterSession13ResetPendingLERK6RArrayImE @ 364 NONAME
 	_ZN19CMdEObjectCondition18SetPlaceholderOnlyEi @ 365 NONAME
 	_ZNK19CMdEObjectCondition15PlaceholderOnlyEv @ 366 NONAME
+	_ZN20CMdEHarvesterSession23CheckMassStorageMediaIdEm @ 367 NONAME
 
--- a/metadataengine/client/inc/mdeenginesession.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/client/inc/mdeenginesession.h	Tue Feb 02 00:24:33 2010 +0200
@@ -465,6 +465,11 @@
 		 */
 		void DoChangeCDriveMediaId();
 		
+        /**
+         * Change intenal mass storage media id in the DB and update objects accordingly
+         */
+        void DoCheckMassStorageMediaId( const TUint32 aMediaId );
+		
 		/**
 		 * Set "binary composing to file" pending flag to objects
 		 *
--- a/metadataengine/client/inc/mdenotifierao.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/client/inc/mdenotifierao.h	Tue Feb 02 00:24:33 2010 +0200
@@ -130,7 +130,6 @@
         */
         void DoNotifyObserver();
 		
-		
 		void DecodeIdBufferL();
 		void DecodeRelationItemBufferL();
 
--- a/metadataengine/client/src/mdeenginesession.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/client/src/mdeenginesession.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -808,9 +808,19 @@
 
 void RMdEEngineSession::DoChangeCDriveMediaId()
 	{
-	SendReceive( EChangeMediaId );
+	Send( EChangeMediaId );
 	}
 
+void RMdEEngineSession::DoCheckMassStorageMediaId( const TUint32 aMediaId  )
+    {
+    TPckgC<TUint32> mediaIdPckg( aMediaId );
+
+    TIpcArgs ipcArgs;
+    ipcArgs.Set( 0, &mediaIdPckg );
+
+    SendReceive( EChangeMassStorageMediaId, ipcArgs );
+    }
+
 void RMdEEngineSession::DoSetPendingL( const RArray<TItemId>& aObjectIds )
 	{
 	HBufC8* idBuffer = SerializeArrayL( aObjectIds );
--- a/metadataengine/client/src/mdeharvestersession.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/client/src/mdeharvestersession.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -342,3 +342,8 @@
 			aObjectIdBuffer );
 	}
 
+EXPORT_C void CMdEHarvesterSession::CheckMassStorageMediaId( const TUint32 aMediaId  )
+    {
+    iSession->EngineSession().DoCheckMassStorageMediaId( aMediaId );
+    }
+
--- a/metadataengine/client/src/mdesessionimpl.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/client/src/mdesessionimpl.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -2523,6 +2523,7 @@
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
+    	iNotifiers.Compress();
         }
     else
     	{
@@ -2544,6 +2545,7 @@
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
+    	iNotifiers.Compress();
         }
     else
     	{
@@ -2574,6 +2576,7 @@
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
+    	iNotifiers.Compress();
         }
     else
     	{
@@ -2627,6 +2630,7 @@
     	delete iNotifiers[index];
     	iNotifiers[index] = NULL;
     	iNotifiers.Remove( index );
+    	iNotifiers.Compress();
         }
     else
     	{
--- a/metadataengine/server/group/mdsserver.mmp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/group/mdsserver.mmp	Tue Feb 02 00:24:33 2010 +0200
@@ -93,6 +93,7 @@
 LIBRARY           flogger.lib
 LIBRARY           hash.lib
 LIBRARY			  inetprotutil.lib
+LIBRARY           platformenv.lib 
 
 UNPAGED
 
--- a/metadataengine/server/inc/mdsimportexport.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/inc/mdsimportexport.h	Tue Feb 02 00:24:33 2010 +0200
@@ -520,6 +520,8 @@
     TInt iLastDriveNumber;
     
     TVolumeInfo iLastVolumeInfo;
+    
+    TBool iLogEnabled;
     };
 
 
--- a/metadataengine/server/inc/mdsmaintenanceengine.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/inc/mdsmaintenanceengine.h	Tue Feb 02 00:24:33 2010 +0200
@@ -82,9 +82,9 @@
                               CMdCSerializationBuffer& aItems );
         
         /**
-         * Stores C-drive media id to the DB.
+         * Stores drive media id to the DB.
          */
-        void StoreCDriveMediaIdL();
+        void StoreDriveMediaIdsL();
 
   	    /**
 	    * Creates metadata tables to database.
--- a/metadataengine/server/inc/mdsmanipulationengine.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/inc/mdsmanipulationengine.h	Tue Feb 02 00:24:33 2010 +0200
@@ -240,7 +240,12 @@
 		 * Updates C drive media id for all objects with the old media id. 
 		 */
 		void ChangeMediaIdL();
-		
+
+        /**
+         * Updates internal mass storage media id for all objects. 
+         */
+        void CheckMassStorageMediaIdL( const TUint32 aMediaId );
+        
 		/**
 		 * Adds new relation definition to the DB.
 		 * @param aNamespaceId namespace id
--- a/metadataengine/server/inc/mdsserversession.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/inc/mdsserversession.h	Tue Feb 02 00:24:33 2010 +0200
@@ -306,6 +306,11 @@
         void ChangeMediaIdL( const RMessage2& aMessage );
         
         /**
+         * Check media id of internal mass storage to DB and update items accordingly
+         */
+        void CheckMassStorageMediaIdL( const RMessage2& aMessage );
+        
+        /**
          * Set "binary composing to file" pending flag to objects.
          * 
          * @param aMessage message from client where first argument is 
--- a/metadataengine/server/inc/mdssqlobjectmanipulate.h	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/inc/mdssqlobjectmanipulate.h	Tue Feb 02 00:24:33 2010 +0200
@@ -465,6 +465,8 @@
 		 */
 		TInt GetPendingL(TDefId aObjectDefId, TInt aBufferSize, 
 				RArray<TItemId>& aObjectIds);
+
+		void CheckMassStorageMediaIdL( const TUint32 aMediaId );
 		
     protected: // personal methods
 
--- a/metadataengine/server/src/mdsimportexport.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdsimportexport.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -51,10 +51,12 @@
 const TInt KMdsMaxUriLenght = KMaxFileName;
 const TChar KMdsLineFeed = '\n';
 
+#ifdef _DEBUG
 const TInt KMdsMaxLogLineLenght( 2056 );
 
 _LIT( KMdsErrorLogDirectory, "Metadata" );
 _LIT( KMdsErrorLogFilename, "importerror.log" );
+#endif
 
 // keyword definitions in import file
 _LIT8( KMdsKeywordComment,     "//" );
@@ -117,8 +119,13 @@
 	{
    	delete iConverter;
 
-    iLog.CloseLog(); 
-    iLog.Close();
+#ifdef _DEBUG
+   	if( iLogEnabled )
+   	    {
+        iLog.CloseLog(); 
+        iLog.Close();
+   	    }
+#endif
     iFs.Close();
 
    	delete iBuffer;
@@ -136,10 +143,16 @@
 
     User::LeaveIfError( iFs.Connect() );
     iConverter->PrepareToConvertToOrFromL( KCharacterSetIdentifierUtf8, iFs );
-    
-    User::LeaveIfError( iLog.Connect( ) );
-    iLog.CreateLog( KMdsErrorLogDirectory, KMdsErrorLogFilename, EFileLoggingModeOverwrite );
-    iLog.SetDateAndTime(EFalse, ETrue);
+
+#ifdef _DEBUG
+    const TInt logError( iLog.Connect( ) );
+    if( logError == KErrNone )
+        {
+        iLogEnabled = ETrue;
+        iLog.CreateLog( KMdsErrorLogDirectory, KMdsErrorLogFilename, EFileLoggingModeOverwrite );
+        iLog.SetDateAndTime(EFalse, ETrue);
+        }
+#endif
 
 	iBuffer = NULL;
     iLastObjectDef = NULL;
@@ -2474,19 +2487,28 @@
 // LogError
 // ------------------------------------------------
 //
+#ifdef _DEBUG
 void CMdsImportExport::LogError( const TDesC& aMessage )
     {
-    _LIT( KParseError, "Parse error: %S" );
-    _LIT( KCurrentFile, "Current file: %S" );
-    _LIT( KCurrentLineNum, "Current line number: %d" );
-    _LIT( KCurrentLine, "Current line: %S" );
-    iLog.WriteFormat( KParseError, &aMessage );
-    iLog.WriteFormat( KCurrentFile, &iFileName );
-    iLog.WriteFormat( KCurrentLineNum, iLineNumber );
-    TBuf16<KMdsMaxLogLineLenght> line16;
-    Conv8To16( iLine, line16 );
-    iLog.WriteFormat( KCurrentLine, &line16 );
+    if( iLogEnabled )
+        {
+        _LIT( KParseError, "Parse error: %S" );
+        _LIT( KCurrentFile, "Current file: %S" );
+        _LIT( KCurrentLineNum, "Current line number: %d" );
+        _LIT( KCurrentLine, "Current line: %S" );
+        iLog.WriteFormat( KParseError, &aMessage );
+        iLog.WriteFormat( KCurrentFile, &iFileName );
+        iLog.WriteFormat( KCurrentLineNum, iLineNumber );
+        TBuf16<KMdsMaxLogLineLenght> line16;
+        Conv8To16( iLine, line16 );
+        iLog.WriteFormat( KCurrentLine, &line16 );
+        }
     }
+#else
+void CMdsImportExport::LogError( const TDesC& /*aMessage*/ )
+    {
+    }
+#endif
 
 
 // ------------------------------------------------
--- a/metadataengine/server/src/mdsmaintenanceengine.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdsmaintenanceengine.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -16,6 +16,8 @@
 */
 
 // INCLUDE FILES
+#include <driveinfo.h>
+
 #include "mdsmaintenanceengine.h"
 #include "mdslogger.h"
 #include "mdsmanipulationengine.h"
@@ -153,7 +155,7 @@
        		TRAP_IGNORE( ImportMetadataL( aManipulate, aSchema, KMdsDefaultRomImportFile ) );
        		}
        	
-       	StoreCDriveMediaIdL();
+       	StoreDriveMediaIdsL();
         }
     else
         {
@@ -226,10 +228,10 @@
     }
 
 // ------------------------------------------------
-// StoreCDriveMediaIdL
+// StoreDriveMediaIdsL
 // ------------------------------------------------
 //
-void CMdSMaintenanceEngine::StoreCDriveMediaIdL()
+void CMdSMaintenanceEngine::StoreDriveMediaIdsL()
 	{
 	RFs fs;
     User::LeaveIfError( fs.Connect() );
@@ -238,6 +240,26 @@
     fs.Volume( volumeInfo, EDriveC );
     MMdsPreferences::InsertL( KCMediaIdKey, MMdsPreferences::EPreferenceValueSet,
     		(TUint32) volumeInfo.iUniqueID );
+
+    TInt drive( -1 );
+    TInt massStorageError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) );
+    if( massStorageError == KErrNone )
+        {
+        TVolumeInfo massStorageVolumeInfo;
+        fs.Volume( massStorageVolumeInfo, drive );
+        const TUint32 massStorageMediaId( massStorageVolumeInfo.iUniqueID );
+        massStorageError = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive );
+        if( massStorageError == KErrNone )
+            {
+            fs.Volume( massStorageVolumeInfo, drive );
+            // Update mass storage media id if the mass storage is not memory card
+            if( massStorageVolumeInfo.iUniqueID != massStorageMediaId && massStorageMediaId != 0 )
+                {
+                MMdsPreferences::InsertL( KMassStorageMediaIdKey, MMdsPreferences::EPreferenceValueSet,
+                        (TUint32) massStorageMediaId );
+                }
+            }
+        }
     
     CleanupStack::PopAndDestroy( &fs );
 	}
--- a/metadataengine/server/src/mdsmanipulationengine.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdsmanipulationengine.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -1002,6 +1002,20 @@
 	CleanupStack::PopAndDestroy( &transaction );
 	}
 
+void CMdSManipulationEngine::CheckMassStorageMediaIdL( const TUint32 aMediaId )
+    {
+    CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
+    RMdSTransaction transaction( connection );
+    CleanupClosePushL( transaction );
+    User::LeaveIfError( transaction.Error() );
+    
+    iManipulate->CheckMassStorageMediaIdL( aMediaId );
+    
+    transaction.CommitL();
+
+    CleanupStack::PopAndDestroy( &transaction );
+    }
+
 void CMdSManipulationEngine::AddRelationDefL( TDefId aNamespaceId, const TDesC& aRelationDefName )
 	{
 	CMdsNamespaceDef* namespaceDef = CONST_CAST( CMdsNamespaceDef*, iSchema.GetNamespaceByIdL( aNamespaceId ) );
--- a/metadataengine/server/src/mdsnotifier.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdsnotifier.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -468,7 +468,7 @@
 		aSerializedItems.PositionL( KNoOffset );
 		aSerializedItemIds.PositionL( KNoOffset );
 
-		TBool someMatches = iComparator->MatchL( e.NamespaceDefId(), e.iType, e.Condition(), 
+		const TBool someMatches = iComparator->MatchL( e.NamespaceDefId(), e.iType, e.Condition(), 
 												 aSerializedItems, aSerializedItemIds, 
 												 matchingItemIdArray,
 												 e.AllowConfidential() );
@@ -561,9 +561,12 @@
     		}
 		}
 
-	if( objectIdArray.Count() != 0 
-			|| eventIdArray.Count() != 0 
-			|| relationIdArray.Count() != 0 )
+	const TInt objectCount( objectIdArray.Count() );
+	const TInt eventCount( eventIdArray.Count() );
+	const TInt relationCount( relationIdArray.Count() );
+	if( objectCount != 0 
+			|| eventCount != 0 
+			|| relationCount != 0 )
 		{
 		const TInt entriesCount = iEntries.Count();
 	    for( TInt i=0; i < entriesCount; ++i )
@@ -581,13 +584,13 @@
 	        	continue;	
 	        	}
 
-	        if( e.iType & EObjectNotifyRemove && objectIdArray.Count() > 0 )
+	        if( e.iType & EObjectNotifyRemove && objectCount > 0 )
 	            {
 	            // collect matching object IDs
 	            RArray<TItemId> matchingObjectIdArray;
 				CleanupClosePushL( matchingObjectIdArray );
 	
-	            TBool allMatches = iComparator->MatchObjectIdsL( e.Condition(),
+	            const TBool allMatches = iComparator->MatchObjectIdsL( e.Condition(),
 	            		objectIdArray, matchingObjectIdArray );
 	
 				// check is there any matches
@@ -634,7 +637,7 @@
 				CleanupStack::PopAndDestroy( &matchingObjectIdArray );
 				}
 	        else if( ( e.iType & EEventNotifyRemove ) 
-	        		&& eventIdArray.Count() > 0 )
+	        		&& eventCount > 0 )
             	{
 				// event condition can't contain ID conditions, 
             	// so get all IDs
@@ -655,7 +658,7 @@
 	        		}
             	}
 	        else if( ( e.iType & ERelationNotifyRemove ) 
-	        		&& relationIdArray.Count() > 0 )
+	        		&& relationCount > 0 )
             	{
 	            // relation condition can't contain ID conditions, 
             	// so get all IDs
@@ -677,7 +680,6 @@
             	}
 	        }
 		}
-
 	CleanupStack::PopAndDestroy( 3, &objectIdArray ); // relationIdArray, eventIdArray, objectIdArray
     }
 
@@ -694,7 +696,7 @@
         {
         TEntry& e = iEntries[i];
 
-        if ( ! (e.iType & ( EObjectNotifyModify | ERelationNotifyModify /*| ERelationItemNotifyModify*/ ) ) )
+        if ( ! (e.iType & ( EObjectNotifyModify | ERelationNotifyModify ) ) )
         	{
         	continue;
         	}
@@ -705,7 +707,7 @@
 		aSerializedItems.PositionL( KNoOffset );
 		aSerializedItemIds.PositionL( KNoOffset );
 
-		TBool someMatches = iComparator->MatchL( e.NamespaceDefId(), 
+		const TBool someMatches = iComparator->MatchL( e.NamespaceDefId(), 
 				e.iType, e.Condition(), aSerializedItems, aSerializedItemIds, 
 				matchingObjectIdArray, e.AllowConfidential() );
 
@@ -714,7 +716,7 @@
             if( e.IsPending() )
             	{
             	// match found. trigger notifier entry !
-	            TRAPD( err, e.TriggerL( EObjectNotifyModify | ERelationNotifyModify /*| ERelationItemNotifyModify*/,
+	            TRAPD( err, e.TriggerL( EObjectNotifyModify | ERelationNotifyModify,
 	            		matchingObjectIdArray ) );
 	            if( err != KErrNone )
 	            	{
@@ -723,7 +725,7 @@
             	}
             else
             	{
-            	TRAP_IGNORE( e.CacheL( EObjectNotifyModify | ERelationNotifyModify /*| ERelationItemNotifyModify*/,
+            	TRAP_IGNORE( e.CacheL( EObjectNotifyModify | ERelationNotifyModify,
             			matchingObjectIdArray ) );
             	}
             }
@@ -755,7 +757,7 @@
             RArray<TItemId> matchingObjectIdArray;
 			CleanupClosePushL( matchingObjectIdArray );
 
-            TBool allMatches = iComparator->MatchObjectIdsL( e.Condition(), 
+                const TBool allMatches = iComparator->MatchObjectIdsL( e.Condition(),
             		aObjectIds, matchingObjectIdArray );
 
 			// check is there any matches
@@ -764,7 +766,7 @@
             	if(e.IsPending())
             		{
 	            	// Match found. Trigger notifier entry.
-	            	TInt err;
+	            	TInt err( KErrNone );
 
 	            	if( allMatches )
 	            		{
@@ -810,7 +812,8 @@
 //
 void CMdSNotifier::NotifyRemovedL(const RArray<TItemId>& aItemIdArray)
 	{
-    for( TInt i=0; i<iEntries.Count(); ++i )
+    const TInt entriesCount( iEntries.Count() );
+    for( TInt i=0; i<entriesCount; ++i )
         {
         TEntry& e = iEntries[i];
 
--- a/metadataengine/server/src/mdsnotifycomparator.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdsnotifycomparator.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -151,7 +151,7 @@
     	}
     else if( ( items.iEvents.iPtr.iCount > 0 ) && 
     		 ( itemIds.iEventIds.iPtr.iCount > 0 ) && 
-    		 ( aType & ( EEventNotifyAdd /*| EEventNotifyRemove*/ ) ) )
+    		 ( aType & ( EEventNotifyAdd ) ) )
     	{
     	// event ID count and event item count should match
 		__ASSERT_DEBUG( items.iEvents.iPtr.iCount == itemIds.iEventIds.iPtr.iCount, MMdCCommon::Panic( KErrCorrupt ) );
@@ -183,7 +183,7 @@
     	}
     else if( ( items.iRelations.iPtr.iCount > 0 ) && 
     		 ( itemIds.iRelationIds.iPtr.iCount > 0 ) && 
-    		 ( aType & ( ERelationNotifyAdd | ERelationNotifyModify /*| ERelationNotifyRemove*/ ) ) )
+    		 ( aType & ( ERelationNotifyAdd | ERelationNotifyModify ) ) )
     	{
     	// relation ID count and relation item count should match
 		__ASSERT_DEBUG( items.iRelations.iPtr.iCount == itemIds.iRelationIds.iPtr.iCount, MMdCCommon::Panic( KErrCorrupt ) );
--- a/metadataengine/server/src/mdsserver.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdsserver.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -93,6 +93,7 @@
     EGetPending,
     EResetDB,
     EChangeMediaId,
+    EChangeMassStorageMediaId,
     EUnknownMdEServRqst     // handle for unknown requests
     };
 
@@ -140,7 +141,8 @@
     CPolicyServer::ECustomCheck, 	// EGetPendingCount
     CPolicyServer::ECustomCheck, 	// EGetPending
     CPolicyServer::ECustomCheck, 	// EResetDB
-    CPolicyServer::ECustomCheck, 	// EChangeMediaId
+    CPolicyServer::ECustomCheck,    // EChangeMediaId
+    CPolicyServer::ECustomCheck,    // EChangeMassStorageMediaId
     CPolicyServer::ENotSupported	// EUnknownMdEServRqst
     };
 
@@ -170,6 +172,7 @@
         case EAddRelationDef:
         case EAddEventDef:
         case EImportSchema:
+        case EChangeMassStorageMediaId:
         case ESetObjectToPresentByGuid:
             {
             if( aMsg.HasCapability( ECapabilityWriteDeviceData ) )
--- a/metadataengine/server/src/mdsserversession.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdsserversession.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -410,6 +410,12 @@
         	ChangeMediaIdL( aMessage );
         	break;
         	}	
+
+        case EChangeMassStorageMediaId:
+            {
+            CheckMassStorageMediaIdL( aMessage );
+            break;
+            }   
         	
         case ESetPending:
         	{
@@ -1509,6 +1515,15 @@
 	iServer.Manipulate().ChangeMediaIdL();
 	}
 
+void CMdSServerSession::CheckMassStorageMediaIdL( const RMessage2& aMessage )
+    {
+    TUint32 mediaId;
+    TPckg<TUint32> mediaIdPckg( mediaId );
+    aMessage.ReadL( 0, mediaIdPckg );
+
+    iServer.Manipulate().CheckMassStorageMediaIdL( mediaId );
+    }
+
 void CMdSServerSession::SetPendingL(const RMessage2& aMessage)
 	{
 	const TInt serializedObjectIdsLength = aMessage.GetDesLength( 0 );
--- a/metadataengine/server/src/mdssqlobjectmanipulate.cpp	Tue Jan 26 12:13:20 2010 +0200
+++ b/metadataengine/server/src/mdssqlobjectmanipulate.cpp	Tue Feb 02 00:24:33 2010 +0200
@@ -1020,6 +1020,27 @@
 	CleanupStack::PopAndDestroy( &clauseOne );
 	}
 
+void CMdSSqlObjectManipulate::CheckMassStorageMediaIdL( const TUint32 aMediaId )
+    {
+    TUint32 oldMediaId( 0 );
+    const TInt rowCount = MMdsPreferences::GetL( KMassStorageMediaIdKey, 
+                                                                 MMdsPreferences::EPreferenceValueGet, oldMediaId );
+    if( rowCount == 0 )
+        {
+        MMdsPreferences::InsertL( KMassStorageMediaIdKey, MMdsPreferences::EPreferenceValueSet, (TUint32) aMediaId );
+        }
+    else if( aMediaId != oldMediaId )
+        {
+        RArray<TItemId> objectIds;
+        CleanupClosePushL( objectIds );
+        MMdsPreferences::UpdateL( KMassStorageMediaIdKey, MMdsPreferences::EPreferenceValueSet, (TUint32) aMediaId );
+        SetFilesToNotPresentL( oldMediaId, EFalse, objectIds );
+        objectIds.Reset();
+        RemoveFilesNotPresentL( oldMediaId, &objectIds );
+        CleanupStack::PopAndDestroy( &objectIds );
+        }
+    }
+
 const CMdsPropertyDef& CMdSSqlObjectManipulate::ReadPropertyL( 
 		CMdCSerializationBuffer& aBuffer, const CMdsObjectDef& aObjectDef,
 		CMdsClauseBuffer& aBaseObjectClause, CMdsClauseBuffer& aObjectClause,
Binary file sis/mds/mds_stub.sis has changed
--- a/sis/mds/package.pkg	Tue Jan 26 12:13:20 2010 +0200
+++ b/sis/mds/package.pkg	Tue Feb 02 00:24:33 2010 +0200
@@ -17,7 +17,7 @@
 &EN
 
 ;packet-header (name, uid, major, minor, build, type)
-#{"Metadata System Upgrade"},(0x200009F5), 9, 20, 1, TYPE=SA, RU
+#{"Metadata System Upgrade"},(0x200009F5), 9, 20, 2, TYPE=SA, RU
 
 ; Localised vendor name
 %{"Nokia"}
--- a/sis/mds/package_separate.pkg	Tue Jan 26 12:13:20 2010 +0200
+++ b/sis/mds/package_separate.pkg	Tue Feb 02 00:24:33 2010 +0200
@@ -17,7 +17,7 @@
 &EN
 
 ;packet-header (name, uid, major, minor, build, type)
-#{"Metadata System Upgrade"},(0x200009F5), 9, 20, 1, TYPE=SA, RU
+#{"Metadata System Upgrade"},(0x200009F5), 9, 20, 2, TYPE=SA, RU
 
 ; Localised vendor name
 %{"Nokia"}
--- a/sis/mds/stub.pkg	Tue Jan 26 12:13:20 2010 +0200
+++ b/sis/mds/stub.pkg	Tue Feb 02 00:24:33 2010 +0200
@@ -17,7 +17,7 @@
 &EN
 
 ; Header
-#{"Metadata System"}, (0x200009F5), 9, 20, 1, TYPE=SA
+#{"Metadata System"}, (0x200009F5), 9, 20, 2, TYPE=SA
 
 ; Localised Vendor name
 %{"Nokia"}