os/kernelhwsrv/userlibandfileserver/fileserver/sfat/sl_dir_cache.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-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
// f32\sfat32\inc\sl_dir_cache.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    24
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    25
//!!
sl@0
    26
//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
sl@0
    27
//!!
sl@0
    28
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    29
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    30
sl@0
    31
sl@0
    32
#ifndef SL_DIR_CACHE_H
sl@0
    33
#define SL_DIR_CACHE_H
sl@0
    34
sl@0
    35
#include "sf_memory_man.h"
sl@0
    36
#include "sf_memory_client.h"
sl@0
    37
#include "sl_cache.h"
sl@0
    38
#include <e32hashtab.h>
sl@0
    39
sl@0
    40
//---------------------------------------------------------------------------------------------------------------------------------
sl@0
    41
class   CDynamicDirCache;
sl@0
    42
sl@0
    43
sl@0
    44
/**
sl@0
    45
The dynamic directory cache page class
sl@0
    46
*/
sl@0
    47
class TDynamicDirCachePage
sl@0
    48
    {
sl@0
    49
public:
sl@0
    50
    enum TPageType
sl@0
    51
        {
sl@0
    52
        EUnknown,
sl@0
    53
        ELocked,
sl@0
    54
        EUnlocked,
sl@0
    55
        EActivePage,
sl@0
    56
        };
sl@0
    57
sl@0
    58
public:
sl@0
    59
    ~TDynamicDirCachePage();
sl@0
    60
    static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
sl@0
    61
    
sl@0
    62
    inline void SetLocked(TBool);
sl@0
    63
    inline TBool    IsLocked() const;
sl@0
    64
    inline TUint8*  StartPtr()  const;
sl@0
    65
    inline void     SetStartPtr(TUint8* aPtr);
sl@0
    66
    inline void SetValid(TBool aIsValid);
sl@0
    67
    inline TBool    IsValid()   const;
sl@0
    68
    inline void SetPageType(TPageType aType);
sl@0
    69
    inline TPageType PageType();
sl@0
    70
sl@0
    71
    inline TUint32  PageSizeInBytes() const;
sl@0
    72
    inline TUint32  PageSizeInSegs() const;
sl@0
    73
sl@0
    74
    inline void SetPos(TInt64 aPos);
sl@0
    75
    inline void ResetPos();
sl@0
    76
    inline TInt64   StartPos()  const;
sl@0
    77
sl@0
    78
    inline TUint8*  PtrInPage(TInt64 aPos) const;
sl@0
    79
    inline TBool    PosCachedInPage(TInt64 aPos) const;
sl@0
    80
sl@0
    81
    inline void Deque();
sl@0
    82
sl@0
    83
private:
sl@0
    84
    // declared to disable copying and assignment
sl@0
    85
    TDynamicDirCachePage& operator=(const TDynamicDirCachePage&);
sl@0
    86
    TDynamicDirCachePage(const TDynamicDirCachePage&);
sl@0
    87
sl@0
    88
    // private constructor, as this class is not supposed to be created on stack
sl@0
    89
    TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
sl@0
    90
sl@0
    91
public:
sl@0
    92
    TDblQueLink         iLink;          ///< the embedded link object, see TCachePageList
sl@0
    93
    TInt64              iStartMedPos;   ///< the starting media address that this page caches
sl@0
    94
    TUint8*             iStartRamAddr;  ///< the starting ram address that thsi page lives
sl@0
    95
    CDynamicDirCache*   iOwnerCache;    ///< pointer to the cache that owns this page
sl@0
    96
    TBool               iValid  :1;     ///< flag to indicate the validity of the page content
sl@0
    97
    TBool               iLocked :1;     ///< flag to indicate if the page is locked or not
sl@0
    98
    TPageType           iType;          ///< page type, see TPageType
sl@0
    99
    };
sl@0
   100
sl@0
   101
/**
sl@0
   102
The lookup table entry class
sl@0
   103
@see    CDynamicDirCache
sl@0
   104
*/
sl@0
   105
class TLookupEntry
sl@0
   106
    {
sl@0
   107
    public:
sl@0
   108
        TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {};
sl@0
   109
        TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {};
sl@0
   110
    public:
sl@0
   111
        TInt64                  iPos;
sl@0
   112
        TUint32                 iRange;
sl@0
   113
        TDynamicDirCachePage*   iPage;
sl@0
   114
    };
sl@0
   115
sl@0
   116
//---------------------------------------------------------------------------------------------------------------------------------
sl@0
   117
typedef TDblQue<TDynamicDirCachePage> TCachePageList;
sl@0
   118
/**
sl@0
   119
Dynamic directory cache.
sl@0
   120
For now it is directly derived from MWTCacheInterface.
sl@0
   121
Provides caching FAT directory data.
sl@0
   122
*/
sl@0
   123
