userlibandfileserver/fileserver/sfat32/sl_file.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 42 a179b74831c9
child 44 3e88ff8f41d5
--- a/userlibandfileserver/fileserver/sfat32/sl_file.cpp	Thu Aug 19 11:14:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfat32/sl_file.cpp	Tue Aug 31 16:34:26 2010 +0300
@@ -11,7 +11,7 @@
 // Contributors:
 //
 // Description:
-// f32\sfat\sl_file.cpp
+// f32\sfat32\sl_file.cpp
 // 
 //
 
@@ -24,13 +24,13 @@
 const TInt KFirstClusterNum=2;
 
 CFatFileCB::CFatFileCB()
-	{
-	__PRINT1(_L("CFatFileCB created 0x%x"),this);
-	}
+    {
+    __PRINT1(_L("CFatFileCB created 0x%x"),this);
+    }
 
 CFatFileCB::~CFatFileCB()
-	{
-	__PRINT1(_L("~CFatFileCB deleted 0x%x"),this);
+    {
+    __PRINT1(_L("~CFatFileCB deleted 0x%x"),this);
 
     //-- a nasty trick to find out if the CFatFileCB is in consistent state on the moment of destruction.
     //-- Because of OOM conditions CFatFileCB might not be fully constructed and to be deleted, while FlushAll()
@@ -42,125 +42,125 @@
             {
             IndicateFileTimeModified(ETrue); //-- this will force writing file modification time to the media on Flush
             TRAP_IGNORE(FlushAllL());
-	        }
+            }
         }
 
     delete[] iSeekIndex;
-	}
+    }
 
 
 void CFatFileCB::CreateSeekIndex()
 //
 // Create a seek index
 //
-	{
+    {
 
-	iSeekIndex = new TUint32[KSeekIndexSize];
-	if (iSeekIndex == NULL)
-		return;
+    iSeekIndex = new TUint32[KSeekIndexSize];
+    if (iSeekIndex == NULL)
+        return;
 
-	Mem::FillZ(iSeekIndex, sizeof(TUint32) * KSeekIndexSize);
+    Mem::FillZ(iSeekIndex, sizeof(TUint32) * KSeekIndexSize);
 
-	iSeekIndexSize=CalcSeekIndexSize(FCB_FileSize());
-	}
+    iSeekIndexSize=CalcSeekIndexSize(FCB_FileSize());
+    }
 
 TInt CFatFileCB::SeekToPosition(TUint aNewRelCluster, TUint aClusterOffset)
 //
 // Use the seek index to set iCurrentPos.iCluster as close as possible to aNewRelCluster
 // Return aNewRelCluster-aCurrentPos.iCluster
 //
-	{
-	TInt clusterOffset=aClusterOffset;
-	TInt seekPos=(aNewRelCluster>>iSeekIndexSize)-1;
-	__ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
+    {
+    TInt clusterOffset=aClusterOffset;
+    TInt seekPos=(aNewRelCluster>>iSeekIndexSize)-1;
+    __ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
 
-	while(seekPos>=0 && iSeekIndex[seekPos]==0 && clusterOffset!=0)
-		{
-		seekPos--;
-		clusterOffset--;
-		}
-	if (clusterOffset==0) // Counted back to the current cluster
-		return(aClusterOffset);
-	if (seekPos<0)
-		{
-		iCurrentPos.iCluster=FCB_StartCluster();
-		return(aNewRelCluster);
-		}
+    while(seekPos>=0 && iSeekIndex[seekPos]==0 && clusterOffset!=0)
+        {
+        seekPos--;
+        clusterOffset--;
+        }
+    if (clusterOffset==0) // Counted back to the current cluster
+        return(aClusterOffset);
+    if (seekPos<0)
+        {
+        iCurrentPos.iCluster=FCB_StartCluster();
+        return(aNewRelCluster);
+        }
 
-	iCurrentPos.iCluster=iSeekIndex[seekPos];
-	return(aNewRelCluster-((seekPos+1)<<iSeekIndexSize));
-	}
+    iCurrentPos.iCluster=iSeekIndex[seekPos];
+    return(aNewRelCluster-((seekPos+1)<<iSeekIndexSize));
+    }
 
 void CFatFileCB::SetSeekIndexValueL(TUint aRelCluster, TUint aStoredCluster)
 //
 // Sets a value in the seekindex
 //
-	{
+    {
 
-	TInt seekPos=(aRelCluster>>iSeekIndexSize)-1;
-	__ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
-	__ASSERT_DEBUG(seekPos>=0,Fault(EFatFileSeekIndexTooSmall2));
-	iSeekIndex[seekPos] = aStoredCluster;
-	}
+    TInt seekPos=(aRelCluster>>iSeekIndexSize)-1;
+    __ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
+    __ASSERT_DEBUG(seekPos>=0,Fault(EFatFileSeekIndexTooSmall2));
+    iSeekIndex[seekPos] = aStoredCluster;
+    }
 
 void CFatFileCB::CheckPosL(TUint aPos)
 //
 // Check that the file is positioned correctly.
 // If aPos<currentPos attempt to guess the new position.
 //
