os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_plugin_shim.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) 2008-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_shim.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "cl_std.h"
sl@0
    19
#include "sf_std.h"
sl@0
    20
sl@0
    21
/*******************************************************
sl@0
    22
*						RFsPlugin					   *
sl@0
    23
*******************************************************/
sl@0
    24
sl@0
    25
EXPORT_C RFsPlugin::RFsPlugin(TFsPluginRequest& aRequest, TBool aDirectToDrive)
sl@0
    26
  : iSessionHelper(&aRequest, aDirectToDrive)
sl@0
    27
	{
sl@0
    28
	SetReturnedHandle(KNullHandle);
sl@0
    29
	}
sl@0
    30
sl@0
    31
EXPORT_C RFsPlugin::~RFsPlugin()
sl@0
    32
	{
sl@0
    33
	Close();
sl@0
    34
	}
sl@0
    35
sl@0
    36
EXPORT_C TInt RFsPlugin::Connect()
sl@0
    37
/**
sl@0
    38
Connects a file server plugin to the file server.
sl@0
    39
sl@0
    40
To end the file server session, use Close().
sl@0
    41
sl@0
    42
@return KErrNone, if successful, otherwise one of the other system-wide error codes.
sl@0
    43
*/
sl@0
    44
	{
sl@0
    45
	return KErrNone;
sl@0
    46
	}
sl@0
    47
sl@0
    48
EXPORT_C void RFsPlugin::Close()
sl@0
    49
/**
sl@0
    50
Closes a file server plugin session.
sl@0
    51
*/
sl@0
    52
	{
sl@0
    53
	SetReturnedHandle(KNullHandle);
sl@0
    54
	}
sl@0
    55
sl@0
    56
EXPORT_C TInt RFsPlugin::Delete(const TDesC& aName)
sl@0
    57
/**
sl@0
    58
Deletes a single file.
sl@0
    59
sl@0
    60
@see RFs::Delete
sl@0
    61
*/
sl@0
    62
	{
sl@0
    63
	return(RFs::Delete(aName));
sl@0
    64
	}
sl@0
    65
sl@0
    66
EXPORT_C TInt RFsPlugin::Rename(const TDesC& aOldName,const TDesC& aNewName)
sl@0
    67
/**
sl@0
    68
Renames a single file or directory.
sl@0
    69
sl@0
    70
@see RFs::Rename
sl@0
    71
*/
sl@0
    72
	{
sl@0
    73
	return(RFs::Rename(aOldName, aNewName));
sl@0
    74
	}
sl@0
    75
sl@0
    76
EXPORT_C TInt RFsPlugin::Replace(const TDesC& aOldName,const TDesC& aNewName)
sl@0
    77
/**
sl@0
    78
Replaces a single file with another.
sl@0
    79
sl@0
    80
@see RFs::Replace
sl@0
    81
*/
sl@0
    82
	{
sl@0
    83
	return(RFs::Replace(aOldName, aNewName));
sl@0
    84
	}
sl@0
    85
sl@0
    86
EXPORT_C TInt RFsPlugin::Entry(const TDesC& aName,TEntry& aEntry) const
sl@0
    87
/**
sl@0
    88
Gets the entry details for a file or directory.
sl@0
    89
sl@0
    90
@see RFs::Entry
sl@0
    91
*/
sl@0
    92
	{
sl@0
    93
	return(RFs::Entry(aName, aEntry));
sl@0
    94
	}
sl@0
    95
sl@0
    96
EXPORT_C TInt RFsPlugin::SetEntry(const TDesC& aName,const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask)
sl@0
    97
/**
sl@0
    98
Sets both the attributes and the last modified date and time for a file or directory.
sl@0
    99
sl@0
   100
@see RFs::SetEntry
sl@0
   101
*/
sl@0
   102
	{
sl@0
   103
	return(RFs::SetEntry(aName,aTime,aSetAttMask,aClearAttMask));
sl@0
   104
	}
sl@0
   105
sl@0
   106
EXPORT_C TInt RFsPlugin::ReadFileSection(const TDesC& aName,TInt64 aPos,TDes8& aDes,TInt aLength) const
sl@0
   107
/**
sl@0
   108
Reads data from a file without opening it.
sl@0
   109
sl@0
   110
The contents of the	file can be accessed regardless of the file's lock state.
sl@0
   111
sl@0
   112
@see RFs::ReadFileSection
sl@0
   113
*/
sl@0
   114
	{
sl@0
   115
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   116
	return(RFs::ReadFileSection(aName,I64LOW(aPos),aDes,aLength));
sl@0
   117
#else
sl@0
   118
	return(RFs::ReadFileSection(aName,aPos,aDes,aLength));
sl@0
   119
#endif
sl@0
   120
	}
