os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_nbs.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
//
sl@0
    15
sl@0
    16
#include "sf_std.h"
sl@0
    17
sl@0
    18
TInt TFsMkDir::DoRequestL(CFsRequest* aRequest)
sl@0
    19
//
sl@0
    20
// Make a directory path.
sl@0
    21
//
sl@0
    22
	{
sl@0
    23
	__PRINT(_L("TFsMkDir::DoRequestL(CFsRequest* aRequest)"));
sl@0
    24
sl@0
    25
    TInt r = CheckDiskSpace(0, aRequest);
sl@0
    26
    if(r != KErrNone)
sl@0
    27
        return r;
sl@0
    28
sl@0
    29
	r=aRequest->Drive()->CheckMount();
sl@0
    30
	if (r!=KErrNone)
sl@0
    31
		return(r);
sl@0
    32
	
sl@0
    33
    if (aRequest->Src().IsRoot())
sl@0
    34
		return(KErrAlreadyExists);
sl@0
    35
	
sl@0
    36
    TPtrC ptr;
sl@0
    37
	ptr.Set(aRequest->Src().Path().Ptr(), aRequest->Src().Path().Length()-1);
sl@0
    38
	if (ptr.Length()<=1)
sl@0
    39
		return(KErrBadName);
sl@0
    40
	
sl@0
    41
    if (IsIllegalFullName(aRequest->Src().FullName()))
sl@0
    42
		return(KErrBadName);
sl@0
    43
	
sl@0
    44
    if (aRequest->Message().Int1())
sl@0
    45
		{
sl@0
    46
		TLex lex(ptr);
sl@0
    47
		TFileName filename;
sl@0
    48
		FOREVER
sl@0
    49
			{
sl@0
    50
			lex.Inc(); // Skip a delimiter
sl@0
    51
			TInt res=lex.Remainder().Locate(KPathDelimiter);
sl@0
    52
			if (res==KErrNotFound)
sl@0
    53
				break;
sl@0
    54
	
sl@0
    55
    		lex.Inc(res);
sl@0
    56
			filename+=lex.MarkedToken();	
sl@0
    57
			lex.Mark();
sl@0
    58
			TEntry entry;
sl@0
    59
			if ((r=aRequest->Drive()->Entry(filename,entry))==KErrNone)
sl@0
    60
				{
sl@0
    61
				if (!entry.IsDir())
sl@0
    62
					return(KErrAccessDenied);
sl@0
    63
				continue;
sl@0
    64
				}
sl@0
    65
	
sl@0
    66
    		if (r!=KErrNotFound)
sl@0
    67
				return(r);
sl@0
    68
	
sl@0
    69
    		if ((r=aRequest->Drive()->MkDir(filename))!=KErrNone)
sl@0
    70
				return(r);
sl@0
    71
			}
sl@0
    72
		}
sl@0
    73
	
sl@0
    74
    return(aRequest->Drive()->MkDir(ptr));
sl@0
    75
	}
sl@0
    76
sl@0
    77
TInt TFsMkDir::Initialise(CFsRequest* aRequest)
sl@0
    78
//
sl@0
    79
//
sl@0
    80
//
sl@0
    81
	{
sl@0
    82
	TInt r=ParseSubstPtr0(aRequest,aRequest->Src());
sl@0
    83
	if (r!=KErrNone)
sl@0
    84
		return(r);
sl@0
    85
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysMkDir,&KCapFsPriMkDir,&KCapFsROMkDir, __PLATSEC_DIAGNOSTIC_STRING("Make Directory"));
sl@0
    86
	return(r);
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
TInt TFsRmDir::DoRequestL(CFsRequest* aRequest)
sl@0
    91
//
sl@0
    92
// Remove a directory.
sl@0
    93
//
sl@0
    94
	{
sl@0
    95
	__PRINT(_L("TFsRmDir::DoRequestL(CFsRequest* aRequest)"));
sl@0
    96
	if (aRequest->Src().IsRoot())
sl@0
    97
		return(KErrInUse);
sl@0
    98
	if (IsIllegalFullName(aRequest->Src().FullName()))
sl@0
    99
		return(KErrBadName);
sl@0
   100
	TPtrC ptr;
sl@0
   101
	ptr.Set(aRequest->Src().Path().Ptr(), aRequest->Src().Path().Length()-1);
sl@0
   102
	return(aRequest->Drive()->RmDir(ptr));
sl@0
   103
	}
sl@0
   104
sl@0
   105
TInt TFsRmDir::Initialise(CFsRequest* aRequest)
sl@0
   106
//
sl@0
   107
//
sl@0
   108
//
sl@0
   109
	{
sl@0
   110
	TInt r=ParseSubstPtr0(aRequest,aRequest->Src());
sl@0
   111
	if (r!=KErrNone)
sl@0
   112
		return(r);
sl@0
   113
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysRmDir,&KCapFsPriRmDir,&KCapFsRORmDir, __PLATSEC_DIAGNOSTIC_STRING("Remove Directory"));
sl@0
   114
	return(r);
sl@0
   115
	}
sl@0
   116
sl@0
   117
sl@0
   118
TInt TFsDelete::DoRequestL(CFsRequest* aRequest)
sl@0
   119
//
sl@0
   120
// Delete a file.
sl@0
   121
//
sl@0
   122
	{
sl@0
   123
	__PRINT(_L("TFsDelete::DoRequestL(CFsRequest* aRequest)"));
sl@0
   124
	return(aRequest->Drive()->Delete(aRequest->Src().FullName().Mid(2)));
sl@0
   125
	}
sl@0
   126
sl@0
   127
TInt TFsDelete::Initialise(CFsRequest* aRequest)
sl@0
   128
//
sl@0
   129
//
sl@0
   130
//
sl@0
   131
	{
sl@0
   132
	TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
sl@0
   133
	if (r!=KErrNone)
sl@0
   134
		return(r);
sl@0
   135
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysDelete,&KCapFsPriDelete,&KCapFsRODelete, __PLATSEC_DIAGNOSTIC_STRING("Delete"));
sl@0
   136
	return(r);
sl@0
   137
	}
sl@0
   138
sl@0
   139
sl@0
   140
TInt TFsRename::DoRequestL(CFsRequest* aRequest)
sl@0
   141
//
sl@0
   142
// Rename a file or directory. Wild cards not allowed.
sl@0
   143
//
sl@0
   144
	{
sl@0
   145
	__PRINT(_L("TFsRename::DoRequestL(CFsRequest* aRequest)"));
sl@0
   146
    TInt r = CheckDiskSpace(0, aRequest);
sl@0
   147
    if(r != KErrNone)
sl@0
   148
        return r;
sl@0
   149
	
sl@0
   150
    r = aRequest->Drive()->Rename(aRequest->Src().FullName().Mid(2),aRequest->Dest().FullName().Mid(2));
sl@0
   151
	return (r);
sl@0
   152
	}
