os/kernelhwsrv/userlibandfileserver/fileserver/sfat/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
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    24
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    25
//!!
sl@0
    26
//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
sl@0
    27
//!!
sl@0
    28
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    29
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sl@0
    30
sl@0
    31
sl@0
    32
#ifndef SL_DIR_CACHE_INL
sl@0
    33
#define SL_DIR_CACHE_INL
sl@0
    34
sl@0
    35
#include "sl_dir_cache.h"
sl@0
    36
sl@0
    37
/**
sl@0
    38
Get function of TDynamicDirCachePage.
sl@0
    39
@return TInt64  the starting media address of the page content.
sl@0
    40
*/
sl@0
    41
TInt64 TDynamicDirCachePage::StartPos() const
sl@0
    42
    {
sl@0
    43
    return iStartMedPos;
sl@0
    44
    }
sl@0
    45
sl@0
    46
/**
sl@0
    47
Get function of TDynamicDirCachePage.
sl@0
    48
@return TUint8* the starting ram content of the page content.
sl@0
    49
*/
sl@0
    50
TUint8* TDynamicDirCachePage::StartPtr() const
sl@0
    51
    {
sl@0
    52
    return iStartRamAddr;
sl@0
    53
    }
sl@0
    54
sl@0
    55
/**
sl@0
    56
Set function of TDynamicDirCachePage.
sl@0
    57
@param  aPtr    starting RAM Ptr that holds the cache page data.
sl@0
    58
*/
sl@0
    59
void TDynamicDirCachePage::SetStartPtr(TUint8* aPtr)
sl@0
    60
    {
sl@0
    61
    iStartRamAddr = aPtr;
sl@0
    62
    }
sl@0
    63
sl@0
    64
/**
sl@0
    65
Set function of TDynamicDirCachePage.
sl@0
    66
@param  aIsValid    boolean value to set validity of the page content.
sl@0
    67
*/
sl@0
    68
void TDynamicDirCachePage::SetValid(TBool aIsValid)
sl@0
    69
    {
sl@0
    70
    iValid = aIsValid;
sl@0
    71
    }
sl@0
    72
sl@0
    73
/**
sl@0
    74
Get function of TDynamicDirCachePage.
sl@0
    75
@return TBool   boolean value that indicates validity of the page content.
sl@0
    76
*/
sl@0
    77
TBool TDynamicDirCachePage::IsValid() const
sl@0
    78
    {
sl@0
    79
    return iValid;
sl@0
    80
    }
sl@0
    81
sl@0
    82
/**
sl@0
    83
Set function of TDynamicDirCachePage.
sl@0
    84
@param  aLocked flag that sets if the page is locked or not.
sl@0
    85
*/
sl@0
    86
void TDynamicDirCachePage::SetLocked(TBool aLocked)
sl@0
    87
    {
sl@0
    88
    iLocked = aLocked;
sl@0
    89
    }
sl@0
    90
sl@0
    91
/**
sl@0
    92
Get function of TDynamicDirCachePage.
sl@0
    93
@return TBool   boolean value that indicates if the page is locked.
sl@0
    94
*/
sl@0
    95
TBool TDynamicDirCachePage::IsLocked() const
sl@0
    96
    {
sl@0
    97
    return iLocked;
sl@0
    98
    }
sl@0
    99
sl@0
   100
/**
sl@0
   101
Set function of TDynamicDirCachePage.
sl@0
   102
@param  aType   set page type: EUnknown, ELocked, EUnlocked or EActivePage.
sl@0
   103
*/
sl@0
   104
void TDynamicDirCachePage::SetPageType(TDynamicDirCachePage::TPageType aType)
sl@0
   105
    {
sl@0
   106
    iType = aType;
sl@0
   107
    }
sl@0
   108
sl@0
   109
/**
sl@0
   110
Get function of TDynamicDirCachePage.
sl@0
   111
@return TPageType   get page type: EUnknown, ELocked, EUnlocked or EActivePage.
sl@0
   112
*/
sl@0
   113
TDynamicDirCachePage::TPageType TDynamicDirCachePage::PageType()
sl@0
   114
    {
sl@0
   115
    return iType;
sl@0
   116
    }
sl@0
   117
sl@0
   118
/**
sl@0
   119
Get function of TDynamicDirCachePage.
sl@0
   120
@return TUint32 page size in bytes.
sl@0
   121
*/
sl@0
   122
TUint32 TDynamicDirCachePage::PageSizeInBytes() const
sl@0
   123
    {
sl@0
   124
    return 1 << iOwnerCache->PageSizeInBytesLog2();
sl@0
   125
    }
