os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/inc/sl_std.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-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
// fileserver\sfat32\inc\sl_std.h
sl@0
    15
//
sl@0
    16
sl@0
    17
/**
sl@0
    18
 @file
sl@0
    19
 @internalTechnology
sl@0
    20
*/
sl@0
    21
sl@0
    22
#ifndef SL_STD_H
sl@0
    23
#define SL_STD_H
sl@0
    24
sl@0
    25
sl@0
    26
//
sl@0
    27
// #define _DEBUG_RELEASE
sl@0
    28
//
sl@0
    29
sl@0
    30
#include "common.h"
sl@0
    31
#include <f32ver.h>
sl@0
    32
#include <e32svr.h>
sl@0
    33
#include <kernel/localise.h>
sl@0
    34
sl@0
    35
#include "filesystem_fat.h"
sl@0
    36
using namespace FileSystem_FAT;
sl@0
    37
sl@0
    38
#include "common_constants.h"
sl@0
    39
#include "sl_bpb.h"
sl@0
    40
#include "fat_config.h"
sl@0
    41
#include "fat_dir_entry.h"
sl@0
    42
#include "bit_vector.h"
sl@0
    43
sl@0
    44
sl@0
    45
sl@0
    46
#ifdef _DEBUG
sl@0
    47
_LIT(KThisFsyName,"EFAT32.FSY"); ///< This FSY name
sl@0
    48
#endif
sl@0
    49
sl@0
    50
//-----------------------------------------------------------------------------
sl@0
    51
//-- FAT32 specific declarations
sl@0
    52
sl@0
    53
const TUint32 KFat32EntryMask = 0x0FFFFFFF;
sl@0
    54
sl@0
    55
//-----------------------------------------------------------------------------
sl@0
    56
sl@0
    57
class CFatMountCB;
sl@0
    58
class CFatFileSystem;
sl@0
    59
sl@0
    60
/**
sl@0
    61
Represents the position of a directory entery in terms of a cluster and off set into it
sl@0
    62
*/
sl@0
    63
class TEntryPos
sl@0
    64
	{
sl@0
    65
public:
sl@0
    66
	TEntryPos() {}
sl@0
    67
	TEntryPos(TInt aCluster,TUint aPos) : iCluster(aCluster), iPos(aPos) {}
sl@0
    68
sl@0
    69
    inline TUint32 Cluster() const;
sl@0
    70
    inline TUint32 Pos() const;
sl@0
    71
    inline TBool operator==(const TEntryPos& aRhs) const;
sl@0
    72
sl@0
    73
public:
sl@0
    74
	TInt iCluster;
sl@0
    75
	TUint iPos;
sl@0
    76
	};
sl@0
    77
sl@0
    78
sl@0
    79
/**
sl@0
    80
    Interface class between the file system and the local drive media interface,
sl@0
    81
    handles incomplete writes to media with the ability to notify the user.
sl@0
    82
    This class can't be instantinated by user; only CFatMountCB can do this; see CFatMountCB::DriveInterface()
sl@0
    83
sl@0
    84
*/
sl@0
    85
class TDriveInterface
sl@0
    86
    {
sl@0
    87
public:
sl@0
    88
	enum TAction {ERetry=1};
sl@0
    89
sl@0
    90
public:
sl@0
    91
sl@0
    92
    //-- public interface to the local drive. Provides media driver's error handling (critical and non-critical user notifiers)
sl@0
    93
    //-- and thread-safety if required.
sl@0
    94
	TInt ReadNonCritical(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const;
sl@0
    95
	TInt ReadNonCritical(TInt64 aPos,TInt aLength,TDes8& aTrg) const;
sl@0
    96
	TInt ReadCritical(TInt64 aPos,TInt aLength,TDes8& aTrg) const;
sl@0
    97
	
sl@0
    98
    TInt WriteCritical(TInt64 aPos,const TDesC8& aSrc);
sl@0
    99
    TInt WriteNonCritical(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset);
sl@0
   100
	
sl@0
   101
    TInt GetLastErrorInfo(TDes8& aErrorInfo) const;
sl@0
   102
sl@0
   103
    //-- lock the mutex guarding CProxyDrive interface in order to be sure that no other thread can access it.
sl@0
   104
    //-- The thread that calls this method may be suspended until another signals the mutex, i.e. leaves the critical section.
sl@0
   105
    inline void AcquireLock() const {iProxyDrive.EnterCriticalSection();}
sl@0
   106
    
sl@0
   107
    //-- release the mutex guarding CProxyDrive.
sl@0
   108
    inline void ReleaseLock() const {iProxyDrive.LeaveCriticalSection();} 
sl@0
   109
sl@0
   110
sl@0
   111
protected:
sl@0
   112
    TDriveInterface();
sl@0
   113
    TDriveInterface(const TDriveInterface&);
sl@0
   114
    TDriveInterface& operator=(const TDriveInterface&);
sl@0
   115
sl@0
   116
    TBool Init(CFatMountCB* aMount);
sl@0
   117
    void Close(); 
sl@0
   118
sl@0
   119
	inline TBool NotifyUser() const;
sl@0
   120
	TInt HandleRecoverableError(TInt aRes) const;
sl@0
   121
	TInt HandleCriticalError(TInt aRes) const;
sl@0
   122
	TInt UnlockAndReMount() const;
sl@0
   123
	TBool IsDriveWriteProtected() const;
sl@0
   124
	TBool IsRecoverableRemount() const;
sl@0
   125
sl@0
   126
private:
sl@0
   127
	
sl@0
   128
	/** 
sl@0
   129
        An internal class that represents a thread-safe wrapper around raw interface to the CProxyDrive 
sl@0
   130
        and restricts access to it.
sl@0
   131
    */
sl@0
   132
    class XProxyDriveWrapper
sl@0
   133
        {
sl@0
   134
     public:
sl@0
   135
       
sl@0
   136
        XProxyDriveWrapper();
sl@0
   137
       ~XProxyDriveWrapper();
sl@0
   138
sl@0
   139
        TBool Init(CProxyDrive* aProxyDrive);
sl@0
   140
            
sl@0
   141
        inline void EnterCriticalSection() const {iLock.Wait();}
sl@0
   142
        inline void LeaveCriticalSection() const {iLock.Signal();}
sl@0
   143
sl@0
   144
        //-- methods' wrappers that are used by TDriveInterface
sl@0
   145
        TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const;
sl@0
   146
        TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg) const;
sl@0
   147
        TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset);
sl@0
   148
        TInt Write(TInt64 aPos, const TDesC8& aSrc);
sl@0
   149
        TInt GetLastErrorInfo(TDes8& aErrorInfo) const;
sl@0
   150
        TInt Caps(TDes8& anInfo) const;
sl@0
   151
sl@0
   152
     private:
sl@0
   153
        CProxyDrive*    iLocalDrive; ///< raw interface to the media operations
sl@0
   154
        mutable RMutex  iLock;       ///< used for sorting out multithreaded access to the iLocalDrive
sl@0
   155
        };
sl@0
   156
    
sl@0
   157
    CFatMountCB*        iMount;      ///< Pointer to the owning file system mount
sl@0
   158
    XProxyDriveWrapper  iProxyDrive; ///< wrapper around raw interface to the media operations
sl@0
   159
    
sl@0
   160
    };
sl@0
   161
sl@0
   162
sl@0
   163
/**
sl@0
   164
    Class providing FAT table interface and basic functionality.
sl@0
   165
*/	
sl@0
   166
class CFatTable : public CBase
sl@0
   167
	{
sl@0
   168
    
sl@0
   169
public:
sl@0
   170
	
sl@0
   171
    virtual ~CFatTable();
sl@0
   172
    
sl@0
   173
    static CFatTable* NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps);
sl@0
   174
sl@0
   175
    /** FAT table mounting parameters */
sl@0
   176
    struct TMountParams
