Update contrib.
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_utl.cpp
22 const TInt KLog2BufGranularity=4; // 2^5 == 32
24 TBool ComparePaths(const TDesC& aPath1,const TDesC& aPath2)
26 // Return ETrue if the paths are identical
27 // To catch case "\\F32.\\GROUP\\" == "\\F32\\GROUP\\"
37 NextInPath(aPath1,entry1,pos1);
38 NextInPath(aPath2,entry2,pos2);
39 if (entry1.MatchF(entry2)==KErrNotFound)
41 } while (entry1.Length() && entry2.Length());
46 TBool CompareResource(const TDesC & aThePath)
48 //compare function for the Resource path true for match
51 TInt pathLen = aThePath.Length();
52 if(pathLen < KResourceLength)
54 //if not word aligned then no less efficient than treating as TUint16
55 const TUint32 * path32 = reinterpret_cast<const TUint32*>(aThePath.Ptr());
56 if( (*path32 & 0xFFDFFFFF) != 0x0052005c) // '/R'
59 if( (*path32 & 0xFFDFFFDF) != 0x00530045) // 'ES'
62 if( (*path32 & 0xFFDFFFDF) != 0x0055004F) // 'OU'
65 if( (*path32 & 0xFFDFFFDF) != 0x00430052) // 'RC'
68 if(pathLen > KResourceLength)
70 if( (*path32 & 0xFFFFFFDF) != 0x005c0045) // 'E/'
75 if( (*path32 & 0x0000FFDF) != 0x00000045) // 'E'
82 TBool CompareSystem(const TDesC & aThePath)
84 //compare function for the system path true for match
87 TInt pathLen = aThePath.Length();
88 if(pathLen < KSystemLength)
90 //if not word aligned then no less efficient than treating as TUint16
91 const TUint32 * path32 = reinterpret_cast<const TUint32*>(aThePath.Ptr());
92 if( (*path32 & 0xFFDFFFFF) != 0x0053005c) // '/S'
95 if( (*path32 & 0xFFDFFFDF) != 0x00530059) // 'YS
97 if(pathLen == KSystemLength)
100 if( (*path32 & 0x0000FFFF) != 0x0000005c) // '/'
106 TBool ComparePrivate(const TDesC & aThePath)
108 //compare function to compare if private path being accessed true for match
111 TInt pathLen = aThePath.Length();
112 if(pathLen < KPrivateLength)
114 const TUint32 * path32 = reinterpret_cast<const TUint32*>(aThePath.Ptr());
116 if((*path32 & 0xFFDFFFFF) != 0x0050005c) // '/P'
119 if( (*path32 & 0xFFDFFFDF) != 0x00490052) // 'RI
122 if( (*path32 & 0xFFDFFFDF) != 0x00410056) // 'VA'
125 if( (*path32 & 0xFFDFFFDF) != 0x00450054) // 'TE'
127 if(pathLen == KPrivateLength)
130 if( (*path32 & 0x0000FFFF) != 0x0000005c) // '/'
136 TBool SIDCheck(CFsRequest* aRequest, const TDesC& aThePath)
138 // Compare the Private/XXXXXXXX/ portion of a path be accessed to make sure it matches the process SID
141 if(aThePath.Length() >= KPrivateLengthCheck)
143 TSecureId appUID = aRequest->Message().SecureId();
144 TBuf<KSIDLength+1> dirName;
145 dirName.AppendNumFixedWidth(appUID.iId, EHex, 8);
147 TInt match = dirName.CompareF(aThePath.Mid(KSIDPathOffset,KPrivateLength));
157 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
158 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, const char* aDiag)
159 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
160 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, OnlyCreateWithNull /*aDiag*/)
161 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
163 // Compare the parsed path with protected path names path must be parsed b4 using
167 if(aRequest->Message().Handle() == KLocalMessageHandle)
170 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
173 TInt len = aThePath.Length();
174 diagmsg.Append((TUint8*)aThePath.Ptr(),len*2);
176 diagmsg.SetLength(len);
177 diagmsg.Append(_L(" Used to call: "));
178 len = User::StringLength((const TUint8*)aDiag);
179 diagmsg.Append((TUint8*)aDiag, len);
180 const char* const diagout = (char*)diagmsg.PtrZ();
182 const char* const diagout = aDiag;
184 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
186 if(ComparePrivate(aThePath))
188 if(SIDCheck(aRequest, aThePath))
192 if(aPriCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
195 return KErrPermissionDenied;
198 else if(CompareSystem(aThePath))
200 if(aSysCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
203 return KErrPermissionDenied;
205 else if(CompareResource(aThePath))
207 if(aROCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
210 return KErrPermissionDenied;
216 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
217 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const char* aDiag)
218 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
219 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, OnlyCreateWithNull /*aDiag*/)
220 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
222 // Compare the parsed path with protected path names path must be parsed b4 using
226 if(aRequest->Message().Handle() == KLocalMessageHandle)
229 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
232 TInt len = aThePath.Length();
233 diagmsg.Append((TUint8*)aThePath.Ptr(),len*2);
235 diagmsg.SetLength(len);
236 diagmsg.Append(_L(" Used to call: "));
237 len = User::StringLength((const TUint8*)aDiag);
238 diagmsg.Append((TUint8*)aDiag, len);
239 const char* const diagout = (char*)diagmsg.PtrZ();
241 const char* const diagout = aDiag;
243 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
245 if(ComparePrivate(aThePath))
247 if(SIDCheck(aRequest, aThePath))
251 if(aPriCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
254 return KErrPermissionDenied;
257 else if(CompareSystem(aThePath))
259 if(aSysCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
262 return KErrPermissionDenied;
268 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
269 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aCap, const char* aDiag, TBool aExactMatchAllowed)
270 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
271 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aCap, OnlyCreateWithNull /*aDiag*/, TBool aExactMatchAllowed)
272 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
274 // Compare the parsed path with protected path names path must be parsed b4 using
278 if(aRequest->Message().Handle() == KLocalMessageHandle)
281 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
284 TInt len = aThePath.Length();
285 diagmsg.Append((TUint8*)aThePath.Ptr(),len*2);
287 diagmsg.SetLength(len);
288 diagmsg.Append(_L(" Used to call: "));
289 len = User::StringLength((const TUint8*)aDiag);
290 diagmsg.Append((TUint8*)aDiag, len);
291 const char* const diagout = (char*)diagmsg.PtrZ();
293 const char* const diagout = aDiag;
295 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
297 if(ComparePrivate(aThePath))
299 if(SIDCheck(aRequest, aThePath))
303 if(aCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
305 else if (aExactMatchAllowed && aThePath.Length() <= KPrivateLength + 1)
308 return KErrPermissionDenied;
311 else if(CompareSystem(aThePath))
313 if(aCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
315 else if (aExactMatchAllowed && aThePath.Length() <= KSystemLength + 1)
318 return KErrPermissionDenied;
328 void Fault(TFsFault aFault)
330 // Fault the file server.
334 __PRINT1(_L("FAULT: TFsFault %d"),aFault);
335 User::Panic(_L("Fserv fault"),aFault);
339 Get Ptr() from the client and parse it. Allow wild cards.
340 Then get the drive and if the drive is substed get the real name.
342 @param aP message parameter number
343 @param aRequest pointer to the reques object
345 @param aUseSessionPath flag specifying whether the session path is to be
346 used for parsing or not. Default value is ETrue meaning
347 that the session path is used while parsing.
349 @return system-wide error code.
351 TInt ParseSubst(const TInt aP, CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
353 __ASSERT_DEBUG(aRequest->Session(),Fault(EParseSubstSession));
355 //-- check the length of the name, passed by client.
356 //-- it shall not be longer than KMaxFileName
357 TInt nameLen=aRequest->GetDesLength(aP);
358 if(nameLen < 0 || nameLen > KMaxFileName)
362 TRAPD(r, aRequest->ReadL(aP,n));
367 r=aParse.Set(n,NULL,&aRequest->Session()->Path());
369 r=aParse.Set(n,NULL,NULL);
373 if(!aUseSessionPath && !aParse.DrivePresent())
376 if ((r=RFs::CharToDrive(aParse.Drive()[0],drive))!=KErrNone)
378 aRequest->SetDrive(&TheDrives[drive]);
379 if (aRequest->Drive()->Att()&KDriveAttSubsted)
381 if ((aRequest->Drive()->Subst().Length()+aParse.FullName().Length())>(KMaxFileName+3))
383 aRequest->SetSubstedDrive(aRequest->Drive());
384 // and now set aParse with the full path name
385 n=aRequest->Drive()->Subst().Mid(2);
386 n+=aParse.FullName().Mid(3);
387 TFileName n2=aRequest->SubstedDrive()->Subst().Left(2);
388 r=aParse.Set(n,NULL,&n2);
391 aRequest->SetDrive(&aRequest->Drive()->SubstedDrive());
397 TInt ParseSubstPtr0(CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
399 // Get Ptr0() from the client and parse it. Allow wild cards.
400 // Then get the drive and if the drive is substed get the real name.
404 return(ParseSubst(KMsgPtr0,aRequest,aParse,aUseSessionPath));
407 TInt ParseNoWildSubstPtr0(CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
409 // Get Ptr0() from the client and parse it. Dis-allow wild cards.
410 // Then get the drive and if the drive is substed get the real name.
413 TInt r=ParseSubst(KMsgPtr0,aRequest,aParse,aUseSessionPath);
415 return(r); // Returns KErrBadName if "/" in the name or length > 256 chars
417 if (aParse.IsWild()) // No *s or ?s allowed in the file name
423 TInt ParseNoWildSubstPtr1(CFsRequest* aRequest,TParse& aParse)
425 // Get Ptr0() from the client and parse it. Dis-allow wild cards.
426 // Then get the drive and if the drive is substed get the real name.
429 TInt r=ParseSubst(KMsgPtr1, aRequest, aParse);
431 return(r); // Returns KErrBadName if "/" in the name or length > 256 chars
433 if (aParse.IsWild()) // No *s or ?s allowed in the file name
439 TInt ParseNoWildSubstCheckPathPtr0(CFsRequest* aRequest,TParse& aParse)
441 // Get Ptr0() from the client and parse it.
442 // Then get the drive and if the drive is substed get the real name.
443 // Dis-allow wild cards and the root directory
447 TInt r=ParseSubst(KMsgPtr0,aRequest,aParse);
450 if (aParse.IsWild() || (aParse.IsRoot() && !aParse.NameOrExtPresent()))
455 TInt ParseNoWildSubstCheckPathPtr1(CFsRequest* aRequest,TParse& aParse)
457 // Get Ptr1() from the client and parse it.
458 // Then get the drive and if the drive is substed get the real name.
459 // Dis-allow wild cards and the root directory
463 TInt r=ParseSubst(KMsgPtr1,aRequest,aParse);
466 if (aParse.IsWild() || (aParse.IsRoot() && !aParse.NameOrExtPresent()))
472 TInt ParseNoWildSubstFileCheckPtr1(CFsRequest* aRequest,TParse& aParse)
474 // Get Ptr0() from the client and parse it.
475 // Then get the drive and if the drive is substed get the real name.
476 // Dis-allow wild cards and the root directory
477 // Finally check that there is a name or extension.
480 TInt r=ParseSubst(KMsgPtr1,aRequest,aParse);
483 if (aParse.IsWild() || (aParse.IsRoot() && !aParse.NameOrExtPresent()))
485 if(!aParse.NameOrExtPresent())
486 return (KErrBadName);
490 TInt ParseNoWildSubstCheckPtr0(CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
492 // Get Ptr0() from the client and parse it. Dis-allow wild cards.
493 // Then get the drive and if the drive is substed get the real name.
494 // Finally check that there is a name or extension.
498 TInt r=ParseNoWildSubstPtr0(aRequest,aParse, aUseSessionPath);
501 if (!aParse.NameOrExtPresent())
506 TInt ParseNoWildSubstCheckPtr1(CFsRequest* aRequest,TParse& aParse)
508 // Get Ptr1() from the client and parse it. Dis-allow wild cards.
509 // Then get the drive and if the drive is substed get the real name.
510 // Finally check that there is a name or extension.
514 TInt r=ParseNoWildSubstPtr1(aRequest,aParse);
517 if (!aParse.NameOrExtPresent())
523 Get Ptr0() from the client and parse it.
525 @param aRequest pointer to the reques object
528 @return system-wide error code.
530 TInt ParsePathPtr0(CFsRequest* aRequest,TParse& aParse)
532 //-- check the length of the name, passed by client.
533 //-- it shall not be longer than KMaxFileName
534 TInt nameLen=aRequest->GetDesLength(KMsgPtr0);
535 if(nameLen < 0 || nameLen > KMaxFileName)
539 TRAPD(r,aRequest->ReadL(KMsgPtr0,n));
541 r=aParse.SetNoWild(n,NULL,&aRequest->Session()->Path());
544 if (aParse.NameOrExtPresent())
547 if ((r=RFs::CharToDrive(aParse.Drive()[0],drive))!=KErrNone)
549 aRequest->SetDrive(&TheDrives[drive]);
554 TInt ParseNotificationPath(CFsRequest* aRequest, TParse& aParse, TDes& aNotifyPath)
556 // Called by Notify Change extended function when client has submitted a path
557 // which contains a wildcarded initial character to represent the drive
558 // This is required when notification over a number of drives is required
561 if ((aNotifyPath[0]==KMatchAny)||(aNotifyPath[0]==KMatchOne))
563 // Use the default session drive for now
564 TFileName sessionDefault=aRequest->Session()->Path();
565 aNotifyPath[0]=sessionDefault[0];
568 TInt r=aParse.Set(aNotifyPath,NULL,&aRequest->Session()->Path());
572 if ((r=RFs::CharToDrive(aParse.Drive()[0],drive))!=KErrNone)
574 aRequest->SetDrive(&TheDrives[drive]);
575 if (aRequest->Drive()->Att()&KDriveAttSubsted)
577 if ((aRequest->Drive()->Subst().Length()+aParse.FullName().Length())>(KMaxFileName+3))
579 aRequest->SetSubstedDrive(aRequest->Drive());
580 // and now set aParse with the full path name
581 TFileName n=aRequest->Drive()->Subst().Mid(2);
582 n+=aParse.FullName().Mid(3);
583 TFileName n2=aRequest->SubstedDrive()->Subst().Left(2);
584 r=aParse.Set(n,NULL,&n2);
587 aRequest->SetDrive(&aRequest->Drive()->SubstedDrive());
595 CFsObject* SessionObjectFromHandle(TInt aHandle,TInt aUniqueID, CSessionFs* aSession)
597 // Lookup an object from its handle.
601 return(aSession->Handles().At(aHandle,ETrue));
603 return(aSession->Handles().At(aHandle,aUniqueID,ETrue));
607 CFileShare* GetShareFromHandle(CSessionFs* aSession, TInt aHandle)
609 // Get the share control block from its handle.
612 return((CFileShare*)(SessionObjectFromHandle(aHandle,FileShares->UniqueID(),aSession)));
617 // Returns ETrue if aDes only contains spaces or is zero length
619 static TBool IsSpace(const TDesC& aDes)
622 TInt len=aDes.Length();
625 for (TInt i=0;i<len;i++)
634 TUint32 CalcNameHash(const TDesC& aName)
636 const TUint32 KNameHashCRCInitialiser=0x12345678;
637 TUint32 hash=KNameHashCRCInitialiser;
638 Mem::Crc32(hash, aName.Ptr(), aName.Size());
643 TBool TNameChecker::IsIllegal(TText& aChar) const
645 // Checks aChar != any of < > : " / |
646 // \ is also illegal in a name but will be considered a path delimiter
667 TBool TNameChecker::IsIllegalChar(TText& aChar)
669 // Checks aName for illegal components and returns the offending character if any
670 // No other parsing is performed
673 TInt len=iName.Length();
676 if (IsIllegal(iName[len]))// '<', '>', ':', '"', '/', '|' or '\000'?
686 TBool TNameChecker::IsIllegalName()
688 // Checks name is not _L(".") or _L("..") and that there are no illegal characters
692 TInt pos=iName.LocateReverse(KPathDelimiter)+1;
693 TPtrC fileName(iName.Ptr()+pos,iName.Length()-pos);
696 if (iName==_L(".") || iName==_L("..") || IsSpace(iName))
698 TInt len=iName.Length();
702 if (IsIllegal(iName[len])) // '<', '>', ':', '"', '/', '|' or '\000'?
709 TBool TNameChecker::IsIllegalName(TText& aChar)
711 // Check name and path are legal - if not, return the offending component
714 TInt r=iParse.Set(iName,NULL,NULL);
716 return(ETrue); // Checks for names > 256 chars etc
718 SetName(iParse.FullName());
719 if (IsIllegalPath(aChar))
720 return(ETrue); // Checks for illegal characters in path
722 TInt nameStart=iParse.FullName().LocateReverse(KPathDelimiter)+1;
723 r=(iParse.FullName().Mid(nameStart)).LocateReverse(KPathDelimiter)+1;
724 TPtrC fileName(iName.Ptr()+r,iName.Length()-r);
727 if (iName==_L(".") || iName==_L("..") || IsSpace(iName))
733 return (IsIllegalChar(aChar));
736 const TInt KSpace = ' ';
737 TBool TNameChecker::IsIllegalPath()
739 // Checks the path does not contain wildcards or directories _L(".") or _L("..") or just spaces
743 if (iName.Locate(KMatchOne)!=KErrNotFound || iName.Locate(KMatchAny)!=KErrNotFound)
750 if (pathLex.Remainder().Length()==0)
752 TInt nextPath=pathLex.Remainder().Locate(KPathDelimiter);
753 if (nextPath==0) // Reject double backslashes
755 if (nextPath==KErrNotFound)
756 nextPath=pathLex.Remainder().Length();
758 pathLex.Inc(nextPath);
759 SetName(pathLex.MarkedToken());
762 // check for tailing dots
763 for(TInt i = pathLex.MarkedToken().Length() - 1; i >= 0; --i)
765 if (pathLex.MarkedToken()[i] == KExtDelimiter)
769 else if (pathLex.MarkedToken()[i] == KSpace)
783 TBool TNameChecker::IsIllegalPath(TText& aChar)
785 // Checks the path does not contain wildcards or directories _L(".") or _L("..") or just spaces
786 // Returns the first offending character found (if any)
789 if (iName.Locate(KMatchOne)!=KErrNotFound)
794 if (iName.Locate(KMatchAny)!=KErrNotFound)
805 if (pathLex.Remainder().Length()==0)
807 TInt nextPath=pathLex.Remainder().Locate(KPathDelimiter);
808 if (nextPath==0) // Reject double backslashes
810 aChar=KPathDelimiter;
813 if (nextPath==KErrNotFound)
814 nextPath=pathLex.Remainder().Length();
816 pathLex.Inc(nextPath);
817 name=pathLex.MarkedToken();
818 // check for tailing dots
819 for(TInt i = pathLex.MarkedToken().Length() - 1; i >= 0; --i)
821 if (pathLex.MarkedToken()[i] == KExtDelimiter)
823 aChar = KExtDelimiter;
826 else if (pathLex.MarkedToken()[i] == KSpace)
835 TInt pos=name.LocateReverse(KPathDelimiter)+1;
836 TPtrC fileName(name.Ptr()+pos,name.Length()-pos);
838 if (iName==_L(".") || iName==_L("..") || IsSpace(iName))
844 if (IsIllegalChar(aChar))
852 TBool IsIllegalFullName(const TParse& aParse)
854 TPtrC ptr=aParse.Path();
855 TNameChecker checker(ptr);
856 if (checker.IsIllegalPath())
857 return(ETrue); // Checks for illegal characters in path
859 TInt nameStart=aParse.FullName().LocateReverse(KPathDelimiter)+1;
860 checker.SetName(aParse.FullName().Mid(nameStart));
862 if (checker.IsIllegalName())
863 return(ETrue); // Checks illegal characters such as ></|". and ..
867 TBool IsIllegalFullName(const TDesC& aName)
869 // Check name and path are legal
873 TInt r=parser.Set(aName,NULL,NULL);
875 return(ETrue); // Checks for wild cards, names>256 chars etc
877 return IsIllegalFullName(parser);
882 // Check the power is OK
886 TBool powerGood=EFalse;
887 TInt r=HAL::Get(HAL::EPowerGood, powerGood);
893 void AddResource(CMountCB& aMount)
895 // Decrement resource counters
898 __CHECK_DRIVETHREAD(aMount.Drive().DriveNumber());
899 __ASSERT_DEBUG(aMount.LockStatus()<=0,Fault(ERawDiskBadAccessCount2));
903 void RemoveResource(CMountCB& aMount)
905 // Increment resource counters
908 __ASSERT_DEBUG(aMount.LockStatus()<0,Fault(ERawDiskBadAccessCount1));
913 void AddDiskAccess(CMountCB& aMount)
915 // Increment resource counters
921 void RemoveDiskAccess(CMountCB& aMount)
923 // Decrement resource counters
929 EXPORT_C void AllocBufferL(HBufC*& aBuf,const TDesC& aName)
931 // Alloc or ReAlloc buffer
940 if (aBuf->Length()<aName.Length())
942 TInt bufGranularity=(1<<KLog2BufGranularity);
943 TInt size=((aName.Length()+bufGranularity-1)>>KLog2BufGranularity)<<KLog2BufGranularity;
944 aBuf=aBuf->ReAllocL(size);
949 void NextInPath(const TDesC& aPath,TPtrC& anEntry,TInt& aPos)
951 // Returns the next entry in the path
956 if ((aPos+1)>=aPath.Length())
958 TPtrC path(aPath.Mid(aPos+1)); // Skip delimiter
959 TInt delimiterPos=path.Locate(KPathDelimiter);
960 if (delimiterPos==KErrNotFound)
961 delimiterPos=aPath.Length()-(aPos+1);
965 if (path[delimiterPos-1]==KExtDelimiter) // return "F32." as "F32"
966 anEntry.Set(aPath.Mid(aPos+1,delimiterPos-1));
968 anEntry.Set(aPath.Mid(aPos+1,delimiterPos));
969 aPos+=delimiterPos+1;
972 TInt MatchUidType(const TUidType &aMatch, const TUidType &aType)
974 // Compare aType against aMatch with KNullUid as a wildcard
980 if (mu!=KNullUid && tu!=KNullUid && mu!=tu)
981 return KErrNotSupported;
984 if (mu!=KNullUid && tu!=KNullUid && mu!=tu)
985 return KErrNotSupported;
988 if (mu!=KNullUid && tu!=KNullUid && mu!=tu)
989 return KErrNotSupported;
994 * Compare sections of filenames according to locale-independent rules as well
995 * as locale-dependent rules. This is an attempt to get an ordering where
996 * equivalent names sort together but the overall ordering is culturally
997 * acceptable. Sadly, the ordering it gives is not consistent, and it is not
998 * clear how to make it so. Hence this function is deprecated. The correct way
999 * to do this is to code around it: If you need a sorted array for display that
1000 * you also need to search for equivalent filenames, either use a linear search
1001 * or keep two arrays, one sorted with CompareF, the other with CompareC.
1004 EXPORT_C TInt CompareFilenames(const TDesC& aFileName1,const TDesC& aFileName2)
1006 // Compare filenames. Case is ignored and names are normalised
1007 // (base+accent is equal to composed character) but spaces
1008 // and punctuation are significant for determining equality.
1009 // Whether two filenames are identical is the same in all
1010 // locales, but the ordering of non-identical filenames is locale-specific.
1014 // Create a non-locale-specific collation method that doesn't ignore spaces and punctuation but folds case.
1015 TCollationMethod method;
1016 method.iFlags = TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase;
1017 method.iMainTable=NULL;
1018 method.iOverrideTable=NULL;
1020 // Get the non-locale-specific order and return it if the names are equal.
1021 TInt base_order = aFileName1.CompareC(aFileName2,3,&method);
1022 if (base_order == 0)
1025 // Get the locale-specific order and use it unless it is equality, in which case the non-locale-specific order must be used.
1026 TInt locale_order = aFileName1.CompareC(aFileName2);
1027 return locale_order ? locale_order : base_order;
1030 void Get8BitDllName(TDes8& aDllName, const TDesC& aFileName)
1032 // Convert a 16 bit name to an 8 bit name
1033 // No data loss because UNICODE Dlls are currently restricted to 8 bit names
1034 // No effect in 8 bit builds - just sets aDllName to aFileName
1037 aDllName.SetLength(aFileName.Length());
1038 aDllName.Copy(aFileName);
1041 void Get16BitDllName(TDes& aFileName, const TDesC8& aDllName)
1043 // Convert an 8 bit name to a 16 bit name - zero padded automatically
1044 // No effect in 8 bit builds - just sets aFileName to aDllName
1047 aFileName.SetLength(aDllName.Length());
1048 aFileName.Copy(aDllName);
1053 Checks that there is sufficient disk space available to complete a task taking into account reserved space
1055 @param aThreshold amount of required free space, in bytes
1058 @return KErrNone on success and if there are _strictly_more_ than aThreshold bytes available on the volume (taking into account reserved space)
1059 KErrDiskFull on success and if there isn't enough space
1060 system-wide error code otherwise
1062 TInt CheckDiskSpace(TInt64 aThreshold, CFsRequest* aRequest)
1064 const TInt KReservedSpace = aRequest->Drive()->ReservedSpace();
1065 const TInt KDriveNumber = aRequest->Drive()->DriveNumber();
1067 if(KReservedSpace == 0 || KDriveNumber == EDriveZ)
1070 //-- if the drive has a reserved space, take it into account
1071 CSessionFs* session=aRequest->Session();
1073 if(!session || !session->ReservedAccess(KDriveNumber))
1074 aThreshold += KReservedSpace;
1076 //-- ask the corresponding file system if there is aThreshold bytes available.
1077 //-- for some reason it's required to be strictly > than aThreshold
1078 return aRequest->Drive()->RequestFreeSpaceOnMount(aThreshold+1);
1082 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1083 EXPORT_C TUint32 DebugRegister() {return(DebugReg);}
1085 EXPORT_C TUint32 DebugRegister() {return(0);}
1088 CLogon* CLogon::NewL()
1090 // Create the CLogon active object.
1094 CLogon* pL=new(ELeave) CLogon(EPriority);
1095 CActiveScheduler::Add(pL);
1099 #pragma warning( disable : 4705 ) // statement has no effect
1100 CLogon::CLogon(TInt aPriority)
1104 : CActive(aPriority)
1107 #pragma warning( default : 4705 )
1109 TInt CLogon::Logon(RThread aThread)
1111 // Issue a request to logon to the thread.
1116 iThread.Logon(iStatus);
1118 if (iStatus==KErrNoMemory)
1119 iThread.Kill(KErrNoMemory);
1123 CActiveScheduler::Start();
1124 return(iStatus.Int());
1127 void CLogon::DoCancel()
1129 // Cancel a pending event.
1133 iThread.LogonCancel(iStatus);
1138 // Thread has terminated.
1142 CActiveScheduler::Stop();