os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_utl.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32\sfile\sf_utl.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "sf_std.h"
sl@0
    19
#include <hal.h>
sl@0
    20
#include <collate.h>
sl@0
    21
sl@0
    22
const TInt KLog2BufGranularity=4; // 2^5 == 32
sl@0
    23
sl@0
    24
TBool ComparePaths(const TDesC& aPath1,const TDesC& aPath2)
sl@0
    25
//
sl@0
    26
// Return ETrue if the paths are identical
sl@0
    27
// To catch case "\\F32.\\GROUP\\" == "\\F32\\GROUP\\"
sl@0
    28
//
sl@0
    29
  	{
sl@0
    30
  
sl@0
    31
  	TPtrC entry1(NULL,0);
sl@0
    32
  	TPtrC entry2(NULL,0);
sl@0
    33
  	TInt pos1=0;
sl@0
    34
  	TInt pos2=0;
sl@0
    35
  
sl@0
    36
  	do {
sl@0
    37
  		NextInPath(aPath1,entry1,pos1);
sl@0
    38
  		NextInPath(aPath2,entry2,pos2);
sl@0
    39
  		if (entry1.MatchF(entry2)==KErrNotFound)
sl@0
    40
  			return(EFalse);
sl@0
    41
  		} while (entry1.Length() && entry2.Length());
sl@0
    42
  	
sl@0
    43
  	return(ETrue);
sl@0
    44
	}
sl@0
    45
sl@0
    46
TBool CompareResource(const TDesC & aThePath)
sl@0
    47
//
sl@0
    48
//compare function for the Resource path true for match
sl@0
    49
//
sl@0
    50
	{
sl@0
    51
	TInt pathLen = aThePath.Length();
sl@0
    52
	if(pathLen < KResourceLength)	
sl@0
    53
		return EFalse;
sl@0
    54
	//if not word aligned then no less efficient than treating as TUint16 
sl@0
    55
	const TUint32 * path32 = reinterpret_cast<const TUint32*>(aThePath.Ptr());
sl@0
    56
	if( (*path32 & 0xFFDFFFFF) != 0x0052005c)			//	'/R' 
sl@0
    57
		return EFalse;
sl@0
    58
	path32++;
sl@0
    59
	if( (*path32 & 0xFFDFFFDF) != 0x00530045)			// 'ES'
sl@0
    60
		return EFalse;
sl@0
    61
	path32++;
sl@0
    62
	if( (*path32 & 0xFFDFFFDF) != 0x0055004F)			// 'OU'
sl@0
    63
		return EFalse;
sl@0
    64
	path32++;
sl@0
    65
	if( (*path32 & 0xFFDFFFDF) != 0x00430052)			// 'RC'
sl@0
    66
		return EFalse;
sl@0
    67
	path32++;
sl@0
    68
	if(pathLen > KResourceLength)
sl@0
    69
		{
sl@0
    70
		if( (*path32 & 0xFFFFFFDF) != 0x005c0045)			// 'E/'
sl@0
    71
			return EFalse;
sl@0
    72
		}
sl@0
    73
	else
sl@0
    74
		{
sl@0
    75
		if( (*path32 & 0x0000FFDF) != 0x00000045)			// 'E'
sl@0
    76
			return EFalse;
sl@0
    77
		}
sl@0
    78
sl@0
    79
	return ETrue;
sl@0
    80
	}
sl@0
    81
sl@0
    82
TBool CompareSystem(const TDesC & aThePath) 
sl@0
    83
//
sl@0
    84
//compare function for the system path true for match
sl@0
    85
//
sl@0
    86
	{
sl@0
    87
	TInt pathLen = aThePath.Length();
sl@0
    88
	if(pathLen < KSystemLength)	
sl@0
    89
		return EFalse;
sl@0
    90
	//if not word aligned then no less efficient than treating as TUint16 
sl@0
    91
	const TUint32 * path32 = reinterpret_cast<const TUint32*>(aThePath.Ptr());
sl@0
    92
	if( (*path32 & 0xFFDFFFFF) != 0x0053005c)			//	'/S' 
sl@0
    93
		return EFalse;
sl@0
    94
	path32++;
sl@0
    95
	if( (*path32 & 0xFFDFFFDF) != 0x00530059)			// 'YS
sl@0
    96
		return EFalse;
sl@0
    97
	if(pathLen == KSystemLength)
sl@0
    98
		return ETrue;
sl@0
    99
	path32++;
sl@0
   100
	if( (*path32 & 0x0000FFFF) != 0x0000005c)			// '/'
sl@0
   101
		return EFalse;
sl@0
   102
sl@0
   103
	return ETrue;
sl@0
   104
	}
sl@0
   105
sl@0
   106
TBool ComparePrivate(const TDesC & aThePath) 
sl@0
   107
//
sl@0
   108
//compare function to compare if private path being accessed true for match
sl@0
   109
//
sl@0
   110
	{
sl@0
   111
	TInt pathLen = aThePath.Length();
sl@0
   112
	if(pathLen < KPrivateLength)	
sl@0
   113
		return EFalse;
sl@0
   114
	const TUint32 * path32 = reinterpret_cast<const TUint32*>(aThePath.Ptr());
sl@0
   115
sl@0
   116
	if((*path32 & 0xFFDFFFFF) != 0x0050005c)			//	'/P' 
sl@0
   117
		return EFalse;
sl@0
   118
	path32++;
sl@0
   119
	if( (*path32 & 0xFFDFFFDF) != 0x00490052)			// 'RI
sl@0
   120
		return EFalse;
sl@0
   121
	path32++;
sl@0
   122
	if( (*path32 & 0xFFDFFFDF) != 0x00410056)			// 'VA'
sl@0
   123
		return EFalse;
sl@0
   124
	path32++;
sl@0
   125
	if( (*path32 & 0xFFDFFFDF) != 0x00450054)			// 'TE'
sl@0
   126
		return EFalse;
sl@0
   127
	if(pathLen == KPrivateLength)
sl@0
   128
		return ETrue;
sl@0
   129
	path32++;
sl@0
   130
	if( (*path32 & 0x0000FFFF) != 0x0000005c)			// '/'
sl@0
   131
		return EFalse;
sl@0
   132
sl@0
   133
	return ETrue;
sl@0
   134
	}
sl@0
   135
sl@0
   136
TBool SIDCheck(CFsRequest* aRequest, const TDesC& aThePath)
sl@0
   137
//
sl@0
   138
//	Compare the Private/XXXXXXXX/ portion of a path be accessed to make sure it matches the process SID 
sl@0
   139
//
sl@0
   140
	{
sl@0
   141
	if(aThePath.Length() >= KPrivateLengthCheck)
sl@0
   142
		{
sl@0
   143
		TSecureId appUID = aRequest->Message().SecureId();
sl@0
   144
		TBuf<KSIDLength+1> dirName;
sl@0
   145
		dirName.AppendNumFixedWidth(appUID.iId, EHex, 8);
sl@0
   146
	
sl@0
   147
		TInt match = dirName.CompareF(aThePath.Mid(KSIDPathOffset,KPrivateLength));
sl@0
   148
		if(match==KErrNone)
sl@0
   149
			return ETrue;
sl@0
   150
		else
sl@0
   151
			return EFalse;
sl@0
   152
		}
sl@0
   153
	
sl@0
   154
	return EFalse;
sl@0
   155
	}