sl@0
   121
sl@0
   122
EXPORT_C TInt RFsPlugin::Volume(TVolumeInfo &aVol, TInt aDrive) const
sl@0
   123
/**
sl@0
   124
Gets volume information for a formatted device.
sl@0
   125
sl@0
   126
@see RFs::Volume
sl@0
   127
*/
sl@0
   128
	{
sl@0
   129
	return (RFs::Volume(aVol, aDrive));
sl@0
   130
	}
sl@0
   131
sl@0
   132
TInt RFsPlugin::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
sl@0
   133
	{
sl@0
   134
	return iSessionHelper.SendReceive(aFunction, aArgs);
sl@0
   135
	}
sl@0
   136
sl@0
   137
TInt RFs::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
sl@0
   138
	{
sl@0
   139
	if(Handle())
sl@0
   140
		return RSessionBase::SendReceive(aFunction, aArgs);
sl@0
   141
sl@0
   142
	return ((RFsPlugin*) this)->SendReceive(aFunction, aArgs);
sl@0
   143
	}
sl@0
   144
sl@0
   145
sl@0
   146
/*******************************************************
sl@0
   147
*						RFilePlugin					   *
sl@0
   148
*******************************************************/
sl@0
   149
sl@0
   150
EXPORT_C RFilePlugin::RFilePlugin(TFsPluginRequest& aRequest, TBool aDirectToDrive)
sl@0
   151
  : iSessionHelper(&aRequest, aDirectToDrive)
sl@0
   152
	{
sl@0
   153
	SetHandle(KErrBadHandle);
sl@0
   154
	SetSubSessionHandle(KErrBadHandle);
sl@0
   155
	}
sl@0
   156
sl@0
   157
EXPORT_C RFilePlugin::~RFilePlugin()
sl@0
   158
	{
sl@0
   159
	Close();
sl@0
   160
	}
sl@0
   161
sl@0
   162
EXPORT_C TInt RFilePlugin::Open(const TDesC& aName,TUint aMode)
sl@0
   163
/**
sl@0
   164
Opens an existing file for reading or writing.
sl@0
   165
sl@0
   166
If the file does not already exist, an error is returned.
sl@0
   167
sl@0
   168
@see RFile::Open
sl@0
   169
*/
sl@0
   170
	{
sl@0
   171
	RFs fs;
sl@0
   172
	fs.SetHandle(Session().Handle());
sl@0
   173
	return(CreateSubSession(fs,EFsFileOpen,TIpcArgs(&aName,aMode)));
sl@0
   174
	}
sl@0
   175
sl@0
   176
EXPORT_C void RFilePlugin::Close()
sl@0
   177
/**
sl@0
   178
Closes the file.
sl@0
   179
sl@0
   180
@see RFile::Close
sl@0
   181
*/
sl@0
   182
	{
sl@0
   183
	CloseSubSession(EFsFileSubClose);
sl@0
   184
	SetSubSessionHandle(KErrBadHandle);
sl@0
   185
	}
sl@0
   186
sl@0
   187
EXPORT_C TInt RFilePlugin::Create(const TDesC& aName,TUint aFileMode)
sl@0
   188
/**
sl@0
   189
Closes the file.
sl@0
   190
sl@0
   191
@see RFile::Create
sl@0
   192
*/
sl@0
   193
	{
sl@0
   194
	RFs fs;
sl@0
   195
	fs.SetHandle(Session().Handle());
sl@0
   196
	return(CreateSubSession(fs,EFsFileCreate,TIpcArgs(&aName,aFileMode)));
sl@0
   197
	}
sl@0
   198
sl@0
   199
EXPORT_C TInt RFilePlugin::Replace(const TDesC& aName,TUint aFileMode)
sl@0
   200
/**
sl@0
   201
Closes the file.
sl@0
   202
sl@0
   203
@see RFile::Replace
sl@0
   204
*/
sl@0
   205
	{
sl@0
   206
	RFs fs;
sl@0
   207
	fs.SetHandle(Session().Handle());
sl@0
   208
	return(CreateSubSession(fs,EFsFileReplace,TIpcArgs(&aName,aFileMode)));
sl@0
   209
	}
sl@0
   210
sl@0
   211
EXPORT_C TInt RFilePlugin::Temp(const TDesC& aPath,TFileName& aName,TUint aFileMode)
sl@0
   212
/**
sl@0
   213
Closes the file.
sl@0
   214
sl@0
   215
@see RFile::Temp
sl@0
   216
*/
sl@0
   217
	{
sl@0
   218
	RFs fs;
sl@0
   219
	fs.SetHandle(Session().Handle());
sl@0
   220
	return(CreateSubSession(fs,EFsFileTemp,TIpcArgs(&aPath,aFileMode,&aName)));
sl@0
   221
	}
