os/kernelhwsrv/kerneltest/f32test/server/t_blockmap.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) 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
// Tests for the blockmap API. The blockmap API enumerates the resources
sl@0
    15
// used by a file depending upon the type of media on which the file
sl@0
    16
// resides.
sl@0
    17
// 002 Test Initialise error checking
sl@0
    18
// 003 Test processing of user-side block map into extent list
sl@0
    19
// 004 Test processing of user-side block map into extent list, block size > read unit size
sl@0
    20
// 005 Test Read error checking
sl@0
    21
// 006 Test Read
sl@0
    22
// Test BlockMap API functionality.
sl@0
    23
// 
sl@0
    24
//
sl@0
    25
sl@0
    26
//! @SYMTestCaseID			KBASE-T_BLOCKMAP-0337
sl@0
    27
//! @SYMTestType			UT
sl@0
    28
//! @SYMPREQ				PREQ1110
sl@0
    29
//! @SYMTestCaseDesc		Demand Paging Blockmap tests
sl@0
    30
//! @SYMTestActions			001 Unit tests the TKernBlockMap class
sl@0
    31
//! @SYMTestExpectedResults All tests should pass.
sl@0
    32
//! @SYMTestPriority        High
sl@0
    33
//! @SYMTestStatus          Implemented
sl@0
    34
sl@0
    35
sl@0
    36
#include <e32test.h>
sl@0
    37
#include <e32svr.h>
sl@0
    38
#include <f32file.h>
sl@0
    39
#include <e32math.h>
sl@0
    40
#include <hal.h>
sl@0
    41
#include "t_server.h"
sl@0
    42
sl@0
    43
RTest test( _L("T_BLOCKMAP") );
sl@0
    44
sl@0
    45
const TInt KReadBufferSize = 1024;
sl@0
    46
const TInt KMaxFragmentSize = 400;
sl@0
    47
const TInt KMaxFileSize = 10000;
sl@0
    48
sl@0
    49
TInt RamFatDrive = -1;
sl@0
    50
TInt RemovableFatDrive = -1;
sl@0
    51
TInt InternalRemovableFatDrive = -1;
sl@0
    52
TInt NandDrive = -1;
sl@0
    53
TBool Pageable = EFalse;
sl@0
    54
TBool Finished = EFalse;
sl@0
    55
sl@0
    56
enum DriveType
sl@0
    57
	{
sl@0
    58
	EDriveNand,
sl@0
    59
	EDriveRam,
sl@0
    60
	EDriveRemovable,
sl@0
    61
	EDriveInternalRemovable
sl@0
    62
	};
sl@0
    63
sl@0
    64
_LIT( KTestFile, "Z:\\TEST\\T_FILE.CPP");
sl@0
    65
_LIT( KTestFileFAT, "Z:\\Multiple\\T_file.cpp");
sl@0
    66
_LIT( KTestFileName, "T_FILE.CPP");
sl@0
    67
_LIT( KFragmentedFileName1, "FRAG1.TXT");
sl@0
    68
_LIT( KFragmentedFileName2, "FRAG2.TXT");
sl@0
    69
_LIT( KDriveBase, " :\\" );
sl@0
    70
sl@0
    71
LOCAL_C TInt TestBlockMapNandFATUserData(TInt64 aStartPos, TInt64 aEndPos)
sl@0
    72
	{
sl@0
    73
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
    74
	test(fMan!=NULL);
sl@0
    75
	TFileName name(KDriveBase);
sl@0
    76
	name[0] = TText('A' + NandDrive);
sl@0
    77
	name.Append( KTestFileName );
sl@0
    78
sl@0
    79
	TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
    80
	r = fMan->Delete(name);
sl@0
    81
sl@0
    82
	r = fMan->Copy(KTestFile, name);
sl@0
    83
	test( r == KErrNone );
sl@0
    84
sl@0
    85
	TInt localDriveNum = 0;
sl@0
    86
	RFile testFile;
sl@0
    87
	r = testFile.Open( TheFs, name, EFileRead );
sl@0
    88
	test( r == KErrNone );
sl@0
    89
	
sl@0
    90
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
    91
	SBlockMapInfo info;
sl@0
    92
	TInt counter = 0;
sl@0
    93
	TInt startPos = aStartPos;
sl@0
    94
	TInt bmErr;
sl@0
    95
sl@0
    96
	// Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
sl@0
    97
	do
sl@0
    98
		{
sl@0
    99
		bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
sl@0
   100
		if (bmErr != 0 && bmErr != KErrCompletion)
sl@0
   101
			{
sl@0
   102
			map.Close();
sl@0
   103
			testFile.Close();
sl@0
   104
			r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   105
			test( r == KErrNone );
sl@0
   106
			r = fMan->Delete(name);
sl@0
   107
			test( r == KErrNone );
sl@0
   108
			delete fMan;
sl@0
   109
			return bmErr;
sl@0
   110
			}
sl@0
   111
		map.Append(info); 
sl@0
   112
		if (counter++ == 0)
sl@0
   113
			localDriveNum = info.iLocalDriveNumber;
sl@0
   114
		} while ( bmErr == 0 && bmErr != KErrCompletion );
sl@0
   115
	test( bmErr == KErrCompletion );
sl@0
   116
	TInt granularity;
sl@0
   117
sl@0
   118
	TInt size;
sl@0
   119
	r = testFile.Size(size);
sl@0
   120
	test( r == KErrNone );
sl@0
   121
sl@0
   122
	TBuf8<KReadBufferSize> buf1;
sl@0
   123
	TBuf8<KReadBufferSize> buf2;
sl@0
   124
	
sl@0
   125
	TBool changed;	
sl@0
   126
	TBusLocalDrive localDrive;
sl@0
   127
sl@0
   128
	UserSvr::UnlockRamDrive();
sl@0
   129
sl@0
   130
	TBlockMapEntry* myBlockMapEntry;
sl@0
   131
	TInt myCounter = 0;
sl@0
   132
	TInt totalSegments = 0;
sl@0
   133
	TInt remainder = 0;
sl@0
   134
	TInt miniLength = 0;
sl@0
   135
	TInt amountRead = 0;
sl@0
   136
sl@0
   137
	TInt c;
sl@0
   138
	for ( c = 0; c < map.Count(); c++ )
sl@0
   139
		{
sl@0
   140
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   141
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   142
		totalSegments += granularity;
sl@0
   143
		}
sl@0
   144
sl@0
   145
	const TInt KTotalSegments = totalSegments;
sl@0
   146
	r = localDrive.Connect( localDriveNum, changed );
sl@0
   147
	test( r == KErrNone );
sl@0
   148
sl@0
   149
//	For each SBlockMapInfo object in RArray map
sl@0
   150
	for ( c = 0; c < map.Count(); c++ )
sl@0
   151
		{
sl@0
   152
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   153
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   154
		TInt length;
sl@0
   155
		if ( aEndPos == -1 )
sl@0
   156
			{
sl@0
   157
			length = size - startPos;
sl@0
   158
			aEndPos = size;
sl@0
   159
			}
sl@0
   160
		else
sl@0
   161
			length = aEndPos - startPos;
sl@0
   162
		
sl@0
   163
		for ( TInt c2 = 1; c2 <= granularity; c2++)
sl@0
   164
			{
sl@0
   165
			myCounter = 0;
sl@0
   166
			if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
sl@0
   167
				remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
sl@0
   168
			else
sl@0
   169
				remainder = 0;
sl@0
   170
			miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
sl@0
   171
			do
sl@0
   172
				{
sl@0
   173
				if ( miniLength >= KReadBufferSize )
sl@0
   174
					{
sl@0
   175
					testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
sl@0
   176
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
sl@0
   177
					r = buf1.Compare( buf2 );
sl@0
   178
					test( r == 0 );
sl@0
   179
					buf1.Zero();
sl@0
   180
					buf2.Zero();
sl@0
   181
					myCounter++;
sl@0
   182
					miniLength -= KReadBufferSize;
sl@0
   183
					length -= KReadBufferSize;
sl@0
   184
					amountRead += KReadBufferSize;
sl@0
   185
					}
sl@0
   186
				else
sl@0
   187
					{
sl@0
   188
					testFile.Read(startPos + amountRead, buf1, miniLength);
sl@0
   189
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
sl@0
   190
					r = buf1.Compare( buf2 );
sl@0
   191
					test( r == 0 );
sl@0
   192
					amountRead += miniLength;
sl@0
   193
					length -= miniLength;
sl@0
   194
					miniLength = 0;
sl@0
   195
					}
sl@0
   196
				} while ( miniLength != 0 && length != 0);
sl@0
   197
			myBlockMapEntry++;
sl@0
   198
			}
sl@0
   199
		}
sl@0
   200
	map.Close();
sl@0
   201
sl@0
   202
	testFile.Close();
sl@0
   203
	r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   204
	test( r == KErrNone );
sl@0
   205
	r = fMan->Delete(name);
sl@0
   206
	test( r == KErrNone );
sl@0
   207
	delete fMan;
sl@0
   208
	return bmErr;
sl@0
   209
	}
