userlibandfileserver/fileserver/sfat32/sl_file.cpp
branchRCL_3
changeset 294 039a3e647356
parent 257 3e88ff8f41d5
equal deleted inserted replaced
268:345b1ca54e88 294:039a3e647356
   101 	__ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
   101 	__ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
   102 	__ASSERT_DEBUG(seekPos>=0,Fault(EFatFileSeekIndexTooSmall2));
   102 	__ASSERT_DEBUG(seekPos>=0,Fault(EFatFileSeekIndexTooSmall2));
   103 	iSeekIndex[seekPos] = aStoredCluster;
   103 	iSeekIndex[seekPos] = aStoredCluster;
   104 	}
   104 	}
   105 
   105 
       
   106 TBool CFatFileCB::IsSeekBackwards(TUint aPos)
       
   107 //
       
   108 // Return true if aPos<currentPos
       
   109 //
       
   110 	{
       
   111 	
       
   112 	TUint cluster=iCurrentPos.iCluster<<ClusterSizeLog2();
       
   113 	TInt offset=ClusterRelativePos(iCurrentPos.iPos);
       
   114 	TUint currentPos=cluster+offset;
       
   115 	return(aPos<currentPos);
       
   116 	}
       
   117 
   106 void CFatFileCB::CheckPosL(TUint aPos)
   118 void CFatFileCB::CheckPosL(TUint aPos)
   107 //
   119 //
   108 // Check that the file is positioned correctly.
   120 // Check that the file is positioned correctly.
   109 // If aPos<currentPos attempt to guess the new position.
   121 // If aPos<currentPos attempt to guess the new position.
   110 //
   122 //
   112 	__PRINT1(_L("CFatFileCB::CheckPosL(%d)"), aPos);
   124 	__PRINT1(_L("CFatFileCB::CheckPosL(%d)"), aPos);
   113 	if (aPos==iCurrentPos.iPos)
   125 	if (aPos==iCurrentPos.iPos)
   114 		return;
   126 		return;
   115     __ASSERT_DEBUG(aPos <= FCB_FileSize(), Fault(EFatFilePosBeyondEnd));
   127     __ASSERT_DEBUG(aPos <= FCB_FileSize(), Fault(EFatFilePosBeyondEnd));
   116 
   128 
       
   129 	if (FileSizeModified() && IsSeekBackwards(aPos))
       
   130 		FlushDataL(); 
       
   131 	
   117 	TUint newRelCluster=aPos>>ClusterSizeLog2();
   132 	TUint newRelCluster=aPos>>ClusterSizeLog2();
   118 	if ( aPos && (aPos==(newRelCluster<<ClusterSizeLog2())) )
   133 	if ( aPos && (aPos==(newRelCluster<<ClusterSizeLog2())) )
   119 		newRelCluster--;
   134 		newRelCluster--;
   120 	TUint oldRelCluster=iCurrentPos.iPos>>ClusterSizeLog2();
   135 	TUint oldRelCluster=iCurrentPos.iPos>>ClusterSizeLog2();
   121 	
   136 	
   228 	const TUint curSize  = FCB_FileSize();
   243 	const TUint curSize  = FCB_FileSize();
   229 	const TUint length   = (TUint)aLength;
   244 	const TUint length   = (TUint)aLength;
   230 	
   245 	
   231 	if((startPos + length > curSize) || (startPos > startPos + length) )
   246 	if((startPos + length > curSize) || (startPos > startPos + length) )
   232 		aLength=curSize-startPos;
   247 		aLength=curSize-startPos;
   233 		
   248 	
   234 	TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0;
   249     FatMount().ReadFromClusterListL(iCurrentPos,aLength,aDes,aMessage,aOffset);
   235 	
       
   236     FatMount().ReadFromClusterListL(iCurrentPos,aLength,aDes,aMessage,aOffset, flag);
       
   237 	aLength=iCurrentPos.iPos-startPos;
   250 	aLength=iCurrentPos.iPos-startPos;
   238 	}
   251 	}
   239 
   252 
   240 
   253 
   241 void CFatFileCB::ReadL(TInt aFilePos,TInt& aLength,const TAny* aTrg,const RMessagePtr2& aMessage)
   254 void CFatFileCB::ReadL(TInt aFilePos,TInt& aLength,const TAny* aTrg,const RMessagePtr2& aMessage)
   280    	
   293    	
   281 	TUint startPos=iCurrentPos.iPos;
   294 	TUint startPos=iCurrentPos.iPos;
   282 	TUint badcluster=0;
   295 	TUint badcluster=0;
   283 	TUint goodcluster=0;
   296 	TUint goodcluster=0;
   284    	
   297    	
   285 	TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0;
   298 	TRAPD(ret, FatMount().WriteToClusterListL(iCurrentPos,aLength,aSrc,aMessage,aOffset,badcluster, goodcluster));
   286 	
       
   287 	TRAPD(ret, FatMount().WriteToClusterListL(iCurrentPos,aLength,aSrc,aMessage,aOffset,badcluster, goodcluster, flag));
       
   288    	
   299    	
   289 	if (ret == KErrCorrupt || ret == KErrDied)
   300 	if (ret == KErrCorrupt || ret == KErrDied)
   290 		{
   301 		{
   291         if(startCluster == 0)
   302         if(startCluster == 0)
   292 			{ //Empty File, revert all the clusters allocated.
   303 			{ //Empty File, revert all the clusters allocated.
   851 	if((fatMount.LocalDrive()->GetLocalDrive(locDrv)==KErrNone) && ((drvNo=GetLocalDriveNumber(locDrv))>=0) && (drvNo<KMaxLocalDrives))
   862 	if((fatMount.LocalDrive()->GetLocalDrive(locDrv)==KErrNone) && ((drvNo=GetLocalDriveNumber(locDrv))>=0) && (drvNo<KMaxLocalDrives))
   852 		aInfo.iLocalDriveNumber=drvNo;
   863 		aInfo.iLocalDriveNumber=drvNo;
   853 	else
   864 	else
   854 		return KErrNotSupported;
   865 		return KErrNotSupported;
   855 
   866 
   856     TInt r;
   867 	// Fetch the address of cluster 0
   857 	
   868 	aInfo.iStartBlockAddress = fatMount.FAT().DataPositionInBytes(KFirstClusterNum);
   858     // Fetch the address of cluster 0
   869 
   859 	TRAP(r, aInfo.iStartBlockAddress = fatMount.FAT().DataPositionInBytesL(KFirstClusterNum));
   870 	TRAPD(r, CheckPosL(startPos));
   860 	if (r != KErrNone)
       
   861 		return r;
       
   862 
       
   863 
       
   864 	TRAP(r, CheckPosL(startPos));
       
   865 	if (r != KErrNone)
   871 	if (r != KErrNone)
   866 		return r;
   872 		return r;
   867 
   873 
   868 	aInfo.iBlockStartOffset = fatMount.ClusterRelativePos(iCurrentPos.iPos);
   874 	aInfo.iBlockStartOffset = fatMount.ClusterRelativePos(iCurrentPos.iPos);
   869 	aInfo.iBlockGranularity = 1 << FatMount().ClusterSizeLog2();
   875 	aInfo.iBlockGranularity = 1 << FatMount().ClusterSizeLog2();