sl@0
   177
        {
sl@0
   178
        TMountParams() :iFreeClusters(0), iFirstFreeCluster(0), iFsInfoValid(0) {};
sl@0
   179
        
sl@0
   180
        TUint32 iFreeClusters;      ///< Free clusters count, obtained from FSInfo
sl@0
   181
        TUint32 iFirstFreeCluster;  ///< First free cluster,  obtained from FSInfo
sl@0
   182
        TUint32 iFsInfoValid : 1;   ///< ETrue if the information in iFreeClusters &  iFirstFreeCluster is valid
sl@0
   183
        };
sl@0
   184
sl@0
   185
    //-----------------------------------------------------------------
sl@0
   186
    //-- pure virtual interface
sl@0
   187
    virtual TUint32 ReadL(TUint32 aFatIndex) const = 0;
sl@0
   188
	virtual void WriteL(TUint32 aFatIndex, TUint32 aValue) = 0;
sl@0
   189
	virtual TInt64 DataPositionInBytes(TUint32 aCluster) const = 0;
sl@0
   190
    virtual void MountL(const TMountParams& aMountParam) = 0;
sl@0
   191
    //-----------------------------------------------------------------
sl@0
   192
    //-- just virtual interface
sl@0
   193
    
sl@0
   194
    virtual void Dismount(TBool /*aDiscardDirtyData*/) {}
sl@0
   195
	virtual void FlushL() {};
sl@0
   196
    
sl@0
   197
    virtual void InvalidateCacheL() {};
sl@0
   198
    virtual void InvalidateCacheL(TInt64 /*aPos*/,TUint32 /*aLength*/) {};
sl@0
   199
sl@0
   200
	virtual void FreeClusterListL(TUint32 aCluster);
sl@0
   201
	virtual void ExtendClusterListL(TUint32 aNumber,TInt& aCluster);
sl@0
   202
	
sl@0
   203
    virtual TUint32 AllocateSingleClusterL(TUint32 aNearestCluster);
sl@0
   204
	virtual TUint32 AllocateClusterListL(TUint32 aNumber,TUint32 aNearestCluster);
sl@0
   205
    
sl@0
   206
    virtual void RequestRawWriteAccess(TInt64 /*aPos*/, TUint32 /*aLen*/) const {};
sl@0
   207
sl@0
   208
    virtual TUint32 FreeClusterHint() const; 
sl@0
   209
    virtual TUint32 NumberOfFreeClusters(TBool aSyncOperation=EFalse) const;
sl@0
   210
    virtual TBool RequestFreeClusters(TUint32 aClustersRequired) const; 
sl@0
   211
sl@0
   212
    virtual void InitializeL();
sl@0
   213
    virtual TBool ConsistentState() const {return ETrue;} //-- dummy
sl@0
   214
sl@0
   215
    //-----------------------------------------------------------------
sl@0
   216
    //-- non-virtual interface
sl@0
   217
    TBool GetNextClusterL(TInt& aCluster) const;
sl@0
   218
    void WriteFatEntryEofL(TUint32 aFatIndex);
sl@0
   219
sl@0
   220
    void MarkAsBadClusterL(TUint32 aCluster);
sl@0
   221
    TInt CountContiguousClustersL(TUint32 aStartCluster,TInt& anEndCluster, TUint32 aMaxCount) const;
sl@0
   222
    
sl@0
   223
    inline TUint32 MaxEntries() const;
sl@0
   224
    
sl@0
   225
    TUint32 PosInBytes(TUint32 aFatIndex) const;	    
sl@0
   226
sl@0
   227
sl@0
   228
protected:
sl@0
   229
	CFatTable(CFatMountCB& aOwner);
sl@0
   230
sl@0
   231
    //-- outlawed
sl@0
   232
    CFatTable();
sl@0
   233
    CFatTable(const CFatTable&);
sl@0
   234
    CFatTable& operator=(const CFatTable&);
sl@0
   235
sl@0
   236
    virtual void SetFreeClusterHint(TUint32 aCluster);
sl@0
   237
sl@0
   238
    virtual void DecrementFreeClusterCount(TUint32 aCount);
sl@0
   239
	virtual void IncrementFreeClusterCount(TUint32 aCount);
sl@0
   240
sl@0
   241
    virtual void SetFreeClusters(TUint32 aFreeClusters); 
sl@0
   242
    virtual void CountFreeClustersL();
sl@0
   243
    virtual TUint32 FindClosestFreeClusterL(TUint32 aCluster);
sl@0
   244
    
sl@0
   245
    
sl@0
   246
    inline TInt     SectorSizeLog2() const;
sl@0
   247
    inline TUint32  FreeClusters() const;
sl@0
   248
sl@0
   249
    inline TBool IsEndOfClusterCh(TUint32 aCluster) const;
sl@0
   250
sl@0
   251
sl@0
   252
    inline TFatType FatType() const;
sl@0
   253
    inline TBool IsFat12() const;
sl@0
   254
    inline TBool IsFat16() const;
sl@0
   255
    inline TBool IsFat32() const;
sl@0
   256
    
sl@0
   257
sl@0
   258
    inline TBool ClusterNumberValid(TUint32 aClusterNo) const;
sl@0
   259
sl@0
   260
    typedef RArray<TUint> RClusterArray;
sl@0
   261
    void DoFreedClustersNotify(RClusterArray &aFreedClusters);
sl@0
   262
sl@0
   263
sl@0
   264
protected:
sl@0
   265
	
sl@0
   266
    CFatMountCB* iOwner;            ///< Owning file system mount
sl@0
   267
    TUint        iMediaAtt;         ///< Cached copy of TLocalDriveCaps::iMediaAtt
sl@0
   268
sl@0
   269
private:   
sl@0
   270
sl@0
   271
    TUint32  iFreeClusters;     ///< Number of free cluster in the fat table
sl@0
   272
	TUint32  iFreeClusterHint;  ///< this is just a hint to the free cluster number, not required to contain exact information.
sl@0
   273
	TFatType iFatType;          ///< FAT type 12/16/32, cached from the iOwner
sl@0
   274
    TUint32  iFatEocCode;       ///< End Of Cluster Chain code, 0xff8 for FAT12, 0xfff8 for FAT16, and 0xffffff8 for FAT32 
sl@0
   275
    TUint32  iMaxEntries;       ///< maximal number of FAT entries in the table. This value is taken from the CFatMount that calculates it
sl@0
   276
sl@0
   277
    };
sl@0
   278
sl@0
   279
sl@0
   280
class MWTCacheInterface;
sl@0
   281
sl@0
   282
sl@0
   283
//---------------------------------------------------------------------------------------------------------------------------------
sl@0
   284
sl@0
   285
/**
sl@0
   286
Base class abstraction of a raw media disk
sl@0
   287
*/
sl@0
   288
sl@0
   289
sl@0
   290
class CRawDisk : public CBase
sl@0
   291
	{
sl@0
   292
public:
sl@0
   293
sl@0
   294
    static CRawDisk* NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps);
sl@0
   295
sl@0
   296
    virtual void InitializeL();
sl@0
   297
	
sl@0
   298
    virtual TInt GetLastErrorInfo(TDes8& aErrorInfo) const;
sl@0
   299
public:
sl@0
   300
	
sl@0
   301
    /**
sl@0
   302
	Read data from the media via simple WT data cache if it is present. Some media types, like RAM do not have caches.
sl@0
   303
    This method is mostly used to read UIDs of executable modules and store them in the cache.
sl@0
   304
sl@0
   305
	@param aPos		Media position in bytes
sl@0
   306
	@param aLength	Length in bytes of read
sl@0
   307
	@param aDes		Data from read
sl@0
   308
	*/
sl@0
   309
	virtual void ReadCachedL(TInt64 aPos,TInt aLength,TDes8& aDes) const = 0;
sl@0
   310
	