sl@0
   210
sl@0
   211
LOCAL_C TInt TestBlockMapNandFAT(TInt64 aStartPos, TInt64 aEndPos)
sl@0
   212
//
sl@0
   213
// Test BlockMap retrieval on NAND FAT.
sl@0
   214
//
sl@0
   215
	{
sl@0
   216
	TInt localDriveNum = 0;
sl@0
   217
	RFile testFile;
sl@0
   218
	TInt r = testFile.Open( TheFs, KTestFileFAT, EFileRead );
sl@0
   219
	test( r == KErrNone );
sl@0
   220
	
sl@0
   221
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
   222
	SBlockMapInfo info;
sl@0
   223
	TInt counter = 0;
sl@0
   224
	TInt startPos = aStartPos;
sl@0
   225
	TInt bmErr;
sl@0
   226
sl@0
   227
	// Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
sl@0
   228
	do
sl@0
   229
		{
sl@0
   230
		bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug);
sl@0
   231
		if (bmErr != 0 && bmErr != KErrCompletion)
sl@0
   232
			{
sl@0
   233
			map.Close();
sl@0
   234
			testFile.Close();
sl@0
   235
			return bmErr;
sl@0
   236
			}
sl@0
   237
		map.Append(info); 
sl@0
   238
		if (counter++ == 0)
sl@0
   239
			localDriveNum = info.iLocalDriveNumber;
sl@0
   240
		} while ( bmErr == 0 && bmErr != KErrCompletion );
sl@0
   241
	test( bmErr == KErrCompletion );
sl@0
   242
	TInt granularity;
sl@0
   243
sl@0
   244
	TInt size;
sl@0
   245
	r = testFile.Size(size);
sl@0
   246
	test( r == KErrNone );
sl@0
   247
sl@0
   248
	TBuf8<KReadBufferSize> buf1;
sl@0
   249
	TBuf8<KReadBufferSize> buf2;
sl@0
   250
	
sl@0
   251
	TBool changed;	
sl@0
   252
	TBusLocalDrive localDrive;
sl@0
   253
sl@0
   254
	TBlockMapEntry* myBlockMapEntry;
sl@0
   255
	TInt myCounter = 0;
sl@0
   256
	TInt totalSegments = 0;
sl@0
   257
	TInt remainder = 0;
sl@0
   258
	TInt miniLength = 0;
sl@0
   259
	TInt amountRead = 0;
sl@0
   260
sl@0
   261
	TInt c;
sl@0
   262
	for ( c = 0; c < map.Count(); c++ )
sl@0
   263
		{
sl@0
   264
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   265
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   266
		totalSegments += granularity;
sl@0
   267
		}
sl@0
   268
sl@0
   269
	const TInt KTotalSegments = totalSegments;
sl@0
   270
	r = localDrive.Connect( localDriveNum, changed );
sl@0
   271
	test( r == KErrNone );
sl@0
   272
sl@0
   273
//	For each SBlockMapInfo object in RArray map
sl@0
   274
	for ( c = 0; c < map.Count(); c++ )
sl@0
   275
		{
sl@0
   276
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   277
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   278
sl@0
   279
		TInt length;
sl@0
   280
		if ( aEndPos == -1 )
sl@0
   281
			{
sl@0
   282
			length = size - startPos;
sl@0
   283
			aEndPos = size;
sl@0
   284
			}
sl@0
   285
		else
sl@0
   286
			length = aEndPos - startPos;
sl@0
   287
sl@0
   288
		for ( TInt c2 = 1; c2 <= granularity; c2++)
sl@0
   289
			{
sl@0
   290
			myCounter = 0;
sl@0
   291
			if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
sl@0
   292
				remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
sl@0
   293
			else
sl@0
   294
				remainder = 0;
sl@0
   295
			miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
sl@0
   296
			do
sl@0
   297
				{
sl@0
   298
				if ( miniLength >= KReadBufferSize )
sl@0
   299
					{
sl@0
   300
					testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
sl@0
   301
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
sl@0
   302
					r = buf1.Compare( buf2 );
sl@0
   303
					test( r == 0 );
sl@0
   304
					buf1.Zero();
sl@0
   305
					buf2.Zero();
sl@0
   306
					myCounter++;
sl@0
   307
					miniLength -= KReadBufferSize;
sl@0
   308
					length -= KReadBufferSize;
sl@0
   309
					amountRead += KReadBufferSize;
sl@0
   310
					}
sl@0
   311
				else
sl@0
   312
					{
sl@0
   313
					testFile.Read(startPos + amountRead, buf1, miniLength);
sl@0
   314
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
sl@0
   315
					r = buf1.Compare( buf2 );
sl@0
   316
					test( r == 0 );
sl@0
   317
					amountRead += miniLength;
sl@0
   318
					length -= miniLength;
sl@0
   319
					miniLength = 0;
sl@0
   320
					}
sl@0
   321
				} while ( miniLength != 0 && length != 0);
sl@0
   322
			myBlockMapEntry++;
sl@0
   323
			}
sl@0
   324
		}
sl@0
   325
	map.Close();
sl@0
   326
	testFile.Close();
sl@0
   327
	return bmErr;
sl@0
   328
	}
sl@0
   329
sl@0
   330
LOCAL_C TInt TestBlockMapNandROFS(TInt64 aStartPos, TInt64 aEndPos)
sl@0
   331
//
sl@0
   332
// Test BlockMap retrieval on NAND ROFS.
sl@0
   333
//
sl@0
   334
	{
sl@0
   335
	TInt localDriveNum = 0;
sl@0
   336
	RFile testFile;
sl@0
   337
	TInt r = testFile.Open( TheFs, KTestFile, EFileRead );
sl@0
   338
	test( r == KErrNone );
sl@0
   339
	
sl@0
   340
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
   341
	SBlockMapInfo info;
sl@0
   342
	TInt counter = 0;
sl@0
   343
	TInt startPos = aStartPos;
sl@0
   344
	TInt bmErr;
sl@0
   345
sl@0
   346
	// Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
sl@0
   347
	do
sl@0
   348
		{
sl@0
   349
		bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug);
sl@0
   350
		if (bmErr != 0 && bmErr != KErrCompletion)
sl@0
   351
			{
sl@0
   352
			map.Close();
sl@0
   353
			testFile.Close();
sl@0
   354
			return bmErr;
sl@0
   355
			}
sl@0
   356
		map.Append(info); 
sl@0
   357
		if (counter++ == 0)
sl@0
   358
			localDriveNum = info.iLocalDriveNumber;
sl@0
   359
		} while ( bmErr == 0 && bmErr != KErrCompletion );
sl@0
   360
	test( bmErr == KErrCompletion );
sl@0
   361
	TInt granularity;
sl@0
   362
sl@0
   363
	TInt size;
sl@0
   364
	r = testFile.Size(size);
sl@0
   365
	test( r == KErrNone );
sl@0
   366
sl@0
   367
	TBuf8<KReadBufferSize> buf1;
sl@0
   368
	TBuf8<KReadBufferSize> buf2;
sl@0
   369
	
sl@0
   370
	TBool changed;	
sl@0
   371
	TBusLocalDrive localDrive;
sl@0
   372
sl@0
   373
	TBlockMapEntry* myBlockMapEntry;
sl@0
   374
	TInt myCounter = 0;
sl@0
   375
	TInt totalSegments = 0;
sl@0
   376
	TInt miniLength = 0;
sl@0
   377
	TInt amountRead = 0;
sl@0
   378
sl@0
   379
	TInt c;
sl@0
   380
	for ( c = 0; c < map.Count(); c++ )
sl@0
   381
		{
sl@0
   382
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   383
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   384
		totalSegments += granularity;
sl@0
   385
		}
sl@0
   386
	r = localDrive.Connect( localDriveNum, changed );
sl@0
   387
	test( r == KErrNone );
sl@0
   388
sl@0
   389
//	For each SBlockMapInfo object in RArray map
sl@0
   390
	for ( c = 0; c < map.Count(); c++ )
