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