os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/sl_cache.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1996-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\sfat32\inc\sl_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_CACHE_INL
sl@0
    24
#define SL_CACHE_INL
sl@0
    25
sl@0
    26
sl@0
    27
/**
sl@0
    28
    @param  aPos media linear position
sl@0
    29
    @return ETrue if the aPos belongs to this page
sl@0
    30
*/
sl@0
    31
TBool CWTCachePage::PosCached(TInt64 aPos) const
sl@0
    32
    {
sl@0
    33
    return (iValid && aPos >= iStartPos && aPos < iStartPos+PageSize());
sl@0
    34
    }
sl@0
    35
sl@0
    36
sl@0
    37
/**
sl@0
    38
    Calculate data position within cache page relatively to the page beginning.
sl@0
    39
    @param  aPos media linear position
sl@0
    40
    @return data offset from the beginning of the page
sl@0
    41
*/
sl@0
    42
TUint32 CWTCachePage::PosInCachePage(TInt64 aPos) const 
sl@0
    43
    { 
sl@0
    44
    return ((TUint32)aPos - (TUint32)iStartPos) & (PageSize()-1);
sl@0
    45
    }
sl@0
    46
sl@0
    47
/**
sl@0
    48
    Obtain pointer to the data in the cache page by media inear position
sl@0
    49
    @param  aPos media linear position
sl@0
    50
    @return pointer to the data in page buffer
sl@0
    51
*/
sl@0
    52
TUint8* CWTCachePage::PtrInCachePage(TInt64 aPos) const 
sl@0
    53
    { 
sl@0
    54
    return (TUint8*)iData.Ptr() + PosInCachePage(aPos);
sl@0
    55
    }
sl@0
    56
sl@0
    57
/**
sl@0
    58
    @return cache page size in bytes
sl@0
    59
*/
sl@0
    60
TUint32 CWTCachePage::PageSize() const 
sl@0
    61
    {
sl@0
    62
    return iData.Size();
sl@0
    63
    }  
sl@0
    64
sl@0
    65
//---------------------------------------------------------------------------------------------------------------------------------
sl@0
    66
sl@0
    67
sl@0
    68
/**
sl@0
    69
    Just helper method to calculate cache page start position by given media pos.
sl@0
    70
    @param  aPos media linear position
sl@0
    71
    @return rounded-down and aligned position that is the beginning of the cache page
sl@0
    72
*/
sl@0
    73
TInt64  CMediaWTCache::CalcPageStartPos(TInt64 aPos) const 
sl@0
    74
    { 
sl@0
    75
    ASSERT(aPos >= iCacheBasePos);
sl@0
    76
    return (((aPos - iCacheBasePos) >> iPageSizeLog2) << iPageSizeLog2) + iCacheBasePos;
sl@0
    77
    }
sl@0
    78
sl@0
    79
/**
sl@0
    80
    @return cache page size
sl@0
    81
*/
sl@0
    82
TUint32 CMediaWTCache::PageSize() const 
sl@0
    83
    {
sl@0
    84
    return 1<<iPageSizeLog2;
sl@0
    85
    }
sl@0
    86
sl@0
    87
sl@0
    88
/**
sl@0
    89
    Set cache base position at aBasePos
sl@0
    90
    @param  aBasePos  base position of the cache pages. Affects pages alignment.
sl@0
    91
*/
sl@0
    92
void CMediaWTCache::SetCacheBasePos(TInt64 aBasePos)
sl@0
    93
    {
sl@0
    94
    iCacheBasePos = aBasePos;
sl@0
    95
    }
sl@0
    96
sl@0
    97
sl@0
    98
sl@0
    99
//---------------------------------------------------------------------------------------------------------------------------------
sl@0
   100
sl@0
   101
sl@0
   102
#endif //SL_CACHE_INL
sl@0
   103
sl@0
   104
sl@0
   105
sl@0
   106