sl@0
   391
		{
sl@0
   392
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   393
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   394
sl@0
   395
		TInt length;
sl@0
   396
		if ( aEndPos == -1 )
sl@0
   397
			{
sl@0
   398
			length = size - startPos;
sl@0
   399
			aEndPos = size;
sl@0
   400
			}
sl@0
   401
		else
sl@0
   402
			length = aEndPos - startPos;
sl@0
   403
		
sl@0
   404
		for ( TInt c2 = 1; c2 <= granularity; c2++)
sl@0
   405
			{
sl@0
   406
			myCounter = 0;
sl@0
   407
			miniLength = length;
sl@0
   408
			do
sl@0
   409
				{
sl@0
   410
				if ( miniLength >= KReadBufferSize )
sl@0
   411
					{
sl@0
   412
					testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
sl@0
   413
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
sl@0
   414
					r = buf1.Compare( buf2 );
sl@0
   415
					test( r == 0 );
sl@0
   416
					buf1.Zero();
sl@0
   417
					buf2.Zero();
sl@0
   418
					myCounter++;
sl@0
   419
					miniLength -= KReadBufferSize;
sl@0
   420
					length -= KReadBufferSize;
sl@0
   421
					amountRead += KReadBufferSize;
sl@0
   422
					}
sl@0
   423
				else
sl@0
   424
					{
sl@0
   425
					testFile.Read(startPos + amountRead, buf1, miniLength);
sl@0
   426
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
sl@0
   427
					r = buf1.Compare( buf2 );
sl@0
   428
					test( r == 0 );
sl@0
   429
					amountRead += miniLength;
sl@0
   430
					length -= miniLength;
sl@0
   431
					miniLength = 0;
sl@0
   432
					}
sl@0
   433
				} while ( miniLength != 0 && length != 0);
sl@0
   434
			myBlockMapEntry++;
sl@0
   435
			}
sl@0
   436
		}
sl@0
   437
	map.Close();
sl@0
   438
sl@0
   439
	testFile.Close();
sl@0
   440
	return bmErr;
sl@0
   441
	}
sl@0
   442
sl@0
   443
LOCAL_C TInt TestBlockMapRamFAT(TInt64 aStartPos, TInt64 aEndPos)
sl@0
   444
//
sl@0
   445
// Test BlockMap retrieval on RAM FAT.
sl@0
   446
//
sl@0
   447
	{
sl@0
   448
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
   449
	test(fMan!=NULL);
sl@0
   450
	TFileName name(KDriveBase);
sl@0
   451
	name[0] = TText('A' + RamFatDrive);
sl@0
   452
	name.Append( KTestFileName );
sl@0
   453
sl@0
   454
	TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   455
	r = fMan->Delete(name);
sl@0
   456
sl@0
   457
	r = fMan->Copy(KTestFile, name);
sl@0
   458
	test( r == KErrNone  || r == KErrAlreadyExists);
sl@0
   459
sl@0
   460
	TInt localDriveNum = 0;
sl@0
   461
	RFile testFile;
sl@0
   462
	r = testFile.Open( TheFs, name, EFileRead );
sl@0
   463
	test( r == KErrNone );
sl@0
   464
	
sl@0
   465
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
   466
	SBlockMapInfo info;
sl@0
   467
	TInt counter = 0;
sl@0
   468
	TInt startPos = aStartPos;
sl@0
   469
	TInt bmErr;
sl@0
   470
sl@0
   471
	// Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
sl@0
   472
	do
sl@0
   473
		{
sl@0
   474
		bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
sl@0
   475
		if (bmErr != 0 && bmErr != KErrCompletion)
sl@0
   476
			{
sl@0
   477
			map.Close();
sl@0
   478
			testFile.Close();
sl@0
   479
			r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   480
			test( r == KErrNone );
sl@0
   481
			r = fMan->Delete(name);
sl@0
   482
			test( r == KErrNone );
sl@0
   483
			delete fMan;
sl@0
   484
			return bmErr;
sl@0
   485
			}
sl@0
   486
		map.Append(info); 
sl@0
   487
		if (counter++ == 0)
sl@0
   488
			localDriveNum = info.iLocalDriveNumber;
sl@0
   489
		} while ( bmErr == 0 && bmErr != KErrCompletion );
sl@0
   490
	test( bmErr == KErrCompletion );
sl@0
   491
	TInt granularity;
sl@0
   492
sl@0
   493
	TInt size;
sl@0
   494
	r = testFile.Size(size);
sl@0
   495
	test( r == KErrNone );
sl@0
   496
sl@0
   497
	TBuf8<KReadBufferSize> buf1;
sl@0
   498
	TBuf8<KReadBufferSize> buf2;
sl@0
   499
	
sl@0
   500
	TBool changed;	
sl@0
   501
	TBusLocalDrive localDrive;
sl@0
   502
sl@0
   503
	UserSvr::UnlockRamDrive();
sl@0
   504
sl@0
   505
	TBlockMapEntry* myBlockMapEntry;
sl@0
   506
	TInt myCounter = 0;
sl@0
   507
	TInt totalSegments = 0;
sl@0
   508
	TInt remainder = 0;
sl@0
   509
	TInt miniLength = 0;
sl@0
   510
	TInt amountRead = 0;
sl@0
   511
sl@0
   512
	TInt c;
sl@0
   513
	for ( c = 0; c < map.Count(); c++ )
sl@0
   514
		{
sl@0
   515
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   516
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   517
		totalSegments += granularity;
sl@0
   518
		}
sl@0
   519
sl@0
   520
	const TInt KTotalSegments = totalSegments;
sl@0
   521
sl@0
   522
	r = localDrive.Connect( localDriveNum, changed );
sl@0
   523
	test( r == KErrNone );
sl@0
   524
sl@0
   525
//	For each SBlockMapInfo object in RArray map
sl@0
   526
	for ( c = 0; c < map.Count(); c++ )
sl@0
   527
		{
sl@0
   528
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   529
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   530
sl@0
   531
		TInt length;
sl@0
   532
		if ( aEndPos == -1 )
sl@0
   533
			{
sl@0
   534
			length = size - startPos;
sl@0
   535
			aEndPos = size;
sl@0
   536
			}
sl@0
   537
		else
sl@0
   538
			length = aEndPos - startPos;
sl@0
   539
	
sl@0
   540
		for ( TInt c2 = 1; c2 <= granularity; c2++)
sl@0
   541
			{
sl@0
   542
			myCounter = 0;
sl@0
   543
			if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
sl@0
   544
				remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
sl@0
   545
			else
sl@0
   546
				remainder = 0;
sl@0
   547
			miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
sl@0
   548
			do
sl@0
   549
				{
sl@0
   550
				if ( miniLength >= KReadBufferSize )
sl@0
   551
					{
sl@0
   552
					testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
sl@0
   553
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
sl@0
   554
					r = buf1.Compare( buf2 );
sl@0
   555
					test( r == 0 );
sl@0
   556
					buf1.Zero();
sl@0
   557
					buf2.Zero();
sl@0
   558
					myCounter++;
sl@0
   559
					miniLength -= KReadBufferSize;
sl@0
   560
					length -= KReadBufferSize;
sl@0
   561
					amountRead += KReadBufferSize;
sl@0
   562
					}
sl@0
   563
				else
sl@0
   564
					{
sl@0
   565
					testFile.Read(startPos + amountRead, buf1, miniLength);
sl@0
   566
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
sl@0
   567
					r = buf1.Compare( buf2 );
sl@0
   568
					test( r == 0 );
sl@0
   569
					amountRead += miniLength;
sl@0
   570
					length -= miniLength;
sl@0
   571
					miniLength = 0;
sl@0
   572
					}
sl@0
   573
				} while ( miniLength != 0 && length != 0);
sl@0
   574
			myBlockMapEntry++;
sl@0
   575
			}
sl@0
   576
		}
sl@0
   577
	map.Close();
sl@0
   578
sl@0
   579
	testFile.Close();
sl@0
   580
	r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   581
	test( r == KErrNone );
sl@0
   582
	r = fMan->Delete(name);
sl@0
   583
	test( r == KErrNone );
sl@0
   584
	delete fMan;
sl@0
   585
	return bmErr;
sl@0
   586
	}
sl@0
   587
sl@0
   588
LOCAL_C TInt TestBlockMapRamFAT2(TInt64 aStartPos, TInt64 aEndPos)
sl@0
   589
//
sl@0
   590
// Test BlockMap retrieval on Ram FAT.
sl@0
   591
//
sl@0
   592
	{
sl@0
   593
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
   594
	test(fMan!=NULL);
sl@0
   595
	TFileName name(KDriveBase);
sl@0
   596
	name[0] = TText('A' + RamFatDrive);
sl@0
   597
	name.Append( KTestFileName );
sl@0
   598
sl@0
   599
	TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   600
	r = fMan->Delete(name);
sl@0
   601
sl@0
   602
	r = fMan->Copy(KTestFile, name);
sl@0
   603
	test( r == KErrNone  || r == KErrAlreadyExists);
sl@0
   604
sl@0
   605
	RFile testFile;
sl@0
   606
	r = testFile.Open( TheFs, name, EFileRead );
sl@0
   607
	test( r == KErrNone );
sl@0
   608
	
sl@0
   609
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
   610
	SBlockMapInfo info;
sl@0
   611
sl@0
   612
	TInt bmErr;
sl@0
   613
	bmErr = testFile.BlockMap(info, aStartPos, aEndPos, EBlockMapUsagePaging);
sl@0
   614
sl@0
   615
	map.Close();
sl@0
   616
sl@0
   617
	testFile.Close();
sl@0
   618
	r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   619
	test( r == KErrNone );
sl@0
   620
	r = fMan->Delete(name);
sl@0
   621
	test( r == KErrNone );
sl@0
   622
	delete fMan;
sl@0
   623
	return bmErr;
sl@0
   624
	}
