os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_plugin.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
// f32\sfile\sf_plugin.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
sl@0
    24
#include "sf_std.h"
sl@0
    25
#include "sf_plugin_priv.h"
sl@0
    26
sl@0
    27
sl@0
    28
EXPORT_C CFsPluginFactory::CFsPluginFactory()
sl@0
    29
	{}
sl@0
    30
sl@0
    31
EXPORT_C CFsPluginFactory::~CFsPluginFactory()
sl@0
    32
	{}
sl@0
    33
sl@0
    34
/**
sl@0
    35
sl@0
    36
Uninstalls the plugin factory.
sl@0
    37
sl@0
    38
This is called just before the plugin factory object is destroyed, and allows
sl@0
    39
any clean up to be carried out.
sl@0
    40
sl@0
    41
The default implementation does nothing except return KErrNone.
sl@0
    42
Implementations should return an error code on error detection.
sl@0
    43
sl@0
    44
@return KErrNone if successful, otherwise one of the other system wide error
sl@0
    45
        codes.
sl@0
    46
*/
sl@0
    47
EXPORT_C TInt CFsPluginFactory::Remove()
sl@0
    48
	{
sl@0
    49
	return(KErrNone);
sl@0
    50
	}
sl@0
    51
sl@0
    52
/**
sl@0
    53
sl@0
    54
Sets the plugin factory's resource library.
sl@0
    55
This library represents the loaded plugin factory.
sl@0
    56
This is called internally by InstallPluginFactory().
sl@0
    57
sl@0
    58
@param aLib The resource library to be set.
sl@0
    59
*/
sl@0
    60
EXPORT_C void CFsPluginFactory::SetLibrary(RLibrary aLib)
sl@0
    61
	{
sl@0
    62
	iLibrary=aLib;
sl@0
    63
	}
sl@0
    64
sl@0
    65
/**
sl@0
    66
Gets the plugin factory's resource library.
sl@0
    67
sl@0
    68
@return The plugin factory's resource library.
sl@0
    69
*/
sl@0
    70
EXPORT_C RLibrary CFsPluginFactory::Library() const
sl@0
    71
	{
sl@0
    72
	return(iLibrary);
sl@0
    73
	}
sl@0
    74
sl@0
    75
/**
sl@0
    76
sl@0
    77
*/
sl@0
    78
TBool CFsPluginFactory::IsDriveSupported(TInt aDrive)
sl@0
    79
	{
sl@0
    80
	//If this is version 1 of the plugins, then if KPluginAutoAttach was specified at mount
sl@0
    81
	//then it just returned ETrue! This behaviour is preserved here:
sl@0
    82
	if(!(iSupportedDrives & KPluginVersionTwo) && (aDrive == KPluginAutoAttach))
sl@0
    83
		{
sl@0
    84
		return(ETrue);
sl@0
    85
		}
sl@0
    86
sl@0
    87
	//If we're version 2 plugin (or version1 && !KPluginAutoAttach) then check against what's been set in iSupportedDrives
sl@0
    88
	return((iSupportedDrives & (1 << aDrive)) ? (TBool)ETrue : (TBool)EFalse);
sl@0
    89
	}
sl@0
    90
sl@0
    91
sl@0
    92
EXPORT_C CFsPlugin::CFsPlugin()
sl@0
    93
	: iReadOnly(0)
sl@0
    94
	{
sl@0
    95
    Mem::FillZ(iRegisteredIntercepts, sizeof(iRegisteredIntercepts));
sl@0
    96
	}
sl@0
    97
sl@0
    98
EXPORT_C CFsPlugin::~CFsPlugin()
sl@0
    99
	{
sl@0
   100
	}
sl@0
   101
sl@0
   102
/**
sl@0
   103
Delivers the request to the end of plugin thread's queue. 
sl@0
   104
In certain circumstances, where the request requires priority handling
sl@0
   105
it adds it to the front of the queue.
sl@0
   106
sl@0
   107
@param	aRequest: The request to be delivered
sl@0
   108
@return KErrNone
sl@0
   109
*/
sl@0
   110
EXPORT_C TInt CFsPlugin::Deliver(TFsPluginRequest& aRequest)
sl@0
   111
	{
sl@0
   112
	__ASSERT_ALWAYS(iThreadP != NULL, User::Panic(_L("CFsPlugin::Dispatch"),999));
sl@0
   113
sl@0
   114
	TInt function = aRequest.Function();
sl@0
   115
sl@0
   116
	if(function == EFsPluginOpen)
sl@0
   117
		{
sl@0
   118
		// Don't dispatch open requests to the plugin thread
sl@0
   119
		return KPluginMessageForward;
sl@0
   120
		}
sl@0
   121
sl@0
   122
	if(function == EFsPluginDoRequest ||
sl@0
   123
	   function == EFsPluginDoControl ||
sl@0
   124
	   function == EFsPluginDoCancel)
sl@0
   125
		{
sl@0
   126
		iThreadP->DeliverFront(aRequest.Request());
sl@0
   127
		}
sl@0
   128
	else
sl@0
   129
		{
sl@0
   130
		iThreadP->DeliverBack(aRequest.Request());
sl@0
   131
		}
sl@0
   132
sl@0
   133
	return KErrNone;
sl@0
   134
	}
sl@0
   135
sl@0
   136
/**
sl@0
   137
Initialises the plugin but setting all registered intercepts to zero.
sl@0
   138
Derived classes might wish to implement their own InitialiseL to add intercepts
sl@0
   139
*/
sl@0
   140
EXPORT_C void CFsPlugin::InitialiseL()
sl@0
   141
	{
sl@0
   142
	}
sl@0
   143
sl@0
   144
/**
sl@0
   145
Creates a new pluginconn object
sl@0
   146
Leaves with KErrNotSupported
sl@0
   147
sl@0
   148
@return NULL
sl@0
   149
*/
sl@0
   150
EXPORT_C CFsPluginConn* CFsPlugin::NewPluginConnL()
sl@0
   151
	{
sl@0
   152
	User::Leave(KErrNotSupported);
sl@0
   153
	return NULL;
sl@0
   154
	}
sl@0
   155
sl@0
   156
/**
sl@0
   157
Registers a particular function with plugin to be intercepted
sl@0
   158
sl@0
   159
@param	aMessage:		the message to be intercepted
sl@0
   160
@param  aInterceptAtts:	If it is post or pre intercept
sl@0
   161
@return KErrNone on successful completion 
sl@0
   162
		KErrNotSupported if message is invalid
sl@0
   163
*/
sl@0
   164
EXPORT_C TInt CFsPlugin::RegisterIntercept(TInt aMessage, TInterceptAtts aInterceptAtts)
sl@0
   165
	{
sl@0
   166
	if(aMessage >= EMaxClientOperations)
sl@0
   167
		{
sl@0
   168
		return KErrNotSupported;
sl@0
   169
		}
sl@0
   170
sl@0
   171
	const TUint32 index = aMessage >> 2; //-- index in the intercepts array
sl@0
   172
sl@0
   173
    if(index >= KIntcArrSize)
sl@0
   174
        {
sl@0
   175
        __ASSERT_DEBUG(0,Fault(EArrayIndexOutOfRange));
sl@0
   176
        return KErrNotSupported;
sl@0
   177
        }
sl@0
   178
sl@0
   179
	const TUint8 msk  = (TUint8)(aInterceptAtts << ((aMessage & 0x03) << 1));
sl@0
   180
	iRegisteredIntercepts[index] |= msk;
sl@0
   181
sl@0
   182
	return KErrNone;
sl@0
   183
	}
sl@0
   184
sl@0
   185
/**
sl@0
   186
Unregisters a particular function with plugin 
sl@0
   187
sl@0
   188
@param	aMessage:		the message which should be unregistered
sl@0
   189
@param  aInterceptAtts:	If it is post or pre intercept
sl@0
   190
@return KErrNone on successful completion 
sl@0
   191
		KErrNotSupported if message is invalid
sl@0
   192
*/
sl@0
   193
EXPORT_C TInt CFsPlugin::UnregisterIntercept(TInt aMessage, TInterceptAtts aInterceptAtts)
sl@0
   194
	{
sl@0
   195
	if(aMessage >= EMaxClientOperations)
sl@0
   196
		{
sl@0
   197
		return KErrNotSupported;
sl@0
   198
		}
sl@0
   199
sl@0
   200
	const TUint32 index = aMessage >> 2; //-- index in the intercepts array
sl@0
   201
    if(index >= KIntcArrSize)
sl@0
   202
        {
sl@0
   203
        __ASSERT_DEBUG(0,Fault(EArrayIndexOutOfRange));
sl@0
   204
        return KErrNotSupported;
sl@0
   205
        }
sl@0
   206
sl@0
   207
	const TUint8 msk = (TUint8)(aInterceptAtts << ((aMessage & 0x03) << 1));
sl@0
   208
	iRegisteredIntercepts[index] &= ~msk;
sl@0
   209
sl@0
   210
	return KErrNone;
sl@0
   211
	}
sl@0
   212
sl@0
   213
/**
sl@0
   214
    @return ETrue if the message aMessage is registered with any TInterceptAtts type
sl@0
   215
*/
sl@0
   216
TBool CFsPlugin::IsRegistered(TInt aMessage)
sl@0
   217
	{
sl@0
   218
	if(IsRegistered(aMessage,(TInterceptAtts)EPreIntercept) ||
sl@0
   219
		IsRegistered(aMessage,(TInterceptAtts)EPrePostIntercept) ||
sl@0
   220
		IsRegistered(aMessage, (TInterceptAtts)EPostIntercept))
sl@0
   221
		{
sl@0
   222
		return (TBool)ETrue;
sl@0
   223
		}
sl@0
   224
	return (TBool)EFalse;
sl@0
   225
	}
sl@0
   226
sl@0
   227
/**
sl@0
   228
    @return ETrue if the message aMessage is registered with the given aInterceptAtts attrubutes
sl@0
   229
*/
sl@0
   230