-	{
-	__PRINT1(_L("CFatFileCB::CheckPosL(%d)"), aPos);
-	if (aPos==iCurrentPos.iPos)
-		return;
+    {
+    __PRINT1(_L("CFatFileCB::CheckPosL(%d)"), aPos);
+    if (aPos==iCurrentPos.iPos)
+        return;
     __ASSERT_DEBUG(aPos <= FCB_FileSize(), Fault(EFatFilePosBeyondEnd));
 
-	TUint newRelCluster=aPos>>ClusterSizeLog2();
-	if ( aPos && (aPos==(newRelCluster<<ClusterSizeLog2())) )
-		newRelCluster--;
-	TUint oldRelCluster=iCurrentPos.iPos>>ClusterSizeLog2();
-	
-	if ( iCurrentPos.iPos && (iCurrentPos.iPos==(oldRelCluster<<ClusterSizeLog2())) )
-		oldRelCluster--;	
-	
-	TInt clusterOffset=newRelCluster-oldRelCluster;
-	TUint32 oldCluster=iCurrentPos.iCluster;
+    TUint newRelCluster=aPos>>ClusterSizeLog2();
+    if ( aPos && (aPos==(newRelCluster<<ClusterSizeLog2())) )
+        newRelCluster--;
+    TUint oldRelCluster=iCurrentPos.iPos>>ClusterSizeLog2();
+    
+    if ( iCurrentPos.iPos && (iCurrentPos.iPos==(oldRelCluster<<ClusterSizeLog2())) )
+        oldRelCluster--;    
+    
+    TInt clusterOffset=newRelCluster-oldRelCluster;
+    TUint32 oldCluster=iCurrentPos.iCluster;
 
-	iCurrentPos.iPos=aPos;
-	if (clusterOffset==0)
-		return;
-	TInt seekOffset=clusterOffset;
-	if (iSeekIndex!=NULL)
-		{ // Can alter iCurrentPos.iCluster
-		seekOffset=SeekToPosition(newRelCluster,seekOffset);
-		if (seekOffset==0)
-			return;
-		}
-	if (clusterOffset==-1 && seekOffset!=1)
-		{ // Check previous cluster
-		TUint32 cluster=oldCluster-1;
-		if (FAT().GetNextClusterL(cluster) && cluster==oldCluster)
-			{
+    iCurrentPos.iPos=aPos;
+    if (clusterOffset==0)
+        return;
+    TInt seekOffset=clusterOffset;
+    if (iSeekIndex!=NULL)
+        { // Can alter iCurrentPos.iCluster
+        seekOffset=SeekToPosition(newRelCluster,seekOffset);
+        if (seekOffset==0)
+            return;
+        }
+    if (clusterOffset==-1 && seekOffset!=1)
+        { // Check previous cluster
+        TUint32 cluster=oldCluster-1;
+        if (FAT().GetNextClusterL(cluster) && cluster==oldCluster)
+            {
             iCurrentPos.iCluster=oldCluster-1;
-			return;
-			}
-		}
-	if (seekOffset<0)
-		{
-		seekOffset=newRelCluster;
-		iCurrentPos.iCluster=FCB_StartCluster();
-		}
-	while (seekOffset--)
-		{
+            return;
+            }
+        }
+    if (seekOffset<0)
+        {
+        seekOffset=newRelCluster;
+        iCurrentPos.iCluster=FCB_StartCluster();
+        }
+    while (seekOffset--)
+        {
         if (!FAT().GetNextClusterL(iCurrentPos.iCluster))
             {
             __PRINT(_L("CFatFileCB::CheckPosL() corrupt#1"));
             User::Leave(KErrCorrupt);
             }
         TInt cluster=newRelCluster-seekOffset;
-		if (iSeekIndex!=NULL && cluster && (cluster>>iSeekIndexSize)<<iSeekIndexSize==cluster)
-			SetSeekIndexValueL(cluster,iCurrentPos.iCluster);
-		}
-	}
+        if (iSeekIndex!=NULL && cluster && (cluster>>iSeekIndexSize)<<iSeekIndexSize==cluster)
+            SetSeekIndexValueL(cluster,iCurrentPos.iCluster);
+        }
+    }
 
 //-----------------------------------------------------------------------------
 /** 
@@ -170,21 +170,21 @@
     @param  aFileDosEntryPos    this file DOS entry dir. iterator in the parent directory.
 */
 void CFatFileCB::SetupL(const TFatDirEntry& aFatDirEntry, const TEntryPos& aFileDosEntryPos)
-	{
-	__PRINT1(_L("CFatFileCB::SetupL[0x%x]"), this);
-	
+    {
+    __PRINT1(_L("CFatFileCB::SetupL[0x%x]"), this);
+    
 
     //-- set up a file control block
-	iCurrentPos.iCluster= FatMount().StartCluster(aFatDirEntry);
-	iCurrentPos.iPos=0;
-	
+    iCurrentPos.iCluster= FatMount().StartCluster(aFatDirEntry);
+    iCurrentPos.iPos=0;
+    
     SetAtt(aFatDirEntry.Attributes());
-	SetModified(aFatDirEntry.Time(FatMount().TimeOffset()));
+    SetModified(aFatDirEntry.Time(FatMount().TimeOffset()));
     
     FCB_SetStartCluster(iCurrentPos.iCluster);
     FCB_SetFileSize(aFatDirEntry.Size()); 
 
-	iFileDosEntryPos = aFileDosEntryPos;
+    iFileDosEntryPos = aFileDosEntryPos;
 
     SetMaxSupportedSize(KMaxSupportedFatFileSize);
 
@@ -198,7 +198,7 @@
     IndicateFileAttModified(EFalse);
     IndicateFileSizeModified(EFalse);
     IndicateFileTimeModified(EFalse);
-	}
+    }
 
 //-----------------------------------------------------------------------------
 /**
@@ -214,22 +214,22 @@
 
 */
 void CFatFileCB::ReadL(TInt64 aPos,TInt& aLength, TDes8* aDes, const RMessagePtr2& aMessage, TInt aOffset)