sl@0
   625
sl@0
   626
LOCAL_C TInt TestBlockMapRemovableFAT(TInt64 aStartPos, TInt64 aEndPos)
sl@0
   627
//
sl@0
   628
// Test BlockMap retrieval on Removable FAT.
sl@0
   629
//
sl@0
   630
	{
sl@0
   631
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
   632
	test(fMan!=NULL);
sl@0
   633
	TFileName name(KDriveBase);
sl@0
   634
	name[0] = TText('A' + RemovableFatDrive);
sl@0
   635
	name.Append( KTestFileName );
sl@0
   636
sl@0
   637
	TInt r=fMan->Copy(KTestFile, name);
sl@0
   638
	test( r == KErrNone  || r == KErrAlreadyExists);
sl@0
   639
sl@0
   640
	RFile testFile;
sl@0
   641
	r = testFile.Open( TheFs, name, EFileRead );
sl@0
   642
	test( r == KErrNone );
sl@0
   643
	
sl@0
   644
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
   645
	SBlockMapInfo info;
sl@0
   646
	TInt bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug);
sl@0
   647
	map.Close();
sl@0
   648
sl@0
   649
	testFile.Close();
sl@0
   650
	r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   651
	test( r == KErrNone );
sl@0
   652
	r = fMan->Delete(name);
sl@0
   653
	test( r == KErrNone );
sl@0
   654
	delete fMan;
sl@0
   655
	return bmErr;
sl@0
   656
	}
sl@0
   657
sl@0
   658
LOCAL_C TInt TestBlockMapInternalRemovableFAT(TInt64 aStartPos, TInt64 aEndPos)
sl@0
   659
//
sl@0
   660
// Test BlockMap retrieval on internal removable FAT.
sl@0
   661
//
sl@0
   662
	{
sl@0
   663
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
   664
	test(fMan!=NULL);
sl@0
   665
	TFileName name(KDriveBase);
sl@0
   666
	name[0] = TText('A' + RamFatDrive);
sl@0
   667
	name.Append( KTestFileName );
sl@0
   668
sl@0
   669
	TInt r=fMan->Copy(KTestFile, name);
sl@0
   670
	test( r == KErrNone  || r == KErrAlreadyExists);
sl@0
   671
sl@0
   672
	TInt localDriveNum = 0;
sl@0
   673
	RFile testFile;
sl@0
   674
	r = testFile.Open( TheFs, name, EFileRead );
sl@0
   675
	test( r == KErrNone );
sl@0
   676
	
sl@0
   677
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
   678
	SBlockMapInfo info;
sl@0
   679
	TInt counter = 0;
sl@0
   680
	TInt startPos = aStartPos;
sl@0
   681
	TInt bmErr;
sl@0
   682
sl@0
   683
	// Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
sl@0
   684
	do
sl@0
   685
		{
sl@0
   686
		bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
sl@0
   687
		if (bmErr != 0 && bmErr != KErrCompletion)
sl@0
   688
			{
sl@0
   689
			map.Close();
sl@0
   690
			testFile.Close();
sl@0
   691
			r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   692
			test( r == KErrNone );
sl@0
   693
			r = fMan->Delete(name);
sl@0
   694
			test( r == KErrNone );
sl@0
   695
			delete fMan;
sl@0
   696
			return bmErr;
sl@0
   697
			}
sl@0
   698
		map.Append(info); 
sl@0
   699
		if (counter++ == 0)
sl@0
   700
			localDriveNum = info.iLocalDriveNumber;
sl@0
   701
		} while ( bmErr == 0 && bmErr != KErrCompletion );
sl@0
   702
	test( bmErr == KErrCompletion );
sl@0
   703
	TInt granularity;
sl@0
   704
sl@0
   705
	TInt size;
sl@0
   706
	r = testFile.Size(size);
sl@0
   707
	test( r == KErrNone );
sl@0
   708
sl@0
   709
	TBuf8<KReadBufferSize> buf1;
sl@0
   710
	TBuf8<KReadBufferSize> buf2;
sl@0
   711
	
sl@0
   712
	TBool changed;	
sl@0
   713
	TBusLocalDrive localDrive;
sl@0
   714
sl@0
   715
	UserSvr::UnlockRamDrive();
sl@0
   716
sl@0
   717
	TBlockMapEntry* myBlockMapEntry;
sl@0
   718
	TInt myCounter = 0;
sl@0
   719
	TInt totalSegments = 0;
sl@0
   720
	TInt remainder = 0;
sl@0
   721
	TInt miniLength = 0;
sl@0
   722
	TInt amountRead = 0;
sl@0
   723
sl@0
   724
	TInt c;
sl@0
   725
	for ( c = 0; c < map.Count(); c++ )
sl@0
   726
		{
sl@0
   727
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   728
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   729
		totalSegments += granularity;
sl@0
   730
		}
sl@0
   731
sl@0
   732
	const TInt KTotalSegments = totalSegments;
sl@0
   733
sl@0
   734
	r = localDrive.Connect( localDriveNum, changed );
sl@0
   735
	test( r == KErrNone );
sl@0
   736
sl@0
   737
//	For each SBlockMapInfo object in RArray map
sl@0
   738
	for ( c = 0; c < map.Count(); c++ )
sl@0
   739
		{
sl@0
   740
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   741
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   742
sl@0
   743
		TInt length;
sl@0
   744
		if ( aEndPos == -1 )
sl@0
   745
			{
sl@0
   746
			length = size - startPos;
sl@0
   747
			aEndPos = size;
sl@0
   748
			}
sl@0
   749
		else
sl@0
   750
			length = aEndPos - startPos;
sl@0
   751
		
sl@0
   752
		for ( TInt c2 = 1; c2 <= granularity; c2++)
sl@0
   753
			{
sl@0
   754
			myCounter = 0;
sl@0
   755
			if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
sl@0
   756
				remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
sl@0
   757
			else
sl@0
   758
				remainder = 0;
sl@0
   759
			miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
sl@0
   760
			do
sl@0
   761
				{
sl@0
   762
				if ( miniLength >= KReadBufferSize )
sl@0
   763
					{
sl@0
   764
					testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
sl@0
   765
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
sl@0
   766
					r = buf1.Compare( buf2 );
sl@0
   767
					test( r == 0 );
sl@0
   768
					buf1.Zero();
sl@0
   769
					buf2.Zero();
sl@0
   770
					myCounter++;
sl@0
   771
					miniLength -= KReadBufferSize;
sl@0
   772
					length -= KReadBufferSize;
sl@0
   773
					amountRead += KReadBufferSize;
sl@0
   774
					}
sl@0
   775
				else
sl@0
   776
					{
sl@0
   777
					testFile.Read(startPos + amountRead, buf1, miniLength);
sl@0
   778
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
sl@0
   779
					r = buf1.Compare( buf2 );
sl@0
   780
					test( r == 0 );
sl@0
   781
					amountRead += miniLength;
sl@0
   782
					length -= miniLength;
sl@0
   783
					miniLength = 0;
sl@0
   784
					}
sl@0
   785
				} while ( miniLength != 0 && length != 0);
sl@0
   786
			myBlockMapEntry++;
sl@0
   787
			}
sl@0
   788
		}
sl@0
   789
	map.Close();
sl@0
   790
sl@0
   791
	testFile.Close();
sl@0
   792
	r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   793
	test( r == KErrNone );
sl@0
   794
	r = fMan->Delete(name);
sl@0
   795
	test( r == KErrNone );
sl@0
   796
	delete fMan;
sl@0
   797
	return bmErr;
sl@0
   798
	}
sl@0
   799
sl@0
   800
