author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:34:56 +0100 | |
branch | RCL_3 |
changeset 44 | 3e88ff8f41d5 |
parent 41 | 0ffb4e86fcc9 |
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 |
// |
|
15 |
||
16 |
#include "sf_std.h" |
|
17 |
||
18 |
TInt TFsMkDir::DoRequestL(CFsRequest* aRequest) |
|
19 |
// |
|
20 |
// Make a directory path. |
|
21 |
// |
|
22 |
{ |
|
23 |
__PRINT(_L("TFsMkDir::DoRequestL(CFsRequest* aRequest)")); |
|
24 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
25 |
TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest); |
0 | 26 |
if(r != KErrNone) |
27 |
return r; |
|
28 |
||
29 |
r=aRequest->Drive()->CheckMount(); |
|
30 |
if (r!=KErrNone) |
|
31 |
return(r); |
|
32 |
||
33 |
if (aRequest->Src().IsRoot()) |
|
34 |
return(KErrAlreadyExists); |
|
35 |
||
36 |
TPtrC ptr; |
|
37 |
ptr.Set(aRequest->Src().Path().Ptr(), aRequest->Src().Path().Length()-1); |
|
38 |
if (ptr.Length()<=1) |
|
39 |
return(KErrBadName); |
|
40 |
||
41 |
if (IsIllegalFullName(aRequest->Src().FullName())) |
|
42 |
return(KErrBadName); |
|
43 |
||
44 |
if (aRequest->Message().Int1()) |
|
45 |
{ |
|
46 |
TLex lex(ptr); |
|
47 |
TFileName filename; |
|
48 |
FOREVER |
|
49 |
{ |
|
50 |
lex.Inc(); // Skip a delimiter |
|
51 |
TInt res=lex.Remainder().Locate(KPathDelimiter); |
|
52 |
if (res==KErrNotFound) |
|
53 |
break; |
|
54 |
||
55 |
lex.Inc(res); |
|
56 |
filename+=lex.MarkedToken(); |
|
57 |
lex.Mark(); |
|
58 |
TEntry entry; |
|
59 |
if ((r=aRequest->Drive()->Entry(filename,entry))==KErrNone) |
|
60 |
{ |
|
61 |
if (!entry.IsDir()) |
|
62 |
return(KErrAccessDenied); |
|
63 |
continue; |
|
64 |
} |
|
65 |
||
66 |
if (r!=KErrNotFound) |
|
67 |
return(r); |
|
68 |
||
69 |
if ((r=aRequest->Drive()->MkDir(filename))!=KErrNone) |
|
70 |
return(r); |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
return(aRequest->Drive()->MkDir(ptr)); |
|
75 |
} |
|
76 |
||
77 |
TInt TFsMkDir::Initialise(CFsRequest* aRequest) |
|
78 |
// |
|
79 |
// |
|
80 |
// |
|
81 |
{ |
|
82 |
TInt r=ParseSubstPtr0(aRequest,aRequest->Src()); |
|
83 |
if (r!=KErrNone) |
|
84 |
return(r); |
|
85 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysMkDir,&KCapFsPriMkDir,&KCapFsROMkDir, __PLATSEC_DIAGNOSTIC_STRING("Make Directory")); |
|
86 |
return(r); |
|
87 |
} |
|
88 |
||
89 |
||
90 |
TInt TFsRmDir::DoRequestL(CFsRequest* aRequest) |
|
91 |
// |
|
92 |
// Remove a directory. |
|
93 |
// |
|
94 |
{ |
|
95 |
__PRINT(_L("TFsRmDir::DoRequestL(CFsRequest* aRequest)")); |
|
96 |
if (aRequest->Src().IsRoot()) |
|
97 |
return(KErrInUse); |
|
98 |
if (IsIllegalFullName(aRequest->Src().FullName())) |
|
99 |
return(KErrBadName); |
|
100 |
TPtrC ptr; |
|
101 |
ptr.Set(aRequest->Src().Path().Ptr(), aRequest->Src().Path().Length()-1); |
|
102 |
return(aRequest->Drive()->RmDir(ptr)); |
|
103 |
} |
|
104 |
||
105 |
TInt TFsRmDir::Initialise(CFsRequest* aRequest) |
|
106 |
// |
|
107 |
// |
|
108 |
// |
|
109 |
{ |
|
110 |
TInt r=ParseSubstPtr0(aRequest,aRequest->Src()); |
|
111 |
if (r!=KErrNone) |
|
112 |
return(r); |
|
113 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysRmDir,&KCapFsPriRmDir,&KCapFsRORmDir, __PLATSEC_DIAGNOSTIC_STRING("Remove Directory")); |
|
114 |
return(r); |
|
115 |
} |
|
116 |
||
117 |
||
118 |
TInt TFsDelete::DoRequestL(CFsRequest* aRequest) |
|
119 |
// |
|
120 |
// Delete a file. |
|
121 |
// |
|
122 |
{ |
|
123 |
__PRINT(_L("TFsDelete::DoRequestL(CFsRequest* aRequest)")); |
|
124 |
return(aRequest->Drive()->Delete(aRequest->Src().FullName().Mid(2))); |
|
125 |
} |
|
126 |
||
127 |
TInt TFsDelete::Initialise(CFsRequest* aRequest) |
|
128 |
// |
|
129 |
// |
|
130 |
// |
|
131 |
{ |
|
132 |
TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src()); |
|
133 |
if (r!=KErrNone) |
|
134 |
return(r); |
|
135 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysDelete,&KCapFsPriDelete,&KCapFsRODelete, __PLATSEC_DIAGNOSTIC_STRING("Delete")); |
|
136 |
return(r); |
|
137 |
} |
|
138 |
||
139 |
||
140 |
TInt TFsRename::DoRequestL(CFsRequest* aRequest) |
|
141 |
// |
|
142 |
// Rename a file or directory. Wild cards not allowed. |
|
143 |
// |
|
144 |
{ |
|
145 |
__PRINT(_L("TFsRename::DoRequestL(CFsRequest* aRequest)")); |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest); |
0 | 147 |
if(r != KErrNone) |
148 |
return r; |
|
149 |
||
150 |
r = aRequest->Drive()->Rename(aRequest->Src().FullName().Mid(2),aRequest->Dest().FullName().Mid(2)); |
|
151 |
return (r); |
|
152 |
} |
|
153 |
||
154 |
TInt TFsRename::Initialise(CFsRequest* aRequest) |
|
155 |
// |
|
156 |
// |
|
157 |
// |
|
158 |
{ |
|
159 |
TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src()); |
|
160 |
if (r!=KErrNone) |
|
161 |
return(r); |
|
162 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysRename,&KCapFsPriRename,&KCapFsRORename, __PLATSEC_DIAGNOSTIC_STRING("File Server Rename")); |
|
163 |
if(r!=KErrNone) |
|
164 |
return(r); |
|
165 |
TDrive* pOldDrive=aRequest->Drive(); |
|
166 |
if ((r=ParseNoWildSubstCheckPathPtr1(aRequest,aRequest->Dest()))!=KErrNone) |
|
167 |
return(r); |
|
168 |
r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysRename,&KCapFsPriRename,&KCapFsRORename, __PLATSEC_DIAGNOSTIC_STRING("File Server Rename")); |
|
169 |
if(r == KErrNone) |
|
170 |
{ |
|
171 |
if (pOldDrive!=aRequest->Drive()) |
|
172 |
r=KErrArgument; |
|
173 |
} |
|
174 |
return(r); |
|
175 |
} |
|
176 |
||
177 |
||
178 |
TInt TFsReplace::DoRequestL(CFsRequest* aRequest) |
|
179 |
// |
|
180 |
// Replace an old file with a new file atomically |
|
181 |
// |
|
182 |
{ |
|
183 |
__PRINT(_L("TFsReplace::DoRequestL(CFsRequest* aRequest)")); |
|
184 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest); |
0 | 186 |
if(r != KErrNone) |
187 |
return r; |
|
188 |
||
189 |
return(aRequest->Drive()->Replace(aRequest->Src().FullName().Mid(2),aRequest->Dest().FullName().Mid(2))); |
|
190 |
} |
|
191 |
||
192 |
TInt TFsReplace::Initialise(CFsRequest* aRequest) |
|
193 |
// |
|
194 |
// |
|
195 |
// |
|
196 |
{ |
|
197 |
TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src()); |
|
198 |
if (r!=KErrNone) |
|
199 |
return(r); |
|
200 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysReplace,&KCapFsPriReplace,&KCapFsROReplace, __PLATSEC_DIAGNOSTIC_STRING("File Server Replace")); |
|
201 |
if(r!=KErrNone) |
|
202 |
return(r); |
|
203 |
TDrive* pOldDrive=aRequest->Drive(); |
|
204 |
if ((r=ParseNoWildSubstCheckPtr1(aRequest,aRequest->Dest()))!=KErrNone) |
|
205 |
return(r); |
|
206 |
r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysReplace,&KCapFsPriReplace,&KCapFsROReplace, __PLATSEC_DIAGNOSTIC_STRING("File Server Replace")); |
|
207 |
if(r == KErrNone) |
|
208 |
{ |
|
209 |
if (pOldDrive!=aRequest->Drive()) |
|
210 |
r=KErrArgument; |
|
211 |
} |
|
212 |
return(r); |
|
213 |
} |
|
214 |
||
215 |
||
216 |
TInt TFsEntry::DoRequestL(CFsRequest* aRequest) |
|
217 |
// |
|
218 |
// Get all the entry details. |
|
219 |
// |
|
220 |
{ |
|
221 |
__PRINT(_L("TInt TFsEntry::DoRequestL(CFsRequest* aRequest)")); |
|
222 |
||
223 |
TEntry t; |
|
224 |
TPtrC filePath = aRequest->Src().FullName().Mid(2); |
|
225 |
TInt r=aRequest->Drive()->Entry(filePath,t); |
|
226 |
if (r!=KErrNone) |
|
227 |
return(r); |
|
228 |
||
229 |
TPckgC<TEntry> p(t); |
|
230 |
aRequest->WriteL(KMsgPtr1,p); |
|
231 |
return(KErrNone); |
|
232 |
} |
|
233 |
||
234 |
TInt TFsEntry::Initialise(CFsRequest* aRequest) |
|
235 |
// |
|
236 |
// |
|
237 |
// |
|
238 |
{ |
|
239 |
TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src()); |
|
240 |
if (r!=KErrNone) |
|
241 |
return(r); |
|
242 |
||
243 |
// Check the capabilites but always allow the entry to be read for private, system and |
|
244 |
// resource directories as long as there are no sub folders or files specified |
|
245 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsEntry, __PLATSEC_DIAGNOSTIC_STRING("Entry"), ETrue); |
|
246 |
||
247 |
return(r); |
|
248 |
} |
|
249 |
||
250 |
||
251 |
TInt TFsSetEntry::DoRequestL(CFsRequest* aRequest) |
|
252 |
// |
|
253 |
// Set the attributes and the modified date and time. |
|
254 |
// |
|
255 |
{ |
|
256 |
__PRINT(_L("TFsSetEntry::DoRequestL(CFsRequest* aRequest)")); |
|
257 |
||
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest); |
0 | 259 |
if(r != KErrNone) |
260 |
return r; |
|
261 |
||
262 |
TTime entryTime; |
|
263 |
TPckgBuf<TTime> timeBuf; |
|
264 |
aRequest->ReadL(KMsgPtr1,timeBuf); |
|
265 |
entryTime=timeBuf(); |
|
266 |
const RMessage2& msg = aRequest->Message(); |
|
267 |
||
268 |
return(aRequest->Drive()->SetEntry(aRequest->Src().FullName().Mid(2),entryTime,msg.Int2(),msg.Int3())); |
|
269 |
} |
|
270 |
||
271 |
||
272 |
TInt TFsSetEntry::Initialise(CFsRequest* aRequest) |
|
273 |
// |
|
274 |
// |
|
275 |
// |
|
276 |
{ |
|
277 |
TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src()); |
|
278 |
if (r!=KErrNone) |
|
279 |
return(r); |
|
280 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysSetEntry,&KCapFsPriSetEntry,&KCapFsROSetEntry, __PLATSEC_DIAGNOSTIC_STRING("Set Entry")); |
|
281 |
return(r); |
|
282 |
} |
|
283 |
||
284 |
LOCAL_C void FsReadFileSectionFileClose(CFsRequest* aRequest, CFileShare* aShare) |
|
285 |
{ |
|
286 |
aRequest->Session()->DecResourceCount(); |
|
287 |
TInt handle = aRequest->Session()->Handles().At(aShare, EFalse); |
|
288 |
aRequest->Session()->Handles().Remove(handle,ETrue); |
|
289 |
// close the file share |
|
290 |
aRequest->SetScratchValue64(0); |
|
291 |
} |
|
292 |
||
293 |
LOCAL_C CFileShare* FsReadFileSectionFileOpen(CFsRequest* aRequest) |
|
294 |
{ |
|
295 |
TInt handle; |
|
296 |
TUint32 mode = EFileShareReadersOrWriters | EFileRead | EFileReadAheadOff; |
|
297 |
||
298 |
TInt r = aRequest->Drive()->FileOpen(aRequest,handle,aRequest->Src().FullName().Mid(2),mode,EFileOpen); |
|
299 |
if (r!=KErrNone) |
|
300 |
return(NULL); |
|
301 |
||
302 |
CFileShare* share = (CFileShare*) SessionObjectFromHandle(handle, FileShares->UniqueID(), aRequest->Session()); |
|
303 |
||
304 |
aRequest->Session()->IncResourceCount(); |
|
305 |
||
306 |
CFileCB& file = share->File(); |
|
307 |
if (!file.FileCache()) |
|
308 |
{ |
|
309 |
FsReadFileSectionFileClose(aRequest, share); |
|
310 |
share = NULL; |
|
311 |
} |
|
312 |
return share; |
|
313 |
} |
|
314 |
||
315 |
TInt TFsReadFileSection::Complete(CFsRequest* aRequest) |
|
316 |
{ |
|
317 |
FsReadFileSectionFileClose(aRequest, (CFileShare*) aRequest->ScratchValue()); |
|
318 |
||
319 |
return CFsRequest::EReqActionComplete; |
|
320 |
} |
|
321 |
||
322 |
TInt TFsReadFileSection::DoRequestL(CFsRequest* aRequest) |
|
323 |
// |
|
324 |
// Read from a file regardless of lock state |
|
325 |
// |
|
326 |
{ |
|
327 |
__PRINT(_L("TFsReadFileSection::DoRequestL(CFsRequest* aRequest)")); |
|
328 |
||
329 |
TAny* pDes=(TAny*)(aRequest->Message().Ptr0()); |
|
330 |
TInt64 pos; |
|
331 |
if(aRequest->IsDescData(KMsgPtr2)) |
|
332 |
{ |
|
333 |
TPckg<TInt64> pkPos(pos); |
|
334 |
aRequest->ReadL(KMsgPtr2, pkPos); |
|
335 |
} |
|
336 |
else |
|
337 |
{ |
|
338 |
pos = MAKE_TINT64(0,aRequest->Message().Int2()); |
|
339 |
} |
|
340 |
TInt len=aRequest->Message().Int3(); |
|
341 |
||
342 |
// Try to open file so we can take advantage of file caching |
|
343 |
CFileShare* share = FsReadFileSectionFileOpen(aRequest); |
|
344 |
if (share) |
|
345 |
{ |
|
346 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest; |
|
347 |
__ASSERT_DEBUG(msgRequest.CurrentOperationPtr() == NULL, Fault(EBadOperationIndex)); |
|
348 |
CFileCB& file = share->File(); |
|
349 |
TInt64 size = file.Size64(); |
|
350 |
TInt r = KErrNone; |
|
351 |
if (pos > size) |
|
352 |
pos = size; |
|
353 |
if (pos + len > size) |
|
354 |
// filesize - pos shall of TInt size |
|
355 |
// Hence to suppress warning |
|
356 |
len = (TInt)(size - pos); |
|
357 |
if (len <= 0) |
|
358 |
r = KErrArgument; |
|
359 |
if (r == KErrNone) |
|
360 |
r = msgRequest.PushOperation(pos, len, (TDesC8*) pDes, 0, TFsReadFileSection::Complete, 0, EFsFileRead); |
|
361 |
msgRequest.SetState(CFsRequest::EReqStatePostInitialise); // DO call PostInitialise() |
|
362 |
if (r == KErrNone) |
|
363 |
{ |
|
364 |
aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) ); |
|
365 |
return CFsRequest::EReqActionBusy; // dispatch the request again |
|
366 |
} |
|
367 |
FsReadFileSectionFileClose(aRequest, share); |
|
368 |
} |
|
369 |
||
370 |
TInt r = KErrNone; |
|
371 |
if (len < 0) |
|
372 |
r = KErrArgument; |
|
373 |
else if (len > 0) |
|
374 |
r = aRequest->Drive()->ReadFileSection64(aRequest->Src().FullName().Mid(2),pos,pDes,len,aRequest->Message()); |
|
375 |
||
376 |
// zero return buffer, but only if we haven't written any data to it already, otherwise kernel's |
|
377 |
// writeback of descriptor length will conflict with that wrttien by media driver |
|
378 |
if (r != KErrNone || len == 0) |
|
379 |
aRequest->WriteL(KMsgPtr0,KNullDesC8); |
|
380 |
||
381 |
return r == KErrEof ? KErrNone : r; |
|
382 |
} |
|
383 |
||
384 |
||
385 |
TInt TFsReadFileSection::Initialise(CFsRequest* aRequest) |
|
386 |
// |
|
387 |
// |
|
388 |
// |
|
389 |
{ |
|
390 |
TInt r=ParseNoWildSubstFileCheckPtr1(aRequest,aRequest->Src()); |
|
391 |
if (r!=KErrNone) |
|
392 |
return(r); |
|
393 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysReadFileSection,&KCapFsPriReadFileSection, __PLATSEC_DIAGNOSTIC_STRING("Read File Section")); |
|
394 |
return(r); |
|
395 |
} |
|
396 |
||
397 |
||
398 |
||
399 |
TInt TFsCheckDisk::DoRequestL(CFsRequest* aRequest) |
|
400 |
// |
|
401 |
// Check the disk's integrity |
|
402 |
// |
|
403 |
{ |
|
404 |
||
405 |
__PRINT(_L("TFsCheckDisk::DoRequestL(CFsRequest* aRequest)")); |
|
406 |
||
407 |
// flush all files on this drive |
|
408 |
TInt r = aRequest->Drive()->FlushCachedFileInfo(); |
|
409 |
if (r == CFsRequest::EReqActionBusy) // ignore any flush errors |
|
410 |
return(r); |
|
411 |
||
412 |
return(aRequest->Drive()->CheckDisk()); |
|
413 |
} |
|
414 |
||
415 |
||
416 |
TInt TFsCheckDisk::Initialise(CFsRequest* aRequest) |
|
417 |
// |
|
418 |
// |
|
419 |
// |
|
420 |
{ |
|
421 |
if (!KCapFsCheckDisk.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("CheckDisk"))) |
|
422 |
return KErrPermissionDenied; |
|
423 |
return ParseSubstPtr0(aRequest,aRequest->Src()); //may make the rfs function call take a drive instead of path |
|
424 |
} |
|
425 |
||
426 |
TInt TFsScanDrive::DoRequestL(CFsRequest* aRequest) |
|
427 |
// |
|
428 |
// |
|
429 |
// |
|
430 |
{ |
|
431 |
__PRINT(_L("TFsScanDrive::DoRequestL(CFsRequest* aRequest)")); |
|
432 |
||
433 |
// flush all files on this drive |
|
434 |
TInt r = aRequest->Drive()->FlushCachedFileInfo(); |
|
435 |
if (r == CFsRequest::EReqActionBusy) // ignore any flush errors |
|
436 |
return(r); |
|
437 |
||
438 |
r=aRequest->Drive()->CheckMount(); |
|
439 |
if(r!=KErrNone) |
|
440 |
return(r); |
|
441 |
if (aRequest->Drive()->CurrentMount().LockStatus()<0) |
|
442 |
return(KErrInUse); |
|
443 |
r=aRequest->Drive()->ScanDrive(); |
|
444 |
// notify sessions since drive contents may have changed |
|
445 |
if(r==KErrNone) |
|
446 |
FsNotify::DiskChange(aRequest->DriveNumber()); |
|
447 |
return(r); |
|
448 |
} |
|
449 |
||
450 |
TInt TFsScanDrive::Initialise(CFsRequest* aRequest) |
|
451 |
// |
|
452 |
// |
|
453 |
// |
|
454 |
{ |
|
455 |
TInt r; |
|
456 |
if(!KCapFsScanDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("ScanDrive"))) |
|
457 |
return KErrPermissionDenied; |
|
458 |
r=ParseSubstPtr0(aRequest,aRequest->Src()); //may make the rfs function call take a drive instead of path |
|
459 |
return(r); //then no need for parse, just needs to check for susted and reject them |
|
460 |
} |
|
461 |
||
462 |
TInt TFsGetShortName::DoRequestL(CFsRequest* aRequest) |
|
463 |
// |
|
464 |
// Get the short name associated with a long file name |
|
465 |
// |
|
466 |
{ |
|
467 |
__PRINT(_L("TFsGetShortName::DoRequestL(CFsRequest* aRequest)")); |
|
468 |
TBuf<0x10> shortName; |
|
469 |
TInt r=aRequest->Drive()->GetShortName(aRequest->Src().FullName().Mid(2),shortName); |
|
470 |
if (r!=KErrNone) |
|
471 |
return(r); |
|
472 |
aRequest->WriteL(KMsgPtr1,shortName); |
|
473 |
return(KErrNone); |
|
474 |
} |
|
475 |
||
476 |
TInt TFsGetShortName::Initialise(CFsRequest* aRequest) |
|
477 |
// |
|
478 |
// |
|
479 |
// |
|
480 |
{ |
|
481 |
TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src()); |
|
482 |
if (r!=KErrNone) |
|
483 |
return(r); |
|
484 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysGetShortName,&KCapFsPriGetShortName, __PLATSEC_DIAGNOSTIC_STRING("Get Short Name")); |
|
485 |
return(r); |
|
486 |
} |
|
487 |
||
488 |
||
489 |
TInt TFsGetLongName::DoRequestL(CFsRequest* aRequest) |
|
490 |
// |
|
491 |
// Get the long name associated with a short file name |
|
492 |
// |
|
493 |
{ |
|
494 |
__PRINT(_L("TFsGetLongName::DoRequestL(CFsRequest* aRequest)")); |
|
495 |
TFileName longName; |
|
496 |
TInt r=aRequest->Drive()->GetLongName(aRequest->Src().FullName().Mid(2),longName); |
|
497 |
if (r!=KErrNone) |
|
498 |
return(r); |
|
499 |
aRequest->WriteL(KMsgPtr1,longName); |
|
500 |
return(KErrNone); |
|
501 |
} |
|
502 |
||
503 |
TInt TFsGetLongName::Initialise(CFsRequest* aRequest) |
|
504 |
// |
|
505 |
// |
|
506 |
// |
|
507 |
{ |
|
508 |
TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src()); |
|
509 |
if (r!=KErrNone) |
|
510 |
return(r); |
|
511 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysGetLongName,&KCapFsPriGetLongName, __PLATSEC_DIAGNOSTIC_STRING("Get Long Name")); |
|
512 |
return(r); |
|
513 |
} |
|
514 |
||
515 |
||
516 |
TInt TFsIsFileInRom::DoRequestL(CFsRequest* aRequest) |
|
517 |
// |
|
518 |
// Return the address of the file |
|
519 |
// |
|
520 |
{ |
|
521 |
||
522 |
__PRINT(_L("DoIsFileInRom")); |
|
523 |
TUint8* fileStart; |
|
524 |
TInt r=aRequest->Drive()->IsFileInRom(aRequest->Src().FullName().Mid(2),fileStart); |
|
525 |
if (r!=KErrNone) |
|
526 |
return(r); |
|
527 |
TPckgBuf<TUint8*> buf(fileStart); |
|
528 |
aRequest->WriteL(KMsgPtr1,buf); |
|
529 |
return(KErrNone); |
|
530 |
} |
|
531 |
||
532 |
TInt TFsIsFileInRom::Initialise(CFsRequest* aRequest) |
|
533 |
// |
|
534 |
// |
|
535 |
// |
|
536 |
{ |
|
537 |
TInt r=ParseNoWildSubstCheckPathPtr0(aRequest,aRequest->Src()); |
|
538 |
if (r!=KErrNone) |
|
539 |
return (r); |
|
540 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysIsFileInRom,&KCapFsPriIsFileInRom, __PLATSEC_DIAGNOSTIC_STRING("Is File In Rom")); |
|
541 |
return(r); |
|
542 |
} |
|
543 |
||
544 |
||
545 |
TInt TFsIsValidName::Initialise(CFsRequest* /*aRequest*/) |
|
546 |
// |
|
547 |
// |
|
548 |
// |
|
549 |
{ |
|
550 |
return(KErrNone); |
|
551 |
} |
|
552 |
||
553 |
||
554 |
TInt TFsIsValidName::DoRequestL(CFsRequest* aRequest) |
|
555 |
// |
|
556 |
// Determine whether the name is valid |
|
557 |
// If returnInvalidChar flag is set - determine the invalid character and |
|
558 |
// return it to the client |
|
559 |
// If TNameValidParam is specified determine the position of the invalid character |
|
560 |
// and return it to the client. |
|
561 |
{ |
|
562 |
__PRINT(_L("DoFsIsValidName")); |
|
563 |
||
564 |
TParse parse; |
|
565 |
const TAny* pParam = aRequest->Message().Ptr3(); |
|
566 |
if(pParam == NULL) |
|
567 |
{ |
|
568 |
// We need to call DoFsIsValidName to determine what the invalid character is |
|
569 |
TInt r=ParseSubstPtr0(aRequest,parse); |
|
570 |
if ((r!=KErrNone) && (r!=KErrBadName)) |
|
571 |
return(r); |
|
572 |
TBool retInvChar; |
|
573 |
TPckg<TBool> bPckg(retInvChar); |
|
574 |
aRequest->ReadL(KMsgPtr1,bPckg); |
|
575 |
if (!retInvChar) |
|
576 |
// Determine whether the name is invalid but don't bother finding out which |
|
577 |
// character (if any) is illegal |
|
578 |
{ |
|
579 |
TInt r=ParseNoWildSubstCheckPtr0(aRequest,parse); |
|
580 |
if ((r!=KErrNone) || IsIllegalFullName(parse.FullName().Mid(2))) |
|
581 |
return(KErrBadName); |
|
582 |
return(KErrNone); |
|
583 |
} |
|
584 |
else |
|
585 |
{ |
|
586 |
// Determine whether the name is invalid and return any offending character |
|
587 |
TText badChar=' '; |
|
588 |
TPckg<TText> pText(badChar); |
|
589 |
||
590 |
TInt r=ParseSubstPtr0(aRequest,parse); |
|
591 |
if (r==KErrBadName) // Name is > 256 characters or an illegal character |
|
592 |
{ // was encountered before path was completely parsed |
|
593 |
TFileName name; |
|
594 |
aRequest->ReadL(KMsgPtr0,name); |
|
595 |
TNameChecker checkName(name); |
|
596 |
checkName.IsIllegalChar(badChar); |
|
597 |
aRequest->WriteL(KMsgPtr2,pText); |
|
598 |
return(KErrBadName); |
|
599 |
} |
|
600 |
// Weed out invalid * or ? in the filename (or no name and extension at all) |
|
601 |
r=ParseNoWildSubstCheckPtr0(aRequest,parse); |
|
602 |
if (r==KErrBadName) |
|
603 |
{ |
|
604 |
if (parse.IsKMatchAny()) |
|
605 |
badChar=KMatchAny; // Offending character is '*' |
|
606 |
else if (parse.IsKMatchOne()) |
|
607 |
badChar=KMatchOne; // Offending character is '?' |
|
608 |
aRequest->WriteL(KMsgPtr2,pText); |
|
609 |
return(KErrBadName); |
|
610 |
} |
|
611 |
||
612 |
// Weed out any other outstanding illegal characters in filename or path |
|
613 |
TNameChecker checkName(parse.FullName().Mid(2)); |
|
614 |
if (checkName.IsIllegalName(badChar)) |
|
615 |
{ |
|
616 |
aRequest->WriteL(KMsgPtr2,pText); |
|
617 |
return(KErrBadName); |
|
618 |
} |
|
619 |
else // No invalid characters in name |
|
620 |
{ // Set badChar to '\0' |
|
621 |
badChar='\0'; |
|
622 |
aRequest->WriteL(KMsgPtr2,pText); |
|
623 |
return(KErrNone); |
|
624 |
} |
|
625 |
} |
|
626 |
} |
|
627 |
else //new API implementation |
|
628 |
{ |
|
629 |
RFs::TNameValidParam param; |
|
630 |
TPckg<RFs::TNameValidParam> paramPckg(param); |
|
631 |
aRequest->ReadL(KMsgPtr3,paramPckg); |
|
632 |
TUint nameLen=(TUint)aRequest->GetDesLength(KMsgPtr0); |
|
633 |
if(nameLen == 0)// a name must be specified |
|
634 |
{ |
|
635 |
param.iError = RFs::TNameValidParam::ErrBadName; |
|
636 |
param.iInvalidCharPos = 0; |
|
637 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
638 |
return KErrBadName; |
|
639 |
} |
|
640 |
if(param.iUseSessionPath) |
|
641 |
nameLen += aRequest->Session()->Path().Length(); |
|
642 |
if(nameLen > (TUint)KMaxFileName) |
|
643 |
{ |
|
644 |
param.iError = RFs::TNameValidParam::ErrNameTooLong; |
|
645 |
param.iInvalidCharPos = 0; |
|
646 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
647 |
return KErrBadName; |
|
648 |
} |
|
649 |
TFileName fileName; |
|
650 |
TInt driveLength = 2; |
|
651 |
TText badChar; |
|
652 |
TRAPD(r, aRequest->ReadL(KMsgPtr0,fileName)); |
|
653 |
if(KErrNone == r) |
|
654 |
{ |
|
655 |
r=ParseSubstPtr0(aRequest,parse,param.iUseSessionPath); |
|
656 |
if (KErrBadName == r) // An illegal character |
|
657 |
{ // was encountered before path was completely parsed |
|
658 |
TNameChecker checkName(fileName); |
|
659 |
if(checkName.IsIllegalChar(badChar)) |
|
660 |
{ |
|
661 |
param.iError = RFs::TNameValidParam::ErrBadCharacter; |
|
662 |
param.iInvalidCharPos = fileName.LocateReverse(badChar)+1; |
|
663 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
664 |
return KErrBadName; |
|
665 |
} |
|
666 |
param.iError = RFs::TNameValidParam::ErrBadName; |
|
667 |
param.iInvalidCharPos = 0; |
|
668 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
669 |
return KErrBadName; |
|
670 |
} |
|
671 |
// Weed out invalid * or ? in the filename |
|
672 |
r=ParseNoWildSubstPtr0(aRequest,parse,param.iUseSessionPath); |
|
673 |
if(KErrBadName == r) |
|
674 |
{ |
|
675 |
if(parse.IsWild()) |
|
676 |
{ |
|
677 |
if (parse.IsKMatchAny()) |
|
678 |
{// offending character is '*' |
|
679 |
param.iError = RFs::TNameValidParam::ErrBadCharacter; |
|
680 |
param.iInvalidCharPos = fileName.LocateReverse(KMatchAny)+1; |
|
681 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
682 |
return KErrBadName; |
|
683 |
} |
|
684 |
else if (parse.IsKMatchOne()) |
|
685 |
{//offending character is '?' |
|
686 |
param.iError = RFs::TNameValidParam::ErrBadCharacter; |
|
687 |
param.iInvalidCharPos = fileName.LocateReverse(KMatchOne)+1; |
|
688 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
689 |
return KErrBadName; |
|
690 |
} |
|
691 |
} |
|
692 |
param.iError = RFs::TNameValidParam::ErrBadName; |
|
693 |
param.iInvalidCharPos = 0; |
|
694 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
695 |
return KErrBadName; |
|
696 |
} |
|
697 |
if(!param.iUseSessionPath && !parse.DrivePresent()) |
|
698 |
driveLength = 0; |
|
699 |
// Weed out any other outstanding illegal characters in filename or path |
|
700 |
TNameChecker checkName(parse.FullName().Mid(driveLength)); |
|
701 |
badChar = ' '; |
|
702 |
if (checkName.IsIllegalName(badChar)) |
|
703 |
{ |
|
704 |
if(badChar == ' ') |
|
705 |
{ |
|
706 |
param.iError = RFs::TNameValidParam::ErrBadName; |
|
707 |
param.iInvalidCharPos = 0; |
|
708 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
709 |
return KErrBadName; |
|
710 |
} |
|
711 |
else |
|
712 |
{ |
|
713 |
if(badChar == '.') |
|
714 |
{ |
|
715 |
param.iError = RFs::TNameValidParam::ErrBadCharacter; |
|
716 |
param.iInvalidCharPos = fileName.Locate(badChar)+1; |
|
717 |
} |
|
718 |
else |
|
719 |
{ |
|
720 |
param.iError = RFs::TNameValidParam::ErrBadCharacter; |
|
721 |
param.iInvalidCharPos = fileName.LocateReverse(badChar)+1; |
|
722 |
} |
|
723 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
724 |
return KErrBadName; |
|
725 |
} |
|
726 |
} |
|
727 |
else // No invalid characters in name |
|
728 |
{ |
|
729 |
param.iError = RFs::TNameValidParam::ErrNone; |
|
730 |
param.iInvalidCharPos = 0; |
|
731 |
aRequest->WriteL(KMsgPtr3,paramPckg); |
|
732 |
return KErrNone; |
|
733 |
} |
|
734 |
} |
|
735 |
else |
|
736 |
return r;//read is not successful. |
|
737 |
} |
|
738 |
} |
|
739 |
||
740 |
||
741 |
TInt TFsLockDrive::DoRequestL(CFsRequest* aRequest) |
|
742 |
// |
|
743 |
// Lock media device |
|
744 |
// |
|
745 |
{ |
|
746 |
__PRINT(_L("TFsLockDrive::DoRequestL(CFsRequest* aRequest)")); |
|
747 |
TMediaPassword oldPw; |
|
748 |
TMediaPassword newPw; |
|
749 |
aRequest->ReadL(KMsgPtr1,oldPw); |
|
750 |
aRequest->ReadL(KMsgPtr2,newPw); |
|
751 |
return(aRequest->Drive()->LockDevice(oldPw,newPw,aRequest->Message().Int3())); |
|
752 |
} |
|
753 |
||
754 |
||
755 |
TInt TFsLockDrive::Initialise(CFsRequest* aRequest) |
|
756 |
// |
|
757 |
// |
|
758 |
// |
|
759 |
{ |
|
760 |
if (!KCapFsLockDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Lock Drive"))) |
|
761 |
return KErrPermissionDenied; |
|
762 |
TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest); |
|
763 |
return(r); |
|
764 |
} |
|
765 |
||
766 |
TInt TFsUnlockDrive::DoRequestL(CFsRequest* aRequest) |
|
767 |
// |
|
768 |
// Unlock media device |
|
769 |
// |
|
770 |
{ |
|
771 |
__PRINT(_L("TFsUnlockDrive::DoRequestL(CFsRequest* aRequest)")); |
|
772 |
TMediaPassword pW; |
|
773 |
aRequest->ReadL(KMsgPtr1,pW); |
|
774 |
return(aRequest->Drive()->UnlockDevice(pW,aRequest->Message().Int2())); |
|
775 |
} |
|
776 |
||
777 |
||
778 |
TInt TFsUnlockDrive::Initialise(CFsRequest* aRequest) |
|
779 |
// |
|
780 |
// |
|
781 |
// |
|
782 |
{ |
|
783 |
if (!KCapFsUnlockDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Unlock Drive"))) |
|
784 |
return KErrPermissionDenied; |
|
785 |
TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest); |
|
786 |
return(r); |
|
787 |
} |
|
788 |
||
789 |
TInt TFsClearPassword::DoRequestL(CFsRequest* aRequest) |
|
790 |
// |
|
791 |
// Clears password of media device |
|
792 |
// |
|
793 |
{ |
|
794 |
__PRINT(_L("TFsClearPassowrd::DoRequestL(CFsRequest* aRequest)")); |
|
795 |
TMediaPassword pW; |
|
796 |
aRequest->ReadL(KMsgPtr1,pW); |
|
797 |
return(aRequest->Drive()->ClearDevicePassword(pW)); |
|
798 |
} |
|
799 |
||
800 |
||
801 |
TInt TFsClearPassword::Initialise(CFsRequest* aRequest) |
|
802 |
// |
|
803 |
// |
|
804 |
// |
|
805 |
{ |
|
806 |
if (!KCapFsClearPassword.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Clear Password"))) |
|
807 |
return KErrPermissionDenied; |
|
808 |
return ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest); |
|
809 |
} |
|
810 |
||
811 |
TInt TFsErasePassword::DoRequestL(CFsRequest* aRequest) |
|
812 |
// |
|
813 |
// Erase the password from the media device |
|
814 |
// |
|
815 |
{ |
|
816 |
__PRINT(_L("TFsErasePassword::DoRequestL(CFsRequest* aRequest)")); |
|
817 |
return(aRequest->Drive()->EraseDevicePassword()); |
|
818 |
} |
|
819 |
||
820 |
||
821 |
TInt TFsErasePassword::Initialise(CFsRequest* aRequest) |
|
822 |
// |
|
823 |
// |
|
824 |
// |
|
825 |
{ |
|
826 |
if (!KCapFsErasePassword.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Erase Password"))) |
|
827 |
return KErrPermissionDenied; |
|
828 |
return ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest); |
|
829 |
||
830 |
} |
|
831 |
||
832 |
||
833 |
TInt TFsSessionToPrivate::DoRequestL(CFsRequest* aRequest) |
|
834 |
// |
|
835 |
// Set session path to the private directory (does not need to exist) |
|
836 |
// |
|
837 |
{ |
|
838 |
TBuf<30> pPath; |
|
839 |
pPath=_L("?:\\Private\\"); |
|
840 |
pPath[0]= (TText)('A'+ aRequest->Message().Int0()); |
|
841 |
pPath.AppendNumFixedWidth(aRequest->Message().SecureId().iId, EHex, 8); |
|
842 |
pPath += KSlash; |
|
843 |
HBufC* pP = pPath.Alloc(); |
|
844 |
if (pP==NULL) |
|
845 |
return KErrNoMemory; |
|
846 |
delete &aRequest->Session()->Path(); |
|
847 |
aRequest->Session()->SetPath(pP); |
|
848 |
return KErrNone; |
|
849 |
} |
|
850 |
||
851 |
||
852 |
TInt TFsSessionToPrivate::Initialise(CFsRequest* /*aRequest*/) |
|
853 |
// |
|
854 |
// standard initialisation |
|
855 |
// |
|
856 |
{ |
|
857 |
return KErrNone; |
|
858 |
} |
|
859 |
||
860 |
TInt TFsPrivatePath::DoRequestL(CFsRequest* aRequest) |
|
861 |
// |
|
862 |
// may be able to do this user side !!! |
|
863 |
// |
|
864 |
{ |
|
865 |
TSecureId appUID = aRequest->Message().SecureId(); |
|
866 |
TFileName pPath(KPrivateSlash); |
|
867 |
pPath.AppendNumFixedWidth(appUID.iId, EHex, 8); |
|
868 |
pPath += KSlash; |
|
869 |
aRequest->WriteL(KMsgPtr0,pPath); |
|
870 |
||
871 |
return KErrNone; |
|
872 |
||
873 |
} |
|
874 |
||
875 |
TInt TFsPrivatePath::Initialise(CFsRequest* /*aRequest*/) |
|
876 |
// |
|
877 |
// |
|
878 |
// |
|
879 |
{ |
|
880 |
return KErrNone; |
|
881 |
} |
|
882 |
||
883 |
||
884 |
TInt TFsCreatePrivatePath::DoRequestL(CFsRequest* aRequest) |
|
885 |
// |
|
886 |
// create the private path unless it already exists |
|
887 |
// |
|
888 |
{ |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
889 |
TInt ret = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest); |
0 | 890 |
if(ret != KErrNone) |
891 |
return ret; |
|
892 |
||
893 |
TBuf<30> pPath(KPrivate); |
|
894 |
pPath += KSlash; |
|
895 |
pPath.AppendNumFixedWidth(aRequest->Message().SecureId().iId, EHex, 8); |
|
896 |
TEntry e; |
|
897 |
ret=aRequest->Drive()->CheckMount(); |
|
898 |
if (ret!=KErrNone) |
|
899 |
return ret; |
|
900 |
||
901 |
//no point going mad on sanity check we know it's not root or a bad name |
|
902 |
ret =aRequest->Drive()->Entry(KPrivate(),e); |
|
903 |
if(ret != KErrNone) |
|
904 |
{ |
|
905 |
if(ret==KErrNotFound) |
|
906 |
{ |
|
907 |
ret = aRequest->Drive()->MkDir(KPrivate()); |
|
908 |
if(ret != KErrNone) |
|
909 |
return ret; |
|
910 |
} |
|
911 |
else |
|
912 |
return ret; |
|
913 |
} |
|
914 |
ret =aRequest->Drive()->Entry(pPath,e); |
|
915 |
if(ret==KErrPathNotFound || ret==KErrNotFound || !e.IsDir()) |
|
916 |
{ |
|
917 |
if((ret=aRequest->Drive()->MkDir(pPath ))!=KErrNone) |
|
918 |
return ret; |
|
919 |
} |
|
920 |
return ret; |
|
921 |
} |
|
922 |
||
923 |
||
924 |
TInt TFsCreatePrivatePath::Initialise(CFsRequest* aRequest) |
|
925 |
// |
|
926 |
// |
|
927 |
// |
|
928 |
{ |
|
929 |
TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest); |
|
930 |
return(r); |
|
931 |
} |
|
932 |
||
933 |
TInt TFsFinaliseDrive::DoRequestL(CFsRequest* aRequest) |
|
934 |
{ |
|
935 |
__PRINT(_L("TFsFinaliseDrive::DoRequestL")); |
|
936 |
||
937 |
TInt r=aRequest->Drive()->CheckMount(); |
|
938 |
if (r!=KErrNone) |
|
939 |
return r; |
|
940 |
||
941 |
const TInt nMode = aRequest->Message().Int1(); //-- finalisation mode, see RFs::TFinaliseDrvMode |
|
942 |
||
943 |
return aRequest->Drive()->FinaliseMount(nMode); |
|
944 |
} |
|
945 |
||
946 |
/** |
|
947 |
Finalise the drive |
|
948 |
*/ |
|
949 |
TInt TFsFinaliseDrive::Initialise(CFsRequest* aRequest) |
|
950 |
{ |
|
951 |
if (!KCapFsFinaliseDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Finalise Drive"))) |
|
952 |
return KErrPermissionDenied; |
|
953 |
||
954 |
const TInt nDrv = aRequest->Message().Int0(); //-- the drive number to be finalised |
|
955 |
||
956 |
TInt r = ValidateDriveDoSubst(nDrv, aRequest); |
|
957 |
if (r != KErrNone) |
|
958 |
return r; |
|
959 |
||
960 |
TDrive& d = TheDrives[nDrv]; |
|
961 |
if(!d.GetFSys()) |
|
962 |
return KErrNotFound; //-- something wrong with this drive |
|
963 |
||
964 |
||
965 |
//-- check the drive attributes |
|
966 |
const TUint KDrvAttExclude = KDriveAttRom | KDriveAttRedirected; //-- the drive attributes to exlcude from the finalisation |
|
967 |
if(d.Att() & KDrvAttExclude) |
|
968 |
return KErrNotSupported; //-- finalisation isn't supported for these drives |
|
969 |
||
970 |
return KErrNone; |
|
971 |
} |
|
972 |
||
973 |
/** Set System Drive (used by GetSystemDrive and SystemDriveChar) */ |
|
974 |
TInt TFsSetSystemDrive::DoRequestL(CFsRequest* aRequest) |
|
975 |
{ |
|
976 |
__PRINT(_L("TFsSetSystemDrive::DoRequestL()")); |
|
977 |
TInt drive; |
|
978 |
TInt err = RProperty::Get(TSecureId(KFileServerUidValue), KSystemDriveKey, drive); |
|
979 |
if(err == KErrNone) |
|
980 |
{ |
|
981 |
__PRINT1(_L("TFsSetSystemDrive::DoRequestL() drv:%d is already defined as system!"), drive); |
|
982 |
return KErrAlreadyExists; |
|
983 |
} |
|
984 |
||
985 |
drive = aRequest->Message().Int0(); |
|
986 |
__ASSERT_ALWAYS(drive>=EDriveA && drive<=EDriveZ, Fault(EInvalidDrive)); |
|
987 |
||
988 |
//Calculates the total number of valid drives present and set RAM as a |
|
989 |
//system drive only if one valid drive is present. |
|
990 |
TInt total_drive = 0; |
|
991 |
for (TInt driveNumber=0; driveNumber<KMaxDrives; driveNumber++) |
|
992 |
{ |
|
993 |
if(TheDrives[driveNumber].GetFSys() != NULL) // is a valid drive |
|
994 |
total_drive++; |
|
995 |
} |
|
996 |
aRequest->SetDrive(&TheDrives[drive]); |
|
997 |
FsThreadManager::LockDrive(aRequest->DriveNumber()); |
|
998 |
TDriveInfo info; |
|
999 |
aRequest->Drive()->DriveInfo(info); |
|
1000 |
FsThreadManager::UnlockDrive(aRequest->DriveNumber()); |
|
1001 |
||
1002 |
__PRINT1(_L("TFsSetSystemDrive::DoRequestL() total drives:%d"), total_drive); |
|
1003 |
__PRINT3(_L("TFsSetSystemDrive::DoRequestL() setting sys:%d, Media:0x%x, DrvAtt:0x%x"), drive, info.iType, info.iDriveAtt); |
|
1004 |
||
1005 |
//-- 1. check media type of the system drive. |
|
1006 |
__ASSERT_ALWAYS(info.iType==EMediaHardDisk || info.iType==EMediaFlash || info.iType==EMediaNANDFlash || info.iType==EMediaRam, Fault(EInvalidDrive)); |
|
1007 |
||
1008 |
if(info.iType == EMediaRam) |
|
1009 |
{//-- It is not nice to use RAM drive as a system one because it might non be persistent, but acceptable though. |
|
1010 |
__PRINT(_L("TFsSetSystemDrive::DoRequestL() WARNING: RAM drive is set as system drive!")); |
|
1011 |
} |
|
1012 |
||
1013 |
//-- 2. check drive attributes for the system drive |
|
1014 |
const TUint requiredDrvAtt = KDriveAttLocal|KDriveAttInternal; |
|
1015 |
const TUint prohibitedDrvAtt = KDriveAttRom|KDriveAttRedirected|KDriveAttSubsted|KDriveAttRemovable; |
|
1016 |
||
1017 |
ASSERT(!(prohibitedDrvAtt & requiredDrvAtt)); |
|
1018 |
if( !(info.iDriveAtt & requiredDrvAtt) || (info.iDriveAtt & prohibitedDrvAtt)) |
|
1019 |
{ |
|
1020 |
__PRINT2(_L("TFsSetSystemDrive::DoRequestL(), Wrong Drive attributes! req:0x%x, disallowed:0x%x"), requiredDrvAtt, prohibitedDrvAtt); |
|
1021 |
Fault(EInvalidDrive); |
|
1022 |
} |
|
1023 |
||
1024 |
||
1025 |
RProcess p; |
|
1026 |
TSecurityPolicy policy(p.SecureId()); |
|
1027 |
err = RProperty::Define(TSecureId(KFileServerUidValue), KSystemDriveKey, RProperty::EInt, TSecurityPolicy::EAlwaysPass, policy); |
|
1028 |
if(err == KErrNone) |
|
1029 |
{ |
|
1030 |
err = RProperty::Set(TSecureId(KFileServerUidValue), KSystemDriveKey, drive); |
|
1031 |
} |
|
1032 |
__ASSERT_ALWAYS(err==KErrNone, User::Invariant()); |
|
1033 |
||
1034 |
return err; |
|
1035 |
} |
|
1036 |
||
1037 |
/** Checks if setting System Drive is allowed */ |
|
1038 |
TInt TFsSetSystemDrive::Initialise(CFsRequest* aRequest) |
|
1039 |
{ |
|
1040 |
if (!KCapFsSetSystemDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Set System Drive"))) |
|
1041 |
{ |
|
1042 |
return KErrPermissionDenied; |
|
1043 |
} |
|
1044 |
return KErrNone; |
|
1045 |
} |