First public contribution.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfile\sf_svr.cpp
19 #include "sf_cache_man.h"
20 #include "sf_file_cache.h"
21 #include "sf_memory_man.h"
23 TInt DoFsSubClose(CFsRequest* aRequest)
25 // Close a subsession.
28 const TInt handle(aRequest->Message().Int3());
30 CFsObject* pO=SessionObjectFromHandle(handle,0,aRequest->Session());
34 aRequest->Session()->DecResourceCount();
35 aRequest->Session()->Handles().Remove(handle,ETrue);
37 // this request has also opened this object, so close it here before it
38 // gets to a plugin as a plugin may attempt to open the file/dir itself
39 aRequest->SetScratchValue64( MAKE_TUINT64(I64HIGH(aRequest->ScratchValue64()), 0));
45 TInt TFsSubClose::DoRequestL(CFsRequest* aRequest)
47 // Close a subsession.
51 // Leave and then panic client with KErrBadHandle if necessary.
52 CFsObject* pO = SessionObjectFromHandle(aRequest->Message().Int3(),0,aRequest->Session());
56 if(aRequest->Message().Function() == EFsFileSubClose)
58 CFileShare* pShare = (CFileShare*) aRequest->ScratchValue();
60 // flush the file cache
61 CFileCache* fileCache = pShare->File().FileCache();
62 if (fileCache && fileCache->FlushDirty(aRequest) == CFsRequest::EReqActionBusy)
63 return CFsRequest::EReqActionBusy;
65 // if any write requests are being fair scheduled, wait for them to complete
66 if (pShare->RequestInProgress())
67 return CFsRequest::EReqActionBusy;
70 return DoFsSubClose(aRequest);
73 TInt TFsSubClose::Initialise(CFsRequest* aRequest)
75 // Now moved to RequestAllocator::GetRequest
79 // Closing a file share may require flushing of dirty data, so deal with this in the drive thread
80 // in TFsSubClose::DoRequestL(). For other objects (EFsFormatSubClose, EFsDirSubClose, EFsRawSubClose,
81 // FsPluginSubClose) we may complete the message here.
82 if(aRequest->FsFunction() == EFsFileSubClose)
84 CFileShare* pShare = (CFileShare*)
85 SessionObjectFromHandle(aRequest->Message().Int3(), FileShares->UniqueID(), aRequest->Session());
88 User::Leave(KErrBadHandle);
90 HBufC* pFileName = pShare->File().FileName().Alloc();
91 aRequest->SetScratchValue64( MAKE_TUINT64((TUint) pFileName, (TUint) pShare) );
92 TInt driveNumber = pShare->File().Drive().DriveNumber();
93 aRequest->SetDriveNumber(driveNumber);
96 // Define a completion routine so that we can see whether this request is cancelled -
97 // if it is we still want to close the subsession (but not bother about flushing dirty data)
98 r = ((CFsMessageRequest*) aRequest)->PushOperation(TFsSubClose::Complete);
105 TInt TFsSubClose::Complete(CFsRequest* aRequest)
107 // if LastError() != KErrNone, this implies the request has been cancelled.
108 // i.e. TFsSubClose::DoRequestL() has not been called, so we need to call DoFsSubClose() here
109 if (((CFsMessageRequest*) aRequest)->LastError() != KErrNone)
110 DoFsSubClose(aRequest);
112 return CFsRequest::EReqActionComplete;
116 TInt TFsNotifyChange::DoRequestL(CFsRequest* aRequest)
121 CStdChangeInfo* notificationInfo=new CStdChangeInfo;
122 if (notificationInfo==NULL)
123 return (KErrNoMemory);
124 const RMessage2& m=aRequest->Message();
125 notificationInfo->Initialise((TNotifyType)m.Int0(),(TRequestStatus*)m.Ptr1(),m,aRequest->Session());
126 TInt r=FsNotify::AddChange(notificationInfo,KDriveInvalid);
128 delete(notificationInfo);
133 TInt TFsNotifyChange::Initialise(CFsRequest* /*aRequest*/)
141 TInt TFsNotifyChangeEx::DoRequestL(CFsRequest* aRequest)
143 // Set up an extended change notification
146 TUint notifyType=aRequest->Message().Int0();
147 if (aRequest->Src().NamePresent()) // Monitoring a file
148 { // Reject if iNotifyType is ENotifyDir
149 if (notifyType&ENotifyDir)
150 return (KErrArgument);
152 CExtChangeInfo* notificationInfo=new CExtChangeInfo;
153 if (notificationInfo==NULL)
154 return (KErrNoMemory);
156 TInt ret=aRequest->Drive()->Entry(aRequest->Src().FullName().Mid(2),t);
157 if ((ret==KErrNotFound)||(ret==KErrPathNotFound)||(ret==KErrInUse))
158 // Path does not yet exist or drive has been locked - still submit request
159 // but mark it as notify all since the client is potentially interested
160 notifyType=ENotifyAll;
161 else if (ret!=KErrNone)
163 delete notificationInfo;
167 const RMessage2& m=aRequest->Message();
168 notificationInfo->Initialise((TNotifyType)notifyType,(TRequestStatus*)m.Ptr2(),m,aRequest->Session(),aRequest->Src().FullName().Mid(2));
170 if (aRequest->ScratchValue()!=0)
173 drive=aRequest->DriveNumber();
174 TInt ret=FsNotify::AddChange(notificationInfo,drive);
176 delete(notificationInfo);
181 TInt TFsNotifyChangeEx::Initialise(CFsRequest* aRequest)
183 // Establish whether the directory or file to watch actually exists
184 // This sets the aSession members iTheName and iTheParse etc
186 TBool monitorAllDrives=EFalse;
187 TFileName notifyPath;
189 TRAP(ret,aRequest->ReadL(KMsgPtr1,notifyPath));
192 if(notifyPath.Length()==0)
193 return(KErrArgument);
195 if ((notifyPath[0]==KMatchAny)||(notifyPath[0]==KMatchOne))
197 // Use the default session drive for now
198 // Client has submitted a ? or * for drive
199 monitorAllDrives=ETrue;
200 ret=ParseNotificationPath(aRequest,aRequest->Src(),notifyPath);
206 // Client has submitted a single drive to monitor
207 monitorAllDrives=EFalse;
209 ret = ParseNoWildSubstPtr1(aRequest, aRequest->Src());
213 aRequest->SetScratchValue(monitorAllDrives);
214 ret = PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsNotifyChangeEx, __PLATSEC_DIAGNOSTIC_STRING("Extended Change Notifier"));
218 TInt TFsNotifyChangeCancel::DoRequestL(CFsRequest* aRequest)
223 FsNotify::CancelChangeSession(aRequest->Session());
225 FsNotify::CancelDebugSession(aRequest->Session());
232 TInt TFsNotifyChangeCancel::Initialise(CFsRequest* /*aRequest*/)
242 TInt TFsNotifyChangeCancelEx::DoRequestL(CFsRequest* aRequest)
247 FsNotify::CancelChangeSession(aRequest->Session(),(TRequestStatus*)aRequest->Message().Ptr0());
248 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
249 FsNotify::CancelDebugSession(aRequest->Session());
256 TInt TFsNotifyChangeCancelEx::Initialise(CFsRequest* /*aRequest*/)
265 // Setup a disk space notification request
267 TInt TFsNotifyDiskSpace::DoRequestL(CFsRequest *aRequest)
269 //-- first check that the threshold value is correct and is less than the volume size
270 const TUint64 threshold = aRequest->ScratchValue64();
274 //-- get the size of the mounted volume to check that the requested threshold isn't larger than the volume
276 TInt r = aRequest->Drive()->MountedVolumeSize(volSz);
280 if(threshold >= volSz)
284 //-- Create the disk space notificator object and append it to the FsNotify queue
285 CDiskSpaceInfo* info=new CDiskSpaceInfo;
287 return(KErrNoMemory);
289 const RMessage2& m=aRequest->Message();
290 info->Initialise((TRequestStatus*)m.Ptr2(),m,aRequest->Session(),threshold);
292 r=FsNotify::AddDiskSpace(info,aRequest->DriveNumber());
300 TInt TFsNotifyDiskSpace::Initialise(CFsRequest *aRequest)
305 TInt r=ValidateDriveDoSubst(aRequest->Message().Int1(),aRequest);
309 TPtr8 tBuf((TUint8*)&threshold,sizeof(TInt64));
310 aRequest->ReadL(KMsgPtr0,tBuf);
311 aRequest->SetScratchValue64(threshold);
316 TInt TFsNotifyDiskSpaceCancel::DoRequestL(CFsRequest *aRequest)
318 // Cancel disk space notification
321 FsNotify::CancelDiskSpaceSession(aRequest->Session(),(TRequestStatus*)aRequest->Message().Ptr0());
326 TInt TFsNotifyDiskSpaceCancel::Initialise(CFsRequest* /*aRequest*/)
334 TInt TFsSynchroniseDriveThread::DoRequestL(CFsRequest* /*aRequest*/)
336 // This is to ensure that previous message has been handled in drive thread.
339 return CFsRequest::EReqActionComplete;
342 TInt TFsSynchroniseDriveThread::Initialise(CFsRequest *aRequest)
344 // Set the drive thread.
347 if(aRequest->Message().Int0() == -1) //If no drive thread then complete the message
349 return CFsRequest::EReqActionComplete;
351 TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
355 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
356 EXPORT_C void DebugNotifySessions(TInt aFunction,TInt /*aDrive*/)
358 // Notify sessions of a debug event
361 // Notifying involves memory de-allocation on the file server's heap -
362 // check if we need to switch heaps.
363 RAllocator* current_alloc = &User::Heap();
364 RAllocator* svr_alloc = ServerThreadAllocator;
365 if (current_alloc != svr_alloc)
366 User::SwitchHeap(svr_alloc);
367 FsNotify::HandleDebug(aFunction);
368 if (current_alloc != svr_alloc)
369 User::SwitchHeap(current_alloc);
372 EXPORT_C void DebugNotifySessions(TInt,TInt)
374 // Notify sessions of a debug event
380 TInt TFsDriveList::DoRequestL(CFsRequest* aRequest)
382 // Get the current drive list.
385 TDriveList list(KMaxDrives);
387 const TUint mask = (TUint) aRequest->Message().Int1();
388 const TUint matchedFlags= mask & KDriveAttMatchedFlags; //KDriveAttMatchedFlags = 0xFFF
389 const TUint matchedAtt = mask & KDriveAttMatchedAtt; //KDriveAttMatchedAtt = 0x0FFF0000
391 TInt r = ValidateMatchMask(mask);
395 for (TInt i=0;i<KMaxDrives;i++)
397 if(RFs::IsValidDrive(i))
399 const TUint driveAtt= TheDrives[i].Att();
400 if(matchedFlags != 0 )
404 case KDriveAttExclude :
406 list[i]= (driveAtt & matchedFlags ) ? (TUint8)0:(TUint8)driveAtt ;
411 list[i] = (driveAtt & matchedFlags) ? (TUint8)driveAtt:(TUint8)0 ;
414 case KDriveAttExclusive :
416 if(matchedFlags != KDriveAttLogicallyRemovable)
418 list[i] = ((TUint8)driveAtt == matchedFlags) ? (TUint8)driveAtt:(TUint8)0;
422 list[i] = (driveAtt == (matchedFlags | KDriveAttRemovable)) ? (TUint8)driveAtt:(TUint8)0;
426 case KDriveAttExclude | KDriveAttExclusive:
428 if(matchedFlags != KDriveAttLogicallyRemovable)
430 list[i] = ((TUint8)driveAtt == matchedFlags) ?(TUint8)0:(TUint8)driveAtt;
434 list[i] = (driveAtt == (matchedFlags | KDriveAttRemovable)) ? (TUint8)driveAtt:(TUint8)0;
444 else //matchedFlags == 0
449 list[i] = (TUint8)0 ;
452 list[i]= (TUint8)driveAtt;
454 default: //all other cases are incorrect
465 aRequest->WriteL(KMsgPtr0,list);
467 // Finally, kick off a speculative probe for devices
469 TInt idx = ProxyDrives->Count();
472 CExtProxyDriveFactory* pF = (CExtProxyDriveFactory*)(*ProxyDrives)[idx];
475 pF->AsyncEnumerate();
478 ProxyDrives->Unlock();
483 TInt TFsDriveList::Initialise(CFsRequest* /*aRequest*/)
491 TInt TFsDrive::DoRequestL(CFsRequest* aRequest)
496 // executed in main thread, therefore lock to ensure that
497 // dismount cannot occur during request
498 FsThreadManager::LockDrive(aRequest->DriveNumber());
500 aRequest->Drive()->DriveInfo(info);
501 if(aRequest->SubstedDrive())
502 info.iDriveAtt=KDriveAttSubsted;
503 FsThreadManager::UnlockDrive(aRequest->DriveNumber());
504 TPckgC<TDriveInfo> pInfo(info);
505 aRequest->WriteL(KMsgPtr0,pInfo);
509 TInt TFsDrive::Initialise(CFsRequest* aRequest)
514 TInt r=ValidateDriveDoSubst(aRequest->Message().Int1(),aRequest);
522 TInt TFsVolume::DoRequestL(CFsRequest* aRequest)
525 TPckg<TVolumeInfo> pV(v);
527 //-- read TVolumeInfo from the client side, the client may have provided some data to pass to the server and FSY side
528 aRequest->ReadL(KMsgPtr0,pV);
530 TRequestStatus* pStat = (TRequestStatus*)aRequest->Message().Ptr2();
532 {//-- the user called an asynchronous version of the RFs::Volume
533 //-- indicate that we request free space asynchronously by setting a special flag that we will pass to the FSY
534 v.iVolSizeAsync = ETrue;
535 //-- at present the user's request will be completed by file server as the result of TFsVolume operation.
539 v.iVolSizeAsync = EFalse;
542 //-- ask the FSY to provide us its volume information
543 TInt r=aRequest->Drive()->Volume(v);
545 CSessionFs* session=aRequest->Session();
548 TDrive* drive = aRequest->Drive();
549 const TInt driveNumber = drive->DriveNumber();
551 if(!session->ReservedAccess(driveNumber))
553 const TInt reserve = drive->ReservedSpace();
554 if(v.iFree <= reserve)
560 if(aRequest->SubstedDrive())
561 v.iDrive.iDriveAtt=KDriveAttSubsted;
565 if (drive->IsMounted() && drive->CurrentMount().LocalBufferSupport() == KErrNone && CCacheManagerFactory::CacheManager() != NULL)
566 v.iFileCacheFlags = TFileCacheSettings::Flags(driveNumber);
568 v.iFileCacheFlags = TFileCacheFlags(0);
571 aRequest->WriteL(KMsgPtr0,pV);
577 TInt TFsVolume::Initialise(CFsRequest* aRequest)
583 TInt r=ValidateDriveDoSubst(aRequest->Message().Int1(),aRequest);
588 TInt TFsSetVolume::DoRequestL(CFsRequest* aRequest)
590 // Set the volume name.
593 TInt r = CheckDiskSpace(0, aRequest);
597 TFileName volumeName;
598 aRequest->ReadL(KMsgPtr0,volumeName);
599 if (volumeName.Length()>KMaxVolumeNameLength) // KMaxVolumeNameLength = 11
602 // Validate name - return KErrBadName if it contains illegal characters such as * ? / | > <
603 TNameChecker checker(volumeName);
605 if (checker.IsIllegalName(badChar))
608 return(aRequest->Drive()->SetVolume(volumeName));
612 TInt TFsSetVolume::Initialise(CFsRequest* aRequest)
617 TInt r=ValidateDriveDoSubst(aRequest->Message().Int1(),aRequest);
620 if (!KCapFsSetVolume.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Set Volume")))
621 return KErrPermissionDenied;
626 TInt TFsSubst::DoRequestL(CFsRequest* aRequest)
628 // Get a drive substitution.
631 TInt r=ValidateDrive(aRequest->Message().Int1(),aRequest);
635 __PRINT(_L("aRequest->Drive()->Att()&KDriveAttSubsted"));
636 __PRINT1(_L("aRequest->Drive()->Subst()"),&aRequest->Drive()->Subst());
637 if (aRequest->Drive()->IsSubsted())
638 substName=aRequest->Drive()->Subst();
639 aRequest->WriteL(KMsgPtr0,substName);
644 TInt TFsSubst::Initialise(CFsRequest* /*aRequest*/)
653 TInt TFsSetSubst::DoRequestL(CFsRequest* aRequest)
655 // Set a drive substitution.
658 TInt r=ValidateDrive(aRequest->Message().Int1(),aRequest);
661 TDrive* pD=aRequest->Drive();
662 r=ParsePathPtr0(aRequest,aRequest->Src());
665 //TODO: no protection for unsubsting drives (could check substed path if system then only CRoot process can unsubst
666 if (pD->IsSubsted() && !aRequest->Src().DrivePresent() && !aRequest->Src().PathPresent())
671 pD->SetSubstedDrive(NULL);
674 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysSetSubst,&KCapFsPriSetSubst,&KCapFsROSetSubst, __PLATSEC_DIAGNOSTIC_STRING("Set Subst"));
677 if (pD->Att()&(KDriveAttLocal|KDriveAttRom|KDriveAttRedirected|KDriveAttSubsted))
679 if (pD==aRequest->Drive())
681 if (aRequest->Drive()->Att()&(KDriveAttRedirected|KDriveAttSubsted))
683 HBufC* pS=aRequest->Src().FullName().Alloc();
685 return(KErrNoMemory);
686 __ASSERT_DEBUG(!&pD->SubstedDrive(),Fault(ETFsSetSubstNotNull));
689 pD->SetSubstedDrive(aRequest->Drive());
690 pD->SetAtt(KDriveAttSubsted);
694 TInt TFsSetSubst::Initialise(CFsRequest* aRequest)
699 if (!KCapFsSetSubst.CheckPolicy(aRequest->Message(),__PLATSEC_DIAGNOSTIC_STRING("Set subst")))
700 return KErrPermissionDenied;
705 TInt TFsRealName::DoRequestL(CFsRequest* aRequest)
707 // Get the real name of a file.
710 TInt r=ParseSubstPtr0(aRequest,aRequest->Src());
713 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysRealName,&KCapFsPriRealName, __PLATSEC_DIAGNOSTIC_STRING("Real Name"));
717 if (aRequest->Drive()->Att()&KDriveAttRedirected)
718 substName=aRequest->Drive()->Subst(); // DANGER?
720 substName=aRequest->Src().Drive();
721 if ((substName.Length()+aRequest->Src().FullName().Mid(2).Length())>KMaxFileName)
723 substName+=aRequest->Src().FullName().Mid(2);
724 aRequest->WriteL(KMsgPtr1,substName);
728 TInt TFsRealName::Initialise(CFsRequest* /*aRequest*/)
736 TInt TFsDefaultPath::DoRequestL(CFsRequest* aRequest)
738 // Get the default path.
741 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement))
742 return KErrNotSupported;
743 else if(PlatSec::ConfigSetting(PlatSec::EPlatSecDiagnotics))
745 //FIXME: to be remove the following when platform is fully secure
747 TInt r=aRequest->Message().Client(tT,EOwnerThread);
759 TInt b=n.Locate('[');
762 RDebug::Print(_L("**** API violation: %S should not use DefaultPath()\n"),&n);
766 aRequest->WriteL(KMsgPtr0,TheDefaultPath);
771 aRequest->WriteL(KMsgPtr0,TheDefaultPath);
776 TInt TFsDefaultPath::Initialise(CFsRequest* /*aRequest*/)
784 TInt TFsSetDefaultPath::DoRequestL(CFsRequest* aRequest)
786 // Set the default path.
789 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement))
790 return KErrNotSupported;
791 else if(PlatSec::ConfigSetting(PlatSec::EPlatSecDiagnotics))
793 //FIXME: to be remove the following when platform is fully secure
795 TInt r=aRequest->Message().Client(tT,EOwnerThread);
807 TInt b=n.Locate('[');
810 RDebug::Print(_L("**** API violation: %S should not use SetDefaultPath()\n"),&n);
815 /*TInt*/ r=ParsePathPtr0(aRequest,parse);
816 if (r!=KErrNone && r!=KErrInUse)
818 if (IsIllegalFullName(parse.FullName()))
820 TheDefaultPath=parse.FullName();
826 TInt r=ParsePathPtr0(aRequest,parse);
827 if (r!=KErrNone && r!=KErrInUse)
829 if (IsIllegalFullName(parse.FullName()))
831 TheDefaultPath=parse.FullName();
837 TInt TFsSetDefaultPath::Initialise(CFsRequest* /*aRequest*/)
845 TInt TFsSessionPath::DoRequestL(CFsRequest* aRequest)
847 // Get the session path
850 aRequest->WriteL(KMsgPtr0,aRequest->Session()->Path());
854 TInt TFsSessionPath::Initialise(CFsRequest* /*aRequest*/)
863 TInt TFsSetSessionPath::DoRequestL(CFsRequest* aRequest)
865 // Set the session path
869 TInt r=ParsePathPtr0(aRequest,parse);
870 if (r!=KErrNone && r!=KErrInUse)
872 r=PathCheck(aRequest,parse.FullName().Mid(2),&KCapFsSysSetSessionPath,&KCapFsPriSetSessionPath, __PLATSEC_DIAGNOSTIC_STRING("Set Session Path"));
875 if (IsIllegalFullName(parse.FullName()))
877 HBufC* pP=parse.FullName().Alloc();
879 return(KErrNoMemory);
880 delete &aRequest->Session()->Path();
881 aRequest->Session()->SetPath(pP);
885 TInt TFsSetSessionPath::Initialise(CFsRequest* /*aRequest*/)
894 TInt TFsParse::DoRequestL(CFsRequest* aRequest)
896 // Parse a file name.
900 aRequest->ReadL(KMsgPtr0,name);
902 if (aRequest->Message().Ptr1()!=NULL)
903 aRequest->ReadL(KMsgPtr1,rel);
905 TInt r=p.Set(name,&rel,&aRequest->Session()->Path());
908 TPckgC<TParse> pP(p);
909 aRequest->WriteL(KMsgPtr2,pP);
914 TInt TFsParse::Initialise(CFsRequest* /*aRequest*/)
922 TInt TFsReserveDriveSpace::DoRequestL(CFsRequest* aRequest)
924 // set reserved value to add to a drives reserved area
927 // extract request info
928 CSessionFs* session=aRequest->Session();
929 TDrive* drive = aRequest->Drive();
931 if(session->ReservedAccess(drive->DriveNumber()))
934 const TInt reserve = aRequest->Message().Int1(); //-- bytes to reserve on the drive
936 // Check if requested reserve space is within the range
937 if(reserve > KMaxSessionDriveReserved || reserve < 0)
940 const TInt64 threshold = reserve + drive->ReservedSpace(); //-- free bytes on the volume we actually need
942 TInt nRes = drive->RequestFreeSpaceOnMount(threshold);
946 const TInt current = session->Reserved(drive->DriveNumber());
947 const TInt diff = reserve - current;
948 TInt drvReserved = drive->ReservedSpace();
949 if((drvReserved + diff) > KMaxTotalDriveReserved)
953 drive->SetReservedSpace(drvReserved);
954 return session->SetReserved(drive->DriveNumber(), reserve);
958 TInt TFsReserveDriveSpace::Initialise(CFsRequest* aRequest)
960 // Validate drive and set up the session parameters for request
963 // if (!KCapFsReserveDriveSpace.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Reserve Drive Space")))
964 // return KErrPermissionDenied;
965 TInt drvNumber=aRequest->Message().Int1();
966 drvNumber=aRequest->Message().Int0();
967 TInt r=ValidateDrive(aRequest->Message().Int0(),aRequest);
972 TInt TFsGetReserveAccess::DoRequestL(CFsRequest* aRequest)
974 // Get reserved access to a drives reserved area first checking that the session has first reserved some space
977 CSessionFs* session=aRequest->Session();
979 TInt size=session->Reserved(aRequest->Drive()->DriveNumber());
981 return KErrPermissionDenied;
983 session->SetReservedAccess(aRequest->Drive()->DriveNumber(),ETrue);
987 TInt TFsGetReserveAccess::Initialise(CFsRequest* aRequest)
992 // if (!KCapFsGetReserveAccess.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Get Reserve Access")))
993 // return KErrPermissionDenied;
994 TInt r=ValidateDrive(aRequest->Message().Int0(),aRequest);
999 TInt TFsReleaseReserveAccess::DoRequestL(CFsRequest* aRequest)
1001 // Remove access for this session to the locked area for a given drive
1004 aRequest->Session()->SetReservedAccess(aRequest->Drive()->DriveNumber(),EFalse);
1008 TInt TFsReleaseReserveAccess::Initialise(CFsRequest* aRequest)
1013 // if (!KCapFsReleaseReserveAccess.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Release Reserve Access")))
1014 // return KErrPermissionDenied;
1015 TInt r=ValidateDrive(aRequest->Message().Int0(),aRequest);
1019 TInt TFsSetStartupConfiguration::DoRequestL(CFsRequest* aRequest)
1021 // Configure file server according to command and parameters.
1024 TInt cmd = aRequest->Message().Int0();
1028 case ELoaderPriority:
1029 // Set loader thread priority
1032 TFullName loaderFullName(RProcess().FullName());
1033 loaderFullName.Append(_L("::LoaderThread"));
1035 r = loader.Open(loaderFullName);
1038 loader.SetPriority((TThreadPriority)aRequest->Message().Int1());
1044 TInt drive = aRequest->Message().Int1();
1045 TInt r = ValidateDrive(drive, aRequest);
1048 TInt value = aRequest->Message().Int2();
1049 aRequest->Drive()->SetRugged(value);
1053 return KErrArgument;
1059 TInt TFsSetStartupConfiguration::Initialise(CFsRequest* aRequest)
1061 // Check SID of message sender. Can be estart only
1064 if (aRequest->Message().SecureId() != KEstartUidValue)
1065 return KErrPermissionDenied;
1070 const TInt KinitialChanges = EChangesLocale|EChangesMidnightCrossover|EChangesThreadDeath|EChangesPowerStatus|EChangesSystemTime|EChangesFreeMemory|EChangesOutOfMemory;
1072 CKernEventNotifier* CKernEventNotifier::New(TInt aPriority)
1074 __PRINT(_L("CKernEventNotifier::New"));
1075 CKernEventNotifier* self = new CKernEventNotifier(aPriority);
1076 if (self && (self->iChangeNotifier.Create() != KErrNone))
1077 delete self, self = NULL;
1081 CKernEventNotifier::~CKernEventNotifier()
1084 iChangeNotifier.Close();
1087 void CKernEventNotifier::Start()
1090 iChangeNotifier.Logon(iStatus);
1093 void CKernEventNotifier::RunL()
1095 __PRINT(_L("CKernEventNotifier::RunL"));
1096 iChange = iStatus.Int();
1099 /* Avoid being triggered by initial events */
1100 if (iChange != 0 && (iChange & KinitialChanges) != KinitialChanges)
1102 if (iChange & EChangesLocale)
1103 CKernEventNotifier::LocaleChangeCallback();
1104 if (iChange & EChangesFreeMemory)
1105 CKernEventNotifier::FreeMemoryChangeCallback();
1106 // Add other event capture below this line
1111 void CKernEventNotifier::DoCancel()
1113 iChangeNotifier.LogonCancel();
1117 extern TBool FatUtilitiesUpdateDrivesNotified;
1118 extern TBool FatUtilityFunctionsSet;
1120 TInt CKernEventNotifier::LocaleChangeCallback(TAny*)
1122 __PRINT(_L("CKernEventNotifier::LocaleChangeCallback"));
1124 //-- check if the locale has just been set and the drives are not yet notified about this.
1125 if(FatUtilityFunctionsSet && !FatUtilitiesUpdateDrivesNotified)
1126 {//-- notify drives about locale shange, but only once
1127 for(TInt i=0; i<KMaxDrives; i++)
1129 TDrive& drive=TheDrives[i];
1131 if(drive.DriveNumber() >=0 && drive.IsRemovable() && !drive.IsSubsted())
1133 __PRINT1(_L("CKernEventNotifier::LocaleChangeCallback upd drive: %d"), drive.DriveNumber());
1134 drive.SetChanged(ETrue);
1138 FatUtilitiesUpdateDrivesNotified = ETrue;
1144 TInt TFsQueryVolumeInfoExt::DoRequestL(CFsRequest* aRequest)
1146 const TInt cmd = aRequest->Message().Int1();
1149 TDrive* pDrive = aRequest->Drive();
1151 rel = pDrive->CheckMount();
1158 //-------------------------------------------------
1159 //-- file system sub type query
1160 case EFileSystemSubType:
1163 if (pDrive->IsMounted())
1165 rel = pDrive->CurrentMount().FileSystemSubType(name);
1167 //-- get the Mount's file system name if the FS subtype query is not supported or there are no subtypes.
1168 if (rel==KErrNotSupported)
1170 pDrive->CurrentMount().FileSystemName(name);
1175 TPckgBuf<TFSName> pckgBuf(name);
1176 aRequest->WriteL(KMsgPtr2, pckgBuf);
1186 return KErrNotReady;
1191 //-------------------------------------------------
1192 //-- this is RFs::VolumeIOParam() query
1195 TVolumeIOParamInfo ioInfo;
1196 // 1. gets block size information via media driver
1197 const TInt drive = aRequest->Message().Int0();
1199 // validates local drive numbers
1200 if(!IsValidLocalDriveMapping(drive))
1202 ioInfo.iBlockSize = KErrNotReady;
1206 // Get media capability
1207 TLocalDriveCapsV6Buf capsBuf;
1209 // is the drive local?
1210 if (!IsProxyDrive(drive))
1212 // if not valid local drive, use default values in localDriveCaps
1213 // if valid local drive and not locked, use TBusLocalDrive::Caps() values
1214 // if valid drive and locked, hard-code attributes
1215 rel = GetLocalDrive(drive).Caps(capsBuf);
1217 else // this need to be made a bit nicer
1219 CExtProxyDrive* pD = GetProxyDrive(drive);
1221 rel = pD->Caps(capsBuf);
1226 if (rel != KErrNone)
1228 ioInfo.iBlockSize = rel;
1232 TLocalDriveCapsV6& caps = capsBuf();
1233 if (caps.iBlockSize)
1235 ioInfo.iBlockSize = caps.iBlockSize;
1237 // returns default size (512) when block is not supported by
1241 ioInfo.iBlockSize = KDefaultVolumeBlockSize;
1246 // 2. gets cluster size via mounted file system; Also get Max. file size supported by the file system
1248 ioInfo.iMaxSupportedFileSize = KMaxTUint64; //-- the value for "not supported case"
1250 if (pDrive->IsMounted())
1252 rel = pDrive->CurrentMount().FileSystemClusterSize();
1253 ioInfo.iClusterSize = rel; // return cluster size or an error code if error happened.
1255 pDrive->CurrentMount().GetMaxSupportedFileSize(ioInfo.iMaxSupportedFileSize);
1260 ioInfo.iClusterSize = KErrNotReady;
1263 // 3. get rec buffer size from estart.txt file
1265 _LIT8(KLitSectionNameDrive,"Drive%C");
1266 ioInfo.iRecReadBufSize = KErrNotSupported;
1267 ioInfo.iRecWriteBufSize = KErrNotSupported;
1269 TBuf8<8> sectionName;
1271 sectionName.Format(KLitSectionNameDrive, 'A' + drive);
1272 // retrieve recommended buffer size information through F32 INI section
1273 if (F32Properties::GetInt(sectionName, _L8("RecReadBufSize"), bufSize))
1275 ioInfo.iRecReadBufSize = bufSize;
1277 if (F32Properties::GetInt(sectionName, _L8("RecWriteBufSize"), bufSize))
1279 ioInfo.iRecWriteBufSize = bufSize;
1282 // packaging and returning results
1283 TPckgBuf<TVolumeIOParamInfo> pckgBuf(ioInfo);
1284 aRequest->WriteL(KMsgPtr2, pckgBuf);
1287 // always return KErrNone as error codes are packaged and returned via ioInfo members
1289 } //case EIOParamInfo:
1291 //-------------------------------------------------
1292 //-- check if the specified drive is synchronous or not
1295 const TInt drive = aRequest->Message().Int0();
1296 const TBool bDrvSynch = FsThreadManager::IsDriveSync(drive, EFalse);
1297 TPckgBuf<TBool> buf(bDrvSynch);
1298 aRequest->WriteL(KMsgPtr2, buf);
1303 //-------------------------------------------------
1304 //-- query if the drive is finalised
1305 case EIsDriveFinalised:
1308 TInt nRes = pDrive->CurrentMount().IsMountFinalised(bFinalised);
1309 if(nRes != KErrNone)
1312 TPckgBuf<TBool> buf(bFinalised);
1313 aRequest->WriteL(KMsgPtr2, buf);
1321 return KErrNotSupported;
1326 TInt TFsQueryVolumeInfoExt::Initialise(CFsRequest* aRequest)
1328 TInt r = ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
1332 TInt CKernEventNotifier::FreeMemoryChangeCallback()
1334 __PRINT(_L("CKernEventNotifier::FreeMemoryChangeCallback"));
1336 TBool belowThreshold = (iChange & EChangesLowMemory)?(TBool)ETrue:(TBool)EFalse;
1337 CCacheManager* manager = CCacheManagerFactory::CacheManager();
1340 manager->FreeMemoryChanged(belowThreshold);
1342 // start flushing all dirty data
1346 TInt count=Files->Count();
1349 CFileCB* file = (CFileCB*)(*Files)[count];
1350 if (file->FileCache())
1351 // Cannot report errors here
1352 // coverity [unchecked_value]
1353 (void)file->FileCache()->FlushDirty();
1359 #ifdef SYMBIAN_ENABLE_FAT_DIRECTORY_OPT
1360 CCacheMemoryManager* cacheMemManager = CCacheMemoryManagerFactory::CacheMemoryManager();
1361 if (cacheMemManager)
1362 cacheMemManager->FreeMemoryChanged(belowThreshold);
1363 #endif //#ifdef SYMBIAN_ENABLE_FAT_DIRECTORY_OPT