LOCAL_C TInt TestBlockMapFragmented(DriveType aDriveType, TInt64 aStartPos, TInt64 aEndPos)
sl@0
   801
	{
sl@0
   802
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
   803
	test(fMan!=NULL);
sl@0
   804
	TFileName name(KDriveBase);
sl@0
   805
	if (aDriveType==EDriveRam)
sl@0
   806
		name[0] = TText('A' + RamFatDrive);
sl@0
   807
	else if (aDriveType==EDriveRemovable)
sl@0
   808
		name[0] = TText('A' + RemovableFatDrive);
sl@0
   809
	else if (aDriveType==EDriveNand)
sl@0
   810
		name[0] = TText('A' + NandDrive);
sl@0
   811
	else 
sl@0
   812
		name[0] = TText('A' + InternalRemovableFatDrive);
sl@0
   813
	name.Append( KFragmentedFileName1 );
sl@0
   814
	TInt localDriveNum = 0;
sl@0
   815
	RFile testFile;
sl@0
   816
	TInt r = testFile.Open( TheFs, name, EFileRead );
sl@0
   817
	test( r == KErrNone );
sl@0
   818
	RArray<SBlockMapInfo> map;	// From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
sl@0
   819
	SBlockMapInfo info;
sl@0
   820
	TInt counter = 0;
sl@0
   821
	TInt startPos = aStartPos;
sl@0
   822
	TInt bmErr;
sl@0
   823
sl@0
   824
	// Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
sl@0
   825
	do
sl@0
   826
		{
sl@0
   827
		bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
sl@0
   828
		if (bmErr != 0 && bmErr != KErrCompletion)
sl@0
   829
			{
sl@0
   830
			map.Close();
sl@0
   831
			testFile.Close();
sl@0
   832
			if ( Finished )
sl@0
   833
				{
sl@0
   834
				r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   835
				test( r == KErrNone );
sl@0
   836
				r = fMan->Delete(name);
sl@0
   837
				test( r == KErrNone );
sl@0
   838
				}
sl@0
   839
			delete fMan;
sl@0
   840
			return bmErr;
sl@0
   841
			}
sl@0
   842
		map.Append(info); 
sl@0
   843
		if (counter++ == 0)
sl@0
   844
			localDriveNum = info.iLocalDriveNumber;
sl@0
   845
		} while ( bmErr == 0 && bmErr != KErrCompletion );
sl@0
   846
	test( bmErr == KErrCompletion );
sl@0
   847
	TInt granularity;
sl@0
   848
	TInt size;
sl@0
   849
	r = testFile.Size(size);
sl@0
   850
	test( r == KErrNone );
sl@0
   851
sl@0
   852
	TBuf8<KReadBufferSize> buf1;
sl@0
   853
	TBuf8<KReadBufferSize> buf2;
sl@0
   854
	
sl@0
   855
	TBool changed;	
sl@0
   856
	TBusLocalDrive localDrive;
sl@0
   857
sl@0
   858
	UserSvr::UnlockRamDrive();
sl@0
   859
sl@0
   860
	TBlockMapEntry* myBlockMapEntry;
sl@0
   861
	TInt myCounter = 0;
sl@0
   862
	TInt totalSegments = 0;
sl@0
   863
	TInt remainder = 0;
sl@0
   864
	TInt miniLength = 0;
sl@0
   865
	TInt amountRead = 0;
sl@0
   866
sl@0
   867
	TInt c;
sl@0
   868
	for ( c = 0; c < map.Count(); c++ )
sl@0
   869
		{
sl@0
   870
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   871
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   872
		totalSegments += granularity;
sl@0
   873
		}
sl@0
   874
sl@0
   875
	const TInt KTotalSegments = totalSegments;
sl@0
   876
	r = localDrive.Connect( localDriveNum, changed );
sl@0
   877
	test( r == KErrNone );
sl@0
   878
sl@0
   879
//	For each SBlockMapInfo object in RArray map
sl@0
   880
	for ( c = 0; c < map.Count(); c++ )
sl@0
   881
		{
sl@0
   882
		myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
sl@0
   883
		granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
sl@0
   884
sl@0
   885
		TInt length;
sl@0
   886
		if ( aEndPos == -1 )
sl@0
   887
			{
sl@0
   888
			length = size - startPos;
sl@0
   889
			aEndPos = size;
sl@0
   890
			}
sl@0
   891
		else
sl@0
   892
			length = aEndPos - startPos;
sl@0
   893
		
sl@0
   894
		for ( TInt c2 = 1; c2 <= granularity; c2++)
sl@0
   895
			{
sl@0
   896
			myCounter = 0;
sl@0
   897
			if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
sl@0
   898
				remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
sl@0
   899
			else
sl@0
   900
				remainder = 0;
sl@0
   901
			miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
sl@0
   902
			do
sl@0
   903
				{
sl@0
   904
				if ( miniLength >= KReadBufferSize )
sl@0
   905
					{
sl@0
   906
					testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
sl@0
   907
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
sl@0
   908
					r = buf1.Compare( buf2 );
sl@0
   909
					test( r == 0 );
sl@0
   910
					buf1.Zero();
sl@0
   911
					buf2.Zero();
sl@0
   912
					myCounter++;
sl@0
   913
					miniLength -= KReadBufferSize;
sl@0
   914
					length -= KReadBufferSize;
sl@0
   915
					amountRead += KReadBufferSize;
sl@0
   916
					}
sl@0
   917
				else
sl@0
   918
					{
sl@0
   919
					testFile.Read(startPos + amountRead, buf1, miniLength );
sl@0
   920
					localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
sl@0
   921
					r = buf1.Compare( buf2 );
sl@0
   922
					test( r == 0 );
sl@0
   923
					amountRead += miniLength;
sl@0
   924
					length -= miniLength;
sl@0
   925
					miniLength = 0;
sl@0
   926
					}
sl@0
   927
				} while ( miniLength != 0 && length != 0);
sl@0
   928
			myBlockMapEntry++;
sl@0
   929
			}
sl@0
   930
		}
sl@0
   931
	map.Close();
sl@0
   932
sl@0
   933
	testFile.Close();
sl@0
   934
	if ( Finished )
sl@0
   935
		{
sl@0
   936
		r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
sl@0
   937
		test( r == KErrNone );
sl@0
   938
		r = fMan->Delete(name);
sl@0
   939
		test( r == KErrNone );
sl@0
   940
		}
sl@0
   941
	delete fMan;
sl@0
   942
	return bmErr;	
sl@0
   943
	}
sl@0
   944
sl@0
   945
LOCAL_C void GenerateFragmentedFiles(DriveType aDriveType)
sl@0
   946
	{
sl@0
   947
	TInt r;
sl@0
   948
	TFileName name1(KDriveBase);
sl@0
   949
	if (aDriveType==EDriveRam)
sl@0
   950
		name1[0] = TText('A' + RamFatDrive);
sl@0
   951
	else if (aDriveType==EDriveRemovable)
sl@0
   952
		name1[0] = TText('A' + RemovableFatDrive);
sl@0
   953
	else if (aDriveType==EDriveNand)
sl@0
   954
		name1[0] = TText('A' + NandDrive);
sl@0
   955
	else 
sl@0
   956
		name1[0] = TText('A' + InternalRemovableFatDrive);
sl@0
   957
	name1.Append( KFragmentedFileName1 );
sl@0
   958
	RFile file1;
sl@0
   959
	r = file1.Create(TheFs, name1, EFileWrite);
sl@0
   960
	test( r == KErrNone );
sl@0
   961
	file1.Close();
sl@0
   962
sl@0
   963
	TFileName name2(KDriveBase);
sl@0
   964
	if (aDriveType==EDriveRam)
sl@0
   965
		name2[0] = TText('A' + RamFatDrive);
sl@0
   966
	else if (aDriveType==EDriveRemovable)
sl@0
   967
		name2[0] = TText('A' + RemovableFatDrive);
sl@0
   968
	else if (aDriveType==EDriveNand)
sl@0
   969
		name2[0] = TText('A' + NandDrive);
sl@0
   970
	else 
sl@0
   971
		name2[0] = TText('A' + InternalRemovableFatDrive);
sl@0
   972
	name2.Append( KFragmentedFileName2 );
sl@0
   973
	RFile file2;
sl@0
   974
	r = file2.Create(TheFs, name2, EFileWrite);
sl@0
   975
	test( r == KErrNone );
sl@0
   976
	file2.Close();
sl@0
   977
	TInt64 randomSeed;
sl@0
   978
	TBuf8<KMaxFragmentSize> tempBuf;	
sl@0
   979
	TUint8 *buf;
sl@0
   980
	TInt fileSize = 0;
sl@0
   981
	TInt fragmentSize;
sl@0
   982
	TInt randomLength;
sl@0
   983
	TInt pos1;
sl@0
   984
	TInt pos2;
sl@0
   985
	TInt mycount = 0;
sl@0
   986
	do	
sl@0
   987
		{
sl@0
   988
		fragmentSize = 0;
sl@0
   989
		pos1 = 0;
sl@0
   990
		pos2 = 0;
sl@0
   991
		buf = (TUint8*) tempBuf.Ptr();
sl@0
   992
		tempBuf.Zero();
sl@0
   993
		randomLength = Math::Random() % KMaxFragmentSize;
sl@0
   994
		randomSeed = Math::Random();
sl@0
   995
		tempBuf.SetLength(randomLength);
sl@0
   996
sl@0
   997
		while (randomLength-- && fragmentSize++ < KMaxFragmentSize && fileSize++ < KMaxFileSize)
sl@0
   998
			{
sl@0
   999
			*buf++ = (TUint8)('A' + (Math::Rand(randomSeed) % ('Z' - 'A')));
sl@0
  1000
			}
sl@0
  1001
		r = file1.Open( TheFs, name1, EFileWrite );
sl@0
  1002
		test( r == KErrNone );
sl@0
  1003
		r = file1.Seek( ESeekEnd, pos1 );
sl@0
  1004
		test( r == KErrNone );
sl@0
  1005
		r = file1.Write( pos1, tempBuf );
sl@0
  1006
		test( r == KErrNone );
sl@0
  1007
		r = file1.Flush();
sl@0
  1008
		test( r == KErrNone );		
sl@0
  1009
		file1.Close();
sl@0
  1010
		if ( mycount++ < 6 )
sl@0
  1011
			{
sl@0
  1012
			r = file2.Open( TheFs, name2, EFileWrite );
sl@0
  1013
			test( r == KErrNone );
sl@0
  1014
			r = file2.Seek( ESeekEnd, pos2 );
sl@0
  1015
			test( r == KErrNone );
sl@0
  1016
			r = file2.Write( pos2, tempBuf );
sl@0
  1017
			test( r == KErrNone );
sl@0
  1018
			r = file2.Flush();
sl@0
  1019
			test( r == KErrNone );
sl@0
  1020
			file2.Close();
sl@0
  1021
			}
sl@0
  1022
		} while ( fileSize < KMaxFileSize );
sl@0
  1023
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
  1024
	test(fMan!=NULL);
sl@0
  1025
	r = fMan->Delete(name2);
sl@0
  1026
	test( r == KErrNone );
sl@0
  1027
	delete fMan;
sl@0
  1028
	}