TBool CFsPlugin::IsRegistered(TInt aMessage, TInterceptAtts aInterceptAtts)
sl@0
   231
	{
sl@0
   232
	if(aMessage >= EMaxClientOperations)
sl@0
   233
		{
sl@0
   234
		return EFalse;
sl@0
   235
		}
sl@0
   236
sl@0
   237
	const TUint32 index = aMessage >> 2; //-- index in the intercepts array
sl@0
   238
    if(index >= KIntcArrSize)
sl@0
   239
        {
sl@0
   240
        __ASSERT_DEBUG(0,Fault(EArrayIndexOutOfRange));
sl@0
   241
        return EFalse;
sl@0
   242
        }
sl@0
   243
sl@0
   244
	const TUint8 msk = (TUint8)(aInterceptAtts << ((aMessage & 0x03) << 1));
sl@0
   245
sl@0
   246
	return((iRegisteredIntercepts[index] & msk) == msk);
sl@0
   247
	}
sl@0
   248
sl@0
   249
/**
sl@0
   250
   Return ETrue if the calling thread is the plugin thread
sl@0
   251
*/
sl@0
   252
TBool CFsPlugin::IsPluginThread(CFsRequest& aRequest)
sl@0
   253
	{
sl@0
   254
	if(aRequest.iOwnerPlugin == this)
sl@0
   255
		return ETrue;
sl@0
   256
sl@0
   257
	if(aRequest.iClientThreadId == iThreadId)
sl@0
   258
		return ETrue;
sl@0
   259
sl@0
   260
	// Allow specific requests from the client connection...
sl@0
   261
	if(aRequest.IsPluginSpecific())
sl@0
   262
		return EFalse;
sl@0
   263
sl@0
   264
	// Check the client connections
sl@0
   265
	return FsPluginManager::IsPluginConnThread(aRequest.iClientThreadId, this);
sl@0
   266
	}
sl@0
   267
sl@0
   268
TBool CFsPlugin::IsMounted(TInt aDrive)
sl@0
   269
	{
sl@0
   270
	CFsPluginFactory* pF = FsPluginManager::GetPluginFactory(this->Name());	
sl@0
   271
	TInt supportedDrives = pF->SupportedDrives();
sl@0
   272
sl@0
   273
	//Version1 plugins could not mount on Z Drive as KPluginAutoAttach==0x19==25==EDriveZ
sl@0
   274
	//Drive Z is only supported for version two of the plugins.
sl@0
   275
	//Prevent version 1 plugins here.
sl@0
   276
	if (!(supportedDrives & KPluginVersionTwo) && (aDrive == EDriveZ))
sl@0
   277
		return EFalse;
sl@0
   278
	
sl@0
   279
	//Some requests have aDrive as -1, so for those requests
sl@0
   280
	// so long as the plugin was registered we shall say it's mounted.
sl@0
   281
	if(aDrive > EDriveZ || aDrive < EDriveA)
sl@0
   282
		return ETrue;
sl@0
   283
	
sl@0
   284
	//Otherwise Check iMountedOn
sl@0
   285
	if(iMountedOn&(1<<aDrive))
sl@0
   286
		{
sl@0
   287
		return ETrue;
sl@0
   288
		}
sl@0
   289
sl@0
   290
	return EFalse;
sl@0
   291
	}
sl@0
   292
sl@0
   293
// NOTE: The following API classification might need changing
sl@0
   294
sl@0
   295
/** 
sl@0
   296
@prototype
sl@0
   297
@deprecated
sl@0
   298
@see RFilePlugin::Read
sl@0
   299
 */
sl@0
   300
EXPORT_C TInt CFsPlugin::FileRead(TFsPluginRequest& aRequest, TDes8& aDes, TInt64 aPos)
sl@0
   301
	{
sl@0
   302
	CFileShare* share;
sl@0
   303
	CFileCB* file;
sl@0
   304
	GetFileFromScratch((CFsMessageRequest*) aRequest.Request(), share, file);
sl@0
   305
	TInt64 fileSize = file->CachedSize64();
sl@0
   306
	if (aPos > fileSize)
sl@0
   307
		aPos = fileSize;
sl@0
   308
	TInt len = aDes.Length();
sl@0
   309
	if (aPos >= fileSize)
sl@0
   310
		len = 0;
sl@0
   311
	if (aPos + len > fileSize)
sl@0
   312
		// filesize - pos shall of TInt size
sl@0
   313
		// Hence to suppress warning
sl@0
   314
		len = (TInt)(fileSize - aPos);
sl@0
   315
	aDes.SetLength(len);
sl@0
   316
sl@0
   317
	return DispatchOperation(aRequest, aDes, aPos, EFsFileRead);
sl@0
   318
	}
sl@0
   319
sl@0
   320
/** 
sl@0
   321
@prototype
sl@0
   322
@deprecated
sl@0
   323
@see RFilePlugin::Write
sl@0
   324
*/
sl@0
   325
