sl@0: // Copyright (c) 1996-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: // Testing "automounter" filesystem plugin functionality. sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "filesystem_fat.h" sl@0: #include "filesystem_automounter.h" sl@0: sl@0: sl@0: #include "t_server.h" sl@0: #include "fat_utils.h" sl@0: sl@0: using namespace Fat_Test_Utils; sl@0: sl@0: sl@0: sl@0: sl@0: RTest test(_L("T_Automounter")); sl@0: sl@0: static TInt gDriveNum=-1; ///< drive number we are dealing with sl@0: sl@0: //------------------------------------------------------------------- sl@0: //-- the debug test property string can be used to control automounter in debug mode. sl@0: const TUid KThisTestSID={0x10210EB3}; ///< this EXE SID sl@0: sl@0: //------------------------------------------------------------------- sl@0: //-- Actually, for testing autoounter, it is neccessary to have at least 3 filesystems: sl@0: //-- automounter itself and any 2 dirrerent filesystems that can be used as child ones. sl@0: //-- Let's use FAT as a 1st child, and exFAT as 2nd. All these 3 *.fsy shall be present. sl@0: sl@0: /** automounter filesystem name */ sl@0: #define KAutoMounterFSName KFileSystemName_AutoMounter sl@0: _LIT(KAutoMounterFsy, "automounter.fsy"); ///< automounter *.fsy module name sl@0: sl@0: sl@0: //-- FAT is used as a child filesystem #0 sl@0: sl@0: /** filesystem #1 name */ sl@0: #define KFSName1 KFileSystemName_FAT sl@0: sl@0: #if defined(__WINS__) //-- FAT fsy name is a mess. sl@0: _LIT(KFsy1, "efat32.fsy"); sl@0: #else sl@0: _LIT(KFsy1, "elocal.fsy"); sl@0: #endif sl@0: sl@0: sl@0: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sl@0: //-- exFAT is used as a child filesystem #1. The problem here: some poor guys might not have the exFAT at all including the header file sl@0: //-- "filesystem_exfat.h" that defines exFAT volume formatting structure. Fortunately for them the exFAT formatting parameters like "sectors per cluster" and sl@0: //-- "number of FATs" have the same layout in the data container as FAT ones. So FAT formatting structure can be used for formatting exFAT. sl@0: //-- The macro defines if exFAT might not be available. sl@0: #define EXFAT_MIGHT_NOT_BE_PRESENT sl@0: sl@0: /** filesystem #2 name */ sl@0: #ifdef EXFAT_MIGHT_NOT_BE_PRESENT sl@0: _LIT(KFSName2, "exFAT"); sl@0: #else sl@0: #define KFSName2 KFileSystemName_exFAT sl@0: #include "filesystem_exfat.h" sl@0: using namespace FileSystem_EXFAT; sl@0: #endif sl@0: sl@0: sl@0: sl@0: sl@0: _LIT(KFsy2, "exfat.fsy"); ///< filesystem #2 *.fsy module name sl@0: sl@0: TBool automounter_Loaded = EFalse; ///< ETrue if automounter.fsy is loaded; used for correct cleanup sl@0: TBool childFs1_Loaded = EFalse; ///< ETrue if child #0 *.fsy is loaded; used for correct cleanup sl@0: TBool childFs2_Loaded = EFalse; ///< ETrue if child #1 *.fsy is loaded; used for correct cleanup sl@0: sl@0: TFSDescriptor orgFsDescriptor; //-- keeps parameters of the original FS sl@0: sl@0: //------------------------------------------------------------------- sl@0: sl@0: /** sl@0: perform some operations to see if the file system works at all sl@0: */ sl@0: void CheckFsOperations() sl@0: { sl@0: TInt nRes; sl@0: sl@0: TVolumeInfo v; sl@0: nRes = TheFs.Volume(v); sl@0: test_KErrNone(nRes); sl@0: sl@0: _LIT(KTestDir, "\\directory1\\DIR2\\another directory\\"); sl@0: MakeDir(KTestDir); sl@0: sl@0: _LIT(KTestFile, "\\this is a file to test.bin"); sl@0: nRes = CreateCheckableStuffedFile(TheFs, KTestFile, 20376); sl@0: test_KErrNone(nRes); sl@0: sl@0: nRes = VerifyCheckableFile(TheFs, KTestFile); sl@0: test_KErrNone(nRes); sl@0: sl@0: nRes = TheFs.Delete(KTestFile); sl@0: test_KErrNone(nRes); sl@0: sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: sl@0: /** sl@0: Check that FileSystem1 subtype matches one of the expected sl@0: */ sl@0: void CheckSubtype_FS1(const TDesC& aFsSubtype) sl@0: { sl@0: _LIT(KFatSubType12, "fat12"); sl@0: _LIT(KFatSubType16, "fat16"); sl@0: _LIT(KFatSubType32, "fat32"); sl@0: sl@0: test(aFsSubtype.CompareF(KFatSubType12) == 0 || aFsSubtype.CompareF(KFatSubType16) == 0 || aFsSubtype.CompareF(KFatSubType32) == 0 ); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: sl@0: /** sl@0: Check that FileSystem2 subtype matches expected sl@0: */ sl@0: void CheckSubtype_FS2(const TDesC& aFsSubtype) sl@0: { sl@0: _LIT(KExFatSubType, "exFAT"); sl@0: test(aFsSubtype.CompareF(KExFatSubType) == 0); sl@0: } sl@0: sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Dismounts Currently mounted file system. sl@0: */ sl@0: static TInt DoDismountFS() sl@0: { sl@0: TBuf<40> fsName(0); sl@0: TInt nRes; sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: if(nRes == KErrNone) sl@0: { sl@0: test.Printf(_L("--- Dismounting FS:%S\n"), &fsName); sl@0: nRes = TheFs.DismountFileSystem(fsName, gDriveNum); sl@0: return nRes; sl@0: } sl@0: sl@0: return KErrNone; //-- no file system mounted sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Dismounts Currently mounted file system. sl@0: */ sl@0: static void DismountFS() sl@0: { sl@0: test(DoDismountFS() == KErrNone); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Dismounts Currently mounted file system. sl@0: */ sl@0: static void ForceDismountFS() sl@0: { sl@0: test.Printf(_L("--- Force dismounting current FS\n")); sl@0: TRequestStatus stat; sl@0: TheFs.NotifyDismount(gDriveNum, stat, EFsDismountForceDismount); sl@0: User::WaitForRequest(stat); sl@0: test(stat.Int() == KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Mount the given file system. Mounting file system doesn't mean that it will be usable. sl@0: For example, KErrCorrupt can be the result if FS doesn't recognise bootsectors etc. sl@0: sl@0: @param aFsName file system name sl@0: @return error code sl@0: */ sl@0: static TInt DoMountFS(const TDesC& aFsName) sl@0: { sl@0: TInt nRes; sl@0: test.Printf(_L("+++ Mounting FS:%S\n"), &aFsName); sl@0: sl@0: TFSDescriptor newFsDescriptor = orgFsDescriptor; sl@0: newFsDescriptor.iFsName = aFsName; sl@0: test(!newFsDescriptor.iDriveSynch); //-- mount the given FS as asynchronous one, the automounter can't be used on a synchronous drive anyway. sl@0: sl@0: nRes = MountFileSystem(TheFs, gDriveNum, newFsDescriptor); sl@0: sl@0: if(nRes != KErrNone) sl@0: { sl@0: test.Printf(_L("++> Error Mounting FS! code:%d\n"), nRes); sl@0: } sl@0: else sl@0: { sl@0: PrintDrvInfo(TheFs, gDriveNum); sl@0: } sl@0: sl@0: sl@0: return nRes; sl@0: } sl@0: sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Explicitly mount the "automounter" FS sl@0: */ sl@0: static void Mount_AutomounterFS() sl@0: { sl@0: DismountFS(); sl@0: DoMountFS(KAutoMounterFSName); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Explicitly mount the FileSystem1 sl@0: */ sl@0: static void Mount_FileSystem1() sl@0: { sl@0: DismountFS(); sl@0: DoMountFS(KFSName1); sl@0: sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Explicitly mount the FileSystem2 sl@0: */ sl@0: static void Mount_FileSystem2() sl@0: { sl@0: DismountFS(); sl@0: DoMountFS(KFSName2); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Just fill first 32 sectors with zeroes. sl@0: The volume will require formatting after this. sl@0: */ sl@0: static void CorruptDrive() sl@0: { sl@0: TInt nRes; sl@0: test.Printf(_L("!!! corrupting the drive...\n")); sl@0: sl@0: RRawDisk rawDisk; sl@0: nRes = rawDisk.Open(TheFs, gDriveNum); sl@0: test(nRes == KErrNone); sl@0: sl@0: TBuf8<512> sectorBuf(512); sl@0: sl@0: sectorBuf.FillZ(); sl@0: sl@0: const TInt KSectors = 32; sl@0: TInt64 mediaPos = 0; sl@0: sl@0: for(TInt i=0; i," sl@0: sl@0: TBuf8<50> cfgBuf(0); sl@0: cfgBuf.Append(KFSName1); sl@0: cfgBuf.Append(_L(" , ")); sl@0: cfgBuf.Append(KFSName2); sl@0: sl@0: sl@0: nRes = RProperty::Set(KThisTestSID, KPropKey, cfgBuf); sl@0: test_KErrNone(nRes); sl@0: sl@0: } sl@0: sl@0: //======================================= sl@0: //-- we must ensure that all 3 required *.fsy are present and load them. sl@0: //-- the automounter must have child filesystems loaded before its initialisation. sl@0: { sl@0: _LIT(KFsyFailure, "can't load '%S', code:%d, the test can't be performed!\n"); sl@0: sl@0: //-- child FS #0 sl@0: nRes = TheFs.AddFileSystem(KFsy1); sl@0: if(nRes != KErrNone && nRes != KErrAlreadyExists) sl@0: { sl@0: test.Printf(KFsyFailure, &KFsy1, nRes); sl@0: return EFalse; sl@0: } sl@0: childFs1_Loaded = ETrue; sl@0: sl@0: sl@0: //-- child FS #1 sl@0: nRes = TheFs.AddFileSystem(KFsy2); sl@0: if(nRes != KErrNone && nRes != KErrAlreadyExists) sl@0: { sl@0: test.Printf(KFsyFailure, &KFsy2, nRes); sl@0: return EFalse; sl@0: } sl@0: childFs2_Loaded = ETrue; sl@0: sl@0: //-- automounter sl@0: nRes = TheFs.AddFileSystem(KAutoMounterFsy); sl@0: if(nRes != KErrNone && nRes != KErrAlreadyExists) sl@0: { sl@0: test.Printf(KFsyFailure, &KAutoMounterFsy, nRes); sl@0: return EFalse; sl@0: } sl@0: automounter_Loaded = ETrue; sl@0: } sl@0: sl@0: sl@0: //======================================= sl@0: //-- dismount original file system and optional primary extension. Secondary extensions are not supported. sl@0: sl@0: test.Printf(_L("Dismounting the original FS:%S, PExt:%S \n"), &orgFsDescriptor.iFsName, &orgFsDescriptor.iPExtName); sl@0: sl@0: nRes = TheFs.DismountFileSystem(orgFsDescriptor.iFsName, gDriveNum); sl@0: test_KErrNone(nRes); sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** destroy test global objects */ sl@0: void DestroyGlobals() sl@0: { sl@0: test.Printf(_L("Restoring the environment....\n")); sl@0: sl@0: TInt nRes; sl@0: sl@0: //======================================= sl@0: //-- dismount current filesystem that was used for testing and mount the original filesystem sl@0: if(orgFsDescriptor.iFsName.Length()) sl@0: {//-- the original file system had been dismounted during test initialisation; dismount whatever we have now sl@0: test.Printf(_L("Mounting back the original FS:%S, PExt:%S \n"), &orgFsDescriptor.iFsName, &orgFsDescriptor.iPExtName); sl@0: sl@0: TBuf<40> fsName; sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: if(nRes == KErrNone && fsName.CompareF(orgFsDescriptor.iFsName) != KErrNone) sl@0: { sl@0: nRes = TheFs.DismountFileSystem(fsName, gDriveNum); sl@0: test_KErrNone(nRes); sl@0: sl@0: sl@0: //-- mount original FS as asynchronous one, the automounter can't be used on a synchronous drive anyway. sl@0: MountFileSystem(TheFs, gDriveNum, orgFsDescriptor); sl@0: sl@0: FormatVolume(); sl@0: } sl@0: } sl@0: sl@0: //======================================= sl@0: //-- delete test property sl@0: RProperty::Delete(KThisTestSID, gDriveNum); sl@0: sl@0: //======================================= sl@0: //-- if the original FS wasn't automounter, unload child file systems sl@0: if(orgFsDescriptor.iFsName.CompareF(KFileSystemName_AutoMounter) != 0) sl@0: { sl@0: sl@0: if(childFs1_Loaded) sl@0: { sl@0: nRes = TheFs.RemoveFileSystem(KFSName1); sl@0: test(nRes == KErrNone || nRes == KErrInUse); //-- if the FS was used on some drive before test started, It will be KErrInUse sl@0: childFs1_Loaded = EFalse; sl@0: } sl@0: sl@0: if(childFs2_Loaded) sl@0: { sl@0: nRes = TheFs.RemoveFileSystem(KFSName2); sl@0: test(nRes == KErrNone || nRes == KErrInUse); //-- if the FS was used on some drive before test started, It will be KErrInUse sl@0: childFs2_Loaded = EFalse; sl@0: } sl@0: sl@0: sl@0: //-- unload test filesystem modules sl@0: if(automounter_Loaded) sl@0: { sl@0: nRes = TheFs.RemoveFileSystem(KAutoMounterFSName); //-- if the FS was used on some drive before test started, It will be KErrInUse sl@0: test(nRes == KErrNone || nRes == KErrInUse); sl@0: automounter_Loaded = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: nRes = RemountFS(TheFs, gDriveNum); sl@0: test(nRes == KErrNone); sl@0: } sl@0: sl@0: TVolumeInfo v; sl@0: TheFs.Volume(v); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: sl@0: /* sl@0: Testing basic automounter functionality. Format media with different file systems FS1/FS2, mount automounter and sl@0: ensure that it recognised and successfully mounts appropriate child file system. sl@0: sl@0: sl@0: 1.1 mount "filesystem1" / format volume sl@0: 1.2 check file system name / subtype / functionality sl@0: 1.3 corrupt "filesystem1" sl@0: 1.4 check file system name / subtype sl@0: sl@0: sl@0: 2.1 mount "automounter" sl@0: 2.2 check file system name / subtype / functionality (this must correspond to the filesystem1) The "filesystem1" must be recognised sl@0: sl@0: 3.1 mount "filesystem2" / format volume sl@0: 3.2 check file system name / subtype / functionality sl@0: 3.3 corrupt "filesystem2" sl@0: 3.4 check file system name / subtype sl@0: 3.5 format volume (it will be filesystem2) sl@0: sl@0: 4.1 mount "automounter" sl@0: 4.2 check file system name / subtype / functionality (this must correspond to the filesystem2) The "filesystem2" must be recognised sl@0: sl@0: sl@0: 5. check the list of supported file systems on the drive sl@0: sl@0: 6.1 corrupt the volume sl@0: 6.2 check that automounter can't recognise it sl@0: sl@0: 7. restore "filesystem1" / format volume sl@0: */ sl@0: void TestAutomounterBasics() sl@0: { sl@0: sl@0: test.Next(_L("Testing automounter basic functionality \n")); sl@0: sl@0: TVolumeInfo v; sl@0: TBuf<40> fsName(0); sl@0: TBuf<40> fsSubType(0); sl@0: TInt nRes; sl@0: sl@0: //================================================================================ sl@0: //-- 1. mount "filesystem1" / format volume sl@0: test.Printf(_L("Mounting FileSystem1...\n")); sl@0: Mount_FileSystem1(); sl@0: sl@0: FormatVolume(); sl@0: sl@0: nRes = TheFs.Volume(v); sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test_KErrNone(nRes); sl@0: test(fsName.CompareF(KFSName1) == 0); sl@0: sl@0: sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: //-- check the list of supported file systems on this drive (there is only 1 FS supported). sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, -1); sl@0: test(nRes == KErrArgument); sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem sl@0: test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0); sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem sl@0: test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0); sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- there are no more supported FSs sl@0: test(nRes == KErrNotFound); sl@0: sl@0: //-- perform some operation sl@0: CheckFsOperations(); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 2. Now we have volume formatted for "filesystem1"; Mount "automounter" and check that the sl@0: //-- file system on the volume is recognised OK. sl@0: test.Printf(_L("Mounting Automounter FS and checking its functionality ...\n")); sl@0: Mount_AutomounterFS(); sl@0: sl@0: nRes = TheFs.Volume(v); sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: sl@0: test.Printf(_L("FS name:'%S', FS Subtype:'%S'\n") ,&fsName, &fsSubType); sl@0: sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- dismount current file system sl@0: test.Printf(_L("Dismomounting FileSystem1...\n")); sl@0: DismountFS(); sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(nRes == KErrNotFound); sl@0: sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem sl@0: test(nRes == KErrNotFound); sl@0: sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem sl@0: test(nRes == KErrNotFound); sl@0: sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test(nRes == KErrNotReady); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 3. mount "filesystem2" / format volume sl@0: test.Printf(_L("Mounting FileSystem2...\n")); sl@0: Mount_FileSystem2(); sl@0: sl@0: FormatVolume(); sl@0: sl@0: nRes = TheFs.Volume(v); sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test_KErrNone(nRes); sl@0: test(fsName.CompareF(KFSName2) == 0); sl@0: sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS2(fsSubType); sl@0: sl@0: //-- check the list of supported file systems on this drive (there is only 1 FS supported). sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem sl@0: test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0); sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem sl@0: test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0); sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- there are no more supported FSs sl@0: test(nRes == KErrNotFound); sl@0: sl@0: //-- perform some operation sl@0: CheckFsOperations(); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 4. Now we have volume formatted for "filesystem2"; Mount "automounter" and check that the sl@0: //-- file system on the volume is recognised OK. sl@0: test.Printf(_L("Mounting Automounter FS and checking its functionality ...\n")); sl@0: Mount_AutomounterFS(); sl@0: sl@0: nRes = TheFs.Volume(v); sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: sl@0: test.Printf(_L("FS name:'%S', FS Subtype:'%S'\n") ,&fsName, &fsSubType); sl@0: sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: CheckSubtype_FS2(fsSubType); sl@0: sl@0: //================================================================================ sl@0: //-- 5. check the list of supported file systems on this drive (there must be 2 child FS supported). sl@0: test.Printf(_L("Getting list of supported by automounter file systems ...\n")); sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem sl@0: test(nRes == KErrNone && fsName.CompareF(KAutoMounterFSName) == 0); sl@0: test.Printf(_L("Root FS:'%S'\n"), &fsName); sl@0: sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem sl@0: test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0); sl@0: sl@0: fsName.SetLength(0); sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- 2nd "child" filesystem sl@0: test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0); sl@0: sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 2); //-- 3rd "child" filesystem sl@0: test(nRes == KErrNotFound); sl@0: sl@0: //-- get and print out list of all child FS (enumeration example) sl@0: TInt i; sl@0: for(i=0; ;++i) sl@0: { sl@0: nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, i); sl@0: if(nRes == KErrNone) sl@0: { sl@0: test.Printf(_L("child FS[%d]:'%S'\n"), i, &fsName); sl@0: } sl@0: else sl@0: { sl@0: test(nRes == KErrNotFound); sl@0: break; sl@0: } sl@0: sl@0: } sl@0: sl@0: //-- perform some operation. They will happen on currently active child FS sl@0: CheckFsOperations(); sl@0: sl@0: //================================================================================ sl@0: //-- 6. corrupt the media, mount automounter, check that FS is not recognised. sl@0: test.Printf(_L("Test automounter handling corrupted media.\n")); sl@0: sl@0: CorruptDrive(); //-- the active child FS will do this and the root FS will be remounted on first access sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype query requires mounted and recognised file system. this shall fail sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test(nRes == KErrCorrupt); sl@0: sl@0: nRes = TheFs.MkDir(_L("\\dir1\\")); sl@0: test(nRes == KErrCorrupt); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 7. restore filesystem on the drive sl@0: test.Printf(_L("Restoring FileSystem1.\n")); sl@0: Mount_FileSystem1(); sl@0: FormatVolume(); sl@0: sl@0: nRes = TheFs.Volume(v); sl@0: test_KErrNone(nRes); sl@0: sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: sl@0: 1.1 mount "filesystem1" / format volume sl@0: 1.2 create and open a file on the volume. sl@0: 1.3 dismount the file system with opened file on it. sl@0: sl@0: 2. mount "automounter" The "filesystem1" must be recognised sl@0: 2.1 open previously created file (it is still opened by dismounted FS1) sl@0: sl@0: 3. forcedly dismount the current file system (automounter) sl@0: 4. mount the automounter FS again. check file system name / subtype; The "filesystem1" must be recognised sl@0: 5. try to read a file (see 2.1), using already dismounted mount; it shall result in KErrDismounted. sl@0: */ sl@0: void TestDismounting() sl@0: { sl@0: test.Next(_L("Testing media dismounting/remounting with automounter FS \n")); sl@0: sl@0: TInt nRes; sl@0: TBuf<40> fsName(0); sl@0: TBuf<40> fsSubType(0); sl@0: TBuf8<40> buf; sl@0: sl@0: //================================================================================ sl@0: //-- 1. mount "filesystem1" / format volume sl@0: test.Printf(_L("Mounting FileSystem1 and opening a file.\n")); sl@0: Mount_FileSystem1(); sl@0: FormatVolume(); sl@0: sl@0: //-- create a file, open it and try to dismount FS sl@0: _LIT(KTestFile, "\\test_file"); sl@0: nRes = CreateEmptyFile(TheFs, KTestFile, 100); sl@0: test(nRes == KErrNone); sl@0: sl@0: RFile file; sl@0: sl@0: nRes = file.Open(TheFs, KTestFile, 0); sl@0: test(nRes == KErrNone); sl@0: sl@0: //TheFs.SetDebugRegister(KFSERV); sl@0: sl@0: test.Printf(_L("dismounting FileSystem1 with a file opened.\n")); sl@0: nRes = DoDismountFS(); sl@0: test(nRes == KErrInUse); sl@0: sl@0: file.Close(); sl@0: sl@0: //================================================================================ sl@0: //-- 2. mount "automounter", previous FS must be recognised and set as an active child sl@0: Mount_AutomounterFS(); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: //-- open the previously created file sl@0: nRes = file.Open(TheFs, KTestFile, 0); sl@0: test(nRes == KErrNone); sl@0: sl@0: //TheFs.SetDebugRegister(KFSERV); sl@0: sl@0: nRes = DoDismountFS(); sl@0: test(nRes == KErrInUse); //-- opened file belongs to the child FS, actually. sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 3. force dismounting the file system, this will leave hanging dismounted mount associated with this drive. sl@0: test.Printf(_L("Force dismounting the file system.\n")); sl@0: ForceDismountFS(); sl@0: sl@0: //TheFs.SetDebugRegister(KFSERV); sl@0: sl@0: //================================================================================ sl@0: //-- 4. mount "automounter" again, this will create another instance of mount corresponding to the filesystem1 sl@0: Mount_AutomounterFS(); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: //================================================================================ sl@0: //-- 5. try to read a file using already dead mount sl@0: nRes = file.Read(0, buf, 2); sl@0: test(nRes == KErrDisMounted); sl@0: sl@0: //-- this will cause the forcedly dismounted hanging mount to self-destruct sl@0: file.Close(); sl@0: sl@0: sl@0: //-- open the previously created file using current alive mount. sl@0: nRes = file.Open(TheFs, KTestFile, 0); sl@0: test(nRes == KErrNone); sl@0: nRes = file.Read(0, buf, 2); sl@0: test(nRes == KErrNone); sl@0: sl@0: file.Close(); sl@0: sl@0: sl@0: //TheFs.SetDebugRegister(0x00); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Testing legacy RFormat API in the case when the volume has "automounter" file system bound. sl@0: The formatting is performed without specifying any parameters, i.e. "all by default" sl@0: sl@0: If the automounter recognises file system on the volume and successfully mounts it, the sl@0: default formatting must be transparent, i.e. the appropriate child FS will perform it. sl@0: sl@0: If the automounter can't recognise the filesystem on the volume because of volume corruption or if this FS is unknown to it, sl@0: the "default" formatting will fail with "KErrNotFound" sl@0: */ sl@0: void TestAutomounterDefaultFormatting() sl@0: { sl@0: test.Next(_L("Testing media formatting with default parameters. Automounter FS\n")); sl@0: sl@0: TInt nRes; sl@0: TBuf<40> fsName(0); sl@0: TBuf<40> fsSubType(0); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 1. mount "filesystem1" / format volume sl@0: Mount_FileSystem1(); sl@0: FormatVolume(); sl@0: sl@0: //================================================================================ sl@0: //-- 2. mount "automounter", previous FS must be recognised and set as an active child sl@0: Mount_AutomounterFS(); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: //================================================================================ sl@0: //-- 3. format the drive with all default parameters; the current active child FS shall be used sl@0: //-- check that we still have automounter as "root" FS and the same active child sl@0: FormatVolume(); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: //-- perform some operations sl@0: CheckFsOperations(); sl@0: test.Printf(_L("default formatting for FS:'%S', subtype:'%S' OK!\n"), &fsName, &fsSubType); sl@0: sl@0: //================================================================================ sl@0: //-- 3. mount "filesystem2" / format volume sl@0: Mount_FileSystem2(); sl@0: FormatVolume(); sl@0: sl@0: //================================================================================ sl@0: //-- 4. mount "automounter", previous FS must be recognised and set as an active child sl@0: Mount_AutomounterFS(); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS2(fsSubType); sl@0: sl@0: //================================================================================ sl@0: //-- 5. format the drive with all default parameters; the current active child FS shall be used sl@0: //-- check that we still have automounter as "root" FS and the same active child sl@0: FormatVolume(); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS2(fsSubType); sl@0: sl@0: //-- perform some operations sl@0: CheckFsOperations(); sl@0: test.Printf(_L("default formatting for FS:'%S', subtype:'%S' OK!\n"), &fsName, &fsSubType); sl@0: sl@0: //================================================================================ sl@0: //-- 6. corrupt the media, mount automounter, check that FS is not recognised. sl@0: //-- default formatting shall fail, because automounter can't chose appropriate child FS sl@0: sl@0: CorruptDrive(); //-- the active child FS will do this and the root FS will be remounted on first access sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype query requires mounted and recognised file system. this shall fail sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test(nRes == KErrCorrupt); sl@0: sl@0: //-- try default formatting; this shall fail with a special error code sl@0: nRes = FormatDrive(TheFs, CurrentDrive(), ETrue); sl@0: test(nRes == KErrNotFound); sl@0: sl@0: //-- try special formatting without any parameters, it shall also fail. sl@0: RFormat format; sl@0: TUint fmtMode = EQuickFormat | ESpecialFormat; sl@0: TInt fmtCnt; sl@0: TBuf<10> drivePath; sl@0: drivePath.Format(_L("%C:\\"), gDriveNum+'A'); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes==KErrNotFound); sl@0: format.Close(); sl@0: sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 7. restore filesystem on the drive, try formatting with specifying ESpecialFormat flag, but without any formatting parameters sl@0: //-- just to check that it works (it will not work on SD cards that do not allow ESpecialFormat) sl@0: test.Printf(_L("Restoring FileSystem1 and use special format without any parameters\n")); sl@0: sl@0: Mount_FileSystem1(); sl@0: //FormatVolume(); sl@0: sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test_KErrNone(nRes); sl@0: test(fsName.CompareF(KFSName1) == 0); sl@0: sl@0: sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Testing the use case when there is "automounter" FS bound to the drive and RFormat API that allows specifying sl@0: the file system name that we want to put on the volume. sl@0: sl@0: It must be possible: sl@0: - format the volume without specifying FS name at all (the currently active child FS will be used) sl@0: - format the volume with specifying FS name that belongs to one of the supported child FS. The volume shall be formatted with this FS. sl@0: - format the volume with specifying incorrect FS name (not supported) the RFormat::Open() must fail with KErrNotSupported. sl@0: sl@0: - If the file system on the volume is damaged or not recognisable, the RFormat::Open() shall with KErrNotFound if the concrete file system name is not specified. sl@0: - If the file system on the volume is damaged or not recognisable, if shall be possible to format such a volume by specifying the child FS name. sl@0: */ sl@0: void TestAutomounterFormatting_FsNameSpecified() sl@0: { sl@0: test.Next(_L("Testing formatting API that allows specifying particular FS. Automounter FS.\n")); sl@0: sl@0: sl@0: TInt nRes; sl@0: TBuf<40> fsName(0); sl@0: TBuf<40> fsSubType(0); sl@0: sl@0: TBuf<10> drivePath; sl@0: drivePath.Format(_L("%C:\\"), gDriveNum+'A'); sl@0: sl@0: RFormat format; sl@0: TUint fmtMode = EQuickFormat | ESpecialFormat; sl@0: TInt fmtCnt; sl@0: sl@0: TVolFormatParamBuf fmtParamBuf; sl@0: TVolFormatParam& fmtParam = fmtParamBuf(); sl@0: sl@0: //_LIT(KTestFile, "\\this is a test file"); sl@0: sl@0: //================================================================================ sl@0: //-- 0. prepare the volume sl@0: Mount_FileSystem1(); sl@0: FormatVolume(); //-- old API, formatting with all parameters by default sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 0.1 mount "automounter", previous FS must be recognised and set as an active child sl@0: Mount_AutomounterFS(); sl@0: sl@0: //-- check file system name / subtype etc. sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS sl@0: test_KErrNone(nRes); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: //================================================================================ sl@0: sl@0: //-- 1.1 format the volume without specifying any parameters at all, the currently active child FS shall be used sl@0: test.Printf(_L("format the volume without specifying any parameters at all\n")); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: sl@0: //-- 1.2 format the volume without specifying the FS name, the currently active child FS shall be used sl@0: test.Printf(_L("format the volume without specifying the FS name\n")); sl@0: fmtParam.Init(); //-- reset all data sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: sl@0: CheckFsOperations(); sl@0: sl@0: //================================================================================ sl@0: //-- 2. format the volume specifying _second_ child FS name sl@0: test.Printf(_L("format the volume specifying second child FS name\n")); sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(KFSName2); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes =DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS2(fsSubType); sl@0: sl@0: CheckFsOperations(); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 3. format the volume specifying _first_ child FS name sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(KFSName1); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes =DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: CheckFsOperations(); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 4. try formatting the volume specifying wrond child FS name sl@0: fmtParam.Init(); //-- reset all data sl@0: sl@0: fmtParam.SetFileSystemName(KAutoMounterFSName); //-- it might have some strange consequences :) sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotSupported); sl@0: format.Close(); sl@0: sl@0: fmtParam.SetFileSystemName(_L("wrong FS")); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotSupported); sl@0: format.Close(); sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 5. corrupt the volume and try formatting without specyfying FS name sl@0: CorruptDrive(); sl@0: sl@0: fmtParam.Init(); //-- reset all data sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotFound); //-- the meaning: "can't find the appropriate file system to put onto the volume" sl@0: format.Close(); sl@0: sl@0: //test.Printf(_L("#### T_a #1 res:%d\n"), nRes); sl@0: sl@0: fmtParam.SetFileSystemName(KAutoMounterFSName); //-- it might have some strange consequences :) sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: //test.Printf(_L("#### T_a #2 res:%d\n"), nRes); sl@0: sl@0: test(nRes == KErrNotSupported || nRes==KErrNotFound); sl@0: sl@0: format.Close(); sl@0: sl@0: fmtParam.SetFileSystemName(_L("wrong FS")); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotSupported); sl@0: format.Close(); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes==KErrNotFound); //-- the meaning: "can't find the appropriate file system to put onto the volume" sl@0: format.Close(); sl@0: sl@0: sl@0: //-------------------------------------------------------------------------------- sl@0: //-- 5.1 format the volume with specifying child FS2 explicitly sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(KFSName2); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes =DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS2(fsSubType); sl@0: sl@0: CheckFsOperations(); sl@0: sl@0: //-------------------------------------------------------------------------------- sl@0: //-- 5.2 corrupt the volume and format with specifying child FS1 explicitly sl@0: CorruptDrive(); sl@0: sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(KFSName1); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes =DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KAutoMounterFSName) == 0); sl@0: sl@0: //-- the FS Subtype must be the subtype of the recognised child FS sl@0: nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType); sl@0: test_KErrNone(nRes); sl@0: CheckSubtype_FS1(fsSubType); sl@0: sl@0: CheckFsOperations(); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Testing the use case when we have some rigidly bound FS to the drive (e.g "FAT") sl@0: and RFormat API that allows specifying the file system name that we want to put on the volume. sl@0: sl@0: It must be possible: sl@0: - format the volume without specifying FS name at all (the bound FS will be used) sl@0: - format the volume without specifying FS name at all when the volume is corrupted (the bound FS will be used) sl@0: - format the volume with specifying FS name that is the same as the bound FS has. sl@0: sl@0: If the specified file system name differs from the name that the bound FS has, the RFormat::Open() fails with KErrNotSupported. sl@0: sl@0: */ sl@0: void TestFixedFsFormatting_FsNameSpecified() sl@0: { sl@0: test.Next(_L("Testing RFormat API that allows specifying particular FS name for fixed FS.\n")); sl@0: sl@0: TInt nRes; sl@0: TBuf<40> fsName(0); sl@0: sl@0: TBuf<10> drivePath; sl@0: drivePath.Format(_L("%C:\\"), gDriveNum+'A'); sl@0: sl@0: RFormat format; sl@0: TUint fmtMode = EQuickFormat | ESpecialFormat; sl@0: TInt fmtCnt; sl@0: sl@0: TVolFormatParamBuf fmtParamBuf; sl@0: TVolFormatParam& fmtParam = fmtParamBuf(); sl@0: sl@0: _LIT(KTestFile, "\\this is a test file"); sl@0: sl@0: //================================================================================ sl@0: //-- 0. prepare the volume sl@0: test.Printf(_L("fmt: ESpecialFormat, no parameters specified\n")); sl@0: Mount_FileSystem1(); sl@0: sl@0: //-- 0.1 format the volume with ESpecialFormat and without any parameters at all sl@0: test(fmtMode & ESpecialFormat); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: sl@0: format.Close(); sl@0: sl@0: //================================================================================ sl@0: //-- 1. format the volume with default parameters without specifying file system name. The volume is already formatted with FS1 sl@0: test.Printf(_L("fmt: ESpecialFormat, no FS name specified #1\n")); sl@0: fmtParam.Init(); //-- reset all data sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes =DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KFSName1) == 0); sl@0: CheckFsOperations(); sl@0: sl@0: //-- 1.1 corrupt the media and check formatting without specifying FS name. sl@0: //-- The file system bount to this drive shall be used. sl@0: CorruptDrive(); sl@0: sl@0: test.Printf(_L("fmt: ESpecialFormat, no FS name specified #2\n")); sl@0: sl@0: fmtParam.Init(); //-- reset all data sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes =DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KFSName1) == 0); sl@0: CheckFsOperations(); sl@0: sl@0: //-- 1.2 the media is already formatted with FS1, try to specify other file system name for formatting. sl@0: //-- this shall fail with KErrNotSupported, the volume must not be affected sl@0: test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #1\n")); sl@0: sl@0: nRes = CreateCheckableStuffedFile(TheFs, KTestFile, 17384); sl@0: test(nRes==KErrNone); sl@0: sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(_L("some filesystem name")); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotSupported); sl@0: format.Close(); sl@0: sl@0: test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #2\n")); sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(KFSName2); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotSupported); sl@0: format.Close(); sl@0: sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KFSName1) == 0); sl@0: CheckFsOperations(); sl@0: sl@0: nRes = VerifyCheckableFile(TheFs, KTestFile); sl@0: test(nRes==KErrNone); sl@0: sl@0: sl@0: //-- 1.3 corrupt the media and check formatting with the FS Name that doesn't match the FS bound to this drive sl@0: //-- this shall fail sl@0: test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #3\n")); sl@0: CorruptDrive(); sl@0: sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(_L("some filesystem name")); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotSupported); sl@0: format.Close(); sl@0: sl@0: test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #4\n")); sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(KFSName2); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNotSupported); sl@0: format.Close(); sl@0: sl@0: //-- 1.4 specify the correct file system name (bound to this drive) formatting must succeed sl@0: test.Printf(_L("fmt: ESpecialFormat, specifying correct FS name\n")); sl@0: fmtParam.Init(); //-- reset all data sl@0: fmtParam.SetFileSystemName(KFSName1); sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KFSName1) == 0); sl@0: CheckFsOperations(); sl@0: sl@0: sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Test formatting FAT file system with some specific parameters, like sector per cluster etc. sl@0: Note that some media types (like SD cards) do not support such type of formatting. sl@0: */ sl@0: void TestFormatting_FsName_Parameters_FAT() sl@0: { sl@0: using namespace FileSystem_FAT; sl@0: sl@0: test.Next(_L("Testing TVolFormatParam_FAT formatting API\n")); sl@0: sl@0: TInt nRes; sl@0: TBuf<40> fsName(0); sl@0: sl@0: TBuf<10> drivePath; sl@0: drivePath.Format(_L("%C:\\"), gDriveNum+'A'); sl@0: sl@0: RFormat format; sl@0: TUint fmtMode = EQuickFormat | ESpecialFormat; sl@0: TInt fmtCnt; sl@0: sl@0: //================================================================================ sl@0: //-- 0. prepare the volume sl@0: Mount_FileSystem1(); sl@0: FormatVolume(); //-- old API, formatting with all parameters by default sl@0: sl@0: //================================================================================ sl@0: //-- 1.0 simple unit test for TVolFormatParam_FAT sl@0: TVolFormatParam_FATBuf fmtParamBuf_FAT; sl@0: TVolFormatParam_FAT& fmtParam_FAT = fmtParamBuf_FAT(); sl@0: sl@0: fmtParam_FAT.SetFatSubType(EFat32); sl@0: test(fmtParam_FAT.FatSubType() == EFat32); sl@0: sl@0: fmtParam_FAT.SetFatSubType(EFat12); sl@0: test(fmtParam_FAT.FatSubType() == EFat12); sl@0: sl@0: fmtParam_FAT.SetFatSubType(EFat16); sl@0: test(fmtParam_FAT.FatSubType() == EFat16); sl@0: sl@0: fmtParam_FAT.SetFatSubType(ENotSpecified); sl@0: test(fmtParam_FAT.FatSubType() == ENotSpecified); sl@0: sl@0: fmtParam_FAT.SetFatSubType(KFSSubType_FAT32); sl@0: test(fmtParam_FAT.FatSubType() == EFat32); sl@0: sl@0: fmtParam_FAT.SetFatSubType(KFSSubType_FAT12); sl@0: test(fmtParam_FAT.FatSubType() == EFat12); sl@0: sl@0: fmtParam_FAT.SetFatSubType(KFSSubType_FAT16); sl@0: test(fmtParam_FAT.FatSubType() == EFat16); sl@0: sl@0: sl@0: fmtParam_FAT.SetSectPerCluster(64); sl@0: test(fmtParam_FAT.SectPerCluster()==64); sl@0: sl@0: fmtParam_FAT.SetNumFATs(1); sl@0: test(fmtParam_FAT.NumFATs()==1); sl@0: sl@0: fmtParam_FAT.SetReservedSectors(13); sl@0: test(fmtParam_FAT.ReservedSectors()==13); sl@0: sl@0: sl@0: fmtParam_FAT.Init(); sl@0: test(fmtParam_FAT.FatSubType() == ENotSpecified); sl@0: test(fmtParam_FAT.SectPerCluster() == 0); sl@0: test(fmtParam_FAT.NumFATs()==0); sl@0: test(fmtParam_FAT.ReservedSectors()==0); sl@0: sl@0: sl@0: //--- formatting FAT without specifying any parameters. This shall always succeed sl@0: test.Printf(_L("fmt: using TVolFormatParam_FAT, no parameters.\n")); sl@0: sl@0: fmtParam_FAT.Init(); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf_FAT); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: //-- formatting FAT with specifying some parameters. This may fail because the media doesn't support overriding FAT parameters sl@0: //-- or because this parameters combination isn't compatible with the volume geometry. sl@0: sl@0: test.Printf(_L("fmt: using TVolFormatParam_FAT, some FAT specific parameters.\n")); sl@0: fmtParam_FAT.SetFatSubType(EFat32); sl@0: fmtParam_FAT.SetSectPerCluster(1); sl@0: fmtParam_FAT.SetNumFATs(1); sl@0: fmtParam_FAT.SetReservedSectors(13); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf_FAT); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: if(nRes != KErrNone) sl@0: { sl@0: test.Printf(_L("formatting failed. reason code:%d\n"), nRes); sl@0: } sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KFSName1) == 0); sl@0: sl@0: CheckFsOperations(); sl@0: sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: /** sl@0: Test formatting FAT file system with some specific parameters, like sector per cluster etc. sl@0: Note that some media types (like SD cards) do not support such type of formatting. sl@0: */ sl@0: sl@0: void TestFormatting_FsName_Parameters_exFAT() sl@0: { sl@0: sl@0: sl@0: test.Next(_L("Testing TVolFormatParam_exFAT formatting API\n")); sl@0: sl@0: TInt nRes; sl@0: TBuf<40> fsName(0); sl@0: sl@0: TBuf<10> drivePath; sl@0: drivePath.Format(_L("%C:\\"), gDriveNum+'A'); sl@0: sl@0: RFormat format; sl@0: TUint fmtMode = EQuickFormat | ESpecialFormat; sl@0: TInt fmtCnt; sl@0: sl@0: sl@0: //================================================================================ sl@0: //-- 0. prepare the volume sl@0: Mount_FileSystem2(); sl@0: FormatVolume(); //-- old API, formatting with all parameters by default sl@0: sl@0: //================================================================================ sl@0: //-- 1.0 simple unit test for TVolFormatParam_FAT sl@0: sl@0: #ifndef EXFAT_MIGHT_NOT_BE_PRESENT sl@0: TVolFormatParam_exFATBuf fmtParamBuf; sl@0: TVolFormatParam_exFAT& fmtParam = fmtParamBuf(); sl@0: #else sl@0: //-- see the comments to "EXFAT_MIGHT_NOT_BE_PRESENT" macro definition sl@0: TVolFormatParam_FATBuf fmtParamBuf; sl@0: TVolFormatParam_FAT& fmtParam= fmtParamBuf(); sl@0: #endif sl@0: sl@0: sl@0: fmtParam.SetSectPerCluster(64); sl@0: test(fmtParam.SectPerCluster()==64); sl@0: sl@0: fmtParam.SetSectPerCluster(14); sl@0: test(fmtParam.SectPerCluster()==14); sl@0: sl@0: fmtParam.SetNumFATs(1); sl@0: test(fmtParam.NumFATs()==1); sl@0: sl@0: fmtParam.SetNumFATs(2); sl@0: test(fmtParam.NumFATs()==2); sl@0: sl@0: fmtParam.Init(); sl@0: test(fmtParam.SectPerCluster() == 0); sl@0: test(fmtParam.NumFATs()==0); sl@0: sl@0: sl@0: //--- formatting exFAT without specifying any parameters. This shall always succeed sl@0: test.Printf(_L("fmt: using TVolFormatParam_exFAT, no parameters.\n")); sl@0: fmtParam.Init(); sl@0: sl@0: #ifdef EXFAT_MIGHT_NOT_BE_PRESENT sl@0: //-- need to forcedly set exFAT FS name, because fmtParam.Init(); set it to "FAT" sl@0: ((TVolFormatParam&)fmtParam).SetFileSystemName(KFSName2); sl@0: #endif sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: test(nRes==KErrNone); sl@0: sl@0: format.Close(); sl@0: sl@0: //-- formatting exFAT with specifying some parameters. This may fail because the media doesn't support overriding FAT parameters sl@0: //-- or because this parameters combination isn't compatible with the volume geometry. sl@0: sl@0: test.Printf(_L("fmt: using TVolFormatParam_exFAT, some exFAT specific parameters.\n")); sl@0: sl@0: fmtParam.SetSectPerCluster(1); sl@0: fmtParam.SetNumFATs(2); sl@0: sl@0: nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf); sl@0: test(nRes==KErrNone); sl@0: sl@0: nRes = DoFormatSteps(format, fmtCnt); sl@0: if(nRes != KErrNone) sl@0: { sl@0: test.Printf(_L("formatting failed. reason code:%d\n"), nRes); sl@0: } sl@0: sl@0: format.Close(); sl@0: sl@0: nRes = TheFs.FileSystemName(fsName, gDriveNum); sl@0: test(fsName.CompareF(KFSName2) == 0); sl@0: sl@0: CheckFsOperations(); sl@0: } sl@0: sl@0: //------------------------------------------------------------------- sl@0: sl@0: void CallTestsL() sl@0: { sl@0: sl@0: sl@0: //-- set up console output sl@0: Fat_Test_Utils::SetConsole(test.Console()); sl@0: sl@0: #ifndef _DEBUG sl@0: //-- automounter has a special debug interface allowing to control child file ssytems mounting in _DEBUG mode only sl@0: test.Printf(_L("Skipping the test in the Release build! \n")); sl@0: return; sl@0: #else sl@0: sl@0: TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum); sl@0: test(nRes==KErrNone); sl@0: sl@0: sl@0: //------------------------------------- sl@0: sl@0: PrintDrvInfo(TheFs, gDriveNum); sl@0: sl@0: TVolumeInfo v; sl@0: nRes = TheFs.Volume(v); sl@0: test(nRes==KErrNone); sl@0: if(v.iDrive.iMediaAtt & KMediaAttVariableSize) sl@0: { sl@0: test.Printf(_L("Skipping. Internal ram drive not tested.\n")); sl@0: return; sl@0: } sl@0: sl@0: if(v.iDrive.iType != EMediaHardDisk || !(v.iDrive.iDriveAtt & KDriveAttRemovable)) sl@0: { sl@0: test.Printf(_L("The drive shall be removable and the media type EMediaHardDisk. Skipping.\n")); sl@0: return; sl@0: } sl@0: sl@0: sl@0: //------------------------------------- sl@0: sl@0: if(InitGlobals()) sl@0: {//-- do tests here sl@0: sl@0: TestAutomounterBasics(); sl@0: TestDismounting(); sl@0: TestFixedFsFormatting_FsNameSpecified(); sl@0: sl@0: TestAutomounterDefaultFormatting(); sl@0: TestAutomounterFormatting_FsNameSpecified(); sl@0: sl@0: TestFormatting_FsName_Parameters_FAT(); sl@0: TestFormatting_FsName_Parameters_exFAT(); sl@0: sl@0: } sl@0: //------------------------------------- sl@0: DestroyGlobals(); sl@0: #endif sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: