1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/fat_config.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,423 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32\sfat\fat_config.cpp
1.18 +// Implementation of the class that reads FAT filesystem configuration parameters from the estart.txt file,
1.19 +// caches and provides access to them
1.20 +//
1.21 +//
1.22 +
1.23 +/**
1.24 + @file
1.25 +*/
1.26 +
1.27 +#include <f32fsys.h>
1.28 +
1.29 +#include "common_constants.h"
1.30 +#include "sl_std.h"
1.31 +#include "fat_config.h"
1.32 +
1.33 +//########################################################################################################################
1.34 +//-- parameters that can be defined in estart.txt file under [Drive%] section
1.35 +
1.36 +//=======================================================================================================================
1.37 +//-- FAT volumes mounting related settings
1.38 +//=======================================================================================================================
1.39 +
1.40 +//-- if this parameter is not 0, ScanDrive will skip finalised volume. Applicable for FAT16/32
1.41 +//-- e.g: FAT_ScanDrv_SkipFinalisedVolume 1
1.42 +_LIT8(KPN_ScanDrvSkipFinalisedVolume,"FAT_ScanDrv_SkipFinalisedVolume"); //-- parameter key name
1.43 +static const TUint32 KDef_ScanDrvSkipFinalisedVolume = 0; //-- parameter default value
1.44 +
1.45 +//-- if this parameter is not 0, enables asynchronous mounting FAT32 volumes.
1.46 +//-- At present it means enabling/disabling FAT32 background scanning for free clusters. Applicable for FAT32 only
1.47 +//-- e.g: FAT_FAT32_AsynchMount=0
1.48 +_LIT8(KPN_FAT32_AsynchMount, "FAT_FAT32_AsynchMount");
1.49 +static const TUint32 KDef_FAT32_AsynchMount = 1;
1.50 +
1.51 +//-- Using FSInfo sector data during FAT32 mount to find out number of free clusters etc.
1.52 +//-- e.g: FAT_FAT32_UseFsInfo=1
1.53 +_LIT8(KPN_FAT32_UseFsInfoOnMount, "FAT_FAT32_UseFsInfo");
1.54 +static const TUint32 KDef_FAT32_UseFsInfoOnMount = 1;
1.55 +
1.56 +//-- Using FAT bit supercache for fast free cluster lookup
1.57 +//-- e.g: FAT_FAT32_UseBitSupercache 0
1.58 +_LIT8(KPN_FAT32_UseFatBitSupercache, "FAT_FAT32_UseBitSupercache");
1.59 +static const TUint32 KDef_FAT32_UseFatBitSupercache = 1;
1.60 +
1.61 +
1.62 +//-- if this parameter is not 0, "clean shutdown mask" bit in FAT16[1] will be used during volume finalisation.
1.63 +//-- Otherwise, FAT16[1] will not be affected during finalisation
1.64 +//-- e.g: KDef_FAT16_UseCleanShutDownBit 0
1.65 +_LIT8(KPN_FAT16_UseCleanShutDownBit,"FAT16_UseCleanShutDownBit"); //-- parameter key name
1.66 +static const TUint32 KDef_FAT16_UseCleanShutDownBit = 1; //-- parameter default value
1.67 +
1.68 +
1.69 +//=======================================================================================================================
1.70 +//-- FAT directory cache settings
1.71 +//=======================================================================================================================
1.72 +//-- FAT_DirCache <CacheSizeKB>,<Log2(max page size)>
1.73 +//-- e.g: FAT_DirCache 16,12
1.74 +_LIT8(KPN_FAT_DirCache, "FAT_DirCache");
1.75 +
1.76 +static const TUint32 KDef_KDirCacheSizeKB = 16; //-- default value for the total directory cache size, kilobytes. 16K by default
1.77 +static const TUint32 KDef_MaxDirCachePageSzLog2 = 12;//-- default value for directory cache single page maximal size Log2, 2^12 (4K) by default
1.78 +
1.79 +
1.80 +//=======================================================================================================================
1.81 +//-- FAT cache settings
1.82 +//=======================================================================================================================
1.83 +
1.84 +//-- Fat16 fixed cache
1.85 +//-- FAT_FAT16FixedCache <Log2(read granularity)>,<Log2(Write granularity)>
1.86 +//-- e.g: FAT_FAT16FixedCache 12,9
1.87 +_LIT8(KPN_FAT_FAT16FixedCache, "FAT_FAT16FixedCache");
1.88 +static const TUint32 KDef_FAT16_FixedCache_Read_Granularity_LOG2 = 12; //-- read granularity Log2, 4K
1.89 +static const TUint32 KDef_FAT16_FixedCache_Write_Granularity_LOG2 = 9; //-- write granularity Log2, 512 bytes
1.90 +
1.91 +
1.92 +//-- Fat32 LRU cache
1.93 +//-- FAT_FAT32LruCache <Size KB>,<Log2(read granularity)>,<Log2(Write granularity)>
1.94 +//-- e.g: FAT_FAT32LruCache 128,12,9
1.95 +_LIT8(KPN_FAT_FAT32LruCache, "FAT_FAT32LruCache");
1.96 +
1.97 +
1.98 +static const TUint32 KDef_FAT32_LruCache_SizeKB = 128; //-- LRU cache size, 128KB
1.99 +static const TUint32 KDef_FAT32_LruCache_Read_Granularity_LOG2 = 12; //-- read granularity Log2, 4K
1.100 +static const TUint32 KDef_FAT32_LruCache_Write_Granularity_LOG2 = 9; //-- write granularity Log2, 512 bytes
1.101 +
1.102 +
1.103 +//=======================================================================================================================
1.104 +//-- FAT leaf directory cache settings
1.105 +//=======================================================================================================================
1.106 +//-- A leaf directory cache for Fat volumes
1.107 +_LIT8(KPN_FAT_LeafDirCache, "FAT_LeafDirCacheSize");
1.108 +static const TUint32 KDef_KLeafDirCacheSize = 1; //-- default number of the most recently visited leaf dirs to be cached
1.109 +
1.110 +//=======================================================================================================================
1.111 +//-- New directory cache settings
1.112 +//=======================================================================================================================
1.113 +//-- New directory cache uses the global cache memory manager for dynamic size allocation
1.114 +_LIT8(KPN_FAT_DynamicDirCacheMin, "FAT_DirCacheSizeMin");
1.115 +_LIT8(KPN_FAT_DynamicDirCacheMax, "FAT_DirCacheSizeMax");
1.116 +static const TUint32 KDef_DynamicDirCacheMin = 128; // default minimum fat dir cache size in KB
1.117 +static const TUint32 KDef_DynamicDirCacheMax = 256; // default maximum fat dir cache size in KB
1.118 +static const TUint32 KDef_MaxDynamicDirCachePageSzLog2 = 14; // default value for directory cache single page
1.119 + // maximal size Log2, 2^14 (16K) by default
1.120 +
1.121 +
1.122 +
1.123 +
1.124 +
1.125 +
1.126 +
1.127 +
1.128 +//########################################################################################################################
1.129 +
1.130 +
1.131 +
1.132 +//-----------------------------------------------------------------------------
1.133 +/**
1.134 + Extract a token from the comma-separated tokens string.
1.135 +
1.136 + @param aSrc source string descriptor
1.137 + @param aTokenNo token number to extract (the 1st token is number 0)
1.138 + @param aToken on success there will be extracted token
1.139 +
1.140 + @return ETrue on success and an extracted token in aToken
1.141 +*/
1.142 +static TBool GetCSV_Token(const TDesC8& aSrc, TUint aTokenNo, TPtrC8& aToken)
1.143 + {
1.144 +
1.145 + const TChar chDelim = ','; //-- token delimiter, comma
1.146 + TInt nRes;
1.147 +
1.148 + //-- 1. find the beginning of the token we are looking for
1.149 + TPtrC8 ptrCurrToken(aSrc);
1.150 + for(TUint i=0; i<aTokenNo; ++i)
1.151 + {
1.152 + const TInt len = ptrCurrToken.Length();
1.153 +
1.154 + nRes = ptrCurrToken.Locate(chDelim);
1.155 + if(nRes == KErrNotFound)
1.156 + return EFalse; //-- did tot find the required token
1.157 +
1.158 + ptrCurrToken.Set(ptrCurrToken.Right(len-nRes-1));
1.159 + }
1.160 +
1.161 + //-- 2. set the end position of the token we found
1.162 + aToken.Set(ptrCurrToken);
1.163 +
1.164 + nRes = ptrCurrToken.Locate(chDelim);
1.165 + if(nRes != KErrNotFound)
1.166 + {
1.167 + aToken.Set(ptrCurrToken.Left(nRes));
1.168 + }
1.169 +
1.170 + return ETrue;
1.171 + }
1.172 +
1.173 +
1.174 +//-----------------------------------------------------------------------------
1.175 +/**
1.176 + Extract a token from the comma-separated tokens string and try to convert it into TInt
1.177 +
1.178 + @param aSrc source string descriptor
1.179 + @param aTokenNo token number to extract (the 1st token is number 0)
1.180 + @param aVal On success will contain the value represented by the token
1.181 +
1.182 + @return ETrue if the token is extracted and converted to TInt OK, in this case aVal contains value
1.183 +*/
1.184 +static TBool GetIntTokenVal(const TDesC8& aSrc, TUint aTokenNo, TInt& aVal)
1.185 +{
1.186 + TPtrC8 ptrToken;
1.187 + TLex8 lex;
1.188 + TInt val;
1.189 +
1.190 + if(!GetCSV_Token(aSrc, aTokenNo, ptrToken))
1.191 + return EFalse;
1.192 +
1.193 + lex.Assign(ptrToken);
1.194 + lex.SkipSpace();
1.195 +
1.196 + if(lex.Val(val) != KErrNone)
1.197 + return EFalse;
1.198 +
1.199 + aVal = val;
1.200 + return ETrue;
1.201 +}
1.202 +
1.203 +static TBool GetIntTokenVal(const TDesC8& aSrc, TUint aTokenNo, TUint16& aVal)
1.204 +{
1.205 + TInt val;
1.206 + if(!GetIntTokenVal(aSrc, aTokenNo, val))
1.207 + return EFalse;
1.208 +
1.209 + aVal = (TUint16)val;
1.210 + return ETrue;
1.211 +}
1.212 +
1.213 +
1.214 +//-----------------------------------------------------------------------------
1.215 +TFatConfig::TFatConfig()
1.216 + {
1.217 + iInitialised = EFalse;
1.218 + }
1.219 +
1.220 +//-----------------------------------------------------------------------------
1.221 +
1.222 +/**
1.223 + reads FAT parameters from estart.txt file.
1.224 + @param aDrvNumber a valid drive number
1.225 + @param aForceRead if ETrue parameters will be forcedly re-read.
1.226 +*/
1.227 +void TFatConfig::ReadConfig(TInt aDrvNumber, TBool aForceRead /*=EFalse*/)
1.228 + {
1.229 + if(aForceRead)
1.230 + iInitialised = EFalse;
1.231 +
1.232 + if(iInitialised)
1.233 + return;
1.234 +
1.235 + //__PRINT1(_L("#>- TFatConfig::ReadConfig() drive:%d\n"),aDrvNumber);
1.236 + ASSERT(aDrvNumber >= EDriveA && aDrvNumber <= EDriveZ);
1.237 +
1.238 + //-- make a section name, like "DriveX"
1.239 + TBuf8<32> section;
1.240 + section.Format(_L8("Drive%c"), 'A'+aDrvNumber);
1.241 +
1.242 + //-- read values from estart.txt and cache them
1.243 + iScanDrvSkipFinalisedVolume = ReadUint(section, KPN_ScanDrvSkipFinalisedVolume, KDef_ScanDrvSkipFinalisedVolume);
1.244 + iFAT32_AsynchMount = ReadUint(section, KPN_FAT32_AsynchMount, KDef_FAT32_AsynchMount);
1.245 + iFAT32_UseFSInfoOnMount = ReadUint(section, KPN_FAT32_UseFsInfoOnMount, KDef_FAT32_UseFsInfoOnMount);
1.246 + iFAT32_UseBitSupercache = ReadUint(section, KPN_FAT32_UseFatBitSupercache, KDef_FAT32_UseFatBitSupercache);
1.247 + iFAT16_UseCleanShutDownBit = ReadUint(section, KPN_FAT16_UseCleanShutDownBit, KDef_FAT16_UseCleanShutDownBit);
1.248 +
1.249 + // If leaf dir cache is supported, read the configuration from estart.txt file
1.250 + iLeafDirCacheSize = ReadUint(section, KPN_FAT_LeafDirCache, KDef_KLeafDirCacheSize);
1.251 + ProcessDynamicDirCacheParams(section); //-- read dynamic dir cache parameters;
1.252 +
1.253 + ProcessDirCacheParams(section); //-- read FAT directory cache parameters
1.254 + ProcessFatCacheParams(section); //-- read FAT cache parameters
1.255 +
1.256 + iInitialised = ETrue;
1.257 +
1.258 + DumpParameters(); //-- print out parameters in debug mode
1.259 + }
1.260 +
1.261 +
1.262 +//-----------------------------------------------------------------------------
1.263 +/**
1.264 + process dynamic directory cache parameters
1.265 + @param aSection section name, like "DriveX"
1.266 +*/
1.267 +void TFatConfig::ProcessDynamicDirCacheParams(const TDesC8& aSection)
1.268 + {
1.269 + // we have to process the data in this file as the default values are all static variables, which means
1.270 + // their scope is limited within this file only.
1.271 + iDynamicDirCacheMaxPageSizeLog2 = KDef_MaxDynamicDirCachePageSzLog2;
1.272 + iDynamicDirCacheSizeMinKB = ReadUint(aSection, KPN_FAT_DynamicDirCacheMin, KDef_DynamicDirCacheMin);
1.273 + iDynamicDirCacheSizeMaxKB = ReadUint(aSection, KPN_FAT_DynamicDirCacheMax, KDef_DynamicDirCacheMax);
1.274 +
1.275 + // if less than default values, set to default values
1.276 + if (iDynamicDirCacheSizeMinKB < KDef_DynamicDirCacheMin)
1.277 + iDynamicDirCacheSizeMinKB = KDef_DynamicDirCacheMin;
1.278 + if (iDynamicDirCacheSizeMaxKB < KDef_DynamicDirCacheMax)
1.279 + iDynamicDirCacheSizeMaxKB = KDef_DynamicDirCacheMax;
1.280 +
1.281 + // validate settings for those values that the default values does not apply onto them
1.282 + __ASSERT_ALWAYS(iDynamicDirCacheSizeMinKB <= iDynamicDirCacheSizeMaxKB, Fault(EFatBadParameter));
1.283 + }
1.284 +
1.285 +/**
1.286 + process directory cache parameters
1.287 + @param aSection section name, like "DriveX"
1.288 +*/
1.289 +void TFatConfig::ProcessDirCacheParams(const TDesC8& aSection)
1.290 + {
1.291 + TBuf8<128> buf;
1.292 +
1.293 + //-- set default values.
1.294 + iDirCacheSizeKB = KDef_KDirCacheSizeKB;
1.295 + iDirCacheMaxPageSizeLog2 = KDef_MaxDirCachePageSzLog2;
1.296 +
1.297 + //-- read a string containing DirCache parameters
1.298 + //-- it looks like this: FAT_DirCache cacheSzKB, maxPageSzBytes
1.299 + if(!F32Properties::GetString(aSection, KPN_FAT_DirCache, buf))
1.300 + return;
1.301 +
1.302 + GetIntTokenVal(buf, 0, iDirCacheSizeKB); //-- 1. extract directory cache size in KB. this is token 0
1.303 + GetIntTokenVal(buf, 1, iDirCacheMaxPageSizeLog2); //-- 2. extract directory cache max page size in bytes Log2. this is token 1
1.304 + }
1.305 +
1.306 +//-----------------------------------------------------------------------------
1.307 +/**
1.308 + process fat cache parameters
1.309 + @param aSection section name, like "DriveX"
1.310 +*/
1.311 +void TFatConfig::ProcessFatCacheParams(const TDesC8& aSection)
1.312 +{
1.313 + TBuf8<128> buf;
1.314 + //-- set default values.
1.315 + iFat16FixedCacheReadGrLog2 = KDef_FAT16_FixedCache_Read_Granularity_LOG2;
1.316 + iFat16FixedCacheWriteGrLog2 = KDef_FAT16_FixedCache_Write_Granularity_LOG2;
1.317 +
1.318 + iFat32LRUCacheSizeKB = KDef_FAT32_LruCache_SizeKB;
1.319 + iFat32LRUCacheReadGrLog2 = KDef_FAT32_LruCache_Read_Granularity_LOG2;
1.320 + iFat32LRUCacheWriteGrLog2 = KDef_FAT32_LruCache_Write_Granularity_LOG2;
1.321 +
1.322 + //-- read a string containing FAT16 fixed cache parameters
1.323 + if(F32Properties::GetString(aSection, KPN_FAT_FAT16FixedCache, buf))
1.324 + {
1.325 + GetIntTokenVal(buf, 0, iFat16FixedCacheReadGrLog2); //-- 1. extract Log2(FAT16 fixed cache read granularity)
1.326 + GetIntTokenVal(buf, 1, iFat16FixedCacheWriteGrLog2); //-- 2. extract Log2(FAT16 fixed cache write granularity)
1.327 + }
1.328 +
1.329 + //-- read a string containing FAT32 LRU cache parameters
1.330 + if(F32Properties::GetString(aSection, KPN_FAT_FAT32LruCache, buf))
1.331 + {
1.332 + GetIntTokenVal(buf, 0, iFat32LRUCacheSizeKB); //-- 1. extract FAT32 LRU cache size, Kbytes
1.333 + GetIntTokenVal(buf, 1, iFat32LRUCacheReadGrLog2); //-- 2. extract Log2(FAT32 LRU cache read granularity)
1.334 + GetIntTokenVal(buf, 2, iFat32LRUCacheWriteGrLog2); //-- 3. extract Log2(FAT32 LRU cache write granularity)
1.335 + }
1.336 +}
1.337 +
1.338 +
1.339 +//-----------------------------------------------------------------------------
1.340 +/**
1.341 + Just a helper method. Reads TUint32 value from the estart.txt
1.342 +
1.343 + @param aSection section name, e.g. [DriveD]
1.344 + @param aKeyName Key name
1.345 + @param aDefaultValue Default value to return in parameter isn't found
1.346 + @return a value from config file or default aDefaultValue
1.347 +*/
1.348 +TUint32 TFatConfig::ReadUint(const TDesC8& aSection, const TDesC8& aKeyName, TUint32 aDefaultValue) const
1.349 + {
1.350 + TInt32 val = aDefaultValue;
1.351 + // coverity[check_return] coverity[unchecked_value]
1.352 + F32Properties::GetInt(aSection, aKeyName, val);
1.353 +
1.354 + return val;
1.355 + }
1.356 +
1.357 +//-----------------------------------------------------------------------------
1.358 +/** Debug method, prints out the parameters*/
1.359 +void TFatConfig::DumpParameters() const
1.360 + {
1.361 +#ifdef _DEBUG
1.362 +
1.363 + ASSERT(iInitialised);
1.364 + __PRINT(_L("#>- TFatConfig parameters:\n"));
1.365 +
1.366 + DoDumpUintParam(KPN_ScanDrvSkipFinalisedVolume, iScanDrvSkipFinalisedVolume);
1.367 + DoDumpUintParam(KPN_FAT32_AsynchMount, iFAT32_AsynchMount);
1.368 + DoDumpUintParam(KPN_FAT32_UseFsInfoOnMount, iFAT32_UseFSInfoOnMount);
1.369 + DoDumpUintParam(KPN_FAT32_UseFatBitSupercache, iFAT32_UseBitSupercache);
1.370 + DoDumpUintParam(KPN_FAT16_UseCleanShutDownBit, iFAT16_UseCleanShutDownBit);
1.371 +
1.372 + DoDumpUintParam(_L8("FAT_DirCache Size, KB"), iDirCacheSizeKB);
1.373 + DoDumpUintParam(_L8("FAT_DirCache MaxPage Size Log2"), iDirCacheMaxPageSizeLog2);
1.374 +
1.375 + DoDumpUintParam(_L8("FAT_16Cache RdGr Log2"), iFat16FixedCacheReadGrLog2);
1.376 + DoDumpUintParam(_L8("FAT_16Cache WrGr Log2"), iFat16FixedCacheWriteGrLog2);
1.377 +
1.378 + DoDumpUintParam(_L8("FAT_32Cache Size, KB"), iFat32LRUCacheSizeKB);
1.379 + DoDumpUintParam(_L8("FAT_32Cache RdGr Log2"), iFat32LRUCacheReadGrLog2);
1.380 + DoDumpUintParam(_L8("FAT_32Cache WrGr Log2"), iFat32LRUCacheWriteGrLog2);
1.381 +
1.382 + __PRINT(_L("#>------ end -------<#\n\n"));
1.383 +
1.384 +#endif
1.385 + }
1.386 +
1.387 +void TFatConfig::DoDumpUintParam(const TDesC8& aKeyName, TUint32 aParam) const
1.388 + {
1.389 +#ifdef _DEBUG
1.390 + TBuf<100> buf;
1.391 +
1.392 + buf.Copy(aKeyName);
1.393 + buf.Insert(0,_L("#>- "));
1.394 + buf.AppendFormat(_L(": %d"), aParam);
1.395 + __PRINT(buf);
1.396 +#else
1.397 + (void)aKeyName; (void)aParam; //-- get rid of warning
1.398 +
1.399 +#endif
1.400 + }
1.401 +
1.402 +
1.403 +
1.404 +
1.405 +
1.406 +
1.407 +
1.408 +
1.409 +
1.410 +
1.411 +
1.412 +
1.413 +
1.414 +
1.415 +
1.416 +
1.417 +
1.418 +
1.419 +
1.420 +
1.421 +
1.422 +
1.423 +
1.424 +
1.425 +
1.426 +