-	{
-	__PRINT3(_L("CFatFileCB::ReadL[0x%x] pos=%LU len=%d"), this, aPos, aLength);
-	
+    {
+    __PRINT3(_L("CFatFileCB::ReadL[0x%x] pos=%LU len=%d"), this, aPos, aLength);
+    
     if((TUint64)aPos > KMaxSupportedFatFileSize-1)
         User::Leave(KErrNotSupported);  //-- max. position in the file is 0xFFFFFFFE
 
     FatMount().CheckStateConsistentL();
     
-	CheckPosL(I64LOW(aPos));
-	
-	const TUint startPos = iCurrentPos.iPos;
-	const TUint curSize  = FCB_FileSize();
-	const TUint length   = (TUint)aLength;
-	
-	if((startPos + length > curSize) || (startPos > startPos + length) )
-		aLength=curSize-startPos;
+    CheckPosL(I64LOW(aPos));
+    
+    const TUint startPos = iCurrentPos.iPos;
+    const TUint curSize  = FCB_FileSize();
+    const TUint length   = (TUint)aLength;
+    
+    if((startPos + length > curSize) || (startPos > startPos + length) )
+        aLength=curSize-startPos;
 		
 	TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0;
 	
@@ -239,9 +239,9 @@
 
 
 void CFatFileCB::ReadL(TInt aFilePos,TInt& aLength,const TAny* aTrg,const RMessagePtr2& aMessage)
-	{
-	ReadL(TInt64(aFilePos),aLength,(TDes8*) aTrg,aMessage, 0);
-	}
+    {
+    ReadL(TInt64(aFilePos),aLength,(TDes8*) aTrg,aMessage, 0);
+    }
 
 //-----------------------------------------------------------------------------
 /**
@@ -257,118 +257,117 @@
 
 */
 void CFatFileCB::WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aSrc,const RMessagePtr2& aMessage, TInt aOffset)
-	{
-	__PRINT3(_L("CFatFileCB::WriteL[0x%x] pos=%LU len=%d"), this, aPos, aLength);
+    {
+    __PRINT3(_L("CFatFileCB::WriteL[0x%x] pos=%LU len=%d"), this, aPos, aLength);
 
-	// FAT supports 32 bits only for file size
-   	TUint64 endPos = aPos + aLength;
-   	if(endPos > KMaxSupportedFatFileSize)
-   		User::Leave(KErrNotSupported);
-   	
+    // FAT supports 32 bits only for file size
+    TUint64 endPos = aPos + aLength;
+    if(endPos > KMaxSupportedFatFileSize)
+        User::Leave(KErrNotSupported);
+    
     FatMount().CheckStateConsistentL();
     FatMount().CheckWritableL();
     const TUint pos = I64LOW(aPos);
-  	CheckPosL(pos);
-  	
-	const TUint startCluster = FCB_StartCluster();
-	const TUint length       = (TUint)aLength;
-	
-	endPos = iCurrentPos.iPos + length; 
-	if ((endPos           > FCB_FileSize()) ||
-	    (iCurrentPos.iPos > endPos)         ) // Overflow condition 
-		DoSetSizeL(iCurrentPos.iPos+length,EFalse);
-   	
-	TUint startPos=iCurrentPos.iPos;
-	TUint badcluster=0;
-	TUint goodcluster=0;
+    CheckPosL(pos);
+    
+    const TUint startCluster = FCB_StartCluster();
+    const TUint length       = (TUint)aLength;
+    
+    endPos = iCurrentPos.iPos + length; 
+    if ((endPos           > FCB_FileSize()) ||
+        (iCurrentPos.iPos > endPos)         ) // Overflow condition 
+        DoSetSizeL(iCurrentPos.iPos+length,EFalse);
+    
+    TUint startPos=iCurrentPos.iPos;
+    TUint badcluster=0;
+    TUint goodcluster=0;
    	
 	TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0;
 	
 	TRAPD(ret, FatMount().WriteToClusterListL(iCurrentPos,aLength,aSrc,aMessage,aOffset,badcluster, goodcluster, flag));
    	
-	if (ret == KErrCorrupt || ret == KErrDied)
-		{
+    if (ret == KErrCorrupt || ret == KErrDied)
+        {
         if(startCluster == 0)
-			{ //Empty File, revert all the clusters allocated.
-			const TUint32 cluster = FCB_StartCluster();
-			FCB_SetStartCluster(0);
-			FCB_SetFileSize(0);
-			IndicateFileSizeModified(ETrue);
+            { //Empty File, revert all the clusters allocated.
+            const TUint32 cluster = FCB_StartCluster();
+            FCB_SetStartCluster(0);
+            FCB_SetFileSize(0);
+            IndicateFileSizeModified(ETrue);
             
-			FlushAllL();
+            FlushAllL();
 
-			iCurrentPos.iCluster = 0;
-			iCurrentPos.iPos = 0;
+            iCurrentPos.iCluster = 0;
+            iCurrentPos.iPos = 0;
 
-			FAT().FreeClusterListL(cluster);
-			FAT().FlushL();
-			}
-		else
-			{ //Calculate the clusters required based on file size, revert extra clusters if allocated.
-			const TUint curSize = FCB_FileSize();
-			TUint ClustersNeeded = curSize >> ClusterSizeLog2();
-			if(curSize > (ClustersNeeded << ClusterSizeLog2()))
-				{
-				ClustersNeeded++;
-				}
+            FAT().FreeClusterListL(cluster);
+            FAT().FlushL();
+            }
+        else
+            { //Calculate the clusters required based on file size, revert extra clusters if allocated.
+            const TUint curSize = FCB_FileSize();
+            TUint ClustersNeeded = curSize >> ClusterSizeLog2();
+            if(curSize > (ClustersNeeded << ClusterSizeLog2()))
+                {
+                ClustersNeeded++;
+                }
 
-			TUint32 cluster = FCB_StartCluster();
-			while(--ClustersNeeded)
-				{
-				FAT().GetNextClusterL(cluster);
-				}
+            TUint32 cluster = FCB_StartCluster();
+            while(--ClustersNeeded)
+                {
+                FAT().GetNextClusterL(cluster);
+                }
                 
-			iCurrentPos.iCluster = cluster;
+            iCurrentPos.iCluster = cluster;
 
-			if (FAT().GetNextClusterL(cluster))
-				{
-				FAT().FreeClusterListL(cluster);
-				}
+            if (FAT().GetNextClusterL(cluster))
+                {
+                FAT().FreeClusterListL(cluster);
+                }
 
-			FAT().WriteFatEntryEofL(iCurrentPos.iCluster);
-			FAT().FlushL();
-			}
-		}
+            FAT().WriteFatEntryEofL(iCurrentPos.iCluster);
+            FAT().FlushL();
+            }
+        }
 
-	User::LeaveIfError(ret);
+    User::LeaveIfError(ret);
 
-	if(badcluster != 0)
-		{
-		if(FCB_StartCluster() == badcluster)
-			{
+    if(badcluster != 0)
+        {
+        if(FCB_StartCluster() == badcluster)
+            {
             FCB_SetStartCluster(goodcluster);
-			FlushStartClusterL();
-			}
-		else
-			{
-			TUint32 aCluster = FCB_StartCluster();
-			do
-				{
+            FlushStartClusterL();
+            }
+        else
+            {
+            TUint32 aCluster = FCB_StartCluster();
+            do
+                {
                 if((TUint)badcluster == FAT().ReadL(aCluster))
-					{
-					FAT().WriteL(aCluster, goodcluster);
-					FAT().FlushL();
-					break;
-					}
-				}
-			while(FAT().GetNextClusterL(aCluster));
-			}
-		}
-	aLength=iCurrentPos.iPos-startPos;
+                    {
+                    FAT().WriteL(aCluster, goodcluster);
+                    FAT().FlushL();
+                    break;
+                    }
+                }
+            while(FAT().GetNextClusterL(aCluster));
+            }
+        }
+    aLength=iCurrentPos.iPos-startPos;
 
-	if(FatMount().IsRuggedFSys() && pos+(TUint)aLength > FCB_FileSize())
-		{
-		WriteFileSizeL(pos+aLength);
-		}
+    if(!IsSequentialMode() && FatMount().IsRuggedFSys() && pos+(TUint)aLength > FCB_FileSize())
+        {
+        WriteFileSizeL(pos+aLength);
+        }
 
-	}
+    }
 
 
 void CFatFileCB::WriteL(TInt aFilePos,TInt& aLength,const TAny* aSrc,const RMessagePtr2& aMessage)
-	{
-	WriteL(TInt64(aFilePos),aLength,(TDesC8*) aSrc,aMessage, 0);
-	}
-
+    {
+    WriteL(TInt64(aFilePos),aLength,(TDesC8*) aSrc,aMessage, 0);
+    }
 
 
 //-----------------------------------------------------------------------------
@@ -378,58 +377,58 @@
 // Resize the seek index to accomodate a larger or smaller filesize
 // Assumes KSeekIndexSize is a power of 2.
 //
-	{
+    {
 
-	TInt maxNewIndex=aNewSize>>(ClusterSizeLog2()+aNewMult);
+    TInt maxNewIndex=aNewSize>>(ClusterSizeLog2()+aNewMult);
 
 
-	TInt    index=0;
-	TInt	indexEnd=KSeekIndexSize;
-	TInt	newValEnd=maxNewIndex;
+    TInt    index=0;
+    TInt    indexEnd=KSeekIndexSize;
+    TInt    newValEnd=maxNewIndex;
 
-	if (iSeekIndexSize<aNewMult)
-		{
-		TInt newVal=index;
-		TInt step=1<<(aNewMult-iSeekIndexSize);
-		index+=step-1;
-		while(index<indexEnd && newVal<newValEnd)
-			{
-			iSeekIndex[newVal] =  iSeekIndex[index];
-			newVal++;
-			index+=step;
-			}
-		while(newVal<indexEnd)
-			iSeekIndex[newVal++] =  0;
-		}
-	else
-		{
-		TInt diffSize = iSeekIndexSize-aNewMult;
-		TInt oldVal=(KSeekIndexSize>>diffSize) - 1;
-		TInt newVal=indexEnd-1;
-		TInt skip=(1<<diffSize)-1;
+    if (iSeekIndexSize<aNewMult)
+        {
+        TInt newVal=index;
+        TInt step=1<<(aNewMult-iSeekIndexSize);
+        index+=step-1;
+        while(index<indexEnd && newVal<newValEnd)
+            {
+            iSeekIndex[newVal] =  iSeekIndex[index];
+            newVal++;
+            index+=step;
+            }
+        while(newVal<indexEnd)
+            iSeekIndex[newVal++] =  0;
+        }
+    else
+        {
+        TInt diffSize = iSeekIndexSize-aNewMult;
+        TInt oldVal=(KSeekIndexSize>>diffSize) - 1;
+        TInt newVal=indexEnd-1;
+        TInt skip=(1<<diffSize)-1;
 
-		if ((iSeekIndexSize - aNewMult) > KSeekIndexSizeLog2)
-			{
+        if ((iSeekIndexSize - aNewMult) > KSeekIndexSizeLog2)
+            {
             ClearIndex(0); //-- Invalidate every entry.
-			}
-		else
-			{
-			while(newVal>=index)
-				{
+            }
+        else
+            {
+            while(newVal>=index)
+                {
 
-				iSeekIndex[newVal--] =  iSeekIndex[oldVal--];
+                iSeekIndex[newVal--] =  iSeekIndex[oldVal--];
 
 
-				for(TInt i=skip;i>0;i--)
-					{	
-					iSeekIndex[newVal--] = 0;
+                for(TInt i=skip;i>0;i--)
+                    {   
+                    iSeekIndex[newVal--] = 0;
 
-					}
-				}
-			}
-		}
-	iSeekIndexSize=aNewMult;
-	}
+                    }
+                }
+            }
+        }
+    iSeekIndexSize=aNewMult;
+    }
 
 
 /**
@@ -439,44 +438,44 @@
             if = 0  all existing index will be zero filled
 */ 
 void CFatFileCB::ClearIndex(TUint aNewSize)
-	{
+    {
 
-	if (!iSeekIndex)
-	    return;
+    if (!iSeekIndex)
+        return;
 
     if(aNewSize==0)
-    	{
-    	//-- zero fill all the array
+        {
+        //-- zero fill all the array
         Mem::FillZ(iSeekIndex, KSeekIndexSize*sizeof(TUint32));
-		return;
-    	}
+        return;
+        }
 
-	// Files that fill up a cluster exactly do not have a trailing empty
-	// cluster. So the entry for that position must also be invalidated
-	aNewSize--;
-	TInt firstInvalidIndex=aNewSize>>(iSeekIndexSize+ClusterSizeLog2());
-		
-	TInt indexLen=KSeekIndexSize-firstInvalidIndex;
+    // Files that fill up a cluster exactly do not have a trailing empty
+    // cluster. So the entry for that position must also be invalidated
+    aNewSize--;
+    TInt firstInvalidIndex=aNewSize>>(iSeekIndexSize+ClusterSizeLog2());
+        
+    TInt indexLen=KSeekIndexSize-firstInvalidIndex;
 
-	Mem::FillZ(iSeekIndex+firstInvalidIndex, indexLen * sizeof(TUint32));
-	}
+    Mem::FillZ(iSeekIndex+firstInvalidIndex, indexLen * sizeof(TUint32));
+    }
 
 TInt CFatFileCB::CalcSeekIndexSize(TUint aSize)
 //
 // Find the nearest power of 2 > aSize
 //
-	{
-	TInt count = 0;
-	const TUint indexSize=KSeekIndexSize<<ClusterSizeLog2();//KSeekIndexSize=128
-	if (aSize<=indexSize)
-	  return(count);
-	
-	while((aSize>>=1)>0)
-		{
-		count++;
-		}
-	return (count - (KSeekIndexSizeLog2 + ClusterSizeLog2()) + 1);
-	}
+    {
+    TInt count = 0;
+    const TUint indexSize=KSeekIndexSize<<ClusterSizeLog2();//KSeekIndexSize=128
+    if (aSize<=indexSize)
+      return(count);
+    
+    while((aSize>>=1)>0)
+        {
+        count++;
+        }
+    return (count - (KSeekIndexSizeLog2 + ClusterSizeLog2()) + 1);
+    }
 
 //-----------------------------------------------------------------------------
 /**
@@ -484,21 +483,21 @@
     @param aSize new file size.
 */
 void CFatFileCB::SetSizeL(TInt64 aSize)
-	{
-	__PRINT2(_L("CFatFileCB::SetSizeL[0x%x] sz=%LU"), this, aSize);
-	
-	//-- max. file size for FAT is 4GB-1
-	if (I64HIGH(aSize))
-		User::Leave(KErrNotSupported);
+    {
+    __PRINT2(_L("CFatFileCB::SetSizeL[0x%x] sz=%LU"), this, aSize);
+    
+    //-- max. file size for FAT is 4GB-1
+    if (I64HIGH(aSize))
+        User::Leave(KErrNotSupported);
 
     DoSetSizeL(I64LOW(aSize), FatMount().IsRuggedFSys());
-	}
+    }
 
 
 void CFatFileCB::SetSizeL(TInt aSize)
-	{
-	SetSizeL(TInt64(aSize));
-	}
+    {
+    SetSizeL(TInt64(aSize));
+    }
 
 //-----------------------------------------------------------------------------
 /**
@@ -506,22 +505,22 @@
 */
 void CFatFileCB::DoShrinkFileToZeroSizeL()
     {
-	    ASSERT(FCB_FileSize());
+        ASSERT(FCB_FileSize());
         ASSERT(FileSizeModified());
         
-            ClearIndex(0); //-- clear seek index array
-		
+        ClearIndex(0); // Clear seek index array
+        
         //-- update file dir. entry
         const TUint32 cluster = FCB_StartCluster();
-		FCB_SetStartCluster(0);
-		FCB_SetFileSize(0);
-			FlushAllL();
-		
+        FCB_SetStartCluster(0);
+        FCB_SetFileSize(0);
+            FlushAllL();
+        
         //-- free cluster list. 
-			CheckPosL(0);
-			FAT().FreeClusterListL(cluster);
-			FAT().FlushL();
-			}
+            CheckPosL(0);
+            FAT().FreeClusterListL(cluster);
+            FAT().FlushL();
+            }
 
 //-----------------------------------------------------------------------------
 /*
@@ -531,35 +530,36 @@
     @param aForceCachesFlush if ETrue, all file/FAT caches will be flushed 
 */
 void CFatFileCB::DoShrinkFileL(TUint32 aNewSize, TBool aForceCachesFlush)
-		{
+    {
     ASSERT(FileSizeModified());
     ASSERT(FCB_FileSize() > aNewSize && aNewSize);
-	
-    if(aForceCachesFlush)		
+    
+    if(aForceCachesFlush)       
         WriteFileSizeL(aNewSize); //-- write file size directly to its dir. entry
 
-	CheckPosL(aNewSize);
-	
+    CheckPosL(aNewSize);
+
     TUint32 cluster=iCurrentPos.iCluster;
-		if (FAT().GetNextClusterL(cluster))
-	    {//-- truncate the cluster chain
-			FAT().WriteFatEntryEofL(iCurrentPos.iCluster);
-			FAT().FreeClusterListL(cluster);
-			}
-		
+    
+    if (FAT().GetNextClusterL(cluster))
+        {//-- truncate the cluster chain
+        FAT().WriteFatEntryEofL(iCurrentPos.iCluster);
+        FAT().FreeClusterListL(cluster);
+        }
+        
     ClearIndex(aNewSize);
-		FAT().FlushL();
-		}
-	
+    FAT().FlushL();
+    }
+    
 //-----------------------------------------------------------------------------
 /**
     Expand a file.
-	
+    
     @param aNewSize new file size.
     @param aForceCachesFlush if ETrue, all file/FAT caches will be flushed
 */
 void CFatFileCB::DoExpandFileL(TUint32 aNewSize, TBool aForceCachesFlush)
