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