EXPORT_C TInt CFsPlugin::FileWrite(TFsPluginRequest& aRequest, const TDesC8& aDes, TInt64 aPos)
sl@0
   326
	{
sl@0
   327
	return DispatchOperation(aRequest, (TDes8&) aDes, aPos, EFsFileWrite);
sl@0
   328
	}
sl@0
   329
sl@0
   330
/**
sl@0
   331
@internalTechnology
sl@0
   332
@prototype
sl@0
   333
@deprecated
sl@0
   334
sl@0
   335
Pushes a msgop, dispatches it and waits for it to complete
sl@0
   336
*/
sl@0
   337
TInt CFsPlugin::DispatchOperation(TFsPluginRequest& aRequest, TDes8& aDes, TInt64 aPos, TInt aFunction)
sl@0
   338
	{
sl@0
   339
	if (aRequest.Function() != EFsFileRead && aRequest.Function() != EFsFileWrite)
sl@0
   340
		return KErrNotSupported;
sl@0
   341
	if (aFunction != EFsFileRead && aFunction != EFsFileWrite)
sl@0
   342
		return KErrNotSupported;
sl@0
   343
sl@0
   344
	CFsMessageRequest& msgRequest = * (CFsMessageRequest*) aRequest.Request();
sl@0
   345
sl@0
   346
sl@0
   347
	TInt len = aDes.Length();
sl@0
   348
	if (len <= 0)
sl@0
   349
		return CFsRequest::EReqActionComplete;
sl@0
   350
sl@0
   351
	TUint8* ptr = (TUint8*) aDes.Ptr();
sl@0
   352
sl@0
   353
	TInt r = msgRequest.PushOperation(
sl@0
   354
		aPos, len, ptr,
sl@0
   355
		0,			// aOffset
sl@0
   356
		Complete,	// callback
sl@0
   357
		0,			// next state
sl@0
   358
		aFunction);
sl@0
   359
	if (r != KErrNone)
sl@0
   360
		return r;
sl@0
   361
sl@0
   362
sl@0
   363
	CFsPlugin* plugin = this;
sl@0
   364
	FsPluginManager::NextPlugin(plugin, &msgRequest,(TBool)ETrue);
sl@0
   365
	msgRequest.iCurrentPlugin = plugin;
sl@0
   366
	msgRequest.Dispatch();
sl@0
   367
	iThreadP->OperationLockWait();
sl@0
   368
sl@0
   369
	aDes.SetLength(len);
sl@0
   370
	
sl@0
   371
	return msgRequest.LastError();	// KErrNone;
sl@0
   372
	}
sl@0
   373
sl@0
   374
TInt CFsPlugin::WaitForRequest()
sl@0
   375
	{
sl@0
   376
	iLastError = KErrNone;
sl@0
   377
	iThreadP->OperationLockWait();
sl@0
   378
	return iLastError;
sl@0
   379
	}
sl@0
   380
sl@0
   381
sl@0
   382
/** @prototype */
sl@0
   383
TInt CFsPlugin::Complete(CFsRequest* aRequest, TInt aError)
sl@0
   384
	{
sl@0
   385
	CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
sl@0
   386
sl@0
   387
	CFsPlugin* plugin = msgRequest.iOwnerPlugin;
sl@0
   388
	if (plugin)
sl@0
   389
		{
sl@0
   390
		plugin->iLastError = aError;
sl@0
   391
		plugin->iThreadP->OperationLockSignal();
sl@0
   392
		msgRequest.iOwnerPlugin = NULL;
sl@0
   393
		return CFsRequest::EReqActionComplete;
sl@0
   394
		}
sl@0
   395
sl@0
   396
	TMsgOperation& currentOperation = msgRequest.CurrentOperation();
sl@0
   397
sl@0
   398
	if (currentOperation.iState == 0)	// waiting ?
sl@0
   399
		{
sl@0
   400
		currentOperation.iState = 1;
sl@0
   401
		msgRequest.iCurrentPlugin->iThreadP->OperationLockSignal();
sl@0
   402
		// DON'T dispatch message again, DON'T complete message
sl@0
   403
		return CFsRequest::EReqActionOwnedByPlugin;	
sl@0
   404
		}
sl@0
   405
	else
sl@0
   406
		{
sl@0
   407
		return CFsRequest::EReqActionComplete;
sl@0
   408
		}
sl@0
   409
	}
sl@0
   410
sl@0
   411
/** @prototype */
sl@0
   412
TInt CFsPlugin::Complete(CFsRequest* aRequest)
sl@0
   413
	{
sl@0
   414
	return CFsPlugin::Complete(aRequest, KErrNone);
sl@0
   415
	}
sl@0
   416
sl@0
   417
/** @prototype */
sl@0
   418
