Update contrib.
1 // Copyright (c) 1998-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.
14 // f32\sfat\sl_facache.h
15 // FAT cache base classes definition
16 // FAT12 and FAT16 cache classes definition
25 #ifndef SL_FAT_CACHE_H
26 #define SL_FAT_CACHE_H
29 //-----------------------------------------------------------------------------
34 An abstract base class for all types of FAT caches.
35 Provides user interface and some common for all types of FAT caches functionality.
37 class CFatCacheBase : public CBase
41 virtual ~CFatCacheBase();
44 virtual void Close(TBool /*aDiscardDirtyData*/) {};
45 virtual void FlushL() = 0;
47 virtual TUint32 ReadEntryL(TUint32 aIndex) = 0;
48 virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry) = 0;
50 virtual TInt Invalidate() = 0;
51 virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries) = 0;
53 TInt ReadFatData(TUint32 aPos, TUint32 aLen, TDes8& aData) const;
54 TInt WriteFatData(TUint32 aPos, const TDesC8& aData) const;
56 inline TUint32 FatStartPos() const;
57 inline TUint32 FatSize() const;
58 inline TFatType FatType() const;
62 //-- auxilary interface to additional bit supercache (it may exist only in FAT32 cache implementation)
63 virtual CFatBitCache* BitCacheInterface();
69 virtual void InitialiseL(CFatMountCB* aOwner);
71 inline TBool IsDirty() const;
72 inline void SetDirty(TBool aDirty);
73 inline TUint NumFATs() const;
75 TBool CheckInvalidatingDirtyCache() const;
77 inline TUint FAT_SectorSzLog2() const;
78 inline TUint FAT_SectorSz() const;
79 inline TUint FAT_ClusterSzLog2() const;
83 enum {KInvalidFatNo = 0xFF}; ///< used to invalidate current FAT no.
84 TUint iCurrentFatNo; ///< current FAT number WriteFatData will write to.
87 //-- values cached from owning mount.
88 TUint32 iFatStartPos; ///< media position of FAT1 start
89 TUint32 iFatSize; ///< size of FAT in bytes
90 TUint16 iNumFATs; ///< number of FATs on the volume
91 TUint16 iFatSecSzLog2; ///< Log2(FAT Sector size)
92 TUint16 iFatClustSzLog2;///< Log2(FAT cluster size)
93 TFatType iFatType; ///< FAT type
94 TDriveInterface* ipDrive;///< interface to the media driver
97 TBool iDirty; ///< ETrue if the cache is dirty
101 //-----------------------------------------------------------------------------
104 Fixed FAT12 cache. This is a contiguous cache that caches whole FAT12.
105 This cache is logically divided to sectors, maximal number of sectors in this cache is KMaxSectorsInCache (32).
107 Read granularity: whole cache; anyway it can't be larger than 6126 bytes.
108 Write granularity: cache sector size, which is always "FAT Sector Size" and non-configurable.
110 class CFat12Cache : public CFatCacheBase
113 static CFat12Cache* NewL(CFatMountCB* aOwner, TUint32 aFatSize);
115 //-- overrides from base class
116 virtual void Close(TBool aDiscardDirtyData);
117 virtual void FlushL();
119 virtual TUint32 ReadEntryL(TUint32 aIndex);
120 virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry);
122 virtual TInt Invalidate();
123 virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries);
124 //------------------------------------
128 void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize);
131 CFat12Cache(const CFat12Cache&);
132 CFat12Cache& operator=(const CFat12Cache&);
135 inline TUint32 NumSectors() const;
136 void AssertCacheReallyClean() const;
140 enum {KMaxSectorsInCache = 32}; ///< maximal number sectors in FAT12 cache
141 enum {KFat12EntryMask = 0x0FFF}; ///< FAT12 entry mask
143 TUint32 iSectorsInCache; ///< total number sectors in the cache, KMaxSectorsInCache max.
144 T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector;
145 RBuf8 iData; ///< Whole FAT12 cache data.
149 //-----------------------------------------------------------------------------
152 Abstract base class for paged caches, i.e. those that consist of some number of cache pages.
153 In this case the most of the functionality is implemented in page classes and this is just a page container.
154 Each cache page in turn is logically divided to sectors. The sector is a logical unit of write granularity
155 See also CFatCachePageBase et al.
157 class CFatPagedCacheBase : public CFatCacheBase
161 inline TUint PageSizeLog2() const;
162 inline TUint PageSize() const;
164 inline TUint SectorSizeLog2() const;
165 inline TUint SectorsInPage() const;
168 CFatPagedCacheBase();
172 enum {KMaxSectorsInPage = 32}; ///< maximal number sectors in FAT cache page
174 TUint iPageSizeLog2; ///< Log2(page size)
175 TUint iSectorSizeLog2; ///< Log2(page sector size)
179 //-----------------------------------------------------------------------------
181 class CFat16FixedCachePage;
184 FAT16 fixed paged cache. Used for FAT16 only and caches whole FAT16 (its max size is 131048 bytes).
185 Consists of the fixed array of cache pages; Pages are allocated on demand and never get evicted.
186 Each page is logically divided to page sectors. The number of pages depends on the FAT16 size.
188 Read granularity: One page, which size is 2^aRdGranularityLog2
189 Write granularity: cache's page sector; its size is 2^aWrGranularityLog2
191 class CFat16FixedCache : public CFatPagedCacheBase
195 static CFat16FixedCache* NewL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2);
197 //-- overrides from base class
198 virtual void Close(TBool aDiscardDirtyData);
199 virtual void FlushL();
201 virtual TUint32 ReadEntryL(TUint32 aIndex);
202 virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry);
205 virtual TInt Invalidate();
206 virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries);
207 //------------------------------------
211 void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2);
214 CFat16FixedCache(const CFat16FixedCache&);
215 CFat16FixedCache& operator=(const CFat16FixedCache&);
217 inline TUint NumPages() const;
218 void AssertCacheReallyClean() const;
221 RPointerArray<CFat16FixedCachePage> iPages; ///< array of pointer to the cahe pages; if the entry is NULL, it means that the page isn't allocated yet.
226 //-----------------------------------------------------------------------------
230 An abstract base class for the cache page. Paged caches, i.e derived form CFatPagedCacheBase uses this functionality.
231 Provides an interface and common functionality for all types of cache pages.
233 The FAT cache page contains a number of FAT16 or FAT32 entries, their number is always the power of 2.
234 The page is logically divided into sectors, the maximal number of sectors in the page is KMaxSectorsInPage (32).
235 The page read granularity is whole page and the write granularity is the sector (see aRdGranularityLog2, aWrGranularityLog2 from the cache)
237 The caching is write-back, i.e WriteCachedEntryL() modifies data in the cache and marks corresponding page sector as dirty.
238 FlushL() shall be called to flust all dirty sectors in page to the media
241 class CFatCachePageBase : public CBase
245 ~CFatCachePageBase();
248 virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult) = 0;
249 virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry) = 0;
250 virtual TUint32 ReadFromMediaL(TUint32 aFatIndex) = 0;
251 virtual void FlushL(TBool aKeepDirty);
254 inline TBool IsEntryCached(TUint32 aFatIndex) const ;
255 void Invalidate(TBool aIgnoreDirtyData = EFalse);
257 inline TBool IsDirty() const;
258 inline TBool IsValid() const;
260 inline TUint32 StartFatIndex() const;
263 CFatCachePageBase(CFatPagedCacheBase& aCache);
265 /** possible states of the page */
268 EInvalid, ///< the page's data are invalid
269 EClean, ///< the page is clean, data valid and the same as on the media
270 EDirty ///< the page is dirty, there are data eventually to be flushed to the media, iDirtySectors contains dirty sectors bitmap.
273 inline void SetState(TState aState);
274 inline TState State() const;
275 inline void SetClean();
276 inline TUint32 PageSize() const;
277 inline TUint32 NumSectors() const;
279 virtual void DoWriteSectorL(TUint32 aSector)=0;
280 inline TUint32 EntriesInPage() const;
283 TUint32 iStartIndexInFAT; ///< FAT index this page starts from
284 T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector;
285 CFatPagedCacheBase& iCache; ///< reference to the owher cache
286 RBuf8 iData; ///< page Data
289 TState iState; ///< page state
290 TUint32 iFatEntriesInPage; ///< number of FAT entries in the page.
295 //---------------------------------------------------------------------------------------------------------------------------------
298 FAT16 cache page. Used only by CFat16FixedCache.
300 class CFat16FixedCachePage : public CFatCachePageBase
303 ~CFat16FixedCachePage() {}
305 static CFat16FixedCachePage* NewL(CFatPagedCacheBase& aCache);
308 virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult);
309 virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry);
310 virtual TUint32 ReadFromMediaL(TUint32 aFatIndex);
314 CFat16FixedCachePage(CFatPagedCacheBase& aCache);
317 CFat16FixedCachePage();
318 CFat16FixedCachePage(const CFat16FixedCachePage&);
319 CFat16FixedCachePage& operator=(const CFat16FixedCachePage&);
321 virtual void DoWriteSectorL(TUint32 aSector);
323 inline TFat16Entry* GetEntryPtr(TUint32 aFatIndex) const;
326 enum {KFat16EntryMask = 0xFFFF}; ///< FAT16 entry mask
331 //---------------------------------------------------------------------------------------------------------------------------------
335 #include "sl_fatcache.inl"
338 #endif //SL_FAT_CACHE_H