sl@0
   153
sl@0
   154
TInt TFsRename::Initialise(CFsRequest* aRequest)
sl@0
   155
//
sl@0
   156
//
sl@0
   157
//
sl@0
   158
	{
sl@0
   159
	TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
sl@0
   160
	if (r!=KErrNone)
sl@0
   161
		return(r);
sl@0
   162
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysRename,&KCapFsPriRename,&KCapFsRORename, __PLATSEC_DIAGNOSTIC_STRING("File Server Rename"));
sl@0
   163
	if(r!=KErrNone)
sl@0
   164
		return(r);
sl@0
   165
	TDrive* pOldDrive=aRequest->Drive();
sl@0
   166
	if ((r=ParseNoWildSubstCheckPathPtr1(aRequest,aRequest->Dest()))!=KErrNone)
sl@0
   167
		return(r);
sl@0
   168
	r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysRename,&KCapFsPriRename,&KCapFsRORename, __PLATSEC_DIAGNOSTIC_STRING("File Server Rename"));	
sl@0
   169
	if(r == KErrNone)
sl@0
   170
		{
sl@0
   171
		if (pOldDrive!=aRequest->Drive())
sl@0
   172
			r=KErrArgument;
sl@0
   173
		}
sl@0
   174
	return(r);
sl@0
   175
	}
sl@0
   176
sl@0
   177
sl@0
   178
TInt TFsReplace::DoRequestL(CFsRequest* aRequest)
sl@0
   179
//
sl@0
   180
// Replace an old file with a new file atomically
sl@0
   181
//
sl@0
   182
	{
sl@0
   183
	__PRINT(_L("TFsReplace::DoRequestL(CFsRequest* aRequest)"));
sl@0
   184
sl@0
   185
    TInt r = CheckDiskSpace(0, aRequest);
sl@0
   186
    if(r != KErrNone)
sl@0
   187
        return r;
sl@0
   188
sl@0
   189
	return(aRequest->Drive()->Replace(aRequest->Src().FullName().Mid(2),aRequest->Dest().FullName().Mid(2)));
sl@0
   190
	}
sl@0
   191
sl@0
   192
TInt TFsReplace::Initialise(CFsRequest* aRequest)
sl@0
   193
//
sl@0
   194
//
sl@0
   195
//
sl@0
   196
	{
sl@0
   197
	TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
sl@0
   198
	if (r!=KErrNone)
sl@0
   199
		return(r);
sl@0
   200
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysReplace,&KCapFsPriReplace,&KCapFsROReplace, __PLATSEC_DIAGNOSTIC_STRING("File Server Replace"));	
sl@0
   201
	if(r!=KErrNone)
sl@0
   202
		return(r);
sl@0
   203
	TDrive* pOldDrive=aRequest->Drive();
sl@0
   204
	if ((r=ParseNoWildSubstCheckPtr1(aRequest,aRequest->Dest()))!=KErrNone)
sl@0
   205
		return(r);
sl@0
   206
	r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysReplace,&KCapFsPriReplace,&KCapFsROReplace, __PLATSEC_DIAGNOSTIC_STRING("File Server Replace"));	
sl@0
   207
	if(r == KErrNone)
sl@0
   208
		{
sl@0
   209
		if (pOldDrive!=aRequest->Drive())
sl@0
   210
			r=KErrArgument;
sl@0
   211
		}
sl@0
   212
	return(r);
sl@0
   213
	}
sl@0
   214
sl@0
   215
sl@0
   216
TInt TFsEntry::DoRequestL(CFsRequest* aRequest)
sl@0
   217
//
sl@0
   218
// Get all the entry details.
sl@0
   219
//
sl@0
   220
	{
sl@0
   221
	__PRINT(_L("TInt TFsEntry::DoRequestL(CFsRequest* aRequest)"));
sl@0
   222
sl@0
   223
	TEntry t; 
sl@0
   224
	TPtrC filePath = aRequest->Src().FullName().Mid(2);
sl@0
   225
	TInt r=aRequest->Drive()->Entry(filePath,t);
sl@0
   226
	if (r!=KErrNone)
sl@0
   227
		return(r);
sl@0
   228
sl@0
   229
	// If the file is open, get the file size from the CFileCB object as there may be cached data
sl@0
   230
	CFileCB* file;
sl@0
   231
	aRequest->Drive()->IsFileOpen(filePath, file);
sl@0
   232
	if (file)
sl@0
   233
		t.SetFileSize(file->CachedSize64());
sl@0
   234
sl@0
   235
	TPckgC<TEntry> p(t);
sl@0
   236
	aRequest->WriteL(KMsgPtr1,p);
sl@0
   237
	return(KErrNone);
sl@0
   238
	}
sl@0
   239
sl@0
   240
TInt TFsEntry::Initialise(CFsRequest* aRequest)
sl@0
   241
//
sl@0
   242
//
sl@0
   243
//
sl@0
   244
	{
sl@0
   245
	TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
sl@0
   246
	if (r!=KErrNone)
sl@0
   247
		return(r);
sl@0
   248
sl@0
   249
	// Check the capabilites but always allow the entry to be read for private, system and 
sl@0
   250
	// resource directories as long as there are no sub folders or files specified
sl@0
   251
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsEntry, __PLATSEC_DIAGNOSTIC_STRING("Entry"), ETrue);	
sl@0
   252
sl@0
   253
	return(r);
sl@0
   254
	}
sl@0
   255
sl@0
   256
sl@0
   257
TInt TFsSetEntry::DoRequestL(CFsRequest* aRequest)
sl@0
   258
//
sl@0
   259
// Set the attributes and the modified date and time.
sl@0
   260
//
sl@0
   261
	{
sl@0
   262
	__PRINT(_L("TFsSetEntry::DoRequestL(CFsRequest* aRequest)"));
sl@0
   263
sl@0
   264
    TInt r = CheckDiskSpace(0, aRequest);
sl@0
   265
    if(r != KErrNone)
sl@0
   266
        return r;
sl@0
   267
sl@0
   268
	TTime entryTime;
sl@0
   269
	TPckgBuf<TTime> timeBuf;
sl@0
   270
	aRequest->ReadL(KMsgPtr1,timeBuf);
sl@0
   271
	entryTime=timeBuf();
sl@0
   272
	const RMessage2& msg = aRequest->Message();
sl@0
   273
sl@0
   274
	return(aRequest->Drive()->SetEntry(aRequest->Src().FullName().Mid(2),entryTime,msg.Int2(),msg.Int3()));
sl@0
   275
	}
sl@0
   276
sl@0
   277
sl@0
   278
TInt TFsSetEntry::Initialise(CFsRequest* aRequest)
sl@0
   279
//
sl@0
   280
//
sl@0
   281
//
sl@0
   282
	{
sl@0
   283
	TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());
sl@0
   284
	if (r!=KErrNone)
sl@0
   285
		return(r);
