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