sl@0
   222
sl@0
   223
EXPORT_C TInt RFilePlugin::AdoptFromClient()
sl@0
   224
/**
sl@0
   225
Closes the file.
sl@0
   226
sl@0
   227
@see RFile::AdoptFromClient
sl@0
   228
*/
sl@0
   229
	{
sl@0
   230
	TFsPluginRequest* request = iSessionHelper.Request();
sl@0
   231
	if(request == NULL)
sl@0
   232
		return KErrBadHandle;
sl@0
   233
sl@0
   234
	TInt clientSubSessionHandle;
sl@0
   235
	TInt err = request->ClientSubSessionHandle(clientSubSessionHandle);
sl@0
   236
	if (err != KErrNone)
sl@0
   237
		return err;
sl@0
   238
sl@0
   239
	RFs fs;
sl@0
   240
	fs.SetHandle(Session().Handle());
sl@0
   241
	err = CreateSubSession(fs,EFsFileDuplicate, TIpcArgs(clientSubSessionHandle, ETrue));
sl@0
   242
	if (err != KErrNone)
sl@0
   243
		return err;
sl@0
   244
sl@0
   245
	SetSubSessionHandle(SubSessionHandle() ^ KSubSessionMangleBit);
sl@0
   246
sl@0
   247
	return err;
sl@0
   248
	}
sl@0
   249
sl@0
   250
EXPORT_C TInt RFilePlugin::TransferToClient()
sl@0
   251
/**
sl@0
   252
Closes the file.
sl@0
   253
sl@0
   254
@see RFile::TransferToClient
sl@0
   255
*/
sl@0
   256
	{
sl@0
   257
	TFsPluginRequest* request = iSessionHelper.Request();
sl@0
   258
	if(request == NULL)
sl@0
   259
		return KErrBadHandle;
sl@0
   260
sl@0
   261
	// This doesn't behave like a standard duplicate as we're running in the context of the
sl@0
   262
	// client's session.  Instead, we can simply return our subsession handle to the client.
sl@0
   263
	TRAPD(err, request->Request()->WriteL(KMsgPtr3, TPckgC<TInt>(SubSessionHandle())));
sl@0
   264
sl@0
   265
	// Next we have to free up the close request reserved for our internal subsession
sl@0
   266
	// otherwise two messages will be reserved for the client...
sl@0
   267
	RequestAllocator::OpenSubFailed(request->Request()->Session());
sl@0
   268
sl@0
   269
	// And now we're done - we don't bother closing, as the client now completely owns the handle
sl@0
   270
	SetSubSessionHandle(KErrBadHandle);
sl@0
   271
sl@0
   272
	return err;
sl@0
   273
	}
sl@0
   274
sl@0
   275
EXPORT_C TInt RFilePlugin::Write(TInt64 aPos, const TDesC8& aDes)
sl@0
   276
/**
sl@0
   277
Writes to the file at the specified offset within the file
sl@0
   278
sl@0
   279
@see RFile::Write
sl@0
   280
*/
sl@0
   281
	{
sl@0
   282
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   283
	return RFile::Write(I64LOW(aPos), aDes);
sl@0
   284
#else
sl@0
   285
	return RFile64::Write(aPos, aDes);
sl@0
   286
#endif
sl@0
   287
	}
sl@0
   288
sl@0
   289
EXPORT_C TInt RFilePlugin::Write(TInt64 aPos,const TDesC8& aDes,TInt aLen)
sl@0
   290
/**
sl@0
   291
Writes the specified number of bytes to the file at the specified offset within the file.
sl@0
   292
sl@0
   293
@see RFile::Write
sl@0
   294
*/
sl@0
   295
	{
sl@0
   296
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   297
	return RFile::Write(I64LOW(aPos), aDes, aLen);
sl@0
   298
#else
sl@0
   299
	return RFile64::Write(aPos, aDes, aLen);
sl@0
   300
#endif
sl@0
   301
	}
sl@0
   302
sl@0
   303
EXPORT_C TInt RFilePlugin::Read(TInt64 aPos,TDes8& aDes) const
sl@0
   304
/**
sl@0
   305
Reads from the file at the specified offset within the file
sl@0
   306
sl@0
   307
@see RFile::Read
sl@0
   308
*/
sl@0
   309
	{
sl@0
   310
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   311
	return RFile::Read(I64LOW(aPos), aDes);
sl@0
   312
#else
sl@0
   313
	return RFile64::Read(aPos, aDes);
sl@0
   314
#endif
sl@0
   315
	}
