userlibandfileserver/fileserver/sfat32/fat_table32.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
child 268 345b1ca54e88
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
   400 
   400 
   401 /**
   401 /**
   402     Notify the media drive about media areas that shall be treated as "deleted" if this feature is supported.
   402     Notify the media drive about media areas that shall be treated as "deleted" if this feature is supported.
   403     @param aFreedClusters array with FAT numbers of clusters that shall be marked as "deleted"
   403     @param aFreedClusters array with FAT numbers of clusters that shall be marked as "deleted"
   404 */
   404 */
   405 void CFatTable::DoFreedClustersNotify(RClusterArray &aFreedClusters)
   405 void CFatTable::DoFreedClustersNotifyL(RClusterArray &aFreedClusters)
   406 {
   406 {
   407     ASSERT(iMediaAtt & KMediaAttDeleteNotify);
   407     ASSERT(iMediaAtt & KMediaAttDeleteNotify);
   408 
   408 
   409     const TUint clusterCount = aFreedClusters.Count();
   409     const TUint clusterCount = aFreedClusters.Count();
   410 
   410 
   421 	for (TUint i=0; i<clusterCount; ++i)
   421 	for (TUint i=0; i<clusterCount; ++i)
   422 	{
   422 	{
   423         const TUint currCluster = aFreedClusters[i];
   423         const TUint currCluster = aFreedClusters[i];
   424         
   424         
   425         if (deleteLen == 0)
   425         if (deleteLen == 0)
   426 		    byteAddress = DataPositionInBytes(currCluster); //-- start of the media range
   426 		    byteAddress = DataPositionInBytesL(currCluster); //-- start of the media range
   427         
   427         
   428         deleteLen += bytesPerCluster;
   428         deleteLen += bytesPerCluster;
   429 
   429 
   430         //-- if this is the last entry in the array or the net cluster number is not consecutive, notify the driver
   430         //-- if this is the last entry in the array or the net cluster number is not consecutive, notify the driver
   431 		if ((i+1) == clusterCount || aFreedClusters[i+1] != (currCluster+1))
   431 		if ((i+1) == clusterCount || aFreedClusters[i+1] != (currCluster+1))
   436             const TInt r = iOwner->LocalDrive()->DeleteNotify(byteAddress, deleteLen);
   436             const TInt r = iOwner->LocalDrive()->DeleteNotify(byteAddress, deleteLen);
   437 			if(r != KErrNone)
   437 			if(r != KErrNone)
   438                 {//-- if DeleteNotify() failed, it means that something terribly wrong happened to the NAND media; 
   438                 {//-- if DeleteNotify() failed, it means that something terribly wrong happened to the NAND media; 
   439                  //-- in normal circumstances it can not happen. One of the reasons: totally worn out media.
   439                  //-- in normal circumstances it can not happen. One of the reasons: totally worn out media.
   440                 const TBool platSecEnabled = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
   440                 const TBool platSecEnabled = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
   441                 __PRINT3(_L("CFatTable::DoFreedClustersNotify() DeleteNotify failure! drv:%d err:%d, PlatSec:%d"),iOwner->DriveNumber(), r, platSecEnabled);
   441                 __PRINT3(_L("CFatTable::DoFreedClustersNotifyL() DeleteNotify failure! drv:%d err:%d, PlatSec:%d"),iOwner->DriveNumber(), r, platSecEnabled);
   442 
   442 
   443                 if(platSecEnabled)
   443                 if(platSecEnabled)
   444                     {
   444                     {
   445                     //-- if PlatSec is enabled, we can't afford jeopardize the security; without DeleteNotify()
   445                     //-- if PlatSec is enabled, we can't afford jeopardize the security; without DeleteNotify()
   446                     //-- it's possible to pick up data from deleted files, so, panic the file server.
   446                     //-- it's possible to pick up data from deleted files, so, panic the file server.
   519         {//-- reached a limit of the entries in the array. Flush FAT cache, notify the driver and empty the array.
   519         {//-- reached a limit of the entries in the array. Flush FAT cache, notify the driver and empty the array.
   520             IncrementFreeClusterCount(cntFreedClusters);
   520             IncrementFreeClusterCount(cntFreedClusters);
   521             cntFreedClusters = 0;
   521             cntFreedClusters = 0;
   522 
   522 
   523             SetFreeClusterHint(lastKnownFreeCluster);
   523             SetFreeClusterHint(lastKnownFreeCluster);
   524             DoFreedClustersNotify(deletedClusters);
   524             DoFreedClustersNotifyL(deletedClusters);
   525         }
   525         }
   526 
   526 
   527     }
   527     }
   528 
   528 
   529     //-- increase the number of free clusters and notify the driver if required.
   529     //-- increase the number of free clusters and notify the driver if required.
   530     IncrementFreeClusterCount(cntFreedClusters);
   530     IncrementFreeClusterCount(cntFreedClusters);
   531     SetFreeClusterHint(lastKnownFreeCluster);
   531     SetFreeClusterHint(lastKnownFreeCluster);
   532     
   532     
   533     if(bFreeClustersNotify)
   533     if(bFreeClustersNotify)
   534         DoFreedClustersNotify(deletedClusters);
   534         DoFreedClustersNotifyL(deletedClusters);
   535 
   535 
   536 	CleanupStack::PopAndDestroy(&deletedClusters);
   536 	CleanupStack::PopAndDestroy(&deletedClusters);
   537 	}
   537 	}
   538 
   538 
   539 //-----------------------------------------------------------------------------
   539 //-----------------------------------------------------------------------------
   669     //__PRINT1(_L("#- CFatTable::RequestFreeClusters(%d)"),aClustersRequired);
   669     //__PRINT1(_L("#- CFatTable::RequestFreeClusters(%d)"),aClustersRequired);
   670     ASSERT(aClustersRequired >0);
   670     ASSERT(aClustersRequired >0);
   671     return (NumberOfFreeClusters() >= aClustersRequired);
   671     return (NumberOfFreeClusters() >= aClustersRequired);
   672     }
   672     }
   673 
   673 
   674 //-----------------------------------------------------------------------------
       
   675 /**
       
   676     @return ETrue if the cluster number aClusterNo is valid, i.e. belongs to the FAT table
       
   677 */
       
   678 TBool CFatTable::ClusterNumberValid(TUint32 aClusterNo) const 
       
   679     {
       
   680     return (aClusterNo >= KFatFirstSearchCluster) && (aClusterNo < iMaxEntries); 
       
   681     }
       
   682     
   674     
   683 
   675 
   684 
   676 
   685 //#######################################################################################################################################
   677 //#######################################################################################################################################
   686 //#     CAtaFatTable class implementation 
   678 //#     CAtaFatTable class implementation 
   690     Constructor
   682     Constructor
   691 */
   683 */
   692 CAtaFatTable::CAtaFatTable(CFatMountCB& aOwner)
   684 CAtaFatTable::CAtaFatTable(CFatMountCB& aOwner)
   693              :CFatTable(aOwner), iDriveInteface(aOwner.DriveInterface())
   685              :CFatTable(aOwner), iDriveInteface(aOwner.DriveInterface())
   694     {
   686     {
   695     iState = ENotInitialised;
   687         iState = ENotInitialised;
   696     }
   688     }
   697 
   689 
   698 
   690 
   699 CAtaFatTable::~CAtaFatTable()
   691 CAtaFatTable::~CAtaFatTable()
   700     {
   692     {
  1042         if(pFatBitCache)
  1034         if(pFatBitCache)
  1043             {//-- bit cache is present, we need to populate (or repopulate it)
  1035             {//-- bit cache is present, we need to populate (or repopulate it)
  1044             //-- create helper thread object and start the thread
  1036             //-- create helper thread object and start the thread
  1045             ipHelperThread = CFat32BitCachePopulator::NewL(*this);
  1037             ipHelperThread = CFat32BitCachePopulator::NewL(*this);
  1046 
  1038 
  1047             if(ipHelperThread->Launch() != KErrNone)
  1039             ipHelperThread->Launch(); 
  1048                 {//-- failed for some reason
  1040             //-- background FAT bit cache populating thread is running now.
  1049                 DestroyHelperThread();
  1041             //-- the result of thread start up and completion isn't very interesting: If it fails to 
  1050                 }
  1042             //-- properly populate the cache, nothing fatal will happen.
  1051                 else
       
  1052                 {
       
  1053                 //-- background FAT bit cache populating thread is running now.
       
  1054                 //-- the result of thread start up and completion isn't very interesting: If it fails to 
       
  1055                 //-- properly populate the cache, nothing fatal will happen.
       
  1056                 }
       
  1057             }
  1043             }
  1058 
  1044 
  1059         //-- CFat32BitCachePopulator doesn't affect FAT table state. 
  1045         //-- CFat32BitCachePopulator doesn't affect FAT table state. 
  1060         SetState(EMounted);
  1046         SetState(EMounted);
  1061         return; 
  1047         return; 
  1484                 TInt nMntDebugFlags;
  1470                 TInt nMntDebugFlags;
  1485                 if(bFat32BkGndScan && RProperty::Get(KSID_Test1, iOwner->DriveNumber(), nMntDebugFlags) == KErrNone)
  1471                 if(bFat32BkGndScan && RProperty::Get(KSID_Test1, iOwner->DriveNumber(), nMntDebugFlags) == KErrNone)
  1486                 {//-- test property for this drive is defined
  1472                 {//-- test property for this drive is defined
  1487                     if(nMntDebugFlags & KMntDisable_FatBkGndScan)
  1473                     if(nMntDebugFlags & KMntDisable_FatBkGndScan)
  1488                     {
  1474                     {
  1489                     __PRINT(_L("#- FAT32 BkGnd scan is disabled by debug interface."));
  1475                     __PRINT(_L("#- FAT32 BkGnd scan is disabled is disabled by debug interface."));
  1490                     bFat32BkGndScan = EFalse;
  1476                     bFat32BkGndScan = EFalse;
  1491                     }
  1477                     }
  1492             
  1478             
  1493                 }
  1479                 }
  1494 #endif
  1480 #endif
  1548     //-- 2. create helper thread object and start the thread
  1534     //-- 2. create helper thread object and start the thread
  1549     ipHelperThread = CFat32FreeSpaceScanner::NewL(*this);
  1535     ipHelperThread = CFat32FreeSpaceScanner::NewL(*this);
  1550     
  1536     
  1551     SetState(EFreeClustersScan);
  1537     SetState(EFreeClustersScan);
  1552     
  1538     
  1553     User::LeaveIfError(ipHelperThread->Launch()); 
  1539     ipHelperThread->Launch(); 
  1554     
       
  1555     //-- background FAT scanning thread is running now
  1540     //-- background FAT scanning thread is running now
  1556     }
  1541     }
  1557 
  1542 
  1558 //-----------------------------------------------------------------------------
  1543 //-----------------------------------------------------------------------------
  1559 /**
  1544 /**
  1794     FlushL();
  1779     FlushL();
  1795 	}
  1780 	}
  1796 
  1781 
  1797 
  1782 
  1798 /**
  1783 /**
  1799     Return the location of a Cluster in the data section of the media
  1784     Return media position in bytes of the cluster start
  1800 
  1785 
  1801     @param aCluster to find location of
  1786     @param aCluster to find location of
  1802     @return Byte offset of the cluster data 
  1787     @return Byte offset of the cluster data 
  1803 */
  1788 */
  1804 TInt64 CAtaFatTable::DataPositionInBytes(TUint32 aCluster) const
  1789 TInt64 CAtaFatTable::DataPositionInBytesL(TUint32 aCluster) const
  1805 	{
  1790 	{
  1806 
  1791     if(!ClusterNumberValid(aCluster))
  1807     __ASSERT_DEBUG(ClusterNumberValid(aCluster), Fault(EFatTable_InvalidIndex));
  1792         {
  1808 
  1793         __ASSERT_DEBUG(0, Fault(EFatTable_InvalidIndex));
  1809     const TInt clusterBasePosition=iOwner->ClusterBasePosition();
  1794         User::Leave(KErrCorrupt);
       
  1795         }
       
  1796 
       
  1797     const TUint32 clusterBasePosition=iOwner->ClusterBasePosition();
  1810 	return(((TInt64(aCluster)-KFatFirstSearchCluster) << iOwner->ClusterSizeLog2()) + clusterBasePosition);
  1798 	return(((TInt64(aCluster)-KFatFirstSearchCluster) << iOwner->ClusterSizeLog2()) + clusterBasePosition);
  1811 	}
  1799 	}
  1812 
  1800 
  1813 
  1801 
  1814 
  1802 
  1969         ForceStop();
  1957         ForceStop();
  1970         ASSERT(0);
  1958         ASSERT(0);
  1971         return nRes;
  1959         return nRes;
  1972         }
  1960         }
  1973 
  1961 
  1974     //-- Helper FAT thread is running now
  1962    //-- Helper FAT thread is running now
  1975     return KErrNone; 
  1963    return KErrNone; 
  1976     }
  1964     }
  1977 
  1965 
  1978 
  1966 
  1979 //#######################################################################################################################################
  1967 //#######################################################################################################################################
  1980 //#     CFat32ScanThread implementation
  1968 //#     CFat32ScanThread implementation
  1988 
  1976 
  1989 //-----------------------------------------------------------------------------
  1977 //-----------------------------------------------------------------------------
  1990 
  1978 
  1991 /**
  1979 /**
  1992     Launches the FAT32_ScanThread scaner thread.
  1980     Launches the FAT32_ScanThread scaner thread.
  1993     @return  KErrNone if the thread launched OK
  1981     @return  standard error code
  1994              standard error code otherwise
       
  1995 */
  1982 */
  1996 TInt CFat32ScanThread::Launch()
  1983 TInt CFat32ScanThread::Launch()
  1997     {
  1984     {
  1998     return DoLaunchThread(FAT32_ScanThread, this);    
  1985     return DoLaunchThread(FAT32_ScanThread, this);    
  1999     }
  1986     }