EXPORT_C TInt CFsPlugin::ClientWrite(TFsPluginRequest& aRequest, const TDesC8& aDes, TInt aOffset)
sl@0
   419
	{
sl@0
   420
	CFsMessageRequest& msgRequest = * (CFsMessageRequest*) aRequest.Request();
sl@0
   421
	TMsgOperation& currentOperation = msgRequest.CurrentOperation();
sl@0
   422
	
sl@0
   423
	TInt r = KErrNone;
sl@0
   424
	if (currentOperation.iClientRequest)
sl@0
   425
		{
sl@0
   426
		r = msgRequest.Write(0, aDes, aOffset);
sl@0
   427
		}
sl@0
   428
	else
sl@0
   429
		{
sl@0
   430
		TInt len = aDes.Length();
sl@0
   431
		if (len > (currentOperation.iReadWriteArgs.iTotalLength - aOffset))
sl@0
   432
			return KErrArgument;
sl@0
   433
		memcpy(((TUint8*) currentOperation.iReadWriteArgs.iData) + aOffset, aDes.Ptr(), len);
sl@0
   434
		currentOperation.iReadWriteArgs.iOffset = aOffset + len;
sl@0
   435
		}
sl@0
   436
	return r;
sl@0
   437
	}
sl@0
   438
sl@0
   439
/** @prototype */
sl@0
   440
EXPORT_C TInt CFsPlugin::ClientRead(TFsPluginRequest& aRequest, TDes8& aDes, TInt aOffset)
sl@0
   441
	{
sl@0
   442
	CFsMessageRequest& msgRequest = * (CFsMessageRequest*) aRequest.Request();
sl@0
   443
	TMsgOperation& currentOperation = msgRequest.CurrentOperation();
sl@0
   444
	
sl@0
   445
	TInt r = KErrNone;
sl@0
   446
	if (currentOperation.iClientRequest)
sl@0
   447
		{
sl@0
   448
		r = msgRequest.Read(0, aDes, aOffset);
sl@0
   449
		}
sl@0
   450
	else
sl@0
   451
		{
sl@0
   452
		TInt len = aDes.Length();
sl@0
   453
		if (len > (currentOperation.iReadWriteArgs.iTotalLength - aOffset))
sl@0
   454
			return KErrArgument;
sl@0
   455
		aDes.Copy ( (TUint8*) currentOperation.iReadWriteArgs.iData + aOffset, len );
sl@0
   456
		currentOperation.iReadWriteArgs.iOffset = aOffset + len;
sl@0
   457
		}
sl@0
   458
	return r;
sl@0
   459
	}
sl@0
   460
sl@0
   461
/**
sl@0
   462
Constructs a TFsPluginRequest object
sl@0
   463
@param	aReuqest	client's request, to be wrapped by TFsPluginRequest object
sl@0
   464
*/
sl@0
   465
EXPORT_C TFsPluginRequest::TFsPluginRequest(CFsRequest* aRequest)
sl@0
   466
 : iFsRequest(aRequest)
sl@0
   467
	{ }
sl@0
   468
sl@0
   469
/**
sl@0
   470
@return		The function of the request
sl@0
   471
*/
sl@0
   472
EXPORT_C TInt TFsPluginRequest::Function() const
sl@0
   473
	{ return(iFsRequest->Operation()->Function()); }
sl@0
   474
sl@0
   475
/**
sl@0
   476
@return		The drive number of the request
sl@0
   477
*/
sl@0
   478
EXPORT_C TInt TFsPluginRequest::DriveNumber() const
sl@0
   479
	{ return(iFsRequest->DriveNumber()); }
sl@0
   480
sl@0
   481
/**
sl@0
   482
@return		The source of the request (often the filename)
sl@0
   483
*/
sl@0
   484
EXPORT_C TParse& TFsPluginRequest::Src() const
sl@0
   485
	{ return(iFsRequest->Src()); }
sl@0
   486
sl@0
   487
/**
sl@0
   488
@return		The destination of the request (often the filename)
sl@0
   489
*/
sl@0
   490
EXPORT_C TParse& TFsPluginRequest::Dest() const
sl@0
   491
	{ return(iFsRequest->Dest()); }
sl@0
   492
sl@0
   493
/**
sl@0
   494
@return		The drive of the request
sl@0
   495
*/
sl@0
   496
EXPORT_C TDrive* TFsPluginRequest::Drive() const
sl@0
   497
	{ return(iFsRequest->Drive()); }
sl@0
   498
sl@0
   499
/**
sl@0
   500
@return		The substitude drive of the request
sl@0
   501
*/
sl@0
   502
EXPORT_C TDrive* TFsPluginRequest::SubstedDrive() const
sl@0
   503
	{ return(iFsRequest->SubstedDrive()); }
sl@0
   504
sl@0
   505
/**
sl@0
   506
@return		The message of the request
sl@0
   507
*/
sl@0
   508
EXPORT_C const RMessage2& TFsPluginRequest::Message() const
sl@0
   509
	{ return(iFsRequest->Message()); }
sl@0
   510
sl@0
   511
/**
sl@0
   512
@return		The request itself
sl@0
   513
*/
sl@0
   514
EXPORT_C CFsRequest* TFsPluginRequest::Request() const
sl@0
   515
	{
sl@0
   516
	__ASSERT_DEBUG(iFsRequest != NULL, User::Invariant());
sl@0
   517
	return iFsRequest; 
sl@0
   518
	}
sl@0
   519
sl@0
   520
/**
sl@0
   521
@return		The scratch value of the request
sl@0
   522
*/
sl@0
   523