sl@0
   316
sl@0
   317
EXPORT_C TInt RFilePlugin::Read(TInt64 aPos,TDes8& aDes,TInt aLen) const
sl@0
   318
/**
sl@0
   319
Reads the specified number of bytes of binary data from the file at a specified
sl@0
   320
offset within the file.
sl@0
   321
sl@0
   322
@see RFile::Read
sl@0
   323
*/
sl@0
   324
	{
sl@0
   325
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   326
	return RFile::Read(I64LOW(aPos), aDes, aLen);
sl@0
   327
#else
sl@0
   328
	return RFile64::Read(aPos, aDes, aLen);
sl@0
   329
#endif
sl@0
   330
	}
sl@0
   331
sl@0
   332
EXPORT_C TInt RFilePlugin::Size(TInt64& aSize) const
sl@0
   333
/**
sl@0
   334
Gets the current file size.
sl@0
   335
sl@0
   336
@see RFile::Size
sl@0
   337
*/
sl@0
   338
	{
sl@0
   339
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   340
	TInt size = I64LOW(aSize);
sl@0
   341
	TInt err = RFile::Size(size);
sl@0
   342
	aSize = size;
sl@0
   343
	return err;
sl@0
   344
#else
sl@0
   345
	return RFile64::Size(aSize);
sl@0
   346
#endif
sl@0
   347
	}
sl@0
   348
sl@0
   349
EXPORT_C TInt RFilePlugin::SetSize(TInt64 aSize)
sl@0
   350
/**
sl@0
   351
Sets the file size.
sl@0
   352
sl@0
   353
@see RFile::SetSize
sl@0
   354
*/
sl@0
   355
	{
sl@0
   356
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   357
	return RFile::SetSize(I64LOW(aSize));
sl@0
   358
#else
sl@0
   359
	return RFile64::SetSize(aSize);
sl@0
   360
#endif
sl@0
   361
	}
sl@0
   362
sl@0
   363
EXPORT_C TInt RFilePlugin::Lock(TInt64 aPos, TInt64 aLength) const
sl@0
   364
/**
sl@0
   365
Locks a region within the file as defined by a range of bytes.
sl@0
   366
sl@0
   367
@see RFile::Lock
sl@0
   368
*/
sl@0
   369
	{
sl@0
   370
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   371
	return RFile::Lock(I64LOW(aPos), I64LOW(aLength));
sl@0
   372
#else
sl@0
   373
	return RFile64::Lock(aPos, aLength);
sl@0
   374
#endif
sl@0
   375
	}
sl@0
   376
sl@0
   377
EXPORT_C TInt RFilePlugin::UnLock(TInt64 aPos, TInt64 aLength) const
sl@0
   378
/**
sl@0
   379
Unlocks a region within the file as defined by a range of bytes.
sl@0
   380
sl@0
   381
@see RFile::UnLock
sl@0
   382
*/
sl@0
   383
	{
sl@0
   384
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   385
	return RFile::UnLock(I64LOW(aPos), I64LOW(aLength));
sl@0
   386
#else
sl@0
   387
	return RFile64::UnLock(aPos, aLength);
sl@0
   388
#endif
sl@0
   389
	}
sl@0
   390
sl@0
   391
EXPORT_C TInt RFilePlugin::Seek(TSeek aMode,TInt64& aPos) const
sl@0
   392
/**
sl@0
   393
Sets the the current file position.
sl@0
   394
sl@0
   395
@see RFile::Seek
sl@0
   396
*/
sl@0
   397
	{
sl@0
   398
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
   399
	TInt position = I64LOW(aPos);
sl@0
   400
	TInt err = RFile::Seek(aMode, position);
sl@0
   401
	if(err != KErrNone)
sl@0
   402
		return err;
sl@0
   403
	aPos = position;
sl@0
   404
	return KErrNone;
sl@0
   405
#else
sl@0
   406
	return RFile64::Seek(aMode, aPos);
sl@0
   407
#endif
sl@0
   408
	}
sl@0
   409
sl@0
   410
EXPORT_C TInt RFilePlugin::Flush()
sl@0
   411
/**
sl@0
   412
Commits data to the storage device and flushes internal buffers without closing
sl@0
   413
the file.
sl@0
   414
sl@0
   415
@see RFile::Flush
sl@0
   416
*/
sl@0
   417
	{
sl@0
   418
	return RFile::Flush();
sl@0
   419
	}
sl@0
   420
sl@0
   421
EXPORT_C TInt RFilePlugin::Att(TUint& aVal) const
sl@0
   422