sl@0
   311
    /**
sl@0
   312
	Write data to the media via simple WT data cache if it is present. Some media types, like RAM do not have caches.
sl@0
   313
	@param aPos		Media position in bytes
sl@0
   314
	@param aDes		Data to write
sl@0
   315
	*/
sl@0
   316
	virtual void WriteCachedL(TInt64 aPos,const TDesC8& aDes) = 0;
sl@0
   317
    
sl@0
   318
    virtual void InvalidateUidCache() {}
sl@0
   319
    virtual void InvalidateUidCachePage(TUint64 /*aPos*/) {}
sl@0
   320
    
sl@0
   321
sl@0
   322
	/**
sl@0
   323
	Disk read function
sl@0
   324
	
sl@0
   325
	@param aPos		Media position in bytes
sl@0
   326
	@param aLength	Length in bytes of read
sl@0
   327
	@param aTrg		Pointer to the data descriptor, i.e. (const TAny*)(&TDes8)
sl@0
   328
	@param aMessage	Refrence to server message from request
sl@0
   329
	@param anOffset	Offset into read data to write
sl@0
   330
	*/
sl@0
   331
	virtual void ReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const = 0;
sl@0
   332
sl@0
   333
	/**
sl@0
   334
	Disk write function
sl@0
   335
sl@0
   336
	@param aPos		Media position in bytes
sl@0
   337
	@param aLength	Length in bytes of write
sl@0
   338
	@param aTrg		Pointer to the data descriptor, i.e. (const TAny*)(&TDes8)
sl@0
   339
	@param aMessage	Refrence to server message from request, contains data
sl@0
   340
	@param anOffset	Offset into write data to use in write
sl@0
   341
	*/
sl@0
   342
	virtual void WriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset) = 0;
sl@0
   343
sl@0
   344
    
sl@0
   345
    virtual inline MWTCacheInterface* DirCacheInterface();
sl@0
   346
sl@0
   347
sl@0
   348
sl@0
   349
sl@0
   350
protected:
sl@0
   351
sl@0
   352
    CRawDisk(CFatMountCB& aOwner);
sl@0
   353
sl@0
   354
    //-- outlawed
sl@0
   355
    CRawDisk(); 
sl@0
   356
    CRawDisk(const CRawDisk&); 
sl@0
   357
    CRawDisk& operator=(const CRawDisk&);
sl@0
   358
sl@0
   359
sl@0
   360
protected:
sl@0
   361
sl@0
   362
	CFatMountCB* iFatMount; ///< Owning file system mount
sl@0
   363
    
sl@0
   364
    
sl@0
   365
sl@0
   366
	};
sl@0
   367
sl@0
   368
class CFatFileCB;
sl@0
   369
class RBitVector;
sl@0
   370
sl@0
   371
/** 
sl@0
   372
    A helper class. Holds the FAT volume parameters, which in turn are obtained from the Boot Sector
sl@0
   373
*/
sl@0
   374
class TFatVolParam
sl@0
   375
    {
sl@0
   376
public:   
sl@0
   377
sl@0
   378
    TFatVolParam();
sl@0
   379
    void Populate(const TFatBootSector& aBootSector);
sl@0
   380
    TBool operator==(const TFatVolParam& aRhs) const;
sl@0
   381
sl@0
   382
    //-- simple getters
sl@0
   383
    TUint32 ClusterSizeLog2() const     {return iClusterSizeLog2;    }        
sl@0
   384
    TUint32 SectorSizeLog2() const      {return iSectorSizeLog2;     }        
sl@0
   385
    TUint32 RootDirEnd() const          {return iRootDirEnd;         }        
sl@0
   386
    TUint32 SectorsPerCluster() const   {return iSectorsPerCluster;  }        
sl@0
   387
    TUint32 RootDirectorySector() const {return iRootDirectorySector;}        
sl@0
   388
    TUint32 FirstFatSector() const      {return iFirstFatSector;     }        
sl@0
   389
    TUint32 TotalSectors() const        {return iTotalSectors;       }        
sl@0
   390
    TUint32 NumberOfFats() const        {return iNumberOfFats;       }        
sl@0
   391
    TUint32 FatSizeInBytes() const      {return iFatSizeInBytes;     }        
sl@0
   392
    TUint32 RootClusterNum() const      {return iRootClusterNum;     }        
sl@0
   393
    TUint32 FSInfoSectorNum() const     {return iFSInfoSectorNum;    }        
sl@0
   394
    TUint32 BkFSInfoSectorNum() const   {return iBkFSInfoSectorNum;  }        
sl@0
   395
 
sl@0
   396
protected:
sl@0
   397
    TUint32 iClusterSizeLog2;      ///< Log2 of fat file system cluster size
sl@0
   398
    TUint32 iSectorSizeLog2;       ///< Log2 of media sector size
sl@0
   399
    TUint32 iRootDirEnd;           ///< End position of the root directory for Fat12/16
sl@0
   400
    TUint32 iSectorsPerCluster;    ///< Sector per cluster ratio for mounted Fat file system volume 
sl@0
   401
    TUint32 iRootDirectorySector;  ///< Start sector of the root directory for Fat12/16
sl@0
   402
    TUint32 iFirstFatSector;       ///< Start sector of the first Fat table in volume
sl@0
   403
    TUint32 iTotalSectors;         ///< Total sectors on media partition
sl@0
   404
    TUint32 iNumberOfFats;         ///< Number of Fats the volume has
sl@0
   405
    TUint32 iFatSizeInBytes;       ///< Size of a single Fat table in volume
sl@0
   406
    TUint32 iRootClusterNum;       ///< Cluster number for Root directory, for Fat32
sl@0
   407
    TUint32 iFSInfoSectorNum;      ///< FSInfo Sector number. If 0, this means that corresponding value isn't set in BPB
sl@0
   408
    TUint32 iBkFSInfoSectorNum;    ///< backup FSInfo Sector number
sl@0
   409
    };
sl@0
   410
sl@0
   411
sl@0
   412
TBool IsLegalDosName(const TDesC&  aName, TBool anAllowWildCards, TBool aUseExtendedChars, TBool aInScanDrive, TBool aAllowLowerCase, TBool aIsForFileCreation);
sl@0
   413
TBool IsLegalDOSNameChar(TChar aCharacter, TBool aUseExtendedChars);
sl@0
   414
sl@0
   415
TUint32 CalculatePageOffsetInCluster(TUint32 aPos, TUint aPageSzLog2);
sl@0
   416
sl@0
   417
class CLruCache;
sl@0
   418
class TLeafDirData;
sl@0
   419
class CLeafDirCache;
sl@0
   420
sl@0
   421
sl@0
   422
/**
sl@0
   423
Fat file system mount implmentation, provides all that is required of a plug in
sl@0
   424
file system mount as well as Fat mount specific functionality 
sl@0
   425
*/
sl@0
   426
class CFatMountCB : public CLocDrvMountCB, 
sl@0
   427
					public MFileSystemSubType,
sl@0
   428
					public MFileSystemClusterSize,
sl@0
   429
					public CMountCB::MFileAccessor,
sl@0
   430
					public CMountCB::MFileExtendedInterface
sl@0
   431
	{
sl@0
   432
public:
sl@0
   433
	static CFatMountCB* NewL();
sl@0
   434
	~CFatMountCB();
sl@0
   435
    void ConstructL();
sl@0
   436
sl@0
   437
public:
sl@0
   438
	
sl@0
   439
	//-- overrides from the abstract CMountCB
sl@0
   440
    void MountL(TBool aForceMount);
sl@0
   441
	TInt ReMount();
sl@0
   442
	void Dismounted();
sl@0
   443
	void VolumeL(TVolumeInfo& aVolume) const;
sl@0
   444
	void SetVolumeL(TDes& aName);
sl@0
   445
	void MkDirL(const TDesC& aName);
sl@0
   446
	void RmDirL(const TDesC& aName);
sl@0
   447
	void DeleteL(const TDesC& aName);
sl@0
   448
	void RenameL(const TDesC& anOldName,const TDesC& anNewName);
sl@0
   449
	void ReplaceL(const TDesC& anOldName,const TDesC& anNewName);
sl@0
   450
	void EntryL(const TDesC& aName,TEntry& anEntry) const;
sl@0
   451
	void SetEntryL(const TDesC& aName,const TTime& aTime,TUint aMask,TUint aVal);
sl@0
   452
	void FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile);
