userlibandfileserver/fileserver/sfat32/inc/sl_std.h
branchanywhere
changeset 41 d32f34975bbf
parent 36 538db54a451d
child 62 4a8fed1c0ef6
child 90 947f0dc9f7a8
--- a/userlibandfileserver/fileserver/sfat32/inc/sl_std.h	Mon Feb 01 19:40:00 2010 +0100
+++ b/userlibandfileserver/fileserver/sfat32/inc/sl_std.h	Mon Feb 01 19:49:38 2010 +0100
@@ -31,14 +31,17 @@
 #include <f32ver.h>
 #include <e32svr.h>
 #include <kernel/localise.h>
+
 #include "filesystem_fat.h"
+using namespace FileSystem_FAT;
 
 #include "common_constants.h"
 #include "sl_bpb.h"
 #include "fat_config.h"
 #include "fat_dir_entry.h"
+#include "bit_vector.h"
 
-using namespace FileSystem_FAT;
+
 
 #ifdef _DEBUG
 _LIT(KThisFsyName,"EFAT32.FSY"); ///< This FSY name
@@ -79,7 +82,7 @@
     This class can't be instantinated by user; only CFatMountCB can do this; see CFatMountCB::DriveInterface()
 
 */
-class TFatDriveInterface
+class TDriveInterface
     {
 public:
 	enum TAction {ERetry=1};
@@ -106,9 +109,9 @@
 
 
 protected:
-    TFatDriveInterface();
-    TFatDriveInterface(const TFatDriveInterface&);
-    TFatDriveInterface& operator=(const TFatDriveInterface&);
+    TDriveInterface();
+    TDriveInterface(const TDriveInterface&);
+    TDriveInterface& operator=(const TDriveInterface&);
 
     TBool Init(CFatMountCB* aMount);
     void Close(); 
@@ -138,7 +141,7 @@
         inline void EnterCriticalSection() const {iLock.Wait();}
         inline void LeaveCriticalSection() const {iLock.Signal();}
 
-        //-- methods' wrappers that are used by TFatDriveInterface
+        //-- methods' wrappers that are used by TDriveInterface
         TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const;
         TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg) const;
         TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset);
@@ -243,15 +246,14 @@
     inline TInt     SectorSizeLog2() const;
     inline TUint32  FreeClusters() const;
 
-	inline TBool IsEof32Bit(TInt aCluster) const;
-	inline TBool IsEof16Bit(TInt aCluster) const;
-	inline TBool IsEof12Bit(TInt aCluster) const;
-	
+    inline TBool IsEndOfClusterCh(TUint32 aCluster) const;
+
 
     inline TFatType FatType() const;
     inline TBool IsFat12() const;
     inline TBool IsFat16() const;
     inline TBool IsFat32() const;
+    
 
     inline TBool ClusterNumberValid(TUint32 aClusterNo) const;
 
@@ -269,6 +271,7 @@
     TUint32  iFreeClusters;     ///< Number of free cluster in the fat table
 	TUint32  iFreeClusterHint;  ///< this is just a hint to the free cluster number, not required to contain exact information.
 	TFatType iFatType;          ///< FAT type 12/16/32, cached from the iOwner
+    TUint32  iFatEocCode;       ///< End Of Cluster Chain code, 0xff8 for FAT12, 0xfff8 for FAT16, and 0xffffff8 for FAT32 
     TUint32  iMaxEntries;       ///< maximal number of FAT entries in the table. This value is taken from the CFatMount that calculates it
 
     };
@@ -487,15 +490,15 @@
     TInt IsFinalised(TBool& aFinalised);
 
     /** 
-        A wrapper around TFatDriveInterface providing its instantination and destruction.
+        A wrapper around TDriveInterface providing its instantination and destruction.
         You must not create objects of this class, use DriveInterface() instead.
     */
-    class XDriveInterface: public TFatDriveInterface
+    class XDriveInterface: public TDriveInterface
         {
       public:
-        XDriveInterface() : TFatDriveInterface() {}
+        XDriveInterface() : TDriveInterface() {}
         ~XDriveInterface() {Close();}
-        TBool Init(CFatMountCB* aMount) {return TFatDriveInterface::Init(aMount);}
+        TBool Init(CFatMountCB* aMount) {return TDriveInterface::Init(aMount);}
         };
 
 
