First public contribution.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\ext\t_testext.cpp
19 #include "t_testext.h"
21 CTestProxyDrive::CTestProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount)
22 : CBaseExtProxyDrive(aProxyDrive,aMount), iMount(aMount)
24 __PRINT(_L("CTestProxyDrive::CTestProxyDrive"));
27 CTestProxyDrive::~CTestProxyDrive()
29 __PRINT(_L("CTestProxyDrive::~CTestProxyDrive"));
33 void CTestProxyDrive::InitL()
35 __PRINT(_L("CTestProxyDrive::Init"));
39 // Allocate bad sector bit map
40 TInt size = (iTotalSectors+7) >> 3; // round up by byte
41 iMap = new(ELeave) TUint8[size];
42 Mem::FillZ(iMap, size);
44 iMountInitialised = ETrue;
47 TInt CTestProxyDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2)
49 __PRINT(_L("CTestProxyDrive::ControlIO"));
53 if (!iMountInitialised)
56 switch(aCommand+EExtCustom)
59 r = SetEvent((TInt)aParam1, (TInt)aParam2);
63 //-- mark given sector as bad
64 __PRINT1(_L("CTestProxyDrive: marking sector:%d as bad"), (TInt)aParam1);
65 r = Mark((TInt)aParam1);
69 //-- mark given sector as good
70 __PRINT1(_L("CTestProxyDrive: Unmarking sector:%d"), (TInt)aParam1);
71 r = Unmark((TInt)aParam1);
79 if (IsMarked((TInt)aParam1))
80 r = aMessage.Write(3, TPckgBuf<TBool>(ETrue));
82 r = aMessage.Write(3, TPckgBuf<TBool>(EFalse));
85 r = aMessage.Write(2, TPckgBuf<TInt64>(iMount->Size()));
88 r = DoControlIO(aMessage,aCommand,aParam1,aParam2);
89 __PRINT2(_L("Get unknown command %d error %d"), aCommand, r);
94 TInt CTestProxyDrive::GetLastErrorInfo(TDes8 &aErrorInfo)
96 __PRINT(_L("CTestProxyDrive::GetLastErrorInfo"));
97 TPckgBuf<TErrorInfo> errInfoBuf;
98 errInfoBuf().iReasonCode = iLastErrorReason;
99 errInfoBuf().iErrorPos = iSuccessBytes;
100 aErrorInfo = errInfoBuf;
105 TInt CTestProxyDrive::SetEvent(TInt aType, TInt aValue)
107 __PRINT(_L("CTestProxyDrive::SetEvent"));
117 Mark((TInt)(Math::Random() / (TReal64)KMaxTUint) * iTotalSectors);
133 mark aSector as a bad sector by adding it to the bad sectors map
134 @param aSector sector number to mark as bad
136 TInt CTestProxyDrive::Mark(TInt aSector)
138 __PRINT1(_L("CTestProxyDrive::Mark %d"), aSector);
140 if (aSector >= iTotalSectors)
144 iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] | (1<<(aSector & 7)));
148 TInt CTestProxyDrive::Unmark(TInt aSector)
150 // Remove bad cluster aValue from list.
153 __PRINT1(_L("CTestProxyDrive::Unmark %d"), aSector);
155 if (aSector>=iTotalSectors || aSector<0)
157 iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] & ~(1<<(aSector & 7)));
161 TInt CTestProxyDrive::UnmarkAll()
163 // Clear all bad cluster marks.
166 __PRINT(_L("CTestProxyDrive::UnmarkAll"));
168 Mem::FillZ(iMap, (iTotalSectors+7)>>3);
172 TBool CTestProxyDrive::IsMarked(TInt aSector) const
174 // Check if cluster number is in bad cluster list.
179 if (aSector>=iTotalSectors || aSector<0)
182 const TBool bMarked = iMap[aSector>>3] & (1<<(aSector & 7));
185 __PRINT1(_L("CTestProxyDrive::IsMarked %d"), aSector);
191 TBool CTestProxyDrive::CheckEvent(TInt64 aPos, TInt aLength)
193 //__PRINT(_L("CTestProxyDrive::CheckEvent"));
195 if (!iMountInitialised)
198 return DoCheckEvent(aPos, aLength);