kerneltest/f32test/ext/t_bitext.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    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
       
    17 // 
       
    18 //
       
    19 
       
    20 #include <f32fsys.h>
       
    21 
       
    22 class CBitExtProxyDrive : public CBaseExtProxyDrive
       
    23 	{
       
    24 public:
       
    25 	static CBitExtProxyDrive* NewL(CProxyDrive* aProxyDrive, CMountCB* aMount);
       
    26 	~CBitExtProxyDrive();
       
    27 public:
       
    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);
       
    38 private:
       
    39 	CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount);
       
    40 private:
       
    41 	TInt iReadThread;
       
    42 	TInt iRead;
       
    43 	TInt iWriteThread;
       
    44 	TInt iWrite;
       
    45 	TInt iFormat;
       
    46 	};
       
    47 
       
    48 class CBitProxyDriveFactory : public CProxyDriveFactory
       
    49 	{
       
    50 public:
       
    51 	CBitProxyDriveFactory();
       
    52 	virtual TInt Install();			
       
    53 	virtual CProxyDrive* NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount);
       
    54 	};
       
    55 
       
    56 const TUint8 KBitMask=0xcc;
       
    57 const TInt KChangePosMask=0x0000001f;
       
    58 
       
    59 LOCAL_C void DoXOR(TInt aPos,TInt aLength,TUint8* aPtr)
       
    60 //
       
    61 //
       
    62 //
       
    63 	{
       
    64 	for(TInt i=0;i<aLength;++i)
       
    65 		{
       
    66 		if(((i+aPos)&KChangePosMask)==0)
       
    67 			aPtr[i]^=KBitMask;
       
    68 		}
       
    69 	}
       
    70 
       
    71 
       
    72 CBitExtProxyDrive* CBitExtProxyDrive::NewL(CProxyDrive* aProxyDrive, CMountCB* aMount)
       
    73 //
       
    74 //
       
    75 //
       
    76 	{
       
    77 	CBitExtProxyDrive* temp=new(ELeave) CBitExtProxyDrive(aProxyDrive,aMount);
       
    78 	return(temp);
       
    79 	}
       
    80 
       
    81 
       
    82 CBitExtProxyDrive::CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount):CBaseExtProxyDrive(aProxyDrive,aMount)
       
    83 	{
       
    84 	RDebug::Print(_L("CBitExtProxyDrive::CBitExtProxyDrive"));
       
    85 	}
       
    86 
       
    87 CBitExtProxyDrive::~CBitExtProxyDrive()
       
    88 //
       
    89 //
       
    90 //
       
    91 	{
       
    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);
       
    97 	}
       
    98 
       
    99 TInt CBitExtProxyDrive::Initialise()
       
   100 //
       
   101 //
       
   102 //
       
   103 	{
       
   104 	return(CBaseExtProxyDrive::Initialise());
       
   105 	}
       
   106 
       
   107 TInt CBitExtProxyDrive::Dismounted()
       
   108 //
       
   109 //
       
   110 //
       
   111 	{
       
   112 	return(CBaseExtProxyDrive::Dismounted());
       
   113 	}
       
   114 
       
   115 TInt CBitExtProxyDrive::Enlarge(TInt aLength)
       
   116 //
       
   117 //
       
   118 //
       
   119 	{
       
   120 	return(CBaseExtProxyDrive::Enlarge(aLength));
       
   121 	}
       
   122 
       
   123 
       
   124 TInt CBitExtProxyDrive::ReduceSize(TInt aPos, TInt aLength)
       
   125 //
       
   126 //
       
   127 //
       
   128 	{
       
   129 	return(CBaseExtProxyDrive::ReduceSize(aPos,aLength));
       
   130 	}
       
   131 
       
   132 TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset)
       
   133 //
       
   134 //
       
   135 //
       
   136 	{
       
   137 	++iReadThread;
       
   138 	return(CBaseExtProxyDrive::Read(aPos,aLength,aTrg,aThreadHandle,anOffset));
       
   139 	}
       
   140 
       
   141 TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,TDes8& aTrg)
       
   142 //
       
   143 //
       
   144 //
       
   145 	{
       
   146 	++iRead;
       
   147 	TInt r=CBaseExtProxyDrive::Read(aPos,aLength,aTrg);
       
   148 	DoXOR(I64INT(aPos),aLength,&aTrg[0]);
       
   149 	return(r);
       
   150 	}
       
   151 
       
   152 
       
   153 TInt CBitExtProxyDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset)
       
   154 //
       
   155 //
       
   156 //
       
   157 	{
       
   158 	++iWriteThread;
       
   159 	return(CBaseExtProxyDrive::Write(aPos,aLength,aSrc,aThreadHandle,anOffset));
       
   160 	}
       
   161 
       
   162 TInt CBitExtProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc)
       
   163 //
       
   164 //
       
   165 //
       
   166 	{
       
   167 	++iWrite;
       
   168 
       
   169 	// data may be read-only, so need to copy to a local buffer
       
   170 	// before XOR-ing...
       
   171 	HBufC8* buf = HBufC8::New( aSrc.Length() );
       
   172 	if( !buf )
       
   173 		return KErrNoMemory;
       
   174 	TPtr8 ptr = buf->Des();
       
   175 	ptr.Copy(aSrc);
       
   176 
       
   177 	DoXOR(I64INT(aPos), ptr.Length(), (TUint8*)ptr.Ptr());
       
   178 	TInt r = CBaseExtProxyDrive::Write(aPos, ptr);
       
   179 	
       
   180 	delete buf;
       
   181 
       
   182 	return(r);
       
   183 	}
       
   184 
       
   185 TInt CBitExtProxyDrive::Format(TFormatInfo& anInfo)
       
   186 //
       
   187 //
       
   188 //
       
   189 	{
       
   190 	++iFormat;
       
   191 	return(CBaseExtProxyDrive::Format(anInfo));
       
   192 	}
       
   193 
       
   194 
       
   195 TInt CBitExtProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
       
   196 	{
       
   197 	switch(aInterfaceId)
       
   198 		{
       
   199 		// file caching supported, so pass query on to next extension
       
   200 		case ELocalBufferSupport:
       
   201 			return CBaseExtProxyDrive::LocalBufferSupport();
       
   202 
       
   203 		default:
       
   204 			return CBaseExtProxyDrive::GetInterface(aInterfaceId, aInterface, aInput);
       
   205 		}
       
   206 	}
       
   207 
       
   208 CBitProxyDriveFactory::CBitProxyDriveFactory()
       
   209 //
       
   210 //
       
   211 //
       
   212 	{
       
   213 	RDebug::Print(_L("CBitProxyDriveFactory::CBitProxyDriveFactory"));
       
   214 	}
       
   215 
       
   216 TInt CBitProxyDriveFactory::Install()
       
   217 //
       
   218 //
       
   219 //
       
   220 	{
       
   221 	_LIT(KBitName,"Bitchange");
       
   222 	return(SetName(&KBitName));
       
   223 	}
       
   224 
       
   225 
       
   226 CProxyDrive* CBitProxyDriveFactory::NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount)
       
   227 //
       
   228 //
       
   229 //
       
   230 	{
       
   231 	return(CBitExtProxyDrive::NewL(aProxy,aMount));
       
   232 	}
       
   233 
       
   234 extern "C" {
       
   235 
       
   236 EXPORT_C CProxyDriveFactory* CreateFileSystem()
       
   237 //
       
   238 // Create a new file system
       
   239 //
       
   240 	{
       
   241 	return(new CBitProxyDriveFactory());
       
   242 	}
       
   243 }
       
   244