1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat/sl_fatcache.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,389 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32\sfat\sl_facache.h
1.18 +// FAT cache base classes definition
1.19 +// FAT12 and FAT16 cache classes definition
1.20 +//
1.21 +//
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalTechnology
1.26 +*/
1.27 +
1.28 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.29 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.30 +//!!
1.31 +//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
1.32 +//!!
1.33 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.34 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.35 +
1.36 +
1.37 +#ifndef SL_FAT_CACHE_H
1.38 +#define SL_FAT_CACHE_H
1.39 +
1.40 +
1.41 +//-----------------------------------------------------------------------------
1.42 +
1.43 +/**
1.44 + A simple abstraction of the 32 bit flags
1.45 +*/
1.46 +class T32Bits
1.47 +{
1.48 + public:
1.49 + T32Bits() : iData(0) {}
1.50 +
1.51 + inline void Clear();
1.52 + inline TBool HasBitsSet() const;
1.53 + inline void SetBit(TUint32 aIndex);
1.54 + inline TBool operator[](TUint32 aIndex) const;
1.55 +
1.56 + private:
1.57 + TUint32 iData; ///< 32 bits data
1.58 +};
1.59 +
1.60 +//-----------------------------------------------------------------------------
1.61 +
1.62 +class CFatBitCache;
1.63 +
1.64 +/**
1.65 + An abstract base class for all types of FAT caches.
1.66 + Provides user interface and some common for all types of FAT caches functionality.
1.67 +*/
1.68 +class CFatCacheBase : public CBase
1.69 +{
1.70 + public:
1.71 +
1.72 + virtual ~CFatCacheBase();
1.73 +
1.74 + //-- public interface
1.75 + virtual void Close(TBool /*aDiscardDirtyData*/) {};
1.76 + virtual void FlushL() = 0;
1.77 +
1.78 + virtual TUint32 ReadEntryL(TUint32 aIndex) = 0;
1.79 + virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry) = 0;
1.80 +
1.81 + virtual TInt Invalidate() = 0;
1.82 + virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries) = 0;
1.83 +
1.84 + TInt ReadFatData(TUint32 aPos, TUint32 aLen, TDes8& aData) const;
1.85 + TInt WriteFatData(TUint32 aPos, const TDesC8& aData) const;
1.86 +
1.87 + inline TUint32 FatStartPos() const;
1.88 + inline TUint32 FatSize() const;
1.89 + inline TFatType FatType() const;
1.90 +
1.91 + public:
1.92 +
1.93 + //-- auxilary interface to additional bit supercache (it may exist only in FAT32 cache implementation)
1.94 + virtual CFatBitCache* BitCacheInterface();
1.95 +
1.96 +
1.97 + protected:
1.98 + CFatCacheBase();
1.99 +
1.100 + virtual void InitialiseL(CFatMountCB* aOwner);
1.101 +
1.102 + inline TBool IsDirty() const;
1.103 + inline void SetDirty(TBool aDirty);
1.104 + inline TUint NumFATs() const;
1.105 +
1.106 + TBool CheckInvalidatingDirtyCache() const;
1.107 +
1.108 + inline TUint FAT_SectorSzLog2() const;
1.109 + inline TUint FAT_SectorSz() const;
1.110 + inline TUint FAT_ClusterSzLog2() const;
1.111 +
1.112 + protected:
1.113 +
1.114 + enum {KInvalidFatNo = 0xFF}; ///< used to invalidate current FAT no.
1.115 + TUint iCurrentFatNo; ///< current FAT number WriteFatData will write to.
1.116 +
1.117 + private:
1.118 + //-- values cached from owning mount.
1.119 + TUint32 iFatStartPos; ///< media position of FAT1 start
1.120 + TUint32 iFatSize; ///< size of FAT in bytes
1.121 + TUint16 iNumFATs; ///< number of FATs on the volume
1.122 + TUint16 iFatSecSzLog2; ///< Log2(FAT Sector size)
1.123 + TUint16 iFatClustSzLog2;///< Log2(FAT cluster size)
1.124 + TFatType iFatType; ///< FAT type
1.125 + TFatDriveInterface* ipDrive;///< interface to the media driver
1.126 + //---
1.127 +
1.128 + TBool iDirty; ///< ETrue if the cache is dirty
1.129 +};
1.130 +
1.131 +
1.132 +//-----------------------------------------------------------------------------
1.133 +
1.134 +/**
1.135 + Fixed FAT12 cache. This is a contiguous cache that caches whole FAT12.
1.136 + This cache is logically divided to sectors, maximal number of sectors in this cache is KMaxSectorsInCache (32).
1.137 +
1.138 + Read granularity: whole cache; anyway it can't be larger than 6126 bytes.
1.139 + Write granularity: cache sector size, which is always "FAT Sector Size" and non-configurable.
1.140 +*/
1.141 +class CFat12Cache : public CFatCacheBase
1.142 +{
1.143 + public:
1.144 + static CFat12Cache* NewL(CFatMountCB* aOwner, TUint32 aFatSize);
1.145 +
1.146 + //-- overrides from base class
1.147 + virtual void Close(TBool aDiscardDirtyData);
1.148 + virtual void FlushL();
1.149 +
1.150 + virtual TUint32 ReadEntryL(TUint32 aIndex);
1.151 + virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry);
1.152 +
1.153 + virtual TInt Invalidate();
1.154 + virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries);
1.155 + //------------------------------------
1.156 +
1.157 + private:
1.158 +
1.159 + void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize);
1.160 +
1.161 + CFat12Cache();
1.162 + CFat12Cache(const CFat12Cache&);
1.163 + CFat12Cache& operator=(const CFat12Cache&);
1.164 +
1.165 +
1.166 + inline TUint32 NumSectors() const;
1.167 + void AssertCacheReallyClean() const;
1.168 +
1.169 + private:
1.170 +
1.171 + enum {KMaxSectorsInCache = 32}; ///< maximal number sectors in FAT12 cache
1.172 + enum {KFat12EntryMask = 0x0FFF}; ///< FAT12 entry mask
1.173 +
1.174 + TUint32 iSectorsInCache; ///< total number sectors in the cache, KMaxSectorsInCache max.
1.175 + T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector;
1.176 + RBuf8 iData; ///< Whole FAT12 cache data.
1.177 +};
1.178 +
1.179 +
1.180 +//-----------------------------------------------------------------------------
1.181 +
1.182 +/**
1.183 + Abstract base class for paged caches, i.e. those that consist of some number of cache pages.
1.184 + In this case the most of the functionality is implemented in page classes and this is just a page container.
1.185 + Each cache page in turn is logically divided to sectors. The sector is a logical unit of write granularity
1.186 + See also CFatCachePageBase et al.
1.187 +*/
1.188 +class CFatPagedCacheBase : public CFatCacheBase
1.189 +{
1.190 + public:
1.191 +
1.192 + inline TUint PageSizeLog2() const;
1.193 + inline TUint PageSize() const;
1.194 +
1.195 + inline TUint SectorSizeLog2() const;
1.196 + inline TUint SectorsInPage() const;
1.197 +
1.198 + protected:
1.199 + CFatPagedCacheBase();
1.200 +
1.201 + protected:
1.202 +
1.203 + enum {KMaxSectorsInPage = 32}; ///< maximal number sectors in FAT cache page
1.204 +
1.205 + TUint iPageSizeLog2; ///< Log2(page size)
1.206 + TUint iSectorSizeLog2; ///< Log2(page sector size)
1.207 +
1.208 +};
1.209 +
1.210 +//-----------------------------------------------------------------------------
1.211 +
1.212 +class CFat16FixedCachePage;
1.213 +
1.214 +/**
1.215 + FAT16 fixed paged cache. Used for FAT16 only and caches whole FAT16 (its max size is 131048 bytes).
1.216 + Consists of the fixed array of cache pages; Pages are allocated on demand and never get evicted.
1.217 + Each page is logically divided to page sectors. The number of pages depends on the FAT16 size.
1.218 +
1.219 + Read granularity: One page, which size is 2^aRdGranularityLog2
1.220 + Write granularity: cache's page sector; its size is 2^aWrGranularityLog2
1.221 +*/
1.222 +class CFat16FixedCache : public CFatPagedCacheBase
1.223 +{
1.224 + public:
1.225 +
1.226 + static CFat16FixedCache* NewL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2);
1.227 +
1.228 + //-- overrides from base class
1.229 + virtual void Close(TBool aDiscardDirtyData);
1.230 + virtual void FlushL();
1.231 +
1.232 + virtual TUint32 ReadEntryL(TUint32 aIndex);
1.233 + virtual void WriteEntryL(TUint32 aIndex, TUint32 aEntry);
1.234 +
1.235 +
1.236 + virtual TInt Invalidate();
1.237 + virtual TInt InvalidateRegion(TUint32 aStartEntry, TUint32 aNumEntries);
1.238 + //------------------------------------
1.239 +
1.240 + private:
1.241 +
1.242 + void InitialiseL(CFatMountCB* aOwner, TUint32 aFatSize, TUint32 aRdGranularityLog2, TUint32 aWrGranularityLog2);
1.243 +
1.244 + CFat16FixedCache();
1.245 + CFat16FixedCache(const CFat16FixedCache&);
1.246 + CFat16FixedCache& operator=(const CFat16FixedCache&);
1.247 +
1.248 + inline TUint NumPages() const;
1.249 + void AssertCacheReallyClean() const;
1.250 +
1.251 + private:
1.252 + RPointerArray<CFat16FixedCachePage> iPages; ///< array of pointer to the cahe pages; if the entry is NULL, it means that the page isn't allocated yet.
1.253 +
1.254 +};
1.255 +
1.256 +
1.257 +//-----------------------------------------------------------------------------
1.258 +
1.259 +
1.260 +/**
1.261 + An abstract base class for the cache page. Paged caches, i.e derived form CFatPagedCacheBase uses this functionality.
1.262 + Provides an interface and common functionality for all types of cache pages.
1.263 +
1.264 + The FAT cache page contains a number of FAT16 or FAT32 entries, their number is always the power of 2.
1.265 + The page is logically divided into sectors, the maximal number of sectors in the page is KMaxSectorsInPage (32).
1.266 + The page read granularity is whole page and the write granularity is the sector (see aRdGranularityLog2, aWrGranularityLog2 from the cache)
1.267 +
1.268 + The caching is write-back, i.e WriteCachedEntryL() modifies data in the cache and marks corresponding page sector as dirty.
1.269 + FlushL() shall be called to flust all dirty sectors in page to the media
1.270 +
1.271 +*/
1.272 +class CFatCachePageBase : public CBase
1.273 +{
1.274 +public:
1.275 +
1.276 + ~CFatCachePageBase();
1.277 +
1.278 + //----------------
1.279 + virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult) = 0;
1.280 + virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry) = 0;
1.281 + virtual TUint32 ReadFromMediaL(TUint32 aFatIndex) = 0;
1.282 + virtual void FlushL(TBool aKeepDirty);
1.283 +
1.284 + //----------------
1.285 + inline TBool IsEntryCached(TUint32 aFatIndex) const ;
1.286 + void Invalidate(TBool aIgnoreDirtyData = EFalse);
1.287 +
1.288 + inline TBool IsDirty() const;
1.289 + inline TBool IsValid() const;
1.290 +
1.291 + inline TUint32 StartFatIndex() const;
1.292 +
1.293 +protected:
1.294 + CFatCachePageBase(CFatPagedCacheBase& aCache);
1.295 +
1.296 + /** possible states of the page */
1.297 + enum TState
1.298 + {
1.299 + EInvalid, ///< the page's data are invalid
1.300 + EClean, ///< the page is clean, data valid and the same as on the media
1.301 + EDirty ///< the page is dirty, there are data eventually to be flushed to the media, iDirtySectors contains dirty sectors bitmap.
1.302 + };
1.303 +
1.304 + inline void SetState(TState aState);
1.305 + inline TState State() const;
1.306 + inline void SetClean();
1.307 + inline TUint32 PageSize() const;
1.308 + inline TUint32 NumSectors() const;
1.309 +
1.310 + virtual void DoWriteSectorL(TUint32 aSector)=0;
1.311 + inline TUint32 EntriesInPage() const;
1.312 +
1.313 +protected:
1.314 + TUint32 iStartIndexInFAT; ///< FAT index this page starts from
1.315 + T32Bits iDirtySectors; ///< dirty sectors bitmap. '1' bit corresponds to the dirty sector;
1.316 + CFatPagedCacheBase& iCache; ///< reference to the owher cache
1.317 + RBuf8 iData; ///< page Data
1.318 +
1.319 +private:
1.320 + TState iState; ///< page state
1.321 + TUint32 iFatEntriesInPage; ///< number of FAT entries in the page.
1.322 +
1.323 +};
1.324 +
1.325 +
1.326 +//---------------------------------------------------------------------------------------------------------------------------------
1.327 +
1.328 +/**
1.329 + FAT16 cache page. Used only by CFat16FixedCache.
1.330 +*/
1.331 +class CFat16FixedCachePage : public CFatCachePageBase
1.332 +{
1.333 + public:
1.334 + ~CFat16FixedCachePage() {}
1.335 +
1.336 + static CFat16FixedCachePage* NewL(CFatPagedCacheBase& aCache);
1.337 +
1.338 + //-- overrides
1.339 + virtual TBool ReadCachedEntryL (TUint32 aFatIndex, TUint32& aResult);
1.340 + virtual TBool WriteCachedEntryL(TUint32 aFatIndex, TUint32 aFatEntry);
1.341 + virtual TUint32 ReadFromMediaL(TUint32 aFatIndex);
1.342 + //----
1.343 +
1.344 + private:
1.345 + CFat16FixedCachePage(CFatPagedCacheBase& aCache);
1.346 +
1.347 + //-- outlaws here
1.348 + CFat16FixedCachePage();
1.349 + CFat16FixedCachePage(const CFat16FixedCachePage&);
1.350 + CFat16FixedCachePage& operator=(const CFat16FixedCachePage&);
1.351 +
1.352 + virtual void DoWriteSectorL(TUint32 aSector);
1.353 +
1.354 + inline TFat16Entry* GetEntryPtr(TUint32 aFatIndex) const;
1.355 +
1.356 + private:
1.357 + enum {KFat16EntryMask = 0xFFFF}; ///< FAT16 entry mask
1.358 +};
1.359 +
1.360 +
1.361 +
1.362 +//---------------------------------------------------------------------------------------------------------------------------------
1.363 +
1.364 +
1.365 +
1.366 +#include "sl_fatcache.inl"
1.367 +
1.368 +
1.369 +#endif //SL_FAT_CACHE_H
1.370 +
1.371 +
1.372 +
1.373 +
1.374 +
1.375 +
1.376 +
1.377 +
1.378 +
1.379 +
1.380 +
1.381 +
1.382 +
1.383 +
1.384 +
1.385 +
1.386 +
1.387 +
1.388 +
1.389 +
1.390 +
1.391 +
1.392 +