sl@0
   286
 	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysSetEntry,&KCapFsPriSetEntry,&KCapFsROSetEntry, __PLATSEC_DIAGNOSTIC_STRING("Set Entry"));	
sl@0
   287
	return(r);
sl@0
   288
	}
sl@0
   289
sl@0
   290
LOCAL_C void FsReadFileSectionFileClose(CFsRequest* aRequest, CFileShare* aShare)
sl@0
   291
	{
sl@0
   292
	aRequest->Session()->DecResourceCount();
sl@0
   293
	TInt handle = aRequest->Session()->Handles().At(aShare, EFalse);
sl@0
   294
	aRequest->Session()->Handles().Remove(handle,ETrue);
sl@0
   295
	// close the file share
sl@0
   296
	aRequest->SetScratchValue64(0);
sl@0
   297
	}
sl@0
   298
sl@0
   299
LOCAL_C CFileShare* FsReadFileSectionFileOpen(CFsRequest* aRequest)
sl@0
   300
	{
sl@0
   301
	TInt handle;
sl@0
   302
	TUint32 mode = EFileShareReadersOrWriters | EFileRead | EFileReadAheadOff;
sl@0
   303
sl@0
   304
	TInt r = aRequest->Drive()->FileOpen(aRequest,handle,aRequest->Src().FullName().Mid(2),mode,EFileOpen);
sl@0
   305
	if (r!=KErrNone)
sl@0
   306
		return(NULL);
sl@0
   307
sl@0
   308
	CFileShare* share = (CFileShare*) SessionObjectFromHandle(handle, FileShares->UniqueID(), aRequest->Session());
sl@0
   309
	
sl@0
   310
	aRequest->Session()->IncResourceCount();
sl@0
   311
sl@0
   312
	CFileCB& file = share->File();
sl@0
   313
	if (!file.FileCache())
sl@0
   314
		{
sl@0
   315
		FsReadFileSectionFileClose(aRequest, share);
sl@0
   316
		share = NULL;
sl@0
   317
		}
sl@0
   318
	return share;
sl@0
   319
	}
sl@0
   320
sl@0
   321
TInt TFsReadFileSection::Complete(CFsRequest* aRequest)
sl@0
   322
	{
sl@0
   323
	FsReadFileSectionFileClose(aRequest, (CFileShare*) aRequest->ScratchValue());
sl@0
   324
sl@0
   325
	return CFsRequest::EReqActionComplete;
sl@0
   326
	}
sl@0
   327
sl@0
   328
TInt TFsReadFileSection::DoRequestL(CFsRequest* aRequest)
sl@0
   329
//
sl@0
   330
//	Read from a file regardless of lock state
sl@0
   331
//
sl@0
   332
	{
sl@0
   333
	__PRINT(_L("TFsReadFileSection::DoRequestL(CFsRequest* aRequest)"));
sl@0
   334
	
sl@0
   335
	TAny* pDes=(TAny*)(aRequest->Message().Ptr0());
sl@0
   336
	TInt64 pos;
sl@0
   337
	if(aRequest->IsDescData(KMsgPtr2))
sl@0
   338
		{
sl@0
   339
		TPckg<TInt64> pkPos(pos);
sl@0
   340
		aRequest->ReadL(KMsgPtr2, pkPos);
sl@0
   341
		}
sl@0
   342
	else
sl@0
   343
		{
sl@0
   344
		pos = MAKE_TINT64(0,aRequest->Message().Int2());
sl@0
   345
		}
sl@0
   346
	TInt len=aRequest->Message().Int3();
sl@0
   347
sl@0
   348
	// Try to open file so we can take advantage of file caching
sl@0
   349
	CFileShare* share = FsReadFileSectionFileOpen(aRequest);
sl@0
   350
	if (share)
sl@0
   351
		{
sl@0
   352
		CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
sl@0
   353
		__ASSERT_DEBUG(msgRequest.CurrentOperationPtr() == NULL, Fault(EBadOperationIndex));
sl@0
   354
		CFileCB& file = share->File();
sl@0
   355
		TInt64 size = file.Size64();
sl@0
   356
		TInt r = KErrNone;
sl@0
   357
		if (pos > size)
sl@0
   358
			pos = size;
sl@0
   359
		if (pos + len > size)
sl@0
   360
		// filesize - pos shall of TInt size
sl@0
   361
		// Hence to suppress warning
sl@0
   362
			len = (TInt)(size - pos);
sl@0
   363
		if (len <= 0)
sl@0
   364
			r = KErrArgument;
sl@0
   365
		if (r == KErrNone)
sl@0
   366
			r = msgRequest.PushOperation(pos, len, (TDesC8*) pDes, 0, TFsReadFileSection::Complete, 0, EFsFileRead);
sl@0
   367
		msgRequest.SetState(CFsRequest::EReqStatePostInitialise);	// DO call PostInitialise()
sl@0
   368
		if (r == KErrNone)
sl@0
   369
			{
sl@0
   370
			aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) );
sl@0
   371
			return CFsRequest::EReqActionBusy; // dispatch the request again
sl@0
   372
			}
sl@0
   373
		FsReadFileSectionFileClose(aRequest, share);
sl@0
   374
		}
sl@0
   375
sl@0
   376
	TInt r = KErrNone;
sl@0
   377
	if (len < 0)
sl@0
   378
		r = KErrArgument;
sl@0
   379
	else if (len > 0)
sl@0
   380
		r = aRequest->Drive()->ReadFileSection64(aRequest->Src().FullName().Mid(2),pos,pDes,len,aRequest->Message());
sl@0
   381
sl@0
   382
	// zero return buffer, but only if we haven't written any data to it already, otherwise kernel's
sl@0
   383
	// writeback of descriptor length will conflict with that wrttien by media driver
sl@0
   384
	if (r != KErrNone || len == 0)
sl@0
   385
		aRequest->WriteL(KMsgPtr0,KNullDesC8);
sl@0
   386
	
sl@0
   387
	return r == KErrEof ? KErrNone : r;  
sl@0
   388
	}
sl@0
   389
sl@0
   390
sl@0
   391
TInt TFsReadFileSection::Initialise(CFsRequest* aRequest)
sl@0
   392
//
sl@0
   393
//
sl@0
   394
//
sl@0
   395
	{
sl@0
   396
	TInt r=ParseNoWildSubstFileCheckPtr1(aRequest,aRequest->Src());
sl@0
   397
	if (r!=KErrNone)
sl@0
   398
		return(r);
sl@0
   399
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysReadFileSection,&KCapFsPriReadFileSection, __PLATSEC_DIAGNOSTIC_STRING("Read File Section"));	
sl@0
   400
	return(r);
sl@0
   401
	}
sl@0
   402
sl@0
   403
sl@0
   404
sl@0
   405
TInt TFsCheckDisk::DoRequestL(CFsRequest* aRequest)
sl@0
   406
//
sl@0
   407
