os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/exclusiveaccess_plugin.cpp
First public contribution.
1 // Copyright (c) 2007-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Template_plugin.cpp
18 #include "exclusiveaccess_plugin.h"
19 #include "plugincommon.h"
20 #include <f32pluginutils.h>
23 Leaving New function for the plugin
26 CExclusiveAccessPlugin* CExclusiveAccessPlugin::NewL()
28 CExclusiveAccessPlugin* self = new(ELeave) CExclusiveAccessPlugin;
29 CleanupStack::PushL(self);
37 Constructor for the plugin
40 CExclusiveAccessPlugin::CExclusiveAccessPlugin() : iInterceptsEnabled(EFalse),
46 void CExclusiveAccessPlugin::ConstructL()
51 The destructor for the plugin
54 CExclusiveAccessPlugin::~CExclusiveAccessPlugin()
60 Initialise the plugin.
63 void CExclusiveAccessPlugin::InitialiseL()
65 User::LeaveIfError(iFs.Connect());
66 CleanupClosePushL(iFs);
68 _LOG(_L("CExclusiveAccessPlugin InitialiseL"));
71 CleanupStack::Pop(); // iFs
75 Enable the plugin's intercepts.
78 void CExclusiveAccessPlugin::EnableInterceptsL()
80 if (iInterceptsEnabled) return;
82 User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
83 User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPrePostIntercept));
85 _LOG(_L("CExclusiveAccessPlugin : Enabled intercepts."));
87 iInterceptsEnabled = ETrue;
91 Disable the plugin's intercepts.
94 void CExclusiveAccessPlugin::DisableInterceptsL()
96 if (!iInterceptsEnabled) return;
98 User::LeaveIfError(UnregisterIntercept(EFsFileRead, EPrePostIntercept));
99 User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPrePostIntercept));
100 _LOG(_L("CExclusiveAccessPlugin : Disabled intercepts."));
102 iInterceptsEnabled = EFalse;
109 TInt CExclusiveAccessPlugin::DoRequestL(TFsPluginRequest& aRequest)
113 TInt function = aRequest.Function();
118 err = FsFileReadL(aRequest);
121 err = FsFileWriteL(aRequest);
124 //Only registered for Read/Write
131 /*Test to ensure that when a file has been opened for exclusive access,
132 * i.e. readonly, that froma plugin we can still read from it
134 TInt CExclusiveAccessPlugin::FsFileReadL(TFsPluginRequest& aRequest)
136 if(!aRequest.IsPostOperation()) // pre-operation
138 RFilePlugin file(aRequest);
140 TInt err = file.AdoptFromClient();
142 iLineNumber = __LINE__;
147 err = aRequest.Read(TFsPluginRequest::EPosition, pos); // get pos
149 iLineNumber = __LINE__;
154 err = aRequest.Read(TFsPluginRequest::ELength, length); //get length
156 iLineNumber = __LINE__;
163 //we should check that this file is in fact registered as read only?
164 //if not.. User::Invariant()?
166 RFsPlugin rfsplugin(aRequest);
167 err = rfsplugin.Connect();
169 iLineNumber = __LINE__;
174 err = aRequest.FileName(fileName);
176 iLineNumber = __LINE__;
180 err = rfsplugin.Entry(fileName, entry);
182 iLineNumber = __LINE__;
186 //can we read a readonly file? - should be fine.
188 err = file.Read(pos,data,length);
190 iLineNumber = __LINE__;
201 /*Test to ensure that when a file has been opened for exclusive access,
202 * i.e. readonly, that from a plugin we can still write to it regardless
204 TInt CExclusiveAccessPlugin::FsFileWriteL(TFsPluginRequest& aRequest)
206 if(!aRequest.IsPostOperation()) // pre-operation
208 //Make sure that the file is read only.
210 RFilePlugin file(aRequest);
211 TInt err = file.AdoptFromClient();
213 iLineNumber = __LINE__;
217 RFsPlugin rfsplugin(aRequest);
218 err = rfsplugin.Connect();
220 iLineNumber = __LINE__;
225 err = rfsplugin.Entry(aRequest.Src().FullName(), entry);
227 iLineNumber = __LINE__;
231 // if(!entry.IsReadOnly())
233 // //this test should only being being used for read only files.
234 // User::Invariant();
238 err = aRequest.Read(TFsPluginRequest::EPosition, pos); //get pos
240 iLineNumber = __LINE__;
245 err = aRequest.Read(TFsPluginRequest::ELength, length); //get length
247 iLineNumber = __LINE__;
252 err = aRequest.Read(TFsPluginRequest::EData, data); //get data to write
254 iLineNumber = __LINE__;
258 //Now test that we can actually write to this read-only file
259 //Should pass, kerrnone.
260 err = file.Write(pos,data,length);
262 iLineNumber = __LINE__;
268 //We've performed the efsfilewrite, so return kerrcompletion.
269 return KErrCompletion;
277 CFsPluginConn* CExclusiveAccessPlugin::NewPluginConnL()
279 return new(ELeave) CExclusiveAccessPluginConn();
283 //Synchronous RPlugin::DoControl
284 TInt CExclusiveAccessPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
288 //We can use this to set the drive
289 //We can store this as a member of this class.
290 TInt function = aRequest.Function();
291 TPckg<TInt> errCodeDes(iLastError);
292 TPckg<TInt> lineNumberDes(iLineNumber);
296 case KPluginGetError:
298 TRAP(err,aRequest.WriteParam1L(errCodeDes));
299 TRAP(err,aRequest.WriteParam2L(lineNumberDes));
310 TInt CExclusiveAccessPluginConn::DoControl(CFsPluginConnRequest& aRequest)
312 return ((CExclusiveAccessPlugin*)Plugin())->FsPluginDoControlL(aRequest);
315 void CExclusiveAccessPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
320 void CExclusiveAccessPluginConn::DoCancel(TInt /*aReqMask*/)
327 class CExclusiveAccessPluginFactory : public CFsPluginFactory
330 CExclusiveAccessPluginFactory();
331 virtual TInt Install();
332 virtual CFsPlugin* NewPluginL();
333 virtual CFsPlugin* NewPluginConnL();
334 virtual TInt UniquePosition();
338 Constructor for the plugin factory
341 CExclusiveAccessPluginFactory::CExclusiveAccessPluginFactory()
346 Install function for the plugin factory
349 TInt CExclusiveAccessPluginFactory::Install()
351 SetSupportedDrives(KPluginSupportAllDrives);
352 return(SetName(&KExclusiveAccessPluginName));
358 TInt CExclusiveAccessPluginFactory::UniquePosition()
360 return(KExclusiveAccessPos);
364 Plugin factory function
367 CFsPlugin* CExclusiveAccessPluginFactory::NewPluginL()
370 return CExclusiveAccessPlugin::NewL();
374 Plugin factory function
377 CFsPlugin* CExclusiveAccessPluginFactory::NewPluginConnL()
380 return CExclusiveAccessPlugin::NewL();
389 EXPORT_C CFsPluginFactory* CreateFileSystem()
391 return(new CExclusiveAccessPluginFactory());