@@ -543,7 +546,11 @@
 	
     inline TBool IsRootDir(const TEntryPos &aEntry) const;
 	inline CAsyncNotifier* Notifier() const;
-	inline TFatDriveInterface& DriveInterface() const;
+	inline TDriveInterface& DriveInterface() const;
+
+    inline TBool IsEndOfClusterCh(TInt aCluster) const;
+	inline void SetEndOfClusterCh(TInt &aCluster) const;
+
     
     void ReadUidL(TInt aCluster,TEntry& anEntry) const;
 	
@@ -567,9 +574,8 @@
 	void FindDosNameL(const TDesC& aName,TUint anAtt,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName,TInt anError) const;
 	
 	void Dismount();
-	TBool IsEndOfClusterCh(TInt aCluster) const;
-	void SetEndOfClusterCh(TInt &aCluster) const;
-	void InitializeRootEntry(TFatDirEntry & anEntry) const;
+	
+    void InitializeRootEntry(TFatDirEntry & anEntry) const;
 
     TInt64 MakeLinAddrL(const TEntryPos& aPos) const;
 	
@@ -711,14 +717,11 @@
     void    DoUpdateFSInfoSectorsL(TBool aInvalidateFSInfo);
     void    UnFinaliseMountL();
     void    DoReMountL();
+    void    SetFatType(TFatType aFatType);
+
 
 private:
 	
-    TBool ValidClusterNumber(TUint32 aCluster) const;
-    void  CheckUnvisitedClustersL(const RBitVector& aFatBitVec) const;
-	TInt  WalkClusterListL(RBitVector& aFatBitVec, TInt aCluster);
-	void  ChkEntryL(RBitVector& aFatBitVec, const TFatDirEntry& anEntry);
-	void  ChkDirL(RBitVector& aFatBitVec, TInt aDirCluster);
 
 	CFatMountCB();
 
@@ -734,7 +737,9 @@
     TBool iMainBootSecValid : 1;///< true if the main boot sector is valid, if false, a backup boot sector may be in use. 
 
     TFatMntState iState;        ///< this mounnt internal state
+
     TFatType iFatType;          ///< FAT type, FAT12,16 or 32
+    TUint32  iFatEocCode;       ///< End Of Cluster Chain code, 0xff8 for FAT12, 0xfff8 for FAT16, and 0xffffff8 for FAT32 
 
     CLeafDirCache* iLeafDirCache;	///< A cache for most recently visited directories, only valid when limit is set bigger than 1
     HBufC* iLastLeafDir;        	///< The last visited directory, only valid when limit of iLeafDirCache is less than 1 
@@ -779,7 +784,7 @@
 
 friend class CFatFormatCB;
 friend class CScanDrive;
-friend class TFatDriveInterface;
+friend class TDriveInterface;
 	};
 
 
@@ -841,13 +846,12 @@
 
 	TUint32* iSeekIndex;    ///< Seek index into file
 	TInt iSeekIndexSize;    ///< size of seek index
-	TBool iAttPending;
 	TInt iStartCluster;     ///< Start cluster number of file
 	TEntryPos iCurrentPos;  ///< Current position in file data
 	TEntryPos iFileDirPos;  ///< File directory entry position
 	TBool iFileSizeModified; 
 	};
-//
+
 
 /**
 Fat file system directory subsession implmentation, provides all that is required of a plug in
@@ -963,7 +967,6 @@
 	CFileCB* NewFileL() const;
 	CDirCB* NewDirL() const;
 	CFormatCB* NewFormatL() const;
-	void DriveInfo(TDriveInfo& anInfo,TInt aDriveNumber) const;
 	TInt DefaultPath(TDes& aPath) const;
 	TBool IsExtensionSupported() const;
 	TBool GetUseLocalTime() const;
@@ -996,26 +999,6 @@
 	};
 //
 
-TPtrC RemoveTrailingDots(const TDesC& aName);
-
-/**
-Indicates if a number passed in is a power of two
-@return ETrue if aVal is a power of 2 
-*/
-inline TBool IsPowerOf2(TUint32 aVal);
-
-/**
-Calculates the log2 of a number
-
-@param aNum Number to calulate the log two of
-@return The log two of the number passed in
-*/
-TUint32 Log2(TUint32 aVal);
-
-/** @return 2^aVal*/
-inline TUint32 Pow2(TUint32 aVal);
-
-
 /**
 Converts Dos time (from a directory entry) to TTime format
 
@@ -1073,103 +1056,7 @@
 */
 TUint8 CalculateShortNameCheckSum(const TDesC8& aShortName);
 
