author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:34:56 +0100 | |
branch | RCL_3 |
changeset 44 | 3e88ff8f41d5 |
parent 43 | c1f20ce4abcf |
permissions | -rw-r--r-- |
0 | 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 |
||
44 | 156 |
FsPluginManager::LockChain(); |
0 | 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 |
||
44 | 212 |
FsPluginManager::LockChain(); |
0 | 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 |
{ |
|
44 | 222 |
if(aRequest->iCurrentPlugin == plugin) |
223 |
{ |
|
224 |
FsPluginManager::DismountPlugin(*pF,pos); |
|
225 |
aRequest->SetScratchValue(0); |
|
226 |
} |
|
0 | 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; |
|
44 | 253 |
FsPluginManager::LockChain(); |
0 | 254 |
TInt err = FsPluginManager::Plugin(plugin, aRequest->Message().Int2()); |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
if(err != KErrNone) //should be ok but just in case |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
{ |
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
FsPluginManager::UnlockChain(); |
0 | 258 |
return err; |
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
} |
0 | 260 |
|
261 |
TInt r = KErrNotFound; |
|
262 |
if(plugin) |
|
263 |
{ |
|
264 |
aRequest->WriteL(KMsgPtr0, plugin->Name()); |
|
265 |
r = KErrNone; |
|
266 |
} |
|
267 |
FsPluginManager::UnlockChain(); |
|
268 |
return r; |
|
269 |
} |
|
270 |
/** |
|
271 |
Open a plugin |
|
272 |
*/ |
|
273 |
TInt TFsPluginOpen::Initialise(CFsRequest* aRequest) |
|
274 |
{ |
|
275 |
TInt pluginPos = aRequest->Message().Int0(); |
|
276 |
CFsPlugin* pP = FsPluginManager::FindByUniquePosition(pluginPos); |
|
277 |
if(pP == NULL) |
|
278 |
return KErrNotFound; |
|
279 |
||
280 |
aRequest->iCurrentPlugin = pP; |
|
281 |
aRequest->SetDriveNumber(-1); |
|
282 |
||
283 |
RThread thread; |
|
284 |
aRequest->Message().Client(thread, EOwnerThread); |
|
285 |
aRequest->SetScratchValue((TUint)(thread.Id())); |
|
286 |
thread.Close(); |
|
287 |
||
288 |
return KErrNone; |
|
289 |
} |
|
290 |
||
291 |
/** |
|
292 |
open the plugin |
|
293 |
*/ |
|
294 |
TInt TFsPluginOpen::DoRequestL(CFsRequest* aRequest) |
|
295 |
{ |
|
296 |
TInt pluginPos = aRequest->Message().Int0(); |
|
297 |
CFsPluginConn* pC = FsPluginManager::CreatePluginConnL(pluginPos, aRequest->ScratchValue()); |
|
298 |
||
299 |
TInt handle = aRequest->Session()->Handles().AddL(pC,ETrue); |
|
300 |
TPtrC8 pH((TUint8*)&handle, sizeof(TInt)); |
|
301 |
aRequest->WriteL(KMsgPtr3, pH); |
|
302 |
aRequest->Session()->IncResourceCount(); |
|
303 |
||
304 |
return KErrNone; |
|
305 |
} |
|
306 |
||
307 |
/** |
|
308 |
Initialising the plugin control |
|
309 |
*/ |
|
310 |
LOCAL_C TInt InitPluginControl(CFsRequest* aRequest) |
|
311 |
{ |
|
312 |
CFsPluginConn* pC = FsPluginManager::GetPluginConnFromHandle(aRequest->Session(), aRequest->Message().Int3()); |
|
313 |
if(pC == NULL) |
|
314 |
return KErrBadHandle; |
|
315 |
||
316 |
aRequest->iCurrentPlugin = pC->Plugin(); |
|
317 |
aRequest->SetDriveNumber(-1); |
|
318 |
||
319 |
CFsPluginConnRequest* request = new CFsPluginConnRequest(pC); |
|
320 |
if(request == NULL) |
|
321 |
return KErrNoMemory; |
|
322 |
||
323 |
aRequest->SetScratchValue((TUint)request); |
|
324 |
return KErrNone; |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
Initialises the plugin control and gets the request |
|
329 |
*/ |
|
330 |
TInt TFsPluginDoControl::Initialise(CFsRequest* aRequest) |
|
331 |
{ |
|
332 |
TInt err = InitPluginControl(aRequest); |
|
333 |
if(err != KErrNone) |
|
334 |
return err; |
|
335 |
||
336 |
CFsPluginConnRequest* request = (CFsPluginConnRequest*)aRequest->ScratchValue(); |
|
337 |
return request->InitControl(aRequest); |
|
338 |
} |
|
339 |
||
340 |
/** |
|
341 |
does handle the control request |
|
342 |
*/ |
|
343 |
TInt TFsPluginDoControl::DoRequestL(CFsRequest* aRequest) |
|
344 |
{ |
|
345 |
CFsPluginConnRequest* pRequest = (CFsPluginConnRequest*)aRequest->ScratchValue(); |
|
346 |
TInt r = pRequest->DoControl(); |
|
347 |
delete pRequest; |
|
348 |
return r; |
|
349 |
} |
|
350 |
||
351 |
||
352 |
/** |
|
353 |
Initialises the request |
|
354 |
*/ |
|
355 |
TInt TFsPluginDoRequest::Initialise(CFsRequest* aRequest) |
|
356 |
{ |
|
357 |
TInt err = InitPluginControl(aRequest); |
|
358 |
if(err != KErrNone) |
|
359 |
return err; |
|
360 |
||
361 |
CFsPluginConnRequest* request = (CFsPluginConnRequest*)aRequest->ScratchValue(); |
|
362 |
return request->InitRequest(aRequest); |
|
363 |
} |
|
364 |
||
365 |
/** |
|
366 |
Handles the request adding it to the queue of the requests |
|
367 |
*/ |
|
368 |
TInt TFsPluginDoRequest::DoRequestL(CFsRequest* aRequest) |
|
369 |
{ |
|
370 |
CFsPluginConnRequest* pRequest = (CFsPluginConnRequest*)aRequest->ScratchValue(); |
|
371 |
pRequest->DoRequest(); |
|
372 |
return KErrNone; |
|
373 |
} |
|
374 |
||
375 |
/** |
|
376 |
Initialises the request |
|
377 |
*/ |
|
378 |
TInt TFsPluginDoCancel::Initialise(CFsRequest* aRequest) |
|
379 |
{ |
|
380 |
CFsPluginConn* pC = FsPluginManager::GetPluginConnFromHandle(aRequest->Session(), aRequest->Message().Int3()); |
|
381 |
if(pC == NULL) |
|
382 |
return KErrBadHandle; |
|
383 |
||
384 |
aRequest->iCurrentPlugin = pC->Plugin(); |
|
385 |
aRequest->SetDriveNumber(-1); |
|
386 |
aRequest->SetScratchValue((TUint)pC); |
|
387 |
||
388 |
return KErrNone; |
|
389 |
} |
|
390 |
||
391 |
/** |
|
392 |
Cancels the outstanding request |
|
393 |
*/ |
|
394 |
TInt TFsPluginDoCancel::DoRequestL(CFsRequest* aRequest) |
|
395 |
{ |
|
396 |
CFsPluginConn* pC = (CFsPluginConn*)aRequest->ScratchValue(); |
|
397 |
pC->DoCancel(aRequest->Message().Int0()); |
|
398 |
return KErrNone; |
|
399 |
} |
|
400 |