sl@0
   126
sl@0
   127
/**
sl@0
   128
Deque the page from its queue.
sl@0
   129
@see    TDblQueLink::Deque()
sl@0
   130
*/
sl@0
   131
void TDynamicDirCachePage::Deque()
sl@0
   132
    {
sl@0
   133
    iLink.Deque();
sl@0
   134
    }
sl@0
   135
sl@0
   136
/**
sl@0
   137
Get function of TDynamicDirCachePage.
sl@0
   138
@return TUint32 page size in segments.
sl@0
   139
*/
sl@0
   140
TUint32 TDynamicDirCachePage::PageSizeInSegs() const
sl@0
   141
    {
sl@0
   142
    return iOwnerCache->PageSizeInSegs();
sl@0
   143
    }
sl@0
   144
sl@0
   145
/**
sl@0
   146
Interpret the media address into ram address.
sl@0
   147
@param  aPos    the media address to be interpreted
sl@0
   148
@return TUint8* the ram content pointer that contains that media content.
sl@0
   149
*/
sl@0
   150
TUint8* TDynamicDirCachePage::PtrInPage(TInt64 aPos) const
sl@0
   151
    {
sl@0
   152
    ASSERT(PosCachedInPage(aPos));
sl@0
   153
    return iStartRamAddr + (((TUint32)aPos - (TUint32)iStartMedPos) & (PageSizeInBytes() - 1));
sl@0
   154
    }
sl@0
   155
sl@0
   156
/**
sl@0
   157
Query function, to check if the media address is contained in the page.
sl@0
   158
@param  aPos    the media address to be queried.
sl@0
   159
@return TBool   ETrue if the media address is cached in the page, otherwise EFalse.
sl@0
   160
*/
sl@0
   161
TBool TDynamicDirCachePage::PosCachedInPage(TInt64 aPos) const
sl@0
   162
    {
sl@0
   163
    return (aPos >= iStartMedPos && aPos < iStartMedPos + PageSizeInBytes());
sl@0
   164
    }
sl@0
   165
sl@0
   166
/**
sl@0
   167
Reset the media address to 0, invalidate page content.
sl@0
   168
*/
sl@0
   169
void TDynamicDirCachePage::ResetPos()
sl@0
   170
    {
sl@0
   171
    iStartMedPos = 0;
sl@0
   172
    SetValid(EFalse);
sl@0
   173
    }
sl@0
   174
sl@0
   175
/**
sl@0
   176
Set page starting media address, invalidate page content.
sl@0
   177
@param  aPos    the new media address to be set.
sl@0
   178
*/
sl@0
   179
void TDynamicDirCachePage::SetPos(TInt64 aPos)
sl@0
   180
    {
sl@0
   181
    iStartMedPos = aPos;
sl@0
   182
    SetValid(EFalse);
sl@0
   183
    return;
sl@0
   184
    }
sl@0
   185
sl@0
   186
sl@0
   187
//========================================================================
sl@0
   188
/**
sl@0
   189
Calculate the page starting media address, aligned with page size.
sl@0
   190
@param  aPos    the media address to be aligned.
sl@0
   191
@return TInt64  the aligned media address.
sl@0
   192
*/
sl@0
   193
TInt64 CDynamicDirCache::CalcPageStartPos(TInt64 aPos) const
sl@0
   194
    {
sl@0
   195
    ASSERT(aPos >= iCacheBasePos);
sl@0
   196
    return (((aPos - iCacheBasePos) >> iPageSizeLog2) << iPageSizeLog2) + iCacheBasePos;
sl@0
   197
    }
sl@0
   198
sl@0
   199
/**
sl@0
   200
Check if the cache has reached its limited page number.
sl@0
   201
@return TBool   ETrue if cache is full, otherwise EFalse.
sl@0
   202
*/
sl@0
   203
TBool CDynamicDirCache::CacheIsFull() const
sl@0
   204
    {
sl@0
   205
    // active page, locked page and unlocked page
sl@0
   206
    return (iLockedQCount + iUnlockedQCount + 1 >= iMaxSizeInPages);
sl@0
   207
    }
sl@0
   208
sl@0
   209
/**
sl@0
   210
Return the maximum allowed page number of the cache.
sl@0
   211
*/
sl@0
   212
TUint32 CDynamicDirCache::MaxCacheSizeInPages() const
sl@0
   213
    {
sl@0
   214
    return iMaxSizeInPages;
sl@0
   215
    }
sl@0
   216
sl@0
   217
#endif //SL_DIR_CACHE_INL
sl@0
   218