1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat/sl_dir_cache.inl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,218 @@
1.4 +// Copyright (c) 2008-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\sl_dir_cache.inl
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalTechnology
1.24 +*/
1.25 +
1.26 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.27 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.28 +//!!
1.29 +//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
1.30 +//!!
1.31 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.32 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.33 +
1.34 +
1.35 +#ifndef SL_DIR_CACHE_INL
1.36 +#define SL_DIR_CACHE_INL
1.37 +
1.38 +#include "sl_dir_cache.h"
1.39 +
1.40 +/**
1.41 +Get function of TDynamicDirCachePage.
1.42 +@return TInt64 the starting media address of the page content.
1.43 +*/
1.44 +TInt64 TDynamicDirCachePage::StartPos() const
1.45 + {
1.46 + return iStartMedPos;
1.47 + }
1.48 +
1.49 +/**
1.50 +Get function of TDynamicDirCachePage.
1.51 +@return TUint8* the starting ram content of the page content.
1.52 +*/
1.53 +TUint8* TDynamicDirCachePage::StartPtr() const
1.54 + {
1.55 + return iStartRamAddr;
1.56 + }
1.57 +
1.58 +/**
1.59 +Set function of TDynamicDirCachePage.
1.60 +@param aPtr starting RAM Ptr that holds the cache page data.
1.61 +*/
1.62 +void TDynamicDirCachePage::SetStartPtr(TUint8* aPtr)
1.63 + {
1.64 + iStartRamAddr = aPtr;
1.65 + }
1.66 +
1.67 +/**
1.68 +Set function of TDynamicDirCachePage.
1.69 +@param aIsValid boolean value to set validity of the page content.
1.70 +*/
1.71 +void TDynamicDirCachePage::SetValid(TBool aIsValid)
1.72 + {
1.73 + iValid = aIsValid;
1.74 + }
1.75 +
1.76 +/**
1.77 +Get function of TDynamicDirCachePage.
1.78 +@return TBool boolean value that indicates validity of the page content.
1.79 +*/
1.80 +TBool TDynamicDirCachePage::IsValid() const
1.81 + {
1.82 + return iValid;
1.83 + }
1.84 +
1.85 +/**
1.86 +Set function of TDynamicDirCachePage.
1.87 +@param aLocked flag that sets if the page is locked or not.
1.88 +*/
1.89 +void TDynamicDirCachePage::SetLocked(TBool aLocked)
1.90 + {
1.91 + iLocked = aLocked;
1.92 + }
1.93 +
1.94 +/**
1.95 +Get function of TDynamicDirCachePage.
1.96 +@return TBool boolean value that indicates if the page is locked.
1.97 +*/
1.98 +TBool TDynamicDirCachePage::IsLocked() const
1.99 + {
1.100 + return iLocked;
1.101 + }
1.102 +
1.103 +/**
1.104 +Set function of TDynamicDirCachePage.
1.105 +@param aType set page type: EUnknown, ELocked, EUnlocked or EActivePage.
1.106 +*/
1.107 +void TDynamicDirCachePage::SetPageType(TDynamicDirCachePage::TPageType aType)
1.108 + {
1.109 + iType = aType;
1.110 + }
1.111 +
1.112 +/**
1.113 +Get function of TDynamicDirCachePage.
1.114 +@return TPageType get page type: EUnknown, ELocked, EUnlocked or EActivePage.
1.115 +*/
1.116 +TDynamicDirCachePage::TPageType TDynamicDirCachePage::PageType()
1.117 + {
1.118 + return iType;
1.119 + }
1.120 +
1.121 +/**
1.122 +Get function of TDynamicDirCachePage.
1.123 +@return TUint32 page size in bytes.
1.124 +*/
1.125 +TUint32 TDynamicDirCachePage::PageSizeInBytes() const
1.126 + {
1.127 + return 1 << iOwnerCache->PageSizeInBytesLog2();
1.128 + }
1.129 +
1.130 +/**
1.131 +Deque the page from its queue.
1.132 +@see TDblQueLink::Deque()
1.133 +*/
1.134 +void TDynamicDirCachePage::Deque()
1.135 + {
1.136 + iLink.Deque();
1.137 + }
1.138 +
1.139 +/**
1.140 +Get function of TDynamicDirCachePage.
1.141 +@return TUint32 page size in segments.
1.142 +*/
1.143 +TUint32 TDynamicDirCachePage::PageSizeInSegs() const
1.144 + {
1.145 + return iOwnerCache->PageSizeInSegs();
1.146 + }
1.147 +
1.148 +/**
1.149 +Interpret the media address into ram address.
1.150 +@param aPos the media address to be interpreted
1.151 +@return TUint8* the ram content pointer that contains that media content.
1.152 +*/
1.153 +TUint8* TDynamicDirCachePage::PtrInPage(TInt64 aPos) const
1.154 + {
1.155 + ASSERT(PosCachedInPage(aPos));
1.156 + return iStartRamAddr + (((TUint32)aPos - (TUint32)iStartMedPos) & (PageSizeInBytes() - 1));
1.157 + }
1.158 +
1.159 +/**
1.160 +Query function, to check if the media address is contained in the page.
1.161 +@param aPos the media address to be queried.
1.162 +@return TBool ETrue if the media address is cached in the page, otherwise EFalse.
1.163 +*/
1.164 +TBool TDynamicDirCachePage::PosCachedInPage(TInt64 aPos) const
1.165 + {
1.166 + return (aPos >= iStartMedPos && aPos < iStartMedPos + PageSizeInBytes());
1.167 + }
1.168 +
1.169 +/**
1.170 +Reset the media address to 0, invalidate page content.
1.171 +*/
1.172 +void TDynamicDirCachePage::ResetPos()
1.173 + {
1.174 + iStartMedPos = 0;
1.175 + SetValid(EFalse);
1.176 + }
1.177 +
1.178 +/**
1.179 +Set page starting media address, invalidate page content.
1.180 +@param aPos the new media address to be set.
1.181 +*/
1.182 +void TDynamicDirCachePage::SetPos(TInt64 aPos)
1.183 + {
1.184 + iStartMedPos = aPos;
1.185 + SetValid(EFalse);
1.186 + return;
1.187 + }
1.188 +
1.189 +
1.190 +//========================================================================
1.191 +/**
1.192 +Calculate the page starting media address, aligned with page size.
1.193 +@param aPos the media address to be aligned.
1.194 +@return TInt64 the aligned media address.
1.195 +*/
1.196 +TInt64 CDynamicDirCache::CalcPageStartPos(TInt64 aPos) const
1.197 + {
1.198 + ASSERT(aPos >= iCacheBasePos);
1.199 + return (((aPos - iCacheBasePos) >> iPageSizeLog2) << iPageSizeLog2) + iCacheBasePos;
1.200 + }
1.201 +
1.202 +/**
1.203 +Check if the cache has reached its limited page number.
1.204 +@return TBool ETrue if cache is full, otherwise EFalse.
1.205 +*/
1.206 +TBool CDynamicDirCache::CacheIsFull() const
1.207 + {
1.208 + // active page, locked page and unlocked page
1.209 + return (iLockedQCount + iUnlockedQCount + 1 >= iMaxSizeInPages);
1.210 + }
1.211 +
1.212 +/**
1.213 +Return the maximum allowed page number of the cache.
1.214 +*/
1.215 +TUint32 CDynamicDirCache::MaxCacheSizeInPages() const
1.216 + {
1.217 + return iMaxSizeInPages;
1.218 + }
1.219 +
1.220 +#endif //SL_DIR_CACHE_INL
1.221 +