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