os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_file_cache.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32\sfile\sf_file_cache.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
sl@0
    24
#if !defined(__SF_FILE_CACHE_H__)
sl@0
    25
#define __SF_FILE_CACHE_H__
sl@0
    26
sl@0
    27
#include "sf_cache_client.h"
sl@0
    28
sl@0
    29
//#define _DEBUG_READ_AHEAD
sl@0
    30
sl@0
    31
sl@0
    32
NONSHARABLE_CLASS(CFileCache) : public CFsDispatchObject
sl@0
    33
	{
sl@0
    34
public:
sl@0
    35
	static CFileCache* NewL(CFileShare& aShare);
sl@0
    36
	CFileCache* ReNewL(CFileShare& aShare);
sl@0
    37
	~CFileCache();
sl@0
    38
	void Init(CFileShare& aShare);
sl@0
    39
sl@0
    40
	CMountCB& Mount() const;
sl@0
    41
sl@0
    42
	CFileCB* FileCB();
sl@0
    43
sl@0
    44
	void ReadAhead(CFsMessageRequest& aMsgRequest, TUint aMode);
sl@0
    45
	void ResetReadAhead();
sl@0
    46
sl@0
    47
	static TInt CompleteRead(CFsRequest* aMsgRequest);
sl@0
    48
	static TInt CompleteWrite(CFsRequest* aMsgRequest);
sl@0
    49
	TInt ReadBuffered(CFsMessageRequest& aMsgRequest, TUint aMode);
sl@0
    50
	TInt WriteBuffered(CFsMessageRequest& aMsgRequest, TUint aMode);
sl@0
    51
sl@0
    52
	inline TBool IsDirty() {return iDirtyDataOwner != NULL;}
sl@0
    53
	TInt FlushDirty(CFsRequest* aOldRequest = NULL);
sl@0
    54
	void Purge(TBool aPurgeDirty = EFalse);
sl@0
    55
sl@0
    56
	// from CFsObject
sl@0
    57
	void Close();
sl@0
    58
sl@0
    59
	inline TInt64 Size64() const {return iSize64;}
sl@0
    60
	
sl@0
    61
	// Sets 64 bit (cached) file size
sl@0
    62
	void SetSize64(TInt64 aSize);
sl@0
    63
	
sl@0
    64
	TDrive& Drive() const;
sl@0
    65
	TUint32 NameHash() const;
sl@0
    66
	HBufC& FileNameF() const;
sl@0
    67
sl@0
    68
    void MarkFileClean();
sl@0
    69
sl@0
    70
private:
sl@0
    71
	void ConstructL(CFileShare& aShare);
sl@0
    72
	CFileCache();
sl@0
    73
	
sl@0
    74
	void SetFileCacheFlags(CFileShare& aShare);
sl@0
    75
sl@0
    76
	TInt DoReadBuffered(CFsMessageRequest& aMsgRequest, TUint aMode, CFsClientMessageRequest*& aNewRequest);
sl@0
    77
	TInt DoWriteBuffered(CFsMessageRequest& aMsgRequest, CFsClientMessageRequest*& aNewRequest, TUint aMode);
sl@0
    78
	TInt DoFlushDirty(CFsClientMessageRequest*& aNewRequest, CFsRequest* aOldRequest, TBool aFlushAll);
sl@0
    79
sl@0
    80
sl@0
    81
	inline TInt SegmentSize() const;
sl@0
    82
	inline TInt SegmentSizeLog2() const;
sl@0
    83
	inline TInt64 SegmentSizeMask() const;
sl@0
    84
sl@0
    85
	inline void UpdateSharePosition(CFsMessageRequest& aMsgRequest, TMsgOperation& aCurrentOperation);
sl@0
    86
sl@0
    87
	static TInt CompleteFlushDirty(CFsRequest* aMsgRequest);
sl@0
    88
	TInt FlushDirtySm(CFsMessageRequest& aMsgRequest);
sl@0
    89
sl@0
    90
	TInt AllocateRequest(CFsClientMessageRequest*& aNewRequest, TBool aWrite, CSessionFs* aSession = NULL);
sl@0
    91
sl@0
    92
	void DoReadAhead(CFsMessageRequest& aMsgRequest, TUint aMode);
sl@0
    93
sl@0
    94
	void FileDirty(CFsMessageRequest& aMsgRequest);
sl@0
    95
	
sl@0
    96
    
sl@0
    97
	
sl@0
    98
    TInt HandleWriteDirtyError(TInt aError);
sl@0
    99
	void PropagateFlushErrorToAllFileShares();
sl@0
   100
sl@0
   101
	static TInt ClosedTimerEvent(TAny* aFileCache);
sl@0
   102
	static TInt DirtyTimerEvent(TAny* aFileCache);
sl@0
   103
sl@0
   104
	TBool IsDriveThread();
sl@0
   105
	
sl@0
   106
private:
sl@0
   107
sl@0
   108
	CCacheClient* iCacheClient;
sl@0
   109
sl@0
   110
	TInt iMaxReadAheadLen;
sl@0
   111
	TInt iCacheSize;
sl@0
   112
sl@0
   113
	TInt32 iClosedFileKeepAliveTime;	// in microseconds
sl@0
   114
	TInt32 iDirtyDataFlushTime;			// in microseconds
sl@0
   115
sl@0
   116
	CFileCB* iFileCB;
sl@0
   117
	
sl@0
   118
	RFastLock iLock;
sl@0
   119
sl@0
   120
	TInt iFlushError;
sl@0
   121
	TBool iFlushBusy;
sl@0
   122
sl@0
   123
	CDriveThread* iDriveThread;
sl@0
   124
	TInt iDriveNum;
sl@0
   125
	
sl@0
   126
	// closed queue eject timer
sl@0
   127
	TThreadTimer iClosedTimer;
sl@0
   128
sl@0
   129
	// dirty data flush timer
sl@0
   130
	TThreadTimer iDirtyTimer;
sl@0
   131
	// The last session writing to this file. If non-NULL indicates cache contains dirty data
sl@0
   132
	CSessionFs* iDirtyDataOwner;
sl@0
   133
	
sl@0
   134
	// The size of the file.
sl@0
   135
	TInt64 iSize64;
sl@0
   136
	
sl@0
   137
	// The size of the file at the start of a write request
sl@0
   138
	TInt64 iInitialSize;
sl@0
   139
	
sl@0
   140
	// The full name of the file, including drive and extensions - Folded. This is "stolen" 
sl@0
   141
	// from the owning CFileCB when the CFileCB destructor calls CFileCache::Close().
sl@0
   142
	HBufC* iFileNameF;
sl@0
   143
sl@0
   144
	TUint32	iNameHash;
sl@0
   145
sl@0
   146
	TDrive* iDrive;
sl@0
   147
sl@0
   148
	CMountCB* iMount;
sl@0
   149
sl@0
   150
	// Read-ahead 
sl@0
   151
	TInt iSequentialReads;
sl@0
   152
	TInt iReadAheadLen;
sl@0
   153
	TInt64 iReadAheadPos;
sl@0
   154
	TInt64 iLastReadPos;
sl@0
   155
	TInt iLastReadLen;
sl@0
   156
	TBool iFileCacheReadAsync;
sl@0
   157
	CFsClientMessageRequest* iReadAheadRequest;
sl@0
   158
sl@0
   159
	friend class TClosedFileUtils;
sl@0
   160
	friend class TFsFileWriteDirty;
sl@0
   161
	};