EXPORT_C TUint TFsPluginRequest::ScratchValue() const
sl@0
   524
	{ return iFsRequest->ScratchValue(); }
sl@0
   525
sl@0
   526
/**
sl@0
   527
@return		The scratch value of the request
sl@0
   528
*/
sl@0
   529
EXPORT_C TInt64 TFsPluginRequest::ScratchValue64() const
sl@0
   530
	{ return iFsRequest->ScratchValue64(); }
sl@0
   531
sl@0
   532
/**
sl@0
   533
@return		ETrue if the operation is in Post-Intercept
sl@0
   534
*/
sl@0
   535
EXPORT_C TInt TFsPluginRequest::IsPostOperation() const
sl@0
   536
	{ return(iFsRequest->IsPostOperation()); }
sl@0
   537
sl@0
   538
sl@0
   539
EXPORT_C TInt TFsPluginRequest::Read(TF32ArgType aType, TDes8& aDes, TInt aOffset)
sl@0
   540
	{ 
sl@0
   541
	return(iFsRequest->Read(aType, aDes, aOffset));
sl@0
   542
	}
sl@0
   543
	
sl@0
   544
EXPORT_C TInt TFsPluginRequest::Read(TF32ArgType aType, TDes16& aDes, TInt aOffset)
sl@0
   545
	{ 
sl@0
   546
	//The following if packaged correctly will never come here
sl@0
   547
	//but just in case someone tries something wrong with a wonky wide descriptor 
sl@0
   548
	switch(aType)
sl@0
   549
		{
sl@0
   550
		case (TF32ArgType)EEntryArray:
sl@0
   551
		case (TF32ArgType)EEntry:
sl@0
   552
		case (TF32ArgType)EUid:
sl@0
   553
		case (TF32ArgType)ETime:
sl@0
   554
			return KErrBadDescriptor;
sl@0
   555
		default:
sl@0
   556
			break;
sl@0
   557
		}
sl@0
   558
	return(iFsRequest->Read(aType, aDes, aOffset));
sl@0
   559
	}
sl@0
   560
	
sl@0
   561
EXPORT_C TInt TFsPluginRequest::Read(TF32ArgType aType, TInt& aVal)
sl@0
   562
	{ 
sl@0
   563
	//
sl@0
   564
	// Some messages require special handling...
sl@0
   565
	//
sl@0
   566
	if(aType == (TF32ArgType)EPosition)
sl@0
   567
		{
sl@0
   568
		return KErrArgument;
sl@0
   569
		}
sl@0
   570
	
sl@0
   571
	return iFsRequest->Read(aType, aVal);
sl@0
   572
	}
sl@0
   573
	
sl@0
   574
EXPORT_C TInt TFsPluginRequest::Read(TF32ArgType aType, TUint& aVal)
sl@0
   575
	{ 
sl@0
   576
	//
sl@0
   577
	// Some messages require special handling...
sl@0
   578
	//
sl@0
   579
	if(aType == (TF32ArgType)EPosition)
sl@0
   580
		{
sl@0
   581
		return KErrArgument;
sl@0
   582
		}
sl@0
   583
	
sl@0
   584
	return iFsRequest->Read(aType, aVal);
sl@0
   585
	}
sl@0
   586
sl@0
   587
EXPORT_C TInt TFsPluginRequest::Read(TF32ArgType aType, TInt64& aVal)
sl@0
   588
	{
sl@0
   589
	TInt err = iFsRequest->Read(aType, aVal);
sl@0
   590
	if(err != KErrNone)
sl@0
   591
		return err;
sl@0
   592
sl@0
   593
	//
sl@0
   594
	// Some messages require special handling...
sl@0
   595
	//
sl@0
   596
	if(aType == (TF32ArgType)EPosition)
sl@0
   597
		{
sl@0
   598
		TInt op = Function();
sl@0
   599
		if(op == EFsFileRead || op == EFsFileWrite)
sl@0
   600
			{	
sl@0
   601
			if (aVal == KCurrentPosition64)
sl@0
   602
				{
sl@0
   603
				CFileShare* share = (CFileShare*)iFsRequest->ScratchValue();
sl@0
   604
				if(share == NULL)
sl@0
   605
					return KErrBadHandle;
sl@0
   606
			
sl@0
   607
				aVal = share->iPos;
sl@0
   608
				}
sl@0
   609
			}
sl@0
   610
		}
sl@0
   611
	
sl@0
   612
	return KErrNone;
sl@0
   613
	}
sl@0
   614
	
sl@0
   615
EXPORT_C TInt TFsPluginRequest::Write(TF32ArgType aType, const TDesC8& aDes, TInt aOffset)
sl@0
   616
	{ 
sl@0
   617
	return(iFsRequest->Write(aType, aDes, aOffset));
sl@0
   618
	}
sl@0
   619
	
sl@0
   620
sl@0
   621
EXPORT_C TInt TFsPluginRequest::Write(TF32ArgType aType, const TDesC16& aDes, TInt aOffset)
sl@0
   622
	{ 
sl@0
   623
	return(iFsRequest->Write(aType, aDes, aOffset));
sl@0
   624
	}
