author | hgs |
Fri, 23 Apr 2010 22:08:41 +0100 | |
changeset 121 | 661475905584 |
parent 90 | 947f0dc9f7a8 |
child 249 | a179b74831c9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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\sfat32\inc\fat_table32.h |
|
15 |
// FAT32 File Allocation Table classes definitions |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
/** |
|
20 |
@file |
|
21 |
@internalTechnology |
|
22 |
*/ |
|
23 |
||
24 |
#ifndef FAT_TABLE_32_H |
|
25 |
#define FAT_TABLE_32_H |
|
26 |
||
27 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
28 |
||
29 |
class CFatHelperThreadBase; |
|
30 |
class CFat32ScanThread; |
|
31 |
||
32 |
TInt FAT32_ScanThread(TAny* apHostObject); |
|
33 |
||
34 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
35 |
||
36 |
/** |
|
37 |
Fat table abstraction for all media types except RAM. |
|
38 |
Supports FAT12/16/32 |
|
39 |
*/ |
|
40 |
class CAtaFatTable : public CFatTable |
|
41 |
{ |
|
42 |
||
43 |
public: |
|
44 |
||
45 |
static CAtaFatTable* NewL(CFatMountCB& aOwner); |
|
46 |
~CAtaFatTable(); |
|
47 |
||
48 |
//-- overrides from th ebase class |
|
49 |
TUint32 ReadL(TUint32 aFatIndex) const; |
|
50 |
void WriteL(TUint32 aFatIndex, TUint32 aValue); |
|
51 |
void MountL(const TMountParams& aMountParam); |
|
52 |
||
53 |
TInt64 DataPositionInBytes(TUint32 aCluster) const; |
|
54 |
||
55 |
void InitializeL(); |
|
56 |
void Dismount(TBool aDiscardDirtyData); |
|
57 |
void FlushL(); |
|
58 |
||
59 |
void InvalidateCacheL(); |
|
60 |
void InvalidateCacheL(TInt64 aPos, TUint32 aLength); |
|
61 |
||
62 |
TUint32 FreeClusterHint() const; |
|
63 |
TUint32 NumberOfFreeClusters(TBool aSyncOperation=EFalse) const; |
|
64 |
||
65 |
TBool ConsistentState() const; |
|
66 |
||
67 |
inline void AcquireLock() const {iDriveInteface.AcquireLock();} |
|
68 |
inline void ReleaseLock() const {iDriveInteface.ReleaseLock();} |
|
69 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
inline TDriveInterface& DriveInterface() const; |
0 | 71 |
inline CFatMountCB* OwnerMount() const; |
72 |
||
73 |
||
74 |
private: |
|
75 |
||
76 |
/** internal states of this object */ |
|
77 |
enum TState |
|
78 |
{ |
|
79 |
ENotInitialised, ///< 0 initial invalid state |
|
80 |
EInitialised, ///< 1 initialised, i.e. internal objects created, but unusable becasue number of free entries isn't known |
|
81 |
EMounting, ///< 2 mounting started |
|
82 |
EMounted, ///< 3 successfully mounted; number of free entries is known. This is the only consistent state. |
|
83 |
EDismounted, ///< 4 FAT table object is dismounted |
|
84 |
EFreeClustersScan, ///< 5 FAT32 scan thread is currently scanning FAT table for free clusters |
|
85 |
EMountAborted ///< 6 Mounting failed, probably because of FAT32 free clusters scan thread failure. |
|
86 |
}; |
|
87 |
||
88 |
public: |
|
89 |
||
90 |
/** A helper class used in FAT scanning for free clusters*/ |
|
91 |
class TFatScanParam |
|
92 |
{ |
|
93 |
public: |
|
94 |
inline TFatScanParam(); |
|
95 |
||
96 |
public: |
|
97 |
TUint32 iEntriesScanned; ///< total number of FAT entries scanned by DoParseFatBuf() |
|
98 |
TUint32 iFirstFree; ///< first free FAT entry found |
|
99 |
TUint32 iCurrFreeEntries; ///< current number of free FAT entries found by DoParseFatBuf() |
|
100 |
TUint32 iCurrOccupiedEntries; ///< current number of non-free FAT entries found by DoParseFatBuf() |
|
101 |
}; |
|
102 |
||
103 |
||
104 |
private: |
|
105 |
CAtaFatTable(CFatMountCB& aOwner); |
|
106 |
||
107 |
void RequestRawWriteAccess(TInt64 aPos, TUint32 aLen) const; |
|
108 |
||
109 |
void SetFreeClusters(TUint32 aFreeClusters); |
|
110 |
void SetFreeClusterHint(TUint32 aCluster); |
|
111 |
void CountFreeClustersL(); |
|
112 |
void CreateCacheL(); |
|
113 |
||
114 |
virtual void DecrementFreeClusterCount(TUint32 aCount); |
|
115 |
virtual void IncrementFreeClusterCount(TUint32 aCount); |
|
116 |
virtual TUint32 FindClosestFreeClusterL(TUint32 aCluster); |
|
117 |
||
118 |
void DoCountFreeClustersL(); |
|
119 |
void DoParseFatBuf(const TPtrC8& aBuf, TFatScanParam& aScanParam) const; |
|
120 |
||
121 |
TBool RequestFreeClusters(TUint32 aClustersRequired) const; |
|
122 |
void DoLaunchFat32FreeSpaceScanThreadL(); |
|
123 |
void DestroyHelperThread(); |
|
124 |
||
125 |
inline TState State() const; |
|
126 |
inline void SetState(TState aState); |
|
127 |
||
128 |
private: |
|
129 |
||
130 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
CFatCacheBase* iCache; ///< FAT cache, fixed or LRU depending on the FAT type |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
TDriveInterface& iDriveInteface; ///< reference to the drive interface |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
CFatHelperThreadBase* ipHelperThread; ///< helper thread object pointer. NULL if it is not present |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
TState iState; ///< state of this object |
0 | 135 |
|
136 |
//-- friends |
|
137 |
friend TInt FAT32_ScanThread(TAny* apHostObject); |
|
138 |
friend class CFat32ScanThread; |
|
139 |
friend class CFat32FreeSpaceScanner; |
|
140 |
friend class CFat32BitCachePopulator; |
|
141 |
}; |
|
142 |
||
143 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
144 |
||
145 |
/** |
|
146 |
Fat table abstraction for RAM media type. |
|
147 |
Supports FAT16/32 only |
|
148 |
*/ |
|
149 |
class CRamFatTable : public CFatTable |
|
150 |
{ |
|
151 |
public: |
|
152 |
||
153 |
static CRamFatTable* NewL(CFatMountCB& aOwner); |
|
154 |
void InitializeL(); |
|
155 |
void MountL(const TMountParams& aMountParam); |
|
156 |
||
157 |
||
158 |
TUint32 ReadL(TUint32 aFatIndex) const; |
|
159 |
void WriteL(TUint32 aFatIndex, TUint32 aValue); |
|
160 |
TInt64 DataPositionInBytes(TUint32 aCluster) const; |
|
161 |
void FreeClusterListL(TUint32 aCluster); |
|
162 |
TUint32 AllocateSingleClusterL(TUint32 aNearestCluster); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
163 |
void ExtendClusterListL(TUint32 aNumber, TUint32& aCluster); |
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
164 |
TUint32 AllocateClusterListL(TUint32 aNumber,TUint32 aNearestCluster); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
165 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
166 |
virtual TUint32 CountContiguousClustersL(TUint32 aStartCluster, TUint32& anEndCluster, TUint32 aMaxCount) const; |
0 | 167 |
|
168 |
private: |
|
169 |
CRamFatTable(CFatMountCB& aOwner); |
|
170 |
||
171 |
inline TUint8 *RamDiskBase() const; |
|
172 |
inline TInt AllocateClusterNumber(); |
|
173 |
inline void WriteFatTable(TInt aFatIndex,TInt aValue); |
|
174 |
inline void WriteFatTable(TInt aFatIndex,TInt aFatValue,TInt anIndirectionTableValue); |
|
175 |
inline void ReadIndirectionTable(TUint32& aCluster) const; |
|
176 |
inline void WriteIndirectionTable(TInt aFatIndex,TInt aValue); |
|
177 |
inline TUint8* MemCopy(TAny* aTrg,const TAny* aSrc,TInt aLength); |
|
178 |
inline TUint8* MemCopyFillZ(TAny* aTrg, TAny* aSrc, TInt aLength); |
|
179 |
inline void ZeroFillCluster(TInt aCluster); |
|
180 |
||
181 |
void UpdateIndirectionTable(TUint32 aStartCluster,TUint32 anEndCluster,TInt aNum); |
|
182 |
||
183 |
protected: |
|
184 |
||
185 |
TInt iFatTablePos; ///< Current position in the fat table |
|
186 |
TInt iIndirectionTablePos; ///< Current position in indirection table, second fat used for this |
|
187 |
TUint8* iRamDiskBase; ///< Pointer to the Ram disk base |
|
188 |
}; |
|
189 |
||
190 |
||
191 |
||
192 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
193 |
||
194 |
/** |
|
195 |
Abstract base class for the FAT32 helper threads. |
|
196 |
Provides basic functionality of the helper threads and interface to the owher CAtaFatTable. |
|
197 |
*/ |
|
198 |
class CFatHelperThreadBase : public CBase |
|
199 |
{ |
|
200 |
public: |
|
201 |
||
202 |
/** Possible types of the FAT32 helper threads */ |
|
203 |
enum TFatHelperThreadType |
|
204 |
{ |
|
205 |
EInvalidType, ///< invalid type |
|
206 |
EFreeSpaceScanner, ///< Free FAT32 entries counter, see CFat32FreeSpaceScanner |
|
207 |
EBitCachePopulator ///< FAT32 bit supercache populating thread. |
|
208 |
}; |
|
209 |
||
210 |
/** this object states, mostly related to the worker thread activity and results */ |
|
211 |
enum TState |
|
212 |
{ |
|
213 |
EInvalid, ///< invalid initial state |
|
214 |
ENotStarted, ///< the worker thread hasn't started yet |
|
215 |
EWorking, ///< worker thread is working |
|
216 |
EFinished_OK, ///< worker thread has successfully finished, everything is fine. |
|
217 |
EFailed ///< worker thread failed to finish its job for some reason; see the thread completion status |
|
218 |
}; |
|
219 |
||
220 |
public: |
|
221 |
~CFatHelperThreadBase(); |
|
222 |
||
223 |
//-- virtual interface |
|
224 |
virtual TFatHelperThreadType Type() const = 0; |
|
225 |
virtual TInt Launch()=0; |
|
226 |
virtual void RequestFatEntryWriteAccess(TUint32 aFatIndex) const=0; |
|
227 |
||
228 |
//-- non-virtual interface for external user only |
|
229 |
void Close(); |
|
230 |
void ForceStop(); |
|
231 |
||
232 |
inline TState State() const; |
|
233 |
||
234 |
inline void Suspend() const; |
|
235 |
inline void Resume() const; |
|
236 |
||
237 |
inline TInt ThreadCompletionCode() const; |
|
238 |
inline TBool ThreadWorking() const; |
|
239 |
||
240 |
inline void BoostPriority(TBool aBoost) const; |
|
241 |
inline TBool IsPriorityBoosted() const; |
|
242 |
||
243 |
inline TThreadId ThreadId() const; |
|
244 |
||
245 |
TInt WaitToFinish() const; |
|
246 |
||
247 |
protected: |
|
248 |
CFatHelperThreadBase(CAtaFatTable& aOwner); |
|
249 |
||
250 |
//-- outlaws |
|
251 |
CFatHelperThreadBase(); |
|
252 |
CFatHelperThreadBase(const CFatHelperThreadBase&); |
|
253 |
CFatHelperThreadBase& operator=(const CFatHelperThreadBase&); |
|
254 |
||
255 |
/** the worker thread priorities values */ |
|
256 |
enum |
|
257 |
{ |
|
258 |
EHelperPriorityNormal = EPriorityMuchLess, ///< FAT32 Helper thread normal priority (assigned on start) |
|
259 |
EHelperPriorityBoosted = EPriorityNormal ///< FAT32 Helper thread bosted priority |
|
260 |
}; |
|
261 |
||
262 |
TInt DoLaunchThread(TThreadFunction aFunction, TAny* aThreadParameter); |
|
263 |
||
264 |
inline void SetState(TState aState); |
|
265 |
inline TBool AllowedToLive() const; |
|
266 |
inline void AllowToLive(TBool aAllow); |
|
267 |
||
268 |
protected: |
|
269 |
CAtaFatTable& iOwner; ///< owner, CAtaFatTable |
|
270 |
||
271 |
private: |
|
272 |
TState iState; ///< internal state of this object |
|
273 |
RThread iThread; ///< FAT helper thread handle |
|
274 |
mutable TRequestStatus iThreadStatus; ///< helper thread logon status |
|
275 |
||
276 |
TBool iAllowedToLive : 1; ///< if EFalse the worker thread must gracefully finish ASAP. |
|
277 |
mutable TBool iPriorityBoosted : 1; ///< ETrue when thread priority is boosted by BoostPriority() call |
|
278 |
||
279 |
||
280 |
}; |
|
281 |
||
282 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
283 |
/** |
|
284 |
Abstract base class for the FAT32 helper threads that read FAT by big chunks of data and parse it. |
|
285 |
Provides basic functionality of the helper threads and interface to the owher CAtaFatTable. |
|
286 |
*/ |
|
287 |
class CFat32ScanThread : public CFatHelperThreadBase |
|
288 |
{ |
|
289 |
public: |
|
290 |
||
291 |
virtual TInt Launch(); |
|
292 |
||
293 |
protected: |
|
294 |
CFat32ScanThread(CAtaFatTable& aOwner); |
|
295 |
||
296 |
//-- virtual private interface for the thread function. |
|
297 |
virtual TInt Thread_Preamble(); |
|
298 |
virtual TInt Thread_Postamble(TInt aResult); |
|
299 |
virtual TInt Thread_ProcessCollectedFreeEntries(const CAtaFatTable::TFatScanParam& aFatScanParam)=0; |
|
300 |
||
301 |
friend TInt FAT32_ScanThread(TAny* apHostObject); ///< FAT32 scanner thread function, generic functionality for derived classes |
|
302 |
||
303 |
protected: |
|
304 |
||
305 |
RBuf8 iFatChunkBuf; ///< a buffer for reading FAT directly from the media |
|
306 |
||
307 |
TTime iTimeStart; ///< thread start time, used to measure how long thread worked |
|
308 |
TTime iTimeEnd; ///< thread end time, used to measure how long thread worked |
|
309 |
||
310 |
CFatBitCache *ipFatBitCache; ///< interface to the FAT bit supercache (if it is present) |
|
311 |
}; |
|
312 |
||
313 |
||
314 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
315 |
/** |
|
316 |
FAT32 free FAT entries scanner thread. |
|
317 |
Represents transient FAT32 helper thread that can be launched on FAT table object mounting stage and will be |
|
318 |
counting free FAT entries in order to find out free space on the volume. |
|
319 |
*/ |
|
320 |
class CFat32FreeSpaceScanner : public CFat32ScanThread |
|
321 |
{ |
|
322 |
public: |
|
323 |
||
324 |
static CFat32FreeSpaceScanner* NewL(CAtaFatTable& aOwner); |
|
325 |
||
326 |
virtual inline TFatHelperThreadType Type() const; |
|
327 |
||
328 |
private: |
|
329 |
CFat32FreeSpaceScanner(CAtaFatTable& aOwner); |
|
330 |
||
331 |
void RequestFatEntryWriteAccess(TUint32 aFatIndex) const; |
|
332 |
||
333 |
//-- virtual private interface for the thread function. |
|
334 |
TInt Thread_Preamble(); |
|
335 |
TInt Thread_Postamble(TInt aResult); |
|
336 |
TInt Thread_ProcessCollectedFreeEntries(const CAtaFatTable::TFatScanParam& aFatScanParam); |
|
337 |
//-- |
|
338 |
||
339 |
private: |
|
340 |
||
341 |
void SetClustersScanned(TUint32 aClusters); |
|
342 |
TUint32 ClustersScanned() const; |
|
343 |
||
344 |
friend TInt FAT32_ScanThread(TAny* apHostObject); ///< FAT32 scanner thread function, generic functionality for CFat32ScanThread derived classes |
|
345 |
||
346 |
private: |
|
347 |
||
348 |
enum |
|
349 |
{ |
|
350 |
KFatChunkBufSize_Small = 16*K1KiloByte, //-- buffer size for reading small FAT tables |
|
351 |
KFatChunkBufSize_Big = 64*K1KiloByte, //-- buffer size for reading large FAT tables |
|
352 |
||
353 |
KBigSzFat_Threshold = 2*K1MegaByte, //-- if FAT table size > this value, larger FAT read chunk (KFatChunkBufSize_Big) will be used |
|
354 |
}; |
|
355 |
||
356 |
TUint32 iClustersScanned; ///< Number of FAT entries already scanned by the thread. Counts from the beginning of the FAT |
|
357 |
||
358 |
//-- volume space treshold in bytes that causes CMountCB::SetDiskSpaceChange() to be called by FAT32 free space scanner thread. |
|
359 |
//-- This thread will be calling CMountCB::SetDiskSpaceChange() after processing number of FAT32 entries corresponding to |
|
360 |
//-- this amount of space in FAT clusters. e.g. after processing amount of FAT32 entries comprising 256MB volume space |
|
361 |
enum {KVolSpaceNotifyThreshold = 256 * K1MegaByte}; |
|
362 |
||
363 |
TUint32 iEntriesNotifyThreshold; ///< the value of FAT32 entries need to be counted for CMountCB::SetDiskSpaceChange() call |
|
364 |
TUint32 iNfyThresholdInc; ///< Threshold increment in FAT32 entries. |
|
365 |
||
366 |
||
367 |
}; |
|
368 |
||
369 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
370 |
/** |
|
371 |
FAT32 Bit supercache populating thread. |
|
372 |
Represents transient FAT32 helper thread that is populating bit supercache in backgroud. |
|
373 |
*/ |
|
374 |
class CFat32BitCachePopulator : public CFat32ScanThread |
|
375 |
{ |
|
376 |
public: |
|
377 |
||
378 |
static CFat32BitCachePopulator* NewL(CAtaFatTable& aOwner); |
|
379 |
||
380 |
virtual inline TFatHelperThreadType Type() const; |
|
381 |
||
382 |
private: |
|
383 |
CFat32BitCachePopulator(CAtaFatTable& aOwner); |
|
384 |
||
385 |
void RequestFatEntryWriteAccess(TUint32 aFatIndex) const; |
|
386 |
||
387 |
//-- virtual private interface for the thread function. |
|
388 |
TInt Thread_Preamble(); |
|
389 |
TInt Thread_Postamble(TInt aResult); |
|
390 |
TInt Thread_ProcessCollectedFreeEntries(const CAtaFatTable::TFatScanParam& aFatScanParam); |
|
391 |
//-- |
|
392 |
||
393 |
private: |
|
394 |
friend TInt FAT32_ScanThread(TAny* apHostObject); ///< FAT32 scanner thread function, generic functionality for CFat32ScanThread derived classes |
|
395 |
enum {KFatChunkBufSize = 16*K1KiloByte}; //-- buffer size for FAT reading |
|
396 |
||
397 |
private: |
|
398 |
TUint32 iTotalOccupiedFatEntries; ///< total counted number of non-free FAT entries |
|
399 |
||
400 |
}; |
|
401 |
||
402 |
||
403 |
//--------------------------------------------------------------------------------------------------------------------------------------- |
|
404 |
||
405 |
#include "fat_table32.inl" |
|
406 |
||
407 |
#endif //FAT_TABLE_32_H |
|
408 |
||
409 |
||
410 |
||
411 |
||
412 |
||
413 |
||
414 |
||
415 |
||
416 |
||
417 |
||
418 |
||
419 |
||
420 |
||
421 |
||
422 |
||
423 |
||
424 |
||
425 |
||
426 |
||
427 |
||
428 |
||
429 |
||
430 |