sl@0
  1029
sl@0
  1030
LOCAL_C void FindDrive(DriveType aDriveType)
sl@0
  1031
	{
sl@0
  1032
	TInt i;
sl@0
  1033
	TInt c = 0;
sl@0
  1034
	for( i = EDriveA; i < EDriveZ; i++ )
sl@0
  1035
		{
sl@0
  1036
		TDriveInfo info;
sl@0
  1037
		TInt r = TheFs.Drive(info, i);
sl@0
  1038
		if ( r != KErrNone )
sl@0
  1039
			continue;
sl@0
  1040
		test( r == KErrNone );
sl@0
  1041
		if ( aDriveType == EDriveNand )	
sl@0
  1042
			{
sl@0
  1043
			c++ == 0 ? test.Printf( _L("Searching for NAND drive.")) : test.Printf( _L("."));
sl@0
  1044
			if ( info.iType == EMediaNANDFlash && ((info.iMediaAtt & KMediaAttWriteProtected) == 0) )
sl@0
  1045
				{
sl@0
  1046
				if ( info.iDriveAtt & KDriveAttPageable )
sl@0
  1047
					Pageable = ETrue;
sl@0
  1048
				NandDrive = i;
sl@0
  1049
				test.Printf( _L("Found NAND drive: %d\n"), NandDrive );
sl@0
  1050
				break;
sl@0
  1051
				}
sl@0
  1052
			}
sl@0
  1053
		else if ( aDriveType == EDriveRam )
sl@0
  1054
			{
sl@0
  1055
			c++ == 0 ? test.Printf( _L("Searching for RAM FAT drive.")) : test.Printf( _L("."));
sl@0
  1056
			if ( (info.iType == EMediaRam) && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttInternal) ) && ( info.iMediaAtt == (KMediaAttVariableSize|KMediaAttFormattable) ) )
sl@0
  1057
				{
sl@0
  1058
				if ( info.iDriveAtt & KDriveAttPageable )
sl@0
  1059
					Pageable = ETrue;
sl@0
  1060
				RamFatDrive = i;
sl@0
  1061
				test.Printf( _L("Found RAM FAT drive: %d\n"), RamFatDrive );
sl@0
  1062
				break;
sl@0
  1063
				}
sl@0
  1064
			}
sl@0
  1065
		else if ( aDriveType == EDriveRemovable )
sl@0
  1066
			{
sl@0
  1067
			c++ == 0 ? test.Printf( _L("Searching for removable FAT drive.")) : test.Printf( _L("."));
sl@0
  1068
			if ( info.iType == EMediaHardDisk && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttRemovable) ) )
sl@0
  1069
				{
sl@0
  1070
				if ( info.iDriveAtt & KDriveAttPageable )
sl@0
  1071
					Pageable = ETrue;
sl@0
  1072
				RemovableFatDrive = i;
sl@0
  1073
				test.Printf( _L("Found removable FAT drive: %d\n"), RemovableFatDrive );
sl@0
  1074
				break;
sl@0
  1075
				}
sl@0
  1076
			}
sl@0
  1077
		else if ( aDriveType == EDriveInternalRemovable )
sl@0
  1078
			{
sl@0
  1079
			c++ == 0 ? test.Printf( _L("Searching for internal removable FAT drive.")) : test.Printf( _L("."));
sl@0
  1080
			if ( info.iType == EMediaHardDisk && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttInternal) ) )
sl@0
  1081
				{
sl@0
  1082
				if ( info.iDriveAtt & KDriveAttPageable )
sl@0
  1083
					Pageable = ETrue;
sl@0
  1084
				InternalRemovableFatDrive = i;
sl@0
  1085
				test.Printf( _L("Found internal removable FAT drive: %d\n"), InternalRemovableFatDrive );
sl@0
  1086
				break;
sl@0
  1087
				}
sl@0
  1088
			}
sl@0
  1089
		}
sl@0
  1090
		if ( i == EDriveZ )
sl@0
  1091
			{
sl@0
  1092
			switch(aDriveType)
sl@0
  1093
				{
sl@0
  1094
				case EDriveNand:
sl@0
  1095
					test.Printf( _L("NAND drive not found.\n") );
sl@0
  1096
					break;
sl@0
  1097
				case EDriveRam:
sl@0
  1098
					test.Printf( _L("RAM FAT drive not found.\n") );
sl@0
  1099
					break;
sl@0
  1100
				case EDriveRemovable:
sl@0
  1101
					test.Printf( _L("Removable FAT drive not found.\n") );
sl@0
  1102
					break;
sl@0
  1103
				case EDriveInternalRemovable:
sl@0
  1104
					test.Printf( _L("Internal removable FAT drive not found.\n") );
sl@0
  1105
					break;
sl@0
  1106
				default:
sl@0
  1107
					test.Printf( _L("Drive not found.\n") );
sl@0
  1108
				}			
sl@0
  1109
			}
sl@0
  1110
	}
sl@0
  1111
sl@0
  1112
//************************
sl@0
  1113
// Entry point
sl@0
  1114
sl@0
  1115
