sl@0
|
1 |
// Copyright (c) 1996-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_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_CACHE_H
|
sl@0
|
33 |
#define SL_CACHE_H
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
//---------------------------------------------------------------------------------------------------------------------------------
|
sl@0
|
37 |
//-- dedicated FAT directory cache related stuff
|
sl@0
|
38 |
|
sl@0
|
39 |
//-- if defined, a dedicated cache will be used for FAT directories
|
sl@0
|
40 |
#define ENABLE_DEDICATED_DIR_CACHE
|
sl@0
|
41 |
|
sl@0
|
42 |
//---------------------------------------------------------------------------------------------------------------------------------
|
sl@0
|
43 |
|
sl@0
|
44 |
|
sl@0
|
45 |
/**
|
sl@0
|
46 |
An abstract interface to the media Write-Through cache
|
sl@0
|
47 |
*/
|
sl@0
|
48 |
class MWTCacheInterface
|
sl@0
|
49 |
{
|
sl@0
|
50 |
public:
|
sl@0
|
51 |
|
sl@0
|
52 |
/** Enums for control functions. See Control() */
|
sl@0
|
53 |
enum TControl
|
sl@0
|
54 |
{
|
sl@0
|
55 |
EDisableCache = 0, ///< disable/enable cache, can be used for debug purposes
|
sl@0
|
56 |
EDumpCache = 1, ///< print full cache content, can be used for debug purposes
|
sl@0
|
57 |
ECacheInfo = 2, ///< print cache info, can be used for debug purposes
|
sl@0
|
58 |
};
|
sl@0
|
59 |
|
sl@0
|
60 |
virtual ~MWTCacheInterface() {}
|
sl@0
|
61 |
|
sl@0
|
62 |
/** the same meaning and parameters as in CRawDisk::ReadL */
|
sl@0
|
63 |
virtual void ReadL(TInt64 aPos, TInt aLength, TDes8& aDes)=0;
|
sl@0
|
64 |
|
sl@0
|
65 |
/** the same meaning and parameters as in CRawDisk::WriteL */
|
sl@0
|
66 |
virtual void WriteL(TInt64 aPos,const TDesC8& aDes)=0;
|
sl@0
|
67 |
|
sl@0
|
68 |
/** Invalidates whole directory cache*/
|
sl@0
|
69 |
virtual void InvalidateCache(void)=0;
|
sl@0
|
70 |
|
sl@0
|
71 |
/** invalidate a single cache page if the aPos is cached*/
|
sl@0
|
72 |
virtual void InvalidateCachePage(TUint64 aPos)=0;
|
sl@0
|
73 |
|
sl@0
|
74 |
/**
|
sl@0
|
75 |
Finds out if the media position "aPosToSearch" is in the cache and returns cache page information in this case.
|
sl@0
|
76 |
|
sl@0
|
77 |
@param aPosToSearch linear media position to lookup in the cache
|
sl@0
|
78 |
@param aCachedPosStart if "aPosToSearch" is cached, here will be media position of this page start
|
sl@0
|
79 |
|
sl@0
|
80 |
@return 0 if aPosToSearch isn't cached, otherwise cache page size in bytes (see also aCachedPosStart).
|
sl@0
|
81 |
*/
|
sl@0
|
82 |
virtual TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart) = 0;
|
sl@0
|
83 |
|
sl@0
|
84 |
/**
|
sl@0
|
85 |
@return size of the cache in bytes. Can be 0.
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
virtual TUint32 CacheSizeInBytes() const = 0;
|
sl@0
|
88 |
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
Make the page indexed by aPos the MRU page in the cache.
|
sl@0
|
91 |
Assumes cache evicts pages according to LRU algorithm.
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
virtual void MakePageMRU(TInt64 aPos) = 0;
|
sl@0
|
94 |
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
@return log2 number of the size of the cache in bytes.
|
sl@0
|
97 |
*/
|
sl@0
|
98 |
virtual TUint32 PageSizeInBytesLog2() const = 0;
|
sl@0
|
99 |
|
sl@0
|
100 |
/**
|
sl@0
|
101 |
Control method.
|
sl@0
|
102 |
|
sl@0
|
103 |
@param aFunction control function
|
sl@0
|
104 |
@param aParam1 just arbitrary parameter
|
sl@0
|
105 |
@param aParam2 just arbitrary parameter
|
sl@0
|
106 |
@return Standard error code.
|
sl@0
|
107 |
*/
|
sl@0
|
108 |
virtual TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2)=0;
|
sl@0
|
109 |
|
sl@0
|
110 |
/**
|
sl@0
|
111 |
Set cache base position at aBasePos
|
sl@0
|
112 |
@param aBasePos base position of the cache pages. Affects pages alignment.
|
sl@0
|
113 |
*/
|
sl@0
|
114 |
virtual void SetCacheBasePos(TInt64 aBasePos)=0;
|
sl@0
|
115 |
|
sl@0
|
116 |
};
|
sl@0
|
117 |
|
sl@0
|
118 |
//---------------------------------------------------------------------------------------------------------------------------------
|
sl@0
|
119 |
|
sl@0
|
120 |
/**
|
sl@0
|
121 |
This class represents the media Write-Through cache page
|
sl@0
|
122 |
*/
|
sl@0
|
123 |
class CWTCachePage
|
sl@0
|
124 |
{
|
sl@0
|
125 |
public:
|
sl@0
|
126 |
|
sl@0
|
127 |
static CWTCachePage* NewL(TUint32 aPageSizeLog2);
|
sl@0
|
128 |
void ConstructL(TUint32 aPageSizeLog2);
|
sl@0
|
129 |
|
sl@0
|
130 |
~CWTCachePage();
|
sl@0
|
131 |
|
sl@0
|
132 |
inline TBool PosCached(TInt64 aPos) const;
|
sl@0
|
133 |
inline TUint32 PosInCachePage(TInt64 aPos) const;
|
sl@0
|
134 |
inline TUint8* PtrInCachePage(TInt64 aPos) const;
|
sl@0
|
135 |
inline TUint32 PageSize() const;
|
sl@0
|
136 |
|
sl@0
|
137 |
protected:
|
sl@0
|
138 |
|
sl@0
|
139 |
CWTCachePage();
|
sl@0
|
140 |
CWTCachePage(const CWTCachePage&);
|
sl@0
|
141 |
CWTCachePage& operator=(const CWTCachePage&);
|
sl@0
|
142 |
|
sl@0
|
143 |
public:
|
sl@0
|
144 |
|
sl@0
|
145 |
TInt32 iValid; ///< 0 if the page doesn't contain valid data
|
sl@0
|
146 |
TInt64 iStartPos; ///< cache page base media position
|
sl@0
|
147 |
RBuf8 iData; ///< page Data
|
sl@0
|
148 |
};
|
sl@0
|
149 |
|
sl@0
|
150 |
//---------------------------------------------------------------------------------------------------------------------------------
|
sl@0
|
151 |
|
sl@0
|
152 |
/**
|
sl@0
|
153 |
Media Write-through cache.
|
sl@0
|
154 |
*/
|
sl@0
|
155 |
class CMediaWTCache : public CBase, public MWTCacheInterface
|
sl@0
|
156 |
{
|
sl@0
|
157 |
public:
|
sl@0
|
158 |
~CMediaWTCache();
|
sl@0
|
159 |
|
sl@0
|
160 |
static CMediaWTCache* NewL(TFatDriveInterface& aDrive, TUint32 aNumPages, TUint32 aPageSizeLog2);
|
sl@0
|
161 |
|
sl@0
|
162 |
void ConstructL(TUint32 aNumPages, TUint32 aPageSizeLog2);
|
sl@0
|
163 |
|
sl@0
|
164 |
//-- overloads from the base class
|
sl@0
|
165 |
void ReadL (TInt64 aPos,TInt aLength,TDes8& aDes);
|
sl@0
|
166 |
void WriteL(TInt64 aPos,const TDesC8& aDes);
|
sl@0
|
167 |
void InvalidateCache(void);
|
sl@0
|
168 |
void InvalidateCachePage(TUint64 aPos);
|
sl@0
|
169 |
|
sl@0
|
170 |
|
sl@0
|
171 |
TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
|
sl@0
|
172 |
TUint32 CacheSizeInBytes() const;
|
sl@0
|
173 |
void MakePageMRU(TInt64 aPos);
|
sl@0
|
174 |
TUint32 PageSizeInBytesLog2() const;
|
sl@0
|
175 |
TInt Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
|
sl@0
|
176 |
inline void SetCacheBasePos(TInt64 aBasePos);
|
sl@0
|
177 |
//--
|
sl@0
|
178 |
|
sl@0
|
179 |
protected:
|
sl@0
|
180 |
CMediaWTCache();
|
sl@0
|
181 |
CMediaWTCache(TFatDriveInterface& aDrive);
|
sl@0
|
182 |
|
sl@0
|
183 |
inline TInt64 CalcPageStartPos(TInt64 aPos) const;
|
sl@0
|
184 |
inline TUint32 PageSize() const;
|
sl@0
|
185 |
|
sl@0
|
186 |
void MakePageLRU(TInt aPageNo);
|
sl@0
|
187 |
|
sl@0
|
188 |
TInt FindPageByPos(TInt64 aPos) const;
|
sl@0
|
189 |
TUint32 GrabPage() const;
|
sl@0
|
190 |
TUint32 GrabReadPageL(TInt64 aPos);
|
sl@0
|
191 |
TUint32 FindOrGrabReadPageL(TInt64 aPos);
|
sl@0
|
192 |
|
sl@0
|
193 |
protected:
|
sl@0
|
194 |
TFatDriveInterface& iDrive; ///< reference to the driver for media access
|
sl@0
|
195 |
TUint32 iPageSizeLog2; ///< Log2 (cache page size)
|
sl@0
|
196 |
mutable TBool iAllPagesValid;///< ETrue if all cache pages have valid data
|
sl@0
|
197 |
TInt64 iCacheBasePos; ///< Cache pages base position, used to align them at cluster size
|
sl@0
|
198 |
RPointerArray<CWTCachePage> iPages; ///< array of pointers to the cache pages. Used for organising LRU list
|
sl@0
|
199 |
TUint32 iCacheDisabled :1; ///< if not 0 the cache is disabled totally and all reads and writes go via TFatDriveInterface directly
|
sl@0
|
200 |
};
|
sl@0
|
201 |
|
sl@0
|
202 |
|
sl@0
|
203 |
|
sl@0
|
204 |
|
sl@0
|
205 |
#include"sl_cache.inl"
|
sl@0
|
206 |
|
sl@0
|
207 |
#endif //SL_CACHE_H
|
sl@0
|
208 |
|
sl@0
|
209 |
|
sl@0
|
210 |
|
sl@0
|
211 |
|