/**
sl@0
   423
Gets the file's attributes.
sl@0
   424
sl@0
   425
@see RFile::Att
sl@0
   426
*/
sl@0
   427
	{
sl@0
   428
	return RFile::Att(aVal);
sl@0
   429
	}
sl@0
   430
sl@0
   431
EXPORT_C TInt RFilePlugin::SetAtt(TUint aSetAttMask,TUint aClearAttMask)
sl@0
   432
/**
sl@0
   433
Sets or clears file attributes using two bitmasks.
sl@0
   434
sl@0
   435
@see RFile::SetAtt
sl@0
   436
*/
sl@0
   437
	{
sl@0
   438
	return RFile::SetAtt(aSetAttMask, aClearAttMask);
sl@0
   439
	}
sl@0
   440
sl@0
   441
EXPORT_C TInt RFilePlugin::Modified(TTime& aTime) const
sl@0
   442
/**
sl@0
   443
Gets local date and time the file was last modified, in universal time.
sl@0
   444
sl@0
   445
@see RFile::Modified
sl@0
   446
*/
sl@0
   447
	{
sl@0
   448
	return RFile::Modified(aTime);
sl@0
   449
	}
sl@0
   450
sl@0
   451
EXPORT_C TInt RFilePlugin::SetModified(const TTime& aTime)
sl@0
   452
/**
sl@0
   453
Sets the date and time the file was last modified. UTC date and time should be used.
sl@0
   454
sl@0
   455
@see RFile::SetModified
sl@0
   456
*/
sl@0
   457
	{
sl@0
   458
	return RFile::SetModified(aTime);
sl@0
   459
	}
sl@0
   460
sl@0
   461
EXPORT_C TInt RFilePlugin::Set(const TTime& aTime,TUint aMask,TUint aVal)
sl@0
   462
/**
sl@0
   463
Sets the file’s attributes, and the date and time it was last modified.
sl@0
   464
sl@0
   465
@see RFile::Set
sl@0
   466
*/
sl@0
   467
	{
sl@0
   468
	return RFile::Set(aTime, aMask, aVal);
sl@0
   469
	}
sl@0
   470
sl@0
   471
EXPORT_C TInt RFilePlugin::ChangeMode(TFileMode aNewMode)
sl@0
   472
/**
sl@0
   473
Switches an open file's access mode between EFileShareExclusive and EFileShareReadersOnly.
sl@0
   474
sl@0
   475
@see RFile::ChangeMode
sl@0
   476
*/
sl@0
   477
	{
sl@0
   478
	return RFile::ChangeMode(aNewMode);
sl@0
   479
	}
sl@0
   480
sl@0
   481
EXPORT_C TInt RFilePlugin::Rename(const TDesC& aNewName)
sl@0
   482
/**
sl@0
   483
Renames a file.
sl@0
   484
sl@0
   485
@see RFile::Rename
sl@0
   486
*/
sl@0
   487
	{
sl@0
   488
	return RFile::Rename(aNewName);
sl@0
   489
	}
sl@0
   490
sl@0
   491
void RFilePlugin::SetHandle(TInt aHandle)
sl@0
   492
	{
sl@0
   493
	*(((TInt*) this) + 0) = aHandle;
sl@0
   494
	}
sl@0
   495
sl@0
   496
void RFilePlugin::SetSubSessionHandle(TInt aHandle)
sl@0
   497
	{
sl@0
   498
	*(((TInt*) this) + 1) = aHandle;
sl@0
   499
	}
sl@0
   500
sl@0
   501
TInt RFilePlugin::CreateSubSession(const RSessionBase& aSession, TInt aFunction, const TIpcArgs& aArgs)
sl@0
   502
	{
sl@0
   503
	TInt reply;
sl@0
   504
	TInt err = iSessionHelper.CreateSubSession(aSession, aFunction, aArgs, &reply);
sl@0
   505
	if(err == KErrNone)
sl@0
   506
		SetSubSessionHandle(reply);
sl@0
   507
	return(err);
sl@0
   508
	}
sl@0
   509
sl@0
   510
void RFilePlugin::CloseSubSession(TInt aFunction)
sl@0
   511
	{
sl@0
   512
	if (SubSessionHandle())
sl@0
   513
		{
sl@0
   514
		SendReceive(aFunction,TIpcArgs(TIpcArgs::ENothing,TIpcArgs::ENothing,TIpcArgs::ENothing,SubSessionHandle()));
sl@0
   515
		}
sl@0
   516
sl@0
   517
	SetHandle(KErrBadHandle);
sl@0
   518
	SetSubSessionHandle(KErrBadHandle);
sl@0
   519
	}
sl@0
   520
sl@0
   521