-
-
-
-//-----------------------------------------------------------------------------
-
-/**
-    This class represents a bit vector i.e. an array of bits. Vector size can be 1..2^32 bits.
-*/
-class RBitVector
-    {
- public:
-    
-    RBitVector(); //-- Creates an empty vector. see Create() methods for memory allocation
-   ~RBitVector(); 
-    
-    void Close(); 
-    
-    TInt Create(TUint32 aNumBits);
-    void CreateL(TUint32 aNumBits);
-
-    inline TUint32 Size() const;
-
-    //-- single bit manipulation methods
-    inline TBool operator[](TUint32 aIndex) const;
-    inline void SetBit(TUint32 aIndex);
-    inline void ResetBit(TUint32 aIndex);
-    inline void InvertBit(TUint32 aIndex);
-    inline void SetBitVal(TUint32 aIndex, TBool aVal);
-    
-    void Fill(TBool aVal);
-    void Fill(TUint32 aIndexFrom, TUint32 aIndexTo, TBool aVal);
-
-    void Invert();
-   
-    TBool operator==(const RBitVector& aRhs) const; 
-    TBool operator!=(const RBitVector& aRhs) const;
-
-    //-- logical operations between 2 vectors. 
-    void And(const RBitVector& aRhs);
-    void Or (const RBitVector& aRhs);
-    void Xor(const RBitVector& aRhs);
-
-    TBool Diff(const RBitVector& aRhs, TUint32& aDiffIndex) const;
-
-    /** Bit search specifiers */
-    enum TFindDirection
-        {
-        ELeft,      ///< Search from the given position to the left (towards lower index)
-        ERight,     ///< Search from the given position to the right (towards higher index)
-        ENearestL,  ///< Search in both directions starting from the given position; in the case of the equal distances return the position to the left
-        ENearestR   ///< Search in both directions starting from the given position; in the case of the equal distances return the position to the right
-
-        //-- N.B the current position the search starts with isn't included to the search.
-        };
-
-    TBool Find(TUint32& aStartPos, TBool aBitVal, TFindDirection aDir) const;
-
-    /** panic codes */
-    enum TPanicCode
-        {
-        EIndexOutOfRange,       ///< index out of range
-        EWrondFindDirection,    ///< a value doesn't belong to TFindDirection
-        ESizeMismatch,          ///< Size mismatch for binary operators
-        ENotInitialised,        ///< No memory allocated for the array
-        ENotImplemented,        ///< functionality isn't implemented
-        };
-
- protected:
-    
-    //-- these are outlawed. Can't use them because memory allocator can leave and we don't have conthrol on it  in these methods. 
-    RBitVector(const RBitVector& aRhs);            
-    RBitVector& operator=(const RBitVector& aRhs); 
-  
-    void Panic(TPanicCode aPanicCode) const;
-
-    inline TUint32 WordNum(TUint32 aBitPos)  const;
-    inline TUint32 BitInWord(TUint32 aBitPos) const;
-
- private:
-    TBool FindToRight(TUint32& aStartPos, TBool aBitVal) const;
-    TBool FindToLeft (TUint32& aStartPos, TBool aBitVal) const;
-    TBool FindNearest(TUint32& aStartPos, TBool aBitVal, TBool aToLeft) const;
-   
-    inline TUint32 MaskLastWord(TUint32 aVal) const; 
-    inline TBool ItrLeft(TUint32& aIdx) const;
-    inline TBool ItrRight(TUint32& aIdx) const;
-
-
- protected:
-
-    TUint32   iNumBits; ///< number of bits in the vector
-    TUint32*  ipData;   ///< pointer to the data 
-    TUint32   iNumWords;///< number of 32-bit words that store bits
-    };
-
-
-//-----------------------------------------------------------------------------
+TUint32 EocCodeByFatType(TFatType aFatType);
 
 
 #include "sl_std.inl"