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