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: // f32test\server\t_format.cpp sl@0: // sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: #include "t_chlffs.h" sl@0: sl@0: #include "f32_test_utils.h" sl@0: sl@0: using namespace F32_Test_Utils; sl@0: sl@0: sl@0: GLREF_D TFileName gSessionPath; sl@0: sl@0: sl@0: void GenerateMediaChange() sl@0: { sl@0: TBuf<2> b; sl@0: b.SetLength(2); sl@0: b[0]=gSessionPath[0]; sl@0: b[1]=':'; sl@0: RFormat format; sl@0: TInt count; sl@0: TInt r=format.Open(TheFs,b,EHighDensity,count); sl@0: test(r==KErrNone); sl@0: format.Close(); sl@0: } sl@0: sl@0: RTest test(_L("T_FORMAT")); sl@0: RSemaphore gSleepThread; sl@0: TRequestStatus gThreadLogon; sl@0: sl@0: static TInt gDrive=-1; sl@0: static const TInt KSectorSize=512; sl@0: static const TInt KHeapSize=0x200; sl@0: sl@0: enum TTestCode{ETest3,ETest5}; sl@0: sl@0: sl@0: //------------------------------------------------------------------- sl@0: TInt DoFormatSteps(RFormat& aFormat, TInt& aFmtCnt) sl@0: { sl@0: TInt nRes = KErrNone; sl@0: sl@0: while(aFmtCnt) sl@0: { sl@0: nRes = aFormat.Next(aFmtCnt); sl@0: if(nRes != KErrNone) sl@0: { sl@0: test.Printf(_L("RFormat::Next() failed! code:%d\n"), nRes); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: return nRes; sl@0: } sl@0: sl@0: static void WaitForMedia() sl@0: // sl@0: // Wait until the media change is serviced sl@0: // sl@0: { sl@0: sl@0: FOREVER sl@0: { sl@0: TInt r=TheFs.MkDir(_L("\\")); sl@0: if (r!=KErrNotReady) sl@0: break; sl@0: User::After(100000); sl@0: } sl@0: } sl@0: sl@0: static TInt ThreadEntryPoint(TAny* aTestCode) sl@0: // sl@0: // Thread entry point sl@0: // sl@0: { sl@0: sl@0: RFs fs; sl@0: TInt ret=fs.Connect(); sl@0: test(ret==KErrNone); sl@0: ret=fs.SetSessionPath(gSessionPath); sl@0: test(ret==KErrNone); sl@0: TTestCode testCode=*(TTestCode*)&aTestCode; sl@0: TInt count; sl@0: RFormat format; sl@0: switch (testCode) sl@0: { sl@0: case ETest3: sl@0: { sl@0: ret=format.Open(fs,gSessionPath,EQuickFormat,count); sl@0: test(ret==KErrNone); sl@0: sl@0: ret = DoFormatSteps(format, count); sl@0: test(ret==KErrNone); sl@0: sl@0: format.Close(); sl@0: break; sl@0: } sl@0: case ETest5: sl@0: { sl@0: ret=format.Open(fs,gSessionPath,EFullFormat,count); sl@0: test(ret==KErrNone); sl@0: gSleepThread.Signal(); sl@0: User::After(100000000); sl@0: break; sl@0: } sl@0: default: sl@0: break; sl@0: } sl@0: return(KErrNone); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void CorruptCurrentDrive() sl@0: // sl@0: // Corrupt the current drive sl@0: // sl@0: { sl@0: test.Printf(_L("CorruptCurrentDrive() %c:"), 'A'+CurrentDrive()); sl@0: sl@0: RRawDisk raw; sl@0: TInt r=raw.Open(TheFs,CurrentDrive()); sl@0: test(r==KErrNone); sl@0: if (!Is_Lffs(TheFs, gDrive)) sl@0: { sl@0: TBuf8 zeroBuf(KSectorSize); sl@0: Mem::FillZ((TAny*)zeroBuf.Ptr(),zeroBuf.MaxSize()); sl@0: sl@0: //-- for FAT32 we need to corrupt a backup BOOT sector as well, sl@0: //-- otherwise it can be used and some tests will fail.. sl@0: const TInt KMaxSectors = 25; //-- how many sectors to corrupt sl@0: for(TInt i=0; i zeroBuf(32); sl@0: for (TInt j=0;j<32;++j) sl@0: zeroBuf[j]=(TUint8)j; //Not actuall zero buf for lffs sl@0: // For LFFS, the media may not exhibit a contiguous region of sufficient length sl@0: // to support a continuous sequence of writes. This is the case if the sl@0: // Control Mode Size is non-zero sl@0: TInt cntlModeSize=GetLFFSControlModeSize(); sl@0: if(cntlModeSize==0) sl@0: { sl@0: //test.Printf(_L("CorruptCurrentDrive() - Control mode size is zero\n"),r); sl@0: for (TInt writePos=0;writePos<0x20200;writePos+=32) sl@0: { sl@0: r=raw.Write(writePos,zeroBuf); sl@0: // The device driver most likely fails when writing a random sl@0: // buffer due to read back checks. Since we're writing sl@0: // aligned 32-byte blocks, we don't need to bother that much. sl@0: // The device driver writes the block but fails when reading sl@0: // it back. sl@0: // test(r==KErrNone); sl@0: } sl@0: } sl@0: else if(cntlModeSize>0) sl@0: { sl@0: //test.Printf(_L("CorruptCurrentDrive() - Control mode = 0x%x\n"),r); sl@0: // For devices which have a non-zero control mode size, the writes may sl@0: // require segmentation. sl@0: TInt cmBase=0; sl@0: TInt cmOffset=0; sl@0: TInt bufOffset=0; sl@0: TInt bytesWritten=0; sl@0: TPtrC8 writeBuf; sl@0: while(bytesWritten < 0x20200) sl@0: { sl@0: TInt bufLeft = 32 - bufOffset; // 32 from size of zeroBuf sl@0: TInt spaceLeft = cntlModeSize - cmOffset; sl@0: TInt writeLen=(bufLeft>spaceLeft)? spaceLeft : bufLeft; sl@0: writeBuf.Set(&(zeroBuf[bufOffset]),writeLen); sl@0: TInt writePos = cmBase + cmOffset; sl@0: r=raw.Write(writePos,writeBuf); sl@0: bytesWritten += writeLen; sl@0: if(bufLeft < spaceLeft) sl@0: { sl@0: bufOffset = 0; sl@0: cmOffset += bufLeft; sl@0: } sl@0: else if(bufLeft == spaceLeft) sl@0: { sl@0: bufOffset = 0; sl@0: cmOffset = 0; sl@0: cmBase += (2*cntlModeSize); sl@0: } sl@0: else sl@0: { // bufRemaining>spaceRemaining sl@0: bufOffset += spaceLeft; sl@0: cmOffset = 0; sl@0: cmBase += (2*cntlModeSize); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // Negative value (error code) returned from GetLFFSControlModeSize() sl@0: test.Printf(_L("CorruptCurrentDrive() - Control mode = %d (ERROR!) \n"),cntlModeSize); sl@0: test(0); sl@0: } sl@0: } sl@0: raw.Close(); sl@0: } sl@0: sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void Test1() sl@0: // sl@0: // Format disk sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test EFullFormat")); sl@0: TInt count; sl@0: RFormat format; sl@0: sl@0: TInt r=format.Open(TheFs,gSessionPath,EFullFormat,count); sl@0: test(r==KErrNone); sl@0: sl@0: r = DoFormatSteps(format, count); sl@0: test(r==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: TVolumeInfo volInfo; sl@0: r=TheFs.Volume(volInfo); sl@0: test(r==KErrNone); sl@0: sl@0: if (volInfo.iSize-volInfo.iFree!=0) sl@0: { sl@0: test.Printf(_L("Memory 'in use' after a full format = %ld\n"),(volInfo.iSize-volInfo.iFree)); sl@0: test.Printf(_L("volInfo.iSize = %ld\n"),volInfo.iSize); sl@0: test.Printf(_L("volInfo.iFree = %ld\n"),volInfo.iFree); sl@0: } sl@0: sl@0: test.Next(_L("Test EQuickFormat")); sl@0: r=format.Open(TheFs,gSessionPath,EQuickFormat,count); sl@0: test(r==KErrNone); sl@0: sl@0: r = DoFormatSteps(format, count); sl@0: test(r==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: r=TheFs.Volume(volInfo); sl@0: test(r==KErrNone); sl@0: sl@0: if (volInfo.iSize-volInfo.iFree!=0) sl@0: { sl@0: test.Printf(_L("Memory 'in use' after a quick format = %ld\n"),(volInfo.iSize-volInfo.iFree)); sl@0: test.Printf(_L("volInfo.iSize = %ld\n"),volInfo.iSize); sl@0: test.Printf(_L("volInfo.iFree = %ld\n"),volInfo.iFree); sl@0: return; sl@0: } sl@0: sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void Test2() sl@0: // sl@0: // Test access controls sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test disk cannot be formatted while a file is open")); sl@0: RFile f; sl@0: TInt r=f.Replace(TheFs,_L("BLARGME.BLARG"),EFileStream); sl@0: test(r==KErrNone); sl@0: sl@0: TInt count; sl@0: RFormat format; sl@0: r=format.Open(TheFs,gSessionPath,EFullFormat,count); sl@0: test(r==KErrInUse); sl@0: sl@0: f.Close(); sl@0: r=format.Open(TheFs,gSessionPath,EFullFormat,count); sl@0: test(r==KErrNone); sl@0: format.Close(); sl@0: sl@0: CheckFileExists(_L("BLARGME.BLARG"),KErrNone); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void Test3() sl@0: // sl@0: // Test notification sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test successful format triggers notifier")); sl@0: MakeFile(_L("\\BLARG_BLARG_BLARG.BLG")); sl@0: TRequestStatus reqStat; sl@0: TheFs.NotifyChange(ENotifyEntry,reqStat); sl@0: sl@0: RThread clientThread; sl@0: TInt r=clientThread.Create(_L("ClientThread"),ThreadEntryPoint,0x4000,KHeapSize,KHeapSize,(TAny*)ETest3); sl@0: test.Printf(_L("Created helper thread #1, res=%d\n"),r); sl@0: test(r==KErrNone); sl@0: sl@0: clientThread.Logon(gThreadLogon); sl@0: clientThread.Resume(); sl@0: clientThread.Close(); sl@0: sl@0: User::WaitForRequest(reqStat); sl@0: test.Printf(_L("Notifier triggered #1, res=%d\n"),reqStat.Int()); sl@0: sl@0: User::WaitForRequest(gThreadLogon); sl@0: test.Printf(_L("Helper thread exited #1, res=%d\n"),gThreadLogon.Int()); sl@0: sl@0: CheckFileExists(_L("BLARG_BLARG_BLARG.BLG"),KErrNotFound); sl@0: MakeFile(_L("\\BLARG_BLARG_BLARG.BLG")); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,reqStat); sl@0: r=clientThread.Create(_L("ClientThread"),ThreadEntryPoint,0x4000,KHeapSize,KHeapSize,(TAny*)ETest3); sl@0: test.Printf(_L("Created helper thread #2, res=%d\n"),r); sl@0: test(r==KErrNone); sl@0: sl@0: sl@0: clientThread.Logon(gThreadLogon); sl@0: clientThread.Resume(); sl@0: clientThread.Close(); sl@0: sl@0: User::WaitForRequest(reqStat); sl@0: test.Printf(_L("Notifier triggered #2, res=%d\n"),reqStat.Int()); sl@0: sl@0: User::WaitForRequest(gThreadLogon); sl@0: test.Printf(_L("Helper thread exited #2, res=%d\n"),gThreadLogon.Int()); sl@0: sl@0: CheckFileExists(_L("BLARG_BLARG_BLARG.BLG"),KErrNotFound); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void Test4() sl@0: // sl@0: // Test partially completed formats sl@0: // sl@0: { sl@0: test.Next(_L("Test partially completed formats")); sl@0: sl@0: if(Is_Automounter(TheFs, gDrive)) sl@0: {//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward sl@0: //-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test. sl@0: test.Printf(_L("This step is skipped for Automounter File System\n")); sl@0: return; sl@0: } sl@0: sl@0: MakeFile(_L("\\FORMAT\\DIR1\\BLARG_BLARG_BLARG.BLG")); sl@0: TInt count; sl@0: CorruptCurrentDrive(); sl@0: sl@0: test.Printf(_L("Formatting the drive...\n")); sl@0: sl@0: RFormat format; sl@0: TInt r=format.Open(TheFs,gSessionPath,EFullFormat,count); sl@0: test(r==KErrNone); sl@0: sl@0: while(count) sl@0: { sl@0: RDir dir; sl@0: r=dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal); sl@0: test(r==KErrInUse); sl@0: r=format.Next(count); sl@0: test(r==KErrNone); sl@0: } sl@0: format.Close(); sl@0: sl@0: CheckFileExists(_L("\\FORMAT\\DIR1\\BLARG_BLARG_BLARG.BLG"),KErrPathNotFound); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void Test5() sl@0: // sl@0: // Test panic formatting thread sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test panic formatting thread")); sl@0: sl@0: if(Is_Automounter(TheFs, gDrive)) sl@0: {//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward sl@0: //-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test. sl@0: test.Printf(_L("This step is skipped for Automounter File System\n")); sl@0: return; sl@0: } sl@0: sl@0: CorruptCurrentDrive(); sl@0: if (!(IsTestingLFFS() && GetDriveLFFS()==EDriveC)) // ??? Remove after ER5U sl@0: { sl@0: // UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change sl@0: GenerateMediaChange(); sl@0: WaitForMedia(); sl@0: } sl@0: sl@0: gSleepThread.CreateLocal(0); sl@0: RThread clientThread; sl@0: TInt r=clientThread.Create(_L("ClientThread"),ThreadEntryPoint,0x4000,KHeapSize,KHeapSize,(TAny*)ETest5); sl@0: test.Printf(_L("Created helper thread #1, res=%d\n"),r); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("Panicing formatting thread #1\n")); sl@0: clientThread.Resume(); sl@0: gSleepThread.Wait(); sl@0: test.Printf(_L("Panicing formatting thread #2\n")); sl@0: User::SetJustInTime(EFalse); sl@0: clientThread.Panic(_L("Panic formatting thread"),KErrGeneral); sl@0: User::SetJustInTime(ETrue); sl@0: User::After(200000); // to let panic take effect sl@0: test.Printf(_L("Panicing formatting thread #3\n")); sl@0: sl@0: RDir dir; sl@0: r=dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal); sl@0: // if(IsTestingLFFS() && (r==KErrNone)) sl@0: // { sl@0: // dir.Close(); sl@0: // } sl@0: // else sl@0: // { sl@0: test(r==KErrCorrupt); sl@0: // } sl@0: sl@0: test.Printf(_L("Formatting the drive...\n")); sl@0: sl@0: TInt count; sl@0: RFormat format; sl@0: r=format.Open(TheFs,gSessionPath,EQuickFormat,count); sl@0: test(r==KErrNone); sl@0: sl@0: r = DoFormatSteps(format, count); sl@0: test(r==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: MakeFile(_L("BLARGOID.BLARG")); sl@0: CheckFileExists(_L("BLARGOID.BLARG"),KErrNone); sl@0: clientThread.Close(); sl@0: gSleepThread.Close(); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void Test6() sl@0: // sl@0: // Test ramdrive is shrunk after formatting sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test ramdrive shrinks after formatting")); sl@0: TVolumeInfo volInfo; sl@0: TInt r=TheFs.Volume(volInfo); sl@0: test(r==KErrNone); sl@0: if ((volInfo.iDrive.iMediaAtt&KMediaAttVariableSize)==0) sl@0: return; sl@0: sl@0: TInt64 used=volInfo.iSize-volInfo.iFree; sl@0: RFile f; sl@0: r=f.Replace(TheFs,_L("BIGFILE.SIZE"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: f.SetSize(0x100000); // 1MB sl@0: f.Close(); sl@0: sl@0: r=TheFs.Volume(volInfo); sl@0: test(r==KErrNone); sl@0: TInt64 used2=volInfo.iSize-volInfo.iFree; sl@0: test(used=used2); sl@0: } sl@0: sl@0: static void Test7() sl@0: // sl@0: // Generate media change before formatting. sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Generate Media change before formatting")); sl@0: sl@0: if(Is_Automounter(TheFs, gDrive)) sl@0: {//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward sl@0: //-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test. sl@0: test.Printf(_L("This step is skipped for Automounter File System\n")); sl@0: return; sl@0: } sl@0: sl@0: TVolumeInfo volInfo; sl@0: TInt r=TheFs.Volume(volInfo); sl@0: test(r==KErrNone); sl@0: sl@0: if (volInfo.iDrive.iMediaAtt&KMediaAttVariableSize) sl@0: return; // Don't bother on internal disk sl@0: sl@0: if (Is_Lffs(TheFs, gDrive)) sl@0: return; // Don't bother on LFFS sl@0: sl@0: CorruptCurrentDrive(); sl@0: // UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change sl@0: GenerateMediaChange(); sl@0: WaitForMedia(); sl@0: TInt count; sl@0: RFormat format; sl@0: r=format.Open(TheFs,gSessionPath,EQuickFormat,count); sl@0: test(r==KErrNone); sl@0: sl@0: r = DoFormatSteps(format, count); sl@0: test(r==KErrNone); sl@0: sl@0: format.Close(); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: static void Test8() sl@0: // sl@0: // Test incomplete format sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test incomplete format")); sl@0: sl@0: if(Is_Automounter(TheFs, gDrive)) sl@0: {//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward sl@0: //-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test. sl@0: test.Printf(_L("This step is skipped for Automounter File System\n")); sl@0: return; sl@0: } sl@0: sl@0: CorruptCurrentDrive(); sl@0: sl@0: if (!(IsTestingLFFS() && GetDriveLFFS()==EDriveC)) // ??? Remove after ER5U sl@0: { sl@0: // UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change sl@0: GenerateMediaChange(); sl@0: WaitForMedia(); sl@0: } sl@0: sl@0: TVolumeInfo volInfo; sl@0: TInt r=TheFs.Volume(volInfo); sl@0: // test(r==KErrCorrupt); sl@0: TInt count; sl@0: RFormat format; sl@0: r=format.Open(TheFs,gSessionPath,EQuickFormat,count); sl@0: r=TheFs.Volume(volInfo); sl@0: test(r==KErrInUse); sl@0: r=format.Next(count); sl@0: test(r==KErrNone); sl@0: TDriveList driveList; sl@0: r=TheFs.DriveList(driveList); sl@0: test(r==KErrNone); sl@0: sl@0: if(gDrive == EDriveC) sl@0: { sl@0: r=TheFs.Volume(volInfo, gDrive); sl@0: test(r==KErrInUse); sl@0: } sl@0: else sl@0: { sl@0: r=TheFs.Volume(volInfo,EDriveC); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Volume(volInfo,gDrive); sl@0: test(r==KErrInUse); sl@0: sl@0: r=TheFs.Volume(volInfo,gDrive); sl@0: test(r==KErrInUse); sl@0: } sl@0: sl@0: sl@0: format.Close(); sl@0: Format(CurrentDrive()); sl@0: } sl@0: sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Test an API that allows force media formatting with the files or other objects opened on the volume sl@0: */ sl@0: void TestFormat_ForceDismount() sl@0: { sl@0: test.Next(_L("Test format with forced media dismounting")); sl@0: sl@0: if(Is_Lffs(TheFs, gDrive)) sl@0: {//-- forced FS dismounting with files/directories opened damages LFFS structure for unknown reason. sl@0: //-- this is a problem of LFFS, anyway, it is not supported. sl@0: test.Next(_L("This test can't be performed on LFFS, Skipping.")); sl@0: return; sl@0: } sl@0: sl@0: TInt nRes; sl@0: RFormat format; sl@0: TUint fmtMode = EQuickFormat; sl@0: TInt fmtCnt; sl@0: TBuf<10> drivePath; sl@0: drivePath.Format(_L("%C:\\"), gDrive+'A'); sl@0: sl@0: sl@0: RBuf8 buf8; sl@0: RFile file1; sl@0: RDir dir; sl@0: sl@0: const TInt KBufLen = 128*K1KiloByte; sl@0: nRes = buf8.CreateMax(KBufLen); sl@0: test_KErrNone(nRes); sl@0: sl@0: _LIT(KFname, "\\file1"); sl@0: sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------- sl@0: //-- 1.1 open a file, try to format in normal mode; this shall fail with KErrInUse sl@0: test.Printf(_L("Test normal format with normal opened objects\n")); sl@0: nRes = file1.Replace(TheFs, KFname, EFileWrite); sl@0: test_KErrNone(nRes); sl@0: sl@0: fmtMode = EQuickFormat; sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes == KErrInUse); sl@0: format.Close(); sl@0: sl@0: buf8.SetLength(22); sl@0: nRes = file1.Write(buf8); sl@0: test_KErrNone(nRes); sl@0: sl@0: file1.Close(); sl@0: sl@0: //-- 1.2 open a directory, try to format in normal mode; this shall fail with KErrInUse sl@0: nRes = dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal); sl@0: test_KErrNone(nRes); sl@0: sl@0: fmtMode = EQuickFormat; sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes == KErrInUse); sl@0: format.Close(); sl@0: sl@0: dir.Close(); sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------- sl@0: //-- 2.1 forced quick formatting sl@0: test.Printf(_L("Test forced quick formatting\n")); sl@0: nRes = file1.Replace(TheFs, KFname, EFileWrite); //-- open a file sl@0: test_KErrNone(nRes); sl@0: sl@0: nRes = dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal); //-- open a directory sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- this will mark the current Mount as "Dismounted" and will instantiate another CMountCB for formatting sl@0: fmtMode = EQuickFormat | EForceFormat; sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test_KErrNone(nRes); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test_KErrNone(nRes); sl@0: sl@0: format.Close(); sl@0: sl@0: sl@0: nRes=TheFs.CheckDisk(gSessionPath); sl@0: test(nRes==KErrNone||nRes==KErrNotSupported); sl@0: sl@0: buf8.SetLength(22); sl@0: nRes = file1.Write(buf8); sl@0: test(nRes == KErrDisMounted); sl@0: file1.Close(); //-- this will make the previously "Dismounted" mount die. sl@0: dir.Close(); sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------- sl@0: //-- 2.2 forced full formatting sl@0: test.Printf(_L("Test forced full formatting\n")); sl@0: nRes = file1.Replace(TheFs, KFname, EFileWrite); sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- this will mark the current Mount as "Dismounted" and will instantiate another CMountCB for formatting sl@0: fmtMode = EFullFormat | EForceFormat; sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test_KErrNone(nRes); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test_KErrNone(nRes); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes=TheFs.CheckDisk(gSessionPath); sl@0: test(nRes==KErrNone||nRes==KErrNotSupported); sl@0: sl@0: buf8.SetLength(22); sl@0: nRes = file1.Write(buf8); sl@0: test(nRes == KErrDisMounted); sl@0: file1.Close(); //-- this will make the previously "Dismounted" mount die. sl@0: sl@0: //--------------------------------------------------------------------------------- sl@0: //-- 3. check that forced formatting will complete NotifyDismount sl@0: test.Printf(_L("Test forced formatting completes NotifyDismount\n")); sl@0: TRequestStatus stat1; sl@0: sl@0: nRes = file1.Replace(TheFs, KFname, EFileWrite); sl@0: test_KErrNone(nRes); sl@0: sl@0: TheFs.NotifyDismount(gDrive, stat1, EFsDismountRegisterClient); sl@0: test(stat1.Int() == KRequestPending); sl@0: sl@0: fmtMode = EQuickFormat; sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes == KErrInUse); sl@0: format.Close(); sl@0: sl@0: test(stat1.Int() == KRequestPending); sl@0: sl@0: fmtMode = EQuickFormat | EForceFormat; sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test_KErrNone(nRes); sl@0: format.Close(); sl@0: sl@0: User::WaitForRequest(stat1); sl@0: test(stat1.Int() == KErrNone); sl@0: sl@0: buf8.SetLength(22); sl@0: nRes = file1.Write(buf8); sl@0: test(nRes == KErrDisMounted); sl@0: file1.Close(); sl@0: sl@0: //--------------------------------------------------------------------------------- sl@0: //-- 4.1 check that forced formatting will succeed with dirty file cache sl@0: test.Printf(_L("Test forced formatting will succeed with dirty file cache\n")); sl@0: sl@0: nRes = file1.Replace(TheFs, KFname, EFileWrite | EFileWriteBuffered); //-- enable write caching sl@0: test_KErrNone(nRes); sl@0: sl@0: buf8.SetLength(KBufLen); sl@0: nRes = file1.Write(buf8); //-- this will hopefully get via file write cache sl@0: test_KErrNone(nRes); sl@0: sl@0: fmtMode = EQuickFormat | EForceFormat; sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test_KErrNone(nRes); sl@0: format.Close(); sl@0: sl@0: nRes = file1.Write(buf8); sl@0: test(nRes == KErrDisMounted); sl@0: file1.Close(); sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------- sl@0: sl@0: test.Printf(_L("Test forced formatting with disk access objects opened\n")); sl@0: sl@0: //-- 5.1 check that forced formatting will fail when there are "disk access" objects opened RFormat sl@0: RFormat format1; sl@0: sl@0: nRes = format1.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes == KErrNone); sl@0: sl@0: fmtMode = EQuickFormat | EForceFormat; sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes == KErrInUse); sl@0: format.Close(); sl@0: sl@0: format1.Close(); sl@0: sl@0: //-- 5.1 check that forced formatting will fail when there are "disk access" objects opened RRawDisk sl@0: RRawDisk rawDisk; sl@0: nRes = rawDisk.Open(TheFs, gDrive); sl@0: test(nRes == KErrNone); sl@0: sl@0: fmtMode = EQuickFormat | EForceFormat; sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes == KErrInUse); sl@0: format.Close(); sl@0: sl@0: rawDisk.Close(); sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------- sl@0: //-- 6. Try forced formatting with clamped files, this shall fail with KErrInuse sl@0: test.Printf(_L("Test forced formatting and clamps on the volume\n")); sl@0: sl@0: nRes = file1.Replace(TheFs, KFname, EFileWrite); sl@0: test_KErrNone(nRes); sl@0: sl@0: buf8.SetLength(KBufLen); sl@0: nRes = file1.Write(buf8); //-- this will hopefully get via file write cache sl@0: test_KErrNone(nRes); sl@0: file1.Flush(); sl@0: sl@0: //-- Clamp file sl@0: RFileClamp handle; sl@0: sl@0: nRes=handle.Clamp(file1); sl@0: if(nRes != KErrNone) sl@0: { sl@0: test.Printf(_L("file clamps on this drive are not supported\n")); sl@0: } sl@0: else sl@0: { sl@0: fmtMode = EQuickFormat | EForceFormat; sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes == KErrInUse); sl@0: format.Close(); sl@0: } sl@0: sl@0: handle.Close(TheFs); sl@0: sl@0: file1.Close(); sl@0: sl@0: buf8.Close(); sl@0: } sl@0: sl@0: sl@0: void CallTestsL() sl@0: // sl@0: // Call tests that may leave sl@0: // sl@0: { sl@0: sl@0: TInt r; sl@0: r = TheFs.CharToDrive(gDriveToTest, gDrive); sl@0: test(r == KErrNone); sl@0: sl@0: //-- set up console output sl@0: F32_Test_Utils::SetConsole(test.Console()); sl@0: sl@0: TInt nRes=TheFs.CharToDrive(gDriveToTest, gDrive); sl@0: test(nRes==KErrNone); sl@0: sl@0: PrintDrvInfo(TheFs, gDrive); sl@0: sl@0: if(Is_Win32(TheFs, gDrive)) sl@0: return; //-- emulator drive c: sl@0: sl@0: sl@0: SetSessionPath(_L("\\")); sl@0: sl@0: Test1(); sl@0: Test2(); sl@0: Test3(); sl@0: Test4(); sl@0: Test5(); sl@0: Test6(); sl@0: Test7(); sl@0: Test8(); sl@0: TestFormat_ForceDismount(); sl@0: sl@0: r=TheFs.CheckDisk(gSessionPath); sl@0: test(r==KErrNone||r==KErrNotSupported); sl@0: } sl@0: sl@0: