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