First public contribution.
1 // Copyright (c) 2002-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\bitext.cpp
15 // extension to do XOR on every byte on 32 byte boundary read or written to media subsystem in same thread
16 // therefore RFile::Read/Write does not have this operation carried out on it
22 class CBitExtProxyDrive : public CBaseExtProxyDrive
25 static CBitExtProxyDrive* NewL(CProxyDrive* aProxyDrive, CMountCB* aMount);
28 virtual TInt Initialise();
29 virtual TInt Dismounted();
30 virtual TInt Enlarge(TInt aLength);
31 virtual TInt ReduceSize(TInt aPos, TInt aLength);
32 virtual TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset);
33 virtual TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg);
34 virtual TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset);
35 virtual TInt Write(TInt64 aPos,const TDesC8& aSrc);
36 virtual TInt Format(TFormatInfo& anInfo);
37 virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
39 CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount);
48 class CBitProxyDriveFactory : public CProxyDriveFactory
51 CBitProxyDriveFactory();
52 virtual TInt Install();
53 virtual CProxyDrive* NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount);
56 const TUint8 KBitMask=0xcc;
57 const TInt KChangePosMask=0x0000001f;
59 LOCAL_C void DoXOR(TInt aPos,TInt aLength,TUint8* aPtr)
64 for(TInt i=0;i<aLength;++i)
66 if(((i+aPos)&KChangePosMask)==0)
72 CBitExtProxyDrive* CBitExtProxyDrive::NewL(CProxyDrive* aProxyDrive, CMountCB* aMount)
77 CBitExtProxyDrive* temp=new(ELeave) CBitExtProxyDrive(aProxyDrive,aMount);
82 CBitExtProxyDrive::CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount):CBaseExtProxyDrive(aProxyDrive,aMount)
84 RDebug::Print(_L("CBitExtProxyDrive::CBitExtProxyDrive"));
87 CBitExtProxyDrive::~CBitExtProxyDrive()
92 RDebug::Print(_L("Read Thread = %d"),iReadThread);
93 RDebug::Print(_L("Read = %d"),iRead);
94 RDebug::Print(_L("Write Thread = %d"),iWriteThread);
95 RDebug::Print(_L("Write = %d"),iWrite);
96 RDebug::Print(_L("Format = %d"),iFormat);
99 TInt CBitExtProxyDrive::Initialise()
104 return(CBaseExtProxyDrive::Initialise());
107 TInt CBitExtProxyDrive::Dismounted()
112 return(CBaseExtProxyDrive::Dismounted());
115 TInt CBitExtProxyDrive::Enlarge(TInt aLength)
120 return(CBaseExtProxyDrive::Enlarge(aLength));
124 TInt CBitExtProxyDrive::ReduceSize(TInt aPos, TInt aLength)
129 return(CBaseExtProxyDrive::ReduceSize(aPos,aLength));
132 TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset)
138 return(CBaseExtProxyDrive::Read(aPos,aLength,aTrg,aThreadHandle,anOffset));
141 TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,TDes8& aTrg)
147 TInt r=CBaseExtProxyDrive::Read(aPos,aLength,aTrg);
148 DoXOR(I64INT(aPos),aLength,&aTrg[0]);
153 TInt CBitExtProxyDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset)
159 return(CBaseExtProxyDrive::Write(aPos,aLength,aSrc,aThreadHandle,anOffset));
162 TInt CBitExtProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc)
169 // data may be read-only, so need to copy to a local buffer
171 HBufC8* buf = HBufC8::New( aSrc.Length() );
174 TPtr8 ptr = buf->Des();
177 DoXOR(I64INT(aPos), ptr.Length(), (TUint8*)ptr.Ptr());
178 TInt r = CBaseExtProxyDrive::Write(aPos, ptr);
185 TInt CBitExtProxyDrive::Format(TFormatInfo& anInfo)
191 return(CBaseExtProxyDrive::Format(anInfo));
195 TInt CBitExtProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
199 // file caching supported, so pass query on to next extension
200 case ELocalBufferSupport:
201 return CBaseExtProxyDrive::LocalBufferSupport();
204 return CBaseExtProxyDrive::GetInterface(aInterfaceId, aInterface, aInput);
208 CBitProxyDriveFactory::CBitProxyDriveFactory()
213 RDebug::Print(_L("CBitProxyDriveFactory::CBitProxyDriveFactory"));
216 TInt CBitProxyDriveFactory::Install()
221 _LIT(KBitName,"Bitchange");
222 return(SetName(&KBitName));
226 CProxyDrive* CBitProxyDriveFactory::NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount)
231 return(CBitExtProxyDrive::NewL(aProxy,aMount));
236 EXPORT_C CProxyDriveFactory* CreateFileSystem()
238 // Create a new file system
241 return(new CBitProxyDriveFactory());