userlibandfileserver/fileserver/sfat32/sl_mnt.cpp
branchRCL_3
changeset 22 2f92ad2dc5db
parent 20 597aaf25e343
child 41 0ffb4e86fcc9
--- a/userlibandfileserver/fileserver/sfat32/sl_mnt.cpp	Mon Mar 15 12:45:50 2010 +0200
+++ b/userlibandfileserver/fileserver/sfat32/sl_mnt.cpp	Wed Mar 31 23:38:45 2010 +0300
@@ -304,11 +304,6 @@
     	{
         iLeafDirCache->Reset();
     	}
-    else
-    	{
-        User::Free(iLastLeafDir);
-        iLastLeafDir=NULL;
-    	}
 	}
 
 //-------------------------------------------------------------------------------------------------------------------
@@ -843,7 +838,7 @@
     @param  aStartCluster   this entry start cluster number
     @param  aParentCluster  parent entry start cluster number
 */
-void CFatMountCB::InitializeFirstDirClusterL(TInt aStartCluster,TInt aParentCluster)
+void CFatMountCB::InitializeFirstDirClusterL(TUint32 aStartCluster, TUint32 aParentCluster)
     {
     const TUint32 KClusterSz= 1<<ClusterSizeLog2();
     const TUint32 KMaxBufSz = KClusterSz;           //-- max. nuffer size is a cluster
@@ -1362,7 +1357,7 @@
 
 //-----------------------------------------------------------------------------------------
 
-void CFatMountCB::DoCheckFatForLoopsL(TInt aCluster, TInt& aPreviousCluster, TInt& aChangePreviousCluster, TInt& aCount) const
+void CFatMountCB::DoCheckFatForLoopsL(TUint32 aCluster, TUint32& aPreviousCluster, TUint32& aChangePreviousCluster, TUint32& aCount) const
 //
 // Check one fat cluster for loops.
 //
@@ -1388,13 +1383,13 @@
 //
     {
 
-    TInt cluster=StartCluster(anEntry);
+    TUint32 cluster = StartCluster(anEntry);
     if (cluster==0 && anEntry.Size()==0)
         return;
 
-    TInt previousCluster=cluster;
-    TInt changePreviousCluster=1;
-    TInt count=0;
+    TUint32 previousCluster=cluster;
+    TUint32 changePreviousCluster=1;
+    TUint32 count=0;
 
 
     for(;;)
@@ -1506,14 +1501,13 @@
         }
 
     CFatFileCB& file=(*((CFatFileCB*)aFile));
-    file.SetL(firstEntry,(TShare)(aMode&KFileShareMask),firstEntryPos);
+    file.SetupL(firstEntry, firstEntryPos);
+
     if (anOpen==EFileReplace && file.Size())
         {
         file.SetSizeL(0);
-        file.SetSize(0);
         }
-    if (file.IsSeekIndex()==EFalse)
-        file.CreateSeekIndex();
+
     if (anOpen==EFileReplace || anOpen==EFileCreate)
         file.SetArchiveAttribute();
 
@@ -1582,10 +1576,10 @@
 
 //-----------------------------------------------------------------------------------------
 
-TBool CFatMountCB::IsDirectoryEmptyL(TInt aCluster)
 //
 // Check aCluster contains no directory entries other than . and ..
 //
+TBool CFatMountCB::IsDirectoryEmptyL(TUint32 aCluster)
     {
 
     __PRINT(_L("CFatMountCB::IsDirectoryEmptyL"));
@@ -1613,13 +1607,13 @@
 /**
     Overwrite as many contiguous file clusters as possible.
 */
-void CFatMountCB::DoWriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt aLastcluster, TInt &aBadcluster, TInt &aGoodcluster)
+void CFatMountCB::DoWriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TUint aLastcluster, TUint& aBadcluster, TUint& aGoodcluster)
     {
 
     __PRINT(_L("CFatMountCB::DoWriteToClusterListL"));
     __ASSERT_ALWAYS(aPos.Cluster()>=KFatFirstSearchCluster,User::Leave(KErrCorrupt));
 
-    TInt endCluster=0;
+    TUint32 endCluster=0;
 
     const TInt clusterRelativePos=ClusterRelativePos(aPos.iPos);
     const TInt maxClusters=((aLength+clusterRelativePos-1)>>ClusterSizeLog2())+1;
@@ -1645,11 +1639,11 @@
     if(r == KErrNone && errinf().iReasonCode == TErrorInfo::EBadSector) // GetLastErrorInfo succeded and Last Error was caused by bad sector
         {
 
-        const TInt badcluster = (TInt)(((dataStart + errinf().iErrorPos) - ClusterBasePosition())>>ClusterSizeLog2())+KFatFirstSearchCluster;
-              TInt goodcluster = FAT().AllocateSingleClusterL(badcluster);
+        const TUint32 badcluster = (TInt)(((dataStart + errinf().iErrorPos) - ClusterBasePosition())>>ClusterSizeLog2())+KFatFirstSearchCluster;
+              TUint32 goodcluster = FAT().AllocateSingleClusterL(badcluster);
 
         //Calculate cluster number to check whether this write started at the beginning of new cluster or middle of previous cluster.
-        TInt cluster = aPos.iCluster;
+        TUint32 cluster = aPos.iCluster;
         if ( (aPos.iPos) && ((aPos.iPos)==((aPos.iPos >> ClusterSizeLog2())<<ClusterSizeLog2())))
             cluster--;
 
@@ -1742,7 +1736,7 @@
 
 //-----------------------------------------------------------------------------------------
 
-void CFatMountCB::WriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt &aBadcluster, TInt& aGoodcluster)
+void CFatMountCB::WriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TUint& aBadcluster, TUint& aGoodcluster)
 //
 // Overwrite cluster list.
 //
