os/kernelhwsrv/kerneltest/f32test/server/t_falsespace.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1997-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 //
    15 
    16 #include <f32file.h>
    17 #include <e32test.h>
    18 #include <e32svr.h>
    19 #include <e32math.h>
    20 
    21 #include "fat_utils.h"
    22 #include "t_server.h"
    23 #include "t_chlffs.h"
    24 
    25 using namespace Fat_Test_Utils;
    26 
    27 RTest test(_L("t_falsespace"));
    28 
    29 const TInt KNumberThreads=2;
    30 const TInt KHeapSize=0x2000;
    31 
    32 static TInt RsrvSpaceThread(TAny* aArg);
    33 static TInt SessCloseThread(TAny* aArg);
    34 static void GetFreeDiskSpace(TInt64 &aFree);
    35 
    36 
    37 TInt gCount;		//count of files used to fill up the disk
    38 TInt gTestDrive;	//drive number of the drive currently being tested
    39 
    40 TChar gCh;
    41 
    42 _LIT(KBasePath,"\\F32-TST\\FILLDIR\\");
    43 _LIT(KBaseName,"\\F32-TST\\FILLDIR\\FILE");
    44 
    45 _LIT(KTestFile,"?:\\test.txt");
    46 _LIT8(KTestData, "12345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678");
    47 _LIT(KDir, "?:\\adodgydir\\");
    48 _LIT(KDrv,"?:\\");	
    49 _LIT(KNewName,"?:\\newname.txt");
    50 
    51 
    52 void FormatDrive()
    53 {
    54     TInt nRes;
    55 
    56     
    57     #if 0
    58     //-- FAT32 SPC:1; for the FAT32 testing on the emulator 
    59     TFatFormatParam fp;
    60     fp.iFatType = EFat32;
    61     fp.iSecPerCluster = 1;
    62 
    63 	nRes = FormatFatDrive(TheFs, gTestDrive, ETrue, &fp);	
    64     #else
    65 
    66     nRes = FormatFatDrive(TheFs, gTestDrive, ETrue);	
    67 
    68     #endif
    69 
    70     test(nRes == KErrNone);
    71 }
    72 
    73 void SynchronousClose(RFs &aSession)
    74 	{
    75 	TRequestStatus s;
    76 	aSession.NotifyDestruction(s);
    77 	test(s.Int()==KRequestPending);
    78 	aSession.Close();
    79 	User::WaitForRequest(s);
    80 	}
    81 
    82 
    83 static TInt CreateFileX(const TDesC& aBaseName,TInt aX, TInt aFileSize)
    84 //
    85 // Create a large file. Return KErrEof or KErrNone
    86 //
    87 	{
    88 
    89 	TBuf<128> fileName=aBaseName;
    90 	fileName.AppendNum(aX);
    91 	RFile file;
    92 
    93 	TInt r=file.Replace(TheFs,fileName,EFileWrite);
    94 	if (r==KErrDiskFull)
    95 		return(r);
    96 	if (r!=KErrNone)
    97 		{
    98 		test.Printf(_L("ERROR:: Replace returned %d\n"),r);
    99 		test(0);
   100 		return(KErrDiskFull);
   101 		}
   102 
   103 	if (!IsTestingLFFS())
   104 		r=file.SetSize(aFileSize);
   105 	else
   106 		{
   107     	TBuf8<1024> testdata(1024);
   108     	TInt count=(aFileSize/testdata.Length());
   109     	r=KErrNone;
   110     	while (count-- && r==KErrNone) 
   111         	r=file.Write(testdata);
   112 		}
   113 	if (r==KErrDiskFull)
   114 		{
   115 		file.Close();
   116 		return(r);
   117 		}
   118 	if (r!=KErrNone)
   119 		{
   120 		test.Printf(_L("ERROR:: SetSize/Write returned %d\n"),r);
   121 		test(0);
   122 		//test.Getch();
   123 		file.Close();
   124 		return(KErrDiskFull);
   125 		}
   126 
   127 	file.Close();
   128 
   129 	test.Printf(_L("Created file %d size %d\n"),aX,aFileSize);
   130 	return(KErrNone);
   131 	}
   132 
   133 LOCAL_C TInt DeleteFileX(const TDesC& aBaseName,TInt aX)
   134 //
   135 // Delete a large file
   136 //
   137 	{
   138 	TBuf<128> fileName=aBaseName;
   139 	fileName.AppendNum(aX);
   140 	return TheFs.Delete(fileName);
   141 	}
   142 
   143 
   144 static void FillUpDisk()
   145 //
   146 // Test that a full disk is ok
   147 //
   148 	{
   149 
   150 	test.Start(_L("Fill disk to capacity"));
   151 	TInt r=TheFs.MkDirAll(KBasePath);
   152 	test(r==KErrNone || r==KErrAlreadyExists);
   153 	gCount=0;
   154 	TFileName sessionPath;
   155 	r=TheFs.SessionPath(sessionPath);
   156 	test(r==KErrNone);
   157 	TBuf<128> fileName=KBaseName();
   158 	
   159 	TInt64 freespace=0;
   160 	TInt64 freespaceBeforeScanDrive = 0;
   161 	TInt64 freespaceAfterScanDrive = 0;
   162 	
   163 	do
   164 		{
   165 		GetFreeDiskSpace(freespace);
   166 		TInt fillfilesize=0;
   167 		if (I64HIGH(freespace))
   168 			fillfilesize=KMaxTInt;
   169 		else
   170 			fillfilesize=I64LOW(freespace)* 7/8;
   171 
   172 		FOREVER
   173 			{
   174 			TInt r=CreateFileX(fileName,gCount,fillfilesize);
   175 			if (r==KErrDiskFull)
   176 				{
   177 				if(fillfilesize <= 2)
   178 					break;
   179 				else
   180 					fillfilesize=fillfilesize/2;
   181 				}
   182 			test(r==KErrNone || r==KErrDiskFull);
   183 			if(r==KErrNone)
   184 				gCount++;
   185 			}
   186 
   187 		r=TheFs.CheckDisk(fileName);
   188 		if (r!=KErrNone && r!=KErrNotSupported)
   189 			{
   190 			test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r);
   191 			test(0);
   192 
   193 			}
   194 
   195 		// Test that scan drive passes on a full disk
   196 		// DEF071696 - KErrCorrupt on Scan Drive 
   197 		GetFreeDiskSpace(freespaceBeforeScanDrive);
   198 		test.Printf(_L("Before ScanDrive freeSpace = %08X:%08X\n"),
   199 			I64HIGH(freespaceBeforeScanDrive), I64LOW(freespaceBeforeScanDrive));
   200 		r = TheFs.ScanDrive(fileName);
   201 		if (r!=KErrNone && r!=KErrNotSupported)
   202 			{
   203 			test.Printf(_L("ScanDrive returned %d\n"), r);
   204 			test(0);
   205 			}
   206 		GetFreeDiskSpace(freespaceAfterScanDrive);
   207 		test.Printf(_L("After ScanDrive freeSpace = %08X:%08X\n"),
   208 			I64HIGH(freespaceAfterScanDrive), I64LOW(freespaceAfterScanDrive));
   209 		}
   210 		while (freespaceBeforeScanDrive != freespaceAfterScanDrive );
   211 
   212 	gCount--;
   213 
   214 	test.End();
   215 	}
   216 
   217 static void GetFreeDiskSpace(TInt64 &aFree)
   218 //
   219 //	Get free disk space
   220 //
   221 	{
   222 	TVolumeInfo v;
   223 
   224 	TInt r=TheFs.Volume(v,gTestDrive);
   225 	test(r==KErrNone);
   226 	aFree=v.iFree;
   227 	}
   228 
   229 
   230 static void Test1()
   231 //
   232 //	Test the API fundamentaly works for one session
   233 //
   234 	{
   235 	test.Next(_L("Test Disk Space reserve APIs"));
   236 	TInt r=0;
   237 	
   238     FormatDrive();
   239 	
   240 	TInt64 free2;
   241 	TInt64 free1; 
   242 	TInt64 diff;
   243 
   244 	r=TheFs.GetReserveAccess(gTestDrive);
   245 	test(r==KErrPermissionDenied);
   246 	
   247 	//make sure nothing odd happens if we didnt already have access
   248 	r=TheFs.ReleaseReserveAccess(gTestDrive);
   249 	test(r==KErrNone);
   250 
   251 	
   252 	GetFreeDiskSpace(free2);
   253 
   254 	r=TheFs.ReserveDriveSpace(gTestDrive,0x1000);
   255 	test(r==KErrNone);
   256 
   257 	GetFreeDiskSpace(free1);
   258 	diff = free2 - free1;
   259 	test(I64INT(diff) > 0xfe0 && I64INT(diff) < 0x1100); 
   260 	
   261 	r=TheFs.GetReserveAccess(gTestDrive);
   262 	test(r==KErrNone);
   263 
   264 	GetFreeDiskSpace(free1);
   265 	TInt64 temp = free2-free1;
   266 	test(I64INT(temp)>(-0x90) && I64INT(temp)<0x90);
   267 	
   268 	r=TheFs.ReleaseReserveAccess(gTestDrive);
   269 	test(r==KErrNone);
   270 	GetFreeDiskSpace(free1);
   271 
   272 	diff = free2 - free1;
   273 	test(I64INT(diff) > 0xfe0 && I64INT(diff) < 0x1100);
   274 	
   275 	
   276 	//test reallocation of reserved space is possible
   277 	r=TheFs.ReserveDriveSpace(gTestDrive,0x2000);
   278 	test(r==KErrNone);
   279 
   280 	//test upper limit of reserved space 
   281 	r=TheFs.ReserveDriveSpace(gTestDrive,0x2000000);
   282 	test(r==KErrArgument);
   283 
   284 	r=TheFs.ReserveDriveSpace(gTestDrive,0);
   285 	test(r==KErrNone);
   286 	
   287 	r=TheFs.GetReserveAccess(gTestDrive);
   288 	test(r==KErrPermissionDenied);
   289 
   290 	//make sure nothing odd happens if we didnt already have access
   291 	r=TheFs.ReleaseReserveAccess(gTestDrive);
   292 	test(r==KErrNone);
   293 	
   294 	r=TheFs.ReserveDriveSpace(gTestDrive,-45);
   295 	test(r==KErrArgument);
   296 	}
   297 
   298 
   299 static void Test2()
   300 //
   301 //	Test multiple sessions, ensure the drive limit is not exceeded
   302 //	
   303 	{
   304 
   305 	test.Next(_L("Test Session and total reserve limits"));
   306 	
   307     FormatDrive();
   308 	
   309 	TInt i=0;
   310 	TInt r=0;
   311 	RFs sessions[17];
   312 	TVolumeInfo v;
   313 
   314 	//Connect Sessions
   315 	for(i=0; i<17; i++)
   316 		{
   317 		r = sessions[i].Connect();
   318 		test(r==KErrNone);
   319 		}
   320 
   321 	test.Next(_L("Test breaching sesson reserve limit"));
   322 	r=sessions[0].ReserveDriveSpace(gTestDrive,0x10001);
   323 	test(r==KErrArgument);
   324 
   325 	//Get Volume Free Space
   326 	r = sessions[0].Volume(v, gTestDrive);
   327 
   328 	if(v.iFree > 0x100000)
   329 		{
   330 		test.Next(_L("Test breaching drive reserve limit"));
   331 
   332 		for (i=0; i<16; i++)
   333 			{
   334 			r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000);
   335 			test(r==KErrNone);
   336 			}
   337 
   338 		//The straw
   339 		r=sessions[16].ReserveDriveSpace(gTestDrive,0x10);
   340 		test(r==KErrTooBig);
   341 		}
   342 	else
   343 		{
   344 		test.Printf(_L("Drive too small: breaching drive reserve limit test skipped\n"));
   345 		test.Next(_L("Testing exhausting available drive free space instead"));
   346 
   347 		for(i=0; (v.iFree -= 0x10000) >= 0; i++)
   348 			{
   349 			r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000);
   350 			test(r==KErrNone);
   351 			}
   352 
   353 		//The straw
   354 		r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000);
   355 		test(r==KErrDiskFull);
   356 		}
   357 
   358 	//Close Sessions
   359 	for(i=0; i<17; i++)
   360 		{
   361 		SynchronousClose(sessions[i]);
   362 		}
   363 	}
   364 
   365 static void Test3()
   366 //
   367 //	Test session cleanup
   368 //		
   369 	{
   370 	test.Next(_L("Test session close and clean up of resrved space"));
   371 
   372 	FormatDrive();
   373 	
   374 	RFs fs1;
   375 	RFs fs2;
   376 	TInt64 free2(0);
   377 	TInt64 free1(0); 
   378 	TInt64 diff(0);
   379 	
   380 	TInt r=0;
   381 	r = fs1.Connect();
   382 	test(r==KErrNone);
   383 	r = fs2.Connect();
   384 	test(r==KErrNone);
   385 
   386 	GetFreeDiskSpace(free1);
   387 
   388 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);
   389 	test(r==KErrNone);
   390 	r=fs2.ReserveDriveSpace(gTestDrive,0x10000);
   391 	test(r==KErrNone);
   392 
   393 	GetFreeDiskSpace(free2);
   394 	diff = free1 - free2;
   395 	test(I64INT(diff)>0x1FBD0 && I64INT(diff)<0x21000); 
   396 
   397 	SynchronousClose(fs1);
   398 
   399 	GetFreeDiskSpace(free2);
   400 	diff = free1-free2;
   401 	test(I64INT(diff)>0xFA00 && I64INT(diff)<0x103C4); 
   402 
   403 	r = fs1.Connect();
   404 	test(r==KErrNone);
   405 
   406 	GetFreeDiskSpace(free1);
   407 	diff= free1-free2;
   408 	test(I64INT(diff)== 0 || I64INT(diff)<0xFA0 ); 
   409 
   410 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);
   411 	test(r==KErrNone);
   412 
   413 	GetFreeDiskSpace(free2);
   414 	diff = free1 - free2;
   415 	test(I64INT(diff)>0xFA00 && I64INT(diff)<0x103C4); 
   416 
   417 	// Make sure no reserve space is allocated
   418 	r=fs1.ReserveDriveSpace(gTestDrive,0);
   419 	test(r==KErrNone);
   420 	r=fs2.ReserveDriveSpace(gTestDrive,0);
   421 	test(r==KErrNone);
   422 
   423 	// Now fill up the disk
   424 	FillUpDisk();
   425 	
   426 	// Should fail as there is no space
   427 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);
   428 	test(r==KErrDiskFull);
   429 
   430 	SynchronousClose(fs1);
   431 	SynchronousClose(fs2);
   432 	}
   433 
   434 
   435 static void Test4()
   436 //
   437 //	Test real out of disk space conditions i.e. properly run out of disk space and try to 
   438 //	reserve an area etc
   439 //	
   440 	{
   441 	test.Next(_L("Test Filling disk and using APIs"));
   442 
   443 	if(IsTestingLFFS())
   444 		{
   445 		//-- This test is not valid for LFFS, because free space on this FS can change itself because of some 
   446         //-- internal FS activities
   447 		test.Printf(_L("This test is inconsistent on LFFS\n"));
   448 		return;
   449 		}
   450 	
   451     FormatDrive();
   452 
   453 	RFs fs;
   454 	TInt r=fs.Connect();
   455 	test(r==KErrNone);
   456 	TInt64 freeA(0);
   457 	TInt64 freeB(0);
   458 	RFile file;
   459 
   460 									//start with known amount of space
   461 
   462 	//create a single file to use for futher tests
   463 	TBuf<20> buf;
   464 	buf=KTestFile;
   465 	buf[0]=(TUint16)gCh;
   466 
   467 	r=file.Replace(fs, buf, EFileWrite);
   468 	test(r==KErrNone);
   469 
   470 	r=file.Write(KTestData());
   471 	test(r==KErrNone);
   472 
   473 	file.Close();
   474 
   475 	r=fs.ReserveDriveSpace(gTestDrive,0x10000);		//reserve some disk space
   476 	test(r==KErrNone);
   477 		
   478 	FillUpDisk();									//fill up the disk
   479 
   480 	TVolumeInfo v;									//get disk space
   481 	r=fs.Volume(v,gTestDrive);
   482 	test(r==KErrNone);
   483 	freeA=v.iFree;
   484 
   485 	r=fs.GetReserveAccess(gTestDrive);				//get access to reserve space
   486 	test(r==KErrNone);
   487 
   488 	r=fs.Volume(v,gTestDrive);						//get disk space
   489 	test(r==KErrNone);
   490 	freeB=v.iFree;
   491 	
   492 	r=fs.ReleaseReserveAccess(gTestDrive);			//release reserve space
   493 	test(r==KErrNone);
   494 	
   495 	test(freeA == (freeB - 0x10000));				//test difference in space is equal to the amount reserved
   496 
   497 	r=fs.Volume(v,gTestDrive);						//get disk space
   498 	test(r==KErrNone);
   499 	freeB=v.iFree;
   500 	test(freeA == freeB);							//check reading is still correct
   501 	
   502 	TBuf <20> dir = KDir();
   503 	dir[0]=(TUint16)gCh;
   504 	r=fs.MkDir(dir);
   505 	test(r==KErrDiskFull);
   506 
   507 	r=fs.MkDirAll(dir);
   508 	test(r==KErrDiskFull);
   509 
   510 	TFileName temp;
   511 	TBuf<5> drv = KDrv();
   512 	drv[0]=(TUint16)gCh;
   513 	r=file.Temp(fs, drv, temp, EFileWrite);
   514 	test(r==KErrDiskFull);
   515 
   516 	r=file.Replace(fs, buf, EFileWrite);
   517 	test(r==KErrDiskFull);
   518 
   519 	r=file.Create(fs, buf, EFileWrite);
   520 	test(r==KErrDiskFull);
   521 
   522 	r=file.Open(fs, buf, EFileWrite);
   523 	test(r==KErrNone);
   524 
   525 	r=file.Write(128, KTestData());
   526 
   527 	if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
   528 		r = file.Flush();
   529 	
   530 	test(r==KErrDiskFull);
   531 
   532 	r=file.SetSize(0x1000);
   533 	test(r==KErrDiskFull);
   534 
   535 	r=file.SetAtt(KEntryAttHidden,0); 
   536 	test(r==KErrDiskFull);
   537 
   538 	TTime dtime;
   539 	r=file.SetModified(dtime); 
   540 	test(r==KErrDiskFull);
   541 
   542 	r=file.Set(dtime,KEntryAttHidden,0);
   543 	test(r==KErrDiskFull);
   544 
   545 	r=file.Rename(buf);
   546 	test(r==KErrDiskFull);
   547 
   548 	file.Close();
   549 
   550 
   551 	// Test that we can create a temporary file & write to it after acquiring reserved access, 
   552 	r=fs.GetReserveAccess(gTestDrive);				//get access to reserve space
   553 	test(r==KErrNone);
   554 
   555 	r=fs.Volume(v,gTestDrive);						//get disk space
   556 	test(r==KErrNone);
   557 	freeA = v.iFree;
   558 
   559 	r=file.Temp(fs, drv, temp, EFileWrite);
   560 	test(r==KErrNone);
   561 
   562 	r = file.Write(KTestData());
   563 	test (r == KErrNone);
   564 
   565 	// If write caching is enabled, call RFs::Entry() to flush the file "anonymously"
   566 	if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
   567 		{
   568 		r = file.Flush();
   569 		test (r == KErrNone);
   570 		}
   571 
   572 	r=fs.Volume(v,gTestDrive);						//get disk space
   573 	test(r==KErrNone);
   574 	freeB = v.iFree;
   575 	test (freeB < freeA);
   576 
   577 	file.Close();
   578 
   579 	r=fs.ReleaseReserveAccess(gTestDrive);			//release reserve space
   580 	test(r==KErrNone);
   581 
   582 
   583 	TBuf<20> newname =KNewName();
   584 	newname[0]=(TUint16)gCh;
   585 	r=fs.Rename(buf, newname);
   586 	test(r==KErrDiskFull);
   587 
   588 	r=fs.Replace(buf, newname);
   589 	test(r==KErrDiskFull);
   590 
   591 	r=fs.SetEntry(buf, dtime, KEntryAttHidden, 0);
   592 	test(r==KErrDiskFull);
   593 
   594 	r=fs.CreatePrivatePath(gTestDrive);
   595 	test(r==KErrDiskFull);
   596 
   597 	r=fs.SetVolumeLabel(_L("Moooo"), gTestDrive);
   598 	test(r==KErrDiskFull);	
   599 
   600 	r=fs.SetModified(buf, dtime);
   601 	test(r==KErrDiskFull);	
   602 
   603 	SynchronousClose(fs);
   604 	}
   605 
   606 	
   607 
   608 static void Test5()
   609 //
   610 //
   611 //
   612 	{
   613 	test.Next(_L("Test Session limits"));
   614 
   615 	if(IsTestingLFFS())
   616 		{
   617 		//-- This test is not valid for LFFS, because free space on this FS can change itself because of some 
   618         //-- internal FS activities
   619 		test.Printf(_L("This test is inconsistent on LFFS\n"));
   620 		return;
   621 		}
   622 
   623 
   624 	RFs fs1;
   625 	RFs fs2;
   626 	TInt r=KErrNone;
   627 
   628 	r=fs1.Connect();
   629 	test(r==KErrNone);
   630 	r=fs2.Connect();
   631 	test(r==KErrNone);
   632 
   633 	FormatDrive();
   634 
   635 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);		
   636 	test(r==KErrNone);
   637 
   638 	r=fs2.ReserveDriveSpace(gTestDrive,0x10000);		
   639 	test(r==KErrNone);
   640 
   641 	FillUpDisk();									
   642 
   643 	r=fs1.GetReserveAccess(gTestDrive);				
   644 	test(r==KErrNone);
   645 
   646 	TBuf<20> dir = KDir();
   647 	dir[0]=(TUint16)gCh;
   648 
   649 
   650 	r=fs2.MkDir(dir);
   651 	test(r==KErrDiskFull);
   652 
   653 	r=fs1.ReserveDriveSpace(gTestDrive,0); //can not release reserve space while you have reserve access
   654 	test(r==KErrInUse);
   655 
   656 	r=fs1.ReleaseReserveAccess(gTestDrive);				
   657 	test(r==KErrNone);
   658 
   659 	r=fs1.ReserveDriveSpace(gTestDrive,0); 
   660 	test(r==KErrNone);
   661 
   662 	r=fs2.MkDir(dir);
   663 	test(r==KErrNone);
   664 
   665 	SynchronousClose(fs1);
   666 	SynchronousClose(fs2);
   667 	}
   668 
   669 static TInt RsrvSpaceThread(TAny* aArg)
   670 	{
   671 	TInt r=KErrNone;
   672 	TInt64 fr1;
   673 	TInt64 fr2;
   674 	TInt64 diff;
   675 
   676 	TVolumeInfo v;
   677 	r=((RFs*)aArg)->Volume(v,gTestDrive);
   678 	if(r!=KErrNone)
   679 		return(r);
   680 
   681 	fr1=v.iFree;
   682 
   683 	r=((RFs*)aArg)->ReserveDriveSpace(gTestDrive,0x10000); 
   684 	if(r!=KErrNone)
   685 		return(r);
   686 
   687 	r=((RFs*)aArg)->Volume(v,gTestDrive);
   688 	if(r!=KErrNone)
   689 		return(r);
   690 	fr2=v.iFree;
   691 	
   692 	diff=fr1-fr2;
   693 	if(!(I64INT(diff)> 0xef38 && I64INT(diff)<0xf100))
   694 		return(KErrGeneral);
   695 	return r;
   696 	}
   697 
   698 static TInt SessCloseThread(TAny* aArg)
   699 	{
   700 	TInt r=KErrNone;
   701 	TInt64 fr1;
   702 	TInt64 fr2;
   703 	TInt64 diff;
   704 
   705 	TVolumeInfo v;
   706 	r=((RFs*)aArg)->Volume(v,gTestDrive);
   707 	if(r!=KErrNone)
   708 		return(r);
   709 	fr1=v.iFree;
   710 
   711 	((RFs*)aArg)->ReserveDriveSpace(gTestDrive,0x1000);
   712 	
   713 	r=((RFs*)aArg)->Volume(v,gTestDrive);
   714 	if(r!=KErrNone)
   715 		return(r);
   716 	fr2=v.iFree;
   717 
   718 	diff=fr2-fr1;
   719 	if(!(I64INT(diff)> 0xef38 && I64INT(diff)<0xf100))
   720 		return(KErrGeneral);
   721 
   722 	SynchronousClose(*((RFs*)aArg));
   723 
   724 	return r;
   725 	}
   726 
   727 static void Test6()
   728 //
   729 //	Test sharabale session
   730 //
   731 	{
   732 	
   733 	test.Next(_L("Test sharable session"));
   734 
   735 	RFs fsess;
   736 	TInt r=KErrNone;
   737 	TInt64 free1(0);
   738 	TInt64 free2(0);
   739 	TInt64 diff(0);
   740 	RThread t[KNumberThreads];
   741 	TRequestStatus tStat[KNumberThreads];
   742 
   743 	r=fsess.Connect();
   744 	test(r==KErrNone);
   745 
   746 	FormatDrive();
   747 
   748 	r= fsess.ShareAuto();
   749 	test(r==KErrNone);
   750 
   751 	GetFreeDiskSpace(free1);
   752 
   753 	fsess.ReserveDriveSpace(gTestDrive,0x1000);
   754 		
   755 	r = t[0].Create(_L("Sub_Thread1"),RsrvSpaceThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); 
   756 	test(r==KErrNone);
   757 
   758 	t[0].Rendezvous(tStat[0]);
   759 	t[0].Resume();
   760 
   761 	User::WaitForRequest(tStat[0]);
   762 
   763 	t[0].Close();
   764 	test(tStat[0]==KErrNone);
   765 
   766 	r = t[1].Create(_L("Sub_Thread2"),SessCloseThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); 
   767 	test(r==KErrNone);
   768 
   769 	t[1].Rendezvous(tStat[1]);
   770 	t[1].Resume();
   771 
   772 	User::WaitForRequest(tStat[1]);
   773 
   774 	t[1].Close();
   775 	test(tStat[1]==KErrNone);
   776 
   777 	GetFreeDiskSpace(free2);
   778 
   779 	diff = free1-free2;
   780 	test(I64INT(diff)== 0 || I64INT(diff)<0xFA0 );
   781 	}
   782 
   783 
   784 static void Test7()
   785 //
   786 // Tests notifier events for sessions with and without reserved access
   787 //
   788 	{
   789 	if(IsTestingLFFS())
   790 		{
   791 		// This test is not valid for LFFS...
   792 		test.Printf(_L("Test reserved access notification not run for LFFS\n"));
   793 		return;
   794 		}
   795 
   796 	
   797 	test.Next(_L("Test reserved access notification"));
   798 	
   799 	FormatDrive();
   800 
   801 	RFs theNrm;
   802 	RFs theRes;
   803 
   804 	TInt err = theNrm.Connect();
   805 	test(KErrNone == err);
   806 
   807 	err = theRes.Connect();
   808 	test(KErrNone == err);
   809 
   810 
   811 	TInt64 freeSpace(0);
   812 	GetFreeDiskSpace(freeSpace);
   813 
   814 	RFs theTestSession;
   815 	theTestSession.Connect();
   816 
   817 	_LIT(KFileFiller, "?:\\t_falseSpaceFiller");
   818 	TBuf<25> fileName;
   819 	fileName = KFileFiller;
   820 	fileName[0] = (TUint16)gCh;
   821 
   822 	err = theTestSession.Connect();
   823 	test(err == KErrNone);
   824 
   825 	// determine the cluster size
   826 	RFile theFile;
   827 	err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite);
   828 	test(err==KErrNone);
   829 
   830 	// Neither notifier should be triggered here
   831 	err = theFile.SetSize(1);
   832 	test(KErrNone == err);
   833 	theFile.Close();
   834 
   835 	TInt64 newFreeSpace;
   836 	GetFreeDiskSpace(newFreeSpace);
   837 	TInt clusterSize = TInt(freeSpace - newFreeSpace);
   838 	theTestSession.Delete(fileName);
   839 	GetFreeDiskSpace(newFreeSpace);
   840 	test (newFreeSpace == freeSpace);
   841 
   842 	TInt resSpace = Max(0x1000, clusterSize);
   843 		
   844 	TVolumeInfo volInfo;
   845 	theNrm.Volume(volInfo, gTestDrive);
   846 	test(volInfo.iFree == freeSpace);
   847 
   848 	err = theRes.ReserveDriveSpace(gTestDrive, resSpace);
   849 	test(KErrNone == err);
   850 	err = theRes.GetReserveAccess(gTestDrive);
   851 	test(KErrNone == err);
   852 
   853 	theRes.Volume(volInfo, gTestDrive);
   854 	test(volInfo.iFree == freeSpace);
   855 
   856 	theNrm.Volume(volInfo, gTestDrive);
   857 	test(volInfo.iFree == freeSpace - resSpace);
   858 
   859 
   860 	//
   861 	// Register the notifiers and verify that the only the "Normal"
   862 	// and not the "Reserved" session is triggered.
   863 	//
   864 	TRequestStatus statNrm;
   865 	TRequestStatus statRes;
   866 
   867 	TInt64 threshold(freeSpace - resSpace*2);
   868 	theNrm.NotifyDiskSpace(threshold, gTestDrive, statNrm);
   869 	theRes.NotifyDiskSpace(threshold, gTestDrive, statRes);
   870 	test((statNrm == KRequestPending) && (statRes == KRequestPending));
   871 
   872 
   873 	//
   874 	// Main part of the test starts here.
   875 	// First we create a new file, then we increase its size to cause the
   876 	// "Normal" notifier to trigger but not the "Reserved" notifier
   877 	//
   878 	err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite);
   879 	test(err==KErrNone);
   880 	test((statNrm == KRequestPending) && (statRes == KRequestPending));
   881 
   882 	// Neither notifier should be triggered here
   883 	err = theFile.SetSize(resSpace);
   884 	test(KErrNone == err);
   885 	test((statNrm == KRequestPending) && (statRes == KRequestPending));
   886 
   887 	// This should trigger the "Normal" notifier, but not the "Reserved" one
   888 	err = theFile.SetSize(2*resSpace);
   889 	test(KErrNone == err);
   890 	test((statNrm == KErrNone) && (statRes == KRequestPending));
   891 
   892 
   893 	//
   894 	// Reset the "Normal" notifier then increase the amount of reserved space
   895 	// on the drive. This should re-trigger the "Normal" notifier but leave
   896 	// the "Reserved" notifier untouched.
   897 	//
   898 	theNrm.NotifyDiskSpace(threshold - resSpace, gTestDrive, statNrm);
   899 	test((statNrm == KRequestPending) && (statRes == KRequestPending));
   900 
   901 	err = theTestSession.ReserveDriveSpace(gTestDrive, resSpace * 3);
   902 	if (err != KErrArgument)	// will have exceeded limit if resSpace = 32K
   903 		{
   904 		test(err == KErrNone);
   905 		test((statNrm == KErrNone) && (statRes == KRequestPending));
   906 		}
   907 
   908 	//
   909 	// All done - tidy up.
   910 	//
   911 	theFile.Close();
   912 	theTestSession.Delete(fileName);
   913 	theTestSession.Close();
   914 	theNrm.Close();
   915 	theRes.Close();
   916 	}
   917 
   918 LOCAL_C void TestForDEF142554()
   919     {
   920     test.Next(_L("Test for DEF142554: test RFile::Modified and RFile::Att when disk full"));
   921     
   922     Format(gTestDrive);
   923     
   924     TUint att;
   925     TTime time;
   926     
   927     RFs fs;
   928     TInt err = fs.Connect();
   929     test(err == KErrNone);
   930 
   931     RFile file;
   932     TBuf<20> fileName;
   933     fileName = KTestFile;
   934     fileName[0] = (TUint16)gCh;
   935     
   936     err = fs.ReserveDriveSpace(gTestDrive,0x10000); 
   937     test(err == KErrNone);
   938 
   939     err = file.Replace(fs, fileName, EFileWrite);
   940     test(err == KErrNone);
   941 
   942     err = file.Write(KTestData);
   943     test(err == KErrNone);
   944     
   945     err = file.Flush();
   946     test(err == KErrNone);
   947     
   948     file.Close();
   949     
   950     err = file.Open(fs, fileName, EFileRead);
   951     test(err == KErrNone);
   952     
   953     err = file.Att(att);
   954     test(err == KErrNone);
   955     
   956     err = file.Modified(time);
   957     test(err == KErrNone);
   958     
   959     file.Close();
   960     
   961     FillUpDisk();
   962     
   963     err = file.Open(fs, fileName, EFileRead);
   964     test(err == KErrNone);
   965     
   966     TUint att1;
   967     err = file.Att(att1);
   968     test(err == KErrNone);
   969     test(att1 == att);
   970     
   971     TTime time1;
   972     err = file.Modified(time1);
   973     test(err == KErrNone);
   974     test(time1 == time);
   975     
   976     file.Close();
   977     fs.Close();
   978     
   979     }
   980 
   981 
   982 //-----------------------------------------------------------------------------
   983 
   984 /**
   985     test creation of the the file that crosses 4G boundary on the FAT media
   986 
   987 */
   988 static void TestFAT4G_Boundary()
   989 	{
   990     const TInt64 K4Gig = 4*(TInt64)K1GigaByte;
   991 
   992 	test.Next(_L("Test files crossing 4G boundary on FAT"));
   993 
   994     if(!Is_Fat32(TheFs, gTestDrive))
   995 		{
   996 		test.Printf(_L("This test requires FAT32. Skipping.\n"));
   997 		return;
   998 		}
   999 
  1000     TVolumeInfo volInfo;
  1001 	
  1002 	TInt nRes = TheFs.Volume(volInfo,gTestDrive);
  1003 	test(nRes == KErrNone);
  1004 	
  1005     if(volInfo.iSize < K4Gig+K1MegaByte)
  1006 		{
  1007 		test.Printf(_L("This test requires volume > 4G. Skipping.\n"));
  1008 		return;
  1009 		}
  1010 	
  1011     //-- 1. format the volume
  1012     FormatDrive();
  1013 
  1014     //-- find out media position of the data region start
  1015     TFatBootSector bootSector;
  1016     nRes = ReadBootSector(TheFs, gTestDrive, 0, bootSector);
  1017     test(nRes == KErrNone);
  1018     test(bootSector.IsValid());
  1019 
  1020     const TInt64 dataStartPos = bootSector.FirstDataSector() << KDefaultSectorLog2;
  1021     const TInt64 lowRegion = K4Gig - dataStartPos - K1MegaByte; 
  1022 
  1023 
  1024     //-- 2. create several empty files that take a bit less that 4gig
  1025     //-- the drive is freshly formatted and the files will expand linearry
  1026     _LIT(KBaseFN, "\\LargeFile");
  1027     
  1028     const TInt MaxDummyFiles = 5;
  1029     const TUint32 DummyFileLen = (TUint32)(lowRegion / MaxDummyFiles);
  1030 	TInt i;
  1031     for(i=0; i<MaxDummyFiles; ++i)
  1032 		{
  1033         nRes = CreateFileX(KBaseFN, i, DummyFileLen); 
  1034         test(nRes == KErrNone);
  1035 		}
  1036 
  1037     //-- 3. create a real file that crosses 4G boundary
  1038     nRes = CreateCheckableStuffedFile(TheFs, KBaseFN, 5*K1MegaByte);
  1039     test(nRes == KErrNone);
  1040     
  1041     test.Printf(_L("Verifying the file that crosses 4G boundary.\n"));
  1042 
  1043     nRes = VerifyCheckableFile(TheFs, KBaseFN);
  1044     test(nRes == KErrNone);
  1045 
  1046 	
  1047 	nRes = TheFs.Delete(KBaseFN);
  1048 	test(nRes == KErrNone);
  1049     for(i=0; i<MaxDummyFiles; ++i)
  1050 	    {
  1051         nRes = DeleteFileX(KBaseFN, i); 
  1052         test(nRes == KErrNone);
  1053 		}
  1054 	}
  1055 
  1056 //-----------------------------------------------------------------------------
  1057 
  1058 GLDEF_C void CallTestsL()
  1059 //
  1060 // Do tests relative to session path
  1061 //
  1062 	{
  1063     //-- set up console output 
  1064     Fat_Test_Utils::SetConsole(test.Console()); 
  1065 
  1066 
  1067 	if (gSessionPath[0]=='C')	//only test on non C drives
  1068 		{
  1069 		test.Printf(_L("TEST NOT RUN FOR THIS DRIVE"));
  1070 		return;
  1071 		}
  1072 	
  1073 	if (UserSvr::DebugMask(2)&0x00000002) // TESTFAST mode set? (for automated test builds)
  1074 		if(IsTestingLFFS())
  1075 			{
  1076 			// Don't run on LFFS (to increase speed of automated testing)
  1077 			test.Printf(_L("TEST NOT RUN FOR THIS DRIVE"));
  1078 			return;
  1079 			}
  1080 
  1081 	//get the number of the drive we are currently testing
  1082 	TInt r=0;
  1083 	r=RFs::CharToDrive(gSessionPath[0],gTestDrive);
  1084     test(r==KErrNone);
  1085 
  1086 	r=RFs::DriveToChar(gTestDrive,gCh);
  1087 	test(r==KErrNone);
  1088 
  1089     //-- print drive information
  1090     PrintDrvInfo(TheFs, gTestDrive);
  1091 
  1092 	Test1();	//General test for new APIs
  1093 	Test2();	//Test to ensure drive and session reserve limits are not exceeded
  1094 	Test3();
  1095 	Test4();	//test filling the drive and that each checked API fails
  1096 	Test5();
  1097 	Test6();
  1098 	Test7();
  1099 	TestForDEF142554();
  1100 	Test2();	//run this test to check reserves are being cleared correctly
  1101 
  1102 	TestFAT4G_Boundary();
  1103     
  1104     TurnAllocFailureOff();
  1105 	}
  1106 
  1107 
  1108 
  1109