sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32\sfat\fat_config.cpp sl@0: // Implementation of the class that reads FAT filesystem configuration parameters from the estart.txt file, sl@0: // caches and provides access to them sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!! sl@0: //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it sl@0: //!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: sl@0: #include sl@0: sl@0: #include "common_constants.h" sl@0: #include "sl_std.h" sl@0: #include "fat_config.h" sl@0: sl@0: //######################################################################################################################## sl@0: //-- parameters that can be defined in estart.txt file under [Drive%] section sl@0: sl@0: //======================================================================================================================= sl@0: //-- FAT volumes mounting related settings sl@0: //======================================================================================================================= sl@0: sl@0: //-- if this parameter is not 0, ScanDrive will skip finalised volume. Applicable for FAT16/32 sl@0: //-- e.g: FAT_ScanDrv_SkipFinalisedVolume 1 sl@0: _LIT8(KPN_ScanDrvSkipFinalisedVolume,"FAT_ScanDrv_SkipFinalisedVolume"); //-- parameter key name sl@0: static const TUint32 KDef_ScanDrvSkipFinalisedVolume = 0; //-- parameter default value sl@0: sl@0: //-- if this parameter is not 0, enables asynchronous mounting FAT32 volumes. sl@0: //-- At present it means enabling/disabling FAT32 background scanning for free clusters. Applicable for FAT32 only sl@0: //-- e.g: FAT_FAT32_AsynchMount=0 sl@0: _LIT8(KPN_FAT32_AsynchMount, "FAT_FAT32_AsynchMount"); sl@0: static const TUint32 KDef_FAT32_AsynchMount = 1; sl@0: sl@0: //-- Using FSInfo sector data during FAT32 mount to find out number of free clusters etc. sl@0: //-- e.g: FAT_FAT32_UseFsInfo=1 sl@0: _LIT8(KPN_FAT32_UseFsInfoOnMount, "FAT_FAT32_UseFsInfo"); sl@0: static const TUint32 KDef_FAT32_UseFsInfoOnMount = 1; sl@0: sl@0: //-- Using FAT bit supercache for fast free cluster lookup sl@0: //-- e.g: FAT_FAT32_UseBitSupercache 0 sl@0: _LIT8(KPN_FAT32_UseFatBitSupercache, "FAT_FAT32_UseBitSupercache"); sl@0: static const TUint32 KDef_FAT32_UseFatBitSupercache = 1; sl@0: sl@0: sl@0: //-- if this parameter is not 0, "clean shutdown mask" bit in FAT16[1] will be used during volume finalisation. sl@0: //-- Otherwise, FAT16[1] will not be affected during finalisation sl@0: //-- e.g: KDef_FAT16_UseCleanShutDownBit 0 sl@0: _LIT8(KPN_FAT16_UseCleanShutDownBit,"FAT16_UseCleanShutDownBit"); //-- parameter key name sl@0: static const TUint32 KDef_FAT16_UseCleanShutDownBit = 1; //-- parameter default value sl@0: sl@0: sl@0: //======================================================================================================================= sl@0: //-- FAT directory cache settings sl@0: //======================================================================================================================= sl@0: //-- FAT_DirCache , sl@0: //-- e.g: FAT_DirCache 16,12 sl@0: _LIT8(KPN_FAT_DirCache, "FAT_DirCache"); sl@0: sl@0: static const TUint32 KDef_KDirCacheSizeKB = 16; //-- default value for the total directory cache size, kilobytes. 16K by default sl@0: static const TUint32 KDef_MaxDirCachePageSzLog2 = 12;//-- default value for directory cache single page maximal size Log2, 2^12 (4K) by default sl@0: sl@0: sl@0: //======================================================================================================================= sl@0: //-- FAT cache settings sl@0: //======================================================================================================================= sl@0: sl@0: //-- Fat16 fixed cache sl@0: //-- FAT_FAT16FixedCache , sl@0: //-- e.g: FAT_FAT16FixedCache 12,9 sl@0: _LIT8(KPN_FAT_FAT16FixedCache, "FAT_FAT16FixedCache"); sl@0: static const TUint32 KDef_FAT16_FixedCache_Read_Granularity_LOG2 = 12; //-- read granularity Log2, 4K sl@0: static const TUint32 KDef_FAT16_FixedCache_Write_Granularity_LOG2 = 9; //-- write granularity Log2, 512 bytes sl@0: sl@0: sl@0: //-- Fat32 LRU cache sl@0: //-- FAT_FAT32LruCache ,, sl@0: //-- e.g: FAT_FAT32LruCache 128,12,9 sl@0: _LIT8(KPN_FAT_FAT32LruCache, "FAT_FAT32LruCache"); sl@0: sl@0: sl@0: static const TUint32 KDef_FAT32_LruCache_SizeKB = 128; //-- LRU cache size, 128KB sl@0: static const TUint32 KDef_FAT32_LruCache_Read_Granularity_LOG2 = 12; //-- read granularity Log2, 4K sl@0: static const TUint32 KDef_FAT32_LruCache_Write_Granularity_LOG2 = 9; //-- write granularity Log2, 512 bytes sl@0: sl@0: sl@0: //======================================================================================================================= sl@0: //-- FAT leaf directory cache settings sl@0: //======================================================================================================================= sl@0: //-- A leaf directory cache for Fat volumes sl@0: _LIT8(KPN_FAT_LeafDirCache, "FAT_LeafDirCacheSize"); sl@0: static const TUint32 KDef_KLeafDirCacheSize = 1; //-- default number of the most recently visited leaf dirs to be cached sl@0: sl@0: //======================================================================================================================= sl@0: //-- New directory cache settings sl@0: //======================================================================================================================= sl@0: //-- New directory cache uses the global cache memory manager for dynamic size allocation sl@0: _LIT8(KPN_FAT_DynamicDirCacheMin, "FAT_DirCacheSizeMin"); sl@0: _LIT8(KPN_FAT_DynamicDirCacheMax, "FAT_DirCacheSizeMax"); sl@0: static const TUint32 KDef_DynamicDirCacheMin = 128; // default minimum fat dir cache size in KB sl@0: static const TUint32 KDef_DynamicDirCacheMax = 128; // default maximum fat dir cache size in KB sl@0: //-- default value for directory cache single page maximal size Log2, 2^14 (16K) by default sl@0: static const TUint32 KDef_MaxDynamicDirCachePageSzLog2 = 14; sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: //######################################################################################################################## sl@0: sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: Extract a token from the comma-separated tokens string. sl@0: sl@0: @param aSrc source string descriptor sl@0: @param aTokenNo token number to extract (the 1st token is number 0) sl@0: @param aToken on success there will be extracted token sl@0: sl@0: @return ETrue on success and an extracted token in aToken sl@0: */ sl@0: static TBool GetCSV_Token(const TDesC8& aSrc, TUint aTokenNo, TPtrC8& aToken) sl@0: { sl@0: sl@0: const TChar chDelim = ','; //-- token delimiter, comma sl@0: TInt nRes; sl@0: sl@0: //-- 1. find the beginning of the token we are looking for sl@0: TPtrC8 ptrCurrToken(aSrc); sl@0: for(TUint i=0; i- TFatConfig::ReadConfig() drive:%d\n"),aDrvNumber); sl@0: ASSERT(aDrvNumber >= EDriveA && aDrvNumber <= EDriveZ); sl@0: sl@0: //-- make a section name, like "DriveX" sl@0: TBuf8<32> section; sl@0: section.Format(_L8("Drive%c"), 'A'+aDrvNumber); sl@0: sl@0: //-- read values from estart.txt and cache them sl@0: iScanDrvSkipFinalisedVolume = ReadUint(section, KPN_ScanDrvSkipFinalisedVolume, KDef_ScanDrvSkipFinalisedVolume); sl@0: iFAT32_AsynchMount = ReadUint(section, KPN_FAT32_AsynchMount, KDef_FAT32_AsynchMount); sl@0: iFAT32_UseFSInfoOnMount = ReadUint(section, KPN_FAT32_UseFsInfoOnMount, KDef_FAT32_UseFsInfoOnMount); sl@0: iFAT32_UseBitSupercache = ReadUint(section, KPN_FAT32_UseFatBitSupercache, KDef_FAT32_UseFatBitSupercache); sl@0: iFAT16_UseCleanShutDownBit = ReadUint(section, KPN_FAT16_UseCleanShutDownBit, KDef_FAT16_UseCleanShutDownBit); sl@0: sl@0: // If leaf dir cache is supported, read the configuration from estart.txt file sl@0: iLeafDirCacheSize = ReadUint(section, KPN_FAT_LeafDirCache, KDef_KLeafDirCacheSize); sl@0: ProcessDynamicDirCacheParams(section); //-- read dynamic dir cache parameters; sl@0: sl@0: ProcessDirCacheParams(section); //-- read FAT directory cache parameters sl@0: ProcessFatCacheParams(section); //-- read FAT cache parameters sl@0: sl@0: iInitialised = ETrue; sl@0: sl@0: DumpParameters(); //-- print out parameters in debug mode sl@0: } sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: process dynamic directory cache parameters sl@0: @param aSection section name, like "DriveX" sl@0: */ sl@0: void TFatConfig::ProcessDynamicDirCacheParams(const TDesC8& aSection) sl@0: { sl@0: // we have to process the data in this file as the default values are all static variables, which means sl@0: // their scope is limited within this file only. sl@0: iDynamicDirCacheMaxPageSizeLog2 = KDef_MaxDynamicDirCachePageSzLog2; sl@0: iDynamicDirCacheSizeMinKB = ReadUint(aSection, KPN_FAT_DynamicDirCacheMin, KDef_DynamicDirCacheMin); sl@0: iDynamicDirCacheSizeMaxKB = ReadUint(aSection, KPN_FAT_DynamicDirCacheMax, KDef_DynamicDirCacheMax); sl@0: sl@0: // if less than default values, set to default values sl@0: if (iDynamicDirCacheSizeMinKB < KDef_DynamicDirCacheMin) sl@0: iDynamicDirCacheSizeMinKB = KDef_DynamicDirCacheMin; sl@0: if (iDynamicDirCacheSizeMaxKB < KDef_DynamicDirCacheMax) sl@0: iDynamicDirCacheSizeMaxKB = KDef_DynamicDirCacheMax; sl@0: sl@0: // validate settings for those values that the default values does not apply onto them sl@0: __ASSERT_ALWAYS(iDynamicDirCacheSizeMinKB <= iDynamicDirCacheSizeMaxKB, Fault(EFatBadParameter)); sl@0: } sl@0: sl@0: /** sl@0: process directory cache parameters sl@0: @param aSection section name, like "DriveX" sl@0: */ sl@0: void TFatConfig::ProcessDirCacheParams(const TDesC8& aSection) sl@0: { sl@0: TBuf8<128> buf; sl@0: sl@0: //-- set default values. sl@0: iDirCacheSizeKB = KDef_KDirCacheSizeKB; sl@0: iDirCacheMaxPageSizeLog2 = KDef_MaxDirCachePageSzLog2; sl@0: sl@0: //-- read a string containing DirCache parameters sl@0: //-- it looks like this: FAT_DirCache cacheSzKB, maxPageSzBytes sl@0: if(!F32Properties::GetString(aSection, KPN_FAT_DirCache, buf)) sl@0: return; sl@0: sl@0: GetIntTokenVal(buf, 0, iDirCacheSizeKB); //-- 1. extract directory cache size in KB. this is token 0 sl@0: GetIntTokenVal(buf, 1, iDirCacheMaxPageSizeLog2); //-- 2. extract directory cache max page size in bytes Log2. this is token 1 sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: process fat cache parameters sl@0: @param aSection section name, like "DriveX" sl@0: */ sl@0: void TFatConfig::ProcessFatCacheParams(const TDesC8& aSection) sl@0: { sl@0: TBuf8<128> buf; sl@0: //-- set default values. sl@0: iFat16FixedCacheReadGrLog2 = KDef_FAT16_FixedCache_Read_Granularity_LOG2; sl@0: iFat16FixedCacheWriteGrLog2 = KDef_FAT16_FixedCache_Write_Granularity_LOG2; sl@0: sl@0: iFat32LRUCacheSizeKB = KDef_FAT32_LruCache_SizeKB; sl@0: iFat32LRUCacheReadGrLog2 = KDef_FAT32_LruCache_Read_Granularity_LOG2; sl@0: iFat32LRUCacheWriteGrLog2 = KDef_FAT32_LruCache_Write_Granularity_LOG2; sl@0: sl@0: //-- read a string containing FAT16 fixed cache parameters sl@0: if(F32Properties::GetString(aSection, KPN_FAT_FAT16FixedCache, buf)) sl@0: { sl@0: GetIntTokenVal(buf, 0, iFat16FixedCacheReadGrLog2); //-- 1. extract Log2(FAT16 fixed cache read granularity) sl@0: GetIntTokenVal(buf, 1, iFat16FixedCacheWriteGrLog2); //-- 2. extract Log2(FAT16 fixed cache write granularity) sl@0: } sl@0: sl@0: //-- read a string containing FAT32 LRU cache parameters sl@0: if(F32Properties::GetString(aSection, KPN_FAT_FAT32LruCache, buf)) sl@0: { sl@0: GetIntTokenVal(buf, 0, iFat32LRUCacheSizeKB); //-- 1. extract FAT32 LRU cache size, Kbytes sl@0: GetIntTokenVal(buf, 1, iFat32LRUCacheReadGrLog2); //-- 2. extract Log2(FAT32 LRU cache read granularity) sl@0: GetIntTokenVal(buf, 2, iFat32LRUCacheWriteGrLog2); //-- 3. extract Log2(FAT32 LRU cache write granularity) sl@0: } sl@0: } sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** sl@0: Just a helper method. Reads TUint32 value from the estart.txt sl@0: sl@0: @param aSection section name, e.g. [DriveD] sl@0: @param aKeyName Key name sl@0: @param aDefaultValue Default value to return in parameter isn't found sl@0: @return a value from config file or default aDefaultValue sl@0: */ sl@0: TUint32 TFatConfig::ReadUint(const TDesC8& aSection, const TDesC8& aKeyName, TUint32 aDefaultValue) const sl@0: { sl@0: TInt32 val = aDefaultValue; sl@0: // coverity[check_return] coverity[unchecked_value] sl@0: F32Properties::GetInt(aSection, aKeyName, val); sl@0: sl@0: return val; sl@0: } sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: /** Debug method, prints out the parameters*/ sl@0: void TFatConfig::DumpParameters() const sl@0: { sl@0: #ifdef _DEBUG sl@0: sl@0: ASSERT(iInitialised); sl@0: __PRINT(_L("#>- TFatConfig parameters:\n")); sl@0: sl@0: DoDumpUintParam(KPN_ScanDrvSkipFinalisedVolume, iScanDrvSkipFinalisedVolume); sl@0: DoDumpUintParam(KPN_FAT32_AsynchMount, iFAT32_AsynchMount); sl@0: DoDumpUintParam(KPN_FAT32_UseFsInfoOnMount, iFAT32_UseFSInfoOnMount); sl@0: DoDumpUintParam(KPN_FAT32_UseFatBitSupercache, iFAT32_UseBitSupercache); sl@0: DoDumpUintParam(KPN_FAT16_UseCleanShutDownBit, iFAT16_UseCleanShutDownBit); sl@0: sl@0: DoDumpUintParam(_L8("FAT_DirCache Size, KB"), iDirCacheSizeKB); sl@0: DoDumpUintParam(_L8("FAT_DirCache MaxPage Size Log2"), iDirCacheMaxPageSizeLog2); sl@0: sl@0: DoDumpUintParam(_L8("FAT_16Cache RdGr Log2"), iFat16FixedCacheReadGrLog2); sl@0: DoDumpUintParam(_L8("FAT_16Cache WrGr Log2"), iFat16FixedCacheWriteGrLog2); sl@0: sl@0: DoDumpUintParam(_L8("FAT_32Cache Size, KB"), iFat32LRUCacheSizeKB); sl@0: DoDumpUintParam(_L8("FAT_32Cache RdGr Log2"), iFat32LRUCacheReadGrLog2); sl@0: DoDumpUintParam(_L8("FAT_32Cache WrGr Log2"), iFat32LRUCacheWriteGrLog2); sl@0: sl@0: __PRINT(_L("#>------ end -------<#\n\n")); sl@0: sl@0: #endif sl@0: } sl@0: sl@0: void TFatConfig::DoDumpUintParam(const TDesC8& aKeyName, TUint32 aParam) const sl@0: { sl@0: #ifdef _DEBUG sl@0: TBuf<100> buf; sl@0: sl@0: buf.Copy(aKeyName); sl@0: buf.Insert(0,_L("#>- ")); sl@0: buf.AppendFormat(_L(": %d"), aParam); sl@0: __PRINT(buf); sl@0: #else sl@0: (void)aKeyName; (void)aParam; //-- get rid of warning sl@0: sl@0: #endif sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: