userlibandfileserver/fileserver/sfat32/ram_fat_table32.cpp
changeset 36 538db54a451d
parent 0 a41df078684a
child 87 2f92ad2dc5db
equal deleted inserted replaced
34:f497542af8e4 36:538db54a451d
   361     //__PRINT(_L("CRamFatTable::DataPositionInBytes"));
   361     //__PRINT(_L("CRamFatTable::DataPositionInBytes"));
   362     ReadIndirectionTable(aCluster);
   362     ReadIndirectionTable(aCluster);
   363     return(aCluster<<iOwner->ClusterSizeLog2());
   363     return(aCluster<<iOwner->ClusterSizeLog2());
   364     }
   364     }
   365 
   365 
       
   366 //-----------------------------------------------------------------------------
       
   367 
       
   368 /**
       
   369     Allocate and link a cluster chain, leaves if there are not enough free clusters.
       
   370     Chain starts as close as possible to aNearestCluster, last cluster will be marked as EOF.
       
   371 
       
   372     @param aNumber Number of clusters to allocate
       
   373     @param aNearestCluster Cluster the new chain should be nearest to
       
   374     @leave System wide error codes
       
   375     @return The first cluster number allocated
       
   376 */
       
   377 TUint32 CRamFatTable::AllocateClusterListL(TUint32 aNumber, TUint32 aNearestCluster)
       
   378 	{
       
   379     __PRINT2(_L("CRamFatTable::AllocateClusterList() N:%d,NearestCL:%d"),aNumber,aNearestCluster);
       
   380 	__ASSERT_DEBUG(aNumber>0, Fault(EFatBadParameter));
       
   381 
       
   382 	if(!RequestFreeClusters(aNumber))
       
   383     	{
       
   384 		__PRINT(_L("CRamFatTable::AllocateClusterListL - leaving KErrDirFull"));
       
   385 		User::Leave(KErrDiskFull);
       
   386 		}
       
   387 
       
   388 	//-- if this leaves for some reason, there will be no lost clusters
       
   389     TInt firstCluster = aNearestCluster = AllocateSingleClusterL(aNearestCluster);
       
   390 	
       
   391     
       
   392     if (aNumber>1)
       
   393 	    {//-- if this part leaves (e.g. fail to expand the RAM drive), we will need to handle the first allocated EOC
       
   394     	TRAPD(nRes, ExtendClusterListL(aNumber-1, (TInt&)aNearestCluster));
       
   395         if(nRes != KErrNone)
       
   396             {
       
   397             __PRINT1(_L("CRamFatTable::AllocateClusterListL:ExtendClusterListL() failed with %d") ,nRes);
       
   398             FreeClusterListL(firstCluster); //-- clean up EOC in firstCluster
       
   399             User::Leave(nRes);
       
   400             }
       
   401         }
       
   402 
       
   403 
       
   404     return firstCluster;
       
   405 	}	
       
   406 
   366 /**
   407 /**
   367 Allocate and mark as EOF a single cluster as close as possible to aNearestCluster,
   408 Allocate and mark as EOF a single cluster as close as possible to aNearestCluster,
   368 calls base class implementation but must Enlarge the RAM drive first. Allocated cluster RAM area will be zero-filled.
   409 calls base class implementation but must Enlarge the RAM drive first. Allocated cluster RAM area will be zero-filled.
   369 
   410 
   370 @param aNearestCluster Cluster the new cluster should be nearest to
   411 @param aNearestCluster Cluster the new cluster should be nearest to
   390     @param aCluster     starting cluster number / ending cluster number after
   431     @param aCluster     starting cluster number / ending cluster number after
   391     @leave KErrDiskFull + system wide error codes
   432     @leave KErrDiskFull + system wide error codes
   392 */
   433 */
   393 void CRamFatTable::ExtendClusterListL(TUint32 aNumber, TInt& aCluster)
   434 void CRamFatTable::ExtendClusterListL(TUint32 aNumber, TInt& aCluster)
   394     {
   435     {
   395     __PRINT(_L("CRamFatTable::ExtendClusterListL"));
   436     __PRINT2(_L("CRamFatTable::ExtendClusterListL(%d, %d)"), aNumber, aCluster);
   396     __ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
   437     __ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
   397 
   438 
   398     iOwner->EnlargeL(aNumber<<iOwner->ClusterSizeLog2());
   439     iOwner->EnlargeL(aNumber<<iOwner->ClusterSizeLog2());
   399 
   440 
   400     while(aNumber && GetNextClusterL(aCluster))
   441     while(aNumber && GetNextClusterL(aCluster))