userlibandfileserver/fileserver/sfat/sl_drv.cpp
changeset 2 4122176ea935
parent 0 a41df078684a
--- a/userlibandfileserver/fileserver/sfat/sl_drv.cpp	Mon Oct 19 15:55:17 2009 +0100
+++ b/userlibandfileserver/fileserver/sfat/sl_drv.cpp	Mon Dec 21 16:14:42 2009 +0000
@@ -15,6 +15,15 @@
 // 
 //
 
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//!!
+//!! 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"
 
@@ -38,7 +47,7 @@
 {
     ASSERT(aMount);
     iMount = aMount;
-	aMount->LocalDrive()->SetMount(aMount);
+    aMount->LocalDrive()->SetMount(aMount);
     return iProxyDrive.Init(aMount->LocalDrive());
 }
 
@@ -47,8 +56,8 @@
 */
 void TFatDriveInterface::Close()
 {
-	 if(iMount)
-		iMount->LocalDrive()->SetMount(NULL);
+     if(iMount)
+        iMount->LocalDrive()->SetMount(NULL);
      iMount = NULL;
 }
 
@@ -168,13 +177,13 @@
     for(;;)
     {
         nRes = iProxyDrive.Read(aPos, aLength, aTrg);
-		if(nRes == KErrNone)
+        if(nRes == KErrNone)
             break;
 
-		__PRINT4(_L("TFatDriveInterface::ReadCritical() Error! drv:%d Posl=%LU len=%d retval=%d"), iMount->DriveNumber(), aPos, aLength, nRes);
-		
+        __PRINT4(_L("TFatDriveInterface::ReadCritical() Error! drv:%d Posl=%LU len=%d retval=%d"), iMount->DriveNumber(), aPos, aLength, nRes);
+        
         nRes=HandleCriticalError(nRes);
-		if (nRes != ERetry)
+        if (nRes != ERetry)
             break;
     }
 
@@ -257,24 +266,24 @@
     TBool simulatedWriteFailure = EFalse; //-- if true it means that the write failure has been simulated
 
     //-- debug interface to simulate write failure
-	if(iMount->IsWriteFail())
+    if(iMount->IsWriteFail())
     {
-		if(iMount->WriteFailCount() != 0)
+        if(iMount->WriteFailCount() != 0)
         {
             iMount->DecWriteFailCount();
         }
         else
-		{//-- simulate write failure
-			if(iMount->WriteFailError()==-99)
-				UserSvr::ResetMachine(EStartupWarmReset);
-			else
-			{
-			    //-- invalidate caches, because actual write to the drive isn't going to happen
+        {//-- simulate write failure
+            if(iMount->WriteFailError()==-99)
+                UserSvr::ResetMachine(EStartupWarmReset);
+            else
+            {
+                //-- invalidate caches, because actual write to the drive isn't going to happen
                 if(iMount->RawDisk().DirCacheInterface())
                     iMount->RawDisk().DirCacheInterface()->InvalidateCache();
 
                 iMount->SetWriteFail(EFalse);
-				
+                
                 TRAP_IGNORE(iMount->RawDisk().InvalidateUidCache()); //-- invalidate whole UID data cache
                 TRAP_IGNORE(iMount->FAT().InvalidateCacheL());       //-- invalidate whole FAT cache
                 
@@ -284,23 +293,23 @@
                 simulatedWriteFailure = ETrue; //-- won't perform actual write later
                 __PRINT4(_L("TFatDriveInterface::WriteCritical() Simulating write failure. drv:%d, aPos=%LU len=%d Code=%d"), iMount->DriveNumber(), aPos,aSrc.Length(),nRes);
 
-			}
-		}
+            }
+        }
     }//if(iMount->IsWriteFail())
 
     if(!simulatedWriteFailure)
 #endif // _DEBUG
     {
         //-- try to write data until success or user gives up
-	    for(;;)
-	    {
+        for(;;)
+        {
             for(TInt i=0; i<KMaxCriticalRetries; i++)
             {
                 iMount->OpenMountForWrite();  //-- make a callback to CFatMountCB to perform some actions on 1st write.
                 nRes=iProxyDrive.Write(aPos,aSrc);
-			    if (nRes==KErrNone)
+                if (nRes==KErrNone)
                     return nRes;
-		    }
+            }
 
             //-- write error occured
             __PRINT4(_L("TFatDriveInterface::WriteCritical() failure! drv:%d, aPos=%LU len=%d retval=%d"), iMount->DriveNumber(), aPos,aSrc.Length(),nRes);
@@ -309,7 +318,7 @@
             if (nRes!=ERetry)
                 break;
 
-	    }//for(;;)
+        }//for(;;)
     
     }// if(!simulatedWriteFailure)
     