TInt RFilePlugin::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
sl@0
   522
	{
sl@0
   523
	return iSessionHelper.SendReceive(aFunction, aArgs, ((RFilePlugin*) this)->SubSessionHandle());
sl@0
   524
	}
sl@0
   525
sl@0
   526
TInt RFile::CreateSubSession(const RSessionBase& aSession,TInt aFunction,const TIpcArgs& aArgs)
sl@0
   527
	{
sl@0
   528
	if(SubSessionHandle() == KErrBadHandle)
sl@0
   529
		return ((RFilePlugin*) this)->CreateSubSession(aSession, aFunction, aArgs);
sl@0
   530
sl@0
   531
	return RSubSessionBase::CreateSubSession(aSession, aFunction, aArgs);
sl@0
   532
	}
sl@0
   533
sl@0
   534
void RFile::CloseSubSession(TInt aFunction)
sl@0
   535
	{
sl@0
   536
	if((Session().Handle() ^ CObjectIx::ENoClose) != KErrBadHandle)
sl@0
   537
		RSubSessionBase::CloseSubSession(aFunction);
sl@0
   538
	else
sl@0
   539
		((RFilePlugin*) this)->CloseSubSession(aFunction);
sl@0
   540
	}
sl@0
   541
sl@0
   542
TInt RFile::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
sl@0
   543
	{
sl@0
   544
	if((Session().Handle() ^ CObjectIx::ENoClose) != KErrBadHandle)
sl@0
   545
		return RSubSessionBase::SendReceive(aFunction, aArgs);
sl@0
   546
sl@0
   547
	return ((RFilePlugin*) this)->SendReceive(aFunction, aArgs);
sl@0
   548
	}
sl@0
   549
sl@0
   550
sl@0
   551
/*******************************************************
sl@0
   552
*						RDirPlugin					   *
sl@0
   553
*******************************************************/
sl@0
   554
sl@0
   555
EXPORT_C RDirPlugin::RDirPlugin(TFsPluginRequest& aRequest, TBool aDirectToDrive)
sl@0
   556
  : iSessionHelper(&aRequest, aDirectToDrive)
sl@0
   557
	{
sl@0
   558
	SetHandle(KErrBadHandle);
sl@0
   559
	SetSubSessionHandle(KErrBadHandle);
sl@0
   560
	}
sl@0
   561
sl@0
   562
EXPORT_C RDirPlugin::~RDirPlugin()
sl@0
   563
	{
sl@0
   564
	Close();
sl@0
   565
	}
sl@0
   566
sl@0
   567
EXPORT_C TInt RDirPlugin::Open(const TDesC& aMatchName,const TUidType& aUidType)
sl@0
   568
/**
sl@0
   569
Opens a directory using the specified UID type to filter the
sl@0
   570
directory entry types that will subsequently be read.
sl@0
   571
sl@0
   572
@see RDir::Open
sl@0
   573
*/
sl@0
   574
	{
sl@0
   575
	RFs fs;
sl@0
   576
	fs.SetHandle(Session().Handle());
sl@0
   577
sl@0
   578
	TPckgC<TUidType> pckgUid(aUidType);
sl@0
   579
	return(CreateSubSession(fs,EFsDirOpen,TIpcArgs(&aMatchName,KEntryAttAllowUid,&pckgUid)));
sl@0
   580
	}
sl@0
   581
sl@0
   582
EXPORT_C TInt RDirPlugin::Open(const TDesC& aMatchName,TUint anAttMask)
sl@0
   583
/**
sl@0
   584
Opens a directory using an attribute bitmask to filter the directory entry
sl@0
   585
types that will subsequently be read.
sl@0
   586
sl@0
   587
@see RDir::Open
sl@0
   588
*/
sl@0
   589
	{
sl@0
   590
	RFs fs;
sl@0
   591
	fs.SetHandle(Session().Handle());
sl@0
   592
sl@0
   593
	TUidType uidType(TUid::Null(),TUid::Null(),TUid::Null());
sl@0
   594
	TPckgC<TUidType> pckgUid(uidType);
sl@0
   595
	return(CreateSubSession(fs,EFsDirOpen,TIpcArgs(&aMatchName,anAttMask,&pckgUid)));
sl@0
   596
	}
sl@0
   597
sl@0
   598
EXPORT_C void RDirPlugin::Close()
sl@0
   599
/**
sl@0
   600
Closes the the directory.
sl@0
   601
sl@0
   602
@see RDir::Close
sl@0
   603
*/
sl@0
   604
	{
sl@0
   605
	CloseSubSession(EFsDirSubClose);
sl@0
   606
	SetSubSessionHandle(KErrBadHandle);
sl@0
   607
	}
sl@0
   608
sl@0
   609