sl@0
   453
	void DirOpenL(const TDesC& aName,CDirCB* aDir);
sl@0
   454
	void RawReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt anOffset,const RMessagePtr2& aMessage) const;
sl@0
   455
	void RawWriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt anOffset,const RMessagePtr2& aMessage);
sl@0
   456
	void GetShortNameL(const TDesC& aLongName,TDes& aShortName);
sl@0
   457
	void GetLongNameL(const TDesC& aShortName,TDes& aLongName);
sl@0
   458
	void ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage);
sl@0
   459
    TInt CheckDisk();
sl@0
   460
	TInt ScanDrive();
sl@0
   461
	TInt ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2);
sl@0
   462
	TInt Lock(TMediaPassword& aOld,TMediaPassword& aNew,TBool aStore);
sl@0
   463
	TInt Unlock(TMediaPassword& aPassword,TBool aStore);
sl@0
   464
	TInt ClearPassword(TMediaPassword& aPassword);
sl@0
   465
	TInt ErasePassword();
sl@0
   466
	TInt ForceRemountDrive(const TDesC8* aMountInfo,TInt aMountInfoMessageHandle,TUint aFlags);
sl@0
   467
    
sl@0
   468
    void FinaliseMountL();
sl@0
   469
    void FinaliseMountL(TInt aOperation, TAny* aParam1=NULL, TAny* aParam2=NULL);
sl@0
   470
    TInt MountControl(TInt aLevel, TInt aOption, TAny* aParam);
sl@0
   471
	TTimeIntervalSeconds TimeOffset() const;
sl@0
   472
sl@0
   473
protected:
sl@0
   474
sl@0
   475
    /** CFatMountCB states */
sl@0
   476
    enum  TFatMntState
sl@0
   477
        {
sl@0
   478
        ENotMounted = 0, ///< 0, initial state, not mounted     (mount state is inconsistent)
sl@0
   479
        EMounting,       ///< 1, Mounting started               (mount state is inconsistent)
sl@0
   480
        EInit_R,         ///< 2, Initialised and not written    (mount state is Consistent)
sl@0
   481
        EInit_W,         ///< 3, Initialised and written        (mount state is Consistent)
sl@0
   482
        EFinalised,      ///< 4, Finalised                      (mount state is Consistent)
sl@0
   483
        EDismounted,     ///< 5, Dismounted                     (mount state is inconsistent)
sl@0
   484
        EInit_Forced,    ///< 6, forcedly mounted, special case (mount state is inconsistent)
sl@0
   485
        };
sl@0
   486
sl@0
   487
    inline TFatMntState State() const;
sl@0
   488
    inline void SetState(TFatMntState aState); 
sl@0
   489
    TInt OpenMountForWrite();
sl@0
   490
    TInt IsFinalised(TBool& aFinalised);
sl@0
   491
sl@0
   492
    /** 
sl@0
   493
        A wrapper around TDriveInterface providing its instantination and destruction.
sl@0
   494
        You must not create objects of this class, use DriveInterface() instead.
sl@0
   495
    */
sl@0
   496
    class XDriveInterface: public TDriveInterface
sl@0
   497
        {
sl@0
   498
      public:
sl@0
   499
        XDriveInterface() : TDriveInterface() {}
sl@0
   500
        ~XDriveInterface() {Close();}
sl@0
   501
        TBool Init(CFatMountCB* aMount) {return TDriveInterface::Init(aMount);}
sl@0
   502
        };
sl@0
   503
sl@0
   504
sl@0
   505
public:
sl@0
   506
    
sl@0
   507
	enum TRenMode {EModeReplace,EModeRename};
sl@0
   508
sl@0
   509
    TBool ConsistentState() const; 
sl@0
   510
    void CheckWritableL() const;
sl@0
   511
    void CheckStateConsistentL() const;
sl@0
   512
sl@0
   513
	inline TBool ReadOnly(void) const;
sl@0
   514
    inline void  SetReadOnly(TBool aReadOnlyMode);
sl@0
   515
	inline TInt StartCluster(const TFatDirEntry & anEntry) const;
sl@0
   516
	inline CRawDisk& RawDisk() const;
sl@0
   517
	inline CFatFileSystem& FatFileSystem() const;
sl@0
   518
	inline CFatTable& FAT() const;
sl@0
   519
	inline TInt ClusterSizeLog2() const;
sl@0
   520
	inline TInt SectorSizeLog2() const;
sl@0
   521
	inline TInt TotalSectors() const;
sl@0
   522
	inline TInt SectorsPerCluster() const;
sl@0
   523
	inline TInt ClusterBasePosition() const;
sl@0
   524
    inline TInt RootDirectorySector() const;
sl@0
   525
    inline TUint RootDirEnd() const;
sl@0
   526
    inline TUint32 RootClusterNum() const;
sl@0
   527
sl@0
   528
	inline TFatType FatType() const;
sl@0
   529
    inline TBool Is16BitFat() const;
sl@0
   530
    inline TBool Is32BitFat() const;
sl@0
   531
sl@0
   532
	inline TUint32 MaxClusterNumber() const;
sl@0
   533
	inline TInt StartOfFatInBytes() const;
sl@0
   534
    inline TUint32 FirstFatSector() const;
sl@0
   535
sl@0
   536
	inline TInt NumberOfFats() const;
sl@0
   537
	inline TInt FatSizeInBytes() const;
sl@0
   538
	inline TInt ClusterRelativePos(TInt aPos) const;
sl@0
   539
	inline TUint StartOfRootDirInBytes() const;
sl@0
   540
	inline TUint32 UsableClusters() const;
sl@0
   541
	inline TBool IsBadCluster(TInt aCluster) const;
sl@0
   542
	inline TBool IsRuggedFSys() const;
sl@0
   543
	inline void SetRuggedFSys(TBool aVal);
sl@0
   544
	
sl@0
   545
	inline TInt RootIndicator() const;
sl@0
   546
	
sl@0
   547
    inline TBool IsRootDir(const TEntryPos &aEntry) const;
sl@0
   548
	inline CAsyncNotifier* Notifier() const;
sl@0
   549
	inline TDriveInterface& DriveInterface() const;
sl@0
   550
sl@0
   551
    inline TBool IsEndOfClusterCh(TInt aCluster) const;
sl@0
   552
	inline void SetEndOfClusterCh(TInt &aCluster) const;
sl@0
   553
sl@0
   554
    
sl@0
   555
    void ReadUidL(TInt aCluster,TEntry& anEntry) const;
sl@0
   556
	
sl@0
   557
    void ReadDirEntryL(const TEntryPos& aPos,TFatDirEntry& aDirEntry) const;
sl@0
   558
	void WriteDirEntryL(const TEntryPos& aPos,const TFatDirEntry& aDirEntry);
sl@0
   559
sl@0
   560
    void DirReadL(const TEntryPos& aPos,TInt aLength,TDes8& aDes) const;
sl@0
   561
    void DirWriteL(const TEntryPos& aPos,const TDesC8& aDes);
sl@0
   562
sl@0
   563
	void ReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const;
sl@0
   564
	void WriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt& aBadcluster, TInt &aGoodcluster);
sl@0
   565
	void MoveToNextEntryL(TEntryPos& aPos) const;
sl@0
   566
	void MoveToDosEntryL(TEntryPos& aPos,TFatDirEntry& anEntry) const;
sl@0
   567
	void EnlargeL(TInt aSize);
sl@0
   568
	void ReduceSizeL(TInt aPos,TInt aLength);
sl@0
   569
	void DoDismount();
