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.
18 TInt TFsMkDir::DoRequestL(CFsRequest* aRequest)
20 // Make a directory path.
23 __PRINT(_L("TFsMkDir::DoRequestL(CFsRequest* aRequest)"));
25 TInt r = CheckDiskSpace(0, aRequest);
29 r=aRequest->Drive()->CheckMount();
33 if (aRequest->Src().IsRoot())
34 return(KErrAlreadyExists);
37 ptr.Set(aRequest->Src().Path().Ptr(), aRequest->Src().Path().Length()-1);
41 if (IsIllegalFullName(aRequest->Src().FullName()))
44 if (aRequest->Message().Int1())
50 lex.Inc(); // Skip a delimiter
51 TInt res=lex.Remainder().Locate(KPathDelimiter);
52 if (res==KErrNotFound)
56 filename+=lex.MarkedToken();
59 if ((r=aRequest->Drive()->Entry(filename,entry))==KErrNone)
62 return(KErrAccessDenied);
69 if ((r=aRequest->Drive()->MkDir(filename))!=KErrNone)
74 return(aRequest->Drive()->MkDir(ptr));
77 TInt TFsMkDir::Initialise(CFsRequest* aRequest)
82 TInt r=ParseSubstPtr0(aRequest,aRequest->Src());
85 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysMkDir,&KCapFsPriMkDir,&KCapFsROMkDir, __PLATSEC_DIAGNOSTIC_STRING("Make Directory"));
90 TInt TFsRmDir::DoRequestL(CFsRequest* aRequest)
92 // Remove a directory.
95 __PRINT(_L("TFsRmDir::DoRequestL(CFsRequest* aRequest)"));
96 if (aRequest->Src().IsRoot())
98 if (IsIllegalFullName(aRequest->Src().FullName()))
101 ptr.Set(aRequest->Src().Path().Ptr(), aRequest->Src().Path().Length()-1);
102 return(aRequest->Drive()->RmDir(ptr));
105 TInt TFsRmDir::Initialise(CFsRequest* aRequest)
110 TInt r=ParseSubstPtr0(aRequest,aRequest->Src());
113 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysRmDir,&KCapFsPriRmDir,&KCapFsRORmDir, __PLATSEC_DIAGNOSTIC_STRING("Remove Directory"));
118 TInt TFsDelete::DoRequestL(CFsRequest* aRequest)
123 __PRINT(_L("TFsDelete::DoRequestL(CFsRequest* aRequest)"));
124 return(aRequest->Drive()->Delete(aRequest->Src().FullName().Mid(2)));
127 TInt TFsDelete::Initialise(CFsRequest* aRequest)
132 TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
135 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysDelete,&KCapFsPriDelete,&KCapFsRODelete, __PLATSEC_DIAGNOSTIC_STRING("Delete"));
140 TInt TFsRename::DoRequestL(CFsRequest* aRequest)
142 // Rename a file or directory. Wild cards not allowed.
145 __PRINT(_L("TFsRename::DoRequestL(CFsRequest* aRequest)"));
146 TInt r = CheckDiskSpace(0, aRequest);
150 r = aRequest->Drive()->Rename(aRequest->Src().FullName().Mid(2),aRequest->Dest().FullName().Mid(2));
154 TInt TFsRename::Initialise(CFsRequest* aRequest)
159 TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
162 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysRename,&KCapFsPriRename,&KCapFsRORename, __PLATSEC_DIAGNOSTIC_STRING("File Server Rename"));
165 TDrive* pOldDrive=aRequest->Drive();
166 if ((r=ParseNoWildSubstCheckPathPtr1(aRequest,aRequest->Dest()))!=KErrNone)
168 r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysRename,&KCapFsPriRename,&KCapFsRORename, __PLATSEC_DIAGNOSTIC_STRING("File Server Rename"));
171 if (pOldDrive!=aRequest->Drive())
178 TInt TFsReplace::DoRequestL(CFsRequest* aRequest)
180 // Replace an old file with a new file atomically
183 __PRINT(_L("TFsReplace::DoRequestL(CFsRequest* aRequest)"));
185 TInt r = CheckDiskSpace(0, aRequest);
189 return(aRequest->Drive()->Replace(aRequest->Src().FullName().Mid(2),aRequest->Dest().FullName().Mid(2)));
192 TInt TFsReplace::Initialise(CFsRequest* aRequest)
197 TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
200 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysReplace,&KCapFsPriReplace,&KCapFsROReplace, __PLATSEC_DIAGNOSTIC_STRING("File Server Replace"));
203 TDrive* pOldDrive=aRequest->Drive();
204 if ((r=ParseNoWildSubstCheckPtr1(aRequest,aRequest->Dest()))!=KErrNone)
206 r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysReplace,&KCapFsPriReplace,&KCapFsROReplace, __PLATSEC_DIAGNOSTIC_STRING("File Server Replace"));
209 if (pOldDrive!=aRequest->Drive())
216 TInt TFsEntry::DoRequestL(CFsRequest* aRequest)
218 // Get all the entry details.
221 __PRINT(_L("TInt TFsEntry::DoRequestL(CFsRequest* aRequest)"));
224 TPtrC filePath = aRequest->Src().FullName().Mid(2);
225 TInt r=aRequest->Drive()->Entry(filePath,t);
229 // If the file is open, get the file size from the CFileCB object as there may be cached data
231 aRequest->Drive()->IsFileOpen(filePath, file);
233 t.SetFileSize(file->CachedSize64());
236 aRequest->WriteL(KMsgPtr1,p);
240 TInt TFsEntry::Initialise(CFsRequest* aRequest)
245 TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
249 // Check the capabilites but always allow the entry to be read for private, system and
250 // resource directories as long as there are no sub folders or files specified
251 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsEntry, __PLATSEC_DIAGNOSTIC_STRING("Entry"), ETrue);
257 TInt TFsSetEntry::DoRequestL(CFsRequest* aRequest)
259 // Set the attributes and the modified date and time.
262 __PRINT(_L("TFsSetEntry::DoRequestL(CFsRequest* aRequest)"));
264 TInt r = CheckDiskSpace(0, aRequest);
269 TPckgBuf<TTime> timeBuf;
270 aRequest->ReadL(KMsgPtr1,timeBuf);
272 const RMessage2& msg = aRequest->Message();
274 return(aRequest->Drive()->SetEntry(aRequest->Src().FullName().Mid(2),entryTime,msg.Int2(),msg.Int3()));
278 TInt TFsSetEntry::Initialise(CFsRequest* aRequest)
283 TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
286 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysSetEntry,&KCapFsPriSetEntry,&KCapFsROSetEntry, __PLATSEC_DIAGNOSTIC_STRING("Set Entry"));
290 LOCAL_C void FsReadFileSectionFileClose(CFsRequest* aRequest, CFileShare* aShare)
292 aRequest->Session()->DecResourceCount();
293 TInt handle = aRequest->Session()->Handles().At(aShare, EFalse);
294 aRequest->Session()->Handles().Remove(handle,ETrue);
295 // close the file share
296 aRequest->SetScratchValue64(0);
299 LOCAL_C CFileShare* FsReadFileSectionFileOpen(CFsRequest* aRequest)
302 TUint32 mode = EFileShareReadersOrWriters | EFileRead | EFileReadAheadOff;
304 TInt r = aRequest->Drive()->FileOpen(aRequest,handle,aRequest->Src().FullName().Mid(2),mode,EFileOpen);
308 CFileShare* share = (CFileShare*) SessionObjectFromHandle(handle, FileShares->UniqueID(), aRequest->Session());
310 aRequest->Session()->IncResourceCount();
312 CFileCB& file = share->File();
313 if (!file.FileCache())
315 FsReadFileSectionFileClose(aRequest, share);
321 TInt TFsReadFileSection::Complete(CFsRequest* aRequest)
323 FsReadFileSectionFileClose(aRequest, (CFileShare*) aRequest->ScratchValue());
325 return CFsRequest::EReqActionComplete;
328 TInt TFsReadFileSection::DoRequestL(CFsRequest* aRequest)
330 // Read from a file regardless of lock state
333 __PRINT(_L("TFsReadFileSection::DoRequestL(CFsRequest* aRequest)"));
335 TAny* pDes=(TAny*)(aRequest->Message().Ptr0());
337 if(aRequest->IsDescData(KMsgPtr2))
339 TPckg<TInt64> pkPos(pos);
340 aRequest->ReadL(KMsgPtr2, pkPos);
344 pos = MAKE_TINT64(0,aRequest->Message().Int2());
346 TInt len=aRequest->Message().Int3();
348 // Try to open file so we can take advantage of file caching
349 CFileShare* share = FsReadFileSectionFileOpen(aRequest);
352 CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
353 __ASSERT_DEBUG(msgRequest.CurrentOperationPtr() == NULL, Fault(EBadOperationIndex));
354 CFileCB& file = share->File();
355 TInt64 size = file.Size64();
359 if (pos + len > size)
360 // filesize - pos shall of TInt size
361 // Hence to suppress warning
362 len = (TInt)(size - pos);
366 r = msgRequest.PushOperation(pos, len, (TDesC8*) pDes, 0, TFsReadFileSection::Complete, 0, EFsFileRead);
367 msgRequest.SetState(CFsRequest::EReqStatePostInitialise); // DO call PostInitialise()
370 aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) );
371 return CFsRequest::EReqActionBusy; // dispatch the request again
373 FsReadFileSectionFileClose(aRequest, share);
380 r = aRequest->Drive()->ReadFileSection64(aRequest->Src().FullName().Mid(2),pos,pDes,len,aRequest->Message());
382 // zero return buffer, but only if we haven't written any data to it already, otherwise kernel's
383 // writeback of descriptor length will conflict with that wrttien by media driver
384 if (r != KErrNone || len == 0)
385 aRequest->WriteL(KMsgPtr0,KNullDesC8);
387 return r == KErrEof ? KErrNone : r;
391 TInt TFsReadFileSection::Initialise(CFsRequest* aRequest)
396 TInt r=ParseNoWildSubstFileCheckPtr1(aRequest,aRequest->Src());
399 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysReadFileSection,&KCapFsPriReadFileSection, __PLATSEC_DIAGNOSTIC_STRING("Read File Section"));
405 TInt TFsCheckDisk::DoRequestL(CFsRequest* aRequest)
407 // Check the disk's integrity
411 __PRINT(_L("TFsCheckDisk::DoRequestL(CFsRequest* aRequest)"));
413 // flush all files on this drive
414 TInt r = aRequest->Drive()->FlushCachedFileInfo();
415 if (r == CFsRequest::EReqActionBusy) // ignore any flush errors
418 return(aRequest->Drive()->CheckDisk());
422 TInt TFsCheckDisk::Initialise(CFsRequest* aRequest)
427 if (!KCapFsCheckDisk.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("CheckDisk")))
428 return KErrPermissionDenied;
429 return ParseSubstPtr0(aRequest,aRequest->Src()); //may make the rfs function call take a drive instead of path
432 TInt TFsScanDrive::DoRequestL(CFsRequest* aRequest)
437 __PRINT(_L("TFsScanDrive::DoRequestL(CFsRequest* aRequest)"));
439 // flush all files on this drive
440 TInt r = aRequest->Drive()->FlushCachedFileInfo();
441 if (r == CFsRequest::EReqActionBusy) // ignore any flush errors
444 r=aRequest->Drive()->CheckMount();
447 if (aRequest->Drive()->CurrentMount().LockStatus()<0)
449 r=aRequest->Drive()->ScanDrive();
450 // notify sessions since drive contents may have changed
452 FsNotify::DiskChange(aRequest->DriveNumber());
456 TInt TFsScanDrive::Initialise(CFsRequest* aRequest)
462 if(!KCapFsScanDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("ScanDrive")))
463 return KErrPermissionDenied;
464 r=ParseSubstPtr0(aRequest,aRequest->Src()); //may make the rfs function call take a drive instead of path
465 return(r); //then no need for parse, just needs to check for susted and reject them
468 TInt TFsGetShortName::DoRequestL(CFsRequest* aRequest)
470 // Get the short name associated with a long file name
473 __PRINT(_L("TFsGetShortName::DoRequestL(CFsRequest* aRequest)"));
474 TBuf<0x10> shortName;
475 TInt r=aRequest->Drive()->GetShortName(aRequest->Src().FullName().Mid(2),shortName);
478 aRequest->WriteL(KMsgPtr1,shortName);
482 TInt TFsGetShortName::Initialise(CFsRequest* aRequest)
487 TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
490 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysGetShortName,&KCapFsPriGetShortName, __PLATSEC_DIAGNOSTIC_STRING("Get Short Name"));
495 TInt TFsGetLongName::DoRequestL(CFsRequest* aRequest)
497 // Get the long name associated with a short file name
500 __PRINT(_L("TFsGetLongName::DoRequestL(CFsRequest* aRequest)"));
502 TInt r=aRequest->Drive()->GetLongName(aRequest->Src().FullName().Mid(2),longName);
505 aRequest->WriteL(KMsgPtr1,longName);
509 TInt TFsGetLongName::Initialise(CFsRequest* aRequest)
514 TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
517 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysGetLongName,&KCapFsPriGetLongName, __PLATSEC_DIAGNOSTIC_STRING("Get Long Name"));
522 TInt TFsIsFileInRom::DoRequestL(CFsRequest* aRequest)
524 // Return the address of the file
528 __PRINT(_L("DoIsFileInRom"));
530 TInt r=aRequest->Drive()->IsFileInRom(aRequest->Src().FullName().Mid(2),fileStart);
533 TPckgBuf<TUint8*> buf(fileStart);
534 aRequest->WriteL(KMsgPtr1,buf);
538 TInt TFsIsFileInRom::Initialise(CFsRequest* aRequest)
543 TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
546 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysIsFileInRom,&KCapFsPriIsFileInRom, __PLATSEC_DIAGNOSTIC_STRING("Is File In Rom"));
551 TInt TFsIsValidName::Initialise(CFsRequest* /*aRequest*/)
560 TInt TFsIsValidName::DoRequestL(CFsRequest* aRequest)
562 // Determine whether the name is valid
563 // If returnInvalidChar flag is set - determine the invalid character and
564 // return it to the client
565 // If TNameValidParam is specified determine the position of the invalid character
566 // and return it to the client.
568 __PRINT(_L("DoFsIsValidName"));
571 const TAny* pParam = aRequest->Message().Ptr3();
574 // We need to call DoFsIsValidName to determine what the invalid character is
575 TInt r=ParseSubstPtr0(aRequest,parse);
576 if ((r!=KErrNone) && (r!=KErrBadName))
579 TPckg<TBool> bPckg(retInvChar);
580 aRequest->ReadL(KMsgPtr1,bPckg);
582 // Determine whether the name is invalid but don't bother finding out which
583 // character (if any) is illegal
585 TInt r=ParseNoWildSubstCheckPtr0(aRequest,parse);
586 if ((r!=KErrNone) || IsIllegalFullName(parse.FullName().Mid(2)))
592 // Determine whether the name is invalid and return any offending character
594 TPckg<TText> pText(badChar);
596 TInt r=ParseSubstPtr0(aRequest,parse);
597 if (r==KErrBadName) // Name is > 256 characters or an illegal character
598 { // was encountered before path was completely parsed
600 aRequest->ReadL(KMsgPtr0,name);
601 TNameChecker checkName(name);
602 checkName.IsIllegalChar(badChar);
603 aRequest->WriteL(KMsgPtr2,pText);
606 // Weed out invalid * or ? in the filename (or no name and extension at all)
607 r=ParseNoWildSubstCheckPtr0(aRequest,parse);
610 if (parse.IsKMatchAny())
611 badChar=KMatchAny; // Offending character is '*'
612 else if (parse.IsKMatchOne())
613 badChar=KMatchOne; // Offending character is '?'
614 aRequest->WriteL(KMsgPtr2,pText);
618 // Weed out any other outstanding illegal characters in filename or path
619 TNameChecker checkName(parse.FullName().Mid(2));
620 if (checkName.IsIllegalName(badChar))
622 aRequest->WriteL(KMsgPtr2,pText);
625 else // No invalid characters in name
626 { // Set badChar to '\0'
628 aRequest->WriteL(KMsgPtr2,pText);
633 else //new API implementation
635 RFs::TNameValidParam param;
636 TPckg<RFs::TNameValidParam> paramPckg(param);
637 aRequest->ReadL(KMsgPtr3,paramPckg);
638 TUint nameLen=(TUint)aRequest->GetDesLength(KMsgPtr0);
639 if(nameLen == 0)// a name must be specified
641 param.iError = RFs::TNameValidParam::ErrBadName;
642 param.iInvalidCharPos = 0;
643 aRequest->WriteL(KMsgPtr3,paramPckg);
646 if(param.iUseSessionPath)
647 nameLen += aRequest->Session()->Path().Length();
648 if(nameLen > (TUint)KMaxFileName)
650 param.iError = RFs::TNameValidParam::ErrNameTooLong;
651 param.iInvalidCharPos = 0;
652 aRequest->WriteL(KMsgPtr3,paramPckg);
656 TInt driveLength = 2;
658 TRAPD(r, aRequest->ReadL(KMsgPtr0,fileName));
661 r=ParseSubstPtr0(aRequest,parse,param.iUseSessionPath);
662 if (KErrBadName == r) // An illegal character
663 { // was encountered before path was completely parsed
664 TNameChecker checkName(fileName);
665 if(checkName.IsIllegalChar(badChar))
667 param.iError = RFs::TNameValidParam::ErrBadCharacter;
668 param.iInvalidCharPos = fileName.LocateReverse(badChar)+1;
669 aRequest->WriteL(KMsgPtr3,paramPckg);
672 param.iError = RFs::TNameValidParam::ErrBadName;
673 param.iInvalidCharPos = 0;
674 aRequest->WriteL(KMsgPtr3,paramPckg);
677 // Weed out invalid * or ? in the filename
678 r=ParseNoWildSubstPtr0(aRequest,parse,param.iUseSessionPath);
683 if (parse.IsKMatchAny())
684 {// offending character is '*'
685 param.iError = RFs::TNameValidParam::ErrBadCharacter;
686 param.iInvalidCharPos = fileName.LocateReverse(KMatchAny)+1;
687 aRequest->WriteL(KMsgPtr3,paramPckg);
690 else if (parse.IsKMatchOne())
691 {//offending character is '?'
692 param.iError = RFs::TNameValidParam::ErrBadCharacter;
693 param.iInvalidCharPos = fileName.LocateReverse(KMatchOne)+1;
694 aRequest->WriteL(KMsgPtr3,paramPckg);
698 param.iError = RFs::TNameValidParam::ErrBadName;
699 param.iInvalidCharPos = 0;
700 aRequest->WriteL(KMsgPtr3,paramPckg);
703 if(!param.iUseSessionPath && !parse.DrivePresent())
705 // Weed out any other outstanding illegal characters in filename or path
706 TNameChecker checkName(parse.FullName().Mid(driveLength));
708 if (checkName.IsIllegalName(badChar))
712 param.iError = RFs::TNameValidParam::ErrBadName;
713 param.iInvalidCharPos = 0;
714 aRequest->WriteL(KMsgPtr3,paramPckg);
721 param.iError = RFs::TNameValidParam::ErrBadCharacter;
722 param.iInvalidCharPos = fileName.Locate(badChar)+1;
726 param.iError = RFs::TNameValidParam::ErrBadCharacter;
727 param.iInvalidCharPos = fileName.LocateReverse(badChar)+1;
729 aRequest->WriteL(KMsgPtr3,paramPckg);
733 else // No invalid characters in name
735 param.iError = RFs::TNameValidParam::ErrNone;
736 param.iInvalidCharPos = 0;
737 aRequest->WriteL(KMsgPtr3,paramPckg);
742 return r;//read is not successful.
747 TInt TFsLockDrive::DoRequestL(CFsRequest* aRequest)
752 __PRINT(_L("TFsLockDrive::DoRequestL(CFsRequest* aRequest)"));
753 TMediaPassword oldPw;
754 TMediaPassword newPw;
755 aRequest->ReadL(KMsgPtr1,oldPw);
756 aRequest->ReadL(KMsgPtr2,newPw);
757 return(aRequest->Drive()->LockDevice(oldPw,newPw,aRequest->Message().Int3()));
761 TInt TFsLockDrive::Initialise(CFsRequest* aRequest)
766 if (!KCapFsLockDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Lock Drive")))
767 return KErrPermissionDenied;
768 TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
772 TInt TFsUnlockDrive::DoRequestL(CFsRequest* aRequest)
774 // Unlock media device
777 __PRINT(_L("TFsUnlockDrive::DoRequestL(CFsRequest* aRequest)"));
779 aRequest->ReadL(KMsgPtr1,pW);
780 return(aRequest->Drive()->UnlockDevice(pW,aRequest->Message().Int2()));
784 TInt TFsUnlockDrive::Initialise(CFsRequest* aRequest)
789 if (!KCapFsUnlockDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Unlock Drive")))
790 return KErrPermissionDenied;
791 TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
795 TInt TFsClearPassword::DoRequestL(CFsRequest* aRequest)
797 // Clears password of media device
800 __PRINT(_L("TFsClearPassowrd::DoRequestL(CFsRequest* aRequest)"));
802 aRequest->ReadL(KMsgPtr1,pW);
803 return(aRequest->Drive()->ClearDevicePassword(pW));
807 TInt TFsClearPassword::Initialise(CFsRequest* aRequest)
812 if (!KCapFsClearPassword.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Clear Password")))
813 return KErrPermissionDenied;
814 return ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
817 TInt TFsErasePassword::DoRequestL(CFsRequest* aRequest)
819 // Erase the password from the media device
822 __PRINT(_L("TFsErasePassword::DoRequestL(CFsRequest* aRequest)"));
823 return(aRequest->Drive()->EraseDevicePassword());
827 TInt TFsErasePassword::Initialise(CFsRequest* aRequest)
832 if (!KCapFsErasePassword.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Erase Password")))
833 return KErrPermissionDenied;
834 return ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
839 TInt TFsSessionToPrivate::DoRequestL(CFsRequest* aRequest)
841 // Set session path to the private directory (does not need to exist)
845 pPath=_L("?:\\Private\\");
846 pPath[0]= (TText)('A'+ aRequest->Message().Int0());
847 pPath.AppendNumFixedWidth(aRequest->Message().SecureId().iId, EHex, 8);
849 HBufC* pP = pPath.Alloc();
852 delete &aRequest->Session()->Path();
853 aRequest->Session()->SetPath(pP);
858 TInt TFsSessionToPrivate::Initialise(CFsRequest* /*aRequest*/)
860 // standard initialisation
866 TInt TFsPrivatePath::DoRequestL(CFsRequest* aRequest)
868 // may be able to do this user side !!!
871 TSecureId appUID = aRequest->Message().SecureId();
872 TFileName pPath(KPrivateSlash);
873 pPath.AppendNumFixedWidth(appUID.iId, EHex, 8);
875 aRequest->WriteL(KMsgPtr0,pPath);
881 TInt TFsPrivatePath::Initialise(CFsRequest* /*aRequest*/)
890 TInt TFsCreatePrivatePath::DoRequestL(CFsRequest* aRequest)
892 // create the private path unless it already exists
895 TInt ret = CheckDiskSpace(0, aRequest);
899 TBuf<30> pPath(KPrivate);
901 pPath.AppendNumFixedWidth(aRequest->Message().SecureId().iId, EHex, 8);
903 ret=aRequest->Drive()->CheckMount();
907 //no point going mad on sanity check we know it's not root or a bad name
908 ret =aRequest->Drive()->Entry(KPrivate(),e);
911 if(ret==KErrNotFound)
913 ret = aRequest->Drive()->MkDir(KPrivate());
920 ret =aRequest->Drive()->Entry(pPath,e);
921 if(ret==KErrPathNotFound || ret==KErrNotFound || !e.IsDir())
923 if((ret=aRequest->Drive()->MkDir(pPath ))!=KErrNone)
930 TInt TFsCreatePrivatePath::Initialise(CFsRequest* aRequest)
935 TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
939 TInt TFsFinaliseDrive::DoRequestL(CFsRequest* aRequest)
941 __PRINT(_L("TFsFinaliseDrive::DoRequestL"));
943 TInt r=aRequest->Drive()->CheckMount();
947 const TInt nMode = aRequest->Message().Int1(); //-- finalisation mode, see RFs::TFinaliseDrvMode
949 return aRequest->Drive()->FinaliseMount(nMode);
955 TInt TFsFinaliseDrive::Initialise(CFsRequest* aRequest)
957 if (!KCapFsFinaliseDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Finalise Drive")))
958 return KErrPermissionDenied;
960 const TInt nDrv = aRequest->Message().Int0(); //-- the drive number to be finalised
962 TInt r = ValidateDriveDoSubst(nDrv, aRequest);
966 TDrive& d = TheDrives[nDrv];
968 return KErrNotFound; //-- something wrong with this drive
971 //-- check the drive attributes
972 const TUint KDrvAttExclude = KDriveAttRom | KDriveAttRedirected; //-- the drive attributes to exlcude from the finalisation
973 if(d.Att() & KDrvAttExclude)
974 return KErrNotSupported; //-- finalisation isn't supported for these drives
979 /** Set System Drive (used by GetSystemDrive and SystemDriveChar) */
980 TInt TFsSetSystemDrive::DoRequestL(CFsRequest* aRequest)
982 __PRINT(_L("TFsSetSystemDrive::DoRequestL()"));
984 TInt err = RProperty::Get(TSecureId(KFileServerUidValue), KSystemDriveKey, drive);
987 __PRINT1(_L("TFsSetSystemDrive::DoRequestL() drv:%d is already defined as system!"), drive);
988 return KErrAlreadyExists;
991 drive = aRequest->Message().Int0();
992 __ASSERT_ALWAYS(drive>=EDriveA && drive<=EDriveZ, Fault(EInvalidDrive));
994 //Calculates the total number of valid drives present and set RAM as a
995 //system drive only if one valid drive is present.
996 TInt total_drive = 0;
997 for (TInt driveNumber=0; driveNumber<KMaxDrives; driveNumber++)
999 if(TheDrives[driveNumber].GetFSys() != NULL) // is a valid drive
1002 aRequest->SetDrive(&TheDrives[drive]);
1003 FsThreadManager::LockDrive(aRequest->DriveNumber());
1005 aRequest->Drive()->DriveInfo(info);
1006 FsThreadManager::UnlockDrive(aRequest->DriveNumber());
1008 __PRINT1(_L("TFsSetSystemDrive::DoRequestL() total drives:%d"), total_drive);
1009 __PRINT3(_L("TFsSetSystemDrive::DoRequestL() setting sys:%d, Media:0x%x, DrvAtt:0x%x"), drive, info.iType, info.iDriveAtt);
1011 //-- 1. check media type of the system drive.
1012 __ASSERT_ALWAYS(info.iType==EMediaHardDisk || info.iType==EMediaFlash || info.iType==EMediaNANDFlash || info.iType==EMediaRam, Fault(EInvalidDrive));
1014 if(info.iType == EMediaRam)
1015 {//-- It is not nice to use RAM drive as a system one because it might non be persistent, but acceptable though.
1016 __PRINT(_L("TFsSetSystemDrive::DoRequestL() WARNING: RAM drive is set as system drive!"));
1019 //-- 2. check drive attributes for the system drive
1020 const TUint requiredDrvAtt = KDriveAttLocal|KDriveAttInternal;
1021 const TUint prohibitedDrvAtt = KDriveAttRom|KDriveAttRedirected|KDriveAttSubsted|KDriveAttRemovable;
1023 ASSERT(!(prohibitedDrvAtt & requiredDrvAtt));
1024 if( !(info.iDriveAtt & requiredDrvAtt) || (info.iDriveAtt & prohibitedDrvAtt))
1026 __PRINT2(_L("TFsSetSystemDrive::DoRequestL(), Wrong Drive attributes! req:0x%x, disallowed:0x%x"), requiredDrvAtt, prohibitedDrvAtt);
1027 Fault(EInvalidDrive);
1032 TSecurityPolicy policy(p.SecureId());
1033 err = RProperty::Define(TSecureId(KFileServerUidValue), KSystemDriveKey, RProperty::EInt, TSecurityPolicy::EAlwaysPass, policy);
1036 err = RProperty::Set(TSecureId(KFileServerUidValue), KSystemDriveKey, drive);
1038 __ASSERT_ALWAYS(err==KErrNone, User::Invariant());
1043 /** Checks if setting System Drive is allowed */
1044 TInt TFsSetSystemDrive::Initialise(CFsRequest* aRequest)
1046 if (!KCapFsSetSystemDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Set System Drive")))
1048 return KErrPermissionDenied;