os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/sl_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.
     1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // f32\sfat32\inc\sl_cache.inl
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalTechnology
    21 */
    22 
    23 #ifndef SL_CACHE_INL
    24 #define SL_CACHE_INL
    25 
    26 
    27 /**
    28     @param  aPos media linear position
    29     @return ETrue if the aPos belongs to this page
    30 */
    31 TBool CWTCachePage::PosCached(TInt64 aPos) const
    32     {
    33     return (iValid && aPos >= iStartPos && aPos < iStartPos+PageSize());
    34     }
    35 
    36 
    37 /**
    38     Calculate data position within cache page relatively to the page beginning.
    39     @param  aPos media linear position
    40     @return data offset from the beginning of the page
    41 */
    42 TUint32 CWTCachePage::PosInCachePage(TInt64 aPos) const 
    43     { 
    44     return ((TUint32)aPos - (TUint32)iStartPos) & (PageSize()-1);
    45     }
    46 
    47 /**
    48     Obtain pointer to the data in the cache page by media inear position
    49     @param  aPos media linear position
    50     @return pointer to the data in page buffer
    51 */
    52 TUint8* CWTCachePage::PtrInCachePage(TInt64 aPos) const 
    53     { 
    54     return (TUint8*)iData.Ptr() + PosInCachePage(aPos);
    55     }
    56 
    57 /**
    58     @return cache page size in bytes
    59 */
    60 TUint32 CWTCachePage::PageSize() const 
    61     {
    62     return iData.Size();
    63     }  
    64 
    65 //---------------------------------------------------------------------------------------------------------------------------------
    66 
    67 
    68 /**
    69     Just helper method to calculate cache page start position by given media pos.
    70     @param  aPos media linear position
    71     @return rounded-down and aligned position that is the beginning of the cache page
    72 */
    73 TInt64  CMediaWTCache::CalcPageStartPos(TInt64 aPos) const 
    74     { 
    75     ASSERT(aPos >= iCacheBasePos);
    76     return (((aPos - iCacheBasePos) >> iPageSizeLog2) << iPageSizeLog2) + iCacheBasePos;
    77     }
    78 
    79 /**
    80     @return cache page size
    81 */
    82 TUint32 CMediaWTCache::PageSize() const 
    83     {
    84     return 1<<iPageSizeLog2;
    85     }
    86 
    87 
    88 /**
    89     Set cache base position at aBasePos
    90     @param  aBasePos  base position of the cache pages. Affects pages alignment.
    91 */
    92 void CMediaWTCache::SetCacheBasePos(TInt64 aBasePos)
    93     {
    94     iCacheBasePos = aBasePos;
    95     }
    96 
    97 
    98 
    99 //---------------------------------------------------------------------------------------------------------------------------------
   100 
   101 
   102 #endif //SL_CACHE_INL
   103 
   104 
   105 
   106