os/kernelhwsrv/kerneltest/e32test/pccd/t_setkey.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-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
// This test tests reading and writing to the protected & unprotected area of an SD card
sl@0
    15
// & verifies that mounting & dismounting the protected area does not disrupt reads and/or 
sl@0
    16
// writes to the unprotected area.
sl@0
    17
// NB For test to work, a valid key which matches the SD card under test needs to be put 
sl@0
    18
// into the byte array testDeviceKeyRawData[].
sl@0
    19
// ********* IMPORTANT NOTE TO SYMBIAN ENGINEERS WORKING WITH THIS TEST *********
sl@0
    20
// The key MUST NOT BE CHECKED INTO PERFORCE as this would contravene the license agreement
sl@0
    21
// we have with the SD Card Association.
sl@0
    22
// ********* IMPORTANT NOTE TO SYMBIAN ENGINEERS WORKING WITH THIS TEST *********
sl@0
    23
// 
sl@0
    24
//
sl@0
    25
sl@0
    26
#include <e32std.h>
sl@0
    27
#include <e32std_private.h>
sl@0
    28
#include <e32cons.h>
sl@0
    29
#include <f32file.h>
sl@0
    30
#include <e32test.h>
sl@0
    31
sl@0
    32
const TUint32 KDriveNumProt = EDriveG;
sl@0
    33
const TUint32 KDriveNumUnprot = EDriveF;
sl@0
    34
TChar gDriveLetterProt;
sl@0
    35
TChar gDriveLetterUnprot;
sl@0
    36
TBool gMountProtectedArea = EFalse;
sl@0
    37
sl@0
    38
GLDEF_D RTest test(_L("T_SETKEY"));
sl@0
    39
sl@0
    40
// flags stolen from locmedia.h
sl@0
    41
//const TInt KForceMediaChangeReOpenAllMediaDrivers	= 0;
sl@0
    42
const TUint KForceMediaChangeReOpenMediaDriver		= 0x80000000UL;
sl@0
    43
const TUint KMediaRemountForceMediaChange			= 0x00000001UL;
sl@0
    44
sl@0
    45
class TSDCardSecureMountInfo
sl@0
    46
	{
sl@0
    47
public:
sl@0
    48
	TUid iUid;
sl@0
    49
	const TDesC8* iEncryptedDeviceKey;
sl@0
    50
	const TDesC8* iRamMKBData;
sl@0
    51
	TInt iMKBNumber;
sl@0
    52
	};
sl@0
    53
typedef TPckgBuf<TSDCardSecureMountInfo> TSDCardSecureMountInfoPckg;
sl@0
    54
sl@0
    55
typedef enum 
sl@0
    56
	{
sl@0
    57
	EClearMountInfo=0,
sl@0
    58
	ESetMountInfo=1
sl@0
    59
	} TMountInfoAction;
sl@0
    60
sl@0
    61
sl@0
    62
// Standard boilerplate for creating a console window ////////////////////////
sl@0
    63
void StartAppL();
sl@0
    64
void SetupConsoleL();
sl@0
    65
sl@0
    66
GLDEF_C TInt E32Main()									// main function called by E32
sl@0
    67
    {
sl@0
    68
	CTrapCleanup* cleanup=CTrapCleanup::New();			// get clean-up stack
sl@0
    69
	TRAPD(error,SetupConsoleL());						// more initialization, then do example
sl@0
    70
	__ASSERT_DEBUG(!error,User::Panic(_L("BossTextUi"),error));
sl@0
    71
	delete cleanup;										// destroy clean-up stack
sl@0
    72
	return 0;											// and return
sl@0
    73
    }
sl@0
    74
sl@0
    75
// Determine whether we should run the full test or just mount the protected area
sl@0
    76
void ParseCommandLine()
sl@0
    77
	{
sl@0
    78
	TBuf<32> args;
sl@0
    79
	User::CommandLine(args);
sl@0
    80
	
sl@0
    81
	if (args == _L("-m"))
sl@0
    82
		{
sl@0
    83
		gMountProtectedArea = ETrue;
sl@0
    84
		}
sl@0
    85
	else if (args == _L("-?"))
sl@0
    86
		{
sl@0
    87
		test.Printf(_L("usage: t_setkey [-m]\n"));
sl@0
    88
		test.Printf(_L("-m => mount proteced area and exit\n"));
sl@0
    89
		}
sl@0
    90
	}
sl@0
    91
sl@0
    92
void SetupConsoleL()									// initialize and call example code under cleanup stack
sl@0
    93
    {
sl@0
    94
	test.Title();
sl@0
    95
	test.Start(_L("Starting tests..."));
sl@0
    96
sl@0
    97
	ParseCommandLine();
sl@0
    98
	TRAPD(error,StartAppL());					// perform example function
sl@0
    99
	if (error) 
sl@0
   100
		test.Printf(_L("failed: leave code=%d\n"), error);
sl@0
   101
	else 
sl@0
   102
		test.Printf(_L("ok\n"));
sl@0
   103
sl@0
   104
	test.Printf(_L(" [press any key]\n"));
sl@0
   105
	test.Getch();
sl@0
   106
sl@0
   107
	test.End();
sl@0
   108
	test.Close();
sl@0
   109
	
sl@0
   110
    }
sl@0
   111
sl@0
   112
// End of standard boilerplate ///////////////////////////////////////////////
sl@0
   113
sl@0
   114
sl@0
   115
static const TUint8 testDeviceKeyRawData[160] =	
sl@0
   116
	{
sl@0
   117
sl@0
   118
// Symbian test key :
sl@0
   119
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   120
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   121
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   122
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   123
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   124
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   125
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   126
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   127
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
sl@0
   128
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
sl@0
   129
sl@0
   130
sl@0
   131
	};
sl@0
   132
sl@0
   133
TInt WriteThreadEntryPoint( TAny* aParam )
sl@0
   134
	{
sl@0
   135
	(void)aParam;
sl@0
   136
	
sl@0
   137
	RTest test(_L("WriteThread"));
sl@0
   138
sl@0
   139
	test.Title();
sl@0
   140
	
sl@0
   141
	test.Start(_L("Starting WriteThread ..."));
sl@0
   142
sl@0
   143
	TInt r;
sl@0
   144
	RFs fs;
sl@0
   145
sl@0
   146
	r = fs.Connect();
sl@0
   147
	if(r != KErrNone)
sl@0
   148
		{
sl@0
   149
		test.Printf(_L("WT Connect err %d\n"), r);
sl@0
   150
		}
sl@0
   151
sl@0
   152
	RFile file;
sl@0
   153
sl@0
   154
	TFileName fileNameUnprot = _L("?:\\TESTTHRD.TXT");
sl@0
   155
	fileNameUnprot[0] = (TText) gDriveLetterUnprot;
sl@0
   156
sl@0
   157
	//Open file on the user area drive
sl@0
   158
	r = file.Replace(fs, fileNameUnprot, EFileWrite);
sl@0
   159
	if(r != KErrNone)
sl@0
   160
		{
sl@0
   161
		test.Printf(_L("WT File Replace err %d\n\n"), r);
sl@0
   162
		test(0);
sl@0
   163
		}
sl@0
   164
sl@0
   165
	TPtrC8 data(testDeviceKeyRawData, 8);
sl@0
   166
sl@0
   167
	RThread().Rendezvous(KErrNone);
sl@0
   168
sl@0
   169
	for(TInt iter=0; iter < KMaxTInt;iter++)	// keep sending write requests to the user area for ever
sl@0
   170
		{
sl@0
   171
		
sl@0
   172
		r = file.Write(data);
sl@0
   173
//test.Printf(_L("WT File Write err %d iter %d\r"), r, iter);
sl@0
   174
sl@0
   175
		if(r != KErrNone)
sl@0
   176
			{
sl@0
   177
			test.Printf(_L("WT File Write err %d\n"), r);
sl@0
   178
			test(0);
sl@0
   179
			}
sl@0
   180
		}
sl@0
   181
sl@0
   182
	file.Close();
sl@0
   183
	fs.Close();
sl@0
   184
sl@0
   185
	test.End();
sl@0
   186
	test.Close();
sl@0
   187
sl@0
   188
	return 0;
sl@0
   189
	}
sl@0
   190
    
sl@0
   191
sl@0
   192
sl@0
   193
