diff -r f6d3d9676ee4 -r d63d727ee0a6 userlibandfileserver/fileserver/sfat/sl_check.cpp --- a/userlibandfileserver/fileserver/sfat/sl_check.cpp Tue Dec 08 08:11:42 2009 +0100 +++ b/userlibandfileserver/fileserver/sfat/sl_check.cpp Mon Jan 04 12:25:19 2010 +0100 @@ -15,6 +15,14 @@ // // +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +//!! +//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it +//!! +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + #include "sl_std.h" #include "sl_scandrv.h" @@ -33,66 +41,66 @@ TInt CCheckFatTable::MaxFatIndex() const { - __ASSERT_DEBUG((TUint)iMaxFatIndex>=KFatFirstSearchCluster, Fault(ECheckFatIndexZero)); - return(iMaxFatIndex); - } + __ASSERT_DEBUG((TUint)iMaxFatIndex>=KFatFirstSearchCluster, Fault(ECheckFatIndexZero)); + return(iMaxFatIndex); + } CCheckFatTable* CCheckFatTable::NewL(CFatMountCB* aOwner) // // Create a CCheckFatTable // - { - CCheckFatTable* fatTable; - fatTable=new(ELeave) CCheckFatTable(aOwner); - return(fatTable); - } + { + CCheckFatTable* fatTable; + fatTable=new(ELeave) CCheckFatTable(aOwner); + return(fatTable); + } CCheckFatTable::CCheckFatTable(CFatMountCB* aOwner) // // Constructor // - { - iOwner=aOwner; - } + { + iOwner=aOwner; + } CCheckFatTable::~CCheckFatTable() // // Destructor // - { - User::Free(iCheckFat); - } + { + User::Free(iCheckFat); + } void CCheckFatTable::InitializeL() // // Initialize the check fat table // - { - __PRINT(_L("CCheckFatTable::InitializeL")); + { + __PRINT(_L("CCheckFatTable::InitializeL")); - TInt fatSize=iOwner->FatSizeInBytes(); + TInt fatSize=iOwner->FatSizeInBytes(); - if(iCheckFat==NULL) - iCheckFat=(TUint8*)User::AllocL(fatSize); - else - iCheckFat=(TUint8*)User::ReAllocL(iCheckFat,fatSize); - Mem::FillZ(iCheckFat,fatSize); - iMaxFatIndex=iOwner->UsableClusters()+1; - if(iOwner->Is16BitFat()) - { - __ASSERT_ALWAYS(iMaxFatIndex>0 && iMaxFatIndex0 && iMaxFatIndexUsableClusters()+1; + if(iOwner->Is16BitFat()) + { + __ASSERT_ALWAYS(iMaxFatIndex>0 && iMaxFatIndex0 && iMaxFatIndexPtr(); - TInt maxSize=hBuf->Des().MaxSize(); + TUint8* ptr=(TUint8*)hBuf->Ptr(); + TInt maxSize=hBuf->Des().MaxSize(); - TPtr8 fatBuffer(ptr,maxSize); - TInt fatSize=iOwner->FatSizeInBytes(); - TInt remainder=fatSize; - TInt offset=iOwner->StartOfFatInBytes(); - TUint8* dataPtr=iCheckFat; + TPtr8 fatBuffer(ptr,maxSize); + TInt fatSize=iOwner->FatSizeInBytes(); + TInt remainder=fatSize; + TInt offset=iOwner->StartOfFatInBytes(); + TUint8* dataPtr=iCheckFat; TFatDriveInterface& drive = iOwner->DriveInterface(); - TInt fatNumber=iOwner->NumberOfFats(); - - while(remainder) - { - TInt s=Min(fatBuffer.MaxSize(),remainder); - TInt fatCount=fatNumber; - TInt fatPos=0; - while(fatCount) - { - TInt fatOffset=offset+fatPos; - User::LeaveIfError(drive.ReadCritical(fatOffset,s,fatBuffer)); - TInt rem2=s; - TInt offset2=fatOffset; - TUint8* dataPtr2=dataPtr; - TInt bufOffset=0; - while(rem2) - { - TInt s2=Min(rem2,512); - TInt r=Mem::Compare(dataPtr2,s2,fatBuffer.Ptr()+bufOffset,s2); - if (r!=0) - { - bErrFound = ETrue; + TInt fatNumber=iOwner->NumberOfFats(); + + while(remainder) + { + TInt s=Min(fatBuffer.MaxSize(),remainder); + TInt fatCount=fatNumber; + TInt fatPos=0; + while(fatCount) + { + TInt fatOffset=offset+fatPos; + User::LeaveIfError(drive.ReadCritical(fatOffset,s,fatBuffer)); + TInt rem2=s; + TInt offset2=fatOffset; + TUint8* dataPtr2=dataPtr; + TInt bufOffset=0; + while(rem2) + { + TInt s2=Min(rem2,512); + TInt r=Mem::Compare(dataPtr2,s2,fatBuffer.Ptr()+bufOffset,s2); + if (r!=0) + { + bErrFound = ETrue; TPtrC8 dataBuf(dataPtr2,s2); - User::LeaveIfError(drive.WriteCritical(offset2,dataBuf)); - } - rem2-=s2; - offset2+=s2; - dataPtr2+=s2; - bufOffset+=s2; - } - --fatCount; - fatPos+=fatSize; - } - offset+=s; - dataPtr+=s; - remainder-=s; - } + User::LeaveIfError(drive.WriteCritical(offset2,dataBuf)); + } + rem2-=s2; + offset2+=s2; + dataPtr2+=s2; + bufOffset+=s2; + } + --fatCount; + fatPos+=fatSize; + } + offset+=s; + dataPtr+=s; + remainder-=s; + } - CleanupStack::PopAndDestroy(); + CleanupStack::PopAndDestroy(); return bErrFound; - } + } void CCheckFatTable::WriteMediaDescriptor() // // Write media descriptor to first byte and 0xFF to // remaining bytes of first two entries // - { - __PRINT(_L("CCheckFatTable::WriteMediaDescriptor")); - iCheckFat[0]=KBootSectorMediaDescriptor; - iCheckFat[1]=0xFF; - iCheckFat[2]=0xFF; - if (iOwner->Is16BitFat()) - iCheckFat[3]=0xFF; - } + { + __PRINT(_L("CCheckFatTable::WriteMediaDescriptor")); + iCheckFat[0]=KBootSectorMediaDescriptor; + iCheckFat[1]=0xFF; + iCheckFat[2]=0xFF; + if (iOwner->Is16BitFat()) + iCheckFat[3]=0xFF; + } TInt CCheckFatTable::PosInBytes(TInt aFatIndex) const // // Return number of bytes into the fat // - { - TInt fatPosInBytes; - if (iOwner->Is16BitFat()) - fatPosInBytes=aFatIndex<<1; - else - // this is used since 8-bit access will be used for reading/writing - fatPosInBytes=(aFatIndex*3>>1); - return(fatPosInBytes); - } + { + TInt fatPosInBytes; + if (iOwner->Is16BitFat()) + fatPosInBytes=aFatIndex<<1; + else + // this is used since 8-bit access will be used for reading/writing + fatPosInBytes=(aFatIndex*3>>1); + return(fatPosInBytes); + } TInt CCheckFatTable::PosInIndex(TInt aBytePos) const // // Return index given byte position in fat // - { - if(iOwner->Is16BitFat()) - return(aBytePos>>1); - else - return((aBytePos<<1)/3); - } + { + if(iOwner->Is16BitFat()) + return(aBytePos>>1); + else + return((aBytePos<<1)/3); + } TInt CCheckFatTable::ReadL(TInt aFatIndex) const // // Read a value from the check fat // - { - __ASSERT_ALWAYS((TUint32)aFatIndex >=KFatFirstSearchCluster && aFatIndex<=MaxFatIndex(),User::Leave(KErrCorrupt)); - TUint clusterVal; - if(iOwner->Is16BitFat()) - clusterVal=*(TUint16*)(iCheckFat+PosInBytes(aFatIndex)); - else - { - TUint8* pCluster=iCheckFat+PosInBytes(aFatIndex); - clusterVal=pCluster[0]|(pCluster[1]<<8); - TBool oddCluster=(aFatIndex)&1; - if(oddCluster) - clusterVal>>=4; - clusterVal&=0xFFF; - } - return(clusterVal); - } + { + __ASSERT_ALWAYS((TUint32)aFatIndex >=KFatFirstSearchCluster && aFatIndex<=MaxFatIndex(),User::Leave(KErrCorrupt)); + TUint clusterVal; + if(iOwner->Is16BitFat()) + clusterVal=*(TUint16*)(iCheckFat+PosInBytes(aFatIndex)); + else + { + TUint8* pCluster=iCheckFat+PosInBytes(aFatIndex); + clusterVal=pCluster[0]|(pCluster[1]<<8); + TBool oddCluster=(aFatIndex)&1; + if(oddCluster) + clusterVal>>=4; + clusterVal&=0xFFF; + } + return(clusterVal); + } void CCheckFatTable::WriteL(TInt aFatIndex,TInt aValue) // // Write a value to the check fat // - { - if(iOwner->Is16BitFat()) - __ASSERT_ALWAYS((TUint32)aFatIndex>=KFatFirstSearchCluster && aFatIndex<=MaxFatIndex() && aValue>=0 && aValue<=0xFFFF,User::Leave(KErrCorrupt)); - else - __ASSERT_ALWAYS((TUint32)aFatIndex>=KFatFirstSearchCluster && aFatIndex<=MaxFatIndex() && aValue>=0 && aValue<=0xFFF,User::Leave(KErrCorrupt)); - TUint8* p=(TUint8*)(iCheckFat+PosInBytes(aFatIndex)); - if (iOwner->Is16BitFat()) - { - *(TUint16*)p=(TUint16)aValue; - return; - } - TUint8 mask=0x0F; - TBool odd=(aFatIndex)&1; - TUint8 fatVal; - if(odd) - { - mask<<=4; - aValue<<=4; - fatVal=p[0]; - fatVal&=~mask; - fatVal|=(TUint8)(aValue&0xFF); - p[0]=fatVal; - p[1]=(TUint8)(aValue>>8); - } - else - { - p[0]=(TUint8)(aValue&0xFF); - fatVal=p[1]; - fatVal&=~mask; - fatVal|=(TUint8)(aValue>>8); - p[1]=fatVal; - } - return; - } - + { + if(iOwner->Is16BitFat()) + __ASSERT_ALWAYS((TUint32)aFatIndex>=KFatFirstSearchCluster && aFatIndex<=MaxFatIndex() && aValue>=0 && aValue<=0xFFFF,User::Leave(KErrCorrupt)); + else + __ASSERT_ALWAYS((TUint32)aFatIndex>=KFatFirstSearchCluster && aFatIndex<=MaxFatIndex() && aValue>=0 && aValue<=0xFFF,User::Leave(KErrCorrupt)); + TUint8* p=(TUint8*)(iCheckFat+PosInBytes(aFatIndex)); + if (iOwner->Is16BitFat()) + { + *(TUint16*)p=(TUint16)aValue; + return; + } + TUint8 mask=0x0F; + TBool odd=(aFatIndex)&1; + TUint8 fatVal; + if(odd) + { + mask<<=4; + aValue<<=4; + fatVal=p[0]; + fatVal&=~mask; + fatVal|=(TUint8)(aValue&0xFF); + p[0]=fatVal; + p[1]=(TUint8)(aValue>>8); + } + else + { + p[0]=(TUint8)(aValue&0xFF); + fatVal=p[1]; + fatVal&=~mask; + fatVal|=(TUint8)(aValue>>8); + p[1]=fatVal; + } + return; + } + TBool CCheckFatTable::GetNextClusterL(TInt& aCluster) const // // Get the next cluster in the chain from the check fat. // { - __PRINT(_L("CCheckFatTable::GetNextClusterL")); - TBool ret; - TInt nextCluster=ReadL(aCluster); - if (iOwner->Is16BitFat()) - ret=!IsEof16Bit(nextCluster); - else - ret=!IsEof12Bit(nextCluster); - if (ret) - aCluster=nextCluster; - return(ret); - } + __PRINT(_L("CCheckFatTable::GetNextClusterL")); + TBool ret; + TInt nextCluster=ReadL(aCluster); + if (iOwner->Is16BitFat()) + ret=!IsEof16Bit(nextCluster); + else + ret=!IsEof12Bit(nextCluster); + if (ret) + aCluster=nextCluster; + return(ret); + } void CCheckFatTable::WriteFatEntryEofFL(TInt aCluster) // // Write EOF to aCluster // - { - __PRINT(_L("CCheckFatTable::WriteFatEntryEofF")); - if (iOwner->Is16BitFat()) - WriteL(aCluster,EOF_16Bit); - else - WriteL(aCluster,EOF_12Bit); - } + { + __PRINT(_L("CCheckFatTable::WriteFatEntryEofF")); + if (iOwner->Is16BitFat()) + WriteL(aCluster,EOF_16Bit); + else + WriteL(aCluster,EOF_12Bit); + }