EXPORT_C TInt RDirPlugin::Read(TEntryArray& aArray)
sl@0
   610
/**
sl@0
   611
Reads all filtered directory entries into the specified array.
sl@0
   612
sl@0
   613
@see RDir::Read
sl@0
   614
*/
sl@0
   615
	{
sl@0
   616
	return RDir::Read(aArray);
sl@0
   617
	}
sl@0
   618
sl@0
   619
EXPORT_C TInt RDirPlugin::Read(TEntry& aEntry)
sl@0
   620
/**
sl@0
   621
Reads all filtered directory entries into the specified array.
sl@0
   622
sl@0
   623
@see RDir::Read
sl@0
   624
*/
sl@0
   625
	{
sl@0
   626
	return RDir::Read(aEntry);
sl@0
   627
	}
sl@0
   628
sl@0
   629
void RDirPlugin::SetHandle(TInt aHandle)
sl@0
   630
	{
sl@0
   631
	*(((TInt*) this) + 0) = aHandle;
sl@0
   632
	}
sl@0
   633
sl@0
   634
void RDirPlugin::SetSubSessionHandle(TInt aHandle)
sl@0
   635
	{
sl@0
   636
	*(((TInt*) this) + 1) = aHandle;
sl@0
   637
	}
sl@0
   638
sl@0
   639
TInt RDirPlugin::CreateSubSession(const RSessionBase& aSession, TInt aFunction, const TIpcArgs& aArgs)
sl@0
   640
	{
sl@0
   641
	TInt reply;
sl@0
   642
	TInt err = iSessionHelper.CreateSubSession(aSession, aFunction, aArgs, &reply);
sl@0
   643
	if(err == KErrNone)
sl@0
   644
		SetSubSessionHandle(reply);
sl@0
   645
	return(err);
sl@0
   646
	}
sl@0
   647
sl@0
   648
void RDirPlugin::CloseSubSession(TInt aFunction)
sl@0
   649
	{
sl@0
   650
	if (SubSessionHandle())
sl@0
   651
		{
sl@0
   652
		SendReceive(aFunction,TIpcArgs(TIpcArgs::ENothing,TIpcArgs::ENothing,TIpcArgs::ENothing,SubSessionHandle()));
sl@0
   653
		}
sl@0
   654
sl@0
   655
	SetHandle(KErrBadHandle);
sl@0
   656
	SetSubSessionHandle(KErrBadHandle);
sl@0
   657
	}
sl@0
   658
sl@0
   659
TInt RDirPlugin::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
sl@0
   660
	{
sl@0
   661
	return iSessionHelper.SendReceive(aFunction, aArgs, ((RDirPlugin*) this)->SubSessionHandle());
sl@0
   662
	}
sl@0
   663
sl@0
   664
TInt RDir::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
sl@0
   665
	{
sl@0
   666
	if((Session().Handle() ^ CObjectIx::ENoClose) != KErrBadHandle)
sl@0
   667
		return RSubSessionBase::SendReceive(aFunction, aArgs);
sl@0
   668
sl@0
   669
	return ((RDirPlugin*) this)->SendReceive(aFunction, aArgs);
sl@0
   670
	}
sl@0
   671
sl@0
   672
sl@0
   673
/*******************************************************
sl@0
   674
*				TFsPluginSessionHelper				   *
sl@0
   675
*******************************************************/
sl@0
   676
sl@0
   677
TPluginSessionHelper::TPluginSessionHelper()
sl@0
   678
	{ memclr(this, sizeof(TPluginSessionHelper)); }
sl@0
   679
sl@0
   680
TPluginSessionHelper::TPluginSessionHelper(TFsPluginRequest* aRequest, TBool aDirectToDrive)
sl@0
   681
  : iPlugin(aRequest->Request()->iCurrentPlugin),
sl@0
   682
	iSession(aRequest->Request()->Session()),
sl@0
   683
	iDirectToDrive(aDirectToDrive),
sl@0
   684
    iRequest(aRequest)
sl@0
   685
	{
sl@0
   686
	// need to initialise RLocalMessage with client session
sl@0
   687
	*((RMessage2*) &iMessage) = aRequest->Message();
sl@0
   688
	iMessage.InitHandle();	// set handle to KLocalMessageHandle
sl@0
   689
	memclr(iSpare, sizeof(iSpare));
sl@0
   690
	}
sl@0
   691
sl@0
   692
