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 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
26 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 //!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
30 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 #ifndef SL_FAT_CACHE_H
35 #define SL_FAT_CACHE_H
38 //-----------------------------------------------------------------------------
41 A simple abstraction of the 32 bit flags
46 T32Bits() : iData(0) {}
49 inline TBool HasBitsSet() const;
50 inline void SetBit(TUint32 aIndex);
51 inline TBool operator[](TUint32 aIndex) const;
54 TUint32 iData; ///< 32 bits data
57 //-----------------------------------------------------------------------------
62 An abstract base class for all types of FAT caches.
63 Provides user interface and some common for all types of FAT caches functionality.
65 class CFatCacheBase : public CBase
69 virtual ~CFatCacheBase();
72 virtual void Close(TBool /*aDiscardDirtyData*/) {};
73 virtual void FlushL() = 0;
75 virtual TUint32 ReadEntryL(TUint32 aIndex) = 0;
76 virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry) = 0;
78 virtual TInt Invalidate() = 0;
79 virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries) = 0;
81 TInt ReadFatData(TUint32 aPos, TUint32 aLen, TDes8& aData) const;
82 TInt WriteFatData(TUint32 aPos, const TDesC8& aData) const;
84 inline TUint32 FatStartPos() const;
85 inline TUint32 FatSize() const;
86 inline TFatType FatType() const;
90 //-- auxilary interface to additional bit supercache (it may exist only in FAT32 cache implementation)
91 virtual CFatBitCache* BitCacheInterface();
97 virtual void InitialiseL(CFatMountCB* aOwner);
99 inline TBool IsDirty() const;
100 inline void SetDirty(TBool aDirty);
101 inline TUint NumFATs() const;
103 TBool CheckInvalidatingDirtyCache() const;
105 inline TUint FAT_SectorSzLog2() const;
106 inline TUint FAT_SectorSz() const;
107 inline TUint FAT_ClusterSzLog2() const;
111 enum {KInvalidFatNo = 0xFF}; ///< used to invalidate current FAT no.
112 TUint iCurrentFatNo; ///< current FAT number WriteFatData will write to.
115 //-- values cached from owning mount.
116 TUint32 iFatStartPos; ///< media position of FAT1 start
117 TUint32 iFatSize; ///< size of FAT in bytes
118 TUint16 iNumFATs; ///< number of FATs on the volume
119 TUint16 iFatSecSzLog2; ///< Log2(FAT Sector size)
120 TUint16 iFatClustSzLog2;///< Log2(FAT cluster size)
121 TFatType iFatType; ///< FAT type
122 TFatDriveInterface* ipDrive;///< interface to the media driver
125 TBool iDirty; ///< ETrue if the cache is dirty
129 //-----------------------------------------------------------------------------
132 Fixed FAT12 cache. This is a contiguous cache that caches whole FAT12.
133 This cache is logically divided to sectors, maximal number of sectors in this cache is KMaxSectorsInCache (32).
135 Read granularity: whole cache; anyway it can't be larger than 6126 bytes.
136 Write granularity: cache sector size, which is always "FAT Sector Size" and non-configurable.
138 class CFat12Cache : public CFatCacheBase
141 static CFat12Cache* NewL(CFatMountCB* aOwner, TUint32 aFatSize);
143 //-- overrides from base class
144 virtual void Close(TBool aDiscardDirtyData);
145 virtual void FlushL();
147 virtual TUint32 ReadEntryL(TUint32 aIndex);
148 virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry);
150 virtual TInt Invalidate();
151 virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries);
152 //------------------------------------
156 void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize);
159 CFat12Cache(const CFat12Cache&);
160 CFat12Cache& operator=(const CFat12Cache&);
163 inline TUint32 NumSectors() const;
164 void AssertCacheReallyClean() const;
168 enum {KMaxSectorsInCache = 32}; ///< maximal number sectors in FAT12 cache
169 enum {KFat12EntryMask = 0x0FFF}; ///< FAT12 entry mask
171 TUint32 iSectorsInCache; ///< total number sectors in the cache, KMaxSectorsInCache max.
172 T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector;
173 RBuf8 iData; ///< Whole FAT12 cache data.
177 //-----------------------------------------------------------------------------
180 Abstract base class for paged caches, i.e. those that consist of some number of cache pages.
181 In this case the most of the functionality is implemented in page classes and this is just a page container.
182 Each cache page in turn is logically divided to sectors. The sector is a logical unit of write granularity
183 See also CFatCachePageBase et al.
185 class CFatPagedCacheBase : public CFatCacheBase
189 inline TUint PageSizeLog2() const;
190 inline TUint PageSize() const;
192 inline TUint SectorSizeLog2() const;
193 inline TUint SectorsInPage() const;
196 CFatPagedCacheBase();
200 enum {KMaxSectorsInPage = 32}; ///< maximal number sectors in FAT cache page
202 TUint iPageSizeLog2; ///< Log2(page size)
203 TUint iSectorSizeLog2; ///< Log2(page sector size)
207 //-----------------------------------------------------------------------------
209 class CFat16FixedCachePage;
212 FAT16 fixed paged cache. Used for FAT16 only and caches whole FAT16 (its max size is 131048 bytes).
213 Consists of the fixed array of cache pages; Pages are allocated on demand and never get evicted.
214 Each page is logically divided to page sectors. The number of pages depends on the FAT16 size.
216 Read granularity: One page, which size is 2^aRdGranularityLog2
217 Write granularity: cache's page sector; its size is 2^aWrGranularityLog2
219 class CFat16FixedCache : public CFatPagedCacheBase
223 static CFat16FixedCache* NewL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2);
225 //-- overrides from base class
226 virtual void Close(TBool aDiscardDirtyData);
227 virtual void FlushL();
229 virtual TUint32 ReadEntryL(TUint32 aIndex);
230 virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry);
233 virtual TInt Invalidate();
234 virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries);
235 //------------------------------------
239 void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2);
242 CFat16FixedCache(const CFat16FixedCache&);
243 CFat16FixedCache& operator=(const CFat16FixedCache&);
245 inline TUint NumPages() const;
246 void AssertCacheReallyClean() const;
249 RPointerArray<CFat16FixedCachePage> iPages; ///< array of pointer to the cahe pages; if the entry is NULL, it means that the page isn't allocated yet.
254 //-----------------------------------------------------------------------------
258 An abstract base class for the cache page. Paged caches, i.e derived form CFatPagedCacheBase uses this functionality.
259 Provides an interface and common functionality for all types of cache pages.
261 The FAT cache page contains a number of FAT16 or FAT32 entries, their number is always the power of 2.
262 The page is logically divided into sectors, the maximal number of sectors in the page is KMaxSectorsInPage (32).
263 The page read granularity is whole page and the write granularity is the sector (see aRdGranularityLog2, aWrGranularityLog2 from the cache)
265 The caching is write-back, i.e WriteCachedEntryL() modifies data in the cache and marks corresponding page sector as dirty.
266 FlushL() shall be called to flust all dirty sectors in page to the media
269 class CFatCachePageBase : public CBase
273 ~CFatCachePageBase();
276 virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult) = 0;
277 virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry) = 0;
278 virtual TUint32 ReadFromMediaL(TUint32 aFatIndex) = 0;
279 virtual void FlushL(TBool aKeepDirty);
282 inline TBool IsEntryCached(TUint32 aFatIndex) const ;
283 void Invalidate(TBool aIgnoreDirtyData = EFalse);
285 inline TBool IsDirty() const;
286 inline TBool IsValid() const;
288 inline TUint32 StartFatIndex() const;
291 CFatCachePageBase(CFatPagedCacheBase& aCache);
293 /** possible states of the page */
296 EInvalid, ///< the page's data are invalid
297 EClean, ///< the page is clean, data valid and the same as on the media
298 EDirty ///< the page is dirty, there are data eventually to be flushed to the media, iDirtySectors contains dirty sectors bitmap.
301 inline void SetState(TState aState);
302 inline TState State() const;
303 inline void SetClean();
304 inline TUint32 PageSize() const;
305 inline TUint32 NumSectors() const;
307 virtual void DoWriteSectorL(TUint32 aSector)=0;
308 inline TUint32 EntriesInPage() const;
311 TUint32 iStartIndexInFAT; ///< FAT index this page starts from
312 T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector;
313 CFatPagedCacheBase& iCache; ///< reference to the owher cache
314 RBuf8 iData; ///< page Data
317 TState iState; ///< page state
318 TUint32 iFatEntriesInPage; ///< number of FAT entries in the page.
323 //---------------------------------------------------------------------------------------------------------------------------------
326 FAT16 cache page. Used only by CFat16FixedCache.
328 class CFat16FixedCachePage : public CFatCachePageBase
331 ~CFat16FixedCachePage() {}
333 static CFat16FixedCachePage* NewL(CFatPagedCacheBase& aCache);
336 virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult);
337 virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry);
338 virtual TUint32 ReadFromMediaL(TUint32 aFatIndex);
342 CFat16FixedCachePage(CFatPagedCacheBase& aCache);
345 CFat16FixedCachePage();
346 CFat16FixedCachePage(const CFat16FixedCachePage&);
347 CFat16FixedCachePage& operator=(const CFat16FixedCachePage&);
349 virtual void DoWriteSectorL(TUint32 aSector);
351 inline TFat16Entry* GetEntryPtr(TUint32 aFatIndex) const;
354 enum {KFat16EntryMask = 0xFFFF}; ///< FAT16 entry mask
359 //---------------------------------------------------------------------------------------------------------------------------------
363 #include "sl_fatcache.inl"
366 #endif //SL_FAT_CACHE_H