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