// Check the disk's integrity
sl@0
   408
//
sl@0
   409
	{
sl@0
   410
sl@0
   411
	__PRINT(_L("TFsCheckDisk::DoRequestL(CFsRequest* aRequest)"));
sl@0
   412
sl@0
   413
	// flush all files on this drive
sl@0
   414
	TInt r = aRequest->Drive()->FlushCachedFileInfo();
sl@0
   415
	if (r == CFsRequest::EReqActionBusy)	// ignore any flush errors
sl@0
   416
		return(r);
sl@0
   417
sl@0
   418
	return(aRequest->Drive()->CheckDisk());
sl@0
   419
	}
sl@0
   420
sl@0
   421
sl@0
   422
TInt TFsCheckDisk::Initialise(CFsRequest* aRequest)
sl@0
   423
//
sl@0
   424
//
sl@0
   425
//
sl@0
   426
	{
sl@0
   427
	if (!KCapFsCheckDisk.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("CheckDisk")))						
sl@0
   428
		return KErrPermissionDenied;
sl@0
   429
	return ParseSubstPtr0(aRequest,aRequest->Src());	//may make the rfs function call take a drive instead of path
sl@0
   430
	}
sl@0
   431
sl@0
   432
TInt TFsScanDrive::DoRequestL(CFsRequest* aRequest)
sl@0
   433
//
sl@0
   434
//
sl@0
   435
//
sl@0
   436
	{
sl@0
   437
	__PRINT(_L("TFsScanDrive::DoRequestL(CFsRequest* aRequest)"));
sl@0
   438
sl@0
   439
	// flush all files on this drive
sl@0
   440
	TInt r = aRequest->Drive()->FlushCachedFileInfo();
sl@0
   441
	if (r == CFsRequest::EReqActionBusy)	// ignore any flush errors
sl@0
   442
		return(r);
sl@0
   443
sl@0
   444
	r=aRequest->Drive()->CheckMount();
sl@0
   445
	if(r!=KErrNone)
sl@0
   446
		return(r);
sl@0
   447
	if (aRequest->Drive()->CurrentMount().LockStatus()<0)
sl@0
   448
		return(KErrInUse);
sl@0
   449
	r=aRequest->Drive()->ScanDrive();
sl@0
   450
	// notify sessions since drive contents may have changed
sl@0
   451
	if(r==KErrNone)
sl@0
   452
		FsNotify::DiskChange(aRequest->DriveNumber());
sl@0
   453
	return(r);
sl@0
   454
	}
sl@0
   455
sl@0
   456
TInt TFsScanDrive::Initialise(CFsRequest* aRequest)
sl@0
   457
//
sl@0
   458
//
sl@0
   459
//
sl@0
   460
	{
sl@0
   461
	TInt r;
sl@0
   462
	if(!KCapFsScanDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("ScanDrive")))	
sl@0
   463
		return KErrPermissionDenied;
sl@0
   464
	r=ParseSubstPtr0(aRequest,aRequest->Src());		//may make the rfs function call take a drive instead of path
sl@0
   465
	return(r);										//then  no need for parse, just needs to check for susted and reject them
sl@0
   466
	}
sl@0
   467
sl@0
   468
TInt TFsGetShortName::DoRequestL(CFsRequest* aRequest)
sl@0
   469
//
sl@0
   470
// Get the short name associated with a long file name
sl@0
   471
//
sl@0
   472
	{
sl@0
   473
	__PRINT(_L("TFsGetShortName::DoRequestL(CFsRequest* aRequest)"));
sl@0
   474
	TBuf<0x10> shortName;
sl@0
   475
	TInt r=aRequest->Drive()->GetShortName(aRequest->Src().FullName().Mid(2),shortName);
sl@0
   476
	if (r!=KErrNone)
sl@0
   477
		return(r);
sl@0
   478
	aRequest->WriteL(KMsgPtr1,shortName);
sl@0
   479
	return(KErrNone);
sl@0
   480
	}
sl@0
   481
sl@0
   482
TInt TFsGetShortName::Initialise(CFsRequest* aRequest)
sl@0
   483
//
sl@0
   484
//
sl@0
   485
//
sl@0
   486
	{
sl@0
   487
	TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());	
sl@0
   488
	if (r!=KErrNone)
sl@0
   489
		return(r);
sl@0
   490
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysGetShortName,&KCapFsPriGetShortName, __PLATSEC_DIAGNOSTIC_STRING("Get Short Name"));	
sl@0
   491
	return(r);
sl@0
   492
	}
sl@0
   493
sl@0
   494
sl@0
   495
TInt TFsGetLongName::DoRequestL(CFsRequest* aRequest)
sl@0
   496
//
sl@0
   497
// Get the long name associated with a short file name
sl@0
   498
//
sl@0
   499
	{
sl@0
   500
	__PRINT(_L("TFsGetLongName::DoRequestL(CFsRequest* aRequest)"));
sl@0
   501
	TFileName longName;
sl@0
   502
	TInt r=aRequest->Drive()->GetLongName(aRequest->Src().FullName().Mid(2),longName);
sl@0
   503
	if (r!=KErrNone)
sl@0
   504
		return(r);
sl@0
   505
	aRequest->WriteL(KMsgPtr1,longName);
sl@0
   506
	return(KErrNone);
sl@0
   507
	}
sl@0
   508
sl@0
   509
TInt TFsGetLongName::Initialise(CFsRequest* aRequest)
sl@0
   510
//
sl@0
   511
//
sl@0
   512
//
sl@0
   513
	{
sl@0
   514
	TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());	
sl@0
   515
	if (r!=KErrNone)
sl@0
   516
		return(r);
sl@0
   517
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysGetLongName,&KCapFsPriGetLongName, __PLATSEC_DIAGNOSTIC_STRING("Get Long Name"));	
sl@0
   518
	return(r);
sl@0
   519
	}
sl@0
   520
sl@0
   521
sl@0
   522
TInt TFsIsFileInRom::DoRequestL(CFsRequest* aRequest)
sl@0
   523
//
sl@0
   524
// Return the address of the file
sl@0
   525
//
sl@0
   526
	{
sl@0
   527
sl@0
   528
	__PRINT(_L("DoIsFileInRom"));
sl@0
   529
	TUint8* fileStart;
sl@0
   530
	TInt r=aRequest->Drive()->IsFileInRom(aRequest->Src().FullName().Mid(2),fileStart);
sl@0
   531
	if (r!=KErrNone)
sl@0
   532
		return(r);
sl@0
   533
	TPckgBuf<TUint8*> buf(fileStart);
sl@0
   534
	aRequest->WriteL(KMsgPtr1,buf);
sl@0
   535
	return(KErrNone);
sl@0
   536
	}
sl@0
   537
sl@0
   538
TInt TFsIsFileInRom::Initialise(CFsRequest* aRequest)
sl@0
   539
//
sl@0
   540
//	
sl@0
   541