TInt TPluginSessionHelper::CreateSubSession(const RSessionBase& aSession, TInt aFunction, const TIpcArgs& aArgs, TInt* aReply)
sl@0
   693
	{
sl@0
   694
	(void)aSession;
sl@0
   695
sl@0
   696
	// Init message
sl@0
   697
	TIpcArgs args;
sl@0
   698
	args.iArgs[0] = aArgs.iArgs[0];
sl@0
   699
	args.iArgs[1] = aArgs.iArgs[1];
sl@0
   700
	args.iArgs[2] = aArgs.iArgs[2];
sl@0
   701
	args.iFlags = aArgs.iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
sl@0
   702
sl@0
   703
	TPckgBuf<TInt> reply;
sl@0
   704
	args.Set(3,&reply);
sl@0
   705
sl@0
   706
	// copy session pointer
sl@0
   707
	RLocalMessage message = iMessage;
sl@0
   708
	message.SetFunction(aFunction);
sl@0
   709
	message.SetArgs(args);
sl@0
   710
sl@0
   711
	TInt err = Dispatch(aFunction, args);
sl@0
   712
	if (err == KErrNone)
sl@0
   713
		*aReply = reply();
sl@0
   714
sl@0
   715
	return err;
sl@0
   716
	}
sl@0
   717
sl@0
   718
TInt TPluginSessionHelper::Dispatch(TInt aFunction, TIpcArgs& aArgs) const
sl@0
   719
	{
sl@0
   720
	// copy session pointer
sl@0
   721
	RLocalMessage message = iMessage;
sl@0
   722
	message.SetFunction(aFunction);
sl@0
   723
	message.SetArgs(aArgs);
sl@0
   724
sl@0
   725
	// allocate request
sl@0
   726
	CFsClientMessageRequest* newRequest;
sl@0
   727
	const TOperation& oP = OperationArray[aFunction & KIpcFunctionMask];
sl@0
   728
	TInt err = RequestAllocator::GetMessageRequest(oP, message, newRequest);
sl@0
   729
	if (err != KErrNone)
sl@0
   730
		return err;
sl@0
   731
sl@0
   732
	newRequest->Set(message, oP, iSession);
sl@0
   733
	
sl@0
   734
	//This is wrong. drive number is set in TFsXxx::initialise
sl@0
   735
	//newRequest->SetDrive(&TheDrives[iPlugin->Drive()]);
sl@0
   736
sl@0
   737
	newRequest->iCurrentPlugin = iPlugin;
sl@0
   738
	newRequest->iOwnerPlugin   = iPlugin;
sl@0
   739
	newRequest->iDirectToDrive = iDirectToDrive;
sl@0
   740
sl@0
   741
	newRequest->Dispatch();
sl@0
   742
sl@0
   743
	// NOTE : newRequest will be free'd by the File Server before completing the
sl@0
   744
	//        request so it's not safe to touch the request from now on...
sl@0
   745
	
sl@0
   746
	return(iPlugin->WaitForRequest());
sl@0
   747
	}
sl@0
   748
sl@0
   749
TInt TPluginSessionHelper::SendReceive(TInt aFunction, const TIpcArgs& aArgs, TInt aSubSessionHandle) const
sl@0
   750
	{
sl@0
   751
	// Init message
sl@0
   752
	TIpcArgs args;
sl@0
   753
	args.iArgs[0] = aArgs.iArgs[0];
sl@0
   754
	args.iArgs[1] = aArgs.iArgs[1];
sl@0
   755
	args.iArgs[2] = aArgs.iArgs[2];
sl@0
   756
	args.iFlags   = aArgs.iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
sl@0
   757
	args.iArgs[3] = aSubSessionHandle;
sl@0
   758
sl@0
   759
	return Dispatch(aFunction, args);
sl@0
   760
	}
sl@0
   761
sl@0
   762
TInt TPluginSessionHelper::SendReceive(TInt aFunction, const TIpcArgs& aArgs) const
sl@0
   763
	{
sl@0
   764
	// Init message
sl@0
   765
	TIpcArgs args;
sl@0
   766
	args.iArgs[0] = aArgs.iArgs[0];
sl@0
   767
	args.iArgs[1] = aArgs.iArgs[1];
sl@0
   768
	args.iArgs[2] = aArgs.iArgs[2];
sl@0
   769
	args.iArgs[3] = aArgs.iArgs[3];
sl@0
   770
	args.iFlags = aArgs.iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
sl@0
   771
sl@0
   772
	return Dispatch(aFunction, args);
sl@0
   773
	}
sl@0
   774
sl@0
   775
GLDEF_C void Panic(TClientPanic aPanic)
sl@0
   776
//
sl@0
   777
// Panic the current client with a file server client side panic.
sl@0
   778
//
sl@0
   779
	{
sl@0
   780
	User::Panic(_L("FS_PLUGIN_CLIENT panic"),aPanic);
sl@0
   781
	}
sl@0
   782