First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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
18 // This is the internal file and must not be exported.
25 #if !defined(__FILESYSTEM_UTILS_H__)
26 #define __FILESYSTEM_UTILS_H__
28 #if !defined(__E32BASE_H__)
32 //#######################################################################################################################################
33 //# constants definitions
34 //#######################################################################################################################################
36 const TUint KBitsInByteLog2 = 3;
37 const TUint KBitsInByte = 1<<KBitsInByteLog2;
40 const TUint16 K1KiloByteLog2 = 10;
41 const TUint32 K1KiloByte = 1<<K1KiloByteLog2;
42 const TUint32 K1MegaByte = 1<<20;
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
48 //---------------------------------------------------------------------------------------------------------------------------------------
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
53 //#######################################################################################################################################
54 //# some useful utility functions
55 //#######################################################################################################################################
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
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
64 inline TUint32 RoundDown(TUint32 aVal, TUint32 aGranularityLog2);
65 inline TUint32 RoundUp(TUint32 aVal, TUint32 aGranularityLog2);
67 inline TBool BoolXOR(TBool a1, TBool a2); //-- return Boolean XOR of a1 and a2
69 inline TUint32 Log2_inline(TUint32 aVal); //-- Calculates the Log2(aVal)
70 TUint32 Log2(TUint32 aVal); //-- Calculates the Log2(aVal)
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
75 //-----------------------------------------------------------------------------
77 TPtrC RemoveTrailingDots(const TDesC& aName); //-- Removes trailing dots from aName. "Name..." -> "Name"
80 //#######################################################################################################################################
82 A class representing a simple abstraction of the 32 bit flags
87 T32Bits() : iData(0) {}
90 inline TBool HasBitsSet() const;
91 inline void SetBit(TUint32 aIndex);
92 inline TBool operator[](TUint32 aIndex) const;
95 TUint32 iData; ///< 32 bits data
103 #include "filesystem_utils.inl"
106 #endif //__FILESYSTEM_UTILS_H__