sl@0
   625
	
sl@0
   626
EXPORT_C TInt TFsPluginRequest::FileName(TDes& aName)
sl@0
   627
	{
sl@0
   628
	//Special handling required for directories.
sl@0
   629
	switch(Function())
sl@0
   630
		{
sl@0
   631
		case EFsDirOpen:
sl@0
   632
		case EFsSetEntry:
sl@0
   633
			{
sl@0
   634
			aName.Copy(Request()->Src().FullName());
sl@0
   635
			break;
sl@0
   636
			}
sl@0
   637
		case EFsDirReadOne:
sl@0
   638
		case EFsDirReadPacked:
sl@0
   639
		case EFsDirSubClose:
sl@0
   640
			{
sl@0
   641
			//Get the name from CDirCB::iName
sl@0
   642
			CDirCB* dir = (CDirCB*) ScratchValue();
sl@0
   643
			__ASSERT_ALWAYS(dir!= NULL, Fault(EPluginOpError));
sl@0
   644
			TName name = dir->Name();
sl@0
   645
			if(name.Size() == 0)
sl@0
   646
				{
sl@0
   647
				return KErrNotFound;
sl@0
   648
				}
sl@0
   649
			aName.Copy(name);
sl@0
   650
			break;
sl@0
   651
			}
sl@0
   652
		default:
sl@0
   653
			{
sl@0
   654
			CFileShare* share;
sl@0
   655
			TInt err = ShareFromClientHandle(share);
sl@0
   656
			if(err != KErrNone || share == NULL)
sl@0
   657
				return(err);
sl@0
   658
			
sl@0
   659
			NameFromShare(*share, aName);
sl@0
   660
			}
sl@0
   661
		}
sl@0
   662
	return KErrNone;
sl@0
   663
	}
sl@0
   664
sl@0
   665
EXPORT_C TInt TFsPluginRequest::SetSharePos(TInt64& aPos)
sl@0
   666
	{
sl@0
   667
	CFileShare* share;
sl@0
   668
	TInt err = ShareFromClientHandle(share);
sl@0
   669
	if(err != KErrNone || share == NULL)
sl@0
   670
		return(KErrBadHandle);
sl@0
   671
	
sl@0
   672
	share->File().Drive().Lock();
sl@0
   673
	share->iPos = aPos;
sl@0
   674
	share->File().Drive().UnLock();
sl@0
   675
	
sl@0
   676
	return KErrNone;
sl@0
   677
	}
sl@0
   678
sl@0
   679
TInt TFsPluginRequest::ShareFromClientHandle(CFileShare*& aShare)
sl@0
   680
	{
sl@0
   681
	aShare = NULL;
sl@0
   682
	
sl@0
   683
	TInt handle;
sl@0
   684
	TInt err = ClientSubSessionHandle(handle);
sl@0
   685
	if(err != KErrNone)
sl@0
   686
		return err;
sl@0
   687
sl@0
   688
	aShare = GetShareFromHandle(iFsRequest->Session(), handle);
sl@0
   689
	
sl@0
   690
	return aShare ? KErrNone : KErrBadHandle;
sl@0
   691
	}
sl@0
   692
sl@0
   693
TInt TFsPluginRequest::ClientSubSessionHandle(TInt& aHandle)
sl@0
   694
	{
sl@0
   695
	aHandle = 0;
sl@0
   696
sl@0
   697
	// Subsession handle is in Arg[3] for read/write etc, but 
sl@0
   698
	// when subsession create it's contained in client descriptor
sl@0
   699
	if(iFsRequest->Operation()->IsOpenSubSess())
sl@0
   700
		{
sl@0
   701
		if(!IsPostOperation())
sl@0
   702
			return KErrNotSupported;
sl@0
   703
sl@0
   704
		TPtr8 handleDes((TUint8*)&aHandle,sizeof(TInt));
sl@0
   705
		TInt err = iFsRequest->Read(KMsgPtr3,handleDes);
sl@0
   706
		if(err != KErrNone)
sl@0
   707
			return err;
sl@0
   708
		}
sl@0
   709
	else
sl@0
   710
		{
sl@0
   711
		aHandle = iFsRequest->Message().Int3(); 
sl@0
   712
		}
sl@0
   713
sl@0
   714
	return KErrNone;
sl@0
   715
	}
sl@0
   716
sl@0
   717
/**
sl@0
   718
@publishedPartner
sl@0
   719
sl@0
   720
Utility function to obtain the file name from a file share object
sl@0
   721
sl@0
   722
@param	aFileShare		A pointer to the file share
sl@0
   723
@param	aName			A reference to the descriptor to contain the file name
sl@0
   724
*/
sl@0
   725
void TFsPluginRequest::NameFromShare(CFileShare& aFileShare, TDes& aName)
sl@0
   726
	{
sl@0
   727
	CFileCB& theFile = aFileShare.File();
sl@0
   728
	aName = _L("?:");
sl@0
   729
	aName[0] = TText('A' + theFile.Drive().DriveNumber());
sl@0
   730
	aName.Append(theFile.FileName());
sl@0
   731
	}
