os/kernelhwsrv/userlibandfileserver/fileserver/fs_utils/filesystem_utils.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1995-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 //
    15 //  Collection of common constants, utility functions, etc. for the file server and file systems.
    16 //  Definitions here must be filesystem-agnostic, i.e. generic enougs to be used by every file system
    17 //
    18 //  This is the internal file and must not be exported.
    19 
    20 /**
    21     @file
    22     @internalTechnology
    23 */
    24 
    25 #if !defined(__FILESYSTEM_UTILS_H__)
    26 #define __FILESYSTEM_UTILS_H__
    27 
    28 #if !defined(__E32BASE_H__)
    29 #include <e32base.h>
    30 #endif
    31 
    32 //#######################################################################################################################################
    33 //#   constants definitions
    34 //#######################################################################################################################################
    35 
    36 const TUint KBitsInByteLog2 = 3;
    37 const TUint KBitsInByte = 1<<KBitsInByteLog2;
    38 
    39 
    40 const TUint16 K1KiloByteLog2 = 10;
    41 const TUint32 K1KiloByte = 1<<K1KiloByteLog2; 
    42 const TUint32 K1MegaByte = 1<<20; 
    43 
    44 const TUint32 K1uSec = 1;               ///< 1 misrosecond in TTimeIntervalMicroSeconds32
    45 const TUint32 K1mSec = 1000;            ///< 1 millisecond in TTimeIntervalMicroSeconds32
    46 const TUint32 K1Sec  = 1000*K1mSec;     ///< 1 second in TTimeIntervalMicroSeconds32
    47 
    48 //---------------------------------------------------------------------------------------------------------------------------------------
    49 
    50 const TUint KDefSectorSzLog2=9;                         ///< Log2 of the default sector size for the media 
    51 const TUint KDefaultSectorSize = 1 << KDefSectorSzLog2; ///< Default sector size for the media, 512 bytes
    52 
    53 //#######################################################################################################################################
    54 //#   some useful utility functions
    55 //#######################################################################################################################################
    56 
    57 inline TUint32 Pow2(TUint32 aVal);          //-- return 2^aVal
    58 inline TUint32 Pow2_32(TUint32 aVal);       //-- return 2^aVal
    59 inline TUint64 Pow2_64(TUint32 aVal);       //-- return 2^aVal
    60 
    61 inline TBool IsPowerOf2(TUint32 aVal);      //-- return ETrue if aVal is a power of 2 
    62 inline TBool IsPowerOf2_64(TUint64 aVal);   //-- return ETrue if aVal is a power of 2 
    63 
    64 inline TUint32 RoundDown(TUint32 aVal, TUint32 aGranularityLog2);
    65 inline TUint32 RoundUp(TUint32 aVal, TUint32 aGranularityLog2);
    66 
    67 inline TBool BoolXOR(TBool a1, TBool a2);           //-- return Boolean XOR of a1 and a2
    68 
    69 inline TUint32 Log2_inline(TUint32 aVal);           //-- Calculates the Log2(aVal)
    70 TUint32 Log2(TUint32 aVal);                         //-- Calculates the Log2(aVal)
    71 
    72 inline TUint32 Count1Bits_inline(TUint32 aVal);     //-- counts number of '1' bits in the aVal
    73 TUint32 Count1Bits(TUint32 aVal);                   //-- counts number of '1' bits in the aVal
    74 
    75 //-----------------------------------------------------------------------------
    76 
    77 TPtrC RemoveTrailingDots(const TDesC& aName); //-- Removes trailing dots from aName. "Name..." -> "Name"
    78 
    79 
    80 //#######################################################################################################################################
    81 /**
    82     A class representing a simple abstraction of the 32 bit flags
    83 */
    84 class T32Bits
    85 {
    86  public:
    87     T32Bits() : iData(0) {}
    88 
    89     inline void  Clear();
    90     inline TBool HasBitsSet() const;
    91     inline void SetBit(TUint32 aIndex);
    92     inline TBool operator[](TUint32 aIndex) const;
    93 
    94  private:
    95     TUint32 iData; ///< 32 bits data
    96 };
    97 
    98 
    99 
   100 
   101 
   102 
   103 #include "filesystem_utils.inl"
   104 
   105 
   106 #endif //__FILESYSTEM_UTILS_H__
   107 
   108 
   109 
   110 
   111 
   112 
   113 
   114 
   115 
   116 
   117 
   118