//
sl@0
   542
	{	
sl@0
   543
	TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src());	
sl@0
   544
	if (r!=KErrNone)
sl@0
   545
		return (r);
sl@0
   546
	r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysIsFileInRom,&KCapFsPriIsFileInRom, __PLATSEC_DIAGNOSTIC_STRING("Is File In Rom"));	
sl@0
   547
	return(r);
sl@0
   548
	}
sl@0
   549
sl@0
   550
sl@0
   551
TInt TFsIsValidName::Initialise(CFsRequest* /*aRequest*/)
sl@0
   552
//
sl@0
   553
//	
sl@0
   554
//
sl@0
   555
	{
sl@0
   556
	return(KErrNone);
sl@0
   557
	}
sl@0
   558
sl@0
   559
sl@0
   560
TInt TFsIsValidName::DoRequestL(CFsRequest* aRequest)
sl@0
   561
//
sl@0
   562
//	Determine whether the name is valid
sl@0
   563
//	If returnInvalidChar flag is set - determine the invalid character and
sl@0
   564
//	return it to the client
sl@0
   565
//  If TNameValidParam is specified determine the position of the invalid character
sl@0
   566
//  and return it to the client.
sl@0
   567
	{
sl@0
   568
	__PRINT(_L("DoFsIsValidName"));
sl@0
   569
sl@0
   570
	TParse parse; 
sl@0
   571
	const TAny* pParam = aRequest->Message().Ptr3();
sl@0
   572
	if(pParam == NULL)
sl@0
   573
		{
sl@0
   574
		//	We need to call DoFsIsValidName	to determine what the invalid character is
sl@0
   575
		TInt r=ParseSubstPtr0(aRequest,parse);
sl@0
   576
		if ((r!=KErrNone) && (r!=KErrBadName))
sl@0
   577
			return(r);
sl@0
   578
		TBool retInvChar;
sl@0
   579
		TPckg<TBool> bPckg(retInvChar);
sl@0
   580
		aRequest->ReadL(KMsgPtr1,bPckg);
sl@0
   581
		if (!retInvChar)
sl@0
   582
			//	Determine whether the name is invalid but don't bother finding out which
sl@0
   583
			//	character (if any) is illegal
sl@0
   584
			{  
sl@0
   585
			TInt r=ParseNoWildSubstCheckPtr0(aRequest,parse);	
sl@0
   586
			if ((r!=KErrNone) || IsIllegalFullName(parse.FullName().Mid(2)))
sl@0
   587
				return(KErrBadName);
sl@0
   588
			return(KErrNone);
sl@0
   589
			}
sl@0
   590
		else	
sl@0
   591
			{
sl@0
   592
			//	Determine whether the name is invalid and return any offending character 	
sl@0
   593
			TText badChar=' ';
sl@0
   594
			TPckg<TText> pText(badChar);
sl@0
   595
				
sl@0
   596
			TInt r=ParseSubstPtr0(aRequest,parse);
sl@0
   597
			if (r==KErrBadName)	//	Name is > 256 characters or an illegal character 
sl@0
   598
				{				//	was encountered before path was completely parsed
sl@0
   599
				TFileName name;
sl@0
   600
				aRequest->ReadL(KMsgPtr0,name);
sl@0
   601
				TNameChecker checkName(name);
sl@0
   602
				checkName.IsIllegalChar(badChar);								
sl@0
   603
				aRequest->WriteL(KMsgPtr2,pText);
sl@0
   604
				return(KErrBadName);
sl@0
   605
				}
sl@0
   606
			//	Weed out invalid * or ? in the filename (or no name and extension at all)
sl@0
   607
			r=ParseNoWildSubstCheckPtr0(aRequest,parse);	
sl@0
   608
			if (r==KErrBadName)
sl@0
   609
				{
sl@0
   610
				if (parse.IsKMatchAny())
sl@0
   611
					badChar=KMatchAny;		//	Offending character is '*'
sl@0
   612
				else if (parse.IsKMatchOne())
sl@0
   613
					badChar=KMatchOne;		//	Offending character is '?'
sl@0
   614
				aRequest->WriteL(KMsgPtr2,pText);
sl@0
   615
				return(KErrBadName);
sl@0
   616
				}
sl@0
   617
sl@0
   618
			//	Weed out any other outstanding illegal characters in filename or path	
sl@0
   619
			TNameChecker checkName(parse.FullName().Mid(2));
sl@0
   620
			if (checkName.IsIllegalName(badChar))
sl@0
   621
				{
sl@0
   622
				aRequest->WriteL(KMsgPtr2,pText);
sl@0
   623
				return(KErrBadName);
sl@0
   624
				}
sl@0
   625
			else					//	No invalid characters in name
sl@0
   626
				{					//	Set badChar to '\0'		
sl@0
   627
				badChar='\0';		
sl@0
   628
				aRequest->WriteL(KMsgPtr2,pText);
sl@0
   629
				return(KErrNone);	
sl@0
   630
				}
sl@0
   631
			}
sl@0
   632
		}
sl@0
   633
	else //new API implementation
sl@0
   634
		{
sl@0
   635
		RFs::TNameValidParam param;
sl@0
   636
		TPckg<RFs::TNameValidParam> paramPckg(param);
sl@0
   637
		aRequest->ReadL(KMsgPtr3,paramPckg);
sl@0
   638
		TUint nameLen=(TUint)aRequest->GetDesLength(KMsgPtr0);
sl@0
   639
		if(nameLen == 0)// a name must be specified
sl@0
   640
			{
sl@0
   641
			param.iError = RFs::TNameValidParam::ErrBadName;
sl@0
   642
			param.iInvalidCharPos = 0;
sl@0
   643
			aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   644
			return KErrBadName;
sl@0
   645
			}
sl@0
   646
		if(param.iUseSessionPath)
sl@0
   647
			nameLen += aRequest->Session()->Path().Length();
sl@0
   648
		if(nameLen > (TUint)KMaxFileName)
sl@0
   649
			{
sl@0
   650
			param.iError = RFs::TNameValidParam::ErrNameTooLong;
sl@0
   651
			param.iInvalidCharPos = 0;
sl@0
   652
			aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   653
		   	return KErrBadName;
sl@0
   654
			}
sl@0
   655
		TFileName fileName;
sl@0
   656
		TInt driveLength = 2;
sl@0
   657
		TText badChar;
sl@0
   658
		TRAPD(r, aRequest->ReadL(KMsgPtr0,fileName));
sl@0
   659
		if(KErrNone == r)
sl@0
   660
			{
sl@0
   661
			r=ParseSubstPtr0(aRequest,parse,param.iUseSessionPath);
sl@0
   662
			if (KErrBadName  == r) 	//	An illegal character 
sl@0
   663
				{					//	was encountered before path was completely parsed
sl@0
   664
				TNameChecker checkName(fileName);
sl@0
   665
				if(checkName.IsIllegalChar(badChar))
sl@0
   666
					{
sl@0
   667
					param.iError = RFs::TNameValidParam::ErrBadCharacter;
sl@0
   668
					param.iInvalidCharPos = fileName.LocateReverse(badChar)+1;
sl@0
   669
					aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   670
					return KErrBadName;
sl@0
   671
					}
sl@0
   672
				param.iError = RFs::TNameValidParam::ErrBadName;
sl@0
   673
				param.iInvalidCharPos = 0;
sl@0
   674
				aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   675
				return KErrBadName;
sl@0
   676
				}
sl@0
   677
			//	Weed out invalid * or ? in the filename
sl@0
   678
			r=ParseNoWildSubstPtr0(aRequest,parse,param.iUseSessionPath);
sl@0
   679
			if(KErrBadName == r)
sl@0
   680
				{
sl@0
   681
				if(parse.IsWild())	
sl@0
   682
					{
sl@0
   683
					if (parse.IsKMatchAny())
sl@0
   684
						{// offending character is '*'
sl@0
   685
						param.iError = RFs::TNameValidParam::ErrBadCharacter;
sl@0
   686
						param.iInvalidCharPos = fileName.LocateReverse(KMatchAny)+1;
sl@0
   687
						aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   688
						return KErrBadName;
sl@0
   689
						}
sl@0
   690
					else if (parse.IsKMatchOne())
sl@0
   691
						{//offending character is '?'
sl@0
   692
						param.iError = RFs::TNameValidParam::ErrBadCharacter;
sl@0
   693
						param.iInvalidCharPos = fileName.LocateReverse(KMatchOne)+1;
sl@0
   694
						aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   695
			    		return KErrBadName;
sl@0
   696
						}
sl@0
   697
					}
sl@0
   698
				param.iError = RFs::TNameValidParam::ErrBadName;
sl@0
   699
				param.iInvalidCharPos = 0;
sl@0
   700
				aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   701
				return KErrBadName;
sl@0
   702
				}
sl@0
   703
			if(!param.iUseSessionPath && !parse.DrivePresent())
sl@0
   704
				driveLength = 0;
sl@0
   705
			//	Weed out any other outstanding illegal characters in filename or path
sl@0
   706
			TNameChecker checkName(parse.FullName().Mid(driveLength));
sl@0
   707
			badChar = ' ';	
sl@0
   708
			if (checkName.IsIllegalName(badChar))
sl@0
   709
				{
sl@0
   710
				if(badChar == ' ')
sl@0
   711
					{
sl@0
   712
					param.iError = RFs::TNameValidParam::ErrBadName;
sl@0
   713
					param.iInvalidCharPos = 0;
sl@0
   714
					aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   715
					return KErrBadName;
sl@0
   716
					}
sl@0
   717
				else
sl@0
   718
					{
sl@0
   719
					if(badChar == '.')
sl@0
   720
						{
sl@0
   721
						param.iError = RFs::TNameValidParam::ErrBadCharacter;
sl@0
   722
						param.iInvalidCharPos = fileName.Locate(badChar)+1;
sl@0
   723
						}
sl@0
   724
					else
sl@0
   725
						{
sl@0
   726
						param.iError = RFs::TNameValidParam::ErrBadCharacter;
sl@0
   727
						param.iInvalidCharPos = fileName.LocateReverse(badChar)+1;
sl@0
   728
						}
sl@0
   729
					aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   730
					return KErrBadName;
sl@0
   731
					}
sl@0
   732
				}
sl@0
   733
			else					//	No invalid characters in name
sl@0
   734
				{
sl@0
   735
				param.iError = RFs::TNameValidParam::ErrNone;
sl@0
   736
				param.iInvalidCharPos = 0;
sl@0
   737
				aRequest->WriteL(KMsgPtr3,paramPckg);
sl@0
   738
				return KErrNone;		
sl@0
   739
				}
sl@0
   740
			}
sl@0
   741
		else
sl@0
   742
			return r;//read is not successful.
sl@0
   743
		}
sl@0
   744
	}
