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