userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp
changeset 33 0173bcd7697c
parent 0 a41df078684a
child 87 2f92ad2dc5db
equal deleted inserted replaced
31:56f325a607ea 33:0173bcd7697c
   233         return;
   233         return;
   234         }
   234         }
   235 
   235 
   236     //-- further read and write will be directly from the CProxyDrive, bypassing FAT cache. 
   236     //-- further read and write will be directly from the CProxyDrive, bypassing FAT cache. 
   237     //-- this is because CFatTable doesn't allow access to FAT[0] & FAT[1]
   237     //-- this is because CFatTable doesn't allow access to FAT[0] & FAT[1]
   238     //-- We also need to write data through CProxyDrive, because TFatDriveInterface has a call back that can call this method
   238     //-- We also need to write data through CProxyDrive, because TDriveInterface has a call back that can call this method
   239 
   239 
   240     if(Is32BitFat())
   240     if(Is32BitFat())
   241         {//-- Fat32
   241         {//-- Fat32
   242 		__PRINT2(_L("#- CFatMountCB::SetVolumeCleanL, drive:%d, param:%d, FAT32"),DriveNumber(), aClean);
   242 		__PRINT2(_L("#- CFatMountCB::SetVolumeCleanL, drive:%d, param:%d, FAT32"),DriveNumber(), aClean);
   243 		
   243 		
   321 @leave  if is called for FAT12 or if read error occured.
   321 @leave  if is called for FAT12 or if read error occured.
   322 */
   322 */
   323 TBool CFatMountCB::VolumeCleanL() 
   323 TBool CFatMountCB::VolumeCleanL() 
   324     {
   324     {
   325 
   325 
   326     //-- read access to the FAT is through TFatDriveInterface, because CFatTable doesn't allow access to FAT[1]
   326     //-- read access to the FAT is through TDriveInterface, because CFatTable doesn't allow access to FAT[1]
   327     TFatDriveInterface& drive =DriveInterface();
   327     TDriveInterface& drive =DriveInterface();
   328 
   328 
   329     if(Is32BitFat())
   329     if(Is32BitFat())
   330         {//-- Fat32
   330         {//-- Fat32
   331         TFat32Entry fatEntry;
   331         TFat32Entry fatEntry;
   332         const TInt  KFatEntrySize=sizeof(fatEntry); //-- FAT entry size in bytes
   332         const TInt  KFatEntrySize=sizeof(fatEntry); //-- FAT entry size in bytes
   410 
   410 
   411     //-- print out boot sector debug information
   411     //-- print out boot sector debug information
   412     bootSector.PrintDebugInfo();
   412     bootSector.PrintDebugInfo();
   413 
   413 
   414     //-- determine FAT type by data from boot sector. This is done by counting number of clusters, not by BPB_RootEntCnt
   414     //-- determine FAT type by data from boot sector. This is done by counting number of clusters, not by BPB_RootEntCnt
   415     iFatType = bootSector.FatType();
   415     SetFatType(bootSector.FatType());
   416     ASSERT(iFatType != EInvalid); //-- this shall be checked in ReadBootSector()
   416     ASSERT(iFatType != EInvalid); //-- this shall be checked in ReadBootSector()
   417     
   417     
   418 
   418 
   419     if(bootSector.RootDirEntries() == 0 && !Is32BitFat())
   419     if(bootSector.RootDirEntries() == 0 && !Is32BitFat())
   420     {//-- FAT types mismatch. BPB_RootEntCnt is 0, which can be only for FAT32, but the number of clusters is less 
   420     {//-- FAT types mismatch. BPB_RootEntCnt is 0, which can be only for FAT32, but the number of clusters is less 
   421      //-- than required for FAT32. Probably this is incorrectly FAT32 formatted media. Put the drive into ReadOnly mode, assuming
   421      //-- than required for FAT32. Probably this is incorrectly FAT32 formatted media. Put the drive into ReadOnly mode, assuming
   422      //-- that is FAT32.
   422      //-- that is FAT32.
   423         __PRINT(_L("FAT type mismatch! Setting drive to ReadOnly mode for FAT32. \n"));
   423         __PRINT(_L("FAT type mismatch! Setting drive to ReadOnly mode for FAT32. \n"));
   424         iFatType = EFat32; //-- force FAT type to be FAT32
   424         SetFatType(EFat32); //-- force FAT type to be FAT32
   425         SetReadOnly(ETrue);
   425         SetReadOnly(ETrue);
   426     }
   426     }
   427 
   427 
   428     //-- store volume UID, it can be checked on Remount
   428     //-- store volume UID, it can be checked on Remount
   429     iUniqueID = bootSector.UniqueID();
   429     iUniqueID = bootSector.UniqueID();
   627     aFSInfo.Internalize(fsInfoSecBuf);
   627     aFSInfo.Internalize(fsInfoSecBuf);
   628     
   628     
   629     return KErrNone;
   629     return KErrNone;
   630     }
   630     }
   631 
   631 
   632 /**
   632 
   633 Checks for end of file for all Fat types
   633 /**
   634 
   634     Initialize data to represent the root directory
   635 @param aCluster Cluster to check
   635 
   636 @return Result of test
   636     @param anEntry Entry to initialise
   637 */
   637 */
   638 TBool CFatMountCB::IsEndOfClusterCh(TInt aCluster) const
   638 void CFatMountCB::InitializeRootEntry(TFatDirEntry& anEntry) const
   639 	{
       
   640 	if(Is32BitFat())
       
   641 		return(aCluster>=(TInt)0x0FFFFFF8 && aCluster<=(TInt)0x0FFFFFFF);
       
   642 	else if(Is16BitFat())
       
   643 		return(aCluster>=0xFFF8 && aCluster<=0xFFFF);
       
   644 	else
       
   645 		return(aCluster>=0xFF8 && aCluster<=0xFFF);
       
   646 	}
       
   647 
       
   648 /**
       
   649 Set a cluster to the end of cluster chain marker
       
   650 
       
   651 @param aCluster cluster to set to end of chain marker
       
   652 */
       
   653 void CFatMountCB::SetEndOfClusterCh(TInt &aCluster) const
       
   654 	{
       
   655 	if(Is32BitFat())
       
   656 		aCluster=EOF_32Bit;
       
   657 	else if(Is16BitFat())
       
   658 		aCluster=EOF_16Bit;
       
   659 	else
       
   660 		aCluster=EOF_12Bit;
       
   661 	}
       
   662 
       
   663 /**
       
   664 Initialize data to represent the root directory
       
   665 
       
   666 @param anEntry Entry to initialise
       
   667 */
       
   668 void CFatMountCB::InitializeRootEntry(TFatDirEntry & anEntry) const
       
   669 	{
   639 	{
   670 	anEntry.SetName(_L8("ROOT"));
   640 	anEntry.SetName(_L8("ROOT"));
   671 	anEntry.SetAttributes(KEntryAttDir);
   641 	anEntry.SetAttributes(KEntryAttDir);
   672 	anEntry.SetStartCluster(RootClusterNum()); //--iRootClusterNum is 0 for FAT12/16
   642 	anEntry.SetStartCluster(RootClusterNum()); //--iRootClusterNum is 0 for FAT12/16
   673 	}
   643 	}
   674 
   644 
   675 
   645 
   676 
   646 
   677 /**
   647 /**
   678 Implementation of CMountCB::FileSystemSubType(). Retrieves the sub type of Fat file system
   648     Implementation of CMountCB::FileSystemSubType(). Retrieves the sub type of Fat file system
   679 and returns the name as a descriptor.
   649     and returns the name as a descriptor.
   680 
   650 
   681 @param aName Name of the sub type of Fat file system
   651     @param aName Name of the sub type of Fat file system
   682 @return KErrNone if successful; KErrArgument if aName is not long enough; KErrNotReady if
   652     @return KErrNone if successful; KErrArgument if aName is not long enough; KErrNotReady if
   683 		the mount is not ready.
   653 		    the mount is not ready.
   684 
   654 
   685 @see CMountCB::FileSystemSubType()
   655     @see CMountCB::FileSystemSubType()
   686 */
   656 */
   687 TInt CFatMountCB::SubType(TDes& aName) const
   657 TInt CFatMountCB::SubType(TDes& aName) const
   688 	{
   658 	{
   689 	if(aName.MaxLength() < 5)
   659 	if(aName.MaxLength() < 5)
   690 		return KErrArgument;
   660 		return KErrArgument;
   691 	
   661 	
   692 	switch (iFatType)
   662 	switch (FatType())
   693 		{
   663 		{
   694 		case EFat12:
   664 		case EFat12:
   695 			{
   665 			{
   696 			aName = KFSSubType_FAT12;
   666 			aName = KFSSubType_FAT12;
   697 			return KErrNone;
   667 			return KErrNone;