@@ -343,84 +352,84 @@
     @return KErrCorrupt - cf-card is corrupt
 */
 TInt TFatDriveInterface::HandleCriticalError(TInt aResult) const
-	{
+    {
     __PRINT2(_L("TFatDriveInterface::HandleCriticalError drv:%d, code:%d"), iMount->DriveNumber(),aResult);
 
-	TLocaleMessage line1;
-	TLocaleMessage line2;
+    TLocaleMessage line1;
+    TLocaleMessage line2;
 
-	TInt r=KErrAbort;
+    TInt r=KErrAbort;
 
-	if (aResult==KErrLocked)
-	{
-		r=KErrLocked;
-		goto End;
-	}
+    if (aResult==KErrLocked)
+    {
+        r=KErrLocked;
+        goto End;
+    }
 
-	if (aResult==KErrAccessDenied)
-		{
-		r=KErrAccessDenied;
-		goto End;
-		}
-	
-	if (aResult==KErrArgument || aResult==KErrBadDescriptor)
-		{
-		r=KErrCorrupt;
-		goto End;
-		}
+    if (aResult==KErrAccessDenied)
+        {
+        r=KErrAccessDenied;
+        goto End;
+        }
+    
+    if (aResult==KErrArgument || aResult==KErrBadDescriptor)
+        {
+        r=KErrCorrupt;
+        goto End;
+        }
 
-	if (iMount->Drive().IsChanged())
-		{//-- check if the media we accessing is the same as it used to be
+    if (iMount->Drive().IsChanged())
+        {//-- check if the media we accessing is the same as it used to be
           if(iMount->CheckVolumeTheSame())
-        	{//-- the media is the same
-			if(!IsDriveWriteProtected())
-				{
-				iMount->Drive().SetChanged(EFalse);
-				r=ERetry;
-				goto End;
-				}
-			}
-		}
+            {//-- the media is the same
+            if(!IsDriveWriteProtected())
+                {
+                iMount->Drive().SetChanged(EFalse);
+                r=ERetry;
+                goto End;
+                }
+            }
+        }
 
-	if (aResult==KErrAbort && !iMount->Drive().IsChanged())
-		{
-		r=ERetry;
-		goto End;
-		}
+    if (aResult==KErrAbort && !iMount->Drive().IsChanged())
+        {
+        r=ERetry;
+        goto End;
+        }
 
-	if (aResult==KErrBadPower)
-		{
-		line1=EFileServer_LowPowerLine1;
-		line2=EFileServer_LowPowerLine2;
-		}
-	else if (iMount->Drive().IsChanged())
-		{
-		line1=EFileServer_PutTheCardBackLine1;
-		line2=EFileServer_PutTheCardBackLine2;
-		}
-	else
-		{
-		line1=EFileServer_DiskErrorLine1;
-		line2=EFileServer_DiskErrorLine2;
-		}
-	
-	if (NotifyUser())
-		{
-		FOREVER
-			{
-			TInt buttonVal;
-			TInt ret=iMount->Notifier()->Notify(TLocaleMessageText(line1),
-												TLocaleMessageText(line2),
-												TLocaleMessageText(EFileServer_Button1),
-												TLocaleMessageText(EFileServer_Button2),
-												buttonVal);
-			if (ret!=KErrNone)
-				break; 
-			if (buttonVal!=1)
-				break; // Abort
+    if (aResult==KErrBadPower)
+        {
+        line1=EFileServer_LowPowerLine1;
+        line2=EFileServer_LowPowerLine2;
+        }
+    else if (iMount->Drive().IsChanged())
+        {
+        line1=EFileServer_PutTheCardBackLine1;
+        line2=EFileServer_PutTheCardBackLine2;
+        }
+    else
+        {
+        line1=EFileServer_DiskErrorLine1;
+        line2=EFileServer_DiskErrorLine2;
+        }
+    
+    if (NotifyUser())
+        {
+        FOREVER
+            {
+            TInt buttonVal;
+            TInt ret=iMount->Notifier()->Notify(TLocaleMessageText(line1),
+                                                TLocaleMessageText(line2),
+                                                TLocaleMessageText(EFileServer_Button1),
+                                                TLocaleMessageText(EFileServer_Button2),
+                                                buttonVal);
+            if (ret!=KErrNone)
+                break; 
+            if (buttonVal!=1)
+                break; // Abort
 
-			if (iMount->Drive().IsChanged())
-				{
+            if (iMount->Drive().IsChanged())
+                {
 //
 // Without this code, retry will indiscriminately write over whatever disk happens to be present.
 // However if the write error is to the bootsector remounting will always fail because the boot
@@ -433,16 +442,16 @@
                     continue; //-- still can not write to the drive
 
 
-				iMount->Drive().SetChanged(EFalse);
-				}
+                iMount->Drive().SetChanged(EFalse);
+                }
 
-			r=ERetry; // Retry
-			break;
-			}
-		}
+            r=ERetry; // Retry
+            break;
+            }
+        }
 End:
-	return(r);
-	}
+    return(r);
+    }
 
 //---------------------------------------------------------------------------------------------------------------------------------------
 