sl@0
   570
    TBool ProcessFSInfoSectors(CFatTable::TMountParams& aFatInitParams) const;
sl@0
   571
    
sl@0
   572
sl@0
   573
	void DoRenameOrReplaceL(const TDesC& anOldName,const TDesC& aNewName,TRenMode aMode,TEntryPos& aNewPos);
sl@0
   574
	void FindDosNameL(const TDesC& aName,TUint anAtt,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName,TInt anError) const;
sl@0
   575
	
sl@0
   576
	void Dismount();
sl@0
   577
	
sl@0
   578
    void InitializeRootEntry(TFatDirEntry & anEntry) const;
sl@0
   579
sl@0
   580
    TInt64 MakeLinAddrL(const TEntryPos& aPos) const;
sl@0
   581
	
sl@0
   582
    inline const TFatConfig& FatConfig() const;
sl@0
   583
    TBool CheckVolumeTheSame();
sl@0
   584
sl@0
   585
    void InvalidateLeafDirCache();
sl@0
   586
    
sl@0
   587
    void BlockMapReadFromClusterListL(TEntryPos& aPos, TInt aLength, SBlockMapInfo& aInfo);
sl@0
   588
	virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
sl@0
   589
	virtual TInt GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId);
sl@0
   590
	virtual TInt Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2);
sl@0
   591
	virtual TInt Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2);
sl@0
   592
	virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2);
sl@0
   593
sl@0
   594
public:
sl@0
   595
	
sl@0
   596
    // interface extension implementation
sl@0
   597
	virtual TInt SubType(TDes& aName) const;
sl@0
   598
	virtual TInt ClusterSize() const;
sl@0
   599
    virtual void ReadSection64L(const TDesC& aName, TInt64 aPos, TAny* aTrg, TInt aLength, const RMessagePtr2& aMessage);
sl@0
   600
sl@0
   601
private:
sl@0
   602
    
sl@0
   603
    /** An ad hoc internal helper object for using in DoFindL() method and its derivatives */
sl@0
   604
    class TFindHelper
sl@0
   605
        {
sl@0
   606
        public:
sl@0
   607
            TFindHelper() {isInitialised = EFalse;}
sl@0
   608
            void  InitialiseL(const TDesC&  aTargetName);
sl@0
   609
            TBool MatchDosEntryName(const TUint8* apDosEntryName) const;
sl@0
   610
            TBool TrgtNameIsLegalDos() const {ASSERT (isInitialised) ;return isLegalDosName;}   
sl@0
   611
        
sl@0
   612
        private:
sl@0
   613
            TFindHelper(const TFindHelper&);
sl@0
   614
            TFindHelper& operator=(const TFindHelper&);
sl@0
   615
        public:
sl@0
   616
            TPtrC       iTargetName;        ///< pointer to the aTargetName, used in DoRummageDirCacheL() as a parameter
sl@0
   617
        private:
sl@0
   618
            TBool       isInitialised  :1;  ///< ETrue if the object is initialised. It can be done only once.
sl@0
   619
            TBool       isLegalDosName :1;  ///< ETrue if iTargetName is a legal DOS name
sl@0
   620
            TShortName  iShortName;         ///< a short DOS name in XXXXXXXXYYY format generated from aTargetName
sl@0
   621
        };
sl@0
   622
sl@0
   623
sl@0
   624
    	/** 
sl@0
   625
	   	An ad hoc internal helper object for entry creations 
sl@0
   626
	    */
sl@0
   627
	    class XFileCreationHelper
sl@0
   628
	    {
sl@0
   629
	    public:
sl@0
   630
	    	XFileCreationHelper();
sl@0
   631
	    	~XFileCreationHelper();
sl@0
   632
	    	void Close();
sl@0
   633
	    	void InitialiseL(const TDesC&  aTargetName);
sl@0
   634
	        TInt GetValidatedShortName(TShortName& aShortName) const;
sl@0
   635
	    	void CheckShortNameCandidates(const TUint8* apDosEntryName);
sl@0
   636
	
sl@0
   637
	        // inline functions for sets and gets
sl@0
   638
	        //  note all the get functions have been checked against initialisation status
sl@0
   639
	    	inline TBool 	IsInitialised() const;
sl@0
   640
	        inline TUint16	NumOfAddingEntries() const;
sl@0
   641
	        inline TEntryPos EntryAddingPos()const;
sl@0
   642
	        inline TBool 	IsNewEntryPosFound() const;
sl@0
   643
	    	inline TBool 	IsTrgNameLegalDosName() const;
sl@0
   644
	
sl@0
   645
	    	inline void	SetEntryAddingPos(const TEntryPos& aEntryPos);
sl@0
   646
	    	inline void	SetIsNewEntryPosFound(TBool aFound);
sl@0
   647
	
sl@0
   648
	    private:
sl@0
   649
	    	XFileCreationHelper(const XFileCreationHelper&);
sl@0
   650
	    	XFileCreationHelper& operator=(const TFindHelper&);
sl@0
   651
	
sl@0
   652
	    private:
sl@0
   653
	        TPtrC       iTargetName;		///< pointer to hold the long file name of the target file
sl@0
   654
	        TUint16		iNumOfAddingEntries;///< calculated number of entries to add
sl@0
   655
	        TEntryPos	iEntryAddingPos;	///< contains new entry position for adding if found any
sl@0
   656
	        TBool		isNewEntryPosFound; ///< flags whether the position for new entries is found
sl@0
   657
	        TBool       isInitialised	:1;	///< flags whether the object is initialised
sl@0
   658
	        TBool       isTrgNameLegalDosName	:1;	///< flags whether the target file name is a valid Dos name
sl@0
   659
	        /**
sl@0
   660
	        an array that holds short name candidates, prepared on initialisation.
sl@0
   661
	        */
sl@0
   662
	        RArray<TShortName>  iShortNameCandidates;
sl@0
   663
	    };
sl@0
   664
sl@0
   665
	
sl@0
   666
sl@0
   667
	TBool DoRummageDirCacheL(TUint anAtt,TEntryPos& aStartEntryPos,TFatDirEntry& aStartEntry,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName, const TFindHelper& aAuxParam, XFileCreationHelper* aFileCreationHelper, const TLeafDirData& aLeafDir) const;
sl@0
   668
    TBool DoFindL(const TDesC& aName,TUint anAtt,TEntryPos& aStartEntryPos,TFatDirEntry& aStartEntry,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName,TInt anError, XFileCreationHelper* aFileCreationHelper, const TLeafDirData& aLeafDirData) const;
sl@0
   669
    void FindEntryStartL(const TDesC& aName,TUint anAtt,TFatDirEntry& anEntry,TEntryPos& aPos, XFileCreationHelper* aFileCreationHelper) const;
sl@0
   670
sl@0
   671
    void FindEntryStartL(const TDesC& aName,TUint anAtt,TFatDirEntry& anEntry,TEntryPos& aPos) const;
sl@0
   672
sl@0
   673
	void CheckFatForLoopsL(const TFatDirEntry& anEntry) const;
sl@0
   674
	void DoCheckFatForLoopsL(TInt aCluster,TInt& aPreviousCluster,TInt& aChangePreviousCluster,TInt& aCount) const;
sl@0
   675
    void InitializeL(const TLocalDriveCaps& aLocDrvCaps, TBool aIgnoreFSInfo=EFalse);
sl@0
   676
	void DoReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const;
sl@0
   677
	void DoWriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt aLastcluster, TInt& aBadcluster, TInt& aGoodcluster);
sl@0
   678
	TBool IsUniqueNameL(const TShortName& aName,TInt aDirCluster);
sl@0
   679
	TBool FindShortNameL(const TShortName& aName,TEntryPos& anEntryPos);
sl@0
   680
	void ReplaceClashingNameL(const TShortName& aNewName,const TEntryPos& anEntryPos);