@@ -1787,7 +1781,7 @@
 
     __PRINT(_L("CFatMountCB::DoReadFromClusterListL"));
 
-    TInt endCluster=0;
+    TUint32 endCluster=0;
 
     const TInt clusterRelativePos=ClusterRelativePos(aPos.iPos);
     const TInt maxClusters=((aLength+clusterRelativePos-1)>>ClusterSizeLog2())+1;
@@ -1860,33 +1854,20 @@
 //
     {
 
-    __PRINT(_L("CFatMountCB::FindLeafDirL"));
+    __PRINT2(_L("CFatMountCB::FindLeafDirL drv:%d, dir:%S"),DriveNumber() ,&aLeafDir);
 
     TLex lex(aName);
     TInt r;
     TEntryPos entryPos(RootIndicator(),0);
 
-    if (iLeafDirCache == NULL)
-    	{
-        TInt leaflen=(iLastLeafDir) ? iLastLeafDir->Length() : 0;
-        TInt namelen=aName.Length();
-        if (leaflen>1 && namelen>=leaflen && *iLastLeafDir==aName.Left(leaflen))
-            {
-            if (leaflen==namelen)
-                return(iLastLeafDirCluster);
-            lex.Inc(leaflen-1);
-            entryPos.iCluster=iLastLeafDirCluster;
-            }
-    	}
-    else
-    	{
-        // Skip root directory
+    ASSERT(iLeafDirCache);
+
         if (iLeafDirCache->CacheCount() > 0 && aName.Length() > 1)
         	{
-        	TInt err = iLeafDirCache->FindInCache(aName, aLeafDir);
+        const TInt err = iLeafDirCache->FindInCache(aName, aLeafDir);
         	if (err == KErrNone)
         		{
-        		ASSERT(aLeafDir.iClusterNum > 0);
+        	ASSERT(ClusterNumberValid(aLeafDir.iClusterNum)); 
         		return aLeafDir.iClusterNum;
         		}
         	else if (err != KErrNotFound)
@@ -1894,23 +1875,27 @@
         		User::LeaveIfError(err);
         		}
         	}
-    	}
-
-    FOREVER
+
+    TFatDirEntry entry;
+    TFileName fileName;
+    TEntryPos startPos;
+    TFatDirEntry startEntry;
+
+    for(;;)
         {
         lex.Inc(); // Skip path delimiter
         lex.Mark();
         r=lex.Remainder().Locate(KPathDelimiter);
+        
         if (r==KErrNotFound)
             r=lex.Remainder().Length();
+        
         if (r==0) // End of the path
             break;
+        
         lex.Inc(r); // Set the token length
-        TFatDirEntry entry;
-
-        TFileName fileName;
-        TEntryPos startPos;
-        TFatDirEntry startEntry;
+        
+        
         DoFindL(lex.MarkedToken(),
         		KEntryAttMatchMask|KEntryAttMatchExclusive,
         		startPos, startEntry, entryPos, entry,
@@ -1921,21 +1906,13 @@
 
         entryPos.iCluster=StartCluster(entry);
         entryPos.iPos=0;
-        }
-
-    if (iLeafDirCache == NULL)
-    	{
-        AllocBufferL(((CFatMountCB*)this)->iLastLeafDir,aName);
-        ((CFatMountCB*)this)->iLastLeafDirCluster=entryPos.iCluster;
-    	}
-    else
-    	{
+        }// for(;;)
+
         if (aName.Length() > 1)
         	{
         	aLeafDir = TLeafDirData(entryPos.iCluster);
             iLeafDirCache->AddToCacheL(aName, aLeafDir);
         	}
-    	}
 
     return entryPos.iCluster;
     }
