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