author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 201 | 43365a9b78a3 |
child 299 | b5a01337d018 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2006-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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32\sfile\sf_file_cache.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
||
24 |
#if !defined(__SF_FILE_CACHE_H__) |
|
25 |
#define __SF_FILE_CACHE_H__ |
|
26 |
||
27 |
#include "sf_cache_client.h" |
|
28 |
||
29 |
//#define _DEBUG_READ_AHEAD |
|
30 |
||
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
// if writing sequentially, start flushing dirty data when the cache is half full |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
32 |
//#define DOUBLE_BUFFERED_WRITING |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
33 |
|
0 | 34 |
|
35 |
NONSHARABLE_CLASS(CFileCache) : public CFsDispatchObject |
|
36 |
{ |
|
37 |
public: |
|
38 |
static CFileCache* NewL(CFileShare& aShare); |
|
39 |
CFileCache* ReNewL(CFileShare& aShare); |
|
40 |
~CFileCache(); |
|
41 |
void Init(CFileShare& aShare); |
|
42 |
||
43 |
CMountCB& Mount() const; |
|
44 |
||
45 |
CFileCB* FileCB(); |
|
46 |
||
47 |
void ReadAhead(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
48 |
void ResetReadAhead(); |
|
49 |
||
50 |
static TInt CompleteRead(CFsRequest* aMsgRequest); |
|
51 |
static TInt CompleteWrite(CFsRequest* aMsgRequest); |
|
52 |
TInt ReadBuffered(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
53 |
TInt WriteBuffered(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
54 |
||
55 |
inline TBool IsDirty() {return iDirtyDataOwner != NULL;} |
|
56 |
TInt FlushDirty(CFsRequest* aOldRequest = NULL); |
|
57 |
void Purge(TBool aPurgeDirty = EFalse); |
|
58 |
||
59 |
// from CFsObject |
|
60 |
void Close(); |
|
61 |
||
62 |
inline TInt64 Size64() const {return iSize64;} |
|
63 |
||
64 |
// Sets 64 bit (cached) file size |
|
65 |
void SetSize64(TInt64 aSize); |
|
66 |
||
67 |
TDrive& Drive() const; |
|
68 |
TUint32 NameHash() const; |
|
69 |
HBufC& FileNameF() const; |
|
70 |
||
71 |
void MarkFileClean(); |
|
72 |
||
73 |
private: |
|
74 |
void ConstructL(CFileShare& aShare); |
|
75 |
CFileCache(); |
|
76 |
||
77 |
void SetFileCacheFlags(CFileShare& aShare); |
|
78 |
||
79 |
TInt DoReadBuffered(CFsMessageRequest& aMsgRequest, TUint aMode, CFsClientMessageRequest*& aNewRequest); |
|
80 |
TInt DoWriteBuffered(CFsMessageRequest& aMsgRequest, CFsClientMessageRequest*& aNewRequest, TUint aMode); |
|
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
enum TFlushMode {EFlushSingle, EFlushHalf, EFlushAll}; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
TInt DoFlushDirty(CFsClientMessageRequest*& aNewRequest, CFsRequest* aOldRequest, TFlushMode aFlushMode); |
0 | 83 |
|
84 |
||
85 |
inline TInt SegmentSize() const; |
|
86 |
inline TInt SegmentSizeLog2() const; |
|
87 |
inline TInt64 SegmentSizeMask() const; |
|
88 |
||
89 |
inline void UpdateSharePosition(CFsMessageRequest& aMsgRequest, TMsgOperation& aCurrentOperation); |
|
90 |
||
91 |
static TInt CompleteFlushDirty(CFsRequest* aMsgRequest); |
|
92 |
TInt FlushDirtySm(CFsMessageRequest& aMsgRequest); |
|
93 |
||
94 |
TInt AllocateRequest(CFsClientMessageRequest*& aNewRequest, TBool aWrite, CSessionFs* aSession = NULL); |
|
95 |
||
96 |
void DoReadAhead(CFsMessageRequest& aMsgRequest, TUint aMode); |
|
97 |
||
98 |
void FileDirty(CFsMessageRequest& aMsgRequest); |
|
99 |
||
100 |
||
101 |
||
102 |
TInt HandleWriteDirtyError(TInt aError); |
|
103 |
void PropagateFlushErrorToAllFileShares(); |
|
104 |
||
105 |
static TInt ClosedTimerEvent(TAny* aFileCache); |
|
106 |
static TInt DirtyTimerEvent(TAny* aFileCache); |
|
107 |
||
108 |
TBool IsDriveThread(); |
|
109 |
||
110 |
private: |
|
111 |
||
112 |
CCacheClient* iCacheClient; |
|
113 |
||
114 |
TInt iMaxReadAheadLen; |
|
115 |
TInt iCacheSize; |
|
116 |
||
117 |
TInt32 iClosedFileKeepAliveTime; // in microseconds |
|
118 |
TInt32 iDirtyDataFlushTime; // in microseconds |
|
119 |
||
120 |
CFileCB* iFileCB; |
|
121 |
||
122 |
RFastLock iLock; |
|
123 |
||
124 |
TInt iFlushError; |
|
125 |
TBool iFlushBusy; |
|
126 |
||
127 |
CDriveThread* iDriveThread; |
|
128 |
TInt iDriveNum; |
|
129 |
||
130 |
// closed queue eject timer |
|
131 |
TThreadTimer iClosedTimer; |
|
132 |
||
133 |
// dirty data flush timer |
|
134 |
TThreadTimer iDirtyTimer; |
|
135 |
// The last session writing to this file. If non-NULL indicates cache contains dirty data |
|
136 |
CSessionFs* iDirtyDataOwner; |
|
137 |
||
138 |
// The size of the file. |
|
139 |
TInt64 iSize64; |
|
140 |
||
141 |
// The size of the file at the start of a write request |
|
142 |
TInt64 iInitialSize; |
|
143 |
||
144 |
// The full name of the file, including drive and extensions - Folded. This is "stolen" |
|
145 |
// from the owning CFileCB when the CFileCB destructor calls CFileCache::Close(). |
|
146 |
HBufC* iFileNameF; |
|
147 |
||
148 |
TUint32 iNameHash; |
|
149 |
||
150 |
TDrive* iDrive; |
|
151 |
||
152 |
CMountCB* iMount; |
|
153 |
||
154 |
// Read-ahead |
|
155 |
TInt iSequentialReads; |
|
156 |
TInt iReadAheadLen; |
|
157 |
TInt64 iReadAheadPos; |
|
158 |
TInt64 iLastReadPos; |
|
159 |
TInt iLastReadLen; |
|
160 |
TBool iFileCacheReadAsync; |
|
161 |
CFsClientMessageRequest* iReadAheadRequest; |
|
162 |
||
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
#ifdef DOUBLE_BUFFERED_WRITING |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
// sequential append-write detection |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
TInt iSequentialAppends; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
#endif |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
|
0 | 168 |
friend class TClosedFileUtils; |
169 |
friend class TFsFileWriteDirty; |
|
170 |
}; |
|
171 |
||
172 |
||
173 |
class TFileCacheSettings |
|
174 |
{ |
|
175 |
public: |
|
176 |
class TFileCacheConfig |
|
177 |
{ |
|
178 |
public: |
|
179 |
TFileCacheConfig(TInt aDrive); |
|
180 |
static TFileCacheFlags ConvertEnumToFlags(const TInt aFileCacheRead, const TInt aFileCacheReadAhead, const TInt aFileCacheWrite); |
|
181 |
public: |
|
182 |
TInt iDrive; |
|
183 |
TFileCacheFlags iFlags; |
|
184 |
||
185 |
TBool iFileCacheReadAsync; |
|
186 |
TInt32 iFairSchedulingLen; // in bytes |
|
187 |
TInt32 iCacheSize; // in bytes |
|
188 |
TInt32 iMaxReadAheadLen; // in bytes |
|
189 |
TInt32 iClosedFileKeepAliveTime; // in microseconds |
|
190 |
TInt32 iDirtyDataFlushTime; // in microseconds |
|
191 |
}; |
|
192 |
||
193 |
public: |
|
194 |
static TInt ReadPropertiesFile(TInt aDriveNumber); |
|
195 |
static void SetFlags(TInt aDrive, TFileCacheFlags alags); |
|
196 |
static TFileCacheFlags Flags(TInt aDrive); |
|
197 |
||
198 |
||
199 |
static TInt FileCacheReadAsync(TInt aDrive); |
|
200 |
static TInt FairSchedulingLen(TInt aDrive); |
|
201 |
static TInt MaxReadAheadLen(TInt aDrive); |
|
202 |
static TInt CacheSize(TInt aDrive); |
|
203 |
static TInt ClosedFileKeepAliveTime(TInt aDrive); |
|
204 |
static TInt DirtyDataFlushTime(TInt aDrive); |
|
205 |
static TInt GetFileCacheConfig(TInt aDrive, TFileCacheConfig*& aConfig); |
|
206 |
private: |
|
207 |
static void Init(); |
|
208 |
static void ReadEnum(const TDesC8& aSection, const TDesC8& aProperty, TInt32& aEnumVal, const TPtrC8* aEnumStrings); |
|
209 |
||
210 |
private: |
|
211 |
static RArray<TFileCacheConfig>* iFileCacheSettings; |
|
212 |
}; |
|
213 |
||
214 |
||
215 |
class TClosedFileUtils |
|
216 |
{ |
|
217 |
public: |
|
218 |
static void InitL(); |
|
219 |
||
220 |
static TInt Count(); |
|
221 |
static CFileCache* At(TInt aIndex); |
|
222 |
static TBool IsClosed(CFileCache* aFileCache); |
|
223 |
||
224 |
static void AddL(CFileCache* aFileCache, TBool aLock); |
|
225 |
||
226 |
static void Remove(); |
|
227 |
static void Remove(TInt aDrvNumber); |
|
228 |
static void Remove(CFileCache* aFileCache); |
|
229 |
||
230 |
static void Lock(); |
|
231 |
static void Unlock(); |
|
232 |
||
233 |
static void ReOpen(CFileCache* aFileCache, TBool aLock); |
|
234 |
private: |
|
235 |
typedef TBool (*TTestFunc)(CFileCache& aFileCache, TAny* aVal); |
|
236 |
static void RemoveFiles(TTestFunc aTestFunc, TAny* aTestVal); |
|
237 |
||
238 |
static TBool TestDrive(CFileCache& aFileCache, TAny* aVal); |
|
239 |
static TBool TestFile(CFileCache& aFileCache, TAny* aVal); |
|
240 |
||
241 |
private: |
|
242 |
static CFsObjectCon* iClosedFiles; |
|
243 |
}; |
|
244 |
||
245 |
||
246 |
||
247 |
#endif |