-		{
+    {
     ASSERT(FCB_FileSize() < aNewSize);
     ASSERT(FileSizeModified());
 
@@ -567,41 +567,41 @@
     const TUint32 newSizeClusters = (TUint32)(((TUint64)aNewSize + Pow2(KClusterSzLog2) - 1) >> KClusterSzLog2);
 
 
-	//-- expanding a file
-	if (FCB_StartCluster() == 0)
-		{//-- the initial file size is 0 (no cluster chain)
+    //-- expanding a file
+    if (FCB_StartCluster() == 0)
+        {//-- the initial file size is 0 (no cluster chain)
          
         ClearIndex(0); //-- clear seek index array
         //-- FAT().FreeClusterHint() will give us a hint of the last free cluster
         const TUint32 tempStartCluster=FAT().AllocateClusterListL(newSizeClusters, FAT().FreeClusterHint()); 
-		FAT().FlushL();
+        FAT().FlushL();
 
-		iCurrentPos.iCluster=tempStartCluster;
-		FCB_SetStartCluster(tempStartCluster);
-		FCB_SetFileSize(aNewSize);
-		FlushAllL();
-		}
-	else
-		{
-		const TUint curSize = FCB_FileSize(); 
-	    const TUint32 oldSizeClusters = ((curSize + Pow2(KClusterSzLog2) - 1) >> KClusterSzLog2);
+        iCurrentPos.iCluster=tempStartCluster;
+        FCB_SetStartCluster(tempStartCluster);
+        FCB_SetFileSize(aNewSize);
+        FlushAllL();
+        }
+    else
+        {
+        const TUint curSize = FCB_FileSize(); 
+        const TUint32 oldSizeClusters = ((curSize + Pow2(KClusterSzLog2) - 1) >> KClusterSzLog2);
         ASSERT(newSizeClusters >= oldSizeClusters);
-		const TUint newClusters = newSizeClusters-oldSizeClusters;	//-- Number of clusters we need to append to the existing cluster chain
-		if (newClusters)
-			{
-			TEntryPos currentPos=iCurrentPos;
-			CheckPosL(FCB_FileSize());
-			FAT().ExtendClusterListL(newClusters,iCurrentPos.iCluster);
-			iCurrentPos=currentPos;
-			}
-	
-		FAT().FlushL();
-		
-        if(aForceCachesFlush)			// write file size if increasing
-			WriteFileSizeL(aNewSize);
-		}
+        const TUint newClusters = newSizeClusters-oldSizeClusters;  //-- Number of clusters we need to append to the existing cluster chain
+        if (newClusters)
+            {
+            TEntryPos currentPos=iCurrentPos;
+            CheckPosL(FCB_FileSize());
+            FAT().ExtendClusterListL(newClusters,iCurrentPos.iCluster);
+            iCurrentPos=currentPos;
+            }
+    
+        FAT().FlushL();
+        
+        if(!IsSequentialMode() && aForceCachesFlush)    // Write file size directly to its dir. entry if a cache flush
+            WriteFileSizeL(aNewSize);               // is needed and rugged FAT is not ignored by client
+        }
 
-	}
+    }
 
 //-----------------------------------------------------------------------------
 /**
@@ -611,18 +611,18 @@
                                 it is used in Rugged FAT mode.
 */
 void CFatFileCB::DoSetSizeL(TUint aSize, TBool aForceCachesFlush)
