First public contribution.
1 // Copyright (c) 1996-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_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 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
36 //---------------------------------------------------------------------------------------------------------------------------------
37 //-- dedicated FAT directory cache related stuff
39 //-- if defined, a dedicated cache will be used for FAT directories
40 #define ENABLE_DEDICATED_DIR_CACHE
42 //---------------------------------------------------------------------------------------------------------------------------------
46 An abstract interface to the media Write-Through cache
48 class MWTCacheInterface
52 /** Enums for control functions. See Control() */
55 EDisableCache = 0, ///< disable/enable cache, can be used for debug purposes
56 EDumpCache = 1, ///< print full cache content, can be used for debug purposes
57 ECacheInfo = 2, ///< print cache info, can be used for debug purposes
60 virtual ~MWTCacheInterface() {}
62 /** the same meaning and parameters as in CRawDisk::ReadL */
63 virtual void ReadL(TInt64 aPos, TInt aLength, TDes8& aDes)=0;
65 /** the same meaning and parameters as in CRawDisk::WriteL */
66 virtual void WriteL(TInt64 aPos,const TDesC8& aDes)=0;
68 /** Invalidates whole directory cache*/
69 virtual void InvalidateCache(void)=0;
71 /** invalidate a single cache page if the aPos is cached*/
72 virtual void InvalidateCachePage(TUint64 aPos)=0;
75 Finds out if the media position "aPosToSearch" is in the cache and returns cache page information in this case.
77 @param aPosToSearch linear media position to lookup in the cache
78 @param aCachedPosStart if "aPosToSearch" is cached, here will be media position of this page start
80 @return 0 if aPosToSearch isn't cached, otherwise cache page size in bytes (see also aCachedPosStart).
82 virtual TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart) = 0;
85 @return size of the cache in bytes. Can be 0.
87 virtual TUint32 CacheSizeInBytes() const = 0;
90 Make the page indexed by aPos the MRU page in the cache.
91 Assumes cache evicts pages according to LRU algorithm.
93 virtual void MakePageMRU(TInt64 aPos) = 0;
96 @return log2 number of the size of the cache in bytes.
98 virtual TUint32 PageSizeInBytesLog2() const = 0;
103 @param aFunction control function
104 @param aParam1 just arbitrary parameter
105 @param aParam2 just arbitrary parameter
106 @return Standard error code.
108 virtual TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2)=0;
111 Set cache base position at aBasePos
112 @param aBasePos base position of the cache pages. Affects pages alignment.
114 virtual void SetCacheBasePos(TInt64 aBasePos)=0;
118 //---------------------------------------------------------------------------------------------------------------------------------
121 This class represents the media Write-Through cache page
127 static CWTCachePage* NewL(TUint32 aPageSizeLog2);
128 void ConstructL(TUint32 aPageSizeLog2);
132 inline TBool PosCached(TInt64 aPos) const;
133 inline TUint32 PosInCachePage(TInt64 aPos) const;
134 inline TUint8* PtrInCachePage(TInt64 aPos) const;
135 inline TUint32 PageSize() const;
140 CWTCachePage(const CWTCachePage&);
141 CWTCachePage& operator=(const CWTCachePage&);
145 TInt32 iValid; ///< 0 if the page doesn't contain valid data
146 TInt64 iStartPos; ///< cache page base media position
147 RBuf8 iData; ///< page Data
150 //---------------------------------------------------------------------------------------------------------------------------------
153 Media Write-through cache.
155 class CMediaWTCache : public CBase, public MWTCacheInterface
160 static CMediaWTCache* NewL(TFatDriveInterface& aDrive, TUint32 aNumPages, TUint32 aPageSizeLog2);
162 void ConstructL(TUint32 aNumPages, TUint32 aPageSizeLog2);
164 //-- overloads from the base class
165 void ReadL (TInt64 aPos,TInt aLength,TDes8& aDes);
166 void WriteL(TInt64 aPos,const TDesC8& aDes);
167 void InvalidateCache(void);
168 void InvalidateCachePage(TUint64 aPos);
171 TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
172 TUint32 CacheSizeInBytes() const;
173 void MakePageMRU(TInt64 aPos);
174 TUint32 PageSizeInBytesLog2() const;
175 TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
176 inline void SetCacheBasePos(TInt64 aBasePos);
181 CMediaWTCache(TFatDriveInterface& aDrive);
183 inline TInt64 CalcPageStartPos(TInt64 aPos) const;
184 inline TUint32 PageSize() const;
186 void MakePageLRU(TInt aPageNo);
188 TInt FindPageByPos(TInt64 aPos) const;
189 TUint32 GrabPage() const;
190 TUint32 GrabReadPageL(TInt64 aPos);
191 TUint32 FindOrGrabReadPageL(TInt64 aPos);
194 TFatDriveInterface& iDrive; ///< reference to the driver for media access
195 TUint32 iPageSizeLog2; ///< Log2 (cache page size)
196 mutable TBool iAllPagesValid;///< ETrue if all cache pages have valid data
197 TInt64 iCacheBasePos; ///< Cache pages base position, used to align them at cluster size
198 RPointerArray<CWTCachePage> iPages; ///< array of pointers to the cache pages. Used for organising LRU list
199 TUint32 iCacheDisabled :1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
205 #include"sl_cache.inl"