Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfat32\inc\sl_dir_cache.h
23 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
26 //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
28 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32 #ifndef SL_DIR_CACHE_H
33 #define SL_DIR_CACHE_H
35 #include "sf_memory_man.h"
36 #include "sf_memory_client.h"
38 #include <e32hashtab.h>
40 //---------------------------------------------------------------------------------------------------------------------------------
41 class CDynamicDirCache;
45 The dynamic directory cache page class
47 class TDynamicDirCachePage
59 ~TDynamicDirCachePage();
60 static TDynamicDirCachePage* NewL(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
62 inline void SetLocked(TBool);
63 inline TBool IsLocked() const;
64 inline TUint8* StartPtr() const;
65 inline void SetStartPtr(TUint8* aPtr);
66 inline void SetValid(TBool aIsValid);
67 inline TBool IsValid() const;
68 inline void SetPageType(TPageType aType);
69 inline TPageType PageType();
71 inline TUint32 PageSizeInBytes() const;
72 inline TUint32 PageSizeInSegs() const;
74 inline void SetPos(TInt64 aPos);
75 inline void ResetPos();
76 inline TInt64 StartPos() const;
78 inline TUint8* PtrInPage(TInt64 aPos) const;
79 inline TBool PosCachedInPage(TInt64 aPos) const;
84 // declared to disable copying and assignment
85 TDynamicDirCachePage& operator=(const TDynamicDirCachePage&);
86 TDynamicDirCachePage(const TDynamicDirCachePage&);
88 // private constructor, as this class is not supposed to be created on stack
89 TDynamicDirCachePage(CDynamicDirCache* aOwnerCache, TInt64 aStartMedPos, TUint8* aStartRamAddr);
92 TDblQueLink iLink; ///< the embedded link object, see TCachePageList
93 TInt64 iStartMedPos; ///< the starting media address that this page caches
94 TUint8* iStartRamAddr; ///< the starting ram address that thsi page lives
95 CDynamicDirCache* iOwnerCache; ///< pointer to the cache that owns this page
96 TBool iValid :1; ///< flag to indicate the validity of the page content
97 TBool iLocked :1; ///< flag to indicate if the page is locked or not
98 TPageType iType; ///< page type, see TPageType
102 The lookup table entry class
103 @see CDynamicDirCache
108 TLookupEntry(): iPos(0), iRange(0), iPage(NULL) {};
109 TLookupEntry(TInt64 aPos, TUint32 aRange, TDynamicDirCachePage* aPage): iPos(aPos), iRange(aRange), iPage(aPage) {};
113 TDynamicDirCachePage* iPage;
116 //---------------------------------------------------------------------------------------------------------------------------------
117 typedef TDblQue<TDynamicDirCachePage> TCachePageList;
119 Dynamic directory cache.
120 For now it is directly derived from MWTCacheInterface.
121 Provides caching FAT directory data.
123 class CDynamicDirCache : public CBase, public MWTCacheInterface
127 static CDynamicDirCache* NewL(TFatDriveInterface& aDrive, TUint32 aMinPageNum, TUint32 aMaxPageNum, TUint32 aPageSizeLog2, const TDesC& aClientName);
129 //-- overloads from the base class
130 void ReadL (TInt64 aPos, TInt aLength, TDes8& aDes);
131 void WriteL(TInt64 aPos, const TDesC8& aDes);
132 void InvalidateCache(void);
133 void InvalidateCachePage(TUint64 aPos);
135 TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
136 TUint32 CacheSizeInBytes() const;
137 TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
138 void SetCacheBasePos(TInt64 aBasePos);
139 void MakePageMRU(TInt64 aPos);
140 TUint32 PageSizeInBytesLog2() const;
142 TUint32 PageSizeInSegs() const;
144 // Debugging functions
149 CDynamicDirCache(TFatDriveInterface& aDrive, TUint32 aMinSizeInBytes, TUint32 aMaxSizeInBytes, TUint32 aPageSizeInBytesLog2);
150 void ConstructL(const TDesC& aClientName);
152 void ReadDataFromSinglePageL(TInt64 aPos, TInt aLength, TDes8& aDes);
153 void WriteDataOntoSinglePageL(TInt64 aPos, const TUint8* aData, TUint32 aDataLen);
154 TDynamicDirCachePage* FindPageByPos(TInt64 aPos);
155 TDynamicDirCachePage* UpdateActivePageL(TInt64 aPos);
156 TDynamicDirCachePage* AllocateAndLockNewPageL(TInt64 aStartMedPos);
157 TUint8* LockPage(TDynamicDirCachePage* aPage);
158 TInt UnlockPage(TDynamicDirCachePage* aPage);
159 TInt DecommitPage(TDynamicDirCachePage* aPage);
160 inline TInt64 CalcPageStartPos(TInt64 aPos) const;
161 void CheckThresholds();
162 inline TBool CacheIsFull() const;
163 inline TUint32 MaxCacheSizeInPages() const;
164 TInt DeQueue(TDynamicDirCachePage* aPage);
165 TInt AddFirstOntoQueue(TDynamicDirCachePage* aPage, TDynamicDirCachePage::TPageType aType);
166 TInt LookupTblRemove(TInt64 aPagePos);
167 TInt LookupTblAdd(TDynamicDirCachePage* aPage);
168 TDynamicDirCachePage* LookupTblFind(TInt64 aPos);
169 TInt ResetPagePos(TDynamicDirCachePage* aPage);
170 void MakePageLastLocked(TDynamicDirCachePage* aPage);
173 TUint32 iPageSizeLog2; ///< log2 value of cache pages size in bytes
174 TUint32 iMinCacheSizeInBytes; ///< minimum cache data size
175 TUint32 iMaxCacheSizeInBytes; ///< maximum cache data size
176 TUint32 iMinSizeInPages; ///< minimum cache page number
177 TUint32 iMaxSizeInPages; ///< maximum cache page number
178 TUint32 iPageSizeInBytes; ///< cache page size in bytes
179 TInt64 iCacheBasePos; ///< cache pages base position, used to align them at cluster size
181 TFatDriveInterface& iDrive; ///< reference to the driver for media access
182 TUint32 iCacheDisabled : 1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
184 TDynamicDirCachePage* iActivePage; ///< a unique page in cache, used to read new page before make it MRU or have it replaced
186 // data structures for LRU page list
187 TCachePageList iLockedQ; ///< the locked queue that manages all locked pages, limited by minimum page number
188 TCachePageList iUnlockedQ; ///< the unlocked queue that manages all locked pages, limited by maximum page number - minimum page number
189 TUint32 iLockedQCount;
190 TUint32 iUnlockedQCount;
192 // data structures for look up table
193 THashFunction32<TLookupEntry> iHashFunction;
194 TIdentityRelation<TLookupEntry> iIdentityFunction;
195 RHashSet<TLookupEntry> iLookupTable; ///< a lookup table that used to speed up page look up
197 CCacheMemoryClient* iCacheMemoryClient; ///< interface to cache memory manager
200 #include"sl_dir_cache.inl"
202 #endif //SL_DIR_CACHE_H