Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfat\fat_config.cpp
15 // Implementation of the class that reads FAT filesystem configuration parameters from the estart.txt file,
16 // caches and provides access to them
24 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
29 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 #include "common_constants.h"
36 #include "fat_config.h"
38 //########################################################################################################################
39 //-- parameters that can be defined in estart.txt file under [Drive%] section
41 //=======================================================================================================================
42 //-- FAT volumes mounting related settings
43 //=======================================================================================================================
45 //-- if this parameter is not 0, ScanDrive will skip finalised volume. Applicable for FAT16/32
46 //-- e.g: FAT_ScanDrv_SkipFinalisedVolume 1
47 _LIT8(KPN_ScanDrvSkipFinalisedVolume,"FAT_ScanDrv_SkipFinalisedVolume"); //-- parameter key name
48 static const TUint32 KDef_ScanDrvSkipFinalisedVolume = 0; //-- parameter default value
50 //-- if this parameter is not 0, enables asynchronous mounting FAT32 volumes.
51 //-- At present it means enabling/disabling FAT32 background scanning for free clusters. Applicable for FAT32 only
52 //-- e.g: FAT_FAT32_AsynchMount=0
53 _LIT8(KPN_FAT32_AsynchMount, "FAT_FAT32_AsynchMount");
54 static const TUint32 KDef_FAT32_AsynchMount = 1;
56 //-- Using FSInfo sector data during FAT32 mount to find out number of free clusters etc.
57 //-- e.g: FAT_FAT32_UseFsInfo=1
58 _LIT8(KPN_FAT32_UseFsInfoOnMount, "FAT_FAT32_UseFsInfo");
59 static const TUint32 KDef_FAT32_UseFsInfoOnMount = 1;
61 //-- Using FAT bit supercache for fast free cluster lookup
62 //-- e.g: FAT_FAT32_UseBitSupercache 0
63 _LIT8(KPN_FAT32_UseFatBitSupercache, "FAT_FAT32_UseBitSupercache");
64 static const TUint32 KDef_FAT32_UseFatBitSupercache = 1;
67 //-- if this parameter is not 0, "clean shutdown mask" bit in FAT16[1] will be used during volume finalisation.
68 //-- Otherwise, FAT16[1] will not be affected during finalisation
69 //-- e.g: KDef_FAT16_UseCleanShutDownBit 0
70 _LIT8(KPN_FAT16_UseCleanShutDownBit,"FAT16_UseCleanShutDownBit"); //-- parameter key name
71 static const TUint32 KDef_FAT16_UseCleanShutDownBit = 1; //-- parameter default value
74 //=======================================================================================================================
75 //-- FAT directory cache settings
76 //=======================================================================================================================
77 //-- FAT_DirCache <CacheSizeKB>,<Log2(max page size)>
78 //-- e.g: FAT_DirCache 16,12
79 _LIT8(KPN_FAT_DirCache, "FAT_DirCache");
81 static const TUint32 KDef_KDirCacheSizeKB = 16; //-- default value for the total directory cache size, kilobytes. 16K by default
82 static const TUint32 KDef_MaxDirCachePageSzLog2 = 12;//-- default value for directory cache single page maximal size Log2, 2^12 (4K) by default
85 //=======================================================================================================================
86 //-- FAT cache settings
87 //=======================================================================================================================
89 //-- Fat16 fixed cache
90 //-- FAT_FAT16FixedCache <Log2(read granularity)>,<Log2(Write granularity)>
91 //-- e.g: FAT_FAT16FixedCache 12,9
92 _LIT8(KPN_FAT_FAT16FixedCache, "FAT_FAT16FixedCache");
93 static const TUint32 KDef_FAT16_FixedCache_Read_Granularity_LOG2 = 12; //-- read granularity Log2, 4K
94 static const TUint32 KDef_FAT16_FixedCache_Write_Granularity_LOG2 = 9; //-- write granularity Log2, 512 bytes
98 //-- FAT_FAT32LruCache <Size KB>,<Log2(read granularity)>,<Log2(Write granularity)>
99 //-- e.g: FAT_FAT32LruCache 128,12,9
100 _LIT8(KPN_FAT_FAT32LruCache, "FAT_FAT32LruCache");
103 static const TUint32 KDef_FAT32_LruCache_SizeKB = 128; //-- LRU cache size, 128KB
104 static const TUint32 KDef_FAT32_LruCache_Read_Granularity_LOG2 = 12; //-- read granularity Log2, 4K
105 static const TUint32 KDef_FAT32_LruCache_Write_Granularity_LOG2 = 9; //-- write granularity Log2, 512 bytes
108 //=======================================================================================================================
109 //-- FAT leaf directory cache settings
110 //=======================================================================================================================
111 //-- A leaf directory cache for Fat volumes
112 _LIT8(KPN_FAT_LeafDirCache, "FAT_LeafDirCacheSize");
113 static const TUint32 KDef_KLeafDirCacheSize = 1; //-- default number of the most recently visited leaf dirs to be cached
115 //=======================================================================================================================
116 //-- New directory cache settings
117 //=======================================================================================================================
118 //-- New directory cache uses the global cache memory manager for dynamic size allocation
119 _LIT8(KPN_FAT_DynamicDirCacheMin, "FAT_DirCacheSizeMin");
120 _LIT8(KPN_FAT_DynamicDirCacheMax, "FAT_DirCacheSizeMax");
121 static const TUint32 KDef_DynamicDirCacheMin = 128; // default minimum fat dir cache size in KB
122 static const TUint32 KDef_DynamicDirCacheMax = 128; // default maximum fat dir cache size in KB
123 //-- default value for directory cache single page maximal size Log2, 2^14 (16K) by default
124 static const TUint32 KDef_MaxDynamicDirCachePageSzLog2 = 14;
133 //########################################################################################################################
137 //-----------------------------------------------------------------------------
139 Extract a token from the comma-separated tokens string.
141 @param aSrc source string descriptor
142 @param aTokenNo token number to extract (the 1st token is number 0)
143 @param aToken on success there will be extracted token
145 @return ETrue on success and an extracted token in aToken
147 static TBool GetCSV_Token(const TDesC8& aSrc, TUint aTokenNo, TPtrC8& aToken)
150 const TChar chDelim = ','; //-- token delimiter, comma
153 //-- 1. find the beginning of the token we are looking for
154 TPtrC8 ptrCurrToken(aSrc);
155 for(TUint i=0; i<aTokenNo; ++i)
157 const TInt len = ptrCurrToken.Length();
159 nRes = ptrCurrToken.Locate(chDelim);
160 if(nRes == KErrNotFound)
161 return EFalse; //-- did tot find the required token
163 ptrCurrToken.Set(ptrCurrToken.Right(len-nRes-1));
166 //-- 2. set the end position of the token we found
167 aToken.Set(ptrCurrToken);
169 nRes = ptrCurrToken.Locate(chDelim);
170 if(nRes != KErrNotFound)
172 aToken.Set(ptrCurrToken.Left(nRes));
179 //-----------------------------------------------------------------------------
181 Extract a token from the comma-separated tokens string and try to convert it into TInt
183 @param aSrc source string descriptor
184 @param aTokenNo token number to extract (the 1st token is number 0)
185 @param aVal On success will contain the value represented by the token
187 @return ETrue if the token is extracted and converted to TInt OK, in this case aVal contains value
189 static TBool GetIntTokenVal(const TDesC8& aSrc, TUint aTokenNo, TInt& aVal)
195 if(!GetCSV_Token(aSrc, aTokenNo, ptrToken))
198 lex.Assign(ptrToken);
201 if(lex.Val(val) != KErrNone)
208 static TBool GetIntTokenVal(const TDesC8& aSrc, TUint aTokenNo, TUint16& aVal)
211 if(!GetIntTokenVal(aSrc, aTokenNo, val))
219 //-----------------------------------------------------------------------------
220 TFatConfig::TFatConfig()
222 iInitialised = EFalse;
225 //-----------------------------------------------------------------------------
228 reads FAT parameters from estart.txt file.
229 @param aDrvNumber a valid drive number
230 @param aForceRead if ETrue parameters will be forcedly re-read.
232 void TFatConfig::ReadConfig(TInt aDrvNumber, TBool aForceRead /*=EFalse*/)
235 iInitialised = EFalse;
240 //__PRINT1(_L("#>- TFatConfig::ReadConfig() drive:%d\n"),aDrvNumber);
241 ASSERT(aDrvNumber >= EDriveA && aDrvNumber <= EDriveZ);
243 //-- make a section name, like "DriveX"
245 section.Format(_L8("Drive%c"), 'A'+aDrvNumber);
247 //-- read values from estart.txt and cache them
248 iScanDrvSkipFinalisedVolume = ReadUint(section, KPN_ScanDrvSkipFinalisedVolume, KDef_ScanDrvSkipFinalisedVolume);
249 iFAT32_AsynchMount = ReadUint(section, KPN_FAT32_AsynchMount, KDef_FAT32_AsynchMount);
250 iFAT32_UseFSInfoOnMount = ReadUint(section, KPN_FAT32_UseFsInfoOnMount, KDef_FAT32_UseFsInfoOnMount);
251 iFAT32_UseBitSupercache = ReadUint(section, KPN_FAT32_UseFatBitSupercache, KDef_FAT32_UseFatBitSupercache);
252 iFAT16_UseCleanShutDownBit = ReadUint(section, KPN_FAT16_UseCleanShutDownBit, KDef_FAT16_UseCleanShutDownBit);
254 // If leaf dir cache is supported, read the configuration from estart.txt file
255 iLeafDirCacheSize = ReadUint(section, KPN_FAT_LeafDirCache, KDef_KLeafDirCacheSize);
256 ProcessDynamicDirCacheParams(section); //-- read dynamic dir cache parameters;
258 ProcessDirCacheParams(section); //-- read FAT directory cache parameters
259 ProcessFatCacheParams(section); //-- read FAT cache parameters
261 iInitialised = ETrue;
263 DumpParameters(); //-- print out parameters in debug mode
267 //-----------------------------------------------------------------------------
269 process dynamic directory cache parameters
270 @param aSection section name, like "DriveX"
272 void TFatConfig::ProcessDynamicDirCacheParams(const TDesC8& aSection)
274 // we have to process the data in this file as the default values are all static variables, which means
275 // their scope is limited within this file only.
276 iDynamicDirCacheMaxPageSizeLog2 = KDef_MaxDynamicDirCachePageSzLog2;
277 iDynamicDirCacheSizeMinKB = ReadUint(aSection, KPN_FAT_DynamicDirCacheMin, KDef_DynamicDirCacheMin);
278 iDynamicDirCacheSizeMaxKB = ReadUint(aSection, KPN_FAT_DynamicDirCacheMax, KDef_DynamicDirCacheMax);
280 // if less than default values, set to default values
281 if (iDynamicDirCacheSizeMinKB < KDef_DynamicDirCacheMin)
282 iDynamicDirCacheSizeMinKB = KDef_DynamicDirCacheMin;
283 if (iDynamicDirCacheSizeMaxKB < KDef_DynamicDirCacheMax)
284 iDynamicDirCacheSizeMaxKB = KDef_DynamicDirCacheMax;
286 // validate settings for those values that the default values does not apply onto them
287 __ASSERT_ALWAYS(iDynamicDirCacheSizeMinKB <= iDynamicDirCacheSizeMaxKB, Fault(EFatBadParameter));
291 process directory cache parameters
292 @param aSection section name, like "DriveX"
294 void TFatConfig::ProcessDirCacheParams(const TDesC8& aSection)
298 //-- set default values.
299 iDirCacheSizeKB = KDef_KDirCacheSizeKB;
300 iDirCacheMaxPageSizeLog2 = KDef_MaxDirCachePageSzLog2;
302 //-- read a string containing DirCache parameters
303 //-- it looks like this: FAT_DirCache cacheSzKB, maxPageSzBytes
304 if(!F32Properties::GetString(aSection, KPN_FAT_DirCache, buf))
307 GetIntTokenVal(buf, 0, iDirCacheSizeKB); //-- 1. extract directory cache size in KB. this is token 0
308 GetIntTokenVal(buf, 1, iDirCacheMaxPageSizeLog2); //-- 2. extract directory cache max page size in bytes Log2. this is token 1
311 //-----------------------------------------------------------------------------
313 process fat cache parameters
314 @param aSection section name, like "DriveX"
316 void TFatConfig::ProcessFatCacheParams(const TDesC8& aSection)
319 //-- set default values.
320 iFat16FixedCacheReadGrLog2 = KDef_FAT16_FixedCache_Read_Granularity_LOG2;
321 iFat16FixedCacheWriteGrLog2 = KDef_FAT16_FixedCache_Write_Granularity_LOG2;
323 iFat32LRUCacheSizeKB = KDef_FAT32_LruCache_SizeKB;
324 iFat32LRUCacheReadGrLog2 = KDef_FAT32_LruCache_Read_Granularity_LOG2;
325 iFat32LRUCacheWriteGrLog2 = KDef_FAT32_LruCache_Write_Granularity_LOG2;
327 //-- read a string containing FAT16 fixed cache parameters
328 if(F32Properties::GetString(aSection, KPN_FAT_FAT16FixedCache, buf))
330 GetIntTokenVal(buf, 0, iFat16FixedCacheReadGrLog2); //-- 1. extract Log2(FAT16 fixed cache read granularity)
331 GetIntTokenVal(buf, 1, iFat16FixedCacheWriteGrLog2); //-- 2. extract Log2(FAT16 fixed cache write granularity)
334 //-- read a string containing FAT32 LRU cache parameters
335 if(F32Properties::GetString(aSection, KPN_FAT_FAT32LruCache, buf))
337 GetIntTokenVal(buf, 0, iFat32LRUCacheSizeKB); //-- 1. extract FAT32 LRU cache size, Kbytes
338 GetIntTokenVal(buf, 1, iFat32LRUCacheReadGrLog2); //-- 2. extract Log2(FAT32 LRU cache read granularity)
339 GetIntTokenVal(buf, 2, iFat32LRUCacheWriteGrLog2); //-- 3. extract Log2(FAT32 LRU cache write granularity)
344 //-----------------------------------------------------------------------------
346 Just a helper method. Reads TUint32 value from the estart.txt
348 @param aSection section name, e.g. [DriveD]
349 @param aKeyName Key name
350 @param aDefaultValue Default value to return in parameter isn't found
351 @return a value from config file or default aDefaultValue
353 TUint32 TFatConfig::ReadUint(const TDesC8& aSection, const TDesC8& aKeyName, TUint32 aDefaultValue) const
355 TInt32 val = aDefaultValue;
356 // coverity[check_return] coverity[unchecked_value]
357 F32Properties::GetInt(aSection, aKeyName, val);
362 //-----------------------------------------------------------------------------
363 /** Debug method, prints out the parameters*/
364 void TFatConfig::DumpParameters() const
368 ASSERT(iInitialised);
369 __PRINT(_L("#>- TFatConfig parameters:\n"));
371 DoDumpUintParam(KPN_ScanDrvSkipFinalisedVolume, iScanDrvSkipFinalisedVolume);
372 DoDumpUintParam(KPN_FAT32_AsynchMount, iFAT32_AsynchMount);
373 DoDumpUintParam(KPN_FAT32_UseFsInfoOnMount, iFAT32_UseFSInfoOnMount);
374 DoDumpUintParam(KPN_FAT32_UseFatBitSupercache, iFAT32_UseBitSupercache);
375 DoDumpUintParam(KPN_FAT16_UseCleanShutDownBit, iFAT16_UseCleanShutDownBit);
377 DoDumpUintParam(_L8("FAT_DirCache Size, KB"), iDirCacheSizeKB);
378 DoDumpUintParam(_L8("FAT_DirCache MaxPage Size Log2"), iDirCacheMaxPageSizeLog2);
380 DoDumpUintParam(_L8("FAT_16Cache RdGr Log2"), iFat16FixedCacheReadGrLog2);
381 DoDumpUintParam(_L8("FAT_16Cache WrGr Log2"), iFat16FixedCacheWriteGrLog2);
383 DoDumpUintParam(_L8("FAT_32Cache Size, KB"), iFat32LRUCacheSizeKB);
384 DoDumpUintParam(_L8("FAT_32Cache RdGr Log2"), iFat32LRUCacheReadGrLog2);
385 DoDumpUintParam(_L8("FAT_32Cache WrGr Log2"), iFat32LRUCacheWriteGrLog2);
387 __PRINT(_L("#>------ end -------<#\n\n"));
392 void TFatConfig::DoDumpUintParam(const TDesC8& aKeyName, TUint32 aParam) const
398 buf.Insert(0,_L("#>- "));
399 buf.AppendFormat(_L(": %d"), aParam);
402 (void)aKeyName; (void)aParam; //-- get rid of warning