userlibandfileserver/fileserver/srofs/sr_rofs.h
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include <e32std.h>
       
    18 #include <f32fsys.h>
       
    19 #include <f32ver.h>
       
    20 #include <e32rom.h>
       
    21 #include <rofs.h>
       
    22 #include <f32dbg.h>
       
    23 
       
    24 IMPORT_C TUint32 DebugRegister();
       
    25 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
       
    26 #define __LOCK_SR_STD__
       
    27 #define __PRINT(t)			{if (DebugRegister()&KROFS) RDebug::Print(t);}
       
    28 #define __PRINT1(t,d)		{if (DebugRegister()&KROFS) RDebug::Print(t,d);}
       
    29 #define __PRINT2(t,d,d1)	{if (DebugRegister()&KROFS) RDebug::Print( t, d , d1);}
       
    30 #else
       
    31 #define __PRINT(t)
       
    32 #define __PRINT1(t,d)
       
    33 #define __PRINT2(t,d,d1)
       
    34 #endif
       
    35 
       
    36 //
       
    37 
       
    38 #define _USE_TRUE_LRU_CACHE
       
    39 
       
    40 const TUint KFileHidden = 0xFFFFFFFF;
       
    41 
       
    42 class CRofs : public CFileSystem
       
    43 	{
       
    44 public:
       
    45 	enum TPanic
       
    46 		{
       
    47 		EPanicEntryNotDir,
       
    48 		EPanicNullSubDir,
       
    49 		EPanicNullFileBlock,
       
    50 		EPanicNullFileBlock2,
       
    51 		EPanicEntryBeforeDirectory,
       
    52 		EPanicEntryAfterDirectory,
       
    53 		EPanicBadMatchName,
       
    54 		EPanicRemountNotSupported,
       
    55 		EPanicGetFileInfo,
       
    56 		EPanicFileTooBig,
       
    57 		EPanicReadUid,
       
    58 		EPanicDirCacheNull,
       
    59 		EPanicDriveInfo
       
    60 		};
       
    61 	static void Panic( TPanic aPanic );
       
    62 
       
    63 public:
       
    64 	CRofs();
       
    65 	~CRofs();
       
    66 	
       
    67 	static CRofs* New();
       
    68 
       
    69 	TInt Install();
       
    70 	CMountCB* NewMountL() const;
       
    71 	CFileCB* NewFileL() const;
       
    72 	CDirCB* NewDirL() const;
       
    73 	CFormatCB* NewFormatL() const;
       
    74 
       
    75 	void DriveInfo(TDriveInfo& anInfo,TInt aDriveNumber) const;
       
    76 	TInt DefaultPath(TDes& aPath) const;
       
    77 	TInt TotalSupportedDrives() const;
       
    78 	TBool IsExtensionSupported() const{	return(ETrue);};
       
    79 private:
       
    80 	TInt	iTotalSupportedDrives;
       
    81 	};
       
    82 
       
    83 
       
    84 class CRofsMountCB;
       
    85 class CDirectoryCache : public CBase
       
    86 	{
       
    87 	public:
       
    88 		CDirectoryCache( CRofsMountCB& aMount, CProxyDrive& aLocalDrive, const TRofsHeader& aHeader );
       
    89 		~CDirectoryCache();
       
    90 	
       
    91 		void ConstructL();
       
    92 
       
    93 		void FindLeafDirL(const TDesC& aName, const TRofsDir*& aDir) const;
       
    94 		void FindFileEntryL(const TDesC& aName, const TRofsEntry*& aEntry) const;
       
    95 		void FindDirectoryEntryL(const TDesC& aName, const TRofsDir*& aDir) const;
       
    96 		void GetNextMatchingL(const TDesC& aName, TUint aAtt, const TRofsDir*& aDir, const TRofsEntry*& aEntry, TInt aError, TBool bUseBinarySearch) const;
       
    97 		void FindGeneralEntryL(const TDesC& aName, TUint aAtt, const TRofsDir*& aDir, const TRofsEntry*& aEntry ) const;
       
    98 
       
    99 		static inline const TText* NameAddress( const TRofsEntry* aEntry );
       
   100 		TUint8 GetMountId(void);
       
   101 
       
   102 	private:
       
   103 		CDirectoryCache();
       
   104 		static inline TUint32 AlignUp( TUint32 aValue );
       
   105 		inline const TRofsDir* RootDirectory() const;
       
   106 		inline const TRofsDir* RofsDirFromMediaOffset( TUint aMediaOffset ) const;
       
   107 		inline const TRofsDir* RofsDirFromSubDirEntry( const TRofsEntry* aEntry ) const;
       
   108 		static inline const TRofsEntry* FirstSubDirEntryFromDir( const TRofsDir* aDir );
       
   109 		inline const TRofsEntry* FirstFileEntryFromDir( const TRofsDir* aDir ) const;
       
   110 		inline const TAny* EndOfFileBlockPlusOne( const TRofsDir* aDir ) const;
       
   111 		inline const TAny* EndOfDirPlusOne( const TRofsDir* aDir ) const;
       
   112 		static inline const TRofsEntry* NextEntry( const TRofsEntry* aEntry );
       
   113 
       
   114 		TInt DoFindSubDir(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
       
   115 		TInt DoFindFile(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
       
   116 
       
   117 		TInt DoBinaryFindSubDir(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
       
   118 		TInt DoBinaryFindFile(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const;
       
   119 
       
   120 		TInt GetDirCount(const TRofsDir* aDir) const;
       
   121 		TInt GetFileCount(const TRofsDir* aDir) const;
       
   122 		TInt Compare(const TDesC& aLeft, const TDesC& aRight) const;
       
   123 		TInt ExtractMangleInfo(const TDesC& searchName, TUint8 &MountId, TUint8 &Reserved) const;
       
   124 	private:
       
   125 		CRofsMountCB&	iMount;
       
   126 		CProxyDrive&	iLocalDrive;
       
   127 		const TUint		iTreeMediaOffset;
       
   128 		const TUint		iTreeSize;
       
   129 		const TUint		iFilesMediaOffset;
       
   130 		const TUint		iFilesSize;
       
   131 		HBufC8*	iTreeBuffer;
       
   132 		HBufC8*	iFilesBuffer;
       
   133 	};
       
   134 
       
   135 class CRofsFileCB;
       
   136 /**
       
   137 
       
   138 */
       
   139 class CRofsLruCache;
       
   140 class CRofsMountCB : public CLocDrvMountCB, public CMountCB::MFileAccessor
       
   141 	{
       
   142 public:
       
   143 	CRofsMountCB();
       
   144 	void MountL(TBool aForceMount);
       
   145 	TInt ReMount();
       
   146 	void Dismounted();
       
   147 	void VolumeL(TVolumeInfo& aVolume) const;
       
   148 	void SetVolumeL(TDes& aName);
       
   149 	void MkDirL(const TDesC& aName);
       
   150 	void RmDirL(const TDesC& aName);
       
   151 	void DeleteL(const TDesC& aName);
       
   152 	void RenameL(const TDesC& anOldName,const TDesC& anNewName);
       
   153 	void ReplaceL(const TDesC& anOldName,const TDesC& anNewName);
       
   154 	void EntryL(const TDesC& aName,TEntry& anEntry) const;
       
   155 	void SetEntryL(const TDesC& aName,const TTime& aTime,TUint aMask,TUint aVal);
       
   156 	void FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile);
       
   157 	void DirOpenL(const TDesC& aName,CDirCB* aDir);
       
   158 	void RawReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt anOffset,const RMessagePtr2& aMessage) const;
       
   159 	void RawWriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt anOffset,const RMessagePtr2& aMessage);
       
   160 	void GetShortNameL(const TDesC& aLongName,TDes& aShortName);
       
   161 	void GetLongNameL(const TDesC& aShortName,TDes& aLongName);
       
   162 	void ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage);
       
   163 	void ReadUidL( TUint aMediaOffset, TEntry& aEntry, TRofsEntry* aRofsEntry) const;
       
   164 	inline CRofs& FileSystem() const;
       
   165 	virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
       
   166 	virtual TInt GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId);
       
   167 	virtual TInt Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2);
       
   168 	virtual TInt Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2);
       
   169 	virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2);
       
   170 
       
   171 #ifdef _USE_TRUE_LRU_CACHE
       
   172 	void CacheReadL(TInt aPos, TInt aLength, const TAny* aDes, TInt anOffset, const RMessagePtr2& aMessage) const;
       
   173 #endif
       
   174 	TUint8 iMountId;
       
   175 
       
   176 private:
       
   177 	TInt CheckHeader() const;
       
   178 	TInt CheckExtension();
       
   179 
       
   180 private:
       
   181 	TPckgBuf<TRofsHeader>	iHeader;
       
   182 	CDirectoryCache*	iDirectoryCache;
       
   183 	TInt64				iMediaSize;
       
   184 
       
   185 #ifdef _USE_TRUE_LRU_CACHE
       
   186  	CRofsLruCache*		iDataCache;
       
   187 #endif
       
   188 
       
   189 	};
       
   190 
       
   191 class CRofsFileCB : public CFileCB, public CFileCB::MBlockMapInterface, public CFileCB::MExtendedFileInterface
       
   192 	{
       
   193 public:
       
   194 	CRofsFileCB();
       
   195 	void RenameL(const TDesC& aNewName);
       
   196 	void ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
       
   197 	void WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
       
   198 	void SetSizeL(TInt aSize);
       
   199 	void SetEntryL(const TTime& aTime,TUint aMask,TUint aVal);
       
   200 	void FlushDataL();
       
   201 	void FlushAllL();
       
   202 	inline void SetMediaBase(const TUint aBase);
       
   203 	inline void SetAttExtra( TUint8 aAttExtra );
       
   204 	TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
       
   205 
       
   206 	// from CFileCB::MExtendedFileInterface
       
   207 	virtual void ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
       
   208 	virtual void WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
       
   209 	virtual void SetSizeL(TInt64 aSize);
       
   210 
       
   211 private:
       
   212 	inline CRofsMountCB& RofsMount();
       
   213 	TInt BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos);
       
   214 
       
   215 private:
       
   216 	TUint iMediaBase;
       
   217 	TUint8	iAttExtra;
       
   218 	};
       
   219 
       
   220 class CRofsDirCB : public CDirCB
       
   221 	{
       
   222 public:
       
   223 	CRofsDirCB();
       
   224 	~CRofsDirCB();
       
   225 	void ReadL(TEntry& anEntry);
       
   226 	void SetDir(const TRofsDir* aDir, const TDesC& aMatch, TInt64& aTimeStamp );
       
   227 	inline void SetCache( CDirectoryCache* aCache );
       
   228 private:
       
   229 	TBool MatchUid();
       
   230 private:
       
   231 	CDirectoryCache* iCache;
       
   232 	TEntry iEntry;
       
   233 	TTime	iTimeStamp;
       
   234 	const TRofsDir* iDir;
       
   235 	const TRofsEntry* iNext;
       
   236 	HBufC* iMatch;
       
   237 	};
       
   238 
       
   239 #ifdef _USE_TRUE_LRU_CACHE
       
   240 const TInt KSizeOfCacheInPages = 5;	// 5K Cache
       
   241 const TInt KSizeOfSegment = 1024;	//Two pages
       
   242 const TInt KPageSize = 512;
       
   243 
       
   244 class TCacheSegment
       
   245 	{
       
   246 public:
       
   247 	TCacheSegment();
       
   248 	void Set(TInt aPos);
       
   249 	TUint8* Data() {return(((TUint8*)this)+sizeof(TCacheSegment));}
       
   250 public:
       
   251 	TInt iPos;	
       
   252 	TDblQueLink iLink;
       
   253 	};
       
   254 
       
   255 //
       
   256 //Data cache for Rofs, (read only cache)
       
   257 //
       
   258 class CRofsLruCache: public CBase
       
   259 	{
       
   260 public:
       
   261 	~CRofsLruCache();
       
   262 	static CRofsLruCache* New(TInt aSegmentSize, CRofsMountCB* aMount, TInt64 aMediaSize);
       
   263 	TUint8* Find(TInt aPos , TInt aLength);
       
   264 	TUint8* ReadL(TInt aPos , TInt aLength);
       
   265 protected:
       
   266 	CRofsLruCache(CRofsMountCB* aMount, TInt64 aMediaSize);
       
   267 private:
       
   268 	TDblQue<TCacheSegment> iQue;
       
   269 	CRofsMountCB* iMount;
       
   270 	TInt64 iMediaSize;
       
   271 	};
       
   272 #endif
       
   273 
       
   274 
       
   275 #include "sr_rofs.inl"