--- a/userlibandfileserver/fileserver/sfat/fat_table.cpp Mon Oct 19 15:55:17 2009 +0100
+++ b/userlibandfileserver/fileserver/sfat/fat_table.cpp Mon Dec 21 16:14:42 2009 +0000
@@ -21,6 +21,13 @@
@internalTechnology
*/
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!
+//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
+//!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include "sl_std.h"
@@ -42,14 +49,14 @@
@return Pointer to the Fat table
*/
CFatTable* CFatTable::NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps)
- {
+ {
CFatTable* pFatTable=NULL;
switch(aLocDrvCaps.iType)
{
case EMediaRam:
- {//-- this is RAM media, try to create CRamFatTable instance.
+ {//-- this is RAM media, try to create CRamFatTable instance.
const TFatType fatType = aOwner.FatType();
if(fatType != EFat16 )
@@ -65,12 +72,12 @@
default:
//-- other media
- pFatTable = CAtaFatTable::NewL(aOwner);
+ pFatTable = CAtaFatTable::NewL(aOwner);
break;
};
- return pFatTable;
- }
+ return pFatTable;
+ }
CFatTable::CFatTable(CFatMountCB& aOwner)
{
@@ -91,8 +98,8 @@
Initialise the object, get data from the owning CFatMountCB
*/
void CFatTable::InitializeL()
- {
- ASSERT(iOwner);
+ {
+ ASSERT(iOwner);
//-- get FAT type from the owner
iFatType = iOwner->FatType();
@@ -101,16 +108,16 @@
iFreeClusterHint = KFatFirstSearchCluster;
//-- cache the media attributes
- TLocalDriveCapsV2 caps;
- TPckg<TLocalDriveCapsV2> capsPckg(caps);
+ TLocalDriveCapsV2 caps;
+ TPckg<TLocalDriveCapsV2> capsPckg(caps);
User::LeaveIfError(iOwner->LocalDrive()->Caps(capsPckg));
- iMediaAtt = caps.iMediaAtt;
-
+ iMediaAtt = caps.iMediaAtt;
+
//-- obtain maximal number of entries in the table
iMaxEntries = iOwner->UsableClusters()+KFatFirstSearchCluster; //-- FAT[0] & FAT[1] are not in use
__PRINT3(_L("CFatTable::InitializeL(), drv:%d, iMediaAtt = %08X, max Entries:%d"), iOwner->DriveNumber(), iMediaAtt, iMaxEntries);
- }
+ }
//-----------------------------------------------------------------------------
@@ -136,7 +143,7 @@
*/
void CFatTable::IncrementFreeClusterCount(TUint32 aCount)
{
- const TUint32 newVal = iFreeClusters+aCount;
+ const TUint32 newVal = iFreeClusters+aCount;
__ASSERT_DEBUG(newVal<=MaxEntries(), Fault(EFatCorrupt));
iFreeClusters = newVal;
@@ -202,16 +209,16 @@
timeStart.UniversalTime(); //-- take start time
//-- walk through whole FAT table looking for free clusters
- for(TUint i=KFatFirstSearchCluster; i<MaxEntries(); ++i)
+ for(TUint i=KFatFirstSearchCluster; i<MaxEntries(); ++i)
{
- if(ReadL(i) == KSpareCluster)
+ if(ReadL(i) == KSpareCluster)
{//-- found a free cluster
- ++freeClusters;
+ ++freeClusters;
if(!firstFreeCluster)
firstFreeCluster = i;
}
- }
+ }
timeEnd.UniversalTime(); //-- take end time
const TInt msScanTime = (TInt)( (timeEnd.MicroSecondsFrom(timeStart)).Int64() / K1mSec);
@@ -239,25 +246,25 @@
@return Number of contiguous clusters from aStartCluster.
*/
TInt CFatTable::CountContiguousClustersL(TUint32 aStartCluster,TInt& anEndCluster,TUint32 aMaxCount) const
- {
- __PRINT2(_L("CFatTable::CountContiguousClustersL() start:%d, max:%d"),aStartCluster, aMaxCount);
- TUint32 clusterListLen=1;
- TInt endCluster=aStartCluster;
- TInt64 endClusterPos=DataPositionInBytes(endCluster);
- while (clusterListLen<aMaxCount)
- {
- TInt oldCluster=endCluster;
- TInt64 oldClusterPos=endClusterPos;
- if (GetNextClusterL(endCluster)==EFalse || (endClusterPos=DataPositionInBytes(endCluster))!=(oldClusterPos+(1<<iOwner->ClusterSizeLog2())))
- {
- endCluster=oldCluster;
- break;
- }
- clusterListLen++;
- }
- anEndCluster=endCluster;
- return(clusterListLen);
- }
+ {
+ __PRINT2(_L("CFatTable::CountContiguousClustersL() start:%d, max:%d"),aStartCluster, aMaxCount);
+ TUint32 clusterListLen=1;
+ TInt endCluster=aStartCluster;
+ TInt64 endClusterPos=DataPositionInBytes(endCluster);
+ while (clusterListLen<aMaxCount)
+ {
+ TInt oldCluster=endCluster;
+ TInt64 oldClusterPos=endClusterPos;
+ if (GetNextClusterL(endCluster)==EFalse || (endClusterPos=DataPositionInBytes(endCluster))!=(oldClusterPos+(1<<iOwner->ClusterSizeLog2())))
+ {
+ endCluster=oldCluster;
+ break;
+ }
+ clusterListLen++;
+ }
+ anEndCluster=endCluster;
+ return(clusterListLen);
+ }
//-----------------------------------------------------------------------------
@@ -270,33 +277,33 @@
@leave KErrDiskFull + system wide error codes
*/
void CFatTable::ExtendClusterListL(TUint32 aNumber,TInt& aCluster)
- {
- __PRINT2(_L("CFatTable::ExtendClusterListL() num:%d, clust:%d"), aNumber, aCluster);
- __ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
-
- while(aNumber && GetNextClusterL(aCluster))
- aNumber--;
+ {
+ __PRINT2(_L("CFatTable::ExtendClusterListL() num:%d, clust:%d"), aNumber, aCluster);
+ __ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
+
+ while(aNumber && GetNextClusterL(aCluster))
+ aNumber--;
if(!aNumber)
return;
- if (iFreeClusters<aNumber)
- {
- __PRINT(_L("CFatTable::ExtendClusterListL - leaving KErrDirFull"));
- User::Leave(KErrDiskFull);
- }
+ if (iFreeClusters<aNumber)
+ {
+ __PRINT(_L("CFatTable::ExtendClusterListL - leaving KErrDirFull"));
+ User::Leave(KErrDiskFull);
+ }
TUint32 freeCluster = 0;
//-- note: this can be impoved by trying to fing as long chain of free clusters as possible in FindClosestFreeClusterL()
for(TUint i=0; i<aNumber; ++i)
- {
+ {
freeCluster = FindClosestFreeClusterL(aCluster);
- WriteFatEntryEofL(freeCluster); // Must write EOF for FindClosestFreeCluster to work again
- WriteL(aCluster,freeCluster);
- aCluster=freeCluster;
- }
+ WriteFatEntryEofL(freeCluster); // Must write EOF for FindClosestFreeCluster to work again
+ WriteL(aCluster,freeCluster);
+ aCluster=freeCluster;
+ }
//-- decrement number of available clusters
DecrementFreeClusterCount(aNumber);
@@ -304,7 +311,7 @@
//-- update free cluster hint, it isn't required to be a precise value, just a hint where to start the from from
SetFreeClusterHint(aCluster);
- }
+ }
//-----------------------------------------------------------------------------
@@ -316,19 +323,19 @@
@return The cluster number allocated
*/
TUint32 CFatTable::AllocateSingleClusterL(TUint32 aNearestCluster)
- {
- __PRINT1(_L("CFatTable::AllocateSingleCluster() nearest:%d"), aNearestCluster);
- if (iFreeClusters==0)
- User::Leave(KErrDiskFull);
- const TInt freeCluster=FindClosestFreeClusterL(aNearestCluster);
- WriteFatEntryEofL(freeCluster);
- DecrementFreeClusterCount(1);
+ {
+ __PRINT1(_L("CFatTable::AllocateSingleCluster() nearest:%d"), aNearestCluster);
+ if (iFreeClusters==0)
+ User::Leave(KErrDiskFull);
+ const TInt freeCluster=FindClosestFreeClusterL(aNearestCluster);
+ WriteFatEntryEofL(freeCluster);
+ DecrementFreeClusterCount(1);
//-- update free cluster hint, it isn't required to be a precise value, just a hint where to start the from from.
SetFreeClusterHint(freeCluster);
- return(freeCluster);
- }
+ return(freeCluster);
+ }
//-----------------------------------------------------------------------------
@@ -342,22 +349,22 @@
@return The first cluster number allocated
*/
TUint32 CFatTable::AllocateClusterListL(TUint32 aNumber, TUint32 aNearestCluster)
- {
+ {
__PRINT2(_L("#>> CFatTable::AllocateClusterList() N:%d,NearestCL:%d"),aNumber,aNearestCluster);
- __ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
+ __ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
- if (iFreeClusters<aNumber)
- {
- __PRINT(_L("CFatTable::AllocateClusterListL - leaving KErrDirFull"));
- User::Leave(KErrDiskFull);
- }
+ if (iFreeClusters<aNumber)
+ {
+ __PRINT(_L("CFatTable::AllocateClusterListL - leaving KErrDirFull"));
+ User::Leave(KErrDiskFull);
+ }
TInt firstCluster = aNearestCluster = AllocateSingleClusterL(aNearestCluster);
- if (aNumber>1)
- ExtendClusterListL(aNumber-1, (TInt&)aNearestCluster);
+ if (aNumber>1)
+ ExtendClusterListL(aNumber-1, (TInt&)aNearestCluster);
- return(firstCluster);
- }
+ return(firstCluster);
+ }
//-----------------------------------------------------------------------------
@@ -378,25 +385,25 @@
const TUint bytesPerCluster = 1 << iOwner->ClusterSizeLog2();
- TInt64 byteAddress = 0;
- TUint deleteLen = 0; // zero indicates no clusters accumulated yet
+ TInt64 byteAddress = 0;
+ TUint deleteLen = 0; // zero indicates no clusters accumulated yet
- for (TUint i=0; i<clusterCount; ++i)
- {
+ for (TUint i=0; i<clusterCount; ++i)
+ {
const TUint currCluster = aFreedClusters[i];
if (deleteLen == 0)
- byteAddress = DataPositionInBytes(currCluster); //-- start of the media range
+ byteAddress = DataPositionInBytes(currCluster); //-- start of the media range
deleteLen += bytesPerCluster;
//-- if this is the last entry in the array or the net cluster number is not consecutive, notify the driver
- if ((i+1) == clusterCount || aFreedClusters[i+1] != (currCluster+1))
+ if ((i+1) == clusterCount || aFreedClusters[i+1] != (currCluster+1))
{
//__PRINT3(_L("DeleteNotify(%08X:%08X, %u), first cluster %u last cluster #%u"), I64HIGH(byteAddress), I64LOW(byteAddress), deleteLen);
- //__PRINT2(_L(" first cluster %u last cluster #%u"), I64LOW((byteAddress - iOwner->ClusterBasePosition()) >> iOwner->ClusterSizeLog2()) + 2, cluster);
+ //__PRINT2(_L(" first cluster %u last cluster #%u"), I64LOW((byteAddress - iOwner->ClusterBasePosition()) >> iOwner->ClusterSizeLog2()) + 2, cluster);
const TInt r = iOwner->LocalDrive()->DeleteNotify(byteAddress, deleteLen);
- if(r != KErrNone)
+ if(r != KErrNone)
{//-- if DeleteNotify() failed, it means that something terribly wrong happened to the NAND media;
//-- in normal circumstances it can not happen. One of the reasons: totally worn out media.
const TBool platSecEnabled = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
@@ -414,7 +421,7 @@
__ASSERT_DEBUG(0, Fault(EFatBadLocalDrive));
}
}
-
+
deleteLen = 0;
}
@@ -433,15 +440,15 @@
@leave System wide error codes
*/
void CFatTable::FreeClusterListL(TUint32 aCluster)
- {
- __PRINT1(_L("CFatTable::FreeClusterListL startCluster=%d"),aCluster);
- if (aCluster == KSpareCluster)
- return;
+ {
+ __PRINT1(_L("CFatTable::FreeClusterListL startCluster=%d"),aCluster);
+ if (aCluster == KSpareCluster)
+ return;
- //-- here we can store array of freed cluster numbers in order to
+ //-- here we can store array of freed cluster numbers in order to
//-- notify media drive about the media addresses marked as "invalid"
RClusterArray deletedClusters;
- CleanupClosePushL(deletedClusters);
+ CleanupClosePushL(deletedClusters);
//-- if ETrue, we need to notify media driver about invalidated media addressses
const TBool bFreeClustersNotify = iMediaAtt & KMediaAttDeleteNotify;
@@ -460,22 +467,22 @@
TInt nextCluster = aCluster;
for(;;)
- {
+ {
const TBool bEOF = !GetNextClusterL(nextCluster);
WriteL(currCluster, KSpareCluster);
lastKnownFreeCluster = Min(currCluster, lastKnownFreeCluster);
- // Keep a record of the deleted clusters so that we can subsequently notify the media driver. This is only safe
- // to do once the FAT changes have been written to disk.
+ // Keep a record of the deleted clusters so that we can subsequently notify the media driver. This is only safe
+ // to do once the FAT changes have been written to disk.
if(bFreeClustersNotify)
deletedClusters.Append(currCluster);
++cntFreedClusters;
currCluster = nextCluster;
- if (bEOF || aCluster == KSpareCluster)
- break;
+ if (bEOF || aCluster == KSpareCluster)
+ break;
if(bFreeClustersNotify && cntFreedClusters && (cntFreedClusters & (KSubListLen-1))==0)
{//-- reached a limit of the entries in the array. Flush FAT cache, notify the driver and empty the array.
@@ -495,8 +502,8 @@
if(bFreeClustersNotify)
DoFreedClustersNotify(deletedClusters);
- CleanupStack::PopAndDestroy(&deletedClusters);
- }
+ CleanupStack::PopAndDestroy(&deletedClusters);
+ }
//-----------------------------------------------------------------------------
@@ -509,7 +516,7 @@
@return cluster number found
*/
TUint32 CFatTable::FindClosestFreeClusterL(TUint32 aCluster)
- {
+ {
__PRINT2(_L("CFatTable::FindClosestFreeClusterL() drv:%d cl:%d"),iOwner->DriveNumber(),aCluster);
if(!ClusterNumberValid(aCluster))
@@ -520,11 +527,11 @@
if(iFreeClusters==0)
- {//-- there is no at least 1 free cluster available
- __PRINT(_L("CFatTable::FindClosestFreeClusterL() leaving KErrDiskFull #1"));
- User::Leave(KErrDiskFull);
+ {//-- there is no at least 1 free cluster available
+ __PRINT(_L("CFatTable::FindClosestFreeClusterL() leaving KErrDiskFull #1"));
+ User::Leave(KErrDiskFull);
}
-
+
//-- 1. look if the given index contains a free entry
if(ReadL(aCluster) != KSpareCluster)
{//-- no, it doesn't...
@@ -560,22 +567,22 @@
}
if(!canGoRight && !canGoLeft)
- {
- __PRINT(_L("CFatTable::FindClosestFreeClusterL() leaving KErrDiskFull #2"));
+ {
+ __PRINT(_L("CFatTable::FindClosestFreeClusterL() leaving KErrDiskFull #2"));
User::Leave(KErrDiskFull);
}
if (canGoRight && ReadL(rightIdx) == KSpareCluster)
- {
- aCluster = rightIdx;
- break;
- }
+ {
+ aCluster = rightIdx;
+ break;
+ }
- if (canGoLeft && ReadL(leftIdx) == KSpareCluster)
- {
- aCluster = leftIdx;
- break;
- }
+ if (canGoLeft && ReadL(leftIdx) == KSpareCluster)
+ {
+ aCluster = leftIdx;
+ break;
+ }
}//for(..)
}//if(ReadL(aCluster) != KSpareCluster)
@@ -588,7 +595,7 @@
// __PRINT1(_L("CFatTable::FindClosestFreeClusterL found:%d"),aCluster);
return aCluster;
- }
+ }
//-----------------------------------------------------------------------------
@@ -599,7 +606,7 @@
@return Number of bytes from the beginning of the FAT
*/
TUint32 CFatTable::PosInBytes(TUint32 aFatIndex) const
- {
+ {
switch(FatType())
{
case EFat12:
@@ -613,7 +620,7 @@
return 0;//-- get rid of warning
};
- }
+ }
//-----------------------------------------------------------------------------
@@ -651,8 +658,8 @@
*/
CAtaFatTable::CAtaFatTable(CFatMountCB& aOwner)
:CFatTable(aOwner)
- {
- }
+ {
+ }
/** factory method */
@@ -680,7 +687,7 @@
ASSERT(iOwner);
const TUint32 fatSize=iOwner->FatSizeInBytes();
__PRINT3(_L("CAtaFatTable::CreateCacheL drv:%d, FAT:%d, FAT Size:%d"), iOwner->DriveNumber(), FatType(), fatSize);
-
+
//-- according to FAT specs:
//-- FAT12 max size is 4084 entries or 6126 bytes => create fixed cache for whole FAT
@@ -718,7 +725,7 @@
default:
ASSERT(0);
- User::Leave(KErrCorrupt);
+ User::Leave(KErrCorrupt);
break;
};
@@ -733,33 +740,33 @@
@leave System wide error codes
*/
void CAtaFatTable::FlushL()
- {
+ {
//-- the data can't be written if the mount is inconsistent
iOwner->CheckStateConsistentL();
- if (iCache)
- iCache->FlushL();
- }
+ if (iCache)
+ iCache->FlushL();
+ }
/**
Clear any cached data
@param aDiscardDirtyData if ETrue, non-flushed data in the cache will be discarded.
*/
void CAtaFatTable::Dismount(TBool aDiscardDirtyData)
- {
- if (iCache)
- {
+ {
+ if (iCache)
+ {
//-- cache's Close() can check if the cache is clean.
//-- ignore dirty data in cache if the mount is not in consistent state (it's impossible to flush cache data)
//-- or if we are asked to do so.
const TBool bIgnoreDirtyData = aDiscardDirtyData || !iOwner->ConsistentState();
iCache->Close(bIgnoreDirtyData);
- delete iCache;
- iCache=NULL;
- }
+ delete iCache;
+ iCache=NULL;
+ }
- }
+ }
//---------------------------------------------------------------------------------------------------------------------------------------
@@ -790,7 +797,7 @@
@param aLength length in bytes of region to invalidate / refresh
*/
void CAtaFatTable::InvalidateCacheL(TInt64 aPos, TUint32 aLength)
- {
+ {
__PRINT3(_L("CAtaFatTable::InvalidateCacheL() drv:%d, pos:%LU, len:%u,"), iOwner->DriveNumber(), aPos, aLength);
if(I64HIGH(aPos) || !aLength || I64HIGH(aPos+aLength))
@@ -864,7 +871,7 @@
}
User::LeaveIfError(iCache->InvalidateRegion(startFatEntry, numEntries));
- }
+ }
//-----------------------------------------------------------------------------
@@ -873,14 +880,14 @@
@leave KErrNoMemory
*/
void CAtaFatTable::InitializeL()
- {
+ {
__PRINT1(_L("CAtaFatTable::InitializeL() drv:%d"), iOwner->DriveNumber());
CFatTable::InitializeL();
//-- create the FAT cache.
ASSERT(!iCache);
CreateCacheL();
- }
+ }
//-----------------------------------------------------------------------------
@@ -914,7 +921,7 @@
@return FAT entry value
*/
TUint32 CAtaFatTable::ReadL(TUint32 aFatIndex) const
- {
+ {
if(!ClusterNumberValid(aFatIndex))
{
//ASSERT(0); //-- for some silly reason some callers pass 0 here and expect it to leave
@@ -936,7 +943,7 @@
@leave
*/
void CAtaFatTable::WriteL(TUint32 aFatIndex, TUint32 aValue)
- {
+ {
const TUint32 KFat16EntryMask = 0x0FFFF;
__PRINT2(_L("CAtaFatTable::WriteL() entry:%d, val:0x%x"), aFatIndex, aValue);
@@ -953,7 +960,7 @@
User::Leave(KErrCorrupt);
}
iCache->WriteEntryL(aFatIndex, aValue);
- }
+ }
/**
@@ -965,7 +972,7 @@
*/
TBool CFatTable::GetNextClusterL(TInt& aCluster) const
{
- __PRINT1(_L("CAtaFatTable::GetNextClusterL(%d)"), aCluster);
+ __PRINT1(_L("CAtaFatTable::GetNextClusterL(%d)"), aCluster);
const TInt nextCluster = ReadL(aCluster);
TBool ret = EFalse;
@@ -984,12 +991,12 @@
ASSERT(0);
return EFalse;//-- get rid of warning
};
-
+
if (ret)
{
- aCluster=nextCluster;
- }
-
+ aCluster=nextCluster;
+ }
+
return ret;
}
@@ -999,12 +1006,12 @@
@param aFatIndex index in FAT (cluster number) to be written
*/
void CFatTable::WriteFatEntryEofL(TUint32 aFatIndex)
- {
- __PRINT1(_L("CAtaFatTable::WriteFatEntryEofL(%d)"), aFatIndex);
+ {
+ __PRINT1(_L("CAtaFatTable::WriteFatEntryEofL(%d)"), aFatIndex);
//-- use EOF_16Bit (0x0ffff) for all types of FAT, FAT cache will mask it appropriately
WriteL(aFatIndex, EOF_16Bit);
- }
+ }
@@ -1020,7 +1027,7 @@
WriteL(aFatIndex, KBad_16Bit);
FlushL();
- }
+ }
/**
@@ -1030,12 +1037,12 @@
@return Byte offset of the cluster data
*/
TInt64 CAtaFatTable::DataPositionInBytes(TUint32 aCluster) const
- {
+ {
__ASSERT_DEBUG(ClusterNumberValid(aCluster), Fault(EFatTable_InvalidIndex));
const TInt clusterBasePosition=iOwner->ClusterBasePosition();
- return(((TInt64(aCluster)-KFatFirstSearchCluster) << iOwner->ClusterSizeLog2()) + clusterBasePosition);
- }
+ return(((TInt64(aCluster)-KFatFirstSearchCluster) << iOwner->ClusterSizeLog2()) + clusterBasePosition);
+ }