diff -r 000000000000 -r bde4ae8d615e os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_prel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_prel.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,360 @@ +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// f32\sfile\sf_prel.cpp +// +// + +#include "sf_std.h" +#include "u32std.h" +#include +#include "sf_cache_man.h" + +_LIT(KLitInitCompleteThread,"InitCompleteThread"); + +#if defined(_DEBUG) || defined(_DEBUG_RELEASE) +_LIT(KCorruptFileNamesList,"CorruptFileNames.lst"); +_LIT(KSysData,"\\sys\\data\\"); +_LIT(KSystemData,"\\system\\data\\"); +/** +ASCII text file reader constructor +This code is more or less lifted directly from estart.cpp +*/ +TText8FileReader::TText8FileReader() + { + + iBufPos=-1; + iFileDataBuf=NULL; + iFileSize=0; + } + +/** +ASCII text file reader destructor +*/ +TText8FileReader::~TText8FileReader() + { + + delete[] iFileDataBuf; + } + +/** +Supply an ASCII text file for the file reader. +This function reads the entire contents of this file into a buffer, converting to +unicode / folding each character. Subsequent parsing of the file data is all done from this +buffer. +@param aFile The file to be read. Must already be opened for read access in EFileStreamText mode. +@return KErrNone if no error. +*/ +TInt TText8FileReader::Set(RFile& aFile) + { + + iFile=aFile; + iBuf.Zero(); + iBufPos=0; + + // Read the size of the file + TInt r=iFile.Size(iFileSize); + if (r!=KErrNone || !iFileSize) + return(KErrGeneral); + + // Allocate a buffer to read in the + iFileDataBuf=new TText[iFileSize+1]; // +1 in case need to NULL terminate the end of the last string + if (iFileDataBuf==NULL) + return(KErrNoMemory); + + // Read the entire contents of the file into the buffer + TPtr fdata(NULL,0); + TInt pos=0; + r=iFile.Seek(ESeekStart,pos); + while (pos, , <[ONCE,EVERY]> +e.g. +c:\system\bin\bt.lst, -6,EVERY +the filename should be fully qualified, +errorCode should be a literal not a symbol +EVERY means that every attempt to open the file will be failed +ONCE means that only the first access to the file will be failed +*/ + +TInt FindHitListFile(RFs aFs) + { + TFindFile finder(aFs); + TInt r=finder.FindByDir(KCorruptFileNamesList,_L("\\")); + if(r!=KErrNone) + { + r=finder.FindByDir(KCorruptFileNamesList,KSysData); + } + + if(r!=KErrNone) + { + r=finder.FindByDir(KCorruptFileNamesList,KSystemData); + } + + if(r==KErrNone) + { // This is stored as a global because the name can be retrieved by a user api + gCorruptFileNamesListFile=finder.File().Alloc(); + if(gCorruptFileNamesListFile==NULL) + { + r=KErrNoMemory; + } + } + return r; + } + +void CreateCorruptFileNamesList() + { + RFs fs; + fs.Connect(); + TInt r=FindHitListFile(fs); + if(r!=KErrNone) + return; + RFile f; + r=f.Open(fs,*gCorruptFileNamesListFile,EFileShareExclusive|EFileStreamText|EFileRead); + if(r!=KErrNone) + { + return; + } + // Create a corrupt filenames file reader and pass it the file object. This will also result in the copying of the contents of + // the file into reader's buffer. Filename information read from the file will include pointers to text strings in + // this buffer and so the reader object must not be deleted until processing is complete. + __PRINT1(_L("@@@@ Using Corrupt names file %S"),gCorruptFileNamesListFile); + + TText8FileReader* namesFile=new TText8FileReader; + if (!namesFile) + { + f.Close(); + return; + } + + r=namesFile->Set(f); + f.Close(); + fs.Close(); + if(r==KErrNone) + { + // Parse each drive mapping record in turn, saving the information in an array of mapping structures - one for + // each valid record. + TPtr linePtr(NULL,0); + while ((r=namesFile->Read(linePtr))==KErrNone) + { + TInt returnCode; + TBool useOnce; + TPtr namePtr(NULL,0); + if (ParseCorruptNamesRecord(linePtr,namePtr,returnCode,useOnce)==KErrNone) + { + // Valid corrupt filename record found + TCorruptNameRec* newRec=new TCorruptNameRec; + if(!newRec) + { + break; + } + if(newRec->Construct(&namePtr,returnCode,useOnce,gCorruptFileNameList)!=KErrNone) + { + delete newRec; + newRec=NULL; + break; + } + + gCorruptFileNameList=newRec; + } + else + { + __PRINT1(_L("@@@@@ Bad Parse corrupt file name record %S\n"),&linePtr); + } + } + } + + delete namesFile; + } +#endif + +TInt InitCompleteThread(TAny* aPtr) + { + __PRINT(KLitInitCompleteThread); + RMessagePtr2 message=*(RMessagePtr2*)aPtr; + RThread::Rendezvous(0); + + + // +#if defined(_DEBUG) || defined(_DEBUG_RELEASE) + CreateCorruptFileNamesList(); +#endif + + TInt r = KErrNone; + message.Complete(r); + return(KErrNone); + } + + +TInt TFsStartupInitComplete::DoRequestL(CFsRequest *aRequest) +// +// do further initialisation once necessary startup init complete outside file server +// + { + if(StartupInitCompleted) + return(KErrAlreadyExists); + + + StartupInitCompleted=ETrue; + RMessagePtr2 msg=aRequest->Message(); + RThread thread; + TInt r=thread.Create(KLitInitCompleteThread,InitCompleteThread,KDefaultStackSize,NULL,&msg); + if (KErrNone == r) + { + TRequestStatus s; + thread.Rendezvous(s); + if (s==KRequestPending) + thread.Resume(); + else + thread.Kill(0); + thread.Close(); + User::WaitForRequest(s); + r = s.Int(); + } + return(KErrNone); + } + +TInt TFsStartupInitComplete::Initialise(CFsRequest* /*aRequest*/) +// +// +// + { + return KErrNone; + }