1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_file.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,3636 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "sf_std.h"
1.20 +#include "sf_file_cache.h"
1.21 +#include "cl_std.h"
1.22 +
1.23 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.24 +
1.25 +TInt OutputTraceInfo(CFsRequest* aRequest,TCorruptNameRec* aNameRec)
1.26 + {
1.27 + RThread tT;
1.28 + RProcess tP;
1.29 + TBool nameUnknown=EFalse;
1.30 + TInt r=aRequest->Message().Client(tT,EOwnerThread);
1.31 + if(r!=KErrNone)
1.32 + {
1.33 + nameUnknown=ETrue;
1.34 + }
1.35 + else
1.36 + {
1.37 + r=tT.Process(tP);
1.38 + if(r!=KErrNone)
1.39 + {
1.40 + tT.Close();
1.41 + nameUnknown=ETrue;
1.42 + }
1.43 + }
1.44 + TName n;
1.45 + if(!nameUnknown)
1.46 + {
1.47 + n=tP.Name();
1.48 + TInt b=n.Locate('[');
1.49 + if (b>=0)
1.50 + n.SetLength(b);
1.51 + tP.Close();
1.52 + tT.Close();
1.53 + }
1.54 + else
1.55 + {
1.56 + n=_L("*Unknown*");
1.57 + }
1.58 + TPtrC t(aRequest->Src().FullName());
1.59 + // output a message via the debug port
1.60 + RDebug::Print(_L("@@@@ Corrupt file check %S tried to open %S"),&n,&t);
1.61 + // make a new log record & chain it in
1.62 + TCorruptLogRec* pLogRec= new TCorruptLogRec;
1.63 + if(pLogRec==NULL)
1.64 + return KErrNoMemory;
1.65 + TPtrC nPtr(n);
1.66 + if(pLogRec->Construct(aNameRec,&nPtr,gCorruptLogRecordList)!=KErrNone)
1.67 + {
1.68 + delete pLogRec;
1.69 + return KErrNoMemory;
1.70 + }
1.71 + else
1.72 + {
1.73 + gCorruptLogRecordList=pLogRec;
1.74 + // really a count of number of log records
1.75 + gNumberOfCorruptHits++;
1.76 + }
1.77 + return KErrNone;
1.78 + }
1.79 +
1.80 +TCorruptLogRec::TCorruptLogRec()
1.81 + :iProcessName(NULL),iNameRec(NULL),iNext(NULL)
1.82 + {}
1.83 +
1.84 +TCorruptLogRec::~TCorruptLogRec()
1.85 + { // free off name memory
1.86 + delete iProcessName;
1.87 + }
1.88 +
1.89 +
1.90 +void TCorruptLogRec::DestroyList()
1.91 + {
1.92 + TCorruptLogRec* pList=gCorruptLogRecordList;
1.93 +
1.94 + while(pList!=NULL)
1.95 + {
1.96 + TCorruptLogRec* pThis=pList;
1.97 + pList=pList->iNext;
1.98 + delete pThis;
1.99 + }
1.100 + gCorruptLogRecordList=NULL;
1.101 + gNumberOfCorruptHits=0;
1.102 + }
1.103 +
1.104 +TInt TCorruptLogRec::Construct(TCorruptNameRec* aNameRec, TPtrC* aProcessName, TCorruptLogRec* aChain)
1.105 + {
1.106 + iProcessName=aProcessName->Alloc();
1.107 + if(iProcessName==NULL)
1.108 + return KErrNoMemory;
1.109 +
1.110 + iNameRec=aNameRec;
1.111 + iNext=aChain;
1.112 + return KErrNone;
1.113 + }
1.114 +
1.115 +TInt TCorruptLogRec::GetLogRecord(TFsDebugCorruptLogRecordBuf& aLogRecord,TInt aLogRecNum)
1.116 + {
1.117 + if(aLogRecNum<=0)
1.118 + {
1.119 + return KErrArgument;
1.120 + }
1.121 + else if(aLogRecNum>gNumberOfCorruptHits)
1.122 + {
1.123 + return KErrNotFound;
1.124 + }
1.125 +
1.126 + TCorruptLogRec* pList=gCorruptLogRecordList;
1.127 +
1.128 + for(TInt i=1;i<aLogRecNum && pList!=NULL;i++)
1.129 + {
1.130 + pList=pList->iNext;
1.131 + }
1.132 +
1.133 + TInt r=KErrNotFound;
1.134 +
1.135 + if(pList)
1.136 + {
1.137 + aLogRecord().iProcessName=pList->iProcessName->Des();
1.138 + aLogRecord().iFileName=pList->iNameRec->Name();
1.139 + aLogRecord().iError=pList->iNameRec->ReturnCode();
1.140 + r=KErrNone;
1.141 + }
1.142 +
1.143 + return r;
1.144 + }
1.145 +
1.146 +TCorruptNameRec::TCorruptNameRec()
1.147 +:iName(NULL),iNext(NULL){}
1.148 +
1.149 +TInt TCorruptNameRec::Construct(TPtr* aName,TInt aReturnCode, TBool aUseOnce, TCorruptNameRec* aChain)
1.150 + {
1.151 + iName=aName->Alloc();
1.152 + if(iName==NULL)
1.153 + return KErrNoMemory;
1.154 + iReturnCode=aReturnCode;
1.155 + iUseOnce=aUseOnce;
1.156 + iConsumed=EFalse;
1.157 + iNext=aChain;
1.158 + return KErrNone;
1.159 + }
1.160 +
1.161 +void TCorruptNameRec::ResetListConsumed()
1.162 + {
1.163 + TCorruptNameRec* pList=gCorruptFileNameList;
1.164 + while(pList!=NULL)
1.165 + {
1.166 + pList->iConsumed=EFalse;
1.167 + pList=pList->Next();
1.168 + }
1.169 + }
1.170 +
1.171 +LOCAL_C void checkCorruptNamesList(CFsRequest* aRequest, TInt &aError)
1.172 + {
1.173 + aError=KErrNone;
1.174 + TPtrC path(aRequest->Src().FullName());
1.175 + TCorruptNameRec* pList=gCorruptFileNameList;
1.176 + while(pList)
1.177 + {
1.178 + if(pList->Name().MatchF(path)==0)
1.179 + {
1.180 + if(!pList->Consumed())
1.181 + {
1.182 + aError=pList->ReturnCode();
1.183 + pList->SetConsumed();
1.184 + OutputTraceInfo(aRequest,pList);
1.185 + }
1.186 + break;
1.187 + }
1.188 + pList=pList->Next();
1.189 + }
1.190 + }
1.191 +#endif
1.192 +
1.193 +
1.194 +LOCAL_C TInt DoInitNoParse(CFsRequest* aRequest)
1.195 +//
1.196 +// Common init for read and write access to files
1.197 +//
1.198 + {
1.199 + CFileShare* share = GetShareFromHandle(aRequest->Session(), aRequest->Message().Int3());
1.200 + if(!share)
1.201 + return(KErrBadHandle);
1.202 + aRequest->SetDrive(&share->File().Drive());
1.203 + aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) );
1.204 + return KErrNone;
1.205 + }
1.206 +
1.207 +_LIT(KDrivePath,"?:");
1.208 +LOCAL_C TInt DoInitialise(CFsRequest* aRequest)
1.209 +//
1.210 +// Common initialisation code use file share to determine asychronicity
1.211 +//
1.212 + {
1.213 + CFileShare* share = GetShareFromHandle(aRequest->Session(), aRequest->Message().Int3());
1.214 + if(!share)
1.215 + return(KErrBadHandle);
1.216 + aRequest->SetDrive(&share->File().Drive());
1.217 + aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) );
1.218 + TBuf<2> drive(KDrivePath);
1.219 + drive[0]=TText(aRequest->DriveNumber()+'A');
1.220 + aRequest->Src().Set(share->File().FileName(),NULL,&drive);
1.221 + return KErrNone;
1.222 + }
1.223 +
1.224 +LOCAL_C TInt InitialiseScratchToShare(CFsRequest* aRequest)
1.225 +//
1.226 +// Common code used to initialise the scratch value to the CFileShare* from the request
1.227 +//
1.228 + {
1.229 + CFileShare* share=GetShareFromHandle(aRequest->Session(), aRequest->Message().Int3());
1.230 + if(!share)
1.231 + return(KErrBadHandle);
1.232 + aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) );
1.233 +
1.234 + return(KErrNone);
1.235 + }
1.236 +
1.237 +LOCAL_C TInt FsFileOpenL(CFsRequest* aRequest, TFileOpen anOpen)
1.238 +//
1.239 +// Open a file.
1.240 +//
1.241 + {
1.242 + TInt r;
1.243 +
1.244 + TUint32 mode=aRequest->Message().Int1();
1.245 + if (anOpen==EFileCreate || anOpen==EFileReplace)
1.246 + {
1.247 + r = CheckDiskSpace(0, aRequest);
1.248 + if(r != KErrNone)
1.249 + return r;
1.250 +
1.251 + mode|=EFileWrite;
1.252 + }
1.253 +
1.254 + TInt h;
1.255 + r=aRequest->Drive()->FileOpen(aRequest,h,aRequest->Src().FullName().Mid(2),mode,anOpen);
1.256 + if (r!=KErrNone)
1.257 + return(r);
1.258 +
1.259 + TPtrC8 pH((TUint8*)&h,sizeof(TInt));
1.260 + TRAP(r, aRequest->WriteL(KMsgPtr3,pH))
1.261 + CheckForLeaveAfterOpenL(r, aRequest, h);
1.262 + aRequest->Session()->IncResourceCount();
1.263 +
1.264 + return(KErrNone);
1.265 + }
1.266 +
1.267 +TInt TFsFileOpen::DoRequestL(CFsRequest* aRequest)
1.268 +//
1.269 +//
1.270 +//
1.271 + {
1.272 + __PRINT(_L("TFsFileOpen::DoRequestL(CFsRequest* aRequest)"));
1.273 + return FsFileOpenL(aRequest, EFileOpen);
1.274 + }
1.275 +
1.276 +TInt TFsFileCreate::DoRequestL(CFsRequest* aRequest)
1.277 +//
1.278 +//
1.279 +//
1.280 + {
1.281 +
1.282 + __PRINT(_L("TFsFileCreate::DoRequestL(CFsRequest* aRequest)"));
1.283 + return FsFileOpenL(aRequest, EFileCreate);
1.284 + }
1.285 +
1.286 +TInt TFsFileCreate::Initialise(CFsRequest* aRequest)
1.287 +//
1.288 +//
1.289 +//
1.290 + {
1.291 + TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
1.292 + if (r!=KErrNone)
1.293 + return(r);
1.294 + r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysFileCreate,&KCapFsPriFileCreate,&KCapFsROFileCreate, __PLATSEC_DIAGNOSTIC_STRING("Create File"));
1.295 + if (r!=KErrNone)
1.296 + return(r);
1.297 + if (OpenOnDriveZOnly)
1.298 + {
1.299 + aRequest->SetDrive(&TheDrives[EDriveZ]);
1.300 + aRequest->SetSubstedDrive(NULL);
1.301 + }
1.302 + return(r);
1.303 + }
1.304 +
1.305 +
1.306 +
1.307 +TInt TFsFileReplace::DoRequestL(CFsRequest* aRequest)
1.308 +//
1.309 +//
1.310 +//
1.311 + {
1.312 + __PRINT(_L("TFsFileReplace::DoRequestL(CFsRequest* aRequest)"));
1.313 + return FsFileOpenL(aRequest, EFileReplace);
1.314 + }
1.315 +
1.316 +TInt TFsFileReplace::Initialise(CFsRequest* aRequest)
1.317 +//
1.318 +//
1.319 +//
1.320 + {
1.321 + TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
1.322 + if (r!=KErrNone)
1.323 + return(r);
1.324 + r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysFileReplace,&KCapFsPriFileReplace,&KCapFsROFileReplace, __PLATSEC_DIAGNOSTIC_STRING("Replace File"));
1.325 + if (r!=KErrNone)
1.326 + return(r);
1.327 +
1.328 + if (OpenOnDriveZOnly) // Yuck! yet another global
1.329 + {
1.330 + aRequest->SetDrive(&TheDrives[EDriveZ]);
1.331 + aRequest->SetSubstedDrive(NULL);
1.332 + }
1.333 + return(r);
1.334 + }
1.335 +
1.336 +
1.337 +#ifdef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
1.338 +
1.339 +#define __PLATSEC_DIAGNOSTIC_MESSAGE(s) NULL
1.340 +static const TInt KMsgBuffSize = KMaxPath;
1.341 +
1.342 +#else
1.343 +
1.344 + #if defined(_UNICODE) && !defined(__KERNEL_MODE__)
1.345 +
1.346 +static const TInt KCharMsgMaxLen = KMaxPath - 1;
1.347 +static const TInt KMsgBuffSize = KMaxPath;
1.348 +
1.349 + #else
1.350 +
1.351 +static const TInt KCharMsgMaxLen = 50;
1.352 +static const TInt KMsgBuffSize = KMaxPath + KMsgMaxLen + 1;
1.353 +
1.354 + #endif // #if defined(_UNICODE) && !defined(__KERNEL_MODE__)
1.355 +
1.356 +// Local function to format a message
1.357 +static
1.358 +const char* FmtPlatSecMessage(TBufC<KMsgBuffSize>& buff, CFsRequest& req, const char* str)
1.359 + {
1.360 + char* p = (char*)buff.Ptr();
1.361 + const char* const base = p;
1.362 + // copy message string (if any)
1.363 + if(str)
1.364 + {
1.365 + while(*str && p < &base[KCharMsgMaxLen - 2]) // 2 for trailing ": "
1.366 + *p++ = *str++;
1.367 + *p++ = ':';
1.368 + *p++ = ' ';
1.369 + }
1.370 + // append filename
1.371 + const TDesC& fname = req.Src().FullName();
1.372 + const TInt end = Min(fname.Length(),
1.373 + KMsgBuffSize * sizeof(*buff.Ptr()) - (p - base) - 1);
1.374 + for(TInt i = 0; i < end; ++i)
1.375 + *p++ = (char)fname[i];
1.376 + *p = 0;
1.377 + return base;
1.378 + }
1.379 +
1.380 +#define __PLATSEC_DIAGNOSTIC_MESSAGE(s) FmtPlatSecMessage(thisPath, *aRequest, s)
1.381 +
1.382 +#endif // #ifdef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
1.383 +
1.384 +
1.385 +TInt TFsFileOpen::Initialise(CFsRequest* aRequest)
1.386 +//
1.387 +// Parse and execute FileOpen service otherwise sets flag for
1.388 +// asynchronous service
1.389 +//
1.390 + {
1.391 + TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
1.392 + if (r!=KErrNone)
1.393 + return(r);
1.394 +
1.395 + TBufC<KMsgBuffSize> thisPath(aRequest->Src().FullName().Mid(2));
1.396 + TUint32 mode = (aRequest->Message().Int1() & ~(EFileStreamText | EFileReadAsyncAll | EFileBigFile));
1.397 +
1.398 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.399 +// see if file is on our "Most Wanted" list
1.400 + TInt errorCode;
1.401 + checkCorruptNamesList(aRequest,errorCode);
1.402 + if(errorCode!=KErrNone)
1.403 + {
1.404 + return errorCode;
1.405 + }
1.406 +#endif
1.407 +
1.408 + CFsMessageRequest* msgRequest = (CFsMessageRequest*)aRequest;
1.409 + if (OpenOnDriveZOnly)
1.410 + {
1.411 + aRequest->SetDrive(&TheDrives[EDriveZ]);
1.412 + aRequest->SetSubstedDrive(NULL);
1.413 + }
1.414 +
1.415 + if(msgRequest->IsPluginRequest())
1.416 + {
1.417 + // Always allow plugins to open files, regardless of the clients policy
1.418 + return KErrNone;
1.419 + }
1.420 +
1.421 + if(ComparePrivate(thisPath))
1.422 + {
1.423 + if(! SIDCheck(aRequest,thisPath))
1.424 + {
1.425 + if(!KCapFsPriFileOpen.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in private path")))
1.426 + return KErrPermissionDenied;
1.427 + }
1.428 + }
1.429 + else if(CompareResource(thisPath))
1.430 + {
1.431 + if(mode != EFileShareReadersOrWriters && mode != EFileShareReadersOnly && mode != EFileRead)
1.432 + // File opening mode EFileShareReadersOrWriters|EFileRead will fail the above test and not
1.433 + // be checked for policy, whereas file opening mode EFileShareReadersOrWriters|EFileWrite
1.434 + // will pass the test and will be checked for policy.
1.435 + // EFileRead is 0 whereas EFileWrite is non 0.
1.436 + {
1.437 + if(!KCapFsROFileOpenWr.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in resource path")))
1.438 + return KErrPermissionDenied;
1.439 + }
1.440 + }
1.441 + else if(CompareSystem(thisPath))
1.442 + {
1.443 + if(!(mode & EFileShareReadersOnly) && (mode & EFileWrite))
1.444 + {
1.445 + if(!KCapFsSysFileOpenWr.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in system path")))
1.446 + return KErrPermissionDenied;
1.447 + }
1.448 + else
1.449 + {
1.450 + if(!KCapFsSysFileOpenRd.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_MESSAGE("File Open in system path")))
1.451 + return KErrPermissionDenied;
1.452 + }
1.453 + }
1.454 +
1.455 + return(r);
1.456 + }
1.457 +
1.458 +#undef __PLATSEC_DIAGNOSTIC_MESSAGE
1.459 +
1.460 +TInt TFsIsFileOpen::DoRequestL(CFsRequest* aRequest)
1.461 +//
1.462 +// Return whether a file is open or not
1.463 +//
1.464 + {
1.465 +
1.466 + __PRINT(_L("TFsIsFileOpen::DoRequestL(CFsRequest* aRequest)"));
1.467 + CFileCB* file;
1.468 + TInt r=aRequest->Drive()->IsFileOpen(aRequest->Src().FullName().Mid(2),file);
1.469 + if (r!=KErrNone)
1.470 + return(r);
1.471 + TBool isOpen = file?(TBool)ETrue:(TBool)EFalse;
1.472 + TPtrC8 pA((TUint8*)&isOpen,sizeof(TBool));
1.473 + aRequest->WriteL(KMsgPtr1,pA);
1.474 + return(KErrNone);
1.475 + }
1.476 +
1.477 +TInt TFsIsFileOpen::Initialise(CFsRequest* aRequest)
1.478 +//
1.479 +//
1.480 +//
1.481 + {
1.482 + TInt r=ParseNoWildSubstCheckPtr0(aRequest,aRequest->Src());
1.483 + if (r!=KErrNone)
1.484 + return(r);
1.485 + r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysIsFileOpen,&KCapFsPriIsFileOpen, __PLATSEC_DIAGNOSTIC_STRING("Is File Open"));
1.486 + return(r);
1.487 + }
1.488 +
1.489 +
1.490 +TInt TFsListOpenFiles::DoRequestL(CFsRequest* aRequest)
1.491 +//
1.492 +// List open files
1.493 +//
1.494 + {
1.495 +
1.496 + __PRINT(_L("TFsListOpenFiles::DoRequestL(CFsRequest* aRequest)"));
1.497 +
1.498 + TOpenFileListPos listPos;
1.499 + TPckg<TOpenFileListPos> listPkg(listPos);
1.500 + aRequest->ReadL(KMsgPtr0,listPkg);
1.501 + TBuf8<KEntryArraySize> entryArray(0);
1.502 +
1.503 + TThreadId idClient;
1.504 + TPckgC<TThreadId> id(idClient);
1.505 +
1.506 + CSessionFs* session;
1.507 + TBool fileFound=(listPos.iEntryListPos) ? (TBool)ETrue : EFalse;
1.508 + TInt entryListPos;
1.509 + TInt count;
1.510 +Start:
1.511 + FOREVER
1.512 + {
1.513 + session=(*TheFileServer)[listPos.iSession]; //this global may not be the best way AJ
1.514 + if (session==NULL)
1.515 + goto End;
1.516 + session->Handles().Lock();
1.517 + count=session->Handles().Count();
1.518 + if (count)
1.519 + break;
1.520 + session->Handles().Unlock();
1.521 + listPos.iSession++;
1.522 + }
1.523 +
1.524 + entryListPos=listPos.iEntryListPos;
1.525 + while (entryListPos<count)
1.526 + {
1.527 + CObjPromotion* obj=(CObjPromotion*)session->Handles()[entryListPos];
1.528 + if (obj==NULL || obj->UniqueID()!=FileShares->UniqueID())
1.529 + {
1.530 + entryListPos++;
1.531 + continue; // Is not a CFileShare
1.532 + }
1.533 + CFileCB& fileCb=((CFileShare*)obj)->File();
1.534 +
1.535 + TEntry fileEntry;
1.536 + // Set kEntryAttPacked to indicate it is in packed form
1.537 + fileEntry.iAtt=fileCb.Att() | KEntryAttPacked;
1.538 + TInt64 fileSize = fileCb.Size64();
1.539 + fileEntry.iSize = I64LOW(fileSize);
1.540 + fileEntry.iModified=fileCb.Modified();
1.541 + fileEntry.iName=fileCb.FileName();
1.542 +
1.543 + // Pack - Copy iSizeHigh and reset iReserved in packed form
1.544 + TUint32* pSizeHigh = PtrAdd((TUint32*)&fileEntry, EntrySize(fileEntry, EFalse));
1.545 +
1.546 + *pSizeHigh++ = I64HIGH(fileSize); // Copy iSizeHigh
1.547 + *pSizeHigh = 0; // Reset iReserved
1.548 +
1.549 + TInt entrySize=EntrySize(fileEntry, ETrue);
1.550 + if (entryArray.Length()+entrySize>entryArray.MaxLength())
1.551 + break;
1.552 + TPtrC8 pfileEntry((TUint8*)&fileEntry,entrySize);
1.553 + entryArray.Append(pfileEntry);
1.554 + entryListPos++;
1.555 + }
1.556 + idClient = session->ThreadId();
1.557 + session->Handles().Unlock();
1.558 +
1.559 + if (entryArray.Length()==0)
1.560 + listPos.iSession++;
1.561 + if (fileFound==EFalse && entryArray.Length()==0)
1.562 + goto Start;
1.563 + listPos.iEntryListPos=entryListPos;
1.564 +
1.565 +End:
1.566 + aRequest->WriteL(KMsgPtr1,id);
1.567 + aRequest->WriteL(KMsgPtr0,listPkg);
1.568 + aRequest->WriteL(KMsgPtr2,entryArray);
1.569 + return(KErrNone);
1.570 + }
1.571 +
1.572 +TInt TFsListOpenFiles::Initialise(CFsRequest* /*aRequest*/)
1.573 +//
1.574 +//
1.575 +//
1.576 + {
1.577 + return KErrNone;
1.578 + }
1.579 +
1.580 +LOCAL_C void FsFileTempFinishL(CFsRequest* aRequest,TFileName& aN,TInt aH)
1.581 + {
1.582 +
1.583 + aRequest->WriteL(KMsgPtr2,aRequest->Src().Drive());
1.584 + aRequest->WriteL(KMsgPtr2,aN,2);
1.585 + TPtrC8 pH((TUint8*)&aH,sizeof(TInt));
1.586 + aRequest->WriteL(KMsgPtr3,pH);
1.587 + }
1.588 +
1.589 +TInt TFsFileTemp::DoRequestL(CFsRequest* aRequest)
1.590 +//
1.591 +// Create a temporary file.
1.592 +//
1.593 + {
1.594 + __PRINT(_L("TFsFileTemp::DoRequestL(CFsRequest* aRequest)"));
1.595 +
1.596 + TInt r = CheckDiskSpace(0, aRequest);
1.597 + if(r != KErrNone)
1.598 + return r;
1.599 +
1.600 + TFileName n;
1.601 + TInt h;
1.602 + r=aRequest->Drive()->FileTemp(aRequest,h,aRequest->Src().FullName().Mid(2),n,aRequest->Message().Int1());
1.603 + if (r!=KErrNone)
1.604 + return(r);
1.605 +
1.606 + TRAP(r, FsFileTempFinishL(aRequest,n,h))
1.607 + CheckForLeaveAfterOpenL(r,aRequest,h);
1.608 + aRequest->Session()->IncResourceCount();
1.609 +
1.610 + return(KErrNone);
1.611 + }
1.612 +
1.613 +TInt TFsFileTemp::Initialise(CFsRequest* aRequest)
1.614 +//
1.615 +//
1.616 +//
1.617 + {
1.618 + TInt r=ParseNoWildSubstPtr0(aRequest,aRequest->Src());
1.619 + if (r!=KErrNone)
1.620 + return(r);
1.621 + r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysFileTemp,&KCapFsPriFileTemp,&KCapFsROFileTemp, __PLATSEC_DIAGNOSTIC_STRING("Temp File"));
1.622 + if (r!=KErrNone)
1.623 + return(r);
1.624 + if (aRequest->Src().NameOrExtPresent())
1.625 + return(KErrBadName);
1.626 + return(r);
1.627 + }
1.628 +
1.629 +
1.630 +TInt TFsFileRead::DoRequestL(CFsRequest* aRequest)
1.631 +//
1.632 +// Read from a file.
1.633 +//
1.634 + {
1.635 +
1.636 + __PRINT(_L("TFsFileRead::DoRequestL(CFsRequest* aRequest)"));
1.637 + __PRINT1(_L("aRequest->Session() = 0x%x"),aRequest->Session());
1.638 +
1.639 + CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
1.640 + __ASSERT_DEBUG(msgRequest.CurrentOperationPtr() != NULL, Fault(EBadOperationIndex));
1.641 + TMsgOperation& currentOperation = msgRequest.CurrentOperation();
1.642 +
1.643 + CFileShare* share;
1.644 + CFileCB* file;
1.645 + GetFileFromScratch(aRequest, share, file);
1.646 +
1.647 + TInt r = file->CheckMount();
1.648 + __PRINT1(_L("share->CheckMount() returned = %d"),r);
1.649 + if (r!=KErrNone)
1.650 + return(r);
1.651 +
1.652 + TInt& len = currentOperation.iReadWriteArgs.iLength;
1.653 + TInt& totalLen = currentOperation.iReadWriteArgs.iTotalLength;
1.654 + TInt64 pos = currentOperation.iReadWriteArgs.iPos;
1.655 + TInt& offset = currentOperation.iReadWriteArgs.iOffset;
1.656 +
1.657 + // Fair scheduling -
1.658 + // Needs extended file API to work (so that we can sepcify an offset)
1.659 + // Also needs a separate drive thread to prevent excessive stack usage
1.660 + len = Min(len, totalLen);
1.661 + if (file->ExtendedFileInterfaceSupported() && !FsThreadManager::IsDriveSync(aRequest->DriveNumber(), EFalse))
1.662 + {
1.663 + len = Min(len, file->FairSchedulingLen());
1.664 + }
1.665 + if (pos == KCurrentPosition64)
1.666 + pos = share->iPos;
1.667 +
1.668 + currentOperation.iReadWriteArgs.iPos = pos;
1.669 +
1.670 + __ASSERT_DEBUG(len > 0, Fault(EInvalidReadLength));
1.671 + __ASSERT_DEBUG(len <= totalLen, Fault(EInvalidReadLength));
1.672 +
1.673 + // The mount and any extensions must all support local buffers in order to support
1.674 + // internally generated requests (ie - requests originating from plugins)
1.675 + if ((aRequest->Message().Handle() == KLocalMessageHandle || !currentOperation.iClientRequest) && !file->LocalBufferSupport())
1.676 + {
1.677 + r = KErrNotSupported;
1.678 + }
1.679 +
1.680 + TInt reqLen = len;
1.681 + if(r == KErrNone)
1.682 + {
1.683 + if (currentOperation.iClientRequest)
1.684 + {
1.685 + // Current operation points to a descriptor
1.686 + // The request originated from a client (with a normal message handle) or a plugin (KLocalMessageHandle)
1.687 + TRAP(r,file->ReadL(pos, len, (TPtr8*) aRequest->Message().Ptr0(), aRequest->Message(), offset))
1.688 + }
1.689 + else
1.690 + {
1.691 + // Current operation points to a local buffer
1.692 + // The request originated from the file server (e.g. file cache) with a local message handle (KLocalMessageHandle)
1.693 + TPtr8 dataDesc((TUint8*) currentOperation.iReadWriteArgs.iData + currentOperation.iReadWriteArgs.iOffset, len, len);
1.694 + const RLocalMessage msg;
1.695 + TRAP(r,file->ReadL(pos, len, &dataDesc, msg, 0));
1.696 + }
1.697 + }
1.698 +
1.699 +
1.700 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.701 + CCacheManager* manager = CCacheManagerFactory::CacheManager();
1.702 + if (manager)
1.703 + {
1.704 + manager->Stats().iUncachedPacketsRead++;
1.705 + manager->Stats().iUncachedBytesRead+= len;
1.706 + }
1.707 +#endif
1.708 +
1.709 +//RDebug::Print(_L("ReadR: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file);
1.710 +
1.711 +
1.712 +#if defined (_DEBUG_READ_AHEAD)
1.713 + RDebug::Print(_L("ReadR: req %08X pos %ld\t len %d nextPos %ld file %08X\n"), aRequest, pos, len, pos + len, file);
1.714 +#endif
1.715 +
1.716 + offset+= len;
1.717 + currentOperation.iReadWriteArgs.iPos+= len;
1.718 + totalLen-= reqLen;
1.719 +
1.720 +
1.721 + // update the file share's position IF this request came from the client
1.722 + if (share && r==KErrNone && currentOperation.iClientRequest)
1.723 + {
1.724 + __e32_atomic_store_ord64(&share->iPos, pos + len);
1.725 + }
1.726 +
1.727 + // re-issue request if not complete (to support fair scheduling)
1.728 + if (r == KErrNone && totalLen > 0)
1.729 + return CFsRequest::EReqActionBusy; // dispatch request again to back of queue
1.730 +
1.731 + return(r);
1.732 + }
1.733 +
1.734 +
1.735 +TInt TFsFileRead::Initialise(CFsRequest* aRequest)
1.736 +//
1.737 +//
1.738 +//
1.739 + {
1.740 + CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
1.741 +
1.742 + TInt r = DoInitNoParse(aRequest);
1.743 + if (r != KErrNone)
1.744 + return r;
1.745 +
1.746 + CFileShare* share;
1.747 + CFileCB* file;
1.748 + GetFileFromScratch(aRequest, share, file);
1.749 +
1.750 + TMsgOperation* msgOp = msgRequest.CurrentOperationPtr();
1.751 + if (!msgOp) // initialised already ?
1.752 + {
1.753 + r = msgRequest.PushOperation(TFsFileRead::Complete);
1.754 + if (r != KErrNone)
1.755 + return r;
1.756 + msgOp = msgRequest.CurrentOperationPtr();
1.757 + }
1.758 + // try to serialize requests to prevent asynchronous requests being processed out of sequence -
1.759 + // this isn't possible if a plugin is loaded as this may issue it's own requests
1.760 + if (!share->RequestStart(&msgRequest))
1.761 + return CFsRequest::EReqActionPending;
1.762 +
1.763 + TDrive& drive = share->File().Drive();
1.764 +
1.765 + TInt64 pos, reqPos;
1.766 + TInt len, reqLen;
1.767 +
1.768 + reqLen = len = aRequest->Message().Int1();
1.769 +
1.770 + if(aRequest->IsDescData(KMsgPtr2))
1.771 + {//-- 64-bit file addressing, absolute read position is TInt64
1.772 + TPckg<TInt64> pkPos(reqPos);
1.773 + aRequest->ReadL(KMsgPtr2, pkPos);
1.774 + }
1.775 + else
1.776 + {
1.777 + if(aRequest->Message().Int2() == (TInt)I64LOW(KCurrentPosition64))
1.778 + reqPos = KCurrentPosition64; // Position is KCurrentPosition64 (-1)
1.779 + else //-- legacy, RFile addressing
1.780 + reqPos = MAKE_TINT64(0,aRequest->Message().Int2()); // Position is absolute value < 4GB, it's TUint
1.781 + }
1.782 +
1.783 + msgOp->iClientPosition = pos = reqPos;
1.784 +
1.785 + if (len < 0)
1.786 + return KErrArgument;
1.787 +
1.788 + if (len == 0)
1.789 + return CFsRequest::EReqActionComplete;
1.790 +
1.791 + if (pos == KCurrentPosition64)
1.792 + pos = share->iPos;
1.793 +
1.794 + const TInt64 fileSize = file->CachedSize64();
1.795 + if (pos > fileSize)
1.796 + pos = fileSize;
1.797 +
1.798 + if ((r = file->CheckLock64(share,pos,len)) != KErrNone)
1.799 + return r;
1.800 +
1.801 +
1.802 + TDes8* pD = (TDes8*) aRequest->Message().Ptr0();
1.803 +
1.804 + if((share->iMode & EFileReadAsyncAll) && (aRequest->Message().ClientStatus() != NULL))
1.805 + {
1.806 + drive.Lock();
1.807 + if (pos + len > fileSize)
1.808 + {
1.809 + r = share->File().AddAsyncReadRequest(share, reqPos, reqLen, aRequest);
1.810 + drive.UnLock();
1.811 + return (r == KErrNone)?CFsRequest::EReqActionComplete:r;
1.812 + }
1.813 + drive.UnLock();
1.814 + }
1.815 +
1.816 + if (pos == fileSize)
1.817 + {
1.818 + __e32_atomic_store_ord64(&share->iPos, pos);
1.819 + r = aRequest->Write(KMsgPtr0, KNullDesC8);
1.820 + return(r == KErrNone?CFsRequest::EReqActionComplete:r);
1.821 + }
1.822 +
1.823 + if (pos + len > fileSize)
1.824 + {
1.825 + // filesize - pos shall of TInt size
1.826 + // Hence to suppress warning
1.827 + len = (TInt)(fileSize - pos);
1.828 + }
1.829 +
1.830 + msgOp->Set(pos, len, (TDesC8*) pD);
1.831 +
1.832 +//RDebug::Print(_L("ReadI: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file);
1.833 +
1.834 +#if defined (_DEBUG_READ_AHEAD)
1.835 + RDebug::Print(_L("ReadI: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file);
1.836 +#endif
1.837 +
1.838 + return KErrNone;
1.839 + }
1.840 +
1.841 +TInt TFsFileRead::PostInitialise(CFsRequest* aRequest)
1.842 + {
1.843 + CFileShare* share = (CFileShare*) aRequest->ScratchValue();
1.844 + CFileCB* file = &share->File();
1.845 + TInt r = KErrNone;
1.846 +
1.847 + CFileCache* fileCache = file->FileCache();
1.848 + if (fileCache)
1.849 + {
1.850 + r = fileCache->ReadBuffered(*(CFsMessageRequest*)aRequest, share->iMode);
1.851 +
1.852 + // if we're not reading from cache, force read ahead position & length to be recalculated
1.853 + if (r == KErrNone)
1.854 + fileCache->ResetReadAhead();
1.855 + }
1.856 +
1.857 + return r;
1.858 + }
1.859 +
1.860 +TInt TFsFileRead::Complete(CFsRequest* aRequest)
1.861 + {
1.862 +// RDebug::Print(_L("TFsFileRead::Complete() aRequest %08X"), aRequest);
1.863 +
1.864 + CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
1.865 +
1.866 + CFileShare* share;
1.867 + CFileCB* file;
1.868 + GetFileFromScratch(aRequest, share, file);
1.869 +
1.870 + // Flag the request as having ended to allow another async read to occur
1.871 + share->RequestEnd(&msgRequest);
1.872 +
1.873 +
1.874 + // issue read-ahead
1.875 + CFileCache* fileCache = file->FileCache();
1.876 + if (fileCache && msgRequest.LastError() == KErrNone)
1.877 + fileCache->ReadAhead(msgRequest, share->iMode);
1.878 +
1.879 + return CFsRequest::EReqActionComplete;
1.880 + }
1.881 +
1.882 +
1.883 +void GetFileFromScratch(CFsRequest* aRequest, CFileShare*& aShare, CFileCB*& aFile)
1.884 + {
1.885 +
1.886 + TInt64 scratchValue = aRequest->ScratchValue64();
1.887 + TBool scratchValueIsShare I64HIGH(scratchValue);
1.888 + TUint32 scratchValueLow = I64LOW(scratchValue);
1.889 +
1.890 + aShare = NULL;
1.891 + aFile = NULL;
1.892 +
1.893 + if (scratchValueIsShare)
1.894 + {
1.895 + aShare = (CFileShare*) scratchValueLow;
1.896 + if (aShare)
1.897 + aFile = &aShare->File();
1.898 + }
1.899 + else
1.900 + {
1.901 + aFile = (CFileCB*) scratchValueLow;
1.902 + }
1.903 + }
1.904 +
1.905 +/**
1.906 + Common init preamble for TFsFileWrite::Initialise() and TFsFileWrite::DoRequestL()
1.907 +
1.908 + @param aShare pointer to the file share
1.909 + @param aFile pointer to the file object this function is called for
1.910 + @param aPos file position to write data. Note that it can be KCurrentPosition64 i.e. KMaxTUint64
1.911 + @param aLen length of the data to write
1.912 + @param aFileSize current file size
1.913 + @param aFsOp File Server message code. See TFsMessage. It must be ether EFsFileWrite for normal write, or EFsFileWriteDirty when file cache flushes dirty data
1.914 +*/
1.915 +
1.916 +TInt TFsFileWrite::CommonInit(CFileShare* aShare, CFileCB* aFile, TInt64& aPos, TInt& aLen, TInt64 aFileSize, TFsMessage aFsOp)
1.917 + {
1.918 +
1.919 + if (aShare && aPos==KCurrentPosition64)
1.920 + {//-- write to the current position in the file
1.921 + aPos = aShare->iPos;
1.922 + }
1.923 +
1.924 + if(aPos > aFileSize)
1.925 + aPos = aFileSize;
1.926 +
1.927 + //-- check that the new position won't exceed maximum file size
1.928 + {
1.929 + const TUint64 endPos = aPos+aLen;
1.930 +
1.931 + //-- Large file mode check. Legacy RFile size can't exceed 2G-1
1.932 + if(aShare && !(aShare->IsFileModeBig()) && (endPos > KMaxLegacyFileSize))
1.933 + return KErrTooBig;
1.934 +
1.935 + //-- check CMountCB limitation on maximum file size
1.936 + if(endPos > aFile->MaxSupportedSize())
1.937 + return KErrNotSupported; //-- this is for the sake of error codes consistency; current FSYs return
1.938 + //-- this code in the case of accessing a file beyond its limit
1.939 + }
1.940 +
1.941 + if (aShare)
1.942 + {
1.943 + TInt r;
1.944 + if ((r=aFile->CheckLock64(aShare,aPos,aLen))!=KErrNone)
1.945 + return(r);
1.946 + }
1.947 +
1.948 + ASSERT(aFsOp == EFsFileWrite || aFsOp == EFsFileWriteDirty);
1.949 + if(aFsOp == EFsFileWrite)
1.950 + {//-- this call is originated from explicit file write operation. Set 'Archive' attribute and new file time.
1.951 + aFile->SetArchiveAttribute(); //-- it will also set KEntryAttModified
1.952 + }
1.953 + else
1.954 + {//-- don't touch data and attributes if it is cache flushing dirty data
1.955 + aFile->iAtt |= KEntryAttModified;
1.956 + }
1.957 +
1.958 +
1.959 + return KErrNone;
1.960 + }
1.961 +
1.962 +void TFsFileWrite::CommonEnd(CFsMessageRequest* aMsgRequest, TInt aRetVal, TUint64 aInitSize, TUint64 aNewSize, TInt64 aNewPos, TBool aFileWrite)
1.963 +//
1.964 +// Common end for TFsFileWrite::DoRequestL() and CFileCache::WriteBuffered()
1.965 +//
1.966 + {
1.967 +
1.968 + CFileShare* share;
1.969 + CFileCB* file;
1.970 + GetFileFromScratch(aMsgRequest, share, file);
1.971 + CFileCache* fileCache = file->FileCache();
1.972 + ASSERT(aFileWrite || fileCache);
1.973 +
1.974 + TMsgOperation& currentOperation = aMsgRequest->CurrentOperation();
1.975 +
1.976 + if (aRetVal == KErrNone || aRetVal == CFsRequest::EReqActionComplete)
1.977 + {
1.978 + if (share)
1.979 + {
1.980 + __e32_atomic_store_ord64(&share->iPos, aNewPos);
1.981 + }
1.982 +
1.983 + if ((TUint64)aNewPos > aNewSize)
1.984 + {
1.985 + if(aFileWrite)
1.986 + file->SetSize64(aNewPos, EFalse);
1.987 + else
1.988 + fileCache->SetSize64(aNewPos);
1.989 + aNewSize = aNewPos;
1.990 + }
1.991 +
1.992 + // ensure cached file is at least as big as uncached file
1.993 + if (fileCache && fileCache->Size64() < aNewPos)
1.994 + {
1.995 + file->SetCachedSize64(aNewPos);
1.996 + }
1.997 +
1.998 + // Service async reads if the file has grown & this is the last fair-scheduled request
1.999 +
1.1000 + // If the file has grown, flag this and call CFileCB::NotifyAsyncReaders()
1.1001 + // later in TFsFileWrite::Complete() - we need to delay the call because
1.1002 + // CFileCB::NotifyAsyncReaders() may requeue a request which will cause
1.1003 + // the drive thread to spin because this file share is still marked as in use
1.1004 + // (by CFileShare::RequestStart())
1.1005 + if((aNewSize > aInitSize) && (currentOperation.iReadWriteArgs.iTotalLength == 0))
1.1006 + {
1.1007 + file->SetNotifyAsyncReadersPending(ETrue);
1.1008 + }
1.1009 +
1.1010 + file->iAtt |= KEntryAttModified;
1.1011 +
1.1012 + }
1.1013 + else if (aRetVal == KErrCorrupt)
1.1014 + file->SetFileCorrupt(ETrue);
1.1015 + else if (aRetVal == KErrBadPower || (aRetVal == KErrAbort && !PowerOk()))
1.1016 + file->SetBadPower(ETrue);
1.1017 +
1.1018 + file->ResetReadAhead();
1.1019 + aMsgRequest->SetFreeChanged(aNewSize != aInitSize);
1.1020 + }
1.1021 +
1.1022 +TInt TFsFileWrite::DoRequestL(CFsRequest* aRequest)
1.1023 +//
1.1024 +// Write to a file.
1.1025 +//
1.1026 + {
1.1027 + __PRINT(_L("TFsFileWrite::DoRequestL(CFsRequest* aRequest)"));
1.1028 +
1.1029 + CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
1.1030 + __ASSERT_DEBUG(msgRequest.CurrentOperationPtr() != NULL, Fault(EBadOperationIndex));
1.1031 + TMsgOperation& currentOperation = msgRequest.CurrentOperation();
1.1032 +
1.1033 + TInt r;
1.1034 +
1.1035 + CFileShare* share;
1.1036 + CFileCB* file;
1.1037 + GetFileFromScratch(aRequest, share, file);
1.1038 +
1.1039 + TInt64 initSize = file->Size64();
1.1040 +
1.1041 + r = file->CheckMount();
1.1042 + if (r!=KErrNone)
1.1043 + return(r);
1.1044 +
1.1045 +
1.1046 + TInt& len = currentOperation.iReadWriteArgs.iLength;
1.1047 +
1.1048 + // Fair scheduling -
1.1049 + // Needs extended file API to work (so that we can specify an offset)
1.1050 + // Also needs a separate drive thread to prevent excessive stack usage
1.1051 + len = Min(len, currentOperation.iReadWriteArgs.iTotalLength);
1.1052 + if (file->ExtendedFileInterfaceSupported() && !FsThreadManager::IsDriveSync(aRequest->DriveNumber(), EFalse))
1.1053 + {
1.1054 + len = Min(len, file->FairSchedulingLen());
1.1055 + }
1.1056 +
1.1057 + __ASSERT_DEBUG(len <= currentOperation.iReadWriteArgs.iTotalLength, Fault(EInvalidWriteLength));
1.1058 +
1.1059 +
1.1060 + const TFsMessage fsOp = (TFsMessage)aRequest->Operation()->Function();
1.1061 + r = CommonInit(share, file, currentOperation.iReadWriteArgs.iPos, len, initSize, fsOp);
1.1062 +
1.1063 + if (r != KErrNone)
1.1064 + return r;
1.1065 +
1.1066 + TInt64 pos = currentOperation.iReadWriteArgs.iPos;
1.1067 +
1.1068 + TInt64 upos = pos+len;
1.1069 + if (upos > initSize)
1.1070 + {
1.1071 + r = CheckDiskSpace(upos - initSize, aRequest);
1.1072 + if(r != KErrNone)
1.1073 + return r;
1.1074 + }
1.1075 +
1.1076 + // The mount and any extensions must all support local buffers in order to support
1.1077 + // internally generated requests (ie - requests originating from plugins)
1.1078 + if ((aRequest->Message().Handle() == KLocalMessageHandle || !currentOperation.iClientRequest) && !file->LocalBufferSupport())
1.1079 + {
1.1080 + r = KErrNotSupported;
1.1081 + }
1.1082 +
1.1083 + if(r == KErrNone)
1.1084 + {
1.1085 + if (currentOperation.iClientRequest)
1.1086 + {
1.1087 + TRAP(r,file->WriteL(pos, len, (const TPtrC8*) aRequest->Message().Ptr0(), aRequest->Message(), currentOperation.iReadWriteArgs.iOffset))
1.1088 + }
1.1089 + else
1.1090 + {
1.1091 + TPtr8 dataDesc((TUint8*) currentOperation.iReadWriteArgs.iData + currentOperation.iReadWriteArgs.iOffset, len, len);
1.1092 + const RLocalMessage msg;
1.1093 + TRAP(r,file->WriteL(pos, len, &dataDesc, msg, 0));
1.1094 + }
1.1095 + }
1.1096 +
1.1097 +//RDebug::Print(_L("WriteR: req %08X pos %ld\t len %d file %08X\n"), aRequest, pos, len, file);
1.1098 +
1.1099 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.1100 + CCacheManager* manager = CCacheManagerFactory::CacheManager();
1.1101 + if (manager)
1.1102 + {
1.1103 + manager->Stats().iUncachedPacketsWritten++;
1.1104 + manager->Stats().iUncachedBytesWritten+= len;
1.1105 + }
1.1106 +#endif
1.1107 +
1.1108 + if (r == KErrNone)
1.1109 + {
1.1110 + // update position, offset & length remaining
1.1111 + currentOperation.iReadWriteArgs.iOffset+= len;
1.1112 + currentOperation.iReadWriteArgs.iPos+= len;
1.1113 + currentOperation.iReadWriteArgs.iTotalLength-= len;
1.1114 + }
1.1115 + TUint64 currentSize = MAKE_TUINT64(file->iBody->iSizeHigh,file->iSize);
1.1116 + CommonEnd(&msgRequest, r, initSize, currentSize, pos+len, ETrue);
1.1117 +
1.1118 + // re-issue request if not complete (to support fair scheduling)
1.1119 + if (r == KErrNone && currentOperation.iReadWriteArgs.iTotalLength > 0)
1.1120 + return CFsRequest::EReqActionBusy; // dispatch request again to back of queue
1.1121 +
1.1122 + return(r);
1.1123 + }
1.1124 +
1.1125 +TInt TFsFileWrite::Initialise(CFsRequest* aRequest)
1.1126 +//
1.1127 +//
1.1128 +//
1.1129 + {
1.1130 + CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
1.1131 +
1.1132 + TInt r = DoInitNoParse(aRequest);
1.1133 + if (r != KErrNone)
1.1134 + return r;
1.1135 +
1.1136 + // If the drive has been dismounted, don't even attempt to write to the file as that
1.1137 + // will create dirty data which can then not be flushed without hitting ASSERTs etc.
1.1138 + if (!FsThreadManager::IsDriveAvailable(aRequest->DriveNumber(), EFalse))
1.1139 + return KErrNotReady;
1.1140 +
1.1141 + CFileShare* share;
1.1142 + CFileCB* file;
1.1143 + GetFileFromScratch(aRequest, share, file);
1.1144 +
1.1145 + // Bail out if there's a new mount which isn't ours - this would fail
1.1146 + // later on anyway when TFsFileWrite::DoRequestL() called CFileCB::CheckMount()
1.1147 + if ( !file->Drive().IsCurrentMount(file->Mount()) )
1.1148 + return KErrDisMounted;
1.1149 +
1.1150 +
1.1151 + TMsgOperation* msgOp = msgRequest.CurrentOperationPtr();
1.1152 + if (!msgOp) // initialised already ?
1.1153 + {
1.1154 + r = msgRequest.PushOperation(TFsFileWrite::Complete);
1.1155 + if (r != KErrNone)
1.1156 + return r;
1.1157 + msgOp = msgRequest.CurrentOperationPtr();
1.1158 + }
1.1159 + // try to serialize requests to prevent asynchronous requests being processed out of sequence -
1.1160 + // this isn't possible if a plugin is loaded as this may issue it's own requests
1.1161 + if (share && !share->RequestStart(&msgRequest))
1.1162 + return CFsRequest::EReqActionPending;
1.1163 +
1.1164 + TInt64 pos;
1.1165 +
1.1166 + if(aRequest->IsDescData(KMsgPtr2))
1.1167 + {//-- 64-bit file addressing, absolute read position is TInt64
1.1168 + TPckg<TInt64> pkPos(pos);
1.1169 + aRequest->ReadL(KMsgPtr2, pkPos);
1.1170 + }
1.1171 + else
1.1172 + {
1.1173 + if(aRequest->Message().Int2() == (TInt)I64LOW(KCurrentPosition64))
1.1174 + pos = KCurrentPosition64;// Position is KCurrentPosition64 (-1)
1.1175 + else
1.1176 + pos = MAKE_TINT64(0,aRequest->Message().Int2());// Position is absolute value < 4GB, it's a TUint type
1.1177 + }
1.1178 +
1.1179 + msgOp->iClientPosition = pos;
1.1180 + TInt len = aRequest->Message().Int1();
1.1181 +
1.1182 + TDesC8* pD = (TDes8*) aRequest->Message().Ptr0();
1.1183 +
1.1184 + if (len == 0)
1.1185 + return CFsRequest::EReqActionComplete;
1.1186 +
1.1187 + if (len < 0)
1.1188 + return KErrArgument;
1.1189 +
1.1190 + //if this request was sent down from a plugin, then we want to
1.1191 + //ignore the mode that the files was opened in.
1.1192 + if (share && !msgRequest.IsPluginRequest())
1.1193 + {
1.1194 + if ((share->iMode & EFileWrite)==0 ||
1.1195 + (share->iMode & KFileShareMask) == EFileShareReadersOnly)
1.1196 + {
1.1197 + return(KErrAccessDenied);
1.1198 + }
1.1199 + }
1.1200 +
1.1201 +
1.1202 + const TFsMessage fsOp = (TFsMessage)aRequest->Operation()->Function();
1.1203 + r = CommonInit(share, file, pos, len, file->CachedSize64(), fsOp);
1.1204 + if (r != KErrNone)
1.1205 + return r;
1.1206 +
1.1207 + msgOp->Set(pos, len, pD);
1.1208 +
1.1209 + return KErrNone;
1.1210 + }
1.1211 +
1.1212 +
1.1213 +TInt TFsFileWrite::PostInitialise(CFsRequest* aRequest)
1.1214 + {
1.1215 + CFileShare* share = (CFileShare*) aRequest->ScratchValue();
1.1216 + CFileCB* file = &share->File();
1.1217 + TInt r = KErrNone;
1.1218 +
1.1219 + CFileCache* fileCache = file->FileCache();
1.1220 + if (fileCache)
1.1221 + {
1.1222 + // If there's no data left proceed straight to completion stage
1.1223 + // This can happen when re-posting a completed write request to
1.1224 + // start the dirty data timer
1.1225 + if (((CFsMessageRequest*) aRequest)->CurrentOperation().iReadWriteArgs.iTotalLength == 0)
1.1226 + return CFsRequest::EReqActionComplete;
1.1227 +
1.1228 + r = fileCache->WriteBuffered(*(CFsMessageRequest*)aRequest, share->iMode);
1.1229 + }
1.1230 +
1.1231 + return r;
1.1232 + }
1.1233 +
1.1234 +TInt TFsFileWrite::Complete(CFsRequest* aRequest)
1.1235 + {
1.1236 + CFsMessageRequest& msgRequest = *(CFsMessageRequest*) aRequest;
1.1237 +
1.1238 +
1.1239 + CFileShare* share;
1.1240 + CFileCB* file;
1.1241 + GetFileFromScratch(aRequest, share, file);
1.1242 +
1.1243 + if (share)
1.1244 + share->RequestEnd(&msgRequest);
1.1245 +
1.1246 + if (file->NotifyAsyncReadersPending())
1.1247 + file->NotifyAsyncReaders();
1.1248 +
1.1249 + return CFsRequest::EReqActionComplete;
1.1250 + }
1.1251 +
1.1252 +TInt TFsFileLock::DoRequestL(CFsRequest* aRequest)
1.1253 +//
1.1254 +// Lock a region of the file.
1.1255 +//
1.1256 + {
1.1257 +
1.1258 + __PRINT(_L("TFsFileLock::DoRequestL(CFsRequest* aRequest)"));
1.1259 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1260 +
1.1261 + // We must wait for ALL shares to have no active requests (see RequestStart())
1.1262 + // and post this request to the back of the queue if there are any. This is to
1.1263 + // avoid a fair-scheduled write from writing to a locked region of a file
1.1264 + CSessionFs* session = aRequest->Session();
1.1265 + if (session)
1.1266 + {
1.1267 + TBool fileInUse = EFalse;
1.1268 + session->Handles().Lock();
1.1269 + TInt count = session->Handles().Count();
1.1270 + CFileCB* file = &share->File();
1.1271 +
1.1272 + for (TInt n=0; n<count; n++)
1.1273 + {
1.1274 + CObjPromotion* obj = (CObjPromotion*)session->Handles()[n];
1.1275 + if (obj != NULL &&
1.1276 + obj->UniqueID() == FileShares->UniqueID() &&
1.1277 + (file == &((CFileShare*) obj)->File()) &&
1.1278 + ((CFileShare*) obj)->RequestInProgress())
1.1279 + {
1.1280 + CFsMessageRequest& msgRequest = *(CFsMessageRequest*)aRequest;
1.1281 + if(msgRequest.IsPluginRequest())
1.1282 + break;
1.1283 +
1.1284 + fileInUse = ETrue;
1.1285 + break;
1.1286 + }
1.1287 + }
1.1288 + session->Handles().Unlock();
1.1289 + if (fileInUse)
1.1290 + return CFsRequest::EReqActionBusy;
1.1291 + }
1.1292 +
1.1293 + TInt64 pos, length;
1.1294 + if(aRequest->IsDescData(KMsgPtr0))
1.1295 + {
1.1296 + TPckg<TInt64> pkPos(pos);
1.1297 + aRequest->ReadL(KMsgPtr0, pkPos);
1.1298 + }
1.1299 + else
1.1300 + {
1.1301 + pos = MAKE_TINT64(0, aRequest->Message().Int0());
1.1302 + }
1.1303 +
1.1304 + if(aRequest->IsDescData(KMsgPtr1))
1.1305 + {
1.1306 + TPckg<TInt64> pkLength(length);
1.1307 + aRequest->ReadL(KMsgPtr1, pkLength);
1.1308 + if(length <= 0)
1.1309 + User::Leave(ELockLengthZero);
1.1310 + }
1.1311 + else
1.1312 + {
1.1313 + length = aRequest->Message().Int1();
1.1314 + if(length <= 0)
1.1315 + User::Leave(ELockLengthZero);
1.1316 + }
1.1317 + return(share->File().AddLock64(share, pos, length));
1.1318 + }
1.1319 +
1.1320 +TInt TFsFileLock::Initialise(CFsRequest* aRequest)
1.1321 +//
1.1322 +//
1.1323 +//
1.1324 + {
1.1325 + return(DoInitNoParse(aRequest));
1.1326 + }
1.1327 +
1.1328 +
1.1329 +TInt TFsFileUnlock::DoRequestL(CFsRequest* aRequest)
1.1330 +//
1.1331 +// Unlock a region of the file.
1.1332 +//
1.1333 + {
1.1334 + __PRINT(_L("TFsFileUnlock::DoRequestL(CFsRequest* aRequest)"));
1.1335 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1336 +
1.1337 + TInt64 pos, length;
1.1338 +
1.1339 + if(aRequest->IsDescData(KMsgPtr0))
1.1340 + {
1.1341 + TPckg<TInt64> pkPos(pos);
1.1342 + aRequest->ReadL(KMsgPtr0, pkPos);
1.1343 + }
1.1344 + else
1.1345 + {
1.1346 + pos = MAKE_TINT64(0, aRequest->Message().Int0());
1.1347 + }
1.1348 +
1.1349 + if(aRequest->IsDescData(KMsgPtr1))
1.1350 + {
1.1351 + TPckg<TInt64> pkLength(length);
1.1352 + aRequest->ReadL(KMsgPtr1, pkLength);
1.1353 + if(length <= 0)
1.1354 + User::Leave(EUnlockLengthZero);
1.1355 + }
1.1356 + else
1.1357 + {
1.1358 + length = aRequest->Message().Int1();
1.1359 + if(length <= 0)
1.1360 + User::Leave(EUnlockLengthZero);
1.1361 + }
1.1362 + return(share->File().RemoveLock64(share, pos, length));
1.1363 + }
1.1364 +
1.1365 +TInt TFsFileUnlock::Initialise(CFsRequest* aRequest)
1.1366 +//
1.1367 +//
1.1368 +//
1.1369 + {
1.1370 + return(DoInitNoParse(aRequest));
1.1371 + }
1.1372 +
1.1373 +
1.1374 +TInt TFsFileSeek::DoRequestL(CFsRequest* aRequest)
1.1375 +//
1.1376 +// Set the file position.
1.1377 +//
1.1378 + {
1.1379 +
1.1380 + __PRINT(_L("TFsFileSeek::DoRequestL(CFsRequest* aRequest)"));
1.1381 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1382 + TInt64 size = share->File().CachedSize64();
1.1383 + TInt64 pos;
1.1384 + if(aRequest->IsDescData(KMsgPtr0))
1.1385 + {
1.1386 + TPckg<TInt64> pkPos(pos);
1.1387 + aRequest->ReadL(KMsgPtr0, pkPos);
1.1388 + }
1.1389 + else
1.1390 + {
1.1391 + pos = aRequest->Message().Int0();
1.1392 + }
1.1393 +
1.1394 + TInt r,t;
1.1395 +
1.1396 + if (share->iPos != pos)
1.1397 + share->File().ResetReadAhead();
1.1398 +
1.1399 + switch (aRequest->Message().Int1())
1.1400 + {
1.1401 + case ESeekCurrent:
1.1402 + pos+=share->iPos;
1.1403 + if (pos<0)
1.1404 + pos=0;
1.1405 +
1.1406 + if (pos>size)
1.1407 + pos=size;
1.1408 +
1.1409 + // Large file mode check
1.1410 + if((!(share->IsFileModeBig())) && ((TUint64)pos > KMaxLegacyFileSize))
1.1411 + return (KErrTooBig);
1.1412 +
1.1413 + break;
1.1414 + case ESeekEnd:
1.1415 + pos+=size;
1.1416 + if (pos<0)
1.1417 + pos=0;
1.1418 + if (pos>size)
1.1419 + pos=size;
1.1420 + // Large file mode check
1.1421 + if((!(share->IsFileModeBig())) && ((TUint64)pos > KMaxLegacyFileSize))
1.1422 + return (KErrTooBig);
1.1423 +
1.1424 + break;
1.1425 + case ESeekAddress:
1.1426 + t = (TUint)pos;
1.1427 + r = share->File().Address(t);
1.1428 + pos = (TUint)t;
1.1429 + if(KErrNone != r)
1.1430 + return(r);
1.1431 + goto writeBackPos;
1.1432 + case ESeekStart:
1.1433 + if (pos>=0)
1.1434 + {
1.1435 + share->iPos = pos;
1.1436 + return KErrNone;
1.1437 + }
1.1438 + return(KErrArgument);
1.1439 + default:
1.1440 + return(KErrArgument);
1.1441 + }
1.1442 + __e32_atomic_store_ord64(&share->iPos, pos);
1.1443 +writeBackPos:
1.1444 + TPckgC<TInt64> pkNewPos(pos);
1.1445 + aRequest->WriteL(KMsgPtr2, pkNewPos);
1.1446 + return(KErrNone);
1.1447 + }
1.1448 +
1.1449 +TInt TFsFileSeek::Initialise(CFsRequest* aRequest)
1.1450 +//
1.1451 +//
1.1452 +//
1.1453 + {
1.1454 + return(DoInitNoParse(aRequest));
1.1455 + }
1.1456 +
1.1457 +
1.1458 +TInt TFsFileFlush::DoRequestL(CFsRequest* aRequest)
1.1459 +//
1.1460 +// Commit any data in memory to the media.
1.1461 +//
1.1462 + {
1.1463 +
1.1464 + __PRINT(_L("TFsFileFlush::DoRequestL(CFsRequest* aRequest)"));
1.1465 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1466 +
1.1467 + // if any write requests are being fair scheduled, wait for them to complete
1.1468 + if (share->RequestInProgress())
1.1469 + return CFsRequest::EReqActionBusy;
1.1470 +
1.1471 + // flush the write cache
1.1472 + TInt r;
1.1473 + CFileCache* fileCache = share->File().FileCache();
1.1474 + if (fileCache && (r = fileCache->FlushDirty(aRequest)) != CFsRequest::EReqActionComplete)
1.1475 + {
1.1476 + //To be used in notification framework
1.1477 + //CFsMessageRequest& msgRequest = (CFsMessageRequest&)*aRequest;
1.1478 + //msgRequest.iUID = msgRequest.Message().Identity();
1.1479 + return r;
1.1480 + }
1.1481 +
1.1482 + if ((share->File().Att()&KEntryAttModified)==0)
1.1483 + return(KErrNone);
1.1484 + if ((share->iMode&EFileWrite)==0)
1.1485 + return(KErrAccessDenied);
1.1486 + r=share->CheckMount();
1.1487 + if (r!=KErrNone)
1.1488 + return(r);
1.1489 +
1.1490 + TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataL, EF32TraceUidFileSys, &share->File());
1.1491 + TRAP(r,share->File().FlushDataL());
1.1492 + TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataLRet, EF32TraceUidFileSys, r);
1.1493 +
1.1494 + return(r);
1.1495 + }
1.1496 +
1.1497 +TInt TFsFileFlush::Initialise(CFsRequest* aRequest)
1.1498 +//
1.1499 +//
1.1500 +//
1.1501 + {
1.1502 + return(DoInitNoParse(aRequest));
1.1503 + }
1.1504 +
1.1505 +
1.1506 +TInt TFsFileSize::DoRequestL(CFsRequest* aRequest)
1.1507 +//
1.1508 +// Get the file size.
1.1509 +//
1.1510 + {
1.1511 +
1.1512 + __PRINT(_L("TFsFileSize::DoRequestL(CFsRequest* aRequest)"));
1.1513 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1514 + TInt64 size = share->File().CachedSize64();
1.1515 + // Large file mode check and error handling is done at client library side.
1.1516 + // Return file size even if it is greater than 2GB - 1.
1.1517 + TPckgC<TInt64> pkSize(size);
1.1518 + aRequest->WriteL(KMsgPtr0, pkSize);
1.1519 + return(KErrNone);
1.1520 + }
1.1521 +
1.1522 +TInt TFsFileSize::Initialise(CFsRequest* aRequest)
1.1523 +//
1.1524 +//
1.1525 +//
1.1526 + {
1.1527 + return(DoInitNoParse(aRequest));
1.1528 + }
1.1529 +
1.1530 +
1.1531 +TInt TFsFileSetSize::DoRequestL(CFsRequest* aRequest)
1.1532 +//
1.1533 +// Set the file size.
1.1534 +//
1.1535 + {
1.1536 + __PRINT(_L("TFsFileSetSize::DoRequestL(CFsRequest* aRequest)"));
1.1537 +
1.1538 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1539 + if ((share->iMode&EFileWrite)==0)
1.1540 + return(KErrAccessDenied);
1.1541 + TInt r=share->CheckMount();
1.1542 + if (r!=KErrNone)
1.1543 + return(r);
1.1544 +
1.1545 + TInt64 size;
1.1546 + if(aRequest->IsDescData(KMsgPtr0))
1.1547 + {
1.1548 + TPckg<TInt64> pkSize(size);
1.1549 + aRequest->ReadL(KMsgPtr0, pkSize);
1.1550 + }
1.1551 + else
1.1552 + {
1.1553 + size = aRequest->Message().Int0();
1.1554 + }
1.1555 +
1.1556 + if(size < 0)
1.1557 + User::Leave(ESizeNegative);
1.1558 +
1.1559 + // Large file mode check
1.1560 + if((!(share->IsFileModeBig())) && ((TUint64)size > KMaxLegacyFileSize))
1.1561 + return (KErrTooBig);
1.1562 +
1.1563 + CFileCB& file=share->File();
1.1564 +
1.1565 + // flush the write cache
1.1566 + CFileCache* fileCache = share->File().FileCache();
1.1567 + if (fileCache && (r = fileCache->FlushDirty(aRequest)) != CFsRequest::EReqActionComplete)
1.1568 + return r;
1.1569 +
1.1570 + if (size==file.Size64())
1.1571 + return(KErrNone);
1.1572 +
1.1573 + TBool fileHasGrown = size > file.Size64();
1.1574 + if (fileHasGrown)
1.1575 + {
1.1576 + r = CheckDiskSpace(size - file.Size64(), aRequest);
1.1577 + if(r != KErrNone)
1.1578 + return r;
1.1579 +
1.1580 + r=file.CheckLock64(share,file.Size64(),size-file.Size64());
1.1581 + }
1.1582 + else
1.1583 + r=file.CheckLock64(share,size,file.Size64()-size);
1.1584 + if (r!=KErrNone)
1.1585 + return(r);
1.1586 + __PRINT1(_L("Owner mount size before SetSize() = %d"),I64LOW(file.Mount().Size()));
1.1587 + TRAP(r,file.SetSizeL(size))
1.1588 + if (r!=KErrNone)
1.1589 + {
1.1590 + // Set size failed
1.1591 + __PRINT1(_L("SetSize() failed = %d"),r);
1.1592 + __PRINT1(_L("Owner mount size now = %d"),I64LOW(file.Mount().Size()));
1.1593 + return(r);
1.1594 + }
1.1595 + file.SetArchiveAttribute();
1.1596 + file.SetSize64(size, EFalse);
1.1597 + file.SetCachedSize64(size);
1.1598 +
1.1599 + if(fileHasGrown)
1.1600 + file.NotifyAsyncReaders(); // Service outstanding async reads if the file has grown
1.1601 +
1.1602 + return(r);
1.1603 + }
1.1604 +
1.1605 +TInt TFsFileSetSize::Initialise(CFsRequest* aRequest)
1.1606 +//
1.1607 +//
1.1608 +//
1.1609 + {
1.1610 + return(DoInitNoParse(aRequest));
1.1611 + }
1.1612 +
1.1613 +
1.1614 +TInt TFsFileAtt::DoRequestL(CFsRequest* aRequest)
1.1615 +//
1.1616 +// Get the file attributes.
1.1617 +//
1.1618 + {
1.1619 +
1.1620 + __PRINT(_L("TFsFileAtt::DoRequestL(CFsRequest* aRequest)"));
1.1621 +
1.1622 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1623 +// TInt att=(TInt)aRequest->FileShare()->File().Att()&KEntryAttMaskSupported;
1.1624 + TInt att=(TInt)share->File().Att(); // DRM: let ROM XIP attribute through
1.1625 + TPtrC8 pA((TUint8*)&att,sizeof(TInt));
1.1626 + aRequest->WriteL(KMsgPtr0,pA);
1.1627 +
1.1628 + return(KErrNone);
1.1629 + }
1.1630 +
1.1631 +TInt TFsFileAtt::Initialise(CFsRequest* aRequest)
1.1632 +//
1.1633 +//
1.1634 +//
1.1635 + {
1.1636 + return(DoInitNoParse(aRequest));
1.1637 + }
1.1638 +
1.1639 +
1.1640 +TInt TFsFileSetAtt::DoRequestL(CFsRequest* aRequest)
1.1641 +//
1.1642 +// Set the file attributes.
1.1643 +//
1.1644 + {
1.1645 + __PRINT(_L("TFsFileSetAtt::DoRequestL(CSessionFs* aSession)"));
1.1646 +
1.1647 + TInt r = CheckDiskSpace(0, aRequest);
1.1648 + if(r != KErrNone)
1.1649 + return r;
1.1650 +
1.1651 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1652 + r=share->CheckMount();
1.1653 + if (r!=KErrNone)
1.1654 + return(r);
1.1655 +
1.1656 + if ((share->iMode&EFileWrite)==EFalse)
1.1657 + return(KErrAccessDenied);
1.1658 +
1.1659 + TUint setAttMask=(TUint)(aRequest->Message().Int0());
1.1660 + TUint clearAttMask=(TUint)aRequest->Message().Int1();
1.1661 + ValidateAtts(share->File().Att(),setAttMask,clearAttMask);
1.1662 +
1.1663 + TRACE5(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryL, EF32TraceUidFileSys, &share->File(), 0, 0, setAttMask,clearAttMask);
1.1664 + TRAP(r,share->File().SetEntryL(TTime(0),setAttMask,clearAttMask))
1.1665 + TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryLRet, EF32TraceUidFileSys, r);
1.1666 +
1.1667 + return(r);
1.1668 + }
1.1669 +
1.1670 +
1.1671 +TInt TFsFileSetAtt::Initialise(CFsRequest* aRequest)
1.1672 +//
1.1673 +// Call GetShareFromHandle to determine asynchronicity ***
1.1674 +//
1.1675 + {
1.1676 + return(DoInitNoParse(aRequest));
1.1677 + }
1.1678 +
1.1679 +
1.1680 +TInt TFsFileModified::DoRequestL(CFsRequest* aRequest)
1.1681 +//
1.1682 +// Get the modified date and time.
1.1683 +//
1.1684 + {
1.1685 + __PRINT(_L("TFsFileModified::DoRequestL(CFsRequest* aRequest)"));
1.1686 +
1.1687 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1688 + TTime mod=share->File().Modified();
1.1689 + TPtrC8 pM((TUint8*)&mod,sizeof(TTime));
1.1690 + aRequest->WriteL(KMsgPtr0,pM);
1.1691 +
1.1692 + return(KErrNone);
1.1693 + }
1.1694 +
1.1695 +
1.1696 +TInt TFsFileModified::Initialise(CFsRequest* aRequest)
1.1697 +//
1.1698 +// Call GetShareFromHandle to determine asynchronicity ***
1.1699 +//
1.1700 + {
1.1701 + return(DoInitNoParse(aRequest));
1.1702 + }
1.1703 +
1.1704 +
1.1705 +TInt TFsFileSetModified::DoRequestL(CFsRequest* aRequest)
1.1706 +//
1.1707 +// Set the modified date and time.
1.1708 +//
1.1709 + {
1.1710 + __PRINT(_L("TFsFileSetModified::DoRequestL(CFsRequest* aRequest)"));
1.1711 +
1.1712 + TInt r = CheckDiskSpace(0, aRequest);
1.1713 + if(r != KErrNone)
1.1714 + return r;
1.1715 +
1.1716 +
1.1717 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1718 + r=share->CheckMount();
1.1719 + if (r!=KErrNone)
1.1720 + return(r);
1.1721 +
1.1722 + if ((share->iMode&EFileWrite)==EFalse)
1.1723 + return(KErrAccessDenied);
1.1724 +
1.1725 + TTime time;
1.1726 + TPtr8 t((TUint8*)&time,sizeof(TTime));
1.1727 + aRequest->ReadL(KMsgPtr0,t);
1.1728 +
1.1729 + TRACE5(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryL, EF32TraceUidFileSys, &share->File(), 0, 0, KEntryAttModified,0);
1.1730 + TRAP(r,share->File().SetEntryL(time,KEntryAttModified,0))
1.1731 + TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryLRet, EF32TraceUidFileSys, r);
1.1732 +
1.1733 + return(r);
1.1734 + }
1.1735 +
1.1736 +
1.1737 +TInt TFsFileSetModified::Initialise(CFsRequest* aRequest)
1.1738 +//
1.1739 +// Call GetShareFromHandle to determine asynchronicity ***
1.1740 +//
1.1741 + {
1.1742 + return(DoInitNoParse(aRequest));
1.1743 + }
1.1744 +
1.1745 +TInt TFsFileSet::DoRequestL(CFsRequest* aRequest)
1.1746 +//
1.1747 +// Set the attributes and the modified date and time.
1.1748 +//
1.1749 + {
1.1750 + __PRINT(_L("TFsFileSet::DoRequestL(CFsRequest* aRequest)"));
1.1751 +
1.1752 + TInt r = CheckDiskSpace(0, aRequest);
1.1753 + if(r != KErrNone)
1.1754 + return r;
1.1755 +
1.1756 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1757 + r=share->CheckMount();
1.1758 + if (r!=KErrNone)
1.1759 + return(r);
1.1760 +
1.1761 + if (share->File().Att()&KEntryAttReadOnly)
1.1762 + return(KErrAccessDenied);
1.1763 +
1.1764 + if ((share->iMode&EFileWrite)==0)
1.1765 + {
1.1766 + if(share->File().Drive().IsWriteProtected())
1.1767 + return(KErrAccessDenied);
1.1768 + }
1.1769 +
1.1770 + TTime time;
1.1771 + TPtr8 t((TUint8*)&time,sizeof(TTime));
1.1772 + aRequest->ReadL(KMsgPtr0,t);
1.1773 + TUint setAttMask=(TUint)(aRequest->Message().Int1()|KEntryAttModified);
1.1774 + TUint clearAttMask=(TUint)aRequest->Message().Int2();
1.1775 + ValidateAtts(share->File().Att(),setAttMask,clearAttMask);// Validate attributes
1.1776 +
1.1777 + TRACE5(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryL, EF32TraceUidFileSys, &share->File(), 0, 0, setAttMask,clearAttMask);
1.1778 + TRAP(r,share->File().SetEntryL(time,setAttMask,clearAttMask))
1.1779 + TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetEntryLRet, EF32TraceUidFileSys, r);
1.1780 +
1.1781 + return(r);
1.1782 + }
1.1783 +
1.1784 +TInt TFsFileSet::Initialise(CFsRequest* aRequest)
1.1785 +//
1.1786 +//
1.1787 +//
1.1788 + {
1.1789 + return(DoInitNoParse(aRequest));
1.1790 + }
1.1791 +
1.1792 +
1.1793 +TInt TFsFileChangeMode::DoRequestL(CFsRequest* aRequest)
1.1794 +//
1.1795 +// The access to a file may be changed from share exclusive to share readers only or vice versa.
1.1796 +// KErrAccessDenied is returned if the file has multiple readers.
1.1797 +//
1.1798 + {
1.1799 + __PRINT(_L("TFsFileChangeMode::DoRequestL(CFsRequest* aRequest)"));
1.1800 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1801 + TInt r=share->CheckMount();
1.1802 + if (r!=KErrNone)
1.1803 + return(r);
1.1804 +
1.1805 + const TFileMode currentMode = (TFileMode)share->iMode;
1.1806 + const TFileMode newMode = (TFileMode)aRequest->Message().Int0();
1.1807 +
1.1808 + // check argument
1.1809 + // (only EFileShareExclusive and EFileShareReadersOnly are allowed)
1.1810 + if((newMode & ~EFileShareReadersOnly) != 0)
1.1811 + return KErrArgument;
1.1812 +
1.1813 + // check if the file is in EFileShareAny mode
1.1814 + if( (currentMode & EFileShareAny) ||
1.1815 + // or the file has been opened for writing in EFileShareExclusive mode,
1.1816 + // and an attempt is made to change the access mode to EFileShareReadersOnly
1.1817 + ((currentMode & EFileWrite) &&
1.1818 + (currentMode & KFileShareMask) == EFileShareExclusive &&
1.1819 + newMode == EFileShareReadersOnly) )
1.1820 + return KErrAccessDenied;
1.1821 +
1.1822 + // check if an attempt is made to change the share mode to EFileShareExclusive
1.1823 + // while the file has multiple readers
1.1824 + if (newMode == EFileShareExclusive && (currentMode & KFileShareMask) != EFileShareExclusive)
1.1825 + {
1.1826 + // Check no other CFileCB is reading the file.
1.1827 + FileShares->Lock();
1.1828 + TInt count=FileShares->Count();
1.1829 + TBool found=EFalse;
1.1830 + while(count--)
1.1831 + {
1.1832 + CFileShare* fileShare=(CFileShare*)(*FileShares)[count];
1.1833 + if (&fileShare->File()==&share->File())
1.1834 + {
1.1835 + if (found)
1.1836 + {
1.1837 + FileShares->Unlock();
1.1838 + return(KErrAccessDenied);
1.1839 + }
1.1840 + found=ETrue;
1.1841 + }
1.1842 + }
1.1843 + FileShares->Unlock();
1.1844 + }
1.1845 + share->iMode&=~KFileShareMask;
1.1846 + share->iMode|=newMode;
1.1847 + share->File().SetShare(newMode);
1.1848 + return(KErrNone);
1.1849 + }
1.1850 +
1.1851 +
1.1852 +TInt TFsFileChangeMode::Initialise(CFsRequest* aRequest)
1.1853 +//
1.1854 +//
1.1855 +//
1.1856 + {
1.1857 + TInt r = DoInitNoParse(aRequest);
1.1858 + if(r != KErrNone)
1.1859 + return r;
1.1860 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1861 + if(CompareResource(share->File().FileName().Mid(2)) )
1.1862 + {
1.1863 + if(!KCapFsFileChangeMode.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("File Change Mode")))
1.1864 + return KErrPermissionDenied;
1.1865 + }
1.1866 + return KErrNone;
1.1867 + }
1.1868 +
1.1869 +
1.1870 +TInt TFsFileRename::DoRequestL(CFsRequest* aRequest)
1.1871 +//
1.1872 +// Rename the file if it was openned EFileShareExclusive
1.1873 +//
1.1874 + {
1.1875 + __PRINT(_L("TFsFileRename::DoRequestL(CFsRequest* aRequest)"));
1.1876 +
1.1877 + TInt r = CheckDiskSpace(0, aRequest);
1.1878 + if(r != KErrNone)
1.1879 + return r;
1.1880 +
1.1881 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1882 + r=share->CheckMount();
1.1883 + if (r!=KErrNone)
1.1884 + return(r);
1.1885 +
1.1886 + TInt currentMode=(share->iMode&KFileShareMask);
1.1887 + if ((currentMode&EFileShareAny) || (currentMode&EFileShareReadersOnly))
1.1888 + return(KErrAccessDenied); // File must be EFileShareExclusive
1.1889 +
1.1890 + if ((share->iMode&EFileWrite)==0)
1.1891 + return(KErrAccessDenied); // File must have write permission
1.1892 +
1.1893 + TPtrC filePath = aRequest->Dest().FullName().Mid(2);
1.1894 + CFileCB& file = share->File();
1.1895 +
1.1896 + TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECFileCBRenameL, EF32TraceUidFileSys,
1.1897 + (TUint) &file, filePath);
1.1898 + TRAP(r,file.RenameL(filePath));
1.1899 + TRACERETMULT1(UTF::EBorder, UTraceModuleFileSys::ECFileCBRenameLRet, EF32TraceUidFileSys, r);
1.1900 +
1.1901 + // Re-write the file's folded name & re-calculate the hash
1.1902 + if (r == KErrNone)
1.1903 + {
1.1904 + TFileName filePathF;
1.1905 + filePathF.CopyF(filePath);
1.1906 + TRAP(r, AllocBufferL(file.iFileNameF, filePathF));
1.1907 + file.iNameHash=CalcNameHash(*file.iFileNameF);
1.1908 + }
1.1909 +
1.1910 + return(r);
1.1911 + }
1.1912 +
1.1913 +TInt TFsFileRename::Initialise(CFsRequest* aRequest)
1.1914 +//
1.1915 +//
1.1916 +//
1.1917 + {
1.1918 + TInt r=DoInitialise(aRequest);
1.1919 + if(r!=KErrNone)
1.1920 + return(r);
1.1921 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1922 + TFileName newName;
1.1923 + TRAP(r,aRequest->ReadL(KMsgPtr0,newName));
1.1924 + if(r!=KErrNone)
1.1925 + return(r);
1.1926 + TDriveUnit currentDrive(share->File().Mount().Drive().DriveNumber());
1.1927 + TDriveName driveName=currentDrive.Name();
1.1928 + r=aRequest->Dest().Set(newName,&share->File().FileName(),&driveName);
1.1929 + if (r!=KErrNone)
1.1930 + return(r);
1.1931 + if (aRequest->Dest().IsWild())
1.1932 + return(KErrBadName);
1.1933 + TInt driveNo;
1.1934 + if ((r=RFs::CharToDrive(aRequest->Dest().Drive()[0],driveNo))!=KErrNone)
1.1935 + return(r);
1.1936 + TDrive& drive=TheDrives[driveNo];
1.1937 + if(drive.IsSubsted())
1.1938 + {
1.1939 + if ((drive.Subst().Length()+aRequest->Dest().FullName().Length())>(KMaxFileName+3))
1.1940 + return(KErrBadName);
1.1941 + TFileName n=drive.Subst();
1.1942 + n+=aRequest->Dest().FullName().Mid(3);
1.1943 + r=aRequest->Dest().Set(n,NULL,NULL);
1.1944 + if(r!=KErrNone)
1.1945 + return(r);
1.1946 + }
1.1947 +
1.1948 + TDriveUnit newDrive(aRequest->Dest().Drive());
1.1949 + if (newDrive!=currentDrive)
1.1950 + return(KErrBadName);
1.1951 + if (IsIllegalFullName(aRequest->Dest().FullName().Mid(2)))
1.1952 + return(KErrBadName);
1.1953 + r=PathCheck(aRequest,aRequest->Dest().FullName().Mid(2),&KCapFsSysFileRename,&KCapFsPriFileRename,&KCapFsROFileRename, __PLATSEC_DIAGNOSTIC_STRING("File Rename"));
1.1954 + return(r);
1.1955 + }
1.1956 +
1.1957 +
1.1958 +TInt TFsFileDrive::DoRequestL(CFsRequest* aRequest)
1.1959 +//
1.1960 +// Get the drive info for the file.
1.1961 +//
1.1962 + {
1.1963 + __PRINT(_L("TFsFileDrive::DoRequestL(CFsRequest* aRequest)"));
1.1964 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.1965 + TDrive *dr = &share->File().Drive();
1.1966 +
1.1967 + TPckgBuf<TInt> pkiF(dr->DriveNumber()); // copy drive number to user
1.1968 + aRequest->WriteL(KMsgPtr0, pkiF);
1.1969 +
1.1970 + TDriveInfo di; // copy drive info to user
1.1971 + dr->DriveInfo(di);
1.1972 + TPckgC<TDriveInfo> pkdiF(di);
1.1973 + aRequest->WriteL(KMsgPtr1, pkdiF);
1.1974 +
1.1975 + return(KErrNone);
1.1976 + }
1.1977 +
1.1978 +
1.1979 +TInt TFsFileDrive::Initialise(CFsRequest* aRequest)
1.1980 +//
1.1981 +//
1.1982 +//
1.1983 + {
1.1984 + return(DoInitNoParse(aRequest));
1.1985 + }
1.1986 +
1.1987 +
1.1988 +TInt TFsFileDuplicate::DoRequestL(CFsRequest* aRequest)
1.1989 +//
1.1990 +// Duplicate the received file handle ready for transfer to another process.
1.1991 +// The new file handle is written back to the client in a a mangled form to prevent
1.1992 +// it from being used. Calling TFsFileAdopt will de-mangle the handle.
1.1993 +//
1.1994 + {
1.1995 + CFileShare* pS = (CFileShare*)aRequest->ScratchValue();
1.1996 +
1.1997 + // get the file control block from the client's file share
1.1998 + CFileCB& fileCB = pS->File();
1.1999 +
1.2000 + // Create a new file share and initialize it with the
1.2001 + // client file share's file control block, position & mode
1.2002 +
1.2003 + CFileShare* pNewFileShare = new CFileShare(&fileCB);
1.2004 + if (pNewFileShare == NULL)
1.2005 + return KErrNoMemory;
1.2006 +
1.2007 + // We need to call CFileCB::PromoteShare immediately after the CFileShare
1.2008 + // instance is created since the destructor calls CFileCB::DemoteShare()
1.2009 + // which checks the share count is non-zero
1.2010 + pNewFileShare->iMode = pS->iMode;
1.2011 + fileCB.PromoteShare(pNewFileShare);
1.2012 +
1.2013 +
1.2014 + TInt r = fileCB.Open(); // increment the ref count
1.2015 +
1.2016 + if (r == KErrNone)
1.2017 + TRAP(r, pNewFileShare->InitL());
1.2018 + __e32_atomic_store_ord64(&pNewFileShare->iPos, pS->iPos);
1.2019 +
1.2020 + // Add new file share to the global file share container
1.2021 + if (r == KErrNone)
1.2022 + TRAP(r, FileShares->AddL(pNewFileShare,ETrue));
1.2023 +
1.2024 + // Add new file share to list owned by this session
1.2025 + TInt newHandle;
1.2026 + if (r == KErrNone)
1.2027 + TRAP(r,newHandle = aRequest->Session()->Handles().AddL(pNewFileShare,ETrue));
1.2028 +
1.2029 + if (r!=KErrNone)
1.2030 + {
1.2031 + pNewFileShare->Close();
1.2032 + return r;
1.2033 + }
1.2034 +
1.2035 + newHandle^= KSubSessionMangleBit;
1.2036 +
1.2037 + TPtrC8 pH((TUint8*)&newHandle, sizeof(TInt));
1.2038 + aRequest->WriteL(KMsgPtr3, pH);
1.2039 + aRequest->Session()->IncResourceCount();
1.2040 + return(KErrNone);
1.2041 + }
1.2042 +
1.2043 +TInt TFsFileDuplicate::Initialise(CFsRequest* aRequest)
1.2044 + {
1.2045 + TInt handle = aRequest->Message().Int0();
1.2046 + CFileShare* share = GetShareFromHandle(aRequest->Session(), handle);
1.2047 +
1.2048 + // If the handle is invalid, either panic (CFsMessageRequest::Dispatch() will
1.2049 + // panic if we return KErrBadHandle) or complete the request with KErrArgument.
1.2050 + // The latter case is the behaviour for the (deprecated) RFile::Adopt() to
1.2051 + // prevent a server from panicing if the passed file handle is invalid.
1.2052 + if(!share)
1.2053 + return aRequest->Message().Int1()?KErrBadHandle:KErrArgument;
1.2054 +
1.2055 + aRequest->SetDrive(&share->File().Drive());
1.2056 + aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) );
1.2057 + return(KErrNone);
1.2058 + }
1.2059 +
1.2060 +
1.2061 +
1.2062 +TInt TFsFileAdopt::DoRequestL(CFsRequest* aRequest)
1.2063 +//
1.2064 +// Adopt the passed file handle. This assumes that the handle has already been
1.2065 +// duplicated by calling TFsFileDuplicate and is therefore mangled.
1.2066 +//
1.2067 + {
1.2068 + if (((CFileShare*)aRequest->ScratchValue()) == NULL)
1.2069 + return KErrBadHandle;
1.2070 +
1.2071 + TInt adoptType = aRequest->Message().Int1();
1.2072 + // EFileBigFile mode check
1.2073 + switch(adoptType)
1.2074 + {
1.2075 + case KFileAdopt32:
1.2076 + // Request is from RFile::Adopt or RFile::AdoptFromXXX: Force NO EFileBigFile
1.2077 + ((CFileShare*)aRequest->ScratchValue())->iMode &= ~EFileBigFile;
1.2078 + break;
1.2079 + case KFileAdopt64:
1.2080 + // Request is from RFile64::AdoptFromXXX: Force EFileBigFile
1.2081 + ((CFileShare*)aRequest->ScratchValue())->iMode |= EFileBigFile;
1.2082 + break;
1.2083 + case KFileDuplicate:
1.2084 + // Request is from RFile::Duplucate
1.2085 + // adopt original file mode - do nothing
1.2086 + break;
1.2087 + //default:
1.2088 + // Do nothing
1.2089 + }
1.2090 +
1.2091 + // De-mangle the existing sub-session handle and return it to the client
1.2092 + TInt newHandle = aRequest->Message().Int0() ^ KSubSessionMangleBit;
1.2093 +
1.2094 + TPtrC8 pH((TUint8*)&newHandle,sizeof(TInt));
1.2095 + aRequest->WriteL(KMsgPtr3,pH);
1.2096 + return(KErrNone);
1.2097 + }
1.2098 +
1.2099 +TInt TFsFileAdopt::Initialise(CFsRequest* aRequest)
1.2100 + {
1.2101 + TInt handle = aRequest->Message().Int0() ^KSubSessionMangleBit;
1.2102 +
1.2103 + CFileShare* share = GetShareFromHandle(aRequest->Session(), handle);
1.2104 + // Normally returning KErrBadHandle will result in a panic, but when a server calls
1.2105 + // RFile::AdoptXXX() and it's client has given it a bad handle then it's not a good
1.2106 + // idea to panic the server. So we return KErrNone here and allow
1.2107 + // TFsFileAdopt::DoRequestL() to return KErrBadHandle
1.2108 + if (share)
1.2109 + aRequest->SetDrive(&share->File().Drive());
1.2110 +
1.2111 + aRequest->SetScratchValue64( MAKE_TINT64(ETrue, (TUint) share) );
1.2112 + return(KErrNone);
1.2113 + }
1.2114 +
1.2115 +
1.2116 +TInt TFsFileName::DoRequestL(CFsRequest* aRequest)
1.2117 +//
1.2118 +// Get the name of a file.
1.2119 +// i.e. including the name & extension but excluding the drive and path
1.2120 +//
1.2121 + {
1.2122 + CFileShare* share = (CFileShare*)aRequest->ScratchValue();
1.2123 +
1.2124 + // Search backwards until a backslash is found
1.2125 + // This should always succeed as this is a full pathname
1.2126 + TPtrC name(share->File().FileName());
1.2127 + TInt offset = name.LocateReverse('\\');
1.2128 + aRequest->WriteL(KMsgPtr0, name.Mid(offset+1));
1.2129 +
1.2130 + return(KErrNone);
1.2131 + }
1.2132 +
1.2133 +TInt TFsFileName::Initialise(CFsRequest* aRequest)
1.2134 +//
1.2135 +// Get the full name of a file, including path and drive
1.2136 +//
1.2137 +//
1.2138 + {
1.2139 + return InitialiseScratchToShare(aRequest);
1.2140 + }
1.2141 +
1.2142 +
1.2143 +TInt TFsFileFullName::DoRequestL(CFsRequest* aRequest)
1.2144 +//
1.2145 +// Get the full name of a file, including path and drive
1.2146 +//
1.2147 + {
1.2148 + CFileShare* share = (CFileShare*)aRequest->ScratchValue();
1.2149 +
1.2150 + // Write the drive letter and ':'
1.2151 + TBuf<2> driveBuf(KDrivePath);
1.2152 + driveBuf[0]=TText('A' + share->File().Drive().DriveNumber());
1.2153 + aRequest->WriteL(KMsgPtr0, driveBuf);
1.2154 +
1.2155 + // Write the file and path including leading '\'
1.2156 + TPtrC name(share->File().FileName());
1.2157 + aRequest->WriteL(KMsgPtr0, name, 2);
1.2158 +
1.2159 + return(KErrNone);
1.2160 + }
1.2161 +
1.2162 +
1.2163 +TInt TFsFileFullName::Initialise(CFsRequest* aRequest)
1.2164 +//
1.2165 +//
1.2166 +//
1.2167 + {
1.2168 + return InitialiseScratchToShare(aRequest);
1.2169 + }
1.2170 +
1.2171 +TInt TFsGetMediaSerialNumber::DoRequestL(CFsRequest* aRequest)
1.2172 +//
1.2173 +// Acquire capability from media and return serial number if supported.
1.2174 +//
1.2175 + {
1.2176 + // Get request parameters
1.2177 + const TInt drvNum = aRequest->Message().Int1();
1.2178 +
1.2179 + // Get media capability
1.2180 + TLocalDriveCapsV5Buf capsBuf;
1.2181 +
1.2182 + TInt r = KErrNone;
1.2183 +
1.2184 + // is the drive local?
1.2185 + if (!IsProxyDrive(drvNum))
1.2186 + {
1.2187 + // if not valid local drive, use default values in localDriveCaps
1.2188 + // if valid local drive and not locked, use TBusLocalDrive::Caps() values
1.2189 + // if valid drive and locked, hard-code attributes
1.2190 + r = GetLocalDrive(drvNum).Caps(capsBuf);
1.2191 + }
1.2192 + else // this need to be made a bit nicer
1.2193 + {
1.2194 + CExtProxyDrive* pD = GetProxyDrive(drvNum);
1.2195 + if(pD)
1.2196 + r = pD->Caps(capsBuf);
1.2197 + else
1.2198 + r = KErrNotReady;
1.2199 + }
1.2200 +
1.2201 + if (r != KErrNone)
1.2202 + return r;
1.2203 +
1.2204 + TLocalDriveCapsV5& capsV5 = capsBuf();
1.2205 +
1.2206 + // Return serial number if supported
1.2207 + if (capsV5.iSerialNumLength == 0)
1.2208 + return KErrNotSupported;
1.2209 +
1.2210 + TPtrC8 snPtr(capsV5.iSerialNum, capsV5.iSerialNumLength);
1.2211 + aRequest->WriteL(KMsgPtr0, snPtr);
1.2212 +
1.2213 + return KErrNone;
1.2214 + }
1.2215 +
1.2216 +TInt TFsGetMediaSerialNumber::Initialise(CFsRequest* aRequest)
1.2217 +//
1.2218 +// Validate drive number and its attributes passed in a request object.
1.2219 +//
1.2220 + {
1.2221 + const TInt drvNum = aRequest->Message().Int1();
1.2222 +
1.2223 + TInt nRes = ValidateDrive(drvNum, aRequest);
1.2224 + if(nRes != KErrNone)
1.2225 + return KErrBadName; //-- incorrect drive number
1.2226 +
1.2227 + if(aRequest->Drive()->IsSubsted())
1.2228 + return KErrNotSupported; //-- the drive is substed, this operation doesn't make a sense
1.2229 +
1.2230 + if(!IsValidLocalDriveMapping(drvNum))
1.2231 + return KErrNotReady;
1.2232 +
1.2233 + return KErrNone;
1.2234 + }
1.2235 +
1.2236 +TInt TFsBlockMap::Initialise(CFsRequest* aRequest)
1.2237 + {
1.2238 + TInt r = DoInitNoParse(aRequest);
1.2239 + if(r!=KErrNone)
1.2240 + return r;
1.2241 +
1.2242 + TInt blockMapUsage = aRequest->Message().Int2();
1.2243 + if ( blockMapUsage == EBlockMapUsagePaging )
1.2244 + {
1.2245 + CFileShare* share = (CFileShare*) aRequest->ScratchValue();
1.2246 + CFileCB& file = share->File();
1.2247 +
1.2248 + // To determine whether the drive where this file resides is pageable, we need to locate
1.2249 + // the specific TBusLocalDrive object first; querying the drive attributes directly from the
1.2250 + // (composite) file system is no good as this API treats all slave file systems as "ROM & not pageable.
1.2251 + TBusLocalDrive* localDrive;
1.2252 + TInt r = file.LocalDrive(localDrive);
1.2253 + if (r != KErrNone)
1.2254 + return r;
1.2255 + TLocalDriveCapsV4Buf caps;
1.2256 + r = localDrive->Caps(caps);
1.2257 + if (r != KErrNone)
1.2258 + return r;
1.2259 + __PRINT4(_L("TFsBlockMap::Initialise, drive %d file %S iMediaAtt %08X iDriveAtt %08X\n"), file.DriveNumber(), &file.FileName(), caps().iMediaAtt, caps().iDriveAtt);
1.2260 + if ( !(caps().iDriveAtt & KDriveAttPageable))
1.2261 + return KErrNotSupported;
1.2262 + }
1.2263 +
1.2264 + return KErrNone;
1.2265 + }
1.2266 +
1.2267 +TInt TFsBlockMap::DoRequestL(CFsRequest* aRequest)
1.2268 + {
1.2269 + __PRINT(_L("TFsBlockMap::DoRequestL(CFsRequest* aRequest)"));
1.2270 + __PRINT1(_L("aRequest->Session() = 0x%x"), aRequest->Session());
1.2271 +
1.2272 + CFileShare* share = (CFileShare*) aRequest->ScratchValue();
1.2273 +
1.2274 + TInt r = share->CheckMount();
1.2275 +
1.2276 + __PRINT1(_L("share->CheckMount() returned - %d"), r);
1.2277 + if ( r != KErrNone )
1.2278 + return(r);
1.2279 +
1.2280 + SBlockMapInfo reqInfo;
1.2281 + SBlockMapArgs args;
1.2282 + TPckg<SBlockMapArgs> pkArgs(args);
1.2283 + aRequest->ReadL(KMsgPtr1, pkArgs);
1.2284 +
1.2285 + CFileCB& file = share->File();
1.2286 + TInt64& reqStartPos = args.iStartPos;
1.2287 + TInt64 reqEndPos = args.iEndPos;
1.2288 +
1.2289 + if ( ( reqStartPos > file.Size64() ) || ( reqStartPos < 0 ) )
1.2290 + return KErrArgument;
1.2291 +
1.2292 + const TInt64 KReadToEOF = -1;
1.2293 + if ( reqEndPos != KReadToEOF )
1.2294 + {
1.2295 + if ( !( reqEndPos >= reqStartPos ) )
1.2296 + return KErrArgument;
1.2297 + }
1.2298 + else
1.2299 + reqEndPos = file.Size64();
1.2300 +
1.2301 + // If the requested start position is equal to the size of the file
1.2302 + // then we read no data and return an empty BlockMap.
1.2303 + if ( reqStartPos == file.Size64() || reqEndPos == 0 || reqEndPos == reqStartPos )
1.2304 + {
1.2305 + TPckg<SBlockMapInfo> pkInfo(reqInfo);
1.2306 + TRAP(r,aRequest->WriteL(KMsgPtr0,pkInfo) );
1.2307 + if ( r == KErrNone )
1.2308 + return(KErrArgument);
1.2309 + else
1.2310 + return(r);
1.2311 + }
1.2312 + r = share->File().BlockMap(reqInfo, reqStartPos, reqEndPos);
1.2313 + TPckg<SBlockMapInfo> pkInfo(reqInfo);
1.2314 + aRequest->WriteL(KMsgPtr0, pkInfo);
1.2315 + aRequest->WriteL(KMsgPtr1, pkArgs);
1.2316 +
1.2317 + return(r);
1.2318 + }
1.2319 +
1.2320 +#pragma warning( disable : 4705 ) // statement has no effect
1.2321 +/**
1.2322 +Default constructor
1.2323 +*/
1.2324 +EXPORT_C CFileCB::CFileCB()
1.2325 + {
1.2326 + }
1.2327 +#pragma warning( default : 4705 )
1.2328 +
1.2329 +
1.2330 +
1.2331 +
1.2332 +/**
1.2333 +Destructor.
1.2334 +
1.2335 +Frees resources before destruction of the object.
1.2336 +*/
1.2337 +EXPORT_C CFileCB::~CFileCB()
1.2338 + {
1.2339 + // NB Must be careful to close the file cache BEFORE deleting iFileNameF
1.2340 + // as CFileCache may steal it (!)
1.2341 + if (FileCache())
1.2342 + FileCache()->Close();
1.2343 + if (iBody && iBody->iDeleteOnClose)
1.2344 + {
1.2345 + TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteL, EF32TraceUidFileSys, DriveNumber(), FileName());
1.2346 + TInt r;
1.2347 + TRAP(r, iMount->DeleteL(FileName()));
1.2348 + TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteLRet, EF32TraceUidFileSys, r);
1.2349 + }
1.2350 +
1.2351 + if(iMount)
1.2352 + iMount->Close();
1.2353 + if (iMountLink.iNext!=NULL)
1.2354 + {
1.2355 + iMountLink.Deque();
1.2356 + }
1.2357 + delete iFileName;
1.2358 + delete iFileNameF;
1.2359 + if (iFileLocks)
1.2360 + {
1.2361 + iFileLocks->Close();
1.2362 + delete iFileLocks;
1.2363 + }
1.2364 +
1.2365 + delete iBody;
1.2366 + }
1.2367 +
1.2368 +/**
1.2369 + Initialise CFileCB object.
1.2370 + @internalTechnology
1.2371 +
1.2372 + @param aDrive
1.2373 + @param aCreatedDrive
1.2374 + @param aName file name descriptor
1.2375 +*/
1.2376 +EXPORT_C void CFileCB::InitL(TDrive* aDrive, TDrive* aCreatedDrive, HBufC* aName)
1.2377 + {
1.2378 + // Take ownership of heap-allocated objects aName and aLock before attempting any memory allocation
1.2379 + // to avoid leaking memory
1.2380 + iFileName = aName;
1.2381 +
1.2382 + DoInitL(aDrive->DriveNumber());
1.2383 + iDrive=aDrive;
1.2384 + iCreatedDrive=aCreatedDrive;
1.2385 + TFileName tempName;
1.2386 + tempName.CopyF(*aName);
1.2387 + iFileNameF=tempName.AllocL();
1.2388 + iNameHash=CalcNameHash(*iFileNameF);
1.2389 +
1.2390 +
1.2391 +
1.2392 + // see whether the file system supports the CFileCB extended API
1.2393 + MExtendedFileInterface* extendedFileInterface = NULL;
1.2394 + GetInterfaceTraced(CFileCB::EExtendedFileInterface, (void*&) extendedFileInterface, NULL);
1.2395 + iBody = new(ELeave)CFileBody(this, extendedFileInterface);
1.2396 +
1.2397 + iMount=&iDrive->CurrentMount();
1.2398 + iBody->InitL();
1.2399 + User::LeaveIfError(iMount->Open());
1.2400 +
1.2401 + //-- create file locks array
1.2402 + ASSERT(!iFileLocks);
1.2403 + iFileLocks = new(ELeave) TFileLocksArray(KFileShareLockGranularity, _FOFF(TFileShareLock, iPosLow));
1.2404 +
1.2405 + }
1.2406 +
1.2407 +
1.2408 +TInt CFileCB::FindLock(TInt aPosLow,TInt aPosHigh)
1.2409 + {
1.2410 + return FindLock64(aPosLow, aPosHigh);
1.2411 + }
1.2412 +
1.2413 +TInt CFileCB::AddLock(CFileShare* aFileShare,TInt aPos,TInt aLength)
1.2414 + {
1.2415 + return AddLock64(aFileShare, aPos, aLength);
1.2416 + }
1.2417 +
1.2418 +TInt CFileCB::RemoveLock(CFileShare* aFileShare,TInt aPos,TInt aLength)
1.2419 + {
1.2420 + return RemoveLock64(aFileShare, aPos, aLength);
1.2421 + }
1.2422 +
1.2423 +TInt CFileCB::CheckLock(CFileShare* aFileShare,TInt aPos,TInt aLength)
1.2424 + {
1.2425 + return CheckLock64(aFileShare, aPos, aLength);
1.2426 + }
1.2427 +
1.2428 +/**
1.2429 + Remove any locks held by aFileShare.
1.2430 +*/
1.2431 +void CFileCB::RemoveLocks(CFileShare* aFileShare)
1.2432 + {
1.2433 +
1.2434 + TInt i=0;
1.2435 + while (i<FileLocks().Count())
1.2436 + {
1.2437 + if (FileLocks()[i].MatchOwner(aFileShare))
1.2438 + FileLocks().Remove(i);
1.2439 + else
1.2440 + i++;
1.2441 + }
1.2442 + }
1.2443 +
1.2444 +
1.2445 +void CFileCB::PromoteShare(CFileShare* aShare)
1.2446 +//
1.2447 +// Manages share promotion after the share has been added to the FilsShares container.
1.2448 +//
1.2449 +// - Assumes the share has already been validated using ValidateShare()
1.2450 +//
1.2451 +// - The count of promoted shares (ie - non-EFileShareReadersOrWriters) is incremented
1.2452 +// to allow the share mode to be demoted when the last promoted share is closed.
1.2453 +//
1.2454 + {
1.2455 + TShare reqShare = (TShare)(aShare->iMode & KFileShareMask);
1.2456 + if(reqShare != EFileShareReadersOrWriters)
1.2457 + {
1.2458 + iBody->iPromotedShares++;
1.2459 + iShare = reqShare;
1.2460 + }
1.2461 + }
1.2462 +
1.2463 +
1.2464 +void CFileCB::DemoteShare(CFileShare* aShare)
1.2465 +//
1.2466 +// Manages share demotion after the share has been removed from the FileShares container.
1.2467 +//
1.2468 +// - If the share being removed is not EFileShareReadersOrWriters, then the current
1.2469 +// share mode may require demotion back to EFileShareReadersOrWriters.
1.2470 +//
1.2471 +// - This is determined by the iPromotedShares count, incremented in PromoteShare()
1.2472 +//
1.2473 + {
1.2474 + if((aShare->iMode & KFileShareMask) != EFileShareReadersOrWriters)
1.2475 + {
1.2476 + if(--iBody->iPromotedShares == 0)
1.2477 + {
1.2478 + // Don't worry if the file has never been opened as EFileShareReadersOrWriters
1.2479 + // - in this case the CFileCB object is about to be closed anyway.
1.2480 + iShare = EFileShareReadersOrWriters;
1.2481 + }
1.2482 + }
1.2483 + __ASSERT_DEBUG(iBody->iPromotedShares>=0,Fault(EFileShareBadPromoteCount));
1.2484 + }
1.2485 +
1.2486 +
1.2487 +RArray<TAsyncReadRequest>& CFileCB::AsyncReadRequests()
1.2488 +//
1.2489 +// Gets a reference to the pending asynchronous read requests for this file.
1.2490 +//
1.2491 +// - The request is completed when all data is available or the request is cancelled.
1.2492 +//
1.2493 + {
1.2494 + return(*iBody->iAsyncReadRequests);
1.2495 + }
1.2496 +
1.2497 +
1.2498 +TInt CFileCB::AddAsyncReadRequest(CFileShare* aShareP, TInt64 aPos, TInt aLen, CFsRequest* aRequestP)
1.2499 +//
1.2500 +// Adds a pending asynchronous read request to the list.
1.2501 +//
1.2502 +// - The request is completed when all data is available or the request is cancelled.
1.2503 +//
1.2504 + {
1.2505 +
1.2506 + __ASSERT_ALWAYS(aRequestP->Operation()->Function() == EFsFileRead, Fault(EBaseRequestMessage));
1.2507 +
1.2508 + TAsyncReadRequest req(aPos + aLen, aShareP, aRequestP);
1.2509 + TInt err = AsyncReadRequests().InsertInSignedKeyOrderAllowRepeats(req);
1.2510 + if(err != KErrNone)
1.2511 + return err;
1.2512 +
1.2513 + aRequestP->SetCompleted(EFalse);
1.2514 + return KErrNone;
1.2515 + }
1.2516 +
1.2517 +
1.2518 +TInt CFileCB::CancelAsyncReadRequest(CFileShare* aShareP, TRequestStatus* aStatusP)
1.2519 +//
1.2520 +// Cancels (and completes) an outstanding read request for the specified share.
1.2521 +//
1.2522 +// - aStatusP == NULL cancels all outstanding read requests.
1.2523 +//
1.2524 + {
1.2525 +
1.2526 + TInt i=0;
1.2527 + Drive().Lock();
1.2528 + while (i < AsyncReadRequests().Count())
1.2529 + {
1.2530 + TAsyncReadRequest& req = AsyncReadRequests()[i];
1.2531 + if(req.CompleteIfMatching(aShareP, aStatusP, KErrCancel))
1.2532 + {
1.2533 + iBody->iAsyncReadRequests->Remove(i);
1.2534 + if(aStatusP != NULL)
1.2535 + {
1.2536 + Drive().UnLock();
1.2537 + return KErrNone;
1.2538 + }
1.2539 + }
1.2540 + else
1.2541 + {
1.2542 + i++;
1.2543 + }
1.2544 + }
1.2545 +
1.2546 + Drive().UnLock();
1.2547 + return KErrNone;
1.2548 + }
1.2549 +
1.2550 +
1.2551 +void CFileCB::NotifyAsyncReaders()
1.2552 +//
1.2553 +// Determine if any outstanding read requests require completion.
1.2554 +//
1.2555 +// - Called whenever the file size changes (due to a write operation or SetSize)
1.2556 +//
1.2557 +// - Any outstanding read requests are re-issued (rather then completed in the
1.2558 +// context of the current operation so not to affect performance of the writer).
1.2559 +//
1.2560 +// - Should the file size shrink before the request is serviced, the request will
1.2561 +// be added back onto the queue.
1.2562 +//
1.2563 +// - A future optimisation may issue the request as data becomes available (which
1.2564 +// would minimise the final latency between writer and reader) but the current
1.2565 +// implementation reads all requested data in one operation.
1.2566 +//
1.2567 + {
1.2568 + Drive().Lock();
1.2569 +
1.2570 + SetNotifyAsyncReadersPending(EFalse);
1.2571 +
1.2572 + while(AsyncReadRequests().Count())
1.2573 + {
1.2574 + TAsyncReadRequest& req = AsyncReadRequests()[0];
1.2575 + if(req.iEndPos > CachedSize64())
1.2576 + break;
1.2577 +
1.2578 + // Make a copy and then remove it from the queue before releasing the lock -
1.2579 + // because the file server thread could append to the RArray and this might
1.2580 + // cause a re-allocation which would move the whole array (!)
1.2581 + TAsyncReadRequest reqCopy = req;
1.2582 + AsyncReadRequests().Remove(0);
1.2583 + Drive().UnLock();
1.2584 +
1.2585 + // allocate a new request, push a TMsgOperation onto the request's stack (duplicating
1.2586 + // the functionality of TFsFileRead::Initialise()) & dispatch the request
1.2587 + CFsClientMessageRequest* pRequest = NULL;
1.2588 + const TOperation& oP = OperationArray[EFsFileRead];
1.2589 + TInt r = RequestAllocator::GetMessageRequest(oP, reqCopy.iMessage, pRequest);
1.2590 + if (r != KErrNone)
1.2591 + {
1.2592 + reqCopy.iMessage.Complete(r); // complete the client's message with an error
1.2593 + continue;
1.2594 + }
1.2595 + pRequest->Set(reqCopy.iMessage, oP, reqCopy.iSessionP);
1.2596 +
1.2597 + r = DoInitNoParse(pRequest);
1.2598 + if (r != KErrNone)
1.2599 + {
1.2600 + pRequest->Complete(r); // complete the client's message with an error
1.2601 + continue;
1.2602 + }
1.2603 +
1.2604 + r = pRequest->PushOperation(TFsFileRead::Complete);
1.2605 + if (r != KErrNone)
1.2606 + {
1.2607 + pRequest->Complete(r); // complete the client's message with an error
1.2608 + continue;
1.2609 + }
1.2610 +
1.2611 + pRequest->CurrentOperation().Set(
1.2612 + reqCopy.iEndPos - pRequest->Message().Int1(),
1.2613 + pRequest->Message().Int1(),
1.2614 + (TDes8*) pRequest->Message().Ptr0());
1.2615 +
1.2616 + // don't call Initialise()
1.2617 + pRequest->SetState(CFsRequest::EReqStatePostInitialise);
1.2618 +
1.2619 + pRequest->Dispatch();
1.2620 + Drive().Lock();
1.2621 + }
1.2622 + Drive().UnLock();
1.2623 + }
1.2624 +
1.2625 +
1.2626 +/**
1.2627 +Gets the address of the file that the file control block represents.
1.2628 +
1.2629 +The default implementation returns KErrNotSupported and should only
1.2630 +be overridden for ROM file systems.
1.2631 +
1.2632 +@param aPos On return, should contain the address of the file that
1.2633 + the file control block represents.
1.2634 +
1.2635 +@return KErrNone, if successful,otherwise one of the other system wide error
1.2636 + codes,
1.2637 +*/
1.2638 +EXPORT_C TInt CFileCB::Address(TInt& /*aPos*/) const
1.2639 + {
1.2640 +
1.2641 + return(KErrNotSupported);
1.2642 + }
1.2643 +
1.2644 +
1.2645 +/**
1.2646 +Sets the archive attribute, KEntryAttArchive, in iAtt.
1.2647 +*/
1.2648 +EXPORT_C void CFileCB::SetArchiveAttribute()
1.2649 + {
1.2650 +
1.2651 + iAtt|=KEntryAttArchive;
1.2652 + iAtt|=KEntryAttModified;
1.2653 + iModified.UniversalTime();
1.2654 + }
1.2655 +
1.2656 +
1.2657 +EXPORT_C TInt CFileCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* /*aInput*/)
1.2658 + {
1.2659 + switch(aInterfaceId)
1.2660 + {
1.2661 + case EGetLocalDrive:
1.2662 + return Mount().LocalDrive((TBusLocalDrive*&) aInterface);
1.2663 + default:
1.2664 + return(KErrNotSupported);
1.2665 + }
1.2666 + }
1.2667 +
1.2668 +
1.2669 +CFileCache* CFileCB::FileCache() const
1.2670 + {return iBody?iBody->iFileCache:NULL;}
1.2671 +
1.2672 +TBool CFileCB::LocalBufferSupport() const
1.2673 + {return iBody?iBody->iLocalBufferSupport:EFalse;}
1.2674 +
1.2675 +void CFileCB::SetLocalBufferSupport(TBool aEnabled)
1.2676 + {iBody->iLocalBufferSupport = aEnabled;}
1.2677 +
1.2678 +TInt CFileCB::CheckMount()
1.2679 +//
1.2680 +// Check that the media is still mounted.
1.2681 +//
1.2682 + {
1.2683 +
1.2684 + TDrive& d = Drive();
1.2685 + TInt r=d.CheckMount();
1.2686 + if (r!=KErrNone)
1.2687 + return(r);
1.2688 + if (&Mount() != &d.CurrentMount())
1.2689 + return(KErrDisMounted);
1.2690 + if (FileCorrupt())
1.2691 + return(KErrCorrupt);
1.2692 + if (BadPower())
1.2693 + {
1.2694 + if (PowerOk())
1.2695 + SetBadPower(EFalse);
1.2696 + else
1.2697 + return(KErrBadPower);
1.2698 + }
1.2699 + return(KErrNone);
1.2700 + }
1.2701 +
1.2702 +TInt64 CFileCB::CachedSize64() const
1.2703 + {
1.2704 + CFileCache* fileCache = iBody?iBody->iFileCache:NULL;
1.2705 + return fileCache? fileCache->Size64(): Size64();
1.2706 + }
1.2707 +
1.2708 +void CFileCB::SetCachedSize64(TInt64 aSize)
1.2709 + {
1.2710 + if (FileCache())
1.2711 + FileCache()->SetSize64(aSize);
1.2712 + else
1.2713 + SetSize64(aSize, EFalse); // assume not locked
1.2714 + }
1.2715 +
1.2716 +/**
1.2717 +Constructor.
1.2718 +Locks the mount resource to which the shared file resides.
1.2719 +
1.2720 +@param aFileCB File to be shared.
1.2721 +*/
1.2722 +CFileShare::CFileShare(CFileCB* aFileCB)
1.2723 + : iFile(aFileCB)
1.2724 + {
1.2725 + AddResource(iFile->Mount());
1.2726 + }
1.2727 +
1.2728 +/**
1.2729 +Destructor.
1.2730 +
1.2731 +Frees mount resource to which the shared file resides,
1.2732 +removes share status from the shared file and finally closes
1.2733 +the file.
1.2734 +*/
1.2735 +CFileShare::~CFileShare()
1.2736 + {
1.2737 + // We shouldn't be deleting the file share with a valid request queue or there will be request (& memory) leakage
1.2738 + __ASSERT_DEBUG(iCurrentRequest == NULL, Fault(ERequestQueueNotEmpty));
1.2739 +
1.2740 + RemoveResource(iFile->Mount());
1.2741 + iFile->RemoveLocks(this);
1.2742 + iFile->DemoteShare(this);
1.2743 + iFile->CancelAsyncReadRequest(this, NULL);
1.2744 + iFile->Close();
1.2745 + }
1.2746 +
1.2747 +/**
1.2748 +Check that the media is still mounted.
1.2749 +
1.2750 +@return KErrNone if successful.
1.2751 + KErrDisMounted if media has dismounted.
1.2752 + KErrCorrupted if shared file is corrupted.
1.2753 + KErrBadPower if insufficent power supply.
1.2754 + or other system wide error code.
1.2755 +*/
1.2756 +TInt CFileShare::CheckMount()
1.2757 + {
1.2758 + return File().CheckMount();
1.2759 + }
1.2760 +
1.2761 +/**
1.2762 +Initialise the object
1.2763 +*/
1.2764 +void CFileShare::InitL()
1.2765 + {
1.2766 + DoInitL(iFile->Drive().DriveNumber());
1.2767 +
1.2768 + // override the close operation so that we can flush the write cache if necessary
1.2769 + iRequest->Set(FileShareCloseOp,NULL);
1.2770 + iRequest->SetDriveNumber(DriveNumber());
1.2771 + iRequest->SetScratchValue((TUint)this);
1.2772 + }
1.2773 +
1.2774 +// Mark the start of a request -
1.2775 +// the is to prevent fair-scheduled async read/writes from being processed out of sequence. This is especially
1.2776 +// important when considering a client which appends to a file by issuing more than one asynchronous request as each
1.2777 +// write request must be entirely satisfied before a subsequent request can append to the file
1.2778 +TBool CFileShare::RequestStart(CFsMessageRequest* aRequest)
1.2779 + {
1.2780 + TBool ret;
1.2781 +
1.2782 + TDrive& drive = File().Drive();
1.2783 + drive.Lock();
1.2784 +
1.2785 + if (iCurrentRequest == NULL || iCurrentRequest == aRequest)
1.2786 + {
1.2787 + iCurrentRequest = aRequest;
1.2788 + ret = ETrue;
1.2789 + }
1.2790 + else
1.2791 + {
1.2792 + // add to end of linked list of requests if there is already an active request for this share
1.2793 + CFsClientMessageRequest* request;
1.2794 + for (request = (CFsClientMessageRequest*) iCurrentRequest; request->iNext != NULL; request = request->iNext)
1.2795 + {
1.2796 + }
1.2797 + request->iNext = (CFsClientMessageRequest*) aRequest;
1.2798 + ret = EFalse;
1.2799 + }
1.2800 +
1.2801 + drive.UnLock();
1.2802 + return ret;
1.2803 + }
1.2804 +
1.2805 +
1.2806 +// Mark the end of a request
1.2807 +void CFileShare::RequestEnd(CFsMessageRequest* aRequest)
1.2808 + {
1.2809 + TDrive& drive = File().Drive();
1.2810 + drive.Lock();
1.2811 +
1.2812 + if (aRequest == iCurrentRequest)
1.2813 + {
1.2814 + // Any requests in the queue ?
1.2815 + if (((CFsClientMessageRequest*) iCurrentRequest)->iNext)
1.2816 + {
1.2817 + iCurrentRequest = ((CFsClientMessageRequest*) aRequest)->iNext;
1.2818 + ((CFsClientMessageRequest*) aRequest)->iNext = NULL;
1.2819 +
1.2820 + // if the current request has been cancelled, cancel all requests in the queue
1.2821 + TInt lastError = aRequest->LastError();
1.2822 + if (lastError == KErrCancel || lastError == KErrNotReady)
1.2823 + {
1.2824 + // take ownership of this queue and make it invisible to anyone else by setting iCurrentRequest to NULL
1.2825 + CFsClientMessageRequest* currentRequest = (CFsClientMessageRequest*) iCurrentRequest;
1.2826 + iCurrentRequest = NULL;
1.2827 + drive.UnLock();
1.2828 + while(currentRequest)
1.2829 + {
1.2830 + CFsClientMessageRequest* nextRequest = ((CFsClientMessageRequest*) currentRequest)->iNext;
1.2831 + ((CFsClientMessageRequest*) currentRequest)->iNext = NULL;
1.2832 + currentRequest->Complete(lastError);
1.2833 + currentRequest = nextRequest;
1.2834 + }
1.2835 + }
1.2836 + else
1.2837 + {
1.2838 + drive.UnLock();
1.2839 + iCurrentRequest->Dispatch(EFalse);
1.2840 + }
1.2841 + }
1.2842 + else // queue empty
1.2843 + {
1.2844 + iCurrentRequest = NULL;
1.2845 + drive.UnLock();
1.2846 + }
1.2847 + }
1.2848 + else // if (aRequest == iCurrentRequest)
1.2849 + {
1.2850 + drive.UnLock();
1.2851 + }
1.2852 + }
1.2853 +
1.2854 +TBool CFileShare::RequestInProgress() const
1.2855 + {
1.2856 + return (iCurrentRequest != NULL)?(TBool)ETrue:(TBool)EFalse;
1.2857 + }
1.2858 +
1.2859 +
1.2860 +
1.2861 +/**
1.2862 +Initialise the object
1.2863 +*/
1.2864 +TInt TFsCloseFileShare::DoRequestL(CFsRequest* aRequest)
1.2865 +//
1.2866 + {
1.2867 + __PRINT(_L("TFsCloseFileCache::DoRequestL()"));
1.2868 +
1.2869 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.2870 +
1.2871 + // flush the write cache before closing the file share
1.2872 + TInt r;
1.2873 + CFileCache* fileCache = share->File().FileCache();
1.2874 + if (fileCache && (r = fileCache->FlushDirty(aRequest)) == CFsRequest::EReqActionBusy)
1.2875 + return r;
1.2876 +
1.2877 + return KErrNone;
1.2878 + }
1.2879 +
1.2880 +TInt TFsCloseFileShare::Complete(CFsRequest* aRequest)
1.2881 + {
1.2882 + __PRINT(_L("TFsCloseFileShare::Complete()"));
1.2883 + return TFsCloseObject::Complete(aRequest);
1.2884 + }
1.2885 +
1.2886 +
1.2887 +TAsyncReadRequest::TAsyncReadRequest(TInt64 aEndPos, CFileShare* aOwningShareP, CFsRequest* aRequestP)
1.2888 +//
1.2889 +// Constructor for TAsyncReadRequest
1.2890 +// - Maintains information about oustanding async read requests
1.2891 +//
1.2892 + : iEndPos(aEndPos),
1.2893 + iOwningShareP(aOwningShareP)
1.2894 + {
1.2895 + iMessage = aRequestP->Message();
1.2896 + iSessionP = aRequestP->Session();
1.2897 + iStatusP = iMessage.ClientStatus();
1.2898 + }
1.2899 +
1.2900 +
1.2901 +TBool TAsyncReadRequest::CompleteIfMatching(CFileShare* aShareP, TRequestStatus* aStatusP, TInt aError)
1.2902 +//
1.2903 +// Completes an asynchronous read request.
1.2904 +//
1.2905 + {
1.2906 + if (iOwningShareP == aShareP && (aStatusP == NULL || aStatusP == iStatusP))
1.2907 + {
1.2908 + iMessage.Complete(aError);
1.2909 + return ETrue;
1.2910 + }
1.2911 +
1.2912 + return EFalse;
1.2913 + }
1.2914 +
1.2915 +
1.2916 +TInt TFsFileReadCancel::Initialise(CFsRequest* aRequest)
1.2917 +//
1.2918 +// Initialise function for RFile::ReadCancel [EFsReadCancel]
1.2919 +//
1.2920 + {
1.2921 + return InitialiseScratchToShare(aRequest);
1.2922 + }
1.2923 +
1.2924 +
1.2925 +TInt TFsFileReadCancel::DoRequestL(CFsRequest* aRequest)
1.2926 +//
1.2927 +// Request function for RFile::ReadCancel [EFsReadCancel]
1.2928 +//
1.2929 + {
1.2930 + CFileShare* share = (CFileShare*)aRequest->ScratchValue();
1.2931 + TRequestStatus* status = (TRequestStatus*)aRequest->Message().Ptr0();
1.2932 + share->File().CancelAsyncReadRequest(share, status);
1.2933 + return(KErrNone);
1.2934 + }
1.2935 +
1.2936 +void CFileCB::ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset)
1.2937 + {
1.2938 + TRACETHREADID(aMessage);
1.2939 + TRACE7(UTF::EBorder, UTraceModuleFileSys::ECFileCBReadL, EF32TraceUidFileSys,
1.2940 + this, I64LOW(aPos), I64HIGH(aPos), aLength, aDes, threadId, aOffset);
1.2941 +
1.2942 + iBody->iExtendedFileInterface->ReadL(aPos,aLength,aDes,aMessage,aOffset);
1.2943 +
1.2944 + TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBReadLRet, EF32TraceUidFileSys, KErrNone);
1.2945 + }
1.2946 +
1.2947 +void CFileCB::WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset)
1.2948 + {
1.2949 + TRACETHREADID(aMessage);
1.2950 + TRACE7(UTF::EBorder, UTraceModuleFileSys::ECFileCBWriteL, EF32TraceUidFileSys,
1.2951 + this, I64LOW(aPos), I64HIGH(aPos), aLength, aDes, threadId, aOffset);
1.2952 +
1.2953 + iBody->iExtendedFileInterface->WriteL(aPos,aLength,aDes,aMessage,aOffset);
1.2954 +
1.2955 + TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBWriteLRet, EF32TraceUidFileSys, KErrNone);
1.2956 + }
1.2957 +
1.2958 +void CFileCB::SetSizeL(TInt64 aSize)
1.2959 + {
1.2960 + TRACE3(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetSizeL, EF32TraceUidFileSys, this, I64LOW(aSize), I64HIGH(aSize));
1.2961 +
1.2962 + iBody->iExtendedFileInterface->SetSizeL(aSize);
1.2963 +
1.2964 + TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBSetSizeLRet, EF32TraceUidFileSys, KErrNone);
1.2965 + }
1.2966 +
1.2967 +TBool CFileCB::ExtendedFileInterfaceSupported()
1.2968 + {
1.2969 + return iBody->ExtendedFileInterfaceSupported();
1.2970 + }
1.2971 +
1.2972 +TInt CFileCB::FairSchedulingLen() const
1.2973 + {
1.2974 + return iBody->iFairSchedulingLen;
1.2975 + }
1.2976 +
1.2977 +void CFileCB::SetNotifyAsyncReadersPending(TBool aNotifyAsyncReadersPending)
1.2978 +//
1.2979 +// Notify the asynchronous reader that a file has grown so that it may service outstanding async reads
1.2980 +//
1.2981 + {
1.2982 + iBody->iNotifyAsyncReadersPending = aNotifyAsyncReadersPending;
1.2983 + }
1.2984 +
1.2985 +TBool CFileCB::NotifyAsyncReadersPending() const
1.2986 + {
1.2987 + return iBody->iNotifyAsyncReadersPending;
1.2988 + }
1.2989 +
1.2990 +
1.2991 +void CFileCB::ResetReadAhead()
1.2992 + {
1.2993 + CFileCache* fileCache = FileCache();
1.2994 + if (fileCache)
1.2995 + fileCache->ResetReadAhead();
1.2996 + }
1.2997 +
1.2998 +void CFileCB::SetDeleteOnClose()
1.2999 + {
1.3000 + iBody->iDeleteOnClose = ETrue;
1.3001 + }
1.3002 +
1.3003 +TBool CFileCB::DeleteOnClose() const
1.3004 + {
1.3005 + return iBody->iDeleteOnClose;
1.3006 + }
1.3007 +
1.3008 +TInt CFileCB::GetInterfaceTraced(TInt aInterfaceId, TAny*& aInterface, TAny* aInput)
1.3009 + {
1.3010 + TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileCBGetInterface, EF32TraceUidFileSys, aInterfaceId, aInput);
1.3011 +
1.3012 + TInt r = GetInterface(aInterfaceId, aInterface, aInput);
1.3013 +
1.3014 + TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileCBGetInterfaceRet, EF32TraceUidFileSys, r, aInterface);
1.3015 +
1.3016 + return r;
1.3017 + }
1.3018 +
1.3019 +CFileBody::CFileBody(CFileCB* aFileCB, CFileCB::MExtendedFileInterface* aExtendedFileInterface)
1.3020 + : iFileCB(aFileCB),
1.3021 + iExtendedFileInterface(aExtendedFileInterface ? aExtendedFileInterface : this),
1.3022 + iSizeHigh(0)
1.3023 + {
1.3024 + iFairSchedulingLen = TFileCacheSettings::FairSchedulingLen(iFileCB->DriveNumber());
1.3025 + iMaxSupportedFileSize = KMaxSupportedFileSize;
1.3026 + }
1.3027 +
1.3028 +
1.3029 +CFileBody::~CFileBody()
1.3030 + {
1.3031 + if (iAsyncReadRequests)
1.3032 + {
1.3033 + iAsyncReadRequests->Close();
1.3034 + delete iAsyncReadRequests;
1.3035 + }
1.3036 + }
1.3037 +
1.3038 +
1.3039 +void CFileBody::InitL()
1.3040 + {
1.3041 + iAsyncReadRequests = new(ELeave) RArray<TAsyncReadRequest>(KAsyncRequestArrayGranularity, _FOFF(TAsyncReadRequest, iEndPos));
1.3042 + }
1.3043 +
1.3044 +
1.3045 +
1.3046 +TInt TFsFileClamp::Initialise(CFsRequest* aRequest)
1.3047 +//
1.3048 +// Initialise function for RFile::Clamp [EFsFileClamp]
1.3049 +//
1.3050 + {
1.3051 + TSecureId aUID = aRequest->Message().SecureId();
1.3052 + if (aUID!=KEstartUidValue && aUID!=KFileServerUidValue)
1.3053 + {
1.3054 + SSecurityInfo info;
1.3055 + info.iVendorId=0;
1.3056 + info.iCaps.iCaps[0]=0;
1.3057 + info.iCaps.iCaps[1]=0;
1.3058 + info.iSecureId=KEstartUidValue;
1.3059 + PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Clamp");
1.3060 + info.iSecureId=KFileServerUidValue;
1.3061 + PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Clamp");
1.3062 + return KErrPermissionDenied;
1.3063 + }
1.3064 +
1.3065 + TInt r=DoInitialise(aRequest);
1.3066 + if(r!=KErrNone)
1.3067 + return r;
1.3068 +
1.3069 + // The clamp API is only supported on non-removable media
1.3070 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.3071 + TDriveInfo di;
1.3072 + share->File().Drive().DriveInfo(di);
1.3073 + if (!(di.iDriveAtt & KDriveAttInternal))
1.3074 + r = KErrNotSupported;
1.3075 +
1.3076 + return(r);
1.3077 + }
1.3078 +
1.3079 +
1.3080 +TInt TFsFileClamp::DoRequestL(CFsRequest* aRequest)
1.3081 +//
1.3082 +// Request function for RFile::Clamp [EFsFileClamp]
1.3083 +//
1.3084 + {
1.3085 + TInt r;
1.3086 +
1.3087 + // Flush data for this file, if it is open for writing, before clamping
1.3088 + CFileShare* share=(CFileShare*)aRequest->ScratchValue();
1.3089 +
1.3090 + if (((share->iMode&EFileWrite)) || ((share->File().Att()&KEntryAttModified)))
1.3091 + {
1.3092 + r=share->CheckMount();
1.3093 + if (r!=KErrNone)
1.3094 + return(r);
1.3095 +
1.3096 + TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataL, EF32TraceUidFileSys, &share->File());
1.3097 + TRAP(r,share->File().FlushDataL());
1.3098 + TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECFileCBFlushDataLRet, EF32TraceUidFileSys, r);
1.3099 +
1.3100 + if(r!=KErrNone)
1.3101 + return(r);
1.3102 + }
1.3103 +
1.3104 + RFileClamp clamp;
1.3105 + r=aRequest->Drive()->ClampFile(aRequest->Src().FullName().Mid(2),
1.3106 + (TAny*)(&clamp));
1.3107 + // Write clamp information to user
1.3108 + TPckgC<RFileClamp> pkClamp(clamp);
1.3109 + aRequest->WriteL(KMsgPtr0, pkClamp);
1.3110 + return r;
1.3111 + }
1.3112 +
1.3113 +
1.3114 +TInt TFsUnclamp::Initialise(CFsRequest* aRequest)
1.3115 +//
1.3116 +// Initialise function for RFs::Unclamp [EFsUnclamp]
1.3117 +//
1.3118 + {
1.3119 + TSecureId aUID = aRequest->Message().SecureId();
1.3120 + if (aUID!=KEstartUidValue && aUID!=KFileServerUidValue)
1.3121 + {
1.3122 + SSecurityInfo info;
1.3123 + info.iVendorId=0;
1.3124 + info.iCaps.iCaps[0]=0;
1.3125 + info.iCaps.iCaps[1]=0;
1.3126 + info.iSecureId=KEstartUidValue;
1.3127 + PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Unclamp");
1.3128 + info.iSecureId=KFileServerUidValue;
1.3129 + PlatSec::PolicyCheckFail(aRequest->Message(),info,"File Unclamp");
1.3130 + return KErrPermissionDenied;
1.3131 + }
1.3132 + RFileClamp clamp;
1.3133 + TPckg<RFileClamp> pkClamp(clamp);
1.3134 + aRequest->ReadL(KMsgPtr0, pkClamp);
1.3135 + TInt driveNo=(I64HIGH(clamp.iCookie[1]));
1.3136 + TDrive& drive=TheDrives[driveNo];
1.3137 + aRequest->SetDrive(&drive);
1.3138 + return KErrNone;
1.3139 + }
1.3140 +
1.3141 +
1.3142 +TInt TFsUnclamp::DoRequestL(CFsRequest* aRequest)
1.3143 +//
1.3144 +// Request function for RFs::Unclamp [EFsUnclamp]
1.3145 +//
1.3146 + {
1.3147 + RFileClamp clamp;
1.3148 + TPckg<RFileClamp> pkClamp(clamp);
1.3149 + aRequest->ReadL(KMsgPtr0, pkClamp);
1.3150 + TDrive* drive=aRequest->Drive();
1.3151 + CMountCB* mount=(CMountCB*)&(drive->CurrentMount());
1.3152 + return(drive->UnclampFile(mount,&clamp));
1.3153 + }
1.3154 +
1.3155 +CMountBody::CMountBody(CMountCB* aMountCB, CMountCB::MFileAccessor* aFileAccessor, CMountCB::MFileExtendedInterface* aFileInterface)
1.3156 +//
1.3157 +// Constructor for private body class
1.3158 +//
1.3159 + : iMountCB(aMountCB),
1.3160 + iFileAccessor(aFileAccessor?aFileAccessor:this),
1.3161 + iFileExtendedInterface(aFileInterface?aFileInterface:this)
1.3162 + {
1.3163 + }
1.3164 +
1.3165 +CMountBody::~CMountBody()
1.3166 +//
1.3167 +// Destructor for private body class
1.3168 +//
1.3169 + {
1.3170 + __ASSERT_DEBUG(iClampIdentifiers.Count() == 0, User::Invariant());
1.3171 + iClampIdentifiers.Close();
1.3172 + }
1.3173 +
1.3174 +TInt CMountBody::ClampFile(const TInt aDriveNo,const TDesC& aName,TAny* aHandle)
1.3175 + {
1.3176 + // Need CMountCB::MFileAccessor interface support
1.3177 + if(iFileAccessor==this)
1.3178 + return KErrNotSupported;
1.3179 +
1.3180 + // Get unique identifier for the file
1.3181 + TInt64 uniqueId = 0;
1.3182 + TInt r = iFileAccessor->GetFileUniqueId(aName,uniqueId);
1.3183 + if(r!=KErrNone)
1.3184 + return r;
1.3185 +
1.3186 + // Populate the RFileClamp clamp instance and store it in iClampIdentifiers
1.3187 + RFileClamp* newClamp = (RFileClamp*)aHandle;
1.3188 + newClamp->iCookie[0]=uniqueId;
1.3189 + newClamp->iCookie[1]=MAKE_TINT64(aDriveNo,++iClampCount);
1.3190 + r = iClampIdentifiers.InsertInOrder((const RFileClamp&)*newClamp,&CompareClampsByIdAndCount);
1.3191 + if(r != KErrNone)
1.3192 + return r;
1.3193 +
1.3194 + // Indicate that (at least) one file is clamped on this drive
1.3195 + iMountCB->Drive().SetClampFlag(ETrue);
1.3196 + AddResource(*iMountCB);
1.3197 + return KErrNone;
1.3198 + }
1.3199 +
1.3200 +
1.3201 +TInt CMountBody::UnclampFile(RFileClamp* aHandle)
1.3202 + {
1.3203 + // Need CMountCB::MFileAccessor interface support
1.3204 + if(iFileAccessor==this)
1.3205 + return KErrNotSupported;
1.3206 +
1.3207 + TInt idx;
1.3208 + if((idx = iClampIdentifiers.Find((const RFileClamp&)*aHandle,&FindClampByIdAndCount)) < KErrNone)
1.3209 + {
1.3210 + // This file is not 'clamped'
1.3211 + return idx;
1.3212 + }
1.3213 +
1.3214 + // If we're removing the last clamp and a dismount has been deferred (due to files being clamped),
1.3215 + // then DeferredDismount() will trigger a dismount: before this happens we need to flush all
1.3216 + // dirty data on this drive;
1.3217 + TDrive& drive = iMountCB->Drive();
1.3218 + TInt noOfClamps = NoOfClamps();
1.3219 + if (noOfClamps == 1 && drive.DismountDeferred())
1.3220 + {
1.3221 + TInt r = drive.FlushCachedFileInfo(ETrue);
1.3222 + if (r == CFsRequest::EReqActionBusy)
1.3223 + return r;
1.3224 + }
1.3225 +
1.3226 + RemoveResource(*iMountCB);
1.3227 + iClampIdentifiers.Remove(idx);
1.3228 +
1.3229 + TInt r = KErrNone;
1.3230 + // If this was the last clamp, check for outstanding dismount requests
1.3231 + if (noOfClamps == 1)
1.3232 + {
1.3233 + ASSERT(NoOfClamps() == 0);
1.3234 + drive.SetClampFlag(EFalse);
1.3235 + if (drive.DismountDeferred())
1.3236 + r = drive.DeferredDismount();
1.3237 + }
1.3238 +
1.3239 + return r;
1.3240 + }
1.3241 +
1.3242 +
1.3243 +TInt CMountBody::IsFileClamped(const TInt64 aUniqueId)
1.3244 + {
1.3245 + // Need CMountCB::MFileAccessor interface support
1.3246 + if(iFileAccessor==this)
1.3247 + return KErrNotSupported;
1.3248 +
1.3249 + // Encapsulate the unique identifier in an appropriate class
1.3250 + RFileClamp newClamp;
1.3251 + newClamp.iCookie[0]=aUniqueId;
1.3252 + // Search for (any) entry in iClampIdentifiers holding this value
1.3253 + TInt index=iClampIdentifiers.Find((const RFileClamp&)newClamp,&FindClampById);
1.3254 + return (index==KErrNotFound?0:1);
1.3255 + }
1.3256 +
1.3257 +TInt CMountBody::NoOfClamps()
1.3258 + {
1.3259 + // Need CMountCB::MFileAccessor interface support
1.3260 + if(iFileAccessor==this)
1.3261 + return KErrNotSupported;
1.3262 +
1.3263 + // This will return zero if ClampFile has not previously been invoked
1.3264 + return iClampIdentifiers.Count();
1.3265 + }
1.3266 +
1.3267 +TInt CMountBody::CompareClampsById(const RFileClamp& aClampA, const RFileClamp& aClampB)
1.3268 + {
1.3269 + if(aClampA.iCookie[0] < aClampB.iCookie[0]) return 1;
1.3270 + if(aClampA.iCookie[0] > aClampB.iCookie[0]) return -1;
1.3271 + return 0;
1.3272 + }
1.3273 +
1.3274 +TInt CMountBody::CompareClampsByIdAndCount(const RFileClamp& aClampA, const RFileClamp& aClampB)
1.3275 + {
1.3276 + if(aClampA.iCookie[0] > aClampB.iCookie[0]) return 1;
1.3277 + if(aClampA.iCookie[0] < aClampB.iCookie[0]) return -1;
1.3278 + // Now compare the count values
1.3279 + if(I64LOW(aClampA.iCookie[1]) > I64LOW(aClampB.iCookie[1])) return 1;
1.3280 + if(I64LOW(aClampA.iCookie[1]) < I64LOW(aClampB.iCookie[1])) return -1;
1.3281 + return 0;
1.3282 + }
1.3283 +
1.3284 +TInt CMountBody::FindClampById(const RFileClamp& aClampA, const RFileClamp& aClampB)
1.3285 + {
1.3286 + return (TInt)(!CompareClampsById(aClampA, aClampB));
1.3287 + }
1.3288 +
1.3289 +
1.3290 +TInt CMountBody::FindClampByIdAndCount(const RFileClamp& aClampA, const RFileClamp& aClampB)
1.3291 + {
1.3292 + return (TInt)(!CompareClampsByIdAndCount(aClampA, aClampB));
1.3293 + }
1.3294 +
1.3295 +void CMountBody::SetProxyDriveDismounted()
1.3296 + {
1.3297 + iProxyDriveDismounted = ETrue;
1.3298 + }
1.3299 +
1.3300 +TBool CMountBody::ProxyDriveDismounted()
1.3301 + {
1.3302 + return iProxyDriveDismounted;
1.3303 + }
1.3304 +
1.3305 +
1.3306 +TInt CMountBody::GetFileUniqueId(const TDesC& /*aName*/, TInt64& /*aUniqueId*/)
1.3307 + {
1.3308 + return KErrNotSupported;
1.3309 + }
1.3310 +TInt CMountBody::Spare3(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
1.3311 + {
1.3312 + return KErrNotSupported;
1.3313 + }
1.3314 +TInt CMountBody::Spare2(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
1.3315 + {
1.3316 + return KErrNotSupported;
1.3317 + }
1.3318 +TInt CMountBody::Spare1(TInt /*aVal*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
1.3319 + {
1.3320 + return KErrNotSupported;
1.3321 + }
1.3322 +void CMountBody::ReadSection64L(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage)
1.3323 + {
1.3324 + if((TUint64)aPos > KMaxLegacyFileSize)
1.3325 + User::Leave(KErrNotSupported);
1.3326 +
1.3327 + iMountCB->ReadSectionL(aName, I64LOW(aPos), aTrg, aLength, aMessage);
1.3328 + }
1.3329 +
1.3330 +TBool CFileBody::ExtendedFileInterfaceSupported()
1.3331 + {
1.3332 + return (iExtendedFileInterface==this) ? (TBool)EFalse : (TBool)ETrue;
1.3333 + }
1.3334 +
1.3335 +// default implementations of MExtendedFileInterface
1.3336 +void CFileBody::ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset)
1.3337 + {
1.3338 + if ((TUint64)aPos > KMaxLegacyFileSize || aOffset > 0)
1.3339 + User::Leave(KErrNotSupported);
1.3340 +
1.3341 + iFileCB->ReadL((TInt) aPos, aLength, aDes, aMessage);
1.3342 + }
1.3343 +
1.3344 +void CFileBody::WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset)
1.3345 + {
1.3346 + if ((TUint64)aPos > KMaxLegacyFileSize || aOffset > 0)
1.3347 + User::Leave(KErrNotSupported);
1.3348 +
1.3349 + iFileCB->WriteL((TInt) aPos, aLength, aDes, aMessage);
1.3350 + }
1.3351 +
1.3352 +void CFileBody::SetSizeL(TInt64 aSize)
1.3353 + {
1.3354 + if ((TUint64)aSize > KMaxLegacyFileSize)
1.3355 + User::Leave(KErrNotSupported);
1.3356 +
1.3357 + iFileCB->SetSizeL((TInt) aSize);
1.3358 + }
1.3359 +
1.3360 +//---------------------------------------------------------------------------------------------------------------------
1.3361 +/**
1.3362 + This method allows file system to set maximum file size it supports.
1.3363 + This can be called on instantiation of the CFileCB derived class object by the file system implementation.
1.3364 + If this method is not called, the iMaxSupportedFileSize will have default value KMaxTUint64
1.3365 +
1.3366 + @param aMaxFileSize maximum file size supported by file system
1.3367 +*/
1.3368 +EXPORT_C void CFileCB::SetMaxSupportedSize(TUint64 aMaxFileSize)
1.3369 + {
1.3370 + iBody->iMaxSupportedFileSize = aMaxFileSize;
1.3371 + }
1.3372 +
1.3373 +/**
1.3374 + @return maximum supported file size (depends on the file system created it)
1.3375 +*/
1.3376 +TUint64 CFileCB::MaxSupportedSize(void) const
1.3377 + {
1.3378 + return iBody->iMaxSupportedFileSize;
1.3379 + }
1.3380 +
1.3381 +//---------------------------------------------------------------------------------------------------------------------
1.3382 +
1.3383 +/**
1.3384 +Gets the size of the file.
1.3385 +
1.3386 +This is 64-bit variant for CFileCB::Size().
1.3387 +This shall be used by File Systems supporting file size > 4GB - 1 to query the file size
1.3388 +inplace of CFileCB::Size() or CFileCB::iSize.
1.3389 +
1.3390 +@see CFileCB::iSize
1.3391 +@see CFileCB::Size()
1.3392 +
1.3393 +@prototype
1.3394 +
1.3395 +@return The size of the file.
1.3396 +*/
1.3397 +EXPORT_C TInt64 CFileCB::Size64() const
1.3398 + {
1.3399 + __ASSERT_DEBUG(iBody != NULL, Fault(EFileBodyIsNull));
1.3400 + const TInt64 size = MAKE_TINT64(iBody->iSizeHigh,iSize);
1.3401 + return size;
1.3402 + }
1.3403 +
1.3404 +//---------------------------------------------------------------------------------------------------------------------
1.3405 +/**
1.3406 +Sets the size of the file.
1.3407 +
1.3408 +This is 64-bit variant for CFileCB::SetSize().
1.3409 +This should be used by File Systems supporting file size > 4GB - 1 to set the file size
1.3410 +inplace of CFileCB::SetSize() or CFileCB::iSize.
1.3411 +
1.3412 +@see CFileCB::iSize
1.3413 +@see CFileCB::SetSize()
1.3414 +
1.3415 +@prototype
1.3416 +
1.3417 +@param aSize The size of the file.
1.3418 +@param aDriveLocked The status of the Drive Lock. If it is EFalse,
1.3419 +the file size shall be modified after acquiring the iLock mutex and if it is ETrue,
1.3420 +the file size shall be modified without aquiring the iLock mutex.
1.3421 +*/
1.3422 +EXPORT_C void CFileCB::SetSize64(TInt64 aSize, TBool aDriveLocked)
1.3423 + {
1.3424 + if(aDriveLocked)
1.3425 + {
1.3426 + iSize = (TInt)I64LOW(aSize);
1.3427 + iBody->iSizeHigh = (TInt)I64HIGH(aSize);
1.3428 + }
1.3429 + else
1.3430 + {
1.3431 + Drive().Lock();
1.3432 + iSize = (TInt)I64LOW(aSize);
1.3433 + iBody->iSizeHigh = (TInt)I64HIGH(aSize);
1.3434 + Drive().UnLock();
1.3435 + }
1.3436 + }
1.3437 +
1.3438 +
1.3439 +/** used to organize key comparison for the TFileShareLock*/
1.3440 +TInt LockOrder(const TFileShareLock& aMatch, const TFileShareLock& anEntry)
1.3441 + {
1.3442 +
1.3443 + if(aMatch.PosLow() > anEntry.PosLow())
1.3444 + return 1;
1.3445 + else if(aMatch.PosLow() < anEntry.PosLow())
1.3446 + return -1;
1.3447 + else
1.3448 + return 0;
1.3449 +
1.3450 + }
1.3451 +
1.3452 +//---------------------------------------------------------------------------------------------------------------------
1.3453 +/**
1.3454 + Find a lock inclusive of aPosLow to aPosHigh.
1.3455 +*/
1.3456 +TInt CFileCB::FindLock64(TInt64 aPosLow, TInt64 aPosHigh)
1.3457 + {
1.3458 +
1.3459 + const TInt count=FileLocks().Count();
1.3460 + for (TInt i=0; i<count; i++)
1.3461 + {
1.3462 +
1.3463 + const TFileShareLock& lock=FileLocks()[i];
1.3464 +
1.3465 + if(lock.PosLow() > (TUint64)aPosHigh)
1.3466 + return KErrNotFound;
1.3467 +
1.3468 + if(lock.MatchByPos(aPosLow, aPosHigh))
1.3469 + return i;
1.3470 + }
1.3471 +
1.3472 + return KErrNotFound;
1.3473 + }
1.3474 +
1.3475 +//---------------------------------------------------------------------------------------------------------------------
1.3476 +/**
1.3477 + Add a lock on a range.
1.3478 +*/
1.3479 +TInt CFileCB::AddLock64(CFileShare* aFileShare,TInt64 aPos,TInt64 aLength)
1.3480 + {
1.3481 + const TUint64 posHigh=aPos+aLength-1;
1.3482 +
1.3483 +
1.3484 + {//-- Lock overflow check
1.3485 + const TUint64 KMaxFileSize = aFileShare->IsFileModeBig() ? MaxSupportedSize() : KMaxLegacyFileSize;
1.3486 + if(posHigh > KMaxFileSize)
1.3487 + return KErrArgument;
1.3488 + }
1.3489 +
1.3490 +
1.3491 + TInt r=CheckLock64(NULL, aPos, aLength);
1.3492 + if (r!=KErrNone)
1.3493 + return r;
1.3494 +
1.3495 + TFileShareLock lock(aFileShare, aPos, posHigh);
1.3496 +
1.3497 + TLinearOrder<TFileShareLock> lockOrder(LockOrder);
1.3498 + r=FileLocks().InsertInOrder(lock, lockOrder);
1.3499 + __ASSERT_ALWAYS(r!=KErrAlreadyExists,Fault(EFileDuplicateLock));
1.3500 +
1.3501 + return r;
1.3502 + }
1.3503 +
1.3504 +//---------------------------------------------------------------------------------------------------------------------
1.3505 +/**
1.3506 + Remove a lock on a range.
1.3507 +*/
1.3508 +TInt CFileCB::RemoveLock64(CFileShare* aFileShare, TInt64 aPos, TInt64 aLength)
1.3509 + {
1.3510 + const TUint64 posHigh = aPos+aLength-1;
1.3511 +
1.3512 + {//-- Lock overflow check
1.3513 + const TUint64 KMaxFileSize = aFileShare->IsFileModeBig() ? MaxSupportedSize() : KMaxLegacyFileSize;
1.3514 + if(posHigh > KMaxFileSize)
1.3515 + return KErrArgument;
1.3516 + }
1.3517 +
1.3518 + const TInt pos=FindLock64(aPos, posHigh);
1.3519 + if (pos==KErrNotFound)
1.3520 + return KErrNotFound;
1.3521 +
1.3522 + const TFileShareLock& lock=FileLocks()[pos];
1.3523 + if (!lock.MatchOwner(aFileShare) || lock.PosLow() != (TUint64)aPos || lock.PosHigh() != posHigh)
1.3524 + return KErrNotFound;
1.3525 +
1.3526 +
1.3527 + FileLocks().Remove(pos);
1.3528 +
1.3529 + return KErrNone;
1.3530 + }
1.3531 +
1.3532 +//---------------------------------------------------------------------------------------------------------------------
1.3533 +/**
1.3534 + Check if a range is available.
1.3535 + @param aFileShare pointer to FileShare object. NULL only when is called from CFileCB::AddLock64()
1.3536 +
1.3537 +*/
1.3538 +TInt CFileCB::CheckLock64(CFileShare* aFileShare,TInt64 aPos,TInt64 aLength)
1.3539 + {
1.3540 + const TUint64 posHigh=aPos+aLength-1;
1.3541 +
1.3542 + //-- Lock overflow check. It is OK to have a lock that is beyond the real file size.
1.3543 + //-- if aFileShare == NULL, this is the call from AddLock64 and the position is already checked.
1.3544 + if(aFileShare)
1.3545 + {
1.3546 + const TUint64 KMaxFileSize = aFileShare->IsFileModeBig() ? MaxSupportedSize() : KMaxLegacyFileSize;
1.3547 + if(posHigh > KMaxFileSize)
1.3548 + return KErrNone; //-- OK, there can't be any locks beyond the max. supported file length
1.3549 + }
1.3550 +
1.3551 +
1.3552 + TInt lockIdx=FindLock64(aPos, posHigh);
1.3553 + if (lockIdx == KErrNotFound)
1.3554 + return KErrNone;
1.3555 +
1.3556 + const TInt count=FileLocks().Count();
1.3557 + const TFileShareLock* lock=(&FileLocks()[lockIdx]);
1.3558 +
1.3559 + for(;;)
1.3560 + {
1.3561 + if (!lock->MatchOwner(aFileShare))
1.3562 + return KErrLocked;
1.3563 +
1.3564 + if (lock->PosHigh() >= posHigh)
1.3565 + break;
1.3566 +
1.3567 + lockIdx++;
1.3568 + if (lockIdx >= count)
1.3569 + break;
1.3570 +
1.3571 + lock=&FileLocks()[lockIdx];
1.3572 +
1.3573 + if (posHigh < lock->PosLow())
1.3574 + break;
1.3575 + }
1.3576 +
1.3577 + return KErrNone;
1.3578 + }
1.3579 +
1.3580 +
1.3581 +//#####################################################################################################################
1.3582 +//# TFileShareLock class implementation
1.3583 +//#####################################################################################################################
1.3584 +
1.3585 +TFileShareLock::TFileShareLock(const CFileShare* aOwner, TUint64 aPosLow, TUint64 aPosHigh)
1.3586 + : iOwner(aOwner), iPosLow(aPosLow), iPosHigh(aPosHigh)
1.3587 + {
1.3588 + }
1.3589 +
1.3590 +
1.3591 +
1.3592 +TUint64 TFileShareLock::PosLow() const
1.3593 + {
1.3594 + return iPosLow;
1.3595 + }
1.3596 +
1.3597 +
1.3598 +TUint64 TFileShareLock::PosHigh() const
1.3599 + {
1.3600 + return iPosHigh;
1.3601 + }
1.3602 +
1.3603 +TBool TFileShareLock::MatchOwner(const CFileShare* aShare) const
1.3604 + {
1.3605 + return (aShare == iOwner);
1.3606 + }
1.3607 +
1.3608 +/**
1.3609 + @return ETrue if aPosLow and PosHigh match the lock boundaries
1.3610 +*/
1.3611 +TBool TFileShareLock::MatchByPos(TUint64 aPosLow, TUint64 aPosHigh) const
1.3612 + {
1.3613 + if(PosLow() > aPosHigh)
1.3614 + return EFalse;
1.3615 +
1.3616 + if ((aPosLow >= PosLow() && aPosLow <= PosHigh()) ||
1.3617 + (aPosHigh >= PosLow() && aPosHigh <= PosHigh()) ||
1.3618 + (aPosLow <= PosLow() && aPosHigh >= PosHigh() ))
1.3619 + {
1.3620 + return ETrue;
1.3621 + }
1.3622 +
1.3623 + return EFalse;
1.3624 + }
1.3625 +
1.3626 +
1.3627 +
1.3628 +
1.3629 +
1.3630 +
1.3631 +
1.3632 +
1.3633 +
1.3634 +
1.3635 +
1.3636 +
1.3637 +
1.3638 +
1.3639 +