sl@0
   732
sl@0
   733
sl@0
   734
/**
sl@0
   735
Constructor of plugin connection object
sl@0
   736
*/
sl@0
   737
EXPORT_C CFsPluginConn::CFsPluginConn()
sl@0
   738
	{
sl@0
   739
	}
sl@0
   740
sl@0
   741
/**
sl@0
   742
Destructor of plugin conn. object
sl@0
   743
*/
sl@0
   744
EXPORT_C CFsPluginConn::~CFsPluginConn()
sl@0
   745
	{
sl@0
   746
	}
sl@0
   747
sl@0
   748
/**
sl@0
   749
Closes the plugin conn. 
sl@0
   750
*/
sl@0
   751
EXPORT_C void CFsPluginConn::Close()
sl@0
   752
	{
sl@0
   753
	iRequestQue.DoCancelAll(KErrCancel);
sl@0
   754
	CFsObject::Close();
sl@0
   755
	}
sl@0
   756
sl@0
   757
CFsPluginConnRequest::CFsPluginConnRequest(CFsPluginConn* aPluginConn)
sl@0
   758
 : iPluginConn(*aPluginConn)
sl@0
   759
	{	
sl@0
   760
	}
sl@0
   761
	
sl@0
   762
TInt CFsPluginConnRequest::InitControl(CFsRequest* aRequest)
sl@0
   763
	{
sl@0
   764
	iMessage = aRequest->Message();
sl@0
   765
	const RMessage2& m = aRequest->Message();
sl@0
   766
	iFunction = m.Int0();
sl@0
   767
	iParam1 = (TDes8*)m.Ptr1();
sl@0
   768
	iParam2 = (TDes8*)m.Ptr2();
sl@0
   769
	return KErrNone;
sl@0
   770
	}
sl@0
   771
sl@0
   772
TInt CFsPluginConnRequest::DoControl()
sl@0
   773
	{	
sl@0
   774
	return iPluginConn.DoControl(*this);
sl@0
   775
	}
sl@0
   776
sl@0
   777
TInt CFsPluginConnRequest::InitRequest(CFsRequest* aRequest)
sl@0
   778
	{
sl@0
   779
	InitControl(aRequest);
sl@0
   780
	iPluginConn.iRequestQue.DoAddRequest(this);
sl@0
   781
	return KErrNone;
sl@0
   782
	}
sl@0
   783
	
sl@0
   784
void CFsPluginConnRequest::DoRequest()
sl@0
   785
	{	
sl@0
   786
	iPluginConn.DoRequest(*this);
sl@0
   787
	}
sl@0
   788
	
sl@0
   789
TPluginConnRequestQue::TPluginConnRequestQue()
sl@0
   790
	{
sl@0
   791
	iHeader.SetOffset(_FOFF(CFsPluginConnRequest,iLink));
sl@0
   792
	}
sl@0
   793
sl@0
   794
TPluginConnRequestQue::~TPluginConnRequestQue()
sl@0
   795
	{
sl@0
   796
	}
sl@0
   797
sl@0
   798
void TPluginConnRequestQue::DoAddRequest(CFsPluginConnRequest* aRequest)
sl@0
   799
	{
sl@0
   800
	iHeader.AddLast(*aRequest);
sl@0
   801
	}
sl@0
   802
sl@0
   803
/**
sl@0
   804
Cancels all the requests of plugin connection
sl@0
   805
sl@0
   806
@param		aCompletionCode: the code the request are completed 
sl@0
   807
*/
sl@0
   808
EXPORT_C void TPluginConnRequestQue::DoCancelAll(TInt aCompletionCode)
sl@0
   809
	{
sl@0
   810
	TDblQueIter<CFsPluginConnRequest> q(iHeader);
sl@0
   811
	CFsPluginConnRequest* info;
sl@0
   812
	while((info=q++)!=NULL)
sl@0
   813
		{
sl@0
   814
		info->Complete(aCompletionCode);
sl@0
   815
		}
sl@0
   816
	__ASSERT_DEBUG(iHeader.IsEmpty(),Fault(EBaseQueCancel));
sl@0
   817
	}
sl@0
   818
sl@0
   819
sl@0
   820
/**
sl@0
   821
*/
sl@0
   822
EXPORT_C TDes8& TRawEntryArray::Buf()
sl@0
   823
	{ return iBuf; }
sl@0
   824
sl@0
   825
/**
sl@0
   826
*/
sl@0
   827
EXPORT_C void TRawEntryArray::SetBuf(TDes8& aBuf)
sl@0
   828
	{
sl@0
   829
	iCount = KCountNeeded;
sl@0
   830
	iBuf.Copy(aBuf);
sl@0
   831
	}
sl@0
   832
sl@0
   833
/**
sl@0
   834
*/
sl@0
   835
EXPORT_C TInt TRawEntryArray::EntrySize(TInt aIdx)
sl@0
   836
	{ return Align4(::EntrySize((*this)[aIdx])); }