-	{
-	__PRINT4(_L("CFatFileCB::DoSetSizeL[0x%x] sz:%d, oldSz:%d, flush:%d"), this, aSize, FCB_FileSize(), aForceCachesFlush);
+    {
+    __PRINT4(_L("CFatFileCB::DoSetSizeL[0x%x] sz:%d, oldSz:%d, flush:%d"), this, aSize, FCB_FileSize(), aForceCachesFlush);
 
     FatMount().CheckStateConsistentL();
     FatMount().CheckWritableL();
 
-	
-	// Can not change the file size if it is clamped
-	if(Mount().IsFileClamped(MAKE_TINT64(0,FCB_StartCluster())) > 0)
-		User::Leave(KErrInUse);
-	
-	if(aSize == FCB_FileSize())
+    
+    // Can not change the file size if it is clamped
+    if(Mount().IsFileClamped(MAKE_TINT64(0,FCB_StartCluster())) > 0)
+        User::Leave(KErrInUse);
+    
+    if(aSize == FCB_FileSize())
         return;
 
     IndicateFileSizeModified(ETrue);
@@ -641,18 +641,18 @@
         }
 
     //-------------------------------------------
-	//-- shrinking file to non-zero size
+    //-- shrinking file to non-zero size
     if (aSize < FCB_FileSize())
-		{
+        {
         DoShrinkFileL(aSize, aForceCachesFlush);
         return;
         }
     
     //-------------------------------------------
-	//-- expanding a file
+    //-- expanding a file
     DoExpandFileL(aSize, aForceCachesFlush);
 
-	}
+    }
 
 //-----------------------------------------------------------------------------
 /**
@@ -666,8 +666,8 @@
 
 */
 void CFatFileCB::SetEntryL(const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask)
-	{
-	__PRINT1(_L("CFatFileCB::SetEntryL[0x%x]"), this);
+    {
+    __PRINT1(_L("CFatFileCB::SetEntryL[0x%x]"), this);
     
     FatMount().CheckStateConsistentL();
     FatMount().CheckWritableL();
@@ -696,7 +696,7 @@
         IndicateFileTimeModified(ETrue); //-- this will force writing file mod. time to the media on Flush
         }
 
-	}
+    }
 
 
 //-----------------------------------------------------------------------------
@@ -704,39 +704,39 @@
     The same as FlushAllL(). This method is called from RFile::Flush()
 */
 void CFatFileCB::FlushDataL()