@@ -457,53 +466,53 @@
     @return KErrNotReady - non-critical error
 */
 TInt TFatDriveInterface::HandleRecoverableError(TInt aResult) const
-	{
-	__PRINT2(_L("TFatDriveInterface::HandleRecoverableError drv:%d, code:%d"), iMount->DriveNumber(),aResult);
+    {
+    __PRINT2(_L("TFatDriveInterface::HandleRecoverableError drv:%d, code:%d"), iMount->DriveNumber(),aResult);
 
-	if (aResult==KErrAccessDenied)
-		return(KErrAccessDenied);
-	if (aResult == KErrLocked)
-		return KErrLocked;
-	if (aResult==KErrArgument || aResult==KErrBadDescriptor)
-		return(KErrCorrupt);
-	if (aResult==KErrBadPower)
-		return(KErrBadPower);
-	if (aResult==KErrDied)	// client thread died
-		return(KErrDied);
-	if (iMount->Drive().IsChanged())
-		{
+    if (aResult==KErrAccessDenied)
+        return(KErrAccessDenied);
+    if (aResult == KErrLocked)
+        return KErrLocked;
+    if (aResult==KErrArgument || aResult==KErrBadDescriptor)
+        return(KErrCorrupt);
+    if (aResult==KErrBadPower)
+        return(KErrBadPower);
+    if (aResult==KErrDied)  // client thread died
+        return(KErrDied);
+    if (iMount->Drive().IsChanged())
+        {
 
         if(! iMount->CheckVolumeTheSame())
             {//-- the media is different now.
             return KErrNotReady;
-			}
-		else if(!IsRecoverableRemount())
-			{
-			return KErrAccessDenied;
-			}
-		}
-	return(ERetry);
-	}	
+            }
+        else if(!IsRecoverableRemount())
+            {
+            return KErrAccessDenied;
+            }
+        }
+    return(ERetry);
+    }   
 
 /** @return true if the mount can be remounted for a recoverable error */
 TBool TFatDriveInterface::IsRecoverableRemount() const
-	{
-	if(IsDriveWriteProtected()&&(iMount->Drive().IsWriteableResource()||iMount->Drive().IsCurrentWriteFunction()))
-		return(EFalse);
-	return(ETrue);
-	}
+    {
+    if(IsDriveWriteProtected()&&(iMount->Drive().IsWriteableResource()||iMount->Drive().IsCurrentWriteFunction()))
+        return(EFalse);
+    return(ETrue);
+    }
 
 /** return true if the media is write protected */
 TBool TFatDriveInterface::IsDriveWriteProtected() const
-	{
-	TLocalDriveCapsV2Buf localDriveCaps;
+    {
+    TLocalDriveCapsV2Buf localDriveCaps;
     TInt r=iProxyDrive.Caps(localDriveCaps);
 
-	if(r!=KErrNone)
-		return(EFalse);
+    if(r!=KErrNone)
+        return(EFalse);
 
-	return((localDriveCaps().iMediaAtt&KMediaAttWriteProtected)!=0);
-	}
+    return((localDriveCaps().iMediaAtt&KMediaAttWriteProtected)!=0);
+    }