os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/sl_dir_cache.inl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32\sfat\sl_dir_cache.inl
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
#ifndef SL_DIR_CACHE_INL
sl@0
    24
#define SL_DIR_CACHE_INL
sl@0
    25
sl@0
    26
#include "sl_dir_cache.h"
sl@0
    27
sl@0
    28
/**
sl@0
    29
Get function of TDynamicDirCachePage.
sl@0
    30
@return	TInt64	the starting media address of the page content.
sl@0
    31
*/
sl@0
    32
TInt64 TDynamicDirCachePage::StartPos()	const
sl@0
    33
	{
sl@0
    34
	return iStartMedPos;
sl@0
    35
	}
sl@0
    36
sl@0
    37
/**
sl@0
    38
Get function of TDynamicDirCachePage.
sl@0
    39
@return	TUint8*	the starting ram content of the page content.
sl@0
    40
*/
sl@0
    41
TUint8*	TDynamicDirCachePage::StartPtr() const
sl@0
    42
	{
sl@0
    43
	return iStartRamAddr;
sl@0
    44
	}
sl@0
    45
sl@0
    46
/**
sl@0
    47
Set function of TDynamicDirCachePage.
sl@0
    48
@param	aPtr	starting RAM Ptr that holds the cache page data.
sl@0
    49
*/
sl@0
    50
void TDynamicDirCachePage::SetStartPtr(TUint8* aPtr)
sl@0
    51
	{
sl@0
    52
	iStartRamAddr = aPtr;
sl@0
    53
	}
sl@0
    54
sl@0
    55
/**
sl@0
    56
Set function of TDynamicDirCachePage.
sl@0
    57
@param	aIsValid	boolean value to set validity of the page content.
sl@0
    58
*/
sl@0
    59
void TDynamicDirCachePage::SetValid(TBool aIsValid)
sl@0
    60
	{
sl@0
    61
	iValid = aIsValid;
sl@0
    62
	}
sl@0
    63
sl@0
    64
/**
sl@0
    65
Get	function of TDynamicDirCachePage.
sl@0
    66
@return TBool	boolean value that indicates validity of the page content.
sl@0
    67
*/
sl@0
    68
TBool TDynamicDirCachePage::IsValid() const
sl@0
    69
	{
sl@0
    70
	return iValid;
sl@0
    71
	}
sl@0
    72
sl@0
    73
/**
sl@0
    74
Set	function of TDynamicDirCachePage.
sl@0
    75
@param	aLocked	flag that sets if the page is locked or not.
sl@0
    76
*/
sl@0
    77
void TDynamicDirCachePage::SetLocked(TBool aLocked)
sl@0
    78
	{
sl@0
    79
	iLocked = aLocked;
sl@0
    80
	}
sl@0
    81
sl@0
    82
/**
sl@0
    83
Get	function of TDynamicDirCachePage.
sl@0
    84
@return TBool	boolean value that indicates if the page is locked.
sl@0
    85
*/
sl@0
    86
TBool TDynamicDirCachePage::IsLocked() const
sl@0
    87
	{
sl@0
    88
	return iLocked;
sl@0
    89
	}
sl@0
    90
sl@0
    91
/**
sl@0
    92
Set	function of TDynamicDirCachePage.
sl@0
    93
@param	aType	set page type: EUnknown, ELocked, EUnlocked or EActivePage.
sl@0
    94
*/
sl@0
    95
void TDynamicDirCachePage::SetPageType(TDynamicDirCachePage::TPageType aType)
sl@0
    96
	{
sl@0
    97
	iType = aType;
sl@0
    98
	}
sl@0
    99
sl@0
   100
/**
sl@0
   101
Get	function of TDynamicDirCachePage.
sl@0
   102
@return	TPageType	get page type: EUnknown, ELocked, EUnlocked or EActivePage.
sl@0
   103
*/
sl@0
   104
TDynamicDirCachePage::TPageType TDynamicDirCachePage::PageType()
sl@0
   105
	{
sl@0
   106
	return iType;
sl@0
   107
	}
sl@0
   108
sl@0
   109
/**
sl@0
   110
Get	function of TDynamicDirCachePage.
sl@0
   111
@return	TUint32	page size in bytes.
sl@0
   112
*/
sl@0
   113
TUint32	TDynamicDirCachePage::PageSizeInBytes() const
sl@0
   114
	{
sl@0
   115
	return 1 << iOwnerCache->PageSizeInBytesLog2();
sl@0
   116
	}
sl@0
   117
sl@0
   118