-	{
-	__PRINT1(_L("CFatFileCB::FlushDataL[0x%x]"), this);
+    {
+    __PRINT1(_L("CFatFileCB::FlushDataL[0x%x]"), this);
     FlushAllL();
-	}
+    }
 
 //-----------------------------------------------------------------------------
 /** 
     Flush the fide directory entry data: files size, attributes, time etc. 
 */
 void CFatFileCB::FlushAllL()
-	{
+    {
 
     //-- define this symbol in order to enable legacy behaviour, i.e. compulsory updating file dir. entry on flush.
     //-- otherwise the FlushAllL() will update the file dir. entry only if it differs from what is on the media, i.e.
     //-- file size, start cluster, attributes and modification timestamp
     #define ALWAYS_UPDATE_ENTRY_ON_FLUSH
 
-	__PRINT1(_L("CFatFileCB::FlushAllL[0x%x]"), this);
+    __PRINT1(_L("CFatFileCB::FlushAllL[0x%x]"), this);
 
     if (Mount().IsCurrentMount()==EFalse)
-		User::Leave(KErrDisMounted);
+        User::Leave(KErrDisMounted);
 
     FatMount().CheckStateConsistentL();
     FatMount().CheckWritableL();
 
-	if(!FileSizeModified() && !FileAttModified() && !FileTimeModified())
+    if(!FileSizeModified() && !FileAttModified() && !FileTimeModified())
         return; //-- nothing has changed in the file entry at all
 
 
     //-- read file dir. entry
-	TFatDirEntry entry;
-	FatMount().ReadDirEntryL(iFileDosEntryPos,entry);
-	__ASSERT_ALWAYS(entry.IsEndOfDirectory()==EFalse,User::Leave(KErrCorrupt));
+    TFatDirEntry entry;
+    FatMount().ReadDirEntryL(iFileDosEntryPos,entry);
+    __ASSERT_ALWAYS(entry.IsEndOfDirectory()==EFalse,User::Leave(KErrCorrupt));
 
     //-- the problem with KEntryAttModified here is that the file server uses this flag to 
     //-- deal with dirty file data. This means that this flag can be set even if there were no changes
@@ -767,35 +767,35 @@
 
     if(bUpdateDirEntry)
         {//-- write entry to the media
-	    __PRINT(_L("  CFatFileCB::FlushAllL #1"));
+        __PRINT(_L("  CFatFileCB::FlushAllL #1"));
         entry.SetAttributes(Att() & KEntryAttMaskSupported);
-	    entry.SetSize(FCB_FileSize());
-	    entry.SetTime(iModified, timeOffset);
-	    
+        entry.SetSize(FCB_FileSize());
+        entry.SetTime(iModified, timeOffset);
+        
         entry.SetStartCluster(FCB_StartCluster());
 
 	    const TBool setNotify = FatMount().GetNotifyUser();
-	if(setNotify)
-		{
-		FatMount().SetNotifyOff();	// do not launch a notifier
-		}
+		if(setNotify)
+			{
+			FatMount().SetNotifyOff();	// do not launch a notifier
+			}
 
-	    TRAPD(ret, FatMount().WriteDirEntryL(iFileDosEntryPos,entry));
-	
-	if(setNotify)
-		{
-		FatMount().SetNotifyOn();
-		}
+			TRAPD(ret, FatMount().WriteDirEntryL(iFileDosEntryPos,entry));
+		
+		if(setNotify)
+			{
+			FatMount().SetNotifyOn();
+			}
 
-	User::LeaveIfError(ret);
+		User::LeaveIfError(ret);
 
-        IndicateFileSizeModified(EFalse);
-        IndicateFileTimeModified(EFalse);
+		IndicateFileSizeModified(EFalse);
+		IndicateFileTimeModified(EFalse);
 	    }
 
 
-        //-- KEntryAttModified must be reset anyway
-        IndicateFileAttModified(EFalse); 
+    //-- KEntryAttModified must be reset anyway
+    IndicateFileAttModified(EFalse); 
 	}
 
 //-----------------------------------------------------------------------------
@@ -805,7 +805,7 @@
     @param  aNewName new file name; all trailing dots from the name will be removed
 */
 void CFatFileCB::RenameL(const TDesC& aNewName)
-	{
+    {
     __PRINT2(_L("CFatFileCB::RenameL[0x%x], name:%S"),this, &aNewName);
 
     FatMount().CheckStateConsistentL();
@@ -814,105 +814,97 @@
     const TPtrC fileName = RemoveTrailingDots(aNewName); //-- remove trailing dots from the name
 
 
-	FatMount().DoRenameOrReplaceL(*iFileName, fileName, CFatMountCB::EModeRename, iFileDosEntryPos);
-	
+    FatMount().DoRenameOrReplaceL(*iFileName, fileName, CFatMountCB::EModeRename, iFileDosEntryPos);
+    
     AllocBufferL(iFileName, fileName);
-	
-	if(!FatMount().IsRuggedFSys())
-		FAT().FlushL();
-	}
+    
+    if(!FatMount().IsRuggedFSys())
+        FAT().FlushL();
+    }
 
 
 //***********************************************************
 //* BlockMap interface
 //***********************************************************
-	
+    
 TInt CFatFileCB::BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos)
 //
 // Retrieves the block map of a given section of the file, in the FAT file system.
