os/kernelhwsrv/kerneltest/f32test/filesystem/automounter/t_automounter.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // 
    15 // Testing "automounter" filesystem plugin functionality. 
    16 //
    17 //
    18 
    19 /**
    20  @file
    21 */
    22 
    23 #define __E32TEST_EXTENSION__
    24 
    25 #include <f32file.h>
    26 #include <e32test.h>
    27 #include <e32math.h>
    28 #include <e32property.h>
    29 #include <f32dbg.h>
    30 
    31 #include "filesystem_fat.h"
    32 #include "filesystem_automounter.h" 
    33 
    34 
    35 #include "t_server.h"
    36 #include "fat_utils.h"
    37 
    38 using namespace Fat_Test_Utils;
    39 
    40 
    41 
    42 
    43 RTest test(_L("T_Automounter"));
    44 
    45 static TInt     gDriveNum=-1; ///< drive number we are dealing with
    46 
    47 //-------------------------------------------------------------------
    48 //-- the debug test property string can be used to control automounter in debug mode.
    49 const TUid KThisTestSID={0x10210EB3}; ///< this EXE SID
    50 
    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.
    55 
    56 /** automounter filesystem name */
    57 #define KAutoMounterFSName KFileSystemName_AutoMounter
    58 _LIT(KAutoMounterFsy,    "automounter.fsy");    ///< automounter *.fsy module name
    59 
    60 
    61 //-- FAT is used as a child filesystem #0
    62 
    63 /**  filesystem #1 name */
    64 #define KFSName1 KFileSystemName_FAT
    65 
    66 #if defined(__WINS__) //-- FAT fsy name is a mess.
    67 _LIT(KFsy1, "efat32.fsy");
    68 #else
    69 _LIT(KFsy1, "elocal.fsy");
    70 #endif    
    71     
    72 
    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
    79 
    80 /** filesystem #2 name */
    81 #ifdef EXFAT_MIGHT_NOT_BE_PRESENT
    82     _LIT(KFSName2, "exFAT");
    83 #else
    84     #define KFSName2 KFileSystemName_exFAT
    85     #include "filesystem_exfat.h" 
    86     using namespace FileSystem_EXFAT;
    87 #endif
    88 
    89 
    90 
    91 
    92 _LIT(KFsy2, "exfat.fsy"); ///< filesystem #2 *.fsy module name
    93 
    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
    97 
    98 TFSDescriptor   orgFsDescriptor; //-- keeps parameters of the original FS
    99 
   100 //-------------------------------------------------------------------
   101 
   102 /**
   103     perform some operations to see if the file system works at all
   104 */
   105 void CheckFsOperations()
   106 {
   107     TInt nRes;
   108 
   109     TVolumeInfo v;
   110     nRes = TheFs.Volume(v);
   111     test_KErrNone(nRes);
   112 
   113     _LIT(KTestDir, "\\directory1\\DIR2\\another directory\\");
   114     MakeDir(KTestDir);
   115 
   116     _LIT(KTestFile, "\\this is a file to test.bin");
   117     nRes = CreateCheckableStuffedFile(TheFs, KTestFile, 20376);
   118     test_KErrNone(nRes);
   119 
   120     nRes = VerifyCheckableFile(TheFs, KTestFile);
   121     test_KErrNone(nRes);
   122 
   123     nRes = TheFs.Delete(KTestFile);
   124     test_KErrNone(nRes);
   125 
   126 }
   127 
   128 //-------------------------------------------------------------------
   129 
   130 /**
   131     Check that FileSystem1 subtype matches one of the expected
   132 */
   133 void CheckSubtype_FS1(const TDesC& aFsSubtype)
   134 {
   135     _LIT(KFatSubType12, "fat12");
   136     _LIT(KFatSubType16, "fat16");
   137     _LIT(KFatSubType32, "fat32");
   138 
   139     test(aFsSubtype.CompareF(KFatSubType12) == 0 || aFsSubtype.CompareF(KFatSubType16) == 0 || aFsSubtype.CompareF(KFatSubType32) == 0 );
   140 }
   141 
   142 //-------------------------------------------------------------------
   143 
   144 /**
   145     Check that FileSystem2 subtype matches expected
   146 */
   147 void CheckSubtype_FS2(const TDesC& aFsSubtype)
   148 {
   149     _LIT(KExFatSubType, "exFAT");
   150     test(aFsSubtype.CompareF(KExFatSubType) == 0);
   151 }
   152 
   153 
   154 //-------------------------------------------------------------------
   155 /**
   156     Dismounts Currently mounted file system.
   157 */
   158 static TInt DoDismountFS()
   159 {
   160     TBuf<40> fsName(0);
   161     TInt nRes;
   162    
   163     nRes = TheFs.FileSystemName(fsName, gDriveNum);
   164     if(nRes == KErrNone)
   165     {
   166         test.Printf(_L("--- Dismounting FS:%S\n"), &fsName);
   167         nRes = TheFs.DismountFileSystem(fsName, gDriveNum);
   168         return nRes;
   169     }
   170 
   171     return KErrNone; //-- no file system mounted
   172 }
   173 
   174 //-------------------------------------------------------------------
   175 /**
   176     Dismounts Currently mounted file system.
   177 */
   178 static void DismountFS()
   179 {
   180     test(DoDismountFS() == KErrNone);
   181 }
   182 
   183 //-------------------------------------------------------------------
   184 /**
   185     Dismounts Currently mounted file system.
   186 */
   187 static void ForceDismountFS()
   188 {
   189     test.Printf(_L("--- Force dismounting current FS\n"));
   190     TRequestStatus stat;
   191     TheFs.NotifyDismount(gDriveNum, stat, EFsDismountForceDismount); 
   192     User::WaitForRequest(stat);         
   193     test(stat.Int() == KErrNone);
   194 }
   195 
   196 
   197 
   198 //-------------------------------------------------------------------
   199 /**
   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. 
   202 
   203     @param  aFsName file system name
   204     @return error code
   205 */
   206 static TInt DoMountFS(const TDesC& aFsName)
   207 {
   208     TInt nRes;
   209     test.Printf(_L("+++ Mounting FS:%S\n"), &aFsName);
   210 
   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.
   214 
   215     nRes = MountFileSystem(TheFs, gDriveNum, newFsDescriptor);
   216     
   217     if(nRes != KErrNone)
   218     {
   219         test.Printf(_L("++> Error Mounting FS! code:%d\n"), nRes);
   220     }
   221     else
   222     {
   223         PrintDrvInfo(TheFs, gDriveNum);
   224     }
   225 
   226 
   227     return nRes;
   228 }
   229 
   230 
   231 //-------------------------------------------------------------------
   232 /**
   233     Explicitly mount the "automounter" FS
   234 */
   235 static void Mount_AutomounterFS()
   236 {
   237     DismountFS();
   238     DoMountFS(KAutoMounterFSName);
   239 }
   240 
   241 //-------------------------------------------------------------------
   242 /**
   243     Explicitly mount the FileSystem1
   244 */
   245 static void Mount_FileSystem1()
   246 {
   247     DismountFS();
   248     DoMountFS(KFSName1);
   249 
   250 }
   251 
   252 //-------------------------------------------------------------------
   253 /**
   254     Explicitly mount the FileSystem2
   255 */
   256 static void Mount_FileSystem2()
   257 {
   258     DismountFS();
   259     DoMountFS(KFSName2);
   260 }
   261 
   262 //-------------------------------------------------------------------
   263 /**
   264     Just fill first 32 sectors with zeroes.
   265     The volume will require formatting after this.
   266 */
   267 static void CorruptDrive()
   268 {
   269     TInt nRes;
   270     test.Printf(_L("!!! corrupting the drive...\n"));
   271 
   272     RRawDisk  rawDisk;
   273     nRes = rawDisk.Open(TheFs, gDriveNum);
   274     test(nRes == KErrNone);
   275 
   276     TBuf8<512>  sectorBuf(512);
   277 
   278     sectorBuf.FillZ();
   279 
   280     const TInt  KSectors = 32;
   281     TInt64      mediaPos = 0;
   282 
   283     for(TInt i=0; i<KSectors; ++i)
   284     {
   285         nRes = rawDisk.Write(mediaPos, sectorBuf);
   286         test(nRes == KErrNone);
   287         
   288         mediaPos += sectorBuf.Size();
   289     }
   290 
   291     rawDisk.Close();
   292 }
   293 
   294 //-------------------------------------------------------------------
   295 
   296 
   297 /**
   298     quick format the volume using all parameter by default
   299 */
   300 static void FormatVolume(TBool aQuickFormat = ETrue)
   301 {
   302     TInt nRes;
   303     nRes = FormatDrive(TheFs, CurrentDrive(), aQuickFormat);
   304     test_KErrNone(nRes);
   305 }
   306 
   307 
   308 //-------------------------------------------------------------------
   309 TInt DoFormatSteps(RFormat& aFormat, TInt& aFmtCnt)
   310 {
   311     TInt nRes = KErrNone;
   312 
   313     while(aFmtCnt)
   314     {
   315         nRes = aFormat.Next(aFmtCnt);
   316         if(nRes != KErrNone)
   317         {
   318             test.Printf(_L("RFormat::Next() failed! code:%d\n"), nRes);
   319             break;
   320         }
   321     }
   322 
   323     return nRes;
   324 }
   325 
   326 //-------------------------------------------------------------------
   327 
   328 /** 
   329     initialise test global objects 
   330     @return EFalse if something goes wrong
   331 */
   332 TBool InitGlobals()
   333 {
   334 #ifndef _DEBUG
   335     test.Printf(_L("This test can't be performed in RELEASE mode! Skipping.\n"));
   336     test(0);
   337 #endif
   338     
   339     TInt nRes;
   340 
   341     //-- store original file system parameters
   342     nRes = GetFileSystemDescriptor(TheFs, gDriveNum, orgFsDescriptor);
   343     test_KErrNone(nRes);
   344 
   345 
   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
   350     {
   351         const TUint KPropKey = 0; //-- property key
   352         _LIT_SECURITY_POLICY_PASS(KTestPropPolicy);
   353         
   354         nRes = RProperty::Define(KThisTestSID, KPropKey, RProperty::EText, KTestPropPolicy, KTestPropPolicy);
   355         test(nRes == KErrNone || nRes == KErrAlreadyExists);
   356 
   357         //-- set the propery, it will override automounter config from estart.txt. 
   358         //-- the config string has following format: "<fs_name1>,<fsname2>"
   359     
   360         TBuf8<50> cfgBuf(0);
   361         cfgBuf.Append(KFSName1);
   362         cfgBuf.Append(_L(" , "));
   363         cfgBuf.Append(KFSName2);
   364   
   365     
   366         nRes = RProperty::Set(KThisTestSID, KPropKey, cfgBuf);
   367         test_KErrNone(nRes);
   368 
   369     }
   370     
   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. 
   374     {
   375         _LIT(KFsyFailure, "can't load '%S', code:%d, the test can't be performed!\n");
   376         
   377         //-- child FS #0
   378         nRes = TheFs.AddFileSystem(KFsy1);
   379         if(nRes != KErrNone && nRes != KErrAlreadyExists)
   380         {
   381             test.Printf(KFsyFailure, &KFsy1, nRes);    
   382             return EFalse;
   383         }
   384         childFs1_Loaded = ETrue;
   385 
   386 
   387         //-- child FS #1
   388         nRes = TheFs.AddFileSystem(KFsy2);
   389         if(nRes != KErrNone && nRes != KErrAlreadyExists)
   390         {
   391             test.Printf(KFsyFailure, &KFsy2, nRes);    
   392             return EFalse;
   393         }
   394         childFs2_Loaded = ETrue;
   395 
   396         //-- automounter
   397         nRes = TheFs.AddFileSystem(KAutoMounterFsy);
   398         if(nRes != KErrNone && nRes != KErrAlreadyExists)
   399         {
   400             test.Printf(KFsyFailure, &KAutoMounterFsy, nRes);    
   401             return EFalse;
   402         }
   403         automounter_Loaded = ETrue;
   404     }
   405 
   406 
   407     //=======================================
   408     //-- dismount original file system and optional primary extension. Secondary extensions are not supported.
   409 
   410     test.Printf(_L("Dismounting the original FS:%S, PExt:%S \n"), &orgFsDescriptor.iFsName, &orgFsDescriptor.iPExtName);
   411 
   412     nRes = TheFs.DismountFileSystem(orgFsDescriptor.iFsName, gDriveNum);
   413     test_KErrNone(nRes);
   414 
   415     return ETrue;
   416 }
   417 
   418 //-------------------------------------------------------------------
   419 /** destroy test global objects */
   420 void DestroyGlobals()
   421 {
   422     test.Printf(_L("Restoring the environment....\n"));
   423 
   424     TInt nRes;
   425 
   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);
   431         
   432         TBuf<40> fsName;
   433 
   434         nRes = TheFs.FileSystemName(fsName, gDriveNum);
   435         if(nRes == KErrNone && fsName.CompareF(orgFsDescriptor.iFsName) != KErrNone)
   436         {
   437             nRes = TheFs.DismountFileSystem(fsName, gDriveNum);
   438             test_KErrNone(nRes);
   439         
   440 
   441             //-- mount original FS as asynchronous one, the automounter can't be used on a synchronous drive anyway.
   442             MountFileSystem(TheFs, gDriveNum, orgFsDescriptor);
   443        
   444             FormatVolume();
   445         }
   446     }
   447 
   448     //=======================================
   449     //-- delete test property
   450     RProperty::Delete(KThisTestSID, gDriveNum);
   451 
   452     //=======================================
   453     //-- if the original FS wasn't automounter, unload child file systems
   454     if(orgFsDescriptor.iFsName.CompareF(KFileSystemName_AutoMounter) != 0)
   455     { 
   456 
   457         if(childFs1_Loaded)
   458         {
   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;
   462         }
   463 
   464         if(childFs2_Loaded)
   465         {
   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;
   469         }
   470     
   471 
   472         //-- unload test filesystem modules
   473         if(automounter_Loaded)
   474         {
   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;
   478         }
   479      }
   480      else
   481      {
   482         nRes = RemountFS(TheFs, gDriveNum);
   483         test(nRes == KErrNone);
   484      }
   485 
   486     TVolumeInfo v;
   487     TheFs.Volume(v);
   488 }
   489 
   490 //-------------------------------------------------------------------
   491 
   492 /*
   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.
   495 
   496     
   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
   501 
   502 
   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
   505 
   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)
   511 
   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
   514     
   515     
   516     5.  check the list of supported file systems on the drive
   517 
   518     6.1 corrupt the volume 
   519     6.2 check that automounter can't recognise it
   520 
   521     7.  restore "filesystem1" / format volume 
   522 */
   523 void TestAutomounterBasics()
   524 {
   525     
   526     test.Next(_L("Testing automounter basic functionality \n"));
   527 
   528     TVolumeInfo v;
   529     TBuf<40> fsName(0);
   530     TBuf<40> fsSubType(0);
   531     TInt nRes;
   532    
   533     //================================================================================
   534     //-- 1. mount "filesystem1" / format volume
   535     test.Printf(_L("Mounting FileSystem1...\n"));
   536     Mount_FileSystem1();
   537     
   538     FormatVolume();
   539 
   540     nRes = TheFs.Volume(v);
   541     test_KErrNone(nRes);
   542     
   543     //-- check file system name / subtype etc.
   544     nRes = TheFs.FileSystemName(fsName, gDriveNum);
   545     test_KErrNone(nRes);
   546     test(fsName.CompareF(KFSName1) == 0);
   547 
   548 
   549     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
   550     test_KErrNone(nRes);
   551     CheckSubtype_FS1(fsSubType);
   552 
   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);
   556     
   557     fsName.SetLength(0);
   558     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem
   559     test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0);
   560 
   561     fsName.SetLength(0);
   562     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
   563     test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0);
   564 
   565     fsName.SetLength(0);
   566     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- there are no more supported FSs
   567     test(nRes == KErrNotFound);
   568 
   569     //-- perform some operation
   570     CheckFsOperations();
   571     
   572 
   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();
   578 
   579     nRes = TheFs.Volume(v);
   580     test_KErrNone(nRes);
   581 
   582     //-- check file system name / subtype etc.
   583     nRes = TheFs.FileSystemName(fsName, gDriveNum);
   584     test_KErrNone(nRes);
   585 
   586     //-- the FS Subtype must be the subtype of the recognised child FS
   587     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   588     test_KErrNone(nRes);
   589     
   590     test.Printf(_L("FS name:'%S', FS Subtype:'%S'\n") ,&fsName, &fsSubType);
   591 
   592     test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
   593     CheckSubtype_FS1(fsSubType);
   594 
   595 
   596 
   597     //================================================================================
   598     //-- dismount current file system
   599     test.Printf(_L("Dismomounting FileSystem1...\n"));
   600     DismountFS();
   601     nRes = TheFs.FileSystemName(fsName, gDriveNum);
   602     test(nRes == KErrNotFound);
   603 
   604     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem
   605     test(nRes == KErrNotFound);
   606 
   607     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
   608     test(nRes == KErrNotFound);
   609 
   610     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
   611     test(nRes == KErrNotReady);
   612 
   613     
   614     //================================================================================
   615     //-- 3. mount "filesystem2" / format volume
   616     test.Printf(_L("Mounting FileSystem2...\n"));
   617     Mount_FileSystem2();
   618     
   619     FormatVolume();
   620 
   621     nRes = TheFs.Volume(v);
   622     test_KErrNone(nRes);
   623     
   624     //-- check file system name / subtype etc.
   625     nRes = TheFs.FileSystemName(fsName, gDriveNum);
   626     test_KErrNone(nRes);
   627     test(fsName.CompareF(KFSName2) == 0);
   628 
   629     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
   630     test_KErrNone(nRes);
   631     CheckSubtype_FS2(fsSubType);
   632 
   633     //-- check the list of supported file systems on this drive (there is only 1 FS supported).
   634     fsName.SetLength(0);
   635     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, RFs::KRootFileSystem); //-- "root" filesystem
   636     test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0);
   637 
   638     fsName.SetLength(0);
   639     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
   640     test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0);
   641 
   642     fsName.SetLength(0);
   643     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- there are no more supported FSs
   644     test(nRes == KErrNotFound);
   645 
   646     //-- perform some operation
   647     CheckFsOperations();
   648 
   649 
   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();
   655 
   656     nRes = TheFs.Volume(v);
   657     test_KErrNone(nRes);
   658 
   659     //-- check file system name / subtype etc.
   660     nRes = TheFs.FileSystemName(fsName, gDriveNum);
   661     test_KErrNone(nRes);
   662 
   663     //-- the FS Subtype must be the subtype of the recognised child FS
   664     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   665     test_KErrNone(nRes);
   666     
   667     test.Printf(_L("FS name:'%S', FS Subtype:'%S'\n") ,&fsName, &fsSubType);
   668 
   669     test(fsName.CompareF(KAutoMounterFSName) == 0); //-- the file system name shall be "automounter" - it is a root FS
   670     CheckSubtype_FS2(fsSubType);
   671 
   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"));
   675     
   676     fsName.SetLength(0);
   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);
   680 
   681 
   682     fsName.SetLength(0);
   683     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 0); //-- 1st "child" filesystem
   684     test(nRes == KErrNone && fsName.CompareF(KFSName1) == 0);
   685 
   686     fsName.SetLength(0);
   687     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 1); //-- 2nd "child" filesystem
   688     test(nRes == KErrNone && fsName.CompareF(KFSName2) == 0);
   689 
   690     nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, 2); //-- 3rd "child" filesystem
   691     test(nRes == KErrNotFound);
   692 
   693     //-- get and print out list of all child FS (enumeration example)
   694     TInt i;
   695     for(i=0; ;++i)
   696     {
   697         nRes = TheFs.SupportedFileSystemName(fsName, gDriveNum, i); 
   698         if(nRes == KErrNone)
   699         {
   700             test.Printf(_L("child FS[%d]:'%S'\n"), i, &fsName);
   701         }
   702         else
   703         {
   704         test(nRes == KErrNotFound);
   705         break;    
   706         }
   707         
   708     }
   709 
   710     //-- perform some operation. They will happen on currently active child FS
   711     CheckFsOperations();
   712 
   713     //================================================================================
   714     //-- 6. corrupt the media, mount automounter, check that FS is not recognised.
   715     test.Printf(_L("Test automounter handling corrupted media.\n"));
   716     
   717     CorruptDrive(); //-- the active child FS will do this and the root FS will be remounted on first access
   718 
   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
   722     test_KErrNone(nRes);
   723 
   724     //-- the FS Subtype query requires mounted and recognised file system. this shall fail
   725     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   726     test(nRes == KErrCorrupt);
   727 
   728     nRes = TheFs.MkDir(_L("\\dir1\\"));
   729     test(nRes == KErrCorrupt);
   730 
   731 
   732     //================================================================================
   733     //-- 7. restore filesystem on the drive 
   734     test.Printf(_L("Restoring FileSystem1.\n"));
   735     Mount_FileSystem1();
   736     FormatVolume();
   737     
   738     nRes = TheFs.Volume(v);
   739     test_KErrNone(nRes);
   740 
   741 }
   742 
   743 //-------------------------------------------------------------------
   744 /**
   745     
   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.
   749 
   750     2.  mount "automounter" The "filesystem1" must be recognised
   751     2.1 open previously created file (it is still opened by dismounted FS1)
   752 
   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.
   756 */
   757 void TestDismounting()
   758 {
   759     test.Next(_L("Testing media dismounting/remounting with automounter FS \n"));
   760 
   761     TInt nRes;
   762     TBuf<40>    fsName(0);
   763     TBuf<40>    fsSubType(0);
   764     TBuf8<40>   buf;
   765 
   766     //================================================================================
   767     //-- 1. mount "filesystem1" / format volume
   768     test.Printf(_L("Mounting FileSystem1 and opening a file.\n"));
   769     Mount_FileSystem1();
   770     FormatVolume();
   771 
   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);
   776     
   777     RFile file;
   778 
   779     nRes = file.Open(TheFs, KTestFile, 0);
   780     test(nRes == KErrNone);
   781 
   782         //TheFs.SetDebugRegister(KFSERV);
   783 
   784     test.Printf(_L("dismounting FileSystem1 with a file opened.\n"));
   785     nRes = DoDismountFS();
   786     test(nRes == KErrInUse);
   787 
   788     file.Close();
   789 
   790     //================================================================================
   791     //-- 2. mount "automounter", previous FS must be recognised and set as an active child
   792     Mount_AutomounterFS();
   793    
   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
   797     test_KErrNone(nRes);
   798 
   799     //-- the FS Subtype must be the subtype of the recognised child FS
   800     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   801     test_KErrNone(nRes);
   802     CheckSubtype_FS1(fsSubType);
   803 
   804     //-- open the previously created file
   805     nRes = file.Open(TheFs, KTestFile, 0);
   806     test(nRes == KErrNone);
   807 
   808         //TheFs.SetDebugRegister(KFSERV);
   809 
   810     nRes = DoDismountFS();
   811     test(nRes == KErrInUse); //-- opened file belongs to the child FS, actually.
   812 
   813 
   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"));
   817     ForceDismountFS();
   818 
   819         //TheFs.SetDebugRegister(KFSERV);
   820 
   821     //================================================================================
   822     //-- 4. mount "automounter" again, this will create another instance of mount corresponding to the filesystem1
   823     Mount_AutomounterFS();
   824    
   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
   828     test_KErrNone(nRes);
   829 
   830     //-- the FS Subtype must be the subtype of the recognised child FS
   831     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   832     test_KErrNone(nRes);
   833     CheckSubtype_FS1(fsSubType);
   834 
   835     //================================================================================
   836     //-- 5. try to read a file using already dead mount
   837     nRes = file.Read(0, buf, 2);
   838     test(nRes == KErrDisMounted);
   839 
   840     //-- this will cause the forcedly dismounted hanging mount to self-destruct
   841     file.Close();   
   842 
   843 
   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);
   849 
   850     file.Close();
   851 
   852     
   853     //TheFs.SetDebugRegister(0x00);
   854 }
   855 
   856 //-------------------------------------------------------------------
   857 /**
   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"
   860 
   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.
   863 
   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"
   866 */
   867 void TestAutomounterDefaultFormatting()
   868 {
   869     test.Next(_L("Testing media formatting with default parameters. Automounter FS\n"));
   870 
   871     TInt nRes;
   872     TBuf<40>    fsName(0);
   873     TBuf<40>    fsSubType(0);
   874 
   875 
   876     //================================================================================
   877     //-- 1. mount "filesystem1" / format volume
   878     Mount_FileSystem1();
   879     FormatVolume();
   880 
   881     //================================================================================
   882     //-- 2. mount "automounter", previous FS must be recognised and set as an active child
   883     Mount_AutomounterFS();
   884    
   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
   888     test_KErrNone(nRes);
   889 
   890     //-- the FS Subtype must be the subtype of the recognised child FS
   891     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   892     test_KErrNone(nRes);
   893     CheckSubtype_FS1(fsSubType);
   894 
   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
   898     FormatVolume();
   899 
   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
   903     test_KErrNone(nRes);
   904 
   905     //-- the FS Subtype must be the subtype of the recognised child FS
   906     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   907     test_KErrNone(nRes);
   908     CheckSubtype_FS1(fsSubType);
   909 
   910     //-- perform some operations
   911     CheckFsOperations();
   912     test.Printf(_L("default formatting for FS:'%S', subtype:'%S' OK!\n"), &fsName, &fsSubType);
   913 
   914     //================================================================================
   915     //-- 3. mount "filesystem2" / format volume
   916     Mount_FileSystem2();
   917     FormatVolume();
   918 
   919     //================================================================================
   920     //-- 4. mount "automounter", previous FS must be recognised and set as an active child
   921     Mount_AutomounterFS();
   922    
   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
   926     test_KErrNone(nRes);
   927 
   928     //-- the FS Subtype must be the subtype of the recognised child FS
   929     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   930     test_KErrNone(nRes);
   931     CheckSubtype_FS2(fsSubType);
   932 
   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
   936     FormatVolume();
   937 
   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
   941     test_KErrNone(nRes);
   942 
   943     //-- the FS Subtype must be the subtype of the recognised child FS
   944     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   945     test_KErrNone(nRes);
   946     CheckSubtype_FS2(fsSubType);
   947 
   948     //-- perform some operations
   949     CheckFsOperations();
   950     test.Printf(_L("default formatting for FS:'%S', subtype:'%S' OK!\n"), &fsName, &fsSubType);
   951 
   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
   955     
   956     CorruptDrive(); //-- the active child FS will do this and the root FS will be remounted on first access
   957 
   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
   961     test_KErrNone(nRes);
   962 
   963     //-- the FS Subtype query requires mounted and recognised file system. this shall fail
   964     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);   
   965     test(nRes == KErrCorrupt);
   966 
   967     //-- try default formatting; this shall fail with a special error code
   968     nRes = FormatDrive(TheFs, CurrentDrive(), ETrue);
   969     test(nRes == KErrNotFound);
   970 
   971     //-- try special formatting without any parameters, it shall also fail.
   972     RFormat     format;
   973     TUint       fmtMode = EQuickFormat | ESpecialFormat;
   974     TInt        fmtCnt;
   975     TBuf<10>    drivePath;
   976     drivePath.Format(_L("%C:\\"), gDriveNum+'A');
   977 
   978     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
   979     test(nRes==KErrNotFound);
   980     format.Close();
   981 
   982 
   983 
   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"));
   988 
   989     Mount_FileSystem1();
   990     //FormatVolume();
   991     
   992 
   993     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
   994     test(nRes==KErrNone);
   995 
   996     nRes = DoFormatSteps(format, fmtCnt);
   997     test(nRes==KErrNone);
   998 
   999     format.Close();
  1000 
  1001 
  1002     
  1003     //-- check file system name / subtype etc.
  1004     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1005     test_KErrNone(nRes);
  1006     test(fsName.CompareF(KFSName1) == 0);
  1007 
  1008 
  1009     nRes = TheFs.FileSystemSubType(gDriveNum, fsSubType);
  1010     test_KErrNone(nRes);
  1011     CheckSubtype_FS1(fsSubType);
  1012 
  1013 
  1014 }
  1015 
  1016 
  1017 
  1018 //-------------------------------------------------------------------
  1019 /**
  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.
  1022     
  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.
  1027 
  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.
  1030 */
  1031 void TestAutomounterFormatting_FsNameSpecified()
  1032 {
  1033     test.Next(_L("Testing formatting API that allows specifying particular FS. Automounter FS.\n"));
  1034 
  1035 
  1036     TInt nRes;
  1037     TBuf<40>    fsName(0);
  1038     TBuf<40>    fsSubType(0);
  1039     
  1040     TBuf<10>    drivePath;
  1041     drivePath.Format(_L("%C:\\"), gDriveNum+'A');
  1042 
  1043     RFormat     format;
  1044     TUint       fmtMode = EQuickFormat | ESpecialFormat;
  1045     TInt        fmtCnt;
  1046 
  1047     TVolFormatParamBuf  fmtParamBuf;
  1048     TVolFormatParam& fmtParam = fmtParamBuf();
  1049 
  1050     //_LIT(KTestFile, "\\this is a test file");
  1051 
  1052     //================================================================================
  1053     //-- 0. prepare the volume
  1054     Mount_FileSystem1();    
  1055     FormatVolume(); //-- old API, formatting with all parameters by default
  1056 
  1057 
  1058     //================================================================================
  1059     //-- 0.1 mount "automounter", previous FS must be recognised and set as an active child
  1060     Mount_AutomounterFS();
  1061    
  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);
  1066 
  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);
  1071 
  1072     //================================================================================
  1073     
  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"));
  1076 
  1077     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
  1078     test(nRes==KErrNone);
  1079     
  1080     nRes = DoFormatSteps(format, fmtCnt);
  1081     test(nRes==KErrNone);
  1082 
  1083     format.Close();
  1084 
  1085     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1086     test(fsName.CompareF(KAutoMounterFSName) == 0); 
  1087 
  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);
  1092 
  1093     
  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);
  1099     
  1100     nRes = DoFormatSteps(format, fmtCnt);
  1101     test(nRes==KErrNone);
  1102 
  1103     format.Close();
  1104 
  1105     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1106     test(fsName.CompareF(KAutoMounterFSName) == 0); 
  1107 
  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);
  1112 
  1113 
  1114     CheckFsOperations();
  1115 
  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);
  1123     
  1124     nRes =DoFormatSteps(format, fmtCnt);
  1125     test(nRes==KErrNone);
  1126 
  1127     format.Close();
  1128 
  1129     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1130     test(fsName.CompareF(KAutoMounterFSName) == 0); 
  1131 
  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);
  1136     
  1137     CheckFsOperations();
  1138 
  1139 
  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);
  1146     
  1147     nRes =DoFormatSteps(format, fmtCnt);
  1148     test(nRes==KErrNone);
  1149 
  1150     format.Close();
  1151 
  1152     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1153     test(fsName.CompareF(KAutoMounterFSName) == 0); 
  1154 
  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);
  1159     
  1160     CheckFsOperations();
  1161 
  1162 
  1163     //================================================================================
  1164     //-- 4. try formatting the volume specifying wrond child FS name
  1165     fmtParam.Init(); //-- reset all data
  1166     
  1167     fmtParam.SetFileSystemName(KAutoMounterFSName); //-- it might have some strange consequences :)
  1168     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1169     test(nRes==KErrNotSupported);
  1170     format.Close();
  1171 
  1172     fmtParam.SetFileSystemName(_L("wrong FS")); 
  1173     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1174     test(nRes==KErrNotSupported);
  1175     format.Close();
  1176 
  1177 
  1178     //================================================================================
  1179     //-- 5. corrupt the volume and try formatting without specyfying FS name
  1180     CorruptDrive();
  1181 
  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"
  1185     format.Close();
  1186 
  1187     //test.Printf(_L("#### T_a #1 res:%d\n"), nRes);
  1188 
  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);
  1192     
  1193     test(nRes == KErrNotSupported || nRes==KErrNotFound);
  1194 
  1195     format.Close();
  1196 
  1197     fmtParam.SetFileSystemName(_L("wrong FS")); 
  1198     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1199     test(nRes==KErrNotSupported);
  1200     format.Close();
  1201 
  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"
  1204     format.Close();
  1205 
  1206 
  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);
  1213     
  1214     nRes =DoFormatSteps(format, fmtCnt);
  1215     test(nRes==KErrNone);
  1216 
  1217     format.Close();
  1218 
  1219     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1220     test(fsName.CompareF(KAutoMounterFSName) == 0); 
  1221 
  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);
  1226     
  1227     CheckFsOperations();
  1228 
  1229     //--------------------------------------------------------------------------------
  1230     //-- 5.2 corrupt the volume and format with specifying child FS1 explicitly
  1231     CorruptDrive();
  1232 
  1233     fmtParam.Init(); //-- reset all data
  1234     fmtParam.SetFileSystemName(KFSName1);
  1235     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1236     test(nRes==KErrNone);
  1237     
  1238     nRes =DoFormatSteps(format, fmtCnt);
  1239     test(nRes==KErrNone);
  1240 
  1241     format.Close();
  1242 
  1243     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1244     test(fsName.CompareF(KAutoMounterFSName) == 0); 
  1245 
  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);
  1250     
  1251     CheckFsOperations();
  1252 }
  1253 
  1254 //-------------------------------------------------------------------
  1255 /**
  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.
  1258     
  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.
  1263 
  1264     If the specified file system name differs from the name that the bound FS has, the RFormat::Open() fails with KErrNotSupported.
  1265 
  1266 */
  1267 void TestFixedFsFormatting_FsNameSpecified()
  1268 {
  1269     test.Next(_L("Testing RFormat API that allows specifying particular FS name for fixed FS.\n"));
  1270 
  1271     TInt nRes;
  1272     TBuf<40>    fsName(0);
  1273    
  1274     TBuf<10>    drivePath;
  1275     drivePath.Format(_L("%C:\\"), gDriveNum+'A');
  1276 
  1277     RFormat     format;
  1278     TUint       fmtMode = EQuickFormat | ESpecialFormat;
  1279     TInt        fmtCnt;
  1280 
  1281     TVolFormatParamBuf  fmtParamBuf;
  1282     TVolFormatParam& fmtParam = fmtParamBuf();
  1283 
  1284     _LIT(KTestFile, "\\this is a test file");
  1285 
  1286     //================================================================================
  1287     //-- 0. prepare the volume
  1288     test.Printf(_L("fmt: ESpecialFormat, no parameters specified\n"));
  1289     Mount_FileSystem1();    
  1290     
  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);
  1295     
  1296     nRes = DoFormatSteps(format, fmtCnt);
  1297     test(nRes==KErrNone);
  1298 
  1299 
  1300     format.Close();
  1301 
  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);
  1308     
  1309     nRes =DoFormatSteps(format, fmtCnt);
  1310     test(nRes==KErrNone);
  1311 
  1312     format.Close();
  1313 
  1314     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1315     test(fsName.CompareF(KFSName1) == 0); 
  1316     CheckFsOperations();
  1317 
  1318     //-- 1.1 corrupt the media and check formatting without specifying FS name. 
  1319     //-- The file system bount to this drive shall be used.
  1320     CorruptDrive();
  1321     
  1322     test.Printf(_L("fmt: ESpecialFormat, no FS name specified #2\n"));
  1323 
  1324     fmtParam.Init(); //-- reset all data
  1325     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1326     test(nRes==KErrNone);
  1327     
  1328     nRes =DoFormatSteps(format, fmtCnt);
  1329     test(nRes==KErrNone);
  1330 
  1331     format.Close();
  1332 
  1333     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1334     test(fsName.CompareF(KFSName1) == 0); 
  1335     CheckFsOperations();
  1336 
  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"));
  1340 
  1341     nRes = CreateCheckableStuffedFile(TheFs, KTestFile, 17384);
  1342     test(nRes==KErrNone);
  1343 
  1344     fmtParam.Init(); //-- reset all data
  1345     fmtParam.SetFileSystemName(_L("some filesystem name"));
  1346 
  1347     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1348     test(nRes==KErrNotSupported);
  1349     format.Close();
  1350 
  1351     test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #2\n"));
  1352     fmtParam.Init(); //-- reset all data
  1353     fmtParam.SetFileSystemName(KFSName2);
  1354 
  1355     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1356     test(nRes==KErrNotSupported);
  1357     format.Close();
  1358     
  1359     
  1360     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1361     test(fsName.CompareF(KFSName1) == 0); 
  1362     CheckFsOperations();
  1363 
  1364     nRes = VerifyCheckableFile(TheFs, KTestFile);
  1365     test(nRes==KErrNone);
  1366 
  1367 
  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"));
  1371     CorruptDrive();
  1372 
  1373     fmtParam.Init(); //-- reset all data
  1374     fmtParam.SetFileSystemName(_L("some filesystem name"));
  1375 
  1376     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1377     test(nRes==KErrNotSupported);
  1378     format.Close();
  1379 
  1380     test.Printf(_L("fmt: ESpecialFormat, specifying wrong FS name #4\n"));
  1381     fmtParam.Init(); //-- reset all data
  1382     fmtParam.SetFileSystemName(KFSName2);
  1383 
  1384     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1385     test(nRes==KErrNotSupported);
  1386     format.Close();
  1387 
  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);
  1394     
  1395     nRes = DoFormatSteps(format, fmtCnt);
  1396     test(nRes==KErrNone);
  1397 
  1398     format.Close();
  1399 
  1400     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1401     test(fsName.CompareF(KFSName1) == 0); 
  1402     CheckFsOperations();
  1403 
  1404 
  1405 }
  1406 
  1407 //-------------------------------------------------------------------
  1408 /**
  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. 
  1411 */
  1412 void TestFormatting_FsName_Parameters_FAT()
  1413 {
  1414     using namespace FileSystem_FAT;
  1415 
  1416     test.Next(_L("Testing TVolFormatParam_FAT formatting API\n"));
  1417 
  1418     TInt nRes;
  1419     TBuf<40>    fsName(0);
  1420    
  1421     TBuf<10>    drivePath;
  1422     drivePath.Format(_L("%C:\\"), gDriveNum+'A');
  1423 
  1424     RFormat     format;
  1425     TUint       fmtMode = EQuickFormat | ESpecialFormat;
  1426     TInt        fmtCnt;
  1427 
  1428     //================================================================================
  1429     //-- 0. prepare the volume
  1430     Mount_FileSystem1();    
  1431     FormatVolume(); //-- old API, formatting with all parameters by default
  1432 
  1433     //================================================================================
  1434     //-- 1.0  simple unit test for TVolFormatParam_FAT
  1435     TVolFormatParam_FATBuf  fmtParamBuf_FAT;
  1436     TVolFormatParam_FAT&    fmtParam_FAT = fmtParamBuf_FAT();
  1437 
  1438     fmtParam_FAT.SetFatSubType(EFat32);
  1439     test(fmtParam_FAT.FatSubType() == EFat32);
  1440     
  1441     fmtParam_FAT.SetFatSubType(EFat12);
  1442     test(fmtParam_FAT.FatSubType() == EFat12);
  1443      
  1444     fmtParam_FAT.SetFatSubType(EFat16);
  1445     test(fmtParam_FAT.FatSubType() == EFat16);
  1446 
  1447     fmtParam_FAT.SetFatSubType(ENotSpecified);
  1448     test(fmtParam_FAT.FatSubType() == ENotSpecified);
  1449 
  1450     fmtParam_FAT.SetFatSubType(KFSSubType_FAT32);
  1451     test(fmtParam_FAT.FatSubType() == EFat32);
  1452     
  1453     fmtParam_FAT.SetFatSubType(KFSSubType_FAT12);
  1454     test(fmtParam_FAT.FatSubType() == EFat12);
  1455      
  1456     fmtParam_FAT.SetFatSubType(KFSSubType_FAT16);
  1457     test(fmtParam_FAT.FatSubType() == EFat16);
  1458 
  1459     
  1460     fmtParam_FAT.SetSectPerCluster(64);
  1461     test(fmtParam_FAT.SectPerCluster()==64);
  1462 
  1463     fmtParam_FAT.SetNumFATs(1);
  1464     test(fmtParam_FAT.NumFATs()==1);
  1465 
  1466     fmtParam_FAT.SetReservedSectors(13);
  1467     test(fmtParam_FAT.ReservedSectors()==13);
  1468 
  1469     
  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);
  1475 
  1476     
  1477     //--- formatting FAT without specifying any parameters. This shall always succeed
  1478     test.Printf(_L("fmt: using TVolFormatParam_FAT, no parameters.\n"));
  1479 
  1480     fmtParam_FAT.Init();
  1481 
  1482     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf_FAT);
  1483     test(nRes==KErrNone);
  1484     
  1485     nRes = DoFormatSteps(format, fmtCnt);
  1486     test(nRes==KErrNone);
  1487 
  1488     format.Close();
  1489 
  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.
  1492 
  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);
  1498 
  1499     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf_FAT);
  1500     test(nRes==KErrNone);
  1501     
  1502     nRes = DoFormatSteps(format, fmtCnt);
  1503     if(nRes != KErrNone)
  1504     {
  1505         test.Printf(_L("formatting failed. reason code:%d\n"), nRes);        
  1506     }
  1507 
  1508     format.Close();
  1509 
  1510     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1511     test(fsName.CompareF(KFSName1) == 0); 
  1512 
  1513     CheckFsOperations();
  1514 
  1515 }
  1516 
  1517 //-------------------------------------------------------------------
  1518 /**
  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. 
  1521 */
  1522 
  1523 void TestFormatting_FsName_Parameters_exFAT()
  1524 {
  1525 
  1526 
  1527     test.Next(_L("Testing TVolFormatParam_exFAT formatting API\n"));
  1528 
  1529     TInt nRes;
  1530     TBuf<40>    fsName(0);
  1531    
  1532     TBuf<10>    drivePath;
  1533     drivePath.Format(_L("%C:\\"), gDriveNum+'A');
  1534 
  1535     RFormat     format;
  1536     TUint       fmtMode = EQuickFormat | ESpecialFormat;
  1537     TInt        fmtCnt;
  1538 
  1539 
  1540     //================================================================================
  1541     //-- 0. prepare the volume
  1542     Mount_FileSystem2();    
  1543     FormatVolume(); //-- old API, formatting with all parameters by default
  1544 
  1545     //================================================================================
  1546     //-- 1.0  simple unit test for TVolFormatParam_FAT
  1547 
  1548 #ifndef EXFAT_MIGHT_NOT_BE_PRESENT    
  1549     TVolFormatParam_exFATBuf    fmtParamBuf;
  1550     TVolFormatParam_exFAT&      fmtParam = fmtParamBuf();
  1551 #else
  1552     //-- see the comments to "EXFAT_MIGHT_NOT_BE_PRESENT" macro definition
  1553     TVolFormatParam_FATBuf  fmtParamBuf;
  1554     TVolFormatParam_FAT&    fmtParam= fmtParamBuf();
  1555 #endif
  1556 
  1557 
  1558     fmtParam.SetSectPerCluster(64);
  1559     test(fmtParam.SectPerCluster()==64);
  1560 
  1561     fmtParam.SetSectPerCluster(14);
  1562     test(fmtParam.SectPerCluster()==14);
  1563 
  1564     fmtParam.SetNumFATs(1);
  1565     test(fmtParam.NumFATs()==1);
  1566 
  1567     fmtParam.SetNumFATs(2);
  1568     test(fmtParam.NumFATs()==2);
  1569 
  1570     fmtParam.Init();
  1571     test(fmtParam.SectPerCluster() == 0);
  1572     test(fmtParam.NumFATs()==0);
  1573 
  1574 
  1575     //--- formatting exFAT without specifying any parameters. This shall always succeed
  1576     test.Printf(_L("fmt: using TVolFormatParam_exFAT, no parameters.\n"));
  1577     fmtParam.Init();
  1578     
  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);
  1582 #endif        
  1583 
  1584     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1585     test(nRes==KErrNone);
  1586     
  1587     nRes = DoFormatSteps(format, fmtCnt);
  1588     test(nRes==KErrNone);
  1589 
  1590     format.Close();
  1591 
  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.
  1594 
  1595     test.Printf(_L("fmt: using TVolFormatParam_exFAT, some exFAT specific parameters.\n"));
  1596 
  1597     fmtParam.SetSectPerCluster(1);
  1598     fmtParam.SetNumFATs(2);
  1599 
  1600     nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt, fmtParamBuf);
  1601     test(nRes==KErrNone);
  1602     
  1603     nRes = DoFormatSteps(format, fmtCnt);
  1604     if(nRes != KErrNone)
  1605     {
  1606         test.Printf(_L("formatting failed. reason code:%d\n"), nRes);        
  1607     }
  1608 
  1609     format.Close();
  1610 
  1611     nRes = TheFs.FileSystemName(fsName, gDriveNum);
  1612     test(fsName.CompareF(KFSName2) == 0); 
  1613 
  1614     CheckFsOperations();
  1615 }
  1616 
  1617 //-------------------------------------------------------------------
  1618 
  1619 void CallTestsL()
  1620     {
  1621 
  1622     
  1623     //-- set up console output
  1624     Fat_Test_Utils::SetConsole(test.Console());
  1625 
  1626 #ifndef _DEBUG
  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"));
  1629     return;
  1630 #else
  1631 
  1632     TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum);
  1633     test(nRes==KErrNone);
  1634 
  1635 
  1636     //-------------------------------------
  1637 
  1638     PrintDrvInfo(TheFs, gDriveNum);
  1639 
  1640     TVolumeInfo v;
  1641     nRes = TheFs.Volume(v);
  1642     test(nRes==KErrNone);
  1643     if(v.iDrive.iMediaAtt & KMediaAttVariableSize)
  1644         {
  1645         test.Printf(_L("Skipping. Internal ram drive not tested.\n"));
  1646         return;
  1647         }
  1648 
  1649     if(v.iDrive.iType != EMediaHardDisk || !(v.iDrive.iDriveAtt & KDriveAttRemovable)) 
  1650         {
  1651         test.Printf(_L("The drive shall be removable and the media type EMediaHardDisk. Skipping.\n"));
  1652         return;
  1653         }
  1654 
  1655     
  1656     //-------------------------------------
  1657 
  1658     if(InitGlobals())
  1659         {//-- do tests here
  1660     
  1661           TestAutomounterBasics();
  1662           TestDismounting(); 
  1663           TestFixedFsFormatting_FsNameSpecified();  
  1664 
  1665           TestAutomounterDefaultFormatting();
  1666           TestAutomounterFormatting_FsNameSpecified();
  1667 
  1668           TestFormatting_FsName_Parameters_FAT();
  1669           TestFormatting_FsName_Parameters_exFAT();
  1670         
  1671         }
  1672     //-------------------------------------
  1673     DestroyGlobals();
  1674 #endif
  1675     }
  1676 
  1677 
  1678 
  1679 
  1680 
  1681 
  1682 
  1683 
  1684 
  1685 
  1686 
  1687 
  1688 
  1689 
  1690 
  1691 
  1692 
  1693