GLDEF_C void StartAppL()
sl@0
   194
    {
sl@0
   195
sl@0
   196
	// Exit if no key defined
sl@0
   197
	if (testDeviceKeyRawData[0] == 0 && testDeviceKeyRawData[1] == 0)
sl@0
   198
		{
sl@0
   199
		test.Printf(_L("This test needs to be recompiled with a valid key\n"));
sl@0
   200
		test(0);
sl@0
   201
		}
sl@0
   202
sl@0
   203
	RFs fs;
sl@0
   204
	TInt r;
sl@0
   205
sl@0
   206
sl@0
   207
	test.Printf(_L("Starting Setkey\n"));
sl@0
   208
	if(fs.Connect()!=KErrNone)
sl@0
   209
		return;
sl@0
   210
sl@0
   211
	test.Printf(_L("Connected to fileserver OK\n"));
sl@0
   212
	TBuf8<160> mkBData;
sl@0
   213
sl@0
   214
	mkBData.SetLength(160);
sl@0
   215
	TInt i;
sl@0
   216
	for (i = 0; i < 160; i++)
sl@0
   217
		{
sl@0
   218
		mkBData[i] = testDeviceKeyRawData[i];
sl@0
   219
		}
sl@0
   220
	
sl@0
   221
	TSDCardSecureMountInfoPckg pckg;
sl@0
   222
sl@0
   223
sl@0
   224
	pckg().iRamMKBData=(const TDesC8*)0x01;   //Unused for now.
sl@0
   225
	pckg().iMKBNumber = 0;
sl@0
   226
//	pckg().iMKBNumber = 11;		// for SD Binding ?
sl@0
   227
	static TPtrC8 encryptedDeviceKey(testDeviceKeyRawData, sizeof(testDeviceKeyRawData));
sl@0
   228
	pckg().iEncryptedDeviceKey = &encryptedDeviceKey;
sl@0
   229
sl@0
   230
sl@0
   231
	r = fs.DriveToChar(KDriveNumProt, gDriveLetterProt);
sl@0
   232
	r = fs.DriveToChar(KDriveNumUnprot, gDriveLetterUnprot);
sl@0
   233
	TFileName fileNameUnprot = _L("?:\\TEST.TXT");
sl@0
   234
	TFileName fileNameProt = _L("?:\\TEST.TXT");
sl@0
   235
	fileNameUnprot[0] = (TText) gDriveLetterUnprot;
sl@0
   236
	fileNameProt[0] = (TText) gDriveLetterProt;
sl@0
   237
sl@0
   238
	TVolumeInfo v;
sl@0
   239
sl@0
   240
	r = fs.Volume(v, KDriveNumProt); //Check
sl@0
   241
test.Printf(_L("Volume() returned %d\n"), r);
sl@0
   242
	test(r == KErrNotReady || r == KErrNone);
sl@0
   243
sl@0
   244
sl@0
   245
	if (gMountProtectedArea)
sl@0
   246
		{
sl@0
   247
		test.Next(_L("test remount with KForceMediaChangeReOpenMediaDriver flag"));
sl@0
   248
		// verify that the unprotected area does not get a change notification
sl@0
   249
		TFileName filePathUnprot = _L("?:\\");
sl@0
   250
		filePathUnprot[0] = (TText) gDriveLetterUnprot;
sl@0
   251
		TRequestStatus changeStatus;
sl@0
   252
		fs.NotifyChange(ENotifyAll, changeStatus, filePathUnprot);
sl@0
   253
sl@0
   254
		r = fs.RemountDrive(KDriveNumProt, &pckg, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   255
		test(r == KErrNone);
sl@0
   256
		r = fs.Volume(v, KDriveNumProt); //Check
sl@0
   257
		test.Printf(_L("Volume() returned %d\n"), r);
sl@0
   258
		test(r == KErrNone || r == KErrCorrupt);
sl@0
   259
sl@0
   260
		test.Next(_L("test this causes no change to unprotected drive"));
sl@0
   261
		test.Printf(_L("changeStatus %d\n"), changeStatus.Int());
sl@0
   262
		test (changeStatus.Int() == KRequestPending);
sl@0
   263
		fs.NotifyChangeCancel(changeStatus);
sl@0
   264
sl@0
   265
		test.Printf(_L("Remount Drive suceeded.  Secure area is now unlocked\n"));
sl@0
   266
		fs.Close();
sl@0
   267
		return;
sl@0
   268
		}
sl@0
   269
sl@0
   270
	// Set the mount info for the secure area using KMediaRemountForceMediaChange flag
sl@0
   271
	// This is asynchronous in behaviour i.e. we need to wait for (two) media change notifications
sl@0
   272
	// before the drive is ready for use
sl@0
   273
	test.Next(_L("test remount with KMediaRemountForceMediaChange flag"));
sl@0
   274
	TRequestStatus changeStatus;
sl@0
   275
	fs.NotifyChange(ENotifyAll, changeStatus);
sl@0
   276
	r = fs.RemountDrive(KDriveNumProt, &pckg, (TUint) KMediaRemountForceMediaChange);
sl@0
   277
test.Printf(_L("RemountDrive() returned %d\n"), r);
sl@0
   278
	test(r == KErrNotReady || r == KErrNone);
sl@0
   279
	
sl@0
   280
	test.Printf(_L("Waiting for media change...\n"));
sl@0
   281
	User::WaitForRequest(changeStatus);
sl@0
   282
	
sl@0
   283
	do
sl@0
   284
		{
sl@0
   285
sl@0
   286
sl@0
   287
		r = fs.Volume(v, KDriveNumProt); //Check
sl@0
   288
		test.Printf(_L("Volume() returned %d\n"), r);
sl@0
   289
sl@0
   290
	fs.NotifyChange(ENotifyAll, changeStatus);
sl@0
   291
		}
sl@0
   292
	while (r == KErrNotReady);
sl@0
   293
	fs.NotifyChangeCancel(changeStatus);
sl@0
   294
	
sl@0
   295
sl@0
   296
sl@0
   297
	// Set the mount info for the secure area using KForceMediaChangeReOpenMediaDriver flag
sl@0
   298
	// This should be synchronous in behaviour
sl@0
   299
	test.Next(_L("test remount with KForceMediaChangeReOpenMediaDriver flag"));
sl@0
   300
	r = fs.RemountDrive(KDriveNumProt, NULL, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   301
	test(r == KErrNone);
sl@0
   302
	r = fs.RemountDrive(KDriveNumProt, &pckg, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   303
	test(r == KErrNone);
sl@0
   304
	r = fs.Volume(v, KDriveNumProt); //Check
sl@0
   305
test.Printf(_L("Volume() returned %d\n"), r);
sl@0
   306
	test(r == KErrNone);
sl@0
   307
sl@0
   308
	test.Printf(_L("Remount Drive suceeded.  Secure area is now unlocked\n"));
sl@0
   309
	test.Printf(_L("Press any key to continue...\n"));
sl@0
   310
sl@0
   311
sl@0
   312
	test.Next(_L("test writing to protected & unprotected areas"));
sl@0
   313
sl@0
   314
	RFile f1,f2;
sl@0
   315
	TRequestStatus req1, req2, req3, req4;
sl@0
   316
sl@0
   317
	const TInt KBufSize = 32 * 1024;
sl@0
   318
	LOCAL_D TBuf8<KBufSize> gBuf;
sl@0
   319
sl@0
   320
sl@0
   321
	test.Printf(_L("Opening files...\n"));
sl@0
   322
test.Printf(_L("Opening %S...\n"), &fileNameUnprot);
sl@0
   323
	r = f1.Replace(fs, fileNameUnprot,EFileStreamText|EFileWrite);
sl@0
   324
	test (r == KErrNone);
sl@0
   325
sl@0
   326
test.Printf(_L("Opening %S...\n"), &fileNameProt);
sl@0
   327
	r = f2.Replace(fs, fileNameProt,EFileStreamText|EFileWrite);
sl@0
   328
	test (r == KErrNone);
sl@0
   329
	
sl@0
   330
sl@0
   331
//	test.Printf(_L("Wait 10 secs for stack to power down...\n"));
sl@0
   332
//	User::After(10 * 1000000);
sl@0
   333
//	test.Printf(_L("done\n"));
sl@0
   334
	
sl@0
   335
	gBuf.SetLength(KBufSize);
sl@0
   336
	
sl@0
   337
test.Printf(_L("Writing files...\n"));
sl@0
   338
sl@0
   339
	req1 = KRequestPending;
sl@0
   340
	req2 = KRequestPending;
sl@0
   341
	req3 = KRequestPending;
sl@0
   342
	req4 = KRequestPending;
sl@0
   343
sl@0
   344
	f1.Write(gBuf, req1);
sl@0
   345
r = fs.RemountDrive(KDriveNumProt, &pckg, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   346
test (r == KErrNone);
sl@0
   347
	f2.Write(gBuf, req2);
sl@0
   348
sl@0
   349
test.Printf(_L("req1 %d, req2 %d\n"), req1.Int(), req2.Int());
sl@0
   350
	test (req1 == KRequestPending || req1 == KErrNone);
sl@0
   351
	test (req2 == KRequestPending || req2 == KErrNone);
sl@0
   352
sl@0
   353
	// force a remount to test whether a write to the unprotected area
sl@0
   354
	// is disrupted.... 
sl@0
   355
	// NB Should set aFlags to KForceMediaChangeReOpenMediaDriver, otherwise a media change will occur which WILL
sl@0
   356
	// prematurely complete any pending writes 
sl@0
   357
r = fs.RemountDrive(KDriveNumProt, &pckg, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   358
test (r == KErrNone);
sl@0
   359
sl@0
   360
//r = fs.RemountDrive(KDriveNumProt, &pckg, 1);
sl@0
   361
test.Printf(_L("RemountDrive() returned %d\n"), r);
sl@0
   362
	
sl@0
   363
	f1.Write(gBuf, req3);
sl@0
   364
	f2.Write(gBuf, req4);
sl@0
   365
sl@0
   366
test.Printf(_L("WaitForRequests...\n"));
sl@0
   367
	User::WaitForRequest(req1);
sl@0
   368
	User::WaitForRequest(req2);
sl@0
   369
	User::WaitForRequest(req3);
sl@0
   370
	User::WaitForRequest(req4);
sl@0
   371
sl@0
   372
test.Printf(_L("req1 %d, req2 %d req3 %d, req4 %d\n"), req1.Int(), req2.Int(), req3.Int(), req4.Int());
sl@0
   373
	test (req1 == KErrNone);
sl@0
   374
	test (req2 == KErrNone);
sl@0
   375
	test (req3 == KErrNone);
sl@0
   376
	test (req4 == KErrNone);
sl@0
   377
	
sl@0
   378
	f1.Close();
sl@0
   379
	f2.Close();
sl@0
   380
sl@0
   381
sl@0
   382
	// create a thread which continuously writes to the unprotected area
sl@0
   383
	// whilst continually remounting protected area in this thread.
sl@0
   384
	
sl@0
   385
	test.Next(_L("test writing to protected & unprotected areas using different threads"));
sl@0
   386
sl@0
   387
test.Printf(_L("Opening %S for read access...\n"), &fileNameUnprot);
sl@0
   388
	r = f2.Open(fs, fileNameProt, EFileShareReadersOnly);
sl@0
   389
	test (r == KErrNone);
sl@0
   390
sl@0
   391
sl@0
   392
	test (r == KErrNone);
sl@0
   393
	RThread thread;
sl@0
   394
	r = thread.Create( _L("Write Thread"), WriteThreadEntryPoint, KDefaultStackSize, NULL, NULL);
sl@0
   395
	if(r !=KErrNone)
sl@0
   396
		{
sl@0
   397
		test.Printf(_L("MT Thread Create 1 ret = %d\n"),r);
sl@0
   398
		return;
sl@0
   399
		}
sl@0
   400
	TRequestStatus writeThreadStat;
sl@0
   401
	
sl@0
   402
	thread.Rendezvous(writeThreadStat);
sl@0
   403
	thread.Resume();
sl@0
   404
	User::WaitForRequest(writeThreadStat);
sl@0
   405
//	thread.Close(); //close handle to thread
sl@0
   406
	if(writeThreadStat.Int() != KErrNone)
sl@0
   407
		{
sl@0
   408
		test.Printf(_L("MT Thread Create 2 ret = %d\n"),writeThreadStat.Int());
sl@0
   409
		test(0);
sl@0
   410
		}
sl@0
   411
sl@0
   412
	TBuf8<14> buf;
sl@0
   413
sl@0
   414
sl@0
   415
	const TInt KMaxIterations = 1000;
sl@0
   416
	for(TInt n=0; n<KMaxIterations; n++)
sl@0
   417
		{
sl@0
   418
		if (n % 10 == 0)
sl@0
   419
			test.Printf(_L("iteration %d of %d\r"), n, KMaxIterations);
sl@0
   420
sl@0
   421
		//Set the mount info for the secure area.
sl@0
   422
		r = fs.RemountDrive(KDriveNumProt, &pckg, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   423
		if (r == KErrNone)
sl@0
   424
			{
sl@0
   425
//			test.Printf(_L("Remount Drive KEY suceeded. Secure area is now unlocked\n"));
sl@0
   426
			}
sl@0
   427
		else
sl@0
   428
			{
sl@0
   429
			test.Printf(_L("Remount Drive KEY failed with %d\n"), r);
sl@0
   430
			test(0);
sl@0
   431
			}
sl@0
   432
sl@0
   433
		// take it in turns to 
sl@0
   434
		// (0) call Rfs:Volume()
sl@0
   435
		// (1) call RFile::Read
sl@0
   436
		// (2) do nothing
sl@0
   437
		TInt testNum = n & 0x3;
sl@0
   438
		if (testNum == 0)
sl@0
   439
			{
sl@0
   440
			TVolumeInfo volumeInfo;
sl@0
   441
			r = fs.Volume( volumeInfo, KDriveNumProt );
sl@0
   442
			if (r != KErrNone)
sl@0
   443
				{
sl@0
   444
				RDebug::Print( _L("Volume returned %d after RemountDrive"), r);
sl@0
   445
				break;
sl@0
   446
				}
sl@0
   447
			}
sl@0
   448
		else if (testNum == 1)
sl@0
   449
			{
sl@0
   450
			r = f2.Read(0,buf);
sl@0
   451
			if(r != KErrNone)
sl@0
   452
				{
sl@0
   453
				test.Printf(_L("protected Drive Access failed %d\n"), r);
sl@0
   454
				test(0);
sl@0
   455
				}
sl@0
   456
			}
sl@0
   457
		else if (testNum == 2)
sl@0
   458
			{
sl@0
   459
			}
sl@0
   460
		else if (testNum == 3)
sl@0
   461
			{
sl@0
   462
			}
sl@0
   463
		
sl@0
   464
sl@0
   465
//test.Printf(_L("protected Drive KEY Access succeeded\n"));
sl@0
   466
		r = fs.RemountDrive(KDriveNumProt, NULL, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   467
		if (r == KErrNone)
sl@0
   468
			{
sl@0
   469
//			test.Printf(_L("Remount Drive NULL suceeded. Secure area is now locked\n"));
sl@0
   470
			}
sl@0
   471
		else
sl@0
   472
			{
sl@0
   473
			test.Printf(_L("Remount Drive NULL failed with %d\n"), r);
sl@0
   474
			test(0);
sl@0
   475
			}
sl@0
   476
sl@0
   477
		if (testNum == 1)
sl@0
   478
			{
sl@0
   479
			r = f2.Read(0,buf);
sl@0
   480
//test.Printf(_L("protected Drive NULL Access failed with %d\n"), r);
sl@0
   481
			if (r != KErrNotReady)
sl@0
   482
				{
sl@0
   483
				test.Printf(_L("protected Drive NULL Access failed with unexpected error %d\n"), r);
sl@0
   484
				test(0);
sl@0
   485
				}
sl@0
   486
			}
sl@0
   487
	
sl@0
   488
		}
sl@0
   489
sl@0
   490
	f1.Close();
sl@0
   491
sl@0
   492
sl@0
   493
	// comment in the next 2 lines to leave the protected area mounted...
sl@0
   494
	r = fs.RemountDrive(KDriveNumProt, &pckg, (TUint) KForceMediaChangeReOpenMediaDriver);
sl@0
   495
	test(r == KErrNone);
sl@0
   496
sl@0
   497
	thread.Kill(KErrNone);
sl@0
   498
	thread.Close(); //close handle to thread
sl@0
   499
sl@0
   500
	fs.Close();
sl@0
   501
sl@0
   502
	}