userlibandfileserver/fileserver/sfat32/fat_table32.cpp
changeset 6 0173bcd7697c
parent 0 a41df078684a
child 8 538db54a451d
equal deleted inserted replaced
4:56f325a607ea 6:0173bcd7697c
    31 
    31 
    32 
    32 
    33 //---------------------------------------------------------------------------------------------------------------------------------------
    33 //---------------------------------------------------------------------------------------------------------------------------------------
    34 /** 
    34 /** 
    35     Implements automatic locking object.
    35     Implements automatic locking object.
    36     Calls TFatDriveInterface::AcquireLock() on construction and TFatDriveInterface::ReleaseLock() on destruction. 
    36     Calls TDriveInterface::AcquireLock() on construction and TDriveInterface::ReleaseLock() on destruction. 
    37     Can be constructed on the stack only.
    37     Can be constructed on the stack only.
    38 */
    38 */
    39 class XAutoLock
    39 class XAutoLock
    40     {
    40     {
    41      public:
    41      public:
    42        inline XAutoLock(CFatMountCB* apOwner) : iDrv(apOwner->DriveInterface()) {iDrv.AcquireLock();}
    42        inline XAutoLock(CFatMountCB* apOwner) : iDrv(apOwner->DriveInterface()) {iDrv.AcquireLock();}
    43        inline XAutoLock(TFatDriveInterface& aDrv) : iDrv(aDrv) {iDrv.AcquireLock();}
    43        inline XAutoLock(TDriveInterface& aDrv) : iDrv(aDrv) {iDrv.AcquireLock();}
    44        inline ~XAutoLock() {iDrv.ReleaseLock();}
    44        inline ~XAutoLock() {iDrv.ReleaseLock();}
    45 
    45 
    46      private:
    46      private:
    47         void* operator new(TUint); //-- disable creating objects on heap.
    47         void* operator new(TUint); //-- disable creating objects on heap.
    48         void* operator new(TUint, void*);
    48         void* operator new(TUint, void*);
    49 
    49 
    50      private:
    50      private:
    51         TFatDriveInterface &iDrv; ///< reference to the drive interface
    51         TDriveInterface &iDrv; ///< reference to the drive interface
    52     };
    52     };
    53 
    53 
    54 
    54 
    55 //---------------------------------------------------------------------------------------------------------------------------------------
    55 //---------------------------------------------------------------------------------------------------------------------------------------
    56 
    56 
   123     ASSERT(iOwner);
   123     ASSERT(iOwner);
   124 
   124 
   125     //-- get FAT type from the owner
   125     //-- get FAT type from the owner
   126     iFatType = iOwner->FatType();
   126     iFatType = iOwner->FatType();
   127     ASSERT(IsFat12() || IsFat16() || IsFat32());
   127     ASSERT(IsFat12() || IsFat16() || IsFat32());
       
   128 
       
   129     //-- set the EOC code
       
   130     iFatEocCode = EocCodeByFatType(iFatType);
       
   131     
       
   132 
       
   133 
   128 
   134 
   129     iFreeClusterHint = KFatFirstSearchCluster;
   135     iFreeClusterHint = KFatFirstSearchCluster;
   130 
   136 
   131     //-- cache the media attributes
   137     //-- cache the media attributes
   132     TLocalDriveCapsV2 caps;
   138     TLocalDriveCapsV2 caps;
  1730 
  1736 
  1731 /**
  1737 /**
  1732     Get the next cluster in the chain from the FAT
  1738     Get the next cluster in the chain from the FAT
  1733 
  1739 
  1734     @param aCluster number to read, contains next cluster upon return
  1740     @param aCluster number to read, contains next cluster upon return
  1735     @leave
       
  1736     @return False if end of cluster chain
  1741     @return False if end of cluster chain
  1737 */
  1742 */
  1738 TBool CFatTable::GetNextClusterL(TInt& aCluster) const
  1743 TBool CFatTable::GetNextClusterL(TInt& aCluster) const
  1739     {
  1744     {
  1740 	__PRINT1(_L("CAtaFatTable::GetNextClusterL(%d)"), aCluster);
  1745 	__PRINT1(_L("CAtaFatTable::GetNextClusterL(%d)"), aCluster);
  1741     
  1746     
  1742     const TInt nextCluster = ReadL(aCluster);
  1747     const TUint32 nextCluster = ReadL(aCluster);
  1743     TBool ret = EFalse; 
  1748     const TBool bEOC = IsEndOfClusterCh(nextCluster);
  1744     
  1749 
  1745     switch(FatType())
  1750     if(bEOC) 
  1746         {
  1751         return EFalse; //-- the end of cluster chain
  1747         case EFat12:
  1752 
  1748             ret=!IsEof12Bit(nextCluster);
  1753     aCluster = nextCluster;
  1749         break;
  1754     
  1750 
  1755     return ETrue;    
  1751         case EFat16:
       
  1752             ret=!IsEof16Bit(nextCluster);
       
  1753         break;
       
  1754 
       
  1755         case EFat32:
       
  1756             ret=!IsEof32Bit(nextCluster);
       
  1757         break;
       
  1758 
       
  1759         default:
       
  1760             ASSERT(0);
       
  1761             return EFalse;//-- get rid of warning
       
  1762         };
       
  1763 	
       
  1764     if (ret)
       
  1765         {
       
  1766 		aCluster=nextCluster;
       
  1767 	    }
       
  1768 
       
  1769     return ret;
       
  1770 
       
  1771     }
  1756     }
  1772 
  1757 
  1773 /**
  1758 /**
  1774     Write EOF to aFatIndex
  1759     Write EOF to aFatIndex
  1775     @param aFatIndex index in FAT (cluster number) to be written
  1760     @param aFatIndex index in FAT (cluster number) to be written