sl@0
   681
    TBool GenerateShortNameL(TInt aDirCluster,const TDesC& aLongName,TShortName& aShortName, TBool aForceRandomize=EFalse);
sl@0
   682
    TInt FindLeafDirL(const TDesC& aName, TLeafDirData& aLeafDir) const;
sl@0
   683
	
sl@0
   684
	TInt GetDirEntry(TEntryPos& aPos,TFatDirEntry& aDosEntry,TFatDirEntry& aStartEntry,TDes& aLongFileName) const;
sl@0
   685
    TBool DoGetDirEntryL(TEntryPos& aPos,TFatDirEntry& aDosEntry,TFatDirEntry& aStartEntry,TDes& aLongFileName) const;
sl@0
   686
    
sl@0
   687
	void WriteDirEntryL(TEntryPos& aPos,const TFatDirEntry& aFatDirEntry,const TDesC& aLongFileName);
sl@0
   688
	void EraseDirEntryL(TEntryPos aPos,const TFatDirEntry& anEntry);
sl@0
   689
	void EraseDirEntryL(const TEntryPos& aPos);
sl@0
   690
	void InitializeFirstDirClusterL(TInt aCluster,TInt aParentCluster);
sl@0
   691
	void AddDirEntryL(TEntryPos& aPos,TInt aNameLength);
sl@0
   692
	void ZeroDirClusterL(TInt aCluster);
sl@0
   693
	
sl@0
   694
    TInt DoWriteBootSector(TInt64 aMediaPos, const TFatBootSector& aBootSector) const;
sl@0
   695
	TInt DoReadBootSector(TInt64 aMediaPos, TFatBootSector& aBootSector) const;
sl@0
   696
    TInt ReadBootSector(TFatBootSector& aBootSector, TBool aDoNotReadBkBootSec=EFalse);
sl@0
   697
sl@0
   698
    TInt WriteFSInfoSector(TInt64 aMediaPos, const TFSInfo& aFSInfo) const;
sl@0
   699
	TInt ReadFSInfoSector(TInt64 aMediaPos, TFSInfo& aFSInfo) const;
sl@0
   700
sl@0
   701
    TBool IsDirectoryEmptyL(TInt aCluster);
sl@0
   702
	void ExtendClusterListZeroedL(TInt aNumber,TInt& aCluster);
sl@0
   703
	void WritePasswordData();
sl@0
   704
	
sl@0
   705
    void WriteVolumeLabelL(const TDesC8& aVolumeLabel) const;
sl@0
   706
    TInt ReadVolumeLabelFile(TDes8& aLabel);
sl@0
   707
	void WriteVolumeLabelFileL(const TDesC8& aNewName);
sl@0
   708
	void FindVolumeLabelFileL(TDes8& aLabel, TEntryPos& aDosEntryPos, TFatDirEntry& aDosEntry);
sl@0
   709
	void GetVolumeLabelFromDiskL(const TFatBootSector& aBootSector);
sl@0
   710
	void TrimVolumeLabel(TDes8& aLabel) const;
sl@0
   711
sl@0
   712
    TInt    DoRunScanDrive();
sl@0
   713
    TBool   VolumeCleanL();
sl@0
   714
    void    SetVolumeCleanL(TBool aClean);
sl@0
   715
    TBool   VolCleanFlagSupported() const;
sl@0
   716
sl@0
   717
    void    DoUpdateFSInfoSectorsL(TBool aInvalidateFSInfo);
sl@0
   718
    void    UnFinaliseMountL();
sl@0
   719
    void    DoReMountL();
sl@0
   720
    void    SetFatType(TFatType aFatType);
sl@0
   721
sl@0
   722
sl@0
   723
private:
sl@0
   724
	
sl@0
   725
sl@0
   726
	CFatMountCB();
sl@0
   727
sl@0
   728
	TInt GetDosEntryFromNameL(const TDesC& aName, TEntryPos& aDosEntryPos, TFatDirEntry& aDosEntry);
sl@0
   729
sl@0
   730
    TInt MntCtl_DoCheckFileSystemMountable();
sl@0
   731
sl@0
   732
sl@0
   733
private:
sl@0
   734
sl@0
   735
    TBool iReadOnly         : 1;///< if true, the drive is in read-only mode 
sl@0
   736
    TBool iRamDrive         : 1;///< true if this is a RAM drive    
sl@0
   737
    TBool iMainBootSecValid : 1;///< true if the main boot sector is valid, if false, a backup boot sector may be in use. 
sl@0
   738
sl@0
   739
    TFatMntState iState;        ///< this mounnt internal state
sl@0
   740
sl@0
   741
    TFatType iFatType;          ///< FAT type, FAT12,16 or 32
sl@0
   742
    TUint32  iFatEocCode;       ///< End Of Cluster Chain code, 0xff8 for FAT12, 0xfff8 for FAT16, and 0xffffff8 for FAT32 
sl@0
   743
sl@0
   744
    CLeafDirCache* iLeafDirCache;	///< A cache for most recently visited directories, only valid when limit is set bigger than 1
sl@0
   745
    HBufC* iLastLeafDir;        	///< The last visited directory, only valid when limit of iLeafDirCache is less than 1 
sl@0
   746
    TInt iLastLeafDirCluster;   	///< Cluster number of the last visited cluster, only valid when limit of iLeafDirCache is less than 1
sl@0
   747
sl@0
   748
	TFatVolParam iVolParam;         ///< FAT volume parameters, populated form the boot sector values.
sl@0
   749
    
sl@0
   750
	TInt iFirstFreeByte;            ///< First free byte in media (start of the data area on the volume)
sl@0
   751
	TUint32 iUsableClusters;        ///< Number of usable cluster on the volume 
sl@0
   752
	
sl@0
   753
    CFatTable* iFatTable;           ///< Pointer to the volume Fat 
sl@0
   754
	CRawDisk*  iRawDisk;            ///< Pointer to the raw data interface class
sl@0
   755
	
sl@0
   756
    CAsyncNotifier* iNotifier;  ///< Async notifier for notifying user of Fat error conditions 
sl@0
   757
sl@0
   758
    XDriveInterface iDriverInterface; ///< the object representing interface to the drive, provides read/write access and notifiers
sl@0
   759
    TInt            iChkDiscRecLevel; ///< Check disk recursion level counter. A temporary measure. 
sl@0
   760
	TFatConfig      iFatConfig;       ///< FAT parametrers from estart.txt
sl@0
   761
sl@0
   762
	XFileCreationHelper iFileCreationHelper;
sl@0
   763
sl@0
   764
sl@0
   765
#ifdef  _DEBUG
sl@0
   766
    private:
sl@0
   767
    //-- debug odds and ends
sl@0
   768
    inline TBool IsWriteFail()const;
sl@0
   769
	inline void SetWriteFail(TBool aIsWriteFail);
sl@0
   770
	inline TInt WriteFailCount()const;
sl@0
   771
	inline void SetWriteFailCount(TInt aFailCount);
sl@0
   772
	inline void DecWriteFailCount();
sl@0
   773
	inline TInt WriteFailError()const;
sl@0
   774
	inline void SetWriteFailError(TInt aErrorValue);
sl@0
   775
sl@0
   776
sl@0
   777
	TBool   iIsWriteFail : 1; ///< Flag to indicate if write failed used for debugging
sl@0
   778
    TBool   iCBRecFlag   : 1; ///< in debug mode used for checking unwanted recursion
sl@0
   779
sl@0
   780
    TInt    iWriteFailCount;  ///< Write fail count for debug
sl@0
   781
	TInt    iWriteFailError;  ///< Write fail error to use for debug
sl@0
   782
sl@0
   783
#endif
sl@0
   784
sl@0
   785
friend class CFatFormatCB;
sl@0
   786
friend class CScanDrive;
sl@0
   787
friend class TDriveInterface;
sl@0
   788
	};
sl@0
   789
sl@0
   790
sl@0
   791
sl@0
   792
