userlibandfileserver/fileserver/sfat32/sl_cache.h
branchRCL_3
changeset 62 4a8fed1c0ef6
parent 33 0173bcd7697c
equal deleted inserted replaced
52:2d65c2f76d7b 62:4a8fed1c0ef6
    25 
    25 
    26 
    26 
    27 //---------------------------------------------------------------------------------------------------------------------------------
    27 //---------------------------------------------------------------------------------------------------------------------------------
    28 //-- dedicated FAT directory cache related stuff
    28 //-- dedicated FAT directory cache related stuff
    29 
    29 
    30 //-- if defined, a dedicated cache will be used for FAT directories
       
    31 #define ENABLE_DEDICATED_DIR_CACHE
       
    32 
    30 
    33 //---------------------------------------------------------------------------------------------------------------------------------
    31 //---------------------------------------------------------------------------------------------------------------------------------
    34 
    32 
    35 
    33 
    36 /** 
    34 /** 
    62         /** invalidate a single cache page if the aPos is cached*/
    60         /** invalidate a single cache page if the aPos is cached*/
    63         virtual void    InvalidateCachePage(TUint64 aPos)=0;
    61         virtual void    InvalidateCachePage(TUint64 aPos)=0;
    64         
    62         
    65         /**
    63         /**
    66         Finds out if the media position "aPosToSearch" is in the cache and returns cache page information in this case.
    64         Finds out if the media position "aPosToSearch" is in the cache and returns cache page information in this case.
    67         
       
    68         @param  aPosToSearch    linear media position to lookup in the cache
    65         @param  aPosToSearch    linear media position to lookup in the cache
    69         @param  aCachedPosStart if "aPosToSearch" is cached, here will be media position of this page start
       
    70           
       
    71         @return 0 if aPosToSearch isn't cached, otherwise  cache page size in bytes (see also aCachedPosStart).
    66         @return 0 if aPosToSearch isn't cached, otherwise  cache page size in bytes (see also aCachedPosStart).
    72         */
    67         */
    73         virtual TUint32  PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart) = 0;
    68         virtual TUint32  PosCached(TInt64 aPosToSearch) = 0;
    74         
    69         
    75         /**
    70         /**
    76         @return size of the cache in bytes. Can be 0.
    71         @return size of the cache in bytes. Can be 0.
    77         */
    72         */
    78         virtual TUint32 CacheSizeInBytes() const = 0;
    73         virtual TUint32 CacheSizeInBytes() const = 0;
   114 class CWTCachePage
   109 class CWTCachePage
   115     {
   110     {
   116 public:   
   111 public:   
   117         
   112         
   118         static CWTCachePage* NewL(TUint32 aPageSizeLog2);
   113         static CWTCachePage* NewL(TUint32 aPageSizeLog2);
   119         void ConstructL(TUint32 aPageSizeLog2);
       
   120         
   114         
   121         ~CWTCachePage();
   115         ~CWTCachePage();
   122         
   116         
   123         inline TBool   PosCached(TInt64 aPos) const;
   117         inline TBool   PosCached(TInt64 aPos) const;
   124         inline TUint32 PosInCachePage(TInt64 aPos) const; 
   118         inline TUint32 PosInCachePage(TInt64 aPos) const; 
   146 class CMediaWTCache : public CBase, public MWTCacheInterface
   140 class CMediaWTCache : public CBase, public MWTCacheInterface
   147     {
   141     {
   148 public:
   142 public:
   149         ~CMediaWTCache();
   143         ~CMediaWTCache();
   150         
   144         
   151         static CMediaWTCache* NewL(TDriveInterface& aDrive, TUint32 aNumPages, TUint32 aPageSizeLog2);
   145         static CMediaWTCache* NewL(TDriveInterface& aDrive, TUint32 aNumPages, TUint32 aPageSizeLog2, TUint32 aWrGranularityLog2);
   152 
       
   153         void ConstructL(TUint32 aNumPages, TUint32 aPageSizeLog2);
       
   154         
   146         
   155         //-- overloads from the base class
   147         //-- overloads from the base class
   156         void    ReadL (TInt64 aPos,TInt aLength,TDes8& aDes);
   148         void    ReadL (TInt64 aPos,TInt aLength,TDes8& aDes);
   157         void    WriteL(TInt64 aPos,const TDesC8& aDes);
   149         void    WriteL(TInt64 aPos,const TDesC8& aDes);
   158         void    InvalidateCache(void);
   150         void    InvalidateCache(void);
   159         void    InvalidateCachePage(TUint64 aPos);
   151         void    InvalidateCachePage(TUint64 aPos);
   160 
   152 
   161 
   153 
   162         TUint32 PosCached(const TInt64& aPosToSearch, TInt64& aCachedPosStart);
   154         TUint32 PosCached(TInt64 aPosToSearch);
   163         TUint32 CacheSizeInBytes()  const;
   155         TUint32 CacheSizeInBytes()  const;
   164         void 	MakePageMRU(TInt64 aPos);
   156         void 	MakePageMRU(TInt64 aPos);
   165         TUint32 PageSizeInBytesLog2()	const;
   157         TUint32 PageSizeInBytesLog2()	const;
   166         TInt    Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
   158         TInt    Control(TUint32 aFunction, TUint32 aParam1, TAny* aParam2);
   167         inline void SetCacheBasePos(TInt64 aBasePos);
   159         inline void SetCacheBasePos(TInt64 aBasePos);
   169         
   161         
   170 protected:
   162 protected:
   171         CMediaWTCache();
   163         CMediaWTCache();
   172         CMediaWTCache(TDriveInterface& aDrive);
   164         CMediaWTCache(TDriveInterface& aDrive);
   173         
   165         
       
   166         void InitialiseL(TUint32 aNumPages, TUint32 aPageSizeLog2, TUint32 aWrGranularityLog2);
       
   167 
   174         inline TInt64  CalcPageStartPos(TInt64 aPos) const;
   168         inline TInt64  CalcPageStartPos(TInt64 aPos) const;
   175         inline TUint32 PageSize() const;
   169         inline TUint32 PageSize() const;
   176         
   170         
   177         void MakePageLRU(TInt aPageNo);
   171         void MakePageLRU(TInt aPageNo);
   178         
   172         
   181         TUint32 GrabReadPageL(TInt64 aPos);
   175         TUint32 GrabReadPageL(TInt64 aPos);
   182         TUint32 FindOrGrabReadPageL(TInt64 aPos);
   176         TUint32 FindOrGrabReadPageL(TInt64 aPos);
   183         
   177         
   184 protected:
   178 protected:
   185         TDriveInterface& iDrive;        ///< reference to the driver for media access
   179         TDriveInterface& iDrive;        ///< reference to the driver for media access
   186         TUint32             iPageSizeLog2; ///< Log2 (cache page size)
   180         
       
   181         TUint32             iPageSizeLog2;      ///< Log2(cache page size or read granularity unit) 
       
   182         TUint32             iWrGranularityLog2; ///< Log2(cache write granularity unit). Can't be > iPageSizeLog2. '0' has a special meaning - "don't use write granularity"
       
   183 
   187         mutable TBool       iAllPagesValid;///< ETrue if all cache pages have valid data
   184         mutable TBool       iAllPagesValid;///< ETrue if all cache pages have valid data
   188         TInt64              iCacheBasePos; ///< Cache pages base position, used to align them at cluster size
   185         TInt64              iCacheBasePos; ///< Cache pages base position, used to align them at cluster size
   189         RPointerArray<CWTCachePage> iPages; ///< array of pointers to the cache pages. Used for organising LRU list
   186         RPointerArray<CWTCachePage> iPages; ///< array of pointers to the cache pages. Used for organising LRU list
       
   187         
   190         TUint32             iCacheDisabled :1; ///< if not 0 the cache is disabled totally and all reads and writes go via TDriveInterface directly
   188         TUint32             iCacheDisabled :1; ///< if not 0 the cache is disabled totally and all reads and writes go via TDriveInterface directly
   191     };
   189     };
   192 
   190 
   193 
   191 
   194 
   192