First public contribution.
1 // Copyright (c) 1998-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 // e32test\pccd\d_medt1.cpp
23 #include <kernel/kernel.h>
24 const TInt KTestDriverBufferMaxSize=0x1000; // 4K
26 class DPhysicalDeviceMediaTest : public DPhysicalDeviceMedia
29 DPhysicalDeviceMediaTest();
30 virtual TInt Install();
31 virtual TInt Remove();
32 virtual void GetCaps(TDes8 &aDes) const;
33 virtual CBase *CreateL(TInt aDevice,const TDesC *anInfo,const TVersion &aVer);
34 virtual TInt Priority();
37 class DMediaDriverTest : public DMediaDriver
41 TInt DoCreate(TMediaDevice aMediaDevice);
42 void DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg);
43 void DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc);
44 void DoFormat(TInt64 &aPos,TInt aLength);
45 TInt Enlarge(TInt aLength);
46 TInt ReduceSize(TInt64 &aPos,TInt aLength);
48 TInt PartitionInfo(TPartitionInfo &anInfo);
49 void Caps(TDes8& aCapsBuf);
51 static void WriteCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
52 static void FormatCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
54 TUint8 iBuf[KTestDriverBufferMaxSize];
55 TTickLink iWriteTickLink;
56 TTickLink iFormatTickLink;
59 DPhysicalDeviceMediaTest::DPhysicalDeviceMediaTest()
64 iUnitsMask=0x1; // Support only one
65 iVersion=TVersion(KMediaDriverInterfaceMajorVersionNumber,KMediaDriverInterfaceMinorVersionNumber,KMediaDriverInterfaceBuildVersionNumber);
68 TInt DPhysicalDeviceMediaTest::Install()
70 // Install the test Media PDD.
74 TPtrC name=_L("Media.Tst1");
75 return(SetName(&name));
78 TInt DPhysicalDeviceMediaTest::Remove()
80 // Remove the test Media PDD.
86 void DPhysicalDeviceMediaTest::GetCaps(TDes8 &/* aDes */) const
88 // Return the media drivers capabilities.
93 CBase *DPhysicalDeviceMediaTest::CreateL(TInt aDevice,const TDesC * /* anInfo */,const TVersion &aVer)
95 // Create a test media driver.
98 if (User::QueryVersionSupported(iVersion,aVer)==EFalse)
99 User::Leave(KErrNotSupported);
100 DMediaDriverTest *mD=new(ELeave) DMediaDriverTest;
101 TInt ret=mD->DoCreate((TMediaDevice)aDevice);
110 TInt DPhysicalDeviceMediaTest::Priority()
112 // Return the priority of this media driver
116 return(KMediaDriverPriorityLow);
119 DMediaDriverTest::DMediaDriverTest()
125 // Mem::FillZ(&iBuf[0],sizeof(iBuf));
128 TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice)
130 // Create the media driver.
134 if (!__IS_REMOVABLE(aMediaDevice))
135 return(KErrNotSupported);
136 SetTotalSizeInBytes(KTestDriverBufferMaxSize);
140 void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg)
142 // Read from specified area of media.
147 if (!aTrg.IsCurrentThread())
151 if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone)
153 TDes8 &t=*((TDes8*)aTrg.iPtr);
154 Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength);
155 t.SetLength(aLength+aTrg.iOffset);
158 Complete(KMediaDrvReadReq,ret);
161 const TInt KWriteAsyncTime=100000; // 100mS
162 void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc)
164 // Write to specifed area of media.
168 if (!aSrc.IsCurrentThread())
169 Complete(KMediaDrvWriteReq,KErrGeneral);
172 Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength);
173 iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this);
177 const TInt KFormatAsyncTime=5000000; // 5S
178 void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength)
180 // Format the specified area of the media.
184 Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF);
185 iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this);
188 TInt DMediaDriverTest::Enlarge(TInt /*aLength*/)
194 return(KErrNotSupported);
197 TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/)
199 // Reduce in size the drive
203 return(KErrNotSupported);
206 void DMediaDriverTest::Close()
208 // Close the media driver
212 TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo)
214 // Return partition information on the media.
218 anInfo.iPartitionCount=1;
219 anInfo.iEntry[0].iPartitionBaseAddr=0;
220 anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes();
224 void DMediaDriverTest::Caps(TDes8& aCapsBuf)
226 // Return the capabilities of the media
229 TLocalDriveCapsV2 caps;
230 caps.iType=EMediaRam;
231 caps.iConnectionBusType=EConnectionBusInternal;
232 caps.iDriveAtt=KDriveAttLocal|KDriveAttRemovable;
233 caps.iMediaAtt=KMediaAttFormattable;
234 caps.iFileSystemId=KDriveFileSysFAT;
235 caps.iHiddenSectors=0;
236 aCapsBuf.FillZ(aCapsBuf.MaxLength());
237 aCapsBuf.Copy((TUint8 *)&caps,Min(aCapsBuf.MaxLength(),sizeof(caps)));
240 void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
242 // Complete a write request
246 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
247 md.Complete(KMediaDrvWriteReq,KErrNone);
251 void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
253 // Complete a format request
257 DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
258 md.Complete(KMediaDrvFormatReq,KErrNone);
262 DECLARE_STANDARD_PDD()
264 return(new DPhysicalDeviceMediaTest);