os/kernelhwsrv/kerneltest/f32test/ext/t_bitext.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32test\ext\bitext.cpp
sl@0
    15
// extension to do XOR on every byte on 32 byte boundary read or written to media subsystem in same thread
sl@0
    16
// therefore RFile::Read/Write does not have this operation carried out on it
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#include <f32fsys.h>
sl@0
    21
sl@0
    22
class CBitExtProxyDrive : public CBaseExtProxyDrive
sl@0
    23
	{
sl@0
    24
public:
sl@0
    25
	static CBitExtProxyDrive* NewL(CProxyDrive* aProxyDrive, CMountCB* aMount);
sl@0
    26
	~CBitExtProxyDrive();
sl@0
    27
public:
sl@0
    28
	virtual TInt Initialise();
sl@0
    29
	virtual TInt Dismounted();
sl@0
    30
	virtual TInt Enlarge(TInt aLength);
sl@0
    31
	virtual TInt ReduceSize(TInt aPos, TInt aLength);
sl@0
    32
	virtual TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset);
sl@0
    33
	virtual TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg);
sl@0
    34
	virtual TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset);
sl@0
    35
	virtual TInt Write(TInt64 aPos,const TDesC8& aSrc);
sl@0
    36
	virtual TInt Format(TFormatInfo& anInfo);
sl@0
    37
	virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
sl@0
    38
private:
sl@0
    39
	CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount);
sl@0
    40
private:
sl@0
    41
	TInt iReadThread;
sl@0
    42
	TInt iRead;
sl@0
    43
	TInt iWriteThread;
sl@0
    44
	TInt iWrite;
sl@0
    45
	TInt iFormat;
sl@0
    46
	};
sl@0
    47
sl@0
    48
class CBitProxyDriveFactory : public CProxyDriveFactory
sl@0
    49
	{
sl@0
    50
public:
sl@0
    51
	CBitProxyDriveFactory();
sl@0
    52
	virtual TInt Install();			
sl@0
    53
	virtual CProxyDrive* NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount);
sl@0
    54
	};
sl@0
    55
sl@0
    56
const TUint8 KBitMask=0xcc;
sl@0
    57
const TInt KChangePosMask=0x0000001f;
sl@0
    58
sl@0
    59
LOCAL_C void DoXOR(TInt aPos,TInt aLength,TUint8* aPtr)
sl@0
    60
//
sl@0
    61
//
sl@0
    62
//
sl@0
    63
	{
sl@0
    64
	for(TInt i=0;i<aLength;++i)
sl@0
    65
		{
sl@0
    66
		if(((i+aPos)&KChangePosMask)==0)
sl@0
    67
			aPtr[i]^=KBitMask;
sl@0
    68
		}
sl@0
    69
	}
sl@0
    70
sl@0
    71
sl@0
    72
CBitExtProxyDrive* CBitExtProxyDrive::NewL(CProxyDrive* aProxyDrive, CMountCB* aMount)
sl@0
    73
//
sl@0
    74
//
sl@0
    75
//
sl@0
    76
	{
sl@0
    77
	CBitExtProxyDrive* temp=new(ELeave) CBitExtProxyDrive(aProxyDrive,aMount);
sl@0
    78
	return(temp);
sl@0
    79
	}
sl@0
    80
sl@0
    81
sl@0
    82
CBitExtProxyDrive::CBitExtProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount):CBaseExtProxyDrive(aProxyDrive,aMount)
sl@0
    83
	{
sl@0
    84
	RDebug::Print(_L("CBitExtProxyDrive::CBitExtProxyDrive"));
sl@0
    85
	}
sl@0
    86
sl@0
    87
CBitExtProxyDrive::~CBitExtProxyDrive()
sl@0
    88
//
sl@0
    89
//
sl@0
    90
//
sl@0
    91
	{
sl@0
    92
	RDebug::Print(_L("Read Thread = %d"),iReadThread);
sl@0
    93
	RDebug::Print(_L("Read = %d"),iRead);
sl@0
    94
	RDebug::Print(_L("Write Thread = %d"),iWriteThread);
sl@0
    95
	RDebug::Print(_L("Write = %d"),iWrite);
sl@0
    96
	RDebug::Print(_L("Format = %d"),iFormat);
sl@0
    97
	}
sl@0
    98
sl@0
    99
TInt CBitExtProxyDrive::Initialise()
sl@0
   100
//
sl@0
   101
//
sl@0
   102
//
sl@0
   103
	{
sl@0
   104
	return(CBaseExtProxyDrive::Initialise());
sl@0
   105
	}
sl@0
   106
sl@0
   107
TInt CBitExtProxyDrive::Dismounted()
sl@0
   108
//
sl@0
   109
//
sl@0
   110
//
sl@0
   111
	{
sl@0
   112
	return(CBaseExtProxyDrive::Dismounted());
sl@0
   113
	}
sl@0
   114
sl@0
   115
TInt CBitExtProxyDrive::Enlarge(TInt aLength)
sl@0
   116
//
sl@0
   117
//
sl@0
   118
//
sl@0
   119
	{
sl@0
   120
	return(CBaseExtProxyDrive::Enlarge(aLength));
sl@0
   121
	}
sl@0
   122
sl@0
   123
sl@0
   124
TInt CBitExtProxyDrive::ReduceSize(TInt aPos, TInt aLength)
sl@0
   125
//
sl@0
   126
//
sl@0
   127
//
sl@0
   128
	{
sl@0
   129
	return(CBaseExtProxyDrive::ReduceSize(aPos,aLength));
sl@0
   130
	}
sl@0
   131
sl@0
   132
TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aThreadHandle,TInt anOffset)
sl@0
   133
//
sl@0
   134
//
sl@0
   135
//
sl@0
   136
	{
sl@0
   137
	++iReadThread;
sl@0
   138
	return(CBaseExtProxyDrive::Read(aPos,aLength,aTrg,aThreadHandle,anOffset));
sl@0
   139
	}
sl@0
   140
sl@0
   141
TInt CBitExtProxyDrive::Read(TInt64 aPos,TInt aLength,TDes8& aTrg)
sl@0
   142
//
sl@0
   143
//
sl@0
   144
//
sl@0
   145
	{
sl@0
   146
	++iRead;
sl@0
   147
	TInt r=CBaseExtProxyDrive::Read(aPos,aLength,aTrg);
sl@0
   148
	DoXOR(I64INT(aPos),aLength,&aTrg[0]);
sl@0
   149
	return(r);
sl@0
   150
	}
sl@0
   151
sl@0
   152
sl@0
   153
TInt CBitExtProxyDrive::Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aThreadHandle,TInt anOffset)
sl@0
   154
//
sl@0
   155
//
sl@0
   156
//
sl@0
   157
	{
sl@0
   158
	++iWriteThread;
sl@0
   159
	return(CBaseExtProxyDrive::Write(aPos,aLength,aSrc,aThreadHandle,anOffset));
sl@0
   160
	}
sl@0
   161
sl@0
   162
TInt CBitExtProxyDrive::Write(TInt64 aPos,const TDesC8& aSrc)
sl@0
   163
//
sl@0
   164
//
sl@0
   165
//
sl@0
   166
	{
sl@0
   167
	++iWrite;
sl@0
   168
sl@0
   169
	// data may be read-only, so need to copy to a local buffer
sl@0
   170
	// before XOR-ing...
sl@0
   171
	HBufC8* buf = HBufC8::New( aSrc.Length() );
sl@0
   172
	if( !buf )
sl@0
   173
		return KErrNoMemory;
sl@0
   174
	TPtr8 ptr = buf->Des();
sl@0
   175
	ptr.Copy(aSrc);
sl@0
   176
sl@0
   177
	DoXOR(I64INT(aPos), ptr.Length(), (TUint8*)ptr.Ptr());
sl@0
   178
	TInt r = CBaseExtProxyDrive::Write(aPos, ptr);
sl@0
   179
	
sl@0
   180
	delete buf;
sl@0
   181
sl@0
   182
	return(r);
sl@0
   183
	}
sl@0
   184
sl@0
   185
TInt CBitExtProxyDrive::Format(TFormatInfo& anInfo)
sl@0
   186
//
sl@0
   187
//
sl@0
   188
//
sl@0
   189
	{
sl@0
   190
	++iFormat;
sl@0
   191
	return(CBaseExtProxyDrive::Format(anInfo));
sl@0
   192
	}
sl@0
   193
sl@0
   194
sl@0
   195
TInt CBitExtProxyDrive::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
sl@0
   196
	{
sl@0
   197
	switch(aInterfaceId)
sl@0
   198
		{
sl@0
   199
		// file caching supported, so pass query on to next extension
sl@0
   200
		case ELocalBufferSupport:
sl@0
   201
			return CBaseExtProxyDrive::LocalBufferSupport();
sl@0
   202
sl@0
   203
		default:
sl@0
   204
			return CBaseExtProxyDrive::GetInterface(aInterfaceId, aInterface, aInput);
sl@0
   205
		}
sl@0
   206
	}
sl@0
   207
sl@0
   208
CBitProxyDriveFactory::CBitProxyDriveFactory()
sl@0
   209
//
sl@0
   210
//
sl@0
   211
//
sl@0
   212
	{
sl@0
   213
	RDebug::Print(_L("CBitProxyDriveFactory::CBitProxyDriveFactory"));
sl@0
   214
	}
sl@0
   215
sl@0
   216
TInt CBitProxyDriveFactory::Install()
sl@0
   217
//
sl@0
   218
//
sl@0
   219
//
sl@0
   220
	{
sl@0
   221
	_LIT(KBitName,"Bitchange");
sl@0
   222
	return(SetName(&KBitName));
sl@0
   223
	}
sl@0
   224
sl@0
   225
sl@0
   226
CProxyDrive* CBitProxyDriveFactory::NewProxyDriveL(CProxyDrive* aProxy,CMountCB* aMount)
sl@0
   227
//
sl@0
   228
//
sl@0
   229
//
sl@0
   230
	{
sl@0
   231
	return(CBitExtProxyDrive::NewL(aProxy,aMount));
sl@0
   232
	}
sl@0
   233
sl@0
   234
extern "C" {
sl@0
   235
sl@0
   236
EXPORT_C CProxyDriveFactory* CreateFileSystem()
sl@0
   237
//
sl@0
   238
// Create a new file system
sl@0
   239
//
sl@0
   240
	{
sl@0
   241
	return(new CBitProxyDriveFactory());
sl@0
   242
	}
sl@0
   243
}
sl@0
   244