sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32\sfat\sl_facache.h sl@0: // FAT cache base classes definition sl@0: // FAT12 and FAT16 cache classes definition sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!! sl@0: //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it sl@0: //!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! sl@0: sl@0: sl@0: #ifndef SL_FAT_CACHE_H sl@0: #define SL_FAT_CACHE_H sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: A simple abstraction of the 32 bit flags sl@0: */ sl@0: class T32Bits sl@0: { sl@0: public: sl@0: T32Bits() : iData(0) {} sl@0: sl@0: inline void Clear(); sl@0: inline TBool HasBitsSet() const; sl@0: inline void SetBit(TUint32 aIndex); sl@0: inline TBool operator[](TUint32 aIndex) const; sl@0: sl@0: private: sl@0: TUint32 iData; ///< 32 bits data sl@0: }; sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: class CFatBitCache; sl@0: sl@0: /** sl@0: An abstract base class for all types of FAT caches. sl@0: Provides user interface and some common for all types of FAT caches functionality. sl@0: */ sl@0: class CFatCacheBase : public CBase sl@0: { sl@0: public: sl@0: sl@0: virtual ~CFatCacheBase(); sl@0: sl@0: //-- public interface sl@0: virtual void Close(TBool /*aDiscardDirtyData*/) {}; sl@0: virtual void FlushL() = 0; sl@0: sl@0: virtual TUint32 ReadEntryL(TUint32 aIndex) = 0; sl@0: virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry) = 0; sl@0: sl@0: virtual TInt Invalidate() = 0; sl@0: virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries) = 0; sl@0: sl@0: TInt ReadFatData(TUint32 aPos, TUint32 aLen, TDes8& aData) const; sl@0: TInt WriteFatData(TUint32 aPos, const TDesC8& aData) const; sl@0: sl@0: inline TUint32 FatStartPos() const; sl@0: inline TUint32 FatSize() const; sl@0: inline TFatType FatType() const; sl@0: sl@0: public: sl@0: sl@0: //-- auxilary interface to additional bit supercache (it may exist only in FAT32 cache implementation) sl@0: virtual CFatBitCache* BitCacheInterface(); sl@0: sl@0: sl@0: protected: sl@0: CFatCacheBase(); sl@0: sl@0: virtual void InitialiseL(CFatMountCB* aOwner); sl@0: sl@0: inline TBool IsDirty() const; sl@0: inline void SetDirty(TBool aDirty); sl@0: inline TUint NumFATs() const; sl@0: sl@0: TBool CheckInvalidatingDirtyCache() const; sl@0: sl@0: inline TUint FAT_SectorSzLog2() const; sl@0: inline TUint FAT_SectorSz() const; sl@0: inline TUint FAT_ClusterSzLog2() const; sl@0: sl@0: protected: sl@0: sl@0: enum {KInvalidFatNo = 0xFF}; ///< used to invalidate current FAT no. sl@0: TUint iCurrentFatNo; ///< current FAT number WriteFatData will write to. sl@0: sl@0: private: sl@0: //-- values cached from owning mount. sl@0: TUint32 iFatStartPos; ///< media position of FAT1 start sl@0: TUint32 iFatSize; ///< size of FAT in bytes sl@0: TUint16 iNumFATs; ///< number of FATs on the volume sl@0: TUint16 iFatSecSzLog2; ///< Log2(FAT Sector size) sl@0: TUint16 iFatClustSzLog2;///< Log2(FAT cluster size) sl@0: TFatType iFatType; ///< FAT type sl@0: TFatDriveInterface* ipDrive;///< interface to the media driver sl@0: //--- sl@0: sl@0: TBool iDirty; ///< ETrue if the cache is dirty sl@0: }; sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: Fixed FAT12 cache. This is a contiguous cache that caches whole FAT12. sl@0: This cache is logically divided to sectors, maximal number of sectors in this cache is KMaxSectorsInCache (32). sl@0: sl@0: Read granularity: whole cache; anyway it can't be larger than 6126 bytes. sl@0: Write granularity: cache sector size, which is always "FAT Sector Size" and non-configurable. sl@0: */ sl@0: class CFat12Cache : public CFatCacheBase sl@0: { sl@0: public: sl@0: static CFat12Cache* NewL(CFatMountCB* aOwner, TUint32 aFatSize); sl@0: sl@0: //-- overrides from base class sl@0: virtual void Close(TBool aDiscardDirtyData); sl@0: virtual void FlushL(); sl@0: sl@0: virtual TUint32 ReadEntryL(TUint32 aIndex); sl@0: virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry); sl@0: sl@0: virtual TInt Invalidate(); sl@0: virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries); sl@0: //------------------------------------ sl@0: sl@0: private: sl@0: sl@0: void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize); sl@0: sl@0: CFat12Cache(); sl@0: CFat12Cache(const CFat12Cache&); sl@0: CFat12Cache& operator=(const CFat12Cache&); sl@0: sl@0: sl@0: inline TUint32 NumSectors() const; sl@0: void AssertCacheReallyClean() const; sl@0: sl@0: private: sl@0: sl@0: enum {KMaxSectorsInCache = 32}; ///< maximal number sectors in FAT12 cache sl@0: enum {KFat12EntryMask = 0x0FFF}; ///< FAT12 entry mask sl@0: sl@0: TUint32 iSectorsInCache; ///< total number sectors in the cache, KMaxSectorsInCache max. sl@0: T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector; sl@0: RBuf8 iData; ///< Whole FAT12 cache data. sl@0: }; sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: Abstract base class for paged caches, i.e. those that consist of some number of cache pages. sl@0: In this case the most of the functionality is implemented in page classes and this is just a page container. sl@0: Each cache page in turn is logically divided to sectors. The sector is a logical unit of write granularity sl@0: See also CFatCachePageBase et al. sl@0: */ sl@0: class CFatPagedCacheBase : public CFatCacheBase sl@0: { sl@0: public: sl@0: sl@0: inline TUint PageSizeLog2() const; sl@0: inline TUint PageSize() const; sl@0: sl@0: inline TUint SectorSizeLog2() const; sl@0: inline TUint SectorsInPage() const; sl@0: sl@0: protected: sl@0: CFatPagedCacheBase(); sl@0: sl@0: protected: sl@0: sl@0: enum {KMaxSectorsInPage = 32}; ///< maximal number sectors in FAT cache page sl@0: sl@0: TUint iPageSizeLog2; ///< Log2(page size) sl@0: TUint iSectorSizeLog2; ///< Log2(page sector size) sl@0: sl@0: }; sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: class CFat16FixedCachePage; sl@0: sl@0: /** sl@0: FAT16 fixed paged cache. Used for FAT16 only and caches whole FAT16 (its max size is 131048 bytes). sl@0: Consists of the fixed array of cache pages; Pages are allocated on demand and never get evicted. sl@0: Each page is logically divided to page sectors. The number of pages depends on the FAT16 size. sl@0: sl@0: Read granularity: One page, which size is 2^aRdGranularityLog2 sl@0: Write granularity: cache's page sector; its size is 2^aWrGranularityLog2 sl@0: */ sl@0: class CFat16FixedCache : public CFatPagedCacheBase sl@0: { sl@0: public: sl@0: sl@0: static CFat16FixedCache* NewL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2); sl@0: sl@0: //-- overrides from base class sl@0: virtual void Close(TBool aDiscardDirtyData); sl@0: virtual void FlushL(); sl@0: sl@0: virtual TUint32 ReadEntryL(TUint32 aIndex); sl@0: virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry); sl@0: sl@0: sl@0: virtual TInt Invalidate(); sl@0: virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries); sl@0: //------------------------------------ sl@0: sl@0: private: sl@0: sl@0: void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2); sl@0: sl@0: CFat16FixedCache(); sl@0: CFat16FixedCache(const CFat16FixedCache&); sl@0: CFat16FixedCache& operator=(const CFat16FixedCache&); sl@0: sl@0: inline TUint NumPages() const; sl@0: void AssertCacheReallyClean() const; sl@0: sl@0: private: sl@0: RPointerArray iPages; ///< array of pointer to the cahe pages; if the entry is NULL, it means that the page isn't allocated yet. sl@0: sl@0: }; sl@0: sl@0: sl@0: //----------------------------------------------------------------------------- sl@0: sl@0: sl@0: /** sl@0: An abstract base class for the cache page. Paged caches, i.e derived form CFatPagedCacheBase uses this functionality. sl@0: Provides an interface and common functionality for all types of cache pages. sl@0: sl@0: The FAT cache page contains a number of FAT16 or FAT32 entries, their number is always the power of 2. sl@0: The page is logically divided into sectors, the maximal number of sectors in the page is KMaxSectorsInPage (32). sl@0: The page read granularity is whole page and the write granularity is the sector (see aRdGranularityLog2, aWrGranularityLog2 from the cache) sl@0: sl@0: The caching is write-back, i.e WriteCachedEntryL() modifies data in the cache and marks corresponding page sector as dirty. sl@0: FlushL() shall be called to flust all dirty sectors in page to the media sl@0: sl@0: */ sl@0: class CFatCachePageBase : public CBase sl@0: { sl@0: public: sl@0: sl@0: ~CFatCachePageBase(); sl@0: sl@0: //---------------- sl@0: virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult) = 0; sl@0: virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry) = 0; sl@0: virtual TUint32 ReadFromMediaL(TUint32 aFatIndex) = 0; sl@0: virtual void FlushL(TBool aKeepDirty); sl@0: sl@0: //---------------- sl@0: inline TBool IsEntryCached(TUint32 aFatIndex) const ; sl@0: void Invalidate(TBool aIgnoreDirtyData = EFalse); sl@0: sl@0: inline TBool IsDirty() const; sl@0: inline TBool IsValid() const; sl@0: sl@0: inline TUint32 StartFatIndex() const; sl@0: sl@0: protected: sl@0: CFatCachePageBase(CFatPagedCacheBase& aCache); sl@0: sl@0: /** possible states of the page */ sl@0: enum TState sl@0: { sl@0: EInvalid, ///< the page's data are invalid sl@0: EClean, ///< the page is clean, data valid and the same as on the media sl@0: EDirty ///< the page is dirty, there are data eventually to be flushed to the media, iDirtySectors contains dirty sectors bitmap. sl@0: }; sl@0: sl@0: inline void SetState(TState aState); sl@0: inline TState State() const; sl@0: inline void SetClean(); sl@0: inline TUint32 PageSize() const; sl@0: inline TUint32 NumSectors() const; sl@0: sl@0: virtual void DoWriteSectorL(TUint32 aSector)=0; sl@0: inline TUint32 EntriesInPage() const; sl@0: sl@0: protected: sl@0: TUint32 iStartIndexInFAT; ///< FAT index this page starts from sl@0: T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector; sl@0: CFatPagedCacheBase& iCache; ///< reference to the owher cache sl@0: RBuf8 iData; ///< page Data sl@0: sl@0: private: sl@0: TState iState; ///< page state sl@0: TUint32 iFatEntriesInPage; ///< number of FAT entries in the page. sl@0: sl@0: }; sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------------------------------------------------------- sl@0: sl@0: /** sl@0: FAT16 cache page. Used only by CFat16FixedCache. sl@0: */ sl@0: class CFat16FixedCachePage : public CFatCachePageBase sl@0: { sl@0: public: sl@0: ~CFat16FixedCachePage() {} sl@0: sl@0: static CFat16FixedCachePage* NewL(CFatPagedCacheBase& aCache); sl@0: sl@0: //-- overrides sl@0: virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult); sl@0: virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry); sl@0: virtual TUint32 ReadFromMediaL(TUint32 aFatIndex); sl@0: //---- sl@0: sl@0: private: sl@0: CFat16FixedCachePage(CFatPagedCacheBase& aCache); sl@0: sl@0: //-- outlaws here sl@0: CFat16FixedCachePage(); sl@0: CFat16FixedCachePage(const CFat16FixedCachePage&); sl@0: CFat16FixedCachePage& operator=(const CFat16FixedCachePage&); sl@0: sl@0: virtual void DoWriteSectorL(TUint32 aSector); sl@0: sl@0: inline TFat16Entry* GetEntryPtr(TUint32 aFatIndex) const; sl@0: sl@0: private: sl@0: enum {KFat16EntryMask = 0xFFFF}; ///< FAT16 entry mask sl@0: }; sl@0: sl@0: sl@0: sl@0: //--------------------------------------------------------------------------------------------------------------------------------- sl@0: sl@0: sl@0: sl@0: #include "sl_fatcache.inl" sl@0: sl@0: sl@0: #endif //SL_FAT_CACHE_H sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: