userlibandfileserver/fileserver/sfile/sf_drv.cpp
changeset 8 538db54a451d
parent 6 0173bcd7697c
child 41 0ffb4e86fcc9
equal deleted inserted replaced
7:f497542af8e4 8:538db54a451d
    57 TInt ValidateDrive(TInt aDriveNumber,CFsRequest* aRequest)
    57 TInt ValidateDrive(TInt aDriveNumber,CFsRequest* aRequest)
    58 //
    58 //
    59 // Validate a drive number and set iTheDrive.
    59 // Validate a drive number and set iTheDrive.
    60 //
    60 //
    61 	{
    61 	{
    62 	__CHECK_MAINTHREAD();
       
    63 	if (aDriveNumber==KDefaultDrive)
    62 	if (aDriveNumber==KDefaultDrive)
    64 		aDriveNumber=aRequest->Session()->CurrentDrive();
    63 		aDriveNumber=aRequest->Session()->CurrentDrive();
    65 	if (!RFs::IsValidDrive(aDriveNumber))
    64 	if (!RFs::IsValidDrive(aDriveNumber))
    66 		return(KErrBadName);
    65 		return(KErrBadName);
    67 	aRequest->SetDrive(&TheDrives[aDriveNumber]);
    66 	aRequest->SetDrive(&TheDrives[aDriveNumber]);
  1000 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirLRet, EF32TraceUidFileSys, r);
   999 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirLRet, EF32TraceUidFileSys, r);
  1001 
  1000 
  1002 	return(r);
  1001 	return(r);
  1003 	}
  1002 	}
  1004 
  1003 
       
  1004 /*
       
  1005  Delete files allowing wild cards.
       
  1006 */
  1005 TInt TDrive::Delete(const TDesC& aName)
  1007 TInt TDrive::Delete(const TDesC& aName)
  1006 //
       
  1007 // Delete files allowing wild cards.
       
  1008 //
       
  1009 	{
  1008 	{
  1010 	TInt r=CheckMountAndEntryName(aName);
  1009 	TInt r=CheckMountAndEntryName(aName);
  1011 	if (r!=KErrNone)
  1010 	if(r!=KErrNone)
  1012 		return(r);
  1011 		return r;
  1013 	CFileCB* pF=LocateFile(aName);
  1012 	
  1014 	if (pF!=NULL)
  1013 	if(LocateFile(aName))
  1015 		return(KErrInUse);		
  1014 		return KErrInUse; //-- the file is already opened by someone
  1016 
  1015 
  1017 	// remove from closed queue - NB this isn't strictly necessary if file is read-only or write-protected...
  1016 	// remove from closed queue - NB this isn't strictly necessary if file is read-only or write-protected...
  1018 	LocateClosedFile(aName, EFalse);
  1017 	LocateClosedFile(aName, EFalse);
  1019 
  1018 
  1020 	TEntry entry;
  1019     if (IsWriteProtected())
  1021 	r=Entry(aName,entry);
       
  1022 	if (r!=KErrNone)
       
  1023 		return(r);
       
  1024 	if (entry.IsDir() || IsWriteProtected() || entry.IsReadOnly())
       
  1025 		return(KErrAccessDenied);
  1020 		return(KErrAccessDenied);
  1026 
  1021 
       
  1022     //-- filesystems' CMountCB::DeleteL() implementations shall check the entry attributes themeselves. 
  1027 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteL, EF32TraceUidFileSys, DriveNumber(), aName);
  1023 	TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteL, EF32TraceUidFileSys, DriveNumber(), aName);
  1028 	TRAP(r,CurrentMount().DeleteL(aName))
  1024 	TRAP(r,CurrentMount().DeleteL(aName))
  1029 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteLRet, EF32TraceUidFileSys, r);
  1025 	TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteLRet, EF32TraceUidFileSys, r);
  1030 
  1026 
  1031 	return(r);
  1027 	return r;
  1032 	}
  1028 	}
  1033 
  1029 
  1034 TInt TDrive::CheckMountAndEntryNames(const TDesC& anOldName,const TDesC& aNewName)
  1030 TInt TDrive::CheckMountAndEntryNames(const TDesC& anOldName,const TDesC& aNewName)
  1035 //
  1031 //
  1036 // Check mount, that neither is open, and that both names are legal.
  1032 // Check mount, that neither is open, and that both names are legal.
  1684 	TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameLRet, EF32TraceUidFileSys, r, aLongName);
  1680 	TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameLRet, EF32TraceUidFileSys, r, aLongName);
  1685 
  1681 
  1686 	return(r);
  1682 	return(r);
  1687 	}
  1683 	}
  1688 
  1684 
       
  1685 
       
  1686 /**
       
  1687     Query whether the file is open or not.
       
  1688 */
  1689 TInt TDrive::IsFileOpen(const TDesC& aFileName,CFileCB*& aFileCB)
  1689 TInt TDrive::IsFileOpen(const TDesC& aFileName,CFileCB*& aFileCB)
  1690 //
       
  1691 // Query whether the file is open or not.
       
  1692 //
       
  1693 	{
  1690 	{
  1694 	__CHECK_DRIVETHREAD(iDriveNumber);
  1691 	__CHECK_DRIVETHREAD(iDriveNumber);
  1695 
  1692 
  1696 	aFileCB = NULL;
  1693 	aFileCB = NULL;
  1697 	
  1694 	
  1698 	TEntry dumEntry;
  1695 	TInt r=CheckMountAndEntryName(aFileName);
  1699 	TInt r=Entry(aFileName,dumEntry);
       
  1700 	if (r!=KErrNone)
  1696 	if (r!=KErrNone)
  1701 		return(r);
  1697 		return(r);
  1702 	if(dumEntry.iAtt&KEntryAttDir)
  1698     
  1703 		return KErrArgument;
       
  1704 
       
  1705 	Files->Lock();
  1699 	Files->Lock();
  1706 	TInt count=Files->Count();
  1700 	TInt count=Files->Count();
  1707 
  1701 
  1708 	// create a hash to speed up the search
  1702 	// create a hash to speed up the search
  1709 
  1703