sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "fat_utils.h" sl@0: #include "t_server.h" sl@0: #include "t_chlffs.h" sl@0: sl@0: using namespace Fat_Test_Utils; sl@0: sl@0: RTest test(_L("t_falsespace")); sl@0: sl@0: const TInt KNumberThreads=2; sl@0: const TInt KHeapSize=0x2000; sl@0: sl@0: static TInt RsrvSpaceThread(TAny* aArg); sl@0: static TInt SessCloseThread(TAny* aArg); sl@0: static void GetFreeDiskSpace(TInt64 &aFree); sl@0: sl@0: sl@0: TInt gCount; //count of files used to fill up the disk sl@0: TInt gTestDrive; //drive number of the drive currently being tested sl@0: sl@0: TChar gCh; sl@0: sl@0: _LIT(KBasePath,"\\F32-TST\\FILLDIR\\"); sl@0: _LIT(KBaseName,"\\F32-TST\\FILLDIR\\FILE"); sl@0: sl@0: _LIT(KTestFile,"?:\\test.txt"); sl@0: _LIT8(KTestData, "12345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"); sl@0: _LIT(KDir, "?:\\adodgydir\\"); sl@0: _LIT(KDrv,"?:\\"); sl@0: _LIT(KNewName,"?:\\newname.txt"); sl@0: sl@0: sl@0: void FormatDrive() sl@0: { sl@0: TInt nRes; sl@0: sl@0: sl@0: #if 0 sl@0: //-- FAT32 SPC:1; for the FAT32 testing on the emulator sl@0: TFatFormatParam fp; sl@0: fp.iFatType = EFat32; sl@0: fp.iSecPerCluster = 1; sl@0: sl@0: nRes = FormatFatDrive(TheFs, gTestDrive, ETrue, &fp); sl@0: #else sl@0: sl@0: nRes = FormatFatDrive(TheFs, gTestDrive, ETrue); sl@0: sl@0: #endif sl@0: sl@0: test(nRes == KErrNone); sl@0: } sl@0: sl@0: void SynchronousClose(RFs &aSession) sl@0: { sl@0: TRequestStatus s; sl@0: aSession.NotifyDestruction(s); sl@0: test(s.Int()==KRequestPending); sl@0: aSession.Close(); sl@0: User::WaitForRequest(s); sl@0: } sl@0: sl@0: sl@0: static TInt CreateFileX(const TDesC& aBaseName,TInt aX, TInt aFileSize) sl@0: // sl@0: // Create a large file. Return KErrEof or KErrNone sl@0: // sl@0: { sl@0: sl@0: TBuf<128> fileName=aBaseName; sl@0: fileName.AppendNum(aX); sl@0: RFile file; sl@0: sl@0: TInt r=file.Replace(TheFs,fileName,EFileWrite); sl@0: if (r==KErrDiskFull) sl@0: return(r); sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("ERROR:: Replace returned %d\n"),r); sl@0: test(0); sl@0: return(KErrDiskFull); sl@0: } sl@0: sl@0: if (!IsTestingLFFS()) sl@0: r=file.SetSize(aFileSize); sl@0: else sl@0: { sl@0: TBuf8<1024> testdata(1024); sl@0: TInt count=(aFileSize/testdata.Length()); sl@0: r=KErrNone; sl@0: while (count-- && r==KErrNone) sl@0: r=file.Write(testdata); sl@0: } sl@0: if (r==KErrDiskFull) sl@0: { sl@0: file.Close(); sl@0: return(r); sl@0: } sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("ERROR:: SetSize/Write returned %d\n"),r); sl@0: test(0); sl@0: //test.Getch(); sl@0: file.Close(); sl@0: return(KErrDiskFull); sl@0: } sl@0: sl@0: file.Close(); sl@0: sl@0: test.Printf(_L("Created file %d size %d\n"),aX,aFileSize); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C TInt DeleteFileX(const TDesC& aBaseName,TInt aX) sl@0: // sl@0: // Delete a large file sl@0: // sl@0: { sl@0: TBuf<128> fileName=aBaseName; sl@0: fileName.AppendNum(aX); sl@0: return TheFs.Delete(fileName); sl@0: } sl@0: sl@0: sl@0: static void FillUpDisk() sl@0: // sl@0: // Test that a full disk is ok sl@0: // sl@0: { sl@0: sl@0: test.Start(_L("Fill disk to capacity")); sl@0: TInt r=TheFs.MkDirAll(KBasePath); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: gCount=0; sl@0: TFileName sessionPath; sl@0: r=TheFs.SessionPath(sessionPath); sl@0: test(r==KErrNone); sl@0: TBuf<128> fileName=KBaseName(); sl@0: sl@0: TInt64 freespace=0; sl@0: TInt64 freespaceBeforeScanDrive = 0; sl@0: TInt64 freespaceAfterScanDrive = 0; sl@0: sl@0: do sl@0: { sl@0: GetFreeDiskSpace(freespace); sl@0: TInt fillfilesize=0; sl@0: if (I64HIGH(freespace)) sl@0: fillfilesize=KMaxTInt; sl@0: else sl@0: fillfilesize=I64LOW(freespace)* 7/8; sl@0: sl@0: FOREVER sl@0: { sl@0: TInt r=CreateFileX(fileName,gCount,fillfilesize); sl@0: if (r==KErrDiskFull) sl@0: { sl@0: if(fillfilesize <= 2) sl@0: break; sl@0: else sl@0: fillfilesize=fillfilesize/2; sl@0: } sl@0: test(r==KErrNone || r==KErrDiskFull); sl@0: if(r==KErrNone) sl@0: gCount++; sl@0: } sl@0: sl@0: r=TheFs.CheckDisk(fileName); sl@0: if (r!=KErrNone && r!=KErrNotSupported) sl@0: { sl@0: test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); sl@0: test(0); sl@0: sl@0: } sl@0: sl@0: // Test that scan drive passes on a full disk sl@0: // DEF071696 - KErrCorrupt on Scan Drive sl@0: GetFreeDiskSpace(freespaceBeforeScanDrive); sl@0: test.Printf(_L("Before ScanDrive freeSpace = %08X:%08X\n"), sl@0: I64HIGH(freespaceBeforeScanDrive), I64LOW(freespaceBeforeScanDrive)); sl@0: r = TheFs.ScanDrive(fileName); sl@0: if (r!=KErrNone && r!=KErrNotSupported) sl@0: { sl@0: test.Printf(_L("ScanDrive returned %d\n"), r); sl@0: test(0); sl@0: } sl@0: GetFreeDiskSpace(freespaceAfterScanDrive); sl@0: test.Printf(_L("After ScanDrive freeSpace = %08X:%08X\n"), sl@0: I64HIGH(freespaceAfterScanDrive), I64LOW(freespaceAfterScanDrive)); sl@0: } sl@0: while (freespaceBeforeScanDrive != freespaceAfterScanDrive ); sl@0: sl@0: gCount--; sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: static void GetFreeDiskSpace(TInt64 &aFree) sl@0: // sl@0: // Get free disk space sl@0: // sl@0: { sl@0: TVolumeInfo v; sl@0: sl@0: TInt r=TheFs.Volume(v,gTestDrive); sl@0: test(r==KErrNone); sl@0: aFree=v.iFree; sl@0: } sl@0: sl@0: sl@0: static void Test1() sl@0: // sl@0: // Test the API fundamentaly works for one session sl@0: // sl@0: { sl@0: test.Next(_L("Test Disk Space reserve APIs")); sl@0: TInt r=0; sl@0: sl@0: FormatDrive(); sl@0: sl@0: TInt64 free2; sl@0: TInt64 free1; sl@0: TInt64 diff; sl@0: sl@0: r=TheFs.GetReserveAccess(gTestDrive); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: //make sure nothing odd happens if we didnt already have access sl@0: r=TheFs.ReleaseReserveAccess(gTestDrive); sl@0: test(r==KErrNone); sl@0: sl@0: sl@0: GetFreeDiskSpace(free2); sl@0: sl@0: r=TheFs.ReserveDriveSpace(gTestDrive,0x1000); sl@0: test(r==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free1); sl@0: diff = free2 - free1; sl@0: test(I64INT(diff) > 0xfe0 && I64INT(diff) < 0x1100); sl@0: sl@0: r=TheFs.GetReserveAccess(gTestDrive); sl@0: test(r==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free1); sl@0: TInt64 temp = free2-free1; sl@0: test(I64INT(temp)>(-0x90) && I64INT(temp)<0x90); sl@0: sl@0: r=TheFs.ReleaseReserveAccess(gTestDrive); sl@0: test(r==KErrNone); sl@0: GetFreeDiskSpace(free1); sl@0: sl@0: diff = free2 - free1; sl@0: test(I64INT(diff) > 0xfe0 && I64INT(diff) < 0x1100); sl@0: sl@0: sl@0: //test reallocation of reserved space is possible sl@0: r=TheFs.ReserveDriveSpace(gTestDrive,0x2000); sl@0: test(r==KErrNone); sl@0: sl@0: //test upper limit of reserved space sl@0: r=TheFs.ReserveDriveSpace(gTestDrive,0x2000000); sl@0: test(r==KErrArgument); sl@0: sl@0: r=TheFs.ReserveDriveSpace(gTestDrive,0); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.GetReserveAccess(gTestDrive); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: //make sure nothing odd happens if we didnt already have access sl@0: r=TheFs.ReleaseReserveAccess(gTestDrive); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.ReserveDriveSpace(gTestDrive,-45); sl@0: test(r==KErrArgument); sl@0: } sl@0: sl@0: sl@0: static void Test2() sl@0: // sl@0: // Test multiple sessions, ensure the drive limit is not exceeded sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test Session and total reserve limits")); sl@0: sl@0: FormatDrive(); sl@0: sl@0: TInt i=0; sl@0: TInt r=0; sl@0: RFs sessions[17]; sl@0: TVolumeInfo v; sl@0: sl@0: //Connect Sessions sl@0: for(i=0; i<17; i++) sl@0: { sl@0: r = sessions[i].Connect(); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: test.Next(_L("Test breaching sesson reserve limit")); sl@0: r=sessions[0].ReserveDriveSpace(gTestDrive,0x10001); sl@0: test(r==KErrArgument); sl@0: sl@0: //Get Volume Free Space sl@0: r = sessions[0].Volume(v, gTestDrive); sl@0: sl@0: if(v.iFree > 0x100000) sl@0: { sl@0: test.Next(_L("Test breaching drive reserve limit")); sl@0: sl@0: for (i=0; i<16; i++) sl@0: { sl@0: r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: //The straw sl@0: r=sessions[16].ReserveDriveSpace(gTestDrive,0x10); sl@0: test(r==KErrTooBig); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Drive too small: breaching drive reserve limit test skipped\n")); sl@0: test.Next(_L("Testing exhausting available drive free space instead")); sl@0: sl@0: for(i=0; (v.iFree -= 0x10000) >= 0; i++) sl@0: { sl@0: r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: //The straw sl@0: r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrDiskFull); sl@0: } sl@0: sl@0: //Close Sessions sl@0: for(i=0; i<17; i++) sl@0: { sl@0: SynchronousClose(sessions[i]); sl@0: } sl@0: } sl@0: sl@0: static void Test3() sl@0: // sl@0: // Test session cleanup sl@0: // sl@0: { sl@0: test.Next(_L("Test session close and clean up of resrved space")); sl@0: sl@0: FormatDrive(); sl@0: sl@0: RFs fs1; sl@0: RFs fs2; sl@0: TInt64 free2(0); sl@0: TInt64 free1(0); sl@0: TInt64 diff(0); sl@0: sl@0: TInt r=0; sl@0: r = fs1.Connect(); sl@0: test(r==KErrNone); sl@0: r = fs2.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free1); sl@0: sl@0: r=fs1.ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrNone); sl@0: r=fs2.ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free2); sl@0: diff = free1 - free2; sl@0: test(I64INT(diff)>0x1FBD0 && I64INT(diff)<0x21000); sl@0: sl@0: SynchronousClose(fs1); sl@0: sl@0: GetFreeDiskSpace(free2); sl@0: diff = free1-free2; sl@0: test(I64INT(diff)>0xFA00 && I64INT(diff)<0x103C4); sl@0: sl@0: r = fs1.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free1); sl@0: diff= free1-free2; sl@0: test(I64INT(diff)== 0 || I64INT(diff)<0xFA0 ); sl@0: sl@0: r=fs1.ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free2); sl@0: diff = free1 - free2; sl@0: test(I64INT(diff)>0xFA00 && I64INT(diff)<0x103C4); sl@0: sl@0: // Make sure no reserve space is allocated sl@0: r=fs1.ReserveDriveSpace(gTestDrive,0); sl@0: test(r==KErrNone); sl@0: r=fs2.ReserveDriveSpace(gTestDrive,0); sl@0: test(r==KErrNone); sl@0: sl@0: // Now fill up the disk sl@0: FillUpDisk(); sl@0: sl@0: // Should fail as there is no space sl@0: r=fs1.ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrDiskFull); sl@0: sl@0: SynchronousClose(fs1); sl@0: SynchronousClose(fs2); sl@0: } sl@0: sl@0: sl@0: static void Test4() sl@0: // sl@0: // Test real out of disk space conditions i.e. properly run out of disk space and try to sl@0: // reserve an area etc sl@0: // sl@0: { sl@0: test.Next(_L("Test Filling disk and using APIs")); sl@0: sl@0: if(IsTestingLFFS()) sl@0: { sl@0: //-- This test is not valid for LFFS, because free space on this FS can change itself because of some sl@0: //-- internal FS activities sl@0: test.Printf(_L("This test is inconsistent on LFFS\n")); sl@0: return; sl@0: } sl@0: sl@0: FormatDrive(); sl@0: sl@0: RFs fs; sl@0: TInt r=fs.Connect(); sl@0: test(r==KErrNone); sl@0: TInt64 freeA(0); sl@0: TInt64 freeB(0); sl@0: RFile file; sl@0: sl@0: //start with known amount of space sl@0: sl@0: //create a single file to use for futher tests sl@0: TBuf<20> buf; sl@0: buf=KTestFile; sl@0: buf[0]=(TUint16)gCh; sl@0: sl@0: r=file.Replace(fs, buf, EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=file.Write(KTestData()); sl@0: test(r==KErrNone); sl@0: sl@0: file.Close(); sl@0: sl@0: r=fs.ReserveDriveSpace(gTestDrive,0x10000); //reserve some disk space sl@0: test(r==KErrNone); sl@0: sl@0: FillUpDisk(); //fill up the disk sl@0: sl@0: TVolumeInfo v; //get disk space sl@0: r=fs.Volume(v,gTestDrive); sl@0: test(r==KErrNone); sl@0: freeA=v.iFree; sl@0: sl@0: r=fs.GetReserveAccess(gTestDrive); //get access to reserve space sl@0: test(r==KErrNone); sl@0: sl@0: r=fs.Volume(v,gTestDrive); //get disk space sl@0: test(r==KErrNone); sl@0: freeB=v.iFree; sl@0: sl@0: r=fs.ReleaseReserveAccess(gTestDrive); //release reserve space sl@0: test(r==KErrNone); sl@0: sl@0: test(freeA == (freeB - 0x10000)); //test difference in space is equal to the amount reserved sl@0: sl@0: r=fs.Volume(v,gTestDrive); //get disk space sl@0: test(r==KErrNone); sl@0: freeB=v.iFree; sl@0: test(freeA == freeB); //check reading is still correct sl@0: sl@0: TBuf <20> dir = KDir(); sl@0: dir[0]=(TUint16)gCh; sl@0: r=fs.MkDir(dir); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=fs.MkDirAll(dir); sl@0: test(r==KErrDiskFull); sl@0: sl@0: TFileName temp; sl@0: TBuf<5> drv = KDrv(); sl@0: drv[0]=(TUint16)gCh; sl@0: r=file.Temp(fs, drv, temp, EFileWrite); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=file.Replace(fs, buf, EFileWrite); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=file.Create(fs, buf, EFileWrite); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=file.Open(fs, buf, EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=file.Write(128, KTestData()); sl@0: sl@0: if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) sl@0: r = file.Flush(); sl@0: sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=file.SetSize(0x1000); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=file.SetAtt(KEntryAttHidden,0); sl@0: test(r==KErrDiskFull); sl@0: sl@0: TTime dtime; sl@0: r=file.SetModified(dtime); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=file.Set(dtime,KEntryAttHidden,0); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=file.Rename(buf); sl@0: test(r==KErrDiskFull); sl@0: sl@0: file.Close(); sl@0: sl@0: sl@0: // Test that we can create a temporary file & write to it after acquiring reserved access, sl@0: r=fs.GetReserveAccess(gTestDrive); //get access to reserve space sl@0: test(r==KErrNone); sl@0: sl@0: r=fs.Volume(v,gTestDrive); //get disk space sl@0: test(r==KErrNone); sl@0: freeA = v.iFree; sl@0: sl@0: r=file.Temp(fs, drv, temp, EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r = file.Write(KTestData()); sl@0: test (r == KErrNone); sl@0: sl@0: // If write caching is enabled, call RFs::Entry() to flush the file "anonymously" sl@0: if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) sl@0: { sl@0: r = file.Flush(); sl@0: test (r == KErrNone); sl@0: } sl@0: sl@0: r=fs.Volume(v,gTestDrive); //get disk space sl@0: test(r==KErrNone); sl@0: freeB = v.iFree; sl@0: test (freeB < freeA); sl@0: sl@0: file.Close(); sl@0: sl@0: r=fs.ReleaseReserveAccess(gTestDrive); //release reserve space sl@0: test(r==KErrNone); sl@0: sl@0: sl@0: TBuf<20> newname =KNewName(); sl@0: newname[0]=(TUint16)gCh; sl@0: r=fs.Rename(buf, newname); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=fs.Replace(buf, newname); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=fs.SetEntry(buf, dtime, KEntryAttHidden, 0); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=fs.CreatePrivatePath(gTestDrive); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=fs.SetVolumeLabel(_L("Moooo"), gTestDrive); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=fs.SetModified(buf, dtime); sl@0: test(r==KErrDiskFull); sl@0: sl@0: SynchronousClose(fs); sl@0: } sl@0: sl@0: sl@0: sl@0: static void Test5() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: test.Next(_L("Test Session limits")); sl@0: sl@0: if(IsTestingLFFS()) sl@0: { sl@0: //-- This test is not valid for LFFS, because free space on this FS can change itself because of some sl@0: //-- internal FS activities sl@0: test.Printf(_L("This test is inconsistent on LFFS\n")); sl@0: return; sl@0: } sl@0: sl@0: sl@0: RFs fs1; sl@0: RFs fs2; sl@0: TInt r=KErrNone; sl@0: sl@0: r=fs1.Connect(); sl@0: test(r==KErrNone); sl@0: r=fs2.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: FormatDrive(); sl@0: sl@0: r=fs1.ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrNone); sl@0: sl@0: r=fs2.ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(r==KErrNone); sl@0: sl@0: FillUpDisk(); sl@0: sl@0: r=fs1.GetReserveAccess(gTestDrive); sl@0: test(r==KErrNone); sl@0: sl@0: TBuf<20> dir = KDir(); sl@0: dir[0]=(TUint16)gCh; sl@0: sl@0: sl@0: r=fs2.MkDir(dir); sl@0: test(r==KErrDiskFull); sl@0: sl@0: r=fs1.ReserveDriveSpace(gTestDrive,0); //can not release reserve space while you have reserve access sl@0: test(r==KErrInUse); sl@0: sl@0: r=fs1.ReleaseReserveAccess(gTestDrive); sl@0: test(r==KErrNone); sl@0: sl@0: r=fs1.ReserveDriveSpace(gTestDrive,0); sl@0: test(r==KErrNone); sl@0: sl@0: r=fs2.MkDir(dir); sl@0: test(r==KErrNone); sl@0: sl@0: SynchronousClose(fs1); sl@0: SynchronousClose(fs2); sl@0: } sl@0: sl@0: static TInt RsrvSpaceThread(TAny* aArg) sl@0: { sl@0: TInt r=KErrNone; sl@0: TInt64 fr1; sl@0: TInt64 fr2; sl@0: TInt64 diff; sl@0: sl@0: TVolumeInfo v; sl@0: r=((RFs*)aArg)->Volume(v,gTestDrive); sl@0: if(r!=KErrNone) sl@0: return(r); sl@0: sl@0: fr1=v.iFree; sl@0: sl@0: r=((RFs*)aArg)->ReserveDriveSpace(gTestDrive,0x10000); sl@0: if(r!=KErrNone) sl@0: return(r); sl@0: sl@0: r=((RFs*)aArg)->Volume(v,gTestDrive); sl@0: if(r!=KErrNone) sl@0: return(r); sl@0: fr2=v.iFree; sl@0: sl@0: diff=fr1-fr2; sl@0: if(!(I64INT(diff)> 0xef38 && I64INT(diff)<0xf100)) sl@0: return(KErrGeneral); sl@0: return r; sl@0: } sl@0: sl@0: static TInt SessCloseThread(TAny* aArg) sl@0: { sl@0: TInt r=KErrNone; sl@0: TInt64 fr1; sl@0: TInt64 fr2; sl@0: TInt64 diff; sl@0: sl@0: TVolumeInfo v; sl@0: r=((RFs*)aArg)->Volume(v,gTestDrive); sl@0: if(r!=KErrNone) sl@0: return(r); sl@0: fr1=v.iFree; sl@0: sl@0: ((RFs*)aArg)->ReserveDriveSpace(gTestDrive,0x1000); sl@0: sl@0: r=((RFs*)aArg)->Volume(v,gTestDrive); sl@0: if(r!=KErrNone) sl@0: return(r); sl@0: fr2=v.iFree; sl@0: sl@0: diff=fr2-fr1; sl@0: if(!(I64INT(diff)> 0xef38 && I64INT(diff)<0xf100)) sl@0: return(KErrGeneral); sl@0: sl@0: SynchronousClose(*((RFs*)aArg)); sl@0: sl@0: return r; sl@0: } sl@0: sl@0: static void Test6() sl@0: // sl@0: // Test sharabale session sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test sharable session")); sl@0: sl@0: RFs fsess; sl@0: TInt r=KErrNone; sl@0: TInt64 free1(0); sl@0: TInt64 free2(0); sl@0: TInt64 diff(0); sl@0: RThread t[KNumberThreads]; sl@0: TRequestStatus tStat[KNumberThreads]; sl@0: sl@0: r=fsess.Connect(); sl@0: test(r==KErrNone); sl@0: sl@0: FormatDrive(); sl@0: sl@0: r= fsess.ShareAuto(); sl@0: test(r==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free1); sl@0: sl@0: fsess.ReserveDriveSpace(gTestDrive,0x1000); sl@0: sl@0: r = t[0].Create(_L("Sub_Thread1"),RsrvSpaceThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); sl@0: test(r==KErrNone); sl@0: sl@0: t[0].Rendezvous(tStat[0]); sl@0: t[0].Resume(); sl@0: sl@0: User::WaitForRequest(tStat[0]); sl@0: sl@0: t[0].Close(); sl@0: test(tStat[0]==KErrNone); sl@0: sl@0: r = t[1].Create(_L("Sub_Thread2"),SessCloseThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); sl@0: test(r==KErrNone); sl@0: sl@0: t[1].Rendezvous(tStat[1]); sl@0: t[1].Resume(); sl@0: sl@0: User::WaitForRequest(tStat[1]); sl@0: sl@0: t[1].Close(); sl@0: test(tStat[1]==KErrNone); sl@0: sl@0: GetFreeDiskSpace(free2); sl@0: sl@0: diff = free1-free2; sl@0: test(I64INT(diff)== 0 || I64INT(diff)<0xFA0 ); sl@0: } sl@0: sl@0: sl@0: static void Test7() sl@0: // sl@0: // Tests notifier events for sessions with and without reserved access sl@0: // sl@0: { sl@0: if(IsTestingLFFS()) sl@0: { sl@0: // This test is not valid for LFFS... sl@0: test.Printf(_L("Test reserved access notification not run for LFFS\n")); sl@0: return; sl@0: } sl@0: sl@0: sl@0: test.Next(_L("Test reserved access notification")); sl@0: sl@0: FormatDrive(); sl@0: sl@0: RFs theNrm; sl@0: RFs theRes; sl@0: sl@0: TInt err = theNrm.Connect(); sl@0: test(KErrNone == err); sl@0: sl@0: err = theRes.Connect(); sl@0: test(KErrNone == err); sl@0: sl@0: sl@0: TInt64 freeSpace(0); sl@0: GetFreeDiskSpace(freeSpace); sl@0: sl@0: RFs theTestSession; sl@0: theTestSession.Connect(); sl@0: sl@0: _LIT(KFileFiller, "?:\\t_falseSpaceFiller"); sl@0: TBuf<25> fileName; sl@0: fileName = KFileFiller; sl@0: fileName[0] = (TUint16)gCh; sl@0: sl@0: err = theTestSession.Connect(); sl@0: test(err == KErrNone); sl@0: sl@0: // determine the cluster size sl@0: RFile theFile; sl@0: err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite); sl@0: test(err==KErrNone); sl@0: sl@0: // Neither notifier should be triggered here sl@0: err = theFile.SetSize(1); sl@0: test(KErrNone == err); sl@0: theFile.Close(); sl@0: sl@0: TInt64 newFreeSpace; sl@0: GetFreeDiskSpace(newFreeSpace); sl@0: TInt clusterSize = TInt(freeSpace - newFreeSpace); sl@0: theTestSession.Delete(fileName); sl@0: GetFreeDiskSpace(newFreeSpace); sl@0: test (newFreeSpace == freeSpace); sl@0: sl@0: TInt resSpace = Max(0x1000, clusterSize); sl@0: sl@0: TVolumeInfo volInfo; sl@0: theNrm.Volume(volInfo, gTestDrive); sl@0: test(volInfo.iFree == freeSpace); sl@0: sl@0: err = theRes.ReserveDriveSpace(gTestDrive, resSpace); sl@0: test(KErrNone == err); sl@0: err = theRes.GetReserveAccess(gTestDrive); sl@0: test(KErrNone == err); sl@0: sl@0: theRes.Volume(volInfo, gTestDrive); sl@0: test(volInfo.iFree == freeSpace); sl@0: sl@0: theNrm.Volume(volInfo, gTestDrive); sl@0: test(volInfo.iFree == freeSpace - resSpace); sl@0: sl@0: sl@0: // sl@0: // Register the notifiers and verify that the only the "Normal" sl@0: // and not the "Reserved" session is triggered. sl@0: // sl@0: TRequestStatus statNrm; sl@0: TRequestStatus statRes; sl@0: sl@0: TInt64 threshold(freeSpace - resSpace*2); sl@0: theNrm.NotifyDiskSpace(threshold, gTestDrive, statNrm); sl@0: theRes.NotifyDiskSpace(threshold, gTestDrive, statRes); sl@0: test((statNrm == KRequestPending) && (statRes == KRequestPending)); sl@0: sl@0: sl@0: // sl@0: // Main part of the test starts here. sl@0: // First we create a new file, then we increase its size to cause the sl@0: // "Normal" notifier to trigger but not the "Reserved" notifier sl@0: // sl@0: err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite); sl@0: test(err==KErrNone); sl@0: test((statNrm == KRequestPending) && (statRes == KRequestPending)); sl@0: sl@0: // Neither notifier should be triggered here sl@0: err = theFile.SetSize(resSpace); sl@0: test(KErrNone == err); sl@0: test((statNrm == KRequestPending) && (statRes == KRequestPending)); sl@0: sl@0: // This should trigger the "Normal" notifier, but not the "Reserved" one sl@0: err = theFile.SetSize(2*resSpace); sl@0: test(KErrNone == err); sl@0: test((statNrm == KErrNone) && (statRes == KRequestPending)); sl@0: sl@0: sl@0: // sl@0: // Reset the "Normal" notifier then increase the amount of reserved space sl@0: // on the drive. This should re-trigger the "Normal" notifier but leave sl@0: // the "Reserved" notifier untouched. sl@0: // sl@0: theNrm.NotifyDiskSpace(threshold - resSpace, gTestDrive, statNrm); sl@0: test((statNrm == KRequestPending) && (statRes == KRequestPending)); sl@0: sl@0: err = theTestSession.ReserveDriveSpace(gTestDrive, resSpace * 3); sl@0: if (err != KErrArgument) // will have exceeded limit if resSpace = 32K sl@0: { sl@0: test(err == KErrNone); sl@0: test((statNrm == KErrNone) && (statRes == KRequestPending)); sl@0: } sl@0: sl@0: // sl@0: // All done - tidy up. sl@0: // sl@0: theFile.Close(); sl@0: theTestSession.Delete(fileName); sl@0: theTestSession.Close(); sl@0: theNrm.Close(); sl@0: theRes.Close(); sl@0: } sl@0: sl@0: LOCAL_C void TestForDEF142554() sl@0: { sl@0: test.Next(_L("Test for DEF142554: test RFile::Modified and RFile::Att when disk full")); sl@0: sl@0: Format(gTestDrive); sl@0: sl@0: TUint att; sl@0: TTime time; sl@0: sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: test(err == KErrNone); sl@0: sl@0: RFile file; sl@0: TBuf<20> fileName; sl@0: fileName = KTestFile; sl@0: fileName[0] = (TUint16)gCh; sl@0: sl@0: err = fs.ReserveDriveSpace(gTestDrive,0x10000); sl@0: test(err == KErrNone); sl@0: sl@0: err = file.Replace(fs, fileName, EFileWrite); sl@0: test(err == KErrNone); sl@0: sl@0: err = file.Write(KTestData); sl@0: test(err == KErrNone); sl@0: sl@0: err = file.Flush(); sl@0: test(err == KErrNone); sl@0: sl@0: file.Close(); sl@0: sl@0: err = file.Open(fs, fileName, EFileRead); sl@0: test(err == KErrNone); sl@0: sl@0: err = file.Att(att); sl@0: test(err == KErrNone); sl@0: sl@0: err = file.Modified(time); sl@0: test(err == KErrNone); sl@0: sl@0: file.Close(); sl@0: sl@0: FillUpDisk(); sl@0: sl@0: err = file.Open(fs, fileName, EFileRead); sl@0: test(err == KErrNone); sl@0: sl@0: TUint att1; sl@0: err = file.Att(att1); sl@0: test(err == KErrNone); sl@0: test(att1 == att); sl@0: sl@0: TTime time1; sl@0: err = file.Modified(time1); sl@0: test(err == KErrNone); sl@0: test(time1 == time); sl@0: sl@0: file.Close(); sl@0: fs.Close(); sl@0: sl@0: } sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: test creation of the the file that crosses 4G boundary on the FAT media sl@0: sl@0: */ sl@0: static void TestFAT4G_Boundary() sl@0: { sl@0: const TInt64 K4Gig = 4*(TInt64)K1GigaByte; sl@0: sl@0: test.Next(_L("Test files crossing 4G boundary on FAT")); sl@0: sl@0: if(!Is_Fat32(TheFs, gTestDrive)) sl@0: { sl@0: test.Printf(_L("This test requires FAT32. Skipping.\n")); sl@0: return; sl@0: } sl@0: sl@0: TVolumeInfo volInfo; sl@0: sl@0: TInt nRes = TheFs.Volume(volInfo,gTestDrive); sl@0: test(nRes == KErrNone); sl@0: sl@0: if(volInfo.iSize < K4Gig+K1MegaByte) sl@0: { sl@0: test.Printf(_L("This test requires volume > 4G. Skipping.\n")); sl@0: return; sl@0: } sl@0: sl@0: //-- 1. format the volume sl@0: FormatDrive(); sl@0: sl@0: //-- find out media position of the data region start sl@0: TFatBootSector bootSector; sl@0: nRes = ReadBootSector(TheFs, gTestDrive, 0, bootSector); sl@0: test(nRes == KErrNone); sl@0: test(bootSector.IsValid()); sl@0: sl@0: const TInt64 dataStartPos = bootSector.FirstDataSector() << KDefaultSectorLog2; sl@0: const TInt64 lowRegion = K4Gig - dataStartPos - K1MegaByte; sl@0: sl@0: sl@0: //-- 2. create several empty files that take a bit less that 4gig sl@0: //-- the drive is freshly formatted and the files will expand linearry sl@0: _LIT(KBaseFN, "\\LargeFile"); sl@0: sl@0: const TInt MaxDummyFiles = 5; sl@0: const TUint32 DummyFileLen = (TUint32)(lowRegion / MaxDummyFiles); sl@0: TInt i; sl@0: for(i=0; i