GLDEF_C void CallTestsL(void)
sl@0
  1116
	{
sl@0
  1117
	test.Title(); 
sl@0
  1118
	test.Start( _L("BlockMap Test\n") );
sl@0
  1119
sl@0
  1120
	TInt testFileSize = 0;
sl@0
  1121
	RFile testFile;
sl@0
  1122
	TInt r = testFile.Open(TheFs, KTestFile, EFileRead);
sl@0
  1123
	test(r==KErrNone);
sl@0
  1124
	r = testFile.Size(testFileSize);
sl@0
  1125
	test(r==KErrNone);
sl@0
  1126
	test(testFileSize>16384);
sl@0
  1127
	testFile.Close();
sl@0
  1128
sl@0
  1129
	if ( gDriveToTest == 'C' )
sl@0
  1130
		{
sl@0
  1131
		TInt value;
sl@0
  1132
		r = HAL::Get( HAL::EMachineUid, value );
sl@0
  1133
		test( r == KErrNone );
sl@0
  1134
		if ( value != HAL::EMachineUid_Lubbock )	// Lubbock cannot run FindDrive as it doesn't support the NAND API
sl@0
  1135
			{
sl@0
  1136
			test.Next(_L("Test BlockMap retrieval on NAND FAT."));
sl@0
  1137
			FindDrive(EDriveNand);
sl@0
  1138
			if ( NandDrive > -1 )	// not finding a NAND drive isn't an error as only NAND builds have one
sl@0
  1139
				{
sl@0
  1140
				r = TestBlockMapNandFATUserData(0, -1);
sl@0
  1141
				test( r == KErrCompletion );
sl@0
  1142
				r = TestBlockMapNandFATUserData(1024, 4096);
sl@0
  1143
				test( r == KErrCompletion );
sl@0
  1144
				r = TestBlockMapNandFATUserData(1020, 4100);
sl@0
  1145
				test( r == KErrCompletion );
sl@0
  1146
				r = TestBlockMapNandFATUserData(1024, 4100);
sl@0
  1147
				test( r == KErrCompletion );
sl@0
  1148
				r = TestBlockMapNandFATUserData(1020, 4096);
sl@0
  1149
				test( r == KErrCompletion );
sl@0
  1150
				r = TestBlockMapNandFATUserData(1025, 1200);
sl@0
  1151
				test( r == KErrCompletion );
sl@0
  1152
				r = TestBlockMapNandFATUserData(0, testFileSize+100);
sl@0
  1153
				test( r == KErrArgument );
sl@0
  1154
				r = TestBlockMapNandFATUserData(-5, -1);
sl@0
  1155
				test( r == KErrArgument );
sl@0
  1156
				r = TestBlockMapNandFATUserData(-5, testFileSize+100);
sl@0
  1157
				test( r == KErrArgument );
sl@0
  1158
				r = TestBlockMapNandFATUserData(0, 0);
sl@0
  1159
				test( r == KErrArgument );
sl@0
  1160
				r = TestBlockMapNandFATUserData(testFileSize, -1);
sl@0
  1161
				test( r == KErrArgument );
sl@0
  1162
				r = TestBlockMapNandFATUserData(0, -1);
sl@0
  1163
				test( r == KErrCompletion );
sl@0
  1164
				r = TestBlockMapNandFATUserData(2000, 2001);
sl@0
  1165
				test( r == KErrCompletion );
sl@0
  1166
				r = TestBlockMapNandFATUserData(0, 0);
sl@0
  1167
				test( r == KErrArgument );
sl@0
  1168
				r = TestBlockMapNandFATUserData(2000, 2000);
sl@0
  1169
				test( r == KErrArgument );
sl@0
  1170
				r = TestBlockMapNandFATUserData(2048, 2048);
sl@0
  1171
				test( r == KErrArgument );
sl@0
  1172
				test.Printf(_L("Generating Fragmented File..."));
sl@0
  1173
				GenerateFragmentedFiles(EDriveNand);
sl@0
  1174
				test.Printf(_L("Done!\n"));
sl@0
  1175
				test.Next(_L("Test BlockMap retrieval on NAND FAT (User area) (fragmented)."));	
sl@0
  1176
				r = TestBlockMapFragmented(EDriveNand, 0, -1);
sl@0
  1177
				test( r == KErrCompletion );
sl@0
  1178
				r = TestBlockMapFragmented(EDriveNand, 1024, 4096);
sl@0
  1179
				test( r == KErrCompletion );
sl@0
  1180
				r = TestBlockMapFragmented(EDriveNand, 1020, 4100);
sl@0
  1181
				test( r == KErrCompletion );
sl@0
  1182
				r = TestBlockMapFragmented(EDriveNand, 1024, 4100);
sl@0
  1183
				test( r == KErrCompletion );
sl@0
  1184
				r = TestBlockMapFragmented(EDriveNand, 1020, 4096);
sl@0
  1185
				test( r == KErrCompletion );
sl@0
  1186
				r = TestBlockMapFragmented(EDriveNand, 1025, 1200);
sl@0
  1187
				test( r == KErrCompletion );
sl@0
  1188
				r = TestBlockMapFragmented(EDriveNand, 0, testFileSize+100);
sl@0
  1189
				test( r == KErrArgument );
sl@0
  1190
				r = TestBlockMapFragmented(EDriveNand, -5, -1);
sl@0
  1191
				test( r == KErrArgument );
sl@0
  1192
				r = TestBlockMapFragmented(EDriveNand, -5, testFileSize+100);
sl@0
  1193
				test( r == KErrArgument );
sl@0
  1194
				r = TestBlockMapFragmented(EDriveNand, 0, 0);
sl@0
  1195
				test( r == KErrArgument );
sl@0
  1196
				r = TestBlockMapFragmented(EDriveNand, testFileSize, -1);
sl@0
  1197
				test( r == KErrArgument );
sl@0
  1198
				r = TestBlockMapFragmented(EDriveNand, 0, -1);
sl@0
  1199
				test( r == KErrCompletion );
sl@0
  1200
				r = TestBlockMapFragmented(EDriveNand, 2000, 2001);
sl@0
  1201
				test( r == KErrCompletion );
sl@0
  1202
				r = TestBlockMapFragmented(EDriveNand, 0, 0);
sl@0
  1203
				test( r == KErrArgument );
sl@0
  1204
				r = TestBlockMapFragmented(EDriveNand, 2000, 2000);
sl@0
  1205
				test( r == KErrArgument );
sl@0
  1206
				Finished = ETrue;
sl@0
  1207
				r = TestBlockMapFragmented(EDriveNand, 2048, 2048);
sl@0
  1208
				test( r == KErrArgument );
sl@0
  1209
				test.Next(_L("Test BlockMap retrieval on NAND FAT."));	
sl@0
  1210
				r = TestBlockMapNandFAT(0, -1);
sl@0
  1211
				test( r == KErrCompletion );
sl@0
  1212
				r = TestBlockMapNandFAT(1024, 4096);
sl@0
  1213
				test( r == KErrCompletion );
sl@0
  1214
				r = TestBlockMapNandFAT(1020, 4100);
sl@0
  1215
				test( r == KErrCompletion );
sl@0
  1216
				r = TestBlockMapNandFAT(1024, 4100);
sl@0
  1217
				test( r == KErrCompletion );
sl@0
  1218
				r = TestBlockMapNandFAT(1020, 4096);
sl@0
  1219
				test( r == KErrCompletion );
sl@0
  1220
				r = TestBlockMapNandFAT(1025, 1200);
sl@0
  1221
				test( r == KErrCompletion );
sl@0
  1222
				r = TestBlockMapNandFAT(0, testFileSize+100);
sl@0
  1223
				test( r == KErrArgument );
sl@0
  1224
				r = TestBlockMapNandFAT(-5, -1);
sl@0
  1225
				test( r == KErrArgument );
sl@0
  1226
				r = TestBlockMapNandFAT(-5, testFileSize+100);
sl@0
  1227
				test( r == KErrArgument );
sl@0
  1228
				r = TestBlockMapNandFAT(0, 0);
sl@0
  1229
				test( r == KErrArgument );
sl@0
  1230
				r = TestBlockMapNandFAT(testFileSize, -1);
sl@0
  1231
				test( r == KErrArgument );
sl@0
  1232
				r = TestBlockMapNandFAT(0, -1);
sl@0
  1233
				test( r == KErrCompletion );
sl@0
  1234
				r = TestBlockMapNandFAT(2000, 2001);
sl@0
  1235
				test( r == KErrCompletion );
sl@0
  1236
				r = TestBlockMapNandFAT(0, 0);
sl@0
  1237
				test( r == KErrArgument );
sl@0
  1238
				r = TestBlockMapNandFAT(2000, 2000);
sl@0
  1239
				test( r == KErrArgument );
sl@0
  1240
				r = TestBlockMapNandFAT(2048, 2048);
sl@0
  1241
				test( r == KErrArgument );
sl@0
  1242
				test.Next(_L("Test BlockMap retrieval on NAND ROFS."));
sl@0
  1243
				r = TestBlockMapNandROFS(0, -1);
sl@0
  1244
				test( r == KErrCompletion );
sl@0
  1245
				r = TestBlockMapNandROFS(1024, 4096);
sl@0
  1246
				test( r == KErrCompletion );
sl@0
  1247
				r = TestBlockMapNandROFS(1020, 4100);
sl@0
  1248
				test( r == KErrCompletion );
sl@0
  1249
				r = TestBlockMapNandROFS(1024, 4100);
sl@0
  1250
				test( r == KErrCompletion );
sl@0
  1251
				r = TestBlockMapNandROFS(1020, 4096);
sl@0
  1252
				test( r == KErrCompletion );
sl@0
  1253
				r = TestBlockMapNandROFS(1025, 1200);
sl@0
  1254
				test( r == KErrCompletion );
sl@0
  1255
				r = TestBlockMapNandROFS(0, testFileSize+100);
sl@0
  1256
				test( r == KErrArgument );
sl@0
  1257
				r = TestBlockMapNandROFS(-5, -1);
sl@0
  1258
				test( r == KErrArgument );
sl@0
  1259
				r = TestBlockMapNandROFS(-5, testFileSize+100);
sl@0
  1260
				test( r == KErrArgument );
sl@0
  1261
				r = TestBlockMapNandROFS(0, 0);
sl@0
  1262
				test( r == KErrArgument );
sl@0
  1263
				r = TestBlockMapNandROFS(testFileSize, -1);
sl@0
  1264
				test( r == KErrArgument );
sl@0
  1265
				r = TestBlockMapNandROFS(0, -1);
sl@0
  1266
				test( r == KErrCompletion );
sl@0
  1267
				r = TestBlockMapNandROFS(2000, 2001);
sl@0
  1268
				test( r == KErrCompletion );
sl@0
  1269
				r = TestBlockMapNandROFS(0, 0);
sl@0
  1270
				test( r == KErrArgument );
sl@0
  1271
				r = TestBlockMapNandROFS(2000, 2000);
sl@0
  1272
				test( r == KErrArgument );
sl@0
  1273
				r = TestBlockMapNandROFS(2048, 2048);
sl@0
  1274
				test( r == KErrArgument );
sl@0
  1275
				test.Next(_L("Test BlockMap retrieval on RAM FAT."));
sl@0
  1276
				FindDrive(EDriveRam);
sl@0
  1277
				test( RamFatDrive > -1 );
sl@0
  1278
				r = TestBlockMapRamFAT(0, -1);
sl@0
  1279
				test( r == KErrCompletion );
sl@0
  1280
				r = TestBlockMapRamFAT(1024, 4096);
sl@0
  1281
				test( r == KErrCompletion );
sl@0
  1282
				r = TestBlockMapRamFAT(1020, 4100);
sl@0
  1283
				test( r == KErrCompletion );
sl@0
  1284
				r = TestBlockMapRamFAT(1024, 4100);
sl@0
  1285
				test( r == KErrCompletion );
sl@0
  1286
				r = TestBlockMapRamFAT(1020, 4096);
sl@0
  1287
				test( r == KErrCompletion );
sl@0
  1288
				r = TestBlockMapRamFAT(1025, 1200);
sl@0
  1289
				test( r == KErrCompletion );
sl@0
  1290
				r = TestBlockMapRamFAT(0, testFileSize+100);
sl@0
  1291
				test( r == KErrArgument );
sl@0
  1292
				r = TestBlockMapRamFAT(-5, -1);
sl@0
  1293
				test( r == KErrArgument );
sl@0
  1294
				r = TestBlockMapRamFAT(-5, testFileSize+100);
sl@0
  1295
				test( r == KErrArgument );
sl@0
  1296
				r = TestBlockMapRamFAT(0, 0);
sl@0
  1297
				test( r == KErrArgument );
sl@0
  1298
				r = TestBlockMapRamFAT(testFileSize, -1);
sl@0
  1299
				test( r == KErrArgument );
sl@0
  1300
				r = TestBlockMapRamFAT(0, -1);
sl@0
  1301
				test( r == KErrCompletion );
sl@0
  1302
				r = TestBlockMapRamFAT(2000, 2001);
sl@0
  1303
				test( r == KErrCompletion );
sl@0
  1304
				r = TestBlockMapRamFAT(0, 0);
sl@0
  1305
				test( r == KErrArgument );
sl@0
  1306
				r = TestBlockMapRamFAT(2000, 2000);
sl@0
  1307
				test( r == KErrArgument );
sl@0
  1308
				r = TestBlockMapRamFAT(2048, 2048);
sl@0
  1309
				test( r == KErrArgument ); 
sl@0
  1310
				test.Next(_L("Test BlockMap retrieval on Ram FAT (2)."));
sl@0
  1311
				r = TestBlockMapRamFAT2(0, -1);
sl@0
  1312
				test( r == KErrNotSupported );
sl@0
  1313
				FindDrive(EDriveRemovable);
sl@0
  1314
				if ( RemovableFatDrive > -1)
sl@0
  1315
					{
sl@0
  1316
					test.Next(_L("Test BlockMap retrieval on removable FAT."));
sl@0
  1317
					r = TestBlockMapRemovableFAT(0, -1);
sl@0
  1318
					Pageable?test( r == KErrNotSupported ):test( r == KErrCompletion );
sl@0
  1319
					}
sl@0
  1320
				else
sl@0
  1321
					{
sl@0
  1322
					test.Next(_L("Test BlockMap retrieval on internal removable FAT."));
sl@0
  1323
					FindDrive(EDriveInternalRemovable);
sl@0
  1324
					test( InternalRemovableFatDrive > -1);
sl@0
  1325
					r = TestBlockMapInternalRemovableFAT(0, -1);
sl@0
  1326
					test( r == KErrCompletion );
sl@0
  1327
					r = TestBlockMapInternalRemovableFAT(1024, 4096);
sl@0
  1328
					test( r == KErrCompletion );
sl@0
  1329
					r = TestBlockMapInternalRemovableFAT(1020, 4100);
sl@0
  1330
					test( r == KErrCompletion );
sl@0
  1331
					r = TestBlockMapInternalRemovableFAT(1024, 4100);
sl@0
  1332
					test( r == KErrCompletion );
sl@0
  1333
					r = TestBlockMapInternalRemovableFAT(1020, 4096);
sl@0
  1334
					test( r == KErrCompletion );
sl@0
  1335
					r = TestBlockMapInternalRemovableFAT(1025, 1200);
sl@0
  1336
					test( r == KErrCompletion );
sl@0
  1337
					r = TestBlockMapInternalRemovableFAT(0, testFileSize+100);
sl@0
  1338
					test( r == KErrArgument );
sl@0
  1339
					r = TestBlockMapInternalRemovableFAT(-5, -1);
sl@0
  1340
					test( r == KErrArgument );
sl@0
  1341
					r = TestBlockMapInternalRemovableFAT(-5, testFileSize+100);
sl@0
  1342
					test( r == KErrArgument );
sl@0
  1343
					r = TestBlockMapInternalRemovableFAT(0, 0);
sl@0
  1344
					test( r == KErrArgument );
sl@0
  1345
					r = TestBlockMapInternalRemovableFAT(testFileSize, -1);
sl@0
  1346
					test( r == KErrArgument );
sl@0
  1347
					r = TestBlockMapInternalRemovableFAT(0, -1);
sl@0
  1348
					test( r == KErrCompletion );
sl@0
  1349
					r = TestBlockMapInternalRemovableFAT(2000, 2001);
sl@0
  1350
					test( r == KErrCompletion );
sl@0
  1351
					r = TestBlockMapInternalRemovableFAT(0, 0);
sl@0
  1352
					test( r == KErrArgument );
sl@0
  1353
					r = TestBlockMapInternalRemovableFAT(2000, 2000);
sl@0
  1354
					test( r == KErrArgument );
sl@0
  1355
					r = TestBlockMapInternalRemovableFAT(2048, 2048);
sl@0
  1356
					test( r == KErrArgument );
sl@0
  1357
					}
sl@0
  1358
				test.Next(_L("Test BlockMap retrieval on Ram FAT (fragmented)."));	
sl@0
  1359
				test.Printf(_L("Generating Fragmented File..."));
sl@0
  1360
				GenerateFragmentedFiles(EDriveRam);
sl@0
  1361
				test.Printf(_L("Done!\n"));
sl@0
  1362
				Finished = EFalse;
sl@0
  1363
				r = TestBlockMapFragmented(EDriveRam, 0, -1);
sl@0
  1364
				test( r == KErrCompletion );
sl@0
  1365
				r = TestBlockMapFragmented(EDriveRam, 1020, 4100);
sl@0
  1366
				test( r == KErrCompletion );
sl@0
  1367
				r = TestBlockMapFragmented(EDriveRam, 2049, 4096);
sl@0
  1368
				test( r == KErrCompletion );
sl@0
  1369
				r = TestBlockMapFragmented(EDriveRam, 1024, 4100);
sl@0
  1370
				test( r == KErrCompletion );
sl@0
  1371
				r = TestBlockMapFragmented(EDriveRam, 1020, 4096);
sl@0
  1372
				test( r == KErrCompletion );
sl@0
  1373
				r = TestBlockMapFragmented(EDriveRam, 1025, 1200);
sl@0
  1374
				test( r == KErrCompletion );
sl@0
  1375
				r = TestBlockMapFragmented(EDriveRam, 0, testFileSize+100);
sl@0
  1376
				test( r == KErrArgument );
sl@0
  1377
				r = TestBlockMapFragmented(EDriveRam, -5, -1);
sl@0
  1378
				test( r == KErrArgument );
sl@0
  1379
				r = TestBlockMapFragmented(EDriveRam, -5, testFileSize+100);
sl@0
  1380
				test( r == KErrArgument );
sl@0
  1381
				r = TestBlockMapFragmented(EDriveRam, 0, 0);
sl@0
  1382
				test( r == KErrArgument );
sl@0
  1383
				r = TestBlockMapFragmented(EDriveRam, testFileSize, -1);
sl@0
  1384
				test( r == KErrArgument );
sl@0
  1385
				r = TestBlockMapFragmented(EDriveRam, 0, -1);
sl@0
  1386
				test( r == KErrCompletion );
sl@0
  1387
				r = TestBlockMapFragmented(EDriveRam, 2000, 2001);
sl@0
  1388
				test( r == KErrCompletion );
sl@0
  1389
				r = TestBlockMapFragmented(EDriveRam, 0, 0);
sl@0
  1390
				test( r == KErrArgument );
sl@0
  1391
				r = TestBlockMapFragmented(EDriveRam, 2000, 2000);
sl@0
  1392
				test( r == KErrArgument );
sl@0
  1393
				Finished = ETrue;
sl@0
  1394
				r = TestBlockMapFragmented(EDriveRam, 2048, 2048);
sl@0
  1395
				test( r == KErrArgument );
sl@0
  1396
				}
sl@0
  1397
			else
sl@0
  1398
				{
sl@0
  1399
				test.Printf( _L("NAND drive not found, skipping test.\n") );
sl@0
  1400
				}
sl@0
  1401
			}
sl@0
  1402
		}
sl@0
  1403
	test.End();
sl@0
  1404
	test.Close();
sl@0
  1405
	}