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