author | hgs |
Fri, 23 Apr 2010 21:54:44 +0100 | |
changeset 119 | 6e99f362aa46 |
parent 90 | 947f0dc9f7a8 |
child 109 | b3a1d9898418 |
child 117 | 5b5d147c7838 |
child 132 | e4a7b1cbe40c |
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 |
#include "sf_file_cache.h" |
|
18 |
#include "cl_std.h" |
|
19 |
||
20 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
21 |
||
22 |
TInt OutputTraceInfo(CFsRequest* aRequest,TCorruptNameRec* aNameRec) |
|
23 |
{ |
|
24 |
RThread tT; |
|
25 |
RProcess tP; |
|
26 |
TBool nameUnknown=EFalse; |
|
27 |
TInt r=aRequest->Message().Client(tT,EOwnerThread); |
|
28 |
if(r!=KErrNone) |
|
29 |
{ |
|
30 |
nameUnknown=ETrue; |
|
31 |
} |
|
32 |
else |
|
33 |
{ |
|
34 |
r=tT.Process(tP); |
|
35 |
if(r!=KErrNone) |
|
36 |
{ |
|
37 |
tT.Close(); |
|
38 |
nameUnknown=ETrue; |
|
39 |
} |
|
40 |
} |
|
41 |
TName n; |
|
42 |
if(!nameUnknown) |
|
43 |
{ |
|
44 |
n=tP.Name(); |
|
45 |
TInt b=n.Locate('['); |
|
46 |
if (b>=0) |
|
47 |
n.SetLength(b); |
|
48 |
tP.Close(); |
|
49 |
tT.Close(); |
|
50 |
} |
|
51 |
else |
|
52 |
{ |
|
53 |
n=_L("*Unknown*"); |
|
54 |
} |
|
55 |
TPtrC t(aRequest->Src().FullName()); |
|
56 |
// output a message via the debug port |
|
57 |
RDebug::Print(_L("@@@@ Corrupt file check %S tried to open %S"),&n,&t); |
|
58 |
// make a new log record & chain it in |
|
59 |
TCorruptLogRec* pLogRec= new TCorruptLogRec; |
|
60 |
if(pLogRec==NULL) |
|
61 |
return KErrNoMemory; |
|
62 |
TPtrC nPtr(n); |
|
63 |
if(pLogRec->Construct(aNameRec,&nPtr,gCorruptLogRecordList)!=KErrNone) |
|
64 |
{ |
|
65 |
delete pLogRec; |
|
66 |
return KErrNoMemory; |
|
67 |
} |
|
68 |
else |
|
69 |
{ |
|
70 |
gCorruptLogRecordList=pLogRec; |
|
71 |
// really a count of number of log records |
|
72 |
gNumberOfCorruptHits++; |
|
73 |
} |
|
74 |
return KErrNone; |
|
75 |
} |
|
76 |
||
77 |
TCorruptLogRec::TCorruptLogRec() |
|
78 |
:iProcessName(NULL),iNameRec(NULL),iNext(NULL) |
|
79 |
{} |
|
80 |
||
81 |
TCorruptLogRec::~TCorruptLogRec() |
|
82 |
{ // free off name memory |
|
83 |
delete iProcessName; |
|
84 |
} |
|
85 |
||
86 |
||
87 |
void TCorruptLogRec::DestroyList() |
|
88 |
{ |
|
89 |
TCorruptLogRec* pList=gCorruptLogRecordList; |
|
90 |
||
91 |
while(pList!=NULL) |
|
92 |
{ |
|
93 |
TCorruptLogRec* pThis=pList; |
|
94 |
pList=pList->iNext; |
|
95 |
delete pThis; |
|
96 |
} |
|
97 |
gCorruptLogRecordList=NULL; |
|
98 |
gNumberOfCorruptHits=0; |
|
99 |
} |
|
100 |
||
101 |
TInt TCorruptLogRec::Construct(TCorruptNameRec* aNameRec, TPtrC* aProcessName, TCorruptLogRec* aChain) |
|
102 |
{ |
|
103 |
iProcessName=aProcessName->Alloc(); |
|
104 |
if(iProcessName==NULL) |
|
105 |
return KErrNoMemory; |
|
106 |
||
107 |
iNameRec=aNameRec; |
|
108 |
iNext=aChain; |
|
109 |
return KErrNone; |
|
110 |
} |
|
111 |
||
112 |
TInt TCorruptLogRec::GetLogRecord(TFsDebugCorruptLogRecordBuf& aLogRecord,TInt aLogRecNum) |
|
113 |
{ |
|
114 |
if(aLogRecNum<=0) |
|
115 |
{ |
|
116 |
return KErrArgument; |
|
117 |
} |
|
118 |
else if(aLogRecNum>gNumberOfCorruptHits) |
|
119 |
{ |
|
120 |
return KErrNotFound; |
|
121 |
} |
|
122 |
||
123 |
TCorruptLogRec* pList=gCorruptLogRecordList; |
|
124 |
||
125 |
for(TInt i=1;i<aLogRecNum && pList!=NULL;i++) |
|
126 |
{ |
|
127 |
pList=pList->iNext; |
|
128 |
} |
|
129 |
||
130 |
TInt r=KErrNotFound; |
|
131 |
||
132 |
if(pList) |
|
133 |
{ |
|
134 |
aLogRecord().iProcessName=pList->iProcessName->Des(); |
|
135 |
aLogRecord().iFileName=pList->iNameRec->Name(); |
|
136 |
aLogRecord().iError=pList->iNameRec->ReturnCode(); |
|
137 |
r=KErrNone; |
|
138 |
} |
|
139 |
||
140 |
return r; |
|
141 |
} |
|
142 |
||
143 |
TCorruptNameRec::TCorruptNameRec() |
|
144 |
:iName(NULL),iNext(NULL){} |
|
145 |
||
146 |
TInt TCorruptNameRec::Construct(TPtr* aName,TInt aReturnCode, TBool aUseOnce, TCorruptNameRec* aChain) |
|
147 |
{ |
|
148 |
iName=aName->Alloc(); |
|
149 |
if(iName==NULL) |
|
150 |
return KErrNoMemory; |
|
151 |
iReturnCode=aReturnCode; |
|
152 |
iUseOnce=aUseOnce; |
|
153 |
iConsumed=EFalse; |
|
154 |
iNext=aChain; |
|
155 |
return KErrNone; |
|
156 |
} |
|
157 |
||
158 |
void TCorruptNameRec::ResetListConsumed() |
|
159 |
{ |
|
160 |
TCorruptNameRec* pList=gCorruptFileNameList; |
|
161 |
while(pList!=NULL) |
|
162 |
{ |
|
163 |
pList->iConsumed=EFalse; |
|
164 |
pList=pList->Next(); |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
LOCAL_C void checkCorruptNamesList(CFsRequest* aRequest, TInt &aError) |
|
169 |
{ |
|
170 |
aError=KErrNone; |
|
171 |
TPtrC path(aRequest->Src().FullName()); |
|
172 |
TCorruptNameRec* pList=gCorruptFileNameList; |
|
173 |
while(pList) |
|
174 |
{ |
|
175 |
if(pList->Name().MatchF(path)==0) |
|
176 |
{ |
|
177 |
if(!pList->Consumed()) |
|
178 |
{ |
|
179 |
aError=pList->ReturnCode(); |
|
180 |
pList->SetConsumed(); |
|
181 |
OutputTraceInfo(aRequest,pList); |
|
182 |
} |
|
183 |
break; |
|
184 |
} |
|
185 |
pList=pList->Next(); |
|
186 |
} |
|
187 |
} |
|
188 |
#endif |
|
189 |
||
190 |
||
191 |
LOCAL_C TInt DoInitNoParse(CFsRequest* aRequest) |
|
192 |
// |
|
193 |
// Common init for read and write access to files |
|
194 |
// |
|
195 |
{ |
|
196 |
CFileShare* share = GetShareFromHandle(aRequest->Session(), aRequest->Message().Int3()); |
|
197 |
if(!share) |
|
198 |
return(KErrBadHandle); |
|
199 |
aRequest->SetDrive(&share->File().Drive()); |
|
200 |
aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) ); |
|
201 |
return KErrNone; |
|
202 |
} |
|
203 |
||
204 |
_LIT(KDrivePath,"?:"); |
|
205 |
LOCAL_C TInt DoInitialise(CFsRequest* aRequest) |
|
206 |
// |
|
207 |
// Common initialisation code use file share to determine asychronicity |
|
208 |
// |
|
209 |
{ |
|
210 |
CFileShare* share = GetShareFromHandle(aRequest->Session(), aRequest->Message().Int3()); |
|
211 |
if(!share) |
|
212 |
return(KErrBadHandle); |
|
213 |
aRequest->SetDrive(&share->File().Drive()); |
|
214 |
aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) ); |
|
215 |
TBuf<2> drive(KDrivePath); |
|
216 |
drive[0]=TText(aRequest->DriveNumber()+'A'); |
|
217 |
aRequest->Src().Set(share->File().FileName(),NULL,&drive); |
|
218 |
return KErrNone; |
|
219 |
} |
|
220 |
||
221 |
LOCAL_C TInt InitialiseScratchToShare(CFsRequest* aRequest) |
|
222 |
// |
|
223 |
// Common code used to initialise the scratch value to the CFileShare* from the request |
|
224 |
// |
|
225 |
{ |
|
226 |
CFileShare* share=GetShareFromHandle(aRequest->Session(), aRequest->Message().Int3()); |
|
227 |
if(!share) |
|
228 |
return(KErrBadHandle); |
|
229 |
aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) ); |
|
230 |
||
231 |
return(KErrNone); |
|
232 |
} |
|
233 |
||
234 |
LOCAL_C TInt FsFileOpenL(CFsRequest* aRequest, TFileOpen anOpen) |
|
235 |
// |
|
236 |
// Open a file. |
|
237 |
// |
|
238 |
{ |
|
239 |
TInt r; |
|
240 |
||
241 |
TUint32 mode=aRequest->Message().Int1(); |
|
242 |
if (anOpen==EFileCreate || anOpen==EFileReplace) |
|
243 |
{ |
|
244 |
r = CheckDiskSpace(0, aRequest); |
|
245 |
if(r != KErrNone) |
|
246 |
return r; |
|
247 |
||
248 |
mode|=EFileWrite; |
|
249 |
} |
|
250 |
||
251 |
TInt h; |
|
252 |
r=aRequest->Drive()->FileOpen(aRequest,h,aRequest->Src().FullName().Mid(2),mode,anOpen); |
|
253 |
if (r!=KErrNone) |
|
254 |
return(r); |
|
255 |
||
256 |
TPtrC8 pH((TUint8*)&h,sizeof(TInt)); |
|
257 |
TRAP(r, aRequest->WriteL(KMsgPtr3,pH)) |
|
258 |
CheckForLeaveAfterOpenL(r, aRequest, h); |
|
259 |
aRequest->Session()->IncResourceCount(); |
|
260 |
||
261 |
return(KErrNone); |
|
262 |
} |
|
263 |
||
264 |
TInt TFsFileOpen::DoRequestL(CFsRequest* aRequest) |
|
265 |
// |
|
266 |
// |
|
267 |
// |
|
268 |
{ |
|
269 |
__PRINT(_L("TFsFileOpen::DoRequestL(CFsRequest* aRequest)")); |
|
270 |
return FsFileOpenL(aRequest, EFileOpen); |
|
271 |
} |
|
272 |
||
273 |
TInt TFsFileCreate::DoRequestL(CFsRequest* aRequest) |
|
274 |
// |
|
275 |
// |
|
276 |
// |
|
277 |
{ |
|
278 |
||
279 |
__PRINT(_L("TFsFileCreate::DoRequestL(CFsRequest* aRequest)")); |
|
280 |
return FsFileOpenL(aRequest, EFileCreate); |
|
281 |
} |
|
282 |
||
283 |
TInt TFsFileCreate::Initialise(CFsRequest* aRequest) |
|
284 |
// |
|
285 |
// |
|
286 |
// |
|
287 |
{ |
|
288 |
TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src()); |
|
289 |
if (r!=KErrNone) |
|
290 |
return(r); |
|
291 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysFileCreate,&KCapFsPriFileCreate,&KCapFsROFileCreate, __PLATSEC_DIAGNOSTIC_STRING("Create File")); |
|
292 |
if (r!=KErrNone) |
|
293 |
return(r); |
|
294 |
if (OpenOnDriveZOnly) |
|
295 |
{ |
|
296 |
aRequest->SetDrive(&TheDrives[EDriveZ]); |
|
297 |
aRequest->SetSubstedDrive(NULL); |
|
298 |
} |
|
299 |
return(r); |
|
300 |
} |
|
301 |
||
302 |
||
303 |
||
304 |
TInt TFsFileReplace::DoRequestL(CFsRequest* aRequest) |
|
305 |
// |
|
306 |
// |
|
307 |
// |
|
308 |
{ |
|
309 |
__PRINT(_L("TFsFileReplace::DoRequestL(CFsRequest* aRequest)")); |
|
310 |
return FsFileOpenL(aRequest, EFileReplace); |
|
311 |
} |
|
312 |
||
313 |
TInt TFsFileReplace::Initialise(CFsRequest* aRequest) |
|
314 |
// |
|
315 |
// |
|
316 |
// |
|
317 |
{ |
|
318 |
TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src()); |
|
319 |
if (r!=KErrNone) |
|
320 |
return(r); |
|
321 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysFileReplace,&KCapFsPriFileReplace,&KCapFsROFileReplace, __PLATSEC_DIAGNOSTIC_STRING("Replace File")); |
|
322 |
if (r!=KErrNone) |
|
323 |
return(r); |
|
324 |
||
325 |
if (OpenOnDriveZOnly) // Yuck! yet another global |
|
326 |
{ |
|
327 |
aRequest->SetDrive(&TheDrives[EDriveZ]); |
|
328 |
aRequest->SetSubstedDrive(NULL); |
|
329 |
} |
|
330 |
return(r); |
|
331 |
} |
|
332 |
||
333 |
||
334 |
#ifdef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
335 |
||
336 |
#define __PLATSEC_DIAGNOSTIC_MESSAGE(s) NULL |
|
337 |
static const TInt KMsgBuffSize = KMaxPath; |
|
338 |
||
339 |
#else |
|
340 |
||
341 |
#if defined(_UNICODE) && !defined(__KERNEL_MODE__) |
|
342 |
||
343 |
static const TInt KCharMsgMaxLen = KMaxPath - 1; |
|
344 |
static const TInt KMsgBuffSize = KMaxPath; |
|
345 |
||
346 |
#else |
|
347 |
||
348 |
static const TInt KCharMsgMaxLen = 50; |
|
349 |
static const TInt KMsgBuffSize = KMaxPath + KMsgMaxLen + 1; |
|
350 |
||
351 |
#endif // #if defined(_UNICODE) && !defined(__KERNEL_MODE__) |
|
352 |
||
353 |
// Local function to format a message |
|
354 |
static |
|
355 |
const char* FmtPlatSecMessage(TBufC<KMsgBuffSize>& buff, CFsRequest& req, const char* str) |
|
356 |
{ |
|
357 |
char* p = (char*)buff.Ptr(); |
|
358 |
const char* const base = p; |
|
359 |
// copy message string (if any) |
|
360 |
if(str) |
|
361 |
{ |
|
362 |
while(*str && p < &base[KCharMsgMaxLen - 2]) // 2 for trailing ": " |
|
363 |
*p++ = *str++; |
|
364 |
*p++ = ':'; |
|
365 |
*p++ = ' '; |
|
366 |
} |
|
367 |
// append filename |
|
368 |
const TDesC& fname = req.Src().FullName(); |
|
369 |
const TInt end = Min(fname.Length(), |
|
370 |
KMsgBuffSize * sizeof(*buff.Ptr()) - (p - base) - 1); |
|
371 |
for(TInt i = 0; i < end; ++i) |
|
372 |
*p++ = (char)fname[i]; |
|
373 |
*p = 0; |
|
374 |
return base; |
|
375 |
} |
|
376 |
||
377 |
#define __PLATSEC_DIAGNOSTIC_MESSAGE(s) FmtPlatSecMessage(thisPath, *aRequest, s) |
|
378 |
||
379 |
#endif // #ifdef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ |
|
380 |
||
381 |
||
382 |
TInt TFsFileOpen::Initialise(CFsRequest* aRequest) |
|
383 |
// |
|
384 |
// Parse and execute FileOpen service otherwise sets flag for |
|
385 |
// asynchronous service |
|
386 |
// |
|
387 |
{ |
|
388 |
TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src()); |
|
389 |
if (r!=KErrNone) |
|
390 |
return(r); |
|
391 |
||
392 |
TBufC<KMsgBuffSize> thisPath(aRequest->Src().FullName().Mid(2)); |
|
393 |
TUint32 mode = (aRequest->Message().Int1() & ~(EFileStreamText | EFileReadAsyncAll | EFileBigFile)); |
|
394 |
||
395 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
396 |
// see if file is on our "Most Wanted" list |
|
397 |
TInt errorCode; |
|
398 |
checkCorruptNamesList(aRequest,errorCode); |
|
399 |
if(errorCode!=KErrNone) |
|
400 |
{ |
|
401 |
return errorCode; |
|
402 |
} |
|
403 |
#endif |
|
404 |
||
405 |
CFsMessageRequest* msgRequest = (CFsMessageRequest*)aRequest; |
|
406 |
if (OpenOnDriveZOnly) |
|
407 |
{ |
|
408 |
aRequest->SetDrive(&TheDrives[EDriveZ]); |
|
409 |
aRequest->SetSubstedDrive(NULL); |
|
410 |
} |
|
411 |
||
412 |
if(msgRequest->IsPluginRequest()) |
|
413 |
{ |
|
414 |
// Always allow plugins to open files, regardless of the clients policy |
|
415 |
return KErrNone; |
|
416 |
} |
|
417 |
||
418 |
if(ComparePrivate(thisPath)) |
|
419 |
{ |
|
420 |
if(! SIDCheck(aRequest,thisPath)) |
|
421 |
{ |
|
422 |
if(!KCapFsPriFileOpen.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in private path"))) |
|
423 |
return KErrPermissionDenied; |
|
424 |
} |
|
425 |
} |
|
426 |
else if(CompareResource(thisPath)) |
|
427 |
{ |
|
428 |
if(mode != EFileShareReadersOrWriters && mode != EFileShareReadersOnly && mode != EFileRead) |
|
429 |
// File opening mode EFileShareReadersOrWriters|EFileRead will fail the above test and not |
|
430 |
// be checked for policy, whereas file opening mode EFileShareReadersOrWriters|EFileWrite |
|
431 |
// will pass the test and will be checked for policy. |
|
432 |
// EFileRead is 0 whereas EFileWrite is non 0. |
|
433 |
{ |
|
434 |
if(!KCapFsROFileOpenWr.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in resource path"))) |
|
435 |
return KErrPermissionDenied; |
|
436 |
} |
|
437 |
} |
|
438 |
else if(CompareSystem(thisPath)) |
|
439 |
{ |
|
440 |
if(!(mode & EFileShareReadersOnly) && (mode & EFileWrite)) |
|
441 |
{ |
|
442 |
if(!KCapFsSysFileOpenWr.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in system path"))) |
|
443 |
return KErrPermissionDenied; |
|
444 |
} |
|
445 |
else |
|
446 |
{ |
|
447 |
if(!KCapFsSysFileOpenRd.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in system path"))) |
|
448 |
return KErrPermissionDenied; |
|
449 |
} |
|
450 |
} |
|
451 |
||
452 |
return(r); |
|
453 |
} |
|
454 |
||
455 |
#undef __PLATSEC_DIAGNOSTIC_MESSAGE |
|
456 |
||
457 |
TInt TFsIsFileOpen::DoRequestL(CFsRequest* aRequest) |
|
458 |
// |
|
459 |
// Return whether a file is open or not |
|
460 |
// |
|
461 |
{ |
|
462 |
||
463 |
__PRINT(_L("TFsIsFileOpen::DoRequestL(CFsRequest* aRequest)")); |
|
464 |
CFileCB* file; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
465 |
TInt r = aRequest->Drive()->IsFileOpen(aRequest->Src().FullName().Mid(2), file); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
466 |
if (r != KErrNone) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
467 |
return (r); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
468 |
TBool isOpen = file ? (TBool)ETrue : (TBool)EFalse; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
469 |
if (!isOpen) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
470 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
471 |
// perform the existance check to retain compatibility with old-style clients |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
472 |
TEntry e; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
473 |
r = aRequest->Drive()->Entry(aRequest->Src().FullName().Mid(2), e); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
474 |
if (r == KErrNone && e.IsDir()) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
475 |
r = KErrArgument; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
476 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
477 |
if (r != KErrNone) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
478 |
return (r); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
479 |
|
0 | 480 |
TPtrC8 pA((TUint8*)&isOpen,sizeof(TBool)); |
481 |
aRequest->WriteL(KMsgPtr1,pA); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
482 |
return (KErrNone); |
0 | 483 |
} |
484 |
||
485 |
TInt TFsIsFileOpen::Initialise(CFsRequest* aRequest) |
|
486 |
// |
|
487 |
// |
|
488 |
// |
|
489 |
{ |
|
490 |
TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src()); |
|
491 |
if (r!=KErrNone) |
|
492 |
return(r); |
|
493 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysIsFileOpen,&KCapFsPriIsFileOpen, __PLATSEC_DIAGNOSTIC_STRING("Is File Open")); |
|
494 |
return(r); |
|
495 |
} |
|
496 |
||
497 |
||
498 |
TInt TFsListOpenFiles::DoRequestL(CFsRequest* aRequest) |
|
499 |
// |
|
500 |
// List open files |
|
501 |
// |
|
502 |
{ |
|
503 |
||
504 |
__PRINT(_L("TFsListOpenFiles::DoRequestL(CFsRequest* aRequest)")); |
|
505 |
||
506 |
TOpenFileListPos listPos; |
|
507 |
TPckg<TOpenFileListPos> listPkg(listPos); |
|
508 |
aRequest->ReadL(KMsgPtr0,listPkg); |
|
509 |
TBuf8<KEntryArraySize> entryArray(0); |
|
510 |
||
511 |
TThreadId idClient; |
|
512 |
TPckgC<TThreadId> id(idClient); |
|
513 |
||
514 |
CSessionFs* session; |
|
515 |
TBool fileFound=(listPos.iEntryListPos) ? (TBool)ETrue : EFalse; |
|
516 |
TInt entryListPos; |
|
517 |
TInt count; |
|
518 |
Start: |
|
519 |
FOREVER |
|
520 |
{ |
|
521 |
session=(*TheFileServer)[listPos.iSession]; //this global may not be the best way AJ |
|
522 |
if (session==NULL) |
|
523 |
goto End; |
|
524 |
session->Handles().Lock(); |
|
525 |
count=session->Handles().Count(); |
|
526 |
if (count) |
|
527 |
break; |
|
528 |
session->Handles().Unlock(); |
|
529 |
listPos.iSession++; |
|
530 |
} |
|
531 |
||
532 |
entryListPos=listPos.iEntryListPos; |
|
533 |
while (entryListPos<count) |
|
534 |
{ |
|
535 |
CObjPromotion* obj=(CObjPromotion*)session->Handles()[entryListPos]; |
|
536 |
if (obj==NULL || obj->UniqueID()!=FileShares->UniqueID()) |
|
537 |
{ |
|
538 |
entryListPos++; |
|
539 |
continue; // Is not a CFileShare |
|
540 |
} |
|
541 |
CFileCB& fileCb=((CFileShare*)obj)->File(); |
|
542 |
||
543 |
TEntry fileEntry; |
|
544 |
// Set kEntryAttPacked to indicate it is in packed form |
|
545 |
fileEntry.iAtt=fileCb.Att() | KEntryAttPacked; |
|
546 |
TInt64 fileSize = fileCb.Size64(); |
|
547 |
fileEntry.iSize = I64LOW(fileSize); |
|
548 |
fileEntry.iModified=fileCb.Modified(); |
|
549 |
fileEntry.iName=fileCb.FileName(); |
|
550 |
||
551 |
// Pack - Copy iSizeHigh and reset iReserved in packed form |
|
552 |
TUint32* pSizeHigh = PtrAdd((TUint32*)&fileEntry, EntrySize(fileEntry, EFalse)); |
|
553 |
||
554 |
*pSizeHigh++ = I64HIGH(fileSize); // Copy iSizeHigh |
|
555 |
*pSizeHigh = 0; // Reset iReserved |
|
556 |
||
557 |
TInt entrySize=EntrySize(fileEntry, ETrue); |
|
558 |
if (entryArray.Length()+entrySize>entryArray.MaxLength()) |
|
559 |
break; |
|
560 |
TPtrC8 pfileEntry((TUint8*)&fileEntry,entrySize); |
|
561 |
entryArray.Append(pfileEntry); |
|
562 |
entryListPos++; |
|
563 |
} |
|
564 |
idClient = session->ThreadId(); |
|
565 |
session->Handles().Unlock(); |
|
566 |
||
567 |
if (entryArray.Length()==0) |
|
568 |
listPos.iSession++; |
|
569 |
if (fileFound==EFalse && entryArray.Length()==0) |
|
570 |
goto Start; |
|
571 |
listPos.iEntryListPos=entryListPos; |
|
572 |
||
573 |
End: |
|
574 |
aRequest->WriteL(KMsgPtr1,id); |
|
575 |
aRequest->WriteL(KMsgPtr0,listPkg); |
|
576 |
aRequest->WriteL(KMsgPtr2,entryArray); |
|
577 |
return(KErrNone); |
|
578 |
} |
|
579 |
||
580 |
TInt TFsListOpenFiles::Initialise(CFsRequest* /*aRequest*/) |
|
581 |
// |
|
582 |
// |
|
583 |
// |
|
584 |
{ |
|
585 |
return KErrNone; |
|
586 |
} |
|
587 |
||
588 |
LOCAL_C void FsFileTempFinishL(CFsRequest* aRequest,TFileName& aN,TInt aH) |
|
589 |
{ |
|
590 |
||
591 |
aRequest->WriteL(KMsgPtr2,aRequest->Src().Drive()); |
|
592 |
aRequest->WriteL(KMsgPtr2,aN,2); |
|
593 |
TPtrC8 pH((TUint8*)&aH,sizeof(TInt)); |
|
594 |
aRequest->WriteL(KMsgPtr3,pH); |
|
595 |
} |
|
596 |
||
597 |
TInt TFsFileTemp::DoRequestL(CFsRequest* aRequest) |
|
598 |
// |
|
599 |
// Create a temporary file. |
|
600 |
// |
|
601 |
{ |
|
602 |
__PRINT(_L("TFsFileTemp::DoRequestL(CFsRequest* aRequest)")); |
|
603 |
||
604 |
TInt r = CheckDiskSpace(0, aRequest); |
|
605 |
if(r != KErrNone) |
|
606 |
return r; |
|
607 |
||
608 |
TFileName n; |
|
609 |
TInt h; |
|
610 |
r=aRequest->Drive()->FileTemp(aRequest,h,aRequest->Src().FullName().Mid(2),n,aRequest->Message().Int1()); |
|
611 |
if (r!=KErrNone) |
|
612 |
return(r); |
|
613 |
||
614 |
TRAP(r, FsFileTempFinishL(aRequest,n,h)) |
|
615 |
CheckForLeaveAfterOpenL(r,aRequest,h); |
|
616 |
aRequest->Session()->IncResourceCount(); |
|
617 |
||
618 |
return(KErrNone); |
|
619 |
} |
|
620 |
||
621 |
TInt TFsFileTemp::Initialise(CFsRequest* aRequest) |
|
622 |
// |
|
623 |
// |
|
624 |
// |
|
625 |
{ |
|
626 |
TInt r=ParseNoWildSubstPtr0(aRequest,aRequest->Src()); |
|
627 |
if (r!=KErrNone) |
|
628 |
return(r); |
|
629 |
r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysFileTemp,&KCapFsPriFileTemp,&KCapFsROFileTemp, __PLATSEC_DIAGNOSTIC_STRING("Temp File")); |
|
630 |
if (r!=KErrNone) |
|
631 |
return(r); |
|
632 |
if (aRequest->Src().NameOrExtPresent()) |
|
633 |
return(KErrBadName); |
|
634 |
return(r); |
|
635 |
} |
|
636 |
||
637 |
||
638 |
TInt TFsFileRead::DoRequestL(CFsRequest* aRequest) |
|
639 |
// |
|
640 |
// Read from a file. |
|
641 |
// |
|
642 |
{ |
|
643 |
||
644 |
__PRINT(_L("TFsFileRead::DoRequestL(CFsRequest* aRequest)")); |
|
645 |
__PRINT1(_L("aRequest->Session() = 0x%x"),aRequest->Session()); |
|
646 |
||
647 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest; |
|
648 |
__ASSERT_DEBUG(msgRequest.CurrentOperationPtr() != NULL, Fault(EBadOperationIndex)); |
|
649 |
TMsgOperation& currentOperation = msgRequest.CurrentOperation(); |
|
650 |
||
651 |
CFileShare* share; |
|
652 |
CFileCB* file; |
|
653 |
GetFileFromScratch(aRequest, share, file); |
|
654 |
||
655 |
TInt r = file->CheckMount(); |
|
656 |
__PRINT1(_L("share->CheckMount() returned = %d"),r); |
|
657 |
if (r!=KErrNone) |
|
658 |
return(r); |
|
659 |
||
660 |
TInt& len = currentOperation.iReadWriteArgs.iLength; |
|
661 |
TInt& totalLen = currentOperation.iReadWriteArgs.iTotalLength; |
|
662 |
TInt64 pos = currentOperation.iReadWriteArgs.iPos; |
|
663 |
TInt& offset = currentOperation.iReadWriteArgs.iOffset; |
|
664 |
||
665 |
// Fair scheduling - |
|
666 |
// Needs extended file API to work (so that we can sepcify an offset) |
|
667 |
// Also needs a separate drive thread to prevent excessive stack usage |
|
668 |
len = Min(len, totalLen); |
|
669 |
if (file->ExtendedFileInterfaceSupported() && !FsThreadManager::IsDriveSync(aRequest->DriveNumber(), EFalse)) |
|
670 |
{ |
|
671 |
len = Min(len, file->FairSchedulingLen()); |
|
672 |
} |
|
673 |
if (pos == KCurrentPosition64) |
|
674 |
pos = share->iPos; |
|
675 |
||
676 |
currentOperation.iReadWriteArgs.iPos = pos; |
|
677 |
||
678 |
__ASSERT_DEBUG(len > 0, Fault(EInvalidReadLength)); |
|
679 |
__ASSERT_DEBUG(len <= totalLen, Fault(EInvalidReadLength)); |
|
680 |
||
681 |
// The mount and any extensions must all support local buffers in order to support |
|
682 |
// internally generated requests (ie - requests originating from plugins) |
|
683 |
if ((aRequest->Message().Handle() == KLocalMessageHandle || !currentOperation.iClientRequest) && !file->LocalBufferSupport()) |
|
684 |
{ |
|
685 |
r = KErrNotSupported; |
|
686 |
} |
|
687 |
||
688 |
TInt reqLen = len; |
|
689 |
if(r == KErrNone) |
|
690 |
{ |
|
691 |
if (currentOperation.iClientRequest) |
|
692 |
{ |
|
693 |
// Current operation points to a descriptor |
|
694 |
// The request originated from a client (with a normal message handle) or a plugin (KLocalMessageHandle) |
|
695 |
TRAP(r,file->ReadL(pos, len, (TPtr8*) aRequest->Message().Ptr0(), aRequest->Message(), offset)) |
|
696 |
} |
|
697 |
else |
|
698 |
{ |
|
699 |
// Current operation points to a local buffer |
|
700 |
// The request originated from the file server (e.g. file cache) with a local message handle (KLocalMessageHandle) |
|
701 |
TPtr8 dataDesc((TUint8*) currentOperation.iReadWriteArgs.iData + currentOperation.iReadWriteArgs.iOffset, len, len); |
|
702 |
const RLocalMessage msg; |
|
703 |
TRAP(r,file->ReadL(pos, len, &dataDesc, msg, 0)); |
|
704 |
} |
|
705 |
} |
|
706 |
||
707 |
||
708 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
709 |
CCacheManager* manager = CCacheManagerFactory::CacheManager(); |
|
710 |
if (manager) |
|
711 |
{ |
|
712 |
manager->Stats().iUncachedPacketsRead++; |
|
713 |
manager->Stats().iUncachedBytesRead+= len; |
|
714 |
} |
|
715 |
#endif |
|
716 |
||
717 |
//RDebug::Print(_L("ReadR: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file); |
|
718 |
||
719 |
||
720 |
#if defined (_DEBUG_READ_AHEAD) |
|
721 |
RDebug::Print(_L("ReadR: req %08X pos %ld\t len %d nextPos %ld file %08X\n"), aRequest, pos, len, pos + len, file); |
|
722 |
#endif |
|
723 |
||
724 |
offset+= len; |
|
725 |
currentOperation.iReadWriteArgs.iPos+= len; |
|
726 |
totalLen-= reqLen; |
|
727 |
||
728 |
||
729 |
// update the file share's position IF this request came from the client |
|
730 |
if (share && r==KErrNone && currentOperation.iClientRequest) |
|
731 |
{ |
|
732 |
__e32_atomic_store_ord64(&share->iPos, pos + len); |
|
733 |
} |
|
734 |
||
735 |
// re-issue request if not complete (to support fair scheduling) |
|
736 |
if (r == KErrNone && totalLen > 0) |
|
737 |
return CFsRequest::EReqActionBusy; // dispatch request again to back of queue |
|
738 |
||
739 |
return(r); |
|
740 |
} |
|
741 |
||
742 |
||
743 |
TInt TFsFileRead::Initialise(CFsRequest* aRequest) |
|
744 |
// |
|
745 |
// |
|
746 |
// |
|
747 |
{ |
|
748 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest; |
|
749 |
||
750 |
TInt r = DoInitNoParse(aRequest); |
|
751 |
if (r != KErrNone) |
|
752 |
return r; |
|
753 |
||
754 |
CFileShare* share; |
|
755 |
CFileCB* file; |
|
756 |
GetFileFromScratch(aRequest, share, file); |
|
757 |
||
758 |
TMsgOperation* msgOp = msgRequest.CurrentOperationPtr(); |
|
759 |
if (!msgOp) // initialised already ? |
|
760 |
{ |
|
761 |
r = msgRequest.PushOperation(TFsFileRead::Complete); |
|
762 |
if (r != KErrNone) |
|
763 |
return r; |
|
764 |
msgOp = msgRequest.CurrentOperationPtr(); |
|
765 |
} |
|
766 |
// try to serialize requests to prevent asynchronous requests being processed out of sequence - |
|
767 |
// this isn't possible if a plugin is loaded as this may issue it's own requests |
|
768 |
if (!share->RequestStart(&msgRequest)) |
|
769 |
return CFsRequest::EReqActionPending; |
|
770 |
||
771 |
TDrive& drive = share->File().Drive(); |
|
772 |
||
773 |
TInt64 pos, reqPos; |
|
774 |
TInt len, reqLen; |
|
775 |
||
776 |
reqLen = len = aRequest->Message().Int1(); |
|
777 |
||
778 |
if(aRequest->IsDescData(KMsgPtr2)) |
|
779 |
{//-- 64-bit file addressing, absolute read position is TInt64 |
|
780 |
TPckg<TInt64> pkPos(reqPos); |
|
781 |
aRequest->ReadL(KMsgPtr2, pkPos); |
|
782 |
} |
|
783 |
else |
|
784 |
{ |
|
785 |
if(aRequest->Message().Int2() == (TInt)I64LOW(KCurrentPosition64)) |
|
786 |
reqPos = KCurrentPosition64; // Position is KCurrentPosition64 (-1) |
|
787 |
else //-- legacy, RFile addressing |
|
788 |
reqPos = MAKE_TINT64(0,aRequest->Message().Int2()); // Position is absolute value < 4GB, it's TUint |
|
789 |
} |
|
790 |
||
791 |
msgOp->iClientPosition = pos = reqPos; |
|
792 |
||
793 |
if (len < 0) |
|
794 |
return KErrArgument; |
|
795 |
||
796 |
if (len == 0) |
|
797 |
return CFsRequest::EReqActionComplete; |
|
798 |
||
799 |
if (pos == KCurrentPosition64) |
|
800 |
pos = share->iPos; |
|
801 |
||
802 |
const TInt64 fileSize = file->CachedSize64(); |
|
803 |
if (pos > fileSize) |
|
804 |
pos = fileSize; |
|
805 |
||
806 |
if ((r = file->CheckLock64(share,pos,len)) != KErrNone) |
|
807 |
return r; |
|
808 |
||
809 |
||
810 |
TDes8* pD = (TDes8*) aRequest->Message().Ptr0(); |
|
811 |
||
812 |
if((share->iMode & EFileReadAsyncAll) && (aRequest->Message().ClientStatus() != NULL)) |
|
813 |
{ |
|
814 |
drive.Lock(); |
|
815 |
if (pos + len > fileSize) |
|
816 |
{ |
|
817 |
r = share->File().AddAsyncReadRequest(share, reqPos, reqLen, aRequest); |
|
818 |
drive.UnLock(); |
|
819 |
return (r == KErrNone)?CFsRequest::EReqActionComplete:r; |
|
820 |
} |
|
821 |
drive.UnLock(); |
|
822 |
} |
|
823 |
||
824 |
if (pos == fileSize) |
|
825 |
{ |
|
826 |
__e32_atomic_store_ord64(&share->iPos, pos); |
|
827 |
r = aRequest->Write(KMsgPtr0, KNullDesC8); |
|
828 |
return(r == KErrNone?CFsRequest::EReqActionComplete:r); |
|
829 |
} |
|
830 |
||
831 |
if (pos + len > fileSize) |
|
832 |
{ |
|
833 |
// filesize - pos shall of TInt size |
|
834 |
// Hence to suppress warning |
|
835 |
len = (TInt)(fileSize - pos); |
|
836 |
} |
|
837 |
||
838 |
msgOp->Set(pos, len, (TDesC8*) pD); |
|
839 |
||
840 |
//RDebug::Print(_L("ReadI: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file); |
|
841 |
||
842 |
#if defined (_DEBUG_READ_AHEAD) |
|
843 |
RDebug::Print(_L("ReadI: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file); |
|
844 |
#endif |
|
845 |
||
846 |
return KErrNone; |
|
847 |
} |
|
848 |
||
849 |
TInt TFsFileRead::PostInitialise(CFsRequest* aRequest) |
|
850 |
{ |
|
851 |
CFileShare* share = (CFileShare*) aRequest->ScratchValue(); |
|
852 |
CFileCB* file = &share->File(); |
|
853 |
TInt r = KErrNone; |
|
854 |
||
855 |
CFileCache* fileCache = file->FileCache(); |
|
856 |
if (fileCache) |
|
857 |
{ |
|
858 |
r = fileCache->ReadBuffered(*(CFsMessageRequest*)aRequest, share->iMode); |
|
859 |
||
860 |
// if we're not reading from cache, force read ahead position & length to be recalculated |
|
861 |
if (r == KErrNone) |
|
862 |
fileCache->ResetReadAhead(); |
|
863 |
} |
|
864 |
||
865 |
return r; |
|
866 |
} |
|
867 |
||
868 |
TInt TFsFileRead::Complete(CFsRequest* aRequest) |
|
869 |
{ |
|
870 |
// RDebug::Print(_L("TFsFileRead::Complete() aRequest %08X"), aRequest); |
|
871 |
||
872 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest; |
|
873 |
||
874 |
CFileShare* share; |
|
875 |
CFileCB* file; |
|
876 |
GetFileFromScratch(aRequest, share, file); |
|
877 |
||
878 |
// Flag the request as having ended to allow another async read to occur |
|
879 |
share->RequestEnd(&msgRequest); |
|
880 |
||
881 |
||
882 |
// issue read-ahead |
|
883 |
CFileCache* fileCache = file->FileCache(); |
|
884 |
if (fileCache && msgRequest.LastError() == KErrNone) |
|
885 |
fileCache->ReadAhead(msgRequest, share->iMode); |
|
886 |
||
887 |
return CFsRequest::EReqActionComplete; |
|
888 |
} |
|
889 |
||
890 |
||
891 |
void GetFileFromScratch(CFsRequest* aRequest, CFileShare*& aShare, CFileCB*& aFile) |
|
892 |
{ |
|
893 |
||
894 |
TInt64 scratchValue = aRequest->ScratchValue64(); |
|
895 |
TBool scratchValueIsShare I64HIGH(scratchValue); |
|
896 |
TUint32 scratchValueLow = I64LOW(scratchValue); |
|
897 |
||
898 |
aShare = NULL; |
|
899 |
aFile = NULL; |
|
900 |
||
901 |
if (scratchValueIsShare) |
|
902 |
{ |
|
903 |
aShare = (CFileShare*) scratchValueLow; |
|
904 |
if (aShare) |
|
905 |
aFile = &aShare->File(); |
|
906 |
} |
|
907 |
else |
|
908 |
{ |
|
909 |
aFile = (CFileCB*) scratchValueLow; |
|
910 |
} |
|
911 |
} |
|
912 |
||
913 |
/** |
|
914 |
Common init preamble for TFsFileWrite::Initialise() and TFsFileWrite::DoRequestL() |
|
915 |
||
916 |
@param aShare pointer to the file share |
|
917 |
@param aFile pointer to the file object this function is called for |
|
918 |
@param aPos file position to write data. Note that it can be KCurrentPosition64 i.e. KMaxTUint64 |
|
919 |
@param aLen length of the data to write |
|
920 |
@param aFileSize current file size |
|
921 |
@param aFsOp File Server message code. See TFsMessage. It must be ether EFsFileWrite for normal write, or EFsFileWriteDirty when file cache flushes dirty data |
|
922 |
*/ |
|
923 |
||
924 |
TInt TFsFileWrite::CommonInit(CFileShare* aShare, CFileCB* aFile, TInt64& aPos, TInt& aLen, TInt64 aFileSize, TFsMessage aFsOp) |
|
925 |
{ |
|
926 |
||
927 |
if (aShare && aPos==KCurrentPosition64) |
|
928 |
{//-- write to the current position in the file |
|
929 |
aPos = aShare->iPos; |
|
930 |
} |
|
931 |
||
932 |
if(aPos > aFileSize) |
|
933 |
aPos = aFileSize; |
|
934 |
||
935 |
//-- check that the new position won't exceed maximum file size |
|
936 |
{ |
|
937 |
const TUint64 endPos = aPos+aLen; |
|
938 |
||
939 |
//-- Large file mode check. Legacy RFile size can't exceed 2G-1 |
|
940 |
if(aShare && !(aShare->IsFileModeBig()) && (endPos > KMaxLegacyFileSize)) |
|
941 |
return KErrTooBig; |
|
942 |
||
943 |
//-- check CMountCB limitation on maximum file size |
|
944 |
if(endPos > aFile->MaxSupportedSize()) |
|
945 |
return KErrNotSupported; //-- this is for the sake of error codes consistency; current FSYs return |
|
946 |
//-- this code in the case of accessing a file beyond its limit |
|
947 |
} |
|
948 |
||
949 |
if (aShare) |
|
950 |
{ |
|
951 |
TInt r; |
|
952 |
if ((r=aFile->CheckLock64(aShare,aPos,aLen))!=KErrNone) |
|
953 |
return(r); |
|
954 |
} |
|
955 |
||
956 |
ASSERT(aFsOp == EFsFileWrite || aFsOp == EFsFileWriteDirty); |
|
957 |
if(aFsOp == EFsFileWrite) |
|
958 |
{//-- this call is originated from explicit file write operation. Set 'Archive' attribute and new file time. |
|
959 |
aFile->SetArchiveAttribute(); //-- it will also set KEntryAttModified |
|
960 |
} |
|
961 |
else |
|
962 |
{//-- don't touch data and attributes if it is cache flushing dirty data |
|
963 |
aFile->iAtt |= KEntryAttModified; |
|
964 |
} |
|
965 |
||
966 |
||
967 |
return KErrNone; |
|
968 |
} |
|
969 |
||
970 |
void TFsFileWrite::CommonEnd(CFsMessageRequest* aMsgRequest, TInt aRetVal, TUint64 aInitSize, TUint64 aNewSize, TInt64 aNewPos, TBool aFileWrite) |
|
971 |
// |
|
972 |
// Common end for TFsFileWrite::DoRequestL() and CFileCache::WriteBuffered() |
|
973 |
// |
|
974 |
{ |
|
975 |
||
976 |
CFileShare* share; |
|
977 |
CFileCB* file; |
|
978 |
GetFileFromScratch(aMsgRequest, share, file); |
|
979 |
CFileCache* fileCache = file->FileCache(); |
|
980 |
ASSERT(aFileWrite || fileCache); |
|
981 |
||
982 |
TMsgOperation& currentOperation = aMsgRequest->CurrentOperation(); |
|
983 |
||
984 |
if (aRetVal == KErrNone || aRetVal == CFsRequest::EReqActionComplete) |
|
985 |
{ |
|
986 |
if (share) |
|
987 |
{ |
|
988 |
__e32_atomic_store_ord64(&share->iPos, aNewPos); |
|
989 |
} |
|
990 |
||
991 |
if ((TUint64)aNewPos > aNewSize) |
|
992 |
{ |
|
993 |
if(aFileWrite) |
|
994 |
file->SetSize64(aNewPos, EFalse); |
|
995 |
else |
|
996 |
fileCache->SetSize64(aNewPos); |
|
997 |
aNewSize = aNewPos; |
|
998 |
} |
|
999 |
||
1000 |
// ensure cached file is at least as big as uncached file |
|
1001 |
if (fileCache && fileCache->Size64() < aNewPos) |
|
1002 |
{ |
|
1003 |
file->SetCachedSize64(aNewPos); |
|
1004 |
} |
|
1005 |
||
1006 |
// Service async reads if the file has grown & this is the last fair-scheduled request |
|
1007 |
||
1008 |
// If the file has grown, flag this and call CFileCB::NotifyAsyncReaders() |
|
1009 |
// later in TFsFileWrite::Complete() - we need to delay the call because |
|
1010 |
// CFileCB::NotifyAsyncReaders() may requeue a request which will cause |
|
1011 |
// the drive thread to spin because this file share is still marked as in use |
|
1012 |
// (by CFileShare::RequestStart()) |
|
1013 |
if((aNewSize > aInitSize) && (currentOperation.iReadWriteArgs.iTotalLength == 0)) |
|
1014 |
{ |
|
1015 |
file->SetNotifyAsyncReadersPending(ETrue); |
|
1016 |
} |
|
1017 |
||
1018 |
file->iAtt |= KEntryAttModified; |
|
1019 |
||
1020 |
} |
|
1021 |
else if (aRetVal == KErrCorrupt) |
|
1022 |
file->SetFileCorrupt(ETrue); |
|
1023 |
else if (aRetVal == KErrBadPower || (aRetVal == KErrAbort && !PowerOk())) |
|
1024 |
file->SetBadPower(ETrue); |
|
1025 |
||
1026 |
file->ResetReadAhead(); |
|
1027 |
aMsgRequest->SetFreeChanged(aNewSize != aInitSize); |
|
1028 |
} |
|
1029 |
||
1030 |
TInt TFsFileWrite::DoRequestL(CFsRequest* aRequest) |
|
1031 |
// |
|
1032 |
// Write to a file. |
|
1033 |
// |
|
1034 |
{ |
|
1035 |
__PRINT(_L("TFsFileWrite::DoRequestL(CFsRequest* aRequest)")); |
|
1036 |
||
1037 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest; |
|
1038 |
__ASSERT_DEBUG(msgRequest.CurrentOperationPtr() != NULL, Fault(EBadOperationIndex)); |
|
1039 |
TMsgOperation& currentOperation = msgRequest.CurrentOperation(); |
|
1040 |
||
1041 |
TInt r; |
|
1042 |
||
1043 |
CFileShare* share; |
|
1044 |
CFileCB* file; |
|
1045 |
GetFileFromScratch(aRequest, share, file); |
|
1046 |
||
1047 |
TInt64 initSize = file->Size64(); |
|
1048 |
||
1049 |
r = file->CheckMount(); |
|
1050 |
if (r!=KErrNone) |
|
1051 |
return(r); |
|
1052 |
||
1053 |
||
1054 |
TInt& len = currentOperation.iReadWriteArgs.iLength; |
|
1055 |
||
1056 |
// Fair scheduling - |
|
1057 |
// Needs extended file API to work (so that we can specify an offset) |
|
1058 |
// Also needs a separate drive thread to prevent excessive stack usage |
|
1059 |
len = Min(len, currentOperation.iReadWriteArgs.iTotalLength); |
|
1060 |
if (file->ExtendedFileInterfaceSupported() && !FsThreadManager::IsDriveSync(aRequest->DriveNumber(), EFalse)) |
|
1061 |
{ |
|
1062 |
len = Min(len, file->FairSchedulingLen()); |
|
1063 |
} |
|
1064 |
||
1065 |
__ASSERT_DEBUG(len <= currentOperation.iReadWriteArgs.iTotalLength, Fault(EInvalidWriteLength)); |
|
1066 |
||
1067 |
||
1068 |
const TFsMessage fsOp = (TFsMessage)aRequest->Operation()->Function(); |
|
1069 |
r = CommonInit(share, file, currentOperation.iReadWriteArgs.iPos, len, initSize, fsOp); |
|
1070 |
||
1071 |
if (r != KErrNone) |
|
1072 |
return r; |
|
1073 |
||
1074 |
TInt64 pos = currentOperation.iReadWriteArgs.iPos; |
|
1075 |
||
1076 |
TInt64 upos = pos+len; |
|
1077 |
if (upos > initSize) |
|
1078 |
{ |
|
1079 |
r = CheckDiskSpace(upos - initSize, aRequest); |
|
1080 |
if(r != KErrNone) |
|
1081 |
return r; |
|
1082 |
} |
|
1083 |
||
1084 |
// The mount and any extensions must all support local buffers in order to support |
|
1085 |
// internally generated requests (ie - requests originating from plugins) |
|
1086 |
if ((aRequest->Message().Handle() == KLocalMessageHandle || !currentOperation.iClientRequest) && !file->LocalBufferSupport()) |
|
1087 |
{ |
|
1088 |
r = KErrNotSupported; |
|
1089 |
} |
|
1090 |
||
1091 |
if(r == KErrNone) |
|
1092 |
{ |
|
1093 |
if (currentOperation.iClientRequest) |
|
1094 |
{ |
|
1095 |
TRAP(r,file->WriteL(pos, len, (const TPtrC8*) aRequest->Message().Ptr0(), aRequest->Message(), currentOperation.iReadWriteArgs.iOffset)) |
|
1096 |
} |
|
1097 |
else |
|
1098 |
{ |
|
1099 |
TPtr8 dataDesc((TUint8*) currentOperation.iReadWriteArgs.iData + currentOperation.iReadWriteArgs.iOffset, len, len); |
|
1100 |
const RLocalMessage msg; |
|
1101 |
TRAP(r,file->WriteL(pos, len, &dataDesc, msg, 0)); |
|
1102 |
} |
|
1103 |
} |
|
1104 |
||
1105 |
//RDebug::Print(_L("WriteR: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file); |
|
1106 |
||
1107 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1108 |
CCacheManager* manager = CCacheManagerFactory::CacheManager(); |
|
1109 |
if (manager) |
|
1110 |
{ |
|
1111 |
manager->Stats().iUncachedPacketsWritten++; |
|
1112 |
manager->Stats().iUncachedBytesWritten+= len; |
|
1113 |
} |
|
1114 |
#endif |
|
1115 |
||
1116 |
if (r == KErrNone) |
|
1117 |
{ |
|
1118 |
// update position, offset & length remaining |
|
1119 |
currentOperation.iReadWriteArgs.iOffset+= len; |
|
1120 |
currentOperation.iReadWriteArgs.iPos+= len; |
|
1121 |
currentOperation.iReadWriteArgs.iTotalLength-= len; |
|
1122 |
} |
|
1123 |
TUint64 currentSize = MAKE_TUINT64(file->iBody->iSizeHigh,file->iSize); |
|
1124 |
CommonEnd(&msgRequest, r, initSize, currentSize, pos+len, ETrue); |
|
1125 |
||
1126 |
// re-issue request if not complete (to support fair scheduling) |
|
1127 |
if (r == KErrNone && currentOperation.iReadWriteArgs.iTotalLength > 0) |
|
1128 |
return CFsRequest::EReqActionBusy; // dispatch request again to back of queue |
|
1129 |
||
1130 |
return(r); |
|
1131 |
} |
|
1132 |
||
1133 |
TInt TFsFileWrite::Initialise(CFsRequest* aRequest) |
|
1134 |
// |
|
1135 |
// |
|
1136 |
// |
|
1137 |
{ |
|
1138 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest; |
|
1139 |
||
1140 |
TInt r = DoInitNoParse(aRequest); |
|
1141 |
if (r != KErrNone) |
|
1142 |
return r; |
|
1143 |
||
1144 |
// If the drive has been dismounted, don't even attempt to write to the file as that |
|
1145 |
// will create dirty data which can then not be flushed without hitting ASSERTs etc. |
|
1146 |
if (!FsThreadManager::IsDriveAvailable(aRequest->DriveNumber(), EFalse)) |
|
1147 |
return KErrNotReady; |
|
1148 |
||
1149 |
CFileShare* share; |
|
1150 |
CFileCB* file; |
|
1151 |
GetFileFromScratch(aRequest, share, file); |
|
1152 |
||
1153 |
// Bail out if there's a new mount which isn't ours - this would fail |
|
1154 |
// later on anyway when TFsFileWrite::DoRequestL() called CFileCB::CheckMount() |
|
1155 |
if ( !file->Drive().IsCurrentMount(file->Mount()) ) |
|
1156 |
return KErrDisMounted; |
|
1157 |
||
1158 |
||
1159 |
TMsgOperation* msgOp = msgRequest.CurrentOperationPtr(); |
|
1160 |
if (!msgOp) // initialised already ? |
|
1161 |
{ |
|
1162 |
r = msgRequest.PushOperation(TFsFileWrite::Complete); |
|
1163 |
if (r != KErrNone) |
|
1164 |
return r; |
|
1165 |
msgOp = msgRequest.CurrentOperationPtr(); |
|
1166 |
} |
|
1167 |
// try to serialize requests to prevent asynchronous requests being processed out of sequence - |
|
1168 |
// this isn't possible if a plugin is loaded as this may issue it's own requests |
|
1169 |
if (share && !share->RequestStart(&msgRequest)) |
|
1170 |
return CFsRequest::EReqActionPending; |
|
1171 |
||
1172 |
TInt64 pos; |
|
1173 |
||
1174 |
if(aRequest->IsDescData(KMsgPtr2)) |
|
1175 |
{//-- 64-bit file addressing, absolute read position is TInt64 |
|
1176 |
TPckg<TInt64> pkPos(pos); |
|
1177 |
aRequest->ReadL(KMsgPtr2, pkPos); |
|
1178 |
} |
|
1179 |
else |
|
1180 |
{ |
|
1181 |
if(aRequest->Message().Int2() == (TInt)I64LOW(KCurrentPosition64)) |
|
1182 |
pos = KCurrentPosition64;// Position is KCurrentPosition64 (-1) |
|
1183 |
else |
|
1184 |
pos = MAKE_TINT64(0,aRequest->Message().Int2());// Position is absolute value < 4GB, it's a TUint type |
|
1185 |
} |
|
1186 |
||
1187 |
msgOp->iClientPosition = pos; |
|
1188 |
TInt len = aRequest->Message().Int1(); |
|
1189 |
||
1190 |
TDesC8* pD = (TDes8*) aRequest->Message().Ptr0(); |
|
1191 |
||
1192 |
if (len == 0) |
|
1193 |
return CFsRequest::EReqActionComplete; |
|
1194 |
||
1195 |
if (len < 0) |
|
1196 |
return KErrArgument; |
|
1197 |
||
1198 |
//if this request was sent down from a plugin, then we want to |
|
1199 |
//ignore the mode that the files was opened in. |
|
1200 |
if (share && !msgRequest.IsPluginRequest()) |
|
1201 |
{ |
|
1202 |
if ((share->iMode & EFileWrite)==0 || |
|
1203 |
(share->iMode & KFileShareMask) == EFileShareReadersOnly) |
|
1204 |
{ |
|
1205 |
return(KErrAccessDenied); |
|
1206 |
} |
|
1207 |
} |
|
1208 |
||
1209 |
||
1210 |
const TFsMessage fsOp = (TFsMessage)aRequest->Operation()->Function(); |
|
1211 |
r = CommonInit(share, file, pos, len, file->CachedSize64(), fsOp); |
|
1212 |
if (r != KErrNone) |
|
1213 |
return r; |
|
1214 |
||
1215 |
msgOp->Set(pos, len, pD); |
|
1216 |
||
1217 |
return KErrNone; |
|
1218 |
} |
|
1219 |
||
1220 |
||
1221 |
TInt TFsFileWrite::PostInitialise(CFsRequest* aRequest) |
|
1222 |
{ |
|
1223 |
CFileShare* share = (CFileShare*) aRequest->ScratchValue(); |
|
1224 |
CFileCB* file = &share->File(); |
|
1225 |
TInt r = KErrNone; |
|
1226 |
||
1227 |
CFileCache* fileCache = file->FileCache(); |
|
1228 |
if (fileCache) |
|
1229 |
{ |
|
1230 |
// If there's no data left proceed straight to completion stage |
|
1231 |
// This can happen when re-posting a completed write request to |
|
1232 |
// start the dirty data timer |
|
1233 |
if (((CFsMessageRequest*) aRequest)->CurrentOperation().iReadWriteArgs.iTotalLength == 0) |
|
1234 |
return CFsRequest::EReqActionComplete; |
|
1235 |
||
1236 |
r = fileCache->WriteBuffered(*(CFsMessageRequest*)aRequest, share->iMode); |
|
1237 |
} |
|
1238 |
||
1239 |
return r; |
|
1240 |
} |
|
1241 |
||
1242 |
TInt TFsFileWrite::Complete(CFsRequest* aRequest) |
|
1243 |
{ |
|
1244 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest; |
|
1245 |
||
1246 |
||
1247 |
CFileShare* share; |
|
1248 |
CFileCB* file; |
|
1249 |
GetFileFromScratch(aRequest, share, file); |
|
1250 |
||
1251 |
if (share) |
|
1252 |
share->RequestEnd(&msgRequest); |
|
1253 |
||
1254 |
if (file->NotifyAsyncReadersPending()) |
|
1255 |
file->NotifyAsyncReaders(); |
|
1256 |
||
1257 |
return CFsRequest::EReqActionComplete; |
|
1258 |
} |
|
1259 |
||
1260 |
TInt TFsFileLock::DoRequestL(CFsRequest* aRequest) |
|
1261 |
// |
|
1262 |
// Lock a region of the file. |
|
1263 |
// |
|
1264 |
{ |
|
1265 |
||
1266 |
__PRINT(_L("TFsFileLock::DoRequestL(CFsRequest* aRequest)")); |
|
1267 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1268 |
||
1269 |
// We must wait for ALL shares to have no active requests (see RequestStart()) |
|
1270 |
// and post this request to the back of the queue if there are any. This is to |
|
1271 |
// avoid a fair-scheduled write from writing to a locked region of a file |
|
1272 |
CSessionFs* session = aRequest->Session(); |
|
1273 |
if (session) |
|
1274 |
{ |
|
1275 |
TBool fileInUse = EFalse; |
|
1276 |
session->Handles().Lock(); |
|
1277 |
TInt count = session->Handles().Count(); |
|
1278 |
CFileCB* file = &share->File(); |
|
1279 |
||
1280 |
for (TInt n=0; n<count; n++) |
|
1281 |
{ |
|
1282 |
CObjPromotion* obj = (CObjPromotion*)session->Handles()[n]; |
|
1283 |
if (obj != NULL && |
|
1284 |
obj->UniqueID() == FileShares->UniqueID() && |
|
1285 |
(file == &((CFileShare*) obj)->File()) && |
|
1286 |
((CFileShare*) obj)->RequestInProgress()) |
|
1287 |
{ |
|
1288 |
CFsMessageRequest& msgRequest = *(CFsMessageRequest*)aRequest; |
|
1289 |
if(msgRequest.IsPluginRequest()) |
|
1290 |
break; |
|
1291 |
||
1292 |
fileInUse = ETrue; |
|
1293 |
break; |
|
1294 |
} |
|
1295 |
} |
|
1296 |
session->Handles().Unlock(); |
|
1297 |
if (fileInUse) |
|
1298 |
return CFsRequest::EReqActionBusy; |
|
1299 |
} |
|
1300 |
||
1301 |
TInt64 pos, length; |
|
1302 |
if(aRequest->IsDescData(KMsgPtr0)) |
|
1303 |
{ |
|
1304 |
TPckg<TInt64> pkPos(pos); |
|
1305 |
aRequest->ReadL(KMsgPtr0, pkPos); |
|
1306 |
} |
|
1307 |
else |
|
1308 |
{ |
|
1309 |
pos = MAKE_TINT64(0, aRequest->Message().Int0()); |
|
1310 |
} |
|
1311 |
||
1312 |
if(aRequest->IsDescData(KMsgPtr1)) |
|
1313 |
{ |
|
1314 |
TPckg<TInt64> pkLength(length); |
|
1315 |
aRequest->ReadL(KMsgPtr1, pkLength); |
|
1316 |
if(length <= 0) |
|
1317 |
User::Leave(ELockLengthZero); |
|
1318 |
} |
|
1319 |
else |
|
1320 |
{ |
|
1321 |
length = aRequest->Message().Int1(); |
|
1322 |
if(length <= 0) |
|
1323 |
User::Leave(ELockLengthZero); |
|
1324 |
} |
|
1325 |
return(share->File().AddLock64(share, pos, length)); |
|
1326 |
} |
|
1327 |
||
1328 |
TInt TFsFileLock::Initialise(CFsRequest* aRequest) |
|
1329 |
// |
|
1330 |
// |
|
1331 |
// |
|
1332 |
{ |
|
1333 |
return(DoInitNoParse(aRequest)); |
|
1334 |
} |
|
1335 |
||
1336 |
||
1337 |
TInt TFsFileUnlock::DoRequestL(CFsRequest* aRequest) |
|
1338 |
// |
|
1339 |
// Unlock a region of the file. |
|
1340 |
// |
|
1341 |
{ |
|
1342 |
__PRINT(_L("TFsFileUnlock::DoRequestL(CFsRequest* aRequest)")); |
|
1343 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1344 |
||
1345 |
TInt64 pos, length; |
|
1346 |
||
1347 |
if(aRequest->IsDescData(KMsgPtr0)) |
|
1348 |
{ |
|
1349 |
TPckg<TInt64> pkPos(pos); |
|
1350 |
aRequest->ReadL(KMsgPtr0, pkPos); |
|
1351 |
} |
|
1352 |
else |
|
1353 |
{ |
|
1354 |
pos = MAKE_TINT64(0, aRequest->Message().Int0()); |
|
1355 |
} |
|
1356 |
||
1357 |
if(aRequest->IsDescData(KMsgPtr1)) |
|
1358 |
{ |
|
1359 |
TPckg<TInt64> pkLength(length); |
|
1360 |
aRequest->ReadL(KMsgPtr1, pkLength); |
|
1361 |
if(length <= 0) |
|
1362 |
User::Leave(EUnlockLengthZero); |
|
1363 |
} |
|
1364 |
else |
|
1365 |
{ |
|
1366 |
length = aRequest->Message().Int1(); |
|
1367 |
if(length <= 0) |
|
1368 |
User::Leave(EUnlockLengthZero); |
|
1369 |
} |
|
1370 |
return(share->File().RemoveLock64(share, pos, length)); |
|
1371 |
} |
|
1372 |
||
1373 |
TInt TFsFileUnlock::Initialise(CFsRequest* aRequest) |
|
1374 |
// |
|
1375 |
// |
|
1376 |
// |
|
1377 |
{ |
|
1378 |
return(DoInitNoParse(aRequest)); |
|
1379 |
} |
|
1380 |
||
1381 |
||
1382 |
TInt TFsFileSeek::DoRequestL(CFsRequest* aRequest) |
|
1383 |
// |
|
1384 |
// Set the file position. |
|
1385 |
// |
|
1386 |
{ |
|
1387 |
||
1388 |
__PRINT(_L("TFsFileSeek::DoRequestL(CFsRequest* aRequest)")); |
|
1389 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1390 |
TInt64 size = share->File().CachedSize64(); |
|
1391 |
TInt64 pos; |
|
1392 |
if(aRequest->IsDescData(KMsgPtr0)) |
|
1393 |
{ |
|
1394 |
TPckg<TInt64> pkPos(pos); |
|
1395 |
aRequest->ReadL(KMsgPtr0, pkPos); |
|
1396 |
} |
|
1397 |
else |
|
1398 |
{ |
|
1399 |
pos = aRequest->Message().Int0(); |
|
1400 |
} |
|
1401 |
||
1402 |
TInt r,t; |
|
1403 |
||
1404 |
if (share->iPos != pos) |
|
1405 |
share->File().ResetReadAhead(); |
|
1406 |
||
1407 |
switch (aRequest->Message().Int1()) |
|
1408 |
{ |
|
1409 |
case ESeekCurrent: |
|
1410 |
pos+=share->iPos; |
|
1411 |
if (pos<0) |
|
1412 |
pos=0; |
|
1413 |
||
1414 |
if (pos>size) |
|
1415 |
pos=size; |
|
1416 |
||
1417 |
// Large file mode check |
|
1418 |
if((!(share->IsFileModeBig())) && ((TUint64)pos > KMaxLegacyFileSize)) |
|
1419 |
return (KErrTooBig); |
|
1420 |
||
1421 |
break; |
|
1422 |
case ESeekEnd: |
|
1423 |
pos+=size; |
|
1424 |
if (pos<0) |
|
1425 |
pos=0; |
|
1426 |
if (pos>size) |
|
1427 |
pos=size; |
|
1428 |
// Large file mode check |
|
1429 |
if((!(share->IsFileModeBig())) && ((TUint64)pos > KMaxLegacyFileSize)) |
|
1430 |
return (KErrTooBig); |
|
1431 |
||
1432 |
break; |
|
1433 |
case ESeekAddress: |
|
1434 |
t = (TUint)pos; |
|
1435 |
r = share->File().Address(t); |
|
1436 |
pos = (TUint)t; |
|
1437 |
if(KErrNone != r) |
|
1438 |
return(r); |
|
1439 |
goto writeBackPos; |
|
1440 |
case ESeekStart: |
|
1441 |
if (pos>=0) |
|
1442 |
{ |
|
1443 |
share->iPos = pos; |
|
1444 |
return KErrNone; |
|
1445 |
} |
|
1446 |
return(KErrArgument); |
|
1447 |
default: |
|
1448 |
return(KErrArgument); |
|
1449 |
} |
|
1450 |
__e32_atomic_store_ord64(&share->iPos, pos); |
|
1451 |
writeBackPos: |
|
1452 |
TPckgC<TInt64> pkNewPos(pos); |
|
1453 |
aRequest->WriteL(KMsgPtr2, pkNewPos); |
|
1454 |
return(KErrNone); |
|
1455 |
} |
|
1456 |
||
1457 |
TInt TFsFileSeek::Initialise(CFsRequest* aRequest) |
|
1458 |
// |
|
1459 |
// |
|
1460 |
// |
|
1461 |
{ |
|
1462 |
return(DoInitNoParse(aRequest)); |
|
1463 |
} |
|
1464 |
||
1465 |
||
1466 |
TInt TFsFileFlush::DoRequestL(CFsRequest* aRequest) |
|
1467 |
// |
|
1468 |
// Commit any data in memory to the media. |
|
1469 |
// |
|
1470 |
{ |
|
1471 |
||
1472 |
__PRINT(_L("TFsFileFlush::DoRequestL(CFsRequest* aRequest)")); |
|
1473 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1474 |
||
1475 |
// if any write requests are being fair scheduled, wait for them to complete |
|
1476 |
if (share->RequestInProgress()) |
|
1477 |
return CFsRequest::EReqActionBusy; |
|
1478 |
||
1479 |
// flush the write cache |
|
1480 |
TInt r; |
|
1481 |
CFileCache* fileCache = share->File().FileCache(); |
|
1482 |
if (fileCache && (r = fileCache->FlushDirty(aRequest)) != CFsRequest::EReqActionComplete) |
|
1483 |
{ |
|
1484 |
//To be used in notification framework |
|
1485 |
//CFsMessageRequest& msgRequest = (CFsMessageRequest&)*aRequest; |
|
1486 |
//msgRequest.iUID = msgRequest.Message().Identity(); |
|
1487 |
return r; |
|
1488 |
} |
|
1489 |
||
1490 |
if ((share->File().Att()&KEntryAttModified)==0) |
|
1491 |
return(KErrNone); |
|
1492 |
if ((share->iMode&EFileWrite)==0) |
|
1493 |
return(KErrAccessDenied); |
|
1494 |
r=share->CheckMount(); |
|
1495 |
if (r!=KErrNone) |
|
1496 |
return(r); |
|
1497 |
||
1498 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataL, EF32TraceUidFileSys, &share->File()); |
|
1499 |
TRAP(r,share->File().FlushDataL()); |
|
1500 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataLRet, EF32TraceUidFileSys, r); |
|
1501 |
||
1502 |
return(r); |
|
1503 |
} |
|
1504 |
||
1505 |
TInt TFsFileFlush::Initialise(CFsRequest* aRequest) |
|
1506 |
// |
|
1507 |
// |
|
1508 |
// |
|
1509 |
{ |
|
1510 |
return(DoInitNoParse(aRequest)); |
|
1511 |
} |
|
1512 |
||
1513 |
||
1514 |
TInt TFsFileSize::DoRequestL(CFsRequest* aRequest) |
|
1515 |
// |
|
1516 |
// Get the file size. |
|
1517 |
// |
|
1518 |
{ |
|
1519 |
||
1520 |
__PRINT(_L("TFsFileSize::DoRequestL(CFsRequest* aRequest)")); |
|
1521 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1522 |
TInt64 size = share->File().CachedSize64(); |
|
1523 |
// Large file mode check and error handling is done at client library side. |
|
1524 |
// Return file size even if it is greater than 2GB - 1. |
|
1525 |
TPckgC<TInt64> pkSize(size); |
|
1526 |
aRequest->WriteL(KMsgPtr0, pkSize); |
|
1527 |
return(KErrNone); |
|
1528 |
} |
|
1529 |
||
1530 |
TInt TFsFileSize::Initialise(CFsRequest* aRequest) |
|
1531 |
// |
|
1532 |
// |
|
1533 |
// |
|
1534 |
{ |
|
1535 |
return(DoInitNoParse(aRequest)); |
|
1536 |
} |
|
1537 |
||
1538 |
||
1539 |
TInt TFsFileSetSize::DoRequestL(CFsRequest* aRequest) |
|
1540 |
// |
|
1541 |
// Set the file size. |
|
1542 |
// |
|
1543 |
{ |
|
1544 |
__PRINT(_L("TFsFileSetSize::DoRequestL(CFsRequest* aRequest)")); |
|
1545 |
||
1546 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1547 |
if ((share->iMode&EFileWrite)==0) |
|
1548 |
return(KErrAccessDenied); |
|
1549 |
TInt r=share->CheckMount(); |
|
1550 |
if (r!=KErrNone) |
|
1551 |
return(r); |
|
1552 |
||
1553 |
TInt64 size; |
|
1554 |
if(aRequest->IsDescData(KMsgPtr0)) |
|
1555 |
{ |
|
1556 |
TPckg<TInt64> pkSize(size); |
|
1557 |
aRequest->ReadL(KMsgPtr0, pkSize); |
|
1558 |
} |
|
1559 |
else |
|
1560 |
{ |
|
1561 |
size = aRequest->Message().Int0(); |
|
1562 |
} |
|
1563 |
||
1564 |
if(size < 0) |
|
1565 |
User::Leave(ESizeNegative); |
|
1566 |
||
1567 |
// Large file mode check |
|
1568 |
if((!(share->IsFileModeBig())) && ((TUint64)size > KMaxLegacyFileSize)) |
|
1569 |
return (KErrTooBig); |
|
1570 |
||
1571 |
CFileCB& file=share->File(); |
|
1572 |
||
1573 |
// flush the write cache |
|
1574 |
CFileCache* fileCache = share->File().FileCache(); |
|
1575 |
if (fileCache && (r = fileCache->FlushDirty(aRequest)) != CFsRequest::EReqActionComplete) |
|
1576 |
return r; |
|
1577 |
||
1578 |
if (size==file.Size64()) |
|
1579 |
return(KErrNone); |
|
1580 |
||
1581 |
TBool fileHasGrown = size > file.Size64(); |
|
1582 |
if (fileHasGrown) |
|
1583 |
{ |
|
1584 |
r = CheckDiskSpace(size - file.Size64(), aRequest); |
|
1585 |
if(r != KErrNone) |
|
1586 |
return r; |
|
1587 |
||
1588 |
r=file.CheckLock64(share,file.Size64(),size-file.Size64()); |
|
1589 |
} |
|
1590 |
else |
|
1591 |
r=file.CheckLock64(share,size,file.Size64()-size); |
|
1592 |
if (r!=KErrNone) |
|
1593 |
return(r); |
|
1594 |
__PRINT1(_L("Owner mount size before SetSize() = %d"),I64LOW(file.Mount().Size())); |
|
1595 |
TRAP(r,file.SetSizeL(size)) |
|
1596 |
if (r!=KErrNone) |
|
1597 |
{ |
|
1598 |
// Set size failed |
|
1599 |
__PRINT1(_L("SetSize() failed = %d"),r); |
|
1600 |
__PRINT1(_L("Owner mount size now = %d"),I64LOW(file.Mount().Size())); |
|
1601 |
return(r); |
|
1602 |
} |
|
1603 |
file.SetArchiveAttribute(); |
|
1604 |
file.SetSize64(size, EFalse); |
|
1605 |
file.SetCachedSize64(size); |
|
1606 |
||
1607 |
if(fileHasGrown) |
|
1608 |
file.NotifyAsyncReaders(); // Service outstanding async reads if the file has grown |
|
1609 |
||
1610 |
return(r); |
|
1611 |
} |
|
1612 |
||
1613 |
TInt TFsFileSetSize::Initialise(CFsRequest* aRequest) |
|
1614 |
// |
|
1615 |
// |
|
1616 |
// |
|
1617 |
{ |
|
1618 |
return(DoInitNoParse(aRequest)); |
|
1619 |
} |
|
1620 |
||
1621 |
||
1622 |
TInt TFsFileAtt::DoRequestL(CFsRequest* aRequest) |
|
1623 |
// |
|
1624 |
// Get the file attributes. |
|
1625 |
// |
|
1626 |
{ |
|
1627 |
||
1628 |
__PRINT(_L("TFsFileAtt::DoRequestL(CFsRequest* aRequest)")); |
|
1629 |
||
1630 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1631 |
// TInt att=(TInt)aRequest->FileShare()->File().Att()&KEntryAttMaskSupported; |
|
1632 |
TInt att=(TInt)share->File().Att(); // DRM: let ROM XIP attribute through |
|
1633 |
TPtrC8 pA((TUint8*)&att,sizeof(TInt)); |
|
1634 |
aRequest->WriteL(KMsgPtr0,pA); |
|
1635 |
||
1636 |
return(KErrNone); |
|
1637 |
} |
|
1638 |
||
1639 |
TInt TFsFileAtt::Initialise(CFsRequest* aRequest) |
|
1640 |
// |
|
1641 |
// |
|
1642 |
// |
|
1643 |
{ |
|
1644 |
return(DoInitNoParse(aRequest)); |
|
1645 |
} |
|
1646 |
||
1647 |
||
1648 |
TInt TFsFileSetAtt::DoRequestL(CFsRequest* aRequest) |
|
1649 |
// |
|
1650 |
// Set the file attributes. |
|
1651 |
// |
|
1652 |
{ |
|
1653 |
__PRINT(_L("TFsFileSetAtt::DoRequestL(CSessionFs* aSession)")); |
|
1654 |
||
1655 |
TInt r = CheckDiskSpace(0, aRequest); |
|
1656 |
if(r != KErrNone) |
|
1657 |
return r; |
|
1658 |
||
1659 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1660 |
r=share->CheckMount(); |
|
1661 |
if (r!=KErrNone) |
|
1662 |
return(r); |
|
1663 |
||
1664 |
if ((share->iMode&EFileWrite)==EFalse) |
|
1665 |
return(KErrAccessDenied); |
|
1666 |
||
1667 |
TUint setAttMask=(TUint)(aRequest->Message().Int0()); |
|
1668 |
TUint clearAttMask=(TUint)aRequest->Message().Int1(); |
|
1669 |
ValidateAtts(share->File().Att(),setAttMask,clearAttMask); |
|
1670 |
||
1671 |
TRACE5(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryL, EF32TraceUidFileSys, &share->File(), 0, 0, setAttMask,clearAttMask); |
|
1672 |
TRAP(r,share->File().SetEntryL(TTime(0),setAttMask,clearAttMask)) |
|
1673 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryLRet, EF32TraceUidFileSys, r); |
|
1674 |
||
1675 |
return(r); |
|
1676 |
} |
|
1677 |
||
1678 |
||
1679 |
TInt TFsFileSetAtt::Initialise(CFsRequest* aRequest) |
|
1680 |
// |
|
1681 |
// Call GetShareFromHandle to determine asynchronicity *** |
|
1682 |
// |
|
1683 |
{ |
|
1684 |
return(DoInitNoParse(aRequest)); |
|
1685 |
} |
|
1686 |
||
1687 |
||
1688 |
TInt TFsFileModified::DoRequestL(CFsRequest* aRequest) |
|
1689 |
// |
|
1690 |
// Get the modified date and time. |
|
1691 |
// |
|
1692 |
{ |
|
1693 |
__PRINT(_L("TFsFileModified::DoRequestL(CFsRequest* aRequest)")); |
|
1694 |
||
1695 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1696 |
TTime mod=share->File().Modified(); |
|
1697 |
TPtrC8 pM((TUint8*)&mod,sizeof(TTime)); |
|
1698 |
aRequest->WriteL(KMsgPtr0,pM); |
|
1699 |
||
1700 |
return(KErrNone); |
|
1701 |
} |
|
1702 |
||
1703 |
||
1704 |
TInt TFsFileModified::Initialise(CFsRequest* aRequest) |
|
1705 |
// |
|
1706 |
// Call GetShareFromHandle to determine asynchronicity *** |
|
1707 |
// |
|
1708 |
{ |
|
1709 |
return(DoInitNoParse(aRequest)); |
|
1710 |
} |
|
1711 |
||
1712 |
||
1713 |
TInt TFsFileSetModified::DoRequestL(CFsRequest* aRequest) |
|
1714 |
// |
|
1715 |
// Set the modified date and time. |
|
1716 |
// |
|
1717 |
{ |
|
1718 |
__PRINT(_L("TFsFileSetModified::DoRequestL(CFsRequest* aRequest)")); |
|
1719 |
||
1720 |
TInt r = CheckDiskSpace(0, aRequest); |
|
1721 |
if(r != KErrNone) |
|
1722 |
return r; |
|
1723 |
||
1724 |
||
1725 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1726 |
r=share->CheckMount(); |
|
1727 |
if (r!=KErrNone) |
|
1728 |
return(r); |
|
1729 |
||
1730 |
if ((share->iMode&EFileWrite)==EFalse) |
|
1731 |
return(KErrAccessDenied); |
|
1732 |
||
1733 |
TTime time; |
|
1734 |
TPtr8 t((TUint8*)&time,sizeof(TTime)); |
|
1735 |
aRequest->ReadL(KMsgPtr0,t); |
|
1736 |
||
1737 |
TRACE5(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryL, EF32TraceUidFileSys, &share->File(), 0, 0, KEntryAttModified,0); |
|
1738 |
TRAP(r,share->File().SetEntryL(time,KEntryAttModified,0)) |
|
1739 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryLRet, EF32TraceUidFileSys, r); |
|
1740 |
||
1741 |
return(r); |
|
1742 |
} |
|
1743 |
||
1744 |
||
1745 |
TInt TFsFileSetModified::Initialise(CFsRequest* aRequest) |
|
1746 |
// |
|
1747 |
// Call GetShareFromHandle to determine asynchronicity *** |
|
1748 |
// |
|
1749 |
{ |
|
1750 |
return(DoInitNoParse(aRequest)); |
|
1751 |
} |
|
1752 |
||
1753 |
TInt TFsFileSet::DoRequestL(CFsRequest* aRequest) |
|
1754 |
// |
|
1755 |
// Set the attributes and the modified date and time. |
|
1756 |
// |
|
1757 |
{ |
|
1758 |
__PRINT(_L("TFsFileSet::DoRequestL(CFsRequest* aRequest)")); |
|
1759 |
||
1760 |
TInt r = CheckDiskSpace(0, aRequest); |
|
1761 |
if(r != KErrNone) |
|
1762 |
return r; |
|
1763 |
||
1764 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1765 |
r=share->CheckMount(); |
|
1766 |
if (r!=KErrNone) |
|
1767 |
return(r); |
|
1768 |
||
1769 |
if (share->File().Att()&KEntryAttReadOnly) |
|
1770 |
return(KErrAccessDenied); |
|
1771 |
||
1772 |
if ((share->iMode&EFileWrite)==0) |
|
1773 |
{ |
|
1774 |
if(share->File().Drive().IsWriteProtected()) |
|
1775 |
return(KErrAccessDenied); |
|
1776 |
} |
|
1777 |
||
1778 |
TTime time; |
|
1779 |
TPtr8 t((TUint8*)&time,sizeof(TTime)); |
|
1780 |
aRequest->ReadL(KMsgPtr0,t); |
|
1781 |
TUint setAttMask=(TUint)(aRequest->Message().Int1()|KEntryAttModified); |
|
1782 |
TUint clearAttMask=(TUint)aRequest->Message().Int2(); |
|
1783 |
ValidateAtts(share->File().Att(),setAttMask,clearAttMask);// Validate attributes |
|
1784 |
||
1785 |
TRACE5(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryL, EF32TraceUidFileSys, &share->File(), 0, 0, setAttMask,clearAttMask); |
|
1786 |
TRAP(r,share->File().SetEntryL(time,setAttMask,clearAttMask)) |
|
1787 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryLRet, EF32TraceUidFileSys, r); |
|
1788 |
||
1789 |
return(r); |
|
1790 |
} |
|
1791 |
||
1792 |
TInt TFsFileSet::Initialise(CFsRequest* aRequest) |
|
1793 |
// |
|
1794 |
// |
|
1795 |
// |
|
1796 |
{ |
|
1797 |
return(DoInitNoParse(aRequest)); |
|
1798 |
} |
|
1799 |
||
1800 |
||
1801 |
TInt TFsFileChangeMode::DoRequestL(CFsRequest* aRequest) |
|
1802 |
// |
|
1803 |
// The access to a file may be changed from share exclusive to share readers only or vice versa. |
|
1804 |
// KErrAccessDenied is returned if the file has multiple readers. |
|
1805 |
// |
|
1806 |
{ |
|
1807 |
__PRINT(_L("TFsFileChangeMode::DoRequestL(CFsRequest* aRequest)")); |
|
1808 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1809 |
TInt r=share->CheckMount(); |
|
1810 |
if (r!=KErrNone) |
|
1811 |
return(r); |
|
1812 |
||
1813 |
const TFileMode currentMode = (TFileMode)share->iMode; |
|
1814 |
const TFileMode newMode = (TFileMode)aRequest->Message().Int0(); |
|
1815 |
||
1816 |
// check argument |
|
1817 |
// (only EFileShareExclusive and EFileShareReadersOnly are allowed) |
|
1818 |
if((newMode & ~EFileShareReadersOnly) != 0) |
|
1819 |
return KErrArgument; |
|
1820 |
||
1821 |
// check if the file is in EFileShareAny mode |
|
1822 |
if( (currentMode & EFileShareAny) || |
|
1823 |
// or the file has been opened for writing in EFileShareExclusive mode, |
|
1824 |
// and an attempt is made to change the access mode to EFileShareReadersOnly |
|
1825 |
((currentMode & EFileWrite) && |
|
1826 |
(currentMode & KFileShareMask) == EFileShareExclusive && |
|
1827 |
newMode == EFileShareReadersOnly) ) |
|
1828 |
return KErrAccessDenied; |
|
1829 |
||
1830 |
// check if an attempt is made to change the share mode to EFileShareExclusive |
|
1831 |
// while the file has multiple readers |
|
1832 |
if (newMode == EFileShareExclusive && (currentMode & KFileShareMask) != EFileShareExclusive) |
|
1833 |
{ |
|
1834 |
// Check no other CFileCB is reading the file. |
|
1835 |
FileShares->Lock(); |
|
1836 |
TInt count=FileShares->Count(); |
|
1837 |
TBool found=EFalse; |
|
1838 |
while(count--) |
|
1839 |
{ |
|
1840 |
CFileShare* fileShare=(CFileShare*)(*FileShares)[count]; |
|
1841 |
if (&fileShare->File()==&share->File()) |
|
1842 |
{ |
|
1843 |
if (found) |
|
1844 |
{ |
|
1845 |
FileShares->Unlock(); |
|
1846 |
return(KErrAccessDenied); |
|
1847 |
} |
|
1848 |
found=ETrue; |
|
1849 |
} |
|
1850 |
} |
|
1851 |
FileShares->Unlock(); |
|
1852 |
} |
|
1853 |
share->iMode&=~KFileShareMask; |
|
1854 |
share->iMode|=newMode; |
|
1855 |
share->File().SetShare(newMode); |
|
1856 |
return(KErrNone); |
|
1857 |
} |
|
1858 |
||
1859 |
||
1860 |
TInt TFsFileChangeMode::Initialise(CFsRequest* aRequest) |
|
1861 |
// |
|
1862 |
// |
|
1863 |
// |
|
1864 |
{ |
|
1865 |
TInt r = DoInitNoParse(aRequest); |
|
1866 |
if(r != KErrNone) |
|
1867 |
return r; |
|
1868 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1869 |
if(CompareResource(share->File().FileName().Mid(2)) ) |
|
1870 |
{ |
|
1871 |
if(!KCapFsFileChangeMode.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("File Change Mode"))) |
|
1872 |
return KErrPermissionDenied; |
|
1873 |
} |
|
1874 |
return KErrNone; |
|
1875 |
} |
|
1876 |
||
1877 |
||
1878 |
TInt TFsFileRename::DoRequestL(CFsRequest* aRequest) |
|
1879 |
// |
|
1880 |
// Rename the file if it was openned EFileShareExclusive |
|
1881 |
// |
|
1882 |
{ |
|
1883 |
__PRINT(_L("TFsFileRename::DoRequestL(CFsRequest* aRequest)")); |
|
1884 |
||
1885 |
TInt r = CheckDiskSpace(0, aRequest); |
|
1886 |
if(r != KErrNone) |
|
1887 |
return r; |
|
1888 |
||
1889 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1890 |
r=share->CheckMount(); |
|
1891 |
if (r!=KErrNone) |
|
1892 |
return(r); |
|
1893 |
||
1894 |
TInt currentMode=(share->iMode&KFileShareMask); |
|
1895 |
if ((currentMode&EFileShareAny) || (currentMode&EFileShareReadersOnly)) |
|
1896 |
return(KErrAccessDenied); // File must be EFileShareExclusive |
|
1897 |
||
1898 |
if ((share->iMode&EFileWrite)==0) |
|
1899 |
return(KErrAccessDenied); // File must have write permission |
|
1900 |
||
1901 |
TPtrC filePath = aRequest->Dest().FullName().Mid(2); |
|
1902 |
CFileCB& file = share->File(); |
|
1903 |
||
1904 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECFileCBRenameL, EF32TraceUidFileSys, |
|
1905 |
(TUint) &file, filePath); |
|
1906 |
TRAP(r,file.RenameL(filePath)); |
|
1907 |
TRACERETMULT1(UTF::EBorder, UTraceModuleFileSys::ECFileCBRenameLRet, EF32TraceUidFileSys, r); |
|
1908 |
||
1909 |
// Re-write the file's folded name & re-calculate the hash |
|
1910 |
if (r == KErrNone) |
|
1911 |
{ |
|
1912 |
TFileName filePathF; |
|
1913 |
filePathF.CopyF(filePath); |
|
1914 |
TRAP(r, AllocBufferL(file.iFileNameF, filePathF)); |
|
1915 |
file.iNameHash=CalcNameHash(*file.iFileNameF); |
|
1916 |
} |
|
1917 |
||
1918 |
return(r); |
|
1919 |
} |
|
1920 |
||
1921 |
TInt TFsFileRename::Initialise(CFsRequest* aRequest) |
|
1922 |
// |
|
1923 |
// |
|
1924 |
// |
|
1925 |
{ |
|
1926 |
TInt r=DoInitialise(aRequest); |
|
1927 |
if(r!=KErrNone) |
|
1928 |
return(r); |
|
1929 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1930 |
TFileName newName; |
|
1931 |
TRAP(r,aRequest->ReadL(KMsgPtr0,newName)); |
|
1932 |
if(r!=KErrNone) |
|
1933 |
return(r); |
|
1934 |
TDriveUnit currentDrive(share->File().Mount().Drive().DriveNumber()); |
|
1935 |
TDriveName driveName=currentDrive.Name(); |
|
1936 |
r=aRequest->Dest().Set(newName,&share->File().FileName(),&driveName); |
|
1937 |
if (r!=KErrNone) |
|
1938 |
return(r); |
|
1939 |
if (aRequest->Dest().IsWild()) |
|
1940 |
return(KErrBadName); |
|
1941 |
TInt driveNo; |
|
1942 |
if ((r=RFs::CharToDrive(aRequest->Dest().Drive()[0],driveNo))!=KErrNone) |
|
1943 |
return(r); |
|
1944 |
TDrive& drive=TheDrives[driveNo]; |
|
1945 |
if(drive.IsSubsted()) |
|
1946 |
{ |
|
1947 |
if ((drive.Subst().Length()+aRequest->Dest().FullName().Length())>(KMaxFileName+3)) |
|
1948 |
return(KErrBadName); |
|
1949 |
TFileName n=drive.Subst(); |
|
1950 |
n+=aRequest->Dest().FullName().Mid(3); |
|
1951 |
r=aRequest->Dest().Set(n,NULL,NULL); |
|
1952 |
if(r!=KErrNone) |
|
1953 |
return(r); |
|
1954 |
} |
|
1955 |
||
1956 |
TDriveUnit newDrive(aRequest->Dest().Drive()); |
|
1957 |
if (newDrive!=currentDrive) |
|
1958 |
return(KErrBadName); |
|
1959 |
if (IsIllegalFullName(aRequest->Dest().FullName().Mid(2))) |
|
1960 |
return(KErrBadName); |
|
1961 |
r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysFileRename,&KCapFsPriFileRename,&KCapFsROFileRename, __PLATSEC_DIAGNOSTIC_STRING("File Rename")); |
|
1962 |
return(r); |
|
1963 |
} |
|
1964 |
||
1965 |
||
1966 |
TInt TFsFileDrive::DoRequestL(CFsRequest* aRequest) |
|
1967 |
// |
|
1968 |
// Get the drive info for the file. |
|
1969 |
// |
|
1970 |
{ |
|
1971 |
__PRINT(_L("TFsFileDrive::DoRequestL(CFsRequest* aRequest)")); |
|
1972 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
1973 |
TDrive *dr = &share->File().Drive(); |
|
1974 |
||
1975 |
TPckgBuf<TInt> pkiF(dr->DriveNumber()); // copy drive number to user |
|
1976 |
aRequest->WriteL(KMsgPtr0, pkiF); |
|
1977 |
||
1978 |
TDriveInfo di; // copy drive info to user |
|
1979 |
dr->DriveInfo(di); |
|
1980 |
TPckgC<TDriveInfo> pkdiF(di); |
|
1981 |
aRequest->WriteL(KMsgPtr1, pkdiF); |
|
1982 |
||
1983 |
return(KErrNone); |
|
1984 |
} |
|
1985 |
||
1986 |
||
1987 |
TInt TFsFileDrive::Initialise(CFsRequest* aRequest) |
|
1988 |
// |
|
1989 |
// |
|
1990 |
// |
|
1991 |
{ |
|
1992 |
return(DoInitNoParse(aRequest)); |
|
1993 |
} |
|
1994 |
||
1995 |
||
1996 |
TInt TFsFileDuplicate::DoRequestL(CFsRequest* aRequest) |
|
1997 |
// |
|
1998 |
// Duplicate the received file handle ready for transfer to another process. |
|
1999 |
// The new file handle is written back to the client in a a mangled form to prevent |
|
2000 |
// it from being used. Calling TFsFileAdopt will de-mangle the handle. |
|
2001 |
// |
|
2002 |
{ |
|
2003 |
CFileShare* pS = (CFileShare*)aRequest->ScratchValue(); |
|
2004 |
||
2005 |
// get the file control block from the client's file share |
|
2006 |
CFileCB& fileCB = pS->File(); |
|
2007 |
||
2008 |
// Create a new file share and initialize it with the |
|
2009 |
// client file share's file control block, position & mode |
|
2010 |
||
2011 |
CFileShare* pNewFileShare = new CFileShare(&fileCB); |
|
2012 |
if (pNewFileShare == NULL) |
|
2013 |
return KErrNoMemory; |
|
2014 |
||
2015 |
// We need to call CFileCB::PromoteShare immediately after the CFileShare |
|
2016 |
// instance is created since the destructor calls CFileCB::DemoteShare() |
|
2017 |
// which checks the share count is non-zero |
|
2018 |
pNewFileShare->iMode = pS->iMode; |
|
2019 |
fileCB.PromoteShare(pNewFileShare); |
|
2020 |
||
2021 |
||
2022 |
TInt r = fileCB.Open(); // increment the ref count |
|
2023 |
||
2024 |
if (r == KErrNone) |
|
2025 |
TRAP(r, pNewFileShare->InitL()); |
|
2026 |
__e32_atomic_store_ord64(&pNewFileShare->iPos, pS->iPos); |
|
2027 |
||
2028 |
// Add new file share to the global file share container |
|
2029 |
if (r == KErrNone) |
|
2030 |
TRAP(r, FileShares->AddL(pNewFileShare,ETrue)); |
|
2031 |
||
2032 |
// Add new file share to list owned by this session |
|
2033 |
TInt newHandle; |
|
2034 |
if (r == KErrNone) |
|
2035 |
TRAP(r,newHandle = aRequest->Session()->Handles().AddL(pNewFileShare,ETrue)); |
|
2036 |
||
2037 |
if (r!=KErrNone) |
|
2038 |
{ |
|
2039 |
pNewFileShare->Close(); |
|
2040 |
return r; |
|
2041 |
} |
|
2042 |
||
2043 |
newHandle^= KSubSessionMangleBit; |
|
2044 |
||
2045 |
TPtrC8 pH((TUint8*)&newHandle, sizeof(TInt)); |
|
2046 |
aRequest->WriteL(KMsgPtr3, pH); |
|
2047 |
aRequest->Session()->IncResourceCount(); |
|
2048 |
return(KErrNone); |
|
2049 |
} |
|
2050 |
||
2051 |
TInt TFsFileDuplicate::Initialise(CFsRequest* aRequest) |
|
2052 |
{ |
|
2053 |
TInt handle = aRequest->Message().Int0(); |
|
2054 |
CFileShare* share = GetShareFromHandle(aRequest->Session(), handle); |
|
2055 |
||
2056 |
// If the handle is invalid, either panic (CFsMessageRequest::Dispatch() will |
|
2057 |
// panic if we return KErrBadHandle) or complete the request with KErrArgument. |
|
2058 |
// The latter case is the behaviour for the (deprecated) RFile::Adopt() to |
|
2059 |
// prevent a server from panicing if the passed file handle is invalid. |
|
2060 |
if(!share) |
|
2061 |
return aRequest->Message().Int1()?KErrBadHandle:KErrArgument; |
|
2062 |
||
2063 |
aRequest->SetDrive(&share->File().Drive()); |
|
2064 |
aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) ); |
|
2065 |
return(KErrNone); |
|
2066 |
} |
|
2067 |
||
2068 |
||
2069 |
||
2070 |
TInt TFsFileAdopt::DoRequestL(CFsRequest* aRequest) |
|
2071 |
// |
|
2072 |
// Adopt the passed file handle. This assumes that the handle has already been |
|
2073 |
// duplicated by calling TFsFileDuplicate and is therefore mangled. |
|
2074 |
// |
|
2075 |
{ |
|
2076 |
if (((CFileShare*)aRequest->ScratchValue()) == NULL) |
|
2077 |
return KErrBadHandle; |
|
2078 |
||
2079 |
TInt adoptType = aRequest->Message().Int1(); |
|
2080 |
// EFileBigFile mode check |
|
2081 |
switch(adoptType) |
|
2082 |
{ |
|
2083 |
case KFileAdopt32: |
|
2084 |
// Request is from RFile::Adopt or RFile::AdoptFromXXX: Force NO EFileBigFile |
|
2085 |
((CFileShare*)aRequest->ScratchValue())->iMode &= ~EFileBigFile; |
|
2086 |
break; |
|
2087 |
case KFileAdopt64: |
|
2088 |
// Request is from RFile64::AdoptFromXXX: Force EFileBigFile |
|
2089 |
((CFileShare*)aRequest->ScratchValue())->iMode |= EFileBigFile; |
|
2090 |
break; |
|
2091 |
case KFileDuplicate: |
|
2092 |
// Request is from RFile::Duplucate |
|
2093 |
// adopt original file mode - do nothing |
|
2094 |
break; |
|
2095 |
//default: |
|
2096 |
// Do nothing |
|
2097 |
} |
|
2098 |
||
2099 |
// De-mangle the existing sub-session handle and return it to the client |
|
2100 |
TInt newHandle = aRequest->Message().Int0() ^ KSubSessionMangleBit; |
|
2101 |
||
2102 |
TPtrC8 pH((TUint8*)&newHandle,sizeof(TInt)); |
|
2103 |
aRequest->WriteL(KMsgPtr3,pH); |
|
2104 |
return(KErrNone); |
|
2105 |
} |
|
2106 |
||
2107 |
TInt TFsFileAdopt::Initialise(CFsRequest* aRequest) |
|
2108 |
{ |
|
2109 |
TInt handle = aRequest->Message().Int0() ^KSubSessionMangleBit; |
|
2110 |
||
2111 |
CFileShare* share = GetShareFromHandle(aRequest->Session(), handle); |
|
2112 |
// Normally returning KErrBadHandle will result in a panic, but when a server calls |
|
2113 |
// RFile::AdoptXXX() and it's client has given it a bad handle then it's not a good |
|
2114 |
// idea to panic the server. So we return KErrNone here and allow |
|
2115 |
// TFsFileAdopt::DoRequestL() to return KErrBadHandle |
|
2116 |
if (share) |
|
2117 |
aRequest->SetDrive(&share->File().Drive()); |
|
2118 |
||
2119 |
aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) ); |
|
2120 |
return(KErrNone); |
|
2121 |
} |
|
2122 |
||
2123 |
||
2124 |
TInt TFsFileName::DoRequestL(CFsRequest* aRequest) |
|
2125 |
// |
|
2126 |
// Get the name of a file. |
|
2127 |
// i.e. including the name & extension but excluding the drive and path |
|
2128 |
// |
|
2129 |
{ |
|
2130 |
CFileShare* share = (CFileShare*)aRequest->ScratchValue(); |
|
2131 |
||
2132 |
// Search backwards until a backslash is found |
|
2133 |
// This should always succeed as this is a full pathname |
|
2134 |
TPtrC name(share->File().FileName()); |
|
2135 |
TInt offset = name.LocateReverse('\\'); |
|
2136 |
aRequest->WriteL(KMsgPtr0, name.Mid(offset+1)); |
|
2137 |
||
2138 |
return(KErrNone); |
|
2139 |
} |
|
2140 |
||
2141 |
TInt TFsFileName::Initialise(CFsRequest* aRequest) |
|
2142 |
// |
|
2143 |
// Get the full name of a file, including path and drive |
|
2144 |
// |
|
2145 |
// |
|
2146 |
{ |
|
2147 |
return InitialiseScratchToShare(aRequest); |
|
2148 |
} |
|
2149 |
||
2150 |
||
2151 |
TInt TFsFileFullName::DoRequestL(CFsRequest* aRequest) |
|
2152 |
// |
|
2153 |
// Get the full name of a file, including path and drive |
|
2154 |
// |
|
2155 |
{ |
|
2156 |
CFileShare* share = (CFileShare*)aRequest->ScratchValue(); |
|
2157 |
||
2158 |
// Write the drive letter and ':' |
|
2159 |
TBuf<2> driveBuf(KDrivePath); |
|
2160 |
driveBuf[0]=TText('A' + share->File().Drive().DriveNumber()); |
|
2161 |
aRequest->WriteL(KMsgPtr0, driveBuf); |
|
2162 |
||
2163 |
// Write the file and path including leading '\' |
|
2164 |
TPtrC name(share->File().FileName()); |
|
2165 |
aRequest->WriteL(KMsgPtr0, name, 2); |
|
2166 |
||
2167 |
return(KErrNone); |
|
2168 |
} |
|
2169 |
||
2170 |
||
2171 |
TInt TFsFileFullName::Initialise(CFsRequest* aRequest) |
|
2172 |
// |
|
2173 |
// |
|
2174 |
// |
|
2175 |
{ |
|
2176 |
return InitialiseScratchToShare(aRequest); |
|
2177 |
} |
|
2178 |
||
2179 |
TInt TFsGetMediaSerialNumber::DoRequestL(CFsRequest* aRequest) |
|
2180 |
// |
|
2181 |
// Acquire capability from media and return serial number if supported. |
|
2182 |
// |
|
2183 |
{ |
|
2184 |
// Get request parameters |
|
2185 |
const TInt drvNum = aRequest->Message().Int1(); |
|
2186 |
||
2187 |
// Get media capability |
|
2188 |
TLocalDriveCapsV5Buf capsBuf; |
|
2189 |
||
2190 |
TInt r = KErrNone; |
|
2191 |
||
2192 |
// is the drive local? |
|
2193 |
if (!IsProxyDrive(drvNum)) |
|
2194 |
{ |
|
2195 |
// if not valid local drive, use default values in localDriveCaps |
|
2196 |
// if valid local drive and not locked, use TBusLocalDrive::Caps() values |
|
2197 |
// if valid drive and locked, hard-code attributes |
|
2198 |
r = GetLocalDrive(drvNum).Caps(capsBuf); |
|
2199 |
} |
|
2200 |
else // this need to be made a bit nicer |
|
2201 |
{ |
|
2202 |
CExtProxyDrive* pD = GetProxyDrive(drvNum); |
|
2203 |
if(pD) |
|
2204 |
r = pD->Caps(capsBuf); |
|
2205 |
else |
|
2206 |
r = KErrNotReady; |
|
2207 |
} |
|
2208 |
||
2209 |
if (r != KErrNone) |
|
2210 |
return r; |
|
2211 |
||
2212 |
TLocalDriveCapsV5& capsV5 = capsBuf(); |
|
2213 |
||
2214 |
// Return serial number if supported |
|
2215 |
if (capsV5.iSerialNumLength == 0) |
|
2216 |
return KErrNotSupported; |
|
2217 |
||
2218 |
TPtrC8 snPtr(capsV5.iSerialNum, capsV5.iSerialNumLength); |
|
2219 |
aRequest->WriteL(KMsgPtr0, snPtr); |
|
2220 |
||
2221 |
return KErrNone; |
|
2222 |
} |
|
2223 |
||
2224 |
TInt TFsGetMediaSerialNumber::Initialise(CFsRequest* aRequest) |
|
2225 |
// |
|
2226 |
// Validate drive number and its attributes passed in a request object. |
|
2227 |
// |
|
2228 |
{ |
|
2229 |
const TInt drvNum = aRequest->Message().Int1(); |
|
2230 |
||
2231 |
TInt nRes = ValidateDrive(drvNum, aRequest); |
|
2232 |
if(nRes != KErrNone) |
|
2233 |
return KErrBadName; //-- incorrect drive number |
|
2234 |
||
2235 |
if(aRequest->Drive()->IsSubsted()) |
|
2236 |
return KErrNotSupported; //-- the drive is substed, this operation doesn't make a sense |
|
2237 |
||
2238 |
if(!IsValidLocalDriveMapping(drvNum)) |
|
2239 |
return KErrNotReady; |
|
2240 |
||
2241 |
return KErrNone; |
|
2242 |
} |
|
2243 |
||
2244 |
TInt TFsBlockMap::Initialise(CFsRequest* aRequest) |
|
2245 |
{ |
|
2246 |
TInt r = DoInitNoParse(aRequest); |
|
2247 |
if(r!=KErrNone) |
|
2248 |
return r; |
|
2249 |
||
2250 |
TInt blockMapUsage = aRequest->Message().Int2(); |
|
2251 |
if ( blockMapUsage == EBlockMapUsagePaging ) |
|
2252 |
{ |
|
2253 |
CFileShare* share = (CFileShare*) aRequest->ScratchValue(); |
|
2254 |
CFileCB& file = share->File(); |
|
2255 |
||
2256 |
// To determine whether the drive where this file resides is pageable, we need to locate |
|
2257 |
// the specific TBusLocalDrive object first; querying the drive attributes directly from the |
|
2258 |
// (composite) file system is no good as this API treats all slave file systems as "ROM & not pageable. |
|
2259 |
TBusLocalDrive* localDrive; |
|
2260 |
TInt r = file.LocalDrive(localDrive); |
|
2261 |
if (r != KErrNone) |
|
2262 |
return r; |
|
2263 |
TLocalDriveCapsV4Buf caps; |
|
2264 |
r = localDrive->Caps(caps); |
|
2265 |
if (r != KErrNone) |
|
2266 |
return r; |
|
2267 |
__PRINT4(_L("TFsBlockMap::Initialise, drive %d file %S iMediaAtt %08X iDriveAtt %08X\n"), file.DriveNumber(), &file.FileName(), caps().iMediaAtt, caps().iDriveAtt); |
|
2268 |
if ( !(caps().iDriveAtt & KDriveAttPageable)) |
|
2269 |
return KErrNotSupported; |
|
2270 |
} |
|
2271 |
||
2272 |
return KErrNone; |
|
2273 |
} |
|
2274 |
||
2275 |
TInt TFsBlockMap::DoRequestL(CFsRequest* aRequest) |
|
2276 |
{ |
|
2277 |
__PRINT(_L("TFsBlockMap::DoRequestL(CFsRequest* aRequest)")); |
|
2278 |
__PRINT1(_L("aRequest->Session() = 0x%x"), aRequest->Session()); |
|
2279 |
||
2280 |
CFileShare* share = (CFileShare*) aRequest->ScratchValue(); |
|
2281 |
||
2282 |
TInt r = share->CheckMount(); |
|
2283 |
||
2284 |
__PRINT1(_L("share->CheckMount() returned - %d"), r); |
|
2285 |
if ( r != KErrNone ) |
|
2286 |
return(r); |
|
2287 |
||
2288 |
SBlockMapInfo reqInfo; |
|
2289 |
SBlockMapArgs args; |
|
2290 |
TPckg<SBlockMapArgs> pkArgs(args); |
|
2291 |
aRequest->ReadL(KMsgPtr1, pkArgs); |
|
2292 |
||
2293 |
CFileCB& file = share->File(); |
|
2294 |
TInt64& reqStartPos = args.iStartPos; |
|
2295 |
TInt64 reqEndPos = args.iEndPos; |
|
2296 |
||
2297 |
if ( ( reqStartPos > file.Size64() ) || ( reqStartPos < 0 ) ) |
|
2298 |
return KErrArgument; |
|
2299 |
||
2300 |
const TInt64 KReadToEOF = -1; |
|
2301 |
if ( reqEndPos != KReadToEOF ) |
|
2302 |
{ |
|
2303 |
if ( !( reqEndPos >= reqStartPos ) ) |
|
2304 |
return KErrArgument; |
|
2305 |
} |
|
2306 |
else |
|
2307 |
reqEndPos = file.Size64(); |
|
2308 |
||
2309 |
// If the requested start position is equal to the size of the file |
|
2310 |
// then we read no data and return an empty BlockMap. |
|
2311 |
if ( reqStartPos == file.Size64() || reqEndPos == 0 || reqEndPos == reqStartPos ) |
|
2312 |
{ |
|
2313 |
TPckg<SBlockMapInfo> pkInfo(reqInfo); |
|
2314 |
TRAP(r,aRequest->WriteL(KMsgPtr0,pkInfo) ); |
|
2315 |
if ( r == KErrNone ) |
|
2316 |
return(KErrArgument); |
|
2317 |
else |
|
2318 |
return(r); |
|
2319 |
} |
|
2320 |
r = share->File().BlockMap(reqInfo, reqStartPos, reqEndPos); |
|
2321 |
TPckg<SBlockMapInfo> pkInfo(reqInfo); |
|
2322 |
aRequest->WriteL(KMsgPtr0, pkInfo); |
|
2323 |
aRequest->WriteL(KMsgPtr1, pkArgs); |
|
2324 |
||
2325 |
return(r); |
|
2326 |
} |
|
2327 |
||
2328 |
#pragma warning( disable : 4705 ) // statement has no effect |
|
2329 |
/** |
|
2330 |
Default constructor |
|
2331 |
*/ |
|
2332 |
EXPORT_C CFileCB::CFileCB() |
|
2333 |
{ |
|
2334 |
} |
|
2335 |
#pragma warning( default : 4705 ) |
|
2336 |
||
2337 |
||
2338 |
||
2339 |
||
2340 |
/** |
|
2341 |
Destructor. |
|
2342 |
||
2343 |
Frees resources before destruction of the object. |
|
2344 |
*/ |
|
2345 |
EXPORT_C CFileCB::~CFileCB() |
|
2346 |
{ |
|
2347 |
// NB Must be careful to close the file cache BEFORE deleting iFileNameF |
|
2348 |
// as CFileCache may steal it (!) |
|
2349 |
if (FileCache()) |
|
2350 |
FileCache()->Close(); |
|
2351 |
if (iBody && iBody->iDeleteOnClose) |
|
2352 |
{ |
|
2353 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteL, EF32TraceUidFileSys, DriveNumber(), FileName()); |
|
2354 |
TInt r; |
|
2355 |
TRAP(r, iMount->DeleteL(FileName())); |
|
2356 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteLRet, EF32TraceUidFileSys, r); |
|
2357 |
} |
|
2358 |
||
2359 |
if(iMount) |
|
2360 |
iMount->Close(); |
|
2361 |
if (iMountLink.iNext!=NULL) |
|
2362 |
{ |
|
2363 |
iMountLink.Deque(); |
|
2364 |
} |
|
2365 |
delete iFileName; |
|
2366 |
delete iFileNameF; |
|
2367 |
if (iFileLocks) |
|
2368 |
{ |
|
2369 |
iFileLocks->Close(); |
|
2370 |
delete iFileLocks; |
|
2371 |
} |
|
2372 |
||
2373 |
delete iBody; |
|
2374 |
} |
|
2375 |
||
2376 |
/** |
|
2377 |
Initialise CFileCB object. |
|
2378 |
@internalTechnology |
|
2379 |
||
2380 |
@param aDrive |
|
2381 |
@param aCreatedDrive |
|
2382 |
@param aName file name descriptor |
|
2383 |
*/ |
|
2384 |
EXPORT_C void CFileCB::InitL(TDrive* aDrive, TDrive* aCreatedDrive, HBufC* aName) |
|
2385 |
{ |
|
2386 |
// Take ownership of heap-allocated objects aName and aLock before attempting any memory allocation |
|
2387 |
// to avoid leaking memory |
|
2388 |
iFileName = aName; |
|
2389 |
||
2390 |
DoInitL(aDrive->DriveNumber()); |
|
2391 |
iDrive=aDrive; |
|
2392 |
iCreatedDrive=aCreatedDrive; |
|
2393 |
TFileName tempName; |
|
2394 |
tempName.CopyF(*aName); |
|
2395 |
iFileNameF=tempName.AllocL(); |
|
2396 |
iNameHash=CalcNameHash(*iFileNameF); |
|
2397 |
||
2398 |
||
2399 |
||
2400 |
// see whether the file system supports the CFileCB extended API |
|
2401 |
MExtendedFileInterface* extendedFileInterface = NULL; |
|
2402 |
GetInterfaceTraced(CFileCB::EExtendedFileInterface, (void*&) extendedFileInterface, NULL); |
|
2403 |
iBody = new(ELeave)CFileBody(this, extendedFileInterface); |
|
2404 |
||
2405 |
iMount=&iDrive->CurrentMount(); |
|
2406 |
iBody->InitL(); |
|
2407 |
User::LeaveIfError(iMount->Open()); |
|
2408 |
||
2409 |
//-- create file locks array |
|
2410 |
ASSERT(!iFileLocks); |
|
2411 |
iFileLocks = new(ELeave) TFileLocksArray(KFileShareLockGranularity, _FOFF(TFileShareLock, iPosLow)); |
|
2412 |
||
2413 |
} |
|
2414 |
||
2415 |
||
2416 |
TInt CFileCB::FindLock(TInt aPosLow,TInt aPosHigh) |
|
2417 |
{ |
|
2418 |
return FindLock64(aPosLow, aPosHigh); |
|
2419 |
} |
|
2420 |
||
2421 |
TInt CFileCB::AddLock(CFileShare* aFileShare,TInt aPos,TInt aLength) |
|
2422 |
{ |
|
2423 |
return AddLock64(aFileShare, aPos, aLength); |
|
2424 |
} |
|
2425 |
||
2426 |
TInt CFileCB::RemoveLock(CFileShare* aFileShare,TInt aPos,TInt aLength) |
|
2427 |
{ |
|
2428 |
return RemoveLock64(aFileShare, aPos, aLength); |
|
2429 |
} |
|
2430 |
||
2431 |
TInt CFileCB::CheckLock(CFileShare* aFileShare,TInt aPos,TInt aLength) |
|
2432 |
{ |
|
2433 |
return CheckLock64(aFileShare, aPos, aLength); |
|
2434 |
} |
|
2435 |
||
2436 |
/** |
|
2437 |
Remove any locks held by aFileShare. |
|
2438 |
*/ |
|
2439 |
void CFileCB::RemoveLocks(CFileShare* aFileShare) |
|
2440 |
{ |
|
2441 |
||
2442 |
TInt i=0; |
|
2443 |
while (i<FileLocks().Count()) |
|
2444 |
{ |
|
2445 |
if (FileLocks()[i].MatchOwner(aFileShare)) |
|
2446 |
FileLocks().Remove(i); |
|
2447 |
else |
|
2448 |
i++; |
|
2449 |
} |
|
2450 |
} |
|
2451 |
||
2452 |
||
2453 |
void CFileCB::PromoteShare(CFileShare* aShare) |
|
2454 |
// |
|
2455 |
// Manages share promotion after the share has been added to the FilsShares container. |
|
2456 |
// |
|
2457 |
// - Assumes the share has already been validated using ValidateShare() |
|
2458 |
// |
|
2459 |
// - The count of promoted shares (ie - non-EFileShareReadersOrWriters) is incremented |
|
2460 |
// to allow the share mode to be demoted when the last promoted share is closed. |
|
2461 |
// |
|
2462 |
{ |
|
2463 |
TShare reqShare = (TShare)(aShare->iMode & KFileShareMask); |
|
2464 |
if(reqShare != EFileShareReadersOrWriters) |
|
2465 |
{ |
|
2466 |
iBody->iPromotedShares++; |
|
2467 |
iShare = reqShare; |
|
2468 |
} |
|
2469 |
} |
|
2470 |
||
2471 |
||
2472 |
void CFileCB::DemoteShare(CFileShare* aShare) |
|
2473 |
// |
|
2474 |
// Manages share demotion after the share has been removed from the FileShares container. |
|
2475 |
// |
|
2476 |
// - If the share being removed is not EFileShareReadersOrWriters, then the current |
|
2477 |
// share mode may require demotion back to EFileShareReadersOrWriters. |
|
2478 |
// |
|
2479 |
// - This is determined by the iPromotedShares count, incremented in PromoteShare() |
|
2480 |
// |
|
2481 |
{ |
|
2482 |
if((aShare->iMode & KFileShareMask) != EFileShareReadersOrWriters) |
|
2483 |
{ |
|
2484 |
if(--iBody->iPromotedShares == 0) |
|
2485 |
{ |
|
2486 |
// Don't worry if the file has never been opened as EFileShareReadersOrWriters |
|
2487 |
// - in this case the CFileCB object is about to be closed anyway. |
|
2488 |
iShare = EFileShareReadersOrWriters; |
|
2489 |
} |
|
2490 |
} |
|
2491 |
__ASSERT_DEBUG(iBody->iPromotedShares>=0,Fault(EFileShareBadPromoteCount)); |
|
2492 |
} |
|
2493 |
||
2494 |
||
2495 |
RArray<TAsyncReadRequest>& CFileCB::AsyncReadRequests() |
|
2496 |
// |
|
2497 |
// Gets a reference to the pending asynchronous read requests for this file. |
|
2498 |
// |
|
2499 |
// - The request is completed when all data is available or the request is cancelled. |
|
2500 |
// |
|
2501 |
{ |
|
2502 |
return(*iBody->iAsyncReadRequests); |
|
2503 |
} |
|
2504 |
||
2505 |
||
2506 |
TInt CFileCB::AddAsyncReadRequest(CFileShare* aShareP, TInt64 aPos, TInt aLen, CFsRequest* aRequestP) |
|
2507 |
// |
|
2508 |
// Adds a pending asynchronous read request to the list. |
|
2509 |
// |
|
2510 |
// - The request is completed when all data is available or the request is cancelled. |
|
2511 |
// |
|
2512 |
{ |
|
2513 |
||
2514 |
__ASSERT_ALWAYS(aRequestP->Operation()->Function() == EFsFileRead, Fault(EBaseRequestMessage)); |
|
2515 |
||
2516 |
TAsyncReadRequest req(aPos + aLen, aShareP, aRequestP); |
|
2517 |
TInt err = AsyncReadRequests().InsertInSignedKeyOrderAllowRepeats(req); |
|
2518 |
if(err != KErrNone) |
|
2519 |
return err; |
|
2520 |
||
2521 |
aRequestP->SetCompleted(EFalse); |
|
2522 |
return KErrNone; |
|
2523 |
} |
|
2524 |
||
2525 |
||
2526 |
TInt CFileCB::CancelAsyncReadRequest(CFileShare* aShareP, TRequestStatus* aStatusP) |
|
2527 |
// |
|
2528 |
// Cancels (and completes) an outstanding read request for the specified share. |
|
2529 |
// |
|
2530 |
// - aStatusP == NULL cancels all outstanding read requests. |
|
2531 |
// |
|
2532 |
{ |
|
2533 |
||
2534 |
TInt i=0; |
|
2535 |
Drive().Lock(); |
|
2536 |
while (i < AsyncReadRequests().Count()) |
|
2537 |
{ |
|
2538 |
TAsyncReadRequest& req = AsyncReadRequests()[i]; |
|
2539 |
if(req.CompleteIfMatching(aShareP, aStatusP, KErrCancel)) |
|
2540 |
{ |
|
2541 |
iBody->iAsyncReadRequests->Remove(i); |
|
2542 |
if(aStatusP != NULL) |
|
2543 |
{ |
|
2544 |
Drive().UnLock(); |
|
2545 |
return KErrNone; |
|
2546 |
} |
|
2547 |
} |
|
2548 |
else |
|
2549 |
{ |
|
2550 |
i++; |
|
2551 |
} |
|
2552 |
} |
|
2553 |
||
2554 |
Drive().UnLock(); |
|
2555 |
return KErrNone; |
|
2556 |
} |
|
2557 |
||
2558 |
||
2559 |
void CFileCB::NotifyAsyncReaders() |
|
2560 |
// |
|
2561 |
// Determine if any outstanding read requests require completion. |
|
2562 |
// |
|
2563 |
// - Called whenever the file size changes (due to a write operation or SetSize) |
|
2564 |
// |
|
2565 |
// - Any outstanding read requests are re-issued (rather then completed in the |
|
2566 |
// context of the current operation so not to affect performance of the writer). |
|
2567 |
// |
|
2568 |
// - Should the file size shrink before the request is serviced, the request will |
|
2569 |
// be added back onto the queue. |
|
2570 |
// |
|
2571 |
// - A future optimisation may issue the request as data becomes available (which |
|
2572 |
// would minimise the final latency between writer and reader) but the current |
|
2573 |
// implementation reads all requested data in one operation. |
|
2574 |
// |
|
2575 |
{ |
|
2576 |
Drive().Lock(); |
|
2577 |
||
2578 |
SetNotifyAsyncReadersPending(EFalse); |
|
2579 |
||
2580 |
while(AsyncReadRequests().Count()) |
|
2581 |
{ |
|
2582 |
TAsyncReadRequest& req = AsyncReadRequests()[0]; |
|
2583 |
if(req.iEndPos > CachedSize64()) |
|
2584 |
break; |
|
2585 |
||
2586 |
// Make a copy and then remove it from the queue before releasing the lock - |
|
2587 |
// because the file server thread could append to the RArray and this might |
|
2588 |
// cause a re-allocation which would move the whole array (!) |
|
2589 |
TAsyncReadRequest reqCopy = req; |
|
2590 |
AsyncReadRequests().Remove(0); |
|
2591 |
Drive().UnLock(); |
|
2592 |
||
2593 |
// allocate a new request, push a TMsgOperation onto the request's stack (duplicating |
|
2594 |
// the functionality of TFsFileRead::Initialise()) & dispatch the request |
|
2595 |
CFsClientMessageRequest* pRequest = NULL; |
|
2596 |
const TOperation& oP = OperationArray[EFsFileRead]; |
|
2597 |
TInt r = RequestAllocator::GetMessageRequest(oP, reqCopy.iMessage, pRequest); |
|
2598 |
if (r != KErrNone) |
|
2599 |
{ |
|
2600 |
reqCopy.iMessage.Complete(r); // complete the client's message with an error |
|
2601 |
continue; |
|
2602 |
} |
|
2603 |
pRequest->Set(reqCopy.iMessage, oP, reqCopy.iSessionP); |
|
2604 |
||
2605 |
r = DoInitNoParse(pRequest); |
|
2606 |
if (r != KErrNone) |
|
2607 |
{ |
|
2608 |
pRequest->Complete(r); // complete the client's message with an error |
|
2609 |
continue; |
|
2610 |
} |
|
2611 |
||
2612 |
r = pRequest->PushOperation(TFsFileRead::Complete); |
|
2613 |
if (r != KErrNone) |
|
2614 |
{ |
|
2615 |
pRequest->Complete(r); // complete the client's message with an error |
|
2616 |
continue; |
|
2617 |
} |
|
2618 |
||
2619 |
pRequest->CurrentOperation().Set( |
|
2620 |
reqCopy.iEndPos - pRequest->Message().Int1(), |
|
2621 |
pRequest->Message().Int1(), |
|
2622 |
(TDes8*) pRequest->Message().Ptr0()); |
|
2623 |
||
2624 |
// don't call Initialise() |
|
2625 |
pRequest->SetState(CFsRequest::EReqStatePostInitialise); |
|
2626 |
||
2627 |
pRequest->Dispatch(); |
|
2628 |
Drive().Lock(); |
|
2629 |
} |
|
2630 |
Drive().UnLock(); |
|
2631 |
} |
|
2632 |
||
2633 |
||
2634 |
/** |
|
2635 |
Gets the address of the file that the file control block represents. |
|
2636 |
||
2637 |
The default implementation returns KErrNotSupported and should only |
|
2638 |
be overridden for ROM file systems. |
|
2639 |
||
2640 |
@param aPos On return, should contain the address of the file that |
|
2641 |
the file control block represents. |
|
2642 |
||
2643 |
@return KErrNone, if successful,otherwise one of the other system wide error |
|
2644 |
codes, |
|
2645 |
*/ |
|
2646 |
EXPORT_C TInt CFileCB::Address(TInt& /*aPos*/) const |
|
2647 |
{ |
|
2648 |
||
2649 |
return(KErrNotSupported); |
|
2650 |
} |
|
2651 |
||
2652 |
||
2653 |
/** |
|
2654 |
Sets the archive attribute, KEntryAttArchive, in iAtt. |
|
2655 |
*/ |
|
2656 |
EXPORT_C void CFileCB::SetArchiveAttribute() |
|
2657 |
{ |
|
2658 |
||
2659 |
iAtt|=KEntryAttArchive; |
|
2660 |
iAtt|=KEntryAttModified; |
|
2661 |
iModified.UniversalTime(); |
|
2662 |
} |
|
2663 |
||
2664 |
||
2665 |
EXPORT_C TInt CFileCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* /*aInput*/) |
|
2666 |
{ |
|
2667 |
switch(aInterfaceId) |
|
2668 |
{ |
|
2669 |
case EGetLocalDrive: |
|
2670 |
return Mount().LocalDrive((TBusLocalDrive*&) aInterface); |
|
2671 |
default: |
|
2672 |
return(KErrNotSupported); |
|
2673 |
} |
|
2674 |
} |
|
2675 |
||
2676 |
||
2677 |
CFileCache* CFileCB::FileCache() const |
|
2678 |
{return iBody?iBody->iFileCache:NULL;} |
|
2679 |
||
2680 |
TBool CFileCB::LocalBufferSupport() const |
|
2681 |
{return iBody?iBody->iLocalBufferSupport:EFalse;} |
|
2682 |
||
2683 |
void CFileCB::SetLocalBufferSupport(TBool aEnabled) |
|
2684 |
{iBody->iLocalBufferSupport = aEnabled;} |
|
2685 |
||
2686 |
TInt CFileCB::CheckMount() |
|
2687 |
// |
|
2688 |
// Check that the media is still mounted. |
|
2689 |
// |
|
2690 |
{ |
|
2691 |
||
2692 |
TDrive& d = Drive(); |
|
2693 |
TInt r=d.CheckMount(); |
|
2694 |
if (r!=KErrNone) |
|
2695 |
return(r); |
|
2696 |
if (&Mount() != &d.CurrentMount()) |
|
2697 |
return(KErrDisMounted); |
|
2698 |
if (FileCorrupt()) |
|
2699 |
return(KErrCorrupt); |
|
2700 |
if (BadPower()) |
|
2701 |
{ |
|
2702 |
if (PowerOk()) |
|
2703 |
SetBadPower(EFalse); |
|
2704 |
else |
|
2705 |
return(KErrBadPower); |
|
2706 |
} |
|
2707 |
return(KErrNone); |
|
2708 |
} |
|
2709 |
||
2710 |
TInt64 CFileCB::CachedSize64() const |
|
2711 |
{ |
|
2712 |
CFileCache* fileCache = iBody?iBody->iFileCache:NULL; |
|
2713 |
return fileCache? fileCache->Size64(): Size64(); |
|
2714 |
} |
|
2715 |
||
2716 |
void CFileCB::SetCachedSize64(TInt64 aSize) |
|
2717 |
{ |
|
2718 |
if (FileCache()) |
|
2719 |
FileCache()->SetSize64(aSize); |
|
2720 |
else |
|
2721 |
SetSize64(aSize, EFalse); // assume not locked |
|
2722 |
} |
|
2723 |
||
2724 |
/** |
|
2725 |
Constructor. |
|
2726 |
Locks the mount resource to which the shared file resides. |
|
2727 |
||
2728 |
@param aFileCB File to be shared. |
|
2729 |
*/ |
|
2730 |
CFileShare::CFileShare(CFileCB* aFileCB) |
|
2731 |
: iFile(aFileCB) |
|
2732 |
{ |
|
2733 |
AddResource(iFile->Mount()); |
|
2734 |
} |
|
2735 |
||
2736 |
/** |
|
2737 |
Destructor. |
|
2738 |
||
2739 |
Frees mount resource to which the shared file resides, |
|
2740 |
removes share status from the shared file and finally closes |
|
2741 |
the file. |
|
2742 |
*/ |
|
2743 |
CFileShare::~CFileShare() |
|
2744 |
{ |
|
2745 |
// We shouldn't be deleting the file share with a valid request queue or there will be request (& memory) leakage |
|
2746 |
__ASSERT_DEBUG(iCurrentRequest == NULL, Fault(ERequestQueueNotEmpty)); |
|
2747 |
||
2748 |
RemoveResource(iFile->Mount()); |
|
2749 |
iFile->RemoveLocks(this); |
|
2750 |
iFile->DemoteShare(this); |
|
2751 |
iFile->CancelAsyncReadRequest(this, NULL); |
|
2752 |
iFile->Close(); |
|
2753 |
} |
|
2754 |
||
2755 |
/** |
|
2756 |
Check that the media is still mounted. |
|
2757 |
||
2758 |
@return KErrNone if successful. |
|
2759 |
KErrDisMounted if media has dismounted. |
|
2760 |
KErrCorrupted if shared file is corrupted. |
|
2761 |
KErrBadPower if insufficent power supply. |
|
2762 |
or other system wide error code. |
|
2763 |
*/ |
|
2764 |
TInt CFileShare::CheckMount() |
|
2765 |
{ |
|
2766 |
return File().CheckMount(); |
|
2767 |
} |
|
2768 |
||
2769 |
/** |
|
2770 |
Initialise the object |
|
2771 |
*/ |
|
2772 |
void CFileShare::InitL() |
|
2773 |
{ |
|
2774 |
DoInitL(iFile->Drive().DriveNumber()); |
|
2775 |
||
2776 |
// override the close operation so that we can flush the write cache if necessary |
|
2777 |
iRequest->Set(FileShareCloseOp,NULL); |
|
2778 |
iRequest->SetDriveNumber(DriveNumber()); |
|
2779 |
iRequest->SetScratchValue((TUint)this); |
|
2780 |
} |
|
2781 |
||
2782 |
// Mark the start of a request - |
|
2783 |
// the is to prevent fair-scheduled async read/writes from being processed out of sequence. This is especially |
|
2784 |
// important when considering a client which appends to a file by issuing more than one asynchronous request as each |
|
2785 |
// write request must be entirely satisfied before a subsequent request can append to the file |
|
2786 |
TBool CFileShare::RequestStart(CFsMessageRequest* aRequest) |
|
2787 |
{ |
|
2788 |
TBool ret; |
|
2789 |
||
2790 |
TDrive& drive = File().Drive(); |
|
2791 |
drive.Lock(); |
|
2792 |
||
2793 |
if (iCurrentRequest == NULL || iCurrentRequest == aRequest) |
|
2794 |
{ |
|
2795 |
iCurrentRequest = aRequest; |
|
2796 |
ret = ETrue; |
|
2797 |
} |
|
2798 |
else |
|
2799 |
{ |
|
2800 |
// add to end of linked list of requests if there is already an active request for this share |
|
2801 |
CFsClientMessageRequest* request; |
|
2802 |
for (request = (CFsClientMessageRequest*) iCurrentRequest; request->iNext != NULL; request = request->iNext) |
|
2803 |
{ |
|
2804 |
} |
|
2805 |
request->iNext = (CFsClientMessageRequest*) aRequest; |
|
2806 |
ret = EFalse; |
|
2807 |
} |
|
2808 |
||
2809 |
drive.UnLock(); |
|
2810 |
return ret; |
|
2811 |
} |
|
2812 |
||
2813 |
||
2814 |
// Mark the end of a request |
|
2815 |
void CFileShare::RequestEnd(CFsMessageRequest* aRequest) |
|
2816 |
{ |
|
2817 |
TDrive& drive = File().Drive(); |
|
2818 |
drive.Lock(); |
|
2819 |
||
2820 |
if (aRequest == iCurrentRequest) |
|
2821 |
{ |
|
2822 |
// Any requests in the queue ? |
|
2823 |
if (((CFsClientMessageRequest*) iCurrentRequest)->iNext) |
|
2824 |
{ |
|
2825 |
iCurrentRequest = ((CFsClientMessageRequest*) aRequest)->iNext; |
|
2826 |
((CFsClientMessageRequest*) aRequest)->iNext = NULL; |
|
2827 |
||
2828 |
// if the current request has been cancelled, cancel all requests in the queue |
|
2829 |
TInt lastError = aRequest->LastError(); |
|
2830 |
if (lastError == KErrCancel || lastError == KErrNotReady) |
|
2831 |
{ |
|
2832 |
// take ownership of this queue and make it invisible to anyone else by setting iCurrentRequest to NULL |
|
2833 |
CFsClientMessageRequest* currentRequest = (CFsClientMessageRequest*) iCurrentRequest; |
|
2834 |
iCurrentRequest = NULL; |
|
2835 |
drive.UnLock(); |
|
2836 |
while(currentRequest) |
|
2837 |
{ |
|
2838 |
CFsClientMessageRequest* nextRequest = ((CFsClientMessageRequest*) currentRequest)->iNext; |
|
2839 |
((CFsClientMessageRequest*) currentRequest)->iNext = NULL; |
|
2840 |
currentRequest->Complete(lastError); |
|
2841 |
currentRequest = nextRequest; |
|
2842 |
} |
|
2843 |
} |
|
2844 |
else |
|
2845 |
{ |
|
2846 |
drive.UnLock(); |
|
2847 |
iCurrentRequest->Dispatch(EFalse); |
|
2848 |
} |
|
2849 |
} |
|
2850 |
else // queue empty |
|
2851 |
{ |
|
2852 |
iCurrentRequest = NULL; |
|
2853 |
drive.UnLock(); |
|
2854 |
} |
|
2855 |
} |
|
2856 |
else // if (aRequest == iCurrentRequest) |
|
2857 |
{ |
|
2858 |
drive.UnLock(); |
|
2859 |
} |
|
2860 |
} |
|
2861 |
||
2862 |
TBool CFileShare::RequestInProgress() const |
|
2863 |
{ |
|
2864 |
return (iCurrentRequest != NULL)?(TBool)ETrue:(TBool)EFalse; |
|
2865 |
} |
|
2866 |
||
2867 |
||
2868 |
||
2869 |
/** |
|
2870 |
Initialise the object |
|
2871 |
*/ |
|
2872 |
TInt TFsCloseFileShare::DoRequestL(CFsRequest* aRequest) |
|
2873 |
// |
|
2874 |
{ |
|
2875 |
__PRINT(_L("TFsCloseFileCache::DoRequestL()")); |
|
2876 |
||
2877 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
2878 |
||
2879 |
// flush the write cache before closing the file share |
|
2880 |
TInt r; |
|
2881 |
CFileCache* fileCache = share->File().FileCache(); |
|
2882 |
if (fileCache && (r = fileCache->FlushDirty(aRequest)) == CFsRequest::EReqActionBusy) |
|
2883 |
return r; |
|
2884 |
||
2885 |
return KErrNone; |
|
2886 |
} |
|
2887 |
||
2888 |
TInt TFsCloseFileShare::Complete(CFsRequest* aRequest) |
|
2889 |
{ |
|
2890 |
__PRINT(_L("TFsCloseFileShare::Complete()")); |
|
2891 |
return TFsCloseObject::Complete(aRequest); |
|
2892 |
} |
|
2893 |
||
2894 |
||
2895 |
TAsyncReadRequest::TAsyncReadRequest(TInt64 aEndPos, CFileShare* aOwningShareP, CFsRequest* aRequestP) |
|
2896 |
// |
|
2897 |
// Constructor for TAsyncReadRequest |
|
2898 |
// - Maintains information about oustanding async read requests |
|
2899 |
// |
|
2900 |
: iEndPos(aEndPos), |
|
2901 |
iOwningShareP(aOwningShareP) |
|
2902 |
{ |
|
2903 |
iMessage = aRequestP->Message(); |
|
2904 |
iSessionP = aRequestP->Session(); |
|
2905 |
iStatusP = iMessage.ClientStatus(); |
|
2906 |
} |
|
2907 |
||
2908 |
||
2909 |
TBool TAsyncReadRequest::CompleteIfMatching(CFileShare* aShareP, TRequestStatus* aStatusP, TInt aError) |
|
2910 |
// |
|
2911 |
// Completes an asynchronous read request. |
|
2912 |
// |
|
2913 |
{ |
|
2914 |
if (iOwningShareP == aShareP && (aStatusP == NULL || aStatusP == iStatusP)) |
|
2915 |
{ |
|
2916 |
iMessage.Complete(aError); |
|
2917 |
return ETrue; |
|
2918 |
} |
|
2919 |
||
2920 |
return EFalse; |
|
2921 |
} |
|
2922 |
||
2923 |
||
2924 |
TInt TFsFileReadCancel::Initialise(CFsRequest* aRequest) |
|
2925 |
// |
|
2926 |
// Initialise function for RFile::ReadCancel [EFsReadCancel] |
|
2927 |
// |
|
2928 |
{ |
|
2929 |
return InitialiseScratchToShare(aRequest); |
|
2930 |
} |
|
2931 |
||
2932 |
||
2933 |
TInt TFsFileReadCancel::DoRequestL(CFsRequest* aRequest) |
|
2934 |
// |
|
2935 |
// Request function for RFile::ReadCancel [EFsReadCancel] |
|
2936 |
// |
|
2937 |
{ |
|
2938 |
CFileShare* share = (CFileShare*)aRequest->ScratchValue(); |
|
2939 |
TRequestStatus* status = (TRequestStatus*)aRequest->Message().Ptr0(); |
|
2940 |
share->File().CancelAsyncReadRequest(share, status); |
|
2941 |
return(KErrNone); |
|
2942 |
} |
|
2943 |
||
2944 |
void CFileCB::ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset) |
|
2945 |
{ |
|
2946 |
TRACETHREADID(aMessage); |
|
2947 |
TRACE7(UTF::EBorder, UTraceModuleFileSys::ECFileCBReadL, EF32TraceUidFileSys, |
|
2948 |
this, I64LOW(aPos), I64HIGH(aPos), aLength, aDes, threadId, aOffset); |
|
2949 |
||
2950 |
iBody->iExtendedFileInterface->ReadL(aPos,aLength,aDes,aMessage,aOffset); |
|
2951 |
||
2952 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBReadLRet, EF32TraceUidFileSys, KErrNone); |
|
2953 |
} |
|
2954 |
||
2955 |
void CFileCB::WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset) |
|
2956 |
{ |
|
2957 |
TRACETHREADID(aMessage); |
|
2958 |
TRACE7(UTF::EBorder, UTraceModuleFileSys::ECFileCBWriteL, EF32TraceUidFileSys, |
|
2959 |
this, I64LOW(aPos), I64HIGH(aPos), aLength, aDes, threadId, aOffset); |
|
2960 |
||
2961 |
iBody->iExtendedFileInterface->WriteL(aPos,aLength,aDes,aMessage,aOffset); |
|
2962 |
||
2963 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBWriteLRet, EF32TraceUidFileSys, KErrNone); |
|
2964 |
} |
|
2965 |
||
2966 |
void CFileCB::SetSizeL(TInt64 aSize) |
|
2967 |
{ |
|
2968 |
TRACE3(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetSizeL, EF32TraceUidFileSys, this, I64LOW(aSize), I64HIGH(aSize)); |
|
2969 |
||
2970 |
iBody->iExtendedFileInterface->SetSizeL(aSize); |
|
2971 |
||
2972 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetSizeLRet, EF32TraceUidFileSys, KErrNone); |
|
2973 |
} |
|
2974 |
||
2975 |
TBool CFileCB::ExtendedFileInterfaceSupported() |
|
2976 |
{ |
|
2977 |
return iBody->ExtendedFileInterfaceSupported(); |
|
2978 |
} |
|
2979 |
||
2980 |
TInt CFileCB::FairSchedulingLen() const |
|
2981 |
{ |
|
2982 |
return iBody->iFairSchedulingLen; |
|
2983 |
} |
|
2984 |
||
2985 |
void CFileCB::SetNotifyAsyncReadersPending(TBool aNotifyAsyncReadersPending) |
|
2986 |
// |
|
2987 |
// Notify the asynchronous reader that a file has grown so that it may service outstanding async reads |
|
2988 |
// |
|
2989 |
{ |
|
2990 |
iBody->iNotifyAsyncReadersPending = aNotifyAsyncReadersPending; |
|
2991 |
} |
|
2992 |
||
2993 |
TBool CFileCB::NotifyAsyncReadersPending() const |
|
2994 |
{ |
|
2995 |
return iBody->iNotifyAsyncReadersPending; |
|
2996 |
} |
|
2997 |
||
2998 |
||
2999 |
void CFileCB::ResetReadAhead() |
|
3000 |
{ |
|
3001 |
CFileCache* fileCache = FileCache(); |
|
3002 |
if (fileCache) |
|
3003 |
fileCache->ResetReadAhead(); |
|
3004 |
} |
|
3005 |
||
3006 |
void CFileCB::SetDeleteOnClose() |
|
3007 |
{ |
|
3008 |
iBody->iDeleteOnClose = ETrue; |
|
3009 |
} |
|
3010 |
||
3011 |
TBool CFileCB::DeleteOnClose() const |
|
3012 |
{ |
|
3013 |
return iBody->iDeleteOnClose; |
|
3014 |
} |
|
3015 |
||
3016 |
TInt CFileCB::GetInterfaceTraced(TInt aInterfaceId, TAny*& aInterface, TAny* aInput) |
|
3017 |
{ |
|
3018 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileCBGetInterface, EF32TraceUidFileSys, aInterfaceId, aInput); |
|
3019 |
||
3020 |
TInt r = GetInterface(aInterfaceId, aInterface, aInput); |
|
3021 |
||
3022 |
TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileCBGetInterfaceRet, EF32TraceUidFileSys, r, aInterface); |
|
3023 |
||
3024 |
return r; |
|
3025 |
} |
|
3026 |
||
3027 |
CFileBody::CFileBody(CFileCB* aFileCB, CFileCB::MExtendedFileInterface* aExtendedFileInterface) |
|
3028 |
: iFileCB(aFileCB), |
|
3029 |
iExtendedFileInterface(aExtendedFileInterface ? aExtendedFileInterface : this), |
|
3030 |
iSizeHigh(0) |
|
3031 |
{ |
|
3032 |
iFairSchedulingLen = TFileCacheSettings::FairSchedulingLen(iFileCB->DriveNumber()); |
|
3033 |
iMaxSupportedFileSize = KMaxSupportedFileSize; |
|
3034 |
} |
|
3035 |
||
3036 |
||
3037 |
CFileBody::~CFileBody() |
|
3038 |
{ |
|
3039 |
if (iAsyncReadRequests) |
|
3040 |
{ |
|
3041 |
iAsyncReadRequests->Close(); |
|
3042 |
delete iAsyncReadRequests; |
|
3043 |
} |
|
3044 |
} |
|
3045 |
||
3046 |
||
3047 |
void CFileBody::InitL() |
|
3048 |
{ |
|
3049 |
iAsyncReadRequests = new(ELeave) RArray<TAsyncReadRequest>(KAsyncRequestArrayGranularity, _FOFF(TAsyncReadRequest, iEndPos)); |
|
3050 |
} |
|
3051 |
||
3052 |
||
3053 |
||
3054 |
TInt TFsFileClamp::Initialise(CFsRequest* aRequest) |
|
3055 |
// |
|
3056 |
// Initialise function for RFile::Clamp [EFsFileClamp] |
|
3057 |
// |
|
3058 |
{ |
|
3059 |
TSecureId aUID = aRequest->Message().SecureId(); |
|
3060 |
if (aUID!=KEstartUidValue && aUID!=KFileServerUidValue) |
|
3061 |
{ |
|
3062 |
SSecurityInfo info; |
|
3063 |
info.iVendorId=0; |
|
3064 |
info.iCaps.iCaps[0]=0; |
|
3065 |
info.iCaps.iCaps[1]=0; |
|
3066 |
info.iSecureId=KEstartUidValue; |
|
3067 |
PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Clamp"); |
|
3068 |
info.iSecureId=KFileServerUidValue; |
|
3069 |
PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Clamp"); |
|
3070 |
return KErrPermissionDenied; |
|
3071 |
} |
|
3072 |
||
3073 |
TInt r=DoInitialise(aRequest); |
|
3074 |
if(r!=KErrNone) |
|
3075 |
return r; |
|
3076 |
||
3077 |
// The clamp API is only supported on non-removable media |
|
3078 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
3079 |
TDriveInfo di; |
|
3080 |
share->File().Drive().DriveInfo(di); |
|
3081 |
if (!(di.iDriveAtt & KDriveAttInternal)) |
|
3082 |
r = KErrNotSupported; |
|
3083 |
||
3084 |
return(r); |
|
3085 |
} |
|
3086 |
||
3087 |
||
3088 |
TInt TFsFileClamp::DoRequestL(CFsRequest* aRequest) |
|
3089 |
// |
|
3090 |
// Request function for RFile::Clamp [EFsFileClamp] |
|
3091 |
// |
|
3092 |
{ |
|
3093 |
TInt r; |
|
3094 |
||
3095 |
// Flush data for this file, if it is open for writing, before clamping |
|
3096 |
CFileShare* share=(CFileShare*)aRequest->ScratchValue(); |
|
3097 |
||
3098 |
if (((share->iMode&EFileWrite)) || ((share->File().Att()&KEntryAttModified))) |
|
3099 |
{ |
|
3100 |
r=share->CheckMount(); |
|
3101 |
if (r!=KErrNone) |
|
3102 |
return(r); |
|
3103 |
||
3104 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataL, EF32TraceUidFileSys, &share->File()); |
|
3105 |
TRAP(r,share->File().FlushDataL()); |
|
3106 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataLRet, EF32TraceUidFileSys, r); |
|
3107 |
||
3108 |
if(r!=KErrNone) |
|
3109 |
return(r); |
|
3110 |
} |
|
3111 |
||
3112 |
RFileClamp clamp; |
|
3113 |
r=aRequest->Drive()->ClampFile(aRequest->Src().FullName().Mid(2), |
|
3114 |
(TAny*)(&clamp)); |
|
3115 |
// Write clamp information to user |
|
3116 |
TPckgC<RFileClamp> pkClamp(clamp); |
|
3117 |
aRequest->WriteL(KMsgPtr0, pkClamp); |
|
3118 |
return r; |
|
3119 |
} |
|
3120 |
||
3121 |
||
3122 |
TInt TFsUnclamp::Initialise(CFsRequest* aRequest) |
|
3123 |
// |
|
3124 |
// Initialise function for RFs::Unclamp [EFsUnclamp] |
|
3125 |
// |
|
3126 |
{ |
|
3127 |
TSecureId aUID = aRequest->Message().SecureId(); |
|
3128 |
if (aUID!=KEstartUidValue && aUID!=KFileServerUidValue) |
|
3129 |
{ |
|
3130 |
SSecurityInfo info; |
|
3131 |
info.iVendorId=0; |
|
3132 |
info.iCaps.iCaps[0]=0; |
|
3133 |
info.iCaps.iCaps[1]=0; |
|
3134 |
info.iSecureId=KEstartUidValue; |
|
3135 |
PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Unclamp"); |
|
3136 |
info.iSecureId=KFileServerUidValue; |
|
3137 |
PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Unclamp"); |
|
3138 |
return KErrPermissionDenied; |
|
3139 |
} |
|
3140 |
RFileClamp clamp; |
|
3141 |
TPckg<RFileClamp> pkClamp(clamp); |
|
3142 |
aRequest->ReadL(KMsgPtr0, pkClamp); |
|
3143 |
TInt driveNo=(I64HIGH(clamp.iCookie[1])); |
|
3144 |
TDrive& drive=TheDrives[driveNo]; |
|
3145 |
aRequest->SetDrive(&drive); |
|
3146 |
return KErrNone; |
|
3147 |
} |
|
3148 |
||
3149 |
||
3150 |
TInt TFsUnclamp::DoRequestL(CFsRequest* aRequest) |
|
3151 |
// |
|
3152 |
// Request function for RFs::Unclamp [EFsUnclamp] |
|
3153 |
// |
|
3154 |
{ |
|
3155 |
RFileClamp clamp; |
|
3156 |
TPckg<RFileClamp> pkClamp(clamp); |
|
3157 |
aRequest->ReadL(KMsgPtr0, pkClamp); |
|
3158 |
TDrive* drive=aRequest->Drive(); |
|
3159 |
CMountCB* mount=(CMountCB*)&(drive->CurrentMount()); |
|
3160 |
return(drive->UnclampFile(mount,&clamp)); |
|
3161 |
} |
|
3162 |
||
3163 |
CMountBody::CMountBody(CMountCB* aMountCB, CMountCB::MFileAccessor* aFileAccessor, CMountCB::MFileExtendedInterface* aFileInterface) |
|
3164 |
// |
|
3165 |
// Constructor for private body class |
|
3166 |
// |
|
3167 |
: iMountCB(aMountCB), |
|
3168 |
iFileAccessor(aFileAccessor?aFileAccessor:this), |
|
3169 |
iFileExtendedInterface(aFileInterface?aFileInterface:this) |
|
3170 |
{ |
|
3171 |
} |
|
3172 |
||
3173 |
CMountBody::~CMountBody() |
|
3174 |
// |
|
3175 |
// Destructor for private body class |
|
3176 |
// |
|
3177 |
{ |
|
3178 |
__ASSERT_DEBUG(iClampIdentifiers.Count() == 0, User::Invariant()); |
|
3179 |
iClampIdentifiers.Close(); |
|
3180 |
} |
|
3181 |
||
3182 |
TInt CMountBody::ClampFile(const TInt aDriveNo,const TDesC& aName,TAny* aHandle) |
|
3183 |
{ |
|
3184 |
// Need CMountCB::MFileAccessor interface support |
|
3185 |
if(iFileAccessor==this) |
|
3186 |
return KErrNotSupported; |
|
3187 |
||
3188 |
// Get unique identifier for the file |
|
3189 |
TInt64 uniqueId = 0; |
|
3190 |
TInt r = iFileAccessor->GetFileUniqueId(aName,uniqueId); |
|
3191 |
if(r!=KErrNone) |
|
3192 |
return r; |
|
3193 |
||
3194 |
// Populate the RFileClamp clamp instance and store it in iClampIdentifiers |
|
3195 |
RFileClamp* newClamp = (RFileClamp*)aHandle; |
|
3196 |
newClamp->iCookie[0]=uniqueId; |
|
3197 |
newClamp->iCookie[1]=MAKE_TINT64(aDriveNo,++iClampCount); |
|
3198 |
r = iClampIdentifiers.InsertInOrder((const RFileClamp&)*newClamp,&CompareClampsByIdAndCount); |
|
3199 |
if(r != KErrNone) |
|
3200 |
return r; |
|
3201 |
||
3202 |
// Indicate that (at least) one file is clamped on this drive |
|
3203 |
iMountCB->Drive().SetClampFlag(ETrue); |
|
3204 |
AddResource(*iMountCB); |
|
3205 |
return KErrNone; |
|
3206 |
} |
|
3207 |
||
3208 |
||
3209 |
TInt CMountBody::UnclampFile(RFileClamp* aHandle) |
|
3210 |
{ |
|
3211 |
// Need CMountCB::MFileAccessor interface support |
|
3212 |
if(iFileAccessor==this) |
|
3213 |
return KErrNotSupported; |
|
3214 |
||
3215 |
TInt idx; |
|
3216 |
if((idx = iClampIdentifiers.Find((const RFileClamp&)*aHandle,&FindClampByIdAndCount)) < KErrNone) |
|
3217 |
{ |
|
3218 |
// This file is not 'clamped' |
|
3219 |
return idx; |
|
3220 |
} |
|
3221 |
||
3222 |
// If we're removing the last clamp and a dismount has been deferred (due to files being clamped), |
|
3223 |
// then DeferredDismount() will trigger a dismount: before this happens we need to flush all |
|
3224 |
// dirty data on this drive; |
|
3225 |
TDrive& drive = iMountCB->Drive(); |
|
3226 |
TInt noOfClamps = NoOfClamps(); |
|
3227 |
if (noOfClamps == 1 && drive.DismountDeferred()) |
|
3228 |
{ |
|
3229 |
TInt r = drive.FlushCachedFileInfo(ETrue); |
|
3230 |
if (r == CFsRequest::EReqActionBusy) |
|
3231 |
return r; |
|
3232 |
} |
|
3233 |
||
3234 |
RemoveResource(*iMountCB); |
|
3235 |
iClampIdentifiers.Remove(idx); |
|
3236 |
||
3237 |
TInt r = KErrNone; |
|
3238 |
// If this was the last clamp, check for outstanding dismount requests |
|
3239 |
if (noOfClamps == 1) |
|
3240 |
{ |
|
3241 |
ASSERT(NoOfClamps() == 0); |
|
3242 |
drive.SetClampFlag(EFalse); |
|
3243 |
if (drive.DismountDeferred()) |
|
3244 |
r = drive.DeferredDismount(); |
|
3245 |
} |
|
3246 |
||
3247 |
return r; |
|
3248 |
} |
|
3249 |
||
3250 |
||
3251 |
TInt CMountBody::IsFileClamped(const TInt64 aUniqueId) |
|
3252 |
{ |
|
3253 |
// Need CMountCB::MFileAccessor interface support |
|
3254 |
if(iFileAccessor==this) |
|
3255 |
return KErrNotSupported; |
|
3256 |
||
3257 |
// Encapsulate the unique identifier in an appropriate class |
|
3258 |
RFileClamp newClamp; |
|
3259 |
newClamp.iCookie[0]=aUniqueId; |
|
3260 |
// Search for (any) entry in iClampIdentifiers holding this value |
|
3261 |
TInt index=iClampIdentifiers.Find((const RFileClamp&)newClamp,&FindClampById); |
|
3262 |
return (index==KErrNotFound?0:1); |
|
3263 |
} |
|
3264 |
||
3265 |
TInt CMountBody::NoOfClamps() |
|
3266 |
{ |
|
3267 |
// Need CMountCB::MFileAccessor interface support |
|
3268 |
if(iFileAccessor==this) |
|
3269 |
return KErrNotSupported; |
|
3270 |
||
3271 |
// This will return zero if ClampFile has not previously been invoked |
|
3272 |
return iClampIdentifiers.Count(); |
|
3273 |
} |
|
3274 |
||
3275 |
TInt CMountBody::CompareClampsById(const RFileClamp& aClampA, const RFileClamp& aClampB) |
|
3276 |
{ |
|
3277 |
if(aClampA.iCookie[0] < aClampB.iCookie[0]) return 1; |
|
3278 |
if(aClampA.iCookie[0] > aClampB.iCookie[0]) return -1; |
|
3279 |
return 0; |
|
3280 |
} |
|
3281 |
||
3282 |
TInt CMountBody::CompareClampsByIdAndCount(const RFileClamp& aClampA, const RFileClamp& aClampB) |
|
3283 |
{ |
|
3284 |
if(aClampA.iCookie[0] > aClampB.iCookie[0]) return 1; |
|
3285 |
if(aClampA.iCookie[0] < aClampB.iCookie[0]) return -1; |
|
3286 |
// Now compare the count values |
|
3287 |
if(I64LOW(aClampA.iCookie[1]) > I64LOW(aClampB.iCookie[1])) return 1; |
|
3288 |
if(I64LOW(aClampA.iCookie[1]) < I64LOW(aClampB.iCookie[1])) return -1; |
|
3289 |
return 0; |
|
3290 |
} |
|
3291 |
||
3292 |
TInt CMountBody::FindClampById(const RFileClamp& aClampA, const RFileClamp& aClampB) |
|
3293 |
{ |
|
3294 |
return (TInt)(!CompareClampsById(aClampA, aClampB)); |
|
3295 |
} |
|
3296 |
||
3297 |
||
3298 |
TInt CMountBody::FindClampByIdAndCount(const RFileClamp& aClampA, const RFileClamp& aClampB) |
|
3299 |
{ |
|
3300 |
return (TInt)(!CompareClampsByIdAndCount(aClampA, aClampB)); |
|
3301 |
} |
|
3302 |
||
3303 |
void CMountBody::SetProxyDriveDismounted() |
|
3304 |
{ |
|
3305 |
iProxyDriveDismounted = ETrue; |
|
3306 |
} |
|
3307 |
||
3308 |
TBool CMountBody::ProxyDriveDismounted() |
|
3309 |
{ |
|
3310 |
return iProxyDriveDismounted; |
|
3311 |
} |
|
3312 |
||
3313 |
||
3314 |
TInt CMountBody::GetFileUniqueId(const TDesC& /*aName*/, TInt64& /*aUniqueId*/) |
|
3315 |
{ |
|
3316 |
return KErrNotSupported; |
|
3317 |
} |
|
3318 |
TInt CMountBody::Spare3(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/) |
|
3319 |
{ |
|
3320 |
return KErrNotSupported; |
|
3321 |
} |
|
3322 |
TInt CMountBody::Spare2(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/) |
|
3323 |
{ |
|
3324 |
return KErrNotSupported; |
|
3325 |
} |
|
3326 |
TInt CMountBody::Spare1(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/) |
|
3327 |
{ |
|
3328 |
return KErrNotSupported; |
|
3329 |
} |
|
3330 |
void CMountBody::ReadSection64L(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) |
|
3331 |
{ |
|
3332 |
if((TUint64)aPos > KMaxLegacyFileSize) |
|
3333 |
User::Leave(KErrNotSupported); |
|
3334 |
||
3335 |
iMountCB->ReadSectionL(aName, I64LOW(aPos), aTrg, aLength, aMessage); |
|
3336 |
} |
|
3337 |
||
3338 |
TBool CFileBody::ExtendedFileInterfaceSupported() |
|
3339 |
{ |
|
3340 |
return (iExtendedFileInterface==this) ? (TBool)EFalse : (TBool)ETrue; |
|
3341 |
} |
|
3342 |
||
3343 |
// default implementations of MExtendedFileInterface |
|
3344 |
void CFileBody::ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset) |
|
3345 |
{ |
|
3346 |
if ((TUint64)aPos > KMaxLegacyFileSize || aOffset > 0) |
|
3347 |
User::Leave(KErrNotSupported); |
|
3348 |
||
3349 |
iFileCB->ReadL((TInt) aPos, aLength, aDes, aMessage); |
|
3350 |
} |
|
3351 |
||
3352 |
void CFileBody::WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset) |
|
3353 |
{ |
|
3354 |
if ((TUint64)aPos > KMaxLegacyFileSize || aOffset > 0) |
|
3355 |
User::Leave(KErrNotSupported); |
|
3356 |
||
3357 |
iFileCB->WriteL((TInt) aPos, aLength, aDes, aMessage); |
|
3358 |
} |
|
3359 |
||
3360 |
void CFileBody::SetSizeL(TInt64 aSize) |
|
3361 |
{ |
|
3362 |
if ((TUint64)aSize > KMaxLegacyFileSize) |
|
3363 |
User::Leave(KErrNotSupported); |
|
3364 |
||
3365 |
iFileCB->SetSizeL((TInt) aSize); |
|
3366 |
} |
|
3367 |
||
3368 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3369 |
/** |
|
3370 |
This method allows file system to set maximum file size it supports. |
|
3371 |
This can be called on instantiation of the CFileCB derived class object by the file system implementation. |
|
3372 |
If this method is not called, the iMaxSupportedFileSize will have default value KMaxTUint64 |
|
3373 |
||
3374 |
@param aMaxFileSize maximum file size supported by file system |
|
3375 |
*/ |
|
3376 |
EXPORT_C void CFileCB::SetMaxSupportedSize(TUint64 aMaxFileSize) |
|
3377 |
{ |
|
3378 |
iBody->iMaxSupportedFileSize = aMaxFileSize; |
|
3379 |
} |
|
3380 |
||
3381 |
/** |
|
3382 |
@return maximum supported file size (depends on the file system created it) |
|
3383 |
*/ |
|
3384 |
TUint64 CFileCB::MaxSupportedSize(void) const |
|
3385 |
{ |
|
3386 |
return iBody->iMaxSupportedFileSize; |
|
3387 |
} |
|
3388 |
||
3389 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3390 |
||
3391 |
/** |
|
3392 |
Gets the size of the file. |
|
3393 |
||
3394 |
This is 64-bit variant for CFileCB::Size(). |
|
3395 |
This shall be used by File Systems supporting file size > 4GB - 1 to query the file size |
|
3396 |
inplace of CFileCB::Size() or CFileCB::iSize. |
|
3397 |
||
3398 |
@see CFileCB::iSize |
|
3399 |
@see CFileCB::Size() |
|
3400 |
||
3401 |
@prototype |
|
3402 |
||
3403 |
@return The size of the file. |
|
3404 |
*/ |
|
3405 |
EXPORT_C TInt64 CFileCB::Size64() const |
|
3406 |
{ |
|
3407 |
__ASSERT_DEBUG(iBody != NULL, Fault(EFileBodyIsNull)); |
|
3408 |
const TInt64 size = MAKE_TINT64(iBody->iSizeHigh,iSize); |
|
3409 |
return size; |
|
3410 |
} |
|
3411 |
||
3412 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3413 |
/** |
|
3414 |
Sets the size of the file. |
|
3415 |
||
3416 |
This is 64-bit variant for CFileCB::SetSize(). |
|
3417 |
This should be used by File Systems supporting file size > 4GB - 1 to set the file size |
|
3418 |
inplace of CFileCB::SetSize() or CFileCB::iSize. |
|
3419 |
||
3420 |
@see CFileCB::iSize |
|
3421 |
@see CFileCB::SetSize() |
|
3422 |
||
3423 |
@prototype |
|
3424 |
||
3425 |
@param aSize The size of the file. |
|
3426 |
@param aDriveLocked The status of the Drive Lock. If it is EFalse, |
|
3427 |
the file size shall be modified after acquiring the iLock mutex and if it is ETrue, |
|
3428 |
the file size shall be modified without aquiring the iLock mutex. |
|
3429 |
*/ |
|
3430 |
EXPORT_C void CFileCB::SetSize64(TInt64 aSize, TBool aDriveLocked) |
|
3431 |
{ |
|
3432 |
if(aDriveLocked) |
|
3433 |
{ |
|
3434 |
iSize = (TInt)I64LOW(aSize); |
|
3435 |
iBody->iSizeHigh = (TInt)I64HIGH(aSize); |
|
3436 |
} |
|
3437 |
else |
|
3438 |
{ |
|
3439 |
Drive().Lock(); |
|
3440 |
iSize = (TInt)I64LOW(aSize); |
|
3441 |
iBody->iSizeHigh = (TInt)I64HIGH(aSize); |
|
3442 |
Drive().UnLock(); |
|
3443 |
} |
|
3444 |
} |
|
3445 |
||
3446 |
||
3447 |
/** used to organize key comparison for the TFileShareLock*/ |
|
3448 |
TInt LockOrder(const TFileShareLock& aMatch, const TFileShareLock& anEntry) |
|
3449 |
{ |
|
3450 |
||
3451 |
if(aMatch.PosLow() > anEntry.PosLow()) |
|
3452 |
return 1; |
|
3453 |
else if(aMatch.PosLow() < anEntry.PosLow()) |
|
3454 |
return -1; |
|
3455 |
else |
|
3456 |
return 0; |
|
3457 |
||
3458 |
} |
|
3459 |
||
3460 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3461 |
/** |
|
3462 |
Find a lock inclusive of aPosLow to aPosHigh. |
|
3463 |
*/ |
|
3464 |
TInt CFileCB::FindLock64(TInt64 aPosLow, TInt64 aPosHigh) |
|
3465 |
{ |
|
3466 |
||
3467 |
const TInt count=FileLocks().Count(); |
|
3468 |
for (TInt i=0; i<count; i++) |
|
3469 |
{ |
|
3470 |
||
3471 |
const TFileShareLock& lock=FileLocks()[i]; |
|
3472 |
||
3473 |
if(lock.PosLow() > (TUint64)aPosHigh) |
|
3474 |
return KErrNotFound; |
|
3475 |
||
3476 |
if(lock.MatchByPos(aPosLow, aPosHigh)) |
|
3477 |
return i; |
|
3478 |
} |
|
3479 |
||
3480 |
return KErrNotFound; |
|
3481 |
} |
|
3482 |
||
3483 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3484 |
/** |
|
3485 |
Add a lock on a range. |
|
3486 |
*/ |
|
3487 |
TInt CFileCB::AddLock64(CFileShare* aFileShare,TInt64 aPos,TInt64 aLength) |
|
3488 |
{ |
|
3489 |
const TUint64 posHigh=aPos+aLength-1; |
|
3490 |
||
3491 |
||
3492 |
{//-- Lock overflow check |
|
3493 |
const TUint64 KMaxFileSize = aFileShare->IsFileModeBig() ? MaxSupportedSize() : KMaxLegacyFileSize; |
|
3494 |
if(posHigh > KMaxFileSize) |
|
3495 |
return KErrArgument; |
|
3496 |
} |
|
3497 |
||
3498 |
||
3499 |
TInt r=CheckLock64(NULL, aPos, aLength); |
|
3500 |
if (r!=KErrNone) |
|
3501 |
return r; |
|
3502 |
||
3503 |
TFileShareLock lock(aFileShare, aPos, posHigh); |
|
3504 |
||
3505 |
TLinearOrder<TFileShareLock> lockOrder(LockOrder); |
|
3506 |
r=FileLocks().InsertInOrder(lock, lockOrder); |
|
3507 |
__ASSERT_ALWAYS(r!=KErrAlreadyExists,Fault(EFileDuplicateLock)); |
|
3508 |
||
3509 |
return r; |
|
3510 |
} |
|
3511 |
||
3512 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3513 |
/** |
|
3514 |
Remove a lock on a range. |
|
3515 |
*/ |
|
3516 |
TInt CFileCB::RemoveLock64(CFileShare* aFileShare, TInt64 aPos, TInt64 aLength) |
|
3517 |
{ |
|
3518 |
const TUint64 posHigh = aPos+aLength-1; |
|
3519 |
||
3520 |
{//-- Lock overflow check |
|
3521 |
const TUint64 KMaxFileSize = aFileShare->IsFileModeBig() ? MaxSupportedSize() : KMaxLegacyFileSize; |
|
3522 |
if(posHigh > KMaxFileSize) |
|
3523 |
return KErrArgument; |
|
3524 |
} |
|
3525 |
||
3526 |
const TInt pos=FindLock64(aPos, posHigh); |
|
3527 |
if (pos==KErrNotFound) |
|
3528 |
return KErrNotFound; |
|
3529 |
||
3530 |
const TFileShareLock& lock=FileLocks()[pos]; |
|
3531 |
if (!lock.MatchOwner(aFileShare) || lock.PosLow() != (TUint64)aPos || lock.PosHigh() != posHigh) |
|
3532 |
return KErrNotFound; |
|
3533 |
||
3534 |
||
3535 |
FileLocks().Remove(pos); |
|
3536 |
||
3537 |
return KErrNone; |
|
3538 |
} |
|
3539 |
||
3540 |
//--------------------------------------------------------------------------------------------------------------------- |
|
3541 |
/** |
|
3542 |
Check if a range is available. |
|
3543 |
@param aFileShare pointer to FileShare object. NULL only when is called from CFileCB::AddLock64() |
|
3544 |
||
3545 |
*/ |
|
3546 |
TInt CFileCB::CheckLock64(CFileShare* aFileShare,TInt64 aPos,TInt64 aLength) |
|
3547 |
{ |
|
3548 |
const TUint64 posHigh=aPos+aLength-1; |
|
3549 |
||
3550 |
//-- Lock overflow check. It is OK to have a lock that is beyond the real file size. |
|
3551 |
//-- if aFileShare == NULL, this is the call from AddLock64 and the position is already checked. |
|
3552 |
if(aFileShare) |
|
3553 |
{ |
|
3554 |
const TUint64 KMaxFileSize = aFileShare->IsFileModeBig() ? MaxSupportedSize() : KMaxLegacyFileSize; |
|
3555 |
if(posHigh > KMaxFileSize) |
|
3556 |
return KErrNone; //-- OK, there can't be any locks beyond the max. supported file length |
|
3557 |
} |
|
3558 |
||
3559 |
||
3560 |
TInt lockIdx=FindLock64(aPos, posHigh); |
|
3561 |
if (lockIdx == KErrNotFound) |
|
3562 |
return KErrNone; |
|
3563 |
||
3564 |
const TInt count=FileLocks().Count(); |
|
3565 |
const TFileShareLock* lock=(&FileLocks()[lockIdx]); |
|
3566 |
||
3567 |
for(;;) |
|
3568 |
{ |
|
3569 |
if (!lock->MatchOwner(aFileShare)) |
|
3570 |
return KErrLocked; |
|
3571 |
||
3572 |
if (lock->PosHigh() >= posHigh) |
|
3573 |
break; |
|
3574 |
||
3575 |
lockIdx++; |
|
3576 |
if (lockIdx >= count) |
|
3577 |
break; |
|
3578 |
||
3579 |
lock=&FileLocks()[lockIdx]; |
|
3580 |
||
3581 |
if (posHigh < lock->PosLow()) |
|
3582 |
break; |
|
3583 |
} |
|
3584 |
||
3585 |
return KErrNone; |
|
3586 |
} |
|
3587 |
||
3588 |
||
3589 |
//##################################################################################################################### |
|
3590 |
//# TFileShareLock class implementation |
|
3591 |
//##################################################################################################################### |
|
3592 |
||
3593 |
TFileShareLock::TFileShareLock(const CFileShare* aOwner, TUint64 aPosLow, TUint64 aPosHigh) |
|
3594 |
: iOwner(aOwner), iPosLow(aPosLow), iPosHigh(aPosHigh) |
|
3595 |
{ |
|
3596 |
} |
|
3597 |
||
3598 |
||
3599 |
||
3600 |
TUint64 TFileShareLock::PosLow() const |
|
3601 |
{ |
|
3602 |
return iPosLow; |
|
3603 |
} |
|
3604 |
||
3605 |
||
3606 |
TUint64 TFileShareLock::PosHigh() const |
|
3607 |
{ |
|
3608 |
return iPosHigh; |
|
3609 |
} |
|
3610 |
||
3611 |
TBool TFileShareLock::MatchOwner(const CFileShare* aShare) const |
|
3612 |
{ |
|
3613 |
return (aShare == iOwner); |
|
3614 |
} |
|
3615 |
||
3616 |
/** |
|
3617 |
@return ETrue if aPosLow and PosHigh match the lock boundaries |
|
3618 |
*/ |
|
3619 |
TBool TFileShareLock::MatchByPos(TUint64 aPosLow, TUint64 aPosHigh) const |
|
3620 |
{ |
|
3621 |
if(PosLow() > aPosHigh) |
|
3622 |
return EFalse; |
|
3623 |
||
3624 |
if ((aPosLow >= PosLow() && aPosLow <= PosHigh()) || |
|
3625 |
(aPosHigh >= PosLow() && aPosHigh <= PosHigh()) || |
|
3626 |
(aPosLow <= PosLow() && aPosHigh >= PosHigh() )) |
|
3627 |
{ |
|
3628 |
return ETrue; |
|
3629 |
} |
|
3630 |
||
3631 |
return EFalse; |
|
3632 |
} |
|
3633 |
||
3634 |
||
3635 |
||
3636 |
||
3637 |
||
3638 |
||
3639 |
||
3640 |
||
3641 |
||
3642 |
||
3643 |
||
3644 |
||
3645 |
||
3646 |
||
3647 |