userlibandfileserver/fileserver/sfat32/fat_table32.cpp
changeset 90 947f0dc9f7a8
parent 36 538db54a451d
child 109 b3a1d9898418
child 189 a5496987b1da
child 249 a179b74831c9
equal deleted inserted replaced
52:2d65c2f76d7b 90:947f0dc9f7a8
   262     }
   262     }
   263 
   263 
   264 //-----------------------------------------------------------------------------
   264 //-----------------------------------------------------------------------------
   265 
   265 
   266 /**
   266 /**
   267 Count the number of contiguous cluster from a start cluster
   267     Count the number of continuous cluster from a start cluster in FAT table.
   268 
   268 
   269 @param aStartCluster cluster to start counting from
   269 @param aStartCluster cluster to start counting from
   270 @param anEndCluster contains the end cluster number upon return
   270     @param  aEndCluster     contains the end cluster number upon return
   271 @param aMaxCount Maximum cluster required
   271 @param aMaxCount Maximum cluster required
   272 @leave System wide error values
   272     @return Number of continuous clusters from aStartCluster.
   273 @return Number of contiguous clusters from aStartCluster.
   273 */
   274 */
   274 TUint32 CFatTable::CountContiguousClustersL(TUint32 aStartCluster, TUint32& aEndCluster, TUint32 aMaxCount) const
   275 TInt CFatTable::CountContiguousClustersL(TUint32 aStartCluster,TInt& anEndCluster,TUint32 aMaxCount) const
       
   276 	{
   275 	{
   277 	__PRINT2(_L("CFatTable::CountContiguousClustersL() start:%d, max:%d"),aStartCluster, aMaxCount);
   276 	__PRINT2(_L("CFatTable::CountContiguousClustersL() start:%d, max:%d"),aStartCluster, aMaxCount);
   278 	TUint32 clusterListLen=1;
   277 
   279 	TInt endCluster=aStartCluster;
   278     ASSERT(ClusterNumberValid(aStartCluster));
   280 	TInt64 endClusterPos=DataPositionInBytes(endCluster);
   279 
   281 	while (clusterListLen<aMaxCount)
   280     TUint32 currClusterNo = aStartCluster;
   282 		{
   281     
   283 		TInt oldCluster=endCluster;
   282     TUint32 clusterListLen;
   284 		TInt64 oldClusterPos=endClusterPos;
   283     for(clusterListLen=1; clusterListLen < aMaxCount; ++clusterListLen)
   285 		if (GetNextClusterL(endCluster)==EFalse || (endClusterPos=DataPositionInBytes(endCluster))!=(oldClusterPos+(1<<iOwner->ClusterSizeLog2())))
   284         {
   286 			{
   285         TUint32 nextClusterNo = currClusterNo;
   287 			endCluster=oldCluster;
   286 
   288 			break;
   287         if(!GetNextClusterL(nextClusterNo))
   289 			}
   288             break; //-- end of cluster chain
   290 		clusterListLen++;
   289             
   291 		}
   290         if(nextClusterNo != currClusterNo+1)
   292 	anEndCluster=endCluster;
   291             break; //-- not the next cluster
   293 	return(clusterListLen);
   292       
       
   293         currClusterNo = nextClusterNo;
       
   294         }
       
   295 
       
   296     aEndCluster = aStartCluster+clusterListLen-1;
       
   297 
       
   298     return clusterListLen;
   294 	}	
   299 	}	
   295 
       
   296 //-----------------------------------------------------------------------------
   300 //-----------------------------------------------------------------------------
   297 
   301 
   298 /**
   302 /**
   299     Extend a file or directory cluster chain, leaves if there are no free clusters (the disk is full).
   303     Extend a file or directory cluster chain, leaves if there are no free clusters (the disk is full).
   300 
   304 
   301     @param aNumber  amount of clusters to allocate
   305     @param aNumber  amount of clusters to allocate
   302     @param aCluster FAT entry index to start with.
   306     @param aCluster FAT entry index to start with.
   303 
   307 
   304     @leave KErrDiskFull + system wide error codes
   308     @leave KErrDiskFull + system wide error codes
   305 */
   309 */
   306 void CFatTable::ExtendClusterListL(TUint32 aNumber,TInt& aCluster)
   310 void CFatTable::ExtendClusterListL(TUint32 aNumber, TUint32& aCluster)
   307 	{
   311 	{
   308 	__PRINT2(_L("CFatTable::ExtendClusterListL() num:%d, clust:%d"), aNumber, aCluster);
   312 	__PRINT2(_L("CFatTable::ExtendClusterListL() num:%d, clust:%d"), aNumber, aCluster);
   309 	__ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
   313 	__ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
   310 	
   314 	
   311 	while(aNumber && GetNextClusterL(aCluster))
   315 	while(aNumber && GetNextClusterL(aCluster))
   383     	{
   387     	{
   384 		__PRINT(_L("CFatTable::AllocateClusterListL - leaving KErrDirFull"));
   388 		__PRINT(_L("CFatTable::AllocateClusterListL - leaving KErrDirFull"));
   385 		User::Leave(KErrDiskFull);
   389 		User::Leave(KErrDiskFull);
   386 		}
   390 		}
   387 
   391 
   388 	TInt firstCluster = aNearestCluster = AllocateSingleClusterL(aNearestCluster);
   392 	TUint32 firstCluster = aNearestCluster = AllocateSingleClusterL(aNearestCluster);
   389 	if (aNumber>1)
   393 	if (aNumber>1)
   390 		ExtendClusterListL(aNumber-1, (TInt&)aNearestCluster);
   394 		ExtendClusterListL(aNumber-1, aNearestCluster);
   391 
   395 
   392     return(firstCluster);
   396     return(firstCluster);
   393 	}	
   397 	}	
   394 
   398 
   395 //-----------------------------------------------------------------------------
   399 //-----------------------------------------------------------------------------
   489 
   493 
   490     TUint32 lastKnownFreeCluster = FreeClusterHint();
   494     TUint32 lastKnownFreeCluster = FreeClusterHint();
   491     TUint32 cntFreedClusters = 0;
   495     TUint32 cntFreedClusters = 0;
   492 
   496 
   493     TUint32 currCluster = aCluster;
   497     TUint32 currCluster = aCluster;
   494     TInt    nextCluster = aCluster;
   498     TUint32 nextCluster = aCluster;
   495 
   499 
   496     for(;;)
   500     for(;;)
   497     {
   501     {
   498         const TBool bEOF = !GetNextClusterL(nextCluster);    
   502         const TBool bEOF = !GetNextClusterL(nextCluster);    
   499         WriteL(currCluster, KSpareCluster);
   503         WriteL(currCluster, KSpareCluster);
  1738     Get the next cluster in the chain from the FAT
  1742     Get the next cluster in the chain from the FAT
  1739 
  1743 
  1740     @param aCluster number to read, contains next cluster upon return
  1744     @param aCluster number to read, contains next cluster upon return
  1741     @return False if end of cluster chain
  1745     @return False if end of cluster chain
  1742 */
  1746 */
  1743 TBool CFatTable::GetNextClusterL(TInt& aCluster) const
  1747 TBool CFatTable::GetNextClusterL(TUint32& aCluster) const
  1744     {
  1748     {
  1745 	__PRINT1(_L("CAtaFatTable::GetNextClusterL(%d)"), aCluster);
  1749 	__PRINT1(_L("CAtaFatTable::GetNextClusterL(%d)"), aCluster);
  1746     
  1750     
  1747     const TUint32 nextCluster = ReadL(aCluster);
  1751     const TUint32 nextCluster = ReadL(aCluster);
  1748     const TBool bEOC = IsEndOfClusterCh(nextCluster);
  1752     const TBool bEOC = IsEndOfClusterCh(nextCluster);