@@ -1995,7 +1972,7 @@
 
 	TInt numFound = 0;
 	TEntryPos startPos = DosEntryPos1;
-	TInt clusterNum = DosEntryPos1.iCluster;
+	TUint32 clusterNum = DosEntryPos1.iCluster;
 
     for(TUint32 entryCnt=0; entryCnt < maxDirEntries; ++entryCnt)
         {//-- walk through directory cluster list. The loop is limited by maximal number of dir entries
@@ -2041,7 +2018,7 @@
             for(;;)
                 {
                 StartEntryPos1 = DosEntryPos1;
-                TInt clSave = DosEntryPos1.iCluster; //-- need to save current cluster number because GetDirEntry() & MoveToNextEntryL() can change it
+                TUint32 clSave = DosEntryPos1.iCluster; //-- need to save current cluster number because GetDirEntry() & MoveToNextEntryL() can change it
 
                 //-- get directory entry from the cache. We know that the DosEntryPos1 is cached.
                 nErr = GetDirEntry(DosEntryPos1, DosEntry1, StartEntry1, aFileName);
@@ -2460,10 +2437,10 @@
 
     __PRINT2(_L("CFatMountCB::DoFindL() drv:%d, %S"),Drive().DriveNumber(),&aTrgtName);
 
-    TInt previousCluster=aDosEntryPos.iCluster;
+    TUint32 previousCluster=aDosEntryPos.iCluster;
     TUint previousPosition=aDosEntryPos.iPos;
-    TInt changePreviousCluster=1;
-    TInt count=0;
+    TUint32 changePreviousCluster=1;
+    TUint32 count=0;
 
     TBool trgNameIsWildCard     = EFalse; //-- ETrue if the name we are looking for is a wildcard
     TBool trgNameFullySpecified = ETrue;  //-- ETrue if the name we are looking for doesn't contain wildcards
@@ -2948,7 +2925,7 @@
     Zero fill a cluster
     @param  aCluster cluster number to zero-fill
 */
-void CFatMountCB::ZeroDirClusterL(TInt aCluster)
+void CFatMountCB::ZeroDirClusterL(TUint32 aCluster)
     {
 
     __PRINT1(_L("CFatMountCB::ZeroDirClusterL %d"),aCluster);
@@ -3165,12 +3142,12 @@
 //-----------------------------------------------------------------------------------------
 
 /** Read the Uid of the entry starting at aCluster */
-void CFatMountCB::ReadUidL(TInt aCluster,TEntry& anEntry) const
+void CFatMountCB::ReadUidL(TUint32 aCluster,TEntry& anEntry) const
     {
 
     __PRINT1(_L("CFatMountCB::ReadUidL(%d)"), aCluster);
 
-    if((TUint)aCluster < KFatFirstSearchCluster || (TUint)aCluster >= UsableClusters()+KFatFirstSearchCluster)
+    if(aCluster < KFatFirstSearchCluster || aCluster >= UsableClusters()+KFatFirstSearchCluster)
         User::Leave(KErrCorrupt);
 
     TBuf8<sizeof(TCheckedUid)> uidBuf;
@@ -3227,10 +3204,10 @@
     if ((TUint)(aPos+aLength)>fileSize)
         aLength=fileSize-aPos;
 
-    TInt cluster=StartCluster(dosEntry);
+    TUint32 cluster=StartCluster(dosEntry);
 	TInt pos = aPos;
 
-    TInt endCluster;
+    TUint32 endCluster;
     TInt clusterSize=1<<ClusterSizeLog2();      //  Size of file clusters
 	TInt readTotal = 0;
 
@@ -3346,14 +3323,16 @@
 
 //-----------------------------------------------------------------------------------------
 
+/**
+    Write a FAT directory entry to disk. Assumes sufficient space has been created for it by AddDirEntry.
+
+    @param  aPos        dir. entry position 
+    @param  aDirEntry   entry data
+*/
 void CFatMountCB::WriteDirEntryL(const TEntryPos& aPos,const TFatDirEntry& aDirEntry)
-//
-// Write a FAT directory entry to disk.
-// Assumes sufficient space has been created for it by AddDirEntry.
-//
     {
 
-    __PRINT(_L("CFatMountCB::WriteDirEntryL"));
+    __PRINT2(_L("CFatMountCB::WriteDirEntryL cl:%d, pos:%d"), aPos.Cluster(), aPos.Pos());
 
     //-- use special interface to access FAT directory file
     DirWriteL(aPos,TPtrC8((TUint8*)&aDirEntry,KSizeOfFatDirEntry));
@@ -3361,15 +3340,13 @@
 
 //-----------------------------------------------------------------------------------------
 
+/**
+    Mark a dir entry as erased
+    @param  aPos dir. entry position 
+*/
 void CFatMountCB::EraseDirEntryL(const TEntryPos& aPos)
-//
-// Mark a dir entry as erased
-//
     {
-
-    __PRINT(_L("CFatMountCB::EraseDirEntryL"));
-    if(!iLeafDirCache && iLastLeafDir)
-        iLastLeafDir->Des().SetLength(0);
+    __PRINT2(_L("CFatMountCB::EraseDirEntryL cl:%d, pos:%d"), aPos.Cluster(), aPos.Pos());
 
     //-- use special interface to access FAT directory file
     DirWriteL(aPos,TPtrC8((TUint8*)&KEntryErasedMarker,sizeof(TUint8)));
@@ -3377,10 +3354,12 @@
 
 //-----------------------------------------------------------------------------------------
 
+/**
+    Read a FAT directory entry 
+    @param  aPos        dir. entry position 
+    @param  aDirEntry   entry data
+*/
 void CFatMountCB::ReadDirEntryL(const TEntryPos& aPos,TFatDirEntry& aDirEntry) const
-//
-// Read a FAT directory entry to disk
-//
     {
 
 //  __PRINT(_L("CFatMountCB::ReadDirEntryL"));
@@ -3525,7 +3504,7 @@
     This method is called for rugged FAT only.
     for parameters see CFatTable::ExtendClusterListL
 */
-void CFatMountCB::ExtendClusterListZeroedL(TInt aNumber,TInt& aCluster)
+void CFatMountCB::ExtendClusterListZeroedL(TUint32 aNumber, TUint32& aCluster)
     {
     __PRINT(_L("CFatMountCB::ExtendClusterListZeroedL"));
     __ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
@@ -3961,10 +3940,10 @@
         User::Leave(KErrNotFound); // Allows maximum number of entries in root directory
         }
 
-    TInt previousCluster= aDosEntryPos.iCluster;
+    TUint32 previousCluster= aDosEntryPos.iCluster;
     TUint previousPosition= aDosEntryPos.iPos;
-    TInt changePreviousCluster=1;
-    TInt count=0;
+    TUint32 changePreviousCluster=1;
+    TUint32 count=0;
 
     TFatDirEntry startEntry;
     TFileName dummyLongName;
@@ -4054,7 +4033,7 @@
     TUint i = 0;
     TInt clusterRelativePos;
     TInt maxClusters;
-    TInt endCluster;
+    TUint32 endCluster;
     TInt clusterListLen;
     TInt readLength;
     TInt temp;
@@ -4205,6 +4184,7 @@
         }
 
     delete pScnDrv;
+    pScnDrv = NULL;
 
     if(chkDskRes != KErrNone)
         {
@@ -4234,7 +4214,7 @@
 
     const TBool bNeedFatRemount = (nScnDrvRes!=KErrNone) || pScnDrv->ProblemsDiscovered();
     delete pScnDrv;
-
+    pScnDrv = NULL;
 
     if(bNeedFatRemount)
         {//-- ScanDrive found and probably fixed some errors.