author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Sat, 20 Feb 2010 00:10:51 +0200 | |
branch | RCL_3 |
changeset 19 | 4a8fed1c0ef6 |
parent 8 | 538db54a451d |
child 20 | 597aaf25e343 |
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 |
// fileserver\sfat32\inc\sl_std.h |
|
15 |
// |
|
16 |
||
17 |
/** |
|
18 |
@file |
|
19 |
@internalTechnology |
|
20 |
*/ |
|
21 |
||
22 |
#ifndef SL_STD_H |
|
23 |
#define SL_STD_H |
|
24 |
||
25 |
||
26 |
// |
|
27 |
// #define _DEBUG_RELEASE |
|
28 |
// |
|
29 |
||
30 |
#include "common.h" |
|
31 |
#include <f32ver.h> |
|
32 |
#include <e32svr.h> |
|
33 |
#include <kernel/localise.h> |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
34 |
|
0 | 35 |
#include "filesystem_fat.h" |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
36 |
using namespace FileSystem_FAT; |
0 | 37 |
|
38 |
#include "common_constants.h" |
|
39 |
#include "sl_bpb.h" |
|
40 |
#include "fat_config.h" |
|
41 |
#include "fat_dir_entry.h" |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
42 |
#include "bit_vector.h" |
0 | 43 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
44 |
|
0 | 45 |
|
46 |
#ifdef _DEBUG |
|
47 |
_LIT(KThisFsyName,"EFAT32.FSY"); ///< This FSY name |
|
48 |
#endif |
|
49 |
||
50 |
//----------------------------------------------------------------------------- |
|
51 |
//-- FAT32 specific declarations |
|
52 |
||
53 |
const TUint32 KFat32EntryMask = 0x0FFFFFFF; |
|
54 |
||
55 |
//----------------------------------------------------------------------------- |
|
56 |
||
57 |
class CFatMountCB; |
|
58 |
class CFatFileSystem; |
|
59 |
||
60 |
/** |
|
61 |
Represents the position of a directory entery in terms of a cluster and off set into it |
|
62 |
*/ |
|
63 |
class TEntryPos |
|
64 |
{ |
|
65 |
public: |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
66 |
TEntryPos() : iCluster(EOF_32Bit), iPos(0) {} |
0 | 67 |
TEntryPos(TInt aCluster,TUint aPos) : iCluster(aCluster), iPos(aPos) {} |
68 |
||
69 |
inline TUint32 Cluster() const; |
|
70 |
inline TUint32 Pos() const; |
|
71 |
inline TBool operator==(const TEntryPos& aRhs) const; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
72 |
inline void SetEndOfDir(); |
0 | 73 |
|
74 |
public: |
|
75 |
TInt iCluster; |
|
76 |
TUint iPos; |
|
77 |
}; |
|
78 |
||
79 |
||
80 |
/** |
|
81 |
Interface class between the file system and the local drive media interface, |
|
82 |
handles incomplete writes to media with the ability to notify the user. |
|
83 |
This class can't be instantinated by user; only CFatMountCB can do this; see CFatMountCB::DriveInterface() |
|
84 |
||
85 |
*/ |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
class TDriveInterface |
0 | 87 |
{ |
88 |
public: |
|
89 |
enum TAction {ERetry=1}; |
|
90 |
||
91 |
public: |
|
92 |
||
93 |
//-- public interface to the local drive. Provides media driver's error handling (critical and non-critical user notifiers) |
|
94 |
//-- and thread-safety if required. |
|
95 |
TInt ReadNonCritical(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const; |
|
96 |
TInt ReadNonCritical(TInt64 aPos,TInt aLength,TDes8& aTrg) const; |
|
97 |
TInt ReadCritical(TInt64 aPos,TInt aLength,TDes8& aTrg) const; |
|
98 |
||
99 |
TInt WriteCritical(TInt64 aPos,const TDesC8& aSrc); |
|
100 |
TInt WriteNonCritical(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset); |
|
101 |
||
102 |
TInt GetLastErrorInfo(TDes8& aErrorInfo) const; |
|
103 |
||
104 |
//-- lock the mutex guarding CProxyDrive interface in order to be sure that no other thread can access it. |
|
105 |
//-- The thread that calls this method may be suspended until another signals the mutex, i.e. leaves the critical section. |
|
106 |
inline void AcquireLock() const {iProxyDrive.EnterCriticalSection();} |
|
107 |
||
108 |
//-- release the mutex guarding CProxyDrive. |
|
109 |
inline void ReleaseLock() const {iProxyDrive.LeaveCriticalSection();} |
|
110 |
||
111 |
||
112 |
protected: |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
TDriveInterface(); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
114 |
~TDriveInterface() {Close();} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
115 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
116 |
//-- outlawed |
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
TDriveInterface(const TDriveInterface&); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
TDriveInterface& operator=(const TDriveInterface&); |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
119 |
void* operator new(TUint); //-- disable creating objets of this class on the heap. |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
120 |
void* operator new(TUint, void*); |
0 | 121 |
|
122 |
TBool Init(CFatMountCB* aMount); |
|
123 |
void Close(); |
|
124 |
||
125 |
inline TBool NotifyUser() const; |
|
126 |
TInt HandleRecoverableError(TInt aRes) const; |
|
127 |
TInt HandleCriticalError(TInt aRes) const; |
|
128 |
TInt UnlockAndReMount() const; |
|
129 |
TBool IsDriveWriteProtected() const; |
|
130 |
TBool IsRecoverableRemount() const; |
|
131 |
||
132 |
private: |
|
133 |
||
134 |
/** |
|
135 |
An internal class that represents a thread-safe wrapper around raw interface to the CProxyDrive |
|
136 |
and restricts access to it. |
|
137 |
*/ |
|
138 |
class XProxyDriveWrapper |
|
139 |
{ |
|
140 |
public: |
|
141 |
||
142 |
XProxyDriveWrapper(); |
|
143 |
~XProxyDriveWrapper(); |
|
144 |
||
145 |
TBool Init(CProxyDrive* aProxyDrive); |
|
146 |
||
147 |
inline void EnterCriticalSection() const {iLock.Wait();} |
|
148 |
inline void LeaveCriticalSection() const {iLock.Signal();} |
|
149 |
||
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
//-- methods' wrappers that are used by TDriveInterface |
0 | 151 |
TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const; |
152 |
TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg) const; |
|
153 |
TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset); |
|
154 |
TInt Write(TInt64 aPos, const TDesC8& aSrc); |
|
155 |
TInt GetLastErrorInfo(TDes8& aErrorInfo) const; |
|
156 |
TInt Caps(TDes8& anInfo) const; |
|
157 |
||
158 |
private: |
|
159 |
CProxyDrive* iLocalDrive; ///< raw interface to the media operations |
|
160 |
mutable RMutex iLock; ///< used for sorting out multithreaded access to the iLocalDrive |
|
161 |
}; |
|
162 |
||
163 |
CFatMountCB* iMount; ///< Pointer to the owning file system mount |
|
164 |
XProxyDriveWrapper iProxyDrive; ///< wrapper around raw interface to the media operations |
|
165 |
||
166 |
}; |
|
167 |
||
168 |
||
169 |
/** |
|
170 |
Class providing FAT table interface and basic functionality. |
|
171 |
*/ |
|
172 |
class CFatTable : public CBase |
|
173 |
{ |
|
174 |
||
175 |
public: |
|
176 |
||
177 |
virtual ~CFatTable(); |
|
178 |
||
179 |
static CFatTable* NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps); |
|
180 |
||
181 |
/** FAT table mounting parameters */ |
|
182 |
struct TMountParams |
|
183 |
{ |
|
184 |
TMountParams() :iFreeClusters(0), iFirstFreeCluster(0), iFsInfoValid(0) {}; |
|
185 |
||
186 |
TUint32 iFreeClusters; ///< Free clusters count, obtained from FSInfo |
|
187 |
TUint32 iFirstFreeCluster; ///< First free cluster, obtained from FSInfo |
|
188 |
TUint32 iFsInfoValid : 1; ///< ETrue if the information in iFreeClusters & iFirstFreeCluster is valid |
|
189 |
}; |
|
190 |
||
191 |
//----------------------------------------------------------------- |
|
192 |
//-- pure virtual interface |
|
193 |
virtual TUint32 ReadL(TUint32 aFatIndex) const = 0; |
|
194 |
virtual void WriteL(TUint32 aFatIndex, TUint32 aValue) = 0; |
|
195 |
virtual TInt64 DataPositionInBytes(TUint32 aCluster) const = 0; |
|
196 |
virtual void MountL(const TMountParams& aMountParam) = 0; |
|
197 |
//----------------------------------------------------------------- |
|
198 |
//-- just virtual interface |
|
199 |
||
200 |
virtual void Dismount(TBool /*aDiscardDirtyData*/) {} |
|
201 |
virtual void FlushL() {}; |
|
202 |
||
203 |
virtual void InvalidateCacheL() {}; |
|
204 |
virtual void InvalidateCacheL(TInt64 /*aPos*/,TUint32 /*aLength*/) {}; |
|
205 |
||
206 |
virtual void FreeClusterListL(TUint32 aCluster); |
|
207 |
virtual void ExtendClusterListL(TUint32 aNumber,TInt& aCluster); |
|
208 |
||
209 |
virtual TUint32 AllocateSingleClusterL(TUint32 aNearestCluster); |
|
210 |
virtual TUint32 AllocateClusterListL(TUint32 aNumber,TUint32 aNearestCluster); |
|
211 |
||
212 |
virtual void RequestRawWriteAccess(TInt64 /*aPos*/, TUint32 /*aLen*/) const {}; |
|
213 |
||
214 |
virtual TUint32 FreeClusterHint() const; |
|
215 |
virtual TUint32 NumberOfFreeClusters(TBool aSyncOperation=EFalse) const; |
|
216 |
virtual TBool RequestFreeClusters(TUint32 aClustersRequired) const; |
|
217 |
||
218 |
virtual void InitializeL(); |
|
219 |
virtual TBool ConsistentState() const {return ETrue;} //-- dummy |
|
220 |
||
221 |
//----------------------------------------------------------------- |
|
222 |
//-- non-virtual interface |
|
223 |
TBool GetNextClusterL(TInt& aCluster) const; |
|
224 |
void WriteFatEntryEofL(TUint32 aFatIndex); |
|
225 |
||
226 |
void MarkAsBadClusterL(TUint32 aCluster); |
|
227 |
TInt CountContiguousClustersL(TUint32 aStartCluster,TInt& anEndCluster, TUint32 aMaxCount) const; |
|
228 |
||
229 |
inline TUint32 MaxEntries() const; |
|
230 |
||
231 |
TUint32 PosInBytes(TUint32 aFatIndex) const; |
|
232 |
||
233 |
||
234 |
protected: |
|
235 |
CFatTable(CFatMountCB& aOwner); |
|
236 |
||
237 |
//-- outlawed |
|
238 |
CFatTable(); |
|
239 |
CFatTable(const CFatTable&); |
|
240 |
CFatTable& operator=(const CFatTable&); |
|
241 |
||
242 |
virtual void SetFreeClusterHint(TUint32 aCluster); |
|
243 |
||
244 |
virtual void DecrementFreeClusterCount(TUint32 aCount); |
|
245 |
virtual void IncrementFreeClusterCount(TUint32 aCount); |
|
246 |
||
247 |
virtual void SetFreeClusters(TUint32 aFreeClusters); |
|
248 |
virtual void CountFreeClustersL(); |
|
249 |
virtual TUint32 FindClosestFreeClusterL(TUint32 aCluster); |
|
250 |
||
251 |
||
252 |
inline TInt SectorSizeLog2() const; |
|
253 |
inline TUint32 FreeClusters() const; |
|
254 |
||
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
inline TBool IsEndOfClusterCh(TUint32 aCluster) const; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
|
0 | 257 |
|
258 |
inline TFatType FatType() const; |
|
259 |
inline TBool IsFat12() const; |
|
260 |
inline TBool IsFat16() const; |
|
261 |
inline TBool IsFat32() const; |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
|
0 | 263 |
|
264 |
inline TBool ClusterNumberValid(TUint32 aClusterNo) const; |
|
265 |
||
266 |
typedef RArray<TUint> RClusterArray; |
|
267 |
void DoFreedClustersNotify(RClusterArray &aFreedClusters); |
|
268 |
||
269 |
||
270 |
protected: |
|
271 |
||
272 |
CFatMountCB* iOwner; ///< Owning file system mount |
|
273 |
TUint iMediaAtt; ///< Cached copy of TLocalDriveCaps::iMediaAtt |
|
274 |
||
275 |
private: |
|
276 |
||
277 |
TUint32 iFreeClusters; ///< Number of free cluster in the fat table |
|
278 |
TUint32 iFreeClusterHint; ///< this is just a hint to the free cluster number, not required to contain exact information. |
|
279 |
TFatType iFatType; ///< FAT type 12/16/32, cached from the iOwner |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
TUint32 iFatEocCode; ///< End Of Cluster Chain code, 0xff8 for FAT12, 0xfff8 for FAT16, and 0xffffff8 for FAT32 |
0 | 281 |
TUint32 iMaxEntries; ///< maximal number of FAT entries in the table. This value is taken from the CFatMount that calculates it |
282 |
||
283 |
}; |
|
284 |
||
285 |
||
286 |
class MWTCacheInterface; |
|
287 |
||
288 |
||
289 |
//--------------------------------------------------------------------------------------------------------------------------------- |
|
290 |
||
291 |
/** |
|
292 |
Base class abstraction of a raw media disk |
|
293 |
*/ |
|
294 |
||
295 |
||
296 |
class CRawDisk : public CBase |
|
297 |
{ |
|
298 |
public: |
|
299 |
||
300 |
static CRawDisk* NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps); |
|
301 |
||
302 |
virtual void InitializeL(); |
|
303 |
||
304 |
virtual TInt GetLastErrorInfo(TDes8& aErrorInfo) const; |
|
305 |
public: |
|
306 |
||
307 |
/** |
|
308 |
Read data from the media via simple WT data cache if it is present. Some media types, like RAM do not have caches. |
|
309 |
This method is mostly used to read UIDs of executable modules and store them in the cache. |
|
310 |
||
311 |
@param aPos Media position in bytes |
|
312 |
@param aLength Length in bytes of read |
|
313 |
@param aDes Data from read |
|
314 |
*/ |
|
315 |
virtual void ReadCachedL(TInt64 aPos,TInt aLength,TDes8& aDes) const = 0; |
|
316 |
||
317 |
/** |
|
318 |
Write data to the media via simple WT data cache if it is present. Some media types, like RAM do not have caches. |
|
319 |
@param aPos Media position in bytes |
|
320 |
@param aDes Data to write |
|
321 |
*/ |
|
322 |
virtual void WriteCachedL(TInt64 aPos,const TDesC8& aDes) = 0; |
|
323 |
||
324 |
virtual void InvalidateUidCache() {} |
|
325 |
virtual void InvalidateUidCachePage(TUint64 /*aPos*/) {} |
|
326 |
||
327 |
||
328 |
/** |
|
329 |
Disk read function |
|
330 |
||
331 |
@param aPos Media position in bytes |
|
332 |
@param aLength Length in bytes of read |
|
333 |
@param aTrg Pointer to the data descriptor, i.e. (const TAny*)(&TDes8) |
|
334 |
@param aMessage Refrence to server message from request |
|
335 |
@param anOffset Offset into read data to write |
|
336 |
*/ |
|
337 |
virtual void ReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const = 0; |
|
338 |
||
339 |
/** |
|
340 |
Disk write function |
|
341 |
||
342 |
@param aPos Media position in bytes |
|
343 |
@param aLength Length in bytes of write |
|
344 |
@param aTrg Pointer to the data descriptor, i.e. (const TAny*)(&TDes8) |
|
345 |
@param aMessage Refrence to server message from request, contains data |
|
346 |
@param anOffset Offset into write data to use in write |
|
347 |
*/ |
|
348 |
virtual void WriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset) = 0; |
|
349 |
||
350 |
||
351 |
virtual inline MWTCacheInterface* DirCacheInterface(); |
|
352 |
||
353 |
||
354 |
||
355 |
||
356 |
protected: |
|
357 |
||
358 |
CRawDisk(CFatMountCB& aOwner); |
|
359 |
||
360 |
//-- outlawed |
|
361 |
CRawDisk(); |
|
362 |
CRawDisk(const CRawDisk&); |
|
363 |
CRawDisk& operator=(const CRawDisk&); |
|
364 |
||
365 |
||
366 |
protected: |
|
367 |
||
368 |
CFatMountCB* iFatMount; ///< Owning file system mount |
|
369 |
||
370 |
||
371 |
||
372 |
}; |
|
373 |
||
374 |
class CFatFileCB; |
|
375 |
class RBitVector; |
|
376 |
||
377 |
/** |
|
378 |
A helper class. Holds the FAT volume parameters, which in turn are obtained from the Boot Sector |
|
379 |
*/ |
|
380 |
class TFatVolParam |
|
381 |
{ |
|
382 |
public: |
|
383 |
||
384 |
TFatVolParam(); |
|
385 |
void Populate(const TFatBootSector& aBootSector); |
|
386 |
TBool operator==(const TFatVolParam& aRhs) const; |
|
387 |
||
388 |
//-- simple getters |
|
389 |
TUint32 ClusterSizeLog2() const {return iClusterSizeLog2; } |
|
390 |
TUint32 SectorSizeLog2() const {return iSectorSizeLog2; } |
|
391 |
TUint32 RootDirEnd() const {return iRootDirEnd; } |
|
392 |
TUint32 SectorsPerCluster() const {return iSectorsPerCluster; } |
|
393 |
TUint32 RootDirectorySector() const {return iRootDirectorySector;} |
|
394 |
TUint32 FirstFatSector() const {return iFirstFatSector; } |
|
395 |
TUint32 TotalSectors() const {return iTotalSectors; } |
|
396 |
TUint32 NumberOfFats() const {return iNumberOfFats; } |
|
397 |
TUint32 FatSizeInBytes() const {return iFatSizeInBytes; } |
|
398 |
TUint32 RootClusterNum() const {return iRootClusterNum; } |
|
399 |
TUint32 FSInfoSectorNum() const {return iFSInfoSectorNum; } |
|
400 |
TUint32 BkFSInfoSectorNum() const {return iBkFSInfoSectorNum; } |
|
401 |
||
402 |
protected: |
|
403 |
TUint32 iClusterSizeLog2; ///< Log2 of fat file system cluster size |
|
404 |
TUint32 iSectorSizeLog2; ///< Log2 of media sector size |
|
405 |
TUint32 iRootDirEnd; ///< End position of the root directory for Fat12/16 |
|
406 |
TUint32 iSectorsPerCluster; ///< Sector per cluster ratio for mounted Fat file system volume |
|
407 |
TUint32 iRootDirectorySector; ///< Start sector of the root directory for Fat12/16 |
|
408 |
TUint32 iFirstFatSector; ///< Start sector of the first Fat table in volume |
|
409 |
TUint32 iTotalSectors; ///< Total sectors on media partition |
|
410 |
TUint32 iNumberOfFats; ///< Number of Fats the volume has |
|
411 |
TUint32 iFatSizeInBytes; ///< Size of a single Fat table in volume |
|
412 |
TUint32 iRootClusterNum; ///< Cluster number for Root directory, for Fat32 |
|
413 |
TUint32 iFSInfoSectorNum; ///< FSInfo Sector number. If 0, this means that corresponding value isn't set in BPB |
|
414 |
TUint32 iBkFSInfoSectorNum; ///< backup FSInfo Sector number |
|
415 |
}; |
|
416 |
||
417 |
||
418 |
TBool IsLegalDosName(const TDesC& aName, TBool anAllowWildCards, TBool aUseExtendedChars, TBool aInScanDrive, TBool aAllowLowerCase, TBool aIsForFileCreation); |
|
419 |
TBool IsLegalDOSNameChar(TChar aCharacter, TBool aUseExtendedChars); |
|
420 |
||
421 |
TUint32 CalculatePageOffsetInCluster(TUint32 aPos, TUint aPageSzLog2); |
|
422 |
||
423 |
class CLruCache; |
|
424 |
class TLeafDirData; |
|
425 |
class CLeafDirCache; |
|
426 |
||
427 |
||
428 |
/** |
|
429 |
Fat file system mount implmentation, provides all that is required of a plug in |
|
430 |
file system mount as well as Fat mount specific functionality |
|
431 |
*/ |
|
432 |
class CFatMountCB : public CLocDrvMountCB, |
|
433 |
public MFileSystemSubType, |
|
434 |
public MFileSystemClusterSize, |
|
435 |
public CMountCB::MFileAccessor, |
|
436 |
public CMountCB::MFileExtendedInterface |
|
437 |
{ |
|
438 |
public: |
|
439 |
static CFatMountCB* NewL(); |
|
440 |
~CFatMountCB(); |
|
441 |
void ConstructL(); |
|
442 |
||
443 |
public: |
|
444 |
||
445 |
//-- overrides from the abstract CMountCB |
|
446 |
void MountL(TBool aForceMount); |
|
447 |
TInt ReMount(); |
|
448 |
void Dismounted(); |
|
449 |
void VolumeL(TVolumeInfo& aVolume) const; |
|
450 |
void SetVolumeL(TDes& aName); |
|
451 |
void MkDirL(const TDesC& aName); |
|
452 |
void RmDirL(const TDesC& aName); |
|
453 |
void DeleteL(const TDesC& aName); |
|
454 |
void RenameL(const TDesC& anOldName,const TDesC& anNewName); |
|
455 |
void ReplaceL(const TDesC& anOldName,const TDesC& anNewName); |
|
456 |
void EntryL(const TDesC& aName,TEntry& anEntry) const; |
|
457 |
void SetEntryL(const TDesC& aName,const TTime& aTime,TUint aMask,TUint aVal); |
|
458 |
void FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile); |
|
459 |
void DirOpenL(const TDesC& aName,CDirCB* aDir); |
|
460 |
void RawReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt anOffset,const RMessagePtr2& aMessage) const; |
|
461 |
void RawWriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt anOffset,const RMessagePtr2& aMessage); |
|
462 |
void GetShortNameL(const TDesC& aLongName,TDes& aShortName); |
|
463 |
void GetLongNameL(const TDesC& aShortName,TDes& aLongName); |
|
464 |
void ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage); |
|
465 |
TInt CheckDisk(); |
|
466 |
TInt ScanDrive(); |
|
467 |
TInt ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2); |
|
468 |
TInt Lock(TMediaPassword& aOld,TMediaPassword& aNew,TBool aStore); |
|
469 |
TInt Unlock(TMediaPassword& aPassword,TBool aStore); |
|
470 |
TInt ClearPassword(TMediaPassword& aPassword); |
|
471 |
TInt ErasePassword(); |
|
472 |
TInt ForceRemountDrive(const TDesC8* aMountInfo,TInt aMountInfoMessageHandle,TUint aFlags); |
|
473 |
||
474 |
void FinaliseMountL(); |
|
475 |
void FinaliseMountL(TInt aOperation, TAny* aParam1=NULL, TAny* aParam2=NULL); |
|
476 |
TInt MountControl(TInt aLevel, TInt aOption, TAny* aParam); |
|
477 |
TTimeIntervalSeconds TimeOffset() const; |
|
478 |
||
479 |
protected: |
|
480 |
||
481 |
/** CFatMountCB states */ |
|
482 |
enum TFatMntState |
|
483 |
{ |
|
484 |
ENotMounted = 0, ///< 0, initial state, not mounted (mount state is inconsistent) |
|
485 |
EMounting, ///< 1, Mounting started (mount state is inconsistent) |
|
486 |
EInit_R, ///< 2, Initialised and not written (mount state is Consistent) |
|
487 |
EInit_W, ///< 3, Initialised and written (mount state is Consistent) |
|
488 |
EFinalised, ///< 4, Finalised (mount state is Consistent) |
|
489 |
EDismounted, ///< 5, Dismounted (mount state is inconsistent) |
|
490 |
EInit_Forced, ///< 6, forcedly mounted, special case (mount state is inconsistent) |
|
491 |
}; |
|
492 |
||
493 |
inline TFatMntState State() const; |
|
494 |
inline void SetState(TFatMntState aState); |
|
495 |
TInt OpenMountForWrite(); |
|
496 |
TInt IsFinalised(TBool& aFinalised); |
|
497 |
||
498 |
/** |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
A wrapper around TDriveInterface providing its instantination and destruction. |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
500 |
You must not create objects of this class, use DriveInterface() method for obtaining the reference to the driver interface. |
0 | 501 |
*/ |
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
class XDriveInterface: public TDriveInterface |
0 | 503 |
{ |
504 |
public: |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
505 |
using TDriveInterface::Init; |
0 | 506 |
}; |
507 |
||
508 |
||
509 |
public: |
|
510 |
||
511 |
enum TRenMode {EModeReplace,EModeRename}; |
|
512 |
||
513 |
TBool ConsistentState() const; |
|
514 |
void CheckWritableL() const; |
|
515 |
void CheckStateConsistentL() const; |
|
516 |
||
517 |
inline TBool ReadOnly(void) const; |
|
518 |
inline void SetReadOnly(TBool aReadOnlyMode); |
|
519 |
inline TInt StartCluster(const TFatDirEntry & anEntry) const; |
|
520 |
inline CRawDisk& RawDisk() const; |
|
521 |
inline CFatFileSystem& FatFileSystem() const; |
|
522 |
inline CFatTable& FAT() const; |
|
523 |
inline TInt ClusterSizeLog2() const; |
|
524 |
inline TInt SectorSizeLog2() const; |
|
525 |
inline TInt TotalSectors() const; |
|
526 |
inline TInt SectorsPerCluster() const; |
|
527 |
inline TInt ClusterBasePosition() const; |
|
528 |
inline TInt RootDirectorySector() const; |
|
529 |
inline TUint RootDirEnd() const; |
|
530 |
inline TUint32 RootClusterNum() const; |
|
531 |
||
532 |
inline TFatType FatType() const; |
|
533 |
inline TBool Is16BitFat() const; |
|
534 |
inline TBool Is32BitFat() const; |
|
535 |
||
536 |
inline TUint32 MaxClusterNumber() const; |
|
537 |
inline TInt StartOfFatInBytes() const; |
|
538 |
inline TUint32 FirstFatSector() const; |
|
539 |
||
540 |
inline TInt NumberOfFats() const; |
|
541 |
inline TInt FatSizeInBytes() const; |
|
542 |
inline TInt ClusterRelativePos(TInt aPos) const; |
|
543 |
inline TUint StartOfRootDirInBytes() const; |
|
544 |
inline TUint32 UsableClusters() const; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
545 |
inline TBool ClusterNumberValid(TUint32 aClusterNo) const; |
0 | 546 |
inline TBool IsBadCluster(TInt aCluster) const; |
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
547 |
|
0 | 548 |
inline TBool IsRuggedFSys() const; |
549 |
inline void SetRuggedFSys(TBool aVal); |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
550 |
inline TUint32 AtomicWriteGranularityLog2() const; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
551 |
|
0 | 552 |
|
553 |
inline TInt RootIndicator() const; |
|
554 |
||
555 |
inline TBool IsRootDir(const TEntryPos &aEntry) const; |
|
556 |
inline CAsyncNotifier* Notifier() const; |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
inline TDriveInterface& DriveInterface() const; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
inline TBool IsEndOfClusterCh(TInt aCluster) const; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
inline void SetEndOfClusterCh(TInt &aCluster) const; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
|
0 | 562 |
|
563 |
void ReadUidL(TInt aCluster,TEntry& anEntry) const; |
|
564 |
||
565 |
void ReadDirEntryL(const TEntryPos& aPos,TFatDirEntry& aDirEntry) const; |
|
566 |
void WriteDirEntryL(const TEntryPos& aPos,const TFatDirEntry& aDirEntry); |
|
567 |
||
568 |
void DirReadL(const TEntryPos& aPos,TInt aLength,TDes8& aDes) const; |
|
569 |
void DirWriteL(const TEntryPos& aPos,const TDesC8& aDes); |
|
570 |
||
571 |
void ReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const; |
|
572 |
void WriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt& aBadcluster, TInt &aGoodcluster); |
|
573 |
void MoveToNextEntryL(TEntryPos& aPos) const; |
|
574 |
void MoveToDosEntryL(TEntryPos& aPos,TFatDirEntry& anEntry) const; |
|
575 |
void EnlargeL(TInt aSize); |
|
576 |
void ReduceSizeL(TInt aPos,TInt aLength); |
|
577 |
void DoDismount(); |
|
578 |
TBool ProcessFSInfoSectors(CFatTable::TMountParams& aFatInitParams) const; |
|
579 |
||
580 |
||
581 |
void DoRenameOrReplaceL(const TDesC& anOldName,const TDesC& aNewName,TRenMode aMode,TEntryPos& aNewPos); |
|
582 |
void FindDosNameL(const TDesC& aName,TUint anAtt,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName,TInt anError) const; |
|
583 |
||
584 |
void Dismount(); |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
585 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
void InitializeRootEntry(TFatDirEntry & anEntry) const; |
0 | 587 |
|
588 |
TInt64 MakeLinAddrL(const TEntryPos& aPos) const; |
|
589 |
||
590 |
inline const TFatConfig& FatConfig() const; |
|
591 |
TBool CheckVolumeTheSame(); |
|
592 |
||
593 |
void InvalidateLeafDirCache(); |
|
594 |
||
595 |
void BlockMapReadFromClusterListL(TEntryPos& aPos, TInt aLength, SBlockMapInfo& aInfo); |
|
596 |
virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput); |
|
597 |
virtual TInt GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId); |
|
598 |
virtual TInt Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2); |
|
599 |
virtual TInt Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2); |
|
600 |
virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2); |
|
601 |
||
602 |
public: |
|
603 |
||
604 |
// interface extension implementation |
|
605 |
virtual TInt SubType(TDes& aName) const; |
|
606 |
virtual TInt ClusterSize() const; |
|
607 |
virtual void ReadSection64L(const TDesC& aName, TInt64 aPos, TAny* aTrg, TInt aLength, const RMessagePtr2& aMessage); |
|
608 |
||
609 |
private: |
|
610 |
||
611 |
/** An ad hoc internal helper object for using in DoFindL() method and its derivatives */ |
|
612 |
class TFindHelper |
|
613 |
{ |
|
614 |
public: |
|
615 |
TFindHelper() {isInitialised = EFalse;} |
|
616 |
void InitialiseL(const TDesC& aTargetName); |
|
617 |
TBool MatchDosEntryName(const TUint8* apDosEntryName) const; |
|
618 |
TBool TrgtNameIsLegalDos() const {ASSERT (isInitialised) ;return isLegalDosName;} |
|
619 |
||
620 |
private: |
|
621 |
TFindHelper(const TFindHelper&); |
|
622 |
TFindHelper& operator=(const TFindHelper&); |
|
623 |
public: |
|
624 |
TPtrC iTargetName; ///< pointer to the aTargetName, used in DoRummageDirCacheL() as a parameter |
|
625 |
private: |
|
626 |
TBool isInitialised :1; ///< ETrue if the object is initialised. It can be done only once. |
|
627 |
TBool isLegalDosName :1; ///< ETrue if iTargetName is a legal DOS name |
|
628 |
TShortName iShortName; ///< a short DOS name in XXXXXXXXYYY format generated from aTargetName |
|
629 |
}; |
|
630 |
||
631 |
||
632 |
/** |
|
633 |
An ad hoc internal helper object for entry creations |
|
634 |
*/ |
|
635 |
class XFileCreationHelper |
|
636 |
{ |
|
637 |
public: |
|
638 |
XFileCreationHelper(); |
|
639 |
~XFileCreationHelper(); |
|
640 |
void Close(); |
|
641 |
void InitialiseL(const TDesC& aTargetName); |
|
642 |
TInt GetValidatedShortName(TShortName& aShortName) const; |
|
643 |
void CheckShortNameCandidates(const TUint8* apDosEntryName); |
|
644 |
||
645 |
// inline functions for sets and gets |
|
646 |
// note all the get functions have been checked against initialisation status |
|
647 |
inline TBool IsInitialised() const; |
|
648 |
inline TUint16 NumOfAddingEntries() const; |
|
649 |
inline TEntryPos EntryAddingPos()const; |
|
650 |
inline TBool IsNewEntryPosFound() const; |
|
651 |
inline TBool IsTrgNameLegalDosName() const; |
|
652 |
||
653 |
inline void SetEntryAddingPos(const TEntryPos& aEntryPos); |
|
654 |
inline void SetIsNewEntryPosFound(TBool aFound); |
|
655 |
||
656 |
private: |
|
657 |
XFileCreationHelper(const XFileCreationHelper&); |
|
658 |
XFileCreationHelper& operator=(const TFindHelper&); |
|
659 |
||
660 |
private: |
|
661 |
TPtrC iTargetName; ///< pointer to hold the long file name of the target file |
|
662 |
TUint16 iNumOfAddingEntries;///< calculated number of entries to add |
|
663 |
TEntryPos iEntryAddingPos; ///< contains new entry position for adding if found any |
|
664 |
TBool isNewEntryPosFound; ///< flags whether the position for new entries is found |
|
665 |
TBool isInitialised :1; ///< flags whether the object is initialised |
|
666 |
TBool isTrgNameLegalDosName :1; ///< flags whether the target file name is a valid Dos name |
|
667 |
/** |
|
668 |
an array that holds short name candidates, prepared on initialisation. |
|
669 |
*/ |
|
670 |
RArray<TShortName> iShortNameCandidates; |
|
671 |
}; |
|
672 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
673 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
674 |
/** a helper class that describes a continuous chunk of diectory entries*/ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
675 |
class TEntrySetChunkInfo |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
676 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
677 |
public: |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
678 |
inline TEntrySetChunkInfo(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
679 |
inline TBool operator==(const TEntrySetChunkInfo& aRhs); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
680 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
681 |
//-- FAT entryset can't span more than 3 clusters/sectors |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
682 |
enum {KMaxChunks = 3}; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
683 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
684 |
public: |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
685 |
TEntryPos iEntryPos; ///< entryset chunk dir. starting position |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
686 |
TUint iNumEntries; ///< number of entries in the chunk |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
687 |
}; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
688 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
689 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
690 |
void DoEraseEntrySetChunkL(const TEntrySetChunkInfo& aEntrySetChunk); |
0 | 691 |
|
692 |
||
693 |
TBool DoRummageDirCacheL(TUint anAtt,TEntryPos& aStartEntryPos,TFatDirEntry& aStartEntry,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName, const TFindHelper& aAuxParam, XFileCreationHelper* aFileCreationHelper, const TLeafDirData& aLeafDir) const; |
|
694 |
TBool DoFindL(const TDesC& aName,TUint anAtt,TEntryPos& aStartEntryPos,TFatDirEntry& aStartEntry,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName,TInt anError, XFileCreationHelper* aFileCreationHelper, const TLeafDirData& aLeafDirData) const; |
|
695 |
void FindEntryStartL(const TDesC& aName,TUint anAtt,TFatDirEntry& anEntry,TEntryPos& aPos, XFileCreationHelper* aFileCreationHelper) const; |
|
696 |
||
697 |
void FindEntryStartL(const TDesC& aName,TUint anAtt,TFatDirEntry& anEntry,TEntryPos& aPos) const; |
|
698 |
||
699 |
void CheckFatForLoopsL(const TFatDirEntry& anEntry) const; |
|
700 |
void DoCheckFatForLoopsL(TInt aCluster,TInt& aPreviousCluster,TInt& aChangePreviousCluster,TInt& aCount) const; |
|
701 |
void InitializeL(const TLocalDriveCaps& aLocDrvCaps, TBool aIgnoreFSInfo=EFalse); |
|
702 |
void DoReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const; |
|
703 |
void DoWriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt aLastcluster, TInt& aBadcluster, TInt& aGoodcluster); |
|
704 |
TBool IsUniqueNameL(const TShortName& aName,TInt aDirCluster); |
|
705 |
TBool FindShortNameL(const TShortName& aName,TEntryPos& anEntryPos); |
|
706 |
void ReplaceClashingNameL(const TShortName& aNewName,const TEntryPos& anEntryPos); |
|
707 |
TBool GenerateShortNameL(TInt aDirCluster,const TDesC& aLongName,TShortName& aShortName, TBool aForceRandomize=EFalse); |
|
708 |
TInt FindLeafDirL(const TDesC& aName, TLeafDirData& aLeafDir) const; |
|
709 |
||
710 |
TInt GetDirEntry(TEntryPos& aPos,TFatDirEntry& aDosEntry,TFatDirEntry& aStartEntry,TDes& aLongFileName) const; |
|
711 |
TBool DoGetDirEntryL(TEntryPos& aPos,TFatDirEntry& aDosEntry,TFatDirEntry& aStartEntry,TDes& aLongFileName) const; |
|
712 |
||
713 |
void WriteDirEntryL(TEntryPos& aPos,const TFatDirEntry& aFatDirEntry,const TDesC& aLongFileName); |
|
714 |
void EraseDirEntryL(TEntryPos aPos,const TFatDirEntry& anEntry); |
|
715 |
void EraseDirEntryL(const TEntryPos& aPos); |
|
716 |
void InitializeFirstDirClusterL(TInt aCluster,TInt aParentCluster); |
|
717 |
void AddDirEntryL(TEntryPos& aPos,TInt aNameLength); |
|
718 |
void ZeroDirClusterL(TInt aCluster); |
|
719 |
||
720 |
TInt DoWriteBootSector(TInt64 aMediaPos, const TFatBootSector& aBootSector) const; |
|
721 |
TInt DoReadBootSector(TInt64 aMediaPos, TFatBootSector& aBootSector) const; |
|
722 |
TInt ReadBootSector(TFatBootSector& aBootSector, TBool aDoNotReadBkBootSec=EFalse); |
|
723 |
||
724 |
TInt WriteFSInfoSector(TInt64 aMediaPos, const TFSInfo& aFSInfo) const; |
|
725 |
TInt ReadFSInfoSector(TInt64 aMediaPos, TFSInfo& aFSInfo) const; |
|
726 |
||
727 |
TBool IsDirectoryEmptyL(TInt aCluster); |
|
728 |
void ExtendClusterListZeroedL(TInt aNumber,TInt& aCluster); |
|
729 |
void WritePasswordData(); |
|
730 |
||
731 |
void WriteVolumeLabelL(const TDesC8& aVolumeLabel) const; |
|
732 |
TInt ReadVolumeLabelFile(TDes8& aLabel); |
|
733 |
void WriteVolumeLabelFileL(const TDesC8& aNewName); |
|
734 |
void FindVolumeLabelFileL(TDes8& aLabel, TEntryPos& aDosEntryPos, TFatDirEntry& aDosEntry); |
|
735 |
void GetVolumeLabelFromDiskL(const TFatBootSector& aBootSector); |
|
736 |
void TrimVolumeLabel(TDes8& aLabel) const; |
|
737 |
||
738 |
TInt DoRunScanDrive(); |
|
739 |
TBool VolumeCleanL(); |
|
740 |
void SetVolumeCleanL(TBool aClean); |
|
741 |
TBool VolCleanFlagSupported() const; |
|
742 |
||
743 |
void DoUpdateFSInfoSectorsL(TBool aInvalidateFSInfo); |
|
744 |
void UnFinaliseMountL(); |
|
745 |
void DoReMountL(); |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
void SetFatType(TFatType aFatType); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
747 |
|
0 | 748 |
|
749 |
private: |
|
750 |
||
751 |
||
752 |
CFatMountCB(); |
|
753 |
||
754 |
TInt GetDosEntryFromNameL(const TDesC& aName, TEntryPos& aDosEntryPos, TFatDirEntry& aDosEntry); |
|
755 |
||
756 |
TInt MntCtl_DoCheckFileSystemMountable(); |
|
757 |
||
758 |
||
759 |
private: |
|
760 |
||
761 |
TBool iReadOnly : 1;///< if true, the drive is in read-only mode |
|
762 |
TBool iRamDrive : 1;///< true if this is a RAM drive |
|
763 |
TBool iMainBootSecValid : 1;///< true if the main boot sector is valid, if false, a backup boot sector may be in use. |
|
764 |
||
765 |
TFatMntState iState; ///< this mounnt internal state |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
|
0 | 767 |
TFatType iFatType; ///< FAT type, FAT12,16 or 32 |
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
TUint32 iFatEocCode; ///< End Of Cluster Chain code, 0xff8 for FAT12, 0xfff8 for FAT16, and 0xffffff8 for FAT32 |
0 | 769 |
|
770 |
CLeafDirCache* iLeafDirCache; ///< A cache for most recently visited directories, only valid when limit is set bigger than 1 |
|
771 |
HBufC* iLastLeafDir; ///< The last visited directory, only valid when limit of iLeafDirCache is less than 1 |
|
772 |
TInt iLastLeafDirCluster; ///< Cluster number of the last visited cluster, only valid when limit of iLeafDirCache is less than 1 |
|
773 |
||
774 |
TFatVolParam iVolParam; ///< FAT volume parameters, populated form the boot sector values. |
|
775 |
||
776 |
TInt iFirstFreeByte; ///< First free byte in media (start of the data area on the volume) |
|
777 |
TUint32 iUsableClusters; ///< Number of usable cluster on the volume |
|
778 |
||
779 |
CFatTable* iFatTable; ///< Pointer to the volume Fat |
|
780 |
CRawDisk* iRawDisk; ///< Pointer to the raw data interface class |
|
781 |
||
782 |
CAsyncNotifier* iNotifier; ///< Async notifier for notifying user of Fat error conditions |
|
783 |
||
784 |
XDriveInterface iDriverInterface; ///< the object representing interface to the drive, provides read/write access and notifiers |
|
785 |
TInt iChkDiscRecLevel; ///< Check disk recursion level counter. A temporary measure. |
|
786 |
TFatConfig iFatConfig; ///< FAT parametrers from estart.txt |
|
787 |
||
788 |
XFileCreationHelper iFileCreationHelper; |
|
789 |
||
790 |
||
791 |
#ifdef _DEBUG |
|
792 |
private: |
|
793 |
//-- debug odds and ends |
|
794 |
inline TBool IsWriteFail()const; |
|
795 |
inline void SetWriteFail(TBool aIsWriteFail); |
|
796 |
inline TInt WriteFailCount()const; |
|
797 |
inline void SetWriteFailCount(TInt aFailCount); |
|
798 |
inline void DecWriteFailCount(); |
|
799 |
inline TInt WriteFailError()const; |
|
800 |
inline void SetWriteFailError(TInt aErrorValue); |
|
801 |
||
802 |
||
803 |
TBool iIsWriteFail : 1; ///< Flag to indicate if write failed used for debugging |
|
804 |
TBool iCBRecFlag : 1; ///< in debug mode used for checking unwanted recursion |
|
805 |
||
806 |
TInt iWriteFailCount; ///< Write fail count for debug |
|
807 |
TInt iWriteFailError; ///< Write fail error to use for debug |
|
808 |
||
809 |
#endif |
|
810 |
||
811 |
friend class CFatFormatCB; |
|
812 |
friend class CScanDrive; |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
813 |
friend class TDriveInterface; |
0 | 814 |
}; |
815 |
||
816 |
||
817 |
||
818 |
||
819 |
/** |
|
820 |
Fat file system file subsession implmentation, provides all that is required of a plug in |
|
821 |
file system file as well as Fat specific functionality |
|
822 |
*/ |
|
823 |
class CFatFileCB : public CFileCB, public CFileCB::MBlockMapInterface, public CFileCB::MExtendedFileInterface |
|
824 |
{ |
|
825 |
public: |
|
826 |
CFatFileCB(); |
|
827 |
~CFatFileCB(); |
|
828 |
public: |
|
829 |
void RenameL(const TDesC& aNewName); |
|
830 |
void ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage); |
|
831 |
void WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage); |
|
832 |
void SetSizeL(TInt aSize); |
|
833 |
void SetEntryL(const TTime& aTime,TUint aMask,TUint aVal); |
|
834 |
void FlushDataL(); |
|
835 |
void FlushAllL(); |
|
836 |
public: |
|
837 |
void CheckPosL(TUint aPos); |
|
838 |
void SetL(const TFatDirEntry& aFatDirEntry,TShare aShare,const TEntryPos& aPos); |
|
839 |
void CreateSeekIndex(); |
|
840 |
||
841 |
inline TBool IsSeekIndex() const; |
|
842 |
||
843 |
// from MBlockMapInterface |
|
844 |
TInt BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos); |
|
845 |
||
846 |
// from CFileCB |
|
847 |
virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput); |
|
848 |
||
849 |
// from CFileCB::MExtendedFileInterface |
|
850 |
virtual void ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset); |
|
851 |
virtual void WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset); |
|
852 |
virtual void SetSizeL(TInt64 aSize); |
|
853 |
||
854 |
private: |
|
855 |
inline CFatMountCB& FatMount() const; |
|
856 |
inline CFatTable& FAT(); |
|
857 |
inline TInt ClusterSizeLog2(); |
|
858 |
inline TInt ClusterRelativePos(TInt aPos); |
|
859 |
||
860 |
||
861 |
void FlushStartClusterL(); |
|
862 |
TInt SeekToPosition(TInt aNewCluster,TInt aClusterOffset); |
|
863 |
void SetSeekIndexValueL(TInt aFileCluster,TInt aStoredCluster); |
|
864 |
void ResizeIndex(TInt aNewMult,TUint aNewSize); |
|
865 |
TInt CalcSeekIndexSize(TUint aSize); |
|
866 |
TBool IsSeekBackwards(TUint aPos); |
|
867 |
void ClearIndex(TUint aNewSize); |
|
868 |
void DoSetSizeL(TUint aSize,TBool aIsSizeWrite); |
|
869 |
void WriteFileSizeL(TUint aSize); |
|
870 |
||
871 |
private: |
|
872 |
||
873 |
TUint32* iSeekIndex; ///< Seek index into file |
|
874 |
TInt iSeekIndexSize; ///< size of seek index |
|
875 |
TInt iStartCluster; ///< Start cluster number of file |
|
876 |
TEntryPos iCurrentPos; ///< Current position in file data |
|
877 |
TEntryPos iFileDirPos; ///< File directory entry position |
|
878 |
TBool iFileSizeModified; |
|
879 |
}; |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
880 |
|
0 | 881 |
|
882 |
/** |
|
883 |
Fat file system directory subsession implmentation, provides all that is required of a plug in |
|
884 |
file system directory as well as Fat specific functionality |
|
885 |
*/ |
|
886 |
class CFatDirCB : public CDirCB |
|
887 |
{ |
|
888 |
public: |
|
889 |
static CFatDirCB* NewL(); |
|
890 |
~CFatDirCB(); |
|
891 |
public: |
|
892 |
void ReadL(TEntry& anEntry); |
|
893 |
void StoreLongEntryNameL(const TDesC& aName); |
|
894 |
public: |
|
895 |
void SetDirL(const TFatDirEntry& anEntry,const TDesC& aMatchName); |
|
896 |
inline CFatMountCB& FatMount(); |
|
897 |
private: |
|
898 |
CFatDirCB(); |
|
899 |
private: |
|
900 |
TFatDirEntry iEntry; ///< Current directory entry in this directory |
|
901 |
TEntryPos iCurrentPos; ///< Current position in directory |
|
902 |
HBufC* iMatch; ///< Current name being searched in directory (Dos Name) |
|
903 |
HBufC* iLongNameBuf; ///< Long name storage |
|
904 |
TBool iMatchUid; ///< Flag to indicate if UID matches |
|
905 |
}; |
|
906 |
||
907 |
/** |
|
908 |
Fat file system Format subsession implmentation, provides all that is required of a plug in |
|
909 |
file system format as well as Fat specific functionality |
|
910 |
*/ |
|
911 |
class CFatFormatCB : public CFormatCB |
|
912 |
{ |
|
913 |
public: |
|
914 |
CFatFormatCB(); |
|
915 |
~CFatFormatCB(); |
|
916 |
public: |
|
917 |
||
918 |
//-- overrides from CFormatCB |
|
919 |
void DoFormatStepL(); |
|
920 |
||
921 |
private: |
|
922 |
//-- overrides from CFormatCB |
|
923 |
TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput); |
|
924 |
||
925 |
private: |
|
926 |
||
927 |
TInt DoProcessTVolFormatParam(const TVolFormatParam_FAT* apVolFormatParam); |
|
928 |
||
929 |
void CreateBootSectorL(); |
|
930 |
void CreateFSInfoSectorL(); |
|
931 |
void CreateReservedBootSectorL(); |
|
932 |
void InitializeFormatDataL(); |
|
933 |
void DoZeroFillMediaL(TInt64 aStartPos, TInt64 aEndPos); |
|
934 |
||
935 |
TInt InitFormatDataForVariableSizeDisk(TInt aDiskSizeInSectors); |
|
936 |
TInt InitFormatDataForFixedSizeDiskNormal(TInt aDiskSizeInSectors, const TLocalDriveCapsV6& aCaps); |
|
937 |
TInt InitFormatDataForFixedSizeDiskCustom(const TLDFormatInfo& aFormatInfo); |
|
938 |
TInt InitFormatDataForFixedSizeDiskUser(TInt aDiskSizeInSectors); |
|
939 |
void AdjustClusterSize(TInt aRecommendedSectorsPerCluster); |
|
940 |
TInt AdjustFirstDataSectorAlignment(TInt aBlockSize); |
|
941 |
TInt FirstDataSector() const; |
|
942 |
||
943 |
TInt HandleCorrupt(TInt aError); |
|
944 |
TInt BadSectorToCluster(); |
|
945 |
void TranslateL(); |
|
946 |
TInt DoTranslate(TPtr8& aBuf, RArray<TInt>& aArray); |
|
947 |
void RecordOldInfoL(); |
|
948 |
TInt MaxFat12Sectors() const; |
|
949 |
TInt MaxFat16Sectors() const; |
|
950 |
TUint32 MaxFat32Sectors() const; |
|
951 |
inline TBool Is16BitFat() const; |
|
952 |
inline TBool Is32BitFat() const; |
|
953 |
inline CFatMountCB& FatMount(); |
|
954 |
inline CProxyDrive* LocalDrive(); |
|
955 |
TFatType SuggestFatType() const; |
|
956 |
||
957 |
private: |
|
958 |
||
959 |
TBool iVariableSize; ///< Flag to indicat if we are dealing with a variable size volume |
|
960 |
TInt iBytesPerSector; ///< Byte per sector of media |
|
961 |
TInt iSectorSizeLog2; ///< Sector size in log2 |
|
962 |
TInt iNumberOfFats; ///< Number of Fats the volume will contain |
|
963 |
TInt iReservedSectors; ///< Number of reserved sectors in the volume |
|
964 |
TInt iRootDirEntries; ///< Nummer of root directory entries the root dir will have, specific to Fat12/16 volumes |
|
965 |
TInt iSectorsPerCluster; ///< Sector per cluster ration the volume will be formatted with |
|
966 |
TInt iSectorsPerFat; ///< Number of sectors the Fat uses |
|
967 |
TInt iMaxDiskSectors; ///< number of sectors the volume has |
|
968 |
TFormatInfo iFormatInfo; ///< format information for a custom format |
|
969 |
TBuf8<16> iFileSystemName;///< Buffer to contain the volume name |
|
970 |
TInt iHiddenSectors; ///< Number of hidden sectors in the volume |
|
971 |
TInt iNumberOfHeads; ///< Number of heads the media device has, not used so far as only used on solid state media. |
|
972 |
TInt iSectorsPerTrack; ///< Number of sectors the media device has, not used so far as only used on solid state media. |
|
973 |
TUint32 iRootClusterNum; ///< cluster number used for root directory, Fat32 specific |
|
974 |
TUint32 iCountOfClusters; ///< Count of clusters on the media |
|
975 |
RArray<TInt> iBadClusters; ///< Array of bad cluster numbers |
|
976 |
RArray<TInt> iBadSectors; ///< Array of bad sector numbers |
|
977 |
TBool iDiskCorrupt; ///< Disk is corrupt when format or not |
|
978 |
TInt iOldFirstFreeSector; |
|
979 |
TInt iOldSectorsPerCluster; |
|
980 |
}; |
|
981 |
||
982 |
/** |
|
983 |
Required file system class used by file server to create the file system objects |
|
984 |
*/ |
|
985 |
class CFatFileSystem : public CFileSystem |
|
986 |
{ |
|
987 |
public: |
|
988 |
static CFatFileSystem* New(); |
|
989 |
~CFatFileSystem(); |
|
990 |
public: |
|
991 |
TInt Install(); |
|
992 |
CMountCB* NewMountL() const; |
|
993 |
CFileCB* NewFileL() const; |
|
994 |
CDirCB* NewDirL() const; |
|
995 |
CFormatCB* NewFormatL() const; |
|
996 |
TInt DefaultPath(TDes& aPath) const; |
|
997 |
TBool IsExtensionSupported() const; |
|
998 |
TBool GetUseLocalTime() const; |
|
999 |
void SetUseLocalTime(TBool aFlag); |
|
1000 |
TInt GetInterface(TInt aInterfaceId, TAny*& aInterface,TAny* aInput); |
|
1001 |
protected: |
|
1002 |
CFatFileSystem(); |
|
1003 |
/** |
|
1004 |
If true, then local time will be used when writing timestamps to FS. When reading, |
|
1005 |
timestamps will be assumed local and converted back to UTC. |
|
1006 |
At present, this behaviour will also be conditional upon a particular drive being logically removable. |
|
1007 |
*/ |
|
1008 |
TBool iUseLocalTimeIfRemovable; |
|
1009 |
}; |
|
1010 |
||
1011 |
||
1012 |
||
1013 |
/** |
|
1014 |
Locale utilities allows the file system to call into a specific locale for tasks |
|
1015 |
such as Dos name to unicode conversions and testing the legality of characters for |
|
1016 |
any given locale. |
|
1017 |
*/ |
|
1018 |
class LocaleUtils |
|
1019 |
||
1020 |
{ |
|
1021 |
public: |
|
1022 |
static void ConvertFromUnicodeL(TDes8& aForeign, const TDesC16& aUnicode, TFatUtilityFunctions::TOverflowAction aOverflowAction=TFatUtilityFunctions::EOverflowActionTruncate); |
|
1023 |
static void ConvertToUnicodeL(TDes16& aUnicode, const TDesC8& aForeign, TFatUtilityFunctions::TOverflowAction aOverflowAction=TFatUtilityFunctions::EOverflowActionTruncate); |
|
1024 |
static TBool IsLegalShortNameCharacter(TUint aCharacter,TBool aUseExtendedChars=EFalse); |
|
1025 |
}; |
|
1026 |
// |
|
1027 |
||
1028 |
/** |
|
1029 |
Converts Dos time (from a directory entry) to TTime format |
|
1030 |
||
1031 |
@param aDosTime Dos format time |
|
1032 |
@param aDosDate Dos format Date |
|
1033 |
@return TTime format of Dos time passed in |
|
1034 |
*/ |
|
1035 |
TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate); |
|
1036 |
/** |
|
1037 |
Converts TTime format to Dos time format |
|
1038 |
||
1039 |
@param aTime TTime to convert to Dos time |
|
1040 |
@return Dos time format |
|
1041 |
*/ |
|
1042 |
TInt DosTimeFromTTime(const TTime& aTime); |
|
1043 |
/** |
|
1044 |
Converts TTime format to Dos time format |
|
1045 |
||
1046 |
@param aTime TTime to convert to Dos Date |
|
1047 |
@return Dos Date format |
|
1048 |
*/ |
|
1049 |
TInt DosDateFromTTime(const TTime& aTime); |
|
1050 |
/** |
|
1051 |
Converts Dos Directory entry format to 8.3 format |
|
1052 |
||
1053 |
@param aDosName Directory entry format with space delimeter |
|
1054 |
@return 8.3 Dos filename format |
|
1055 |
*/ |
|
1056 |
TBuf8<12> DosNameToStdFormat(const TDesC8& aDosName); |
|
1057 |
/** |
|
1058 |
Converts 8.3 format to Dos Directory entry format |
|
1059 |
||
1060 |
@param aStdFormatName 8.3 Dos filename format |
|
1061 |
@return Directory entry format with space delimeter |
|
1062 |
*/ |
|
1063 |
TBuf8<12> DosNameFromStdFormat(const TDesC8& aStdFormatName); |
|
1064 |
/** |
|
1065 |
Fault function calls user panic with a fault reason |
|
1066 |
||
1067 |
@param Enumerated fault reason |
|
1068 |
*/ |
|
1069 |
void Fault(TFault aFault); |
|
1070 |
/** |
|
1071 |
calculates the number of VFat directory entries for a given file/directory name length |
|
1072 |
||
1073 |
@param the length in characters of the name |
|
1074 |
@return the number of VFat entries required |
|
1075 |
*/ |
|
1076 |
TInt NumberOfVFatEntries(TInt aNameLength); |
|
1077 |
/** |
|
1078 |
Calculates the check sum for a standard directory entry |
|
1079 |
||
1080 |
@param the Dos name for the directory entry |
|
1081 |
@return the checksum |
|
1082 |
*/ |
|
1083 |
TUint8 CalculateShortNameCheckSum(const TDesC8& aShortName); |
|
1084 |
||
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1085 |
TUint32 EocCodeByFatType(TFatType aFatType); |
0 | 1086 |
|
1087 |
||
1088 |
#include "sl_std.inl" |
|
1089 |
#include "sl_bpb.inl" |
|
1090 |
#include "fat_dir_entry.inl" |
|
1091 |
||
1092 |
#endif //SL_STD_H |