sl@0
   162
sl@0
   163
sl@0
   164
class TFileCacheSettings
sl@0
   165
	{
sl@0
   166
public:
sl@0
   167
	class TFileCacheConfig
sl@0
   168
		{
sl@0
   169
	public:
sl@0
   170
		TFileCacheConfig(TInt aDrive);
sl@0
   171
		static TFileCacheFlags ConvertEnumToFlags(const TInt aFileCacheRead, const TInt aFileCacheReadAhead, const TInt aFileCacheWrite);
sl@0
   172
	public:
sl@0
   173
		TInt iDrive;
sl@0
   174
		TFileCacheFlags iFlags;
sl@0
   175
sl@0
   176
		TBool iFileCacheReadAsync;
sl@0
   177
		TInt32 iFairSchedulingLen;			// in bytes
sl@0
   178
		TInt32 iCacheSize;					// in bytes
sl@0
   179
		TInt32 iMaxReadAheadLen;			// in bytes
sl@0
   180
		TInt32 iClosedFileKeepAliveTime;	// in microseconds
sl@0
   181
		TInt32 iDirtyDataFlushTime;			// in microseconds
sl@0
   182
		};
sl@0
   183
sl@0
   184
public:
sl@0
   185
	static TInt ReadPropertiesFile(TInt aDriveNumber);
sl@0
   186
	static void SetFlags(TInt aDrive, TFileCacheFlags alags);
sl@0
   187
	static TFileCacheFlags Flags(TInt aDrive);
sl@0
   188
sl@0
   189
sl@0
   190
	static TInt FileCacheReadAsync(TInt aDrive);
sl@0
   191
	static TInt FairSchedulingLen(TInt aDrive);
sl@0
   192
	static TInt MaxReadAheadLen(TInt aDrive);
sl@0
   193
	static TInt CacheSize(TInt aDrive);
sl@0
   194
	static TInt ClosedFileKeepAliveTime(TInt aDrive);
sl@0
   195
	static TInt DirtyDataFlushTime(TInt aDrive);
sl@0
   196
	static TInt GetFileCacheConfig(TInt aDrive, TFileCacheConfig*& aConfig);
sl@0
   197
private:
sl@0
   198
	static void Init();
sl@0
   199
	static void ReadEnum(const TDesC8& aSection, const TDesC8& aProperty, TInt32& aEnumVal, const TPtrC8* aEnumStrings);
sl@0
   200
sl@0
   201
private:
sl@0
   202
	static RArray<TFileCacheConfig>* iFileCacheSettings;
sl@0
   203
	};