-//	
-	{
-	__PRINT2(_L("CFatFileCB::BlockMap aStartPos=%ld aEndPos=%ld"), aStartPos, aEndPos);
-	
-	if ( I64HIGH(aStartPos) || I64HIGH(aEndPos) )
-		return KErrNotSupported;
+//  
+    {
+    __PRINT2(_L("CFatFileCB::BlockMap aStartPos=%ld aEndPos=%ld"), aStartPos, aEndPos);
+    
+    if ( I64HIGH(aStartPos) || I64HIGH(aEndPos) )
+        return KErrNotSupported;
 
     TUint startPos = I64LOW(aStartPos);
-	TUint endPos = I64LOW(aEndPos);
+    TUint endPos = I64LOW(aEndPos);
 
-	// aEndPos will always be >=0 at this point
-	const TUint length = endPos - startPos;
-	
-	// Store the position of cluster zero in aInfo
-	CFatMountCB& fatMount = FatMount();
+    // aEndPos will always be >=0 at this point
+    const TUint length = endPos - startPos;
+    
+    // Store the position of cluster zero in aInfo
+    CFatMountCB& fatMount = FatMount();
 
-	TInt drvNo=-1;
-	TBusLocalDrive* locDrv;
-	if((fatMount.LocalDrive()->GetLocalDrive(locDrv)==KErrNone) && ((drvNo=GetLocalDriveNumber(locDrv))>=0) && (drvNo<KMaxLocalDrives))
-		aInfo.iLocalDriveNumber=drvNo;
-	else
-		return KErrNotSupported;
+    TInt drvNo=-1;
+    TBusLocalDrive* locDrv;
+    if((fatMount.LocalDrive()->GetLocalDrive(locDrv)==KErrNone) && ((drvNo=GetLocalDriveNumber(locDrv))>=0) && (drvNo<KMaxLocalDrives))
+        aInfo.iLocalDriveNumber=drvNo;
+    else
+        return KErrNotSupported;
 
-    TInt r;
-	
     // Fetch the address of cluster 0
-	TRAP(r, aInfo.iStartBlockAddress = fatMount.FAT().DataPositionInBytesL(KFirstClusterNum));
-	if (r != KErrNone)
-		return r;
+    aInfo.iStartBlockAddress = fatMount.FAT().DataPositionInBytes(KFirstClusterNum);
 
-
-	TRAP(r, CheckPosL(startPos));
-	if (r != KErrNone)
-		return r;
+    TRAPD(r, CheckPosL(startPos));
+    if (r != KErrNone)
+        return r;
 
-	aInfo.iBlockStartOffset = fatMount.ClusterRelativePos(iCurrentPos.iPos);
-	aInfo.iBlockGranularity = 1 << FatMount().ClusterSizeLog2();
-	const TUint myStartPos = iCurrentPos.iPos;
-	if ( myStartPos + length > FCB_FileSize())
-		return KErrArgument;
+    aInfo.iBlockStartOffset = fatMount.ClusterRelativePos(iCurrentPos.iPos);
+    aInfo.iBlockGranularity = 1 << FatMount().ClusterSizeLog2();
+    const TUint myStartPos = iCurrentPos.iPos;
+    if ( myStartPos + length > FCB_FileSize())
+        return KErrArgument;
 
-	TRAP(r, FatMount().BlockMapReadFromClusterListL(iCurrentPos, length, aInfo));
-	if (r != KErrNone)
-		return r;
+    TRAP(r, FatMount().BlockMapReadFromClusterListL(iCurrentPos, length, aInfo));
+    if (r != KErrNone)
+        return r;
 
-	aStartPos = iCurrentPos.iPos;
-	if ((I64LOW(aStartPos) == FCB_FileSize()) || ( I64LOW(aStartPos) == (myStartPos + length)))
-		return KErrCompletion;
-	else
-		return KErrNone;
-	}
-
+    aStartPos = iCurrentPos.iPos;
+    if ((I64LOW(aStartPos) == FCB_FileSize()) || ( I64LOW(aStartPos) == (myStartPos + length)))
+        return KErrCompletion;
+    else
+        return KErrNone;
+    }
 
 
 TInt CFatFileCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
-	{
-	switch(aInterfaceId)
-		{
-		case EExtendedFileInterface:
-			((CFileCB::MExtendedFileInterface*&) aInterface) = this;
-			return KErrNone;
+    {
+    switch(aInterfaceId)
+        {
+        case EExtendedFileInterface:
+            ((CFileCB::MExtendedFileInterface*&) aInterface) = this;
+            return KErrNone;
 
-		case EBlockMapInterface:
-			aInterface = (CFileCB::MBlockMapInterface*) this;
-			return KErrNone;
-
-		case EGetLocalDrive:
-			return FatMount().LocalDrive()->GetLocalDrive((TBusLocalDrive*&) aInterface);
+        case EBlockMapInterface:
+            aInterface = (CFileCB::MBlockMapInterface*) this;
+            return KErrNone;
 
-		default:
-			return CFileCB::GetInterface(aInterfaceId,aInterface,aInput);
-		}
-	}
+        case EGetLocalDrive:
+            return FatMount().LocalDrive()->GetLocalDrive((TBusLocalDrive*&) aInterface);
 
-
+        default:
+            return CFileCB::GetInterface(aInterfaceId,aInterface,aInput);
+        }
+    }
 
 
 /**
     Overwrites file's start cluster (iStartCluster) in its directory entry.
 */
 void CFatFileCB::FlushStartClusterL()
-	{
-	__PRINT1(_L("CFatFileCB::FlushStartClusterL[0x%x]"), this);
+    {
+    __PRINT1(_L("CFatFileCB::FlushStartClusterL[0x%x]"), this);
 
     CFatMountCB& mount = FatMount();
     TFatDirEntry dirEntry;
@@ -920,15 +912,15 @@
     mount.ReadDirEntryL(iFileDosEntryPos, dirEntry); //-- read this file's dir. entry
     dirEntry.SetStartCluster(FCB_StartCluster());    //-- set new start cluster
     mount.WriteDirEntryL(iFileDosEntryPos, dirEntry);//-- write the entry back
-	}
+    }
 
 
 /**
     This is a RuggedFAT - specific method. Writes file size to the corresponding field of its file directory entry.
 */
 void CFatFileCB::WriteFileSizeL(TUint aSize)
-	{
-	__PRINT2(_L("CFatFileCB::WriteFileSizeL[0x%x], sz:%d"), this, aSize);
+    {
+    __PRINT2(_L("CFatFileCB::WriteFileSizeL[0x%x], sz:%d"), this, aSize);
 
     CFatMountCB& mount = FatMount();
     TFatDirEntry dirEntry;