sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\ext\t_testext.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "t_testext.h" sl@0: sl@0: CTestProxyDrive::CTestProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount) sl@0: : CBaseExtProxyDrive(aProxyDrive,aMount), iMount(aMount) sl@0: { sl@0: __PRINT(_L("CTestProxyDrive::CTestProxyDrive")); sl@0: } sl@0: sl@0: CTestProxyDrive::~CTestProxyDrive() sl@0: { sl@0: __PRINT(_L("CTestProxyDrive::~CTestProxyDrive")); sl@0: delete[] iMap; sl@0: } sl@0: sl@0: void CTestProxyDrive::InitL() sl@0: { sl@0: __PRINT(_L("CTestProxyDrive::Init")); sl@0: sl@0: DoInitL(); sl@0: sl@0: // Allocate bad sector bit map sl@0: TInt size = (iTotalSectors+7) >> 3; // round up by byte sl@0: iMap = new(ELeave) TUint8[size]; sl@0: Mem::FillZ(iMap, size); sl@0: sl@0: iMountInitialised = ETrue; sl@0: } sl@0: sl@0: TInt CTestProxyDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2) sl@0: { sl@0: __PRINT(_L("CTestProxyDrive::ControlIO")); sl@0: sl@0: TInt r = KErrNone; sl@0: sl@0: if (!iMountInitialised) sl@0: return KErrNotReady; sl@0: sl@0: switch(aCommand+EExtCustom) sl@0: { sl@0: case ESetEvent: sl@0: r = SetEvent((TInt)aParam1, (TInt)aParam2); sl@0: break; sl@0: sl@0: case EMark: sl@0: //-- mark given sector as bad sl@0: __PRINT1(_L("CTestProxyDrive: marking sector:%d as bad"), (TInt)aParam1); sl@0: r = Mark((TInt)aParam1); sl@0: break; sl@0: sl@0: case EUnmark: sl@0: //-- mark given sector as good sl@0: __PRINT1(_L("CTestProxyDrive: Unmarking sector:%d"), (TInt)aParam1); sl@0: r = Unmark((TInt)aParam1); sl@0: break; sl@0: sl@0: case EUnmarkAll: sl@0: r = UnmarkAll(); sl@0: break; sl@0: sl@0: case EIsMarked: sl@0: if (IsMarked((TInt)aParam1)) sl@0: r = aMessage.Write(3, TPckgBuf(ETrue)); sl@0: else sl@0: r = aMessage.Write(3, TPckgBuf(EFalse)); sl@0: break; sl@0: case EDiskSize: sl@0: r = aMessage.Write(2, TPckgBuf(iMount->Size())); sl@0: break; sl@0: default: sl@0: r = DoControlIO(aMessage,aCommand,aParam1,aParam2); sl@0: __PRINT2(_L("Get unknown command %d error %d"), aCommand, r); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: TInt CTestProxyDrive::GetLastErrorInfo(TDes8 &aErrorInfo) sl@0: { sl@0: __PRINT(_L("CTestProxyDrive::GetLastErrorInfo")); sl@0: TPckgBuf errInfoBuf; sl@0: errInfoBuf().iReasonCode = iLastErrorReason; sl@0: errInfoBuf().iErrorPos = iSuccessBytes; sl@0: aErrorInfo = errInfoBuf; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestProxyDrive::SetEvent(TInt aType, TInt aValue) sl@0: { sl@0: __PRINT(_L("CTestProxyDrive::SetEvent")); sl@0: sl@0: switch (aType) sl@0: { sl@0: case ENone: sl@0: break; sl@0: case ENext: sl@0: iEventType = aType; sl@0: break; sl@0: case ERandom: sl@0: Mark((TInt)(Math::Random() / (TReal64)KMaxTUint) * iTotalSectors); sl@0: break; sl@0: case EDeterministic: sl@0: iEventType = aType; sl@0: if (aValue <= 0) sl@0: return KErrArgument; sl@0: iCount = aValue; sl@0: break; sl@0: default: sl@0: return KErrArgument; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: mark aSector as a bad sector by adding it to the bad sectors map sl@0: @param aSector sector number to mark as bad sl@0: */ sl@0: TInt CTestProxyDrive::Mark(TInt aSector) sl@0: { sl@0: __PRINT1(_L("CTestProxyDrive::Mark %d"), aSector); sl@0: sl@0: if (aSector >= iTotalSectors) sl@0: return KErrNone; sl@0: if (aSector < 0) sl@0: return KErrArgument; sl@0: iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] | (1<<(aSector & 7))); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestProxyDrive::Unmark(TInt aSector) sl@0: // sl@0: // Remove bad cluster aValue from list. sl@0: // sl@0: { sl@0: __PRINT1(_L("CTestProxyDrive::Unmark %d"), aSector); sl@0: sl@0: if (aSector>=iTotalSectors || aSector<0) sl@0: return KErrArgument; sl@0: iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] & ~(1<<(aSector & 7))); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTestProxyDrive::UnmarkAll() sl@0: // sl@0: // Clear all bad cluster marks. sl@0: // sl@0: { sl@0: __PRINT(_L("CTestProxyDrive::UnmarkAll")); sl@0: sl@0: Mem::FillZ(iMap, (iTotalSectors+7)>>3); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TBool CTestProxyDrive::IsMarked(TInt aSector) const sl@0: // sl@0: // Check if cluster number is in bad cluster list. sl@0: // sl@0: { sl@0: sl@0: sl@0: if (aSector>=iTotalSectors || aSector<0) sl@0: return EFalse; sl@0: sl@0: const TBool bMarked = iMap[aSector>>3] & (1<<(aSector & 7)); sl@0: if(bMarked) sl@0: { sl@0: __PRINT1(_L("CTestProxyDrive::IsMarked %d"), aSector); sl@0: } sl@0: sl@0: return bMarked ; sl@0: } sl@0: sl@0: TBool CTestProxyDrive::CheckEvent(TInt64 aPos, TInt aLength) sl@0: { sl@0: //__PRINT(_L("CTestProxyDrive::CheckEvent")); sl@0: sl@0: if (!iMountInitialised) sl@0: return EFalse; sl@0: sl@0: return DoCheckEvent(aPos, aLength); sl@0: }