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