Update contrib.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
15 // Testing "automounter" filesystem plugin functionality.
23 #define __E32TEST_EXTENSION__
28 #include <e32property.h>
31 #include "filesystem_fat.h"
32 #include "filesystem_automounter.h"
36 #include "fat_utils.h"
38 using namespace Fat_Test_Utils;
43 RTest test(_L("T_Automounter"));
45 static TInt gDriveNum=-1; ///< drive number we are dealing with
47 //-------------------------------------------------------------------
48 //-- the debug test property string can be used to control automounter in debug mode.
49 const TUid KThisTestSID={0x10210EB3}; ///< this EXE SID
51 //-------------------------------------------------------------------
52 //-- Actually, for testing autoounter, it is neccessary to have at least 3 filesystems:
53 //-- automounter itself and any 2 dirrerent filesystems that can be used as child ones.
54 //-- Let's use FAT as a 1st child, and exFAT as 2nd. All these 3 *.fsy shall be present.
56 /** automounter filesystem name */
57 #define KAutoMounterFSName KFileSystemName_AutoMounter
58 _LIT(KAutoMounterFsy, "automounter.fsy"); ///< automounter *.fsy module name
61 //-- FAT is used as a child filesystem #0
63 /** filesystem #1 name */
64 #define KFSName1 KFileSystemName_FAT
66 #if defined(__WINS__) //-- FAT fsy name is a mess.
67 _LIT(KFsy1, "efat32.fsy");
69 _LIT(KFsy1, "elocal.fsy");
73 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74 //-- 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
75 //-- "filesystem_exfat.h" that defines exFAT volume formatting structure. Fortunately for them the exFAT formatting parameters like "sectors per cluster" and
76 //-- "number of FATs" have the same layout in the data container as FAT ones. So FAT formatting structure can be used for formatting exFAT.
77 //-- The macro defines if exFAT might not be available.
78 #define EXFAT_MIGHT_NOT_BE_PRESENT
80 /** filesystem #2 name */
81 #ifdef EXFAT_MIGHT_NOT_BE_PRESENT
82 _LIT(KFSName2, "exFAT");
84 #define KFSName2 KFileSystemName_exFAT
85 #include "filesystem_exfat.h"
86 using namespace FileSystem_EXFAT;
92 _LIT(KFsy2, "exfat.fsy"); ///< filesystem #2 *.fsy module name
94 TBool automounter_Loaded = EFalse; ///< ETrue if automounter.fsy is loaded; used for correct cleanup
95 TBool childFs1_Loaded = EFalse; ///< ETrue if child #0 *.fsy is loaded; used for correct cleanup
96 TBool childFs2_Loaded = EFalse; ///< ETrue if child #1 *.fsy is loaded; used for correct cleanup
98 TFSDescriptor orgFsDescriptor; //-- keeps parameters of the original FS
100 //-------------------------------------------------------------------
103 perform some operations to see if the file system works at all
105 void CheckFsOperations()
110 nRes = TheFs.Volume(v);
113 _LIT(KTestDir, "\\directory1\\DIR2\\another directory\\");
116 _LIT(KTestFile, "\\this is a file to test.bin");
117 nRes = CreateCheckableStuffedFile(TheFs, KTestFile, 20376);
120 nRes = VerifyCheckableFile(TheFs, KTestFile);
123 nRes = TheFs.Delete(KTestFile);
128 //-------------------------------------------------------------------
131 Check that FileSystem1 subtype matches one of the expected
133 void CheckSubtype_FS1(const TDesC& aFsSubtype)
135 _LIT(KFatSubType12, "fat12");
136 _LIT(KFatSubType16, "fat16");
137 _LIT(KFatSubType32, "fat32");
139 test(aFsSubtype.CompareF(KFatSubType12) == 0 || aFsSubtype.CompareF(KFatSubType16) == 0 || aFsSubtype.CompareF(KFatSubType32) == 0 );
142 //-------------------------------------------------------------------
145 Check that FileSystem2 subtype matches expected
147 void CheckSubtype_FS2(const TDesC& aFsSubtype)
149 _LIT(KExFatSubType, "exFAT");
150 test(aFsSubtype.CompareF(KExFatSubType) == 0);
154 //-------------------------------------------------------------------
156 Dismounts Currently mounted file system.
158 static TInt DoDismountFS()
163 nRes = TheFs.FileSystemName(fsName, gDriveNum);
166 test.Printf(_L("--- Dismounting FS:%S\n"), &fsName);
167 nRes = TheFs.DismountFileSystem(fsName, gDriveNum);
171 return KErrNone; //-- no file system mounted
174 //-------------------------------------------------------------------
176 Dismounts Currently mounted file system.
178 static void DismountFS()
180 test(DoDismountFS() == KErrNone);
183 //-------------------------------------------------------------------
185 Dismounts Currently mounted file system.
187 static void ForceDismountFS()
189 test.Printf(_L("--- Force dismounting current FS\n"));
191 TheFs.NotifyDismount(gDriveNum, stat, EFsDismountForceDismount);
192 User::WaitForRequest(stat);
193 test(stat.Int() == KErrNone);
198 //-------------------------------------------------------------------
200 Mount the given file system. Mounting file system doesn't mean that it will be usable.
201 For example, KErrCorrupt can be the result if FS doesn't recognise bootsectors etc.
203 @param aFsName file system name
206 static TInt DoMountFS(const TDesC& aFsName)
209 test.Printf(_L("+++ Mounting FS:%S\n"), &aFsName);
211 TFSDescriptor newFsDescriptor = orgFsDescriptor;
212 newFsDescriptor.iFsName = aFsName;
213 test(!newFsDescriptor.iDriveSynch); //-- mount the given FS as asynchronous one, the automounter can't be used on a synchronous drive anyway.
215 nRes = MountFileSystem(TheFs, gDriveNum, newFsDescriptor);
219 test.Printf(_L("++> Error Mounting FS! code:%d\n"), nRes);
223 PrintDrvInfo(TheFs, gDriveNum);
231 //-------------------------------------------------------------------
233 Explicitly mount the "automounter" FS
235 static void Mount_AutomounterFS()
238 DoMountFS(KAutoMounterFSName);
241 //-------------------------------------------------------------------
243 Explicitly mount the FileSystem1
245 static void Mount_FileSystem1()
252 //-------------------------------------------------------------------
254 Explicitly mount the FileSystem2
256 static void Mount_FileSystem2()
262 //-------------------------------------------------------------------
264 Just fill first 32 sectors with zeroes.
265 The volume will require formatting after this.
267 static void CorruptDrive()
270 test.Printf(_L("!!! corrupting the drive...\n"));
273 nRes = rawDisk.Open(TheFs, gDriveNum);
274 test(nRes == KErrNone);
276 TBuf8<512> sectorBuf(512);
280 const TInt KSectors = 32;
283 for(TInt i=0; i<KSectors; ++i)
285 nRes = rawDisk.Write(mediaPos, sectorBuf);
286 test(nRes == KErrNone);
288 mediaPos += sectorBuf.Size();
294 //-------------------------------------------------------------------
298 quick format the volume using all parameter by default
300 static void FormatVolume(TBool aQuickFormat = ETrue)
303 nRes = FormatDrive(TheFs, CurrentDrive(), aQuickFormat);
308 //-------------------------------------------------------------------
309 TInt DoFormatSteps(RFormat& aFormat, TInt& aFmtCnt)
311 TInt nRes = KErrNone;
315 nRes = aFormat.Next(aFmtCnt);
318 test.Printf(_L("RFormat::Next() failed! code:%d\n"), nRes);
326 //-------------------------------------------------------------------
329 initialise test global objects
330 @return EFalse if something goes wrong
335 test.Printf(_L("This test can't be performed in RELEASE mode! Skipping.\n"));
341 //-- store original file system parameters
342 nRes = GetFileSystemDescriptor(TheFs, gDriveNum, orgFsDescriptor);
346 //=======================================
347 //-- define a text propery that will override automounter config string in estart.txt
348 //-- automounter must be able to parse this string.
349 //-- The property key is a drive number being tested
351 const TUint KPropKey = 0; //-- property key
352 _LIT_SECURITY_POLICY_PASS(KTestPropPolicy);
354 nRes = RProperty::Define(KThisTestSID, KPropKey, RProperty::EText, KTestPropPolicy, KTestPropPolicy);
355 test(nRes == KErrNone || nRes == KErrAlreadyExists);
357 //-- set the propery, it will override automounter config from estart.txt.
358 //-- the config string has following format: "<fs_name1>,<fsname2>"
361 cfgBuf.Append(KFSName1);
362 cfgBuf.Append(_L(" , "));
363 cfgBuf.Append(KFSName2);
366 nRes = RProperty::Set(KThisTestSID, KPropKey, cfgBuf);
371 //=======================================
372 //-- we must ensure that all 3 required *.fsy are present and load them.
373 //-- the automounter must have child filesystems loaded before its initialisation.
375 _LIT(KFsyFailure, "can't load '%S', code:%d, the test can't be performed!\n");
378 nRes = TheFs.AddFileSystem(KFsy1);
379 if(nRes != KErrNone && nRes != KErrAlreadyExists)
381 test.Printf(KFsyFailure, &KFsy1, nRes);
384 childFs1_Loaded = ETrue;
388 nRes = TheFs.AddFileSystem(KFsy2);
389 if(nRes != KErrNone && nRes != KErrAlreadyExists)
391 test.Printf(KFsyFailure, &KFsy2, nRes);
394 childFs2_Loaded = ETrue;
397 nRes = TheFs.AddFileSystem(KAutoMounterFsy);
398 if(nRes != KErrNone && nRes != KErrAlreadyExists)
400 test.Printf(KFsyFailure, &KAutoMounterFsy, nRes);
403 automounter_Loaded = ETrue;
407 //=======================================
408 //-- dismount original file system and optional primary extension. Secondary extensions are not supported.
410 test.Printf(_L("Dismounting the original FS:%S, PExt:%S \n"), &orgFsDescriptor.iFsName, &orgFsDescriptor.iPExtName);
412 nRes = TheFs.DismountFileSystem(orgFsDescriptor.iFsName, gDriveNum);
418 //-------------------------------------------------------------------
419 /** destroy test global objects */
420 void DestroyGlobals()
422 test.Printf(_L("Restoring the environment....\n"));
426 //=======================================
427 //-- dismount current filesystem that was used for testing and mount the original filesystem
428 if(orgFsDescriptor.iFsName.Length())
429 {//-- the original file system had been dismounted during test initialisation; dismount whatever we have now
430 test.Printf(_L("Mounting back the original FS:%S, PExt:%S \n"), &orgFsDescriptor.iFsName, &orgFsDescriptor.iPExtName);
434 nRes = TheFs.FileSystemName(fsName, gDriveNum);
435 if(nRes == KErrNone && fsName.CompareF(orgFsDescriptor.iFsName) != KErrNone)
437 nRes = TheFs.DismountFileSystem(fsName, gDriveNum);
441 //-- mount original FS as asynchronous one, the automounter can't be used on a synchronous drive anyway.
442 MountFileSystem(TheFs, gDriveNum, orgFsDescriptor);
448 //=======================================
449 //-- delete test property
450 RProperty::Delete(KThisTestSID, gDriveNum);
452 //=======================================
453 //-- if the original FS wasn't automounter, unload child file systems
454 if(orgFsDescriptor.iFsName.CompareF(KFileSystemName_AutoMounter) != 0)
459 nRes = TheFs.RemoveFileSystem(KFSName1);
460 test(nRes == KErrNone || nRes == KErrInUse); //-- if the FS was used on some drive before test started, It will be KErrInUse
461 childFs1_Loaded = EFalse;
466 nRes = TheFs.RemoveFileSystem(KFSName2);
467 test(nRes == KErrNone || nRes == KErrInUse); //-- if the FS was used on some drive before test started, It will be KErrInUse
468 childFs2_Loaded = EFalse;
472 //-- unload test filesystem modules
473 if(automounter_Loaded)
475 nRes = TheFs.RemoveFileSystem(KAutoMounterFSName); //-- if the FS was used on some drive before test started, It will be KErrInUse
476 test(nRes == KErrNone || nRes == KErrInUse);
477 automounter_Loaded = EFalse;
482 nRes = RemountFS(TheFs, gDriveNum);
483 test(nRes == KErrNone);
490 //-------------------------------------------------------------------
493 Testing basic automounter functionality. Format media with different file systems FS1/FS2, mount automounter and
494 ensure that it recognised and successfully mounts appropriate child file system.
497 1.1 mount "filesystem1" / format volume
498 1.2 check file system name / subtype / functionality
499 1.3 corrupt "filesystem1"
500 1.4 check file system name / subtype
503 2.1 mount "automounter"
504 2.2 check file system name / subtype / functionality (this must correspond to the filesystem1) The "filesystem1" must be recognised
506 3.1 mount "filesystem2" / format volume
507 3.2 check file system name / subtype / functionality
508 3.3 corrupt "filesystem2"
509 3.4 check file system name / subtype
510 3.5 format volume (it will be filesystem2)
512 4.1 mount "automounter"
513 4.2 check file system name / subtype / functionality (this must correspond to the filesystem2) The "filesystem2" must be recognised
516 5. check the list of supported file systems on the drive
518 6.1 corrupt the volume
519 6.2 check that automounter can't recognise it
521 7. restore "filesystem1" / format volume
523 void TestAutomounterBasics()
526 test.Next(_L("Testing automounter basic functionality \n"));
530 TBuf<40> fsSubType(0);
533 //================================================================================
534 //-- 1. mount "filesystem1" / format volume
535 test.Printf(_L("Mounting FileSystem1...\n"));
540 nRes = TheFs.Volume(v);
543 //-- check file system name / subtype etc.
544 nRes = TheFs.FileSystemName(fsName, gDriveNum);
546 test(fsName.CompareF(KFSName1) == 0);
549 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
551 CheckSubtype_FS1(fsSubType);
553 //-- check the list of supported file systems on this drive (there is only 1 FS supported).
554 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, -1);
555 test(nRes == KErrArgument);
558 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem
559 test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0);
562 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
563 test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0);
566 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- there are no more supported FSs
567 test(nRes == KErrNotFound);
569 //-- perform some operation
573 //================================================================================
574 //-- 2. Now we have volume formatted for "filesystem1"; Mount "automounter" and check that the
575 //-- file system on the volume is recognised OK.
576 test.Printf(_L("Mounting Automounter FS and checking its functionality ...\n"));
577 Mount_AutomounterFS();
579 nRes = TheFs.Volume(v);
582 //-- check file system name / subtype etc.
583 nRes = TheFs.FileSystemName(fsName, gDriveNum);
586 //-- the FS Subtype must be the subtype of the recognised child FS
587 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
590 test.Printf(_L("FS name:'%S', FS Subtype:'%S'\n") ,&fsName, &fsSubType);
592 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
593 CheckSubtype_FS1(fsSubType);
597 //================================================================================
598 //-- dismount current file system
599 test.Printf(_L("Dismomounting FileSystem1...\n"));
601 nRes = TheFs.FileSystemName(fsName, gDriveNum);
602 test(nRes == KErrNotFound);
604 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem
605 test(nRes == KErrNotFound);
607 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
608 test(nRes == KErrNotFound);
610 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
611 test(nRes == KErrNotReady);
614 //================================================================================
615 //-- 3. mount "filesystem2" / format volume
616 test.Printf(_L("Mounting FileSystem2...\n"));
621 nRes = TheFs.Volume(v);
624 //-- check file system name / subtype etc.
625 nRes = TheFs.FileSystemName(fsName, gDriveNum);
627 test(fsName.CompareF(KFSName2) == 0);
629 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
631 CheckSubtype_FS2(fsSubType);
633 //-- check the list of supported file systems on this drive (there is only 1 FS supported).
635 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem
636 test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0);
639 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
640 test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0);
643 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- there are no more supported FSs
644 test(nRes == KErrNotFound);
646 //-- perform some operation
650 //================================================================================
651 //-- 4. Now we have volume formatted for "filesystem2"; Mount "automounter" and check that the
652 //-- file system on the volume is recognised OK.
653 test.Printf(_L("Mounting Automounter FS and checking its functionality ...\n"));
654 Mount_AutomounterFS();
656 nRes = TheFs.Volume(v);
659 //-- check file system name / subtype etc.
660 nRes = TheFs.FileSystemName(fsName, gDriveNum);
663 //-- the FS Subtype must be the subtype of the recognised child FS
664 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
667 test.Printf(_L("FS name:'%S', FS Subtype:'%S'\n") ,&fsName, &fsSubType);
669 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
670 CheckSubtype_FS2(fsSubType);
672 //================================================================================
673 //-- 5. check the list of supported file systems on this drive (there must be 2 child FS supported).
674 test.Printf(_L("Getting list of supported by automounter file systems ...\n"));
677 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem
678 test(nRes == KErrNone && fsName.CompareF(KAutoMounterFSName) == 0);
679 test.Printf(_L("Root FS:'%S'\n"), &fsName);
683 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
684 test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0);
687 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- 2nd "child" filesystem
688 test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0);
690 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 2); //-- 3rd "child" filesystem
691 test(nRes == KErrNotFound);
693 //-- get and print out list of all child FS (enumeration example)
697 nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, i);
700 test.Printf(_L("child FS[%d]:'%S'\n"), i, &fsName);
704 test(nRes == KErrNotFound);
710 //-- perform some operation. They will happen on currently active child FS
713 //================================================================================
714 //-- 6. corrupt the media, mount automounter, check that FS is not recognised.
715 test.Printf(_L("Test automounter handling corrupted media.\n"));
717 CorruptDrive(); //-- the active child FS will do this and the root FS will be remounted on first access
719 //-- check file system name / subtype etc.
720 nRes = TheFs.FileSystemName(fsName, gDriveNum);
721 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
724 //-- the FS Subtype query requires mounted and recognised file system. this shall fail
725 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
726 test(nRes == KErrCorrupt);
728 nRes = TheFs.MkDir(_L("\\dir1\\"));
729 test(nRes == KErrCorrupt);
732 //================================================================================
733 //-- 7. restore filesystem on the drive
734 test.Printf(_L("Restoring FileSystem1.\n"));
738 nRes = TheFs.Volume(v);
743 //-------------------------------------------------------------------
746 1.1 mount "filesystem1" / format volume
747 1.2 create and open a file on the volume.
748 1.3 dismount the file system with opened file on it.
750 2. mount "automounter" The "filesystem1" must be recognised
751 2.1 open previously created file (it is still opened by dismounted FS1)
753 3. forcedly dismount the current file system (automounter)
754 4. mount the automounter FS again. check file system name / subtype; The "filesystem1" must be recognised
755 5. try to read a file (see 2.1), using already dismounted mount; it shall result in KErrDismounted.
757 void TestDismounting()
759 test.Next(_L("Testing media dismounting/remounting with automounter FS \n"));
763 TBuf<40> fsSubType(0);
766 //================================================================================
767 //-- 1. mount "filesystem1" / format volume
768 test.Printf(_L("Mounting FileSystem1 and opening a file.\n"));
772 //-- create a file, open it and try to dismount FS
773 _LIT(KTestFile, "\\test_file");
774 nRes = CreateEmptyFile(TheFs, KTestFile, 100);
775 test(nRes == KErrNone);
779 nRes = file.Open(TheFs, KTestFile, 0);
780 test(nRes == KErrNone);
782 //TheFs.SetDebugRegister(KFSERV);
784 test.Printf(_L("dismounting FileSystem1 with a file opened.\n"));
785 nRes = DoDismountFS();
786 test(nRes == KErrInUse);
790 //================================================================================
791 //-- 2. mount "automounter", previous FS must be recognised and set as an active child
792 Mount_AutomounterFS();
794 //-- check file system name / subtype etc.
795 nRes = TheFs.FileSystemName(fsName, gDriveNum);
796 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
799 //-- the FS Subtype must be the subtype of the recognised child FS
800 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
802 CheckSubtype_FS1(fsSubType);
804 //-- open the previously created file
805 nRes = file.Open(TheFs, KTestFile, 0);
806 test(nRes == KErrNone);
808 //TheFs.SetDebugRegister(KFSERV);
810 nRes = DoDismountFS();
811 test(nRes == KErrInUse); //-- opened file belongs to the child FS, actually.
814 //================================================================================
815 //-- 3. force dismounting the file system, this will leave hanging dismounted mount associated with this drive.
816 test.Printf(_L("Force dismounting the file system.\n"));
819 //TheFs.SetDebugRegister(KFSERV);
821 //================================================================================
822 //-- 4. mount "automounter" again, this will create another instance of mount corresponding to the filesystem1
823 Mount_AutomounterFS();
825 //-- check file system name / subtype etc.
826 nRes = TheFs.FileSystemName(fsName, gDriveNum);
827 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
830 //-- the FS Subtype must be the subtype of the recognised child FS
831 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
833 CheckSubtype_FS1(fsSubType);
835 //================================================================================
836 //-- 5. try to read a file using already dead mount
837 nRes = file.Read(0, buf, 2);
838 test(nRes == KErrDisMounted);
840 //-- this will cause the forcedly dismounted hanging mount to self-destruct
844 //-- open the previously created file using current alive mount.
845 nRes = file.Open(TheFs, KTestFile, 0);
846 test(nRes == KErrNone);
847 nRes = file.Read(0, buf, 2);
848 test(nRes == KErrNone);
853 //TheFs.SetDebugRegister(0x00);
856 //-------------------------------------------------------------------
858 Testing legacy RFormat API in the case when the volume has "automounter" file system bound.
859 The formatting is performed without specifying any parameters, i.e. "all by default"
861 If the automounter recognises file system on the volume and successfully mounts it, the
862 default formatting must be transparent, i.e. the appropriate child FS will perform it.
864 If the automounter can't recognise the filesystem on the volume because of volume corruption or if this FS is unknown to it,
865 the "default" formatting will fail with "KErrNotFound"
867 void TestAutomounterDefaultFormatting()
869 test.Next(_L("Testing media formatting with default parameters. Automounter FS\n"));
873 TBuf<40> fsSubType(0);
876 //================================================================================
877 //-- 1. mount "filesystem1" / format volume
881 //================================================================================
882 //-- 2. mount "automounter", previous FS must be recognised and set as an active child
883 Mount_AutomounterFS();
885 //-- check file system name / subtype etc.
886 nRes = TheFs.FileSystemName(fsName, gDriveNum);
887 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
890 //-- the FS Subtype must be the subtype of the recognised child FS
891 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
893 CheckSubtype_FS1(fsSubType);
895 //================================================================================
896 //-- 3. format the drive with all default parameters; the current active child FS shall be used
897 //-- check that we still have automounter as "root" FS and the same active child
900 //-- check file system name / subtype etc.
901 nRes = TheFs.FileSystemName(fsName, gDriveNum);
902 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
905 //-- the FS Subtype must be the subtype of the recognised child FS
906 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
908 CheckSubtype_FS1(fsSubType);
910 //-- perform some operations
912 test.Printf(_L("default formatting for FS:'%S', subtype:'%S' OK!\n"), &fsName, &fsSubType);
914 //================================================================================
915 //-- 3. mount "filesystem2" / format volume
919 //================================================================================
920 //-- 4. mount "automounter", previous FS must be recognised and set as an active child
921 Mount_AutomounterFS();
923 //-- check file system name / subtype etc.
924 nRes = TheFs.FileSystemName(fsName, gDriveNum);
925 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
928 //-- the FS Subtype must be the subtype of the recognised child FS
929 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
931 CheckSubtype_FS2(fsSubType);
933 //================================================================================
934 //-- 5. format the drive with all default parameters; the current active child FS shall be used
935 //-- check that we still have automounter as "root" FS and the same active child
938 //-- check file system name / subtype etc.
939 nRes = TheFs.FileSystemName(fsName, gDriveNum);
940 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
943 //-- the FS Subtype must be the subtype of the recognised child FS
944 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
946 CheckSubtype_FS2(fsSubType);
948 //-- perform some operations
950 test.Printf(_L("default formatting for FS:'%S', subtype:'%S' OK!\n"), &fsName, &fsSubType);
952 //================================================================================
953 //-- 6. corrupt the media, mount automounter, check that FS is not recognised.
954 //-- default formatting shall fail, because automounter can't chose appropriate child FS
956 CorruptDrive(); //-- the active child FS will do this and the root FS will be remounted on first access
958 //-- check file system name / subtype etc.
959 nRes = TheFs.FileSystemName(fsName, gDriveNum);
960 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
963 //-- the FS Subtype query requires mounted and recognised file system. this shall fail
964 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
965 test(nRes == KErrCorrupt);
967 //-- try default formatting; this shall fail with a special error code
968 nRes = FormatDrive(TheFs, CurrentDrive(), ETrue);
969 test(nRes == KErrNotFound);
971 //-- try special formatting without any parameters, it shall also fail.
973 TUint fmtMode = EQuickFormat | ESpecialFormat;
976 drivePath.Format(_L("%C:\\"), gDriveNum+'A');
978 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
979 test(nRes==KErrNotFound);
984 //================================================================================
985 //-- 7. restore filesystem on the drive, try formatting with specifying ESpecialFormat flag, but without any formatting parameters
986 //-- just to check that it works (it will not work on SD cards that do not allow ESpecialFormat)
987 test.Printf(_L("Restoring FileSystem1 and use special format without any parameters\n"));
993 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
994 test(nRes==KErrNone);
996 nRes = DoFormatSteps(format, fmtCnt);
997 test(nRes==KErrNone);
1003 //-- check file system name / subtype etc.
1004 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1005 test_KErrNone(nRes);
1006 test(fsName.CompareF(KFSName1) == 0);
1009 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1010 test_KErrNone(nRes);
1011 CheckSubtype_FS1(fsSubType);
1018 //-------------------------------------------------------------------
1020 Testing the use case when there is "automounter" FS bound to the drive and RFormat API that allows specifying
1021 the file system name that we want to put on the volume.
1023 It must be possible:
1024 - format the volume without specifying FS name at all (the currently active child FS will be used)
1025 - format the volume with specifying FS name that belongs to one of the supported child FS. The volume shall be formatted with this FS.
1026 - format the volume with specifying incorrect FS name (not supported) the RFormat::Open() must fail with KErrNotSupported.
1028 - 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.
1029 - 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.
1031 void TestAutomounterFormatting_FsNameSpecified()
1033 test.Next(_L("Testing formatting API that allows specifying particular FS. Automounter FS.\n"));
1038 TBuf<40> fsSubType(0);
1041 drivePath.Format(_L("%C:\\"), gDriveNum+'A');
1044 TUint fmtMode = EQuickFormat | ESpecialFormat;
1047 TVolFormatParamBuf fmtParamBuf;
1048 TVolFormatParam& fmtParam = fmtParamBuf();
1050 //_LIT(KTestFile, "\\this is a test file");
1052 //================================================================================
1053 //-- 0. prepare the volume
1054 Mount_FileSystem1();
1055 FormatVolume(); //-- old API, formatting with all parameters by default
1058 //================================================================================
1059 //-- 0.1 mount "automounter", previous FS must be recognised and set as an active child
1060 Mount_AutomounterFS();
1062 //-- check file system name / subtype etc.
1063 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1064 test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
1065 test_KErrNone(nRes);
1067 //-- the FS Subtype must be the subtype of the recognised child FS
1068 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1069 test_KErrNone(nRes);
1070 CheckSubtype_FS1(fsSubType);
1072 //================================================================================
1074 //-- 1.1 format the volume without specifying any parameters at all, the currently active child FS shall be used
1075 test.Printf(_L("format the volume without specifying any parameters at all\n"));
1077 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
1078 test(nRes==KErrNone);
1080 nRes = DoFormatSteps(format, fmtCnt);
1081 test(nRes==KErrNone);
1085 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1086 test(fsName.CompareF(KAutoMounterFSName) == 0);
1088 //-- the FS Subtype must be the subtype of the recognised child FS
1089 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1090 test_KErrNone(nRes);
1091 CheckSubtype_FS1(fsSubType);
1094 //-- 1.2 format the volume without specifying the FS name, the currently active child FS shall be used
1095 test.Printf(_L("format the volume without specifying the FS name\n"));
1096 fmtParam.Init(); //-- reset all data
1097 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1098 test(nRes==KErrNone);
1100 nRes = DoFormatSteps(format, fmtCnt);
1101 test(nRes==KErrNone);
1105 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1106 test(fsName.CompareF(KAutoMounterFSName) == 0);
1108 //-- the FS Subtype must be the subtype of the recognised child FS
1109 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1110 test_KErrNone(nRes);
1111 CheckSubtype_FS1(fsSubType);
1114 CheckFsOperations();
1116 //================================================================================
1117 //-- 2. format the volume specifying _second_ child FS name
1118 test.Printf(_L("format the volume specifying second child FS name\n"));
1119 fmtParam.Init(); //-- reset all data
1120 fmtParam.SetFileSystemName(KFSName2);
1121 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1122 test(nRes==KErrNone);
1124 nRes =DoFormatSteps(format, fmtCnt);
1125 test(nRes==KErrNone);
1129 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1130 test(fsName.CompareF(KAutoMounterFSName) == 0);
1132 //-- the FS Subtype must be the subtype of the recognised child FS
1133 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1134 test_KErrNone(nRes);
1135 CheckSubtype_FS2(fsSubType);
1137 CheckFsOperations();
1140 //================================================================================
1141 //-- 3. format the volume specifying _first_ child FS name
1142 fmtParam.Init(); //-- reset all data
1143 fmtParam.SetFileSystemName(KFSName1);
1144 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1145 test(nRes==KErrNone);
1147 nRes =DoFormatSteps(format, fmtCnt);
1148 test(nRes==KErrNone);
1152 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1153 test(fsName.CompareF(KAutoMounterFSName) == 0);
1155 //-- the FS Subtype must be the subtype of the recognised child FS
1156 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1157 test_KErrNone(nRes);
1158 CheckSubtype_FS1(fsSubType);
1160 CheckFsOperations();
1163 //================================================================================
1164 //-- 4. try formatting the volume specifying wrond child FS name
1165 fmtParam.Init(); //-- reset all data
1167 fmtParam.SetFileSystemName(KAutoMounterFSName); //-- it might have some strange consequences :)
1168 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1169 test(nRes==KErrNotSupported);
1172 fmtParam.SetFileSystemName(_L("wrong FS"));
1173 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1174 test(nRes==KErrNotSupported);
1178 //================================================================================
1179 //-- 5. corrupt the volume and try formatting without specyfying FS name
1182 fmtParam.Init(); //-- reset all data
1183 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1184 test(nRes==KErrNotFound); //-- the meaning: "can't find the appropriate file system to put onto the volume"
1187 //test.Printf(_L("#### T_a #1 res:%d\n"), nRes);
1189 fmtParam.SetFileSystemName(KAutoMounterFSName); //-- it might have some strange consequences :)
1190 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1191 //test.Printf(_L("#### T_a #2 res:%d\n"), nRes);
1193 test(nRes == KErrNotSupported || nRes==KErrNotFound);
1197 fmtParam.SetFileSystemName(_L("wrong FS"));
1198 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1199 test(nRes==KErrNotSupported);
1202 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
1203 test(nRes==KErrNotFound); //-- the meaning: "can't find the appropriate file system to put onto the volume"
1207 //--------------------------------------------------------------------------------
1208 //-- 5.1 format the volume with specifying child FS2 explicitly
1209 fmtParam.Init(); //-- reset all data
1210 fmtParam.SetFileSystemName(KFSName2);
1211 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1212 test(nRes==KErrNone);
1214 nRes =DoFormatSteps(format, fmtCnt);
1215 test(nRes==KErrNone);
1219 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1220 test(fsName.CompareF(KAutoMounterFSName) == 0);
1222 //-- the FS Subtype must be the subtype of the recognised child FS
1223 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1224 test_KErrNone(nRes);
1225 CheckSubtype_FS2(fsSubType);
1227 CheckFsOperations();
1229 //--------------------------------------------------------------------------------
1230 //-- 5.2 corrupt the volume and format with specifying child FS1 explicitly
1233 fmtParam.Init(); //-- reset all data
1234 fmtParam.SetFileSystemName(KFSName1);
1235 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1236 test(nRes==KErrNone);
1238 nRes =DoFormatSteps(format, fmtCnt);
1239 test(nRes==KErrNone);
1243 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1244 test(fsName.CompareF(KAutoMounterFSName) == 0);
1246 //-- the FS Subtype must be the subtype of the recognised child FS
1247 nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
1248 test_KErrNone(nRes);
1249 CheckSubtype_FS1(fsSubType);
1251 CheckFsOperations();
1254 //-------------------------------------------------------------------
1256 Testing the use case when we have some rigidly bound FS to the drive (e.g "FAT")
1257 and RFormat API that allows specifying the file system name that we want to put on the volume.
1259 It must be possible:
1260 - format the volume without specifying FS name at all (the bound FS will be used)
1261 - format the volume without specifying FS name at all when the volume is corrupted (the bound FS will be used)
1262 - format the volume with specifying FS name that is the same as the bound FS has.
1264 If the specified file system name differs from the name that the bound FS has, the RFormat::Open() fails with KErrNotSupported.
1267 void TestFixedFsFormatting_FsNameSpecified()
1269 test.Next(_L("Testing RFormat API that allows specifying particular FS name for fixed FS.\n"));
1275 drivePath.Format(_L("%C:\\"), gDriveNum+'A');
1278 TUint fmtMode = EQuickFormat | ESpecialFormat;
1281 TVolFormatParamBuf fmtParamBuf;
1282 TVolFormatParam& fmtParam = fmtParamBuf();
1284 _LIT(KTestFile, "\\this is a test file");
1286 //================================================================================
1287 //-- 0. prepare the volume
1288 test.Printf(_L("fmt: ESpecialFormat, no parameters specified\n"));
1289 Mount_FileSystem1();
1291 //-- 0.1 format the volume with ESpecialFormat and without any parameters at all
1292 test(fmtMode & ESpecialFormat);
1293 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
1294 test(nRes==KErrNone);
1296 nRes = DoFormatSteps(format, fmtCnt);
1297 test(nRes==KErrNone);
1302 //================================================================================
1303 //-- 1. format the volume with default parameters without specifying file system name. The volume is already formatted with FS1
1304 test.Printf(_L("fmt: ESpecialFormat, no FS name specified #1\n"));
1305 fmtParam.Init(); //-- reset all data
1306 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1307 test(nRes==KErrNone);
1309 nRes =DoFormatSteps(format, fmtCnt);
1310 test(nRes==KErrNone);
1314 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1315 test(fsName.CompareF(KFSName1) == 0);
1316 CheckFsOperations();
1318 //-- 1.1 corrupt the media and check formatting without specifying FS name.
1319 //-- The file system bount to this drive shall be used.
1322 test.Printf(_L("fmt: ESpecialFormat, no FS name specified #2\n"));
1324 fmtParam.Init(); //-- reset all data
1325 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1326 test(nRes==KErrNone);
1328 nRes =DoFormatSteps(format, fmtCnt);
1329 test(nRes==KErrNone);
1333 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1334 test(fsName.CompareF(KFSName1) == 0);
1335 CheckFsOperations();
1337 //-- 1.2 the media is already formatted with FS1, try to specify other file system name for formatting.
1338 //-- this shall fail with KErrNotSupported, the volume must not be affected
1339 test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #1\n"));
1341 nRes = CreateCheckableStuffedFile(TheFs, KTestFile, 17384);
1342 test(nRes==KErrNone);
1344 fmtParam.Init(); //-- reset all data
1345 fmtParam.SetFileSystemName(_L("some filesystem name"));
1347 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1348 test(nRes==KErrNotSupported);
1351 test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #2\n"));
1352 fmtParam.Init(); //-- reset all data
1353 fmtParam.SetFileSystemName(KFSName2);
1355 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1356 test(nRes==KErrNotSupported);
1360 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1361 test(fsName.CompareF(KFSName1) == 0);
1362 CheckFsOperations();
1364 nRes = VerifyCheckableFile(TheFs, KTestFile);
1365 test(nRes==KErrNone);
1368 //-- 1.3 corrupt the media and check formatting with the FS Name that doesn't match the FS bound to this drive
1369 //-- this shall fail
1370 test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #3\n"));
1373 fmtParam.Init(); //-- reset all data
1374 fmtParam.SetFileSystemName(_L("some filesystem name"));
1376 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1377 test(nRes==KErrNotSupported);
1380 test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #4\n"));
1381 fmtParam.Init(); //-- reset all data
1382 fmtParam.SetFileSystemName(KFSName2);
1384 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1385 test(nRes==KErrNotSupported);
1388 //-- 1.4 specify the correct file system name (bound to this drive) formatting must succeed
1389 test.Printf(_L("fmt: ESpecialFormat, specifying correct FS name\n"));
1390 fmtParam.Init(); //-- reset all data
1391 fmtParam.SetFileSystemName(KFSName1);
1392 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1393 test(nRes==KErrNone);
1395 nRes = DoFormatSteps(format, fmtCnt);
1396 test(nRes==KErrNone);
1400 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1401 test(fsName.CompareF(KFSName1) == 0);
1402 CheckFsOperations();
1407 //-------------------------------------------------------------------
1409 Test formatting FAT file system with some specific parameters, like sector per cluster etc.
1410 Note that some media types (like SD cards) do not support such type of formatting.
1412 void TestFormatting_FsName_Parameters_FAT()
1414 using namespace FileSystem_FAT;
1416 test.Next(_L("Testing TVolFormatParam_FAT formatting API\n"));
1422 drivePath.Format(_L("%C:\\"), gDriveNum+'A');
1425 TUint fmtMode = EQuickFormat | ESpecialFormat;
1428 //================================================================================
1429 //-- 0. prepare the volume
1430 Mount_FileSystem1();
1431 FormatVolume(); //-- old API, formatting with all parameters by default
1433 //================================================================================
1434 //-- 1.0 simple unit test for TVolFormatParam_FAT
1435 TVolFormatParam_FATBuf fmtParamBuf_FAT;
1436 TVolFormatParam_FAT& fmtParam_FAT = fmtParamBuf_FAT();
1438 fmtParam_FAT.SetFatSubType(EFat32);
1439 test(fmtParam_FAT.FatSubType() == EFat32);
1441 fmtParam_FAT.SetFatSubType(EFat12);
1442 test(fmtParam_FAT.FatSubType() == EFat12);
1444 fmtParam_FAT.SetFatSubType(EFat16);
1445 test(fmtParam_FAT.FatSubType() == EFat16);
1447 fmtParam_FAT.SetFatSubType(ENotSpecified);
1448 test(fmtParam_FAT.FatSubType() == ENotSpecified);
1450 fmtParam_FAT.SetFatSubType(KFSSubType_FAT32);
1451 test(fmtParam_FAT.FatSubType() == EFat32);
1453 fmtParam_FAT.SetFatSubType(KFSSubType_FAT12);
1454 test(fmtParam_FAT.FatSubType() == EFat12);
1456 fmtParam_FAT.SetFatSubType(KFSSubType_FAT16);
1457 test(fmtParam_FAT.FatSubType() == EFat16);
1460 fmtParam_FAT.SetSectPerCluster(64);
1461 test(fmtParam_FAT.SectPerCluster()==64);
1463 fmtParam_FAT.SetNumFATs(1);
1464 test(fmtParam_FAT.NumFATs()==1);
1466 fmtParam_FAT.SetReservedSectors(13);
1467 test(fmtParam_FAT.ReservedSectors()==13);
1470 fmtParam_FAT.Init();
1471 test(fmtParam_FAT.FatSubType() == ENotSpecified);
1472 test(fmtParam_FAT.SectPerCluster() == 0);
1473 test(fmtParam_FAT.NumFATs()==0);
1474 test(fmtParam_FAT.ReservedSectors()==0);
1477 //--- formatting FAT without specifying any parameters. This shall always succeed
1478 test.Printf(_L("fmt: using TVolFormatParam_FAT, no parameters.\n"));
1480 fmtParam_FAT.Init();
1482 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf_FAT);
1483 test(nRes==KErrNone);
1485 nRes = DoFormatSteps(format, fmtCnt);
1486 test(nRes==KErrNone);
1490 //-- formatting FAT with specifying some parameters. This may fail because the media doesn't support overriding FAT parameters
1491 //-- or because this parameters combination isn't compatible with the volume geometry.
1493 test.Printf(_L("fmt: using TVolFormatParam_FAT, some FAT specific parameters.\n"));
1494 fmtParam_FAT.SetFatSubType(EFat32);
1495 fmtParam_FAT.SetSectPerCluster(1);
1496 fmtParam_FAT.SetNumFATs(1);
1497 fmtParam_FAT.SetReservedSectors(13);
1499 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf_FAT);
1500 test(nRes==KErrNone);
1502 nRes = DoFormatSteps(format, fmtCnt);
1503 if(nRes != KErrNone)
1505 test.Printf(_L("formatting failed. reason code:%d\n"), nRes);
1510 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1511 test(fsName.CompareF(KFSName1) == 0);
1513 CheckFsOperations();
1517 //-------------------------------------------------------------------
1519 Test formatting FAT file system with some specific parameters, like sector per cluster etc.
1520 Note that some media types (like SD cards) do not support such type of formatting.
1523 void TestFormatting_FsName_Parameters_exFAT()
1527 test.Next(_L("Testing TVolFormatParam_exFAT formatting API\n"));
1533 drivePath.Format(_L("%C:\\"), gDriveNum+'A');
1536 TUint fmtMode = EQuickFormat | ESpecialFormat;
1540 //================================================================================
1541 //-- 0. prepare the volume
1542 Mount_FileSystem2();
1543 FormatVolume(); //-- old API, formatting with all parameters by default
1545 //================================================================================
1546 //-- 1.0 simple unit test for TVolFormatParam_FAT
1548 #ifndef EXFAT_MIGHT_NOT_BE_PRESENT
1549 TVolFormatParam_exFATBuf fmtParamBuf;
1550 TVolFormatParam_exFAT& fmtParam = fmtParamBuf();
1552 //-- see the comments to "EXFAT_MIGHT_NOT_BE_PRESENT" macro definition
1553 TVolFormatParam_FATBuf fmtParamBuf;
1554 TVolFormatParam_FAT& fmtParam= fmtParamBuf();
1558 fmtParam.SetSectPerCluster(64);
1559 test(fmtParam.SectPerCluster()==64);
1561 fmtParam.SetSectPerCluster(14);
1562 test(fmtParam.SectPerCluster()==14);
1564 fmtParam.SetNumFATs(1);
1565 test(fmtParam.NumFATs()==1);
1567 fmtParam.SetNumFATs(2);
1568 test(fmtParam.NumFATs()==2);
1571 test(fmtParam.SectPerCluster() == 0);
1572 test(fmtParam.NumFATs()==0);
1575 //--- formatting exFAT without specifying any parameters. This shall always succeed
1576 test.Printf(_L("fmt: using TVolFormatParam_exFAT, no parameters.\n"));
1579 #ifdef EXFAT_MIGHT_NOT_BE_PRESENT
1580 //-- need to forcedly set exFAT FS name, because fmtParam.Init(); set it to "FAT"
1581 ((TVolFormatParam&)fmtParam).SetFileSystemName(KFSName2);
1584 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1585 test(nRes==KErrNone);
1587 nRes = DoFormatSteps(format, fmtCnt);
1588 test(nRes==KErrNone);
1592 //-- formatting exFAT with specifying some parameters. This may fail because the media doesn't support overriding FAT parameters
1593 //-- or because this parameters combination isn't compatible with the volume geometry.
1595 test.Printf(_L("fmt: using TVolFormatParam_exFAT, some exFAT specific parameters.\n"));
1597 fmtParam.SetSectPerCluster(1);
1598 fmtParam.SetNumFATs(2);
1600 nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
1601 test(nRes==KErrNone);
1603 nRes = DoFormatSteps(format, fmtCnt);
1604 if(nRes != KErrNone)
1606 test.Printf(_L("formatting failed. reason code:%d\n"), nRes);
1611 nRes = TheFs.FileSystemName(fsName, gDriveNum);
1612 test(fsName.CompareF(KFSName2) == 0);
1614 CheckFsOperations();
1617 //-------------------------------------------------------------------
1623 //-- set up console output
1624 Fat_Test_Utils::SetConsole(test.Console());
1627 //-- automounter has a special debug interface allowing to control child file ssytems mounting in _DEBUG mode only
1628 test.Printf(_L("Skipping the test in the Release build! \n"));
1632 TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum);
1633 test(nRes==KErrNone);
1636 //-------------------------------------
1638 PrintDrvInfo(TheFs, gDriveNum);
1641 nRes = TheFs.Volume(v);
1642 test(nRes==KErrNone);
1643 if(v.iDrive.iMediaAtt & KMediaAttVariableSize)
1645 test.Printf(_L("Skipping. Internal ram drive not tested.\n"));
1649 if(v.iDrive.iType != EMediaHardDisk || !(v.iDrive.iDriveAtt & KDriveAttRemovable))
1651 test.Printf(_L("The drive shall be removable and the media type EMediaHardDisk. Skipping.\n"));
1656 //-------------------------------------
1661 TestAutomounterBasics();
1663 TestFixedFsFormatting_FsNameSpecified();
1665 TestAutomounterDefaultFormatting();
1666 TestAutomounterFormatting_FsNameSpecified();
1668 TestFormatting_FsName_Parameters_FAT();
1669 TestFormatting_FsName_Parameters_exFAT();
1672 //-------------------------------------