os/kernelhwsrv/userlibandfileserver/fileserver/srofs/sr_rofs.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/srofs/sr_rofs.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,275 @@
     1.4 +// Copyright (c) 1995-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 +//
    1.18 +
    1.19 +
    1.20 +#include <e32std.h>
    1.21 +#include <f32fsys.h>
    1.22 +#include <f32ver.h>
    1.23 +#include <e32rom.h>
    1.24 +#include <rofs.h>
    1.25 +#include <f32dbg.h>
    1.26 +
    1.27 +IMPORT_C TUint32 DebugRegister();
    1.28 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
    1.29 +#define __LOCK_SR_STD__
    1.30 +#define __PRINT(t)			{if (DebugRegister()&KROFS) RDebug::Print(t);}
    1.31 +#define __PRINT1(t,d)		{if (DebugRegister()&KROFS) RDebug::Print(t,d);}
    1.32 +#define __PRINT2(t,d,d1)	{if (DebugRegister()&KROFS) RDebug::Print( t, d , d1);}
    1.33 +#else
    1.34 +#define __PRINT(t)
    1.35 +#define __PRINT1(t,d)
    1.36 +#define __PRINT2(t,d,d1)
    1.37 +#endif
    1.38 +
    1.39 +//
    1.40 +
    1.41 +#define _USE_TRUE_LRU_CACHE
    1.42 +
    1.43 +const TUint KFileHidden = 0xFFFFFFFF;
    1.44 +
    1.45 +class CRofs : public CFileSystem
    1.46 +	{
    1.47 +public:
    1.48 +	enum TPanic
    1.49 +		{
    1.50 +		EPanicEntryNotDir,
    1.51 +		EPanicNullSubDir,
    1.52 +		EPanicNullFileBlock,
    1.53 +		EPanicNullFileBlock2,
    1.54 +		EPanicEntryBeforeDirectory,
    1.55 +		EPanicEntryAfterDirectory,
    1.56 +		EPanicBadMatchName,
    1.57 +		EPanicRemountNotSupported,
    1.58 +		EPanicGetFileInfo,
    1.59 +		EPanicFileTooBig,
    1.60 +		EPanicReadUid,
    1.61 +		EPanicDirCacheNull,
    1.62 +		EPanicDriveInfo
    1.63 +		};
    1.64 +	static void Panic( TPanic aPanic );
    1.65 +
    1.66 +public:
    1.67 +	CRofs();
    1.68 +	~CRofs();
    1.69 +	
    1.70 +	static CRofs* New();
    1.71 +
    1.72 +	TInt Install();
    1.73 +	CMountCB* NewMountL() const;
    1.74 +	CFileCB* NewFileL() const;
    1.75 +	CDirCB* NewDirL() const;
    1.76 +	CFormatCB* NewFormatL() const;
    1.77 +
    1.78 +	void DriveInfo(TDriveInfo& anInfo,TInt aDriveNumber) const;
    1.79 +	TInt DefaultPath(TDes& aPath) const;
    1.80 +	TInt TotalSupportedDrives() const;
    1.81 +	TBool IsExtensionSupported() const{	return(ETrue);};
    1.82 +private:
    1.83 +	TInt	iTotalSupportedDrives;
    1.84 +	};
    1.85 +
    1.86 +
    1.87 +class CRofsMountCB;
    1.88 +class CDirectoryCache : public CBase
    1.89 +	{
    1.90 +	public:
    1.91 +		CDirectoryCache( CRofsMountCB& aMount, CProxyDrive& aLocalDrive, const TRofsHeader& aHeader );
    1.92 +		~CDirectoryCache();
    1.93 +	
    1.94 +		void ConstructL();
    1.95 +
    1.96 +		void FindLeafDirL(const TDesC& aName, const TRofsDir*& aDir) const;
    1.97 +		void FindFileEntryL(const TDesC& aName, const TRofsEntry*& aEntry) const;
    1.98 +		void FindDirectoryEntryL(const TDesC& aName, const TRofsDir*& aDir) const;
    1.99 +		void GetNextMatchingL(const TDesC& aName, TUint aAtt, const TRofsDir*& aDir, const TRofsEntry*& aEntry, TInt aError, TBool bUseBinarySearch) const;
   1.100 +		void FindGeneralEntryL(const TDesC& aName, TUint aAtt, const TRofsDir*& aDir, const TRofsEntry*& aEntry ) const;
   1.101 +
   1.102 +		static inline const TText* NameAddress( const TRofsEntry* aEntry );
   1.103 +		TUint8 GetMountId(void);
   1.104 +
   1.105 +	private:
   1.106 +		CDirectoryCache();
   1.107 +		static inline TUint32 AlignUp( TUint32 aValue );
   1.108 +		inline const TRofsDir* RootDirectory() const;
   1.109 +		inline const TRofsDir* RofsDirFromMediaOffset( TUint aMediaOffset ) const;
   1.110 +		inline const TRofsDir* RofsDirFromSubDirEntry( const TRofsEntry* aEntry ) const;
   1.111 +		static inline const TRofsEntry* FirstSubDirEntryFromDir( const TRofsDir* aDir );
   1.112 +		inline const TRofsEntry* FirstFileEntryFromDir( const TRofsDir* aDir ) const;
   1.113 +		inline const TAny* EndOfFileBlockPlusOne( const TRofsDir* aDir ) const;
   1.114 +		inline const TAny* EndOfDirPlusOne( const TRofsDir* aDir ) const;
   1.115 +		static inline const TRofsEntry* NextEntry( const TRofsEntry* aEntry );
   1.116 +
   1.117 +		TInt DoFindSubDir(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
   1.118 +		TInt DoFindFile(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
   1.119 +
   1.120 +		TInt DoBinaryFindSubDir(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
   1.121 +		TInt DoBinaryFindFile(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
   1.122 +
   1.123 +		TInt GetDirCount(const TRofsDir* aDir) const;
   1.124 +		TInt GetFileCount(const TRofsDir* aDir) const;
   1.125 +		TInt Compare(const TDesC& aLeft, const TDesC& aRight) const;
   1.126 +		TInt ExtractMangleInfo(const TDesC& searchName, TUint8 &MountId, TUint8 &Reserved) const;
   1.127 +	private:
   1.128 +		CRofsMountCB&	iMount;
   1.129 +		CProxyDrive&	iLocalDrive;
   1.130 +		const TUint		iTreeMediaOffset;
   1.131 +		const TUint		iTreeSize;
   1.132 +		const TUint		iFilesMediaOffset;
   1.133 +		const TUint		iFilesSize;
   1.134 +		HBufC8*	iTreeBuffer;
   1.135 +		HBufC8*	iFilesBuffer;
   1.136 +	};
   1.137 +
   1.138 +class CRofsFileCB;
   1.139 +/**
   1.140 +
   1.141 +*/
   1.142 +class CRofsLruCache;
   1.143 +class CRofsMountCB : public CLocDrvMountCB, public CMountCB::MFileAccessor
   1.144 +	{
   1.145 +public:
   1.146 +	CRofsMountCB();
   1.147 +	void MountL(TBool aForceMount);
   1.148 +	TInt ReMount();
   1.149 +	void Dismounted();
   1.150 +	void VolumeL(TVolumeInfo& aVolume) const;
   1.151 +	void SetVolumeL(TDes& aName);
   1.152 +	void MkDirL(const TDesC& aName);
   1.153 +	void RmDirL(const TDesC& aName);
   1.154 +	void DeleteL(const TDesC& aName);
   1.155 +	void RenameL(const TDesC& anOldName,const TDesC& anNewName);
   1.156 +	void ReplaceL(const TDesC& anOldName,const TDesC& anNewName);
   1.157 +	void EntryL(const TDesC& aName,TEntry& anEntry) const;
   1.158 +	void SetEntryL(const TDesC& aName,const TTime& aTime,TUint aMask,TUint aVal);
   1.159 +	void FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile);
   1.160 +	void DirOpenL(const TDesC& aName,CDirCB* aDir);
   1.161 +	void RawReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt anOffset,const RMessagePtr2& aMessage) const;
   1.162 +	void RawWriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt anOffset,const RMessagePtr2& aMessage);
   1.163 +	void GetShortNameL(const TDesC& aLongName,TDes& aShortName);
   1.164 +	void GetLongNameL(const TDesC& aShortName,TDes& aLongName);
   1.165 +	void ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage);
   1.166 +	void ReadUidL( TUint aMediaOffset, TEntry& aEntry, TRofsEntry* aRofsEntry) const;
   1.167 +	inline CRofs& FileSystem() const;
   1.168 +	virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
   1.169 +	virtual TInt GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId);
   1.170 +	virtual TInt Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2);
   1.171 +	virtual TInt Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2);
   1.172 +	virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2);
   1.173 +
   1.174 +#ifdef _USE_TRUE_LRU_CACHE
   1.175 +	void CacheReadL(TInt aPos, TInt aLength, const TAny* aDes, TInt anOffset, const RMessagePtr2& aMessage) const;
   1.176 +#endif
   1.177 +	TUint8 iMountId;
   1.178 +
   1.179 +private:
   1.180 +	TInt CheckHeader() const;
   1.181 +	TInt CheckExtension();
   1.182 +
   1.183 +private:
   1.184 +	TPckgBuf<TRofsHeader>	iHeader;
   1.185 +	CDirectoryCache*	iDirectoryCache;
   1.186 +	TInt64				iMediaSize;
   1.187 +
   1.188 +#ifdef _USE_TRUE_LRU_CACHE
   1.189 + 	CRofsLruCache*		iDataCache;
   1.190 +#endif
   1.191 +
   1.192 +	};
   1.193 +
   1.194 +class CRofsFileCB : public CFileCB, public CFileCB::MBlockMapInterface, public CFileCB::MExtendedFileInterface
   1.195 +	{
   1.196 +public:
   1.197 +	CRofsFileCB();
   1.198 +	void RenameL(const TDesC& aNewName);
   1.199 +	void ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
   1.200 +	void WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
   1.201 +	void SetSizeL(TInt aSize);
   1.202 +	void SetEntryL(const TTime& aTime,TUint aMask,TUint aVal);
   1.203 +	void FlushDataL();
   1.204 +	void FlushAllL();
   1.205 +	inline void SetMediaBase(const TUint aBase);
   1.206 +	inline void SetAttExtra( TUint8 aAttExtra );
   1.207 +	TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
   1.208 +
   1.209 +	// from CFileCB::MExtendedFileInterface
   1.210 +	virtual void ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
   1.211 +	virtual void WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
   1.212 +	virtual void SetSizeL(TInt64 aSize);
   1.213 +
   1.214 +private:
   1.215 +	inline CRofsMountCB& RofsMount();
   1.216 +	TInt BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos);
   1.217 +
   1.218 +private:
   1.219 +	TUint iMediaBase;
   1.220 +	TUint8	iAttExtra;
   1.221 +	};
   1.222 +
   1.223 +class CRofsDirCB : public CDirCB
   1.224 +	{
   1.225 +public:
   1.226 +	CRofsDirCB();
   1.227 +	~CRofsDirCB();
   1.228 +	void ReadL(TEntry& anEntry);
   1.229 +	void SetDir(const TRofsDir* aDir, const TDesC& aMatch, TInt64& aTimeStamp );
   1.230 +	inline void SetCache( CDirectoryCache* aCache );
   1.231 +private:
   1.232 +	TBool MatchUid();
   1.233 +private:
   1.234 +	CDirectoryCache* iCache;
   1.235 +	TEntry iEntry;
   1.236 +	TTime	iTimeStamp;
   1.237 +	const TRofsDir* iDir;
   1.238 +	const TRofsEntry* iNext;
   1.239 +	HBufC* iMatch;
   1.240 +	};
   1.241 +
   1.242 +#ifdef _USE_TRUE_LRU_CACHE
   1.243 +const TInt KSizeOfCacheInPages = 5;	// 5K Cache
   1.244 +const TInt KSizeOfSegment = 1024;	//Two pages
   1.245 +const TInt KPageSize = 512;
   1.246 +
   1.247 +class TCacheSegment
   1.248 +	{
   1.249 +public:
   1.250 +	TCacheSegment();
   1.251 +	void Set(TInt aPos);
   1.252 +	TUint8* Data() {return(((TUint8*)this)+sizeof(TCacheSegment));}
   1.253 +public:
   1.254 +	TInt iPos;	
   1.255 +	TDblQueLink iLink;
   1.256 +	};
   1.257 +
   1.258 +//
   1.259 +//Data cache for Rofs, (read only cache)
   1.260 +//
   1.261 +class CRofsLruCache: public CBase
   1.262 +	{
   1.263 +public:
   1.264 +	~CRofsLruCache();
   1.265 +	static CRofsLruCache* New(TInt aSegmentSize, CRofsMountCB* aMount, TInt64 aMediaSize);
   1.266 +	TUint8* Find(TInt aPos , TInt aLength);
   1.267 +	TUint8* ReadL(TInt aPos , TInt aLength);
   1.268 +protected:
   1.269 +	CRofsLruCache(CRofsMountCB* aMount, TInt64 aMediaSize);
   1.270 +private:
   1.271 +	TDblQue<TCacheSegment> iQue;
   1.272 +	CRofsMountCB* iMount;
   1.273 +	TInt64 iMediaSize;
   1.274 +	};
   1.275 +#endif
   1.276 +
   1.277 +
   1.278 +#include "sr_rofs.inl"