sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: IMPORT_C TUint32 DebugRegister(); sl@0: #if defined(_DEBUG) || defined(_DEBUG_RELEASE) sl@0: #define __LOCK_SR_STD__ sl@0: #define __PRINT(t) {if (DebugRegister()&KROFS) RDebug::Print(t);} sl@0: #define __PRINT1(t,d) {if (DebugRegister()&KROFS) RDebug::Print(t,d);} sl@0: #define __PRINT2(t,d,d1) {if (DebugRegister()&KROFS) RDebug::Print( t, d , d1);} sl@0: #else sl@0: #define __PRINT(t) sl@0: #define __PRINT1(t,d) sl@0: #define __PRINT2(t,d,d1) sl@0: #endif sl@0: sl@0: // sl@0: sl@0: #define _USE_TRUE_LRU_CACHE sl@0: sl@0: const TUint KFileHidden = 0xFFFFFFFF; sl@0: sl@0: class CRofs : public CFileSystem sl@0: { sl@0: public: sl@0: enum TPanic sl@0: { sl@0: EPanicEntryNotDir, sl@0: EPanicNullSubDir, sl@0: EPanicNullFileBlock, sl@0: EPanicNullFileBlock2, sl@0: EPanicEntryBeforeDirectory, sl@0: EPanicEntryAfterDirectory, sl@0: EPanicBadMatchName, sl@0: EPanicRemountNotSupported, sl@0: EPanicGetFileInfo, sl@0: EPanicFileTooBig, sl@0: EPanicReadUid, sl@0: EPanicDirCacheNull, sl@0: EPanicDriveInfo sl@0: }; sl@0: static void Panic( TPanic aPanic ); sl@0: sl@0: public: sl@0: CRofs(); sl@0: ~CRofs(); sl@0: sl@0: static CRofs* New(); sl@0: sl@0: TInt Install(); sl@0: CMountCB* NewMountL() const; sl@0: CFileCB* NewFileL() const; sl@0: CDirCB* NewDirL() const; sl@0: CFormatCB* NewFormatL() const; sl@0: sl@0: void DriveInfo(TDriveInfo& anInfo,TInt aDriveNumber) const; sl@0: TInt DefaultPath(TDes& aPath) const; sl@0: TInt TotalSupportedDrives() const; sl@0: TBool IsExtensionSupported() const{ return(ETrue);}; sl@0: private: sl@0: TInt iTotalSupportedDrives; sl@0: }; sl@0: sl@0: sl@0: class CRofsMountCB; sl@0: class CDirectoryCache : public CBase sl@0: { sl@0: public: sl@0: CDirectoryCache( CRofsMountCB& aMount, CProxyDrive& aLocalDrive, const TRofsHeader& aHeader ); sl@0: ~CDirectoryCache(); sl@0: sl@0: void ConstructL(); sl@0: sl@0: void FindLeafDirL(const TDesC& aName, const TRofsDir*& aDir) const; sl@0: void FindFileEntryL(const TDesC& aName, const TRofsEntry*& aEntry) const; sl@0: void FindDirectoryEntryL(const TDesC& aName, const TRofsDir*& aDir) const; sl@0: void GetNextMatchingL(const TDesC& aName, TUint aAtt, const TRofsDir*& aDir, const TRofsEntry*& aEntry, TInt aError, TBool bUseBinarySearch) const; sl@0: void FindGeneralEntryL(const TDesC& aName, TUint aAtt, const TRofsDir*& aDir, const TRofsEntry*& aEntry ) const; sl@0: sl@0: static inline const TText* NameAddress( const TRofsEntry* aEntry ); sl@0: TUint8 GetMountId(void); sl@0: sl@0: private: sl@0: CDirectoryCache(); sl@0: static inline TUint32 AlignUp( TUint32 aValue ); sl@0: inline const TRofsDir* RootDirectory() const; sl@0: inline const TRofsDir* RofsDirFromMediaOffset( TUint aMediaOffset ) const; sl@0: inline const TRofsDir* RofsDirFromSubDirEntry( const TRofsEntry* aEntry ) const; sl@0: static inline const TRofsEntry* FirstSubDirEntryFromDir( const TRofsDir* aDir ); sl@0: inline const TRofsEntry* FirstFileEntryFromDir( const TRofsDir* aDir ) const; sl@0: inline const TAny* EndOfFileBlockPlusOne( const TRofsDir* aDir ) const; sl@0: inline const TAny* EndOfDirPlusOne( const TRofsDir* aDir ) const; sl@0: static inline const TRofsEntry* NextEntry( const TRofsEntry* aEntry ); sl@0: sl@0: TInt DoFindSubDir(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const; sl@0: TInt DoFindFile(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const; sl@0: sl@0: TInt DoBinaryFindSubDir(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const; sl@0: TInt DoBinaryFindFile(const TDesC& aName, TUint aAtt, const TRofsDir* aDir, const TRofsEntry*& aEntry) const; sl@0: sl@0: TInt GetDirCount(const TRofsDir* aDir) const; sl@0: TInt GetFileCount(const TRofsDir* aDir) const; sl@0: TInt Compare(const TDesC& aLeft, const TDesC& aRight) const; sl@0: TInt ExtractMangleInfo(const TDesC& searchName, TUint8 &MountId, TUint8 &Reserved) const; sl@0: private: sl@0: CRofsMountCB& iMount; sl@0: CProxyDrive& iLocalDrive; sl@0: const TUint iTreeMediaOffset; sl@0: const TUint iTreeSize; sl@0: const TUint iFilesMediaOffset; sl@0: const TUint iFilesSize; sl@0: HBufC8* iTreeBuffer; sl@0: HBufC8* iFilesBuffer; sl@0: }; sl@0: sl@0: class CRofsFileCB; sl@0: /** sl@0: sl@0: */ sl@0: class CRofsLruCache; sl@0: class CRofsMountCB : public CLocDrvMountCB, public CMountCB::MFileAccessor sl@0: { sl@0: public: sl@0: CRofsMountCB(); sl@0: void MountL(TBool aForceMount); sl@0: TInt ReMount(); sl@0: void Dismounted(); sl@0: void VolumeL(TVolumeInfo& aVolume) const; sl@0: void SetVolumeL(TDes& aName); sl@0: void MkDirL(const TDesC& aName); sl@0: void RmDirL(const TDesC& aName); sl@0: void DeleteL(const TDesC& aName); sl@0: void RenameL(const TDesC& anOldName,const TDesC& anNewName); sl@0: void ReplaceL(const TDesC& anOldName,const TDesC& anNewName); sl@0: void EntryL(const TDesC& aName,TEntry& anEntry) const; sl@0: void SetEntryL(const TDesC& aName,const TTime& aTime,TUint aMask,TUint aVal); sl@0: void FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile); sl@0: void DirOpenL(const TDesC& aName,CDirCB* aDir); sl@0: void RawReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt anOffset,const RMessagePtr2& aMessage) const; sl@0: void RawWriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt anOffset,const RMessagePtr2& aMessage); sl@0: void GetShortNameL(const TDesC& aLongName,TDes& aShortName); sl@0: void GetLongNameL(const TDesC& aShortName,TDes& aLongName); sl@0: void ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage); sl@0: void ReadUidL( TUint aMediaOffset, TEntry& aEntry, TRofsEntry* aRofsEntry) const; sl@0: inline CRofs& FileSystem() const; sl@0: virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput); sl@0: virtual TInt GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId); sl@0: virtual TInt Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2); sl@0: virtual TInt Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2); sl@0: virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2); sl@0: sl@0: #ifdef _USE_TRUE_LRU_CACHE sl@0: void CacheReadL(TInt aPos, TInt aLength, const TAny* aDes, TInt anOffset, const RMessagePtr2& aMessage) const; sl@0: #endif sl@0: TUint8 iMountId; sl@0: sl@0: private: sl@0: TInt CheckHeader() const; sl@0: TInt CheckExtension(); sl@0: sl@0: private: sl@0: TPckgBuf iHeader; sl@0: CDirectoryCache* iDirectoryCache; sl@0: TInt64 iMediaSize; sl@0: sl@0: #ifdef _USE_TRUE_LRU_CACHE sl@0: CRofsLruCache* iDataCache; sl@0: #endif sl@0: sl@0: }; sl@0: sl@0: class CRofsFileCB : public CFileCB, public CFileCB::MBlockMapInterface, public CFileCB::MExtendedFileInterface sl@0: { sl@0: public: sl@0: CRofsFileCB(); sl@0: void RenameL(const TDesC& aNewName); sl@0: void ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage); sl@0: void WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage); sl@0: void SetSizeL(TInt aSize); sl@0: void SetEntryL(const TTime& aTime,TUint aMask,TUint aVal); sl@0: void FlushDataL(); sl@0: void FlushAllL(); sl@0: inline void SetMediaBase(const TUint aBase); sl@0: inline void SetAttExtra( TUint8 aAttExtra ); sl@0: TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput); sl@0: sl@0: // from CFileCB::MExtendedFileInterface sl@0: virtual void ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset); sl@0: virtual void WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset); sl@0: virtual void SetSizeL(TInt64 aSize); sl@0: sl@0: private: sl@0: inline CRofsMountCB& RofsMount(); sl@0: TInt BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos); sl@0: sl@0: private: sl@0: TUint iMediaBase; sl@0: TUint8 iAttExtra; sl@0: }; sl@0: sl@0: class CRofsDirCB : public CDirCB sl@0: { sl@0: public: sl@0: CRofsDirCB(); sl@0: ~CRofsDirCB(); sl@0: void ReadL(TEntry& anEntry); sl@0: void SetDir(const TRofsDir* aDir, const TDesC& aMatch, TInt64& aTimeStamp ); sl@0: inline void SetCache( CDirectoryCache* aCache ); sl@0: private: sl@0: TBool MatchUid(); sl@0: private: sl@0: CDirectoryCache* iCache; sl@0: TEntry iEntry; sl@0: TTime iTimeStamp; sl@0: const TRofsDir* iDir; sl@0: const TRofsEntry* iNext; sl@0: HBufC* iMatch; sl@0: }; sl@0: sl@0: #ifdef _USE_TRUE_LRU_CACHE sl@0: const TInt KSizeOfCacheInPages = 5; // 5K Cache sl@0: const TInt KSizeOfSegment = 1024; //Two pages sl@0: const TInt KPageSize = 512; sl@0: sl@0: class TCacheSegment sl@0: { sl@0: public: sl@0: TCacheSegment(); sl@0: void Set(TInt aPos); sl@0: TUint8* Data() {return(((TUint8*)this)+sizeof(TCacheSegment));} sl@0: public: sl@0: TInt iPos; sl@0: TDblQueLink iLink; sl@0: }; sl@0: sl@0: // sl@0: //Data cache for Rofs, (read only cache) sl@0: // sl@0: class CRofsLruCache: public CBase sl@0: { sl@0: public: sl@0: ~CRofsLruCache(); sl@0: static CRofsLruCache* New(TInt aSegmentSize, CRofsMountCB* aMount, TInt64 aMediaSize); sl@0: TUint8* Find(TInt aPos , TInt aLength); sl@0: TUint8* ReadL(TInt aPos , TInt aLength); sl@0: protected: sl@0: CRofsLruCache(CRofsMountCB* aMount, TInt64 aMediaSize); sl@0: private: sl@0: TDblQue iQue; sl@0: CRofsMountCB* iMount; sl@0: TInt64 iMediaSize; sl@0: }; sl@0: #endif sl@0: sl@0: sl@0: #include "sr_rofs.inl"