userlibandfileserver/fileserver/sfile/sf_drv.cpp
changeset 109 b3a1d9898418
parent 36 538db54a451d
child 134 95847726fe57
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
   231 			}
   231 			}
   232 		}
   232 		}
   233 
   233 
   234 	if (iReason==KErrNone && CurrentMount().LockStatus() > 0)
   234 	if (iReason==KErrNone && CurrentMount().LockStatus() > 0)
   235 	    {
   235 	    {
   236     	//-- this meand that the mount has drive access objetcs opened (RFormat or RRawDisk)
   236     	//-- this means that the mount has drive access objects opened (RFormat or RRawDisk)
   237         __PRINT1(_L("TDrive::CheckMount() Mount is locked! LockStaus:%d"), CurrentMount().LockStatus());
   237         __PRINT1(_L("TDrive::CheckMount() Mount is locked! LockStaus:%d"), CurrentMount().LockStatus());
   238         return KErrInUse;
   238         return KErrInUse;
   239 	    }	
   239 	    }	
   240 
   240 
   241 	__PRINT1(_L("TDrive::CheckMount returned %d "),iReason);
   241 	__PRINT1(_L("TDrive::CheckMount returned %d "),iReason);
   545 
   545 
   546 	TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2);
   546 	TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2);
   547 	TRAP(r,CurrentMount().FinaliseMountL(aOperation, aParam1, aParam2));
   547 	TRAP(r,CurrentMount().FinaliseMountL(aOperation, aParam1, aParam2));
   548 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2Ret, EF32TraceUidFileSys, r);
   548 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2Ret, EF32TraceUidFileSys, r);
   549 	
   549 	
       
   550 	// Pass FinaliseDrive notification down to media driver
       
   551 	TInt driveNumber = DriveNumber();
       
   552 	if (LocalDrives::IsValidDriveMapping(driveNumber) && !LocalDrives::IsProxyDrive(driveNumber))
       
   553 		{
       
   554 		TBusLocalDrive& drv = LocalDrives::GetLocalDrive(driveNumber);
       
   555 
       
   556 		TLocalDriveFinaliseInfoBuf finaliseBuf;
       
   557 		finaliseBuf().iMode = aOperation;
       
   558 
       
   559 		// notify local drive, ignore the error
       
   560 		drv.QueryDevice(RLocalDrive::EQueryFinaliseDrive, finaliseBuf);	
       
   561 		}
       
   562 
   550     return r;
   563     return r;
   551 	}
   564 	}
   552 
   565 
   553 //----------------------------------------------------------------------------
   566 //----------------------------------------------------------------------------
   554 /** old implementation */
   567 /** old implementation */
   813 TInt TDrive::ValidateShare(CFileCB& aFile, TShare aReqShare)
   826 TInt TDrive::ValidateShare(CFileCB& aFile, TShare aReqShare)
   814 //
   827 //
   815 // Check that the sharing rules are obeyed.
   828 // Check that the sharing rules are obeyed.
   816 //
   829 //
   817 	{
   830 	{
   818 
   831 	// Check the correct share modes are passed in
   819 	switch (aReqShare)
   832 	switch (aReqShare)
   820 		{
   833 		{
   821 	case EFileShareExclusive:
   834 	case EFileShareExclusive:
   822 	case EFileShareReadersOnly:
   835 	case EFileShareReadersOnly:
   823 	case EFileShareAny:
   836 	case EFileShareAny:
   824 	case EFileShareReadersOrWriters:
   837 	case EFileShareReadersOrWriters:
   825 		break;
   838 		break;
   826 	default:
   839 	default:
   827 		return(KErrArgument);
   840 		return KErrArgument;
   828 		}
   841 		}
       
   842 	
       
   843 	// Check the share mode of the file
   829 	switch (aFile.iShare)
   844 	switch (aFile.iShare)
   830 		{
   845 		{
   831 	case EFileShareExclusive:
   846 	case EFileShareExclusive:
   832 		return(KErrInUse);
   847 		return KErrInUse;
   833 
   848 
   834 	case EFileShareReadersOnly:
   849 	case EFileShareReadersOnly:
   835 	case EFileShareAny:
   850 	case EFileShareAny:
   836 		if (aReqShare != aFile.iShare && aReqShare != EFileShareReadersOrWriters)
   851 		if (aReqShare != aFile.iShare && aReqShare != EFileShareReadersOrWriters)
   837 			return(KErrInUse);
   852 		    {
       
   853             return KErrInUse;
       
   854 		    }
   838 		break;
   855 		break;
   839 
   856 
   840 	case EFileShareReadersOrWriters:
   857 	case EFileShareReadersOrWriters:
   841 		if (aReqShare==EFileShareExclusive)
   858 		if (aReqShare == EFileShareExclusive)
   842 			return(KErrInUse);
   859 		    {
       
   860             return KErrInUse;
       
   861 		    }
   843 		//
   862 		//
   844 		// If the file is currently open as EFileShareReadersOrWriters then
   863 		// If the file is currently opened as EFileShareReadersOrWriters then
   845 		// promote the share to the requested share mode.
   864 		// promote the share to the requested share mode.
       
   865 		// 
       
   866 		// If the requested share is EFileShareReadersOnly, verify that no
       
   867 		// other share has the file opened for writing.
   846 		//
   868 		//
   847 		// If the requested share is EFileShareReadersOnly, verfiy that no
       
   848 		// other share has the file open for writing.
       
   849 		//
       
   850 
       
   851 		if (aReqShare == EFileShareReadersOnly)
   869 		if (aReqShare == EFileShareReadersOnly)
   852 			{
   870 			{
   853 			FileShares->Lock();
   871 			TDblQueIter<CFileShare> fileShareIter(aFile.FileShareList());
   854 			TInt count = FileShares->Count();
   872 			CFileShare* pFileShare;
   855 			while(count--)
   873 			while ((pFileShare = fileShareIter++) != NULL)
   856 				{
   874 				{
   857 				CFileShare* share = (CFileShare*)(*FileShares)[count];
   875 				if(pFileShare->iMode & EFileWrite)
   858 				if (&share->File() == &aFile)
       
   859 					{
   876 					{
   860 					if(share->iMode & EFileWrite)
   877 					return KErrInUse;
   861 						{
       
   862 						FileShares->Unlock();
       
   863 						return KErrInUse;
       
   864 						}
       
   865 					}
   878 					}
   866 				}
   879 				}
   867 			FileShares->Unlock();
       
   868 			}
   880 			}
   869 		break;
   881 		break;
   870     
   882     
   871 	default:
   883 	default:
   872 		Fault(EDrvIllegalShareValue);
   884 		Fault(EDrvIllegalShareValue);
   873         break;
   885         break;
   874 		}
   886 		}
   875 	return(KErrNone);
   887 
       
   888 	return KErrNone;
   876 	}
   889 	}
   877 
   890 
   878 void TDrive::DriveInfo(TDriveInfo& anInfo)
   891 void TDrive::DriveInfo(TDriveInfo& anInfo)
   879 //
   892 //
   880 // Get the drive info.
   893 // Get the drive info.
  1330 
  1343 
  1331 	// Only allow delete on close for a newly created file.
  1344 	// Only allow delete on close for a newly created file.
  1332 	if ((aMode & EDeleteOnClose) && (anOpen!=EFileCreate))
  1345 	if ((aMode & EDeleteOnClose) && (anOpen!=EFileCreate))
  1333 		User::Leave(KErrArgument);
  1346 		User::Leave(KErrArgument);
  1334 
  1347 
  1335 	CFileCB* pF=LocateFile(aName);
  1348 	CFileCB* pFile=LocateFile(aName);
  1336 	CFileCache* pFileCache = NULL;
  1349 	CFileCache* pFileCache = NULL;
  1337 	TBool openFile=EFalse;
  1350 	TBool openFile=EFalse;	// True if file is being opened for the first time
  1338 	if (pF!=NULL)
  1351 	if (pFile!=NULL)		// File is already opened on the drive
  1339 		{
  1352 		{
  1340 		if (pF->iShare==EFileShareReadersOnly && (aMode&EFileWrite)!=0)
  1353 		if (pFile->iShare==EFileShareReadersOnly && (aMode&EFileWrite))
  1341 			User::Leave(KErrInUse);
  1354 			User::Leave(KErrInUse);
  1342 		if (anOpen==EFileCreate)
  1355 		if (anOpen==EFileCreate)
  1343 			User::Leave(KErrAlreadyExists);
  1356 			User::Leave(KErrAlreadyExists);
  1344 		TInt r=ValidateShare(*pF,share);
  1357 		TInt r=ValidateShare(*pFile,share);
  1345 		if (r!=KErrNone)
  1358 		if (r!=KErrNone)
  1346 			User::Leave(r);
  1359 			User::Leave(r);
  1347 		if ((r=pF->Open())!=KErrNone)
  1360 		if ((r=pFile->Open())!=KErrNone)
  1348 			User::Leave(r);
  1361 			User::Leave(r);
  1349 		aFileCB=pF;
  1362 		
  1350 		pFileCache = pF->FileCache();
  1363 		aFileCB=pFile;
       
  1364 		pFileCache = pFile->FileCache();
  1351 		}
  1365 		}
  1352 	else
  1366 	else
  1353 		{
  1367 		{
  1354 		TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  1368 		TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileL, EF32TraceUidFileSys, &FSys(), DriveNumber());
  1355 
  1369 
  1356         //-- construct CFileCB object, belonging to the corresponding mount
  1370         //-- construct CFileCB object, belonging to the corresponding mount
  1357         pF = aFileCB = CurrentMount().NewFileL();
  1371         pFile = aFileCB = CurrentMount().NewFileL();
  1358 
  1372 
  1359 		TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileLRet, EF32TraceUidFileSys, r, pF);
  1373 		TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileLRet, EF32TraceUidFileSys, r, pFile);
  1360 		TDrive* createdDrive=!aRequest->SubstedDrive() ? this : aRequest->SubstedDrive();
  1374 		TDrive* createdDrive=!aRequest->SubstedDrive() ? this : aRequest->SubstedDrive();
  1361 
  1375 
  1362     	HBufC* fileName = CreateFileNameL(aName);
  1376     	HBufC* fileName = CreateFileNameL(aName);
  1363 
  1377 
  1364         pF->InitL(this, createdDrive, fileName);
  1378         pFile->InitL(this, createdDrive, fileName);
  1365 
  1379 
  1366 
  1380 		pFile->iShare = share;
  1367 		pF->iShare = share;
  1381 		pFile->SetSequentialMode(aMode & EFileSequential);
  1368 		openFile=ETrue;
  1382 		openFile=ETrue;
  1369 		CurrentMount().iMountQ.AddLast(*pF);
  1383 		CurrentMount().iMountQ.AddLast(*pFile);
  1370 		Files->AddL(pF,ETrue);
  1384 		Files->AddL(pFile,ETrue);
       
  1385 		__PRINT1(_L("TDrive::FileOpenL - CFileCB->IsSequentialMode = %d"), pFile->IsSequentialMode());
  1371 		}
  1386 		}
  1372 	
  1387 	
  1373     CFileShare* pS=aFileShare=new(ELeave) CFileShare(pF);
  1388     CFileShare* pFileShare=aFileShare=new(ELeave) CFileShare(pFile);
  1374 
  1389 
  1375 	// We need to call CFileCB::PromoteShare immediately after the CFileShare 
  1390 	// We need to call CFileCB::PromoteShare immediately after the CFileShare 
  1376 	// instance is created since the destructor calls CFileCB::DemoteShare()
  1391 	// instance is created since the destructor calls CFileCB::DemoteShare()
  1377 	// which checks the share count is non-zero
  1392 	// which checks the share count is non-zero
  1378 	pS->iMode=aMode;
  1393 	pFileShare->iMode=aMode;
  1379 	pF->PromoteShare(pS);
  1394 	pFile->PromoteShare(pFileShare);
  1380 
  1395 
  1381 	pS->InitL();
  1396 	pFileShare->InitL();
  1382 	aFileCB=NULL; 
  1397 	aFileCB=NULL; 
  1383 	FileShares->AddL(pS,ETrue);
  1398 	FileShares->AddL(pFileShare,ETrue);
  1384 	aHandle=aRequest->Session()->Handles().AddL(pS,ETrue);
  1399 	aHandle=aRequest->Session()->Handles().AddL(pFileShare,ETrue);
  1385 
  1400 
  1386 
  1401 
  1387 	if (openFile)
  1402 	if (openFile)
  1388 		{
  1403 		{
  1389 		TRACEMULT5(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenL, EF32TraceUidFileSys, DriveNumber(), aName, aMode, (TUint) anOpen, (TUint) pF);
  1404 		TRACEMULT5(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenL, EF32TraceUidFileSys, DriveNumber(), aName, aMode, (TUint) anOpen, (TUint) pFile);
  1390 		CurrentMount().FileOpenL(aName,aMode,anOpen,pF);
  1405 		CurrentMount().FileOpenL(aName,aMode,anOpen,pFile);
  1391 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenLRet, EF32TraceUidFileSys, KErrNone);
  1406 		TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenLRet, EF32TraceUidFileSys, KErrNone);
  1392 
  1407 
  1393 		// Delete on close may now be safely flagged if required.
  1408 		// Delete on close may now be safely flagged if required.
  1394 		// The file did not exist on the media prior to the
  1409 		// The file did not exist on the media prior to the
  1395 		// CMountCB::FileOpenL() call for the case of a create.
  1410 		// CMountCB::FileOpenL() call for the case of a create.
  1396 		if ((aMode & EDeleteOnClose) && (anOpen==EFileCreate))
  1411 		if ((aMode & EDeleteOnClose) && (anOpen==EFileCreate))
  1397 			pF->SetDeleteOnClose();
  1412 			pFile->SetDeleteOnClose();
  1398 
  1413 
  1399 		TBool localBufferSuppport = (CurrentMount().LocalBufferSupport(pF) == KErrNone)?(TBool)ETrue:(TBool)EFalse;
  1414 		TBool localBufferSuppport = (CurrentMount().LocalBufferSupport(pFile) == KErrNone)?(TBool)ETrue:(TBool)EFalse;
  1400 		pF->SetLocalBufferSupport(localBufferSuppport);
  1415 		pFile->SetLocalBufferSupport(localBufferSuppport);
  1401 		if (localBufferSuppport)
  1416 		if (localBufferSuppport)
  1402 			{
  1417 			{
  1403 			// if file exists on closed queue resurrect it or discard it,
  1418 			// If file exists on closed queue resurrect it or discard it,
  1404 			// depending on the file open mode
  1419 			// depending on the file open mode
  1405 			pFileCache = LocateClosedFile(aName, anOpen == EFileOpen?(TBool)ETrue:(TBool)EFalse);
  1420 			pFileCache = LocateClosedFile(aName, anOpen == EFileOpen?(TBool)ETrue:(TBool)EFalse);
  1406 			if (pFileCache)
  1421 			if (pFileCache)
  1407 				{
  1422 				{
  1408 				pFileCache = pFileCache->ReNewL(*pS);	// NB may return NULL if caching not enabled
  1423 				pFileCache = pFileCache->ReNewL(*pFileShare);	// NB may return NULL if caching not enabled
  1409 				}
  1424 				}
  1410 			else
  1425 			else
  1411 				{
  1426 				{
  1412 				pFileCache = CFileCache::NewL(*pS);		// NB may return NULL if caching not enabled
  1427 				pFileCache = CFileCache::NewL(*pFileShare);		// NB may return NULL if caching not enabled
  1413 				}
  1428 				}
  1414 			if (pFileCache)
  1429 			if (pFileCache)
  1415 				// set the cached size to be the same as the uncached size
  1430 				// Set the cached size to be the same as the uncached size
  1416 				pF->SetCachedSize64(pF->Size64());
  1431 				pFile->SetCachedSize64(pFile->Size64());
  1417 			}
  1432 			}
  1418 		else
  1433 		else
  1419 			{
  1434 			{
  1420 			__CACHE_PRINT(_L("TDrive::FileOpenL(), Local buffers not supported"));
  1435 			__CACHE_PRINT(_L("TDrive::FileOpenL(), Local buffers not supported"));
  1421 			}
  1436 			}
  1422 		}
  1437 		}
  1423 
  1438 
  1424 	// initialize share mode flags
  1439 	// Initialize share mode flags
  1425 	if (pFileCache != NULL)
  1440 	if (pFileCache != NULL)
  1426 		pFileCache->Init(*pS);
  1441 		pFileCache->Init(*pFileShare);
  1427 	}
  1442 	}
  1428 
  1443 
  1429 TInt TDrive::FileOpen(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen)
  1444 TInt TDrive::FileOpen(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen)
  1430 //
  1445 //
  1431 // Open/Create/Replace a file.
  1446 // Open/Create/Replace a file.
  1433 	{
  1448 	{
  1434 	__CHECK_DRIVETHREAD(iDriveNumber);
  1449 	__CHECK_DRIVETHREAD(iDriveNumber);
  1435 	CFileCB* pF=NULL;
  1450 	CFileCB* pF=NULL;
  1436 	CFileShare* pS=NULL;
  1451 	CFileShare* pS=NULL;
  1437 	aHandle=0;
  1452 	aHandle=0;
  1438 	TRAPD(r,FileOpenL(aRequest,aHandle,aName,aMode,anOpen,pF,pS))
  1453 	TRAPD(r,FileOpenL(aRequest,aHandle,aName,aMode,anOpen,pF,pS));
  1439 
  1454 
  1440 	// Allow files > 2GB-1 to be opened only if EFileBigFile is specified in iMode
  1455 	// Allow files > 2GB-1 to be opened only if EFileBigFile is specified in iMode
  1441 	if (r == KErrNone && pS && ((TUint64)pS->File().Size64() > KMaxLegacyFileSize) && (!(pS->IsFileModeBig())))
  1456 	if (r == KErrNone && pS && ((TUint64)pS->File().Size64() > KMaxLegacyFileSize) && (!(pS->IsFileModeBig())))
  1442 		r = KErrTooBig;
  1457 		r = KErrTooBig;
  1443 
  1458