userlibandfileserver/fileserver/sfat/sl_mnt16.cpp
changeset 15 4122176ea935
parent 0 a41df078684a
--- a/userlibandfileserver/fileserver/sfat/sl_mnt16.cpp	Mon Oct 19 15:55:17 2009 +0100
+++ b/userlibandfileserver/fileserver/sfat/sl_mnt16.cpp	Mon Dec 21 16:14:42 2009 +0000
@@ -20,6 +20,15 @@
  @file 
 */
 
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!
+//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
+//!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+
 #include "sl_std.h"
 #include "sl_cache.h"
 #include "sl_leafdir_cache.h"
@@ -82,14 +91,14 @@
         {
         __PRINT2(_L("CFatMountCB::DoReadBootSector() failed! drv:%d, code:%d"),Drive().DriveNumber(),r);
 
-	    //-- fiddling with the error code; taken from MountL()
+        //-- fiddling with the error code; taken from MountL()
         if (r==KErrNotSupported)
-		    return KErrNotReady;
+            return KErrNotReady;
     #if defined(_LOCKABLE_MEDIA)
-	    else if(r==KErrLocked)
-		    return KErrLocked;
+        else if(r==KErrLocked)
+            return KErrLocked;
     #endif
-	    else if (r!=KErrNoMemory && r!=KErrNotReady && r!=KErrCorrupt && r!=KErrUnknown)
+        else if (r!=KErrNoMemory && r!=KErrNotReady && r!=KErrCorrupt && r!=KErrUnknown)
                 return KErrCorrupt; 
 
         return r;
@@ -157,18 +166,18 @@
 @leave 
 */
 void CFatMountCB::WriteVolumeLabelL(const TDesC8& aVolumeLabel) const
-	{
+    {
     if(aVolumeLabel.Length() > KVolumeLabelSize)
         User::Leave(KErrArgument);
 
-	User::LeaveIfError(LocalDrive()->Write(KFat16VolumeLabelPos,aVolumeLabel)); 
+    User::LeaveIfError(LocalDrive()->Write(KFat16VolumeLabelPos,aVolumeLabel)); 
     }
 
 
 
 //-------------------------------------------------------------------------------------------------------------------
 
-const TUint16 KFat16CleanShutDownMask	= 0x08000;    ///< Mask used to indicate test clean/dirty bit for Fat16
+const TUint16 KFat16CleanShutDownMask   = 0x08000;    ///< Mask used to indicate test clean/dirty bit for Fat16
 
 /**
 Set or reset "VolumeClean" (ClnShutBitmask) flag.
@@ -178,7 +187,7 @@
 */
 void CFatMountCB::SetVolumeCleanL(TBool aClean) 
     {
-	//-- The volume can't be set clean if there are objects opened on it. This precondition must be checked before calling this function
+    //-- The volume can't be set clean if there are objects opened on it. This precondition must be checked before calling this function
     if(aClean && LockStatus()!=0)
         {
         __PRINT1(_L("#- CFatMountCB::SetVolumeCleanL drive:%d isn't free!"),DriveNumber());
@@ -189,9 +198,9 @@
 
     if(FatType() == EFat12)
         {//-- Fat12 doesn't support this feature; do nothing other than notify the underlying drive
-		 //   (ignoring any error for now as there's nothing we can do with it)
-		(void)LocalDrive()->Finalise(aClean);
-		return;
+         //   (ignoring any error for now as there's nothing we can do with it)
+        (void)LocalDrive()->Finalise(aClean);
+        return;
         }
 
     //-- further read and write will be directly from the CProxyDrive, bypassing FAT cache. 
@@ -225,10 +234,10 @@
                     User::LeaveIfError(LocalDrive()->Write(pos, ptrFatEntry)); //write FAT16[1] entry
                     }
                 }
-		    
-		     //-- Notify the underlying media that the mount is consistent
-		     //   (ignoring any error for now as there's nothing we can do with it)
-		    (void)LocalDrive()->Finalise(aClean);
+            
+             //-- Notify the underlying media that the mount is consistent
+             //   (ignoring any error for now as there's nothing we can do with it)
+            (void)LocalDrive()->Finalise(aClean);
 
             __PRINT2(_L("#- CFatMountCB::SetVolumeCleanL() entry:  %x->%x"), tmp, fatEntry);    
         
@@ -284,7 +293,7 @@
 @leave KErrNoMemory,KErrNotReady,KErrCorrupt,KErrUnknown.
 */
 void CFatMountCB::MountL(TBool aForceMount)
-	{
+    {
     const TInt driveNo = Drive().DriveNumber();
     
     __PRINT2(_L("CFatMountCB::MountL() drv:%d, forceMount=%d\n"),driveNo,aForceMount);
@@ -294,7 +303,7 @@
     SetReadOnly(EFalse);
    
 
-	User::LeaveIfError(CreateDrive(Drive().DriveNumber()));
+    User::LeaveIfError(CreateDrive(Drive().DriveNumber()));
 
     //-- read FAT configuration parameters from estart.txt
     iFatConfig.ReadConfig(driveNo);
@@ -304,23 +313,23 @@
     if(!iDriverInterface.Init(this))
         User::LeaveIfError(KErrNoMemory);    
 
-	//-- get drive capabilities
+    //-- get drive capabilities
     TLocalDriveCapsV2Buf capsBuf;
-	User::LeaveIfError(LocalDrive()->Caps(capsBuf));
-	
+    User::LeaveIfError(LocalDrive()->Caps(capsBuf));
+    
     iSize=capsBuf().iSize;
     iRamDrive = EFalse;
 
     if(capsBuf().iMediaAtt & KMediaAttVariableSize)
     {//-- this is a RAM drive
-		UserSvr::UnlockRamDrive();
+        UserSvr::UnlockRamDrive();
         iRamDrive = ETrue;
-	}
+    }
 
-	if(aForceMount)
-	{//-- the state is "forcedly mounted", special case. This is an inconsistent state.
+    if(aForceMount)
+    {//-- the state is "forcedly mounted", special case. This is an inconsistent state.
         SetState(EInit_Forced);  
-    	return;
+        return;
     }
 
     //-- read and validate boot sector (sector 0)
@@ -330,7 +339,7 @@
     //-- print out boot sector debug information
     bootSector.PrintDebugInfo();
 
-	//-- determine FAT type by data from boot sector. This is done by counting number of clusters, not by BPB_RootEntCnt
+    //-- determine FAT type by data from boot sector. This is done by counting number of clusters, not by BPB_RootEntCnt
     iFatType=bootSector.FatType();
     ASSERT(iFatType != EInvalid); //-- this shall be checked in ReadBootSector()
 
@@ -347,8 +356,8 @@
 
     GetVolumeLabelFromDiskL(bootSector);
 
-	__PRINT2(_L("CFatMountCB::MountL() Completed, drv: %d, state:%d"), DriveNumber(), State());
-	}
+    __PRINT2(_L("CFatMountCB::MountL() Completed, drv: %d, state:%d"), DriveNumber(), State());
+    }
 
 
 
@@ -361,28 +370,28 @@
 @leave KErrNoMemory,KErrNotReady,KErrCorrupt,KErrUnknown.
 */
 void CFatMountCB::InitializeL(const TLocalDriveCaps& aLocDrvCaps, TBool /*aIgnoreFSInfo=EFalse*/)
-	{
+    {
     __PRINT1(_L("CFatMountCB::InitializeL() drv:%d"), DriveNumber());
 
     ASSERT(State() == EMounting); //-- we must get here only from MountL()
 
     //========== Find out number of clusters on the volume
-	if(iRamDrive && SectorsPerCluster()!=1)
-		{// Align iFirstFreeByte to cluster boundary if internal ram drive
-		const TInt sectorsPerClusterLog2=ClusterSizeLog2()-SectorSizeLog2();
-		const TInt rootDirEndSector=RootDirEnd()>>SectorSizeLog2();
-		const TInt alignedSector=((rootDirEndSector+SectorsPerCluster()-1)>>sectorsPerClusterLog2)<<sectorsPerClusterLog2;
-		iFirstFreeByte=alignedSector<<SectorSizeLog2();
-		}
-	else
-		{
-		iFirstFreeByte=RootDirEnd();
-		}
+    if(iRamDrive && SectorsPerCluster()!=1)
+        {// Align iFirstFreeByte to cluster boundary if internal ram drive
+        const TInt sectorsPerClusterLog2=ClusterSizeLog2()-SectorSizeLog2();
+        const TInt rootDirEndSector=RootDirEnd()>>SectorSizeLog2();
+        const TInt alignedSector=((rootDirEndSector+SectorsPerCluster()-1)>>sectorsPerClusterLog2)<<sectorsPerClusterLog2;
+        iFirstFreeByte=alignedSector<<SectorSizeLog2();
+        }
+    else
+        {
+        iFirstFreeByte=RootDirEnd();
+        }
 
 
-	    {//-- check if volume geometry looks valid
-	    const TInt usableSectors=TotalSectors()-(iFirstFreeByte>>SectorSizeLog2());
-	    iUsableClusters=usableSectors>>(ClusterSizeLog2()-SectorSizeLog2());
+        {//-- check if volume geometry looks valid
+        const TInt usableSectors=TotalSectors()-(iFirstFreeByte>>SectorSizeLog2());
+        iUsableClusters=usableSectors>>(ClusterSizeLog2()-SectorSizeLog2());
 
         const TUint32 KMinClusters = 32; //-- absolute minimum number of clusters on the volume
         const TUint32 KMaxClusters =(TotalSectors()-FirstFatSector()-NumberOfFats()*(FatSizeInBytes()>>SectorSizeLog2())) >> (ClusterSizeLog2()-SectorSizeLog2());
@@ -395,30 +404,30 @@
         }
 
 
-	//========== initialise RawDisk interface
-	//-- CFatMountCB parameters might have changed, e.g. after formatting. Reconstruct directory cache with new parameters
-	
+    //========== initialise RawDisk interface
+    //-- CFatMountCB parameters might have changed, e.g. after formatting. Reconstruct directory cache with new parameters
+    
     delete iRawDisk;
-	iRawDisk=CRawDisk::NewL(*this, aLocDrvCaps);
+    iRawDisk=CRawDisk::NewL(*this, aLocDrvCaps);
     iRawDisk->InitializeL();
     
 
     //========== create FAT table object
-	delete iFatTable;
-	iFatTable=CFatTable::NewL(*this, aLocDrvCaps);
+    delete iFatTable;
+    iFatTable=CFatTable::NewL(*this, aLocDrvCaps);
 
     //========== create and setup leaf direcotry cache if cache limit is set bigger than one 
-	const TUint32 cacheLimit = iFatConfig.LeafDirCacheSize();
-	if (cacheLimit > 1)
-		{
-		// destroy the old leaf dir cache to avoid memory leak.
-		delete iLeafDirCache;
-		iLeafDirCache = CLeafDirCache::NewL(cacheLimit);
-		}
-	else
-		{
-		iLeafDirCache = NULL;
-		}
+    const TUint32 cacheLimit = iFatConfig.LeafDirCacheSize();
+    if (cacheLimit > 1)
+        {
+        // destroy the old leaf dir cache to avoid memory leak.
+        delete iLeafDirCache;
+        iLeafDirCache = CLeafDirCache::NewL(cacheLimit);
+        }
+    else
+        {
+        iLeafDirCache = NULL;
+        }
 
     //==========  find out free clusters number on the volume
     FAT().CountFreeClustersL();
@@ -430,7 +439,7 @@
     SetDiskSpaceChange(freeSpace);
 
     __PRINT3(_L("#- CFatMountCB::InitializeL() done. drv:%d, Free clusters:%d, 1st Free cluster:%d"),DriveNumber(), FAT().NumberOfFreeClusters(), FAT().FreeClusterHint());
-	}
+    }
 
 //-------------------------------------------------------------------------------------------------------------------
 
@@ -443,12 +452,12 @@
 @return Result of test
 */
 TBool CFatMountCB::IsEndOfClusterCh(TInt aCluster) const
-	{
-	if(Is16BitFat())
-		return(aCluster>=0xFFF8 && aCluster<=0xFFFF);
-	else
-		return(aCluster>=0xFF8 && aCluster<=0xFFF);
-	}
+    {
+    if(Is16BitFat())
+        return(aCluster>=0xFFF8 && aCluster<=0xFFFF);
+    else
+        return(aCluster>=0xFF8 && aCluster<=0xFFF);
+    }
 
 /**
 Set a cluster to the end of cluster chain marker
@@ -456,12 +465,12 @@
 @param aCluster cluster to set to end of chain marker
 */
 void CFatMountCB::SetEndOfClusterCh(TInt &aCluster) const
-	{
-	if(Is16BitFat())
-		aCluster=0xFFF8;
-	else
-		aCluster=0xFF8;
-	}
+    {
+    if(Is16BitFat())
+        aCluster=0xFFF8;
+    else
+        aCluster=0xFF8;
+    }
 
 /**
 Initialize data to represent the root directory
@@ -469,11 +478,11 @@
 @param anEntry Entry to initialise
 */
 void CFatMountCB::InitializeRootEntry(TFatDirEntry & anEntry) const
-	{
-	anEntry.SetName(_L8("ROOT"));
-	anEntry.SetAttributes(KEntryAttDir);
-	anEntry.SetStartCluster(0);		
-	}
+    {
+    anEntry.SetName(_L8("ROOT"));
+    anEntry.SetAttributes(KEntryAttDir);
+    anEntry.SetStartCluster(0);     
+    }
 
 
 /**
@@ -482,32 +491,32 @@
 
 @param aName Name of the sub type of Fat file system
 @return KErrNone if successful; KErrArgument if aName is not long enough; KErrNotReady if
-		the mount is not ready.
+        the mount is not ready.
 
 @see CMountCB::FileSystemSubType()
 */
 TInt CFatMountCB::SubType(TDes& aName) const
-	{
-	if(aName.MaxLength() < 5)
-		return KErrArgument;
-	
-	switch (iFatType)
-		{
-		case EFat12:
-			{
-			aName = KFSSubType_FAT12;
-			return KErrNone;
-			}
-		case EFat16:
-			{
-			aName = KFSSubType_FAT16;
-			return KErrNone;
-			}
-		default:
-		// case EInvalidFatType
-			return KErrNotReady;
-		}
-	}
+    {
+    if(aName.MaxLength() < 5)
+        return KErrArgument;
+    
+    switch (iFatType)
+        {
+        case EFat12:
+            {
+            aName = KFSSubType_FAT12;
+            return KErrNone;
+            }
+        case EFat16:
+            {
+            aName = KFSSubType_FAT16;
+            return KErrNone;
+            }
+        default:
+        // case EInvalidFatType
+            return KErrNotReady;
+        }
+    }
 
 //-------------------------------------------------------------------------------------------------------------------
 /**
@@ -585,9 +594,9 @@
             else
                 return LocalDrive()->LocalBufferSupport();
 
-		case EGetProxyDrive:
-			((CProxyDrive*&)aInterface) = LocalDrive();
-			return KErrNone;
+        case EGetProxyDrive:
+            ((CProxyDrive*&)aInterface) = LocalDrive();
+            return KErrNone;
         
         default:
             return(CMountCB::GetInterface(aInterfaceId, aInterface, aInput));