userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp
changeset 90 947f0dc9f7a8
parent 33 0173bcd7697c
child 117 5b5d147c7838
child 131 e880629062dd
equal deleted inserted replaced
52:2d65c2f76d7b 90:947f0dc9f7a8
   254         else
   254         else
   255             fatEntry &= ~KFat32CleanShutDownMask; //-- reset ClnShutBit flag
   255             fatEntry &= ~KFat32CleanShutDownMask; //-- reset ClnShutBit flag
   256 
   256 
   257         if(tmp != fatEntry)
   257         if(tmp != fatEntry)
   258             {//-- write FAT[1] entry to all available FATs
   258             {//-- write FAT[1] entry to all available FATs
   259                 for(TInt i=0; i<NumberOfFats(); ++i)
   259                 for(TUint32 i=0; i<NumberOfFats(); ++i)
   260                 {
   260                 {
   261                 const TInt64 pos = StartOfFatInBytes()+KFatEntrySize+(FatSizeInBytes()*i);
   261                 const TInt64 pos = StartOfFatInBytes()+KFatEntrySize+(FatSizeInBytes()*i);
   262                 User::LeaveIfError(LocalDrive()->Write(pos, ptrFatEntry)); //write FAT32[1] entry
   262                 User::LeaveIfError(LocalDrive()->Write(pos, ptrFatEntry)); //write FAT32[1] entry
   263                 }
   263                 }
   264             }
   264             }
   285             else
   285             else
   286                 fatEntry &= ~KFat16CleanShutDownMask; //-- reset ClnShutBit flag
   286                 fatEntry &= ~KFat16CleanShutDownMask; //-- reset ClnShutBit flag
   287 
   287 
   288             if(tmp != fatEntry)
   288             if(tmp != fatEntry)
   289                 {//-- write FAT[1] entry to all available FATs
   289                 {//-- write FAT[1] entry to all available FATs
   290                 for(TInt i=0; i<NumberOfFats(); ++i)
   290                 for(TUint32 i=0; i<NumberOfFats(); ++i)
   291                     {
   291                     {
   292                     const TInt64 pos = StartOfFatInBytes()+KFatEntrySize+(FatSizeInBytes()*i);
   292                     const TInt64 pos = StartOfFatInBytes()+KFatEntrySize+(FatSizeInBytes()*i);
   293                     User::LeaveIfError(LocalDrive()->Write(pos, ptrFatEntry)); //write FAT16[1] entry
   293                     User::LeaveIfError(LocalDrive()->Write(pos, ptrFatEntry)); //write FAT16[1] entry
   294                     }
   294                     }
   295                 }
   295                 }
   365 void CFatMountCB::MountL(TBool aForceMount)
   365 void CFatMountCB::MountL(TBool aForceMount)
   366 	{
   366 	{
   367 
   367 
   368     const TInt driveNo = Drive().DriveNumber();
   368     const TInt driveNo = Drive().DriveNumber();
   369     
   369     
   370     __PRINT2(_L("CFatMountCB::MountL() drv:%d, forceMount=%d\n"),driveNo,aForceMount);
   370     __PRINT3(_L("CFatMountCB::MountL() drv:%d, forceMount=%d, RuggedFAT:%d\n"), driveNo, aForceMount, IsRuggedFSys());
   371 
   371 
   372     ASSERT(State() == ENotMounted || State() == EDismounted);
   372     ASSERT(State() == ENotMounted || State() == EDismounted);
   373     SetState(EMounting);
   373     SetState(EMounting);
   374     SetReadOnly(EFalse);
   374     SetReadOnly(EFalse);
   375    
   375    
   474 			iFirstFreeByte=RootDirEnd();
   474 			iFirstFreeByte=RootDirEnd();
   475 		}
   475 		}
   476 
   476 
   477 
   477 
   478 	    {//-- check if volume geometry looks valid
   478 	    {//-- check if volume geometry looks valid
   479         const TInt usableSectors=TotalSectors()-(iFirstFreeByte>>SectorSizeLog2());
   479         const TUint32 usableSectors = TotalSectors()-(iFirstFreeByte>>SectorSizeLog2());
   480 	    iUsableClusters=usableSectors>>(ClusterSizeLog2()-SectorSizeLog2());
   480 	    iUsableClusters=usableSectors>>(ClusterSizeLog2()-SectorSizeLog2());
   481 
   481 
   482         const TUint32 KMinClusters = 32; //-- absolute minimum number of clusters on the volume
   482         const TUint32 KMinClusters = 32; //-- absolute minimum number of clusters on the volume
   483         const TUint32 KMaxClusters=(TotalSectors()-FirstFatSector()-NumberOfFats()*(FatSizeInBytes()>>SectorSizeLog2())) >> (ClusterSizeLog2()-SectorSizeLog2());
   483         const TUint32 KMaxClusters=(TotalSectors()-FirstFatSector()-NumberOfFats()*(FatSizeInBytes()>>SectorSizeLog2())) >> (ClusterSizeLog2()-SectorSizeLog2());
   484         
   484         
   485         if(usableSectors <=0 || iUsableClusters < KMinClusters || iUsableClusters > KMaxClusters)
   485         if(iUsableClusters < KMinClusters || iUsableClusters > KMaxClusters)
   486             {
   486             {
   487             __PRINT(_L("CFatMountCB::InitializeL() Wrong number of usable cluster/sectors on the volume!"));
   487             __PRINT(_L("CFatMountCB::InitializeL() Wrong number of usable cluster/sectors on the volume!"));
   488             User::Leave(KErrCorrupt);
   488             User::Leave(KErrCorrupt);
   489             }
   489             }
   490         }
   490         }
   491 
   491 
   492 	//========== initialise RawDisk interface
   492 	//========== initialise RawDisk interface
   493 	//-- CFatMountCB parameters might have changed, e.g. after formatting. Reconstruct directory cache with new parameters
   493 	//-- CFatMountCB parameters might have changed, e.g. after formatting. Reconstruct directory cache with new parameters
   494 	
   494 	
   495     delete iRawDisk;
   495     delete iRawDisk;
       
   496     iRawDisk = NULL;
   496 	iRawDisk=CRawDisk::NewL(*this, aLocDrvCaps);
   497 	iRawDisk=CRawDisk::NewL(*this, aLocDrvCaps);
   497     iRawDisk->InitializeL();
   498     iRawDisk->InitializeL();
   498 
   499 
   499 
   500 
   500     //========== Try to read FSInfo and deduct number of free clusters and other information from there
   501     //========== Try to read FSInfo and deduct number of free clusters and other information from there
   536         }
   537         }
   537 
   538 
   538     //========== create and initialise FAT table 
   539     //========== create and initialise FAT table 
   539 	
   540 	
   540     delete iFatTable;
   541     delete iFatTable;
       
   542     iFatTable = NULL;
   541     iFatTable=CFatTable::NewL(*this, aLocDrvCaps);
   543     iFatTable=CFatTable::NewL(*this, aLocDrvCaps);
   542 
   544 
   543     //-- mount the FAT table. Depending on mount parameters and configuration this method 
   545     //-- mount the FAT table. Depending on mount parameters and configuration this method 
   544     //-- can do various things, like counting free clusters synchronously if data from FSInfo isn't valid, 
   546     //-- can do various things, like counting free clusters synchronously if data from FSInfo isn't valid, 
   545     //-- or setting up a FAT backround thread and return immediately etc.
   547     //-- or setting up a FAT backround thread and return immediately etc.
   548     SetState(EInit_R);  //-- the state is "Initialized, but not writen"
   550     SetState(EInit_R);  //-- the state is "Initialized, but not writen"
   549 
   551 
   550     //-- make a callback, telling FileServer about free space discovered.
   552     //-- make a callback, telling FileServer about free space discovered.
   551     const TInt64 freeSpace = ((TInt64)FAT().NumberOfFreeClusters()) << ClusterSizeLog2();
   553     const TInt64 freeSpace = ((TInt64)FAT().NumberOfFreeClusters()) << ClusterSizeLog2();
   552     SetDiskSpaceChange(freeSpace);
   554     SetDiskSpaceChange(freeSpace);
   553     //========== create and setup leaf direcotry cache if cache limit is set bigger than one 
   555 
   554 
   556     //========== create and setup leaf direcotry cache
   555 	const TUint32 cacheLimit = iFatConfig.LeafDirCacheSize();
       
   556 	if (cacheLimit > 1)
       
   557 		{
   557 		{
   558 		// destroy the old leaf dir cache to avoid memory leak.
   558 	const TUint32 cacheLimit = Max(iFatConfig.LeafDirCacheSize(), 1lu);
       
   559 	
   559 		delete iLeafDirCache;
   560 		delete iLeafDirCache;
       
   561         iLeafDirCache = NULL;
   560 		iLeafDirCache = CLeafDirCache::NewL(cacheLimit);
   562 		iLeafDirCache = CLeafDirCache::NewL(cacheLimit);
   561 		}
   563 		}
   562 	else
   564 
   563 		{
   565 
   564 		iLeafDirCache = NULL;
       
   565 		}
       
   566     
   566     
   567     __PRINT3(_L("#- CFatMountCB::InitializeL() done. drv:%d, Free clusters:%d, 1st Free cluster:%d"),DriveNumber(), FAT().NumberOfFreeClusters(), FAT().FreeClusterHint());
   567     __PRINT3(_L("#- CFatMountCB::InitializeL() done. drv:%d, Free clusters:%d, 1st Free cluster:%d"),DriveNumber(), FAT().NumberOfFreeClusters(), FAT().FreeClusterHint());
   568 
   568 
   569     
   569     
   570 	}
   570 	}
   879         {
   879         {
   880         TBool bFinalised;
   880         TBool bFinalised;
   881         nRes = IsFinalised(bFinalised);
   881         nRes = IsFinalised(bFinalised);
   882         if(nRes == KErrNone)
   882         if(nRes == KErrNone)
   883             {
   883             {
       
   884             ASSERT(aParam);
   884             *((TBool*)aParam) = bFinalised;
   885             *((TBool*)aParam) = bFinalised;
   885             }
   886             }
   886         
   887         
   887         return nRes;
   888         return nRes;
   888         }
   889         }
  1045         aLength=(TInt)(fileSize-aPos);
  1046         aLength=(TInt)(fileSize-aPos);
  1046     
  1047     
  1047     TInt cluster=StartCluster(dosEntry);	
  1048     TInt cluster=StartCluster(dosEntry);	
  1048 	TInt64 pos = aPos;
  1049 	TInt64 pos = aPos;
  1049 	
  1050 	
  1050     TInt endCluster;
  1051     TUint32 endCluster;
  1051     TInt clusterSize=1<<ClusterSizeLog2();      //  Size of file clusters
  1052     TInt clusterSize=1<<ClusterSizeLog2();      //  Size of file clusters
  1052 	TInt readTotal = 0;
  1053 	TInt readTotal = 0;
  1053 	
  1054 	
  1054 	// Total number of clusters in file
  1055 	// Total number of clusters in file
  1055     TInt maxClusters=(TInt)((fileSize+clusterSize-1)>>ClusterSizeLog2());
  1056     TInt maxClusters=(TInt)((fileSize+clusterSize-1)>>ClusterSizeLog2());