os/kernelhwsrv/kerneltest/f32test/ext/t_bitext.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/ext/t_bitext.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,244 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\ext\bitext.cpp
    1.18 +// extension to do XOR on every byte on 32 byte boundary read or written to media subsystem in same thread
    1.19 +// therefore RFile::Read/Write does not have this operation carried out on it
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +#include <f32fsys.h>
    1.24 +
    1.25 +class CBitExtProxyDrive : public CBaseExtProxyDrive
    1.26 +	{
    1.27 +public:
    1.28 +	static CBitExtProxyDrive* NewL(CProxyDrive* aProxyDrive, CMountCB* aMount);
    1.29 +	~CBitExtProxyDrive();
    1.30 +public:
    1.31 +	virtual TInt Initialise();
    1.32 +	virtual TInt Dismounted();
    1.33 +	virtual TInt Enlarge(TInt aLength);
    1.34 +	virtual TInt ReduceSize(TInt aPos, TInt aLength);
    1.35 +	virtual TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset);
    1.36 +	virtual TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg);
    1.37 +	virtual TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset);
    1.38 +	virtual TInt Write(TInt64 aPos,const TDesC8& aSrc);
    1.39 +	virtual TInt Format(TFormatInfo& anInfo);
    1.40 +	virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
    1.41 +private:
    1.42 +	CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount);
    1.43 +private:
    1.44 +	TInt iReadThread;
    1.45 +	TInt iRead;
    1.46 +	TInt iWriteThread;
    1.47 +	TInt iWrite;
    1.48 +	TInt iFormat;
    1.49 +	};
    1.50 +
    1.51 +class CBitProxyDriveFactory : public CProxyDriveFactory
    1.52 +	{
    1.53 +public:
    1.54 +	CBitProxyDriveFactory();
    1.55 +	virtual TInt Install();			
    1.56 +	virtual CProxyDrive* NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount);
    1.57 +	};
    1.58 +
    1.59 +const TUint8 KBitMask=0xcc;
    1.60 +const TInt KChangePosMask=0x0000001f;
    1.61 +
    1.62 +LOCAL_C void DoXOR(TInt aPos,TInt aLength,TUint8* aPtr)
    1.63 +//
    1.64 +//
    1.65 +//
    1.66 +	{
    1.67 +	for(TInt i=0;i<aLength;++i)
    1.68 +		{
    1.69 +		if(((i+aPos)&KChangePosMask)==0)
    1.70 +			aPtr[i]^=KBitMask;
    1.71 +		}
    1.72 +	}
    1.73 +
    1.74 +
    1.75 +CBitExtProxyDrive* CBitExtProxyDrive::NewL(CProxyDrive* aProxyDrive, CMountCB* aMount)
    1.76 +//
    1.77 +//
    1.78 +//
    1.79 +	{
    1.80 +	CBitExtProxyDrive* temp=new(ELeave) CBitExtProxyDrive(aProxyDrive,aMount);
    1.81 +	return(temp);
    1.82 +	}
    1.83 +
    1.84 +
    1.85 +CBitExtProxyDrive::CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount):CBaseExtProxyDrive(aProxyDrive,aMount)
    1.86 +	{
    1.87 +	RDebug::Print(_L("CBitExtProxyDrive::CBitExtProxyDrive"));
    1.88 +	}
    1.89 +
    1.90 +CBitExtProxyDrive::~CBitExtProxyDrive()
    1.91 +//
    1.92 +//
    1.93 +//
    1.94 +	{
    1.95 +	RDebug::Print(_L("Read Thread = %d"),iReadThread);
    1.96 +	RDebug::Print(_L("Read = %d"),iRead);
    1.97 +	RDebug::Print(_L("Write Thread = %d"),iWriteThread);
    1.98 +	RDebug::Print(_L("Write = %d"),iWrite);
    1.99 +	RDebug::Print(_L("Format = %d"),iFormat);
   1.100 +	}
   1.101 +
   1.102 +TInt CBitExtProxyDrive::Initialise()
   1.103 +//
   1.104 +//
   1.105 +//
   1.106 +	{
   1.107 +	return(CBaseExtProxyDrive::Initialise());
   1.108 +	}
   1.109 +
   1.110 +TInt CBitExtProxyDrive::Dismounted()
   1.111 +//
   1.112 +//
   1.113 +//
   1.114 +	{
   1.115 +	return(CBaseExtProxyDrive::Dismounted());
   1.116 +	}
   1.117 +
   1.118 +TInt CBitExtProxyDrive::Enlarge(TInt aLength)
   1.119 +//
   1.120 +//
   1.121 +//
   1.122 +	{
   1.123 +	return(CBaseExtProxyDrive::Enlarge(aLength));
   1.124 +	}
   1.125 +
   1.126 +
   1.127 +TInt CBitExtProxyDrive::ReduceSize(TInt aPos, TInt aLength)
   1.128 +//
   1.129 +//
   1.130 +//
   1.131 +	{
   1.132 +	return(CBaseExtProxyDrive::ReduceSize(aPos,aLength));
   1.133 +	}
   1.134 +
   1.135 +TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset)
   1.136 +//
   1.137 +//
   1.138 +//
   1.139 +	{
   1.140 +	++iReadThread;
   1.141 +	return(CBaseExtProxyDrive::Read(aPos,aLength,aTrg,aThreadHandle,anOffset));
   1.142 +	}
   1.143 +
   1.144 +TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,TDes8& aTrg)
   1.145 +//
   1.146 +//
   1.147 +//
   1.148 +	{
   1.149 +	++iRead;
   1.150 +	TInt r=CBaseExtProxyDrive::Read(aPos,aLength,aTrg);
   1.151 +	DoXOR(I64INT(aPos),aLength,&aTrg[0]);
   1.152 +	return(r);
   1.153 +	}
   1.154 +
   1.155 +
   1.156 +TInt CBitExtProxyDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset)
   1.157 +//
   1.158 +//
   1.159 +//
   1.160 +	{
   1.161 +	++iWriteThread;
   1.162 +	return(CBaseExtProxyDrive::Write(aPos,aLength,aSrc,aThreadHandle,anOffset));
   1.163 +	}
   1.164 +
   1.165 +TInt CBitExtProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc)
   1.166 +//
   1.167 +//
   1.168 +//
   1.169 +	{
   1.170 +	++iWrite;
   1.171 +
   1.172 +	// data may be read-only, so need to copy to a local buffer
   1.173 +	// before XOR-ing...
   1.174 +	HBufC8* buf = HBufC8::New( aSrc.Length() );
   1.175 +	if( !buf )
   1.176 +		return KErrNoMemory;
   1.177 +	TPtr8 ptr = buf->Des();
   1.178 +	ptr.Copy(aSrc);
   1.179 +
   1.180 +	DoXOR(I64INT(aPos), ptr.Length(), (TUint8*)ptr.Ptr());
   1.181 +	TInt r = CBaseExtProxyDrive::Write(aPos, ptr);
   1.182 +	
   1.183 +	delete buf;
   1.184 +
   1.185 +	return(r);
   1.186 +	}
   1.187 +
   1.188 +TInt CBitExtProxyDrive::Format(TFormatInfo& anInfo)
   1.189 +//
   1.190 +//
   1.191 +//
   1.192 +	{
   1.193 +	++iFormat;
   1.194 +	return(CBaseExtProxyDrive::Format(anInfo));
   1.195 +	}
   1.196 +
   1.197 +
   1.198 +TInt CBitExtProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
   1.199 +	{
   1.200 +	switch(aInterfaceId)
   1.201 +		{
   1.202 +		// file caching supported, so pass query on to next extension
   1.203 +		case ELocalBufferSupport:
   1.204 +			return CBaseExtProxyDrive::LocalBufferSupport();
   1.205 +
   1.206 +		default:
   1.207 +			return CBaseExtProxyDrive::GetInterface(aInterfaceId, aInterface, aInput);
   1.208 +		}
   1.209 +	}
   1.210 +
   1.211 +CBitProxyDriveFactory::CBitProxyDriveFactory()
   1.212 +//
   1.213 +//
   1.214 +//
   1.215 +	{
   1.216 +	RDebug::Print(_L("CBitProxyDriveFactory::CBitProxyDriveFactory"));
   1.217 +	}
   1.218 +
   1.219 +TInt CBitProxyDriveFactory::Install()
   1.220 +//
   1.221 +//
   1.222 +//
   1.223 +	{
   1.224 +	_LIT(KBitName,"Bitchange");
   1.225 +	return(SetName(&KBitName));
   1.226 +	}
   1.227 +
   1.228 +
   1.229 +CProxyDrive* CBitProxyDriveFactory::NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount)
   1.230 +//
   1.231 +//
   1.232 +//
   1.233 +	{
   1.234 +	return(CBitExtProxyDrive::NewL(aProxy,aMount));
   1.235 +	}
   1.236 +
   1.237 +extern "C" {
   1.238 +
   1.239 +EXPORT_C CProxyDriveFactory* CreateFileSystem()
   1.240 +//
   1.241 +// Create a new file system
   1.242 +//
   1.243 +	{
   1.244 +	return(new CBitProxyDriveFactory());
   1.245 +	}
   1.246 +}
   1.247 +