sl@0
   204
sl@0
   205
sl@0
   206
class TClosedFileUtils
sl@0
   207
	{
sl@0
   208
public:
sl@0
   209
	static void InitL();
sl@0
   210
sl@0
   211
	static TInt Count();
sl@0
   212
	static CFileCache* At(TInt aIndex);
sl@0
   213
	static TBool IsClosed(CFileCache* aFileCache);
sl@0
   214
sl@0
   215
	static void AddL(CFileCache* aFileCache, TBool aLock);
sl@0
   216
sl@0
   217
	static void Remove();
sl@0
   218
	static void Remove(TInt aDrvNumber);
sl@0
   219
	static void Remove(CFileCache* aFileCache);
sl@0
   220
sl@0
   221
	static void Lock();
sl@0
   222
	static void Unlock();
sl@0
   223
sl@0
   224
	static void ReOpen(CFileCache* aFileCache, TBool aLock);
sl@0
   225
private:
sl@0
   226
	typedef TBool (*TTestFunc)(CFileCache& aFileCache, TAny* aVal);
sl@0
   227
	static void RemoveFiles(TTestFunc aTestFunc, TAny* aTestVal);
sl@0
   228
sl@0
   229
	static TBool TestDrive(CFileCache& aFileCache, TAny* aVal);
sl@0
   230
	static TBool TestFile(CFileCache& aFileCache, TAny* aVal);
sl@0
   231
sl@0
   232
private:
sl@0
   233
	static CFsObjectCon* iClosedFiles;
sl@0
   234
	};
sl@0
   235
sl@0
   236
sl@0
   237
sl@0
   238
#endif