os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_plugin_ops.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_plugin_ops.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "sf_std.h"
sl@0
    19
#include "sf_plugin_priv.h"
sl@0
    20
#include "sf_file_cache.h"
sl@0
    21
sl@0
    22
/**
sl@0
    23
Platform security check
sl@0
    24
*/
sl@0
    25
TInt TFsAddPlugin::Initialise(CFsRequest* aRequest)
sl@0
    26
	{
sl@0
    27
	if (!KCapFsPlugin.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Mount Plugin")))
sl@0
    28
		return KErrPermissionDenied;
sl@0
    29
sl@0
    30
	return(KErrNone);
sl@0
    31
	}
sl@0
    32
sl@0
    33
/**
sl@0
    34
Adds the plugin and installs plugin factory
sl@0
    35
*/
sl@0
    36
TInt TFsAddPlugin::DoRequestL(CFsRequest* aRequest)
sl@0
    37
	{
sl@0
    38
	__PRINT(_L("TFsAddPlugin::DoRequestL(CFsRequest* aRequest)"));
sl@0
    39
	
sl@0
    40
	RLibrary lib;
sl@0
    41
	lib.SetHandle(aRequest->Message().Int0());				
sl@0
    42
	if (lib.Type()[1]!=TUid::Uid(KFileSystemUidValue))		
sl@0
    43
		return KErrNotSupported;
sl@0
    44
sl@0
    45
	TPluginNew e=(TPluginNew)lib.Lookup(1);					
sl@0
    46
	if (!e)
sl@0
    47
		return KErrCorrupt;
sl@0
    48
sl@0
    49
	CFsPluginFactory* pF=(*e)();
sl@0
    50
	if(!pF)													
sl@0
    51
		return KErrNoMemory;
sl@0
    52
	
sl@0
    53
	TInt r = FsPluginManager::InstallPluginFactory(pF,lib);
sl@0
    54
	return(r);
sl@0
    55
	}
sl@0
    56
sl@0
    57
/**
sl@0
    58
Platform security checking
sl@0
    59
*/
sl@0
    60
TInt TFsRemovePlugin::Initialise(CFsRequest* aRequest)
sl@0
    61
	{
sl@0
    62
	if (!KCapFsPlugin.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Mount Plugin")))
sl@0
    63
		return KErrPermissionDenied;
sl@0
    64
	return KErrNone;
sl@0
    65
	}
sl@0
    66
sl@0
    67
/**
sl@0
    68
Removes the plugin from session. Can't remove if have plugin mounted. 
sl@0
    69
*/
sl@0
    70
TInt TFsRemovePlugin::DoRequestL(CFsRequest* aRequest)
sl@0
    71
	{
sl@0
    72
	TFullName name;
sl@0
    73
	aRequest->ReadL(KMsgPtr0,name);	
sl@0
    74
	
sl@0
    75
	CFsPluginFactory* pF = FsPluginManager::GetPluginFactory(name);			
sl@0
    76
	if (pF==NULL)								
sl@0
    77
		return(KErrNotFound);
sl@0
    78
sl@0
    79
	// Check if any plugin is mounted in the chain
sl@0
    80
	if(pF->MountedPlugins()!=0)
sl@0
    81
		return KErrInUse;	
sl@0
    82
sl@0
    83
	TInt r=pF->Remove();						
sl@0
    84
	if (r!=KErrNone)
sl@0
    85
		return(r);
sl@0
    86
	RLibrary lib=pF->Library();					
sl@0
    87
	pF->Close();								
sl@0
    88
	lib.Close();								
sl@0
    89
	return(KErrNone);
sl@0
    90
	}
sl@0
    91
sl@0
    92
/**
sl@0
    93
Platform security check.
sl@0
    94
Finding the plugin factory & checking if the drive supports the plugin
sl@0
    95
*/
sl@0
    96
TInt TFsMountPlugin::Initialise(CFsRequest* aRequest)
sl@0
    97
	{
sl@0
    98
	
sl@0
    99
	if (!KCapFsPlugin.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Mount Plugin")))
sl@0
   100
		return KErrPermissionDenied;
sl@0
   101
	
sl@0
   102
	TFullName pluginName;
sl@0
   103
	TRAPD(err,aRequest->ReadL(KMsgPtr0,pluginName));
sl@0
   104
	if(err != KErrNone)
sl@0
   105
		return err;
sl@0
   106
sl@0
   107
	CFsPluginFactory* pF = FsPluginManager::GetPluginFactory(pluginName);
sl@0
   108
	if (pF==NULL)
sl@0
   109
		return(KErrNotFound);
sl@0
   110
sl@0
   111
	if(pF->IsDriveSupported(aRequest->Message().Int1()) == EFalse)
sl@0
   112
		return KErrNotSupported;
sl@0
   113
sl@0
   114
	aRequest->SetScratchValue((TUint)pF);
sl@0
   115
sl@0
   116
	return KErrNone;
sl@0
   117
	}
sl@0
   118
sl@0
   119
/**
sl@0
   120
Mounts the plugin
sl@0
   121
*/
sl@0
   122
TInt TFsMountPlugin::DoRequestL(CFsRequest* aRequest)
sl@0
   123
	{
sl@0
   124
	CFsPluginFactory* pF = (CFsPluginFactory*)aRequest->ScratchValue();
sl@0
   125
	if(pF == NULL)
sl@0
   126
		return KErrNotFound;
sl@0
   127
sl@0
   128
	// empty the closed file queue
sl@0
   129
	TClosedFileUtils::Remove();
sl@0
   130
sl@0
   131
	TInt err = FsPluginManager::MountPlugin(*pF,aRequest->Message().Int1(),aRequest->Message().Int2());
sl@0
   132
	return err;
sl@0
   133
	}
sl@0
   134
sl@0
   135
/**
sl@0
   136
Platform security check.
sl@0
   137
Finding the plugin factory & checking if the drive supports the plugin
sl@0
   138
*/
sl@0
   139
TInt TFsDismountPlugin::Initialise(CFsRequest* aRequest)
sl@0
   140
	{
sl@0
   141
	if (!KCapFsPlugin.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Mount Plugin")))
sl@0
   142
		return KErrPermissionDenied;
sl@0
   143
sl@0
   144
	TFullName name;
sl@0
   145
	TRAPD(err, aRequest->ReadL(KMsgPtr0,name));					//get plugin name
sl@0
   146
	if(err!=KErrNone)
sl@0
   147
		return err;
sl@0
   148
sl@0
   149
	TInt drive = aRequest->Message().Int1();
sl@0
   150
	CFsPluginFactory* pF = FsPluginManager::GetPluginFactory(name);				
sl@0
   151
	if (!pF || pF->MountedPlugins()==0)
sl@0
   152
		return(KErrNotFound);
sl@0
   153
	if(pF->IsDriveSupported(drive) == EFalse)
sl@0
   154
		return KErrNotSupported;
sl@0
   155
sl@0
   156
	FsPluginManager::LockChain();
sl@0
   157
	err = FsPluginManager::IsInChain(pF->UniquePosition(),aRequest->Message().Int2(),aRequest->Message().Int1(), pF);
sl@0
   158
sl@0
   159
	// plugin might have been mounted in different pos and drive. Find the right one
sl@0
   160
	if(err >= 0)
sl@0
   161
		{
sl@0
   162
		TInt pos = err;
sl@0
   163
		CFsPlugin* plugin = NULL;
sl@0
   164
		err = FsPluginManager::Plugin(plugin, pos);
sl@0
   165
		if(err == KErrNone)
sl@0
   166
			{
sl@0
   167
			//If we're version2 plugin, and we're dismounting a single drive
sl@0
   168
			// but we're mounted on many drives, then
sl@0
   169
			// just remove drive from iMountedOn and return KErrCompletion.
sl@0
   170
			//
sl@0
   171
			//NB: Already checked that we're mounted on 'drive' in IsInChain
sl@0
   172
			
sl@0
   173
			if(pF->SupportedDrives()&KPluginVersionTwo && drive!=KPluginAutoAttach)
sl@0
   174
				{
sl@0
   175
				//Special Case:
sl@0
   176
				//Z Drive
sl@0
   177
				if(drive==KPluginMountDriveZ)
sl@0
   178
					{
sl@0
   179
					drive = 25;
sl@0
   180
					}
sl@0
   181
				
sl@0
   182
				//Are we mounted on many drives?
sl@0
   183
				if((plugin->iMountedOn&(~1<<drive)) > 0) //without 'drive' is there still a drive set?
sl@0
   184
					{
sl@0
   185
					plugin->iMountedOn &= ~1<<drive;
sl@0
   186
					FsPluginManager::UnlockChain();
sl@0
   187
					return KErrCompletion; //don't go to dorequestl
sl@0
   188
					}
sl@0
   189
				}
sl@0
   190
			
sl@0
   191
			plugin->RegisterIntercept(EFsDismountPlugin, CFsPlugin::EPreIntercept);
sl@0
   192
			aRequest->SetScratchValue((TUint)pF);
sl@0
   193
			}
sl@0
   194
		}
sl@0
   195
	// pos contains an error code
sl@0
   196
	FsPluginManager::UnlockChain();
sl@0
   197
	return err;
sl@0
   198
	}
sl@0
   199
sl@0
   200
/**
sl@0
   201
Dismount the plugin from the stack
sl@0
   202
*/
sl@0
   203
TInt TFsDismountPlugin::DoRequestL(CFsRequest* aRequest)
sl@0
   204
	{
sl@0
   205
sl@0
   206
	CFsPluginFactory* pF = (CFsPluginFactory*)aRequest->ScratchValue();
sl@0
   207
	if(pF == NULL)
sl@0
   208
		return KErrNone;	// The plugin has already been dismounted
sl@0
   209
sl@0
   210
	TInt drive = aRequest->Message().Int1();
sl@0
   211
sl@0
   212
	FsPluginManager::LockChain();
sl@0
   213
sl@0
   214
	TInt err = FsPluginManager::IsInChain(pF->UniquePosition(),aRequest->Message().Int2(),drive, pF);
sl@0
   215
	if(err >= 0)
sl@0
   216
		{
sl@0
   217
		TInt pos = err;
sl@0
   218
		CFsPlugin* plugin = NULL;
sl@0
   219
		err = FsPluginManager::Plugin(plugin, pos);
sl@0
   220
		if(err == KErrNone)
sl@0
   221
			{
sl@0
   222
			if(aRequest->iCurrentPlugin == plugin)
sl@0
   223
				{
sl@0
   224
				FsPluginManager::DismountPlugin(*pF,pos);
sl@0
   225
				aRequest->SetScratchValue(0);
sl@0
   226
				}
sl@0
   227
			}
sl@0
   228
		}
sl@0
   229
	FsPluginManager::UnlockChain();
sl@0
   230
	return err;
sl@0
   231
	}
sl@0
   232
sl@0
   233
sl@0
   234
/**
sl@0
   235
Validates the drive
sl@0
   236
*/
sl@0
   237
TInt TFsPluginName::Initialise(CFsRequest* aRequest)
sl@0
   238
	{
sl@0
   239
	TInt r=ValidateDrive(aRequest->Message().Int1(),aRequest);
sl@0
   240
	if(r!=KErrNone)
sl@0
   241
		return r;
sl@0
   242
	if(aRequest->Drive()->IsSubsted())
sl@0
   243
		return KErrNotSupported;
sl@0
   244
	return r;
sl@0
   245
	}
sl@0
   246
sl@0
   247
/**
sl@0
   248
Return the name of a plugin for a given drive and plugin chain position
sl@0
   249
*/
sl@0
   250
TInt TFsPluginName::DoRequestL(CFsRequest* aRequest)
sl@0
   251
	{
sl@0
   252
	CFsPlugin* plugin=NULL;
sl@0
   253
	FsPluginManager::LockChain();
sl@0
   254
	TInt err = FsPluginManager::Plugin(plugin, aRequest->Message().Int2());
sl@0
   255
	if(err != KErrNone)
sl@0
   256
		return err;
sl@0
   257
sl@0
   258
	TInt r = KErrNotFound;
sl@0
   259
	if(plugin)
sl@0
   260
		{
sl@0
   261
		aRequest->WriteL(KMsgPtr0, plugin->Name());
sl@0
   262
		r = KErrNone;
sl@0
   263
		}
sl@0
   264
	FsPluginManager::UnlockChain();
sl@0
   265
	return r;
sl@0
   266
	}
sl@0
   267
/**
sl@0
   268
Open a plugin
sl@0
   269
*/
sl@0
   270
TInt TFsPluginOpen::Initialise(CFsRequest* aRequest)
sl@0
   271
	{
sl@0
   272
	TInt pluginPos = aRequest->Message().Int0();
sl@0
   273
	CFsPlugin* pP = FsPluginManager::FindByUniquePosition(pluginPos);
sl@0
   274
	if(pP == NULL)
sl@0
   275
		return KErrNotFound;
sl@0
   276
sl@0
   277
	aRequest->iCurrentPlugin = pP;
sl@0
   278
	aRequest->SetDriveNumber(-1);
sl@0
   279
	
sl@0
   280
	RThread thread;
sl@0
   281
	aRequest->Message().Client(thread, EOwnerThread);
sl@0
   282
	aRequest->SetScratchValue((TUint)(thread.Id()));
sl@0
   283
	thread.Close();
sl@0
   284
	
sl@0
   285
	return KErrNone;
sl@0
   286
	}
sl@0
   287
sl@0
   288
/**
sl@0
   289
open the plugin
sl@0
   290
*/
sl@0
   291
TInt TFsPluginOpen::DoRequestL(CFsRequest* aRequest)
sl@0
   292
	{
sl@0
   293
	TInt pluginPos = aRequest->Message().Int0();
sl@0
   294
	CFsPluginConn* pC = FsPluginManager::CreatePluginConnL(pluginPos, aRequest->ScratchValue());
sl@0
   295
sl@0
   296
	TInt handle = aRequest->Session()->Handles().AddL(pC,ETrue);
sl@0
   297
	TPtrC8 pH((TUint8*)&handle, sizeof(TInt));
sl@0
   298
	aRequest->WriteL(KMsgPtr3, pH);
sl@0
   299
	aRequest->Session()->IncResourceCount();
sl@0
   300
	
sl@0
   301
	return KErrNone;
sl@0
   302
	}
sl@0
   303
sl@0
   304
/**
sl@0
   305
Initialising the plugin control
sl@0
   306
*/
sl@0
   307
LOCAL_C TInt InitPluginControl(CFsRequest* aRequest)
sl@0
   308
	{
sl@0
   309
	CFsPluginConn* pC = FsPluginManager::GetPluginConnFromHandle(aRequest->Session(), aRequest->Message().Int3());
sl@0
   310
	if(pC == NULL)
sl@0
   311
		return KErrBadHandle;
sl@0
   312
sl@0
   313
	aRequest->iCurrentPlugin = pC->Plugin();
sl@0
   314
	aRequest->SetDriveNumber(-1);
sl@0
   315
sl@0
   316
	CFsPluginConnRequest* request = new CFsPluginConnRequest(pC);
sl@0
   317
	if(request == NULL)
sl@0
   318
		return KErrNoMemory;
sl@0
   319
sl@0
   320
	aRequest->SetScratchValue((TUint)request);
sl@0
   321
	return KErrNone;
sl@0
   322
	}
sl@0
   323
sl@0
   324
/**
sl@0
   325
Initialises the plugin control and gets the request
sl@0
   326
*/
sl@0
   327
TInt TFsPluginDoControl::Initialise(CFsRequest* aRequest)
sl@0
   328
	{
sl@0
   329
	TInt err = InitPluginControl(aRequest);
sl@0
   330
	if(err != KErrNone)
sl@0
   331
		return err;
sl@0
   332
sl@0
   333
	CFsPluginConnRequest* request = (CFsPluginConnRequest*)aRequest->ScratchValue();
sl@0
   334
	return request->InitControl(aRequest);
sl@0
   335
	}
sl@0
   336
sl@0
   337
/**
sl@0
   338
does handle the control request
sl@0
   339
*/
sl@0
   340
TInt TFsPluginDoControl::DoRequestL(CFsRequest* aRequest)
sl@0
   341
	{
sl@0
   342
	CFsPluginConnRequest* pRequest = (CFsPluginConnRequest*)aRequest->ScratchValue();	
sl@0
   343
	TInt r = pRequest->DoControl();
sl@0
   344
	delete pRequest;
sl@0
   345
	return r;
sl@0
   346
	}
sl@0
   347
sl@0
   348
sl@0
   349
/**
sl@0
   350
Initialises the request 
sl@0
   351
*/
sl@0
   352
TInt TFsPluginDoRequest::Initialise(CFsRequest* aRequest)
sl@0
   353
	{
sl@0
   354
	TInt err = InitPluginControl(aRequest);
sl@0
   355
	if(err != KErrNone)
sl@0
   356
		return err;
sl@0
   357
sl@0
   358
	CFsPluginConnRequest* request = (CFsPluginConnRequest*)aRequest->ScratchValue();
sl@0
   359
	return request->InitRequest(aRequest);
sl@0
   360
	}
sl@0
   361
sl@0
   362
/**
sl@0
   363
Handles the request adding it to the queue of the requests
sl@0
   364
*/
sl@0
   365
TInt TFsPluginDoRequest::DoRequestL(CFsRequest* aRequest)
sl@0
   366
	{
sl@0
   367
	CFsPluginConnRequest* pRequest = (CFsPluginConnRequest*)aRequest->ScratchValue();	
sl@0
   368
	pRequest->DoRequest();
sl@0
   369
	return KErrNone;
sl@0
   370
	}
sl@0
   371
sl@0
   372
/**
sl@0
   373
Initialises the request
sl@0
   374
*/
sl@0
   375
TInt TFsPluginDoCancel::Initialise(CFsRequest* aRequest)
sl@0
   376
	{
sl@0
   377
	CFsPluginConn* pC = FsPluginManager::GetPluginConnFromHandle(aRequest->Session(), aRequest->Message().Int3());
sl@0
   378
	if(pC == NULL)
sl@0
   379
		return KErrBadHandle;
sl@0
   380
sl@0
   381
	aRequest->iCurrentPlugin = pC->Plugin();
sl@0
   382
	aRequest->SetDriveNumber(-1);
sl@0
   383
	aRequest->SetScratchValue((TUint)pC);
sl@0
   384
	
sl@0
   385
	return KErrNone;
sl@0
   386
	}
sl@0
   387
sl@0
   388
/**
sl@0
   389
Cancels the outstanding request
sl@0
   390
*/
sl@0
   391
TInt TFsPluginDoCancel::DoRequestL(CFsRequest* aRequest)
sl@0
   392
	{
sl@0
   393
	CFsPluginConn* pC = (CFsPluginConn*)aRequest->ScratchValue();	
sl@0
   394
	pC->DoCancel(aRequest->Message().Int0());
sl@0
   395
	return KErrNone;
sl@0
   396
	}
sl@0
   397