userlibandfileserver/fileserver/sfile/sf_drv.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 42 a179b74831c9
child 44 3e88ff8f41d5
equal deleted inserted replaced
42:a179b74831c9 43:c1f20ce4abcf
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 #include "sf_std.h"
    18 #include "sf_std.h"
    19 #include "sf_file_cache.h"
    19 #include "sf_file_cache.h"
    20 
    20 #ifdef OST_TRACE_COMPILER_IN_USE
    21 
    21 #include "sf_drvTraces.h"
       
    22 #endif
    22 //const TInt KMaxNotifierAttempts=4; // not used anywhere
    23 //const TInt KMaxNotifierAttempts=4; // not used anywhere
    23 
    24 
    24 static TPtrC StripBackSlash(const TDesC& aName)
    25 static TPtrC StripBackSlash(const TDesC& aName)
    25 //
    26 //
    26 // If aName ends in a backslash, strip it.
    27 // If aName ends in a backslash, strip it.
   280 	iReason=KErrNone;
   281 	iReason=KErrNone;
   281 
   282 
   282 	if (!aMount.IsDismounted() && !aMount.ProxyDriveDismounted())
   283 	if (!aMount.IsDismounted() && !aMount.ProxyDriveDismounted())
   283 		{
   284 		{
   284 		aMount.SetDrive(this);
   285 		aMount.SetDrive(this);
   285 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMount, EF32TraceUidFileSys, DriveNumber());
   286 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREMOUNT1, "drive %d", DriveNumber());
   286 		
   287 		
   287         //-- actually, this is asking CMountCB to see if it belongs to the current media. 
   288         //-- actually, this is asking CMountCB to see if it belongs to the current media. 
   288         iReason = aMount.ReMount();
   289         iReason = aMount.ReMount();
   289 
   290 
   290 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMountRet, EF32TraceUidFileSys, iReason);
   291 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREMOUNT1RET, "success %d", iReason);
   291 		
   292 		
   292         if (iReason == KErrNone)	//	ReMount succeeded
   293         if (iReason == KErrNone)	//	ReMount succeeded
   293 			{
   294 			{
   294 			aMount.Open();
   295 			aMount.Open();
   295 			iCurrentMount = &aMount;
   296 			iCurrentMount = &aMount;
   321 	{
   322 	{
   322 	CFileSystem* pMountsFs = NULL; //-- reference to the filesystem that will be producing CMountCB
   323 	CFileSystem* pMountsFs = NULL; //-- reference to the filesystem that will be producing CMountCB
   323     
   324     
   324     apMount = NULL;
   325     apMount = NULL;
   325 
   326 
   326     TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber());
   327     OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
   327    
   328    
   328     //-- construct a new CmountCB object.
   329     //-- construct a new CmountCB object.
   329     //-- on return pMountsFs will be the pointer to the factory object of CFileSystem that produced this mount
   330     //-- on return pMountsFs will be the pointer to the factory object of CFileSystem that produced this mount
   330     apMount = FSys().NewMountExL(this, &pMountsFs, aForceMount, aFsNameHash);
   331     apMount = FSys().NewMountExL(this, &pMountsFs, aForceMount, aFsNameHash);
   331 
   332 
   332 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, KErrNone, apMount);
   333 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTLRET, "r %d CMountCB %x", (TUint) KErrNone, (TUint) apMount);
   333 	__PRINT2(_L("TDrive::MountMediaL created mount:0x%x FileSys:0x%x"), apMount, pMountsFs);
   334 	__PRINT2(_L("TDrive::MountMediaL created mount:0x%x FileSys:0x%x"), apMount, pMountsFs);
   334 
   335 
   335     ASSERT(pMountsFs && apMount);
   336     ASSERT(pMountsFs && apMount);
   336 
   337 
   337 	apMount->SetMountNumber(iMountNumber++);
   338 	apMount->SetMountNumber(iMountNumber++);
   396 
   397 
   397     @return standard error code.
   398     @return standard error code.
   398 */
   399 */
   399 TInt TDrive::MountControl(TInt aLevel, TInt aOption, TAny* aParam)
   400 TInt TDrive::MountControl(TInt aLevel, TInt aOption, TAny* aParam)
   400     {
   401     {
   401 	TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBMountControl, EF32TraceUidFileSys, DriveNumber(), aLevel, aOption, aParam);
   402 	OstTraceExt4(TRACE_FILESYSTEM, FSYS_ECMOUNTCBMOUNTCONTROL, "drive %d aLevel %d aOption %x aParam %x", (TUint) DriveNumber(), (TUint) aLevel, (TUint) aOption, (TUint) aParam);
   402     TInt r = CurrentMount().MountControl(aLevel, aOption, aParam);
   403     TInt r = CurrentMount().MountControl(aLevel, aOption, aParam);
   403 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBMountControlRet, EF32TraceUidFileSys, r);
   404 	
   404 
   405 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBMOUNTCONTROLRET, "r %d", r);
   405 	return r;
   406 	return r;
   406     }
   407     }
   407 
   408 
   408 //----------------------------------------------------------------------------
   409 //----------------------------------------------------------------------------
   409 /**
   410 /**
   428 
   429 
   429     //-- 1. Try mount-specific request first. If the mount is still performing free space calculations,
   430     //-- 1. Try mount-specific request first. If the mount is still performing free space calculations,
   430     //-- the caller will be suspended until aFreeSpaceRequired bytes is available or scanning process finishes
   431     //-- the caller will be suspended until aFreeSpaceRequired bytes is available or scanning process finishes
   431     {
   432     {
   432         TUint64 freeSpaceReq = aFreeSpaceRequired;
   433         TUint64 freeSpaceReq = aFreeSpaceRequired;
   433 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFreeSpace, EF32TraceUidFileSys, DriveNumber());
   434 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFREESPACE, "drive %d", DriveNumber());
   434         nRes = CurrentMount().RequestFreeSpace(freeSpaceReq);
   435         nRes = CurrentMount().RequestFreeSpace(freeSpaceReq);
   435 		TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBFreeSpaceRet, EF32TraceUidFileSys, nRes, I64LOW(freeSpaceReq), I64HIGH(freeSpaceReq));
   436 		OstTraceExt3(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFREESPACERET, "r %d FreeSpace %x:%x", (TUint) nRes, (TUint) I64HIGH(freeSpaceReq), (TUint) I64LOW(freeSpaceReq));
   436         if(nRes == KErrNone)
   437         if(nRes == KErrNone)
   437             {
   438             {
   438             return (freeSpaceReq >= aFreeSpaceRequired) ? KErrNone : KErrDiskFull;
   439             return (freeSpaceReq >= aFreeSpaceRequired) ? KErrNone : KErrDiskFull;
   439             }
   440             }
   440     }
   441     }
   460     TInt nRes;
   461     TInt nRes;
   461 
   462 
   462     nRes = CheckMount();
   463     nRes = CheckMount();
   463     if(nRes != KErrNone)
   464     if(nRes != KErrNone)
   464         return nRes;
   465         return nRes;
   465 
       
   466     //-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do if some background activity is going on the mount
   466     //-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do if some background activity is going on the mount
   467 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeSize, EF32TraceUidFileSys, DriveNumber());
   467 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBVOLUMESIZE, "drive %d", DriveNumber());
   468     nRes = CurrentMount().MountedVolumeSize(aSize);
   468     nRes = CurrentMount().MountedVolumeSize(aSize);
   469 	TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeSize, EF32TraceUidFileSys, nRes, I64LOW(aSize), I64HIGH(aSize));
   469 	OstTraceExt3(TRACE_FILESYSTEM, FSYS_ECMOUNTCBVOLUMESIZERET, "r %d aSize %x:%x", (TUint) nRes, (TUint) I64HIGH(aSize), (TUint) I64LOW(aSize));
   470     if(nRes == KErrNone)
   470     if(nRes == KErrNone)
   471         return nRes;
   471         return nRes;
   472 
   472 
   473     //-- given Mount doesn't support this functionality, use legacy method
   473     //-- given Mount doesn't support this functionality, use legacy method
   474     TVolumeInfo volInfo;
   474     TVolumeInfo volInfo;
   497     nRes = CheckMount();
   497     nRes = CheckMount();
   498     if(nRes != KErrNone)
   498     if(nRes != KErrNone)
   499         return nRes;
   499         return nRes;
   500 
   500 
   501     //-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do 
   501     //-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do 
   502 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCurrentFreeSpace, EF32TraceUidFileSys, DriveNumber());
   502 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCURRENTFREESPACE, "drive %d", DriveNumber());
   503     nRes = CurrentMount().GetCurrentFreeSpaceAvailable(aFreeDiskSpace);
   503     nRes = CurrentMount().GetCurrentFreeSpaceAvailable(aFreeDiskSpace);
   504 	TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBCurrentFreeSpaceRet, EF32TraceUidFileSys, nRes, I64LOW(aFreeDiskSpace), I64HIGH(aFreeDiskSpace));
   504 	OstTraceExt3(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCURRENTFREESPACERET, "r %d FreeSpace %x:%x", (TUint) nRes, (TUint) I64HIGH(aFreeDiskSpace), (TUint) I64LOW(aFreeDiskSpace));
   505     if(nRes == KErrNone)
   505     if(nRes == KErrNone)
   506         return nRes;
   506         return nRes;
   507 
   507 
   508     //-- given Mount doesn't support this functionality, use legacy method
   508     //-- given Mount doesn't support this functionality, use legacy method
   509     TVolumeInfo volInfo;
   509     TVolumeInfo volInfo;
   537 		return(r);
   537 		return(r);
   538 
   538 
   539 	if(IsWriteProtected())
   539 	if(IsWriteProtected())
   540 		return(KErrAccessDenied);
   540 		return(KErrAccessDenied);
   541 
   541 
   542 	TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2);
   542 	OstTraceExt4(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFINALISEMOUNT2, "drive %d aOperation %d aParam1 %x aParam2 %x", (TUint) DriveNumber(), (TUint) aOperation, (TUint) aParam1, (TUint) aParam2);
   543 	TRAP(r,CurrentMount().FinaliseMountL(aOperation, aParam1, aParam2));
   543 	TRAP(r,CurrentMount().FinaliseMountL(aOperation, aParam1, aParam2));
   544 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2Ret, EF32TraceUidFileSys, r);
   544 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFINALISEMOUNT2RET, "r %d", r);
   545 	
   545 	
   546 	// Pass FinaliseDrive notification down to media driver
   546 	// Pass FinaliseDrive notification down to media driver
   547 	TInt driveNumber = DriveNumber();
   547 	TInt driveNumber = DriveNumber();
   548 	if (LocalDrives::IsValidDriveMapping(driveNumber) && !LocalDrives::IsProxyDrive(driveNumber))
   548 	if (LocalDrives::IsValidDriveMapping(driveNumber) && !LocalDrives::IsProxyDrive(driveNumber))
   549 		{
   549 		{
   572 		return(r);
   572 		return(r);
   573 
   573 
   574 	if(IsWriteProtected())
   574 	if(IsWriteProtected())
   575 		return(KErrAccessDenied);
   575 		return(KErrAccessDenied);
   576 
   576 
   577 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount1, EF32TraceUidFileSys, DriveNumber());
   577 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFINALISEMOUNT1, "drive %d", DriveNumber());
   578 	TRAP(r,CurrentMount().FinaliseMountL());
   578 	TRAP(r,CurrentMount().FinaliseMountL());
   579 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount1Ret, EF32TraceUidFileSys, r);
   579 	
       
   580 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFINALISEMOUNT1RET, "r %d", r);
   580 	
   581 	
   581     return r;
   582     return r;
   582 	}
   583 	}
   583 
   584 
   584 
   585 
   822 TInt TDrive::ValidateShare(CFileCB& aFile, TShare aReqShare)
   823 TInt TDrive::ValidateShare(CFileCB& aFile, TShare aReqShare)
   823 //
   824 //
   824 // Check that the sharing rules are obeyed.
   825 // Check that the sharing rules are obeyed.
   825 //
   826 //
   826 	{
   827 	{
   827 
   828 	// Check the correct share modes are passed in
   828 	switch (aReqShare)
   829 	switch (aReqShare)
   829 		{
   830 		{
   830 	case EFileShareExclusive:
   831 	case EFileShareExclusive:
   831 	case EFileShareReadersOnly:
   832 	case EFileShareReadersOnly:
   832 	case EFileShareAny:
   833 	case EFileShareAny:
   833 	case EFileShareReadersOrWriters:
   834 	case EFileShareReadersOrWriters:
   834 		break;
   835 		break;
   835 	default:
   836 	default:
   836 		return(KErrArgument);
   837 		return KErrArgument;
   837 		}
   838 		}
       
   839 	
       
   840 	// Check the share mode of the file
   838 	switch (aFile.iShare)
   841 	switch (aFile.iShare)
   839 		{
   842 		{
   840 	case EFileShareExclusive:
   843 	case EFileShareExclusive:
   841 		return(KErrInUse);
   844 		return KErrInUse;
   842 
   845 
   843 	case EFileShareReadersOnly:
   846 	case EFileShareReadersOnly:
   844 	case EFileShareAny:
   847 	case EFileShareAny:
   845 		if (aReqShare != aFile.iShare && aReqShare != EFileShareReadersOrWriters)
   848 		if (aReqShare != aFile.iShare && aReqShare != EFileShareReadersOrWriters)
   846 			return(KErrInUse);
   849 		    {
       
   850             return KErrInUse;
       
   851 		    }
   847 		break;
   852 		break;
   848 
   853 
   849 	case EFileShareReadersOrWriters:
   854 	case EFileShareReadersOrWriters:
   850 		if (aReqShare==EFileShareExclusive)
   855 		if (aReqShare == EFileShareExclusive)
   851 			return(KErrInUse);
   856 		    {
       
   857             return KErrInUse;
       
   858 		    }
   852 		//
   859 		//
   853 		// If the file is currently open as EFileShareReadersOrWriters then
   860 		// If the file is currently opened as EFileShareReadersOrWriters then
   854 		// promote the share to the requested share mode.
   861 		// promote the share to the requested share mode.
       
   862 		// 
       
   863 		// If the requested share is EFileShareReadersOnly, verify that no
       
   864 		// other share has the file opened for writing.
   855 		//
   865 		//
   856 		// If the requested share is EFileShareReadersOnly, verfiy that no
       
   857 		// other share has the file open for writing.
       
   858 		//
       
   859 
       
   860 		if (aReqShare == EFileShareReadersOnly)
   866 		if (aReqShare == EFileShareReadersOnly)
   861 			{
   867 			{
   862 			FileShares->Lock();
   868 			TDblQueIter<CFileShare> fileShareIter(aFile.FileShareList());
   863 			TInt count = FileShares->Count();
   869 			CFileShare* pFileShare;
   864 			while(count--)
   870 			while ((pFileShare = fileShareIter++) != NULL)
   865 				{
   871 				{
   866 				CFileShare* share = (CFileShare*)(*FileShares)[count];
   872 				if(pFileShare->iMode & EFileWrite)
   867 				if (&share->File() == &aFile)
       
   868 					{
   873 					{
   869 					if(share->iMode & EFileWrite)
   874 					return KErrInUse;
   870 						{
       
   871 						FileShares->Unlock();
       
   872 						return KErrInUse;
       
   873 						}
       
   874 					}
   875 					}
   875 				}
   876 				}
   876 			FileShares->Unlock();
       
   877 			}
   877 			}
   878 		break;
   878 		break;
   879     
   879     
   880 	default:
   880 	default:
   881 		Fault(EDrvIllegalShareValue);
   881 		Fault(EDrvIllegalShareValue);
   882         break;
   882         break;
   883 		}
   883 		}
   884 	return(KErrNone);
   884 
   885 	}
   885 	return KErrNone;
   886 
   886 	}
   887 void TDrive::DriveInfo(TDriveInfo& anInfo)
   887 void TDrive::DriveInfo(TDriveInfo& anInfo)
   888 //
   888 //
   889 // Get the drive info.
   889 // Get the drive info.
   890 //
   890 //
   891 	{
   891 	{
   894 	anInfo.iBattery=EBatNotSupported;
   894 	anInfo.iBattery=EBatNotSupported;
   895     anInfo.iConnectionBusType=EConnectionBusInternal;
   895     anInfo.iConnectionBusType=EConnectionBusInternal;
   896 
   896 
   897 	if(iFSys)
   897 	if(iFSys)
   898 		{
   898 		{
   899 		TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemDriveInfo, EF32TraceUidFileSys, &FSys(), DriveNumber());
   899 		OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMDRIVEINFO, "this %x aDriveNumber %d", (TUint) &FSys(), (TUint) DriveNumber());
   900 		FSys().DriveInfo(anInfo,DriveNumber());
   900 		FSys().DriveInfo(anInfo,DriveNumber());
   901 		TRACE3(UTF::EBorder, UTraceModuleFileSys::ECFileSystemDriveInfoRet, EF32TraceUidFileSys, 
   901 		OstTraceExt3(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMDRIVEINFORET, "type %d driveAtt %x mediaAtt %x", (TUint) anInfo.iType, (TUint) anInfo.iDriveAtt, (TUint) anInfo.iMediaAtt);
   902 			anInfo.iType, anInfo.iDriveAtt, anInfo.iMediaAtt);
       
   903 		}
   902 		}
   904 
   903 
   905 	anInfo.iDriveAtt=Att();
   904 	anInfo.iDriveAtt=Att();
   906 	}
   905 	}
   907 
   906 
   917 		CMountCB& m=CurrentMount();
   916 		CMountCB& m=CurrentMount();
   918 		aVolume.iName=m.VolumeName();
   917 		aVolume.iName=m.VolumeName();
   919 		aVolume.iUniqueID=m.iUniqueID;
   918 		aVolume.iUniqueID=m.iUniqueID;
   920 		aVolume.iSize=m.iSize;
   919 		aVolume.iSize=m.iSize;
   921 
   920 
   922 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeL, EF32TraceUidFileSys, DriveNumber());
   921 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBVOLUMEL, "drive %d", DriveNumber());
   923 		TRAP(r,m.VolumeL(aVolume))
   922 		TRAP(r,m.VolumeL(aVolume))
   924 		TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeLRet, EF32TraceUidFileSys, 
   923 		OstTraceExt5(TRACE_FILESYSTEM, FSYS_ECMOUNTCBVOLUMELRETA, "r %d iSize %x:%x iFree %x:%x", (TUint) r, (TUint) I64HIGH(aVolume.iSize), (TUint) I64LOW(aVolume.iSize), (TUint) I64HIGH(aVolume.iFree), (TUint) I64LOW(aVolume.iFree));
   925 			r, aVolume.iUniqueID, I64LOW(aVolume.iSize), I64HIGH(aVolume.iSize),
   924 		OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECMOUNTCBVOLUMELRETB, "iUniqueID %x iFileCacheFlags %x", (TUint) aVolume.iUniqueID, (TUint) aVolume.iFileCacheFlags);
   926 			I64LOW(aVolume.iFree), I64HIGH(aVolume.iFree), aVolume.iFileCacheFlags);
       
   927 
       
   928 		}
   925 		}
   929 	return(r);
   926 	return(r);
   930 	}
   927 	}
   931 
   928 
   932 
   929 
   936 //
   933 //
   937 	{
   934 	{
   938 	__CHECK_DRIVETHREAD(iDriveNumber);
   935 	__CHECK_DRIVETHREAD(iDriveNumber);
   939 	aBuf=aName.AllocL();
   936 	aBuf=aName.AllocL();
   940 	TPtr volumeName=aBuf->Des();
   937 	TPtr volumeName=aBuf->Des();
   941 
   938 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSETVOLUMEL, "drive %d", DriveNumber());
   942 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetVolumeL, EF32TraceUidFileSys, DriveNumber(), aName);
   939 	OstTraceData(TRACE_FILESYSTEM, FSYS_EVOLUMENAME, "VolumeName %S", aName.Ptr(), aName.Length()<<1);
       
   940 	
   943 	CurrentMount().SetVolumeL(volumeName);
   941 	CurrentMount().SetVolumeL(volumeName);
   944 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetVolumeLRet, EF32TraceUidFileSys, KErrNone);
   942 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSETVOLUMELRET, "r %d", KErrNone);
   945 
       
   946 
       
   947 	delete &CurrentMount().VolumeName();
   943 	delete &CurrentMount().VolumeName();
   948 	CurrentMount().SetVolumeName(aBuf);
   944 	CurrentMount().SetVolumeName(aBuf);
   949 	}
   945 	}
   950 
   946 
   951 TInt TDrive::SetVolume(const TDesC& aName)
   947 TInt TDrive::SetVolume(const TDesC& aName)
   976 		return(r);
   972 		return(r);
   977 	if(IsWriteProtected())
   973 	if(IsWriteProtected())
   978 		return(KErrAccessDenied);
   974 		return(KErrAccessDenied);
   979 	TParse newDirName;
   975 	TParse newDirName;
   980 	newDirName.Set(aName,NULL,NULL);
   976 	newDirName.Set(aName,NULL,NULL);
   981 
   977 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBMKDIRL, "drive %d", DriveNumber());
   982 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBMkDirL, EF32TraceUidFileSys, DriveNumber(), aName);
   978 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBMKDIRLYS_EDIRNAME, "Dir %S", aName.Ptr(), aName.Length()<<1);
   983 	TRAP(r,CurrentMount().MkDirL(newDirName.FullName()))
   979 	TRAP(r,CurrentMount().MkDirL(newDirName.FullName()))
   984 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBMkDirLRet, EF32TraceUidFileSys, r);
   980 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBMKDIRLRET, "r %d", r);
   985 
       
   986 	return(r);
   981 	return(r);
   987 	}
   982 	}
   988 
       
   989 TInt TDrive::RmDir(const TDesC& aName)
   983 TInt TDrive::RmDir(const TDesC& aName)
   990 //
   984 //
   991 // Remove a directory.
   985 // Remove a directory.
   992 //
   986 //
   993 	{
   987 	{
  1000 		return(r);
   994 		return(r);
  1001 	if (entry.IsDir()==EFalse)
   995 	if (entry.IsDir()==EFalse)
  1002 		return(KErrPathNotFound);
   996 		return(KErrPathNotFound);
  1003 	if ((entry.iAtt&KEntryAttReadOnly) || IsWriteProtected())
   997 	if ((entry.iAtt&KEntryAttReadOnly) || IsWriteProtected())
  1004 		return(KErrAccessDenied);
   998 		return(KErrAccessDenied);
  1005 
   999 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBRMDIRL, "drive %d", DriveNumber());
  1006 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirL, EF32TraceUidFileSys, DriveNumber(), aName);
  1000 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBRMDIRLYS_EDIRNAME, "Dir %S", aName.Ptr(), aName.Length()<<1);
  1007 	TRAP(r,CurrentMount().RmDirL(aName))
  1001 	TRAP(r,CurrentMount().RmDirL(aName))
  1008 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirLRet, EF32TraceUidFileSys, r);
  1002 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBRMDIRLRET, "r %d", r);
  1009 
       
  1010 	return(r);
  1003 	return(r);
  1011 	}
  1004 	}
  1012 
  1005 
  1013 /*
  1006 /*
  1014  Delete files allowing wild cards.
  1007  Delete files allowing wild cards.
  1025 	// remove from closed queue - NB this isn't strictly necessary if file is read-only or write-protected...
  1018 	// remove from closed queue - NB this isn't strictly necessary if file is read-only or write-protected...
  1026 	LocateClosedFile(aName, EFalse);
  1019 	LocateClosedFile(aName, EFalse);
  1027 
  1020 
  1028     if (IsWriteProtected())
  1021     if (IsWriteProtected())
  1029 		return(KErrAccessDenied);
  1022 		return(KErrAccessDenied);
  1030 
  1023 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDELETEL1, "drive %d", DriveNumber());
  1031     //-- filesystems' CMountCB::DeleteL() implementations shall check the entry attributes themeselves. 
  1024 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDELETEL1_EFILENAME, "FileName %S", aName.Ptr(), aName.Length()<<1);
  1032 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteL, EF32TraceUidFileSys, DriveNumber(), aName);
       
  1033 	TRAP(r,CurrentMount().DeleteL(aName))
  1025 	TRAP(r,CurrentMount().DeleteL(aName))
  1034 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteLRet, EF32TraceUidFileSys, r);
  1026 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDELETEL1_RET, "r %d", r);
  1035 
       
  1036 	return r;
  1027 	return r;
  1037 	}
  1028 	}
  1038 
  1029 
  1039 TInt TDrive::CheckMountAndEntryNames(const TDesC& anOldName,const TDesC& aNewName)
  1030 TInt TDrive::CheckMountAndEntryNames(const TDesC& anOldName,const TDesC& aNewName)
  1040 //
  1031 //
  1101 		return(KErrAccessDenied);
  1092 		return(KErrAccessDenied);
  1102 
  1093 
  1103 	// remove from closed queue
  1094 	// remove from closed queue
  1104 	LocateClosedFile(anOldName, EFalse);
  1095 	LocateClosedFile(anOldName, EFalse);
  1105 	LocateClosedFile(aNewName, EFalse);
  1096 	LocateClosedFile(aNewName, EFalse);
  1106 
  1097 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBRENAMEL, "drive %d", DriveNumber());
  1107 	TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBRenameL, EF32TraceUidFileSys, DriveNumber(), oldEntryName,newEntryName);
  1098 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBRENAMELYS_EOLDNAME, "OldName %S", oldEntryName.Ptr(), oldEntryName.Length()<<1);
       
  1099 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBRENAMELYS_ENEWNAME, "NewName %S", newEntryName.Ptr(), newEntryName.Length()<<1);
  1108 	TRAP(r,CurrentMount().RenameL(oldEntryName,newEntryName))
  1100 	TRAP(r,CurrentMount().RenameL(oldEntryName,newEntryName))
  1109 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRenameLRet, EF32TraceUidFileSys, r);
  1101 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBRENAMELRET, "r %d", r);
  1110 
       
  1111 	return(r);
  1102 	return(r);
  1112 	}
  1103 	}
  1113 
  1104 
  1114 TInt TDrive::Replace(const TDesC& anOldName,const TDesC& aNewName)
  1105 TInt TDrive::Replace(const TDesC& anOldName,const TDesC& aNewName)
  1115 //
  1106 //
  1139 		return(KErrInUse);
  1130 		return(KErrInUse);
  1140 
  1131 
  1141 	// remove from closed queue
  1132 	// remove from closed queue
  1142 	LocateClosedFile(anOldName, EFalse);
  1133 	LocateClosedFile(anOldName, EFalse);
  1143 	LocateClosedFile(aNewName, EFalse);
  1134 	LocateClosedFile(aNewName, EFalse);
  1144 
  1135 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREPLACEL, "drive %d", DriveNumber());
  1145 	TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBReplaceL, EF32TraceUidFileSys, DriveNumber(), anOldName, aNewName);
  1136 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREPLACEL_EOLDNAME, "OldName %S", anOldName.Ptr(), anOldName.Length()<<1);
       
  1137 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREPLACEL_ENEWNAME, "NewName %S", aNewName.Ptr(), aNewName.Length()<<1);
  1146 	TRAP(r,CurrentMount().ReplaceL(anOldName,aNewName))
  1138 	TRAP(r,CurrentMount().ReplaceL(anOldName,aNewName))
  1147 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReplaceLRet, EF32TraceUidFileSys, r);
  1139 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREPLACELRET, "r %d", r);
  1148 
       
  1149 	return(r);
  1140 	return(r);
  1150 	}
  1141 	}
  1151 
  1142 
  1152 TInt TDrive::Entry(const TDesC& aName,TEntry& anEntry)
  1143 TInt TDrive::Entry(const TDesC& aName,TEntry& anEntry)
  1153 //
  1144 //
  1172 void TDrive::DoEntryL(const TDesC& aName, TEntry& anEntry)
  1163 void TDrive::DoEntryL(const TDesC& aName, TEntry& anEntry)
  1173 //
  1164 //
  1174 // Get entry details
  1165 // Get entry details
  1175 //
  1166 //
  1176 	{
  1167 	{
  1177 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBEntryL, EF32TraceUidFileSys, DriveNumber(), aName);
  1168 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBENTRYL, "drive %d", DriveNumber());
       
  1169 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBENTRYL_EFILEPATH, "FilePath %S", aName.Ptr(), aName.Length()<<1);
  1178 	CurrentMount().EntryL(aName,anEntry);
  1170 	CurrentMount().EntryL(aName,anEntry);
  1179 
  1171 
  1180 	// If the file is already open then read the file attributes directly from the file
  1172 	// If the file is already open then read the file attributes directly from the file
  1181 	TFileName foldedName;
  1173 	TFileName foldedName;
  1182 	TUint32 nameHash=0;
  1174 	TUint32 nameHash=0;
  1200 			break;
  1192 			break;
  1201 			}
  1193 			}
  1202 		}
  1194 		}
  1203 
  1195 
  1204 
  1196 
  1205 	TRACE5(UTF::EBorder, UTraceModuleFileSys::ECMountCBEntryLRet, EF32TraceUidFileSys, 
  1197 	OstTraceExt5(TRACE_FILESYSTEM, FSYS_ECMOUNTCBENTRYLRET, "att %x modified %x:%x  size %x:%x", (TUint) anEntry.iAtt, (TUint) I64HIGH(anEntry.iModified.Int64()), (TUint) I64LOW(anEntry.iModified.Int64()), (TUint) I64HIGH(anEntry.FileSize()), (TUint) anEntry.FileSize());
  1206 		KErrNone, anEntry.iAtt, 
       
  1207 		I64LOW(anEntry.iModified.Int64()), I64HIGH(anEntry.iModified.Int64()), 
       
  1208 		anEntry.iSize);
       
  1209 
       
  1210 	}
  1198 	}
  1211 
  1199 
  1212 TInt TDrive::CheckAttributes(TUint& aSetAttMask,TUint& aClearAttMask)
  1200 TInt TDrive::CheckAttributes(TUint& aSetAttMask,TUint& aClearAttMask)
  1213 //
  1201 //
  1214 // Validate the changes against the current entry attributes
  1202 // Validate the changes against the current entry attributes
  1237 	if (IsWriteProtected())
  1225 	if (IsWriteProtected())
  1238 		return(KErrAccessDenied);
  1226 		return(KErrAccessDenied);
  1239 	TTime nullTime(0);
  1227 	TTime nullTime(0);
  1240 	if (aTime!=nullTime)
  1228 	if (aTime!=nullTime)
  1241 		aSetAttMask|=KEntryAttModified;
  1229 		aSetAttMask|=KEntryAttModified;
  1242 
  1230 	OstTraceExt5(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSETENTRYL, "drive %d aTime %x:%x  aSetAttMask %x aClearAttMask %x", (TUint) DriveNumber(), (TUint) I64HIGH(aTime.Int64()), (TUint) I64LOW(aTime.Int64()), (TUint) aSetAttMask, (TUint) aClearAttMask);
  1243 	TRACEMULT6(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetEntryL, EF32TraceUidFileSys, 
  1231 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSETENTRYL_EFILEPATH, "FilePath %S", aName.Ptr(), aName.Length()<<1);
  1244 		DriveNumber(), aName, I64LOW(aTime.Int64()), I64HIGH(aTime.Int64()), aSetAttMask, aClearAttMask);
       
  1245 	TRAP(r,CurrentMount().SetEntryL(entryName,aTime,aSetAttMask,aClearAttMask))
  1232 	TRAP(r,CurrentMount().SetEntryL(entryName,aTime,aSetAttMask,aClearAttMask))
  1246 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetEntryLRet, EF32TraceUidFileSys, r);
  1233 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSETENTRYLRET, "r %d", r);
       
  1234 
  1247 	// If the file is already open then write the file attributes directly to the file
  1235 	// If the file is already open then write the file attributes directly to the file
  1248 	TFileName foldedName;
  1236 	TFileName foldedName;
  1249 	TUint32 nameHash=0;
  1237 	TUint32 nameHash=0;
  1250 	foldedName.CopyF(aName);
  1238 	foldedName.CopyF(aName);
  1251 	nameHash=CalcNameHash(foldedName);
  1239 	nameHash=CalcNameHash(foldedName);
  1383 
  1371 
  1384 	// Only allow delete on close for a newly created file.
  1372 	// Only allow delete on close for a newly created file.
  1385 	if ((aMode & EDeleteOnClose) && (anOpen!=EFileCreate))
  1373 	if ((aMode & EDeleteOnClose) && (anOpen!=EFileCreate))
  1386 		User::Leave(KErrArgument);
  1374 		User::Leave(KErrArgument);
  1387 
  1375 
  1388 	CFileCB* pF=LocateFile(aName);
  1376 	CFileCB* pFile=LocateFile(aName);
  1389 	CFileCache* pFileCache = NULL;
  1377 	CFileCache* pFileCache = NULL;
  1390 	TBool openFile=EFalse;
  1378 	TBool openFile=EFalse;	// True if file is being opened for the first time
  1391 	if (pF!=NULL)
  1379 	if (pFile!=NULL)		// File is already opened on the drive
  1392 		{
  1380 		{
  1393 		if (pF->iShare==EFileShareReadersOnly && (aMode&EFileWrite)!=0)
  1381 		if (pFile->iShare==EFileShareReadersOnly && (aMode&EFileWrite))
  1394 			User::Leave(KErrInUse);
  1382 			User::Leave(KErrInUse);
  1395 		if (anOpen==EFileCreate)
  1383 		if (anOpen==EFileCreate)
  1396 			User::Leave(KErrAlreadyExists);
  1384 			User::Leave(KErrAlreadyExists);
  1397 		TInt r=ValidateShare(*pF,share);
  1385 		TInt r=ValidateShare(*pFile,share);
  1398 		if (r!=KErrNone)
  1386 		if (r!=KErrNone)
  1399 			User::Leave(r);
  1387 			User::Leave(r);
  1400 		if ((r=pF->Open())!=KErrNone)
  1388 		if ((r=pFile->Open())!=KErrNone)
  1401 			User::Leave(r);
  1389 			User::Leave(r);
  1402 		aFileCB=pF;
  1390 		
  1403 		pFileCache = pF->FileCache();
  1391 		aFileCB=pFile;
       
  1392 		pFileCache = pFile->FileCache();
  1404 		}
  1393 		}
  1405 	else
  1394 	else
  1406 		{
  1395 		{
  1407 		TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  1396 		OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWFILEL, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
  1408 
       
  1409         //-- construct CFileCB object, belonging to the corresponding mount
  1397         //-- construct CFileCB object, belonging to the corresponding mount
  1410         pF = aFileCB = CurrentMount().NewFileL();
  1398         pFile = aFileCB = CurrentMount().NewFileL();
  1411 
  1399 
  1412 		TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileLRet, EF32TraceUidFileSys, r, pF);
  1400 		OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWFILELRET, "r %d CFileCB %x", (TUint) r, (TUint) pFile);
  1413 		TDrive* createdDrive=!aRequest->SubstedDrive() ? this : aRequest->SubstedDrive();
  1401 		TDrive* createdDrive=!aRequest->SubstedDrive() ? this : aRequest->SubstedDrive();
  1414 
  1402 
  1415     	HBufC* fileName = CreateFileNameL(aName);
  1403     	HBufC* fileName = CreateFileNameL(aName);
  1416 
  1404 
  1417         pF->InitL(this, createdDrive, fileName);
  1405         pFile->InitL(this, createdDrive, fileName);
  1418 
  1406 
  1419 
  1407 		pFile->iShare = share;
  1420 		pF->iShare = share;
  1408 		pFile->SetSequentialMode(aMode & EFileSequential);
  1421 		openFile=ETrue;
  1409 		openFile=ETrue;
  1422 		CurrentMount().iMountQ.AddLast(*pF);
  1410 		CurrentMount().iMountQ.AddLast(*pFile);
  1423 		Files->AddL(pF,ETrue);
  1411 		Files->AddL(pFile,ETrue);
  1424 		}
  1412 		__PRINT1(_L("TDrive::FileOpenL - CFileCB->IsSequentialMode = %d"), pFile->IsSequentialMode());
  1425 	
  1413 		}
  1426     CFileShare* pS=aFileShare=new(ELeave) CFileShare(pF);
  1414 	
       
  1415     CFileShare* pFileShare=aFileShare=new(ELeave) CFileShare(pFile);
  1427 
  1416 
  1428 	// We need to call CFileCB::PromoteShare immediately after the CFileShare 
  1417 	// We need to call CFileCB::PromoteShare immediately after the CFileShare 
  1429 	// instance is created since the destructor calls CFileCB::DemoteShare()
  1418 	// instance is created since the destructor calls CFileCB::DemoteShare()
  1430 	// which checks the share count is non-zero
  1419 	// which checks the share count is non-zero
  1431 	pS->iMode=aMode;
  1420 	pFileShare->iMode=aMode;
  1432 	pF->PromoteShare(pS);
  1421 	pFile->PromoteShare(pFileShare);
  1433 
  1422 
  1434 	pS->InitL();
  1423 	pFileShare->InitL();
  1435 	aFileCB=NULL; 
  1424 	aFileCB=NULL; 
  1436 	FileShares->AddL(pS,ETrue);
  1425 	FileShares->AddL(pFileShare,ETrue);
  1437 	aHandle=aRequest->Session()->Handles().AddL(pS,ETrue);
  1426 	aHandle=aRequest->Session()->Handles().AddL(pFileShare,ETrue);
  1438 
  1427 
  1439 
  1428 
  1440 	if (openFile)
  1429 	if (openFile)
  1441 		{
  1430 		{
  1442 		TRACEMULT5(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenL, EF32TraceUidFileSys, DriveNumber(), aName, aMode, (TUint) anOpen, (TUint) pF);
  1431 		OstTraceExt4(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFILEOPENL, "drive %d aMode %x anOpen %d aFile %x", (TUint) DriveNumber(), (TUint) aMode, (TUint) anOpen, (TUint) pFile);
  1443 		CurrentMount().FileOpenL(aName,aMode,anOpen,pF);
  1432 		OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFILEOPENL_EFILENAME, "FileName %S", aName.Ptr(), aName.Length()<<1);
  1444 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenLRet, EF32TraceUidFileSys, KErrNone);
  1433 		CurrentMount().FileOpenL(aName,aMode,anOpen,pFile);
  1445 
  1434 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFILEOPENLRET, "r %d", KErrNone);
  1446 		// Delete on close may now be safely flagged if required.
  1435 		// Delete on close may now be safely flagged if required.
  1447 		// The file did not exist on the media prior to the
  1436 		// The file did not exist on the media prior to the
  1448 		// CMountCB::FileOpenL() call for the case of a create.
  1437 		// CMountCB::FileOpenL() call for the case of a create.
  1449 		if ((aMode & EDeleteOnClose) && (anOpen==EFileCreate))
  1438 		if ((aMode & EDeleteOnClose) && (anOpen==EFileCreate))
  1450 			pF->SetDeleteOnClose();
  1439 			pFile->SetDeleteOnClose();
  1451 
  1440 
  1452 		TBool localBufferSuppport = (CurrentMount().LocalBufferSupport(pF) == KErrNone)?(TBool)ETrue:(TBool)EFalse;
  1441 		TBool localBufferSuppport = (CurrentMount().LocalBufferSupport(pFile) == KErrNone)?(TBool)ETrue:(TBool)EFalse;
  1453 		pF->SetLocalBufferSupport(localBufferSuppport);
  1442 		pFile->SetLocalBufferSupport(localBufferSuppport);
  1454 		if (localBufferSuppport)
  1443 		if (localBufferSuppport)
  1455 			{
  1444 			{
  1456 			// if file exists on closed queue resurrect it or discard it,
  1445 			// If file exists on closed queue resurrect it or discard it,
  1457 			// depending on the file open mode
  1446 			// depending on the file open mode
  1458 			pFileCache = LocateClosedFile(aName, anOpen == EFileOpen?(TBool)ETrue:(TBool)EFalse);
  1447 			pFileCache = LocateClosedFile(aName, anOpen == EFileOpen?(TBool)ETrue:(TBool)EFalse);
  1459 			if (pFileCache)
  1448 			if (pFileCache)
  1460 				{
  1449 				{
  1461 				pFileCache = pFileCache->ReNewL(*pS);	// NB may return NULL if caching not enabled
  1450 				pFileCache = pFileCache->ReNewL(*pFileShare);	// NB may return NULL if caching not enabled
  1462 				}
  1451 				}
  1463 			else
  1452 			else
  1464 				{
  1453 				{
  1465 				pFileCache = CFileCache::NewL(*pS);		// NB may return NULL if caching not enabled
  1454 				pFileCache = CFileCache::NewL(*pFileShare);		// NB may return NULL if caching not enabled
  1466 				}
  1455 				}
  1467 			if (pFileCache)
  1456 			if (pFileCache)
  1468 				// set the cached size to be the same as the uncached size
  1457 				// Set the cached size to be the same as the uncached size
  1469 				pF->SetCachedSize64(pF->Size64());
  1458 				pFile->SetCachedSize64(pFile->Size64());
  1470 			}
  1459 			}
  1471 		else
  1460 		else
  1472 			{
  1461 			{
  1473 			__CACHE_PRINT(_L("TDrive::FileOpenL(), Local buffers not supported"));
  1462 			__CACHE_PRINT(_L("TDrive::FileOpenL(), Local buffers not supported"));
  1474 			}
  1463 			}
  1475 		}
  1464 		}
  1476 
  1465 
  1477 	// initialize share mode flags
  1466 	// Initialize share mode flags
  1478 	if (pFileCache != NULL)
  1467 	if (pFileCache != NULL)
  1479 		pFileCache->Init(*pS);
  1468 		pFileCache->Init(*pFileShare);
  1480 	}
  1469 	}
  1481 
  1470 
  1482 TInt TDrive::FileOpen(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen)
  1471 TInt TDrive::FileOpen(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen)
  1483 //
  1472 //
  1484 // Open/Create/Replace a file.
  1473 // Open/Create/Replace a file.
  1486 	{
  1475 	{
  1487 	__CHECK_DRIVETHREAD(iDriveNumber);
  1476 	__CHECK_DRIVETHREAD(iDriveNumber);
  1488 	CFileCB* pF=NULL;
  1477 	CFileCB* pF=NULL;
  1489 	CFileShare* pS=NULL;
  1478 	CFileShare* pS=NULL;
  1490 	aHandle=0;
  1479 	aHandle=0;
  1491 	TRAPD(r,FileOpenL(aRequest,aHandle,aName,aMode,anOpen,pF,pS))
  1480 	TRAPD(r,FileOpenL(aRequest,aHandle,aName,aMode,anOpen,pF,pS));
  1492 
  1481 
  1493 	// Allow files > 2GB-1 to be opened only if EFileBigFile is specified in iMode
  1482 	// Allow files > 2GB-1 to be opened only if EFileBigFile is specified in iMode
  1494 	if (r == KErrNone && pS && ((TUint64)pS->File().Size64() > KMaxLegacyFileSize) && (!(pS->IsFileModeBig())))
  1483 	if (r == KErrNone && pS && ((TUint64)pS->File().Size64() > KMaxLegacyFileSize) && (!(pS->IsFileModeBig())))
  1495 		r = KErrTooBig;
  1484 		r = KErrTooBig;
  1496 
  1485 
  1511 void TDrive::DirOpenL(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType,CDirCB*& aDir)
  1500 void TDrive::DirOpenL(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType,CDirCB*& aDir)
  1512 //
  1501 //
  1513 // Open a directory listing. Leave on error.
  1502 // Open a directory listing. Leave on error.
  1514 //
  1503 //
  1515 	{
  1504 	{
  1516 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewDirL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  1505 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWDIRL, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
  1517 
       
  1518     CDirCB* pD = aDir = CurrentMount().NewDirL(); //-- construct CDirCB object, belonging to the corresponding mount
  1506     CDirCB* pD = aDir = CurrentMount().NewDirL(); //-- construct CDirCB object, belonging to the corresponding mount
  1519 
  1507 
  1520 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewDirLRet, EF32TraceUidFileSys, KErrNone, pD);
  1508 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWDIRLRET, "r %d CDirCB %x", (TUint) KErrNone, (TUint) pD);
  1521 	pD->InitL(this);
  1509 	pD->InitL(this);
  1522 	// modify resource counter after initialisation to ensure correct cleanup
  1510 	// modify resource counter after initialisation to ensure correct cleanup
  1523 	AddResource(CurrentMount());
  1511 	AddResource(CurrentMount());
  1524 	pD->iAtt=anAtt;
  1512 	pD->iAtt=anAtt;
  1525 	pD->iUidType=aUidType;
  1513 	pD->iUidType=aUidType;
  1526 	Dirs->AddL(pD,ETrue);
  1514 	Dirs->AddL(pD,ETrue);
  1527 	aHandle=aSession->Handles().AddL(pD,ETrue);
  1515 	aHandle=aSession->Handles().AddL(pD,ETrue);
  1528 
  1516 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDIROPENL, "drive %d aDir %x", (TUint) DriveNumber(), (TUint) pD);
  1529 	TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBDirOpenL, EF32TraceUidFileSys, DriveNumber(), aName, (TUint) pD);
  1517 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDIROPENL_EDIRNAME, "Dir %S", aName.Ptr(), aName.Length()<<1);
  1530 	CurrentMount().DirOpenL(aName,pD);
  1518 	CurrentMount().DirOpenL(aName,pD);
  1531 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDirOpenLRet, EF32TraceUidFileSys, KErrNone);
  1519 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDIROPENLRET, "r %d", KErrNone);
  1532 	}
  1520 	}
  1533 
  1521 
  1534 TInt TDrive::DirOpen(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType)
  1522 TInt TDrive::DirOpen(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType)
  1535 //
  1523 //
  1536 // Open a directory listing.
  1524 // Open a directory listing.
  1585 	__PRINT(_L("TDrive::ReadSection"));
  1573 	__PRINT(_L("TDrive::ReadSection"));
  1586 	TInt r=CheckMountAndEntryName(aName);
  1574 	TInt r=CheckMountAndEntryName(aName);
  1587 	if (r!=KErrNone)
  1575 	if (r!=KErrNone)
  1588 		return(r);
  1576 		return(r);
  1589 	TPtrC entryName(StripBackSlash(aName));
  1577 	TPtrC entryName(StripBackSlash(aName));
  1590 
       
  1591 	TRACETHREADID(aMessage);
  1578 	TRACETHREADID(aMessage);
  1592 	TRACEMULT7(UTF::EBorder, UTraceModuleFileSys::ECMountCBReadFileSectionL, EF32TraceUidFileSys, 
  1579 	OstTraceExt5(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREADFILESECTIONL, "drive %d clientThreadId %x aPos %x:%x aLength %d", (TUint) DriveNumber(), (TUint) threadId, (TUint) I64HIGH(aPos), (TUint) I64LOW(aPos), (TUint) aLength);
  1593 		DriveNumber(), aName, I64LOW(aPos), I64HIGH(aPos), (TUint) aTrg, aLength, I64LOW(threadId));
  1580 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREADFILESECTIONL_EFILENAME, "FileName %S", aName.Ptr(), aName.Length()<<1);
  1594 	TRAP(r,ReadSectionL(entryName,aPos,aTrg,aLength,aMessage));
  1581 	TRAP(r,ReadSectionL(entryName,aPos,aTrg,aLength,aMessage));
  1595 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReadFileSectionLRet, EF32TraceUidFileSys, r);
  1582 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBREADFILESECTIONLRET, "r %d", r);
  1596 
       
  1597 	if (r==KErrHidden)
  1583 	if (r==KErrHidden)
  1598 		r=KErrNotFound;	
  1584 		r=KErrNotFound;	
  1599 	else if (r==KErrPathHidden)
  1585 	else if (r==KErrPathHidden)
  1600 		r=KErrPathNotFound;
  1586 		r=KErrPathNotFound;
  1601 
  1587 
  1623 	TInt r=CheckMount();
  1609 	TInt r=CheckMount();
  1624 	if (r==KErrNone)
  1610 	if (r==KErrNone)
  1625 		TRAP(r,FlushCachedFileInfoL());
  1611 		TRAP(r,FlushCachedFileInfoL());
  1626 	if (r==KErrNone)
  1612 	if (r==KErrNone)
  1627 		{
  1613 		{
  1628 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk1, EF32TraceUidFileSys, DriveNumber());
  1614 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCHECKDISK1, "drive %d", DriveNumber());
  1629 		r=CurrentMount().CheckDisk();
  1615 		r=CurrentMount().CheckDisk();
  1630 		TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk1Ret, EF32TraceUidFileSys, r);
  1616 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCHECKDISK1RET, "r %d", r);
  1631 		}
  1617 		}
  1632 	return(r);
  1618 	return(r);
  1633 	}
  1619 	}
  1634 
  1620 
  1635 /**
  1621 /**
  1640 	TInt r=CheckMount();
  1626 	TInt r=CheckMount();
  1641 	if (r==KErrNone)
  1627 	if (r==KErrNone)
  1642 		TRAP(r,FlushCachedFileInfoL());
  1628 		TRAP(r,FlushCachedFileInfoL());
  1643 	if (r==KErrNone)
  1629 	if (r==KErrNone)
  1644 		{
  1630 		{
  1645 		TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2);
  1631 		OstTraceExt4(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCHECKDISK2, "drive %d aOperation %d aParam1 %x aParam2 %x", (TUint) DriveNumber(), (TUint) aOperation, (TUint) aParam1, (TUint) aParam2);
  1646 		r=CurrentMount().CheckDisk(aOperation, aParam1, aParam2);
  1632 		r=CurrentMount().CheckDisk(aOperation, aParam1, aParam2);
  1647 		TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk2Ret, EF32TraceUidFileSys, r);
  1633 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCHECKDISK2RET, "r %d", r);
  1648 		}
  1634 		}
  1649 
  1635 
  1650 	return(r);
  1636 	return(r);
  1651     }
  1637     }
  1652 
  1638 
  1664 		return r;
  1650 		return r;
  1665 
  1651 
  1666 	// Empty closed file queue
  1652 	// Empty closed file queue
  1667 	TClosedFileUtils::Remove(DriveNumber());
  1653 	TClosedFileUtils::Remove(DriveNumber());
  1668 
  1654 
  1669 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive1, EF32TraceUidFileSys, DriveNumber());
  1655 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSCANDRIVE1, "drive %d", DriveNumber());
  1670 	r = CurrentMount().ScanDrive();
  1656 	r = CurrentMount().ScanDrive();
  1671 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive1Ret, EF32TraceUidFileSys, r);
  1657 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSCANDRIVE1RET, "r %d", r);
  1672 
       
  1673 	return r;
  1658 	return r;
  1674 	}
  1659 	}
  1675 
  1660 
  1676 
  1661 
  1677 /**
  1662 /**
  1691 		return r;
  1676 		return r;
  1692 
  1677 
  1693 	// Empty closed file queue
  1678 	// Empty closed file queue
  1694 	TClosedFileUtils::Remove(DriveNumber());
  1679 	TClosedFileUtils::Remove(DriveNumber());
  1695 
  1680 
  1696 	TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2);
  1681 	OstTraceExt4(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSCANDRIVE2, "drive %d aOperation %d aParam1 %x aParam2 %x", (TUint) DriveNumber(), (TUint) aOperation, (TUint) aParam1, (TUint) aParam2);
  1697 	r = CurrentMount().ScanDrive(aOperation, aParam1, aParam2);
  1682 	r = CurrentMount().ScanDrive(aOperation, aParam1, aParam2);
  1698 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive2Ret, EF32TraceUidFileSys, r);
  1683 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBSCANDRIVE2RET, "r %d", r);
  1699 
       
  1700 	return r;
  1684 	return r;
  1701 	}
  1685 	}
  1702 
  1686 
  1703 
  1687 
  1704 TInt TDrive::GetShortName(const TDesC& aName,TDes& aShortName)
  1688 TInt TDrive::GetShortName(const TDesC& aName,TDes& aShortName)
  1708 	{
  1692 	{
  1709 	TInt r=CheckMountAndEntryName(aName);
  1693 	TInt r=CheckMountAndEntryName(aName);
  1710 	if (r!=KErrNone)
  1694 	if (r!=KErrNone)
  1711 		return(r);
  1695 		return(r);
  1712 	TPtrC entryName(StripBackSlash(aName));
  1696 	TPtrC entryName(StripBackSlash(aName));
  1713 
  1697 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETSHORTNAMEL, "drive %d", DriveNumber());
  1714 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetShortNameL, EF32TraceUidFileSys, DriveNumber(), entryName);
  1698 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETSHORTNAMEL_ELONGNAME, "LongName %S", entryName.Ptr(), entryName.Length()<<1);
  1715 	TRAP(r,CurrentMount().GetShortNameL(entryName,aShortName));
  1699 	TRAP(r,CurrentMount().GetShortNameL(entryName,aShortName));
  1716 	TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetShortNameLRet, EF32TraceUidFileSys, r, aShortName);
  1700 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETSHORTNAMEL_ESHORTNAME, "ShortName %S", aShortName.Ptr(), aShortName.Length()<<1);
  1717 
  1701 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETSHORTNAMEL_ECMOUNTCBGETSHORTNAMELRET, "r %d", r);
  1718 	return(r);
  1702 	return(r);
  1719 	}
  1703 	}
  1720 
  1704 
  1721 TInt TDrive::GetLongName(const TDesC& aShortName,TDes& aLongName)
  1705 TInt TDrive::GetLongName(const TDesC& aShortName,TDes& aLongName)
  1722 //
  1706 //
  1725 	{
  1709 	{
  1726 	TInt r=CheckMountAndEntryName(aShortName);
  1710 	TInt r=CheckMountAndEntryName(aShortName);
  1727 	if (r!=KErrNone)
  1711 	if (r!=KErrNone)
  1728 		return(r);
  1712 		return(r);
  1729 	TPtrC entryName(StripBackSlash(aShortName));
  1713 	TPtrC entryName(StripBackSlash(aShortName));
  1730 
  1714 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETLONGNAMEL, "drive %d", DriveNumber());
  1731 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameL, EF32TraceUidFileSys, DriveNumber(), entryName);
  1715 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETLONGNAMEL_ESHORTNAME, "ShortName %S", entryName.Ptr(), entryName.Length()<<1);
  1732 	TRAP(r,CurrentMount().GetLongNameL(entryName,aLongName));
  1716 	TRAP(r,CurrentMount().GetLongNameL(entryName,aLongName));
  1733 	TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameLRet, EF32TraceUidFileSys, r, aLongName);
  1717 	OstTraceData(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETLONGNAMEL_ELONGNAME, "LongName %S", aLongName.Ptr(), aLongName.Length()<<1);
  1734 
  1718 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBGETLONGNAMELRET, "r %d", r);
  1735 	return(r);
  1719 	return(r);
  1736 	}
  1720 	}
  1737 
  1721 
  1738 
  1722 
  1739 /**
  1723 /**
  1893 	__CHECK_DRIVETHREAD(iDriveNumber);
  1877 	__CHECK_DRIVETHREAD(iDriveNumber);
  1894 	if(iFSys==NULL)
  1878 	if(iFSys==NULL)
  1895 		return(KErrNotReady);
  1879 		return(KErrNotReady);
  1896 	TInt r;
  1880 	TInt r;
  1897 	CMountCB* pM=NULL;
  1881 	CMountCB* pM=NULL;
  1898 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  1882 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL1, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
  1899 	TRAP(r,pM=FSys().NewMountL());
  1883 	TRAP(r,pM=FSys().NewMountL());
  1900 	TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM);
  1884 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL1RET, "r %d CMountCB %x", (TUint) r, (TUint) pM);
  1901 	if(r!=KErrNone)
  1885 	if(r!=KErrNone)
  1902 		return(r);
  1886 		return(r);
  1903 	pM->SetDrive(this);
  1887 	pM->SetDrive(this);
  1904 
  1888 	OstTraceExt4(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFORCEREMOUNTDRIVE, "drive %d aMountInfo %x aMountInfoMessageHandle %x aFlags %x", (TUint) DriveNumber(), (TUint) aMountInfo, (TUint) aMountInfoMessageHandle, (TUint) aFlags);
  1905 	TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBForceRemountDrive, EF32TraceUidFileSys, 
       
  1906 		DriveNumber(), aMountInfo, aMountInfoMessageHandle, aFlags);
       
  1907 	r=pM->ForceRemountDrive(aMountInfo,aMountInfoMessageHandle,aFlags);
  1889 	r=pM->ForceRemountDrive(aMountInfo,aMountInfoMessageHandle,aFlags);
  1908 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBForceRemountDriveRet, EF32TraceUidFileSys, r);
  1890 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBFORCEREMOUNTDRIVERET, "r %d", r);
  1909 
       
  1910 	pM->Close();
  1891 	pM->Close();
  1911 	return(r);
  1892 	return(r);
  1912 	}
  1893 	}
  1913 
       
  1914 TBool TDrive::IsExtensionMounted(CProxyDriveFactory* aFactory)
  1894 TBool TDrive::IsExtensionMounted(CProxyDriveFactory* aFactory)
  1915 //
  1895 //
  1916 // return ETrue if extension mounted on the drive
  1896 // return ETrue if extension mounted on the drive
  1917 //
  1897 //
  1918 	{
  1898 	{
  1921 		if(iExtInfo.iInfo[i].iFactory==aFactory)
  1901 		if(iExtInfo.iInfo[i].iFactory==aFactory)
  1922 			return(ETrue);
  1902 			return(ETrue);
  1923 		}
  1903 		}
  1924 	return(EFalse);
  1904 	return(EFalse);
  1925 	}
  1905 	}
  1926 
       
  1927 TInt TDrive::MountExtension(CProxyDriveFactory* aFactory,TBool aIsPrimary)
  1906 TInt TDrive::MountExtension(CProxyDriveFactory* aFactory,TBool aIsPrimary)
  1928 //
  1907 //
  1929 // Mount an extension
  1908 // Mount an extension
  1930 //
  1909 //
  1931 	{
  1910 	{
  1945 	__CHECK_DRIVETHREAD(iDriveNumber);
  1924 	__CHECK_DRIVETHREAD(iDriveNumber);
  1946 	// must be a secondary extension
  1925 	// must be a secondary extension
  1947 	if(iFSys==NULL)
  1926 	if(iFSys==NULL)
  1948 		return(KErrNotReady);
  1927 		return(KErrNotReady);
  1949 	TBool extSupported = iFSys->IsExtensionSupported();
  1928 	TBool extSupported = iFSys->IsExtensionSupported();
  1950 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileSystemIsExtensionSupported, EF32TraceUidFileSys, extSupported);
  1929 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMISEXTENSIONSUPPORTED1, "%x r %d", (TUint) iFSys, (TUint) extSupported);
  1951 	if(!extSupported)
  1930 	if(!extSupported)
  1952 		return(KErrNotSupported);
  1931 		return(KErrNotSupported);
  1953 	if(IsExtensionMounted(aFactory))
  1932 	if(IsExtensionMounted(aFactory))
  1954 		return(KErrAlreadyExists);
  1933 		return(KErrAlreadyExists);
  1955 	if(iCurrentMount && (CurrentMount().LockStatus()!=0 || Mount().Count()>1))
  1934 	if(iCurrentMount && (CurrentMount().LockStatus()!=0 || Mount().Count()>1))
  2033 	__CHECK_DRIVETHREAD(iDriveNumber);
  2012 	__CHECK_DRIVETHREAD(iDriveNumber);
  2034 	if(iFSys==NULL)
  2013 	if(iFSys==NULL)
  2035 		return(KErrNotReady);
  2014 		return(KErrNotReady);
  2036 	TInt r;
  2015 	TInt r;
  2037 	CMountCB* pM=NULL;
  2016 	CMountCB* pM=NULL;
  2038 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  2017 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL2, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
  2039 	TRAP(r,pM=FSys().NewMountL());
  2018 	TRAP(r,pM=FSys().NewMountL());
  2040 	TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM);
  2019 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL2RET, "r %d CMountCB %x", (TUint) r, (TUint) pM);
  2041 	if(r!=KErrNone)
  2020 	if(r!=KErrNone)
  2042 		return(r);
  2021 		return(r);
  2043 	pM->SetDrive(this);
  2022 	pM->SetDrive(this);
  2044 
  2023 
  2045 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECMountCBLock, EF32TraceUidFileSys, DriveNumber(), aStore);
  2024 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECMOUNTCBLOCK, "drive %d aStore %d", (TUint) DriveNumber(), (TUint) aStore);
  2046 	r=pM->Lock(aOld,aNew,aStore);
  2025 	r=pM->Lock(aOld,aNew,aStore);
  2047 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBLockRet, EF32TraceUidFileSys, r);
  2026 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBLOCKRET, "r %d", r);
  2048 
       
  2049 	pM->Close();
  2027 	pM->Close();
  2050 	return(r);
  2028 	return(r);
  2051 	}
  2029 	}
  2052 
  2030 
  2053 TInt TDrive::UnlockDevice(TMediaPassword& aPassword,TBool aStore)
  2031 TInt TDrive::UnlockDevice(TMediaPassword& aPassword,TBool aStore)
  2059 	__CHECK_DRIVETHREAD(iDriveNumber);
  2037 	__CHECK_DRIVETHREAD(iDriveNumber);
  2060 	if(iFSys==NULL)
  2038 	if(iFSys==NULL)
  2061 		return(KErrNotReady);
  2039 		return(KErrNotReady);
  2062 	TInt r;
  2040 	TInt r;
  2063 	CMountCB* pM=NULL;
  2041 	CMountCB* pM=NULL;
  2064 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  2042 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL3, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
  2065 	TRAP(r,pM=FSys().NewMountL());
  2043 	TRAP(r,pM=FSys().NewMountL());
  2066 	TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM);
  2044 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL3RET, "r %d CMountCB %x", (TUint) r, (TUint) pM);
  2067 	if(r!=KErrNone)
  2045 	if(r!=KErrNone)
  2068 		return(r);
  2046 		return(r);
  2069 
  2047 
  2070 	// reset mount failure count - which is likely to be non-zero if drive is locked
  2048 	// reset mount failure count - which is likely to be non-zero if drive is locked
  2071 	iMountFailures = 0;
  2049 	iMountFailures = 0;
  2072 
  2050 
  2073 	pM->SetDrive(this);
  2051 	pM->SetDrive(this);
  2074 
  2052 
  2075 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECMountCBUnlock, EF32TraceUidFileSys, DriveNumber(), aStore);
  2053 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECMOUNTCBUNLOCK, "drive %d aStore %d", (TUint) DriveNumber(), (TUint) aStore);
  2076 	r=pM->Unlock(aPassword,aStore);
  2054 	r=pM->Unlock(aPassword,aStore);
  2077 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBUnlockRet, EF32TraceUidFileSys, r);
  2055 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBUNLOCKRET, "r %d", r);
  2078 
       
  2079 	pM->Close();
  2056 	pM->Close();
  2080 	return(r);
  2057 	return(r);
  2081 	}
  2058 	}
  2082 
  2059 
  2083 TInt TDrive::ClearDevicePassword(TMediaPassword& aPassword)
  2060 TInt TDrive::ClearDevicePassword(TMediaPassword& aPassword)
  2089 	__CHECK_DRIVETHREAD(iDriveNumber);
  2066 	__CHECK_DRIVETHREAD(iDriveNumber);
  2090 	if(iFSys==NULL)
  2067 	if(iFSys==NULL)
  2091 		return(KErrNotReady);
  2068 		return(KErrNotReady);
  2092 	TInt r;
  2069 	TInt r;
  2093 	CMountCB* pM=NULL;
  2070 	CMountCB* pM=NULL;
  2094 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  2071 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL4, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
  2095 	TRAP(r,pM=FSys().NewMountL());
  2072 	TRAP(r,pM=FSys().NewMountL());
  2096 	TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM);
  2073 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL4RET, "r %d CMountCB %x", (TUint) r, (TUint) pM);
  2097 	if(r!=KErrNone)
  2074 	if(r!=KErrNone)
  2098 		return(r);
  2075 		return(r);
  2099 	pM->SetDrive(this);
  2076 	pM->SetDrive(this);
  2100 
  2077 
  2101 	// ClearPassword() will only work if the card is already unlocked. 
  2078 	// ClearPassword() will only work if the card is already unlocked. 
  2105 	TDriveInfo info;
  2082 	TDriveInfo info;
  2106 	DriveInfo(info);
  2083 	DriveInfo(info);
  2107 	if (info.iMediaAtt & KMediaAttLocked)
  2084 	if (info.iMediaAtt & KMediaAttLocked)
  2108 		UnlockDevice(aPassword, EFalse);
  2085 		UnlockDevice(aPassword, EFalse);
  2109 
  2086 
  2110 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBClearPassword, EF32TraceUidFileSys, DriveNumber());
  2087 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCLEARPASSWORD, "drive %d", DriveNumber());
  2111 	r=pM->ClearPassword(aPassword);
  2088 	r=pM->ClearPassword(aPassword);
  2112 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBClearPasswordRet, EF32TraceUidFileSys, r);
  2089 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCLEARPASSWORDRET, "r %d", r);
  2113 
       
  2114 	pM->Close();
  2090 	pM->Close();
  2115 	return(r);
  2091 	return(r);
  2116 	}
  2092 	}
  2117 
  2093 
  2118 TInt TDrive::EraseDevicePassword()
  2094 TInt TDrive::EraseDevicePassword()
  2124 	__CHECK_DRIVETHREAD(iDriveNumber);
  2100 	__CHECK_DRIVETHREAD(iDriveNumber);
  2125 	if(iFSys==NULL)
  2101 	if(iFSys==NULL)
  2126 		return(KErrNotReady);
  2102 		return(KErrNotReady);
  2127 	TInt r;
  2103 	TInt r;
  2128 	CMountCB* pM=NULL;
  2104 	CMountCB* pM=NULL;
  2129 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  2105 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL5, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber());
  2130 	TRAP(r,pM=FSys().NewMountL());
  2106 	TRAP(r,pM=FSys().NewMountL());
  2131 	TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM);
  2107 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWMOUNTL5RET, "r %d CMountCB %x", (TUint) r, (TUint) pM);
  2132 	if(r!=KErrNone)
  2108 	if(r!=KErrNone)
  2133 		return(r);
  2109 		return(r);
  2134 	pM->SetDrive(this);
  2110 	pM->SetDrive(this);
  2135 
  2111 
  2136 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBErasePassword, EF32TraceUidFileSys, DriveNumber());
  2112 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBERASEPASSWORD, "drive %d", DriveNumber());
  2137 	r=pM->ErasePassword();
  2113 	r=pM->ErasePassword();
  2138 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBErasePasswordRet, EF32TraceUidFileSys, r);
  2114 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBERASEPASSWORDRET, "r %d", r);
  2139 
       
  2140 	pM->Close();
  2115 	pM->Close();
  2141 	return(r);
  2116 	return(r);
  2142 	}
  2117 	}
  2143 
  2118 
  2144 #else
  2119 #else
  2219 
  2194 
  2220 
  2195 
  2221 
  2196 
  2222 
  2197 
  2223 /**
  2198 /**
  2224 Dismounts the current mount. This is method is called from outside, so do some finalisation work on mount.
  2199     Gracefully dismounts the current mount. This is method is called from outside, so do some finalisation work on mount.
  2225 After calling this function there is no current mount on the drive.
  2200 After calling this function there is no current mount on the drive.
       
  2201 
  2226 */
  2202 */
  2227 EXPORT_C void TDrive::Dismount()
  2203 EXPORT_C void TDrive::Dismount()
  2228 	{
  2204 	{
  2229 	__PRINT1(_L("TDrive::Dismount() iCurrentMount:0x%x"),iCurrentMount);
  2205 	__PRINT1(_L("TDrive::Dismount() iCurrentMount:0x%x"),iCurrentMount);
  2230 
  2206 
  2231 	iMountFailures = 0;
  2207 	iMountFailures = 0;
  2232 	if (!iCurrentMount)
  2208 	if (!iCurrentMount)
  2233 		return;
  2209 		return;
  2234 
  2210 
       
  2211     //-- try to do the best flushing file caches
  2235     TRAP_IGNORE(FlushCachedFileInfoL());
  2212     TRAP_IGNORE(FlushCachedFileInfoL());
  2236 
  2213 
  2237     //-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data)
  2214     //-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data)
  2238     TRAP_IGNORE(iCurrentMount->FinaliseMountL());
  2215     //-- finalise the mount in RO mode, we are dismounting the FS anyway
       
  2216     TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RO));
  2239     
  2217     
  2240     DoDismount();
  2218     DoDismount();
  2241 	}
  2219 	}
  2242 
  2220 
  2243 
  2221 
  2244 
  2222 
  2245 
  2223 
  2246 /**
  2224 /**
  2247 Forcibly dismounts the current mount and prevents it being remounted.
  2225     Dismounts the current mount by force.
  2248 After calling this function there is no current mount on the drive.
       
  2249 */
  2226 */
  2250 void TDrive::ForceDismount()
  2227 void TDrive::ForceDismount()
  2251 	{
  2228 	{
  2252 	__PRINT1(_L("TDrive::ForceDismount() iCurrentMount:0x%x"),iCurrentMount);
  2229 	__PRINT1(_L("TDrive::ForceDismount() iCurrentMount:0x%x"),iCurrentMount);
  2253 
  2230 
  2255 
  2232 
  2256 	if(!iCurrentMount)
  2233 	if(!iCurrentMount)
  2257 		return;
  2234 		return;
  2258   
  2235   
  2259 	TRAP_IGNORE(FlushCachedFileInfoL());
  2236 	TRAP_IGNORE(FlushCachedFileInfoL());
  2260 	iCurrentMount->SetDismounted(); //! this affects TDrive::ReMount()
  2237 
       
  2238     //-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data)
       
  2239     //-- finalise the mount in RO mode, we are dismounting the FS anyway
       
  2240     TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RO));
       
  2241 
       
  2242     //-- mark the mount as 'Dismounted'; this invalidates all object handles until the mount is successfully "remounted". 
       
  2243     //-- if there are still some objects opened on this mount, CMountCB::Close() won't destroy it until all objects are closed.
       
  2244     iCurrentMount->SetDismounted(); 
       
  2245     
  2261     DoDismount();
  2246     DoDismount();
  2262 	}
  2247 	}
  2263 
  2248 
  2264 /** 
  2249 /** 
  2265     An internal method. Dismounts and closes a current mount. 
  2250     An internal method. Dismounts and closes a current mount. 
  2273     iMountFailures = 0;
  2258     iMountFailures = 0;
  2274 
  2259 
  2275 	if (!iCurrentMount)
  2260 	if (!iCurrentMount)
  2276 		return;
  2261 		return;
  2277 
  2262 
  2278 	TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDismounted, EF32TraceUidFileSys, DriveNumber());
  2263 	OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDISMOUNTED, "drive %d", DriveNumber());
  2279     iCurrentMount->Dismounted();
  2264     iCurrentMount->Dismounted();
  2280 	TRACE0(UTF::EBorder, UTraceModuleFileSys::ECMountCBDismountedRet, EF32TraceUidFileSys);
  2265 	OstTrace0(TRACE_FILESYSTEM, FSYS_ECMOUNTCBDISMOUNTEDRET, "");
  2281 
       
  2282 	iCurrentMount->Close();
  2266 	iCurrentMount->Close();
  2283 	iCurrentMount=NULL;
  2267 	iCurrentMount=NULL;
  2284     }
  2268     }
  2285 
  2269 
  2286 
  2270 
  2373 	else
  2357 	else
  2374 		iDriveFlags &= ~EDismountDeferred;
  2358 		iDriveFlags &= ~EDismountDeferred;
  2375 	}
  2359 	}
  2376 
  2360 
  2377 
  2361 
  2378 
       
  2379 TInt TDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2)
  2362 TInt TDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2)
  2380 //
  2363 //
  2381 // General purpose test interface - .FSY specific.
  2364 // General purpose test interface - .FSY specific.
  2382 //
  2365 //
  2383 	{
  2366 	{
  2384 	TInt r=CheckMount();
  2367 	TInt r=CheckMount();
  2385 	if(r==KErrNone || (r==KErrInUse && iReason==KErrNone))
  2368 	if(r==KErrNone || (r==KErrInUse && iReason==KErrNone))
  2386 		{
  2369 		{
  2387 		TRACETHREADID(aMessage);
  2370 		TRACETHREADID(aMessage);
  2388 		TRACE5(UTF::EBorder, UTraceModuleFileSys::ECMountCBControlIO, EF32TraceUidFileSys, 
  2371 		OstTraceExt5(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCONTROLIO, "drive %d aCommand %d aParam1 %x aParam2 %x clientThreadId %x", (TUint) DriveNumber(), (TUint) aCommand, (TUint) aParam1, (TUint) aParam2, (TUint) threadId);
  2389 			DriveNumber(), aCommand, aParam1, aParam2, I64LOW(threadId));
       
  2390 		r=CurrentMount().ControlIO(aMessage,aCommand,aParam1,aParam2);
  2372 		r=CurrentMount().ControlIO(aMessage,aCommand,aParam1,aParam2);
  2391 		TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBControlIORet, EF32TraceUidFileSys, r);
  2373 		OstTrace1(TRACE_FILESYSTEM, FSYS_ECMOUNTCBCONTROLIORET, "r %d", r);
  2392 		}
  2374 		}
  2393 	return(r);
  2375 	return(r);
  2394 	}
  2376 	}
  2395 
  2377 
  2396 
  2378 
  2603 */
  2585 */
  2604 CFormatCB* TDrive::FormatOpenL(CFsRequest* aRequest, TInt& aFmtHandle, TFormatMode aFmtMode, const TLDFormatInfo* apLDFormatInfo, const TVolFormatParam* apVolFormatParam)
  2586 CFormatCB* TDrive::FormatOpenL(CFsRequest* aRequest, TInt& aFmtHandle, TFormatMode aFmtMode, const TLDFormatInfo* apLDFormatInfo, const TVolFormatParam* apVolFormatParam)
  2605     {
  2587     {
  2606     ASSERT(!(apLDFormatInfo && apVolFormatParam));  //-- these parameters are mutually exclusive
  2588     ASSERT(!(apLDFormatInfo && apVolFormatParam));  //-- these parameters are mutually exclusive
  2607     
  2589     
  2608     TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFormatL, EF32TraceUidFileSys, &FSys(), DriveNumber()); 
  2590     OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWFORMATL, "this %x drive %d", (TUint) &FSys(), (TUint) DriveNumber()); 
  2609 
       
  2610     CFormatCB* pFormat = CurrentMount().NewFormatL(); 
  2591     CFormatCB* pFormat = CurrentMount().NewFormatL(); 
  2611 
  2592 
  2612 	TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFormatLRet, EF32TraceUidFileSys, KErrNone, pFormat); 
  2593 	OstTraceExt2(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWFORMATLRET, "r %d CFormatCB %x", (TUint) KErrNone, (TUint) pFormat); 
  2613 	
  2594 	
  2614     Formats->AddL(pFormat, ETrue); 
  2595     Formats->AddL(pFormat, ETrue); 
  2615 	pFormat->InitL(this, aFmtMode); 
  2596 	pFormat->InitL(this, aFmtMode); 
  2616 
  2597 
  2617     if(aFmtMode & ESpecialFormat) 
  2598     if(aFmtMode & ESpecialFormat)