sl@0
   745
				
sl@0
   746
	
sl@0
   747
TInt TFsLockDrive::DoRequestL(CFsRequest* aRequest)
sl@0
   748
//
sl@0
   749
// Lock media device
sl@0
   750
//
sl@0
   751
	{
sl@0
   752
	__PRINT(_L("TFsLockDrive::DoRequestL(CFsRequest* aRequest)"));	
sl@0
   753
	TMediaPassword oldPw;
sl@0
   754
	TMediaPassword newPw;
sl@0
   755
	aRequest->ReadL(KMsgPtr1,oldPw);
sl@0
   756
	aRequest->ReadL(KMsgPtr2,newPw);
sl@0
   757
	return(aRequest->Drive()->LockDevice(oldPw,newPw,aRequest->Message().Int3()));
sl@0
   758
	}
sl@0
   759
sl@0
   760
sl@0
   761
TInt TFsLockDrive::Initialise(CFsRequest* aRequest)
sl@0
   762
//
sl@0
   763
// 
sl@0
   764
//
sl@0
   765
	{
sl@0
   766
	if (!KCapFsLockDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Lock Drive")))
sl@0
   767
		return KErrPermissionDenied;
sl@0
   768
	TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
sl@0
   769
	return(r);
sl@0
   770
	}
sl@0
   771
sl@0
   772
TInt TFsUnlockDrive::DoRequestL(CFsRequest* aRequest)
sl@0
   773
//
sl@0
   774
// Unlock media device
sl@0
   775
//
sl@0
   776
	{
sl@0
   777
	__PRINT(_L("TFsUnlockDrive::DoRequestL(CFsRequest* aRequest)"));
sl@0
   778
	TMediaPassword pW;
sl@0
   779
	aRequest->ReadL(KMsgPtr1,pW);
sl@0
   780
	return(aRequest->Drive()->UnlockDevice(pW,aRequest->Message().Int2()));
sl@0
   781
	}
sl@0
   782
sl@0
   783
sl@0
   784
TInt TFsUnlockDrive::Initialise(CFsRequest* aRequest)
sl@0
   785
//
sl@0
   786
// 
sl@0
   787
//
sl@0
   788
	{
sl@0
   789
	if (!KCapFsUnlockDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Unlock Drive")))
sl@0
   790
		return KErrPermissionDenied;
sl@0
   791
	TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
sl@0
   792
	return(r);
sl@0
   793
	}
sl@0
   794
sl@0
   795
TInt TFsClearPassword::DoRequestL(CFsRequest* aRequest)
sl@0
   796
//
sl@0
   797
// Clears password of media device
sl@0
   798
//
sl@0
   799
	{
sl@0
   800
	__PRINT(_L("TFsClearPassowrd::DoRequestL(CFsRequest* aRequest)"));	
sl@0
   801
	TMediaPassword pW;
sl@0
   802
	aRequest->ReadL(KMsgPtr1,pW);
sl@0
   803
	return(aRequest->Drive()->ClearDevicePassword(pW));
sl@0
   804
	}
sl@0
   805
sl@0
   806
sl@0
   807
TInt TFsClearPassword::Initialise(CFsRequest* aRequest)
sl@0
   808
//
sl@0
   809
//
sl@0
   810
//
sl@0
   811
	{
sl@0
   812
	if (!KCapFsClearPassword.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Clear Password")))
sl@0
   813
		return KErrPermissionDenied;
sl@0
   814
	return ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
sl@0
   815
	}
sl@0
   816
sl@0
   817
TInt TFsErasePassword::DoRequestL(CFsRequest* aRequest)
sl@0
   818
//
sl@0
   819
// Erase the password from the media device
sl@0
   820
//
sl@0
   821
	{
sl@0
   822
	__PRINT(_L("TFsErasePassword::DoRequestL(CFsRequest* aRequest)"));
sl@0
   823
	return(aRequest->Drive()->EraseDevicePassword());
sl@0
   824
	}
sl@0
   825
sl@0
   826
sl@0
   827
TInt TFsErasePassword::Initialise(CFsRequest* aRequest)
sl@0
   828
//
sl@0
   829
// 
sl@0
   830
//
sl@0
   831
	{
sl@0
   832
	if (!KCapFsErasePassword.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Erase Password")))
sl@0
   833
		return KErrPermissionDenied;
sl@0
   834
	return ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
sl@0
   835
sl@0
   836
	}
sl@0
   837
sl@0
   838
sl@0
   839
TInt TFsSessionToPrivate::DoRequestL(CFsRequest* aRequest)
sl@0
   840
//
sl@0
   841
//	Set session path to the private directory (does not need to exist)
sl@0
   842
//
sl@0
   843
	{
sl@0
   844
	TBuf<30> pPath;	
sl@0
   845
	pPath=_L("?:\\Private\\");	
sl@0
   846
	pPath[0]= (TText)('A'+ aRequest->Message().Int0());
sl@0
   847
	pPath.AppendNumFixedWidth(aRequest->Message().SecureId().iId, EHex, 8);
sl@0
   848
	pPath += KSlash;
sl@0
   849
	HBufC* pP = pPath.Alloc();
sl@0
   850
	if (pP==NULL)
sl@0
   851
		return KErrNoMemory;
sl@0
   852
	delete &aRequest->Session()->Path();
sl@0
   853
	aRequest->Session()->SetPath(pP);
sl@0
   854
	return KErrNone;
sl@0
   855
	}
sl@0
   856
sl@0
   857
	
sl@0
   858
TInt TFsSessionToPrivate::Initialise(CFsRequest* /*aRequest*/) 
sl@0
   859
//
sl@0
   860
//	standard initialisation
sl@0
   861
//
sl@0
   862
	{
sl@0
   863
	return KErrNone;
sl@0
   864
	}
sl@0
   865
sl@0
   866
TInt TFsPrivatePath::DoRequestL(CFsRequest* aRequest)
sl@0
   867
//
sl@0
   868
//	may be able to do this user side !!!
sl@0
   869
//
sl@0
   870
	{
sl@0
   871
	TSecureId appUID = aRequest->Message().SecureId();	
sl@0
   872
	TFileName pPath(KPrivateSlash);	
sl@0
   873
	pPath.AppendNumFixedWidth(appUID.iId, EHex, 8);
sl@0
   874
	pPath += KSlash;
sl@0
   875
	aRequest->WriteL(KMsgPtr0,pPath);
sl@0
   876
sl@0
   877
	return KErrNone;	
sl@0
   878
sl@0
   879
	}
sl@0
   880
sl@0
   881
TInt TFsPrivatePath::Initialise(CFsRequest* /*aRequest*/) 
sl@0
   882
//
sl@0
   883
//
sl@0
   884
//
sl@0
   885
	{
sl@0
   886
	return KErrNone;
sl@0
   887
	}
sl@0
   888
sl@0
   889
sl@0
   890
TInt TFsCreatePrivatePath::DoRequestL(CFsRequest* aRequest)
sl@0
   891
//
sl@0
   892
//	create the private path unless it already exists
sl@0
   893
//
sl@0
   894
	{
sl@0
   895
    TInt ret = CheckDiskSpace(0, aRequest);
sl@0
   896
    if(ret != KErrNone)
sl@0
   897
        return ret;
sl@0
   898
sl@0
   899
	TBuf<30> pPath(KPrivate);	
sl@0
   900
	pPath += KSlash;
sl@0
   901
	pPath.AppendNumFixedWidth(aRequest->Message().SecureId().iId, EHex, 8);
sl@0
   902
	TEntry e;
sl@0
   903
	ret=aRequest->Drive()->CheckMount();
sl@0
   904
	if (ret!=KErrNone)
sl@0
   905
		return ret;
sl@0
   906
sl@0
   907
	//no point going mad on sanity check we know it's not root or a bad name
sl@0
   908
	ret =aRequest->Drive()->Entry(KPrivate(),e);
sl@0
   909
	if(ret != KErrNone)
sl@0
   910
		{
sl@0
   911
		if(ret==KErrNotFound)
sl@0
   912
			{
sl@0
   913
			ret = aRequest->Drive()->MkDir(KPrivate());	
sl@0
   914
			if(ret != KErrNone)
sl@0
   915
				return ret;
sl@0
   916
			}
sl@0
   917
		else
sl@0
   918
			return ret;
sl@0
   919
		}
sl@0
   920
	ret =aRequest->Drive()->Entry(pPath,e);
sl@0
   921
	if(ret==KErrPathNotFound || ret==KErrNotFound || !e.IsDir())	
sl@0
   922
		{	
sl@0
   923
		if((ret=aRequest->Drive()->MkDir(pPath ))!=KErrNone)
sl@0
   924
			return ret;			
sl@0
   925
		}
sl@0
   926
	return ret;
sl@0
   927
	}
sl@0
   928
sl@0
   929
sl@0
   930
TInt TFsCreatePrivatePath::Initialise(CFsRequest* aRequest) 
sl@0
   931
//
sl@0
   932
//
sl@0
   933
//
sl@0
   934
	{
sl@0
   935
	TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest);
sl@0
   936
	return(r);
sl@0
   937
	}
sl@0
   938
sl@0
   939
TInt TFsFinaliseDrive::DoRequestL(CFsRequest* aRequest)
sl@0
   940
	{
sl@0
   941
	__PRINT(_L("TFsFinaliseDrive::DoRequestL"));
sl@0
   942
sl@0
   943
	TInt r=aRequest->Drive()->CheckMount();
sl@0
   944
	if (r!=KErrNone)
sl@0
   945
		return r;
sl@0
   946
sl@0
   947
    const TInt nMode = aRequest->Message().Int1(); //-- finalisation mode, see RFs::TFinaliseDrvMode
sl@0
   948
sl@0
   949
	return aRequest->Drive()->FinaliseMount(nMode);
sl@0
   950
	}
sl@0
   951
sl@0
   952
/**
sl@0
   953
    Finalise the drive
sl@0
   954
*/
sl@0
   955
TInt TFsFinaliseDrive::Initialise(CFsRequest* aRequest)
sl@0
   956
	{
sl@0
   957
	if (!KCapFsFinaliseDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Finalise Drive")))
sl@0
   958
		return KErrPermissionDenied;
sl@0
   959
sl@0
   960
	const TInt nDrv  = aRequest->Message().Int0(); //-- the drive number to be finalised
sl@0
   961
sl@0
   962
    TInt r = ValidateDriveDoSubst(nDrv, aRequest);
sl@0
   963
    if (r != KErrNone)
sl@0
   964
        return r;
sl@0
   965
sl@0
   966
	TDrive& d = TheDrives[nDrv];
sl@0
   967
    if(!d.GetFSys())
sl@0
   968
	    return KErrNotFound; //-- something wrong with this drive 
sl@0
   969
sl@0
   970
    
sl@0
   971
    //-- check the drive attributes
sl@0
   972
    const TUint KDrvAttExclude = KDriveAttRom | KDriveAttRedirected; //-- the drive attributes to exlcude from the finalisation
sl@0
   973
    if(d.Att() & KDrvAttExclude) 
sl@0
   974
        return KErrNotSupported; //-- finalisation isn't supported for these drives
sl@0
   975
sl@0
   976
	return KErrNone;
sl@0
   977
	}
sl@0
   978
sl@0
   979
/**  Set System Drive (used by GetSystemDrive and SystemDriveChar) */
sl@0
   980
TInt TFsSetSystemDrive::DoRequestL(CFsRequest* aRequest)
sl@0
   981
	{
sl@0
   982
    __PRINT(_L("TFsSetSystemDrive::DoRequestL()"));
sl@0
   983
    TInt drive;
sl@0
   984
	TInt err = RProperty::Get(TSecureId(KFileServerUidValue), KSystemDriveKey, drive);
sl@0
   985
	if(err == KErrNone)
sl@0
   986
		{
sl@0
   987
		__PRINT1(_L("TFsSetSystemDrive::DoRequestL() drv:%d is already defined as system!"), drive);
sl@0
   988
        return KErrAlreadyExists;
sl@0
   989
		}
sl@0
   990
	
sl@0
   991
    drive = aRequest->Message().Int0();    
sl@0
   992
	__ASSERT_ALWAYS(drive>=EDriveA && drive<=EDriveZ, Fault(EInvalidDrive));
sl@0
   993
sl@0
   994
	//Calculates the total number of valid drives present and set RAM as a
sl@0
   995
	//system drive only if one valid drive is present.
sl@0
   996
	TInt total_drive = 0;
sl@0
   997
	for (TInt driveNumber=0; driveNumber<KMaxDrives; driveNumber++)
sl@0
   998
		{
sl@0
   999
		if(TheDrives[driveNumber].GetFSys() != NULL)  // is a valid drive
sl@0
  1000
			total_drive++;
sl@0
  1001
		}
sl@0
  1002
	aRequest->SetDrive(&TheDrives[drive]);
sl@0
  1003
	FsThreadManager::LockDrive(aRequest->DriveNumber());
sl@0
  1004
	TDriveInfo info;
sl@0
  1005
	aRequest->Drive()->DriveInfo(info);
sl@0
  1006
	FsThreadManager::UnlockDrive(aRequest->DriveNumber());
sl@0
  1007
sl@0
  1008
	__PRINT1(_L("TFsSetSystemDrive::DoRequestL() total drives:%d"), total_drive);
sl@0
  1009
    __PRINT3(_L("TFsSetSystemDrive::DoRequestL() setting sys:%d, Media:0x%x, DrvAtt:0x%x"), drive, info.iType, info.iDriveAtt);
sl@0
  1010
sl@0
  1011
    //-- 1. check media type of the system drive.
sl@0
  1012
    __ASSERT_ALWAYS(info.iType==EMediaHardDisk || info.iType==EMediaFlash || info.iType==EMediaNANDFlash || info.iType==EMediaRam, Fault(EInvalidDrive));
sl@0
  1013
    
sl@0
  1014
    if(info.iType == EMediaRam)
sl@0
  1015
		{//-- It is not nice to use RAM drive as a system one because it might non be persistent, but acceptable though. 
sl@0
  1016
         __PRINT(_L("TFsSetSystemDrive::DoRequestL() WARNING: RAM drive is set as system drive!"));
sl@0
  1017
        }
sl@0
  1018
   
sl@0
  1019
    //-- 2. check drive attributes for the system drive
sl@0
  1020
    const TUint requiredDrvAtt   = KDriveAttLocal|KDriveAttInternal;
sl@0
  1021
    const TUint prohibitedDrvAtt = KDriveAttRom|KDriveAttRedirected|KDriveAttSubsted|KDriveAttRemovable;
sl@0
  1022
sl@0
  1023
    ASSERT(!(prohibitedDrvAtt & requiredDrvAtt));
sl@0
  1024
    if( !(info.iDriveAtt & requiredDrvAtt) || (info.iDriveAtt & prohibitedDrvAtt))
sl@0
  1025
        {
sl@0
  1026
        __PRINT2(_L("TFsSetSystemDrive::DoRequestL(), Wrong Drive attributes! req:0x%x, disallowed:0x%x"), requiredDrvAtt, prohibitedDrvAtt);
sl@0
  1027
        Fault(EInvalidDrive);
sl@0
  1028
        }
sl@0
  1029
sl@0
  1030
sl@0
  1031
	RProcess p;
sl@0
  1032
	TSecurityPolicy policy(p.SecureId());
sl@0
  1033
	err = RProperty::Define(TSecureId(KFileServerUidValue), KSystemDriveKey, RProperty::EInt, TSecurityPolicy::EAlwaysPass, policy);
sl@0
  1034
	if(err == KErrNone)
sl@0
  1035
		{
sl@0
  1036
		err = RProperty::Set(TSecureId(KFileServerUidValue), KSystemDriveKey, drive);
sl@0
  1037
		}
sl@0
  1038
	__ASSERT_ALWAYS(err==KErrNone, User::Invariant());
sl@0
  1039
    
sl@0
  1040
    return err;
sl@0
  1041
	}
sl@0
  1042
	
sl@0
  1043
/** Checks if setting System Drive is allowed */
sl@0
  1044
TInt TFsSetSystemDrive::Initialise(CFsRequest* aRequest)
sl@0
  1045
	{
sl@0
  1046
	if (!KCapFsSetSystemDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Set System Drive")))
sl@0
  1047
		{
sl@0
  1048
		return KErrPermissionDenied;
sl@0
  1049
		}
sl@0
  1050
    return KErrNone;
sl@0
  1051
	}