sl@0
   156
sl@0
   157
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   158
TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, const char* aDiag)
sl@0
   159
#else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   160
TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, OnlyCreateWithNull /*aDiag*/)
sl@0
   161
#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   162
//
sl@0
   163
//	Compare the parsed path with protected path names path must be parsed b4 using
sl@0
   164
//
sl@0
   165
	{
sl@0
   166
sl@0
   167
	if(aRequest->Message().Handle() == KLocalMessageHandle)
sl@0
   168
		return KErrNone;
sl@0
   169
sl@0
   170
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   171
#ifdef _DEBUG
sl@0
   172
	TBuf8<512> diagmsg;
sl@0
   173
	TInt len = aThePath.Length();
sl@0
   174
	diagmsg.Append((TUint8*)aThePath.Ptr(),len*2);
sl@0
   175
	diagmsg.Collapse();
sl@0
   176
	diagmsg.SetLength(len);
sl@0
   177
	diagmsg.Append(_L(" Used to call: "));
sl@0
   178
	len = User::StringLength((const TUint8*)aDiag);
sl@0
   179
	diagmsg.Append((TUint8*)aDiag, len);
sl@0
   180
	const char* const diagout = (char*)diagmsg.PtrZ();
sl@0
   181
#else //!_DEBUG
sl@0
   182
	const char* const diagout = aDiag;
sl@0
   183
#endif //_DEBUG
sl@0
   184
#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   185
sl@0
   186
	if(ComparePrivate(aThePath))
sl@0
   187
		{	
sl@0
   188
		if(SIDCheck(aRequest, aThePath))
sl@0
   189
			return KErrNone;	
sl@0
   190
		else
sl@0
   191
			{
sl@0
   192
			if(aPriCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
sl@0
   193
				return KErrNone;
sl@0
   194
			else
sl@0
   195
				return KErrPermissionDenied;
sl@0
   196
			}
sl@0
   197
		}
sl@0
   198
	else if(CompareSystem(aThePath))
sl@0
   199
		{
sl@0
   200
		if(aSysCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
sl@0
   201
			return KErrNone;
sl@0
   202
		else
sl@0
   203
			return KErrPermissionDenied;
sl@0
   204
		}
sl@0
   205
	else if(CompareResource(aThePath))
sl@0
   206
		{
sl@0
   207
		if(aROCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
sl@0
   208
			return KErrNone;
sl@0
   209
		else
sl@0
   210
			return KErrPermissionDenied;
sl@0
   211
		}
sl@0
   212
	else
sl@0
   213
		return KErrNone;
sl@0
   214
 	}
sl@0
   215
sl@0
   216
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   217
TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const char* aDiag) 
sl@0
   218
#else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   219
TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, OnlyCreateWithNull /*aDiag*/) 
sl@0
   220
#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   221
//
sl@0
   222
//	Compare the parsed path with protected path names path must be parsed b4 using
sl@0
   223
//
sl@0
   224
	{
sl@0
   225
sl@0
   226
	if(aRequest->Message().Handle() == KLocalMessageHandle)
sl@0
   227
		return KErrNone;
sl@0
   228
sl@0
   229
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   230
#ifdef _DEBUG
sl@0
   231
	TBuf8<512> diagmsg;
sl@0
   232
	TInt len = aThePath.Length();
sl@0
   233
	diagmsg.Append((TUint8*)aThePath.Ptr(),len*2);
sl@0
   234
	diagmsg.Collapse();
sl@0
   235
	diagmsg.SetLength(len);
sl@0
   236
	diagmsg.Append(_L(" Used to call: "));
sl@0
   237
	len = User::StringLength((const TUint8*)aDiag);
sl@0
   238
	diagmsg.Append((TUint8*)aDiag, len);
sl@0
   239
	const char* const diagout = (char*)diagmsg.PtrZ();
sl@0
   240
#else //!_DEBUG	
sl@0
   241
	const char* const diagout = aDiag;
sl@0
   242
#endif //_DEBUG
sl@0
   243
#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   244
sl@0
   245
	if(ComparePrivate(aThePath))
sl@0
   246
		{	
sl@0
   247
		if(SIDCheck(aRequest, aThePath))
sl@0
   248
			return KErrNone;	
sl@0
   249
		else
sl@0
   250
			{
sl@0
   251
			if(aPriCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
sl@0
   252
				return KErrNone;
sl@0
   253
			else
sl@0
   254
				return KErrPermissionDenied;
sl@0
   255
			}
sl@0
   256
		}
sl@0
   257
	else if(CompareSystem(aThePath))
sl@0
   258
		{
sl@0
   259
		if(aSysCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
sl@0
   260
			return KErrNone;
sl@0
   261
		else
sl@0
   262
			return KErrPermissionDenied;
sl@0
   263
		}
sl@0
   264
	else
sl@0
   265
		return KErrNone;
sl@0
   266
 	}
sl@0
   267
sl@0
   268
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   269
TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aCap, const char* aDiag, TBool aExactMatchAllowed) 
sl@0
   270
#else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   271
TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aCap, OnlyCreateWithNull /*aDiag*/, TBool aExactMatchAllowed) 
sl@0
   272
#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   273
//
sl@0
   274
//	Compare the parsed path with protected path names path must be parsed b4 using
sl@0
   275
//
sl@0
   276
	{
sl@0
   277
sl@0
   278
	if(aRequest->Message().Handle() == KLocalMessageHandle)
sl@0
   279
		return KErrNone;
sl@0
   280
sl@0
   281
#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   282
#ifdef _DEBUG
sl@0
   283
	TBuf8<512> diagmsg;
sl@0
   284
	TInt len = aThePath.Length();
sl@0
   285
	diagmsg.Append((TUint8*)aThePath.Ptr(),len*2);
sl@0
   286
	diagmsg.Collapse();
sl@0
   287
	diagmsg.SetLength(len);
sl@0
   288
	diagmsg.Append(_L(" Used to call: "));
sl@0
   289
	len = User::StringLength((const TUint8*)aDiag);
sl@0
   290
	diagmsg.Append((TUint8*)aDiag, len);
sl@0
   291
	const char* const diagout = (char*)diagmsg.PtrZ();
sl@0
   292
#else //!_DEBUG	
sl@0
   293
	const char* const diagout = aDiag;
sl@0
   294
#endif //_DEBUG
sl@0
   295
#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
sl@0
   296
sl@0
   297
	if(ComparePrivate(aThePath))
sl@0
   298
		{	
sl@0
   299
		if(SIDCheck(aRequest, aThePath))
sl@0
   300
			return KErrNone;	
sl@0
   301
		else
sl@0
   302
			{
sl@0
   303
			if(aCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
sl@0
   304
				return KErrNone;
sl@0
   305
			else if (aExactMatchAllowed && aThePath.Length() <= KPrivateLength + 1)
sl@0
   306
				return KErrNone;
sl@0
   307
			else
sl@0
   308
				return KErrPermissionDenied;
sl@0
   309
			}
sl@0
   310
		}
sl@0
   311
	else if(CompareSystem(aThePath))
sl@0
   312
		{
sl@0
   313
		if(aCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
sl@0
   314
			return KErrNone;
sl@0
   315
		else if (aExactMatchAllowed && aThePath.Length() <= KSystemLength + 1)
sl@0
   316
			return KErrNone;
sl@0
   317
		else
sl@0
   318
			return KErrPermissionDenied;
sl@0
   319
		}
sl@0
   320
	else
sl@0
   321
		return KErrNone;
sl@0
   322
	
sl@0
   323
	}
sl@0
   324
sl@0
   325
sl@0
   326
sl@0
   327
sl@0
   328
void Fault(TFsFault aFault)
sl@0
   329
//
sl@0
   330
// Fault the file server.
sl@0
   331
//
sl@0
   332
	{
sl@0
   333
sl@0
   334
	__PRINT1(_L("FAULT: TFsFault %d"),aFault);
sl@0
   335
	User::Panic(_L("Fserv fault"),aFault);
sl@0
   336
	}
sl@0
   337
sl@0
   338
/**
sl@0
   339
    Get Ptr() from the client and parse it. Allow wild cards.
sl@0
   340
    Then get the drive and if the drive is substed get the real name.
sl@0
   341
    
sl@0
   342
    @param  aP          	message parameter number
sl@0
   343
    @param  aRequest    	pointer to the reques object
sl@0
   344
    @param  aParse      	parser
sl@0
   345
    @param  aUseSessionPath flag specifying whether the session path is to be
sl@0
   346
     						used for parsing or not. Default value is ETrue meaning
sl@0
   347
     						that the session path is used while parsing.
sl@0
   348
sl@0
   349
    @return     system-wide error code.
sl@0
   350
*/
sl@0
   351
TInt ParseSubst(const TInt aP, CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
sl@0
   352
	{
sl@0
   353
	__ASSERT_DEBUG(aRequest->Session(),Fault(EParseSubstSession));
sl@0
   354
	
sl@0
   355
	//-- check the length of the name, passed by client.
sl@0
   356
	//-- it shall not be longer than KMaxFileName
sl@0
   357
	TInt nameLen=aRequest->GetDesLength(aP);
sl@0
   358
	if(nameLen < 0 || nameLen > KMaxFileName)
sl@0
   359
	    return KErrBadName;
sl@0
   360
	
sl@0
   361
	TFileName n;
sl@0
   362
	TRAPD(r, aRequest->ReadL(aP,n));
sl@0
   363
	
sl@0
   364
	if(r==KErrNone)
sl@0
   365
		{
sl@0
   366
		if(aUseSessionPath)
sl@0
   367
			r=aParse.Set(n,NULL,&aRequest->Session()->Path());
sl@0
   368
		else
sl@0
   369
			r=aParse.Set(n,NULL,NULL);
sl@0
   370
		}
sl@0
   371
	if (r!=KErrNone)
sl@0
   372
		return(r);
sl@0
   373
	if(!aUseSessionPath && !aParse.DrivePresent())
sl@0
   374
		return(r);
sl@0
   375
	TInt drive;
sl@0
   376
	if ((r=RFs::CharToDrive(aParse.Drive()[0],drive))!=KErrNone)
sl@0
   377
		return(r);
sl@0
   378
	aRequest->SetDrive(&TheDrives[drive]);
sl@0
   379
	if (aRequest->Drive()->Att()&KDriveAttSubsted)
sl@0
   380
		{
sl@0
   381
		if ((aRequest->Drive()->Subst().Length()+aParse.FullName().Length())>(KMaxFileName+3))
sl@0
   382
			return(KErrBadName);
sl@0
   383
		aRequest->SetSubstedDrive(aRequest->Drive());
sl@0
   384
		// and now set aParse with the full path name
sl@0
   385
		n=aRequest->Drive()->Subst().Mid(2);
sl@0
   386
		n+=aParse.FullName().Mid(3);
sl@0
   387
		TFileName n2=aRequest->SubstedDrive()->Subst().Left(2);
sl@0
   388
		r=aParse.Set(n,NULL,&n2);
sl@0
   389
		if(r!=KErrNone)
sl@0
   390
			return(r);
sl@0
   391
		aRequest->SetDrive(&aRequest->Drive()->SubstedDrive());
sl@0
   392
		}
sl@0
   393
	return(KErrNone);
sl@0
   394
	}
sl@0
   395
sl@0
   396
sl@0
   397
TInt ParseSubstPtr0(CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
sl@0
   398
//
sl@0
   399
// Get Ptr0() from the client and parse it. Allow wild cards.
sl@0
   400
// Then get the drive and if the drive is substed get the real name.
sl@0
   401
//
sl@0
   402
	{
sl@0
   403
sl@0
   404
	return(ParseSubst(KMsgPtr0,aRequest,aParse,aUseSessionPath));
sl@0
   405
	}
sl@0
   406
sl@0
   407
TInt ParseNoWildSubstPtr0(CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
sl@0
   408
//
sl@0
   409
// Get Ptr0() from the client and parse it. Dis-allow wild cards.
sl@0
   410
// Then get the drive and if the drive is substed get the real name.
sl@0
   411
//
sl@0
   412
	{
sl@0
   413
	TInt r=ParseSubst(KMsgPtr0,aRequest,aParse,aUseSessionPath);
sl@0
   414
	if (r!=KErrNone)
sl@0
   415
		return(r);	//	Returns KErrBadName if "/" in the name or length > 256 chars
sl@0
   416
	
sl@0
   417
	if (aParse.IsWild())	//	No *s or ?s allowed in the file name
sl@0
   418
		return(KErrBadName);
sl@0
   419
	return(KErrNone);
sl@0
   420
	}
sl@0
   421
sl@0
   422
sl@0
   423
TInt ParseNoWildSubstPtr1(CFsRequest* aRequest,TParse& aParse)
sl@0
   424
//
sl@0
   425
// Get Ptr0() from the client and parse it. Dis-allow wild cards.
sl@0
   426
// Then get the drive and if the drive is substed get the real name.
sl@0
   427
//
sl@0
   428
	{
sl@0
   429
	TInt r=ParseSubst(KMsgPtr1, aRequest, aParse);
sl@0
   430
	if (r!=KErrNone)
sl@0
   431
		return(r);	//	Returns KErrBadName if "/" in the name or length > 256 chars
sl@0
   432
	
sl@0
   433
	if (aParse.IsWild())	//	No *s or ?s allowed in the file name
sl@0
   434
		return(KErrBadName);
sl@0
   435
	return(KErrNone);
sl@0
   436
	}
sl@0
   437
sl@0
   438
sl@0
   439
TInt ParseNoWildSubstCheckPathPtr0(CFsRequest* aRequest,TParse& aParse)
sl@0
   440
//
sl@0
   441
// Get Ptr0() from the client and parse it.
sl@0
   442
// Then get the drive and if the drive is substed get the real name.
sl@0
   443
// Dis-allow wild cards and the root directory
sl@0
   444
//
sl@0
   445
	{
sl@0
   446
sl@0
   447
	TInt r=ParseSubst(KMsgPtr0,aRequest,aParse);
sl@0
   448
	if (r!=KErrNone)
sl@0
   449
		return(r);
sl@0
   450
	if (aParse.IsWild() || (aParse.IsRoot() && !aParse.NameOrExtPresent()))
sl@0
   451
		return(KErrBadName);
sl@0
   452
	return(KErrNone);
sl@0
   453
	}
sl@0
   454
sl@0
   455
TInt ParseNoWildSubstCheckPathPtr1(CFsRequest* aRequest,TParse& aParse)
sl@0
   456
//
sl@0
   457
// Get Ptr1() from the client and parse it.
sl@0
   458
// Then get the drive and if the drive is substed get the real name.
sl@0
   459
// Dis-allow wild cards and the root directory
sl@0
   460
//
sl@0
   461
	{
sl@0
   462
sl@0
   463
	TInt r=ParseSubst(KMsgPtr1,aRequest,aParse);
sl@0
   464
	if (r!=KErrNone)
sl@0
   465
		return(r);
sl@0
   466
	if (aParse.IsWild() || (aParse.IsRoot() && !aParse.NameOrExtPresent()))
sl@0
   467
		return(KErrBadName);
sl@0
   468
sl@0
   469
	return(KErrNone);
sl@0
   470
	}
sl@0
   471
sl@0
   472
TInt ParseNoWildSubstFileCheckPtr1(CFsRequest* aRequest,TParse& aParse)
sl@0
   473
//
sl@0
   474
// Get Ptr0() from the client and parse it.
sl@0
   475
// Then get the drive and if the drive is substed get the real name.
sl@0
   476
// Dis-allow wild cards and the root directory
sl@0
   477
// Finally check that there is a name or extension.
sl@0
   478
	{
sl@0
   479
sl@0
   480
	TInt r=ParseSubst(KMsgPtr1,aRequest,aParse);
sl@0
   481
	if (r!=KErrNone)
sl@0
   482
		return(r);
sl@0
   483
	if (aParse.IsWild() || (aParse.IsRoot() && !aParse.NameOrExtPresent()))
sl@0
   484
		return(KErrBadName);
sl@0
   485
	if(!aParse.NameOrExtPresent())
sl@0
   486
	    return (KErrBadName);
sl@0
   487
	return(KErrNone);
sl@0
   488
	}
sl@0
   489
sl@0
   490
TInt ParseNoWildSubstCheckPtr0(CFsRequest* aRequest,TParse& aParse, TBool aUseSessionPath)
sl@0
   491
//
sl@0
   492
// Get Ptr0() from the client and parse it. Dis-allow wild cards.
sl@0
   493
// Then get the drive and if the drive is substed get the real name.
sl@0
   494
// Finally check that there is a name or extension.
sl@0
   495
//
sl@0
   496
	{
sl@0
   497
sl@0
   498
	TInt r=ParseNoWildSubstPtr0(aRequest,aParse, aUseSessionPath);	
sl@0
   499
	if (r!=KErrNone)
sl@0
   500
		return(r);
sl@0
   501
	if (!aParse.NameOrExtPresent())
sl@0
   502
		return(KErrBadName);
sl@0
   503
	return(KErrNone);
sl@0
   504
	}
sl@0
   505
sl@0
   506
TInt ParseNoWildSubstCheckPtr1(CFsRequest* aRequest,TParse& aParse)
sl@0
   507
//
sl@0
   508
// Get Ptr1() from the client and parse it. Dis-allow wild cards.
sl@0
   509
// Then get the drive and if the drive is substed get the real name.
sl@0
   510
// Finally check that there is a name or extension.
sl@0
   511
//
sl@0
   512
	{
sl@0
   513
sl@0
   514
	TInt r=ParseNoWildSubstPtr1(aRequest,aParse);
sl@0
   515
	if (r!=KErrNone)
sl@0
   516
		return(r);
sl@0
   517
	if (!aParse.NameOrExtPresent())
sl@0
   518
		return(KErrBadName);
sl@0
   519
	return(KErrNone);
sl@0
   520
	}
sl@0
   521
sl@0
   522
/**
sl@0
   523
    Get Ptr0() from the client and parse it.
sl@0
   524
sl@0
   525
    @param  aRequest    pointer to the reques object
sl@0
   526
    @param  aParse      parser
sl@0
   527
sl@0
   528
    @return     system-wide error code.
sl@0
   529
*/
sl@0
   530
TInt ParsePathPtr0(CFsRequest* aRequest,TParse& aParse)
sl@0
   531
	{
sl@0
   532
	//-- check the length of the name, passed by client.
sl@0
   533
	//-- it shall not be longer than KMaxFileName
sl@0
   534
	TInt nameLen=aRequest->GetDesLength(KMsgPtr0);
sl@0
   535
	if(nameLen < 0 || nameLen > KMaxFileName)
sl@0
   536
	    return KErrBadName;
sl@0
   537
sl@0
   538
	TFileName n;
sl@0
   539
	TRAPD(r,aRequest->ReadL(KMsgPtr0,n));
sl@0
   540
	if (r==KErrNone)
sl@0
   541
		r=aParse.SetNoWild(n,NULL,&aRequest->Session()->Path());
sl@0
   542
	if (r!=KErrNone)
sl@0
   543
		return(r);
sl@0
   544
	if (aParse.NameOrExtPresent())
sl@0
   545
		return(KErrBadName);
sl@0
   546
	TInt drive;
sl@0
   547
	if ((r=RFs::CharToDrive(aParse.Drive()[0],drive))!=KErrNone)
sl@0
   548
		return(r);
sl@0
   549
	aRequest->SetDrive(&TheDrives[drive]);
sl@0
   550
	return(KErrNone);
sl@0
   551
	}
sl@0
   552
sl@0
   553
sl@0
   554
TInt ParseNotificationPath(CFsRequest* aRequest, TParse& aParse, TDes& aNotifyPath)
sl@0
   555
//
sl@0
   556
//	Called by Notify Change extended function when client has submitted a path
sl@0
   557
//	which contains a wildcarded initial character to represent the drive
sl@0
   558
//	This is required when notification over a number of drives is required
sl@0
   559
//
sl@0
   560
	{
sl@0
   561
	if ((aNotifyPath[0]==KMatchAny)||(aNotifyPath[0]==KMatchOne))
sl@0
   562
		{
sl@0
   563
	//	Use the default session drive for now
sl@0
   564
		TFileName sessionDefault=aRequest->Session()->Path();
sl@0
   565
		aNotifyPath[0]=sessionDefault[0];
sl@0
   566
		}
sl@0
   567
sl@0
   568
	TInt r=aParse.Set(aNotifyPath,NULL,&aRequest->Session()->Path());
sl@0
   569
	if (r!=KErrNone)
sl@0
   570
		return(r);
sl@0
   571
	TInt drive;
sl@0
   572
	if ((r=RFs::CharToDrive(aParse.Drive()[0],drive))!=KErrNone)
sl@0
   573
		return(r);
sl@0
   574
	aRequest->SetDrive(&TheDrives[drive]);
sl@0
   575
	if (aRequest->Drive()->Att()&KDriveAttSubsted)
sl@0
   576
		{
sl@0
   577
		if ((aRequest->Drive()->Subst().Length()+aParse.FullName().Length())>(KMaxFileName+3))
sl@0
   578
			return(KErrBadName);
sl@0
   579
		aRequest->SetSubstedDrive(aRequest->Drive());
sl@0
   580
		// and now set aParse with the full path name
sl@0
   581
		TFileName n=aRequest->Drive()->Subst().Mid(2);
sl@0
   582
		n+=aParse.FullName().Mid(3);
sl@0
   583
		TFileName n2=aRequest->SubstedDrive()->Subst().Left(2);
sl@0
   584
		r=aParse.Set(n,NULL,&n2);
sl@0
   585
		if(r!=KErrNone)
sl@0
   586
			return(r);
sl@0
   587
		aRequest->SetDrive(&aRequest->Drive()->SubstedDrive());
sl@0
   588
		}	
sl@0
   589
	if (aParse.IsWild())
sl@0
   590
		return(KErrBadName);
sl@0
   591
	return(KErrNone);
sl@0
   592
	}
sl@0
   593
sl@0
   594
sl@0
   595
CFsObject* SessionObjectFromHandle(TInt aHandle,TInt aUniqueID, CSessionFs* aSession)
sl@0
   596
//
sl@0
   597
// Lookup an object from its handle.
sl@0
   598
//
sl@0
   599
	{
sl@0
   600
	if(aUniqueID==0)
sl@0
   601
		return(aSession->Handles().At(aHandle,ETrue));
sl@0
   602
	else
sl@0
   603
		return(aSession->Handles().At(aHandle,aUniqueID,ETrue));
sl@0
   604
	}
sl@0
   605
sl@0
   606
sl@0
   607
CFileShare* GetShareFromHandle(CSessionFs* aSession, TInt aHandle)
sl@0
   608
//
sl@0
   609
// Get the share control block from its handle.
sl@0
   610
//
sl@0
   611
	{
sl@0
   612
	return((CFileShare*)(SessionObjectFromHandle(aHandle,FileShares->UniqueID(),aSession)));
sl@0
   613
	}
sl@0
   614
sl@0
   615
sl@0
   616
//
sl@0
   617
// Returns ETrue if aDes only contains spaces or is zero length
sl@0
   618
//
sl@0
   619
static TBool IsSpace(const TDesC& aDes)
sl@0
   620
	{
sl@0
   621
sl@0
   622
	TInt len=aDes.Length();
sl@0
   623
	if (len==0)
sl@0
   624
		return(EFalse);
sl@0
   625
	for (TInt i=0;i<len;i++)
sl@0
   626
		{
sl@0
   627
		TChar txt=aDes[i];
sl@0
   628
		if (!txt.IsSpace())
sl@0
   629
			return(EFalse);
sl@0
   630
		}
sl@0
   631
	return(ETrue);
sl@0
   632
	}
sl@0
   633
sl@0
   634
TUint32 CalcNameHash(const TDesC& aName) 
sl@0
   635
	{
sl@0
   636
	const TUint32 KNameHashCRCInitialiser=0x12345678;
sl@0
   637
	TUint32 hash=KNameHashCRCInitialiser;
sl@0
   638
	Mem::Crc32(hash, aName.Ptr(), aName.Size());
sl@0
   639
	return hash;
sl@0
   640
	}
sl@0
   641
sl@0
   642
sl@0
   643
TBool TNameChecker::IsIllegal(TText& aChar) const
sl@0
   644
//
sl@0
   645
// Checks aChar != any of < > : " / |
sl@0
   646
// \ is also illegal in a name but will be considered a path delimiter
sl@0
   647
//
sl@0
   648
	{
sl@0
   649
	switch (aChar)
sl@0
   650
		{
sl@0
   651
	case '<':
sl@0
   652
	case '>':
sl@0
   653
	case ':':
sl@0
   654
	case '"':
sl@0
   655
	case '/':
sl@0
   656
	case '|':
sl@0
   657
	case '\000':
sl@0
   658
		return(ETrue);
sl@0
   659
	default:
sl@0
   660
		break;
sl@0
   661
		}
sl@0
   662
	return(EFalse);
sl@0
   663
	}
sl@0
   664
sl@0
   665
sl@0
   666
sl@0
   667
TBool TNameChecker::IsIllegalChar(TText& aChar)
sl@0
   668
//	
sl@0
   669
//	Checks aName for illegal components and returns the offending character if any
sl@0
   670
//	No other parsing is performed
sl@0
   671
//
sl@0
   672
	{
sl@0
   673
	TInt len=iName.Length();
sl@0
   674
	while (len--)
sl@0
   675
		{
sl@0
   676
		if (IsIllegal(iName[len]))// '<', '>', ':', '"', '/', '|' or '\000'?
sl@0
   677
			{
sl@0
   678
			aChar=iName[len];
sl@0
   679
			return(ETrue);
sl@0
   680
			}
sl@0
   681
		}
sl@0
   682
	return(EFalse);
sl@0
   683
	}
sl@0
   684
sl@0
   685
sl@0
   686
TBool TNameChecker::IsIllegalName()
sl@0
   687
//
sl@0
   688
// Checks name is not _L(".") or _L("..") and that there are no illegal characters
sl@0
   689
//
sl@0
   690
	{
sl@0
   691
sl@0
   692
	TInt pos=iName.LocateReverse(KPathDelimiter)+1;
sl@0
   693
	TPtrC fileName(iName.Ptr()+pos,iName.Length()-pos);
sl@0
   694
	SetName(fileName);
sl@0
   695
	
sl@0
   696
	if (iName==_L(".") || iName==_L("..") || IsSpace(iName))
sl@0
   697
		return ETrue;
sl@0
   698
	TInt len=iName.Length();
sl@0
   699
	
sl@0
   700
	while (len--)
sl@0
   701
		{
sl@0
   702
		if (IsIllegal(iName[len]))	//	'<', '>', ':', '"', '/', '|' or '\000'?
sl@0
   703
			return(ETrue);
sl@0
   704
		}
sl@0
   705
	return(EFalse);
sl@0
   706
	}
sl@0
   707
sl@0
   708
sl@0
   709
TBool TNameChecker::IsIllegalName(TText& aChar)
sl@0
   710
//
sl@0
   711
//	Check name and path are legal - if not, return the offending component
sl@0
   712
//
sl@0
   713
	{
sl@0
   714
	TInt r=iParse.Set(iName,NULL,NULL);
sl@0
   715
	if (r!=KErrNone)
sl@0
   716
		return(ETrue);	//	Checks for names > 256 chars etc
sl@0
   717
	
sl@0
   718
	SetName(iParse.FullName());
sl@0
   719
	if (IsIllegalPath(aChar))
sl@0
   720
		return(ETrue);	//	Checks for illegal characters in path
sl@0
   721
	
sl@0
   722
	TInt nameStart=iParse.FullName().LocateReverse(KPathDelimiter)+1;
sl@0
   723
	r=(iParse.FullName().Mid(nameStart)).LocateReverse(KPathDelimiter)+1;
sl@0
   724
	TPtrC fileName(iName.Ptr()+r,iName.Length()-r);
sl@0
   725
	SetName(fileName);
sl@0
   726
sl@0
   727
	if (iName==_L(".") || iName==_L("..") || IsSpace(iName))
sl@0
   728
		{
sl@0
   729
		aChar=iName[0]; 
sl@0
   730
		return ETrue;
sl@0
   731
		}
sl@0
   732
	
sl@0
   733
	return (IsIllegalChar(aChar));
sl@0
   734
	}
sl@0
   735
sl@0
   736
const TInt KSpace = ' ';
sl@0
   737
TBool TNameChecker::IsIllegalPath()
sl@0
   738
//
sl@0
   739
// Checks the path does not contain wildcards or directories _L(".") or _L("..") or just spaces
sl@0
   740
//
sl@0
   741
	{
sl@0
   742
sl@0
   743
	if (iName.Locate(KMatchOne)!=KErrNotFound || iName.Locate(KMatchAny)!=KErrNotFound)
sl@0
   744
		return(ETrue);
sl@0
   745
sl@0
   746
	TLex pathLex=iName;
sl@0
   747
	FOREVER
sl@0
   748
		{
sl@0
   749
		pathLex.Inc();
sl@0
   750
		if (pathLex.Remainder().Length()==0)
sl@0
   751
			break;
sl@0
   752
		TInt nextPath=pathLex.Remainder().Locate(KPathDelimiter);
sl@0
   753
		if (nextPath==0) // Reject double backslashes
sl@0
   754
			return(ETrue);
sl@0
   755
		if (nextPath==KErrNotFound)
sl@0
   756
			nextPath=pathLex.Remainder().Length();
sl@0
   757
		pathLex.Mark();
sl@0
   758
		pathLex.Inc(nextPath);
sl@0
   759
		SetName(pathLex.MarkedToken());
sl@0
   760
		if (IsIllegalName())
sl@0
   761
			return(ETrue);
sl@0
   762
		// check for tailing dots
sl@0
   763
		for(TInt i = pathLex.MarkedToken().Length() - 1; i >= 0; --i)
sl@0
   764
			{
sl@0
   765
			if (pathLex.MarkedToken()[i] == KExtDelimiter)
sl@0
   766
				{
sl@0
   767
				return ETrue;
sl@0
   768
				}
sl@0
   769
			else if (pathLex.MarkedToken()[i] == KSpace)
sl@0
   770
				{
sl@0
   771
				continue;
sl@0
   772
				}
sl@0
   773
			else
sl@0
   774
				{
sl@0
   775
				break;
sl@0
   776
				}
sl@0
   777
			}
sl@0
   778
		}
sl@0
   779
	return(EFalse);
sl@0
   780
	}
sl@0
   781
sl@0
   782
sl@0
   783
TBool TNameChecker::IsIllegalPath(TText& aChar)
sl@0
   784
//
sl@0
   785
//	Checks the path does not contain wildcards or directories _L(".") or _L("..") or just spaces
sl@0
   786
//	Returns the first offending character found (if any)
sl@0
   787
//
sl@0
   788
	{
sl@0
   789
	if (iName.Locate(KMatchOne)!=KErrNotFound)
sl@0
   790
		{
sl@0
   791
		aChar=KMatchOne;
sl@0
   792
		return (ETrue);
sl@0
   793
		}
sl@0
   794
	if (iName.Locate(KMatchAny)!=KErrNotFound)
sl@0
   795
		{
sl@0
   796
		aChar=KMatchAny;
sl@0
   797
		return (ETrue);
sl@0
   798
		}
sl@0
   799
sl@0
   800
	TLex pathLex=iName;
sl@0
   801
	TFileName name;
sl@0
   802
	FOREVER
sl@0
   803
		{
sl@0
   804
		pathLex.Inc();
sl@0
   805
		if (pathLex.Remainder().Length()==0)
sl@0
   806
			break;
sl@0
   807
		TInt nextPath=pathLex.Remainder().Locate(KPathDelimiter);
sl@0
   808
		if (nextPath==0) // Reject double backslashes
sl@0
   809
			{
sl@0
   810
			aChar=KPathDelimiter; 
sl@0
   811
			return ETrue;
sl@0
   812
			}	
sl@0
   813
		if (nextPath==KErrNotFound)
sl@0
   814
			nextPath=pathLex.Remainder().Length();
sl@0
   815
		pathLex.Mark();
sl@0
   816
		pathLex.Inc(nextPath);
sl@0
   817
		name=pathLex.MarkedToken();
sl@0
   818
		// check for tailing dots
sl@0
   819
		for(TInt i = pathLex.MarkedToken().Length() - 1; i >= 0; --i)
sl@0
   820
			{
sl@0
   821
			if (pathLex.MarkedToken()[i] == KExtDelimiter)
sl@0
   822
				{
sl@0
   823
				aChar = KExtDelimiter;
sl@0
   824
				return ETrue;
sl@0
   825
				}
sl@0
   826
			else if (pathLex.MarkedToken()[i] == KSpace)
sl@0
   827
				{
sl@0
   828
				continue;
sl@0
   829
				}
sl@0
   830
			else
sl@0
   831
				{
sl@0
   832
				break;
sl@0
   833
				}
sl@0
   834
			}
sl@0
   835
		TInt pos=name.LocateReverse(KPathDelimiter)+1;
sl@0
   836
		TPtrC fileName(name.Ptr()+pos,name.Length()-pos);
sl@0
   837
		SetName(fileName);
sl@0
   838
		if (iName==_L(".") || iName==_L("..") || IsSpace(iName))
sl@0
   839
			{
sl@0
   840
			aChar=iName[0]; 
sl@0
   841
			return ETrue;
sl@0
   842
			}
sl@0
   843
		
sl@0
   844
		if (IsIllegalChar(aChar))
sl@0
   845
			return(ETrue);
sl@0
   846
		}
sl@0
   847
	
sl@0
   848
	return(EFalse);
sl@0
   849
	}
sl@0
   850
sl@0
   851
sl@0
   852
TBool IsIllegalFullName(const TParse& aParse)
sl@0
   853
	{
sl@0
   854
	TPtrC ptr=aParse.Path();
sl@0
   855
	TNameChecker checker(ptr);
sl@0
   856
	if (checker.IsIllegalPath())
sl@0
   857
		return(ETrue);	//	Checks for illegal characters in path
sl@0
   858
	
sl@0
   859
	TInt nameStart=aParse.FullName().LocateReverse(KPathDelimiter)+1;
sl@0
   860
	checker.SetName(aParse.FullName().Mid(nameStart));
sl@0
   861
	
sl@0
   862
	if (checker.IsIllegalName())
sl@0
   863
		return(ETrue);	//	Checks illegal characters such as ></|". and ..
sl@0
   864
	return(EFalse);
sl@0
   865
	}
sl@0
   866
sl@0
   867
 TBool IsIllegalFullName(const TDesC& aName)
sl@0
   868
//
sl@0
   869
// Check name and path are legal
sl@0
   870
//
sl@0
   871
	{
sl@0
   872
	TParse parser;
sl@0
   873
	TInt r=parser.Set(aName,NULL,NULL);
sl@0
   874
	if (r!=KErrNone)
sl@0
   875
		return(ETrue);	//	Checks for wild cards, names>256 chars etc
sl@0
   876
	
sl@0
   877
	return IsIllegalFullName(parser);
sl@0
   878
	}
sl@0
   879
sl@0
   880
TBool PowerOk()
sl@0
   881
//
sl@0
   882
// Check the power is OK
sl@0
   883
//
sl@0
   884
	{
sl@0
   885
sl@0
   886
	TBool powerGood=EFalse;
sl@0
   887
	TInt r=HAL::Get(HAL::EPowerGood, powerGood);
sl@0
   888
	if (r!=KErrNone)
sl@0
   889
		return EFalse;
sl@0
   890
	return powerGood;
sl@0
   891
	}
sl@0
   892
sl@0
   893
void AddResource(CMountCB& aMount)
sl@0
   894
//
sl@0
   895
// Decrement resource counters
sl@0
   896
//
sl@0
   897
	{
sl@0
   898
	__CHECK_DRIVETHREAD(aMount.Drive().DriveNumber());
sl@0
   899
	__ASSERT_DEBUG(aMount.LockStatus()<=0,Fault(ERawDiskBadAccessCount2));
sl@0
   900
	aMount.DecLock();
sl@0
   901
	}
sl@0
   902
sl@0
   903
void RemoveResource(CMountCB& aMount)
sl@0
   904
//
sl@0
   905
// Increment resource counters
sl@0
   906
//
sl@0
   907
	{
sl@0
   908
	__ASSERT_DEBUG(aMount.LockStatus()<0,Fault(ERawDiskBadAccessCount1));
sl@0
   909
	aMount.IncLock();
sl@0
   910
	}
sl@0
   911
sl@0
   912
sl@0
   913
void AddDiskAccess(CMountCB& aMount)
sl@0
   914
//
sl@0
   915
// Increment resource counters
sl@0
   916
//
sl@0
   917
	{
sl@0
   918
	aMount.IncLock();
sl@0
   919
	}
sl@0
   920
sl@0
   921
void RemoveDiskAccess(CMountCB& aMount)
sl@0
   922
//
sl@0
   923
// Decrement resource counters
sl@0
   924
//
sl@0
   925
	{
sl@0
   926
	aMount.DecLock();
sl@0
   927
	}
sl@0
   928
sl@0
   929
EXPORT_C void AllocBufferL(HBufC*& aBuf,const TDesC& aName)
sl@0
   930
//
sl@0
   931
// Alloc or ReAlloc buffer 
sl@0
   932
//
sl@0
   933
	{
sl@0
   934
sl@0
   935
	if (aBuf==NULL)
sl@0
   936
		{
sl@0
   937
		aBuf=aName.AllocL();
sl@0
   938
		return;
sl@0
   939
		}
sl@0
   940
	if (aBuf->Length()<aName.Length())
sl@0
   941
		{
sl@0
   942
		TInt bufGranularity=(1<<KLog2BufGranularity);
sl@0
   943
		TInt size=((aName.Length()+bufGranularity-1)>>KLog2BufGranularity)<<KLog2BufGranularity;
sl@0
   944
		aBuf=aBuf->ReAllocL(size);
sl@0
   945
		}
sl@0
   946
	aBuf->Des()=aName;
sl@0
   947
	}
sl@0
   948
sl@0
   949
void NextInPath(const TDesC& aPath,TPtrC& anEntry,TInt& aPos)
sl@0
   950
//
sl@0
   951
// Returns the next entry in the path
sl@0
   952
//
sl@0
   953
	{
sl@0
   954
	
sl@0
   955
	anEntry.Set(NULL,0);
sl@0
   956
	if ((aPos+1)>=aPath.Length())
sl@0
   957
		return;
sl@0
   958
	TPtrC path(aPath.Mid(aPos+1)); // Skip delimiter
sl@0
   959
	TInt delimiterPos=path.Locate(KPathDelimiter);
sl@0
   960
	if (delimiterPos==KErrNotFound)
sl@0
   961
		delimiterPos=aPath.Length()-(aPos+1);
sl@0
   962
	if (delimiterPos<=0)
sl@0
   963
		return;
sl@0
   964
sl@0
   965
	if (path[delimiterPos-1]==KExtDelimiter) // return "F32." as "F32"
sl@0
   966
		anEntry.Set(aPath.Mid(aPos+1,delimiterPos-1));
sl@0
   967
	else
sl@0
   968
		anEntry.Set(aPath.Mid(aPos+1,delimiterPos));
sl@0
   969
	aPos+=delimiterPos+1;
sl@0
   970
	}
sl@0
   971
sl@0
   972
TInt MatchUidType(const TUidType &aMatch, const TUidType &aType)
sl@0
   973
//
sl@0
   974
// Compare aType against aMatch with KNullUid as a wildcard
sl@0
   975
//
sl@0
   976
	{
sl@0
   977
sl@0
   978
	TUid mu=aMatch[2];
sl@0
   979
	TUid tu=aType[2];
sl@0
   980
	if (mu!=KNullUid && tu!=KNullUid && mu!=tu)
sl@0
   981
		return KErrNotSupported;
sl@0
   982
	mu=aMatch[1];
sl@0
   983
	tu=aType[1];
sl@0
   984
	if (mu!=KNullUid && tu!=KNullUid && mu!=tu)
sl@0
   985
		return KErrNotSupported;
sl@0
   986
	mu=aMatch[0];
sl@0
   987
	tu=aType[0];
sl@0
   988
	if (mu!=KNullUid && tu!=KNullUid && mu!=tu)
sl@0
   989
		return KErrNotSupported;
sl@0
   990
	return KErrNone;
sl@0
   991
	}
sl@0
   992
sl@0
   993
/**
sl@0
   994
 * Compare sections of filenames according to locale-independent rules as well
sl@0
   995
 * as locale-dependent rules. This is an attempt to get an ordering where
sl@0
   996
 * equivalent names sort together but the overall ordering is culturally
sl@0
   997
 * acceptable. Sadly, the ordering it gives is not consistent, and it is not
sl@0
   998
 * clear how to make it so. Hence this function is deprecated. The correct way
sl@0
   999
 * to do this is to code around it: If you need a sorted array for display that
sl@0
  1000
 * you also need to search for equivalent filenames, either use a linear search
sl@0
  1001
 * or keep two arrays, one sorted with CompareF, the other with CompareC.
sl@0
  1002
 * @deprecated 6.1
sl@0
  1003
 */
sl@0
  1004
EXPORT_C TInt CompareFilenames(const TDesC& aFileName1,const TDesC& aFileName2)
sl@0
  1005
// 
sl@0
  1006
// Compare filenames. Case is ignored and names are normalised
sl@0
  1007
// (base+accent is equal to composed character) but spaces
sl@0
  1008
// and punctuation are significant for determining equality.
sl@0
  1009
// Whether two filenames are identical is the same in all
sl@0
  1010
// locales, but the ordering of non-identical filenames is locale-specific.
sl@0
  1011
//
sl@0
  1012
//
sl@0
  1013
	{
sl@0
  1014
	// Create a non-locale-specific collation method that doesn't ignore spaces and punctuation but folds case.
sl@0
  1015
	TCollationMethod method;
sl@0
  1016
	method.iFlags = TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase;
sl@0
  1017
	method.iMainTable=NULL;	
sl@0
  1018
	method.iOverrideTable=NULL;	
sl@0
  1019
	
sl@0
  1020
	// Get the non-locale-specific order and return it if the names are equal.
sl@0
  1021
	TInt base_order = aFileName1.CompareC(aFileName2,3,&method);
sl@0
  1022
	if (base_order == 0)
sl@0
  1023
		return base_order;
sl@0
  1024
sl@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.
sl@0
  1026
	TInt locale_order = aFileName1.CompareC(aFileName2);
sl@0
  1027
	return locale_order ? locale_order : base_order;
sl@0
  1028
	}
sl@0
  1029
sl@0
  1030
void Get8BitDllName(TDes8& aDllName, const TDesC& aFileName)
sl@0
  1031
//
sl@0
  1032
//	Convert a 16 bit name to an 8 bit name
sl@0
  1033
//	No data loss because UNICODE Dlls are currently restricted to 8 bit names
sl@0
  1034
//	No effect in 8 bit builds - just sets aDllName to aFileName
sl@0
  1035
//
sl@0
  1036
	{
sl@0
  1037
	aDllName.SetLength(aFileName.Length());
sl@0
  1038
	aDllName.Copy(aFileName);
sl@0
  1039
	}								
sl@0
  1040
sl@0
  1041
void Get16BitDllName(TDes& aFileName, const TDesC8& aDllName)
sl@0
  1042
//
sl@0
  1043
//	Convert an 8 bit name to a 16 bit name - zero padded automatically
sl@0
  1044
//	No effect in 8 bit builds - just sets aFileName to aDllName
sl@0
  1045
//
sl@0
  1046
	{
sl@0
  1047
	aFileName.SetLength(aDllName.Length());
sl@0
  1048
	aFileName.Copy(aDllName);	
sl@0
  1049
	}								
sl@0
  1050
sl@0
  1051
sl@0
  1052
/**
sl@0
  1053
    Checks that there is sufficient disk space available to complete a task taking into account reserved space
sl@0
  1054
 
sl@0
  1055
    @param  aThreshold amount of required free space, in bytes
sl@0
  1056
    @param  aRequest
sl@0
  1057
sl@0
  1058
    @return KErrNone        on success and if there are _strictly_more_ than aThreshold bytes available on the volume (taking into account reserved space)
sl@0
  1059
            KErrDiskFull    on success and if there isn't enough space
sl@0
  1060
            system-wide error code otherwise
sl@0
  1061
*/
sl@0
  1062
TInt CheckDiskSpace(TInt64 aThreshold, CFsRequest* aRequest)
sl@0
  1063
	{
sl@0
  1064
    const TInt KReservedSpace = aRequest->Drive()->ReservedSpace();
sl@0
  1065
    const TInt KDriveNumber = aRequest->Drive()->DriveNumber();
sl@0
  1066
sl@0
  1067
	if(KReservedSpace == 0 || KDriveNumber == EDriveZ)
sl@0
  1068
	    return KErrNone;
sl@0
  1069
sl@0
  1070
    //-- if the drive has a reserved space, take it into account
sl@0
  1071
	CSessionFs* session=aRequest->Session(); 
sl@0
  1072
sl@0
  1073
    if(!session || !session->ReservedAccess(KDriveNumber))
sl@0
  1074
        aThreshold += KReservedSpace;
sl@0
  1075
sl@0
  1076
    //-- ask the corresponding file system if there is aThreshold bytes available.
sl@0
  1077
    //-- for some reason it's required to be strictly > than aThreshold
sl@0
  1078
    return aRequest->Drive()->RequestFreeSpaceOnMount(aThreshold+1);
sl@0
  1079
	}								
sl@0
  1080
sl@0
  1081
sl@0
  1082
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
sl@0
  1083
EXPORT_C TUint32 DebugRegister() {return(DebugReg);}
sl@0
  1084
#else
sl@0
  1085
EXPORT_C TUint32 DebugRegister() {return(0);}
sl@0
  1086
#endif
sl@0
  1087
sl@0
  1088
CLogon* CLogon::NewL()
sl@0
  1089
//
sl@0
  1090
// Create the CLogon active object.
sl@0
  1091
//
sl@0
  1092
	{
sl@0
  1093
sl@0
  1094
	CLogon* pL=new(ELeave) CLogon(EPriority);
sl@0
  1095
	CActiveScheduler::Add(pL);
sl@0
  1096
	return(pL);
sl@0
  1097
	}
sl@0
  1098
sl@0
  1099
#pragma warning( disable : 4705 )	// statement has no effect
sl@0
  1100
CLogon::CLogon(TInt aPriority)
sl@0
  1101
//
sl@0
  1102
// Constructor
sl@0
  1103
//
sl@0
  1104
	: CActive(aPriority)
sl@0
  1105
	{
sl@0
  1106
	}
sl@0
  1107
#pragma warning( default : 4705 )
sl@0
  1108
sl@0
  1109
TInt CLogon::Logon(RThread aThread)
sl@0
  1110
//
sl@0
  1111
// Issue a request to logon to the thread.
sl@0
  1112
//
sl@0
  1113
	{
sl@0
  1114
sl@0
  1115
	iThread=aThread;
sl@0
  1116
	iThread.Logon(iStatus);
sl@0
  1117
		SetActive();
sl@0
  1118
	if (iStatus==KErrNoMemory)
sl@0
  1119
		iThread.Kill(KErrNoMemory);
sl@0
  1120
	else
sl@0
  1121
		iThread.Resume();
sl@0
  1122
	iThread.Close();
sl@0
  1123
	CActiveScheduler::Start();
sl@0
  1124
	return(iStatus.Int());
sl@0
  1125
	}
sl@0
  1126
sl@0
  1127
void CLogon::DoCancel()
sl@0
  1128
//
sl@0
  1129
// Cancel a pending event.
sl@0
  1130
//
sl@0
  1131
	{
sl@0
  1132
sl@0
  1133
	iThread.LogonCancel(iStatus);
sl@0
  1134
	}
sl@0
  1135
sl@0
  1136
void CLogon::RunL()
sl@0
  1137
//
sl@0
  1138
// Thread has terminated.
sl@0
  1139
//
sl@0
  1140
	{
sl@0
  1141
sl@0
  1142
	CActiveScheduler::Stop();
sl@0
  1143
	}
sl@0
  1144