class CDynamicDirCache : public CBase, public MWTCacheInterface
sl@0
   124
    {
sl@0
   125
public:
sl@0
   126
    ~CDynamicDirCache();
sl@0
   127
    static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
sl@0
   128
sl@0
   129
    //-- overloads from the base class
sl@0
   130
    void    ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
sl@0
   131
    void    WriteL(TInt64 aPos, const TDesC8& aDes);
sl@0
   132
    void    InvalidateCache(void);
sl@0
   133
    void    InvalidateCachePage(TUint64 aPos);
sl@0
   134
sl@0
   135
    TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
sl@0
   136
    TUint32 CacheSizeInBytes()  const;
sl@0
   137
    TInt    Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
sl@0
   138
    void    SetCacheBasePos(TInt64 aBasePos);
sl@0
   139
    void    MakePageMRU(TInt64 aPos);
sl@0
   140
    TUint32 PageSizeInBytesLog2() const;
sl@0
   141
    
sl@0
   142
    TUint32 PageSizeInSegs() const;
sl@0
   143
sl@0
   144
    // Debugging functions
sl@0
   145
    void Dump();
sl@0
   146
    void Info() const;
sl@0
   147
sl@0
   148
protected:
sl@0
   149
    CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
sl@0
   150
    void ConstructL(const TDesC& aClientName);
sl@0
   151
sl@0
   152
    void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
sl@0
   153
    void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
sl@0
   154
    TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
sl@0
   155
    TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
sl@0
   156
    TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos);
sl@0
   157
    TUint8* LockPage(TDynamicDirCachePage* aPage);
sl@0
   158
    TInt    UnlockPage(TDynamicDirCachePage* aPage);
sl@0
   159
    TInt    DecommitPage(TDynamicDirCachePage* aPage);
sl@0
   160
    inline TInt64  CalcPageStartPos(TInt64 aPos) const;
sl@0
   161
    void CheckThresholds();
sl@0
   162
    inline TBool CacheIsFull() const;
sl@0
   163
    inline TUint32 MaxCacheSizeInPages() const;
sl@0
   164
    TInt DeQueue(TDynamicDirCachePage* aPage);
sl@0
   165
    TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
sl@0
   166
    TInt LookupTblRemove(TInt64 aPagePos);
sl@0
   167
    TInt LookupTblAdd(TDynamicDirCachePage* aPage);
sl@0
   168
    TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
sl@0
   169
    TInt ResetPagePos(TDynamicDirCachePage* aPage);
sl@0
   170
    void MakePageLastLocked(TDynamicDirCachePage* aPage);
sl@0
   171
    
sl@0
   172
private:
sl@0
   173
    TUint32             iPageSizeLog2;      ///< log2 value of cache pages size in bytes
sl@0
   174
    TUint32             iMinCacheSizeInBytes;   ///< minimum cache data size
sl@0
   175
    TUint32             iMaxCacheSizeInBytes;   ///< maximum cache data size
sl@0
   176
    TUint32             iMinSizeInPages;    ///< minimum cache page number
sl@0
   177
    TUint32             iMaxSizeInPages;    ///< maximum cache page number
sl@0
   178
    TUint32             iPageSizeInBytes;   ///< cache page size in bytes
sl@0
   179
    TInt64              iCacheBasePos;      ///< cache pages base position, used to align them at cluster size
sl@0
   180
sl@0
   181
    TFatDriveInterface& iDrive;             ///< reference to the driver for media access
sl@0
   182
    TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
sl@0
   183
sl@0
   184
    TDynamicDirCachePage*   iActivePage;    ///< a unique page in cache, used to read new page before make it MRU or have it replaced
sl@0
   185
    
sl@0
   186
    // data structures for LRU page list    
sl@0
   187
    TCachePageList  iLockedQ;               ///< the locked queue that manages all locked pages, limited by minimum page number
sl@0
   188
    TCachePageList  iUnlockedQ;             ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
sl@0
   189
    TUint32         iLockedQCount;
sl@0
   190
    TUint32         iUnlockedQCount;
sl@0
   191
sl@0
   192
    // data structures for look up table
sl@0
   193
    THashFunction32<TLookupEntry>   iHashFunction;
sl@0
   194
    TIdentityRelation<TLookupEntry> iIdentityFunction;
sl@0
   195
    RHashSet<TLookupEntry>          iLookupTable;   ///< a lookup table that used to speed up page look up
sl@0
   196
sl@0
   197
    CCacheMemoryClient* iCacheMemoryClient; ///< interface to cache memory manager
sl@0
   198
    };
sl@0
   199
sl@0
   200
#include"sl_dir_cache.inl"
sl@0
   201
sl@0
   202
#endif //SL_DIR_CACHE_H
sl@0
   203
sl@0
   204
sl@0
   205
sl@0
   206