sl@0
   793
/**
sl@0
   794
Fat file system file subsession implmentation, provides all that is required of a plug in
sl@0
   795
file system file as well as Fat specific functionality
sl@0
   796
*/
sl@0
   797
class CFatFileCB : public CFileCB, public CFileCB::MBlockMapInterface, public CFileCB::MExtendedFileInterface
sl@0
   798
	{
sl@0
   799
public:
sl@0
   800
	CFatFileCB();
sl@0
   801
	~CFatFileCB();
sl@0
   802
public:
sl@0
   803
	void RenameL(const TDesC& aNewName);
sl@0
   804
	void ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
sl@0
   805
	void WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
sl@0
   806
	void SetSizeL(TInt aSize);
sl@0
   807
	void SetEntryL(const TTime& aTime,TUint aMask,TUint aVal);
sl@0
   808
	void FlushDataL();
sl@0
   809
	void FlushAllL();
sl@0
   810
public:
sl@0
   811
	void CheckPosL(TUint aPos);
sl@0
   812
	void SetL(const TFatDirEntry& aFatDirEntry,TShare aShare,const TEntryPos& aPos);
sl@0
   813
	void CreateSeekIndex();
sl@0
   814
	
sl@0
   815
    inline TBool IsSeekIndex() const;	
sl@0
   816
	
sl@0
   817
	// from MBlockMapInterface
sl@0
   818
	TInt BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos);
sl@0
   819
sl@0
   820
	// from CFileCB
sl@0
   821
	virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
sl@0
   822
sl@0
   823
	// from CFileCB::MExtendedFileInterface
sl@0
   824
	virtual void ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
sl@0
   825
	virtual void WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
sl@0
   826
	virtual void SetSizeL(TInt64 aSize);
sl@0
   827
sl@0
   828
private:
sl@0
   829
	inline CFatMountCB& FatMount() const;
sl@0
   830
    inline CFatTable& FAT();
sl@0
   831
	inline TInt ClusterSizeLog2();
sl@0
   832
	inline TInt ClusterRelativePos(TInt aPos);
sl@0
   833
sl@0
   834
sl@0
   835
    void FlushStartClusterL();
sl@0
   836
	TInt SeekToPosition(TInt aNewCluster,TInt aClusterOffset);
sl@0
   837
	void SetSeekIndexValueL(TInt aFileCluster,TInt aStoredCluster);
sl@0
   838
	void ResizeIndex(TInt aNewMult,TUint aNewSize);
sl@0
   839
	TInt CalcSeekIndexSize(TUint aSize);
sl@0
   840
	TBool IsSeekBackwards(TUint aPos);
sl@0
   841
	void ClearIndex(TUint aNewSize);
sl@0
   842
	void DoSetSizeL(TUint aSize,TBool aIsSizeWrite);
sl@0
   843
	void WriteFileSizeL(TUint aSize);
sl@0
   844
sl@0
   845
private:
sl@0
   846
sl@0
   847
	TUint32* iSeekIndex;    ///< Seek index into file
sl@0
   848
	TInt iSeekIndexSize;    ///< size of seek index
sl@0
   849
	TInt iStartCluster;     ///< Start cluster number of file
sl@0
   850
	TEntryPos iCurrentPos;  ///< Current position in file data
sl@0
   851
	TEntryPos iFileDirPos;  ///< File directory entry position
sl@0
   852
	TBool iFileSizeModified; 
sl@0
   853
	};
sl@0
   854
sl@0
   855
sl@0
   856
/**
sl@0
   857
Fat file system directory subsession implmentation, provides all that is required of a plug in
sl@0
   858
file system directory as well as Fat specific functionality
sl@0
   859
*/
sl@0
   860
class CFatDirCB : public CDirCB
sl@0
   861
	{
sl@0
   862
public:
sl@0
   863
	static CFatDirCB* NewL();
sl@0
   864
	~CFatDirCB();
sl@0
   865
public:
sl@0
   866
	void ReadL(TEntry& anEntry);
sl@0
   867
	void StoreLongEntryNameL(const TDesC& aName);
sl@0
   868
public:
sl@0
   869
	void SetDirL(const TFatDirEntry& anEntry,const TDesC& aMatchName);
sl@0
   870
	inline CFatMountCB& FatMount();
sl@0
   871
private:
sl@0
   872
	CFatDirCB();
sl@0
   873
private:
sl@0
   874
	TFatDirEntry iEntry;       ///< Current directory entry in this directory
sl@0
   875
	TEntryPos    iCurrentPos;  ///< Current position in directory
sl@0
   876
	HBufC*       iMatch;       ///< Current name being searched in directory (Dos Name)
sl@0
   877
	HBufC*       iLongNameBuf; ///< Long name storage	
sl@0
   878
	TBool        iMatchUid;    ///< Flag to indicate if UID matches
sl@0
   879
	};
sl@0
   880
sl@0
   881
/**
sl@0
   882
    Fat file system Format subsession implmentation, provides all that is required of a plug in
sl@0
   883
    file system format as well as Fat specific functionality
sl@0
   884
*/
sl@0
   885
class CFatFormatCB : public CFormatCB
sl@0
   886
	{
sl@0
   887
public:
sl@0
   888
	CFatFormatCB();
sl@0
   889
	~CFatFormatCB();
sl@0
   890
public:
sl@0
   891
	
sl@0
   892
    //-- overrides from CFormatCB
sl@0
   893
    void DoFormatStepL();
sl@0
   894
sl@0
   895
private:
sl@0
   896
    //-- overrides from CFormatCB
sl@0
   897
    TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
sl@0
   898
sl@0
   899
private:	
sl@0
   900
    
sl@0
   901
    TInt DoProcessTVolFormatParam(const TVolFormatParam_FAT* apVolFormatParam);
sl@0
   902
sl@0
   903
    void CreateBootSectorL();
sl@0
   904
	void CreateFSInfoSectorL();
sl@0
   905
	void CreateReservedBootSectorL();
sl@0
   906
	void InitializeFormatDataL();
sl@0
   907
	void DoZeroFillMediaL(TInt64 aStartPos, TInt64 aEndPos);
sl@0
   908
sl@0
   909
    TInt InitFormatDataForVariableSizeDisk(TInt aDiskSizeInSectors);
sl@0
   910
	TInt InitFormatDataForFixedSizeDiskNormal(TInt aDiskSizeInSectors, const TLocalDriveCapsV6& aCaps);
sl@0
   911
	TInt InitFormatDataForFixedSizeDiskCustom(const TLDFormatInfo& aFormatInfo);
sl@0
   912
    TInt InitFormatDataForFixedSizeDiskUser(TInt aDiskSizeInSectors);
sl@0
   913
	void AdjustClusterSize(TInt aRecommendedSectorsPerCluster);
sl@0
   914
	TInt AdjustFirstDataSectorAlignment(TInt aBlockSize);
sl@0
   915
	TInt FirstDataSector() const;
sl@0
   916
sl@0
   917
	TInt HandleCorrupt(TInt aError);
sl@0
   918
	TInt BadSectorToCluster();
sl@0
   919
    void TranslateL();
sl@0
   920
    TInt DoTranslate(TPtr8& aBuf, RArray<TInt>& aArray);
sl@0
   921
    void RecordOldInfoL();
sl@0
   922
	TInt MaxFat12Sectors() const;
sl@0
   923
	TInt MaxFat16Sectors() const;
sl@0
   924
	TUint32 MaxFat32Sectors() const;
sl@0
   925
	inline TBool Is16BitFat() const;
sl@0
   926
	inline TBool Is32BitFat() const;
sl@0
   927
	inline CFatMountCB& FatMount();
sl@0
   928
	inline CProxyDrive* LocalDrive();
sl@0
   929
    TFatType SuggestFatType() const;
sl@0
   930
sl@0
   931
private:
sl@0
   932
	
sl@0
   933
    TBool   iVariableSize;      ///< Flag to indicat if we are dealing with a variable size volume
sl@0
   934
	TInt    iBytesPerSector;    ///< Byte per sector of media
sl@0
   935
    TInt    iSectorSizeLog2;    ///< Sector size in log2
sl@0
   936
	TInt    iNumberOfFats;      ///< Number of Fats the volume will contain
sl@0
   937
	TInt    iReservedSectors;   ///< Number of reserved sectors in the volume
sl@0
   938
	TInt    iRootDirEntries;    ///< Nummer of root directory entries the root dir will have, specific to Fat12/16 volumes
sl@0
   939
	TInt    iSectorsPerCluster; ///< Sector per cluster ration the volume will be formatted with
sl@0
   940
	TInt    iSectorsPerFat;     ///< Number of sectors the Fat uses
sl@0
   941
	TInt    iMaxDiskSectors;    ///< number of sectors the volume has
sl@0
   942
	TFormatInfo iFormatInfo;    ///< format information for a custom format
sl@0
   943
	TBuf8<16>   iFileSystemName;///< Buffer to contain the volume name 
sl@0
   944
	TInt    iHiddenSectors;     ///< Number of hidden sectors in the volume
sl@0
   945
	TInt    iNumberOfHeads;     ///< Number of heads the media device has, not used so far as only used on solid state media.
sl@0
   946
	TInt    iSectorsPerTrack;   ///< Number of sectors the media device has, not used so far as only used on solid state media.
sl@0
   947
	TUint32 iRootClusterNum;    ///< cluster number used for root directory, Fat32 specific
sl@0
   948
	TUint32 iCountOfClusters;   ///< Count of clusters on the media
sl@0
   949
    RArray<TInt> iBadClusters;  ///< Array of bad cluster numbers
sl@0
   950
    RArray<TInt> iBadSectors;   ///< Array of bad sector numbers
sl@0
   951
    TBool   iDiskCorrupt;       ///< Disk is corrupt when format or not
sl@0
   952
    TInt    iOldFirstFreeSector;
sl@0
   953
    TInt    iOldSectorsPerCluster;
sl@0
   954
	};