/**
sl@0
   119
Deque the page from its queue.
sl@0
   120
@see	TDblQueLink::Deque()
sl@0
   121
*/
sl@0
   122
void TDynamicDirCachePage::Deque()
sl@0
   123
	{
sl@0
   124
	iLink.Deque();
sl@0
   125
	}
sl@0
   126
sl@0
   127
/**
sl@0
   128
Get	function of TDynamicDirCachePage.
sl@0
   129
@return	TUint32	page size in segments.
sl@0
   130
*/
sl@0
   131
TUint32	TDynamicDirCachePage::PageSizeInSegs() const
sl@0
   132
	{
sl@0
   133
	return iOwnerCache->PageSizeInSegs();
sl@0
   134
	}
sl@0
   135
sl@0
   136
/**
sl@0
   137
Interpret the media address into ram address.
sl@0
   138
@param	aPos	the media address to be interpreted
sl@0
   139
@return	TUint8*	the ram content pointer that contains that media content.
sl@0
   140
*/
sl@0
   141
TUint8*	TDynamicDirCachePage::PtrInPage(TInt64 aPos) const
sl@0
   142
	{
sl@0
   143
    ASSERT(PosCachedInPage(aPos));
sl@0
   144
    return iStartRamAddr + (((TUint32)aPos - (TUint32)iStartMedPos) & (PageSizeInBytes() - 1));
sl@0
   145
	}
sl@0
   146
sl@0
   147
/**
sl@0
   148
Query function, to check if the media address is contained in the page.
sl@0
   149
@param	aPos	the media address to be queried.
sl@0
   150
@return	TBool	ETrue if the media address is cached in the page, otherwise EFalse.
sl@0
   151
*/
sl@0
   152
TBool TDynamicDirCachePage::PosCachedInPage(TInt64 aPos) const
sl@0
   153
    {
sl@0
   154
    return (aPos >= iStartMedPos && aPos < iStartMedPos + PageSizeInBytes());
sl@0
   155
    }
sl@0
   156
sl@0
   157
/**
sl@0
   158
Reset the media address to 0, invalidate page content.
sl@0
   159
*/
sl@0
   160
void TDynamicDirCachePage::ResetPos()
sl@0
   161
	{
sl@0
   162
	iStartMedPos = 0;
sl@0
   163
	SetValid(EFalse);
sl@0
   164
	}
sl@0
   165
sl@0
   166
/**
sl@0
   167
Set page starting media address, invalidate page content.
sl@0
   168
@param	aPos	the new media address to be set.
sl@0
   169
*/
sl@0
   170
void TDynamicDirCachePage::SetPos(TInt64 aPos)
sl@0
   171
	{
sl@0
   172
	iStartMedPos = aPos;
sl@0
   173
	SetValid(EFalse);
sl@0
   174
	return;
sl@0
   175
	}
sl@0
   176
sl@0
   177
sl@0
   178
//========================================================================
sl@0
   179
/**
sl@0
   180
Calculate the page starting media address, aligned with page size.
sl@0
   181
@param	aPos	the media address to be aligned.
sl@0
   182
@return	TInt64	the aligned media address.
sl@0
   183
*/
sl@0
   184
TInt64 CDynamicDirCache::CalcPageStartPos(TInt64 aPos) const
sl@0
   185
	{
sl@0
   186
    ASSERT(aPos >= iCacheBasePos);
sl@0
   187
    return (((aPos - iCacheBasePos) >> iPageSizeLog2) << iPageSizeLog2) + iCacheBasePos;
sl@0
   188
	}
sl@0
   189
sl@0
   190
/**
sl@0
   191
Check if the cache has reached its limited page number.
sl@0
   192
@return	TBool	ETrue if cache is full, otherwise EFalse.
sl@0
   193
*/
sl@0
   194
TBool CDynamicDirCache::CacheIsFull() const
sl@0
   195
	{
sl@0
   196
	// active page, locked page and unlocked page
sl@0
   197
	return (iLockedQCount + iUnlockedQCount + 1 >= iMaxSizeInPages);
sl@0
   198
	}
sl@0
   199
sl@0
   200
/**
sl@0
   201
Return the maximum allowed page number of the cache.
sl@0
   202
*/
sl@0
   203
TUint32 CDynamicDirCache::MaxCacheSizeInPages() const
sl@0
   204
	{
sl@0
   205
	return iMaxSizeInPages;
sl@0
   206
	}
sl@0
   207
sl@0
   208
#endif //SL_DIR_CACHE_INL
sl@0
   209