os/kernelhwsrv/userlibandfileserver/fileserver/sfat/sl_dir_cache.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat/sl_dir_cache.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,206 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32\sfat32\inc\sl_dir_cache.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalTechnology
    1.24 +*/
    1.25 +
    1.26 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1.27 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1.28 +//!!
    1.29 +//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
    1.30 +//!!
    1.31 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1.32 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1.33 +
    1.34 +
    1.35 +#ifndef SL_DIR_CACHE_H
    1.36 +#define SL_DIR_CACHE_H
    1.37 +
    1.38 +#include "sf_memory_man.h"
    1.39 +#include "sf_memory_client.h"
    1.40 +#include "sl_cache.h"
    1.41 +#include <e32hashtab.h>
    1.42 +
    1.43 +//---------------------------------------------------------------------------------------------------------------------------------
    1.44 +class   CDynamicDirCache;
    1.45 +
    1.46 +
    1.47 +/**
    1.48 +The dynamic directory cache page class
    1.49 +*/
    1.50 +class TDynamicDirCachePage
    1.51 +    {
    1.52 +public:
    1.53 +    enum TPageType
    1.54 +        {
    1.55 +        EUnknown,
    1.56 +        ELocked,
    1.57 +        EUnlocked,
    1.58 +        EActivePage,
    1.59 +        };
    1.60 +
    1.61 +public:
    1.62 +    ~TDynamicDirCachePage();
    1.63 +    static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
    1.64 +    
    1.65 +    inline void SetLocked(TBool);
    1.66 +    inline TBool    IsLocked() const;
    1.67 +    inline TUint8*  StartPtr()  const;
    1.68 +    inline void     SetStartPtr(TUint8* aPtr);
    1.69 +    inline void SetValid(TBool aIsValid);
    1.70 +    inline TBool    IsValid()   const;
    1.71 +    inline void SetPageType(TPageType aType);
    1.72 +    inline TPageType PageType();
    1.73 +
    1.74 +    inline TUint32  PageSizeInBytes() const;
    1.75 +    inline TUint32  PageSizeInSegs() const;
    1.76 +
    1.77 +    inline void SetPos(TInt64 aPos);
    1.78 +    inline void ResetPos();
    1.79 +    inline TInt64   StartPos()  const;
    1.80 +
    1.81 +    inline TUint8*  PtrInPage(TInt64 aPos) const;
    1.82 +    inline TBool    PosCachedInPage(TInt64 aPos) const;
    1.83 +
    1.84 +    inline void Deque();
    1.85 +
    1.86 +private:
    1.87 +    // declared to disable copying and assignment
    1.88 +    TDynamicDirCachePage& operator=(const TDynamicDirCachePage&);
    1.89 +    TDynamicDirCachePage(const TDynamicDirCachePage&);
    1.90 +
    1.91 +    // private constructor, as this class is not supposed to be created on stack
    1.92 +    TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
    1.93 +
    1.94 +public:
    1.95 +    TDblQueLink         iLink;          ///< the embedded link object, see TCachePageList
    1.96 +    TInt64              iStartMedPos;   ///< the starting media address that this page caches
    1.97 +    TUint8*             iStartRamAddr;  ///< the starting ram address that thsi page lives
    1.98 +    CDynamicDirCache*   iOwnerCache;    ///< pointer to the cache that owns this page
    1.99 +    TBool               iValid  :1;     ///< flag to indicate the validity of the page content
   1.100 +    TBool               iLocked :1;     ///< flag to indicate if the page is locked or not
   1.101 +    TPageType           iType;          ///< page type, see TPageType
   1.102 +    };
   1.103 +
   1.104 +/**
   1.105 +The lookup table entry class
   1.106 +@see    CDynamicDirCache
   1.107 +*/
   1.108 +class TLookupEntry
   1.109 +    {
   1.110 +    public:
   1.111 +        TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {};
   1.112 +        TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {};
   1.113 +    public:
   1.114 +        TInt64                  iPos;
   1.115 +        TUint32                 iRange;
   1.116 +        TDynamicDirCachePage*   iPage;
   1.117 +    };
   1.118 +
   1.119 +//---------------------------------------------------------------------------------------------------------------------------------
   1.120 +typedef TDblQue<TDynamicDirCachePage> TCachePageList;
   1.121 +/**
   1.122 +Dynamic directory cache.
   1.123 +For now it is directly derived from MWTCacheInterface.
   1.124 +Provides caching FAT directory data.
   1.125 +*/
   1.126 +class CDynamicDirCache : public CBase, public MWTCacheInterface
   1.127 +    {
   1.128 +public:
   1.129 +    ~CDynamicDirCache();
   1.130 +    static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
   1.131 +
   1.132 +    //-- overloads from the base class
   1.133 +    void    ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
   1.134 +    void    WriteL(TInt64 aPos, const TDesC8& aDes);
   1.135 +    void    InvalidateCache(void);
   1.136 +    void    InvalidateCachePage(TUint64 aPos);
   1.137 +
   1.138 +    TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
   1.139 +    TUint32 CacheSizeInBytes()  const;
   1.140 +    TInt    Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
   1.141 +    void    SetCacheBasePos(TInt64 aBasePos);
   1.142 +    void    MakePageMRU(TInt64 aPos);
   1.143 +    TUint32 PageSizeInBytesLog2() const;
   1.144 +    
   1.145 +    TUint32 PageSizeInSegs() const;
   1.146 +
   1.147 +    // Debugging functions
   1.148 +    void Dump();
   1.149 +    void Info() const;
   1.150 +
   1.151 +protected:
   1.152 +    CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
   1.153 +    void ConstructL(const TDesC& aClientName);
   1.154 +
   1.155 +    void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
   1.156 +    void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
   1.157 +    TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
   1.158 +    TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
   1.159 +    TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos);
   1.160 +    TUint8* LockPage(TDynamicDirCachePage* aPage);
   1.161 +    TInt    UnlockPage(TDynamicDirCachePage* aPage);
   1.162 +    TInt    DecommitPage(TDynamicDirCachePage* aPage);
   1.163 +    inline TInt64  CalcPageStartPos(TInt64 aPos) const;
   1.164 +    void CheckThresholds();
   1.165 +    inline TBool CacheIsFull() const;
   1.166 +    inline TUint32 MaxCacheSizeInPages() const;
   1.167 +    TInt DeQueue(TDynamicDirCachePage* aPage);
   1.168 +    TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
   1.169 +    TInt LookupTblRemove(TInt64 aPagePos);
   1.170 +    TInt LookupTblAdd(TDynamicDirCachePage* aPage);
   1.171 +    TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
   1.172 +    TInt ResetPagePos(TDynamicDirCachePage* aPage);
   1.173 +    void MakePageLastLocked(TDynamicDirCachePage* aPage);
   1.174 +    
   1.175 +private:
   1.176 +    TUint32             iPageSizeLog2;      ///< log2 value of cache pages size in bytes
   1.177 +    TUint32             iMinCacheSizeInBytes;   ///< minimum cache data size
   1.178 +    TUint32             iMaxCacheSizeInBytes;   ///< maximum cache data size
   1.179 +    TUint32             iMinSizeInPages;    ///< minimum cache page number
   1.180 +    TUint32             iMaxSizeInPages;    ///< maximum cache page number
   1.181 +    TUint32             iPageSizeInBytes;   ///< cache page size in bytes
   1.182 +    TInt64              iCacheBasePos;      ///< cache pages base position, used to align them at cluster size
   1.183 +
   1.184 +    TFatDriveInterface& iDrive;             ///< reference to the driver for media access
   1.185 +    TUint32             iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
   1.186 +
   1.187 +    TDynamicDirCachePage*   iActivePage;    ///< a unique page in cache, used to read new page before make it MRU or have it replaced
   1.188 +    
   1.189 +    // data structures for LRU page list    
   1.190 +    TCachePageList  iLockedQ;               ///< the locked queue that manages all locked pages, limited by minimum page number
   1.191 +    TCachePageList  iUnlockedQ;             ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
   1.192 +    TUint32         iLockedQCount;
   1.193 +    TUint32         iUnlockedQCount;
   1.194 +
   1.195 +    // data structures for look up table
   1.196 +    THashFunction32<TLookupEntry>   iHashFunction;
   1.197 +    TIdentityRelation<TLookupEntry> iIdentityFunction;
   1.198 +    RHashSet<TLookupEntry>          iLookupTable;   ///< a lookup table that used to speed up page look up
   1.199 +
   1.200 +    CCacheMemoryClient* iCacheMemoryClient; ///< interface to cache memory manager
   1.201 +    };
   1.202 +
   1.203 +#include"sl_dir_cache.inl"
   1.204 +
   1.205 +#endif //SL_DIR_CACHE_H
   1.206 +
   1.207 +
   1.208 +
   1.209 +