sl@0
   955
sl@0
   956
/**
sl@0
   957
Required file system class used by file server to create the file system objects
sl@0
   958
*/
sl@0
   959
class CFatFileSystem : public CFileSystem
sl@0
   960
	{
sl@0
   961
public:
sl@0
   962
	static CFatFileSystem* New();
sl@0
   963
	~CFatFileSystem();
sl@0
   964
public:
sl@0
   965
	TInt Install();
sl@0
   966
	CMountCB* NewMountL() const;
sl@0
   967
	CFileCB* NewFileL() const;
sl@0
   968
	CDirCB* NewDirL() const;
sl@0
   969
	CFormatCB* NewFormatL() const;
sl@0
   970
	TInt DefaultPath(TDes& aPath) const;
sl@0
   971
	TBool IsExtensionSupported() const;
sl@0
   972
	TBool GetUseLocalTime() const;
sl@0
   973
	void SetUseLocalTime(TBool aFlag);
sl@0
   974
	TInt GetInterface(TInt aInterfaceId, TAny*& aInterface,TAny* aInput);
sl@0
   975
protected:
sl@0
   976
	CFatFileSystem();
sl@0
   977
	/**
sl@0
   978
	If true, then local time will be used when writing timestamps to FS. When reading,
sl@0
   979
	timestamps will be assumed local and converted back to UTC.
sl@0
   980
	At present, this behaviour will also be conditional upon a particular drive being logically removable.
sl@0
   981
	*/
sl@0
   982
	TBool iUseLocalTimeIfRemovable;
sl@0
   983
	};
sl@0
   984
sl@0
   985
sl@0
   986
sl@0
   987
/**
sl@0
   988
Locale utilities allows the file system to call into a specific locale for tasks
sl@0
   989
such as Dos name to unicode conversions and testing the legality of characters for
sl@0
   990
any given locale.
sl@0
   991
*/
sl@0
   992
class LocaleUtils
sl@0
   993
sl@0
   994
	{
sl@0
   995
public:
sl@0
   996
	static void ConvertFromUnicodeL(TDes8& aForeign, const TDesC16& aUnicode, TFatUtilityFunctions::TOverflowAction aOverflowAction=TFatUtilityFunctions::EOverflowActionTruncate);
sl@0
   997
	static void ConvertToUnicodeL(TDes16& aUnicode, const TDesC8& aForeign, TFatUtilityFunctions::TOverflowAction aOverflowAction=TFatUtilityFunctions::EOverflowActionTruncate);
sl@0
   998
	static TBool IsLegalShortNameCharacter(TUint aCharacter,TBool aUseExtendedChars=EFalse);
sl@0
   999
	};
sl@0
  1000
//
sl@0
  1001
sl@0
  1002
/**
sl@0
  1003
Converts Dos time (from a directory entry) to TTime format
sl@0
  1004
sl@0
  1005
@param aDosTime Dos format time
sl@0
  1006
@param aDosDate Dos format Date
sl@0
  1007
@return TTime format of Dos time passed in 
sl@0
  1008
*/
sl@0
  1009
TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate);
sl@0
  1010
/**
sl@0
  1011
Converts TTime format to Dos time format
sl@0
  1012
sl@0
  1013
@param aTime TTime to convert to Dos time
sl@0
  1014
@return Dos time format
sl@0
  1015
*/
sl@0
  1016
TInt DosTimeFromTTime(const TTime& aTime);
sl@0
  1017
/**
sl@0
  1018
Converts TTime format to Dos time format
sl@0
  1019
sl@0
  1020
@param aTime TTime to convert to Dos Date
sl@0
  1021
@return Dos Date format
sl@0
  1022
*/
sl@0
  1023
TInt DosDateFromTTime(const TTime& aTime);
sl@0
  1024
/**
sl@0
  1025
Converts Dos Directory entry format to 8.3 format
sl@0
  1026
sl@0
  1027
@param aDosName Directory entry format with space delimeter
sl@0
  1028
@return 8.3 Dos filename format
sl@0
  1029
*/
sl@0
  1030
TBuf8<12> DosNameToStdFormat(const TDesC8& aDosName);
sl@0
  1031
/**
sl@0
  1032
Converts 8.3 format to Dos Directory entry format 
sl@0
  1033
sl@0
  1034
@param aStdFormatName 8.3 Dos filename format
sl@0
  1035
@return Directory entry format with space delimeter
sl@0
  1036
*/
sl@0
  1037
TBuf8<12> DosNameFromStdFormat(const TDesC8& aStdFormatName);
sl@0
  1038
/**
sl@0
  1039
Fault function calls user panic with a fault reason
sl@0
  1040
sl@0
  1041
@param Enumerated fault reason
sl@0
  1042
*/
sl@0
  1043
void Fault(TFault aFault);
sl@0
  1044
/**
sl@0
  1045
calculates the number of VFat directory entries for a given file/directory name length
sl@0
  1046
sl@0
  1047
@param the length in characters of the name
sl@0
  1048
@return the number of VFat entries required
sl@0
  1049
*/
sl@0
  1050
TInt NumberOfVFatEntries(TInt aNameLength);
sl@0
  1051
/**
sl@0
  1052
Calculates the check sum for a standard directory entry
sl@0
  1053
sl@0
  1054
@param the Dos name for the directory entry
sl@0
  1055
@return the checksum
sl@0
  1056
*/
sl@0
  1057
TUint8 CalculateShortNameCheckSum(const TDesC8& aShortName);
sl@0
  1058
sl@0
  1059
TUint32 EocCodeByFatType(TFatType aFatType);
sl@0
  1060
sl@0
  1061
sl@0
  1062
#include "sl_std.inl"
sl@0
  1063
#include "sl_bpb.inl"
sl@0
  1064
#include "fat_dir_entry.inl"
sl@0
  1065
              
sl@0
  1066
#endif //SL_STD_H